import {z} from 'zod' export type PatchApiAgentAgentTakeoverRequestAgentTakeoverRequestIdStateArgs = {agent_takeover_request_id: string, new_state: string}; export type PatchApiAgentAgentTakeoverRequestAgentTakeoverRequestIdStateOptions = {baseUrl: string, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const agentTakeoverRequest = z.object({id: z.string().optional(), date_created: z.string().optional(), date_updated: z.string().optional(), agent_user_id: z.string().optional(), conversation_id: z.string(), kb_id: z.string(), request_id: z.number().int(), is_flagged: z.boolean().optional(), category: z.string(), category_id: z.string().optional(), state: z.string(), assigned_to_agent_name: z.string().optional(), flagged_date: z.string().optional(), resolved_date: z.string().optional(), last_seen_by_user: z.string().optional(), last_seen_by_agent: 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 }; /** * Update Agent Takeover Request State * * PATCH /agent/agent-takeover-request/{agent_takeover_request_id}/state * * Also accepts auth: OAuth2PasswordBearer */ export const patchApiAgentAgentTakeoverRequestAgentTakeoverRequestIdState = async (args: PatchApiAgentAgentTakeoverRequestAgentTakeoverRequestIdStateArgs, options: PatchApiAgentAgentTakeoverRequestAgentTakeoverRequestIdStateOptions) => { const {baseUrl, fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.new_state != null) query.append("new_state", String(args.new_state)) if (APIKeyHeader !== undefined) headers.set("x-api-key", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/agent/agent-takeover-request/${encodeURIComponent(String(args.agent_takeover_request_id))}/state${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(agentTakeoverRequest, await res.json()) };