@langchain/openai 1.2.7 → 1.2.8-dev-1771365493298

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 (219) hide show
  1. package/dist/azure/chat_models/common.cjs +9 -10
  2. package/dist/azure/chat_models/common.cjs.map +1 -1
  3. package/dist/azure/chat_models/common.d.cts +0 -1
  4. package/dist/azure/chat_models/common.d.cts.map +1 -1
  5. package/dist/azure/chat_models/common.d.ts +0 -1
  6. package/dist/azure/chat_models/common.d.ts.map +1 -1
  7. package/dist/azure/chat_models/common.js +1 -1
  8. package/dist/azure/chat_models/common.js.map +1 -1
  9. package/dist/azure/chat_models/completions.cjs.map +1 -1
  10. package/dist/azure/chat_models/completions.d.cts.map +1 -1
  11. package/dist/azure/chat_models/completions.d.ts.map +1 -1
  12. package/dist/azure/chat_models/completions.js.map +1 -1
  13. package/dist/azure/chat_models/index.cjs.map +1 -1
  14. package/dist/azure/chat_models/index.d.cts +0 -1
  15. package/dist/azure/chat_models/index.d.cts.map +1 -1
  16. package/dist/azure/chat_models/index.d.ts +0 -1
  17. package/dist/azure/chat_models/index.d.ts.map +1 -1
  18. package/dist/azure/chat_models/index.js.map +1 -1
  19. package/dist/azure/chat_models/responses.cjs.map +1 -1
  20. package/dist/azure/chat_models/responses.d.cts.map +1 -1
  21. package/dist/azure/chat_models/responses.d.ts.map +1 -1
  22. package/dist/azure/chat_models/responses.js.map +1 -1
  23. package/dist/azure/embeddings.cjs +10 -13
  24. package/dist/azure/embeddings.cjs.map +1 -1
  25. package/dist/azure/embeddings.d.cts +1 -2
  26. package/dist/azure/embeddings.d.cts.map +1 -1
  27. package/dist/azure/embeddings.d.ts +1 -2
  28. package/dist/azure/embeddings.d.ts.map +1 -1
  29. package/dist/azure/embeddings.js +3 -5
  30. package/dist/azure/embeddings.js.map +1 -1
  31. package/dist/azure/llms.cjs +9 -10
  32. package/dist/azure/llms.cjs.map +1 -1
  33. package/dist/azure/llms.d.cts +2 -2
  34. package/dist/azure/llms.d.cts.map +1 -1
  35. package/dist/azure/llms.d.ts +2 -2
  36. package/dist/azure/llms.d.ts.map +1 -1
  37. package/dist/azure/llms.js +3 -3
  38. package/dist/azure/llms.js.map +1 -1
  39. package/dist/chat_models/base.cjs +38 -45
  40. package/dist/chat_models/base.cjs.map +1 -1
  41. package/dist/chat_models/base.d.cts.map +1 -1
  42. package/dist/chat_models/base.d.ts.map +1 -1
  43. package/dist/chat_models/base.js +10 -16
  44. package/dist/chat_models/base.js.map +1 -1
  45. package/dist/chat_models/completions.cjs +9 -13
  46. package/dist/chat_models/completions.cjs.map +1 -1
  47. package/dist/chat_models/completions.d.cts.map +1 -1
  48. package/dist/chat_models/completions.d.ts.map +1 -1
  49. package/dist/chat_models/completions.js +3 -6
  50. package/dist/chat_models/completions.js.map +1 -1
  51. package/dist/chat_models/index.cjs.map +1 -1
  52. package/dist/chat_models/index.d.cts.map +1 -1
  53. package/dist/chat_models/index.d.ts.map +1 -1
  54. package/dist/chat_models/index.js.map +1 -1
  55. package/dist/chat_models/profiles.cjs +1 -2
  56. package/dist/chat_models/profiles.cjs.map +1 -1
  57. package/dist/chat_models/profiles.js +1 -2
  58. package/dist/chat_models/profiles.js.map +1 -1
  59. package/dist/chat_models/responses.cjs +4 -7
  60. package/dist/chat_models/responses.cjs.map +1 -1
  61. package/dist/chat_models/responses.d.cts.map +1 -1
  62. package/dist/chat_models/responses.d.ts.map +1 -1
  63. package/dist/chat_models/responses.js +2 -4
  64. package/dist/chat_models/responses.js.map +1 -1
  65. package/dist/converters/completions.cjs +36 -45
  66. package/dist/converters/completions.cjs.map +1 -1
  67. package/dist/converters/completions.d.cts +0 -1
  68. package/dist/converters/completions.d.cts.map +1 -1
  69. package/dist/converters/completions.d.ts +0 -1
  70. package/dist/converters/completions.d.ts.map +1 -1
  71. package/dist/converters/completions.js +14 -22
  72. package/dist/converters/completions.js.map +1 -1
  73. package/dist/converters/index.js +2 -0
  74. package/dist/converters/responses.cjs +39 -54
  75. package/dist/converters/responses.cjs.map +1 -1
  76. package/dist/converters/responses.d.cts.map +1 -1
  77. package/dist/converters/responses.d.ts.map +1 -1
  78. package/dist/converters/responses.js +31 -45
  79. package/dist/converters/responses.js.map +1 -1
  80. package/dist/embeddings.cjs +11 -15
  81. package/dist/embeddings.cjs.map +1 -1
  82. package/dist/embeddings.d.cts +1 -3
  83. package/dist/embeddings.d.cts.map +1 -1
  84. package/dist/embeddings.d.ts +1 -3
  85. package/dist/embeddings.d.ts.map +1 -1
  86. package/dist/embeddings.js +3 -6
  87. package/dist/embeddings.js.map +1 -1
  88. package/dist/index.cjs +2 -2
  89. package/dist/llms.cjs +27 -33
  90. package/dist/llms.cjs.map +1 -1
  91. package/dist/llms.d.cts +0 -1
  92. package/dist/llms.d.cts.map +1 -1
  93. package/dist/llms.d.ts +0 -1
  94. package/dist/llms.d.ts.map +1 -1
  95. package/dist/llms.js +15 -20
  96. package/dist/llms.js.map +1 -1
  97. package/dist/tools/applyPatch.cjs +3 -4
  98. package/dist/tools/applyPatch.cjs.map +1 -1
  99. package/dist/tools/applyPatch.d.cts +0 -1
  100. package/dist/tools/applyPatch.d.cts.map +1 -1
  101. package/dist/tools/applyPatch.d.ts +0 -1
  102. package/dist/tools/applyPatch.d.ts.map +1 -1
  103. package/dist/tools/applyPatch.js.map +1 -1
  104. package/dist/tools/codeInterpreter.cjs.map +1 -1
  105. package/dist/tools/codeInterpreter.d.cts +0 -1
  106. package/dist/tools/codeInterpreter.d.cts.map +1 -1
  107. package/dist/tools/codeInterpreter.d.ts +0 -1
  108. package/dist/tools/codeInterpreter.d.ts.map +1 -1
  109. package/dist/tools/codeInterpreter.js.map +1 -1
  110. package/dist/tools/computerUse.cjs +7 -13
  111. package/dist/tools/computerUse.cjs.map +1 -1
  112. package/dist/tools/computerUse.d.cts +0 -1
  113. package/dist/tools/computerUse.d.cts.map +1 -1
  114. package/dist/tools/computerUse.d.ts +0 -1
  115. package/dist/tools/computerUse.d.ts.map +1 -1
  116. package/dist/tools/computerUse.js +1 -6
  117. package/dist/tools/computerUse.js.map +1 -1
  118. package/dist/tools/custom.cjs +6 -7
  119. package/dist/tools/custom.cjs.map +1 -1
  120. package/dist/tools/custom.d.cts.map +1 -1
  121. package/dist/tools/custom.d.ts.map +1 -1
  122. package/dist/tools/custom.js.map +1 -1
  123. package/dist/tools/dalle.cjs +10 -16
  124. package/dist/tools/dalle.cjs.map +1 -1
  125. package/dist/tools/dalle.d.cts +0 -1
  126. package/dist/tools/dalle.d.cts.map +1 -1
  127. package/dist/tools/dalle.d.ts +0 -1
  128. package/dist/tools/dalle.d.ts.map +1 -1
  129. package/dist/tools/dalle.js +6 -11
  130. package/dist/tools/dalle.js.map +1 -1
  131. package/dist/tools/fileSearch.cjs.map +1 -1
  132. package/dist/tools/fileSearch.d.cts +0 -1
  133. package/dist/tools/fileSearch.d.cts.map +1 -1
  134. package/dist/tools/fileSearch.d.ts +0 -1
  135. package/dist/tools/fileSearch.d.ts.map +1 -1
  136. package/dist/tools/fileSearch.js.map +1 -1
  137. package/dist/tools/imageGeneration.cjs.map +1 -1
  138. package/dist/tools/imageGeneration.d.cts +0 -1
  139. package/dist/tools/imageGeneration.d.cts.map +1 -1
  140. package/dist/tools/imageGeneration.d.ts +0 -1
  141. package/dist/tools/imageGeneration.d.ts.map +1 -1
  142. package/dist/tools/imageGeneration.js.map +1 -1
  143. package/dist/tools/index.cjs.map +1 -1
  144. package/dist/tools/index.d.cts +0 -1
  145. package/dist/tools/index.d.cts.map +1 -1
  146. package/dist/tools/index.d.ts +0 -1
  147. package/dist/tools/index.d.ts.map +1 -1
  148. package/dist/tools/index.js.map +1 -1
  149. package/dist/tools/localShell.cjs +3 -4
  150. package/dist/tools/localShell.cjs.map +1 -1
  151. package/dist/tools/localShell.d.cts +0 -1
  152. package/dist/tools/localShell.d.cts.map +1 -1
  153. package/dist/tools/localShell.d.ts +0 -1
  154. package/dist/tools/localShell.d.ts.map +1 -1
  155. package/dist/tools/localShell.js.map +1 -1
  156. package/dist/tools/mcp.cjs.map +1 -1
  157. package/dist/tools/mcp.d.cts +0 -1
  158. package/dist/tools/mcp.d.cts.map +1 -1
  159. package/dist/tools/mcp.d.ts +0 -1
  160. package/dist/tools/mcp.d.ts.map +1 -1
  161. package/dist/tools/mcp.js.map +1 -1
  162. package/dist/tools/shell.cjs +3 -4
  163. package/dist/tools/shell.cjs.map +1 -1
  164. package/dist/tools/shell.d.cts +0 -1
  165. package/dist/tools/shell.d.cts.map +1 -1
  166. package/dist/tools/shell.d.ts +0 -1
  167. package/dist/tools/shell.d.ts.map +1 -1
  168. package/dist/tools/shell.js.map +1 -1
  169. package/dist/tools/webSearch.cjs.map +1 -1
  170. package/dist/tools/webSearch.d.cts +0 -1
  171. package/dist/tools/webSearch.d.cts.map +1 -1
  172. package/dist/tools/webSearch.d.ts +0 -1
  173. package/dist/tools/webSearch.d.ts.map +1 -1
  174. package/dist/tools/webSearch.js.map +1 -1
  175. package/dist/types.d.cts +0 -1
  176. package/dist/types.d.cts.map +1 -1
  177. package/dist/types.d.ts +0 -1
  178. package/dist/types.d.ts.map +1 -1
  179. package/dist/utils/azure.cjs +2 -3
  180. package/dist/utils/azure.cjs.map +1 -1
  181. package/dist/utils/azure.d.cts.map +1 -1
  182. package/dist/utils/azure.d.ts.map +1 -1
  183. package/dist/utils/azure.js.map +1 -1
  184. package/dist/utils/client.cjs +9 -3
  185. package/dist/utils/client.cjs.map +1 -1
  186. package/dist/utils/client.d.cts.map +1 -1
  187. package/dist/utils/client.d.ts.map +1 -1
  188. package/dist/utils/client.js +8 -1
  189. package/dist/utils/client.js.map +1 -1
  190. package/dist/utils/errors.cjs.map +1 -1
  191. package/dist/utils/errors.js.map +1 -1
  192. package/dist/utils/misc.cjs +2 -3
  193. package/dist/utils/misc.cjs.map +1 -1
  194. package/dist/utils/misc.d.cts +0 -1
  195. package/dist/utils/misc.d.cts.map +1 -1
  196. package/dist/utils/misc.d.ts +0 -1
  197. package/dist/utils/misc.d.ts.map +1 -1
  198. package/dist/utils/misc.js.map +1 -1
  199. package/dist/utils/output.cjs +7 -8
  200. package/dist/utils/output.cjs.map +1 -1
  201. package/dist/utils/output.js.map +1 -1
  202. package/dist/utils/prompts.cjs +1 -2
  203. package/dist/utils/prompts.cjs.map +1 -1
  204. package/dist/utils/prompts.d.cts +0 -1
  205. package/dist/utils/prompts.d.cts.map +1 -1
  206. package/dist/utils/prompts.d.ts +0 -1
  207. package/dist/utils/prompts.d.ts.map +1 -1
  208. package/dist/utils/prompts.js +1 -2
  209. package/dist/utils/prompts.js.map +1 -1
  210. package/dist/utils/tools.cjs +9 -12
  211. package/dist/utils/tools.cjs.map +1 -1
  212. package/dist/utils/tools.d.cts +0 -1
  213. package/dist/utils/tools.d.cts.map +1 -1
  214. package/dist/utils/tools.d.ts +0 -1
  215. package/dist/utils/tools.d.ts.map +1 -1
  216. package/dist/utils/tools.js +5 -7
  217. package/dist/utils/tools.js.map +1 -1
  218. package/package.json +5 -5
  219. package/dist/_virtual/rolldown_runtime.cjs +0 -25
