import {z} from 'zod' export type GetApiV2ProviderActionsIdCaseOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV2ProviderActionsIdCaseResponse = z.object({schemaVersion: z.literal("steward.provider-case-manifest.v1"), caseId: z.string(), tenantId: z.string(), workspaceId: z.string(), requestActor: z.object({type: z.literal("agent"), id: z.string(), revision: z.number().int()}), approvalActor: z.object({type: z.literal("user"), id: z.string()}).nullable(), resumeActor: z.enum(["steward-system", "null"]).nullable(), providerAccount: z.object({id: z.string(), revision: z.number().int()}), operation: z.object({id: z.string(), key: z.string(), revision: z.number().int(), canonicalProfile: z.string(), riskClass: z.string()}), actionDigest: z.string(), requestHash: z.string(), idempotencyKeyHash: z.string(), accessDecision: z.object({id: z.string(), hash: z.string(), effect: z.enum(["allow", "deny"])}), policyDecision: z.object({id: z.string().nullable(), hash: z.string().nullable(), effect: z.string()}), approvalCommitmentHash: z.string().nullable(), execution: z.record(z.string(), z.unknown()).nullable(), dependencyRevisions: z.record(z.string(), z.unknown()), events: z.array(z.object({seq: z.number().int(), action: z.string(), role: z.string(), hmac: z.string()})), eventSeqRange: z.record(z.string(), z.unknown()).nullable(), terminalState: z.string(), completeness: z.enum(["complete", "incomplete", "unknown"]), missingRequiredRoles: z.array(z.string()), incompletenessReasons: z.array(z.string()), safeSummary: z.record(z.string(), z.unknown()).nullable(), genesisAt: z.string().nullable(), terminalAt: z.string().nullable(), assembledAt: 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 a provider-action case manifest * * GET /v2/provider-actions/{id}/case */ export const getApiV2ProviderActionsIdCase = async (options?: GetApiV2ProviderActionsIdCaseOptions) => { const {baseUrl = "http://localhost:3200", 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/provider-actions/${encodeURIComponent(String(args.id))}/case${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(getApiV2ProviderActionsIdCaseResponse, await res.json()) };