import {z} from 'zod' export type GetApiApprovalsApprovalIdArgs = {approval_id: string}; export type GetApiApprovalsApprovalIdOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const runStatus = z.enum(["PENDING", "RUNNING", "COMPLETED", "PAUSED", "CANCELLED", "ERROR", "REGENERATED"]); export const approvalResponse = z.object({id: z.string(), run_id: z.string(), session_id: z.string(), status: z.string(), source_type: z.string(), approval_type: z.string().nullable().optional(), pause_type: z.string().nullable().optional(), tool_name: z.string().nullable().optional(), tool_args: z.record(z.string(), z.unknown()).nullable().optional(), expires_at: z.number().int().nullable().optional(), agent_id: z.string().nullable().optional(), team_id: z.string().nullable().optional(), workflow_id: z.string().nullable().optional(), user_id: z.string().nullable().optional(), schedule_id: z.string().nullable().optional(), schedule_run_id: z.string().nullable().optional(), source_name: z.string().nullable().optional(), requirements: z.array(z.record(z.string(), z.unknown())).nullable().optional(), context: z.record(z.string(), z.unknown()).nullable().optional(), resolution_data: z.record(z.string(), z.unknown()).nullable().optional(), resolved_by: z.string().nullable().optional(), resolved_at: z.number().int().nullable().optional(), created_at: z.number().int().nullable().optional(), updated_at: z.number().int().nullable().optional(), run_status: runStatus.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 Approval * * GET /approvals/{approval_id} */ export const getApiApprovalsApprovalId = async (args: GetApiApprovalsApprovalIdArgs, options: GetApiApprovalsApprovalIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/approvals/${encodeURIComponent(String(args.approval_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(approvalResponse, await res.json()) };