@langchain/openai 1.2.5 → 1.2.7

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.
Files changed (52) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/azure/chat_models/common.cjs.map +1 -1
  3. package/dist/azure/chat_models/common.js.map +1 -1
  4. package/dist/azure/chat_models/completions.cjs.map +1 -1
  5. package/dist/azure/chat_models/completions.js.map +1 -1
  6. package/dist/azure/chat_models/index.cjs.map +1 -1
  7. package/dist/azure/chat_models/index.js.map +1 -1
  8. package/dist/azure/chat_models/responses.cjs.map +1 -1
  9. package/dist/azure/chat_models/responses.js.map +1 -1
  10. package/dist/chat_models/base.cjs.map +1 -1
  11. package/dist/chat_models/base.js.map +1 -1
  12. package/dist/chat_models/completions.cjs.map +1 -1
  13. package/dist/chat_models/completions.js.map +1 -1
  14. package/dist/chat_models/responses.cjs +1 -0
  15. package/dist/chat_models/responses.cjs.map +1 -1
  16. package/dist/chat_models/responses.js +1 -0
  17. package/dist/chat_models/responses.js.map +1 -1
  18. package/dist/converters/completions.cjs +2 -1
  19. package/dist/converters/completions.cjs.map +1 -1
  20. package/dist/converters/completions.js +2 -1
  21. package/dist/converters/completions.js.map +1 -1
  22. package/dist/converters/responses.cjs +56 -2
  23. package/dist/converters/responses.cjs.map +1 -1
  24. package/dist/converters/responses.js +56 -2
  25. package/dist/converters/responses.js.map +1 -1
  26. package/dist/tools/applyPatch.cjs +1 -1
  27. package/dist/tools/applyPatch.cjs.map +1 -1
  28. package/dist/tools/applyPatch.d.cts +1 -1
  29. package/dist/tools/applyPatch.d.cts.map +1 -1
  30. package/dist/tools/applyPatch.d.ts +1 -1
  31. package/dist/tools/applyPatch.d.ts.map +1 -1
  32. package/dist/tools/applyPatch.js +1 -1
  33. package/dist/tools/applyPatch.js.map +1 -1
  34. package/dist/tools/codeInterpreter.d.cts.map +1 -1
  35. package/dist/tools/computerUse.cjs +1 -1
  36. package/dist/tools/computerUse.cjs.map +1 -1
  37. package/dist/tools/computerUse.d.cts +1 -1
  38. package/dist/tools/computerUse.d.cts.map +1 -1
  39. package/dist/tools/computerUse.d.ts +1 -1
  40. package/dist/tools/computerUse.d.ts.map +1 -1
  41. package/dist/tools/computerUse.js +1 -1
  42. package/dist/tools/computerUse.js.map +1 -1
  43. package/dist/tools/localShell.cjs +1 -1
  44. package/dist/tools/localShell.cjs.map +1 -1
  45. package/dist/tools/localShell.d.cts +1 -1
  46. package/dist/tools/localShell.d.cts.map +1 -1
  47. package/dist/tools/localShell.d.ts +1 -1
  48. package/dist/tools/localShell.d.ts.map +1 -1
  49. package/dist/tools/localShell.js +1 -1
  50. package/dist/tools/localShell.js.map +1 -1
  51. package/dist/tools/mcp.d.cts.map +1 -1
  52. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"codeInterpreter.d.cts","names":["OpenAI","OpenAIClient","ServerTool","CodeInterpreterMemoryLimit","CodeInterpreterAutoContainer","CodeInterpreterOptions","CodeInterpreterTool","Responses","Tool","CodeInterpreter","codeInterpreter"],"sources":["../../src/tools/codeInterpreter.d.ts"],"sourcesContent":["import { OpenAI as OpenAIClient } from \"openai\";\nimport type { ServerTool } from \"@langchain/core/tools\";\n/**\n * Memory limit options for the Code Interpreter container.\n * Higher tiers offer more RAM and are billed at different rates.\n */\nexport type CodeInterpreterMemoryLimit = \"1g\" | \"4g\" | \"16g\" | \"64g\";\n/**\n * Auto container configuration for Code Interpreter.\n * Creates a new container automatically or reuses an active one.\n */\nexport interface CodeInterpreterAutoContainer {\n /**\n * Memory limit for the container.\n * - `\"1g\"` (default): 1 GB RAM\n * - `\"4g\"`: 4 GB RAM\n * - `\"16g\"`: 16 GB RAM\n * - `\"64g\"`: 64 GB RAM\n */\n memoryLimit?: CodeInterpreterMemoryLimit;\n /**\n * Optional list of uploaded file IDs to make available to the code.\n * Files in the model input are automatically uploaded, so this is only\n * needed for additional files.\n */\n fileIds?: string[];\n}\n/**\n * Options for the Code Interpreter tool.\n */\nexport interface CodeInterpreterOptions {\n /**\n * The container configuration for the Code Interpreter.\n *\n * Can be either:\n * - A string container ID for explicit mode (created via `/v1/containers` endpoint)\n * - An auto configuration object that creates/reuses containers automatically\n *\n * If not provided, defaults to auto mode with default settings.\n */\n container?: string | CodeInterpreterAutoContainer;\n}\n/**\n * OpenAI Code Interpreter tool type for the Responses API.\n */\nexport type CodeInterpreterTool = OpenAIClient.Responses.Tool.CodeInterpreter;\n/**\n * Creates a Code Interpreter tool that allows models to write and run Python code\n * in a sandboxed environment to solve complex problems.\n *\n * Use Code Interpreter for:\n * - **Data analysis**: Processing files with diverse data and formatting\n * - **File generation**: Creating files with data and images of graphs\n * - **Iterative coding**: Writing and running code iteratively to solve problems\n * - **Visual intelligence**: Cropping, zooming, rotating, and transforming images\n *\n * The tool runs in a container, which is a fully sandboxed virtual machine.\n * Containers can be created automatically (auto mode) or explicitly via the\n * `/v1/containers` endpoint.\n *\n * @see {@link https://platform.openai.com/docs/guides/tools-code-interpreter | OpenAI Code Interpreter Documentation}\n *\n * @param options - Configuration options for the Code Interpreter tool\n * @returns A Code Interpreter tool definition to be passed to the OpenAI Responses API\n *\n * @example\n * ```typescript\n * import { ChatOpenAI, tools } from \"@langchain/openai\";\n *\n * const model = new ChatOpenAI({ model: \"gpt-4.1\" });\n *\n * // Basic usage with auto container (default 1GB memory)\n * const response = await model.invoke(\n * \"Solve the equation 3x + 11 = 14\",\n * { tools: [tools.codeInterpreter()] }\n * );\n *\n * // With increased memory limit for larger computations\n * const response = await model.invoke(\n * \"Analyze this large dataset and create visualizations\",\n * {\n * tools: [tools.codeInterpreter({\n * container: { memoryLimit: \"4g\" }\n * })]\n * }\n * );\n *\n * // With specific files available to the code\n * const response = await model.invoke(\n * \"Process the uploaded CSV file\",\n * {\n * tools: [tools.codeInterpreter({\n * container: {\n * memoryLimit: \"4g\",\n * fileIds: [\"file-abc123\", \"file-def456\"]\n * }\n * })]\n * }\n * );\n *\n * // Using an explicit container ID (created via /v1/containers)\n * const response = await model.invoke(\n * \"Continue working with the data\",\n * {\n * tools: [tools.codeInterpreter({\n * container: \"cntr_abc123\"\n * })]\n * }\n * );\n * ```\n *\n * @remarks\n * - Containers expire after 20 minutes of inactivity\n * - While called \"Code Interpreter\", the model knows it as the \"python tool\"\n * - For explicit prompting, ask for \"the python tool\" in your prompts\n * - Files in model input are automatically uploaded to the container\n * - Generated files are returned as `container_file_citation` annotations\n */\nexport declare function codeInterpreter(options?: CodeInterpreterOptions): ServerTool;\n//# sourceMappingURL=codeInterpreter.d.ts.map"],"mappings":";;;;;;;AAMA;AAKA;AAmBiBK,KAxBLF,0BAAAA,GAwB2B,IAUdC,GAAAA,IAAAA,GAAAA,KAAAA,GAAAA,KAAAA;AAKzB;AAyEA;;;UA3GiBA,4BAAAA;;;;;;;;gBAQCD;;;;;;;;;;;UAWDE,sBAAAA;;;;;;;;;;uBAUQD;;;;;KAKbE,mBAAAA,GAAsBL,QAAAA,CAAaM,SAAAA,CAAUC,IAAAA,CAAKC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAyEtCC,eAAAA,WAA0BL,yBAAyBH"}
1
+ {"version":3,"file":"codeInterpreter.d.cts","names":["OpenAI","OpenAIClient","ServerTool","CodeInterpreterMemoryLimit","CodeInterpreterAutoContainer","CodeInterpreterOptions","CodeInterpreterTool","Responses","Tool","CodeInterpreter","codeInterpreter"],"sources":["../../src/tools/codeInterpreter.d.ts"],"sourcesContent":["import { OpenAI as OpenAIClient } from \"openai\";\nimport type { ServerTool } from \"@langchain/core/tools\";\n/**\n * Memory limit options for the Code Interpreter container.\n * Higher tiers offer more RAM and are billed at different rates.\n */\nexport type CodeInterpreterMemoryLimit = \"1g\" | \"4g\" | \"16g\" | \"64g\";\n/**\n * Auto container configuration for Code Interpreter.\n * Creates a new container automatically or reuses an active one.\n */\nexport interface CodeInterpreterAutoContainer {\n /**\n * Memory limit for the container.\n * - `\"1g\"` (default): 1 GB RAM\n * - `\"4g\"`: 4 GB RAM\n * - `\"16g\"`: 16 GB RAM\n * - `\"64g\"`: 64 GB RAM\n */\n memoryLimit?: CodeInterpreterMemoryLimit;\n /**\n * Optional list of uploaded file IDs to make available to the code.\n * Files in the model input are automatically uploaded, so this is only\n * needed for additional files.\n */\n fileIds?: string[];\n}\n/**\n * Options for the Code Interpreter tool.\n */\nexport interface CodeInterpreterOptions {\n /**\n * The container configuration for the Code Interpreter.\n *\n * Can be either:\n * - A string container ID for explicit mode (created via `/v1/containers` endpoint)\n * - An auto configuration object that creates/reuses containers automatically\n *\n * If not provided, defaults to auto mode with default settings.\n */\n container?: string | CodeInterpreterAutoContainer;\n}\n/**\n * OpenAI Code Interpreter tool type for the Responses API.\n */\nexport type CodeInterpreterTool = OpenAIClient.Responses.Tool.CodeInterpreter;\n/**\n * Creates a Code Interpreter tool that allows models to write and run Python code\n * in a sandboxed environment to solve complex problems.\n *\n * Use Code Interpreter for:\n * - **Data analysis**: Processing files with diverse data and formatting\n * - **File generation**: Creating files with data and images of graphs\n * - **Iterative coding**: Writing and running code iteratively to solve problems\n * - **Visual intelligence**: Cropping, zooming, rotating, and transforming images\n *\n * The tool runs in a container, which is a fully sandboxed virtual machine.\n * Containers can be created automatically (auto mode) or explicitly via the\n * `/v1/containers` endpoint.\n *\n * @see {@link https://platform.openai.com/docs/guides/tools-code-interpreter | OpenAI Code Interpreter Documentation}\n *\n * @param options - Configuration options for the Code Interpreter tool\n * @returns A Code Interpreter tool definition to be passed to the OpenAI Responses API\n *\n * @example\n * ```typescript\n * import { ChatOpenAI, tools } from \"@langchain/openai\";\n *\n * const model = new ChatOpenAI({ model: \"gpt-4.1\" });\n *\n * // Basic usage with auto container (default 1GB memory)\n * const response = await model.invoke(\n * \"Solve the equation 3x + 11 = 14\",\n * { tools: [tools.codeInterpreter()] }\n * );\n *\n * // With increased memory limit for larger computations\n * const response = await model.invoke(\n * \"Analyze this large dataset and create visualizations\",\n * {\n * tools: [tools.codeInterpreter({\n * container: { memoryLimit: \"4g\" }\n * })]\n * }\n * );\n *\n * // With specific files available to the code\n * const response = await model.invoke(\n * \"Process the uploaded CSV file\",\n * {\n * tools: [tools.codeInterpreter({\n * container: {\n * memoryLimit: \"4g\",\n * fileIds: [\"file-abc123\", \"file-def456\"]\n * }\n * })]\n * }\n * );\n *\n * // Using an explicit container ID (created via /v1/containers)\n * const response = await model.invoke(\n * \"Continue working with the data\",\n * {\n * tools: [tools.codeInterpreter({\n * container: \"cntr_abc123\"\n * })]\n * }\n * );\n * ```\n *\n * @remarks\n * - Containers expire after 20 minutes of inactivity\n * - While called \"Code Interpreter\", the model knows it as the \"python tool\"\n * - For explicit prompting, ask for \"the python tool\" in your prompts\n * - Files in model input are automatically uploaded to the container\n * - Generated files are returned as `container_file_citation` annotations\n */\nexport declare function codeInterpreter(options?: CodeInterpreterOptions): ServerTool;\n//# sourceMappingURL=codeInterpreter.d.ts.map"],"mappings":";;;;;;;AAMA;AAKA;AAmBiBK,KAxBLF,0BAAAA,GAkCaC,IAAAA,GAAAA,IAAAA,GAAAA,KAAAA,GAAAA,KAAAA;AAKzB;AAyEA;;;UA3GiBA,4BAAAA;;;;;;;;gBAQCD;;;;;;;;;;;UAWDE,sBAAAA;;;;;;;;;;uBAUQD;;;;;KAKbE,mBAAAA,GAAsBL,QAAAA,CAAaM,SAAAA,CAAUC,IAAAA,CAAKC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAyEtCC,eAAAA,WAA0BL,yBAAyBH"}
@@ -60,7 +60,7 @@ const ComputerUseWaitActionSchema = zod_v4.z.object({
60
60
  type: zod_v4.z.literal("wait"),
61
61
  duration: zod_v4.z.number().optional()
62
62
  });
