import {z} from 'zod' export type GetApiV1MinerAgentsAgentIdVersionsArgs = {agent_id: string}; export type GetApiV1MinerAgentsAgentIdVersionsOptions = {baseUrl: string, SessionBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const agentVersionState = z.enum(["RECEIVED", "QUEUED", "RUNNING", "ELIGIBLE", "DISCARDED", "CANCELLED"]); export const agentVersionHistoryEntry = z.object({eliminated_at: z.string().nullable().optional(), eliminated_in_race_number: z.number().int().nullable().optional(), agent_version_id: z.string(), version_number: z.number().int(), submitted_at: z.string(), state: agentVersionState, final_score: z.number().nullable().optional(), is_selected_for_race: z.boolean().optional(), selection_fallback_reason: z.enum(["eliminated", "discarded", "below_threshold", "not_eligible", "selected_after_close"]).nullable().optional(), is_pinnable: z.boolean().optional(), pin_disabled_reason: z.enum(["eliminated", "discarded", "below_threshold", "not_eligible", "selected_after_close"]).nullable().optional()}); export const getApiV1MinerAgentsAgentIdVersionsResponse = z.array(agentVersionHistoryEntry); 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 agent versions * * GET /v1/miner/agents/{agent_id}/versions * * Also accepts auth: X-Hotkey + X-Timestamp + X-Nonce + X-Signature */ export const getApiV1MinerAgentsAgentIdVersions = async (args: GetApiV1MinerAgentsAgentIdVersionsArgs, options: GetApiV1MinerAgentsAgentIdVersionsOptions) => { const {baseUrl, fetch: fetchFn = fetch, SessionBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (SessionBearer !== undefined) headers.set('authorization', `Bearer ${SessionBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/miner/agents/${encodeURIComponent(String(args.agent_id))}/versions${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(getApiV1MinerAgentsAgentIdVersionsResponse, await res.json()) };