import {z} from 'zod' export type CreateApiV1AiEvalRunsRunIdCancelArgs = {runId: string}; export type CreateApiV1AiEvalRunsRunIdCancelOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const evalRunsCancelResponse = z.object({cancelled: z.number().int(), run: z.object({branch_id: z.string().nullable(), branch_name: z.string().nullable(), completed_at: z.string().nullable(), cost_basis: z.enum(["CREDITS", "LIST_PRICE", "null"]).nullable().optional(), created_at: z.string().nullable(), credit_downgraded: z.boolean(), description: z.string().nullable(), id: z.string(), is_archived: z.boolean(), llm: z.object({family_rank: z.enum(["fastest", "standard", "smartest"]), model: z.string(), model_id: z.string().nullable(), provider: z.enum(["bedrock", "anthropic", "openai", "grok", "snowflake_cortex", "openai_compatible", "fireworks", "fireworks_managed", "databricks_genie", "databricks_managed", "baseten_managed", "vertex_ai"]), thinking: z.enum(["default", "none", "low", "medium", "high"]), effort: z.string().nullable()}), llm_fallback_disabled: z.boolean(), model_id: z.string(), prompt_set_id: z.string(), results: z.array(z.object({agentic_job: z.object({conversation_id: z.string().nullable(), id: z.string(), state: z.enum(["CANCELLED", "COMPLETE", "DELIVERING", "EXECUTING", "FAILED", "QUEUED"])}), cost: z.number().nullable(), error_reason: z.string().nullable(), id: z.string(), limit_kind: z.enum(["STEP_CAP", "WALL_CLOCK", "null"]).nullable().optional(), outcome: z.enum(["ASKED_CLARIFICATION", "CANCELLED", "JOB_FAILED", "JUDGE_ERROR", "LIMIT_REACHED", "NO_TEXT", "null"]).nullable().optional(), prompt: z.string(), score: z.number().nullable(), scoring_cost: z.number().nullable(), timing_ms: z.number().int().nullable()})), run_number: z.number().int(), status: z.enum(["RUNNING", "COMPLETE", "CANCELLED"])}), total: z.number().int()}); 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 }; /** * Cancel an eval run * * POST /v1/ai/eval/runs/{runId}/cancel * * Also accepts auth: orgApiKey */ export const createApiV1AiEvalRunsRunIdCancel = async (args: CreateApiV1AiEvalRunsRunIdCancelArgs, options?: CreateApiV1AiEvalRunsRunIdCancelOptions) => { const {baseUrl = "https://blobsrus.omniapp.co/api", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/ai/eval/runs/${encodeURIComponent(String(args.runId))}/cancel${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(evalRunsCancelResponse, await res.json()) };