import {z} from 'zod' export type FilterParams = {query?: string | undefined, n_articles?: number | undefined, start_timestamp?: (number | null) | undefined, end_timestamp?: (number | null) | undefined, time_filter?: ('crawl_date' | 'pub_date') | undefined, return_type?: ('string' | 'dicts' | 'both') | undefined, historical?: boolean | undefined, method?: ('nl' | 'kw' | 'both') | undefined, similarity_score_threshold?: number | undefined, offset?: (number | string) | undefined, categories?: (Array<'All' | 'Business' | 'Crime' | 'Politics' | 'Science' | 'Sports' | 'Technology' | 'Military' | 'Health' | 'Entertainment' | 'Finance' | 'Culture' | 'Climate' | 'Environment' | 'World'>) | undefined, doc_start_delimiter?: string | undefined, doc_end_delimiter?: string | undefined, provocative?: ('unknown' | 'low' | 'medium' | 'high' | 'all') | undefined, reporting_voice?: (Array<'Objective' | 'Subjective' | 'Investigative' | 'Narrative' | 'Analytical' | 'Advocacy' | 'Conversational' | 'Satirical' | 'Emotive' | 'Explanatory' | 'Persuasive' | 'Sensational' | 'Unknown' | 'all'> | 'Objective' | 'Subjective' | 'Investigative' | 'Narrative' | 'Analytical' | 'Advocacy' | 'Conversational' | 'Satirical' | 'Emotive' | 'Explanatory' | 'Persuasive' | 'Sensational' | 'Unknown' | 'all') | undefined, domain_url?: (Array | string | null) | undefined, bad_domain_url?: (Array | string | null) | undefined, page_rank?: (number | null) | undefined, diversify_sources?: boolean | undefined, strategy?: ('latest news' | 'news knowledge' | 'default') | undefined, hours_back?: number | undefined, string_guarantee?: (Array | null) | undefined, string_guarantee_op?: ('AND' | 'OR') | undefined, reverse_string_guarantee?: (Array | null) | undefined, entity_guarantee?: (Array | null) | undefined, reverse_entity_guarantee?: (Array | null) | undefined, entity_guarantee_op?: ('AND' | 'OR') | undefined, return_graphs?: boolean | undefined, return_geo?: boolean | undefined, languages?: (Array<'sq' | 'ar' | 'az' | 'ca' | 'zh' | 'hr' | 'cs' | 'da' | 'nl' | 'en' | 'eo' | 'fi' | 'fr' | 'gl' | 'de' | 'el' | 'he' | 'hi' | 'hu' | 'is' | 'id' | 'ia' | 'it' | 'ja' | 'kk' | 'km' | 'ko' | 'ky' | 'ms' | 'mt' | 'mhr' | 'mn' | 'no' | 'or' | 'pl' | 'pt' | 'pa' | 'ro' | 'ru' | 'sr' | 'sk' | 'sl' | 'es' | 'sv' | 'ta' | 'te' | 'th' | 'tr' | 'uk' | 'vi' | 'unknown'> | null) | undefined, countries?: (Array | null) | undefined, countries_blacklist?: (Array | null) | undefined, continents?: (Array<'Africa' | 'Asia' | 'Oceania' | 'Europe' | 'Middle East' | 'North America' | 'South America'> | null) | undefined, sentiment?: ('negative' | 'neutral' | 'positive' | null) | undefined, premium?: boolean | undefined}; export type AskNewsSource = {identifier?: 'asknews' | undefined, params?: (FilterParams | null) | undefined}; export type TelegramSourceParams = {channel_name: string}; export type TelegramSource = {identifier?: 'telegram' | undefined, params: TelegramSourceParams}; export type BlueskySourceParams = {query?: (string | null) | undefined}; export type BlueskySource = {identifier?: 'bluesky' | undefined, params?: (BlueskySourceParams | null) | undefined}; export type WebSourceParams = {queries: Array, domains?: (Array | null) | undefined, strict?: boolean | undefined, lookback?: number | undefined}; export type WebSource = {identifier?: 'web' | undefined, params: WebSourceParams}; export type MCPFilterParams = {query?: string | undefined, n_articles?: number | undefined, start_timestamp?: (number | null) | undefined, end_timestamp?: (number | null) | undefined, time_filter?: ('crawl_date' | 'pub_date') | undefined, offset?: (number | string) | undefined, categories?: (Array<'All' | 'Business' | 'Crime' | 'Politics' | 'Science' | 'Sports' | 'Technology' | 'Military' | 'Health' | 'Entertainment' | 'Finance' | 'Culture' | 'Climate' | 'Environment' | 'World'>) | undefined, provocative?: ('unknown' | 'low' | 'medium' | 'high' | 'all') | undefined, authors?: (Array | null) | undefined, reporting_voice?: (Array<'Objective' | 'Subjective' | 'Investigative' | 'Narrative' | 'Analytical' | 'Advocacy' | 'Conversational' | 'Satirical' | 'Emotive' | 'Explanatory' | 'Persuasive' | 'Sensational' | 'Unknown' | 'all'> | 'Objective' | 'Subjective' | 'Investigative' | 'Narrative' | 'Analytical' | 'Advocacy' | 'Conversational' | 'Satirical' | 'Emotive' | 'Explanatory' | 'Persuasive' | 'Sensational' | 'Unknown' | 'all') | undefined, domain_url?: (Array | string | null) | undefined, bad_domain_url?: (Array | string | null) | undefined, page_rank?: (number | null) | undefined, hours_back?: number | undefined, string_guarantee?: (Array | null) | undefined, string_guarantee_op?: ('AND' | 'OR') | undefined, reverse_string_guarantee?: (Array | null) | undefined, entity_guarantee?: (Array | null) | undefined, reverse_entity_guarantee?: (Array | null) | undefined, entity_guarantee_op?: ('AND' | 'OR') | undefined, languages?: (Array<'sq' | 'ar' | 'az' | 'ca' | 'zh' | 'hr' | 'cs' | 'da' | 'nl' | 'en' | 'eo' | 'fi' | 'fr' | 'gl' | 'de' | 'el' | 'he' | 'hi' | 'hu' | 'is' | 'id' | 'ia' | 'it' | 'ja' | 'kk' | 'km' | 'ko' | 'ky' | 'ms' | 'mt' | 'mhr' | 'mn' | 'no' | 'or' | 'pl' | 'pt' | 'pa' | 'ro' | 'ru' | 'sr' | 'sk' | 'sl' | 'es' | 'sv' | 'ta' | 'te' | 'th' | 'tr' | 'uk' | 'vi' | 'unknown'> | null) | undefined, countries?: (Array | null) | undefined, countries_blacklist?: (Array | null) | undefined, continents?: (Array<'Africa' | 'Asia' | 'Oceania' | 'Europe' | 'Middle East' | 'North America' | 'South America'> | null) | undefined, sentiment?: ('negative' | 'neutral' | 'positive' | 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 DeepNewsSourceParams = {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, filter_params?: (MCPFilterParams | null) | undefined, include_entities?: boolean | undefined, include_graphs?: boolean | undefined, include_coordinates?: boolean | undefined, engine?: ('v1' | 'v1.5') | undefined, max_parallel_tool_calls?: number | undefined, enable_source_pruning?: boolean | undefined, cutoff_datetime?: (string | null) | undefined, model?: (DeepNewsModel | null) | undefined, search_depth?: number | undefined, max_depth?: number | undefined}; export type DeepNewsSource = {identifier?: 'deepnews' | undefined, params?: DeepNewsSourceParams | undefined}; export type Sources = Array; export type WebhookParams = {url: string, headers?: ({[key: string]: string} | null) | undefined, payload?: ({[key: string]: unknown} | null) | undefined}; export type WebhookAction = {action?: 'webhook' | undefined, params: WebhookParams}; export type EmailParams = {to: string, subject?: (string | null) | undefined, asknews_watermark?: boolean | undefined}; export type EmailAction = {action?: 'email' | undefined, params: EmailParams}; export type ResendBroadcastParams = {sender: string, reply_to?: (string | Array | null) | undefined, subject?: (string | null) | undefined, audience_id: string, resend_api_key: string, asknews_watermark?: boolean | undefined}; export type ResendBroadcastAction = {action?: 'resend_broadcast' | undefined, params: ResendBroadcastParams}; export type GoogleDocsParams = {client_json: {[key: string]: unknown}, emails?: (Array | null) | undefined, asknews_watermark?: boolean | undefined}; export type GoogleDocsAction = {action?: 'google_docs' | undefined, params: GoogleDocsParams}; export type Triggers = Array; export type LegacyReportRequest = {logo_url?: (string | null) | undefined, include_appendix?: (boolean | null) | undefined, asknews_watermark?: boolean | undefined, identifier?: 'legacy' | undefined, model?: ('gpt-5' | 'gpt-4o' | 'gpt-4.1-2025-04-14' | 'gpt-4.1-mini-2025-04-14' | 'gpt-4o-mini' | 'o3-mini' | 'claude-3-5-sonnet-latest' | 'claude-sonnet-4-20250514' | 'claude-sonnet-4-5-20250929' | 'claude-opus-4-5-20251101' | 'claude-opus-4-6' | 'claude-fable-5' | 'claude-fable-5-1' | 'claude-sonnet-4-6' | 'claude-sonnet-5' | 'claude-opus-4-8' | 'claude-opus-5' | 'gpt-5.6-terra' | 'gpt-5.6-sol' | 'gpt-6-astra' | 'meta-llama/Meta-Llama-3.1-405B-Instruct' | 'meta-llama/Meta-Llama-3.3-70B-Instruct') | undefined}; export type DeepNewsReportParams = {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, filter_params?: (MCPFilterParams | null) | undefined, include_entities?: boolean | undefined, include_graphs?: boolean | undefined, include_coordinates?: boolean | undefined, engine?: ('v1' | 'v1.5') | undefined, max_parallel_tool_calls?: number | undefined, enable_source_pruning?: boolean | undefined, cutoff_datetime?: (string | null) | undefined, model?: (DeepNewsModel | null) | undefined, search_depth?: number | undefined, max_depth?: number | undefined, start_citation_number?: number | undefined, journalist_mode?: boolean | undefined}; export type DeepNewsReportRequest = {logo_url?: (string | null) | undefined, include_appendix?: (boolean | null) | undefined, asknews_watermark?: boolean | undefined, identifier?: 'deepnews' | undefined, params?: DeepNewsReportParams | undefined, prompt: string}; export type CreateAlertRequest = {query?: (string | null) | undefined, sources?: (Sources | null) | undefined, alert_type?: ('AlwaysAlertWhen' | 'AlertOnceIf' | 'ReportAbout' | null) | undefined, model?: ('meta-llama/Meta-Llama-3.1-8B-Instruct' | 'gpt-4o-mini' | 'gpt-5-mini' | 'gpt-5-nano' | 'gpt-4o' | 'o3-mini' | 'meta-llama/Meta-Llama-3.3-70B-Instruct' | 'gpt-4.1-2025-04-14' | 'gpt-4.1-nano-2025-04-14' | 'gpt-4.1-mini-2025-04-14' | 'claude-sonnet-5') | undefined, cron: string, triggers: Triggers, always_trigger?: boolean | undefined, repeat?: boolean | undefined, active?: boolean | undefined, expires_at?: (string | null) | undefined, report?: (LegacyReportRequest | DeepNewsReportRequest | Array | null) | undefined, title?: (string | null) | undefined, share_link?: (string | null) | undefined}; export type CreateApiV1ChatAlertsArgs = {body: CreateAlertRequest}; export type CreateApiV1ChatAlertsOptions = {baseUrl?: string | undefined, APIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const alertResponse = z.object({id: z.string(), created_at: z.string().nullable().optional(), updated_at: z.string().nullable().optional(), expires_at: z.string().nullable().optional(), user_id: z.string(), query: z.string().nullable().optional(), cron: z.string(), model: z.string().nullable(), share_link: z.string().nullable().optional(), sources: z.array(z.record(z.string(), z.unknown())).nullable().optional(), report: z.union([z.record(z.string(), z.unknown()), z.array(z.record(z.string(), z.unknown()))]).nullable().optional(), triggers: z.array(z.record(z.string(), z.unknown())), always_trigger: z.boolean().optional(), repeat: z.boolean().optional(), active: z.boolean().optional(), alert_type: z.enum(["AlwaysAlertWhen", "AlertOnceIf", "ReportAbout"]).nullable().optional(), title: z.string().nullable().optional(), seat_id: z.string().nullable().optional(), api_key_id: z.string().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 }; /** * Create an alert * * POST /v1/chat/alerts */ export const createApiV1ChatAlerts = async (args: CreateApiV1ChatAlertsArgs, options?: CreateApiV1ChatAlertsOptions) => { 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/alerts${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(alertResponse, await res.json()) };