import {z} from 'zod' export type GetApiApiV0AgentSessionsSessionIdMessagesArgs = {session_id: string, after_sequence?: (number | null) | undefined}; export type GetApiApiV0AgentSessionsSessionIdMessagesOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const agentAttachmentGetResponse = z.object({id: z.string(), filename: z.string(), content_type: z.string(), size_bytes: z.number().int(), url: z.string().nullable().optional()}); export const kgSourceRef = z.object({document_public_id: z.string(), document_name: z.string().nullable().optional(), page_number: z.number().int().nullable().optional()}); export const kgNodeRef = z.object({node_id: z.string(), name: z.string(), type_id: z.string().nullable().optional(), type_name: z.string().nullable().optional(), ontology: z.string().nullable().optional(), tier: z.string().nullable().optional(), attributes: z.record(z.string(), z.unknown()).optional(), attribute_sources: z.record(z.string(), z.array(kgSourceRef)).optional()}); export const kgResultRefs = z.object({knowledge_base_id: z.string(), nodes: z.array(kgNodeRef).optional(), groundings: z.array(kgSourceRef).optional()}); export const agentMessageFeedbackResponse = z.object({id: z.string(), rating: z.string(), reason: z.string().nullable().optional(), comment: z.string().nullable().optional(), created_at: z.string(), updated_at: z.string()}); export const agentMessageGetResponse = z.object({id: z.string(), run_id: z.string().nullable().optional(), role: z.string(), content: z.string().nullable().optional(), tool_calls: z.array(z.record(z.string(), z.unknown())).nullable().optional(), tool_call_id: z.string().nullable().optional(), attachments: z.array(agentAttachmentGetResponse).nullable().optional(), model_names: z.array(z.string()).nullable().optional(), kg_refs: kgResultRefs.nullable().optional(), feedback: agentMessageFeedbackResponse.nullable().optional(), sequence_number: z.number().int(), created_at: z.string()}); export const getApiApiV0AgentSessionsSessionIdMessagesResponse = z.array(agentMessageGetResponse); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Get session messages * * GET /api/v0/agent/sessions/{session_id}/messages */ export const getApiApiV0AgentSessionsSessionIdMessages = async (args: GetApiApiV0AgentSessionsSessionIdMessagesArgs, options: GetApiApiV0AgentSessionsSessionIdMessagesOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.after_sequence != null) query.append("after_sequence", String(args.after_sequence)) if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v0/agent/sessions/${encodeURIComponent(String(args.session_id))}/messages${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiApiV0AgentSessionsSessionIdMessagesResponse, await res.json()) };