{"version":3,"file":"live_search.cjs","names":[],"sources":["../../src/tools/live_search.ts"],"sourcesContent":["import type { XAISearchParameters, XAISearchSource } from \"../live_search.js\";\n\n/**\n * xAI's deprecated live_search tool type.\n */\nexport const XAI_LIVE_SEARCH_TOOL_TYPE = \"live_search_deprecated_20251215\";\nexport const XAI_LIVE_SEARCH_TOOL_NAME = \"live_search\";\n\n/**\n * xAI's built-in live_search tool type.\n * Enables the model to search the web for real-time information.\n */\nexport interface XAILiveSearchTool extends XAISearchParameters {\n  /**\n   * The name of the tool. Must be \"live_search\" for xAI's built-in search.\n   */\n  name: typeof XAI_LIVE_SEARCH_TOOL_NAME;\n  /**\n   * The type of the tool. This uses a deprecated Live Search API shape:\n   * the advanced agentic search capabilities powering grok.com are generally\n   * available in the new agentic tool calling API, and the Live Search API\n   * will be deprecated by December 15, 2025.\n   */\n  type: typeof XAI_LIVE_SEARCH_TOOL_TYPE;\n}\n\n/**\n * Web search source configuration for the xAI live search tool (camelCase).\n * This is converted to the snake_case `XAIWebSource` internally.\n */\nexport interface XAIWebSearchToolSource {\n  type: \"web\";\n  country?: string;\n  excludedWebsites?: string[];\n  allowedWebsites?: string[];\n  safeSearch?: boolean;\n}\n\n/**\n * News search source configuration for the xAI live search tool (camelCase).\n * This is converted to the snake_case `XAINewsSource` internally.\n */\nexport interface XAINewsSearchToolSource {\n  type: \"news\";\n  country?: string;\n  excludedWebsites?: string[];\n  safeSearch?: boolean;\n}\n\n/**\n * X (formerly Twitter) search source configuration for the xAI live search tool (camelCase).\n * This is converted to the snake_case `XAIXSource` internally.\n */\nexport interface XAIXSearchToolSource {\n  type: \"x\";\n  includedXHandles?: string[];\n  excludedXHandles?: string[];\n  postFavoriteCount?: number;\n  postViewCount?: number;\n}\n\n/**\n * RSS feed search source configuration for the xAI live search tool.\n * The structure matches `XAIRssSource` (only `links`).\n */\nexport interface XAIRssSearchToolSource {\n  type: \"rss\";\n  links: string[];\n}\n\nexport type XAISearchToolSource =\n  | XAIWebSearchToolSource\n  | XAINewsSearchToolSource\n  | XAIXSearchToolSource\n  | XAIRssSearchToolSource;\n\n/**\n * Options for the xAI live search tool (camelCase).\n * All fields are camel-cased for the TypeScript API and are mapped to the\n * corresponding snake_case fields in the underlying `XAISearchParameters`\n * object that is sent to xAI's deprecated Live Search API.\n */\nexport interface XAILiveSearchToolOptions {\n  /**\n   * Controls when the model should perform a search.\n   * - \"auto\": Let the model decide when to search (default)\n   * - \"on\": Always search for every request\n   * - \"off\": Never search\n   */\n  mode?: \"auto\" | \"on\" | \"off\";\n  /**\n   * Maximum number of search results to return.\n   * @default 20\n   */\n  maxSearchResults?: number;\n  /**\n   * Filter search results to only include content from after this date.\n   * Format: ISO 8601 date string (e.g., \"2024-01-01\")\n   */\n  fromDate?: string;\n  /**\n   * Filter search results to only include content from before this date.\n   * Format: ISO 8601 date string (e.g., \"2024-12-31\")\n   */\n  toDate?: string;\n  /**\n   * Whether to return citations/sources for the search results.\n   * @default true\n   */\n  returnCitations?: boolean;\n  /**\n   * Specific web/news/X/RSS sources that can be used for the search.\n   * These are converted to the snake_case `XAISearchSource` structures\n   * used by the underlying xAI Live Search API.\n   */\n  sources?: XAISearchToolSource[];\n}\n\nfunction mapToolSourceToSearchSource(\n  source: XAISearchToolSource\n): XAISearchSource {\n  switch (source.type) {\n    case \"web\":\n      return {\n        type: \"web\",\n        ...(source.country !== undefined && { country: source.country }),\n        ...(source.allowedWebsites !== undefined && {\n          allowed_websites: source.allowedWebsites,\n        }),\n        ...(source.excludedWebsites !== undefined && {\n          excluded_websites: source.excludedWebsites,\n        }),\n        ...(source.safeSearch !== undefined && {\n          safe_search: source.safeSearch,\n        }),\n      };\n    case \"news\":\n      return {\n        type: \"news\",\n        ...(source.country !== undefined && { country: source.country }),\n        ...(source.excludedWebsites !== undefined && {\n          excluded_websites: source.excludedWebsites,\n        }),\n        ...(source.safeSearch !== undefined && {\n          safe_search: source.safeSearch,\n        }),\n      };\n    case \"x\":\n      return {\n        type: \"x\",\n        ...(source.includedXHandles !== undefined && {\n          included_x_handles: source.includedXHandles,\n        }),\n        ...(source.excludedXHandles !== undefined && {\n          excluded_x_handles: source.excludedXHandles,\n        }),\n        ...(source.postFavoriteCount !== undefined && {\n          post_favorite_count: source.postFavoriteCount,\n        }),\n        ...(source.postViewCount !== undefined && {\n          post_view_count: source.postViewCount,\n        }),\n      };\n    case \"rss\":\n      return {\n        type: \"rss\",\n        links: source.links,\n      };\n    default: {\n      const _exhaustive: never = source;\n      return _exhaustive;\n    }\n  }\n}\n\n/**\n * Creates an xAI built-in live search tool.\n * Enables the model to search the web for real-time information.\n *\n * This tool is executed server-side by the xAI API.\n *\n * @deprecated The Live Search API was deprecated by xAI on December 15, 2025.\n * Use the new agentic tool calling API instead with `xaiWebSearch()` and `xaiXSearch()`.\n *\n * @example Migration to new tools:\n * ```typescript\n * // Old (deprecated):\n * const searchTool = tools.xaiLiveSearch({ maxSearchResults: 5 });\n *\n * // New (recommended):\n * const webSearch = tools.xaiWebSearch({ allowedDomains: [\"example.com\"] });\n * const xSearch = tools.xaiXSearch({ allowedXHandles: [\"elonmusk\"] });\n * ```\n *\n * @example\n * ```typescript\n * import { ChatXAI, tools } from \"@langchain/xai\";\n *\n * const llm = new ChatXAI({\n *   model: \"grok-3-fast\",\n * });\n *\n * const searchTool = tools.xaiLiveSearch({\n *   maxSearchResults: 5,\n *   fromDate: \"2024-01-01\",\n *   returnCitations: true\n * });\n *\n * const llmWithSearch = llm.bindTools([searchTool]);\n * const result = await llmWithSearch.invoke(\"What happened in tech today?\");\n * ```\n */\nexport function xaiLiveSearch(\n  options: XAILiveSearchToolOptions = {}\n): XAILiveSearchTool {\n  return {\n    type: XAI_LIVE_SEARCH_TOOL_TYPE,\n    name: XAI_LIVE_SEARCH_TOOL_NAME,\n    mode: options?.mode,\n    max_search_results: options?.maxSearchResults,\n    from_date: options?.fromDate,\n    to_date: options?.toDate,\n    return_citations: options?.returnCitations,\n    sources: options?.sources?.map(mapToolSourceToSearchSource),\n  } sat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