@langchain/openai 1.1.3 → 1.2.0-dev-1765432861398

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 (204) hide show
  1. package/README.md +583 -2
  2. package/dist/azure/chat_models/common.d.cts.map +1 -0
  3. package/dist/azure/chat_models/common.d.ts.map +1 -0
  4. package/dist/azure/chat_models/completions.d.cts.map +1 -0
  5. package/dist/azure/chat_models/completions.d.ts.map +1 -0
  6. package/dist/azure/chat_models/index.d.cts +1 -1
  7. package/dist/azure/chat_models/index.d.cts.map +1 -0
  8. package/dist/azure/chat_models/index.d.ts.map +1 -0
  9. package/dist/azure/chat_models/responses.d.cts.map +1 -0
  10. package/dist/azure/chat_models/responses.d.ts.map +1 -0
  11. package/dist/azure/embeddings.d.cts.map +1 -0
  12. package/dist/azure/embeddings.d.ts.map +1 -0
  13. package/dist/azure/llms.d.cts +0 -1
  14. package/dist/azure/llms.d.cts.map +1 -0
  15. package/dist/azure/llms.d.ts +0 -1
  16. package/dist/azure/llms.d.ts.map +1 -0
  17. package/dist/chat_models/base.cjs +5 -1
  18. package/dist/chat_models/base.cjs.map +1 -1
  19. package/dist/chat_models/base.d.cts +8 -22
  20. package/dist/chat_models/base.d.cts.map +1 -0
  21. package/dist/chat_models/base.d.ts +6 -20
  22. package/dist/chat_models/base.d.ts.map +1 -0
  23. package/dist/chat_models/base.js +6 -2
  24. package/dist/chat_models/base.js.map +1 -1
  25. package/dist/chat_models/completions.cjs.map +1 -1
  26. package/dist/chat_models/completions.d.cts +1 -3
  27. package/dist/chat_models/completions.d.cts.map +1 -0
  28. package/dist/chat_models/completions.d.ts +1 -3
  29. package/dist/chat_models/completions.d.ts.map +1 -0
  30. package/dist/chat_models/completions.js.map +1 -1
  31. package/dist/chat_models/index.d.cts +42 -4
  32. package/dist/chat_models/index.d.cts.map +1 -0
  33. package/dist/chat_models/index.d.ts +42 -4
  34. package/dist/chat_models/index.d.ts.map +1 -0
  35. package/dist/chat_models/responses.d.cts +2 -2
  36. package/dist/chat_models/responses.d.cts.map +1 -0
  37. package/dist/chat_models/responses.d.ts +2 -2
  38. package/dist/chat_models/responses.d.ts.map +1 -0
  39. package/dist/converters/completions.cjs +22 -12
  40. package/dist/converters/completions.cjs.map +1 -1
  41. package/dist/converters/completions.d.cts +0 -1
  42. package/dist/converters/completions.d.cts.map +1 -0
  43. package/dist/converters/completions.d.ts +0 -1
  44. package/dist/converters/completions.d.ts.map +1 -0
  45. package/dist/converters/completions.js +23 -13
  46. package/dist/converters/completions.js.map +1 -1
  47. package/dist/converters/responses.cjs +37 -4
  48. package/dist/converters/responses.cjs.map +1 -1
  49. package/dist/converters/responses.d.cts.map +1 -0
  50. package/dist/converters/responses.d.ts.map +1 -0
  51. package/dist/converters/responses.js +39 -6
  52. package/dist/converters/responses.js.map +1 -1
  53. package/dist/embeddings.d.cts +0 -1
  54. package/dist/embeddings.d.cts.map +1 -0
  55. package/dist/embeddings.d.ts +0 -1
  56. package/dist/embeddings.d.ts.map +1 -0
  57. package/dist/index.cjs +2 -1
  58. package/dist/index.d.cts +12 -2
  59. package/dist/index.d.ts +12 -3
  60. package/dist/index.js +2 -2
  61. package/dist/llms.d.cts +0 -1
  62. package/dist/llms.d.cts.map +1 -0
  63. package/dist/llms.d.ts +0 -1
  64. package/dist/llms.d.ts.map +1 -0
  65. package/dist/tools/applyPatch.cjs +116 -0
  66. package/dist/tools/applyPatch.cjs.map +1 -0
  67. package/dist/tools/applyPatch.d.cts +148 -0
  68. package/dist/tools/applyPatch.d.cts.map +1 -0
  69. package/dist/tools/applyPatch.d.ts +148 -0
  70. package/dist/tools/applyPatch.d.ts.map +1 -0
  71. package/dist/tools/applyPatch.js +115 -0
  72. package/dist/tools/applyPatch.js.map +1 -0
  73. package/dist/tools/codeInterpreter.cjs +95 -0
  74. package/dist/tools/codeInterpreter.cjs.map +1 -0
  75. package/dist/tools/codeInterpreter.d.cts +125 -0
  76. package/dist/tools/codeInterpreter.d.cts.map +1 -0
  77. package/dist/tools/codeInterpreter.d.ts +125 -0
  78. package/dist/tools/codeInterpreter.d.ts.map +1 -0
  79. package/dist/tools/codeInterpreter.js +94 -0
  80. package/dist/tools/codeInterpreter.js.map +1 -0
  81. package/dist/tools/computerUse.cjs +240 -0
  82. package/dist/tools/computerUse.cjs.map +1 -0
  83. package/dist/tools/computerUse.d.cts +234 -0
  84. package/dist/tools/computerUse.d.cts.map +1 -0
  85. package/dist/tools/computerUse.d.ts +234 -0
  86. package/dist/tools/computerUse.d.ts.map +1 -0
  87. package/dist/tools/computerUse.js +239 -0
  88. package/dist/tools/computerUse.js.map +1 -0
  89. package/dist/tools/custom.d.cts +1 -1
  90. package/dist/tools/custom.d.cts.map +1 -0
  91. package/dist/tools/custom.d.ts.map +1 -0
  92. package/dist/tools/dalle.d.cts +1 -2
  93. package/dist/tools/dalle.d.cts.map +1 -0
  94. package/dist/tools/dalle.d.ts +1 -2
  95. package/dist/tools/dalle.d.ts.map +1 -0
  96. package/dist/tools/fileSearch.cjs +137 -0
  97. package/dist/tools/fileSearch.cjs.map +1 -0
  98. package/dist/tools/fileSearch.d.cts +224 -0
  99. package/dist/tools/fileSearch.d.cts.map +1 -0
  100. package/dist/tools/fileSearch.d.ts +224 -0
  101. package/dist/tools/fileSearch.d.ts.map +1 -0
  102. package/dist/tools/fileSearch.js +136 -0
  103. package/dist/tools/fileSearch.js.map +1 -0
  104. package/dist/tools/imageGeneration.cjs +128 -0
  105. package/dist/tools/imageGeneration.cjs.map +1 -0
  106. package/dist/tools/imageGeneration.d.cts +199 -0
  107. package/dist/tools/imageGeneration.d.cts.map +1 -0
  108. package/dist/tools/imageGeneration.d.ts +199 -0
  109. package/dist/tools/imageGeneration.d.ts.map +1 -0
  110. package/dist/tools/imageGeneration.js +127 -0
  111. package/dist/tools/imageGeneration.js.map +1 -0
  112. package/dist/tools/index.cjs +26 -0
  113. package/dist/tools/index.cjs.map +1 -0
  114. package/dist/tools/index.d.cts +27 -0
  115. package/dist/tools/index.d.cts.map +1 -0
  116. package/dist/tools/index.d.ts +27 -1
  117. package/dist/tools/index.d.ts.map +1 -0
  118. package/dist/tools/index.js +26 -0
  119. package/dist/tools/index.js.map +1 -0
  120. package/dist/tools/localShell.cjs +145 -0
  121. package/dist/tools/localShell.cjs.map +1 -0
  122. package/dist/tools/localShell.d.cts +167 -0
  123. package/dist/tools/localShell.d.cts.map +1 -0
  124. package/dist/tools/localShell.d.ts +167 -0
  125. package/dist/tools/localShell.d.ts.map +1 -0
  126. package/dist/tools/localShell.js +144 -0
  127. package/dist/tools/localShell.js.map +1 -0
  128. package/dist/tools/mcp.cjs +53 -0
  129. package/dist/tools/mcp.cjs.map +1 -0
  130. package/dist/tools/mcp.d.cts +177 -0
  131. package/dist/tools/mcp.d.cts.map +1 -0
  132. package/dist/tools/mcp.d.ts +177 -0
  133. package/dist/tools/mcp.d.ts.map +1 -0
  134. package/dist/tools/mcp.js +52 -0
  135. package/dist/tools/mcp.js.map +1 -0
  136. package/dist/tools/shell.cjs +163 -0
  137. package/dist/tools/shell.cjs.map +1 -0
  138. package/dist/tools/shell.d.cts +221 -0
  139. package/dist/tools/shell.d.cts.map +1 -0
  140. package/dist/tools/shell.d.ts +221 -0
  141. package/dist/tools/shell.d.ts.map +1 -0
  142. package/dist/tools/shell.js +162 -0
  143. package/dist/tools/shell.js.map +1 -0
  144. package/dist/tools/webSearch.cjs +73 -0
  145. package/dist/tools/webSearch.cjs.map +1 -0
  146. package/dist/tools/webSearch.d.cts +130 -0
  147. package/dist/tools/webSearch.d.cts.map +1 -0
  148. package/dist/tools/webSearch.d.ts +130 -0
  149. package/dist/tools/webSearch.d.ts.map +1 -0
  150. package/dist/tools/webSearch.js +72 -0
  151. package/dist/tools/webSearch.js.map +1 -0
  152. package/dist/types.d.cts +2 -4
  153. package/dist/types.d.cts.map +1 -0
  154. package/dist/types.d.ts +1 -3
  155. package/dist/types.d.ts.map +1 -0
  156. package/dist/utils/azure.d.cts +1 -5
  157. package/dist/utils/azure.d.cts.map +1 -0
  158. package/dist/utils/azure.d.ts +1 -5
  159. package/dist/utils/azure.d.ts.map +1 -0
  160. package/dist/utils/client.d.cts.map +1 -0
  161. package/dist/utils/client.d.ts.map +1 -0
  162. package/dist/utils/misc.cjs +6 -0
  163. package/dist/utils/misc.cjs.map +1 -1
  164. package/dist/utils/misc.d.cts +1 -1
  165. package/dist/utils/misc.d.cts.map +1 -0
  166. package/dist/utils/misc.d.ts +1 -1
  167. package/dist/utils/misc.d.ts.map +1 -0
  168. package/dist/utils/misc.js +6 -1
  169. package/dist/utils/misc.js.map +1 -1
  170. package/dist/utils/prompts.d.cts +0 -1
  171. package/dist/utils/prompts.d.cts.map +1 -0
  172. package/dist/utils/prompts.d.ts +0 -1
  173. package/dist/utils/prompts.d.ts.map +1 -0
  174. package/dist/utils/tools.cjs +39 -1
  175. package/dist/utils/tools.cjs.map +1 -1
  176. package/dist/utils/tools.d.cts.map +1 -0
  177. package/dist/utils/tools.d.ts.map +1 -0
  178. package/dist/utils/tools.js +37 -2
  179. package/dist/utils/tools.js.map +1 -1
  180. package/package.json +8 -6
  181. package/dist/langchain-core/dist/callbacks/base.d.ts +0 -1
  182. package/dist/langchain-core/dist/callbacks/manager.d.ts +0 -2
  183. package/dist/langchain-core/dist/documents/transformers.d.ts +0 -2
  184. package/dist/langchain-core/dist/language_models/base.d.ts +0 -7
  185. package/dist/langchain-core/dist/language_models/chat_models.d.cts +0 -13
  186. package/dist/langchain-core/dist/language_models/chat_models.d.ts +0 -23
  187. package/dist/langchain-core/dist/messages/index.d.ts +0 -1
  188. package/dist/langchain-core/dist/messages/transformers.d.ts +0 -3
  189. package/dist/langchain-core/dist/runnables/base.d.ts +0 -7
  190. package/dist/langchain-core/dist/runnables/config.d.ts +0 -2
  191. package/dist/langchain-core/dist/runnables/graph.d.ts +0 -1
  192. package/dist/langchain-core/dist/runnables/types.d.ts +0 -2
  193. package/dist/langchain-core/dist/tools/index.d.ts +0 -8
  194. package/dist/langchain-core/dist/tools/types.d.ts +0 -7
  195. package/dist/langchain-core/dist/tracers/base.d.ts +0 -2
  196. package/dist/langchain-core/dist/tracers/event_stream.d.ts +0 -2
  197. package/dist/langchain-core/dist/tracers/log_stream.d.ts +0 -3
  198. package/dist/langchain-core/dist/types/_internal.d.cts +0 -11
  199. package/dist/langchain-core/dist/types/_internal.d.ts +0 -11
  200. package/dist/langchain-core/dist/utils/json_schema.d.ts +0 -1
  201. package/dist/langchain-core/dist/utils/stream.d.cts +0 -26
  202. package/dist/langchain-core/dist/utils/stream.d.ts +0 -26
  203. package/dist/langchain-core/dist/utils/types/index.d.ts +0 -1
  204. package/dist/langchain-core/dist/utils/types/zod.d.ts +0 -1
