Add RPC helper for agent initialization
This commit is contained in:
@@ -379,6 +379,18 @@ export const InitializeAgentRequestMessageSchema = z.object({
|
||||
requestId: z.string().optional(),
|
||||
});
|
||||
|
||||
export const InitializeAgentResponseMessageSchema = z.object({
|
||||
// Response shares the same type literal as the request for simple requestId matching
|
||||
type: z.literal("initialize_agent_request"),
|
||||
payload: z.object({
|
||||
agentId: z.string(),
|
||||
agentStatus: z.string().optional(),
|
||||
timelineSize: z.number().optional(),
|
||||
requestId: z.string().optional(),
|
||||
error: z.string().optional(),
|
||||
}),
|
||||
});
|
||||
|
||||
export const SetAgentModeMessageSchema = z.object({
|
||||
type: z.literal("set_agent_mode"),
|
||||
agentId: z.string(),
|
||||
@@ -717,6 +729,7 @@ export const SessionOutboundMessageSchema = z.discriminatedUnion("type", [
|
||||
AudioOutputMessageSchema,
|
||||
TranscriptionResultMessageSchema,
|
||||
StatusMessageSchema,
|
||||
InitializeAgentResponseMessageSchema,
|
||||
ArtifactMessageSchema,
|
||||
ConversationLoadedMessageSchema,
|
||||
AgentStateMessageSchema,
|
||||
@@ -764,6 +777,7 @@ export type ListPersistedAgentsResponseMessage = z.infer<typeof ListPersistedAge
|
||||
export type ListProviderModelsResponseMessage = z.infer<
|
||||
typeof ListProviderModelsResponseMessageSchema
|
||||
>;
|
||||
export type InitializeAgentResponseMessage = z.infer<typeof InitializeAgentResponseMessageSchema>;
|
||||
|
||||
// Type exports for payload types
|
||||
export type ActivityLogPayload = z.infer<typeof ActivityLogPayloadSchema>;
|
||||
|
||||
@@ -1183,18 +1183,15 @@ export class Session {
|
||||
// Send timeline snapshot after hydration (if any)
|
||||
const timelineSize = this.emitAgentTimelineSnapshot(snapshot);
|
||||
|
||||
if (requestId) {
|
||||
this.emit({
|
||||
type: "status",
|
||||
payload: {
|
||||
status: "agent_initialized",
|
||||
agentId,
|
||||
agentStatus: snapshot.lifecycle,
|
||||
requestId,
|
||||
timelineSize,
|
||||
},
|
||||
});
|
||||
}
|
||||
this.emit({
|
||||
type: "initialize_agent_request",
|
||||
payload: {
|
||||
agentId,
|
||||
agentStatus: snapshot.lifecycle,
|
||||
timelineSize,
|
||||
requestId,
|
||||
},
|
||||
});
|
||||
|
||||
console.log(
|
||||
`[Session ${this.clientId}] Agent ${agentId} initialized with ${timelineSize} timeline item(s); status=${snapshot.lifecycle}`
|
||||
@@ -1205,12 +1202,11 @@ export class Session {
|
||||
error
|
||||
);
|
||||
this.emit({
|
||||
type: "activity_log",
|
||||
type: "initialize_agent_request",
|
||||
payload: {
|
||||
id: uuidv4(),
|
||||
timestamp: new Date(),
|
||||
type: "error",
|
||||
content: `Failed to initialize agent: ${error.message}`,
|
||||
agentId,
|
||||
requestId,
|
||||
error: error?.message ?? "Failed to initialize agent",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user