import {z} from 'zod' export type GetApiV2AgentsAgentIdRunsRunIdArgs = {agent_id: string, run_id: string}; export type GetApiV2AgentsAgentIdRunsRunIdOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const effort = z.enum(["low", "medium", "high", "x-high", "max"]); export const taskRunErrorPublicV2 = z.object({message: z.string(), ref_id: z.string()}); export const taskRunStatusValue = z.enum(["queued", "running", "completed", "failed", "cancelled"]); export const taskRunResponsePublicV2 = z.object({completed_at: z.string().nullable().optional(), created_at: z.string(), effort: effort, error: taskRunErrorPublicV2.nullable().optional(), id: z.string(), interaction_id: z.string(), is_active: z.boolean(), prompt: z.string().nullable().optional(), started_at: z.string().nullable().optional(), status: taskRunStatusValue, web_search_agent_id: z.string()}); 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 Agent Run * * GET /v2/agents/{agent_id}/runs/{run_id} */ export const getApiV2AgentsAgentIdRunsRunId = async (args: GetApiV2AgentsAgentIdRunsRunIdArgs, options?: GetApiV2AgentsAgentIdRunsRunIdOptions) => { const {baseUrl = "https://sdk.nimbleway.com", 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(/\/+$/, '')}/v2/agents/${encodeURIComponent(String(args.agent_id))}/runs/${encodeURIComponent(String(args.run_id))}${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(taskRunResponsePublicV2, await res.json()) };