@langchain/xai 1.3.9 → 1.3.10-dev-1773698445534
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chat_models/completions.cjs +5 -6
- package/dist/chat_models/completions.cjs.map +1 -1
- package/dist/chat_models/completions.js +2 -3
- package/dist/chat_models/completions.js.map +1 -1
- package/dist/chat_models/index.cjs +2 -2
- package/dist/chat_models/index.js +3 -4
- package/dist/chat_models/responses.cjs +3 -4
- package/dist/chat_models/responses.cjs.map +1 -1
- package/dist/chat_models/responses.js +2 -3
- package/dist/chat_models/responses.js.map +1 -1
- package/dist/converters/responses.cjs +1 -2
- package/dist/converters/responses.cjs.map +1 -1
- package/dist/converters/responses.js +1 -2
- package/dist/converters/responses.js.map +1 -1
- package/dist/index.cjs +6 -7
- package/dist/index.d.ts +0 -1
- package/dist/index.js +1 -2
- package/dist/live_search.cjs +1 -2
- package/dist/live_search.cjs.map +1 -1
- package/dist/live_search.js +1 -1
- package/dist/live_search.js.map +1 -1
- package/dist/profiles.cjs +1 -2
- package/dist/profiles.cjs.map +1 -1
- package/dist/profiles.js +1 -1
- package/dist/tools/code_execution.cjs +1 -2
- package/dist/tools/code_execution.cjs.map +1 -1
- package/dist/tools/code_execution.js +1 -1
- package/dist/tools/collections_search.cjs +1 -2
- package/dist/tools/collections_search.cjs.map +1 -1
- package/dist/tools/collections_search.js +1 -1
- package/dist/tools/collections_search.js.map +1 -1
- package/dist/tools/index.cjs +6 -7
- package/dist/tools/index.cjs.map +1 -1
- package/dist/tools/index.js +6 -7
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/live_search.cjs +1 -2
- package/dist/tools/live_search.cjs.map +1 -1
- package/dist/tools/live_search.js +1 -1
- package/dist/tools/live_search.js.map +1 -1
- package/dist/tools/web_search.cjs +1 -2
- package/dist/tools/web_search.cjs.map +1 -1
- package/dist/tools/web_search.js +1 -1
- package/dist/tools/web_search.js.map +1 -1
- package/dist/tools/x_search.cjs +1 -2
- package/dist/tools/x_search.cjs.map +1 -1
- package/dist/tools/x_search.js +1 -1
- package/dist/tools/x_search.js.map +1 -1
- package/package.json +6 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"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 } satisfies XAILiveSearchTool;\n}\n"],"mappings":"
|
|
1
|
+
{"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 } satisfies XAILiveSearchTool;\n}\n"],"mappings":";;;;AAKA,MAAa,4BAA4B;AACzC,MAAa,4BAA4B;AAgHzC,SAAS,4BACP,QACiB;AACjB,SAAQ,OAAO,MAAf;EACE,KAAK,MACH,QAAO;GACL,MAAM;GACN,GAAI,OAAO,YAAY,KAAA,KAAa,EAAE,SAAS,OAAO,SAAS;GAC/D,GAAI,OAAO,oBAAoB,KAAA,KAAa,EAC1C,kBAAkB,OAAO,iBAC1B;GACD,GAAI,OAAO,qBAAqB,KAAA,KAAa,EAC3C,mBAAmB,OAAO,kBAC3B;GACD,GAAI,OAAO,eAAe,KAAA,KAAa,EACrC,aAAa,OAAO,YACrB;GACF;EACH,KAAK,OACH,QAAO;GACL,MAAM;GACN,GAAI,OAAO,YAAY,KAAA,KAAa,EAAE,SAAS,OAAO,SAAS;GAC/D,GAAI,OAAO,qBAAqB,KAAA,KAAa,EAC3C,mBAAmB,OAAO,kBAC3B;GACD,GAAI,OAAO,eAAe,KAAA,KAAa,EACrC,aAAa,OAAO,YACrB;GACF;EACH,KAAK,IACH,QAAO;GACL,MAAM;GACN,GAAI,OAAO,qBAAqB,KAAA,KAAa,EAC3C,oBAAoB,OAAO,kBAC5B;GACD,GAAI,OAAO,qBAAqB,KAAA,KAAa,EAC3C,oBAAoB,OAAO,kBAC5B;GACD,GAAI,OAAO,sBAAsB,KAAA,KAAa,EAC5C,qBAAqB,OAAO,mBAC7B;GACD,GAAI,OAAO,kBAAkB,KAAA,KAAa,EACxC,iBAAiB,OAAO,eACzB;GACF;EACH,KAAK,MACH,QAAO;GACL,MAAM;GACN,OAAO,OAAO;GACf;EACH,QAEE,QAD2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CjC,SAAgB,cACd,UAAoC,EAAE,EACnB;AACnB,QAAO;EACL,MAAM;EACN,MAAM;EACN,MAAM,SAAS;EACf,oBAAoB,SAAS;EAC7B,WAAW,SAAS;EACpB,SAAS,SAAS;EAClB,kBAAkB,SAAS;EAC3B,SAAS,SAAS,SAAS,IAAI,4BAA4B;EAC5D"}
|
|
@@ -82,7 +82,7 @@ function xaiLiveSearch(options = {}) {
|
|
|
82
82
|
sources: options?.sources?.map(mapToolSourceToSearchSource)
|
|
83
83
|
};
|
|
84
84
|
}
|
|
85
|
-
|
|
86
85
|
//#endregion
|
|
87
86
|
export { XAI_LIVE_SEARCH_TOOL_NAME, XAI_LIVE_SEARCH_TOOL_TYPE, xaiLiveSearch };
|
|
87
|
+
|
|
88
88
|
//# sourceMappingURL=live_search.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"live_search.js","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 } satisfies XAILiveSearchTool;\n}\n"],"mappings":";;;;AAKA,MAAa,4BAA4B;AACzC,MAAa,4BAA4B;AAgHzC,SAAS,4BACP,QACiB;AACjB,SAAQ,OAAO,MAAf;EACE,KAAK,MACH,QAAO;GACL,MAAM;GACN,GAAI,OAAO,YAAY,
|
|
1
|
+
{"version":3,"file":"live_search.js","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 } satisfies XAILiveSearchTool;\n}\n"],"mappings":";;;;AAKA,MAAa,4BAA4B;AACzC,MAAa,4BAA4B;AAgHzC,SAAS,4BACP,QACiB;AACjB,SAAQ,OAAO,MAAf;EACE,KAAK,MACH,QAAO;GACL,MAAM;GACN,GAAI,OAAO,YAAY,KAAA,KAAa,EAAE,SAAS,OAAO,SAAS;GAC/D,GAAI,OAAO,oBAAoB,KAAA,KAAa,EAC1C,kBAAkB,OAAO,iBAC1B;GACD,GAAI,OAAO,qBAAqB,KAAA,KAAa,EAC3C,mBAAmB,OAAO,kBAC3B;GACD,GAAI,OAAO,eAAe,KAAA,KAAa,EACrC,aAAa,OAAO,YACrB;GACF;EACH,KAAK,OACH,QAAO;GACL,MAAM;GACN,GAAI,OAAO,YAAY,KAAA,KAAa,EAAE,SAAS,OAAO,SAAS;GAC/D,GAAI,OAAO,qBAAqB,KAAA,KAAa,EAC3C,mBAAmB,OAAO,kBAC3B;GACD,GAAI,OAAO,eAAe,KAAA,KAAa,EACrC,aAAa,OAAO,YACrB;GACF;EACH,KAAK,IACH,QAAO;GACL,MAAM;GACN,GAAI,OAAO,qBAAqB,KAAA,KAAa,EAC3C,oBAAoB,OAAO,kBAC5B;GACD,GAAI,OAAO,qBAAqB,KAAA,KAAa,EAC3C,oBAAoB,OAAO,kBAC5B;GACD,GAAI,OAAO,sBAAsB,KAAA,KAAa,EAC5C,qBAAqB,OAAO,mBAC7B;GACD,GAAI,OAAO,kBAAkB,KAAA,KAAa,EACxC,iBAAiB,OAAO,eACzB;GACF;EACH,KAAK,MACH,QAAO;GACL,MAAM;GACN,OAAO,OAAO;GACf;EACH,QAEE,QAD2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CjC,SAAgB,cACd,UAAoC,EAAE,EACnB;AACnB,QAAO;EACL,MAAM;EACN,MAAM;EACN,MAAM,SAAS;EACf,oBAAoB,SAAS;EAC7B,WAAW,SAAS;EACpB,SAAS,SAAS;EAClB,kBAAkB,SAAS;EAC3B,SAAS,SAAS,SAAS,IAAI,4BAA4B;EAC5D"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
//#region src/tools/web_search.ts
|
|
3
2
|
/**
|
|
4
3
|
* xAI Web Search tool type constant.
|
|
@@ -50,8 +49,8 @@ function xaiWebSearch(options = {}) {
|
|
|
50
49
|
if (options.enableImageUnderstanding !== void 0) tool.enable_image_understanding = options.enableImageUnderstanding;
|
|
51
50
|
return tool;
|
|
52
51
|
}
|
|
53
|
-
|
|
54
52
|
//#endregion
|
|
55
53
|
exports.XAI_WEB_SEARCH_TOOL_TYPE = XAI_WEB_SEARCH_TOOL_TYPE;
|
|
56
54
|
exports.xaiWebSearch = xaiWebSearch;
|
|
55
|
+
|
|
57
56
|
//# sourceMappingURL=web_search.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web_search.cjs","names":[],"sources":["../../src/tools/web_search.ts"],"sourcesContent":["/**\n * xAI Web Search tool type constant.\n */\nexport const XAI_WEB_SEARCH_TOOL_TYPE = \"web_search\";\n\n/**\n * xAI's built-in web search tool interface.\n * Enables the model to search the web and browse pages for real-time information.\n *\n * This tool is part of xAI's agentic tool calling API.\n */\nexport interface XAIWebSearchTool {\n /**\n * The type of the tool. Must be \"web_search\".\n */\n type: typeof XAI_WEB_SEARCH_TOOL_TYPE;\n /**\n * Domains to exclusively include in the search (max 5).\n * Cannot be used together with `excluded_domains`.\n */\n allowed_domains?: string[];\n /**\n * Domains to exclude from the search (max 5).\n * Cannot be used together with `allowed_domains`.\n */\n excluded_domains?: string[];\n /**\n * Whether to enable image understanding.\n * When enabled, the model can analyze images encountered during search.\n */\n enable_image_understanding?: boolean;\n}\n\n/**\n * Options for the xAI web 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 API request.\n */\nexport interface XAIWebSearchToolOptions {\n /**\n * Domains to exclusively include in the search (max 5).\n * Cannot be used together with `excludedDomains`.\n *\n * @example [\"wikipedia.org\", \"github.com\"]\n */\n allowedDomains?: string[];\n /**\n * Domains to exclude from the search (max 5).\n * Cannot be used together with `allowedDomains`.\n *\n * @example [\"example.com\"]\n */\n excludedDomains?: string[];\n /**\n * Whether to enable image understanding.\n * When enabled, the model can analyze images encountered during search.\n * Note: This increases token usage as images are processed.\n *\n * @default false\n */\n enableImageUnderstanding?: boolean;\n}\n\n/**\n * Creates an xAI web search tool.\n * Enables the model to search the web and browse pages for real-time information.\n *\n * This tool is executed server-side by the xAI API as part of the agentic\n * tool calling workflow.\n *\n * @param options - Configuration options for the web search tool\n * @returns An XAIWebSearchTool object to pass to the model\n *\n * @example Basic usage\n * ```typescript\n * import { ChatXAIResponses, tools } from \"@langchain/xai\";\n *\n * const llm = new ChatXAIResponses({\n * model: \"grok-4-1-fast\",\n * });\n *\n * const webSearch = tools.xaiWebSearch();\n * const result = await llm.invoke(\"What are the latest AI developments?\", {\n * tools: [webSearch],\n * });\n * ```\n *\n * @example With domain filtering\n * ```typescript\n * const webSearch = tools.xaiWebSearch({\n * allowedDomains: [\"wikipedia.org\", \"arxiv.org\"],\n * enableImageUnderstanding: true,\n * });\n * ```\n *\n * @example Excluding specific domains\n * ```typescript\n * const webSearch = tools.xaiWebSearch({\n * excludedDomains: [\"example.com\"],\n * });\n * ```\n */\nexport function xaiWebSearch(\n options: XAIWebSearchToolOptions = {}\n): XAIWebSearchTool {\n const tool: XAIWebSearchTool = {\n type: XAI_WEB_SEARCH_TOOL_TYPE,\n };\n\n if (options.allowedDomains !== undefined) {\n tool.allowed_domains = options.allowedDomains;\n }\n\n if (options.excludedDomains !== undefined) {\n tool.excluded_domains = options.excludedDomains;\n }\n\n if (options.enableImageUnderstanding !== undefined) {\n tool.enable_image_understanding = options.enableImageUnderstanding;\n }\n\n return tool;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"web_search.cjs","names":[],"sources":["../../src/tools/web_search.ts"],"sourcesContent":["/**\n * xAI Web Search tool type constant.\n */\nexport const XAI_WEB_SEARCH_TOOL_TYPE = \"web_search\";\n\n/**\n * xAI's built-in web search tool interface.\n * Enables the model to search the web and browse pages for real-time information.\n *\n * This tool is part of xAI's agentic tool calling API.\n */\nexport interface XAIWebSearchTool {\n /**\n * The type of the tool. Must be \"web_search\".\n */\n type: typeof XAI_WEB_SEARCH_TOOL_TYPE;\n /**\n * Domains to exclusively include in the search (max 5).\n * Cannot be used together with `excluded_domains`.\n */\n allowed_domains?: string[];\n /**\n * Domains to exclude from the search (max 5).\n * Cannot be used together with `allowed_domains`.\n */\n excluded_domains?: string[];\n /**\n * Whether to enable image understanding.\n * When enabled, the model can analyze images encountered during search.\n */\n enable_image_understanding?: boolean;\n}\n\n/**\n * Options for the xAI web 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 API request.\n */\nexport interface XAIWebSearchToolOptions {\n /**\n * Domains to exclusively include in the search (max 5).\n * Cannot be used together with `excludedDomains`.\n *\n * @example [\"wikipedia.org\", \"github.com\"]\n */\n allowedDomains?: string[];\n /**\n * Domains to exclude from the search (max 5).\n * Cannot be used together with `allowedDomains`.\n *\n * @example [\"example.com\"]\n */\n excludedDomains?: string[];\n /**\n * Whether to enable image understanding.\n * When enabled, the model can analyze images encountered during search.\n * Note: This increases token usage as images are processed.\n *\n * @default false\n */\n enableImageUnderstanding?: boolean;\n}\n\n/**\n * Creates an xAI web search tool.\n * Enables the model to search the web and browse pages for real-time information.\n *\n * This tool is executed server-side by the xAI API as part of the agentic\n * tool calling workflow.\n *\n * @param options - Configuration options for the web search tool\n * @returns An XAIWebSearchTool object to pass to the model\n *\n * @example Basic usage\n * ```typescript\n * import { ChatXAIResponses, tools } from \"@langchain/xai\";\n *\n * const llm = new ChatXAIResponses({\n * model: \"grok-4-1-fast\",\n * });\n *\n * const webSearch = tools.xaiWebSearch();\n * const result = await llm.invoke(\"What are the latest AI developments?\", {\n * tools: [webSearch],\n * });\n * ```\n *\n * @example With domain filtering\n * ```typescript\n * const webSearch = tools.xaiWebSearch({\n * allowedDomains: [\"wikipedia.org\", \"arxiv.org\"],\n * enableImageUnderstanding: true,\n * });\n * ```\n *\n * @example Excluding specific domains\n * ```typescript\n * const webSearch = tools.xaiWebSearch({\n * excludedDomains: [\"example.com\"],\n * });\n * ```\n */\nexport function xaiWebSearch(\n options: XAIWebSearchToolOptions = {}\n): XAIWebSearchTool {\n const tool: XAIWebSearchTool = {\n type: XAI_WEB_SEARCH_TOOL_TYPE,\n };\n\n if (options.allowedDomains !== undefined) {\n tool.allowed_domains = options.allowedDomains;\n }\n\n if (options.excludedDomains !== undefined) {\n tool.excluded_domains = options.excludedDomains;\n }\n\n if (options.enableImageUnderstanding !== undefined) {\n tool.enable_image_understanding = options.enableImageUnderstanding;\n }\n\n return tool;\n}\n"],"mappings":";;;;AAGA,MAAa,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmGxC,SAAgB,aACd,UAAmC,EAAE,EACnB;CAClB,MAAM,OAAyB,EAC7B,MAAM,0BACP;AAED,KAAI,QAAQ,mBAAmB,KAAA,EAC7B,MAAK,kBAAkB,QAAQ;AAGjC,KAAI,QAAQ,oBAAoB,KAAA,EAC9B,MAAK,mBAAmB,QAAQ;AAGlC,KAAI,QAAQ,6BAA6B,KAAA,EACvC,MAAK,6BAA6B,QAAQ;AAG5C,QAAO"}
|
package/dist/tools/web_search.js
CHANGED
|
@@ -49,7 +49,7 @@ function xaiWebSearch(options = {}) {
|
|
|
49
49
|
if (options.enableImageUnderstanding !== void 0) tool.enable_image_understanding = options.enableImageUnderstanding;
|
|
50
50
|
return tool;
|
|
51
51
|
}
|
|
52
|
-
|
|
53
52
|
//#endregion
|
|
54
53
|
export { XAI_WEB_SEARCH_TOOL_TYPE, xaiWebSearch };
|
|
54
|
+
|
|
55
55
|
//# sourceMappingURL=web_search.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web_search.js","names":[],"sources":["../../src/tools/web_search.ts"],"sourcesContent":["/**\n * xAI Web Search tool type constant.\n */\nexport const XAI_WEB_SEARCH_TOOL_TYPE = \"web_search\";\n\n/**\n * xAI's built-in web search tool interface.\n * Enables the model to search the web and browse pages for real-time information.\n *\n * This tool is part of xAI's agentic tool calling API.\n */\nexport interface XAIWebSearchTool {\n /**\n * The type of the tool. Must be \"web_search\".\n */\n type: typeof XAI_WEB_SEARCH_TOOL_TYPE;\n /**\n * Domains to exclusively include in the search (max 5).\n * Cannot be used together with `excluded_domains`.\n */\n allowed_domains?: string[];\n /**\n * Domains to exclude from the search (max 5).\n * Cannot be used together with `allowed_domains`.\n */\n excluded_domains?: string[];\n /**\n * Whether to enable image understanding.\n * When enabled, the model can analyze images encountered during search.\n */\n enable_image_understanding?: boolean;\n}\n\n/**\n * Options for the xAI web 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 API request.\n */\nexport interface XAIWebSearchToolOptions {\n /**\n * Domains to exclusively include in the search (max 5).\n * Cannot be used together with `excludedDomains`.\n *\n * @example [\"wikipedia.org\", \"github.com\"]\n */\n allowedDomains?: string[];\n /**\n * Domains to exclude from the search (max 5).\n * Cannot be used together with `allowedDomains`.\n *\n * @example [\"example.com\"]\n */\n excludedDomains?: string[];\n /**\n * Whether to enable image understanding.\n * When enabled, the model can analyze images encountered during search.\n * Note: This increases token usage as images are processed.\n *\n * @default false\n */\n enableImageUnderstanding?: boolean;\n}\n\n/**\n * Creates an xAI web search tool.\n * Enables the model to search the web and browse pages for real-time information.\n *\n * This tool is executed server-side by the xAI API as part of the agentic\n * tool calling workflow.\n *\n * @param options - Configuration options for the web search tool\n * @returns An XAIWebSearchTool object to pass to the model\n *\n * @example Basic usage\n * ```typescript\n * import { ChatXAIResponses, tools } from \"@langchain/xai\";\n *\n * const llm = new ChatXAIResponses({\n * model: \"grok-4-1-fast\",\n * });\n *\n * const webSearch = tools.xaiWebSearch();\n * const result = await llm.invoke(\"What are the latest AI developments?\", {\n * tools: [webSearch],\n * });\n * ```\n *\n * @example With domain filtering\n * ```typescript\n * const webSearch = tools.xaiWebSearch({\n * allowedDomains: [\"wikipedia.org\", \"arxiv.org\"],\n * enableImageUnderstanding: true,\n * });\n * ```\n *\n * @example Excluding specific domains\n * ```typescript\n * const webSearch = tools.xaiWebSearch({\n * excludedDomains: [\"example.com\"],\n * });\n * ```\n */\nexport function xaiWebSearch(\n options: XAIWebSearchToolOptions = {}\n): XAIWebSearchTool {\n const tool: XAIWebSearchTool = {\n type: XAI_WEB_SEARCH_TOOL_TYPE,\n };\n\n if (options.allowedDomains !== undefined) {\n tool.allowed_domains = options.allowedDomains;\n }\n\n if (options.excludedDomains !== undefined) {\n tool.excluded_domains = options.excludedDomains;\n }\n\n if (options.enableImageUnderstanding !== undefined) {\n tool.enable_image_understanding = options.enableImageUnderstanding;\n }\n\n return tool;\n}\n"],"mappings":";;;;AAGA,MAAa,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmGxC,SAAgB,aACd,UAAmC,EAAE,EACnB;CAClB,MAAM,OAAyB,EAC7B,MAAM,0BACP;AAED,KAAI,QAAQ,mBAAmB,
|
|
1
|
+
{"version":3,"file":"web_search.js","names":[],"sources":["../../src/tools/web_search.ts"],"sourcesContent":["/**\n * xAI Web Search tool type constant.\n */\nexport const XAI_WEB_SEARCH_TOOL_TYPE = \"web_search\";\n\n/**\n * xAI's built-in web search tool interface.\n * Enables the model to search the web and browse pages for real-time information.\n *\n * This tool is part of xAI's agentic tool calling API.\n */\nexport interface XAIWebSearchTool {\n /**\n * The type of the tool. Must be \"web_search\".\n */\n type: typeof XAI_WEB_SEARCH_TOOL_TYPE;\n /**\n * Domains to exclusively include in the search (max 5).\n * Cannot be used together with `excluded_domains`.\n */\n allowed_domains?: string[];\n /**\n * Domains to exclude from the search (max 5).\n * Cannot be used together with `allowed_domains`.\n */\n excluded_domains?: string[];\n /**\n * Whether to enable image understanding.\n * When enabled, the model can analyze images encountered during search.\n */\n enable_image_understanding?: boolean;\n}\n\n/**\n * Options for the xAI web 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 API request.\n */\nexport interface XAIWebSearchToolOptions {\n /**\n * Domains to exclusively include in the search (max 5).\n * Cannot be used together with `excludedDomains`.\n *\n * @example [\"wikipedia.org\", \"github.com\"]\n */\n allowedDomains?: string[];\n /**\n * Domains to exclude from the search (max 5).\n * Cannot be used together with `allowedDomains`.\n *\n * @example [\"example.com\"]\n */\n excludedDomains?: string[];\n /**\n * Whether to enable image understanding.\n * When enabled, the model can analyze images encountered during search.\n * Note: This increases token usage as images are processed.\n *\n * @default false\n */\n enableImageUnderstanding?: boolean;\n}\n\n/**\n * Creates an xAI web search tool.\n * Enables the model to search the web and browse pages for real-time information.\n *\n * This tool is executed server-side by the xAI API as part of the agentic\n * tool calling workflow.\n *\n * @param options - Configuration options for the web search tool\n * @returns An XAIWebSearchTool object to pass to the model\n *\n * @example Basic usage\n * ```typescript\n * import { ChatXAIResponses, tools } from \"@langchain/xai\";\n *\n * const llm = new ChatXAIResponses({\n * model: \"grok-4-1-fast\",\n * });\n *\n * const webSearch = tools.xaiWebSearch();\n * const result = await llm.invoke(\"What are the latest AI developments?\", {\n * tools: [webSearch],\n * });\n * ```\n *\n * @example With domain filtering\n * ```typescript\n * const webSearch = tools.xaiWebSearch({\n * allowedDomains: [\"wikipedia.org\", \"arxiv.org\"],\n * enableImageUnderstanding: true,\n * });\n * ```\n *\n * @example Excluding specific domains\n * ```typescript\n * const webSearch = tools.xaiWebSearch({\n * excludedDomains: [\"example.com\"],\n * });\n * ```\n */\nexport function xaiWebSearch(\n options: XAIWebSearchToolOptions = {}\n): XAIWebSearchTool {\n const tool: XAIWebSearchTool = {\n type: XAI_WEB_SEARCH_TOOL_TYPE,\n };\n\n if (options.allowedDomains !== undefined) {\n tool.allowed_domains = options.allowedDomains;\n }\n\n if (options.excludedDomains !== undefined) {\n tool.excluded_domains = options.excludedDomains;\n }\n\n if (options.enableImageUnderstanding !== undefined) {\n tool.enable_image_understanding = options.enableImageUnderstanding;\n }\n\n return tool;\n}\n"],"mappings":";;;;AAGA,MAAa,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmGxC,SAAgB,aACd,UAAmC,EAAE,EACnB;CAClB,MAAM,OAAyB,EAC7B,MAAM,0BACP;AAED,KAAI,QAAQ,mBAAmB,KAAA,EAC7B,MAAK,kBAAkB,QAAQ;AAGjC,KAAI,QAAQ,oBAAoB,KAAA,EAC9B,MAAK,mBAAmB,QAAQ;AAGlC,KAAI,QAAQ,6BAA6B,KAAA,EACvC,MAAK,6BAA6B,QAAQ;AAG5C,QAAO"}
|
package/dist/tools/x_search.cjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
//#region src/tools/x_search.ts
|
|
3
2
|
/**
|
|
4
3
|
* xAI X Search tool type constant.
|
|
@@ -56,8 +55,8 @@ function xaiXSearch(options = {}) {
|
|
|
56
55
|
if (options.enableVideoUnderstanding !== void 0) tool.enable_video_understanding = options.enableVideoUnderstanding;
|
|
57
56
|
return tool;
|
|
58
57
|
}
|
|
59
|
-
|
|
60
58
|
//#endregion
|
|
61
59
|
exports.XAI_X_SEARCH_TOOL_TYPE = XAI_X_SEARCH_TOOL_TYPE;
|
|
62
60
|
exports.xaiXSearch = xaiXSearch;
|
|
61
|
+
|
|
63
62
|
//# sourceMappingURL=x_search.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"x_search.cjs","names":[],"sources":["../../src/tools/x_search.ts"],"sourcesContent":["/**\n * xAI X Search tool type constant.\n */\nexport const XAI_X_SEARCH_TOOL_TYPE = \"x_search\";\n\n/**\n * xAI's built-in X (formerly Twitter) search tool interface.\n * Enables the model to perform keyword search, semantic search, user search,\n * and thread fetch on X.\n *\n * This tool is part of xAI's agentic tool calling API.\n */\nexport interface XAIXSearchTool {\n /**\n * The type of the tool. Must be \"x_search\".\n */\n type: typeof XAI_X_SEARCH_TOOL_TYPE;\n /**\n * X handles to exclusively include in the search (max 10).\n * Cannot be used together with `excluded_x_handles`.\n */\n allowed_x_handles?: string[];\n /**\n * X handles to exclude from the search (max 10).\n * Cannot be used together with `allowed_x_handles`.\n */\n excluded_x_handles?: string[];\n /**\n * Start date for search results (ISO-8601 format: \"YYYY-MM-DD\").\n * Only posts from this date onwards will be included.\n */\n from_date?: string;\n /**\n * End date for search results (ISO-8601 format: \"YYYY-MM-DD\").\n * Only posts up to this date will be included.\n */\n to_date?: string;\n /**\n * Whether to enable image understanding.\n * When enabled, the model can analyze images in X posts.\n */\n enable_image_understanding?: boolean;\n /**\n * Whether to enable video understanding.\n * When enabled, the model can analyze videos in X posts.\n */\n enable_video_understanding?: boolean;\n}\n\n/**\n * Options for the xAI X 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 API request.\n */\nexport interface XAIXSearchToolOptions {\n /**\n * X handles to exclusively include in the search (max 10).\n * Cannot be used together with `excludedXHandles`.\n *\n * @example [\"elonmusk\", \"xai\"]\n */\n allowedXHandles?: string[];\n /**\n * X handles to exclude from the search (max 10).\n * Cannot be used together with `allowedXHandles`.\n *\n * @example [\"spamaccount\"]\n */\n excludedXHandles?: string[];\n /**\n * Start date for search results (ISO-8601 format: \"YYYY-MM-DD\").\n * Only posts from this date onwards will be included.\n *\n * @example \"2024-01-01\"\n */\n fromDate?: string;\n /**\n * End date for search results (ISO-8601 format: \"YYYY-MM-DD\").\n * Only posts up to this date will be included.\n *\n * @example \"2024-12-31\"\n */\n toDate?: string;\n /**\n * Whether to enable image understanding.\n * When enabled, the model can analyze images in X posts.\n * Note: This increases token usage as images are processed.\n *\n * @default false\n */\n enableImageUnderstanding?: boolean;\n /**\n * Whether to enable video understanding.\n * When enabled, the model can analyze videos in X posts.\n * Note: This increases token usage as video content is processed.\n *\n * @default false\n */\n enableVideoUnderstanding?: boolean;\n}\n\n/**\n * Creates an xAI X search tool.\n * Enables the model to perform keyword search, semantic search, user search,\n * and thread fetch on X (formerly Twitter).\n *\n * This tool is executed server-side by the xAI API as part of the agentic\n * tool calling workflow.\n *\n * @param options - Configuration options for the X search tool\n * @returns An XAIXSearchTool object to pass to the model\n *\n * @example Basic usage\n * ```typescript\n * import { ChatXAIResponses, tools } from \"@langchain/xai\";\n *\n * const llm = new ChatXAIResponses({\n * model: \"grok-4-1-fast\",\n * });\n *\n * const xSearch = tools.xaiXSearch();\n * const result = await llm.invoke(\"What is the current status of xAI?\", {\n * tools: [xSearch],\n * });\n * ```\n *\n * @example With handle filtering\n * ```typescript\n * const xSearch = tools.xaiXSearch({\n * allowedXHandles: [\"elonmusk\", \"xai\"],\n * enableImageUnderstanding: true,\n * });\n * ```\n *\n * @example With date range\n * ```typescript\n * const xSearch = tools.xaiXSearch({\n * fromDate: \"2024-10-01\",\n * toDate: \"2024-10-31\",\n * enableVideoUnderstanding: true,\n * });\n * ```\n */\nexport function xaiXSearch(\n options: XAIXSearchToolOptions = {}\n): XAIXSearchTool {\n const tool: XAIXSearchTool = {\n type: XAI_X_SEARCH_TOOL_TYPE,\n };\n\n if (options.allowedXHandles !== undefined) {\n tool.allowed_x_handles = options.allowedXHandles;\n }\n\n if (options.excludedXHandles !== undefined) {\n tool.excluded_x_handles = options.excludedXHandles;\n }\n\n if (options.fromDate !== undefined) {\n tool.from_date = options.fromDate;\n }\n\n if (options.toDate !== undefined) {\n tool.to_date = options.toDate;\n }\n\n if (options.enableImageUnderstanding !== undefined) {\n tool.enable_image_understanding = options.enableImageUnderstanding;\n }\n\n if (options.enableVideoUnderstanding !== undefined) {\n tool.enable_video_understanding = options.enableVideoUnderstanding;\n }\n\n return tool;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"x_search.cjs","names":[],"sources":["../../src/tools/x_search.ts"],"sourcesContent":["/**\n * xAI X Search tool type constant.\n */\nexport const XAI_X_SEARCH_TOOL_TYPE = \"x_search\";\n\n/**\n * xAI's built-in X (formerly Twitter) search tool interface.\n * Enables the model to perform keyword search, semantic search, user search,\n * and thread fetch on X.\n *\n * This tool is part of xAI's agentic tool calling API.\n */\nexport interface XAIXSearchTool {\n /**\n * The type of the tool. Must be \"x_search\".\n */\n type: typeof XAI_X_SEARCH_TOOL_TYPE;\n /**\n * X handles to exclusively include in the search (max 10).\n * Cannot be used together with `excluded_x_handles`.\n */\n allowed_x_handles?: string[];\n /**\n * X handles to exclude from the search (max 10).\n * Cannot be used together with `allowed_x_handles`.\n */\n excluded_x_handles?: string[];\n /**\n * Start date for search results (ISO-8601 format: \"YYYY-MM-DD\").\n * Only posts from this date onwards will be included.\n */\n from_date?: string;\n /**\n * End date for search results (ISO-8601 format: \"YYYY-MM-DD\").\n * Only posts up to this date will be included.\n */\n to_date?: string;\n /**\n * Whether to enable image understanding.\n * When enabled, the model can analyze images in X posts.\n */\n enable_image_understanding?: boolean;\n /**\n * Whether to enable video understanding.\n * When enabled, the model can analyze videos in X posts.\n */\n enable_video_understanding?: boolean;\n}\n\n/**\n * Options for the xAI X 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 API request.\n */\nexport interface XAIXSearchToolOptions {\n /**\n * X handles to exclusively include in the search (max 10).\n * Cannot be used together with `excludedXHandles`.\n *\n * @example [\"elonmusk\", \"xai\"]\n */\n allowedXHandles?: string[];\n /**\n * X handles to exclude from the search (max 10).\n * Cannot be used together with `allowedXHandles`.\n *\n * @example [\"spamaccount\"]\n */\n excludedXHandles?: string[];\n /**\n * Start date for search results (ISO-8601 format: \"YYYY-MM-DD\").\n * Only posts from this date onwards will be included.\n *\n * @example \"2024-01-01\"\n */\n fromDate?: string;\n /**\n * End date for search results (ISO-8601 format: \"YYYY-MM-DD\").\n * Only posts up to this date will be included.\n *\n * @example \"2024-12-31\"\n */\n toDate?: string;\n /**\n * Whether to enable image understanding.\n * When enabled, the model can analyze images in X posts.\n * Note: This increases token usage as images are processed.\n *\n * @default false\n */\n enableImageUnderstanding?: boolean;\n /**\n * Whether to enable video understanding.\n * When enabled, the model can analyze videos in X posts.\n * Note: This increases token usage as video content is processed.\n *\n * @default false\n */\n enableVideoUnderstanding?: boolean;\n}\n\n/**\n * Creates an xAI X search tool.\n * Enables the model to perform keyword search, semantic search, user search,\n * and thread fetch on X (formerly Twitter).\n *\n * This tool is executed server-side by the xAI API as part of the agentic\n * tool calling workflow.\n *\n * @param options - Configuration options for the X search tool\n * @returns An XAIXSearchTool object to pass to the model\n *\n * @example Basic usage\n * ```typescript\n * import { ChatXAIResponses, tools } from \"@langchain/xai\";\n *\n * const llm = new ChatXAIResponses({\n * model: \"grok-4-1-fast\",\n * });\n *\n * const xSearch = tools.xaiXSearch();\n * const result = await llm.invoke(\"What is the current status of xAI?\", {\n * tools: [xSearch],\n * });\n * ```\n *\n * @example With handle filtering\n * ```typescript\n * const xSearch = tools.xaiXSearch({\n * allowedXHandles: [\"elonmusk\", \"xai\"],\n * enableImageUnderstanding: true,\n * });\n * ```\n *\n * @example With date range\n * ```typescript\n * const xSearch = tools.xaiXSearch({\n * fromDate: \"2024-10-01\",\n * toDate: \"2024-10-31\",\n * enableVideoUnderstanding: true,\n * });\n * ```\n */\nexport function xaiXSearch(\n options: XAIXSearchToolOptions = {}\n): XAIXSearchTool {\n const tool: XAIXSearchTool = {\n type: XAI_X_SEARCH_TOOL_TYPE,\n };\n\n if (options.allowedXHandles !== undefined) {\n tool.allowed_x_handles = options.allowedXHandles;\n }\n\n if (options.excludedXHandles !== undefined) {\n tool.excluded_x_handles = options.excludedXHandles;\n }\n\n if (options.fromDate !== undefined) {\n tool.from_date = options.fromDate;\n }\n\n if (options.toDate !== undefined) {\n tool.to_date = options.toDate;\n }\n\n if (options.enableImageUnderstanding !== undefined) {\n tool.enable_image_understanding = options.enableImageUnderstanding;\n }\n\n if (options.enableVideoUnderstanding !== undefined) {\n tool.enable_video_understanding = options.enableVideoUnderstanding;\n }\n\n return tool;\n}\n"],"mappings":";;;;AAGA,MAAa,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4ItC,SAAgB,WACd,UAAiC,EAAE,EACnB;CAChB,MAAM,OAAuB,EAC3B,MAAM,wBACP;AAED,KAAI,QAAQ,oBAAoB,KAAA,EAC9B,MAAK,oBAAoB,QAAQ;AAGnC,KAAI,QAAQ,qBAAqB,KAAA,EAC/B,MAAK,qBAAqB,QAAQ;AAGpC,KAAI,QAAQ,aAAa,KAAA,EACvB,MAAK,YAAY,QAAQ;AAG3B,KAAI,QAAQ,WAAW,KAAA,EACrB,MAAK,UAAU,QAAQ;AAGzB,KAAI,QAAQ,6BAA6B,KAAA,EACvC,MAAK,6BAA6B,QAAQ;AAG5C,KAAI,QAAQ,6BAA6B,KAAA,EACvC,MAAK,6BAA6B,QAAQ;AAG5C,QAAO"}
|
package/dist/tools/x_search.js
CHANGED
|
@@ -55,7 +55,7 @@ function xaiXSearch(options = {}) {
|
|
|
55
55
|
if (options.enableVideoUnderstanding !== void 0) tool.enable_video_understanding = options.enableVideoUnderstanding;
|
|
56
56
|
return tool;
|
|
57
57
|
}
|
|
58
|
-
|
|
59
58
|
//#endregion
|
|
60
59
|
export { XAI_X_SEARCH_TOOL_TYPE, xaiXSearch };
|
|
60
|
+
|
|
61
61
|
//# sourceMappingURL=x_search.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"x_search.js","names":[],"sources":["../../src/tools/x_search.ts"],"sourcesContent":["/**\n * xAI X Search tool type constant.\n */\nexport const XAI_X_SEARCH_TOOL_TYPE = \"x_search\";\n\n/**\n * xAI's built-in X (formerly Twitter) search tool interface.\n * Enables the model to perform keyword search, semantic search, user search,\n * and thread fetch on X.\n *\n * This tool is part of xAI's agentic tool calling API.\n */\nexport interface XAIXSearchTool {\n /**\n * The type of the tool. Must be \"x_search\".\n */\n type: typeof XAI_X_SEARCH_TOOL_TYPE;\n /**\n * X handles to exclusively include in the search (max 10).\n * Cannot be used together with `excluded_x_handles`.\n */\n allowed_x_handles?: string[];\n /**\n * X handles to exclude from the search (max 10).\n * Cannot be used together with `allowed_x_handles`.\n */\n excluded_x_handles?: string[];\n /**\n * Start date for search results (ISO-8601 format: \"YYYY-MM-DD\").\n * Only posts from this date onwards will be included.\n */\n from_date?: string;\n /**\n * End date for search results (ISO-8601 format: \"YYYY-MM-DD\").\n * Only posts up to this date will be included.\n */\n to_date?: string;\n /**\n * Whether to enable image understanding.\n * When enabled, the model can analyze images in X posts.\n */\n enable_image_understanding?: boolean;\n /**\n * Whether to enable video understanding.\n * When enabled, the model can analyze videos in X posts.\n */\n enable_video_understanding?: boolean;\n}\n\n/**\n * Options for the xAI X 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 API request.\n */\nexport interface XAIXSearchToolOptions {\n /**\n * X handles to exclusively include in the search (max 10).\n * Cannot be used together with `excludedXHandles`.\n *\n * @example [\"elonmusk\", \"xai\"]\n */\n allowedXHandles?: string[];\n /**\n * X handles to exclude from the search (max 10).\n * Cannot be used together with `allowedXHandles`.\n *\n * @example [\"spamaccount\"]\n */\n excludedXHandles?: string[];\n /**\n * Start date for search results (ISO-8601 format: \"YYYY-MM-DD\").\n * Only posts from this date onwards will be included.\n *\n * @example \"2024-01-01\"\n */\n fromDate?: string;\n /**\n * End date for search results (ISO-8601 format: \"YYYY-MM-DD\").\n * Only posts up to this date will be included.\n *\n * @example \"2024-12-31\"\n */\n toDate?: string;\n /**\n * Whether to enable image understanding.\n * When enabled, the model can analyze images in X posts.\n * Note: This increases token usage as images are processed.\n *\n * @default false\n */\n enableImageUnderstanding?: boolean;\n /**\n * Whether to enable video understanding.\n * When enabled, the model can analyze videos in X posts.\n * Note: This increases token usage as video content is processed.\n *\n * @default false\n */\n enableVideoUnderstanding?: boolean;\n}\n\n/**\n * Creates an xAI X search tool.\n * Enables the model to perform keyword search, semantic search, user search,\n * and thread fetch on X (formerly Twitter).\n *\n * This tool is executed server-side by the xAI API as part of the agentic\n * tool calling workflow.\n *\n * @param options - Configuration options for the X search tool\n * @returns An XAIXSearchTool object to pass to the model\n *\n * @example Basic usage\n * ```typescript\n * import { ChatXAIResponses, tools } from \"@langchain/xai\";\n *\n * const llm = new ChatXAIResponses({\n * model: \"grok-4-1-fast\",\n * });\n *\n * const xSearch = tools.xaiXSearch();\n * const result = await llm.invoke(\"What is the current status of xAI?\", {\n * tools: [xSearch],\n * });\n * ```\n *\n * @example With handle filtering\n * ```typescript\n * const xSearch = tools.xaiXSearch({\n * allowedXHandles: [\"elonmusk\", \"xai\"],\n * enableImageUnderstanding: true,\n * });\n * ```\n *\n * @example With date range\n * ```typescript\n * const xSearch = tools.xaiXSearch({\n * fromDate: \"2024-10-01\",\n * toDate: \"2024-10-31\",\n * enableVideoUnderstanding: true,\n * });\n * ```\n */\nexport function xaiXSearch(\n options: XAIXSearchToolOptions = {}\n): XAIXSearchTool {\n const tool: XAIXSearchTool = {\n type: XAI_X_SEARCH_TOOL_TYPE,\n };\n\n if (options.allowedXHandles !== undefined) {\n tool.allowed_x_handles = options.allowedXHandles;\n }\n\n if (options.excludedXHandles !== undefined) {\n tool.excluded_x_handles = options.excludedXHandles;\n }\n\n if (options.fromDate !== undefined) {\n tool.from_date = options.fromDate;\n }\n\n if (options.toDate !== undefined) {\n tool.to_date = options.toDate;\n }\n\n if (options.enableImageUnderstanding !== undefined) {\n tool.enable_image_understanding = options.enableImageUnderstanding;\n }\n\n if (options.enableVideoUnderstanding !== undefined) {\n tool.enable_video_understanding = options.enableVideoUnderstanding;\n }\n\n return tool;\n}\n"],"mappings":";;;;AAGA,MAAa,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4ItC,SAAgB,WACd,UAAiC,EAAE,EACnB;CAChB,MAAM,OAAuB,EAC3B,MAAM,wBACP;AAED,KAAI,QAAQ,oBAAoB,
|
|
1
|
+
{"version":3,"file":"x_search.js","names":[],"sources":["../../src/tools/x_search.ts"],"sourcesContent":["/**\n * xAI X Search tool type constant.\n */\nexport const XAI_X_SEARCH_TOOL_TYPE = \"x_search\";\n\n/**\n * xAI's built-in X (formerly Twitter) search tool interface.\n * Enables the model to perform keyword search, semantic search, user search,\n * and thread fetch on X.\n *\n * This tool is part of xAI's agentic tool calling API.\n */\nexport interface XAIXSearchTool {\n /**\n * The type of the tool. Must be \"x_search\".\n */\n type: typeof XAI_X_SEARCH_TOOL_TYPE;\n /**\n * X handles to exclusively include in the search (max 10).\n * Cannot be used together with `excluded_x_handles`.\n */\n allowed_x_handles?: string[];\n /**\n * X handles to exclude from the search (max 10).\n * Cannot be used together with `allowed_x_handles`.\n */\n excluded_x_handles?: string[];\n /**\n * Start date for search results (ISO-8601 format: \"YYYY-MM-DD\").\n * Only posts from this date onwards will be included.\n */\n from_date?: string;\n /**\n * End date for search results (ISO-8601 format: \"YYYY-MM-DD\").\n * Only posts up to this date will be included.\n */\n to_date?: string;\n /**\n * Whether to enable image understanding.\n * When enabled, the model can analyze images in X posts.\n */\n enable_image_understanding?: boolean;\n /**\n * Whether to enable video understanding.\n * When enabled, the model can analyze videos in X posts.\n */\n enable_video_understanding?: boolean;\n}\n\n/**\n * Options for the xAI X 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 API request.\n */\nexport interface XAIXSearchToolOptions {\n /**\n * X handles to exclusively include in the search (max 10).\n * Cannot be used together with `excludedXHandles`.\n *\n * @example [\"elonmusk\", \"xai\"]\n */\n allowedXHandles?: string[];\n /**\n * X handles to exclude from the search (max 10).\n * Cannot be used together with `allowedXHandles`.\n *\n * @example [\"spamaccount\"]\n */\n excludedXHandles?: string[];\n /**\n * Start date for search results (ISO-8601 format: \"YYYY-MM-DD\").\n * Only posts from this date onwards will be included.\n *\n * @example \"2024-01-01\"\n */\n fromDate?: string;\n /**\n * End date for search results (ISO-8601 format: \"YYYY-MM-DD\").\n * Only posts up to this date will be included.\n *\n * @example \"2024-12-31\"\n */\n toDate?: string;\n /**\n * Whether to enable image understanding.\n * When enabled, the model can analyze images in X posts.\n * Note: This increases token usage as images are processed.\n *\n * @default false\n */\n enableImageUnderstanding?: boolean;\n /**\n * Whether to enable video understanding.\n * When enabled, the model can analyze videos in X posts.\n * Note: This increases token usage as video content is processed.\n *\n * @default false\n */\n enableVideoUnderstanding?: boolean;\n}\n\n/**\n * Creates an xAI X search tool.\n * Enables the model to perform keyword search, semantic search, user search,\n * and thread fetch on X (formerly Twitter).\n *\n * This tool is executed server-side by the xAI API as part of the agentic\n * tool calling workflow.\n *\n * @param options - Configuration options for the X search tool\n * @returns An XAIXSearchTool object to pass to the model\n *\n * @example Basic usage\n * ```typescript\n * import { ChatXAIResponses, tools } from \"@langchain/xai\";\n *\n * const llm = new ChatXAIResponses({\n * model: \"grok-4-1-fast\",\n * });\n *\n * const xSearch = tools.xaiXSearch();\n * const result = await llm.invoke(\"What is the current status of xAI?\", {\n * tools: [xSearch],\n * });\n * ```\n *\n * @example With handle filtering\n * ```typescript\n * const xSearch = tools.xaiXSearch({\n * allowedXHandles: [\"elonmusk\", \"xai\"],\n * enableImageUnderstanding: true,\n * });\n * ```\n *\n * @example With date range\n * ```typescript\n * const xSearch = tools.xaiXSearch({\n * fromDate: \"2024-10-01\",\n * toDate: \"2024-10-31\",\n * enableVideoUnderstanding: true,\n * });\n * ```\n */\nexport function xaiXSearch(\n options: XAIXSearchToolOptions = {}\n): XAIXSearchTool {\n const tool: XAIXSearchTool = {\n type: XAI_X_SEARCH_TOOL_TYPE,\n };\n\n if (options.allowedXHandles !== undefined) {\n tool.allowed_x_handles = options.allowedXHandles;\n }\n\n if (options.excludedXHandles !== undefined) {\n tool.excluded_x_handles = options.excludedXHandles;\n }\n\n if (options.fromDate !== undefined) {\n tool.from_date = options.fromDate;\n }\n\n if (options.toDate !== undefined) {\n tool.to_date = options.toDate;\n }\n\n if (options.enableImageUnderstanding !== undefined) {\n tool.enable_image_understanding = options.enableImageUnderstanding;\n }\n\n if (options.enableVideoUnderstanding !== undefined) {\n tool.enable_video_understanding = options.enableVideoUnderstanding;\n }\n\n return tool;\n}\n"],"mappings":";;;;AAGA,MAAa,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4ItC,SAAgB,WACd,UAAiC,EAAE,EACnB;CAChB,MAAM,OAAuB,EAC3B,MAAM,wBACP;AAED,KAAI,QAAQ,oBAAoB,KAAA,EAC9B,MAAK,oBAAoB,QAAQ;AAGnC,KAAI,QAAQ,qBAAqB,KAAA,EAC/B,MAAK,qBAAqB,QAAQ;AAGpC,KAAI,QAAQ,aAAa,KAAA,EACvB,MAAK,YAAY,QAAQ;AAG3B,KAAI,QAAQ,WAAW,KAAA,EACrB,MAAK,UAAU,QAAQ;AAGzB,KAAI,QAAQ,6BAA6B,KAAA,EACvC,MAAK,6BAA6B,QAAQ;AAG5C,KAAI,QAAQ,6BAA6B,KAAA,EACvC,MAAK,6BAA6B,QAAQ;AAG5C,QAAO"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langchain/xai",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.10-dev-1773698445534",
|
|
4
4
|
"description": "xAI integration for LangChain.js",
|
|
5
5
|
"author": "LangChain",
|
|
6
6
|
"license": "MIT",
|
|
@@ -14,10 +14,10 @@
|
|
|
14
14
|
},
|
|
15
15
|
"homepage": "https://github.com/langchain-ai/langchainjs/tree/main/libs/providers/langchain-xai/",
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@langchain/openai": "1.
|
|
17
|
+
"@langchain/openai": "1.3.0-dev-1773698445534"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
|
-
"@langchain/core": "
|
|
20
|
+
"@langchain/core": "1.1.33-dev-1773698445534"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@tsconfig/recommended": "^1.0.3",
|
|
@@ -30,10 +30,10 @@
|
|
|
30
30
|
"typescript": "~5.8.3",
|
|
31
31
|
"vitest": "^3.2.4",
|
|
32
32
|
"zod": "^3.25.76",
|
|
33
|
-
"@langchain/
|
|
34
|
-
"@langchain/standard-tests": "0.0.23",
|
|
33
|
+
"@langchain/core": "^1.1.33-dev-1773698445534",
|
|
35
34
|
"@langchain/eslint": "0.1.1",
|
|
36
|
-
"@langchain/
|
|
35
|
+
"@langchain/standard-tests": "0.0.23",
|
|
36
|
+
"@langchain/openai": "^1.3.0-dev-1773698445534",
|
|
37
37
|
"@langchain/tsconfig": "0.0.1"
|
|
38
38
|
},
|
|
39
39
|
"publishConfig": {
|