import {z} from 'zod' export type GetApiV1PublicEpisodeResultsEpisodeResultIdFeedbackArgs = {episode_result_id: string}; export type GetApiV1PublicEpisodeResultsEpisodeResultIdFeedbackOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const interactionCall = z.object({call_id: z.string(), tool_name: z.string(), args: z.record(z.string(), z.unknown()).nullable().optional(), observation: z.record(z.string(), z.unknown()).nullable().optional(), done: z.boolean().nullable().optional(), error_code: z.string().nullable().optional()}); export const interactionStep = z.object({step_index: z.number().int(), turn: z.number().int().nullable().optional(), calls: z.array(interactionCall).optional(), shopper_message: z.string().nullable().optional(), message: z.string().nullable().optional()}); export const observableIssue = z.object({code: z.string(), count: z.number().int().optional(), step_index: z.number().int().nullable().optional()}); export const episodeFeedback = z.object({schema_version: z.literal("oro.episode_feedback.v1").optional(), episode_result_id: z.string(), task_id: z.string(), query: z.string().nullable().optional(), family: z.string(), phase: z.enum(["QUALIFYING", "RACE"]), outcome: z.enum(["completed", "partial", "agent_error", "environment_error", "verifier_error", "leakage", "exploit"]), passed: z.boolean().nullable().optional(), paid_reward: z.number().nullable().optional(), step_count: z.number().int(), tool_call_count: z.number().int(), search_call_count: z.number().int(), termination_code: z.enum(["placed_order", "step_limit", "no_final_order", "declined", "agent_error", "infrastructure_error", "unknown"]), interaction: z.array(interactionStep).optional(), observable_issues: z.array(observableIssue).optional(), diagnostics_state: z.enum(["available", "diagnostics_unavailable"]).optional(), failure_category: z.enum(["request_not_met", "needs_not_found", "changes_missed", "process_requirement_missed", "not_the_best_option", "did_not_finish", "infrastructure"]).nullable().optional(), end_reason: z.enum(["finished", "budget_exhausted", "timeout", "agent_error", "agent_stopped", "sandbox_stopped", "environment_fault"]).nullable().optional()}); 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 miner-safe episode feedback * * GET /v1/public/episode-results/{episode_result_id}/feedback */ export const getApiV1PublicEpisodeResultsEpisodeResultIdFeedback = async (args: GetApiV1PublicEpisodeResultsEpisodeResultIdFeedbackArgs, options: GetApiV1PublicEpisodeResultsEpisodeResultIdFeedbackOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v1/public/episode-results/${encodeURIComponent(String(args.episode_result_id))}/feedback${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(episodeFeedback, await res.json()) };