@@ -0,0 +1,240 @@
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ const __langchain_core_messages = require_rolldown_runtime.__toESM(require("@langchain/core/messages"));
3
+ const __langchain_core_tools = require_rolldown_runtime.__toESM(require("@langchain/core/tools"));
4
+ const zod_v4 = require_rolldown_runtime.__toESM(require("zod/v4"));
5
+
6
+ //#region src/tools/computerUse.ts
7
+ const ComputerUseScreenshotActionSchema = zod_v4.z.object({ type: zod_v4.z.literal("screenshot") });
8
+ const ComputerUseClickActionSchema = zod_v4.z.object({
9
+ type: zod_v4.z.literal("click"),
10
+ x: zod_v4.z.number(),
11
+ y: zod_v4.z.number(),
12
+ button: zod_v4.z.enum([
13
+ "left",
14
+ "right",
15
+ "wheel",
16
+ "back",
17
+ "forward"
18
+ ]).default("left")
19
+ });
20
+ const ComputerUseDoubleClickActionSchema = zod_v4.z.object({
21
+ type: zod_v4.z.literal("double_click"),
22
+ x: zod_v4.z.number(),
23
+ y: zod_v4.z.number(),
24
+ button: zod_v4.z.enum([
25
+ "left",
26
+ "right",
27
+ "wheel",
28
+ "back",
29
+ "forward"
30
+ ]).default("left")
31
+ });
32
+ const ComputerUseDragActionSchema = zod_v4.z.object({
33
+ type: zod_v4.z.literal("drag"),
34
+ path: zod_v4.z.array(zod_v4.z.object({
35
+ x: zod_v4.z.number(),
36
+ y: zod_v4.z.number()
37
+ }))
38
+ });
39
+ const ComputerUseKeypressActionSchema = zod_v4.z.object({
40
+ type: zod_v4.z.literal("keypress"),
41
+ keys: zod_v4.z.array(zod_v4.z.string())
42
+ });
43
+ const ComputerUseMoveActionSchema = zod_v4.z.object({
44
+ type: zod_v4.z.literal("move"),
45
+ x: zod_v4.z.number(),
46
+ y: zod_v4.z.number()
47
+ });
48
+ const ComputerUseScrollActionSchema = zod_v4.z.object({
49
+ type: zod_v4.z.literal("scroll"),
50
+ x: zod_v4.z.number(),
51
+ y: zod_v4.z.number(),
52
+ scroll_x: zod_v4.z.number(),
53
+ scroll_y: zod_v4.z.number()
54
+ });
55
+ const ComputerUseTypeActionSchema = zod_v4.z.object({
56
+ type: zod_v4.z.literal("type"),
57
+ text: zod_v4.z.string()
58
+ });
59
+ const ComputerUseWaitActionSchema = zod_v4.z.object({
60
+ type: zod_v4.z.literal("wait"),
61
+ duration: zod_v4.z.number().optional()
62
+ });
63
+ const ComputerUseActionUnionSchema = zod_v4.z.discriminatedUnion("type", [
64
+ ComputerUseScreenshotActionSchema,
65
+ ComputerUseClickActionSchema,
66
+ ComputerUseDoubleClickActionSchema,
67
+ ComputerUseDragActionSchema,
68
+ ComputerUseKeypressActionSchema,
69
+ ComputerUseMoveActionSchema,
70
+ ComputerUseScrollActionSchema,
71
+ ComputerUseTypeActionSchema,
72
+ ComputerUseWaitActionSchema
73
+ ]);
74
+ const ComputerUseActionSchema = zod_v4.z.object({ action: ComputerUseActionUnionSchema });
75
+ const TOOL_NAME = "computer_use";
76
+ /**
77
+ * Creates a Computer Use tool that allows models to control computer interfaces
78
+ * and perform tasks by simulating mouse clicks, keyboard input, scrolling, and more.
79
+ *
80
+ * **Computer Use** is a practical application of OpenAI's Computer-Using Agent (CUA)
81
+ * model (`computer-use-preview`), which combines vision capabilities with advanced
82
+ * reasoning to simulate controlling computer interfaces.
83
+ *
84
+ * **How it works**:
85
+ * The tool operates in a continuous loop:
86
+ * 1. Model sends computer actions (click, type, scroll, etc.)
87
+ * 2. Your code executes these actions in a controlled environment
88
+ * 3. You capture a screenshot of the result
89
+ * 4. Send the screenshot back to the model
90
+ * 5. Repeat until the task is complete
91
+ *
92
+ * **Important**: Computer use is in beta and requires careful consideration:
93
+ * - Use in sandboxed environments only
94
+ * - Do not use for high-stakes or authenticated tasks
95
+ * - Always implement human-in-the-loop for important decisions
96
+ * - Handle safety checks appropriately
97
+ *
98
+ * @see {@link https://platform.openai.com/docs/guides/tools-computer-use | OpenAI Computer Use Documentation}
99
+ *
100
+ * @param options - Configuration options for the Computer Use tool
101
+ * @returns A Computer Use tool that can be passed to `bindTools`
102
+ *
103
+ * @example
104
+ * ```typescript
105
+ * import { ChatOpenAI, tools } from "@langchain/openai";
106
+ *
107
+ * const model = new ChatOpenAI({ model: "computer-use-preview" });
108
+ *
109
+ * // With execute callback for automatic action handling
110
+ * const computer = tools.computerUse({
111
+ * displayWidth: 1024,
112
+ * displayHeight: 768,
113
+ * environment: "browser",
114
+ * execute: async (action) => {
115
+ * if (action.type === "screenshot") {
116
+ * return captureScreenshot();
117
+ * }
118
+ * if (action.type === "click") {
119
+ * await page.mouse.click(action.x, action.y, { button: action.button });
120
+ * return captureScreenshot();
121
+ * }
122
+ * if (action.type === "type") {
123
+ * await page.keyboard.type(action.text);
124
+ * return captureScreenshot();
125
+ * }
126
+ * // Handle other actions...
127
+ * return captureScreenshot();
128
+ * },
129
+ * });
130
+ *
131
+ * const llmWithComputer = model.bindTools([computer]);
132
+ * const response = await llmWithComputer.invoke(
133
+ * "Check the latest news on bing.com"
134
+ * );
135
+ * ```
136
+ *
137
+ * @example
138
+ * ```typescript
139
+ * // Without execute callback (manual action handling)
140
+ * const computer = tools.computerUse({
141
+ * displayWidth: 1024,
142
+ * displayHeight: 768,
143
+ * environment: "browser",
144
+ * });
145
+ *
146
+ * const response = await model.invoke("Check the news", {
147
+ * tools: [computer],
148
+ * });
149
+ *
150
+ * // Access the computer call from the response
151
+ * const computerCall = response.additional_kwargs.tool_outputs?.find(
152
+ * (output) => output.type === "computer_call"
153
+ * );
154
+ * if (computerCall) {
155
+ * console.log("Action to execute:", computerCall.action);
156
+ * // Execute the action manually, then send back a screenshot
157
+ * }
158
+ * ```
159
+ *
160
+ * @example
161
+ * ```typescript
162
+ * // For macOS desktop automation with Docker
163
+ * const computer = tools.computerUse({
164
+ * displayWidth: 1920,
165
+ * displayHeight: 1080,
166
+ * environment: "mac",
167
+ * execute: async (action) => {
168
+ * if (action.type === "click") {
169
+ * await dockerExec(
170
+ * `DISPLAY=:99 xdotool mousemove ${action.x} ${action.y} click 1`,
171
+ * containerName
172
+ * );
173
+ * }
174
+ * // Capture screenshot from container
175
+ * return await getDockerScreenshot(containerName);
176
+ * },
177
+ * });
178
+ * ```
179
+ *
180
+ * @remarks
181
+ * - Only available through the Responses API (not Chat Completions)
182
+ * - Requires `computer-use-preview` model
183
+ * - Actions include: click, double_click, drag, keypress, move, screenshot, scroll, type, wait
184
+ * - Safety checks may be returned that require acknowledgment before proceeding
185
+ * - Use `truncation: "auto"` parameter when making requests
186
+ * - Recommended to use with `reasoning.summary` for debugging
187
+ */
188
+ function computerUse(options) {
189
+ const computerTool = (0, __langchain_core_tools.tool)(async (input, runtime) => {
190
+ /**
191
+ * get computer_use call id from runtime
192
+ */
193
+ const aiMessage = runtime.state?.messages.at(-1);
194
+ const computerToolCall = aiMessage?.tool_calls?.find((tc) => tc.name === "computer_use");
195
+ const computerToolCallId = computerToolCall?.id;
196
+ if (!computerToolCallId) throw new Error("Computer use call id not found");
197
+ const result = await options.execute(input.action, runtime);
198
+ /**
199
+ * make sure {@link ToolMessage} is returned with the correct additional kwargs
200
+ */
201
+ if (typeof result === "string") return new __langchain_core_messages.ToolMessage({
202
+ content: result,
203
+ tool_call_id: computerToolCallId,
204
+ additional_kwargs: { type: "computer_call_output" }
205
+ });
206
+ /**
207
+ * make sure {@link ToolMessage} is returned with the correct additional kwargs
208
+ */
209
+ return new __langchain_core_messages.ToolMessage({
210
+ ...result,
211
+ tool_call_id: computerToolCallId,
212
+ additional_kwargs: {
213
+ type: "computer_call_output",
214
+ ...result.additional_kwargs
215
+ }
216
+ });
217
+ }, {
218
+ name: TOOL_NAME,
219
+ description: "Control a computer interface by executing mouse clicks, keyboard input, scrolling, and other actions.",
220
+ schema: ComputerUseActionSchema
221
+ });
222
+ computerTool.extras = {
223
+ ...computerTool.extras ?? {},
224
+ providerToolDefinition: {
225
+ type: "computer_use_preview",
226
+ display_width: options.displayWidth,
227
+ display_height: options.displayHeight,
228
+ environment: options.environment
229
+ }
230
+ };
231
+ /**
232
+ * return as typed {@link DynamicStructuredTool} so we don't get any type
233
+ * errors like "can't export tool without reference"
234
+ */
235
+ return computerTool;
236
+ }
237
+
238
+ //#endregion
239
+ exports.computerUse = computerUse;
240
+ //# sourceMappingURL=computerUse.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"computerUse.cjs","names":["z","options: ComputerUseOptions","input: ComputerUseInput","runtime: ToolRuntime<{ messages: BaseMessage[] }>","ToolMessage"],"sources":["../../src/tools/computerUse.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { z } from \"zod/v4\";\nimport { OpenAI as OpenAIClient } from \"openai\";\nimport { tool, type DynamicStructuredTool } from \"@langchain/core/tools\";\nimport { type ToolRuntime } from \"@langchain/core/tools\";\nimport {\n ToolMessage,\n type AIMessage,\n type BaseMessage,\n} from \"@langchain/core/messages\";\n\n/**\n * The type of computer environment to control.\n */\nexport type ComputerUseEnvironment =\n | \"browser\"\n | \"mac\"\n | \"windows\"\n | \"linux\"\n | \"ubuntu\";\n\n/**\n * Re-export action types from OpenAI SDK for convenience.\n */\nexport type ComputerUseClickAction =\n OpenAIClient.Responses.ResponseComputerToolCall.Click;\nexport type ComputerUseDoubleClickAction =\n OpenAIClient.Responses.ResponseComputerToolCall.DoubleClick;\nexport type ComputerUseDragAction =\n OpenAIClient.Responses.ResponseComputerToolCall.Drag;\nexport type ComputerUseKeypressAction =\n OpenAIClient.Responses.ResponseComputerToolCall.Keypress;\nexport type ComputerUseMoveAction =\n OpenAIClient.Responses.ResponseComputerToolCall.Move;\nexport type ComputerUseScreenshotAction =\n OpenAIClient.Responses.ResponseComputerToolCall.Screenshot;\nexport type ComputerUseScrollAction =\n OpenAIClient.Responses.ResponseComputerToolCall.Scroll;\nexport type ComputerUseTypeAction =\n OpenAIClient.Responses.ResponseComputerToolCall.Type;\nexport type ComputerUseWaitAction =\n OpenAIClient.Responses.ResponseComputerToolCall.Wait;\n\n/**\n * Union type of all computer use actions from OpenAI SDK.\n */\nexport type ComputerUseAction =\n OpenAIClient.Responses.ResponseComputerToolCall[\"action\"];\n\n// Zod schemas for computer use actions\nconst ComputerUseScreenshotActionSchema = z.object({\n type: z.literal(\"screenshot\"),\n});\n\nconst ComputerUseClickActionSchema = z.object({\n type: z.literal(\"click\"),\n x: z.number(),\n y: z.number(),\n button: z.enum([\"left\", \"right\", \"wheel\", \"back\", \"forward\"]).default(\"left\"),\n});\n\nconst ComputerUseDoubleClickActionSchema = z.object({\n type: z.literal(\"double_click\"),\n x: z.number(),\n y: z.number(),\n button: z.enum([\"left\", \"right\", \"wheel\", \"back\", \"forward\"]).default(\"left\"),\n});\n\nconst ComputerUseDragActionSchema = z.object({\n type: z.literal(\"drag\"),\n path: z.array(z.object({ x: z.number(), y: z.number() })),\n});\n\nconst ComputerUseKeypressActionSchema = z.object({\n type: z.literal(\"keypress\"),\n keys: z.array(z.string()),\n});\n\nconst ComputerUseMoveActionSchema = z.object({\n type: z.literal(\"move\"),\n x: z.number(),\n y: z.number(),\n});\n\nconst ComputerUseScrollActionSchema = z.object({\n type: z.literal(\"scroll\"),\n x: z.number(),\n y: z.number(),\n scroll_x: z.number(),\n scroll_y: z.number(),\n});\n\nconst ComputerUseTypeActionSchema = z.object({\n type: z.literal(\"type\"),\n text: z.string(),\n});\n\nconst ComputerUseWaitActionSchema = z.object({\n type: z.literal(\"wait\"),\n duration: z.number().optional(),\n});\n\n// Discriminated union schema for individual action types\nconst ComputerUseActionUnionSchema = z.discriminatedUnion(\"type\", [\n ComputerUseScreenshotActionSchema,\n ComputerUseClickActionSchema,\n ComputerUseDoubleClickActionSchema,\n ComputerUseDragActionSchema,\n ComputerUseKeypressActionSchema,\n ComputerUseMoveActionSchema,\n ComputerUseScrollActionSchema,\n ComputerUseTypeActionSchema,\n ComputerUseWaitActionSchema,\n]);\n\n// Schema for the input structure received from parseComputerCall\n// The action is wrapped in an `action` property: { action: { type: 'screenshot' } }\nexport const ComputerUseActionSchema = z.object({\n action: ComputerUseActionUnionSchema,\n});\n\n// TypeScript types derived from Zod schemas\nexport type ComputerUseScreenshotActionType = z.infer<\n typeof ComputerUseScreenshotActionSchema\n>;\nexport type ComputerUseClickActionType = z.infer<\n typeof ComputerUseClickActionSchema\n>;\nexport type ComputerUseDoubleClickActionType = z.infer<\n typeof ComputerUseDoubleClickActionSchema\n>;\nexport type ComputerUseDragActionType = z.infer<\n typeof ComputerUseDragActionSchema\n>;\nexport type ComputerUseKeypressActionType = z.infer<\n typeof ComputerUseKeypressActionSchema\n>;\nexport type ComputerUseMoveActionType = z.infer<\n typeof ComputerUseMoveActionSchema\n>;\nexport type ComputerUseScrollActionType = z.infer<\n typeof ComputerUseScrollActionSchema\n>;\nexport type ComputerUseTypeActionType = z.infer<\n typeof ComputerUseTypeActionSchema\n>;\nexport type ComputerUseWaitActionType = z.infer<\n typeof ComputerUseWaitActionSchema\n>;\n\n/**\n * Input structure for the Computer Use tool.\n * The action is wrapped in an `action` property.\n */\nexport interface ComputerUseInput {\n action: ComputerUseAction;\n}\n\nexport type ComputerUseReturnType =\n | string\n | Promise<string>\n | ToolMessage<any>\n | Promise<ToolMessage<any>>;\n\n/**\n * Options for the Computer Use tool.\n */\nexport interface ComputerUseOptions {\n /**\n * The width of the computer display in pixels.\n */\n displayWidth: number;\n\n /**\n * The height of the computer display in pixels.\n */\n displayHeight: number;\n\n /**\n * The type of computer environment to control.\n * - `browser`: Browser automation (recommended for most use cases)\n * - `mac`: macOS environment\n * - `windows`: Windows environment\n * - `linux`: Linux environment\n * - `ubuntu`: Ubuntu environment\n */\n environment: ComputerUseEnvironment;\n\n /**\n * Execute function that handles computer action execution.\n * This function receives the action input and should return a base64-encoded\n * screenshot of the result.\n */\n execute: (\n action: ComputerUseAction,\n runtime: ToolRuntime<any, any>\n ) => ComputerUseReturnType;\n}\n\n/**\n * OpenAI Computer Use tool type for the Responses API.\n */\nexport type ComputerUseTool = OpenAIClient.Responses.ComputerTool;\n\nconst TOOL_NAME = \"computer_use\";\n\n/**\n * Creates a Computer Use tool that allows models to control computer interfaces\n * and perform tasks by simulating mouse clicks, keyboard input, scrolling, and more.\n *\n * **Computer Use** is a practical application of OpenAI's Computer-Using Agent (CUA)\n * model (`computer-use-preview`), which combines vision capabilities with advanced\n * reasoning to simulate controlling computer interfaces.\n *\n * **How it works**:\n * The tool operates in a continuous loop:\n * 1. Model sends computer actions (click, type, scroll, etc.)\n * 2. Your code executes these actions in a controlled environment\n * 3. You capture a screenshot of the result\n * 4. Send the screenshot back to the model\n * 5. Repeat until the task is complete\n *\n * **Important**: Computer use is in beta and requires careful consideration:\n * - Use in sandboxed environments only\n * - Do not use for high-stakes or authenticated tasks\n * - Always implement human-in-the-loop for important decisions\n * - Handle safety checks appropriately\n *\n * @see {@link https://platform.openai.com/docs/guides/tools-computer-use | OpenAI Computer Use Documentation}\n *\n * @param options - Configuration options for the Computer Use tool\n * @returns A Computer Use tool that can be passed to `bindTools`\n *\n * @example\n * ```typescript\n * import { ChatOpenAI, tools } from \"@langchain/openai\";\n *\n * const model = new ChatOpenAI({ model: \"computer-use-preview\" });\n *\n * // With execute callback for automatic action handling\n * const computer = tools.computerUse({\n * displayWidth: 1024,\n * displayHeight: 768,\n * environment: \"browser\",\n * execute: async (action) => {\n * if (action.type === \"screenshot\") {\n * return captureScreenshot();\n * }\n * if (action.type === \"click\") {\n * await page.mouse.click(action.x, action.y, { button: action.button });\n * return captureScreenshot();\n * }\n * if (action.type === \"type\") {\n * await page.keyboard.type(action.text);\n * return captureScreenshot();\n * }\n * // Handle other actions...\n * return captureScreenshot();\n * },\n * });\n *\n * const llmWithComputer = model.bindTools([computer]);\n * const response = await llmWithComputer.invoke(\n * \"Check the latest news on bing.com\"\n * );\n * ```\n *\n * @example\n * ```typescript\n * // Without execute callback (manual action handling)\n * const computer = tools.computerUse({\n * displayWidth: 1024,\n * displayHeight: 768,\n * environment: \"browser\",\n * });\n *\n * const response = await model.invoke(\"Check the news\", {\n * tools: [computer],\n * });\n *\n * // Access the computer call from the response\n * const computerCall = response.additional_kwargs.tool_outputs?.find(\n * (output) => output.type === \"computer_call\"\n * );\n * if (computerCall) {\n * console.log(\"Action to execute:\", computerCall.action);\n * // Execute the action manually, then send back a screenshot\n * }\n * ```\n *\n * @example\n * ```typescript\n * // For macOS desktop automation with Docker\n * const computer = tools.computerUse({\n * displayWidth: 1920,\n * displayHeight: 1080,\n * environment: \"mac\",\n * execute: async (action) => {\n * if (action.type === \"click\") {\n * await dockerExec(\n * `DISPLAY=:99 xdotool mousemove ${action.x} ${action.y} click 1`,\n * containerName\n * );\n * }\n * // Capture screenshot from container\n * return await getDockerScreenshot(containerName);\n * },\n * });\n * ```\n *\n * @remarks\n * - Only available through the Responses API (not Chat Completions)\n * - Requires `computer-use-preview` model\n * - Actions include: click, double_click, drag, keypress, move, screenshot, scroll, type, wait\n * - Safety checks may be returned that require acknowledgment before proceeding\n * - Use `truncation: \"auto\"` parameter when making requests\n * - Recommended to use with `reasoning.summary` for debugging\n */\nexport function computerUse(options: ComputerUseOptions) {\n const computerTool = tool(\n async (\n input: ComputerUseInput,\n runtime: ToolRuntime<{ messages: BaseMessage[] }>\n ) => {\n /**\n * get computer_use call id from runtime\n */\n const aiMessage = runtime.state?.messages.at(-1) as AIMessage | undefined;\n const computerToolCall = aiMessage?.tool_calls?.find(\n (tc) => tc.name === \"computer_use\"\n );\n const computerToolCallId = computerToolCall?.id;\n if (!computerToolCallId) {\n throw new Error(\"Computer use call id not found\");\n }\n\n const result = await options.execute(input.action, runtime);\n\n /**\n * make sure {@link ToolMessage} is returned with the correct additional kwargs\n */\n if (typeof result === \"string\") {\n return new ToolMessage({\n content: result,\n tool_call_id: computerToolCallId,\n additional_kwargs: {\n type: \"computer_call_output\",\n },\n });\n }\n\n /**\n * make sure {@link ToolMessage} is returned with the correct additional kwargs\n */\n return new ToolMessage({\n ...result,\n tool_call_id: computerToolCallId,\n additional_kwargs: {\n type: \"computer_call_output\",\n ...result.additional_kwargs,\n },\n });\n },\n {\n name: TOOL_NAME,\n description:\n \"Control a computer interface by executing mouse clicks, keyboard input, scrolling, and other actions.\",\n schema: ComputerUseActionSchema,\n }\n );\n\n computerTool.extras = {\n ...(computerTool.extras ?? {}),\n providerToolDefinition: {\n type: \"computer_use_preview\",\n display_width: options.displayWidth,\n display_height: options.displayHeight,\n environment: options.environment,\n } satisfies ComputerUseTool,\n };\n\n /**\n * return as typed {@link DynamicStructuredTool} so we don't get any type\n * errors like \"can't export tool without reference\"\n */\n return computerTool as DynamicStructuredTool<\n typeof ComputerUseActionSchema,\n ComputerUseInput,\n unknown,\n ComputerUseReturnType\n >;\n}\n"],"mappings":"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"}
@@ -0,0 +1,234 @@
1
+ import { OpenAI as OpenAI$1 } from "openai";
2
+ import { ToolMessage } from "@langchain/core/messages";
3
+ import { DynamicStructuredTool, ToolRuntime } from "@langchain/core/tools";
4
+ import { z } from "zod/v4";
5
+
6
+ //#region src/tools/computerUse.d.ts
7
+
8
+ /**
9
+ * The type of computer environment to control.
10
+ */
11
+ type ComputerUseEnvironment = "browser" | "mac" | "windows" | "linux" | "ubuntu";
12
+ /**
13
+ * Re-export action types from OpenAI SDK for convenience.
14
+ */
15
+ type ComputerUseClickAction = OpenAI$1.Responses.ResponseComputerToolCall.Click;
16
+ type ComputerUseDoubleClickAction = OpenAI$1.Responses.ResponseComputerToolCall.DoubleClick;
17
+ type ComputerUseDragAction = OpenAI$1.Responses.ResponseComputerToolCall.Drag;
18
+ type ComputerUseKeypressAction = OpenAI$1.Responses.ResponseComputerToolCall.Keypress;
19
+ type ComputerUseMoveAction = OpenAI$1.Responses.ResponseComputerToolCall.Move;
20
+ type ComputerUseScreenshotAction = OpenAI$1.Responses.ResponseComputerToolCall.Screenshot;
21
+ type ComputerUseScrollAction = OpenAI$1.Responses.ResponseComputerToolCall.Scroll;
22
+ type ComputerUseTypeAction = OpenAI$1.Responses.ResponseComputerToolCall.Type;
23
+ type ComputerUseWaitAction = OpenAI$1.Responses.ResponseComputerToolCall.Wait;
24
+ /**
25
+ * Union type of all computer use actions from OpenAI SDK.
26
+ */
27
+ type ComputerUseAction = OpenAI$1.Responses.ResponseComputerToolCall["action"];
28
+ /**
29
+ * Input structure for the Computer Use tool.
30
+ * The action is wrapped in an `action` property.
31
+ */
32
+ interface ComputerUseInput {
33
+ action: ComputerUseAction;
34
+ }
35
+ type ComputerUseReturnType = string | Promise<string> | ToolMessage<any> | Promise<ToolMessage<any>>;
36
+ /**
37
+ * Options for the Computer Use tool.
38
+ */
39
+ interface ComputerUseOptions {
40
+ /**
41
+ * The width of the computer display in pixels.
42
+ */
43
+ displayWidth: number;
44
+ /**
45
+ * The height of the computer display in pixels.
46
+ */
47
+ displayHeight: number;
48
+ /**
49
+ * The type of computer environment to control.
50
+ * - `browser`: Browser automation (recommended for most use cases)
51
+ * - `mac`: macOS environment
52
+ * - `windows`: Windows environment
53
+ * - `linux`: Linux environment
54
+ * - `ubuntu`: Ubuntu environment
55
+ */
56
+ environment: ComputerUseEnvironment;
57
+ /**
58
+ * Execute function that handles computer action execution.
59
+ * This function receives the action input and should return a base64-encoded
60
+ * screenshot of the result.
61
+ */
62
+ execute: (action: ComputerUseAction, runtime: ToolRuntime<any, any>) => ComputerUseReturnType;
63
+ }
64
+ /**
65
+ * OpenAI Computer Use tool type for the Responses API.
66
+ */
67
+ type ComputerUseTool = OpenAI$1.Responses.ComputerTool;
68
+ /**
69
+ * Creates a Computer Use tool that allows models to control computer interfaces
70
+ * and perform tasks by simulating mouse clicks, keyboard input, scrolling, and more.
71
+ *
72
+ * **Computer Use** is a practical application of OpenAI's Computer-Using Agent (CUA)
73
+ * model (`computer-use-preview`), which combines vision capabilities with advanced
74
+ * reasoning to simulate controlling computer interfaces.
75
+ *
76
+ * **How it works**:
77
+ * The tool operates in a continuous loop:
78
+ * 1. Model sends computer actions (click, type, scroll, etc.)
79
+ * 2. Your code executes these actions in a controlled environment
80
+ * 3. You capture a screenshot of the result
81
+ * 4. Send the screenshot back to the model
82
+ * 5. Repeat until the task is complete
83
+ *
84
+ * **Important**: Computer use is in beta and requires careful consideration:
85
+ * - Use in sandboxed environments only
86
+ * - Do not use for high-stakes or authenticated tasks
87
+ * - Always implement human-in-the-loop for important decisions
88
+ * - Handle safety checks appropriately
89
+ *
90
+ * @see {@link https://platform.openai.com/docs/guides/tools-computer-use | OpenAI Computer Use Documentation}
91
+ *
92
+ * @param options - Configuration options for the Computer Use tool
93
+ * @returns A Computer Use tool that can be passed to `bindTools`
94
+ *
95
+ * @example
96
+ * ```typescript
97
+ * import { ChatOpenAI, tools } from "@langchain/openai";
98
+ *
99
+ * const model = new ChatOpenAI({ model: "computer-use-preview" });
100
+ *
101
+ * // With execute callback for automatic action handling
102
+ * const computer = tools.computerUse({
103
+ * displayWidth: 1024,
104
+ * displayHeight: 768,
105
+ * environment: "browser",
106
+ * execute: async (action) => {
107
+ * if (action.type === "screenshot") {
108
+ * return captureScreenshot();
109
+ * }
110
+ * if (action.type === "click") {
111
+ * await page.mouse.click(action.x, action.y, { button: action.button });
112
+ * return captureScreenshot();
113
+ * }
114
+ * if (action.type === "type") {
115
+ * await page.keyboard.type(action.text);
116
+ * return captureScreenshot();
117
+ * }
118
+ * // Handle other actions...
119
+ * return captureScreenshot();
120
+ * },
121
+ * });
122
+ *
123
+ * const llmWithComputer = model.bindTools([computer]);
124
+ * const response = await llmWithComputer.invoke(
125
+ * "Check the latest news on bing.com"
126
+ * );
127
+ * ```
128
+ *
129
+ * @example
130
+ * ```typescript
131
+ * // Without execute callback (manual action handling)
132
+ * const computer = tools.computerUse({
133
+ * displayWidth: 1024,
134
+ * displayHeight: 768,
135
+ * environment: "browser",
136
+ * });
137
+ *
138
+ * const response = await model.invoke("Check the news", {
139
+ * tools: [computer],
140
+ * });
141
+ *
142
+ * // Access the computer call from the response
143
+ * const computerCall = response.additional_kwargs.tool_outputs?.find(
144
+ * (output) => output.type === "computer_call"
145
+ * );
146
+ * if (computerCall) {
147
+ * console.log("Action to execute:", computerCall.action);
148
+ * // Execute the action manually, then send back a screenshot
149
+ * }
150
+ * ```
151
+ *
152
+ * @example
153
+ * ```typescript
154
+ * // For macOS desktop automation with Docker
155
+ * const computer = tools.computerUse({
156
+ * displayWidth: 1920,
157
+ * displayHeight: 1080,
158
+ * environment: "mac",
159
+ * execute: async (action) => {
160
+ * if (action.type === "click") {
161
+ * await dockerExec(
162
+ * `DISPLAY=:99 xdotool mousemove ${action.x} ${action.y} click 1`,
163
+ * containerName
164
+ * );
165
+ * }
166
+ * // Capture screenshot from container
167
+ * return await getDockerScreenshot(containerName);
168
+ * },
169
+ * });
170
+ * ```
171
+ *
172
+ * @remarks
173
+ * - Only available through the Responses API (not Chat Completions)
174
+ * - Requires `computer-use-preview` model
175
+ * - Actions include: click, double_click, drag, keypress, move, screenshot, scroll, type, wait
176
+ * - Safety checks may be returned that require acknowledgment before proceeding
177
+ * - Use `truncation: "auto"` parameter when making requests
178
+ * - Recommended to use with `reasoning.summary` for debugging
179
+ */
180
+ declare function computerUse(options: ComputerUseOptions): DynamicStructuredTool<z.ZodObject<{
181
+ action: z.ZodDiscriminatedUnion<[z.ZodObject<{
182
+ type: z.ZodLiteral<"screenshot">;
183
+ }, z.core.$strip>, z.ZodObject<{
184
+ type: z.ZodLiteral<"click">;
185
+ x: z.ZodNumber;
186
+ y: z.ZodNumber;
187
+ button: z.ZodDefault<z.ZodEnum<{
188
+ back: "back";
189
+ forward: "forward";
190
+ left: "left";
191
+ right: "right";
192
+ wheel: "wheel";
193
+ }>>;
194
+ }, z.core.$strip>, z.ZodObject<{
195
+ type: z.ZodLiteral<"double_click">;
196
+ x: z.ZodNumber;
197
+ y: z.ZodNumber;
198
+ button: z.ZodDefault<z.ZodEnum<{
199
+ back: "back";
200
+ forward: "forward";
201
+ left: "left";
202
+ right: "right";
203
+ wheel: "wheel";
204
+ }>>;
205
+ }, z.core.$strip>, z.ZodObject<{
206
+ type: z.ZodLiteral<"drag">;
207
+ path: z.ZodArray<z.ZodObject<{
208
+ x: z.ZodNumber;
209
+ y: z.ZodNumber;
210
+ }, z.core.$strip>>;
211
+ }, z.core.$strip>, z.ZodObject<{
212
+ type: z.ZodLiteral<"keypress">;
213
+ keys: z.ZodArray<z.ZodString>;
214
+ }, z.core.$strip>, z.ZodObject<{
215
+ type: z.ZodLiteral<"move">;
216
+ x: z.ZodNumber;
217
+ y: z.ZodNumber;
218
+ }, z.core.$strip>, z.ZodObject<{
219
+ type: z.ZodLiteral<"scroll">;
220
+ x: z.ZodNumber;
221
+ y: z.ZodNumber;
222
+ scroll_x: z.ZodNumber;
223
+ scroll_y: z.ZodNumber;
224
+ }, z.core.$strip>, z.ZodObject<{
225
+ type: z.ZodLiteral<"type">;
226
+ text: z.ZodString;
227
+ }, z.core.$strip>, z.ZodObject<{
228
+ type: z.ZodLiteral<"wait">;
229
+ duration: z.ZodOptional<z.ZodNumber>;
230
+ }, z.core.$strip>]>;
231
+ }, z.core.$strip>, ComputerUseInput, unknown, ComputerUseReturnType>;
232
+ //#endregion
233
+ export { ComputerUseAction, ComputerUseClickAction, ComputerUseDoubleClickAction, ComputerUseDragAction, ComputerUseEnvironment, ComputerUseInput, ComputerUseKeypressAction, ComputerUseMoveAction, ComputerUseOptions, ComputerUseScreenshotAction, ComputerUseScrollAction, ComputerUseTool, ComputerUseTypeAction, ComputerUseWaitAction, computerUse };
234
+ //# sourceMappingURL=computerUse.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"computerUse.d.cts","names":["z","OpenAI","OpenAIClient","DynamicStructuredTool","ToolRuntime","ToolMessage","ComputerUseEnvironment","ComputerUseClickAction","Responses","ResponseComputerToolCall","Click","ComputerUseDoubleClickAction","DoubleClick","ComputerUseDragAction","Drag","ComputerUseKeypressAction","Keypress","ComputerUseMoveAction","Move","ComputerUseScreenshotAction","Screenshot","ComputerUseScrollAction","Scroll","ComputerUseTypeAction","Type","ComputerUseWaitAction","Wait","ComputerUseAction","ComputerUseScreenshotActionSchema","ZodLiteral","core","$strip","ZodObject","ComputerUseClickActionSchema","ZodNumber","ZodEnum","ZodDefault","ComputerUseDoubleClickActionSchema","ComputerUseDragActionSchema","ZodArray","ComputerUseKeypressActionSchema","ZodString","ComputerUseMoveActionSchema","ComputerUseScrollActionSchema","ComputerUseTypeActionSchema","ComputerUseWaitActionSchema","ZodOptional","ComputerUseActionSchema","ZodDiscriminatedUnion","ComputerUseScreenshotActionType","infer","ComputerUseClickActionType","ComputerUseDoubleClickActionType","ComputerUseDragActionType","ComputerUseKeypressActionType","ComputerUseMoveActionType","ComputerUseScrollActionType","ComputerUseTypeActionType","ComputerUseWaitActionType","ComputerUseInput","ComputerUseReturnType","Promise","ComputerUseOptions","ComputerUseTool","ComputerTool","computerUse"],"sources":["../../src/tools/computerUse.d.ts"],"sourcesContent":["import { z } from \"zod/v4\";\nimport { OpenAI as OpenAIClient } from \"openai\";\nimport { type DynamicStructuredTool } from \"@langchain/core/tools\";\nimport { type ToolRuntime } from \"@langchain/core/tools\";\nimport { ToolMessage } from \"@langchain/core/messages\";\n/**\n * The type of computer environment to control.\n */\nexport type ComputerUseEnvironment = \"browser\" | \"mac\" | \"windows\" | \"linux\" | \"ubuntu\";\n/**\n * Re-export action types from OpenAI SDK for convenience.\n */\nexport type ComputerUseClickAction = OpenAIClient.Responses.ResponseComputerToolCall.Click;\nexport type ComputerUseDoubleClickAction = OpenAIClient.Responses.ResponseComputerToolCall.DoubleClick;\nexport type ComputerUseDragAction = OpenAIClient.Responses.ResponseComputerToolCall.Drag;\nexport type ComputerUseKeypressAction = OpenAIClient.Responses.ResponseComputerToolCall.Keypress;\nexport type ComputerUseMoveAction = OpenAIClient.Responses.ResponseComputerToolCall.Move;\nexport type ComputerUseScreenshotAction = OpenAIClient.Responses.ResponseComputerToolCall.Screenshot;\nexport type ComputerUseScrollAction = OpenAIClient.Responses.ResponseComputerToolCall.Scroll;\nexport type ComputerUseTypeAction = OpenAIClient.Responses.ResponseComputerToolCall.Type;\nexport type ComputerUseWaitAction = OpenAIClient.Responses.ResponseComputerToolCall.Wait;\n/**\n * Union type of all computer use actions from OpenAI SDK.\n */\nexport type ComputerUseAction = OpenAIClient.Responses.ResponseComputerToolCall[\"action\"];\ndeclare const ComputerUseScreenshotActionSchema: z.ZodObject<{\n type: z.ZodLiteral<\"screenshot\">;\n}, z.core.$strip>;\ndeclare const ComputerUseClickActionSchema: z.ZodObject<{\n type: z.ZodLiteral<\"click\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n button: z.ZodDefault<z.ZodEnum<{\n back: \"back\";\n forward: \"forward\";\n left: \"left\";\n right: \"right\";\n wheel: \"wheel\";\n }>>;\n}, z.core.$strip>;\ndeclare const ComputerUseDoubleClickActionSchema: z.ZodObject<{\n type: z.ZodLiteral<\"double_click\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n button: z.ZodDefault<z.ZodEnum<{\n back: \"back\";\n forward: \"forward\";\n left: \"left\";\n right: \"right\";\n wheel: \"wheel\";\n }>>;\n}, z.core.$strip>;\ndeclare const ComputerUseDragActionSchema: z.ZodObject<{\n type: z.ZodLiteral<\"drag\">;\n path: z.ZodArray<z.ZodObject<{\n x: z.ZodNumber;\n y: z.ZodNumber;\n }, z.core.$strip>>;\n}, z.core.$strip>;\ndeclare const ComputerUseKeypressActionSchema: z.ZodObject<{\n type: z.ZodLiteral<\"keypress\">;\n keys: z.ZodArray<z.ZodString>;\n}, z.core.$strip>;\ndeclare const ComputerUseMoveActionSchema: z.ZodObject<{\n type: z.ZodLiteral<\"move\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n}, z.core.$strip>;\ndeclare const ComputerUseScrollActionSchema: z.ZodObject<{\n type: z.ZodLiteral<\"scroll\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n scroll_x: z.ZodNumber;\n scroll_y: z.ZodNumber;\n}, z.core.$strip>;\ndeclare const ComputerUseTypeActionSchema: z.ZodObject<{\n type: z.ZodLiteral<\"type\">;\n text: z.ZodString;\n}, z.core.$strip>;\ndeclare const ComputerUseWaitActionSchema: z.ZodObject<{\n type: z.ZodLiteral<\"wait\">;\n duration: z.ZodOptional<z.ZodNumber>;\n}, z.core.$strip>;\nexport declare const ComputerUseActionSchema: z.ZodObject<{\n action: z.ZodDiscriminatedUnion<[z.ZodObject<{\n type: z.ZodLiteral<\"screenshot\">;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"click\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n button: z.ZodDefault<z.ZodEnum<{\n back: \"back\";\n forward: \"forward\";\n left: \"left\";\n right: \"right\";\n wheel: \"wheel\";\n }>>;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"double_click\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n button: z.ZodDefault<z.ZodEnum<{\n back: \"back\";\n forward: \"forward\";\n left: \"left\";\n right: \"right\";\n wheel: \"wheel\";\n }>>;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"drag\">;\n path: z.ZodArray<z.ZodObject<{\n x: z.ZodNumber;\n y: z.ZodNumber;\n }, z.core.$strip>>;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"keypress\">;\n keys: z.ZodArray<z.ZodString>;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"move\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"scroll\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n scroll_x: z.ZodNumber;\n scroll_y: z.ZodNumber;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"type\">;\n text: z.ZodString;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"wait\">;\n duration: z.ZodOptional<z.ZodNumber>;\n }, z.core.$strip>]>;\n}, z.core.$strip>;\nexport type ComputerUseScreenshotActionType = z.infer<typeof ComputerUseScreenshotActionSchema>;\nexport type ComputerUseClickActionType = z.infer<typeof ComputerUseClickActionSchema>;\nexport type ComputerUseDoubleClickActionType = z.infer<typeof ComputerUseDoubleClickActionSchema>;\nexport type ComputerUseDragActionType = z.infer<typeof ComputerUseDragActionSchema>;\nexport type ComputerUseKeypressActionType = z.infer<typeof ComputerUseKeypressActionSchema>;\nexport type ComputerUseMoveActionType = z.infer<typeof ComputerUseMoveActionSchema>;\nexport type ComputerUseScrollActionType = z.infer<typeof ComputerUseScrollActionSchema>;\nexport type ComputerUseTypeActionType = z.infer<typeof ComputerUseTypeActionSchema>;\nexport type ComputerUseWaitActionType = z.infer<typeof ComputerUseWaitActionSchema>;\n/**\n * Input structure for the Computer Use tool.\n * The action is wrapped in an `action` property.\n */\nexport interface ComputerUseInput {\n action: ComputerUseAction;\n}\nexport type ComputerUseReturnType = string | Promise<string> | ToolMessage<any> | Promise<ToolMessage<any>>;\n/**\n * Options for the Computer Use tool.\n */\nexport interface ComputerUseOptions {\n /**\n * The width of the computer display in pixels.\n */\n displayWidth: number;\n /**\n * The height of the computer display in pixels.\n */\n displayHeight: number;\n /**\n * The type of computer environment to control.\n * - `browser`: Browser automation (recommended for most use cases)\n * - `mac`: macOS environment\n * - `windows`: Windows environment\n * - `linux`: Linux environment\n * - `ubuntu`: Ubuntu environment\n */\n environment: ComputerUseEnvironment;\n /**\n * Execute function that handles computer action execution.\n * This function receives the action input and should return a base64-encoded\n * screenshot of the result.\n */\n execute: (action: ComputerUseAction, runtime: ToolRuntime<any, any>) => ComputerUseReturnType;\n}\n/**\n * OpenAI Computer Use tool type for the Responses API.\n */\nexport type ComputerUseTool = OpenAIClient.Responses.ComputerTool;\n/**\n * Creates a Computer Use tool that allows models to control computer interfaces\n * and perform tasks by simulating mouse clicks, keyboard input, scrolling, and more.\n *\n * **Computer Use** is a practical application of OpenAI's Computer-Using Agent (CUA)\n * model (`computer-use-preview`), which combines vision capabilities with advanced\n * reasoning to simulate controlling computer interfaces.\n *\n * **How it works**:\n * The tool operates in a continuous loop:\n * 1. Model sends computer actions (click, type, scroll, etc.)\n * 2. Your code executes these actions in a controlled environment\n * 3. You capture a screenshot of the result\n * 4. Send the screenshot back to the model\n * 5. Repeat until the task is complete\n *\n * **Important**: Computer use is in beta and requires careful consideration:\n * - Use in sandboxed environments only\n * - Do not use for high-stakes or authenticated tasks\n * - Always implement human-in-the-loop for important decisions\n * - Handle safety checks appropriately\n *\n * @see {@link https://platform.openai.com/docs/guides/tools-computer-use | OpenAI Computer Use Documentation}\n *\n * @param options - Configuration options for the Computer Use tool\n * @returns A Computer Use tool that can be passed to `bindTools`\n *\n * @example\n * ```typescript\n * import { ChatOpenAI, tools } from \"@langchain/openai\";\n *\n * const model = new ChatOpenAI({ model: \"computer-use-preview\" });\n *\n * // With execute callback for automatic action handling\n * const computer = tools.computerUse({\n * displayWidth: 1024,\n * displayHeight: 768,\n * environment: \"browser\",\n * execute: async (action) => {\n * if (action.type === \"screenshot\") {\n * return captureScreenshot();\n * }\n * if (action.type === \"click\") {\n * await page.mouse.click(action.x, action.y, { button: action.button });\n * return captureScreenshot();\n * }\n * if (action.type === \"type\") {\n * await page.keyboard.type(action.text);\n * return captureScreenshot();\n * }\n * // Handle other actions...\n * return captureScreenshot();\n * },\n * });\n *\n * const llmWithComputer = model.bindTools([computer]);\n * const response = await llmWithComputer.invoke(\n * \"Check the latest news on bing.com\"\n * );\n * ```\n *\n * @example\n * ```typescript\n * // Without execute callback (manual action handling)\n * const computer = tools.computerUse({\n * displayWidth: 1024,\n * displayHeight: 768,\n * environment: \"browser\",\n * });\n *\n * const response = await model.invoke(\"Check the news\", {\n * tools: [computer],\n * });\n *\n * // Access the computer call from the response\n * const computerCall = response.additional_kwargs.tool_outputs?.find(\n * (output) => output.type === \"computer_call\"\n * );\n * if (computerCall) {\n * console.log(\"Action to execute:\", computerCall.action);\n * // Execute the action manually, then send back a screenshot\n * }\n * ```\n *\n * @example\n * ```typescript\n * // For macOS desktop automation with Docker\n * const computer = tools.computerUse({\n * displayWidth: 1920,\n * displayHeight: 1080,\n * environment: \"mac\",\n * execute: async (action) => {\n * if (action.type === \"click\") {\n * await dockerExec(\n * `DISPLAY=:99 xdotool mousemove ${action.x} ${action.y} click 1`,\n * containerName\n * );\n * }\n * // Capture screenshot from container\n * return await getDockerScreenshot(containerName);\n * },\n * });\n * ```\n *\n * @remarks\n * - Only available through the Responses API (not Chat Completions)\n * - Requires `computer-use-preview` model\n * - Actions include: click, double_click, drag, keypress, move, screenshot, scroll, type, wait\n * - Safety checks may be returned that require acknowledgment before proceeding\n * - Use `truncation: \"auto\"` parameter when making requests\n * - Recommended to use with `reasoning.summary` for debugging\n */\nexport declare function computerUse(options: ComputerUseOptions): DynamicStructuredTool<z.ZodObject<{\n action: z.ZodDiscriminatedUnion<[z.ZodObject<{\n type: z.ZodLiteral<\"screenshot\">;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"click\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n button: z.ZodDefault<z.ZodEnum<{\n back: \"back\";\n forward: \"forward\";\n left: \"left\";\n right: \"right\";\n wheel: \"wheel\";\n }>>;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"double_click\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n button: z.ZodDefault<z.ZodEnum<{\n back: \"back\";\n forward: \"forward\";\n left: \"left\";\n right: \"right\";\n wheel: \"wheel\";\n }>>;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"drag\">;\n path: z.ZodArray<z.ZodObject<{\n x: z.ZodNumber;\n y: z.ZodNumber;\n }, z.core.$strip>>;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"keypress\">;\n keys: z.ZodArray<z.ZodString>;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"move\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"scroll\">;\n x: z.ZodNumber;\n y: z.ZodNumber;\n scroll_x: z.ZodNumber;\n scroll_y: z.ZodNumber;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"type\">;\n text: z.ZodString;\n }, z.core.$strip>, z.ZodObject<{\n type: z.ZodLiteral<\"wait\">;\n duration: z.ZodOptional<z.ZodNumber>;\n }, z.core.$strip>]>;\n}, z.core.$strip>, ComputerUseInput, unknown, ComputerUseReturnType>;\nexport {};\n//# sourceMappingURL=computerUse.d.ts.map"],"mappings":"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"}