import {z} from 'zod' export type AI72AgentBatchHistoryUserAccount = {email?: string | undefined, phone?: string | undefined}; export type AI72AgentBatchHistoryRequest = {company_id: string, end_time?: number | undefined, page?: number | undefined, start_time?: number | undefined, user_accounts: Array}; export type CreateApiAiSsoAgentBatchHistoryArgs = {body: AI72AgentBatchHistoryRequest}; export type CreateApiAiSsoAgentBatchHistoryOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const aI72AgentBatchHistoryHistoryRecordsDTO = z.object({q: z.string().optional(), id: z.string().optional(), efq: z.string().optional(), link: z.string().optional(), time: z.string().optional(), count: z.object({}).optional(), source: z.string().optional(), message: z.string().optional(), icon_url: z.string().optional(), raw_type: z.string().optional(), icon_path: z.string().optional(), patent_id: z.string().optional(), created_at: z.string().optional(), extra_info: z.object({}).optional(), business_id: z.string().optional(), business_name: z.string().optional()}); export const aI72AgentBatchHistoryDailyRecordsDTO = z.object({data: z.array(aI72AgentBatchHistoryHistoryRecordsDTO).optional(), date: z.string().optional()}); export const aI72AgentBatchHistoryHistoryRecordsResponseDTO = z.object({page: z.number().int().optional(), limit: z.number().int().optional(), total: z.number().int().optional(), history_maps: z.array(aI72AgentBatchHistoryDailyRecordsDTO).optional()}); export const aI72AgentBatchHistoryUserHistory = z.object({email: z.string().optional(), phone: z.string().optional(), history: aI72AgentBatchHistoryHistoryRecordsResponseDTO.optional()}); export const aI72AgentBatchHistoryBatchAgentHistoryResponse = z.object({user_histories: z.array(aI72AgentBatchHistoryUserHistory).optional()}); export const aI72AgentBatchHistoryResponse = z.object({data: aI72AgentBatchHistoryBatchAgentHistoryResponse.optional(), status: z.boolean(), error_msg: z.string().optional(), error_code: z.number().int()}); 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 }; /** * AI72 Batch Obtain Offline History Record * * POST /ai/sso/agent/batch-history */ export const createApiAiSsoAgentBatchHistory = async (args: CreateApiAiSsoAgentBatchHistoryArgs, options?: CreateApiAiSsoAgentBatchHistoryOptions) => { const {baseUrl = "https://connect.patsnap.com", 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 (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/ai/sso/agent/batch-history${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(aI72AgentBatchHistoryResponse, await res.json()) };