63
- const ComputerUseActionUnionSchema = zod_v4.z.discriminatedUnion("type", [
63
+ const ComputerUseActionUnionSchema = zod_v4.z.union([
64
64
  ComputerUseScreenshotActionSchema,
65
65
  ComputerUseClickActionSchema,
66
66
  ComputerUseDoubleClickActionSchema,
@@ -1 +1 @@
1
- {"version":3,"file":"computerUse.cjs","names":["z","options: ComputerUseOptions","input: ComputerUseInput","runtime: ToolRuntime<{ messages: BaseMessage[] }>","ToolMessage"],"sources":["../../src/tools/computerUse.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { z } from \"zod/v4\";\nimport { OpenAI as OpenAIClient } from \"openai\";\nimport { tool, type DynamicStructuredTool } from \"@langchain/core/tools\";\nimport { type ToolRuntime } from \"@langchain/core/tools\";\nimport {\n ToolMessage,\n type AIMessage,\n type BaseMessage,\n} from \"@langchain/core/messages\";\n\n/**\n * The type of computer environment to control.\n */\nexport type ComputerUseEnvironment =\n | \"browser\"\n | \"mac\"\n | \"windows\"\n | \"linux\"\n | \"ubuntu\";\n\n/**\n * Re-export action types from OpenAI SDK for convenience.\n */\nexport type ComputerUseClickAction =\n OpenAIClient.Responses.ResponseComputerToolCall.Click;\nexport type ComputerUseDoubleClickAction =\n OpenAIClient.Responses.ResponseComputerToolCall.DoubleClick;\nexport type ComputerUseDragAction =\n OpenAIClient.Responses.ResponseComputerToolCall.Drag;\nexport type ComputerUseKeypressAction =\n OpenAIClient.Responses.ResponseComputerToolCall.Keypress;\nexport type ComputerUseMoveAction =\n OpenAIClient.Responses.ResponseComputerToolCall.Move;\nexport type ComputerUseScreenshotAction =\n OpenAIClient.Responses.ResponseComputerToolCall.Screenshot;\nexport type ComputerUseScrollAction =\n OpenAIClient.Responses.ResponseComputerToolCall.Scroll;\nexport type ComputerUseTypeAction =\n OpenAIClient.Responses.ResponseComputerToolCall.Type;\nexport type ComputerUseWaitAction =\n OpenAIClient.Responses.ResponseComputerToolCall.Wait;\n\n/**\n * Union type of all computer use actions from OpenAI SDK.\n */\nexport type ComputerUseAction =\n OpenAIClient.Responses.ResponseComputerToolCall[\"action\"];\n\n// Zod schemas for computer use actions\nconst ComputerUseScreenshotActionSchema = z.object({\n type: z.literal(\"screenshot\"),\n});\n\nconst ComputerUseClickActionSchema = z.object({\n type: z.literal(\"click\"),\n x: z.number(),\n y: z.number(),\n button: z.enum([\"left\", \"right\", \"wheel\", \"back\", \"forward\"]).default(\"left\"),\n});\n\nconst ComputerUseDoubleClickActionSchema = z.object({\n type: z.literal(\"double_click\"),\n x: z.number(),\n y: z.number(),\n button: z.enum([\"left\", \"right\", \"wheel\", \"back\", \"forward\"]).default(\"left\"),\n});\n\nconst ComputerUseDragActionSchema = z.object({\n type: z.literal(\"drag\"),\n path: z.array(z.object({ x: z.number(), y: z.number() })),\n});\n\nconst ComputerUseKeypressActionSchema = z.object({\n type: z.literal(\"keypress\"),\n keys: z.array(z.string()),\n});\n\nconst ComputerUseMoveActionSchema = z.object({\n type: z.literal(\"move\"),\n x: z.number(),\n y: z.number(),\n});\n\nconst ComputerUseScrollActionSchema = z.object({\n type: z.literal(\"scroll\"),\n x: z.number(),\n y: z.number(),\n scroll_x: z.number(),\n scroll_y: z.number(),\n});\n\nconst ComputerUseTypeActionSchema = z.object({\n type: z.literal(\"type\"),\n text: z.string(),\n});\n\nconst ComputerUseWaitActionSchema = z.object({\n type: z.literal(\"wait\"),\n duration: z.number().optional(),\n});\n\n// Discriminated union schema for individual action types\nconst ComputerUseActionUnionSchema = z.discriminatedUnion(\"type\", [\n ComputerUseScreenshotActionSchema,\n ComputerUseClickActionSchema,\n ComputerUseDoubleClickActionSchema,\n ComputerUseDragActionSchema,\n ComputerUseKeypressActionSchema,\n ComputerUseMoveActionSchema,\n ComputerUseScrollActionSchema,\n ComputerUseTypeActionSchema,\n ComputerUseWaitActionSchema,\n]);\n\n// Schema for the input structure received from parseComputerCall\n// The action is wrapped in an `action` property: { action: { type: 'screenshot' } }\nexport const ComputerUseActionSchema = z.object({\n action: ComputerUseActionUnionSchema,\n});\n\n// TypeScript types derived from Zod schemas\nexport type ComputerUseScreenshotActionType = z.infer<\n typeof ComputerUseScreenshotActionSchema\n>;\nexport type ComputerUseClickActionType = z.infer<\n typeof ComputerUseClickActionSchema\n>;\nexport type ComputerUseDoubleClickActionType = z.infer<\n typeof ComputerUseDoubleClickActionSchema\n>;\nexport type ComputerUseDragActionType = z.infer<\n typeof ComputerUseDragActionSchema\n>;\nexport type ComputerUseKeypressActionType = z.infer<\n typeof ComputerUseKeypressActionSchema\n>;\nexport type ComputerUseMoveActionType = z.infer<\n typeof ComputerUseMoveActionSchema\n>;\nexport type ComputerUseScrollActionType = z.infer<\n typeof ComputerUseScrollActionSchema\n>;\nexport type ComputerUseTypeActionType = z.infer<\n typeof ComputerUseTypeActionSchema\n>;\nexport type ComputerUseWaitActionType = z.infer<\n typeof ComputerUseWaitActionSchema\n>;\n\n/**\n * Input structure for the Computer Use tool.\n * The action is wrapped in an `action` property.\n */\nexport interface ComputerUseInput {\n action: ComputerUseAction;\n}\n\nexport type ComputerUseReturnType =\n | string\n | Promise<string>\n | ToolMessage<any>\n | Promise<ToolMessage<any>>;\n\n/**\n * Options for the Computer Use tool.\n */\nexport interface ComputerUseOptions {\n /**\n * The width of the computer display in pixels.\n */\n displayWidth: number;\n\n /**\n * The height of the computer display in pixels.\n */\n displayHeight: number;\n\n /**\n * The type of computer environment to control.\n * - `browser`: Browser automation (recommended for most use cases)\n * - `mac`: macOS environment\n * - `windows`: Windows environment\n * - `linux`: Linux environment\n * - `ubuntu`: Ubuntu environment\n */\n environment: ComputerUseEnvironment;\n\n /**\n * Execute function that handles computer action execution.\n * This function receives the action input and should return a base64-encoded\n * screenshot of the result.\n */\n execute: (\n action: ComputerUseAction,\n runtime: ToolRuntime<any, any>\n ) => ComputerUseReturnType;\n}\n\n/**\n * OpenAI Computer Use tool type for the Responses API.\n */\nexport type ComputerUseTool = OpenAIClient.Responses.ComputerTool;\n\nconst TOOL_NAME = \"computer_use\";\n\n/**\n * Creates a Computer Use tool that allows models to control computer interfaces\n * and perform tasks by simulating mouse clicks, keyboard input, scrolling, and more.\n *\n * **Computer Use** is a practical application of OpenAI's Computer-Using Agent (CUA)\n * model (`computer-use-preview`), which combines vision capabilities with advanced\n * reasoning to simulate controlling computer interfaces.\n *\n * **How it works**:\n * The tool operates in a continuous loop:\n * 1. Model sends computer actions (click, type, scroll, etc.)\n * 2. Your code executes these actions in a controlled environment\n * 3. You capture a screenshot of the result\n * 4. Send the screenshot back to the model\n * 5. Repeat until the task is complete\n *\n * **Important**: Computer use is in beta and requires careful consideration:\n * - Use in sandboxed environments only\n * - Do not use for high-stakes or authenticated tasks\n * - Always implement human-in-the-loop for important decisions\n * - Handle safety checks appropriately\n *\n * @see {@link https://platform.openai.com/docs/guides/tools-computer-use | OpenAI Computer Use Documentation}\n *\n * @param options - Configuration options for the Computer Use tool\n * @returns A Computer Use tool that can be passed to `bindTools`\n *\n * @example\n * ```typescript\n * import { ChatOpenAI, tools } from \"@langchain/openai\";\n *\n * const model = new ChatOpenAI({ model: \"computer-use-preview\" });\n *\n * // With execute callback for automatic action handling\n * const computer = tools.computerUse({\n * displayWidth: 1024,\n * displayHeight: 768,\n * environment: \"browser\",\n * execute: async (action) => {\n * if (action.type === \"screenshot\") {\n * return captureScreenshot();\n * }\n * if (action.type === \"click\") {\n * await page.mouse.click(action.x, action.y, { button: action.button });\n * return captureScreenshot();\n * }\n * if (action.type === \"type\") {\n * await page.keyboard.type(action.text);\n * return captureScreenshot();\n * }\n * // Handle other actions...\n * return captureScreenshot();\n * },\n * });\n *\n * const llmWithComputer = model.bindTools([computer]);\n * const response = await llmWithComputer.invoke(\n * \"Check the latest news on bing.com\"\n * );\n * ```\n *\n * @example\n * ```typescript\n * // Without execute callback (manual action handling)\n * const computer = tools.computerUse({\n * displayWidth: 1024,\n * displayHeight: 768,\n * environment: \"browser\",\n * });\n *\n * const response = await model.invoke(\"Check the news\", {\n * tools: [computer],\n * });\n *\n * // Access the computer call from the response\n * const computerCall = response.additional_kwargs.tool_outputs?.find(\n * (output) => output.type === \"computer_call\"\n * );\n * if (computerCall) {\n * console.log(\"Action to execute:\", computerCall.action);\n * // Execute the action manually, then send back a screenshot\n * }\n * ```\n *\n * @example\n * ```typescript\n * // For macOS desktop automation with Docker\n * const computer = tools.computerUse({\n * displayWidth: 1920,\n * displayHeight: 1080,\n * environment: \"mac\",\n * execute: async (action) => {\n * if (action.type === \"click\") {\n * await dockerExec(\n * `DISPLAY=:99 xdotool mousemove ${action.x} ${action.y} click 1`,\n * containerName\n * );\n * }\n * // Capture screenshot from container\n * return await getDockerScreenshot(containerName);\n * },\n * });\n * ```\n *\n * @remarks\n * - Only available through the Responses API (not Chat Completions)\n * - Requires `computer-use-preview` model\n * - Actions include: click, double_click, drag, keypress, move, screenshot, scroll, type, wait\n * - Safety checks may be returned that require acknowledgment before proceeding\n * - Use `truncation: \"auto\"` parameter when making requests\n * - Recommended to use with `reasoning.summary` for debugging\n */\nexport function computerUse(options: ComputerUseOptions) {\n const computerTool = tool(\n async (\n input: ComputerUseInput,\n runtime: ToolRuntime<{ messages: BaseMessage[] }>\n ) => {\n /**\n * get computer_use call id from runtime\n */\n const aiMessage = runtime.state?.messages.at(-1) as AIMessage | undefined;\n const computerToolCall = aiMessage?.tool_calls?.find(\n (tc) => tc.name === \"computer_use\"\n );\n const computerToolCallId = computerToolCall?.id;\n if (!computerToolCallId) {\n throw new Error(\"Computer use call id not found\");\n }\n\n const result = await options.execute(input.action, runtime);\n\n /**\n * make sure {@link ToolMessage} is returned with the correct additional kwargs\n */\n if (typeof result === \"string\") {\n return new ToolMessage({\n content: result,\n tool_call_id: computerToolCallId,\n additional_kwargs: {\n type: \"computer_call_output\",\n },\n });\n }\n\n /**\n * make sure {@link ToolMessage} is returned with the correct additional kwargs\n */\n return new ToolMessage({\n ...result,\n tool_call_id: computerToolCallId,\n additional_kwargs: {\n type: \"computer_call_output\",\n ...result.additional_kwargs,\n },\n });\n },\n {\n name: TOOL_NAME,\n description:\n \"Control a computer interface by executing mouse clicks, keyboard input, scrolling, and other actions.\",\n schema: ComputerUseActionSchema,\n }\n );\n\n computerTool.extras = {\n ...(computerTool.extras ?? {}),\n providerToolDefinition: {\n type: \"computer_use_preview\",\n display_width: options.displayWidth,\n display_height: options.displayHeight,\n environment: options.environment,\n } satisfies ComputerUseTool,\n };\n\n /**\n * return as typed {@link DynamicStructuredTool} so we don't get any type\n * errors like \"can't export tool without reference\"\n */\n return computerTool as DynamicStructuredTool<\n typeof ComputerUseActionSchema,\n ComputerUseInput,\n unknown,\n ComputerUseReturnType\n >;\n}\n"],"mappings":";;;;;;AAkDA,MAAM,oCAAoCA,SAAE,OAAO,EACjD,MAAMA,SAAE,QAAQ,aAAa,CAC9B,EAAC;AAEF,MAAM,+BAA+BA,SAAE,OAAO;CAC5C,MAAMA,SAAE,QAAQ,QAAQ;CACxB,GAAGA,SAAE,QAAQ;CACb,GAAGA,SAAE,QAAQ;CACb,QAAQA,SAAE,KAAK;EAAC;EAAQ;EAAS;EAAS;EAAQ;CAAU,EAAC,CAAC,QAAQ,OAAO;AAC9E,EAAC;AAEF,MAAM,qCAAqCA,SAAE,OAAO;CAClD,MAAMA,SAAE,QAAQ,eAAe;CAC/B,GAAGA,SAAE,QAAQ;CACb,GAAGA,SAAE,QAAQ;CACb,QAAQA,SAAE,KAAK;EAAC;EAAQ;EAAS;EAAS;EAAQ;CAAU,EAAC,CAAC,QAAQ,OAAO;AAC9E,EAAC;AAEF,MAAM,8BAA8BA,SAAE,OAAO;CAC3C,MAAMA,SAAE,QAAQ,OAAO;CACvB,MAAMA,SAAE,MAAMA,SAAE,OAAO;EAAE,GAAGA,SAAE,QAAQ;EAAE,GAAGA,SAAE,QAAQ;CAAE,EAAC,CAAC;AAC1D,EAAC;AAEF,MAAM,kCAAkCA,SAAE,OAAO;CAC/C,MAAMA,SAAE,QAAQ,WAAW;CAC3B,MAAMA,SAAE,MAAMA,SAAE,QAAQ,CAAC;AAC1B,EAAC;AAEF,MAAM,8BAA8BA,SAAE,OAAO;CAC3C,MAAMA,SAAE,QAAQ,OAAO;CACvB,GAAGA,SAAE,QAAQ;CACb,GAAGA,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ACd,mBAAmB;IACjB,MAAM;IACN,GAAG,OAAO;GACX;EACF;CACF,GACD;EACE,MAAM;EACN,aACE;EACF,QAAQ;CACT,EACF;CAED,aAAa,SAAS;EACpB,GAAI,aAAa,UAAU,CAAE;EAC7B,wBAAwB;GACtB,MAAM;GACN,eAAe,QAAQ;GACvB,gBAAgB,QAAQ;GACxB,aAAa,QAAQ;EACtB;CACF;;;;;AAMD,QAAO;AAMR"}
1
+ {"version":3,"file":"computerUse.cjs","names":["z","options: ComputerUseOptions","input: ComputerUseInput","runtime: ToolRuntime<{ messages: BaseMessage[] }>","ToolMessage"],"sources":["../../src/tools/computerUse.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { z } from \"zod/v4\";\nimport { OpenAI as OpenAIClient } from \"openai\";\nimport { tool, type DynamicStructuredTool } from \"@langchain/core/tools\";\nimport { type ToolRuntime } from \"@langchain/core/tools\";\nimport {\n ToolMessage,\n type AIMessage,\n type BaseMessage,\n} from \"@langchain/core/messages\";\n\n/**\n * The type of computer environment to control.\n */\nexport type ComputerUseEnvironment =\n | \"browser\"\n | \"mac\"\n | \"windows\"\n | \"linux\"\n | \"ubuntu\";\n\n/**\n * Re-export action types from OpenAI SDK for convenience.\n */\nexport type ComputerUseClickAction =\n OpenAIClient.Responses.ResponseComputerToolCall.Click;\nexport type ComputerUseDoubleClickAction =\n OpenAIClient.Responses.ResponseComputerToolCall.DoubleClick;\nexport type ComputerUseDragAction =\n OpenAIClient.Responses.ResponseComputerToolCall.Drag;\nexport type ComputerUseKeypressAction =\n OpenAIClient.Responses.ResponseComputerToolCall.Keypress;\nexport type ComputerUseMoveAction =\n OpenAIClient.Responses.ResponseComputerToolCall.Move;\nexport type ComputerUseScreenshotAction =\n OpenAIClient.Responses.ResponseComputerToolCall.Screenshot;\nexport type ComputerUseScrollAction =\n OpenAIClient.Responses.ResponseComputerToolCall.Scroll;\nexport type ComputerUseTypeAction =\n OpenAIClient.Responses.ResponseComputerToolCall.Type;\nexport type ComputerUseWaitAction =\n OpenAIClient.Responses.ResponseComputerToolCall.Wait;\n\n/**\n * Union type of all computer use actions from OpenAI SDK.\n */\nexport type ComputerUseAction =\n OpenAIClient.Responses.ResponseComputerToolCall[\"action\"];\n\n// Zod schemas for computer use actions\nconst ComputerUseScreenshotActionSchema = z.object({\n type: z.literal(\"screenshot\"),\n});\n\nconst ComputerUseClickActionSchema = z.object({\n type: z.literal(\"click\"),\n x: z.number(),\n y: z.number(),\n button: z.enum([\"left\", \"right\", \"wheel\", \"back\", \"forward\"]).default(\"left\"),\n});\n\nconst ComputerUseDoubleClickActionSchema = z.object({\n type: z.literal(\"double_click\"),\n x: z.number(),\n y: z.number(),\n button: z.enum([\"left\", \"right\", \"wheel\", \"back\", \"forward\"]).default(\"left\"),\n});\n\nconst ComputerUseDragActionSchema = z.object({\n type: z.literal(\"drag\"),\n path: z.array(z.object({ x: z.number(), y: z.number() })),\n});\n\nconst ComputerUseKeypressActionSchema = z.object({\n type: z.literal(\"keypress\"),\n keys: z.array(z.string()),\n});\n\nconst ComputerUseMoveActionSchema = z.object({\n type: z.literal(\"move\"),\n x: z.number(),\n y: z.number(),\n});\n\nconst ComputerUseScrollActionSchema = z.object({\n type: z.literal(\"scroll\"),\n x: z.number(),\n y: z.number(),\n scroll_x: z.number(),\n scroll_y: z.number(),\n});\n\nconst ComputerUseTypeActionSchema = z.object({\n type: z.literal(\"type\"),\n text: z.string(),\n});\n\nconst ComputerUseWaitActionSchema = z.object({\n type: z.literal(\"wait\"),\n duration: z.number().optional(),\n});\n\n// Union schema for individual action types\nconst ComputerUseActionUnionSchema = z.union([\n ComputerUseScreenshotActionSchema,\n ComputerUseClickActionSchema,\n ComputerUseDoubleClickActionSchema,\n ComputerUseDragActionSchema,\n ComputerUseKeypressActionSchema,\n ComputerUseMoveActionSchema,\n ComputerUseScrollActionSchema,\n ComputerUseTypeActionSchema,\n ComputerUseWaitActionSchema,\n]);\n\n// Schema for the input structure received from parseComputerCall\n// The action is wrapped in an `action` property: { action: { type: 'screenshot' } }\nexport const ComputerUseActionSchema = z.object({\n action: ComputerUseActionUnionSchema,\n});\n\n// TypeScript types derived from Zod schemas\nexport type ComputerUseScreenshotActionType = z.infer<\n typeof ComputerUseScreenshotActionSchema\n>;\nexport type ComputerUseClickActionType = z.infer<\n typeof ComputerUseClickActionSchema\n>;\nexport type ComputerUseDoubleClickActionType = z.infer<\n typeof ComputerUseDoubleClickActionSchema\n>;\nexport type ComputerUseDragActionType = z.infer<\n typeof ComputerUseDragActionSchema\n>;\nexport type ComputerUseKeypressActionType = z.infer<\n typeof ComputerUseKeypressActionSchema\n>;\nexport type ComputerUseMoveActionType = z.infer<\n typeof ComputerUseMoveActionSchema\n>;\nexport type ComputerUseScrollActionType = z.infer<\n typeof ComputerUseScrollActionSchema\n>;\nexport type ComputerUseTypeActionType = z.infer<\n typeof ComputerUseTypeActionSchema\n>;\nexport type ComputerUseWaitActionType = z.infer<\n typeof ComputerUseWaitActionSchema\n>;\n\n/**\n * Input structure for the Computer Use tool.\n * The action is wrapped in an `action` property.\n */\nexport interface ComputerUseInput {\n action: ComputerUseAction;\n}\n\nexport type ComputerUseReturnType =\n | string\n | Promise<string>\n | ToolMessage<any>\n | Promise<ToolMessage<any>>;\n\n/**\n * Options for the Computer Use tool.\n */\nexport interface ComputerUseOptions {\n /**\n * The width of the computer display in pixels.\n */\n displayWidth: number;\n\n /**\n * The height of the computer display in pixels.\n */\n displayHeight: number;\n\n /**\n * The type of computer environment to control.\n * - `browser`: Browser automation (recommended for most use cases)\n * - `mac`: macOS environment\n * - `windows`: Windows environment\n * - `linux`: Linux environment\n * - `ubuntu`: Ubuntu environment\n */\n environment: ComputerUseEnvironment;\n\n /**\n * Execute function that handles computer action execution.\n * This function receives the action input and should return a base64-encoded\n * screenshot of the result.\n */\n execute: (\n action: ComputerUseAction,\n runtime: ToolRuntime<any, any>\n ) => ComputerUseReturnType;\n}\n\n/**\n * OpenAI Computer Use tool type for the Responses API.\n */\nexport type ComputerUseTool = OpenAIClient.Responses.ComputerTool;\n\nconst TOOL_NAME = \"computer_use\";\n\n/**\n * Creates a Computer Use tool that allows models to control computer interfaces\n * and perform tasks by simulating mouse clicks, keyboard input, scrolling, and more.\n *\n * **Computer Use** is a practical application of OpenAI's Computer-Using Agent (CUA)\n * model (`computer-use-preview`), which combines vision capabilities with advanced\n * reasoning to simulate controlling computer interfaces.\n *\n * **How it works**:\n * The tool operates in a continuous loop:\n * 1. Model sends computer actions (click, type, scroll, etc.)\n * 2. Your code executes these actions in a controlled environment\n * 3. You capture a screenshot of the result\n * 4. Send the screenshot back to the model\n * 5. Repeat until the task is complete\n *\n * **Important**: Computer use is in beta and requires careful consideration:\n * - Use in sandboxed environments only\n * - Do not use for high-stakes or authenticated tasks\n * - Always implement human-in-the-loop for important decisions\n * - Handle safety checks appropriately\n *\n * @see {@link https://platform.openai.com/docs/guides/tools-computer-use | OpenAI Computer Use Documentation}\n *\n * @param options - Configuration options for the Computer Use tool\n * @returns A Computer Use tool that can be passed to `bindTools`\n *\n * @example\n * ```typescript\n * import { ChatOpenAI, tools } from \"@langchain/openai\";\n *\n * const model = new ChatOpenAI({ model: \"computer-use-preview\" });\n *\n * // With execute callback for automatic action handling\n * const computer = tools.computerUse({\n * displayWidth: 1024,\n * displayHeight: 768,\n * environment: \"browser\",\n * execute: async (action) => {\n * if (action.type === \"screenshot\") {\n * return captureScreenshot();\n * }\n * if (action.type === \"click\") {\n * await page.mouse.click(action.x, action.y, { button: action.button });\n * return captureScreenshot();\n * }\n * if (action.type === \"type\") {\n * await page.keyboard.type(action.text);\n * return captureScreenshot();\n * }\n * // Handle other actions...\n * return captureScreenshot();\n * },\n * });\n *\n * const llmWithComputer = model.bindTools([computer]);\n * const response = await llmWithComputer.invoke(\n * \"Check the latest news on bing.com\"\n * );\n * ```\n *\n * @example\n * ```typescript\n * // Without execute callback (manual action handling)\n * const computer = tools.computerUse({\n * displayWidth: 1024,\n * displayHeight: 768,\n * environment: \"browser\",\n * });\n *\n * const response = await model.invoke(\"Check the news\", {\n * tools: [computer],\n * });\n *\n * // Access the computer call from the response\n * const computerCall = response.additional_kwargs.tool_outputs?.find(\n * (output) => output.type === \"computer_call\"\n * );\n * if (computerCall) {\n * console.log(\"Action to execute:\", computerCall.action);\n * // Execute the action manually, then send back a screenshot\n * }\n * ```\n *\n * @example\n * ```typescript\n * // For macOS desktop automation with Docker\n * const computer = tools.computerUse({\n * displayWidth: 1920,\n * displayHeight: 1080,\n * environment: \"mac\",\n * execute: async (action) => {\n * if (action.type === \"click\") {\n * await dockerExec(\n * `DISPLAY=:99 xdotool mousemove ${action.x} ${action.y} click 1`,\n * containerName\n * );\n * }\n * // Capture screenshot from container\n * return await getDockerScreenshot(containerName);\n * },\n * });\n * ```\n *\n * @remarks\n * - Only available through the Responses API (not Chat Completions)\n * - Requires `computer-use-preview` model\n * - Actions include: click, double_click, drag, keypress, move, screenshot, scroll, type, wait\n * - Safety checks may be returned that require acknowledgment before proceeding\n * - Use `truncation: \"auto\"` parameter when making requests\n * - Recommended to use with `reasoning.summary` for debugging\n */\nexport function computerUse(options: ComputerUseOptions) {\n const computerTool = tool(\n async (\n input: ComputerUseInput,\n runtime: ToolRuntime<{ messages: BaseMessage[] }>\n ) => {\n /**\n * get computer_use call id from runtime\n */\n const aiMessage = runtime.state?.messages.at(-1) as AIMessage | undefined;\n const computerToolCall = aiMessage?.tool_calls?.find(\n (tc) => tc.name === \"computer_use\"\n );\n const computerToolCallId = computerToolCall?.id;\n if (!computerToolCallId) {\n throw new Error(\"Computer use call id not found\");\n }\n\n const result = await options.execute(input.action, runtime);\n\n /**\n * make sure {@link ToolMessage} is returned with the correct additional kwargs\n */\n if (typeof result === \"string\") {\n return new ToolMessage({\n content: result,\n tool_call_id: computerToolCallId,\n additional_kwargs: {\n type: \"computer_call_output\",\n },\n });\n }\n\n /**\n * make sure {@link ToolMessage} is returned with the correct additional kwargs\n */\n return new ToolMessage({\n ...result,\n tool_call_id: computerToolCallId,\n additional_kwargs: {\n type: \"computer_call_output\",\n ...result.additional_kwargs,\n },\n });\n },\n {\n name: TOOL_NAME,\n description:\n \"Control a computer interface by executing mouse clicks, keyboard input, scrolling, and other actions.\",\n schema: ComputerUseActionSchema,\n }\n );\n\n computerTool.extras = {\n ...(computerTool.extras ?? {}),\n providerToolDefinition: {\n type: \"computer_use_preview\",\n display_width: options.displayWidth,\n display_height: options.displayHeight,\n environment: options.environment,\n } satisfies ComputerUseTool,\n };\n\n /**\n * return as typed {@link DynamicStructuredTool} so we don't get any type\n * errors like \"can't export tool without reference\"\n */\n return computerTool as DynamicStructuredTool<\n typeof ComputerUseActionSchema,\n ComputerUseInput,\n unknown,\n ComputerUseReturnType\n >;\n}\n"],"mappings":";;;;;;AAkDA,MAAM,oCAAoCA,SAAE,OAAO,EACjD,MAAMA,SAAE,QAAQ,aAAa,CAC9B,EAAC;AAEF,MAAM,+BAA+BA,SAAE,OAAO;CAC5C,MAAMA,SAAE,QAAQ,QAAQ;CACxB,GAAGA,SAAE,QAAQ;CACb,GAAGA,SAAE,QAAQ;CACb,QAAQA,SAAE,KAAK;EAAC;EAAQ;EAAS;EAAS;EAAQ;CAAU,EAAC,CAAC,QAAQ,OAAO;AAC9E,EAAC;AAEF,MAAM,qCAAqCA,SAAE,OAAO;CAClD,MAAMA,SAAE,QAAQ,eAAe;CAC/B,GAAGA,SAAE,QAAQ;CACb,GAAGA,SAAE,QAAQ;CACb,QAAQA,SAAE,KAAK;EAAC;EAAQ;EAAS;EAAS;EAAQ;CAAU,EAAC,CAAC,QAAQ,OAAO;AAC9E,EAAC;AAEF,MAAM,8BAA8BA,SAAE,OAAO;CAC3C,MAAMA,SAAE,QAAQ,OAAO;CACvB,MAAMA,SAAE,MAAMA,SAAE,OAAO;EAAE,GAAGA,SAAE,QAAQ;EAAE,GAAGA,SAAE,QAAQ;CAAE,EAAC,CAAC;AAC1D,EAAC;AAEF,MAAM,kCAAkCA,SAAE,OAAO;CAC/C,MAAMA,SAAE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Q;;;;AAK3D,MAAI,OAAO,WAAW,SACpB,QAAO,IAAIC,sCAAY;GACrB,SAAS;GACT,cAAc;GACd,mBAAmB,EACjB,MAAM,uBACP;EACF;;;;AAMH,SAAO,IAAIA,sCAAY;GACrB,GAAG;GACH,cAAc;GACd,mBAAmB;IACjB,MAAM;IACN,GAAG,OAAO;GACX;EACF;CACF,GACD;EACE,MAAM;EACN,aACE;EACF,QAAQ;CACT,EACF;CAED,aAAa,SAAS;EACpB,GAAI,aAAa,UAAU,CAAE;EAC7B,wBAAwB;GACtB,MAAM;GACN,eAAe,QAAQ;GACvB,gBAAgB,QAAQ;GACxB,aAAa,QAAQ;EACtB;CACF;;;;;AAMD,QAAO;AAMR"}
@@ -178,7 +178,7 @@ type ComputerUseTool = OpenAI$1.Responses.ComputerTool;
178
178
  * - Recommended to use with `reasoning.summary` for debugging
179
179
  */
180
180
  declare function computerUse(options: ComputerUseOptions): DynamicStructuredTool<z.ZodObject<{
181
- action: z.ZodDiscriminatedUnion<[z.ZodObject<{
181
+ action: z.ZodUnion<readonly [z.ZodObject<{
182
182
  type: z.ZodLiteral<"screenshot">;
183
183
  }, z.core.$strip>, z.ZodObject<{
184
184
  type: z.ZodLiteral<"click">;
@@ -1 +1 @@
1
- {"version":3,"file":"computerUse.d.cts","names":["z","OpenAI","OpenAIClient","DynamicStructuredTool","ToolRuntime","ToolMessage","ComputerUseEnvironment","ComputerUseClickAction","Responses","ResponseComputerToolCall","Click","ComputerUseDoubleClickAction","DoubleClick","ComputerUseDragAction","Drag","ComputerUseKeypressAction","Keypress","ComputerUseMoveAction","Move","ComputerUseScreenshotAction","Screenshot","ComputerUseScrollAction","Scroll","ComputerUseTypeAction","Type","ComputerUseWaitAction","Wait","ComputerUseAction","ComputerUseScreenshotActionSchema","ZodLiteral","core","$strip","ZodObject","ComputerUseClickActionSchema","ZodNumber","ZodEnum","ZodDefault","ComputerUseDoubleClickActionSchema","ComputerUseDragActionSchema","ZodArray","ComputerUseKeypressActionSchema","ZodString","ComputerUseMoveActionSchema","ComputerUseScrollActionSchema","ComputerUseTypeActionSchema","ComputerUseWaitActionSchema","ZodOptional","ComputerUseActionSchema","ZodDiscriminatedUnion","ComputerUseScreenshotActionType","infer","ComputerUseClickActionType","ComputerUseDoubleClickActionType","ComputerUseDragActionType","ComputerUseKeypressActionType","ComputerUseMoveActionType","ComputerUseScrollActionType","ComputerUseTypeActionType","ComputerUseWaitActionType","ComputerUseInput","ComputerUseReturnType","Promise","ComputerUseOptions","ComputerUseTool","ComputerTool","computerUse"],"sources":["../../src/tools/computerUse.d.ts"],"sourcesContent":["import { z } from \"zod/v4\";\nimport { OpenAI as OpenAIClient } from \"openai\";\nimport { type DynamicStructuredTool } from \"@langchain/core/tools\";\nimport { type ToolRuntime } from \"@langchain/core/tools\";\nimport { ToolMessage } from \"@langchain/core/messages\";\n/**\n * The type of computer environment to control.\n */\nexport type ComputerUseEnvironment = \"browser\" | \"mac\" | \"windows\" | \"linux\" | \"ubuntu\";\n/**\n * Re-export action types from OpenAI SDK for convenience.\n */\nexport type ComputerUseClickAction = OpenAIClient.Responses.ResponseComputerToolCall.Click;\nexport type ComputerUseDoubleClickAction = OpenAIClient.Responses.ResponseComputerToolCall.DoubleClick;\nexport type ComputerUseDragAction = OpenAIClient.Responses.ResponseComputerToolCall.Drag;\nexport type ComputerUseKeypressAction = OpenAIClient.Responses.ResponseComputerToolCall.Keypress;\nexport type ComputerUseMoveAction = OpenAIClient.Responses.ResponseComputerToolCall.Move;\nexport type ComputerUseScreenshotAction = OpenAIClient.Responses.ResponseComputerToolCall.Screenshot;\nexport type ComputerUseScrollAction = OpenAIClient.Responses.ResponseComputerToolCall.Scroll;\nexport type ComputerUseTypeAction = OpenAIClient.Responses.ResponseComputerToolCall.Type;\nexport type ComputerUseWaitAction = OpenAIClient.Responses.ResponseComputerToolCall.Wait;\n/**\n * Union type of all computer use actions from OpenAI SDK.\n */\nexport type ComputerUseAction = OpenAIClient.Responses.ResponseComputerToolCall[\"action\"];\ndeclare const ComputerUseScreenshotActionSchema: z.ZodObject<{\n type: z.ZodLiteral<\"screenshot\">;\n}, z.core.$strip>;\ndeclare const ComputerUseClickActionSchema: z.ZodObject<{\n type: z.ZodLiteral<\"click\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n button: z.ZodDefault<z.ZodEnum<{\n back: \"back\";\n forward: \"forward\";\n left: \"left\";\n right: \"right\";\n wheel: \"wheel\";\n }>>;\n}, z.core.$strip>;\ndeclare const ComputerUseDoubleClickActionSchema: z.ZodObject<{\n type: z.ZodLiteral<\"double_click\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n button: z.ZodDefault<z.ZodEnum<{\n back: \"back\";\n forward: \"forward\";\n left: \"left\";\n right: \"right\";\n wheel: \"wheel\";\n }>>;\n}, z.core.$strip>;\ndeclare const ComputerUseDragActionSchema: z.ZodObject<{\n type: z.ZodLiteral<\"drag\">;\n path: z.ZodArray<z.ZodObject<{\n x: z.ZodNumber;\n y: z.ZodNumber;\n }, z.core.$strip>>;\n}, z.core.$strip>;\ndeclare const ComputerUseKeypressActionSchema: z.ZodObject<{\n type: z.ZodLiteral<\"keypress\">;\n keys: z.ZodArray<z.ZodString>;\n}, z.core.$strip>;\ndeclare const ComputerUseMoveActionSchema: z.ZodObject<{\n type: z.ZodLiteral<\"move\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n}, z.core.$strip>;\ndeclare const ComputerUseScrollActionSchema: z.ZodObject<{\n type: z.ZodLiteral<\"scroll\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n scroll_x: z.ZodNumber;\n scroll_y: z.ZodNumber;\n}, z.core.$strip>;\ndeclare const ComputerUseTypeActionSchema: z.ZodObject<{\n type: z.ZodLiteral<\"type\">;\n text: z.ZodString;\n}, z.core.$strip>;\ndeclare const ComputerUseWaitActionSchema: z.ZodObject<{\n type: z.ZodLiteral<\"wait\">;\n duration: z.ZodOptional<z.ZodNumber>;\n}, z.core.$strip>;\nexport declare const ComputerUseActionSchema: z.ZodObject<{\n action: z.ZodDiscriminatedUnion<[z.ZodObject<{\n type: z.ZodLiteral<\"screenshot\">;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"click\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n button: z.ZodDefault<z.ZodEnum<{\n back: \"back\";\n forward: \"forward\";\n left: \"left\";\n right: \"right\";\n wheel: \"wheel\";\n }>>;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"double_click\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n button: z.ZodDefault<z.ZodEnum<{\n back: \"back\";\n forward: \"forward\";\n left: \"left\";\n right: \"right\";\n wheel: \"wheel\";\n }>>;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"drag\">;\n path: z.ZodArray<z.ZodObject<{\n x: z.ZodNumber;\n y: z.ZodNumber;\n }, z.core.$strip>>;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"keypress\">;\n keys: z.ZodArray<z.ZodString>;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"move\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"scroll\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n scroll_x: z.ZodNumber;\n scroll_y: z.ZodNumber;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"type\">;\n text: z.ZodString;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"wait\">;\n duration: z.ZodOptional<z.ZodNumber>;\n }, z.core.$strip>]>;\n}, z.core.$strip>;\nexport type ComputerUseScreenshotActionType = z.infer<typeof ComputerUseScreenshotActionSchema>;\nexport type ComputerUseClickActionType = z.infer<typeof ComputerUseClickActionSchema>;\nexport type ComputerUseDoubleClickActionType = z.infer<typeof ComputerUseDoubleClickActionSchema>;\nexport type ComputerUseDragActionType = z.infer<typeof ComputerUseDragActionSchema>;\nexport type ComputerUseKeypressActionType = z.infer<typeof ComputerUseKeypressActionSchema>;\nexport type ComputerUseMoveActionType = z.infer<typeof ComputerUseMoveActionSchema>;\nexport type ComputerUseScrollActionType = z.infer<typeof ComputerUseScrollActionSchema>;\nexport type ComputerUseTypeActionType = z.infer<typeof ComputerUseTypeActionSchema>;\nexport type ComputerUseWaitActionType = z.infer<typeof ComputerUseWaitActionSchema>;\n/**\n * Input structure for the Computer Use tool.\n * The action is wrapped in an `action` property.\n */\nexport interface ComputerUseInput {\n action: ComputerUseAction;\n}\nexport type ComputerUseReturnType = string | Promise<string> | ToolMessage<any> | Promise<ToolMessage<any>>;\n/**\n * Options for the Computer Use tool.\n */\nexport interface ComputerUseOptions {\n /**\n * The width of the computer display in pixels.\n */\n displayWidth: number;\n /**\n * The height of the computer display in pixels.\n */\n displayHeight: number;\n /**\n * The type of computer environment to control.\n * - `browser`: Browser automation (recommended for most use cases)\n * - `mac`: macOS environment\n * - `windows`: Windows environment\n * - `linux`: Linux environment\n * - `ubuntu`: Ubuntu environment\n */\n environment: ComputerUseEnvironment;\n /**\n * Execute function that handles computer action execution.\n * This function receives the action input and should return a base64-encoded\n * screenshot of the result.\n */\n execute: (action: ComputerUseAction, runtime: ToolRuntime<any, any>) => ComputerUseReturnType;\n}\n/**\n * OpenAI Computer Use tool type for the Responses API.\n */\nexport type ComputerUseTool = OpenAIClient.Responses.ComputerTool;\n/**\n * Creates a Computer Use tool that allows models to control computer interfaces\n * and perform tasks by simulating mouse clicks, keyboard input, scrolling, and more.\n *\n * **Computer Use** is a practical application of OpenAI's Computer-Using Agent (CUA)\n * model (`computer-use-preview`), which combines vision capabilities with advanced\n * reasoning to simulate controlling computer interfaces.\n *\n * **How it works**:\n * The tool operates in a continuous loop:\n * 1. Model sends computer actions (click, type, scroll, etc.)\n * 2. Your code executes these actions in a controlled environment\n * 3. You capture a screenshot of the result\n * 4. Send the screenshot back to the model\n * 5. Repeat until the task is complete\n *\n * **Important**: Computer use is in beta and requires careful consideration:\n * - Use in sandboxed environments only\n * - Do not use for high-stakes or authenticated tasks\n * - Always implement human-in-the-loop for important decisions\n * - Handle safety checks appropriately\n *\n * @see {@link https://platform.openai.com/docs/guides/tools-computer-use | OpenAI Computer Use Documentation}\n *\n * @param options - Configuration options for the Computer Use tool\n * @returns A Computer Use tool that can be passed to `bindTools`\n *\n * @example\n * ```typescript\n * import { ChatOpenAI, tools } from \"@langchain/openai\";\n *\n * const model = new ChatOpenAI({ model: \"computer-use-preview\" });\n *\n * // With execute callback for automatic action handling\n * const computer = tools.computerUse({\n * displayWidth: 1024,\n * displayHeight: 768,\n * environment: \"browser\",\n * execute: async (action) => {\n * if (action.type === \"screenshot\") {\n * return captureScreenshot();\n * }\n * if (action.type === \"click\") {\n * await page.mouse.click(action.x, action.y, { button: action.button });\n * return captureScreenshot();\n * }\n * if (action.type === \"type\") {\n * await page.keyboard.type(action.text);\n * return captureScreenshot();\n * }\n * // Handle other actions...\n * return captureScreenshot();\n * },\n * });\n *\n * const llmWithComputer = model.bindTools([computer]);\n * const response = await llmWithComputer.invoke(\n * \"Check the latest news on bing.com\"\n * );\n * ```\n *\n * @example\n * ```typescript\n * // Without execute callback (manual action handling)\n * const computer = tools.computerUse({\n * displayWidth: 1024,\n * displayHeight: 768,\n * environment: \"browser\",\n * });\n *\n * const response = await model.invoke(\"Check the news\", {\n * tools: [computer],\n * });\n *\n * // Access the computer call from the response\n * const computerCall = response.additional_kwargs.tool_outputs?.find(\n * (output) => output.type === \"computer_call\"\n * );\n * if (computerCall) {\n * console.log(\"Action to execute:\", computerCall.action);\n * // Execute the action manually, then send back a screenshot\n * }\n * ```\n *\n * @example\n * ```typescript\n * // For macOS desktop automation with Docker\n * const computer = tools.computerUse({\n * displayWidth: 1920,\n * displayHeight: 1080,\n * environment: \"mac\",\n * execute: async (action) => {\n * if (action.type === \"click\") {\n * await dockerExec(\n * `DISPLAY=:99 xdotool mousemove ${action.x} ${action.y} click 1`,\n * containerName\n * );\n * }\n * // Capture screenshot from container\n * return await getDockerScreenshot(containerName);\n * },\n * });\n * ```\n *\n * @remarks\n * - Only available through the Responses API (not Chat Completions)\n * - Requires `computer-use-preview` model\n * - Actions include: click, double_click, drag, keypress, move, screenshot, scroll, type, wait\n * - Safety checks may be returned that require acknowledgment before proceeding\n * - Use `truncation: \"auto\"` parameter when making requests\n * - Recommended to use with `reasoning.summary` for debugging\n */\nexport declare function computerUse(options: ComputerUseOptions): DynamicStructuredTool<z.ZodObject<{\n action: z.ZodDiscriminatedUnion<[z.ZodObject<{\n type: z.ZodLiteral<\"screenshot\">;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"click\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n button: z.ZodDefault<z.ZodEnum<{\n back: \"back\";\n forward: \"forward\";\n left: \"left\";\n right: \"right\";\n wheel: \"wheel\";\n }>>;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"double_click\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n button: z.ZodDefault<z.ZodEnum<{\n back: \"back\";\n forward: \"forward\";\n left: \"left\";\n right: \"right\";\n wheel: \"wheel\";\n }>>;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"drag\">;\n path: z.ZodArray<z.ZodObject<{\n x: z.ZodNumber;\n y: z.ZodNumber;\n }, z.core.$strip>>;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"keypress\">;\n keys: z.ZodArray<z.ZodString>;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"move\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"scroll\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n scroll_x: z.ZodNumber;\n scroll_y: z.ZodNumber;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"type\">;\n text: z.ZodString;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"wait\">;\n duration: z.ZodOptional<z.ZodNumber>;\n }, z.core.$strip>]>;\n}, z.core.$strip>, ComputerUseInput, unknown, ComputerUseReturnType, string>;\nexport {};\n//# sourceMappingURL=computerUse.d.ts.map"],"mappings":";;;;;;;;AAQA;AAIA;AACYW,KALAL,sBAAAA,GAK4B,SAAA,GAAGJ,KAAAA,GAAaM,SAAAA,GAAUC,OAAAA,GAAAA,QAAAA;AAClE;AACA;AACA;AACYU,KALAZ,sBAAAA,GAAyBL,QAAAA,CAAaM,SAAAA,CAAUC,wBAAAA,CAAyBC,KAKpBD;AACrDY,KALAV,4BAAAA,GAA+BT,QAAAA,CAAaM,SAAAA,CAAUC,wBAAAA,CAAyBG,WAKC;AAChFW,KALAV,qBAAAA,GAAwBX,QAAAA,CAAaM,SAAAA,CAAUC,wBAAAA,CAAyBK,IAKAU;AACxEC,KALAV,yBAAAA,GAA4Bb,QAAAA,CAAaM,SAAAA,CAAUC,wBAAAA,CAAyBO,QAKA;AAI5EW,KARAV,qBAAAA,GAAwBf,QAAAA,CAAaM,SAAAA,CAAUC,wBAAAA,CAAyBS,IAQL;AA4H9DyC,KAnILxC,2BAAAA,GAA8BjB,QAAAA,CAAaM,SAAAA,CAAUC,wBAAAA,CAAyBW,UAoI7D;AAEjBwC,KArIAvC,uBAAAA,GAA0BnB,QAAAA,CAAaM,SAAAA,CAAUC,wBAAAA,CAAyBa,MAqIrD;AAAYuC,KApIjCtC,qBAAAA,GAAwBrB,QAAAA,CAAaM,SAAAA,CAAUC,wBAAAA,CAAyBe,IAoIvCqC;AAAkBxD,KAnInDoB,qBAAAA,GAAwBvB,QAAAA,CAAaM,SAAAA,CAAUC,wBAAAA,CAAyBiB,IAmIrBrB;;;AAA0B;AAIxEyD,KAnILnC,iBAAAA,GAAoBzB,QAAAA,CAAaM,SAAAA,CAAUC,wBAmIpB,CAAA,QAAA,CAAA;;;;;UAPlBkD,gBAAAA;UACLhC;;KAEAiC,qBAAAA,YAAiCC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ACXhC,CAAAA,CAAE6B;OACL7B,CAAAA,CAAEkC;OACFlC,CAAAA,CAAEkC;KACNlC,CAAAA,CAAE8B,IAAAA,CAAKC,SAAS/B,CAAAA,CAAEgC;UACXhC,CAAAA,CAAE6B;OACL7B,CAAAA,CAAEkC;OACFlC,CAAAA,CAAEkC;cACKlC,CAAAA,CAAEkC;cACFlC,CAAAA,CAAEkC;KACblC,CAAAA,CAAE8B,IAAAA,CAAKC,SAAS/B,CAAAA,CAAEgC;UACXhC,CAAAA,CAAE6B;UACF7B,CAAAA,CAAEyC;KACTzC,CAAAA,CAAE8B,IAAAA,CAAKC,SAAS/B,CAAAA,CAAEgC;UACXhC,CAAAA,CAAE6B;cACE7B,CAAAA,CAAE8C,YAAY9C,CAAAA,CAAEkC;KAC3BlC,CAAAA,CAAE8B,IAAAA,CAAKC;GACX/B,CAAAA,CAAE8B,IAAAA,CAAKC,SAAS4B,2BAA2BC"}
1
+ {"version":3,"file":"computerUse.d.cts","names":["z","OpenAI","OpenAIClient","DynamicStructuredTool","ToolRuntime","ToolMessage","ComputerUseEnvironment","ComputerUseClickAction","Responses","ResponseComputerToolCall","Click","ComputerUseDoubleClickAction","DoubleClick","ComputerUseDragAction","Drag","ComputerUseKeypressAction","Keypress","ComputerUseMoveAction","Move","ComputerUseScreenshotAction","Screenshot","ComputerUseScrollAction","Scroll","ComputerUseTypeAction","Type","ComputerUseWaitAction","Wait","ComputerUseAction","ComputerUseScreenshotActionSchema","ZodLiteral","core","$strip","ZodObject","ComputerUseClickActionSchema","ZodNumber","ZodEnum","ZodDefault","ComputerUseDoubleClickActionSchema","ComputerUseDragActionSchema","ZodArray","ComputerUseKeypressActionSchema","ZodString","ComputerUseMoveActionSchema","ComputerUseScrollActionSchema","ComputerUseTypeActionSchema","ComputerUseWaitActionSchema","ZodOptional","ComputerUseActionSchema","ZodUnion","ComputerUseScreenshotActionType","infer","ComputerUseClickActionType","ComputerUseDoubleClickActionType","ComputerUseDragActionType","ComputerUseKeypressActionType","ComputerUseMoveActionType","ComputerUseScrollActionType","ComputerUseTypeActionType","ComputerUseWaitActionType","ComputerUseInput","ComputerUseReturnType","Promise","ComputerUseOptions","ComputerUseTool","ComputerTool","computerUse"],"sources":["../../src/tools/computerUse.d.ts"],"sourcesContent":["import { z } from \"zod/v4\";\nimport { OpenAI as OpenAIClient } from \"openai\";\nimport { type DynamicStructuredTool } from \"@langchain/core/tools\";\nimport { type ToolRuntime } from \"@langchain/core/tools\";\nimport { ToolMessage } from \"@langchain/core/messages\";\n/**\n * The type of computer environment to control.\n */\nexport type ComputerUseEnvironment = \"browser\" | \"mac\" | \"windows\" | \"linux\" | \"ubuntu\";\n/**\n * Re-export action types from OpenAI SDK for convenience.\n */\nexport type ComputerUseClickAction = OpenAIClient.Responses.ResponseComputerToolCall.Click;\nexport type ComputerUseDoubleClickAction = OpenAIClient.Responses.ResponseComputerToolCall.DoubleClick;\nexport type ComputerUseDragAction = OpenAIClient.Responses.ResponseComputerToolCall.Drag;\nexport type ComputerUseKeypressAction = OpenAIClient.Responses.ResponseComputerToolCall.Keypress;\nexport type ComputerUseMoveAction = OpenAIClient.Responses.ResponseComputerToolCall.Move;\nexport type ComputerUseScreenshotAction = OpenAIClient.Responses.ResponseComputerToolCall.Screenshot;\nexport type ComputerUseScrollAction = OpenAIClient.Responses.ResponseComputerToolCall.Scroll;\nexport type ComputerUseTypeAction = OpenAIClient.Responses.ResponseComputerToolCall.Type;\nexport type ComputerUseWaitAction = OpenAIClient.Responses.ResponseComputerToolCall.Wait;\n/**\n * Union type of all computer use actions from OpenAI SDK.\n */\nexport type ComputerUseAction = OpenAIClient.Responses.ResponseComputerToolCall[\"action\"];\ndeclare const ComputerUseScreenshotActionSchema: z.ZodObject<{\n type: z.ZodLiteral<\"screenshot\">;\n}, z.core.$strip>;\ndeclare const ComputerUseClickActionSchema: z.ZodObject<{\n type: z.ZodLiteral<\"click\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n button: z.ZodDefault<z.ZodEnum<{\n back: \"back\";\n forward: \"forward\";\n left: \"left\";\n right: \"right\";\n wheel: \"wheel\";\n }>>;\n}, z.core.$strip>;\ndeclare const ComputerUseDoubleClickActionSchema: z.ZodObject<{\n type: z.ZodLiteral<\"double_click\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n button: z.ZodDefault<z.ZodEnum<{\n back: \"back\";\n forward: \"forward\";\n left: \"left\";\n right: \"right\";\n wheel: \"wheel\";\n }>>;\n}, z.core.$strip>;\ndeclare const ComputerUseDragActionSchema: z.ZodObject<{\n type: z.ZodLiteral<\"drag\">;\n path: z.ZodArray<z.ZodObject<{\n x: z.ZodNumber;\n y: z.ZodNumber;\n }, z.core.$strip>>;\n}, z.core.$strip>;\ndeclare const ComputerUseKeypressActionSchema: z.ZodObject<{\n type: z.ZodLiteral<\"keypress\">;\n keys: z.ZodArray<z.ZodString>;\n}, z.core.$strip>;\ndeclare const ComputerUseMoveActionSchema: z.ZodObject<{\n type: z.ZodLiteral<\"move\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n}, z.core.$strip>;\ndeclare const ComputerUseScrollActionSchema: z.ZodObject<{\n type: z.ZodLiteral<\"scroll\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n scroll_x: z.ZodNumber;\n scroll_y: z.ZodNumber;\n}, z.core.$strip>;\ndeclare const ComputerUseTypeActionSchema: z.ZodObject<{\n type: z.ZodLiteral<\"type\">;\n text: z.ZodString;\n}, z.core.$strip>;\ndeclare const ComputerUseWaitActionSchema: z.ZodObject<{\n type: z.ZodLiteral<\"wait\">;\n duration: z.ZodOptional<z.ZodNumber>;\n}, z.core.$strip>;\nexport declare const ComputerUseActionSchema: z.ZodObject<{\n action: z.ZodUnion<readonly [z.ZodObject<{\n type: z.ZodLiteral<\"screenshot\">;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"click\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n button: z.ZodDefault<z.ZodEnum<{\n back: \"back\";\n forward: \"forward\";\n left: \"left\";\n right: \"right\";\n wheel: \"wheel\";\n }>>;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"double_click\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n button: z.ZodDefault<z.ZodEnum<{\n back: \"back\";\n forward: \"forward\";\n left: \"left\";\n right: \"right\";\n wheel: \"wheel\";\n }>>;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"drag\">;\n path: z.ZodArray<z.ZodObject<{\n x: z.ZodNumber;\n y: z.ZodNumber;\n }, z.core.$strip>>;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"keypress\">;\n keys: z.ZodArray<z.ZodString>;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"move\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"scroll\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n scroll_x: z.ZodNumber;\n scroll_y: z.ZodNumber;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"type\">;\n text: z.ZodString;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"wait\">;\n duration: z.ZodOptional<z.ZodNumber>;\n }, z.core.$strip>]>;\n}, z.core.$strip>;\nexport type ComputerUseScreenshotActionType = z.infer<typeof ComputerUseScreenshotActionSchema>;\nexport type ComputerUseClickActionType = z.infer<typeof ComputerUseClickActionSchema>;\nexport type ComputerUseDoubleClickActionType = z.infer<typeof ComputerUseDoubleClickActionSchema>;\nexport type ComputerUseDragActionType = z.infer<typeof ComputerUseDragActionSchema>;\nexport type ComputerUseKeypressActionType = z.infer<typeof ComputerUseKeypressActionSchema>;\nexport type ComputerUseMoveActionType = z.infer<typeof ComputerUseMoveActionSchema>;\nexport type ComputerUseScrollActionType = z.infer<typeof ComputerUseScrollActionSchema>;\nexport type ComputerUseTypeActionType = z.infer<typeof ComputerUseTypeActionSchema>;\nexport type ComputerUseWaitActionType = z.infer<typeof ComputerUseWaitActionSchema>;\n/**\n * Input structure for the Computer Use tool.\n * The action is wrapped in an `action` property.\n */\nexport interface ComputerUseInput {\n action: ComputerUseAction;\n}\nexport type ComputerUseReturnType = string | Promise<string> | ToolMessage<any> | Promise<ToolMessage<any>>;\n/**\n * Options for the Computer Use tool.\n */\nexport interface ComputerUseOptions {\n /**\n * The width of the computer display in pixels.\n */\n displayWidth: number;\n /**\n * The height of the computer display in pixels.\n */\n displayHeight: number;\n /**\n * The type of computer environment to control.\n * - `browser`: Browser automation (recommended for most use cases)\n * - `mac`: macOS environment\n * - `windows`: Windows environment\n * - `linux`: Linux environment\n * - `ubuntu`: Ubuntu environment\n */\n environment: ComputerUseEnvironment;\n /**\n * Execute function that handles computer action execution.\n * This function receives the action input and should return a base64-encoded\n * screenshot of the result.\n */\n execute: (action: ComputerUseAction, runtime: ToolRuntime<any, any>) => ComputerUseReturnType;\n}\n/**\n * OpenAI Computer Use tool type for the Responses API.\n */\nexport type ComputerUseTool = OpenAIClient.Responses.ComputerTool;\n/**\n * Creates a Computer Use tool that allows models to control computer interfaces\n * and perform tasks by simulating mouse clicks, keyboard input, scrolling, and more.\n *\n * **Computer Use** is a practical application of OpenAI's Computer-Using Agent (CUA)\n * model (`computer-use-preview`), which combines vision capabilities with advanced\n * reasoning to simulate controlling computer interfaces.\n *\n * **How it works**:\n * The tool operates in a continuous loop:\n * 1. Model sends computer actions (click, type, scroll, etc.)\n * 2. Your code executes these actions in a controlled environment\n * 3. You capture a screenshot of the result\n * 4. Send the screenshot back to the model\n * 5. Repeat until the task is complete\n *\n * **Important**: Computer use is in beta and requires careful consideration:\n * - Use in sandboxed environments only\n * - Do not use for high-stakes or authenticated tasks\n * - Always implement human-in-the-loop for important decisions\n * - Handle safety checks appropriately\n *\n * @see {@link https://platform.openai.com/docs/guides/tools-computer-use | OpenAI Computer Use Documentation}\n *\n * @param options - Configuration options for the Computer Use tool\n * @returns A Computer Use tool that can be passed to `bindTools`\n *\n * @example\n * ```typescript\n * import { ChatOpenAI, tools } from \"@langchain/openai\";\n *\n * const model = new ChatOpenAI({ model: \"computer-use-preview\" });\n *\n * // With execute callback for automatic action handling\n * const computer = tools.computerUse({\n * displayWidth: 1024,\n * displayHeight: 768,\n * environment: \"browser\",\n * execute: async (action) => {\n * if (action.type === \"screenshot\") {\n * return captureScreenshot();\n * }\n * if (action.type === \"click\") {\n * await page.mouse.click(action.x, action.y, { button: action.button });\n * return captureScreenshot();\n * }\n * if (action.type === \"type\") {\n * await page.keyboard.type(action.text);\n * return captureScreenshot();\n * }\n * // Handle other actions...\n * return captureScreenshot();\n * },\n * });\n *\n * const llmWithComputer = model.bindTools([computer]);\n * const response = await llmWithComputer.invoke(\n * \"Check the latest news on bing.com\"\n * );\n * ```\n *\n * @example\n * ```typescript\n * // Without execute callback (manual action handling)\n * const computer = tools.computerUse({\n * displayWidth: 1024,\n * displayHeight: 768,\n * environment: \"browser\",\n * });\n *\n * const response = await model.invoke(\"Check the news\", {\n * tools: [computer],\n * });\n *\n * // Access the computer call from the response\n * const computerCall = response.additional_kwargs.tool_outputs?.find(\n * (output) => output.type === \"computer_call\"\n * );\n * if (computerCall) {\n * console.log(\"Action to execute:\", computerCall.action);\n * // Execute the action manually, then send back a screenshot\n * }\n * ```\n *\n * @example\n * ```typescript\n * // For macOS desktop automation with Docker\n * const computer = tools.computerUse({\n * displayWidth: 1920,\n * displayHeight: 1080,\n * environment: \"mac\",\n * execute: async (action) => {\n * if (action.type === \"click\") {\n * await dockerExec(\n * `DISPLAY=:99 xdotool mousemove ${action.x} ${action.y} click 1`,\n * containerName\n * );\n * }\n * // Capture screenshot from container\n * return await getDockerScreenshot(containerName);\n * },\n * });\n * ```\n *\n * @remarks\n * - Only available through the Responses API (not Chat Completions)\n * - Requires `computer-use-preview` model\n * - Actions include: click, double_click, drag, keypress, move, screenshot, scroll, type, wait\n * - Safety checks may be returned that require acknowledgment before proceeding\n * - Use `truncation: \"auto\"` parameter when making requests\n * - Recommended to use with `reasoning.summary` for debugging\n */\nexport declare function computerUse(options: ComputerUseOptions): DynamicStructuredTool<z.ZodObject<{\n action: z.ZodUnion<readonly [z.ZodObject<{\n type: z.ZodLiteral<\"screenshot\">;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"click\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n button: z.ZodDefault<z.ZodEnum<{\n back: \"back\";\n forward: \"forward\";\n left: \"left\";\n right: \"right\";\n wheel: \"wheel\";\n }>>;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"double_click\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n button: z.ZodDefault<z.ZodEnum<{\n back: \"back\";\n forward: \"forward\";\n left: \"left\";\n right: \"right\";\n wheel: \"wheel\";\n }>>;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"drag\">;\n path: z.ZodArray<z.ZodObject<{\n x: z.ZodNumber;\n y: z.ZodNumber;\n }, z.core.$strip>>;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"keypress\">;\n keys: z.ZodArray<z.ZodString>;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"move\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"scroll\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n scroll_x: z.ZodNumber;\n scroll_y: z.ZodNumber;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"type\">;\n text: z.ZodString;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"wait\">;\n duration: z.ZodOptional<z.ZodNumber>;\n }, z.core.$strip>]>;\n}, z.core.$strip>, ComputerUseInput, unknown, ComputerUseReturnType, string>;\nexport {};\n//# sourceMappingURL=computerUse.d.ts.map"],"mappings":";;;;;;;;AAQA;AAIA;AACYW,KALAL,sBAAAA,GAK4B,SA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CAAEkC;cACFlC,CAAAA,CAAEkC;KACblC,CAAAA,CAAE8B,IAAAA,CAAKC,SAAS/B,CAAAA,CAAEgC;UACXhC,CAAAA,CAAE6B;UACF7B,CAAAA,CAAEyC;KACTzC,CAAAA,CAAE8B,IAAAA,CAAKC,SAAS/B,CAAAA,CAAEgC;UACXhC,CAAAA,CAAE6B;cACE7B,CAAAA,CAAE8C,YAAY9C,CAAAA,CAAEkC;KAC3BlC,CAAAA,CAAE8B,IAAAA,CAAKC;GACX/B,CAAAA,CAAE8B,IAAAA,CAAKC,SAAS4B,2BAA2BC"}
@@ -178,7 +178,7 @@ type ComputerUseTool = OpenAI$1.Responses.ComputerTool;
178
178
  * - Recommended to use with `reasoning.summary` for debugging
179
179
  */
180
180
  declare function computerUse(options: ComputerUseOptions): DynamicStructuredTool<z.ZodObject<{
181
- action: z.ZodDiscriminatedUnion<[z.ZodObject<{
181
+ action: z.ZodUnion<readonly [z.ZodObject<{
182
182
  type: z.ZodLiteral<"screenshot">;
183
183
  }, z.core.$strip>, z.ZodObject<{
184
184
  type: z.ZodLiteral<"click">;
@@ -1 +1 @@
1
- {"version":3,"file":"computerUse.d.ts","names":["z","OpenAI","OpenAIClient","DynamicStructuredTool","ToolRuntime","ToolMessage","ComputerUseEnvironment","ComputerUseClickAction","Responses","ResponseComputerToolCall","Click","ComputerUseDoubleClickAction","DoubleClick","ComputerUseDragAction","Drag","ComputerUseKeypressAction","Keypress","ComputerUseMoveAction","Move","ComputerUseScreenshotAction","Screenshot","ComputerUseScrollAction","Scroll","ComputerUseTypeAction","Type","ComputerUseWaitAction","Wait","ComputerUseAction","ComputerUseScreenshotActionSchema","ZodLiteral","core","$strip","ZodObject","ComputerUseClickActionSchema","ZodNumber","ZodEnum","ZodDefault","ComputerUseDoubleClickActionSchema","ComputerUseDragActionSchema","ZodArray","ComputerUseKeypressActionSchema","ZodString","ComputerUseMoveActionSchema","ComputerUseScrollActionSchema","ComputerUseTypeActionSchema","ComputerUseWaitActionSchema","ZodOptional","ComputerUseActionSchema","ZodDiscriminatedUnion","ComputerUseScreenshotActionType","infer","ComputerUseClickActionType","ComputerUseDoubleClickActionType","ComputerUseDragActionType","ComputerUseKeypressActionType","ComputerUseMoveActionType","ComputerUseScrollActionType","ComputerUseTypeActionType","ComputerUseWaitActionType","ComputerUseInput","ComputerUseReturnType","Promise","ComputerUseOptions","ComputerUseTool","ComputerTool","computerUse"],"sources":["../../src/tools/computerUse.d.ts"],"sourcesContent":["import { z } from \"zod/v4\";\nimport { OpenAI as OpenAIClient } from \"openai\";\nimport { type DynamicStructuredTool } from \"@langchain/core/tools\";\nimport { type ToolRuntime } from \"@langchain/core/tools\";\nimport { ToolMessage } from \"@langchain/core/messages\";\n/**\n * The type of computer environment to control.\n */\nexport type ComputerUseEnvironment = \"browser\" | \"mac\" | \"windows\" | \"linux\" | \"ubuntu\";\n/**\n * Re-export action types from OpenAI SDK for convenience.\n */\nexport type ComputerUseClickAction = OpenAIClient.Responses.ResponseComputerToolCall.Click;\nexport type ComputerUseDoubleClickAction = OpenAIClient.Responses.ResponseComputerToolCall.DoubleClick;\nexport type ComputerUseDragAction = OpenAIClient.Responses.ResponseComputerToolCall.Drag;\nexport type ComputerUseKeypressAction = OpenAIClient.Responses.ResponseComputerToolCall.Keypress;\nexport type ComputerUseMoveAction = OpenAIClient.Responses.ResponseComputerToolCall.Move;\nexport type ComputerUseScreenshotAction = OpenAIClient.Responses.ResponseComputerToolCall.Screenshot;\nexport type ComputerUseScrollAction = OpenAIClient.Responses.ResponseComputerToolCall.Scroll;\nexport type ComputerUseTypeAction = OpenAIClient.Responses.ResponseComputerToolCall.Type;\nexport type ComputerUseWaitAction = OpenAIClient.Responses.ResponseComputerToolCall.Wait;\n/**\n * Union type of all computer use actions from OpenAI SDK.\n */\nexport type ComputerUseAction = OpenAIClient.Responses.ResponseComputerToolCall[\"action\"];\ndeclare const ComputerUseScreenshotActionSchema: z.ZodObject<{\n type: z.ZodLiteral<\"screenshot\">;\n}, z.core.$strip>;\ndeclare const ComputerUseClickActionSchema: z.ZodObject<{\n type: z.ZodLiteral<\"click\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n button: z.ZodDefault<z.ZodEnum<{\n back: \"back\";\n forward: \"forward\";\n left: \"left\";\n right: \"right\";\n wheel: \"wheel\";\n }>>;\n}, z.core.$strip>;\ndeclare const ComputerUseDoubleClickActionSchema: z.ZodObject<{\n type: z.ZodLiteral<\"double_click\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n button: z.ZodDefault<z.ZodEnum<{\n back: \"back\";\n forward: \"forward\";\n left: \"left\";\n right: \"right\";\n wheel: \"wheel\";\n }>>;\n}, z.core.$strip>;\ndeclare const ComputerUseDragActionSchema: z.ZodObject<{\n type: z.ZodLiteral<\"drag\">;\n path: z.ZodArray<z.ZodObject<{\n x: z.ZodNumber;\n y: z.ZodNumber;\n }, z.core.$strip>>;\n}, z.core.$strip>;\ndeclare const ComputerUseKeypressActionSchema: z.ZodObject<{\n type: z.ZodLiteral<\"keypress\">;\n keys: z.ZodArray<z.ZodString>;\n}, z.core.$strip>;\ndeclare const ComputerUseMoveActionSchema: z.ZodObject<{\n type: z.ZodLiteral<\"move\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n}, z.core.$strip>;\ndeclare const ComputerUseScrollActionSchema: z.ZodObject<{\n type: z.ZodLiteral<\"scroll\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n scroll_x: z.ZodNumber;\n scroll_y: z.ZodNumber;\n}, z.core.$strip>;\ndeclare const ComputerUseTypeActionSchema: z.ZodObject<{\n type: z.ZodLiteral<\"type\">;\n text: z.ZodString;\n}, z.core.$strip>;\ndeclare const ComputerUseWaitActionSchema: z.ZodObject<{\n type: z.ZodLiteral<\"wait\">;\n duration: z.ZodOptional<z.ZodNumber>;\n}, z.core.$strip>;\nexport declare const ComputerUseActionSchema: z.ZodObject<{\n action: z.ZodDiscriminatedUnion<[z.ZodObject<{\n type: z.ZodLiteral<\"screenshot\">;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"click\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n button: z.ZodDefault<z.ZodEnum<{\n back: \"back\";\n forward: \"forward\";\n left: \"left\";\n right: \"right\";\n wheel: \"wheel\";\n }>>;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"double_click\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n button: z.ZodDefault<z.ZodEnum<{\n back: \"back\";\n forward: \"forward\";\n left: \"left\";\n right: \"right\";\n wheel: \"wheel\";\n }>>;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"drag\">;\n path: z.ZodArray<z.ZodObject<{\n x: z.ZodNumber;\n y: z.ZodNumber;\n }, z.core.$strip>>;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"keypress\">;\n keys: z.ZodArray<z.ZodString>;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"move\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"scroll\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n scroll_x: z.ZodNumber;\n scroll_y: z.ZodNumber;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"type\">;\n text: z.ZodString;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"wait\">;\n duration: z.ZodOptional<z.ZodNumber>;\n }, z.core.$strip>]>;\n}, z.core.$strip>;\nexport type ComputerUseScreenshotActionType = z.infer<typeof ComputerUseScreenshotActionSchema>;\nexport type ComputerUseClickActionType = z.infer<typeof ComputerUseClickActionSchema>;\nexport type ComputerUseDoubleClickActionType = z.infer<typeof ComputerUseDoubleClickActionSchema>;\nexport type ComputerUseDragActionType = z.infer<typeof ComputerUseDragActionSchema>;\nexport type ComputerUseKeypressActionType = z.infer<typeof ComputerUseKeypressActionSchema>;\nexport type ComputerUseMoveActionType = z.infer<typeof ComputerUseMoveActionSchema>;\nexport type ComputerUseScrollActionType = z.infer<typeof ComputerUseScrollActionSchema>;\nexport type ComputerUseTypeActionType = z.infer<typeof ComputerUseTypeActionSchema>;\nexport type ComputerUseWaitActionType = z.infer<typeof ComputerUseWaitActionSchema>;\n/**\n * Input structure for the Computer Use tool.\n * The action is wrapped in an `action` property.\n */\nexport interface ComputerUseInput {\n action: ComputerUseAction;\n}\nexport type ComputerUseReturnType = string | Promise<string> | ToolMessage<any> | Promise<ToolMessage<any>>;\n/**\n * Options for the Computer Use tool.\n */\nexport interface ComputerUseOptions {\n /**\n * The width of the computer display in pixels.\n */\n displayWidth: number;\n /**\n * The height of the computer display in pixels.\n */\n displayHeight: number;\n /**\n * The type of computer environment to control.\n * - `browser`: Browser automation (recommended for most use cases)\n * - `mac`: macOS environment\n * - `windows`: Windows environment\n * - `linux`: Linux environment\n * - `ubuntu`: Ubuntu environment\n */\n environment: ComputerUseEnvironment;\n /**\n * Execute function that handles computer action execution.\n * This function receives the action input and should return a base64-encoded\n * screenshot of the result.\n */\n execute: (action: ComputerUseAction, runtime: ToolRuntime<any, any>) => ComputerUseReturnType;\n}\n/**\n * OpenAI Computer Use tool type for the Responses API.\n */\nexport type ComputerUseTool = OpenAIClient.Responses.ComputerTool;\n/**\n * Creates a Computer Use tool that allows models to control computer interfaces\n * and perform tasks by simulating mouse clicks, keyboard input, scrolling, and more.\n *\n * **Computer Use** is a practical application of OpenAI's Computer-Using Agent (CUA)\n * model (`computer-use-preview`), which combines vision capabilities with advanced\n * reasoning to simulate controlling computer interfaces.\n *\n * **How it works**:\n * The tool operates in a continuous loop:\n * 1. Model sends computer actions (click, type, scroll, etc.)\n * 2. Your code executes these actions in a controlled environment\n * 3. You capture a screenshot of the result\n * 4. Send the screenshot back to the model\n * 5. Repeat until the task is complete\n *\n * **Important**: Computer use is in beta and requires careful consideration:\n * - Use in sandboxed environments only\n * - Do not use for high-stakes or authenticated tasks\n * - Always implement human-in-the-loop for important decisions\n * - Handle safety checks appropriately\n *\n * @see {@link https://platform.openai.com/docs/guides/tools-computer-use | OpenAI Computer Use Documentation}\n *\n * @param options - Configuration options for the Computer Use tool\n * @returns A Computer Use tool that can be passed to `bindTools`\n *\n * @example\n * ```typescript\n * import { ChatOpenAI, tools } from \"@langchain/openai\";\n *\n * const model = new ChatOpenAI({ model: \"computer-use-preview\" });\n *\n * // With execute callback for automatic action handling\n * const computer = tools.computerUse({\n * displayWidth: 1024,\n * displayHeight: 768,\n * environment: \"browser\",\n * execute: async (action) => {\n * if (action.type === \"screenshot\") {\n * return captureScreenshot();\n * }\n * if (action.type === \"click\") {\n * await page.mouse.click(action.x, action.y, { button: action.button });\n * return captureScreenshot();\n * }\n * if (action.type === \"type\") {\n * await page.keyboard.type(action.text);\n * return captureScreenshot();\n * }\n * // Handle other actions...\n * return captureScreenshot();\n * },\n * });\n *\n * const llmWithComputer = model.bindTools([computer]);\n * const response = await llmWithComputer.invoke(\n * \"Check the latest news on bing.com\"\n * );\n * ```\n *\n * @example\n * ```typescript\n * // Without execute callback (manual action handling)\n * const computer = tools.computerUse({\n * displayWidth: 1024,\n * displayHeight: 768,\n * environment: \"browser\",\n * });\n *\n * const response = await model.invoke(\"Check the news\", {\n * tools: [computer],\n * });\n *\n * // Access the computer call from the response\n * const computerCall = response.additional_kwargs.tool_outputs?.find(\n * (output) => output.type === \"computer_call\"\n * );\n * if (computerCall) {\n * console.log(\"Action to execute:\", computerCall.action);\n * // Execute the action manually, then send back a screenshot\n * }\n * ```\n *\n * @example\n * ```typescript\n * // For macOS desktop automation with Docker\n * const computer = tools.computerUse({\n * displayWidth: 1920,\n * displayHeight: 1080,\n * environment: \"mac\",\n * execute: async (action) => {\n * if (action.type === \"click\") {\n * await dockerExec(\n * `DISPLAY=:99 xdotool mousemove ${action.x} ${action.y} click 1`,\n * containerName\n * );\n * }\n * // Capture screenshot from container\n * return await getDockerScreenshot(containerName);\n * },\n * });\n * ```\n *\n * @remarks\n * - Only available through the Responses API (not Chat Completions)\n * - Requires `computer-use-preview` model\n * - Actions include: click, double_click, drag, keypress, move, screenshot, scroll, type, wait\n * - Safety checks may be returned that require acknowledgment before proceeding\n * - Use `truncation: \"auto\"` parameter when making requests\n * - Recommended to use with `reasoning.summary` for debugging\n */\nexport declare function computerUse(options: ComputerUseOptions): DynamicStructuredTool<z.ZodObject<{\n action: z.ZodDiscriminatedUnion<[z.ZodObject<{\n type: z.ZodLiteral<\"screenshot\">;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"click\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n button: z.ZodDefault<z.ZodEnum<{\n back: \"back\";\n forward: \"forward\";\n left: \"left\";\n right: \"right\";\n wheel: \"wheel\";\n }>>;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"double_click\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n button: z.ZodDefault<z.ZodEnum<{\n back: \"back\";\n forward: \"forward\";\n left: \"left\";\n right: \"right\";\n wheel: \"wheel\";\n }>>;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"drag\">;\n path: z.ZodArray<z.ZodObject<{\n x: z.ZodNumber;\n y: z.ZodNumber;\n }, z.core.$strip>>;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"keypress\">;\n keys: z.ZodArray<z.ZodString>;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"move\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"scroll\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n scroll_x: z.ZodNumber;\n scroll_y: z.ZodNumber;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"type\">;\n text: z.ZodString;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"wait\">;\n duration: z.ZodOptional<z.ZodNumber>;\n }, z.core.$strip>]>;\n}, z.core.$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AA,CAAE8B,IAAAA,CAAKC,SAAS/B,CAAAA,CAAEgC;UACXhC,CAAAA,CAAE6B;OACL7B,CAAAA,CAAEkC;OACFlC,CAAAA,CAAEkC;cACKlC,CAAAA,CAAEkC;cACFlC,CAAAA,CAAEkC;KACblC,CAAAA,CAAE8B,IAAAA,CAAKC,SAAS/B,CAAAA,CAAEgC;UACXhC,CAAAA,CAAE6B;UACF7B,CAAAA,CAAEyC;KACTzC,CAAAA,CAAE8B,IAAAA,CAAKC,SAAS/B,CAAAA,CAAEgC;UACXhC,CAAAA,CAAE6B;cACE7B,CAAAA,CAAE8C,YAAY9C,CAAAA,CAAEkC;KAC3BlC,CAAAA,CAAE8B,IAAAA,CAAKC;GACX/B,CAAAA,CAAE8B,IAAAA,CAAKC,SAAS4B,2BAA2BC"}
1
+ {"version":3,"file":"computerUse.d.ts","names":["z","OpenAI","OpenAIClient","DynamicStructuredTool","ToolRuntime","ToolMessage","ComputerUseEnvironment","ComputerUseClickAction","Responses","ResponseComputerToolCall","Click","ComputerUseDoubleClickAction","DoubleClick","ComputerUseDragAction","Drag","ComputerUseKeypressAction","Keypress","ComputerUseMoveAction","Move","ComputerUseScreenshotAction","Screenshot","ComputerUseScrollAction","Scroll","ComputerUseTypeAction","Type","ComputerUseWaitAction","Wait","ComputerUseAction","ComputerUseScreenshotActionSchema","ZodLiteral","core","$strip","ZodObject","ComputerUseClickActionSchema","ZodNumber","ZodEnum","ZodDefault","ComputerUseDoubleClickActionSchema","ComputerUseDragActionSchema","ZodArray","ComputerUseKeypressActionSchema","ZodString","ComputerUseMoveActionSchema","ComputerUseScrollActionSchema","ComputerUseTypeActionSchema","ComputerUseWaitActionSchema","ZodOptional","ComputerUseActionSchema","ZodUnion","ComputerUseScreenshotActionType","infer","ComputerUseClickActionType","ComputerUseDoubleClickActionType","ComputerUseDragActionType","ComputerUseKeypressActionType","ComputerUseMoveActionType","ComputerUseScrollActionType","ComputerUseTypeActionType","ComputerUseWaitActionType","ComputerUseInput","ComputerUseReturnType","Promise","ComputerUseOptions","ComputerUseTool","ComputerTool","computerUse"],"sources":["../../src/tools/computerUse.d.ts"],"sourcesContent":["import { z } from \"zod/v4\";\nimport { OpenAI as OpenAIClient } from \"openai\";\nimport { type DynamicStructuredTool } from \"@langchain/core/tools\";\nimport { type ToolRuntime } from \"@langchain/core/tools\";\nimport { ToolMessage } from \"@langchain/core/messages\";\n/**\n * The type of computer environment to control.\n */\nexport type ComputerUseEnvironment = \"browser\" | \"mac\" | \"windows\" | \"linux\" | \"ubuntu\";\n/**\n * Re-export action types from OpenAI SDK for convenience.\n */\nexport type ComputerUseClickAction = OpenAIClient.Responses.ResponseComputerToolCall.Click;\nexport type ComputerUseDoubleClickAction = OpenAIClient.Responses.ResponseComputerToolCall.DoubleClick;\nexport type ComputerUseDragAction = OpenAIClient.Responses.ResponseComputerToolCall.Drag;\nexport type ComputerUseKeypressAction = OpenAIClient.Responses.ResponseComputerToolCall.Keypress;\nexport type ComputerUseMoveAction = OpenAIClient.Responses.ResponseComputerToolCall.Move;\nexport type ComputerUseScreenshotAction = OpenAIClient.Responses.ResponseComputerToolCall.Screenshot;\nexport type ComputerUseScrollAction = OpenAIClient.Responses.ResponseComputerToolCall.Scroll;\nexport type ComputerUseTypeAction = OpenAIClient.Responses.ResponseComputerToolCall.Type;\nexport type ComputerUseWaitAction = OpenAIClient.Responses.ResponseComputerToolCall.Wait;\n/**\n * Union type of all computer use actions from OpenAI SDK.\n */\nexport type ComputerUseAction = OpenAIClient.Responses.ResponseComputerToolCall[\"action\"];\ndeclare const ComputerUseScreenshotActionSchema: z.ZodObject<{\n type: z.ZodLiteral<\"screenshot\">;\n}, z.core.$strip>;\ndeclare const ComputerUseClickActionSchema: z.ZodObject<{\n type: z.ZodLiteral<\"click\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n button: z.ZodDefault<z.ZodEnum<{\n back: \"back\";\n forward: \"forward\";\n left: \"left\";\n right: \"right\";\n wheel: \"wheel\";\n }>>;\n}, z.core.$strip>;\ndeclare const ComputerUseDoubleClickActionSchema: z.ZodObject<{\n type: z.ZodLiteral<\"double_click\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n button: z.ZodDefault<z.ZodEnum<{\n back: \"back\";\n forward: \"forward\";\n left: \"left\";\n right: \"right\";\n wheel: \"wheel\";\n }>>;\n}, z.core.$strip>;\ndeclare const ComputerUseDragActionSchema: z.ZodObject<{\n type: z.ZodLiteral<\"drag\">;\n path: z.ZodArray<z.ZodObject<{\n x: z.ZodNumber;\n y: z.ZodNumber;\n }, z.core.$strip>>;\n}, z.core.$strip>;\ndeclare const ComputerUseKeypressActionSchema: z.ZodObject<{\n type: z.ZodLiteral<\"keypress\">;\n keys: z.ZodArray<z.ZodString>;\n}, z.core.$strip>;\ndeclare const ComputerUseMoveActionSchema: z.ZodObject<{\n type: z.ZodLiteral<\"move\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n}, z.core.$strip>;\ndeclare const ComputerUseScrollActionSchema: z.ZodObject<{\n type: z.ZodLiteral<\"scroll\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n scroll_x: z.ZodNumber;\n scroll_y: z.ZodNumber;\n}, z.core.$strip>;\ndeclare const ComputerUseTypeActionSchema: z.ZodObject<{\n type: z.ZodLiteral<\"type\">;\n text: z.ZodString;\n}, z.core.$strip>;\ndeclare const ComputerUseWaitActionSchema: z.ZodObject<{\n type: z.ZodLiteral<\"wait\">;\n duration: z.ZodOptional<z.ZodNumber>;\n}, z.core.$strip>;\nexport declare const ComputerUseActionSchema: z.ZodObject<{\n action: z.ZodUnion<readonly [z.ZodObject<{\n type: z.ZodLiteral<\"screenshot\">;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"click\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n button: z.ZodDefault<z.ZodEnum<{\n back: \"back\";\n forward: \"forward\";\n left: \"left\";\n right: \"right\";\n wheel: \"wheel\";\n }>>;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"double_click\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n button: z.ZodDefault<z.ZodEnum<{\n back: \"back\";\n forward: \"forward\";\n left: \"left\";\n right: \"right\";\n wheel: \"wheel\";\n }>>;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"drag\">;\n path: z.ZodArray<z.ZodObject<{\n x: z.ZodNumber;\n y: z.ZodNumber;\n }, z.core.$strip>>;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"keypress\">;\n keys: z.ZodArray<z.ZodString>;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"move\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"scroll\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n scroll_x: z.ZodNumber;\n scroll_y: z.ZodNumber;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"type\">;\n text: z.ZodString;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"wait\">;\n duration: z.ZodOptional<z.ZodNumber>;\n }, z.core.$strip>]>;\n}, z.core.$strip>;\nexport type ComputerUseScreenshotActionType = z.infer<typeof ComputerUseScreenshotActionSchema>;\nexport type ComputerUseClickActionType = z.infer<typeof ComputerUseClickActionSchema>;\nexport type ComputerUseDoubleClickActionType = z.infer<typeof ComputerUseDoubleClickActionSchema>;\nexport type ComputerUseDragActionType = z.infer<typeof ComputerUseDragActionSchema>;\nexport type ComputerUseKeypressActionType = z.infer<typeof ComputerUseKeypressActionSchema>;\nexport type ComputerUseMoveActionType = z.infer<typeof ComputerUseMoveActionSchema>;\nexport type ComputerUseScrollActionType = z.infer<typeof ComputerUseScrollActionSchema>;\nexport type ComputerUseTypeActionType = z.infer<typeof ComputerUseTypeActionSchema>;\nexport type ComputerUseWaitActionType = z.infer<typeof ComputerUseWaitActionSchema>;\n/**\n * Input structure for the Computer Use tool.\n * The action is wrapped in an `action` property.\n */\nexport interface ComputerUseInput {\n action: ComputerUseAction;\n}\nexport type ComputerUseReturnType = string | Promise<string> | ToolMessage<any> | Promise<ToolMessage<any>>;\n/**\n * Options for the Computer Use tool.\n */\nexport interface ComputerUseOptions {\n /**\n * The width of the computer display in pixels.\n */\n displayWidth: number;\n /**\n * The height of the computer display in pixels.\n */\n displayHeight: number;\n /**\n * The type of computer environment to control.\n * - `browser`: Browser automation (recommended for most use cases)\n * - `mac`: macOS environment\n * - `windows`: Windows environment\n * - `linux`: Linux environment\n * - `ubuntu`: Ubuntu environment\n */\n environment: ComputerUseEnvironment;\n /**\n * Execute function that handles computer action execution.\n * This function receives the action input and should return a base64-encoded\n * screenshot of the result.\n */\n execute: (action: ComputerUseAction, runtime: ToolRuntime<any, any>) => ComputerUseReturnType;\n}\n/**\n * OpenAI Computer Use tool type for the Responses API.\n */\nexport type ComputerUseTool = OpenAIClient.Responses.ComputerTool;\n/**\n * Creates a Computer Use tool that allows models to control computer interfaces\n * and perform tasks by simulating mouse clicks, keyboard input, scrolling, and more.\n *\n * **Computer Use** is a practical application of OpenAI's Computer-Using Agent (CUA)\n * model (`computer-use-preview`), which combines vision capabilities with advanced\n * reasoning to simulate controlling computer interfaces.\n *\n * **How it works**:\n * The tool operates in a continuous loop:\n * 1. Model sends computer actions (click, type, scroll, etc.)\n * 2. Your code executes these actions in a controlled environment\n * 3. You capture a screenshot of the result\n * 4. Send the screenshot back to the model\n * 5. Repeat until the task is complete\n *\n * **Important**: Computer use is in beta and requires careful consideration:\n * - Use in sandboxed environments only\n * - Do not use for high-stakes or authenticated tasks\n * - Always implement human-in-the-loop for important decisions\n * - Handle safety checks appropriately\n *\n * @see {@link https://platform.openai.com/docs/guides/tools-computer-use | OpenAI Computer Use Documentation}\n *\n * @param options - Configuration options for the Computer Use tool\n * @returns A Computer Use tool that can be passed to `bindTools`\n *\n * @example\n * ```typescript\n * import { ChatOpenAI, tools } from \"@langchain/openai\";\n *\n * const model = new ChatOpenAI({ model: \"computer-use-preview\" });\n *\n * // With execute callback for automatic action handling\n * const computer = tools.computerUse({\n * displayWidth: 1024,\n * displayHeight: 768,\n * environment: \"browser\",\n * execute: async (action) => {\n * if (action.type === \"screenshot\") {\n * return captureScreenshot();\n * }\n * if (action.type === \"click\") {\n * await page.mouse.click(action.x, action.y, { button: action.button });\n * return captureScreenshot();\n * }\n * if (action.type === \"type\") {\n * await page.keyboard.type(action.text);\n * return captureScreenshot();\n * }\n * // Handle other actions...\n * return captureScreenshot();\n * },\n * });\n *\n * const llmWithComputer = model.bindTools([computer]);\n * const response = await llmWithComputer.invoke(\n * \"Check the latest news on bing.com\"\n * );\n * ```\n *\n * @example\n * ```typescript\n * // Without execute callback (manual action handling)\n * const computer = tools.computerUse({\n * displayWidth: 1024,\n * displayHeight: 768,\n * environment: \"browser\",\n * });\n *\n * const response = await model.invoke(\"Check the news\", {\n * tools: [computer],\n * });\n *\n * // Access the computer call from the response\n * const computerCall = response.additional_kwargs.tool_outputs?.find(\n * (output) => output.type === \"computer_call\"\n * );\n * if (computerCall) {\n * console.log(\"Action to execute:\", computerCall.action);\n * // Execute the action manually, then send back a screenshot\n * }\n * ```\n *\n * @example\n * ```typescript\n * // For macOS desktop automation with Docker\n * const computer = tools.computerUse({\n * displayWidth: 1920,\n * displayHeight: 1080,\n * environment: \"mac\",\n * execute: async (action) => {\n * if (action.type === \"click\") {\n * await dockerExec(\n * `DISPLAY=:99 xdotool mousemove ${action.x} ${action.y} click 1`,\n * containerName\n * );\n * }\n * // Capture screenshot from container\n * return await getDockerScreenshot(containerName);\n * },\n * });\n * ```\n *\n * @remarks\n * - Only available through the Responses API (not Chat Completions)\n * - Requires `computer-use-preview` model\n * - Actions include: click, double_click, drag, keypress, move, screenshot, scroll, type, wait\n * - Safety checks may be returned that require acknowledgment before proceeding\n * - Use `truncation: \"auto\"` parameter when making requests\n * - Recommended to use with `reasoning.summary` for debugging\n */\nexport declare function computerUse(options: ComputerUseOptions): DynamicStructuredTool<z.ZodObject<{\n action: z.ZodUnion<readonly [z.ZodObject<{\n type: z.ZodLiteral<\"screenshot\">;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"click\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n button: z.ZodDefault<z.ZodEnum<{\n back: \"back\";\n forward: \"forward\";\n left: \"left\";\n right: \"right\";\n wheel: \"wheel\";\n }>>;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"double_click\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n button: z.ZodDefault<z.ZodEnum<{\n back: \"back\";\n forward: \"forward\";\n left: \"left\";\n right: \"right\";\n wheel: \"wheel\";\n }>>;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"drag\">;\n path: z.ZodArray<z.ZodObject<{\n x: z.ZodNumber;\n y: z.ZodNumber;\n }, z.core.$strip>>;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"keypress\">;\n keys: z.ZodArray<z.ZodString>;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"move\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"scroll\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n scroll_x: z.ZodNumber;\n scroll_y: z.ZodNumber;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"type\">;\n text: z.ZodString;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"wait\">;\n duration: z.ZodOptional<z.ZodNumber>;\n }, z.core.$strip>]>;\n}, z.core.$strip>, ComputerUseInput, unknown, ComputerUseReturnType, string>;\nexport {};\n//# sourceMappingURL=computerUse.d.ts.map"],"mappings":";;;;;;;;AAQA;AAIA;AACYW,KALAL,sBAAAA,GAK4B,SAAA,GAAGJ,KAAAA,GAAaM,SAAAA,GAAUC,OAAAA,GAAAA,QAAAA;AAClE;AACA;AACA;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AAA,CAAEgC;UACXhC,CAAAA,CAAE6B;UACF7B,CAAAA,CAAEyC;KACTzC,CAAAA,CAAE8B,IAAAA,CAAKC,SAAS/B,CAAAA,CAAEgC;UACXhC,CAAAA,CAAE6B;cACE7B,CAAAA,CAAE8C,YAAY9C,CAAAA,CAAEkC;KAC3BlC,CAAAA,CAAE8B,IAAAA,CAAKC;GACX/B,CAAAA,CAAE8B,IAAAA,CAAKC,SAAS4B,2BAA2BC"}
@@ -59,7 +59,7 @@ const ComputerUseWaitActionSchema = z.object({
59
59
  type: z.literal("wait"),
60
60
  duration: z.number().optional()
61
61
  });
62
- const ComputerUseActionUnionSchema = z.discriminatedUnion("type", [
62
+ const ComputerUseActionUnionSchema = z.union([
63
63
  ComputerUseScreenshotActionSchema,
64
64
  ComputerUseClickActionSchema,
65
65
  ComputerUseDoubleClickActionSchema,
@@ -1 +1 @@
1
- {"version":3,"file":"computerUse.js","names":["options: ComputerUseOptions","input: ComputerUseInput","runtime: ToolRuntime<{ messages: BaseMessage[] }>"],"sources":["../../src/tools/computerUse.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { z } from \"zod/v4\";\nimport { OpenAI as OpenAIClient } from \"openai\";\nimport { tool, type DynamicStructuredTool } from \"@langchain/core/tools\";\nimport { type ToolRuntime } from \"@langchain/core/tools\";\nimport {\n ToolMessage,\n type AIMessage,\n type BaseMessage,\n} from \"@langchain/core/messages\";\n\n/**\n * The type of computer environment to control.\n */\nexport type ComputerUseEnvironment =\n | \"browser\"\n | \"mac\"\n | \"windows\"\n | \"linux\"\n | \"ubuntu\";\n\n/**\n * Re-export action types from OpenAI SDK for convenience.\n */\nexport type ComputerUseClickAction =\n OpenAIClient.Responses.ResponseComputerToolCall.Click;\nexport type ComputerUseDoubleClickAction =\n OpenAIClient.Responses.ResponseComputerToolCall.DoubleClick;\nexport type ComputerUseDragAction =\n OpenAIClient.Responses.ResponseComputerToolCall.Drag;\nexport type ComputerUseKeypressAction =\n OpenAIClient.Responses.ResponseComputerToolCall.Keypress;\nexport type ComputerUseMoveAction =\n OpenAIClient.Responses.ResponseComputerToolCall.Move;\nexport type ComputerUseScreenshotAction =\n OpenAIClient.Responses.ResponseComputerToolCall.Screenshot;\nexport type ComputerUseScrollAction =\n OpenAIClient.Responses.ResponseComputerToolCall.Scroll;\nexport type ComputerUseTypeAction =\n OpenAIClient.Responses.ResponseComputerToolCall.Type;\nexport type ComputerUseWaitAction =\n OpenAIClient.Responses.ResponseComputerToolCall.Wait;\n\n/**\n * Union type of all computer use actions from OpenAI SDK.\n */\nexport type ComputerUseAction =\n OpenAIClient.Responses.ResponseComputerToolCall[\"action\"];\n\n// Zod schemas for computer use actions\nconst ComputerUseScreenshotActionSchema = z.object({\n type: z.literal(\"screenshot\"),\n});\n\nconst ComputerUseClickActionSchema = z.object({\n type: z.literal(\"click\"),\n x: z.number(),\n y: z.number(),\n button: z.enum([\"left\", \"right\", \"wheel\", \"back\", \"forward\"]).default(\"left\"),\n});\n\nconst ComputerUseDoubleClickActionSchema = z.object({\n type: z.literal(\"double_click\"),\n x: z.number(),\n y: z.number(),\n button: z.enum([\"left\", \"right\", \"wheel\", \"back\", \"forward\"]).default(\"left\"),\n});\n\nconst ComputerUseDragActionSchema = z.object({\n type: z.literal(\"drag\"),\n path: z.array(z.object({ x: z.number(), y: z.number() })),\n});\n\nconst ComputerUseKeypressActionSchema = z.object({\n type: z.literal(\"keypress\"),\n keys: z.array(z.string()),\n});\n\nconst ComputerUseMoveActionSchema = z.object({\n type: z.literal(\"move\"),\n x: z.number(),\n y: z.number(),\n});\n\nconst ComputerUseScrollActionSchema = z.object({\n type: z.literal(\"scroll\"),\n x: z.number(),\n y: z.number(),\n scroll_x: z.number(),\n scroll_y: z.number(),\n});\n\nconst ComputerUseTypeActionSchema = z.object({\n type: z.literal(\"type\"),\n text: z.string(),\n});\n\nconst ComputerUseWaitActionSchema = z.object({\n type: z.literal(\"wait\"),\n duration: z.number().optional(),\n});\n\n// Discriminated union schema for individual action types\nconst ComputerUseActionUnionSchema = z.discriminatedUnion(\"type\", [\n ComputerUseScreenshotActionSchema,\n ComputerUseClickActionSchema,\n ComputerUseDoubleClickActionSchema,\n ComputerUseDragActionSchema,\n ComputerUseKeypressActionSchema,\n ComputerUseMoveActionSchema,\n ComputerUseScrollActionSchema,\n ComputerUseTypeActionSchema,\n ComputerUseWaitActionSchema,\n]);\n\n// Schema for the input structure received from parseComputerCall\n// The action is wrapped in an `action` property: { action: { type: 'screenshot' } }\nexport const ComputerUseActionSchema = z.object({\n action: ComputerUseActionUnionSchema,\n});\n\n// TypeScript types derived from Zod schemas\nexport type ComputerUseScreenshotActionType = z.infer<\n typeof ComputerUseScreenshotActionSchema\n>;\nexport type ComputerUseClickActionType = z.infer<\n typeof ComputerUseClickActionSchema\n>;\nexport type ComputerUseDoubleClickActionType = z.infer<\n typeof ComputerUseDoubleClickActionSchema\n>;\nexport type ComputerUseDragActionType = z.infer<\n typeof ComputerUseDragActionSchema\n>;\nexport type ComputerUseKeypressActionType = z.infer<\n typeof ComputerUseKeypressActionSchema\n>;\nexport type ComputerUseMoveActionType = z.infer<\n typeof ComputerUseMoveActionSchema\n>;\nexport type ComputerUseScrollActionType = z.infer<\n typeof ComputerUseScrollActionSchema\n>;\nexport type ComputerUseTypeActionType = z.infer<\n typeof ComputerUseTypeActionSchema\n>;\nexport type ComputerUseWaitActionType = z.infer<\n typeof ComputerUseWaitActionSchema\n>;\n\n/**\n * Input structure for the Computer Use tool.\n * The action is wrapped in an `action` property.\n */\nexport interface ComputerUseInput {\n action: ComputerUseAction;\n}\n\nexport type ComputerUseReturnType =\n | string\n | Promise<string>\n | ToolMessage<any>\n | Promise<ToolMessage<any>>;\n\n/**\n * Options for the Computer Use tool.\n */\nexport interface ComputerUseOptions {\n /**\n * The width of the computer display in pixels.\n */\n displayWidth: number;\n\n /**\n * The height of the computer display in pixels.\n */\n displayHeight: number;\n\n /**\n * The type of computer environment to control.\n * - `browser`: Browser automation (recommended for most use cases)\n * - `mac`: macOS environment\n * - `windows`: Windows environment\n * - `linux`: Linux environment\n * - `ubuntu`: Ubuntu environment\n */\n environment: ComputerUseEnvironment;\n\n /**\n * Execute function that handles computer action execution.\n * This function receives the action input and should return a base64-encoded\n * screenshot of the result.\n */\n execute: (\n action: ComputerUseAction,\n runtime: ToolRuntime<any, any>\n ) => ComputerUseReturnType;\n}\n\n/**\n * OpenAI Computer Use tool type for the Responses API.\n */\nexport type ComputerUseTool = OpenAIClient.Responses.ComputerTool;\n\nconst TOOL_NAME = \"computer_use\";\n\n/**\n * Creates a Computer Use tool that allows models to control computer interfaces\n * and perform tasks by simulating mouse clicks, keyboard input, scrolling, and more.\n *\n * **Computer Use** is a practical application of OpenAI's Computer-Using Agent (CUA)\n * model (`computer-use-preview`), which combines vision capabilities with advanced\n * reasoning to simulate controlling computer interfaces.\n *\n * **How it works**:\n * The tool operates in a continuous loop:\n * 1. Model sends computer actions (click, type, scroll, etc.)\n * 2. Your code executes these actions in a controlled environment\n * 3. You capture a screenshot of the result\n * 4. Send the screenshot back to the model\n * 5. Repeat until the task is complete\n *\n * **Important**: Computer use is in beta and requires careful consideration:\n * - Use in sandboxed environments only\n * - Do not use for high-stakes or authenticated tasks\n * - Always implement human-in-the-loop for important decisions\n * - Handle safety checks appropriately\n *\n * @see {@link https://platform.openai.com/docs/guides/tools-computer-use | OpenAI Computer Use Documentation}\n *\n * @param options - Configuration options for the Computer Use tool\n * @returns A Computer Use tool that can be passed to `bindTools`\n *\n * @example\n * ```typescript\n * import { ChatOpenAI, tools } from \"@langchain/openai\";\n *\n * const model = new ChatOpenAI({ model: \"computer-use-preview\" });\n *\n * // With execute callback for automatic action handling\n * const computer = tools.computerUse({\n * displayWidth: 1024,\n * displayHeight: 768,\n * environment: \"browser\",\n * execute: async (action) => {\n * if (action.type === \"screenshot\") {\n * return captureScreenshot();\n * }\n * if (action.type === \"click\") {\n * await page.mouse.click(action.x, action.y, { button: action.button });\n * return captureScreenshot();\n * }\n * if (action.type === \"type\") {\n * await page.keyboard.type(action.text);\n * return captureScreenshot();\n * }\n * // Handle other actions...\n * return captureScreenshot();\n * },\n * });\n *\n * const llmWithComputer = model.bindTools([computer]);\n * const response = await llmWithComputer.invoke(\n * \"Check the latest news on bing.com\"\n * );\n * ```\n *\n * @example\n * ```typescript\n * // Without execute callback (manual action handling)\n * const computer = tools.computerUse({\n * displayWidth: 1024,\n * displayHeight: 768,\n * environment: \"browser\",\n * });\n *\n * const response = await model.invoke(\"Check the news\", {\n * tools: [computer],\n * });\n *\n * // Access the computer call from the response\n * const computerCall = response.additional_kwargs.tool_outputs?.find(\n * (output) => output.type === \"computer_call\"\n * );\n * if (computerCall) {\n * console.log(\"Action to execute:\", computerCall.action);\n * // Execute the action manually, then send back a screenshot\n * }\n * ```\n *\n * @example\n * ```typescript\n * // For macOS desktop automation with Docker\n * const computer = tools.computerUse({\n * displayWidth: 1920,\n * displayHeight: 1080,\n * environment: \"mac\",\n * execute: async (action) => {\n * if (action.type === \"click\") {\n * await dockerExec(\n * `DISPLAY=:99 xdotool mousemove ${action.x} ${action.y} click 1`,\n * containerName\n * );\n * }\n * // Capture screenshot from container\n * return await getDockerScreenshot(containerName);\n * },\n * });\n * ```\n *\n * @remarks\n * - Only available through the Responses API (not Chat Completions)\n * - Requires `computer-use-preview` model\n * - Actions include: click, double_click, drag, keypress, move, screenshot, scroll, type, wait\n * - Safety checks may be returned that require acknowledgment before proceeding\n * - Use `truncation: \"auto\"` parameter when making requests\n * - Recommended to use with `reasoning.summary` for debugging\n */\nexport function computerUse(options: ComputerUseOptions) {\n const computerTool = tool(\n async (\n input: ComputerUseInput,\n runtime: ToolRuntime<{ messages: BaseMessage[] }>\n ) => {\n /**\n * get computer_use call id from runtime\n */\n const aiMessage = runtime.state?.messages.at(-1) as AIMessage | undefined;\n const computerToolCall = aiMessage?.tool_calls?.find(\n (tc) => tc.name === \"computer_use\"\n );\n const computerToolCallId = computerToolCall?.id;\n if (!computerToolCallId) {\n throw new Error(\"Computer use call id not found\");\n }\n\n const result = await options.execute(input.action, runtime);\n\n /**\n * make sure {@link ToolMessage} is returned with the correct additional kwargs\n */\n if (typeof result === \"string\") {\n return new ToolMessage({\n content: result,\n tool_call_id: computerToolCallId,\n additional_kwargs: {\n type: \"computer_call_output\",\n },\n });\n }\n\n /**\n * make sure {@link ToolMessage} is returned with the correct additional kwargs\n */\n return new ToolMessage({\n ...result,\n tool_call_id: computerToolCallId,\n additional_kwargs: {\n type: \"computer_call_output\",\n ...result.additional_kwargs,\n },\n });\n },\n {\n name: TOOL_NAME,\n description:\n \"Control a computer interface by executing mouse clicks, keyboard input, scrolling, and other actions.\",\n schema: ComputerUseActionSchema,\n }\n );\n\n computerTool.extras = {\n ...(computerTool.extras ?? {}),\n providerToolDefinition: {\n type: \"computer_use_preview\",\n display_width: options.displayWidth,\n display_height: options.displayHeight,\n environment: options.environment,\n } satisfies ComputerUseTool,\n };\n\n /**\n * return as typed {@link DynamicStructuredTool} so we don't get any type\n * errors like \"can't export tool without reference\"\n */\n return computerTool as DynamicStructuredTool<\n typeof ComputerUseActionSchema,\n ComputerUseInput,\n unknown,\n ComputerUseReturnType\n >;\n}\n"],"mappings":";;;;;AAkDA,MAAM,oCAAoC,EAAE,OAAO,EACjD,MAAM,EAAE,QAAQ,aAAa,CAC9B,EAAC;AAEF,MAAM,+BAA+B,EAAE,OAAO;CAC5C,MAAM,EAAE,QAAQ,QAAQ;CACxB,GAAG,EAAE,QAAQ;CACb,GAAG,EAAE,QAAQ;CACb,QAAQ,EAAE,KAAK;EAAC;EAAQ;EAAS;EAAS;EAAQ;CAAU,EAAC,CAAC,QAAQ,OAAO;AAC9E,EAAC;AAEF,MAAM,qCAAqC,EAAE,OAAO;CAClD,MAAM,EAAE,QAAQ,eAAe;CAC/B,GAAG,EAAE,QAAQ;CACb,GAAG,EAAE,QAAQ;CACb,QAAQ,EAAE,KAAK;EAAC;EAAQ;EAAS;EAAS;EAAQ;CAAU,EAAC,CAAC,QA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EAIH,MAAM,YAAY,QAAQ,OAAO,SAAS,GAAG,GAAG;EAChD,MAAM,mBAAmB,WAAW,YAAY,KAC9C,CAAC,OAAO,GAAG,SAAS,eACrB;EACD,MAAM,qBAAqB,kBAAkB;AAC7C,MAAI,CAAC,mBACH,OAAM,IAAI,MAAM;EAGlB,MAAM,SAAS,MAAM,QAAQ,QAAQ,MAAM,QAAQ,QAAQ;;;;AAK3D,MAAI,OAAO,WAAW,SACpB,QAAO,IAAI,YAAY;GACrB,SAAS;GACT,cAAc;GACd,mBAAmB,EACjB,MAAM,uBACP;EACF;;;;AAMH,SAAO,IAAI,YAAY;GACrB,GAAG;GACH,cAAc;GACd,mBAAmB;IACjB,MAAM;IACN,GAAG,OAAO;GACX;EACF;CACF,GACD;EACE,MAAM;EACN,aACE;EACF,QAAQ;CACT,EACF;CAED,aAAa,SAAS;EACpB,GAAI,aAAa,UAAU,CAAE;EAC7B,wBAAwB;GACtB,MAAM;GACN,eAAe,QAAQ;GACvB,gBAAgB,QAAQ;GACxB,aAAa,QAAQ;EACtB;CACF;;;;;AAMD,QAAO;AAMR"}
1
+ {"version":3,"file":"computerUse.js","names":["options: ComputerUseOptions","input: ComputerUseInput","runtime: ToolRuntime<{ messages: BaseMessage[] }>"],"sources":["../../src/tools/computerUse.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { z } from \"zod/v4\";\nimport { OpenAI as OpenAIClient } from \"openai\";\nimport { tool, type DynamicStructuredTool } from \"@langchain/core/tools\";\nimport { type ToolRuntime } from \"@langchain/core/tools\";\nimport {\n ToolMessage,\n type AIMessage,\n type BaseMessage,\n} from \"@langchain/core/messages\";\n\n/**\n * The type of computer environment to control.\n */\nexport type ComputerUseEnvironment =\n | \"browser\"\n | \"mac\"\n | \"windows\"\n | \"linux\"\n | \"ubuntu\";\n\n/**\n * Re-export action types from OpenAI SDK for convenience.\n */\nexport type ComputerUseClickAction =\n OpenAIClient.Responses.ResponseComputerToolCall.Click;\nexport type ComputerUseDoubleClickAction =\n OpenAIClient.Responses.ResponseComputerToolCall.DoubleClick;\nexport type ComputerUseDragAction =\n OpenAIClient.Responses.ResponseComputerToolCall.Drag;\nexport type ComputerUseKeypressAction =\n OpenAIClient.Responses.ResponseComputerToolCall.Keypress;\nexport type ComputerUseMoveAction =\n OpenAIClient.Responses.ResponseComputerToolCall.Move;\nexport type ComputerUseScreenshotAction =\n OpenAIClient.Responses.ResponseComputerToolCall.Screenshot;\nexport type ComputerUseScrollAction =\n OpenAIClient.Responses.ResponseComputerToolCall.Scroll;\nexport type ComputerUseTypeAction =\n OpenAIClient.Responses.ResponseComputerToolCall.Type;\nexport type ComputerUseWaitAction =\n OpenAIClient.Responses.ResponseComputerToolCall.Wait;\n\n/**\n * Union type of all computer use actions from OpenAI SDK.\n */\nexport type ComputerUseAction =\n OpenAIClient.Responses.ResponseComputerToolCall[\"action\"];\n\n// Zod schemas for computer use actions\nconst ComputerUseScreenshotActionSchema = z.object({\n type: z.literal(\"screenshot\"),\n});\n\nconst ComputerUseClickActionSchema = z.object({\n type: z.literal(\"click\"),\n x: z.number(),\n y: z.number(),\n button: z.enum([\"left\", \"right\", \"wheel\", \"back\", \"forward\"]).default(\"left\"),\n});\n\nconst ComputerUseDoubleClickActionSchema = z.object({\n type: z.literal(\"double_click\"),\n x: z.number(),\n y: z.number(),\n button: z.enum([\"left\", \"right\", \"wheel\", \"back\", \"forward\"]).default(\"left\"),\n});\n\nconst ComputerUseDragActionSchema = z.object({\n type: z.literal(\"drag\"),\n path: z.array(z.object({ x: z.number(), y: z.number() })),\n});\n\nconst ComputerUseKeypressActionSchema = z.object({\n type: z.literal(\"keypress\"),\n keys: z.array(z.string()),\n});\n\nconst ComputerUseMoveActionSchema = z.object({\n type: z.literal(\"move\"),\n x: z.number(),\n y: z.number(),\n});\n\nconst ComputerUseScrollActionSchema = z.object({\n type: z.literal(\"scroll\"),\n x: z.number(),\n y: z.number(),\n scroll_x: z.number(),\n scroll_y: z.number(),\n});\n\nconst ComputerUseTypeActionSchema = z.object({\n type: z.literal(\"type\"),\n text: z.string(),\n});\n\nconst ComputerUseWaitActionSchema = z.object({\n type: z.literal(\"wait\"),\n duration: z.number().optional(),\n});\n\n// Union schema for individual action types\nconst ComputerUseActionUnionSchema = z.union([\n ComputerUseScreenshotActionSchema,\n ComputerUseClickActionSchema,\n ComputerUseDoubleClickActionSchema,\n ComputerUseDragActionSchema,\n ComputerUseKeypressActionSchema,\n ComputerUseMoveActionSchema,\n ComputerUseScrollActionSchema,\n ComputerUseTypeActionSchema,\n ComputerUseWaitActionSchema,\n]);\n\n// Schema for the input structure received from parseComputerCall\n// The action is wrapped in an `action` property: { action: { type: 'screenshot' } }\nexport const ComputerUseActionSchema = z.object({\n action: ComputerUseActionUnionSchema,\n});\n\n// TypeScript types derived from Zod schemas\nexport type ComputerUseScreenshotActionType = z.infer<\n typeof ComputerUseScreenshotActionSchema\n>;\nexport type ComputerUseClickActionType = z.infer<\n typeof ComputerUseClickActionSchema\n>;\nexport type ComputerUseDoubleClickActionType = z.infer<\n typeof ComputerUseDoubleClickActionSchema\n>;\nexport type ComputerUseDragActionType = z.infer<\n typeof ComputerUseDragActionSchema\n>;\nexport type ComputerUseKeypressActionType = z.infer<\n typeof ComputerUseKeypressActionSchema\n>;\nexport type ComputerUseMoveActionType = z.infer<\n typeof ComputerUseMoveActionSchema\n>;\nexport type ComputerUseScrollActionType = z.infer<\n typeof ComputerUseScrollActionSchema\n>;\nexport type ComputerUseTypeActionType = z.infer<\n typeof ComputerUseTypeActionSchema\n>;\nexport type ComputerUseWaitActionType = z.infer<\n typeof ComputerUseWaitActionSchema\n>;\n\n/**\n * Input structure for the Computer Use tool.\n * The action is wrapped in an `action` property.\n */\nexport interface ComputerUseInput {\n action: ComputerUseAction;\n}\n\nexport type ComputerUseReturnType =\n | string\n | Promise<string>\n | ToolMessage<any>\n | Promise<ToolMessage<any>>;\n\n/**\n * Options for the Computer Use tool.\n */\nexport interface ComputerUseOptions {\n /**\n * The width of the computer display in pixels.\n */\n displayWidth: number;\n\n /**\n * The height of the computer display in pixels.\n */\n displayHeight: number;\n\n /**\n * The type of computer environment to control.\n * - `browser`: Browser automation (recommended for most use cases)\n * - `mac`: macOS environment\n * - `windows`: Windows environment\n * - `linux`: Linux environment\n * - `ubuntu`: Ubuntu environment\n */\n environment: ComputerUseEnvironment;\n\n /**\n * Execute function that handles computer action execution.\n * This function receives the action input and should return a base64-encoded\n * screenshot of the result.\n */\n execute: (\n action: ComputerUseAction,\n runtime: ToolRuntime<any, any>\n ) => ComputerUseReturnType;\n}\n\n/**\n * OpenAI Computer Use tool type for the Responses API.\n */\nexport type ComputerUseTool = OpenAIClient.Responses.ComputerTool;\n\nconst TOOL_NAME = \"computer_use\";\n\n/**\n * Creates a Computer Use tool that allows models to control computer interfaces\n * and perform tasks by simulating mouse clicks, keyboard input, scrolling, and more.\n *\n * **Computer Use** is a practical application of OpenAI's Computer-Using Agent (CUA)\n * model (`computer-use-preview`), which combines vision capabilities with advanced\n * reasoning to simulate controlling computer interfaces.\n *\n * **How it works**:\n * The tool operates in a continuous loop:\n * 1. Model sends computer actions (click, type, scroll, etc.)\n * 2. Your code executes these actions in a controlled environment\n * 3. You capture a screenshot of the result\n * 4. Send the screenshot back to the model\n * 5. Repeat until the task is complete\n *\n * **Important**: Computer use is in beta and requires careful consideration:\n * - Use in sandboxed environments only\n * - Do not use for high-stakes or authenticated tasks\n * - Always implement human-in-the-loop for important decisions\n * - Handle safety checks appropriately\n *\n * @see {@link https://platform.openai.com/docs/guides/tools-computer-use | OpenAI Computer Use Documentation}\n *\n * @param options - Configuration options for the Computer Use tool\n * @returns A Computer Use tool that can be passed to `bindTools`\n *\n * @example\n * ```typescript\n * import { ChatOpenAI, tools } from \"@langchain/openai\";\n *\n * const model = new ChatOpenAI({ model: \"computer-use-preview\" });\n *\n * // With execute callback for automatic action handling\n * const computer = tools.computerUse({\n * displayWidth: 1024,\n * displayHeight: 768,\n * environment: \"browser\",\n * execute: async (action) => {\n * if (action.type === \"screenshot\") {\n * return captureScreenshot();\n * }\n * if (action.type === \"click\") {\n * await page.mouse.click(action.x, action.y, { button: action.button });\n * return captureScreenshot();\n * }\n * if (action.type === \"type\") {\n * await page.keyboard.type(action.text);\n * return captureScreenshot();\n * }\n * // Handle other actions...\n * return captureScreenshot();\n * },\n * });\n *\n * const llmWithComputer = model.bindTools([computer]);\n * const response = await llmWithComputer.invoke(\n * \"Check the latest news on bing.com\"\n * );\n * ```\n *\n * @example\n * ```typescript\n * // Without execute callback (manual action handling)\n * const computer = tools.computerUse({\n * displayWidth: 1024,\n * displayHeight: 768,\n * environment: \"browser\",\n * });\n *\n * const response = await model.invoke(\"Check the news\", {\n * tools: [computer],\n * });\n *\n * // Access the computer call from the response\n * const computerCall = response.additional_kwargs.tool_outputs?.find(\n * (output) => output.type === \"computer_call\"\n * );\n * if (computerCall) {\n * console.log(\"Action to execute:\", computerCall.action);\n * // Execute the action manually, then send back a screenshot\n * }\n * ```\n *\n * @example\n * ```typescript\n * // For macOS desktop automation with Docker\n * const computer = tools.computerUse({\n * displayWidth: 1920,\n * displayHeight: 1080,\n * environment: \"mac\",\n * execute: async (action) => {\n * if (action.type === \"click\") {\n * await dockerExec(\n * `DISPLAY=:99 xdotool mousemove ${action.x} ${action.y} click 1`,\n * containerName\n * );\n * }\n * // Capture screenshot from container\n * return await getDockerScreenshot(containerName);\n * },\n * });\n * ```\n *\n * @remarks\n * - Only available through the Responses API (not Chat Completions)\n * - Requires `computer-use-preview` model\n * - Actions include: click, double_click, drag, keypress, move, screenshot, scroll, type, wait\n * - Safety checks may be returned that require acknowledgment before proceeding\n * - Use `truncation: \"auto\"` parameter when making requests\n * - Recommended to use with `reasoning.summary` for debugging\n */\nexport function computerUse(options: ComputerUseOptions) {\n const computerTool = tool(\n async (\n input: ComputerUseInput,\n runtime: ToolRuntime<{ messages: BaseMessage[] }>\n ) => {\n /**\n * get computer_use call id from runtime\n */\n const aiMessage = runtime.state?.messages.at(-1) as AIMessage | undefined;\n const computerToolCall = aiMessage?.tool_calls?.find(\n (tc) => tc.name === \"computer_use\"\n );\n const computerToolCallId = computerToolCall?.id;\n if (!computerToolCallId) {\n throw new Error(\"Computer use call id not found\");\n }\n\n const result = await options.execute(input.action, runtime);\n\n /**\n * make sure {@link ToolMessage} is returned with the correct additional kwargs\n */\n if (typeof result === \"string\") {\n return new ToolMessage({\n content: result,\n tool_call_id: computerToolCallId,\n additional_kwargs: {\n type: \"computer_call_output\",\n },\n });\n }\n\n /**\n * make sure {@link ToolMessage} is returned with the correct additional kwargs\n */\n return new ToolMessage({\n ...result,\n tool_call_id: computerToolCallId,\n additional_kwargs: {\n type: \"computer_call_output\",\n ...result.additional_kwargs,\n },\n });\n },\n {\n name: TOOL_NAME,\n description:\n \"Control a computer interface by executing mouse clicks, keyboard input, scrolling, and other actions.\",\n schema: ComputerUseActionSchema,\n }\n );\n\n computerTool.extras = {\n ...(computerTool.extras ?? {}),\n providerToolDefinition: {\n type: \"computer_use_preview\",\n display_width: options.displayWidth,\n display_height: options.displayHeight,\n environment: options.environment,\n } satisfies ComputerUseTool,\n };\n\n /**\n * return as typed {@link DynamicStructuredTool} so we don't get any type\n * errors like \"can't export tool without reference\"\n */\n return computerTool as DynamicStructuredTool<\n typeof ComputerUseActionSchema,\n ComputerUseInput,\n unknown,\n ComputerUseReturnType\n >;\n}\n"],"mappings":";;;;;AAkDA,MAAM,oCAAoC,EAAE,OAAO,EACjD,MAAM,EAAE,QAAQ,aAAa,CAC9B,EAAC;AAEF,MAAM,+BAA+B,EAAE,OAAO;CAC5C,MAAM,EAAE,QAAQ,QAAQ;CACxB,GAAG,EAAE,QAAQ;CACb,GAAG,EAAE,QAAQ;CACb,QAAQ,EAAE,KAAK;EAAC;EAAQ;EAAS;EAAS;EAAQ;CAAU,EAAC,CAAC,QAAQ,OAAO;AAC9E,EAAC;AAEF,MAAM,qCAAqC,EAAE,OAAO;CAClD,MAAM,EAAE,QAAQ,eAAe;CAC/B,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkHlB,SAAgB,YAAYA,SAA6B;CACvD,MAAM,eAAe,KACnB,OACEC,OACAC,YACG;;;;EAIH,MAAM,YAAY,QAAQ,OAAO,SAAS,GAAG,GAAG;EAChD,MAAM,mBAAmB,WAAW,YAAY,KAC9C,CAAC,OAAO,GAAG,SAAS,eACrB;EACD,MAAM,qBAAqB,kBAAkB;AAC7C,MAAI,CAAC,mBACH,OAAM,IAAI,MAAM;EAGlB,MAAM,SAAS,MAAM,QAAQ,QAAQ,MAAM,QAAQ,QAAQ;;;;AAK3D,MAAI,OAAO,WAAW,SACpB,QAAO,IAAI,YAAY;GACrB,SAAS;GACT,cAAc;GACd,mBAAmB,EACjB,MAAM,uBACP;EACF;;;;AAMH,SAAO,IAAI,YAAY;GACrB,GAAG;GACH,cAAc;GACd,mBAAmB;IACjB,MAAM;IACN,GAAG,OAAO;GACX;EACF;CACF,GACD;EACE,MAAM;EACN,aACE;EACF,QAAQ;CACT,EACF;CAED,aAAa,SAAS;EACpB,GAAI,aAAa,UAAU,CAAE;EAC7B,wBAAwB;GACtB,MAAM;GACN,eAAe,QAAQ;GACvB,gBAAgB,QAAQ;GACxB,aAAa,QAAQ;EACtB;CACF;;;;;AAMD,QAAO;AAMR"}
@@ -11,7 +11,7 @@ const LocalShellExecActionSchema = zod_v4.z.object({
11
11
  timeout_ms: zod_v4.z.number().optional(),
12
12
  user: zod_v4.z.string().optional()
13
13
  });
14
- const LocalShellActionSchema = zod_v4.z.discriminatedUnion("type", [LocalShellExecActionSchema]);
14
+ const LocalShellActionSchema = zod_v4.z.union([LocalShellExecActionSchema]);
15
15
  const TOOL_NAME = "local_shell";
16
16
  /**
17
17
  * Creates a Local Shell tool that allows models to run shell commands locally
@@ -1 +1 @@
1
- {"version":3,"file":"localShell.cjs","names":["z","options: LocalShellOptions"],"sources":["../../src/tools/localShell.ts"],"sourcesContent":["import { z } from \"zod/v4\";\nimport { OpenAI as OpenAIClient } from \"openai\";\nimport { tool, type DynamicStructuredTool } from \"@langchain/core/tools\";\n\n/**\n * Re-export action type from OpenAI SDK for convenience.\n * The action contains command details like argv tokens, environment variables,\n * working directory, timeout, and user.\n */\nexport type LocalShellAction =\n OpenAIClient.Responses.ResponseOutputItem.LocalShellCall.Action;\n\n// Zod schema for local shell exec action\nexport const LocalShellExecActionSchema = z.object({\n type: z.literal(\"exec\"),\n command: z.array(z.string()),\n env: z.record(z.string(), z.string()).optional(),\n working_directory: z.string().optional(),\n timeout_ms: z.number().optional(),\n user: z.string().optional(),\n});\n\n// Schema for all local shell actions (currently only exec)\nexport const LocalShellActionSchema = z.discriminatedUnion(\"type\", [\n LocalShellExecActionSchema,\n]);\n\n/**\n * Options for the Local Shell tool.\n */\nexport interface LocalShellOptions {\n /**\n * Optional execute function that handles shell command execution.\n * This function receives the action input and should return the command output\n * (stdout + stderr combined).\n *\n * If not provided, you'll need to handle action execution manually by\n * checking `local_shell_call` outputs in the response.\n *\n * @example\n * ```typescript\n * execute: async (action) => {\n * const result = await exec(action.command.join(' '), {\n * cwd: action.working_directory,\n * env: { ...process.env, ...action.env },\n * timeout: action.timeout_ms,\n * });\n * return result.stdout + result.stderr;\n * }\n * ```\n */\n execute: (action: LocalShellAction) => string | Promise<string>;\n}\n\n/**\n * OpenAI Local Shell tool type for the Responses API.\n */\nexport type LocalShellTool = OpenAIClient.Responses.Tool.LocalShell;\n\nconst TOOL_NAME = \"local_shell\";\n\n/**\n * Creates a Local Shell tool that allows models to run shell commands locally\n * on a machine you provide. Commands are executed inside your own runtime—\n * the API only returns the instructions, but does not execute them on OpenAI infrastructure.\n *\n * **Important**: The local shell tool is designed to work with\n * [Codex CLI](https://github.com/openai/codex) and the `codex-mini-latest` model.\n *\n * **How it works**:\n * The tool operates in a continuous loop:\n * 1. Model sends shell commands (`local_shell_call` with `exec` action)\n * 2. Your code executes the command locally\n * 3. You return the output back to the model\n * 4. Repeat until the task is complete\n *\n * **Security Warning**: Running arbitrary shell commands can be dangerous.\n * Always sandbox execution or add strict allow/deny-lists before forwarding\n * a command to the system shell.\n *\n * @see {@link https://platform.openai.com/docs/guides/tools-local-shell | OpenAI Local Shell Documentation}\n *\n * @param options - Optional configuration for the Local Shell tool\n * @returns A Local Shell tool that can be passed to `bindTools`\n *\n * @example\n * ```typescript\n * import { ChatOpenAI, tools } from \"@langchain/openai\";\n * import { exec } from \"child_process\";\n * import { promisify } from \"util\";\n *\n * const execAsync = promisify(exec);\n * const model = new ChatOpenAI({ model: \"codex-mini-latest\" });\n *\n * // With execute callback for automatic command handling\n * const shell = tools.localShell({\n * execute: async (action) => {\n * const { command, env, working_directory, timeout_ms } = action;\n * const result = await execAsync(command.join(' '), {\n * cwd: working_directory ?? process.cwd(),\n * env: { ...process.env, ...env },\n * timeout: timeout_ms ?? undefined,\n * });\n * return result.stdout + result.stderr;\n * },\n * });\n *\n * const llmWithShell = model.bindTools([shell]);\n * const response = await llmWithShell.invoke(\n * \"List files in the current directory\"\n * );\n * ```\n *\n * @example\n * ```typescript\n * // Without execute callback (manual handling)\n * const shell = tools.localShell();\n *\n * const response = await model.invoke(\"List files\", {\n * tools: [shell],\n * });\n *\n * // Access the shell call from the response\n * const shellCall = response.additional_kwargs.tool_outputs?.find(\n * (output) => output.type === \"local_shell_call\"\n * );\n * if (shellCall) {\n * console.log(\"Command to execute:\", shellCall.action.command);\n * // Execute the command manually, then send back the output\n * }\n * ```\n *\n * @example\n * ```typescript\n * // Full shell loop example\n * async function shellLoop(model, task) {\n * let response = await model.invoke(task, {\n * tools: [tools.localShell()],\n * });\n *\n * while (true) {\n * const shellCall = response.additional_kwargs.tool_outputs?.find(\n * (output) => output.type === \"local_shell_call\"\n * );\n *\n * if (!shellCall) break;\n *\n * // Execute command (with proper sandboxing!)\n * const output = await executeCommand(shellCall.action);\n *\n * // Send output back to model\n * response = await model.invoke([\n * response,\n * {\n * type: \"local_shell_call_output\",\n * id: shellCall.call_id,\n * output: output,\n * },\n * ], {\n * tools: [tools.localShell()],\n * });\n * }\n *\n * return response;\n * }\n * ```\n *\n * @remarks\n * - Only available through the Responses API (not Chat Completions)\n * - Designed for use with `codex-mini-latest` model\n * - Commands are provided as argv tokens in `action.command`\n * - Action includes: `command`, `env`, `working_directory`, `timeout_ms`, `user`\n * - Always sandbox or validate commands before execution\n * - The `timeout_ms` from the model is only a hint—enforce your own limits\n */\nexport function localShell(options: LocalShellOptions) {\n const shellTool = tool(options.execute, {\n name: TOOL_NAME,\n description:\n \"Execute shell commands locally on the machine. Commands are provided as argv tokens.\",\n schema: LocalShellActionSchema,\n });\n\n shellTool.extras = {\n ...(shellTool.extras ?? {}),\n providerToolDefinition: {\n type: \"local_shell\",\n } satisfies LocalShellTool,\n };\n\n return shellTool as DynamicStructuredTool<\n typeof LocalShellActionSchema,\n LocalShellAction,\n unknown,\n string\n >;\n}\n"],"mappings":";;;;;AAaA,MAAa,6BAA6BA,SAAE,OAAO;CACjD,MAAMA,SAAE,QAAQ,OAAO;CACvB,SAASA,SAAE,MAAMA,SAAE,QAAQ,CAAC;CAC5B,KAAKA,SAAE,OAAOA,SAAE,QAAQ,EAAEA,SAAE,QAAQ,CAAC,CAAC,UAAU;CAChD,mBAAmBA,SAAE,QAAQ,CAAC,UAAU;CACxC,YAAYA,SAAE,QAAQ,CAAC,UAAU;CACjC,MAAMA,SAAE,QAAQ,CAAC,UAAU;AAC5B,EAAC;AAGF,MAAa,yBAAyBA,SAAE,mBAAmB,QAAQ,CACjE,0BACD,EAAC;AAkCF,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoHlB,SAAgB,WAAWC,SAA4B;CACrD,MAAM,6CAAiB,QAAQ,SAAS;EACtC,MAAM;EACN,aACE;EACF,QAAQ;CACT,EAAC;CAEF,UAAU,SAAS;EACjB,GAAI,UAAU,UAAU,CAAE;EAC1B,wBAAwB,EACtB,MAAM,cACP;CACF;AAED,QAAO;AAMR"}
1
+ {"version":3,"file":"localShell.cjs","names":["z","options: LocalShellOptions"],"sources":["../../src/tools/localShell.ts"],"sourcesContent":["import { z } from \"zod/v4\";\nimport { OpenAI as OpenAIClient } from \"openai\";\nimport { tool, type DynamicStructuredTool } from \"@langchain/core/tools\";\n\n/**\n * Re-export action type from OpenAI SDK for convenience.\n * The action contains command details like argv tokens, environment variables,\n * working directory, timeout, and user.\n */\nexport type LocalShellAction =\n OpenAIClient.Responses.ResponseOutputItem.LocalShellCall.Action;\n\n// Zod schema for local shell exec action\nexport const LocalShellExecActionSchema = z.object({\n type: z.literal(\"exec\"),\n command: z.array(z.string()),\n env: z.record(z.string(), z.string()).optional(),\n working_directory: z.string().optional(),\n timeout_ms: z.number().optional(),\n user: z.string().optional(),\n});\n\n// Schema for all local shell actions (currently only exec)\nexport const LocalShellActionSchema = z.union([LocalShellExecActionSchema]);\n\n/**\n * Options for the Local Shell tool.\n */\nexport interface LocalShellOptions {\n /**\n * Optional execute function that handles shell command execution.\n * This function receives the action input and should return the command output\n * (stdout + stderr combined).\n *\n * If not provided, you'll need to handle action execution manually by\n * checking `local_shell_call` outputs in the response.\n *\n * @example\n * ```typescript\n * execute: async (action) => {\n * const result = await exec(action.command.join(' '), {\n * cwd: action.working_directory,\n * env: { ...process.env, ...action.env },\n * timeout: action.timeout_ms,\n * });\n * return result.stdout + result.stderr;\n * }\n * ```\n */\n execute: (action: LocalShellAction) => string | Promise<string>;\n}\n\n/**\n * OpenAI Local Shell tool type for the Responses API.\n */\nexport type LocalShellTool = OpenAIClient.Responses.Tool.LocalShell;\n\nconst TOOL_NAME = \"local_shell\";\n\n/**\n * Creates a Local Shell tool that allows models to run shell commands locally\n * on a machine you provide. Commands are executed inside your own runtime—\n * the API only returns the instructions, but does not execute them on OpenAI infrastructure.\n *\n * **Important**: The local shell tool is designed to work with\n * [Codex CLI](https://github.com/openai/codex) and the `codex-mini-latest` model.\n *\n * **How it works**:\n * The tool operates in a continuous loop:\n * 1. Model sends shell commands (`local_shell_call` with `exec` action)\n * 2. Your code executes the command locally\n * 3. You return the output back to the model\n * 4. Repeat until the task is complete\n *\n * **Security Warning**: Running arbitrary shell commands can be dangerous.\n * Always sandbox execution or add strict allow/deny-lists before forwarding\n * a command to the system shell.\n *\n * @see {@link https://platform.openai.com/docs/guides/tools-local-shell | OpenAI Local Shell Documentation}\n *\n * @param options - Optional configuration for the Local Shell tool\n * @returns A Local Shell tool that can be passed to `bindTools`\n *\n * @example\n * ```typescript\n * import { ChatOpenAI, tools } from \"@langchain/openai\";\n * import { exec } from \"child_process\";\n * import { promisify } from \"util\";\n *\n * const execAsync = promisify(exec);\n * const model = new ChatOpenAI({ model: \"codex-mini-latest\" });\n *\n * // With execute callback for automatic command handling\n * const shell = tools.localShell({\n * execute: async (action) => {\n * const { command, env, working_directory, timeout_ms } = action;\n * const result = await execAsync(command.join(' '), {\n * cwd: working_directory ?? process.cwd(),\n * env: { ...process.env, ...env },\n * timeout: timeout_ms ?? undefined,\n * });\n * return result.stdout + result.stderr;\n * },\n * });\n *\n * const llmWithShell = model.bindTools([shell]);\n * const response = await llmWithShell.invoke(\n * \"List files in the current directory\"\n * );\n * ```\n *\n * @example\n * ```typescript\n * // Without execute callback (manual handling)\n * const shell = tools.localShell();\n *\n * const response = await model.invoke(\"List files\", {\n * tools: [shell],\n * });\n *\n * // Access the shell call from the response\n * const shellCall = response.additional_kwargs.tool_outputs?.find(\n * (output) => output.type === \"local_shell_call\"\n * );\n * if (shellCall) {\n * console.log(\"Command to execute:\", shellCall.action.command);\n * // Execute the command manually, then send back the output\n * }\n * ```\n *\n * @example\n * ```typescript\n * // Full shell loop example\n * async function shellLoop(model, task) {\n * let response = await model.invoke(task, {\n * tools: [tools.localShell()],\n * });\n *\n * while (true) {\n * const shellCall = response.additional_kwargs.tool_outputs?.find(\n * (output) => output.type === \"local_shell_call\"\n * );\n *\n * if (!shellCall) break;\n *\n * // Execute command (with proper sandboxing!)\n * const output = await executeCommand(shellCall.action);\n *\n * // Send output back to model\n * response = await model.invoke([\n * response,\n * {\n * type: \"local_shell_call_output\",\n * id: shellCall.call_id,\n * output: output,\n * },\n * ], {\n * tools: [tools.localShell()],\n * });\n * }\n *\n * return response;\n * }\n * ```\n *\n * @remarks\n * - Only available through the Responses API (not Chat Completions)\n * - Designed for use with `codex-mini-latest` model\n * - Commands are provided as argv tokens in `action.command`\n * - Action includes: `command`, `env`, `working_directory`, `timeout_ms`, `user`\n * - Always sandbox or validate commands before execution\n * - The `timeout_ms` from the model is only a hint—enforce your own limits\n */\nexport function localShell(options: LocalShellOptions) {\n const shellTool = tool(options.execute, {\n name: TOOL_NAME,\n description:\n \"Execute shell commands locally on the machine. Commands are provided as argv tokens.\",\n schema: LocalShellActionSchema,\n });\n\n shellTool.extras = {\n ...(shellTool.extras ?? {}),\n providerToolDefinition: {\n type: \"local_shell\",\n } satisfies LocalShellTool,\n };\n\n return shellTool as DynamicStructuredTool<\n typeof LocalShellActionSchema,\n LocalShellAction,\n unknown,\n string\n >;\n}\n"],"mappings":";;;;;AAaA,MAAa,6BAA6BA,SAAE,OAAO;CACjD,MAAMA,SAAE,QAAQ,OAAO;CACvB,SAASA,SAAE,MAAMA,SAAE,QAAQ,CAAC;CAC5B,KAAKA,SAAE,OAAOA,SAAE,QAAQ,EAAEA,SAAE,QAAQ,CAAC,CAAC,UAAU;CAChD,mBAAmBA,SAAE,QAAQ,CAAC,UAAU;CACxC,YAAYA,SAAE,QAAQ,CAAC,UAAU;CACjC,MAAMA,SAAE,QAAQ,CAAC,UAAU;AAC5B,EAAC;AAGF,MAAa,yBAAyBA,SAAE,MAAM,CAAC,0BAA2B,EAAC;AAkC3E,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoHlB,SAAgB,WAAWC,SAA4B;CACrD,MAAM,6CAAiB,QAAQ,SAAS;EACtC,MAAM;EACN,aACE;EACF,QAAQ;CACT,EAAC;CAEF,UAAU,SAAS;EACjB,GAAI,UAAU,UAAU,CAAE;EAC1B,wBAAwB,EACtB,MAAM,cACP;CACF;AAED,QAAO;AAMR"}
@@ -154,7 +154,7 @@ type LocalShellTool = OpenAI$1.Responses.Tool.LocalShell;
154
154
  * - Always sandbox or validate commands before execution
155
155
  * - The `timeout_ms` from the model is only a hint—enforce your own limits
156
156
  */
157
- declare function localShell(options: LocalShellOptions): DynamicStructuredTool<z.ZodDiscriminatedUnion<[z.ZodObject<{
157
+ declare function localShell(options: LocalShellOptions): DynamicStructuredTool<z.ZodUnion<readonly [z.ZodObject<{
158
158
  type: z.ZodLiteral<"exec">;
159
159
  command: z.ZodArray<z.ZodString>;
160
160
  env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
@@ -1 +1 @@
1
- {"version":3,"file":"localShell.d.cts","names":["z","OpenAI","OpenAIClient","DynamicStructuredTool","LocalShellAction","Responses","ResponseOutputItem","LocalShellCall","Action","LocalShellExecActionSchema","ZodLiteral","ZodString","ZodArray","ZodRecord","ZodOptional","ZodNumber","core","$strip","ZodObject","LocalShellActionSchema","ZodDiscriminatedUnion","LocalShellOptions","Promise","LocalShellTool","Tool","LocalShell","localShell"],"sources":["../../src/tools/localShell.d.ts"],"sourcesContent":["import { z } from \"zod/v4\";\nimport { OpenAI as OpenAIClient } from \"openai\";\nimport { type DynamicStructuredTool } from \"@langchain/core/tools\";\n/**\n * Re-export action type from OpenAI SDK for convenience.\n * The action contains command details like argv tokens, environment variables,\n * working directory, timeout, and user.\n */\nexport type LocalShellAction = OpenAIClient.Responses.ResponseOutputItem.LocalShellCall.Action;\nexport declare const LocalShellExecActionSchema: z.ZodObject<{\n type: z.ZodLiteral<\"exec\">;\n command: z.ZodArray<z.ZodString>;\n env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;\n working_directory: z.ZodOptional<z.ZodString>;\n timeout_ms: z.ZodOptional<z.ZodNumber>;\n user: z.ZodOptional<z.ZodString>;\n}, z.core.$strip>;\nexport declare const LocalShellActionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{\n type: z.ZodLiteral<\"exec\">;\n command: z.ZodArray<z.ZodString>;\n env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;\n working_directory: z.ZodOptional<z.ZodString>;\n timeout_ms: z.ZodOptional<z.ZodNumber>;\n user: z.ZodOptional<z.ZodString>;\n}, z.core.$strip>]>;\n/**\n * Options for the Local Shell tool.\n */\nexport interface LocalShellOptions {\n /**\n * Optional execute function that handles shell command execution.\n * This function receives the action input and should return the command output\n * (stdout + stderr combined).\n *\n * If not provided, you'll need to handle action execution manually by\n * checking `local_shell_call` outputs in the response.\n *\n * @example\n * ```typescript\n * execute: async (action) => {\n * const result = await exec(action.command.join(' '), {\n * cwd: action.working_directory,\n * env: { ...process.env, ...action.env },\n * timeout: action.timeout_ms,\n * });\n * return result.stdout + result.stderr;\n * }\n * ```\n */\n execute: (action: LocalShellAction) => string | Promise<string>;\n}\n/**\n * OpenAI Local Shell tool type for the Responses API.\n */\nexport type LocalShellTool = OpenAIClient.Responses.Tool.LocalShell;\n/**\n * Creates a Local Shell tool that allows models to run shell commands locally\n * on a machine you provide. Commands are executed inside your own runtime—\n * the API only returns the instructions, but does not execute them on OpenAI infrastructure.\n *\n * **Important**: The local shell tool is designed to work with\n * [Codex CLI](https://github.com/openai/codex) and the `codex-mini-latest` model.\n *\n * **How it works**:\n * The tool operates in a continuous loop:\n * 1. Model sends shell commands (`local_shell_call` with `exec` action)\n * 2. Your code executes the command locally\n * 3. You return the output back to the model\n * 4. Repeat until the task is complete\n *\n * **Security Warning**: Running arbitrary shell commands can be dangerous.\n * Always sandbox execution or add strict allow/deny-lists before forwarding\n * a command to the system shell.\n *\n * @see {@link https://platform.openai.com/docs/guides/tools-local-shell | OpenAI Local Shell Documentation}\n *\n * @param options - Optional configuration for the Local Shell tool\n * @returns A Local Shell tool that can be passed to `bindTools`\n *\n * @example\n * ```typescript\n * import { ChatOpenAI, tools } from \"@langchain/openai\";\n * import { exec } from \"child_process\";\n * import { promisify } from \"util\";\n *\n * const execAsync = promisify(exec);\n * const model = new ChatOpenAI({ model: \"codex-mini-latest\" });\n *\n * // With execute callback for automatic command handling\n * const shell = tools.localShell({\n * execute: async (action) => {\n * const { command, env, working_directory, timeout_ms } = action;\n * const result = await execAsync(command.join(' '), {\n * cwd: working_directory ?? process.cwd(),\n * env: { ...process.env, ...env },\n * timeout: timeout_ms ?? undefined,\n * });\n * return result.stdout + result.stderr;\n * },\n * });\n *\n * const llmWithShell = model.bindTools([shell]);\n * const response = await llmWithShell.invoke(\n * \"List files in the current directory\"\n * );\n * ```\n *\n * @example\n * ```typescript\n * // Without execute callback (manual handling)\n * const shell = tools.localShell();\n *\n * const response = await model.invoke(\"List files\", {\n * tools: [shell],\n * });\n *\n * // Access the shell call from the response\n * const shellCall = response.additional_kwargs.tool_outputs?.find(\n * (output) => output.type === \"local_shell_call\"\n * );\n * if (shellCall) {\n * console.log(\"Command to execute:\", shellCall.action.command);\n * // Execute the command manually, then send back the output\n * }\n * ```\n *\n * @example\n * ```typescript\n * // Full shell loop example\n * async function shellLoop(model, task) {\n * let response = await model.invoke(task, {\n * tools: [tools.localShell()],\n * });\n *\n * while (true) {\n * const shellCall = response.additional_kwargs.tool_outputs?.find(\n * (output) => output.type === \"local_shell_call\"\n * );\n *\n * if (!shellCall) break;\n *\n * // Execute command (with proper sandboxing!)\n * const output = await executeCommand(shellCall.action);\n *\n * // Send output back to model\n * response = await model.invoke([\n * response,\n * {\n * type: \"local_shell_call_output\",\n * id: shellCall.call_id,\n * output: output,\n * },\n * ], {\n * tools: [tools.localShell()],\n * });\n * }\n *\n * return response;\n * }\n * ```\n *\n * @remarks\n * - Only available through the Responses API (not Chat Completions)\n * - Designed for use with `codex-mini-latest` model\n * - Commands are provided as argv tokens in `action.command`\n * - Action includes: `command`, `env`, `working_directory`, `timeout_ms`, `user`\n * - Always sandbox or validate commands before execution\n * - The `timeout_ms` from the model is only a hint—enforce your own limits\n */\nexport declare function localShell(options: LocalShellOptions): DynamicStructuredTool<z.ZodDiscriminatedUnion<[z.ZodObject<{\n type: z.ZodLiteral<\"exec\">;\n command: z.ZodArray<z.ZodString>;\n env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;\n working_directory: z.ZodOptional<z.ZodString>;\n timeout_ms: z.ZodOptional<z.ZodNumber>;\n user: z.ZodOptional<z.ZodString>;\n}, z.core.$strip>]>, OpenAIClient.Responses.ResponseOutputItem.LocalShellCall.Action, unknown, string, string>;\n//# sourceMappingURL=localShell.d.ts.map"],"mappings":";;;;;;;;AAQA;AAoBA;AA0BA;AAmHwB0B,KAjKZtB,gBAAAA,GAAmBF,QAAAA,CAAaG,SAAAA,CAAUC,kBAAAA,CAAmBC,cAAAA,CAAeC,MAiKtD;;;;AAAmD,UA7IpEa,iBAAAA,CA6IoE;;;;;;;;;;;;;;;;;;;;;oBAxH/DjB,8BAA8BkB;;;;;KAKxCC,cAAAA,GAAiBrB,QAAAA,CAAaG,SAAAA,CAAUmB,IAAAA,CAAKC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAmHjCC,UAAAA,UAAoBL,oBAAoBlB,sBAAsBH,CAAAA,CAAEoB,uBAAuBpB,CAAAA,CAAEkB;QACvGlB,CAAAA,CAAEU;WACCV,CAAAA,CAAEY,SAASZ,CAAAA,CAAEW;OACjBX,CAAAA,CAAEc,YAAYd,CAAAA,CAAEa,UAAUb,CAAAA,CAAEW,WAAWX,CAAAA,CAAEW;qBAC3BX,CAAAA,CAAEc,YAAYd,CAAAA,CAAEW;cACvBX,CAAAA,CAAEc,YAAYd,CAAAA,CAAEe;QACtBf,CAAAA,CAAEc,YAAYd,CAAAA,CAAEW;GACvBX,CAAAA,CAAEgB,IAAAA,CAAKC,WAAWf,QAAAA,CAAaG,SAAAA,CAAUC,kBAAAA,CAAmBC,cAAAA,CAAeC"}
1
+ {"version":3,"file":"localShell.d.cts","names":["z","OpenAI","OpenAIClient","DynamicStructuredTool","LocalShellAction","Responses","ResponseOutputItem","LocalShellCall","Action","LocalShellExecActionSchema","ZodLiteral","ZodString","ZodArray","ZodRecord","ZodOptional","ZodNumber","core","$strip","ZodObject","LocalShellActionSchema","ZodUnion","LocalShellOptions","Promise","LocalShellTool","Tool","LocalShell","localShell"],"sources":["../../src/tools/localShell.d.ts"],"sourcesContent":["import { z } from \"zod/v4\";\nimport { OpenAI as OpenAIClient } from \"openai\";\nimport { type DynamicStructuredTool } from \"@langchain/core/tools\";\n/**\n * Re-export action type from OpenAI SDK for convenience.\n * The action contains command details like argv tokens, environment variables,\n * working directory, timeout, and user.\n */\nexport type LocalShellAction = OpenAIClient.Responses.ResponseOutputItem.LocalShellCall.Action;\nexport declare const LocalShellExecActionSchema: z.ZodObject<{\n type: z.ZodLiteral<\"exec\">;\n command: z.ZodArray<z.ZodString>;\n env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;\n working_directory: z.ZodOptional<z.ZodString>;\n timeout_ms: z.ZodOptional<z.ZodNumber>;\n user: z.ZodOptional<z.ZodString>;\n}, z.core.$strip>;\nexport declare const LocalShellActionSchema: z.ZodUnion<readonly [z.ZodObject<{\n type: z.ZodLiteral<\"exec\">;\n command: z.ZodArray<z.ZodString>;\n env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;\n working_directory: z.ZodOptional<z.ZodString>;\n timeout_ms: z.ZodOptional<z.ZodNumber>;\n user: z.ZodOptional<z.ZodString>;\n}, z.core.$strip>]>;\n/**\n * Options for the Local Shell tool.\n */\nexport interface LocalShellOptions {\n /**\n * Optional execute function that handles shell command execution.\n * This function receives the action input and should return the command output\n * (stdout + stderr combined).\n *\n * If not provided, you'll need to handle action execution manually by\n * checking `local_shell_call` outputs in the response.\n *\n * @example\n * ```typescript\n * execute: async (action) => {\n * const result = await exec(action.command.join(' '), {\n * cwd: action.working_directory,\n * env: { ...process.env, ...action.env },\n * timeout: action.timeout_ms,\n * });\n * return result.stdout + result.stderr;\n * }\n * ```\n */\n execute: (action: LocalShellAction) => string | Promise<string>;\n}\n/**\n * OpenAI Local Shell tool type for the Responses API.\n */\nexport type LocalShellTool = OpenAIClient.Responses.Tool.LocalShell;\n/**\n * Creates a Local Shell tool that allows models to run shell commands locally\n * on a machine you provide. Commands are executed inside your own runtime—\n * the API only returns the instructions, but does not execute them on OpenAI infrastructure.\n *\n * **Important**: The local shell tool is designed to work with\n * [Codex CLI](https://github.com/openai/codex) and the `codex-mini-latest` model.\n *\n * **How it works**:\n * The tool operates in a continuous loop:\n * 1. Model sends shell commands (`local_shell_call` with `exec` action)\n * 2. Your code executes the command locally\n * 3. You return the output back to the model\n * 4. Repeat until the task is complete\n *\n * **Security Warning**: Running arbitrary shell commands can be dangerous.\n * Always sandbox execution or add strict allow/deny-lists before forwarding\n * a command to the system shell.\n *\n * @see {@link https://platform.openai.com/docs/guides/tools-local-shell | OpenAI Local Shell Documentation}\n *\n * @param options - Optional configuration for the Local Shell tool\n * @returns A Local Shell tool that can be passed to `bindTools`\n *\n * @example\n * ```typescript\n * import { ChatOpenAI, tools } from \"@langchain/openai\";\n * import { exec } from \"child_process\";\n * import { promisify } from \"util\";\n *\n * const execAsync = promisify(exec);\n * const model = new ChatOpenAI({ model: \"codex-mini-latest\" });\n *\n * // With execute callback for automatic command handling\n * const shell = tools.localShell({\n * execute: async (action) => {\n * const { command, env, working_directory, timeout_ms } = action;\n * const result = await execAsync(command.join(' '), {\n * cwd: working_directory ?? process.cwd(),\n * env: { ...process.env, ...env },\n * timeout: timeout_ms ?? undefined,\n * });\n * return result.stdout + result.stderr;\n * },\n * });\n *\n * const llmWithShell = model.bindTools([shell]);\n * const response = await llmWithShell.invoke(\n * \"List files in the current directory\"\n * );\n * ```\n *\n * @example\n * ```typescript\n * // Without execute callback (manual handling)\n * const shell = tools.localShell();\n *\n * const response = await model.invoke(\"List files\", {\n * tools: [shell],\n * });\n *\n * // Access the shell call from the response\n * const shellCall = response.additional_kwargs.tool_outputs?.find(\n * (output) => output.type === \"local_shell_call\"\n * );\n * if (shellCall) {\n * console.log(\"Command to execute:\", shellCall.action.command);\n * // Execute the command manually, then send back the output\n * }\n * ```\n *\n * @example\n * ```typescript\n * // Full shell loop example\n * async function shellLoop(model, task) {\n * let response = await model.invoke(task, {\n * tools: [tools.localShell()],\n * });\n *\n * while (true) {\n * const shellCall = response.additional_kwargs.tool_outputs?.find(\n * (output) => output.type === \"local_shell_call\"\n * );\n *\n * if (!shellCall) break;\n *\n * // Execute command (with proper sandboxing!)\n * const output = await executeCommand(shellCall.action);\n *\n * // Send output back to model\n * response = await model.invoke([\n * response,\n * {\n * type: \"local_shell_call_output\",\n * id: shellCall.call_id,\n * output: output,\n * },\n * ], {\n * tools: [tools.localShell()],\n * });\n * }\n *\n * return response;\n * }\n * ```\n *\n * @remarks\n * - Only available through the Responses API (not Chat Completions)\n * - Designed for use with `codex-mini-latest` model\n * - Commands are provided as argv tokens in `action.command`\n * - Action includes: `command`, `env`, `working_directory`, `timeout_ms`, `user`\n * - Always sandbox or validate commands before execution\n * - The `timeout_ms` from the model is only a hint—enforce your own limits\n */\nexport declare function localShell(options: LocalShellOptions): DynamicStructuredTool<z.ZodUnion<readonly [z.ZodObject<{\n type: z.ZodLiteral<\"exec\">;\n command: z.ZodArray<z.ZodString>;\n env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;\n working_directory: z.ZodOptional<z.ZodString>;\n timeout_ms: z.ZodOptional<z.ZodNumber>;\n user: z.ZodOptional<z.ZodString>;\n}, z.core.$strip>]>, OpenAIClient.Responses.ResponseOutputItem.LocalShellCall.Action, unknown, string, string>;\n//# sourceMappingURL=localShell.d.ts.map"],"mappings":";;;;;;;;AAQA;AAoBA;AA0BA;AAmHwB0B,KAjKZtB,gBAAAA,GAAmBF,QAAAA,CAAaG,SAAAA,CAAUC,kBAAAA,CAAmBC,cAAAA,CAAeC,MAiKtD;;;;AAAmD,UA7IpEa,iBAAAA,CA6IoE;;;;;;;;;;;;;;;;;;;;;oBAxH/DjB,8BAA8BkB;;;;;KAKxCC,cAAAA,GAAiBrB,QAAAA,CAAaG,SAAAA,CAAUmB,IAAAA,CAAKC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAmHjCC,UAAAA,UAAoBL,oBAAoBlB,sBAAsBH,CAAAA,CAAEoB,mBAAmBpB,CAAAA,CAAEkB;QACnGlB,CAAAA,CAAEU;WACCV,CAAAA,CAAEY,SAASZ,CAAAA,CAAEW;OACjBX,CAAAA,CAAEc,YAAYd,CAAAA,CAAEa,UAAUb,CAAAA,CAAEW,WAAWX,CAAAA,CAAEW;qBAC3BX,CAAAA,CAAEc,YAAYd,CAAAA,CAAEW;cACvBX,CAAAA,CAAEc,YAAYd,CAAAA,CAAEe;QACtBf,CAAAA,CAAEc,YAAYd,CAAAA,CAAEW;GACvBX,CAAAA,CAAEgB,IAAAA,CAAKC,WAAWf,QAAAA,CAAaG,SAAAA,CAAUC,kBAAAA,CAAmBC,cAAAA,CAAeC"}
@@ -154,7 +154,7 @@ type LocalShellTool = OpenAI$1.Responses.Tool.LocalShell;
154
154
  * - Always sandbox or validate commands before execution
155
155
  * - The `timeout_ms` from the model is only a hint—enforce your own limits
156
156
  */
157
- declare function localShell(options: LocalShellOptions): DynamicStructuredTool<z.ZodDiscriminatedUnion<[z.ZodObject<{
157
+ declare function localShell(options: LocalShellOptions): DynamicStructuredTool<z.ZodUnion<readonly [z.ZodObject<{
158
158
  type: z.ZodLiteral<"exec">;
159
159
  command: z.ZodArray<z.ZodString>;
160
160
  env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
@@ -1 +1 @@
1
- {"version":3,"file":"localShell.d.ts","names":["z","OpenAI","OpenAIClient","DynamicStructuredTool","LocalShellAction","Responses","ResponseOutputItem","LocalShellCall","Action","LocalShellExecActionSchema","ZodLiteral","ZodString","ZodArray","ZodRecord","ZodOptional","ZodNumber","core","$strip","ZodObject","LocalShellActionSchema","ZodDiscriminatedUnion","LocalShellOptions","Promise","LocalShellTool","Tool","LocalShell","localShell"],"sources":["../../src/tools/localShell.d.ts"],"sourcesContent":["import { z } from \"zod/v4\";\nimport { OpenAI as OpenAIClient } from \"openai\";\nimport { type DynamicStructuredTool } from \"@langchain/core/tools\";\n/**\n * Re-export action type from OpenAI SDK for convenience.\n * The action contains command details like argv tokens, environment variables,\n * working directory, timeout, and user.\n */\nexport type LocalShellAction = OpenAIClient.Responses.ResponseOutputItem.LocalShellCall.Action;\nexport declare const LocalShellExecActionSchema: z.ZodObject<{\n type: z.ZodLiteral<\"exec\">;\n command: z.ZodArray<z.ZodString>;\n env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;\n working_directory: z.ZodOptional<z.ZodString>;\n timeout_ms: z.ZodOptional<z.ZodNumber>;\n user: z.ZodOptional<z.ZodString>;\n}, z.core.$strip>;\nexport declare const LocalShellActionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{\n type: z.ZodLiteral<\"exec\">;\n command: z.ZodArray<z.ZodString>;\n env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;\n working_directory: z.ZodOptional<z.ZodString>;\n timeout_ms: z.ZodOptional<z.ZodNumber>;\n user: z.ZodOptional<z.ZodString>;\n}, z.core.$strip>]>;\n/**\n * Options for the Local Shell tool.\n */\nexport interface LocalShellOptions {\n /**\n * Optional execute function that handles shell command execution.\n * This function receives the action input and should return the command output\n * (stdout + stderr combined).\n *\n * If not provided, you'll need to handle action execution manually by\n * checking `local_shell_call` outputs in the response.\n *\n * @example\n * ```typescript\n * execute: async (action) => {\n * const result = await exec(action.command.join(' '), {\n * cwd: action.working_directory,\n * env: { ...process.env, ...action.env },\n * timeout: action.timeout_ms,\n * });\n * return result.stdout + result.stderr;\n * }\n * ```\n */\n execute: (action: LocalShellAction) => string | Promise<string>;\n}\n/**\n * OpenAI Local Shell tool type for the Responses API.\n */\nexport type LocalShellTool = OpenAIClient.Responses.Tool.LocalShell;\n/**\n * Creates a Local Shell tool that allows models to run shell commands locally\n * on a machine you provide. Commands are executed inside your own runtime—\n * the API only returns the instructions, but does not execute them on OpenAI infrastructure.\n *\n * **Important**: The local shell tool is designed to work with\n * [Codex CLI](https://github.com/openai/codex) and the `codex-mini-latest` model.\n *\n * **How it works**:\n * The tool operates in a continuous loop:\n * 1. Model sends shell commands (`local_shell_call` with `exec` action)\n * 2. Your code executes the command locally\n * 3. You return the output back to the model\n * 4. Repeat until the task is complete\n *\n * **Security Warning**: Running arbitrary shell commands can be dangerous.\n * Always sandbox execution or add strict allow/deny-lists before forwarding\n * a command to the system shell.\n *\n * @see {@link https://platform.openai.com/docs/guides/tools-local-shell | OpenAI Local Shell Documentation}\n *\n * @param options - Optional configuration for the Local Shell tool\n * @returns A Local Shell tool that can be passed to `bindTools`\n *\n * @example\n * ```typescript\n * import { ChatOpenAI, tools } from \"@langchain/openai\";\n * import { exec } from \"child_process\";\n * import { promisify } from \"util\";\n *\n * const execAsync = promisify(exec);\n * const model = new ChatOpenAI({ model: \"codex-mini-latest\" });\n *\n * // With execute callback for automatic command handling\n * const shell = tools.localShell({\n * execute: async (action) => {\n * const { command, env, working_directory, timeout_ms } = action;\n * const result = await execAsync(command.join(' '), {\n * cwd: working_directory ?? process.cwd(),\n * env: { ...process.env, ...env },\n * timeout: timeout_ms ?? undefined,\n * });\n * return result.stdout + result.stderr;\n * },\n * });\n *\n * const llmWithShell = model.bindTools([shell]);\n * const response = await llmWithShell.invoke(\n * \"List files in the current directory\"\n * );\n * ```\n *\n * @example\n * ```typescript\n * // Without execute callback (manual handling)\n * const shell = tools.localShell();\n *\n * const response = await model.invoke(\"List files\", {\n * tools: [shell],\n * });\n *\n * // Access the shell call from the response\n * const shellCall = response.additional_kwargs.tool_outputs?.find(\n * (output) => output.type === \"local_shell_call\"\n * );\n * if (shellCall) {\n * console.log(\"Command to execute:\", shellCall.action.command);\n * // Execute the command manually, then send back the output\n * }\n * ```\n *\n * @example\n * ```typescript\n * // Full shell loop example\n * async function shellLoop(model, task) {\n * let response = await model.invoke(task, {\n * tools: [tools.localShell()],\n * });\n *\n * while (true) {\n * const shellCall = response.additional_kwargs.tool_outputs?.find(\n * (output) => output.type === \"local_shell_call\"\n * );\n *\n * if (!shellCall) break;\n *\n * // Execute command (with proper sandboxing!)\n * const output = await executeCommand(shellCall.action);\n *\n * // Send output back to model\n * response = await model.invoke([\n * response,\n * {\n * type: \"local_shell_call_output\",\n * id: shellCall.call_id,\n * output: output,\n * },\n * ], {\n * tools: [tools.localShell()],\n * });\n * }\n *\n * return response;\n * }\n * ```\n *\n * @remarks\n * - Only available through the Responses API (not Chat Completions)\n * - Designed for use with `codex-mini-latest` model\n * - Commands are provided as argv tokens in `action.command`\n * - Action includes: `command`, `env`, `working_directory`, `timeout_ms`, `user`\n * - Always sandbox or validate commands before execution\n * - The `timeout_ms` from the model is only a hint—enforce your own limits\n */\nexport declare function localShell(options: LocalShellOptions): DynamicStructuredTool<z.ZodDiscriminatedUnion<[z.ZodObject<{\n type: z.ZodLiteral<\"exec\">;\n command: z.ZodArray<z.ZodString>;\n env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;\n working_directory: z.ZodOptional<z.ZodString>;\n timeout_ms: z.ZodOptional<z.ZodNumber>;\n user: z.ZodOptional<z.ZodString>;\n}, z.core.$strip>]>, OpenAIClient.Responses.ResponseOutputItem.LocalShellCall.Action, unknown, string, string>;\n//# sourceMappingURL=localShell.d.ts.map"],"mappings":";;;;;;;;AAQA;AAoBA;AA0BA;AAmHwB0B,KAjKZtB,gBAAAA,GAAmBF,QAAAA,CAAaG,SAAAA,CAAUC,kBAAAA,CAAmBC,cAAAA,CAAeC,MAiKtD;;;;AAAmD,UA7IpEa,iBAAAA,CA6IoE;;;;;;;;;;;;;;;;;;;;;oBAxH/DjB,8BAA8BkB;;;;;KAKxCC,cAAAA,GAAiBrB,QAAAA,CAAaG,SAAAA,CAAUmB,IAAAA,CAAKC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAmHjCC,UAAAA,UAAoBL,oBAAoBlB,sBAAsBH,CAAAA,CAAEoB,uBAAuBpB,CAAAA,CAAEkB;QACvGlB,CAAAA,CAAEU;WACCV,CAAAA,CAAEY,SAASZ,CAAAA,CAAEW;OACjBX,CAAAA,CAAEc,YAAYd,CAAAA,CAAEa,UAAUb,CAAAA,CAAEW,WAAWX,CAAAA,CAAEW;qBAC3BX,CAAAA,CAAEc,YAAYd,CAAAA,CAAEW;cACvBX,CAAAA,CAAEc,YAAYd,CAAAA,CAAEe;QACtBf,CAAAA,CAAEc,YAAYd,CAAAA,CAAEW;GACvBX,CAAAA,CAAEgB,IAAAA,CAAKC,WAAWf,QAAAA,CAAaG,SAAAA,CAAUC,kBAAAA,CAAmBC,cAAAA,CAAeC"}
1
+ {"version":3,"file":"localShell.d.ts","names":["z","OpenAI","OpenAIClient","DynamicStructuredTool","LocalShellAction","Responses","ResponseOutputItem","LocalShellCall","Action","LocalShellExecActionSchema","ZodLiteral","ZodString","ZodArray","ZodRecord","ZodOptional","ZodNumber","core","$strip","ZodObject","LocalShellActionSchema","ZodUnion","LocalShellOptions","Promise","LocalShellTool","Tool","LocalShell","localShell"],"sources":["../../src/tools/localShell.d.ts"],"sourcesContent":["import { z } from \"zod/v4\";\nimport { OpenAI as OpenAIClient } from \"openai\";\nimport { type DynamicStructuredTool } from \"@langchain/core/tools\";\n/**\n * Re-export action type from OpenAI SDK for convenience.\n * The action contains command details like argv tokens, environment variables,\n * working directory, timeout, and user.\n */\nexport type LocalShellAction = OpenAIClient.Responses.ResponseOutputItem.LocalShellCall.Action;\nexport declare const LocalShellExecActionSchema: z.ZodObject<{\n type: z.ZodLiteral<\"exec\">;\n command: z.ZodArray<z.ZodString>;\n env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;\n working_directory: z.ZodOptional<z.ZodString>;\n timeout_ms: z.ZodOptional<z.ZodNumber>;\n user: z.ZodOptional<z.ZodString>;\n}, z.core.$strip>;\nexport declare const LocalShellActionSchema: z.ZodUnion<readonly [z.ZodObject<{\n type: z.ZodLiteral<\"exec\">;\n command: z.ZodArray<z.ZodString>;\n env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;\n working_directory: z.ZodOptional<z.ZodString>;\n timeout_ms: z.ZodOptional<z.ZodNumber>;\n user: z.ZodOptional<z.ZodString>;\n}, z.core.$strip>]>;\n/**\n * Options for the Local Shell tool.\n */\nexport interface LocalShellOptions {\n /**\n * Optional execute function that handles shell command execution.\n * This function receives the action input and should return the command output\n * (stdout + stderr combined).\n *\n * If not provided, you'll need to handle action execution manually by\n * checking `local_shell_call` outputs in the response.\n *\n * @example\n * ```typescript\n * execute: async (action) => {\n * const result = await exec(action.command.join(' '), {\n * cwd: action.working_directory,\n * env: { ...process.env, ...action.env },\n * timeout: action.timeout_ms,\n * });\n * return result.stdout + result.stderr;\n * }\n * ```\n */\n execute: (action: LocalShellAction) => string | Promise<string>;\n}\n/**\n * OpenAI Local Shell tool type for the Responses API.\n */\nexport type LocalShellTool = OpenAIClient.Responses.Tool.LocalShell;\n/**\n * Creates a Local Shell tool that allows models to run shell commands locally\n * on a machine you provide. Commands are executed inside your own runtime—\n * the API only returns the instructions, but does not execute them on OpenAI infrastructure.\n *\n * **Important**: The local shell tool is designed to work with\n * [Codex CLI](https://github.com/openai/codex) and the `codex-mini-latest` model.\n *\n * **How it works**:\n * The tool operates in a continuous loop:\n * 1. Model sends shell commands (`local_shell_call` with `exec` action)\n * 2. Your code executes the command locally\n * 3. You return the output back to the model\n * 4. Repeat until the task is complete\n *\n * **Security Warning**: Running arbitrary shell commands can be dangerous.\n * Always sandbox execution or add strict allow/deny-lists before forwarding\n * a command to the system shell.\n *\n * @see {@link https://platform.openai.com/docs/guides/tools-local-shell | OpenAI Local Shell Documentation}\n *\n * @param options - Optional configuration for the Local Shell tool\n * @returns A Local Shell tool that can be passed to `bindTools`\n *\n * @example\n * ```typescript\n * import { ChatOpenAI, tools } from \"@langchain/openai\";\n * import { exec } from \"child_process\";\n * import { promisify } from \"util\";\n *\n * const execAsync = promisify(exec);\n * const model = new ChatOpenAI({ model: \"codex-mini-latest\" });\n *\n * // With execute callback for automatic command handling\n * const shell = tools.localShell({\n * execute: async (action) => {\n * const { command, env, working_directory, timeout_ms } = action;\n * const result = await execAsync(command.join(' '), {\n * cwd: working_directory ?? process.cwd(),\n * env: { ...process.env, ...env },\n * timeout: timeout_ms ?? undefined,\n * });\n * return result.stdout + result.stderr;\n * },\n * });\n *\n * const llmWithShell = model.bindTools([shell]);\n * const response = await llmWithShell.invoke(\n * \"List files in the current directory\"\n * );\n * ```\n *\n * @example\n * ```typescript\n * // Without execute callback (manual handling)\n * const shell = tools.localShell();\n *\n * const response = await model.invoke(\"List files\", {\n * tools: [shell],\n * });\n *\n * // Access the shell call from the response\n * const shellCall = response.additional_kwargs.tool_outputs?.find(\n * (output) => output.type === \"local_shell_call\"\n * );\n * if (shellCall) {\n * console.log(\"Command to execute:\", shellCall.action.command);\n * // Execute the command manually, then send back the output\n * }\n * ```\n *\n * @example\n * ```typescript\n * // Full shell loop example\n * async function shellLoop(model, task) {\n * let response = await model.invoke(task, {\n * tools: [tools.localShell()],\n * });\n *\n * while (true) {\n * const shellCall = response.additional_kwargs.tool_outputs?.find(\n * (output) => output.type === \"local_shell_call\"\n * );\n *\n * if (!shellCall) break;\n *\n * // Execute command (with proper sandboxing!)\n * const output = await executeCommand(shellCall.action);\n *\n * // Send output back to model\n * response = await model.invoke([\n * response,\n * {\n * type: \"local_shell_call_output\",\n * id: shellCall.call_id,\n * output: output,\n * },\n * ], {\n * tools: [tools.localShell()],\n * });\n * }\n *\n * return response;\n * }\n * ```\n *\n * @remarks\n * - Only available through the Responses API (not Chat Completions)\n * - Designed for use with `codex-mini-latest` model\n * - Commands are provided as argv tokens in `action.command`\n * - Action includes: `command`, `env`, `working_directory`, `timeout_ms`, `user`\n * - Always sandbox or validate commands before execution\n * - The `timeout_ms` from the model is only a hint—enforce your own limits\n */\nexport declare function localShell(options: LocalShellOptions): DynamicStructuredTool<z.ZodUnion<readonly [z.ZodObject<{\n type: z.ZodLiteral<\"exec\">;\n command: z.ZodArray<z.ZodString>;\n env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;\n working_directory: z.ZodOptional<z.ZodString>;\n timeout_ms: z.ZodOptional<z.ZodNumber>;\n user: z.ZodOptional<z.ZodString>;\n}, z.core.$strip>]>, OpenAIClient.Responses.ResponseOutputItem.LocalShellCall.Action, unknown, string, string>;\n//# sourceMappingURL=localShell.d.ts.map"],"mappings":";;;;;;;;AAQA;AAoBA;AA0BA;AAmHwB0B,KAjKZtB,gBAAAA,GAAmBF,QAAAA,CAAaG,SAAAA,CAAUC,kBAAAA,CAAmBC,cAAAA,CAAeC,MAiKtD;;;;AAAmD,UA7IpEa,iBAAAA,CA6IoE;;;;;;;;;;;;;;;;;;;;;oBAxH/DjB,8BAA8BkB;;;;;KAKxCC,cAAAA,GAAiBrB,QAAAA,CAAaG,SAAAA,CAAUmB,IAAAA,CAAKC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAmHjCC,UAAAA,UAAoBL,oBAAoBlB,sBAAsBH,CAAAA,CAAEoB,mBAAmBpB,CAAAA,CAAEkB;QACnGlB,CAAAA,CAAEU;WACCV,CAAAA,CAAEY,SAASZ,CAAAA,CAAEW;OACjBX,CAAAA,CAAEc,YAAYd,CAAAA,CAAEa,UAAUb,CAAAA,CAAEW,WAAWX,CAAAA,CAAEW;qBAC3BX,CAAAA,CAAEc,YAAYd,CAAAA,CAAEW;cACvBX,CAAAA,CAAEc,YAAYd,CAAAA,CAAEe;QACtBf,CAAAA,CAAEc,YAAYd,CAAAA,CAAEW;GACvBX,CAAAA,CAAEgB,IAAAA,CAAKC,WAAWf,QAAAA,CAAaG,SAAAA,CAAUC,kBAAAA,CAAmBC,cAAAA,CAAeC"}
@@ -10,7 +10,7 @@ const LocalShellExecActionSchema = z.object({
10
10
  timeout_ms: z.number().optional(),
11
11
  user: z.string().optional()
12
12
  });
13
- const LocalShellActionSchema = z.discriminatedUnion("type", [LocalShellExecActionSchema]);
13
+ const LocalShellActionSchema = z.union([LocalShellExecActionSchema]);
14
14
  const TOOL_NAME = "local_shell";
15
15
  /**
16
16
  * Creates a Local Shell tool that allows models to run shell commands locally