import {z} from 'zod' export type AI362TechnicalQaReportRequest = {task_id: string}; export type CreateApiAiTechnicalQaReportArgs = {body: AI362TechnicalQaReportRequest}; export type CreateApiAiTechnicalQaReportOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const aI362TechnicalQaReportValidationSplitQueryDTO = z.object({query: z.array(z.unknown()), concept: z.array(z.unknown())}); export const aI362TechnicalQaReportPaperAuthor = z.object({id: z.string().optional(), name: z.string().optional()}); export const aI362TechnicalQaReportOrgInfo = z.object({id: z.string().optional(), logo: z.string().optional(), name: z.string().optional(), site: z.string().optional(), name_cn: z.string().optional(), name_en: z.string().optional(), website: z.string().optional(), state_id: z.string().optional(), entity_id: z.string().optional(), country_id: z.string().optional(), state_name: z.string().optional(), entity_type: z.string().optional(), country_name: z.string().optional(), display_name: z.string().optional(), founded_date: z.number().int().optional(), normalized_id: z.string().optional(), normalized_logo: z.string().optional(), normalized_name: z.string().optional(), normalized_display_name: z.string().optional(), normalized_entity_type_en: z.string().optional()}); export const aI362TechnicalQaReportPdfImage = z.object({image_id: z.string().optional(), extracted: z.boolean().optional(), patent_id: z.string().optional(), image_from: z.string().optional(), image_type: z.string().optional(), is_extracted: z.boolean().optional(), storage_path: z.string().optional(), official_size: z.string().optional(), source_image_type: z.string().optional(), fulltext_image240_url: z.string().optional()}); export const aI362TechnicalQaReportSeekReferenceResponseDTO = z.object({apd: z.string().optional(), pbd: z.string().optional(), link: z.string().optional(), title: z.string().optional(), authors: z.array(aI362TechnicalQaReportPaperAuthor).optional(), content: z.string().optional(), org_info: z.array(aI362TechnicalQaReportOrgInfo).optional(), pdf_image: z.array(aI362TechnicalQaReportPdfImage).optional(), project_id: z.string().optional(), solution_id: z.string().optional(), project_name: z.string().optional(), solution_type: z.string().optional(), pdf_image_count: z.number().int().optional(), solution_sub_type: z.string().optional()}); export const aI362TechnicalQaReportSeekStreamMessageResponseDTO = z.object({title: z.string().optional(), modules: z.array(z.unknown()).optional(), summary: z.string().optional(), recommend: z.array(z.unknown()).optional(), references: z.array(aI362TechnicalQaReportSeekReferenceResponseDTO).optional(), application: z.array(z.unknown()).optional(), check_summary: z.string().optional(), summary_think: z.string().optional(), agent_suggestion: z.string().optional(), tech_mind_suggestion: z.string().optional(), agent_suggestion_scene: z.string().optional()}); export const aI362TechnicalQaReportTechnicalQaResponse = z.object({task_id: z.string(), split_query: aI362TechnicalQaReportValidationSplitQueryDTO.optional(), task_status: z.number().int(), message_response: aI362TechnicalQaReportSeekStreamMessageResponseDTO.optional()}); export const aI362TechnicalQaReportResponse = z.object({data: aI362TechnicalQaReportTechnicalQaResponse.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 }; /** * AI36-2 Technical Q&A - Query Task * * POST /ai/technical-qa/report */ export const createApiAiTechnicalQaReport = async (args: CreateApiAiTechnicalQaReportArgs, options?: CreateApiAiTechnicalQaReportOptions) => { 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/technical-qa/report${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(aI362TechnicalQaReportResponse, await res.json()) };