import {z} from 'zod' export type GetApiApiV1UnifiedExecutionsArgs = {'X-Tenant-ID': string, 'X-Org-ID': string, limit?: number | undefined, offset?: number | undefined, execution_type?: ('map_plan' | 'wcp_workflow') | undefined, status?: ('pending' | 'running' | 'completed' | 'failed' | 'cancelled' | 'aborted' | 'expired') | undefined}; export type GetApiApiV1UnifiedExecutionsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const unifiedStepStatus = z.object({step_id: z.string().optional(), step_index: z.number().int().optional(), step_name: z.string().optional(), step_type: z.enum(["llm_call", "tool_call", "connector_call", "human_task", "synthesis", "action", "gate"]).optional(), status: z.enum(["pending", "running", "completed", "failed", "skipped", "blocked", "approval"]).optional(), started_at: z.string().optional(), ended_at: z.string().optional(), duration: z.string().optional(), decision: z.enum(["allow", "block", "require_approval"]).optional(), decision_reason: z.string().optional(), policies_matched: z.array(z.string()).optional(), approval_status: z.enum(["pending", "approved", "rejected", "expired"]).optional(), approved_by: z.string().optional(), approved_at: z.string().optional(), rejected_by: z.string().optional(), rejected_at: z.string().optional(), model: z.string().optional(), provider: z.string().optional(), cost_usd: z.number().optional(), tokens_in: z.number().int().optional(), tokens_out: z.number().int().optional(), input: z.unknown(), output: z.unknown(), result_summary: z.string().optional(), error: z.string().optional()}); export const unifiedExecutionStatus = z.object({execution_id: z.string().optional(), execution_type: z.enum(["map_plan", "wcp_workflow"]).optional(), name: z.string().optional(), source: z.string().optional(), status: z.enum(["pending", "running", "completed", "failed", "cancelled", "aborted", "expired"]).optional(), current_step_index: z.number().int().optional(), total_steps: z.number().int().optional(), progress_percent: z.number().optional(), started_at: z.string().optional(), completed_at: z.string().optional(), duration: z.string().optional(), estimated_cost_usd: z.number().optional(), actual_cost_usd: z.number().optional(), steps: z.array(unifiedStepStatus).optional(), error: z.string().optional(), tenant_id: z.string().optional(), org_id: z.string().optional(), user_id: z.string().optional(), client_id: z.string().optional(), metadata: z.record(z.string(), z.unknown()).optional(), created_at: z.string().optional(), updated_at: z.string().optional()}); export const unifiedExecutionListResponse = z.object({executions: z.array(unifiedExecutionStatus).optional(), total: z.number().int().optional(), limit: z.number().int().optional(), offset: z.number().int().optional(), has_more: z.boolean().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 }; /** * List executions (MAP plans + WCP workflows) * * GET /api/v1/unified/executions */ export const getApiApiV1UnifiedExecutions = async (args: GetApiApiV1UnifiedExecutionsArgs, options?: GetApiApiV1UnifiedExecutionsOptions) => { const {baseUrl = "https://orchestrator.getaxonflow.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['X-Tenant-ID'] != null) headers.set("X-Tenant-ID", String(args['X-Tenant-ID'])) if (args['X-Org-ID'] != null) headers.set("X-Org-ID", String(args['X-Org-ID'])) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.execution_type != null) query.append("execution_type", String(args.execution_type)) if (args.status != null) query.append("status", String(args.status)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/unified/executions${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(unifiedExecutionListResponse, await res.json()) };