import {z} from 'zod' export type WalletCredentialsSchema = {mpp_tempo_key?: (string | null) | undefined, x402_private_key?: (string | null) | undefined}; export type MPPConfigSchema = {chain_id?: (number | null) | undefined, currency?: (string | null) | undefined, decimals?: number | undefined, payment_method_types?: Array | undefined, recipient?: (string | null) | undefined, rpc_url?: (string | null) | undefined, session_budget_usd: number | string, stripe_profile_id?: (string | null) | undefined}; export type BudgetPeriod = 'execution' | 'daily' | 'monthly'; export type WalletStatus = 'active' | 'disabled'; export type WalletType = 'x402' | 'mpp' | 'dual'; export type X402ConfigSchema = {facilitator_url?: string | undefined, network?: string | undefined, scheme?: string | undefined, signer_type?: string | undefined}; export type UpdateWalletRequest = {credentials?: (WalletCredentialsSchema | null) | undefined, mpp_config?: (MPPConfigSchema | null) | undefined, service_budget_period?: (BudgetPeriod | null) | undefined, service_budget_usd?: (number | string | null) | undefined, status?: (WalletStatus | null) | undefined, wallet_type?: (WalletType | null) | undefined, x402_config?: (X402ConfigSchema | null) | undefined}; export type UpdateApiV1WorkspacesWorkspaceAgentsAgentIdWalletArgs = {workspace: string, agent_id: string, body: UpdateWalletRequest}; export type UpdateApiV1WorkspacesWorkspaceAgentsAgentIdWalletOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const walletResponse = z.object({agent_id: z.string(), created_at: z.string().nullable().optional(), has_credentials: z.boolean().optional(), id: z.string(), mpp_config: z.record(z.string(), z.unknown()).nullable().optional(), service_budget_period: z.string(), service_budget_usd: z.string(), status: z.string(), updated_at: z.string().nullable().optional(), wallet_type: z.string(), x402_config: z.record(z.string(), z.unknown()).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 }; /** * Update Wallet * * PUT /v1/workspaces/{workspace}/agents/{agent_id}/wallet */ export const updateApiV1WorkspacesWorkspaceAgentsAgentIdWallet = async (args: UpdateApiV1WorkspacesWorkspaceAgentsAgentIdWalletArgs, options: UpdateApiV1WorkspacesWorkspaceAgentsAgentIdWalletOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/workspaces/${encodeURIComponent(String(args.workspace))}/agents/${encodeURIComponent(String(args.agent_id))}/wallet${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(walletResponse, await res.json()) };