import {z} from 'zod' export type GetApiApiV2ProjectsProjectIdSessionsArgs = {project_id: string, page?: number | undefined, page_size?: number | undefined, to_date?: (string | null) | undefined, from_date?: (string | null) | undefined, test_list?: (string | null) | undefined, test_run_id?: (string | null) | undefined, prompt_name?: (string | null) | undefined, review_queue_id?: (string | null) | undefined}; export type GetApiApiV2ProjectsProjectIdSessionsOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const inputVariable: z.ZodType = z.union([z.string(), z.number().int(), z.boolean(), z.number(), z.record(z.string(), z.lazy(() => inputVariable)), z.array(z.lazy(() => inputVariable))]); export const textBlock = z.object({text: z.string(), type: z.literal("text").optional()}); export const jSONValue: z.ZodType = z.union([z.boolean(), z.number().int(), z.number(), z.string(), z.record(z.string(), z.lazy(() => jSONValue)), z.array(z.lazy(() => jSONValue))]).nullable(); export const toolCallBlock = z.object({id: z.string(), name: z.string(), arguments: jSONValue, thought_signature: z.string().nullable().optional(), type: z.literal("tool_call").optional()}); export const imageBlock = z.object({media_id: z.string(), type: z.literal("image").optional()}); export const audioBlock = z.object({media_id: z.string(), type: z.literal("audio").optional()}); export const fileBlock = z.object({media_id: z.string(), filename: z.string().nullable().optional(), type: z.literal("file").optional()}); export const toolResultBlock: z.ZodType = z.object({tool_call_id: z.string(), content: z.union([z.string(), z.array(z.discriminatedUnion("type", [textBlock, z.lazy(() => toolResultBlock), toolCallBlock, imageBlock, audioBlock, fileBlock]))]), type: z.literal("tool_result").optional()}); export const userMessage = z.object({content: z.union([z.string(), z.array(z.discriminatedUnion("type", [textBlock, toolResultBlock, toolCallBlock, imageBlock, audioBlock, fileBlock]))]), role: z.literal("user").optional()}); export const systemMessage = z.object({content: z.string(), role: z.literal("system").optional()}); export const developerMessage = z.object({content: z.string(), role: z.literal("developer").optional()}); export const assistantMessage = z.object({content: z.union([z.string(), z.array(z.discriminatedUnion("type", [textBlock, toolResultBlock, toolCallBlock, imageBlock, audioBlock, fileBlock]))]), role: z.literal("assistant").optional()}); export const evaluationResultInfo = z.object({name: z.string(), manual_score: jSONValue, auto_eval_score: jSONValue}); export const clientEvaluationResultInfo = z.object({name: z.string(), value: jSONValue}); export const userAPIInfo = z.object({id: z.string(), email_address: z.string(), first_name: z.string(), last_name: z.string()}); export const evaluationNoteExportInfo = z.object({id: z.string(), content: z.string(), created_at: z.string(), created_by: userAPIInfo}); export const sessionCompletionInfo = z.object({message_type: z.string(), completion_id: z.string(), environment: z.string().nullable(), provider_name: z.string().nullable(), model_name: z.string().nullable(), input_variables: z.record(z.string(), inputVariable), prompt: z.array(z.discriminatedUnion("role", [userMessage, systemMessage, developerMessage, assistantMessage])), prompt_template_name: z.string().nullable(), response: z.string().nullable(), customer_feedback: z.record(z.string(), z.union([z.string(), z.number().int(), z.number(), z.boolean()])), evaluation_results: z.array(evaluationResultInfo), client_evaluation_results: z.array(clientEvaluationResultInfo), notes: z.array(evaluationNoteExportInfo).nullable(), trace_id: z.string().nullable(), format_version: z.number().int().nullable(), start_time: z.string().nullable(), end_time: z.string().nullable()}); export const detailedSessionInfo = z.object({session_id: z.string(), start_time: z.string(), custom_metadata: z.record(z.string(), z.union([z.string(), z.number(), z.number().int(), z.boolean()])), messages: z.array(sessionCompletionInfo)}); export const getApiApiV2ProjectsProjectIdSessionsResponse = z.array(detailedSessionInfo); 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 }; /** * List Sessions * * GET /api/v2/projects/{project_id}/sessions */ export const getApiApiV2ProjectsProjectIdSessions = async (args: GetApiApiV2ProjectsProjectIdSessionsArgs, options: GetApiApiV2ProjectsProjectIdSessionsOptions) => { const {baseUrl, fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.page_size != null) query.append("page_size", String(args.page_size)) if (args.to_date != null) query.append("to_date", String(args.to_date)) if (args.from_date != null) query.append("from_date", String(args.from_date)) if (args.test_list != null) query.append("test_list", String(args.test_list)) if (args.test_run_id != null) query.append("test_run_id", String(args.test_run_id)) if (args.prompt_name != null) query.append("prompt_name", String(args.prompt_name)) if (args.review_queue_id != null) query.append("review_queue_id", String(args.review_queue_id)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/projects/${encodeURIComponent(String(args.project_id))}/sessions${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(getApiApiV2ProjectsProjectIdSessionsResponse, await res.json()) };