@@ -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// 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,GA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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkHlB,SAAgB,YAAYC,SAA6B;CACvD,MAAM,gDACJ,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,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"}
1
+ {"version":3,"file":"computerUse.cjs","names":["z","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,EAC9B,CAAC;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;EAAU,CAAC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EAC9C,QAAQ,8BACT,CAAC;AAqFF,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkHlB,SAAgB,YAAY,SAA6B;CACvD,MAAM,+CACJ,OACE,OACA,YACG;EAQH,MAAM,uBAJY,QAAQ,OAAO,SAAS,GAAG,GAAG,GACZ,YAAY,MAC7C,OAAO,GAAG,SAAS,eACrB,GAC4C;AAC7C,MAAI,CAAC,mBACH,OAAM,IAAI,MAAM,iCAAiC;EAGnD,MAAM,SAAS,MAAM,QAAQ,QAAQ,MAAM,QAAQ,QAAQ;;;;AAK3D,MAAI,OAAO,WAAW,SACpB,QAAO,IAAIC,qCAAY;GACrB,SAAS;GACT,cAAc;GACd,mBAAmB,EACjB,MAAM,wBACP;GACF,CAAC;;;;AAMJ,SAAO,IAAIA,qCAAY;GACrB,GAAG;GACH,cAAc;GACd,mBAAmB;IACjB,MAAM;IACN,GAAG,OAAO;IACX;GACF,CAAC;IAEJ;EACE,MAAM;EACN,aACE;EACF,QAAQ;EACT,CACF;AAED,cAAa,SAAS;EACpB,GAAI,aAAa,UAAU,EAAE;EAC7B,wBAAwB;GACtB,MAAM;GACN,eAAe,QAAQ;GACvB,gBAAgB,QAAQ;GACxB,aAAa,QAAQ;GACtB;EACF;;;;;AAMD,QAAO"}
@@ -4,7 +4,6 @@ import { DynamicStructuredTool, ToolRuntime } from "@langchain/core/tools";
4
4
  import { z } from "zod/v4";
5
5
 
6
6
  //#region src/tools/computerUse.d.ts
7
-
8
7
  /**
9
8
  * The type of computer environment to control.
10
9
  */
@@ -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","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;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,CA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A;AAAA,KACtC,qBAAA,GACV,QAAA,CAAa,SAAA,CAAU,wBAAA,CAAyB,IAAA;AAAA,KACtC,2BAAA,GACV,QAAA,CAAa,SAAA,CAAU,wBAAA,CAAyB,UAAA;AAAA,KACtC,uBAAA,GACV,QAAA,CAAa,SAAA,CAAU,wBAAA,CAAyB,MAAA;AAAA,KACtC,qBAAA,GACV,QAAA,CAAa,SAAA,CAAU,wBAAA,CAAyB,IAAA;AAAA,KACtC,qBAAA,GACV,QAAA,CAAa,SAAA,CAAU,wBAAA,CAAyB,IAAA;AAflD;;;AAAA,KAoBY,iBAAA,GACV,QAAA,CAAa,SAAA,CAAU,wBAAA;;;;;UA2GR,gBAAA;EACf,MAAA,EAAQ,iBAAA;AAAA;AAAA,KAGE,qBAAA,YAER,OAAA,WACA,WAAA,QACA,OAAA,CAAQ,WAAA;;;;UAKK,kBAAA;EAmC0B;;;EA/BzC,YAAA;EAmJc;;;EA9Id,aAAA;;;;;;;;;EAUA,WAAA,EAAa,sBAAA;;;;;;EAOb,OAAA,GACE,MAAA,EAAQ,iBAAA,EACR,OAAA,EAAS,WAAA,eACN,qBAAA;AAAA;;;;KAMK,eAAA,GAAkB,QAAA,CAAa,SAAA,CAAU,YAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAoHrC,WAAA,CAAY,OAAA,EAAS,kBAAA,GAAkB,qBAAA,CAAA,CAAA,CAAA,SAAA"}
@@ -4,7 +4,6 @@ import { DynamicStructuredTool, ToolRuntime } from "@langchain/core/tools";
4
4
  import { z } from "zod/v4";
5
5
 
6
6
  //#region src/tools/computerUse.d.ts
7
-
8
7
  /**
9
8
  * The type of computer environment to control.
10
9
  */
@@ -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","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;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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AAyB,IAAA;AAAA,KACtC,yBAAA,GACV,QAAA,CAAa,SAAA,CAAU,wBAAA,CAAyB,QAAA;AAAA,KACtC,qBAAA,GACV,QAAA,CAAa,SAAA,CAAU,wBAAA,CAAyB,IAAA;AAAA,KACtC,2BAAA,GACV,QAAA,CAAa,SAAA,CAAU,wBAAA,CAAyB,UAAA;AAAA,KACtC,uBAAA,GACV,QAAA,CAAa,SAAA,CAAU,wBAAA,CAAyB,MAAA;AAAA,KACtC,qBAAA,GACV,QAAA,CAAa,SAAA,CAAU,wBAAA,CAAyB,IAAA;AAAA,KACtC,qBAAA,GACV,QAAA,CAAa,SAAA,CAAU,wBAAA,CAAyB,IAAA;AAflD;;;AAAA,KAoBY,iBAAA,GACV,QAAA,CAAa,SAAA,CAAU,wBAAA;;;;;UA2GR,gBAAA;EACf,MAAA,EAAQ,iBAAA;AAAA;AAAA,KAGE,qBAAA,YAER,OAAA,WACA,WAAA,QACA,OAAA,CAAQ,WAAA;;;;UAKK,kBAAA;EAmC0B;;;EA/BzC,YAAA;EAmJc;;;EA9Id,aAAA;;;;;;;;;EAUA,WAAA,EAAa,sBAAA;;;;;;EAOb,OAAA,GACE,MAAA,EAAQ,iBAAA,EACR,OAAA,EAAS,WAAA,eACN,qBAAA;AAAA;;;;KAMK,eAAA,GAAkB,QAAA,CAAa,SAAA,CAAU,YAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAoHrC,WAAA,CAAY,OAAA,EAAS,kBAAA,GAAkB,qBAAA,CAAA,CAAA,CAAA,SAAA"}
@@ -186,12 +186,7 @@ const TOOL_NAME = "computer_use";
186
186
  */
187
187
  function computerUse(options) {
188
188
  const computerTool = tool(async (input, runtime) => {
189
- /**
190
- * get computer_use call id from runtime
191
- */
192
- const aiMessage = runtime.state?.messages.at(-1);
193
- const computerToolCall = aiMessage?.tool_calls?.find((tc) => tc.name === "computer_use");
194
- const computerToolCallId = computerToolCall?.id;
189
+ const computerToolCallId = ((runtime.state?.messages.at(-1))?.tool_calls?.find((tc) => tc.name === "computer_use"))?.id;
195
190
  if (!computerToolCallId) throw new Error("Computer use call id not found");
196
191
  const result = await options.execute(input.action, runtime);
197
192
  /**
@@ -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// 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,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,8BAA8B,EAAE,OAAO;CAC3C,MAAM,EAAE,QAAQ,OAAO;CACvB,MAAM,EAAE,MAAM,EAAE,OAAO;EAAE,GAAG,EAAE,QAAQ;EAAE,GAAG,EAAE,QAAQ;CAAE,EAAC,CAAC;AAC1D,EAAC;AAEF,MAAM,kCAAkC,EAAE,OAAO;CAC/C,MAAM,EAAE,QAAQ,WAAW;CAC3B,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC;AAC1B,EAAC;AAEF,M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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":[],"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,EAC9B,CAAC;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;EAAU,CAAC,CAAC,QAAQ,OAAO;CAC9E,CAAC;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;EAAU,CAAC,CAAC,QAAQ,OAAO;CAC9E,CAAC;AAEF,MAAM,8BAA8B,EAAE,OAAO;CAC3C,MAAM,EAAE,QAAQ,OAAO;CACvB,MAAM,EAAE,MAAM,EAAE,OAAO;EAAE,GAAG,EAAE,QAAQ;EAAE,GAAG,EAAE,QAAQ;EAAE,CAAC,CAAC;CAC1D,CAAC;AAEF,MAAM,kCAAkC,EAAE,OAAO;CAC/C,MAAM,EAAE,QAAQ,WAAW;CAC3B,MAAM,E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EACjB,MAAM,wBACP;GACF,CAAC;;;;AAMJ,SAAO,IAAI,YAAY;GACrB,GAAG;GACH,cAAc;GACd,mBAAmB;IACjB,MAAM;IACN,GAAG,OAAO;IACX;GACF,CAAC;IAEJ;EACE,MAAM;EACN,aACE;EACF,QAAQ;EACT,CACF;AAED,cAAa,SAAS;EACpB,GAAI,aAAa,UAAU,EAAE;EAC7B,wBAAwB;GACtB,MAAM;GACN,eAAe,QAAQ;GACvB,gBAAgB,QAAQ;GACxB,aAAa,QAAQ;GACtB;EACF;;;;;AAMD,QAAO"}
@@ -1,17 +1,16 @@
1
- const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
- const __langchain_core_runnables = require_rolldown_runtime.__toESM(require("@langchain/core/runnables"));
3
- const __langchain_core_tools = require_rolldown_runtime.__toESM(require("@langchain/core/tools"));
4
- const __langchain_core_singletons = require_rolldown_runtime.__toESM(require("@langchain/core/singletons"));
1
+ let _langchain_core_runnables = require("@langchain/core/runnables");
2
+ let _langchain_core_tools = require("@langchain/core/tools");
3
+ let _langchain_core_singletons = require("@langchain/core/singletons");
5
4
 
6
5
  //#region src/tools/custom.ts
7
6
  function customTool(func, fields) {
8
- return new __langchain_core_tools.DynamicTool({
7
+ return new _langchain_core_tools.DynamicTool({
9
8
  ...fields,
10
9
  description: "",
11
10
  metadata: { customTool: fields },
12
11
  func: async (input, runManager, config) => new Promise((resolve, reject) => {
13
- const childConfig = (0, __langchain_core_runnables.patchConfig)(config, { callbacks: runManager?.getChild() });
14
- __langchain_core_singletons.AsyncLocalStorageProviderSingleton.runWithConfig((0, __langchain_core_runnables.pickRunnableConfigKeys)(childConfig), async () => {
12
+ const childConfig = (0, _langchain_core_runnables.patchConfig)(config, { callbacks: runManager?.getChild() });
13
+ _langchain_core_singletons.AsyncLocalStorageProviderSingleton.runWithConfig((0, _langchain_core_runnables.pickRunnableConfigKeys)(childConfig), async () => {
15
14
  try {
16
15
  resolve(func(input, childConfig));
17
16
  } catch (e) {
@@ -1 +1 @@
1
- {"version":3,"file":"custom.cjs","names":["func: RunnableFunc<string, string, ToolRunnableConfig>","fields: CustomToolFields","DynamicTool","AsyncLocalStorageProviderSingleton"],"sources":["../../src/tools/custom.ts"],"sourcesContent":["import {\n patchConfig,\n pickRunnableConfigKeys,\n RunnableFunc,\n} from \"@langchain/core/runnables\";\nimport { AsyncLocalStorageProviderSingleton } from \"@langchain/core/singletons\";\nimport { DynamicTool, ToolRunnableConfig } from \"@langchain/core/tools\";\nimport OpenAI from \"openai\";\n\nexport type CustomToolFields = Omit<OpenAI.Responses.CustomTool, \"type\">;\n\nexport function customTool(\n func: RunnableFunc<string, string, ToolRunnableConfig>,\n fields: CustomToolFields\n): DynamicTool<string> {\n return new DynamicTool({\n ...fields,\n description: \"\",\n metadata: {\n customTool: fields,\n },\n func: async (input, runManager, config) =>\n new Promise<string>((resolve, reject) => {\n const childConfig = patchConfig(config, {\n callbacks: runManager?.getChild(),\n });\n // eslint-disable-next-line no-void\n void AsyncLocalStorageProviderSingleton.runWithConfig(\n pickRunnableConfigKeys(childConfig),\n async () => {\n try {\n resolve(func(input, childConfig));\n } catch (e) {\n reject(e);\n }\n }\n );\n }),\n });\n}\n"],"mappings":";;;;;;AAWA,SAAgB,WACdA,MACAC,QACqB;AACrB,QAAO,IAAIC,mCAAY;EACrB,GAAG;EACH,aAAa;EACb,UAAU,EACR,YAAY,OACb;EACD,MAAM,OAAO,OAAO,YAAY,WAC9B,IAAI,QAAgB,CAAC,SAAS,WAAW;GACvC,MAAM,0DAA0B,QAAQ,EACtC,WAAW,YAAY,UAAU,CAClC,EAAC;GAEGC,+DAAmC,qEACf,YAAY,EACnC,YAAY;AACV,QAAI;KACF,QAAQ,KAAK,OAAO,YAAY,CAAC;IAClC,SAAQ,GAAG;KACV,OAAO,EAAE;IACV;GACF,EACF;EACF;CACJ;AACF"}
1
+ {"version":3,"file":"custom.cjs","names":["DynamicTool","AsyncLocalStorageProviderSingleton"],"sources":["../../src/tools/custom.ts"],"sourcesContent":["import {\n patchConfig,\n pickRunnableConfigKeys,\n RunnableFunc,\n} from \"@langchain/core/runnables\";\nimport { AsyncLocalStorageProviderSingleton } from \"@langchain/core/singletons\";\nimport { DynamicTool, ToolRunnableConfig } from \"@langchain/core/tools\";\nimport OpenAI from \"openai\";\n\nexport type CustomToolFields = Omit<OpenAI.Responses.CustomTool, \"type\">;\n\nexport function customTool(\n func: RunnableFunc<string, string, ToolRunnableConfig>,\n fields: CustomToolFields\n): DynamicTool<string> {\n return new DynamicTool({\n ...fields,\n description: \"\",\n metadata: {\n customTool: fields,\n },\n func: async (input, runManager, config) =>\n new Promise<string>((resolve, reject) => {\n const childConfig = patchConfig(config, {\n callbacks: runManager?.getChild(),\n });\n // eslint-disable-next-line no-void\n void AsyncLocalStorageProviderSingleton.runWithConfig(\n pickRunnableConfigKeys(childConfig),\n async () => {\n try {\n resolve(func(input, childConfig));\n } catch (e) {\n reject(e);\n }\n }\n );\n }),\n });\n}\n"],"mappings":";;;;;AAWA,SAAgB,WACd,MACA,QACqB;AACrB,QAAO,IAAIA,kCAAY;EACrB,GAAG;EACH,aAAa;EACb,UAAU,EACR,YAAY,QACb;EACD,MAAM,OAAO,OAAO,YAAY,WAC9B,IAAI,SAAiB,SAAS,WAAW;GACvC,MAAM,yDAA0B,QAAQ,EACtC,WAAW,YAAY,UAAU,EAClC,CAAC;AAEF,GAAKC,8DAAmC,oEACf,YAAY,EACnC,YAAY;AACV,QAAI;AACF,aAAQ,KAAK,OAAO,YAAY,CAAC;aAC1B,GAAG;AACV,YAAO,EAAE;;KAGd;IACD;EACL,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"custom.d.cts","names":["RunnableFunc","DynamicTool","ToolRunnableConfig","OpenAI","CustomToolFields","Responses","CustomTool","Omit","customTool"],"sources":["../../src/tools/custom.d.ts"],"sourcesContent":["import { RunnableFunc } from \"@langchain/core/runnables\";\nimport { DynamicTool, ToolRunnableConfig } from \"@langchain/core/tools\";\nimport OpenAI from \"openai\";\nexport type CustomToolFields = Omit<OpenAI.Responses.CustomTool, \"type\">;\nexport declare function customTool(func: RunnableFunc<string, string, ToolRunnableConfig>, fields: CustomToolFields): DynamicTool<string>;\n//# sourceMappingURL=custom.d.ts.map"],"mappings":";;;;;KAGYI,gBAAAA,GAAmBG,KAAKJ,MAAAA,CAAOE,SAAAA,CAAUC;iBAC7BE,UAAAA,OAAiBR,6BAA6BE,6BAA6BE,mBAAmBH"}
1
+ {"version":3,"file":"custom.d.cts","names":[],"sources":["../../src/tools/custom.ts"],"mappings":";;;;;KASY,gBAAA,GAAmB,IAAA,CAAK,MAAA,CAAO,SAAA,CAAU,UAAA;AAAA,iBAErC,UAAA,CACd,IAAA,EAAM,YAAA,iBAA6B,kBAAA,GACnC,MAAA,EAAQ,gBAAA,GACP,WAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"custom.d.ts","names":["RunnableFunc","DynamicTool","ToolRunnableConfig","OpenAI","CustomToolFields","Responses","CustomTool","Omit","customTool"],"sources":["../../src/tools/custom.d.ts"],"sourcesContent":["import { RunnableFunc } from \"@langchain/core/runnables\";\nimport { DynamicTool, ToolRunnableConfig } from \"@langchain/core/tools\";\nimport OpenAI from \"openai\";\nexport type CustomToolFields = Omit<OpenAI.Responses.CustomTool, \"type\">;\nexport declare function customTool(func: RunnableFunc<string, string, ToolRunnableConfig>, fields: CustomToolFields): DynamicTool<string>;\n//# sourceMappingURL=custom.d.ts.map"],"mappings":";;;;;KAGYI,gBAAAA,GAAmBG,KAAKJ,MAAAA,CAAOE,SAAAA,CAAUC;iBAC7BE,UAAAA,OAAiBR,6BAA6BE,6BAA6BE,mBAAmBH"}
1
+ {"version":3,"file":"custom.d.ts","names":[],"sources":["../../src/tools/custom.ts"],"mappings":";;;;;KASY,gBAAA,GAAmB,IAAA,CAAK,MAAA,CAAO,SAAA,CAAU,UAAA;AAAA,iBAErC,UAAA,CACd,IAAA,EAAM,YAAA,iBAA6B,kBAAA,GACnC,MAAA,EAAQ,gBAAA,GACP,WAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"custom.js","names":["func: RunnableFunc<string, string, ToolRunnableConfig>","fields: CustomToolFields"],"sources":["../../src/tools/custom.ts"],"sourcesContent":["import {\n patchConfig,\n pickRunnableConfigKeys,\n RunnableFunc,\n} from \"@langchain/core/runnables\";\nimport { AsyncLocalStorageProviderSingleton } from \"@langchain/core/singletons\";\nimport { DynamicTool, ToolRunnableConfig } from \"@langchain/core/tools\";\nimport OpenAI from \"openai\";\n\nexport type CustomToolFields = Omit<OpenAI.Responses.CustomTool, \"type\">;\n\nexport function customTool(\n func: RunnableFunc<string, string, ToolRunnableConfig>,\n fields: CustomToolFields\n): DynamicTool<string> {\n return new DynamicTool({\n ...fields,\n description: \"\",\n metadata: {\n customTool: fields,\n },\n func: async (input, runManager, config) =>\n new Promise<string>((resolve, reject) => {\n const childConfig = patchConfig(config, {\n callbacks: runManager?.getChild(),\n });\n // eslint-disable-next-line no-void\n void AsyncLocalStorageProviderSingleton.runWithConfig(\n pickRunnableConfigKeys(childConfig),\n async () => {\n try {\n resolve(func(input, childConfig));\n } catch (e) {\n reject(e);\n }\n }\n );\n }),\n });\n}\n"],"mappings":";;;;;AAWA,SAAgB,WACdA,MACAC,QACqB;AACrB,QAAO,IAAI,YAAY;EACrB,GAAG;EACH,aAAa;EACb,UAAU,EACR,YAAY,OACb;EACD,MAAM,OAAO,OAAO,YAAY,WAC9B,IAAI,QAAgB,CAAC,SAAS,WAAW;GACvC,MAAM,cAAc,YAAY,QAAQ,EACtC,WAAW,YAAY,UAAU,CAClC,EAAC;GAEG,mCAAmC,cACtC,uBAAuB,YAAY,EACnC,YAAY;AACV,QAAI;KACF,QAAQ,KAAK,OAAO,YAAY,CAAC;IAClC,SAAQ,GAAG;KACV,OAAO,EAAE;IACV;GACF,EACF;EACF;CACJ;AACF"}
1
+ {"version":3,"file":"custom.js","names":[],"sources":["../../src/tools/custom.ts"],"sourcesContent":["import {\n patchConfig,\n pickRunnableConfigKeys,\n RunnableFunc,\n} from \"@langchain/core/runnables\";\nimport { AsyncLocalStorageProviderSingleton } from \"@langchain/core/singletons\";\nimport { DynamicTool, ToolRunnableConfig } from \"@langchain/core/tools\";\nimport OpenAI from \"openai\";\n\nexport type CustomToolFields = Omit<OpenAI.Responses.CustomTool, \"type\">;\n\nexport function customTool(\n func: RunnableFunc<string, string, ToolRunnableConfig>,\n fields: CustomToolFields\n): DynamicTool<string> {\n return new DynamicTool({\n ...fields,\n description: \"\",\n metadata: {\n customTool: fields,\n },\n func: async (input, runManager, config) =>\n new Promise<string>((resolve, reject) => {\n const childConfig = patchConfig(config, {\n callbacks: runManager?.getChild(),\n });\n // eslint-disable-next-line no-void\n void AsyncLocalStorageProviderSingleton.runWithConfig(\n pickRunnableConfigKeys(childConfig),\n async () => {\n try {\n resolve(func(input, childConfig));\n } catch (e) {\n reject(e);\n }\n }\n );\n }),\n });\n}\n"],"mappings":";;;;;AAWA,SAAgB,WACd,MACA,QACqB;AACrB,QAAO,IAAI,YAAY;EACrB,GAAG;EACH,aAAa;EACb,UAAU,EACR,YAAY,QACb;EACD,MAAM,OAAO,OAAO,YAAY,WAC9B,IAAI,SAAiB,SAAS,WAAW;GACvC,MAAM,cAAc,YAAY,QAAQ,EACtC,WAAW,YAAY,UAAU,EAClC,CAAC;AAEF,GAAK,mCAAmC,cACtC,uBAAuB,YAAY,EACnC,YAAY;AACV,QAAI;AACF,aAAQ,KAAK,OAAO,YAAY,CAAC;aAC1B,GAAG;AACV,YAAO,EAAE;;KAGd;IACD;EACL,CAAC"}
@@ -1,13 +1,12 @@
1
- const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
- const openai = require_rolldown_runtime.__toESM(require("openai"));
3
- const __langchain_core_utils_env = require_rolldown_runtime.__toESM(require("@langchain/core/utils/env"));
4
- const __langchain_core_tools = require_rolldown_runtime.__toESM(require("@langchain/core/tools"));
1
+ let openai = require("openai");
2
+ let _langchain_core_utils_env = require("@langchain/core/utils/env");
3
+ let _langchain_core_tools = require("@langchain/core/tools");
5
4
 
6
5
  //#region src/tools/dalle.ts
7
6
  /**
8
7
  * A tool for generating images with Open AIs Dall-E 2 or 3 API.
9
8
  */
10
- var DallEAPIWrapper = class extends __langchain_core_tools.Tool {
9
+ var DallEAPIWrapper = class extends _langchain_core_tools.Tool {
11
10
  static lc_name() {
12
11
  return "DallEAPIWrapper";
13
12
  }
@@ -28,15 +27,12 @@ var DallEAPIWrapper = class extends __langchain_core_tools.Tool {
28
27
  fields.responseFormat = "content";
29
28
  }
30
29
  super(fields);
31
- const openAIApiKey = fields?.apiKey ?? fields?.openAIApiKey ?? (0, __langchain_core_utils_env.getEnvironmentVariable)("OPENAI_API_KEY");
32
- const organization = fields?.organization ?? (0, __langchain_core_utils_env.getEnvironmentVariable)("OPENAI_ORGANIZATION");
33
- const clientConfig = {
34
- apiKey: openAIApiKey,
35
- organization,
30
+ this.client = new openai.OpenAI({
31
+ apiKey: fields?.apiKey ?? fields?.openAIApiKey ?? (0, _langchain_core_utils_env.getEnvironmentVariable)("OPENAI_API_KEY"),
32
+ organization: fields?.organization ?? (0, _langchain_core_utils_env.getEnvironmentVariable)("OPENAI_ORGANIZATION"),
36
33
  dangerouslyAllowBrowser: true,
37
34
  baseURL: fields?.baseUrl
38
- };
39
- this.client = new openai.OpenAI(clientConfig);
35
+ });
40
36
  this.model = fields?.model ?? fields?.modelName ?? this.model;
41
37
  this.style = fields?.style ?? this.style;
42
38
  this.quality = fields?.quality ?? this.quality;
@@ -57,24 +53,22 @@ var DallEAPIWrapper = class extends __langchain_core_tools.Tool {
57
53
  */
58
54
  processMultipleGeneratedUrls(response) {
59
55
  if (this.dallEResponseFormat === "url") return response.flatMap((res) => {
60
- const imageUrlContent = res.data?.flatMap((item) => {
56
+ return res.data?.flatMap((item) => {
61
57
  if (!item.url) return [];
62
58
  return {
63
59
  type: "image_url",
64
60
  image_url: item.url
65
61
  };
66
62
  }).filter((item) => item !== void 0 && item.type === "image_url" && typeof item.image_url === "string" && item.image_url !== void 0) ?? [];
67
- return imageUrlContent;
68
63
  });
69
64
  else return response.flatMap((res) => {
70
- const b64Content = res.data?.flatMap((item) => {
65
+ return res.data?.flatMap((item) => {
71
66
  if (!item.b64_json) return [];
72
67
  return {
73
68
  type: "image_url",
74
69
  image_url: { url: item.b64_json }
75
70
  };
76
71
  }).filter((item) => item !== void 0 && item.type === "image_url" && typeof item.image_url === "object" && "url" in item.image_url && typeof item.image_url.url === "string" && item.image_url.url !== void 0) ?? [];
77
- return b64Content;
78
72
  });
79
73
  }
80
74
  /** @ignore */
@@ -1 +1 @@
1
- {"version":3,"file":"dalle.cjs","names":["Tool","fields?: DallEAPIWrapperParams","OpenAIClient","response: OpenAIClient.Images.ImagesResponse[]","input: string"],"sources":["../../src/tools/dalle.ts"],"sourcesContent":["import { getEnvironmentVariable } from \"@langchain/core/utils/env\";\nimport { OpenAI as OpenAIClient } from \"openai\";\nimport { Tool, ToolParams } from \"@langchain/core/tools\";\nimport {\n MessageContentComplex,\n MessageContentImageUrl,\n} from \"@langchain/core/messages\";\n\n/**\n * @see https://platform.openai.com/docs/api-reference/images/create\n */\nexport type OpenAIImageModelId =\n | OpenAIClient.ImageModel\n | (string & NonNullable<unknown>);\n\n/**\n * An interface for the Dall-E API Wrapper.\n */\nexport interface DallEAPIWrapperParams extends ToolParams {\n /**\n * The OpenAI API key\n * Alias for `apiKey`\n */\n openAIApiKey?: string;\n /**\n * The OpenAI API key\n */\n apiKey?: string;\n /**\n * The model to use.\n * Alias for `model`\n * @params \"dall-e-2\" | \"dall-e-3\"\n * @default \"dall-e-3\"\n * @deprecated Use `model` instead.\n */\n modelName?: OpenAIImageModelId;\n /**\n * The model to use.\n * @params \"dall-e-2\" | \"dall-e-3\"\n * @default \"dall-e-3\"\n */\n model?: OpenAIImageModelId;\n /**\n * The style of the generated images. Must be one of vivid or natural.\n * Vivid causes the model to lean towards generating hyper-real and dramatic images.\n * Natural causes the model to produce more natural, less hyper-real looking images.\n * @default \"vivid\"\n */\n style?: \"natural\" | \"vivid\";\n /**\n * The quality of the image that will be generated. ‘hd’ creates images with finer\n * details and greater consistency across the image.\n * @default \"standard\"\n */\n quality?: \"standard\" | \"hd\";\n /**\n * The number of images to generate.\n * Must be between 1 and 10.\n * For dall-e-3, only `n: 1` is supported.\n * @default 1\n */\n n?: number;\n /**\n * The size of the generated images.\n * Must be one of 256x256, 512x512, or 1024x1024 for DALL·E-2 models.\n * Must be one of 1024x1024, 1792x1024, or 1024x1792 for DALL·E-3 models.\n * @default \"1024x1024\"\n */\n size?: \"256x256\" | \"512x512\" | \"1024x1024\" | \"1792x1024\" | \"1024x1792\";\n /**\n * The format in which the generated images are returned.\n * Must be one of \"url\" or \"b64_json\".\n * @default \"url\"\n */\n dallEResponseFormat?: \"url\" | \"b64_json\";\n /**\n * @deprecated Use dallEResponseFormat instead for the Dall-E response type.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n responseFormat?: any;\n /**\n * A unique identifier representing your end-user, which will help\n * OpenAI to monitor and detect abuse.\n */\n user?: string;\n /**\n * The organization to use\n */\n organization?: string;\n /**\n * The base URL of the OpenAI API.\n */\n baseUrl?: string;\n}\n\n/**\n * A tool for generating images with Open AIs Dall-E 2 or 3 API.\n */\nexport class DallEAPIWrapper extends Tool {\n static lc_name() {\n return \"DallEAPIWrapper\";\n }\n\n name = \"dalle_api_wrapper\";\n\n description =\n \"A wrapper around OpenAI DALL-E API. Useful for when you need to generate images from a text description. Input should be an image description.\";\n\n protected client: OpenAIClient;\n\n static readonly toolName = \"dalle_api_wrapper\";\n\n private model = \"dall-e-3\";\n\n private style: \"natural\" | \"vivid\" = \"vivid\";\n\n private quality: \"standard\" | \"hd\" = \"standard\";\n\n private n = 1;\n\n private size:\n | \"256x256\"\n | \"512x512\"\n | \"1024x1024\"\n | \"1792x1024\"\n | \"1024x1792\" = \"1024x1024\";\n\n private dallEResponseFormat: \"url\" | \"b64_json\" = \"url\";\n\n private user?: string;\n\n constructor(fields?: DallEAPIWrapperParams) {\n // Shim for new base tool param name\n if (\n fields?.responseFormat !== undefined &&\n [\"url\", \"b64_json\"].includes(fields.responseFormat)\n ) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n fields.dallEResponseFormat = fields.responseFormat as any;\n fields.responseFormat = \"content\";\n }\n super(fields);\n const openAIApiKey =\n fields?.apiKey ??\n fields?.openAIApiKey ??\n getEnvironmentVariable(\"OPENAI_API_KEY\");\n\n const organization =\n fields?.organization ?? getEnvironmentVariable(\"OPENAI_ORGANIZATION\");\n\n const clientConfig = {\n apiKey: openAIApiKey,\n organization,\n dangerouslyAllowBrowser: true,\n baseURL: fields?.baseUrl,\n };\n this.client = new OpenAIClient(clientConfig);\n this.model = fields?.model ?? fields?.modelName ?? this.model;\n this.style = fields?.style ?? this.style;\n this.quality = fields?.quality ?? this.quality;\n this.n = fields?.n ?? this.n;\n this.size = fields?.size ?? this.size;\n this.dallEResponseFormat =\n fields?.dallEResponseFormat ?? this.dallEResponseFormat;\n this.user = fields?.user;\n }\n\n /**\n * Processes the API response if multiple images are generated.\n * Returns a list of MessageContentImageUrl objects. If the response\n * format is `url`, then the `image_url` field will contain the URL.\n * If it is `b64_json`, then the `image_url` field will contain an object\n * with a `url` field with the base64 encoded image.\n *\n * @param {OpenAIClient.Images.ImagesResponse[]} response The API response\n * @returns {MessageContentImageUrl[]}\n */\n private processMultipleGeneratedUrls(\n response: OpenAIClient.Images.ImagesResponse[]\n ): MessageContentImageUrl[] {\n if (this.dallEResponseFormat === \"url\") {\n return response.flatMap((res) => {\n const imageUrlContent =\n res.data\n ?.flatMap((item) => {\n if (!item.url) return [];\n return {\n type: \"image_url\" as const,\n image_url: item.url,\n };\n })\n .filter(\n (item) =>\n item !== undefined &&\n item.type === \"image_url\" &&\n typeof item.image_url === \"string\" &&\n item.image_url !== undefined\n ) ?? [];\n return imageUrlContent;\n });\n } else {\n return response.flatMap((res) => {\n const b64Content =\n res.data\n ?.flatMap((item) => {\n if (!item.b64_json) return [];\n return {\n type: \"image_url\" as const,\n image_url: {\n url: item.b64_json,\n },\n };\n })\n .filter(\n (item) =>\n item !== undefined &&\n item.type === \"image_url\" &&\n typeof item.image_url === \"object\" &&\n \"url\" in item.image_url &&\n typeof item.image_url.url === \"string\" &&\n item.image_url.url !== undefined\n ) ?? [];\n return b64Content;\n });\n }\n }\n\n /** @ignore */\n async _call(input: string): Promise<string | MessageContentComplex[]> {\n const generateImageFields = {\n model: this.model,\n prompt: input,\n n: 1,\n size: this.size,\n response_format: this.dallEResponseFormat,\n style: this.style,\n quality: this.quality,\n user: this.user,\n };\n\n if (this.n > 1) {\n const results = await Promise.all(\n Array.from({ length: this.n }).map(() =>\n this.client.images.generate(generateImageFields)\n )\n );\n\n return this.processMultipleGeneratedUrls(results);\n }\n\n const response = await this.client.images.generate(generateImageFields);\n\n let data = \"\";\n if (this.dallEResponseFormat === \"url\") {\n [data] =\n response.data\n ?.map((item) => item.url)\n .filter((url): url is string => url !== \"undefined\") ?? [];\n } else {\n [data] =\n response.data\n ?.map((item) => item.b64_json)\n .filter((b64_json): b64_json is string => b64_json !== \"undefined\") ??\n [];\n }\n return data;\n }\n}\n"],"mappings":";;;;;;;;;AAkGA,IAAa,kBAAb,cAAqCA,4BAAK;CACxC,OAAO,UAAU;AACf,SAAO;CACR;CAED,OAAO;CAEP,cACE;CAEF,AAAU;CAEV,OAAgB,WAAW;CAE3B,AAAQ,QAAQ;CAEhB,AAAQ,QAA6B;CAErC,AAAQ,UAA6B;CAErC,AAAQ,IAAI;CAEZ,AAAQ,OAKU;CAElB,AAAQ,sBAA0C;CAElD,AAAQ;CAER,YAAYC,QAAgC;AAE1C,MACE,QAAQ,mBAAmB,UAC3B,CAAC,OAAO,UAAW,EAAC,SAAS,OAAO,eAAe,EACnD;GAEA,OAAO,sBAAsB,OAAO;GACpC,OAAO,iBAAiB;EACzB;EACD,MAAM,OAAO;EACb,MAAM,eACJ,QAAQ,UACR,QAAQ,uEACe,iBAAiB;E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AAM,sBAAsB;GAC1B,OAAO,KAAK;GACZ,QAAQ;GACR,GAAG;GACH,MAAM,KAAK;GACX,iBAAiB,KAAK;GACtB,OAAO,KAAK;GACZ,SAAS,KAAK;GACd,MAAM,KAAK;EACZ;AAED,MAAI,KAAK,IAAI,GAAG;GACd,MAAM,UAAU,MAAM,QAAQ,IAC5B,MAAM,KAAK,EAAE,QAAQ,KAAK,EAAG,EAAC,CAAC,IAAI,MACjC,KAAK,OAAO,OAAO,SAAS,oBAAoB,CACjD,CACF;AAED,UAAO,KAAK,6BAA6B,QAAQ;EAClD;EAED,MAAM,WAAW,MAAM,KAAK,OAAO,OAAO,SAAS,oBAAoB;EAEvE,IAAI,OAAO;AACX,MAAI,KAAK,wBAAwB,OAC/B,CAAC,KAAK,GACJ,SAAS,MACL,IAAI,CAAC,SAAS,KAAK,IAAI,CACxB,OAAO,CAAC,QAAuB,QAAQ,YAAY,IAAI,CAAE;OAE9D,CAAC,KAAK,GACJ,SAAS,MACL,IAAI,CAAC,SAAS,KAAK,SAAS,CAC7B,OAAO,CAAC,aAAiC,aAAa,YAAY,IACrE,CAAE;AAEN,SAAO;CACR;AACF"}
1
+ {"version":3,"file":"dalle.cjs","names":["Tool","OpenAIClient"],"sources":["../../src/tools/dalle.ts"],"sourcesContent":["import { getEnvironmentVariable } from \"@langchain/core/utils/env\";\nimport { OpenAI as OpenAIClient } from \"openai\";\nimport { Tool, ToolParams } from \"@langchain/core/tools\";\nimport {\n MessageContentComplex,\n MessageContentImageUrl,\n} from \"@langchain/core/messages\";\n\n/**\n * @see https://platform.openai.com/docs/api-reference/images/create\n */\nexport type OpenAIImageModelId =\n | OpenAIClient.ImageModel\n | (string & NonNullable<unknown>);\n\n/**\n * An interface for the Dall-E API Wrapper.\n */\nexport interface DallEAPIWrapperParams extends ToolParams {\n /**\n * The OpenAI API key\n * Alias for `apiKey`\n */\n openAIApiKey?: string;\n /**\n * The OpenAI API key\n */\n apiKey?: string;\n /**\n * The model to use.\n * Alias for `model`\n * @params \"dall-e-2\" | \"dall-e-3\"\n * @default \"dall-e-3\"\n * @deprecated Use `model` instead.\n */\n modelName?: OpenAIImageModelId;\n /**\n * The model to use.\n * @params \"dall-e-2\" | \"dall-e-3\"\n * @default \"dall-e-3\"\n */\n model?: OpenAIImageModelId;\n /**\n * The style of the generated images. Must be one of vivid or natural.\n * Vivid causes the model to lean towards generating hyper-real and dramatic images.\n * Natural causes the model to produce more natural, less hyper-real looking images.\n * @default \"vivid\"\n */\n style?: \"natural\" | \"vivid\";\n /**\n * The quality of the image that will be generated. ‘hd’ creates images with finer\n * details and greater consistency across the image.\n * @default \"standard\"\n */\n quality?: \"standard\" | \"hd\";\n /**\n * The number of images to generate.\n * Must be between 1 and 10.\n * For dall-e-3, only `n: 1` is supported.\n * @default 1\n */\n n?: number;\n /**\n * The size of the generated images.\n * Must be one of 256x256, 512x512, or 1024x1024 for DALL·E-2 models.\n * Must be one of 1024x1024, 1792x1024, or 1024x1792 for DALL·E-3 models.\n * @default \"1024x1024\"\n */\n size?: \"256x256\" | \"512x512\" | \"1024x1024\" | \"1792x1024\" | \"1024x1792\";\n /**\n * The format in which the generated images are returned.\n * Must be one of \"url\" or \"b64_json\".\n * @default \"url\"\n */\n dallEResponseFormat?: \"url\" | \"b64_json\";\n /**\n * @deprecated Use dallEResponseFormat instead for the Dall-E response type.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n responseFormat?: any;\n /**\n * A unique identifier representing your end-user, which will help\n * OpenAI to monitor and detect abuse.\n */\n user?: string;\n /**\n * The organization to use\n */\n organization?: string;\n /**\n * The base URL of the OpenAI API.\n */\n baseUrl?: string;\n}\n\n/**\n * A tool for generating images with Open AIs Dall-E 2 or 3 API.\n */\nexport class DallEAPIWrapper extends Tool {\n static lc_name() {\n return \"DallEAPIWrapper\";\n }\n\n name = \"dalle_api_wrapper\";\n\n description =\n \"A wrapper around OpenAI DALL-E API. Useful for when you need to generate images from a text description. Input should be an image description.\";\n\n protected client: OpenAIClient;\n\n static readonly toolName = \"dalle_api_wrapper\";\n\n private model = \"dall-e-3\";\n\n private style: \"natural\" | \"vivid\" = \"vivid\";\n\n private quality: \"standard\" | \"hd\" = \"standard\";\n\n private n = 1;\n\n private size:\n | \"256x256\"\n | \"512x512\"\n | \"1024x1024\"\n | \"1792x1024\"\n | \"1024x1792\" = \"1024x1024\";\n\n private dallEResponseFormat: \"url\" | \"b64_json\" = \"url\";\n\n private user?: string;\n\n constructor(fields?: DallEAPIWrapperParams) {\n // Shim for new base tool param name\n if (\n fields?.responseFormat !== undefined &&\n [\"url\", \"b64_json\"].includes(fields.responseFormat)\n ) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n fields.dallEResponseFormat = fields.responseFormat as any;\n fields.responseFormat = \"content\";\n }\n super(fields);\n const openAIApiKey =\n fields?.apiKey ??\n fields?.openAIApiKey ??\n getEnvironmentVariable(\"OPENAI_API_KEY\");\n\n const organization =\n fields?.organization ?? getEnvironmentVariable(\"OPENAI_ORGANIZATION\");\n\n const clientConfig = {\n apiKey: openAIApiKey,\n organization,\n dangerouslyAllowBrowser: true,\n baseURL: fields?.baseUrl,\n };\n this.client = new OpenAIClient(clientConfig);\n this.model = fields?.model ?? fields?.modelName ?? this.model;\n this.style = fields?.style ?? this.style;\n this.quality = fields?.quality ?? this.quality;\n this.n = fields?.n ?? this.n;\n this.size = fields?.size ?? this.size;\n this.dallEResponseFormat =\n fields?.dallEResponseFormat ?? this.dallEResponseFormat;\n this.user = fields?.user;\n }\n\n /**\n * Processes the API response if multiple images are generated.\n * Returns a list of MessageContentImageUrl objects. If the response\n * format is `url`, then the `image_url` field will contain the URL.\n * If it is `b64_json`, then the `image_url` field will contain an object\n * with a `url` field with the base64 encoded image.\n *\n * @param {OpenAIClient.Images.ImagesResponse[]} response The API response\n * @returns {MessageContentImageUrl[]}\n */\n private processMultipleGeneratedUrls(\n response: OpenAIClient.Images.ImagesResponse[]\n ): MessageContentImageUrl[] {\n if (this.dallEResponseFormat === \"url\") {\n return response.flatMap((res) => {\n const imageUrlContent =\n res.data\n ?.flatMap((item) => {\n if (!item.url) return [];\n return {\n type: \"image_url\" as const,\n image_url: item.url,\n };\n })\n .filter(\n (item) =>\n item !== undefined &&\n item.type === \"image_url\" &&\n typeof item.image_url === \"string\" &&\n item.image_url !== undefined\n ) ?? [];\n return imageUrlContent;\n });\n } else {\n return response.flatMap((res) => {\n const b64Content =\n res.data\n ?.flatMap((item) => {\n if (!item.b64_json) return [];\n return {\n type: \"image_url\" as const,\n image_url: {\n url: item.b64_json,\n },\n };\n })\n .filter(\n (item) =>\n item !== undefined &&\n item.type === \"image_url\" &&\n typeof item.image_url === \"object\" &&\n \"url\" in item.image_url &&\n typeof item.image_url.url === \"string\" &&\n item.image_url.url !== undefined\n ) ?? [];\n return b64Content;\n });\n }\n }\n\n /** @ignore */\n async _call(input: string): Promise<string | MessageContentComplex[]> {\n const generateImageFields = {\n model: this.model,\n prompt: input,\n n: 1,\n size: this.size,\n response_format: this.dallEResponseFormat,\n style: this.style,\n quality: this.quality,\n user: this.user,\n };\n\n if (this.n > 1) {\n const results = await Promise.all(\n Array.from({ length: this.n }).map(() =>\n this.client.images.generate(generateImageFields)\n )\n );\n\n return this.processMultipleGeneratedUrls(results);\n }\n\n const response = await this.client.images.generate(generateImageFields);\n\n let data = \"\";\n if (this.dallEResponseFormat === \"url\") {\n [data] =\n response.data\n ?.map((item) => item.url)\n .filter((url): url is string => url !== \"undefined\") ?? [];\n } else {\n [data] =\n response.data\n ?.map((item) => item.b64_json)\n .filter((b64_json): b64_json is string => b64_json !== \"undefined\") ??\n [];\n }\n return data;\n }\n}\n"],"mappings":";;;;;;;;AAkGA,IAAa,kBAAb,cAAqCA,2BAAK;CACxC,OAAO,UAAU;AACf,SAAO;;CAGT,OAAO;CAEP,cACE;CAEF,AAAU;CAEV,OAAgB,WAAW;CAE3B,AAAQ,QAAQ;CAEhB,AAAQ,QAA6B;CAErC,AAAQ,UAA6B;CAErC,AAAQ,IA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C1B,SAAS,KAAK,aACd,OAAO,KAAK,UAAU,QAAQ,YAC9B,KAAK,UAAU,QAAQ,OAC1B,IAAI,EAAE;IAEX;;;CAKN,MAAM,MAAM,OAA0D;EACpE,MAAM,sBAAsB;GAC1B,OAAO,KAAK;GACZ,QAAQ;GACR,GAAG;GACH,MAAM,KAAK;GACX,iBAAiB,KAAK;GACtB,OAAO,KAAK;GACZ,SAAS,KAAK;GACd,MAAM,KAAK;GACZ;AAED,MAAI,KAAK,IAAI,GAAG;GACd,MAAM,UAAU,MAAM,QAAQ,IAC5B,MAAM,KAAK,EAAE,QAAQ,KAAK,GAAG,CAAC,CAAC,UAC7B,KAAK,OAAO,OAAO,SAAS,oBAAoB,CACjD,CACF;AAED,UAAO,KAAK,6BAA6B,QAAQ;;EAGnD,MAAM,WAAW,MAAM,KAAK,OAAO,OAAO,SAAS,oBAAoB;EAEvE,IAAI,OAAO;AACX,MAAI,KAAK,wBAAwB,MAC/B,EAAC,QACC,SAAS,MACL,KAAK,SAAS,KAAK,IAAI,CACxB,QAAQ,QAAuB,QAAQ,YAAY,IAAI,EAAE;MAE9D,EAAC,QACC,SAAS,MACL,KAAK,SAAS,KAAK,SAAS,CAC7B,QAAQ,aAAiC,aAAa,YAAY,IACrE,EAAE;AAEN,SAAO"}
@@ -3,7 +3,6 @@ import { MessageContentComplex } from "@langchain/core/messages";
3
3
  import { Tool, ToolParams } from "@langchain/core/tools";
4
4
 
5
5
  //#region src/tools/dalle.d.ts
6
-
7
6
  /**
8
7
  * @see https://platform.openai.com/docs/api-reference/images/create
9
8
  */
@@ -1 +1 @@
1
- {"version":3,"file":"dalle.d.cts","names":["OpenAI","OpenAIClient","Tool","ToolParams","MessageContentComplex","OpenAIImageModelId","ImageModel","NonNullable","DallEAPIWrapperParams","DallEAPIWrapper","Promise"],"sources":["../../src/tools/dalle.d.ts"],"sourcesContent":["import { OpenAI as OpenAIClient } from \"openai\";\nimport { Tool, ToolParams } from \"@langchain/core/tools\";\nimport { MessageContentComplex } from \"@langchain/core/messages\";\n/**\n * @see https://platform.openai.com/docs/api-reference/images/create\n */\nexport type OpenAIImageModelId = OpenAIClient.ImageModel | (string & NonNullable<unknown>);\n/**\n * An interface for the Dall-E API Wrapper.\n */\nexport interface DallEAPIWrapperParams extends ToolParams {\n /**\n * The OpenAI API key\n * Alias for `apiKey`\n */\n openAIApiKey?: string;\n /**\n * The OpenAI API key\n */\n apiKey?: string;\n /**\n * The model to use.\n * Alias for `model`\n * @params \"dall-e-2\" | \"dall-e-3\"\n * @default \"dall-e-3\"\n * @deprecated Use `model` instead.\n */\n modelName?: OpenAIImageModelId;\n /**\n * The model to use.\n * @params \"dall-e-2\" | \"dall-e-3\"\n * @default \"dall-e-3\"\n */\n model?: OpenAIImageModelId;\n /**\n * The style of the generated images. Must be one of vivid or natural.\n * Vivid causes the model to lean towards generating hyper-real and dramatic images.\n * Natural causes the model to produce more natural, less hyper-real looking images.\n * @default \"vivid\"\n */\n style?: \"natural\" | \"vivid\";\n /**\n * The quality of the image that will be generated. ‘hd’ creates images with finer\n * details and greater consistency across the image.\n * @default \"standard\"\n */\n quality?: \"standard\" | \"hd\";\n /**\n * The number of images to generate.\n * Must be between 1 and 10.\n * For dall-e-3, only `n: 1` is supported.\n * @default 1\n */\n n?: number;\n /**\n * The size of the generated images.\n * Must be one of 256x256, 512x512, or 1024x1024 for DALL·E-2 models.\n * Must be one of 1024x1024, 1792x1024, or 1024x1792 for DALL·E-3 models.\n * @default \"1024x1024\"\n */\n size?: \"256x256\" | \"512x512\" | \"1024x1024\" | \"1792x1024\" | \"1024x1792\";\n /**\n * The format in which the generated images are returned.\n * Must be one of \"url\" or \"b64_json\".\n * @default \"url\"\n */\n dallEResponseFormat?: \"url\" | \"b64_json\";\n /**\n * @deprecated Use dallEResponseFormat instead for the Dall-E response type.\n */\n responseFormat?: any;\n /**\n * A unique identifier representing your end-user, which will help\n * OpenAI to monitor and detect abuse.\n */\n user?: string;\n /**\n * The organization to use\n */\n organization?: string;\n /**\n * The base URL of the OpenAI API.\n */\n baseUrl?: string;\n}\n/**\n * A tool for generating images with Open AIs Dall-E 2 or 3 API.\n */\nexport declare class DallEAPIWrapper extends Tool {\n static lc_name(): string;\n name: string;\n description: string;\n protected client: OpenAIClient;\n static readonly toolName = \"dalle_api_wrapper\";\n private model;\n private style;\n private quality;\n private n;\n private size;\n private dallEResponseFormat;\n private user?;\n constructor(fields?: DallEAPIWrapperParams);\n /**\n * Processes the API response if multiple images are generated.\n * Returns a list of MessageContentImageUrl objects. If the response\n * format is `url`, then the `image_url` field will contain the URL.\n * If it is `b64_json`, then the `image_url` field will contain an object\n * with a `url` field with the base64 encoded image.\n *\n * @param {OpenAIClient.Images.ImagesResponse[]} response The API response\n * @returns {MessageContentImageUrl[]}\n */\n private processMultipleGeneratedUrls;\n /** @ignore */\n _call(input: string): Promise<string | MessageContentComplex[]>;\n}\n//# sourceMappingURL=dalle.d.ts.map"],"mappings":";;;;;;;;AAMA;AAIiBQ,KAJLH,kBAAAA,GAAqBJ,QAAAA,CAAaK,UAIR,GAAA,CAAA,MAAA,GAJ+BC,WAI/B,CAAA,OAAA,CAAA,CAAA;;;;AAAmB,UAAxCC,qBAAAA,SAA8BL,UAAU,CAAA;EA8EpCM;;;;EA0BKC,YAAAA,CAAAA,EAAAA,MAAAA;EA1BmBR;AAAI;;;;;;;;;;cA7DjCG;;;;;;UAMJA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAuDSI,eAAAA,SAAwBP,IAAAA;;;;oBAIvBD;;;;;;;;;uBASGO;;;;;;;;;;;;;wBAaCE,iBAAiBN"}
1
+ {"version":3,"file":"dalle.d.cts","names":[],"sources":["../../src/tools/dalle.ts"],"mappings":";;;;;;;AAWA;KAAY,kBAAA,GACR,QAAA,CAAa,UAAA,aACH,WAAA;;;;UAKG,qBAAA,SAA8B,UAAA;EALjC;;;AAKd;EAKE,YAAA;;;;EAIA,MAAA;EATuD;;;;;;;EAiBvD,SAAA,GAAY,kBAAA;EAMJ;;;;;EAAR,KAAA,GAAQ,kBAAA;EAsCR;;;;;;EA/BA,KAAA;EAkD2B;;;;;EA5C3B,OAAA;EA4CmC;;;;;;EArCnC,CAAA;EA+CU;;;;;;EAxCV,IAAA;EAoDQ;;;;;EA9CR,mBAAA;EAuGQ;;;EAlGR,cAAA;EAqJ6C;;;;EAhJ7C,IAAA;;;;EAIA,YAAA;;;;EAIA,OAAA;AAAA;;;;cAMW,eAAA,SAAwB,IAAA;EAAA,OAC5B,OAAA,CAAA;EAIP,IAAA;EAEA,WAAA;EAAA,UAGU,MAAA,EAAQ,QAAA;EAAA,gBAEF,QAAA;EAAA,QAER,KAAA;EAAA,QAEA,KAAA;EAAA,QAEA,OAAA;EAAA,QAEA,CAAA;EAAA,QAEA,IAAA;EAAA,QAOA,mBAAA;EAAA,QAEA,IAAA;EAER,WAAA,CAAY,MAAA,GAAS,qBAAA;;;;;;;;;;;UA8Cb,4BAAA;;EAmDF,KAAA,CAAM,KAAA,WAAgB,OAAA,UAAiB,qBAAA;AAAA"}
@@ -3,7 +3,6 @@ import { MessageContentComplex } from "@langchain/core/messages";
3
3
  import { Tool, ToolParams } from "@langchain/core/tools";
4
4
 
5
5
  //#region src/tools/dalle.d.ts
6
-
7
6
  /**
8
7
  * @see https://platform.openai.com/docs/api-reference/images/create
9
8
  */
@@ -1 +1 @@
1
- {"version":3,"file":"dalle.d.ts","names":["OpenAI","OpenAIClient","Tool","ToolParams","MessageContentComplex","OpenAIImageModelId","ImageModel","NonNullable","DallEAPIWrapperParams","DallEAPIWrapper","Promise"],"sources":["../../src/tools/dalle.d.ts"],"sourcesContent":["import { OpenAI as OpenAIClient } from \"openai\";\nimport { Tool, ToolParams } from \"@langchain/core/tools\";\nimport { MessageContentComplex } from \"@langchain/core/messages\";\n/**\n * @see https://platform.openai.com/docs/api-reference/images/create\n */\nexport type OpenAIImageModelId = OpenAIClient.ImageModel | (string & NonNullable<unknown>);\n/**\n * An interface for the Dall-E API Wrapper.\n */\nexport interface DallEAPIWrapperParams extends ToolParams {\n /**\n * The OpenAI API key\n * Alias for `apiKey`\n */\n openAIApiKey?: string;\n /**\n * The OpenAI API key\n */\n apiKey?: string;\n /**\n * The model to use.\n * Alias for `model`\n * @params \"dall-e-2\" | \"dall-e-3\"\n * @default \"dall-e-3\"\n * @deprecated Use `model` instead.\n */\n modelName?: OpenAIImageModelId;\n /**\n * The model to use.\n * @params \"dall-e-2\" | \"dall-e-3\"\n * @default \"dall-e-3\"\n */\n model?: OpenAIImageModelId;\n /**\n * The style of the generated images. Must be one of vivid or natural.\n * Vivid causes the model to lean towards generating hyper-real and dramatic images.\n * Natural causes the model to produce more natural, less hyper-real looking images.\n * @default \"vivid\"\n */\n style?: \"natural\" | \"vivid\";\n /**\n * The quality of the image that will be generated. ‘hd’ creates images with finer\n * details and greater consistency across the image.\n * @default \"standard\"\n */\n quality?: \"standard\" | \"hd\";\n /**\n * The number of images to generate.\n * Must be between 1 and 10.\n * For dall-e-3, only `n: 1` is supported.\n * @default 1\n */\n n?: number;\n /**\n * The size of the generated images.\n * Must be one of 256x256, 512x512, or 1024x1024 for DALL·E-2 models.\n * Must be one of 1024x1024, 1792x1024, or 1024x1792 for DALL·E-3 models.\n * @default \"1024x1024\"\n */\n size?: \"256x256\" | \"512x512\" | \"1024x1024\" | \"1792x1024\" | \"1024x1792\";\n /**\n * The format in which the generated images are returned.\n * Must be one of \"url\" or \"b64_json\".\n * @default \"url\"\n */\n dallEResponseFormat?: \"url\" | \"b64_json\";\n /**\n * @deprecated Use dallEResponseFormat instead for the Dall-E response type.\n */\n responseFormat?: any;\n /**\n * A unique identifier representing your end-user, which will help\n * OpenAI to monitor and detect abuse.\n */\n user?: string;\n /**\n * The organization to use\n */\n organization?: string;\n /**\n * The base URL of the OpenAI API.\n */\n baseUrl?: string;\n}\n/**\n * A tool for generating images with Open AIs Dall-E 2 or 3 API.\n */\nexport declare class DallEAPIWrapper extends Tool {\n static lc_name(): string;\n name: string;\n description: string;\n protected client: OpenAIClient;\n static readonly toolName = \"dalle_api_wrapper\";\n private model;\n private style;\n private quality;\n private n;\n private size;\n private dallEResponseFormat;\n private user?;\n constructor(fields?: DallEAPIWrapperParams);\n /**\n * Processes the API response if multiple images are generated.\n * Returns a list of MessageContentImageUrl objects. If the response\n * format is `url`, then the `image_url` field will contain the URL.\n * If it is `b64_json`, then the `image_url` field will contain an object\n * with a `url` field with the base64 encoded image.\n *\n * @param {OpenAIClient.Images.ImagesResponse[]} response The API response\n * @returns {MessageContentImageUrl[]}\n */\n private processMultipleGeneratedUrls;\n /** @ignore */\n _call(input: string): Promise<string | MessageContentComplex[]>;\n}\n//# sourceMappingURL=dalle.d.ts.map"],"mappings":";;;;;;;;AAMA;AAIiBQ,KAJLH,kBAAAA,GAAqBJ,QAAAA,CAAaK,UAIR,GAAA,CAAA,MAAA,GAJ+BC,WAI/B,CAAA,OAAA,CAAA,CAAA;;;;AAAmB,UAAxCC,qBAAAA,SAA8BL,UAAU,CAAA;EA8EpCM;;;;EA0BKC,YAAAA,CAAAA,EAAAA,MAAAA;EA1BmBR;AAAI;;;;;;;;;;cA7DjCG;;;;;;UAMJA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAuDSI,eAAAA,SAAwBP,IAAAA;;;;oBAIvBD;;;;;;;;;uBASGO;;;;;;;;;;;;;wBAaCE,iBAAiBN"}
1
+ {"version":3,"file":"dalle.d.ts","names":[],"sources":["../../src/tools/dalle.ts"],"mappings":";;;;;;;AAWA;KAAY,kBAAA,GACR,QAAA,CAAa,UAAA,aACH,WAAA;;;;UAKG,qBAAA,SAA8B,UAAA;EALjC;;;AAKd;EAKE,YAAA;;;;EAIA,MAAA;EATuD;;;;;;;EAiBvD,SAAA,GAAY,kBAAA;EAMJ;;;;;EAAR,KAAA,GAAQ,kBAAA;EAsCR;;;;;;EA/BA,KAAA;EAkD2B;;;;;EA5C3B,OAAA;EA4CmC;;;;;;EArCnC,CAAA;EA+CU;;;;;;EAxCV,IAAA;EAoDQ;;;;;EA9CR,mBAAA;EAuGQ;;;EAlGR,cAAA;EAqJ6C;;;;EAhJ7C,IAAA;;;;EAIA,YAAA;;;;EAIA,OAAA;AAAA;;;;cAMW,eAAA,SAAwB,IAAA;EAAA,OAC5B,OAAA,CAAA;EAIP,IAAA;EAEA,WAAA;EAAA,UAGU,MAAA,EAAQ,QAAA;EAAA,gBAEF,QAAA;EAAA,QAER,KAAA;EAAA,QAEA,KAAA;EAAA,QAEA,OAAA;EAAA,QAEA,CAAA;EAAA,QAEA,IAAA;EAAA,QAOA,mBAAA;EAAA,QAEA,IAAA;EAER,WAAA,CAAY,MAAA,GAAS,qBAAA;;;;;;;;;;;UA8Cb,4BAAA;;EAmDF,KAAA,CAAM,KAAA,WAAgB,OAAA,UAAiB,qBAAA;AAAA"}
@@ -27,15 +27,12 @@ var DallEAPIWrapper = class extends Tool {
27
27
  fields.responseFormat = "content";
28
28
  }
29
29
  super(fields);
30
- const openAIApiKey = fields?.apiKey ?? fields?.openAIApiKey ?? getEnvironmentVariable("OPENAI_API_KEY");
31
- const organization = fields?.organization ?? getEnvironmentVariable("OPENAI_ORGANIZATION");
32
- const clientConfig = {
33
- apiKey: openAIApiKey,
34
- organization,
30
+ this.client = new OpenAI$1({
31
+ apiKey: fields?.apiKey ?? fields?.openAIApiKey ?? getEnvironmentVariable("OPENAI_API_KEY"),
32
+ organization: fields?.organization ?? getEnvironmentVariable("OPENAI_ORGANIZATION"),
35
33
  dangerouslyAllowBrowser: true,
36
34
  baseURL: fields?.baseUrl
37
- };
38
- this.client = new OpenAI$1(clientConfig);
35
+ });
39
36
  this.model = fields?.model ?? fields?.modelName ?? this.model;
40
37
  this.style = fields?.style ?? this.style;
41
38
  this.quality = fields?.quality ?? this.quality;
@@ -56,24 +53,22 @@ var DallEAPIWrapper = class extends Tool {
56
53
  */
57
54
  processMultipleGeneratedUrls(response) {
58
55
  if (this.dallEResponseFormat === "url") return response.flatMap((res) => {
59
- const imageUrlContent = res.data?.flatMap((item) => {
56
+ return res.data?.flatMap((item) => {
60
57
  if (!item.url) return [];
61
58
  return {
62
59
  type: "image_url",
63
60
  image_url: item.url
64
61
  };
65
62
  }).filter((item) => item !== void 0 && item.type === "image_url" && typeof item.image_url === "string" && item.image_url !== void 0) ?? [];
66
- return imageUrlContent;
67
63
  });
68
64
  else return response.flatMap((res) => {
69
- const b64Content = res.data?.flatMap((item) => {
65
+ return res.data?.flatMap((item) => {
70
66
  if (!item.b64_json) return [];
71
67
  return {
72
68
  type: "image_url",
73
69
  image_url: { url: item.b64_json }
74
70
  };
75
71
  }).filter((item) => item !== void 0 && item.type === "image_url" && typeof item.image_url === "object" && "url" in item.image_url && typeof item.image_url.url === "string" && item.image_url.url !== void 0) ?? [];
76
- return b64Content;
77
72
  });
78
73
  }
79
74
  /** @ignore */