import {z} from 'zod' export type CreateApiV2AgentsAgentIdMoveArgs = {dry_run?: (boolean | 'true' | 'false') | undefined, agent_id: string, body: {target_team_id: string, move_learnings?: boolean | undefined, bypass_standalone_gate?: boolean | undefined}}; export type CreateApiV2AgentsAgentIdMoveOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV2AgentsAgentIdMoveResponse = z.object({source_team_id: z.string(), target_team_id: z.string(), root_agent_id: z.string(), agents: z.array(z.object({id: z.string(), name: z.string()})), queues: z.array(z.object({id: z.string(), name: z.string(), item_count: z.number()})), total_case_items: z.number(), total_runs: z.number(), skills_to_clone: z.array(z.object({id: z.string(), name: z.string()})), files_to_copy: z.array(z.object({path: z.string()})), warnings: z.object({outcome: z.object({instances_reconnected: z.array(z.object({agent_id: z.string(), agent_name: z.string(), integration_type: z.string(), integration_name: z.string(), instance_name: z.string(), decision: z.enum(["reuse", "needs_reconnect", "unmatched_integration", "custom_to_rebuild"])})), instances_disconnected: z.array(z.object({agent_id: z.string(), agent_name: z.string(), integration_type: z.string(), integration_name: z.string(), instance_name: z.string(), decision: z.enum(["reuse", "needs_reconnect", "unmatched_integration", "custom_to_rebuild"])})), custom_integrations_to_rebuild: z.array(z.object({agent_id: z.string(), agent_name: z.string(), custom_integration_name: z.string()})), catalog_rows_created_on_target: z.number()}), dropped_folders: z.array(z.object({id: z.string(), name: z.string()})), dropped_memory_count: z.number(), files_copied_count: z.number(), files_skipped_conflict: z.array(z.string())}), options: z.object({move_learnings: z.boolean()}), applied: z.boolean()}); 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 }; /** * Move Agent * * POST /v2/agents/{agent_id}/move */ export const createApiV2AgentsAgentIdMove = async (args: CreateApiV2AgentsAgentIdMoveArgs, options?: CreateApiV2AgentsAgentIdMoveOptions) => { const {baseUrl = "https://api.duvo.ai", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.dry_run != null) query.append("dry_run", String(args.dry_run)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/agents/${encodeURIComponent(String(args.agent_id))}/move${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(createApiV2AgentsAgentIdMoveResponse, await res.json()) };