import {z} from 'zod' export type CreateDeepNewsRequestMessage = {role: string, content: string, name?: (string | null) | undefined, function_call?: ({[key: string]: unknown} | null) | undefined}; export type DeepNewsModel = 'o1-mini' | 'o1' | 'o3-mini' | 'o3' | 'gpt-4o-mini' | 'gpt-4o' | 'gpt-4.1-2025-04-14' | 'gpt-5-mini' | 'gpt-5' | 'command-nightly' | 'claude-3-5-sonnet-20240620' | 'claude-3-5-sonnet-latest' | 'claude-3-7-sonnet-latest' | 'claude-3-7-sonnet-20250219' | 'claude-3-7-sonnet-nothinking' | 'claude-sonnet-4-20250514' | 'claude-opus-4-20250514' | 'claude-sonnet-4-5-20250929' | 'claude-opus-4-5-20251101' | 'claude-sonnet-4-6' | 'claude-sonnet-5' | 'claude-sonnet-5-5' | 'claude-opus-4-8' | 'claude-opus-5' | 'claude-opus-5-5' | 'claude-opus-4-6' | 'claude-fable-5' | 'claude-fable-5-1' | 'gpt-5.6-terra' | 'gpt-5.6-sol' | 'gpt-6-sol' | 'gpt-6.1-sol' | 'gpt-6-astra' | 'deepseek' | 'deepseek-basic' | 'deepseek-r1-0528' | 'meta-llama/Meta-Llama-3-8B-Instruct' | 'meta-llama/Meta-Llama-3.1-405B-Instruct' | 'meta-llama/Meta-Llama-3.3-70B-Instruct' | 'meta-llama/Llama-4-Maverick-17B-128E-Instruct' | 'gemini-2.5-flash' | 'gemini-2.5-pro' | 'gemini-2.5-pro-preview-03-25' | 'gemini-3-pro' | 'gemini-3.1-pro' | 'gemini-4-argon' | 'gemini-3-flash' | 'gemini-3.5-flash' | 'gemini-3.6-flash' | 'open-source-best' | 'kimi-k2p5' | 'kimi-k3'; export type CreateDeepNewsRequest = {messages: Array, model?: (DeepNewsModel | null) | undefined, filter_params?: ({[key: string]: unknown} | null) | undefined, search_depth?: number | undefined, max_depth?: number | undefined, sources?: ('asknews' | 'google' | 'graph' | 'wiki' | 'x' | 'reddit' | 'charts' | 'email' | 'full_text_discovery' | 'podcasts' | Array<'asknews' | 'google' | 'graph' | 'wiki' | 'x' | 'reddit' | 'charts' | 'email' | 'full_text_discovery' | 'podcasts'>) | undefined, inline_citations?: ('markdown_link' | 'numbered' | 'none') | undefined, start_citation_number?: number | undefined, return_sources?: boolean | undefined, only_cited_sources?: boolean | undefined, append_references?: boolean | undefined, journalist_mode?: boolean | undefined, conversational_awareness?: boolean | undefined, include_entities?: boolean | undefined, include_graphs?: boolean | undefined, include_coordinates?: boolean | undefined, asknews_watermark?: boolean | undefined, stream?: boolean | undefined, stop?: (string | Array | null) | undefined, temperature?: number | undefined, top_p?: number | undefined, n?: number | undefined, max_tokens?: number | undefined, presence_penalty?: number | undefined, frequency_penalty?: number | undefined, user?: (string | null) | undefined, thread_id?: (string | null) | undefined, max_parallel_tool_calls?: number | undefined, engine?: ('v1' | 'v1.5' | 'v2.0') | undefined, enable_source_pruning?: boolean | undefined, cutoff_datetime?: (string | null) | undefined, stream_sources_inline?: boolean | undefined} | {[key: string]: unknown}; export type CreateApiV1ChatDeepnewsArgs = {body: CreateDeepNewsRequest}; export type CreateApiV1ChatDeepnewsOptions = {baseUrl?: string | undefined, APIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV1ChatDeepnewsResponse = z.object({id: z.string(), created: z.number().int(), object: z.string().optional(), model: z.string().optional(), usage: z.object({prompt_tokens: z.number().int(), completion_tokens: z.number().int(), total_tokens: z.number().int(), tool_usage: z.record(z.string(), z.number().int()).nullable().optional()}), choices: z.array(z.object({index: z.number().int(), message: z.object({role: z.string(), content: z.string(), name: z.string().nullable().optional(), function_call: z.record(z.string(), z.unknown()).nullable().optional()}), finish_reason: z.string().nullable().optional()})), sources: z.object({news: z.array(z.object({article_url: z.string().min(1).max(2083), article_id: z.string(), classification: z.union([z.array(z.string()), z.string()]), country: z.string(), source_id: z.string(), page_rank: z.number().int(), domain_url: z.string(), eng_title: z.string(), entities: z.object({Person: z.array(z.string()).optional(), Organization: z.array(z.string()).optional(), Location: z.array(z.string()).optional(), Nationality: z.array(z.string()).optional(), Date: z.array(z.string()).optional(), Event: z.array(z.string()).optional(), Money: z.array(z.string()).optional(), Law: z.array(z.string()).optional(), Quantity: z.array(z.string()).optional(), Time: z.array(z.string()).optional(), Sports: z.array(z.string()).optional(), Politics: z.array(z.string()).optional(), Title: z.array(z.string()).optional(), Number: z.array(z.string()).optional(), Arms: z.array(z.string()).optional(), Product: z.array(z.string()).optional(), Media: z.array(z.string()).optional(), Transportation: z.array(z.string()).optional(), Religion: z.array(z.string()).optional(), Technology: z.array(z.string()).optional(), Space: z.array(z.string()).optional(), Medicine: z.array(z.string()).optional(), Language: z.array(z.string()).optional(), Science: z.array(z.string()).optional()}), image_url: z.string().nullable().optional(), keywords: z.array(z.string()), language: z.string(), pub_date: z.string(), summary: z.string(), key_points: z.array(z.string()).nullable().optional(), title: z.string(), sentiment: z.number().int(), centroid_distance: z.number().nullable().optional(), cluster_probability: z.number().nullable().optional(), markdown_citation: z.string().optional(), provocative: z.enum(["unknown", "low", "medium", "high"]).optional(), reporting_voice: z.union([z.enum(["Objective", "Subjective", "Investigative", "Narrative", "Analytical", "Advocacy", "Conversational", "Satirical", "Emotive", "Explanatory", "UnknownPersuasive", "Sensational"]), z.enum(["Objective", "Subjective", "Investigative", "Narrative", "Analytical", "Advocacy", "Conversational", "Satirical", "Emotive", "Explanatory", "UnknownPersuasive", "Sensational"]), z.enum(["Objective", "Subjective", "Investigative", "Narrative", "Analytical", "Advocacy", "Conversational", "Satirical", "Emotive", "Explanatory", "UnknownPersuasive", "Sensational"]), z.string()]).optional(), entity_relation_graph: z.object({nodes: z.array(z.record(z.string(), z.string())).optional(), edges: z.array(z.record(z.string(), z.string())).optional()}).nullable().optional(), geo_coordinates: z.record(z.string(), z.object({latitude: z.number(), longitude: z.number(), metadata: z.record(z.string(), z.unknown())})).nullable().optional(), continent: z.enum(["Africa", "Asia", "Europe", "Middle East", "North America", "South America", "Oceania"]).nullable().optional(), assets: z.object({images: z.array(z.string()).nullable().optional(), videos: z.array(z.string()).nullable().optional()}).nullable().optional(), social_embeds: z.array(z.string()).nullable().optional(), bias: z.enum(["Political", "Gender", "Cultural", "Age", "Religious", "Statement", "Illogical Claims", "Slant", "Source Selection", "Omission of Source Attribution", "Spin", "Sensationalism", "Negativity", "Subjective Adjectives", "Ad Hominem", "Mind Reading", "Opinion-as-Fact", "None", "Unknown"]).nullable().optional(), authors: z.array(z.object({email: z.string().nullable().optional(), name: z.string().nullable().optional(), url: z.string().nullable().optional()})).nullable().optional(), wikidata_entities: z.record(z.string(), z.array(z.object({title: z.string(), qid: z.string(), relevance: z.number(), description: z.string().nullable().optional(), source_mention: z.string().nullable().optional(), source_mentions: z.array(z.string()).nullable().optional()}))).nullable().optional(), full_text: z.string().nullable().optional(), original_language_summary: z.string().nullable().optional(), image_description: z.string().nullable().optional(), crawl_date: z.string().nullable().optional(), content_type: z.enum(["news", "opinion", "analysis", "review", "listicle", "guide", "interview", "profile", "forum", "liveblog", "fact-check", "press_release", "obituary", "data_journalism"]).nullable().optional(), as_string_key: z.string()})).nullable().optional(), web: z.array(z.object({title: z.string(), url: z.string().min(1).max(2083), source: z.string(), published: z.string(), key_points: z.array(z.string()), raw_text: z.string().optional(), as_string_key: z.string().nullable().optional()})).nullable().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 }; /** * Deep research into real-time news, archive news, and Google. * * POST /v1/chat/deepnews */ export const createApiV1ChatDeepnews = async (args: CreateApiV1ChatDeepnewsArgs, options?: CreateApiV1ChatDeepnewsOptions) => { const {baseUrl = "https://api.asknews.app", fetch: fetchFn = fetch, APIKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (APIKey !== undefined) headers.set("Authorization", APIKey) const url = `${baseUrl.replace(/\/+$/, '')}/v1/chat/deepnews${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(createApiV1ChatDeepnewsResponse, await res.json()) };