import {z} from 'zod' export type GetApiAgentAgentDashboardDetailsConversationIdArgs = {conversation_id: string}; export type GetApiAgentAgentDashboardDetailsConversationIdOptions = {baseUrl: string, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const categoryResponse = z.object({id: z.string().optional(), name: z.string().optional(), description: z.string().optional(), color: z.string().optional()}); export const agentDashboardResponse = z.object({request_number: z.number().int(), agent_takeover_request_id: z.string().optional(), agent_conversation_id: z.string().optional(), conversation_id: z.string().optional(), request_time: z.string(), assigned_to: z.string(), knowledge_base_name: z.string(), category: categoryResponse.optional(), state: z.string(), is_flagged: z.boolean(), email: z.string().optional(), taken_from_user_id: 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 Agent Dashboard Details Response * * GET /agent/agent-dashboard-details/{conversation_id} * * Also accepts auth: OAuth2PasswordBearer */ export const getApiAgentAgentDashboardDetailsConversationId = async (args: GetApiAgentAgentDashboardDetailsConversationIdArgs, options: GetApiAgentAgentDashboardDetailsConversationIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (APIKeyHeader !== undefined) headers.set("x-api-key", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/agent/agent-dashboard-details/${encodeURIComponent(String(args.conversation_id))}${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(agentDashboardResponse, await res.json()) };