refactor(agent): replace interface with zod schema for message request

Add createMessage method to AgentApiClient to handle posting messages to sessions
This commit is contained in:
icarus 2025-09-19 12:58:14 +08:00
parent 1c19e529ac
commit 445528aff7
2 changed files with 12 additions and 3 deletions

View File

@ -7,6 +7,7 @@ import {
CreateAgentResponse,
CreateAgentResponseSchema,
CreateSessionForm,
CreateSessionMessageRequest,
CreateSessionRequest,
CreateSessionResponse,
CreateSessionResponseSchema,
@ -208,4 +209,14 @@ export class AgentApiClient {
throw processError(error, 'Failed to update session.')
}
}
public async createMessage(agentId: string, sessionId: string, content: string): Promise<void> {
const url = this.getSessionMessagesPath(agentId, sessionId)
try {
const payload = { content } satisfies CreateSessionMessageRequest
await this.axios.post(url, payload)
} catch (error) {
throw processError(error, 'Failed to post message.')
}
}
}

View File

@ -204,9 +204,7 @@ export const ListAgentSessionsResponseSchema = z.object({
export type ListAgentSessionsResponse = z.infer<typeof ListAgentSessionsResponseSchema>
export interface CreateSessionMessageRequest {
content: string
}
export type CreateSessionMessageRequest = z.infer<typeof CreateSessionMessageRequestSchema>
export const CreateSessionResponseSchema = AgentSessionEntitySchema