import {z} from 'zod' export type GetApiVaultAgentIdActionsActionIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiVaultAgentIdActionsActionIdResponse = z.object({ok: z.literal(true), data: z.object({id: z.string(), type: z.literal("transfer"), status: z.enum(["pending_approval", "rejected", "signed", "broadcast", "confirmed", "failed", "outcome_unknown", "retired"]), chainId: z.number().int().gte(1), to: z.string(), value: z.string(), token: z.string(), txHash: z.string().optional(), signedTx: z.string().optional(), sponsorship: z.object({requested: z.boolean().optional(), sponsored: z.boolean().optional(), provider: z.string().optional(), mode: z.string().optional(), estimatedUsd: z.number().nullable().optional()}).optional(), policyResults: z.array(z.record(z.string(), z.unknown())).optional(), createdAt: z.string().optional(), signedAt: z.string().optional(), confirmedAt: z.string().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 transfer wallet action status * * GET /vault/{agentId}/actions/{actionId} */ export const getApiVaultAgentIdActionsActionId = async (options?: GetApiVaultAgentIdActionsActionIdOptions) => { 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(/\/+$/, '')}/vault/${encodeURIComponent(String(args.agentId))}/actions/${encodeURIComponent(String(args.actionId))}${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(getApiVaultAgentIdActionsActionIdResponse, await res.json()) };