fix(useSession): provide default empty array for messages when undefined

Make messages field optional in GetAgentSessionResponseSchema to match actual API behavior and prevent potential undefined access
This commit is contained in:
icarus 2025-09-19 15:56:09 +08:00
parent 798126d39c
commit 7fc676bbc3
2 changed files with 2 additions and 2 deletions

View File

@ -31,7 +31,7 @@ export const useSession = (agentId: string, sessionId: string) => {
return {
session: data,
messages: data?.messages,
messages: data?.messages ?? [],
error,
isLoading,
updateSession

View File

@ -194,7 +194,7 @@ export interface UpdateSessionRequest extends Partial<AgentBase> {}
export const GetAgentSessionResponseSchema = AgentSessionEntitySchema.extend({
built_in_tools: z.array(ToolSchema).optional(), // Built-in tools available to the agent
messages: z.array(AgentSessionMessageEntitySchema) // Messages in the session
messages: z.array(AgentSessionMessageEntitySchema).optional() // Messages in the session
})
export type GetAgentSessionResponse = z.infer<typeof GetAgentSessionResponseSchema>