import {z} from 'zod' export type GetApiApiV1OllieProjectsProjectIdConversationArgs = {project_id: string, before_id?: (string | null) | undefined, limit?: number | undefined}; export type GetApiApiV1OllieProjectsProjectIdConversationOptions = {baseUrl: string, OAuth2PasswordBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const citation = z.object({type: z.enum(["web", "internal_ref", "tool_result", "lookup"]), title: z.string(), url: z.string().nullable().optional(), source_id: z.string().nullable().optional(), section: z.string().nullable().optional(), snippet: z.string().nullable().optional(), confidence: z.enum(["definitive", "confident", "hedged", "unknown"])}); export const agentConversationMessageResponse = z.object({id: z.string(), conversation_id: z.string(), role: z.enum(["user", "ollie", "system"]), content: z.string(), tool_calls: z.array(z.record(z.string(), z.unknown())), citations: z.array(citation), model_used: z.string().nullable().optional(), created_at: z.string(), user_feedback: z.enum(["up", "down"]).nullable().optional(), trace_id: z.string().nullable().optional()}); export const agentConversationPageResponse = z.object({id: z.string(), project_id: z.string(), muted: z.boolean(), message_count: z.number().int(), messages: z.array(agentConversationMessageResponse), has_more: z.boolean()}); 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 Conversation * * GET /api/v1/ollie/projects/{project_id}/conversation */ export const getApiApiV1OllieProjectsProjectIdConversation = async (args: GetApiApiV1OllieProjectsProjectIdConversationArgs, options: GetApiApiV1OllieProjectsProjectIdConversationOptions) => { const {baseUrl, fetch: fetchFn = fetch, OAuth2PasswordBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.before_id != null) query.append("before_id", String(args.before_id)) if (args.limit != null) query.append("limit", String(args.limit)) if (OAuth2PasswordBearer !== undefined) headers.set('authorization', `Bearer ${OAuth2PasswordBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/ollie/projects/${encodeURIComponent(String(args.project_id))}/conversation${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(agentConversationPageResponse, await res.json()) };