{"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"}