@langchain/openai 1.5.5 → 1.5.6

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 (228) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/azure/chat_models/common.cjs.map +1 -1
  3. package/dist/azure/chat_models/common.d.cts +1 -1
  4. package/dist/azure/chat_models/common.d.cts.map +1 -1
  5. package/dist/azure/chat_models/common.d.ts +1 -1
  6. package/dist/azure/chat_models/common.d.ts.map +1 -1
  7. package/dist/azure/chat_models/common.js.map +1 -1
  8. package/dist/azure/chat_models/completions.cjs.map +1 -1
  9. package/dist/azure/chat_models/completions.d.cts +0 -1
  10. package/dist/azure/chat_models/completions.d.cts.map +1 -1
  11. package/dist/azure/chat_models/completions.d.ts +0 -1
  12. package/dist/azure/chat_models/completions.d.ts.map +1 -1
  13. package/dist/azure/chat_models/completions.js.map +1 -1
  14. package/dist/azure/chat_models/index.cjs.map +1 -1
  15. package/dist/azure/chat_models/index.d.cts +1 -2
  16. package/dist/azure/chat_models/index.d.cts.map +1 -1
  17. package/dist/azure/chat_models/index.d.ts +0 -1
  18. package/dist/azure/chat_models/index.d.ts.map +1 -1
  19. package/dist/azure/chat_models/index.js.map +1 -1
  20. package/dist/azure/chat_models/responses.cjs.map +1 -1
  21. package/dist/azure/chat_models/responses.d.cts +0 -1
  22. package/dist/azure/chat_models/responses.d.cts.map +1 -1
  23. package/dist/azure/chat_models/responses.d.ts +0 -1
  24. package/dist/azure/chat_models/responses.d.ts.map +1 -1
  25. package/dist/azure/chat_models/responses.js.map +1 -1
  26. package/dist/azure/embeddings.cjs.map +1 -1
  27. package/dist/azure/embeddings.d.cts +2 -2
  28. package/dist/azure/embeddings.d.cts.map +1 -1
  29. package/dist/azure/embeddings.d.ts +2 -2
  30. package/dist/azure/embeddings.d.ts.map +1 -1
  31. package/dist/azure/embeddings.js.map +1 -1
  32. package/dist/azure/llms.cjs.map +1 -1
  33. package/dist/azure/llms.d.cts +0 -1
  34. package/dist/azure/llms.d.cts.map +1 -1
  35. package/dist/azure/llms.d.ts +0 -1
  36. package/dist/azure/llms.d.ts.map +1 -1
  37. package/dist/azure/llms.js.map +1 -1
  38. package/dist/chat_models/base.cjs +37 -3
  39. package/dist/chat_models/base.cjs.map +1 -1
  40. package/dist/chat_models/base.d.cts +6 -7
  41. package/dist/chat_models/base.d.cts.map +1 -1
  42. package/dist/chat_models/base.d.ts +5 -6
  43. package/dist/chat_models/base.d.ts.map +1 -1
  44. package/dist/chat_models/base.js +37 -3
  45. package/dist/chat_models/base.js.map +1 -1
  46. package/dist/chat_models/completions.cjs.map +1 -1
  47. package/dist/chat_models/completions.d.cts +0 -1
  48. package/dist/chat_models/completions.d.cts.map +1 -1
  49. package/dist/chat_models/completions.d.ts +0 -1
  50. package/dist/chat_models/completions.d.ts.map +1 -1
  51. package/dist/chat_models/completions.js.map +1 -1
  52. package/dist/chat_models/index.cjs.map +1 -1
  53. package/dist/chat_models/index.d.cts +14 -17
  54. package/dist/chat_models/index.d.cts.map +1 -1
  55. package/dist/chat_models/index.d.ts +14 -17
  56. package/dist/chat_models/index.d.ts.map +1 -1
  57. package/dist/chat_models/index.js.map +1 -1
  58. package/dist/chat_models/profiles.cjs.map +1 -1
  59. package/dist/chat_models/profiles.js.map +1 -1
  60. package/dist/chat_models/responses.cjs.map +1 -1
  61. package/dist/chat_models/responses.d.cts +0 -1
  62. package/dist/chat_models/responses.d.cts.map +1 -1
  63. package/dist/chat_models/responses.d.ts +0 -1
  64. package/dist/chat_models/responses.d.ts.map +1 -1
  65. package/dist/chat_models/responses.js.map +1 -1
  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.map +1 -1
  72. package/dist/converters/index.cjs +14 -2
  73. package/dist/converters/index.d.cts +2 -1
  74. package/dist/converters/index.d.ts +2 -1
  75. package/dist/converters/index.js +3 -3
  76. package/dist/converters/responses.cjs.map +1 -1
  77. package/dist/converters/responses.d.cts +0 -1
  78. package/dist/converters/responses.d.cts.map +1 -1
  79. package/dist/converters/responses.d.ts +0 -1
  80. package/dist/converters/responses.d.ts.map +1 -1
  81. package/dist/converters/responses.js.map +1 -1
  82. package/dist/embeddings.cjs.map +1 -1
  83. package/dist/embeddings.d.cts +2 -2
  84. package/dist/embeddings.d.cts.map +1 -1
  85. package/dist/embeddings.d.ts +2 -2
  86. package/dist/embeddings.d.ts.map +1 -1
  87. package/dist/embeddings.js.map +1 -1
  88. package/dist/index.d.cts +2 -1
  89. package/dist/index.d.ts +2 -1
  90. package/dist/llms.cjs +1 -1
  91. package/dist/llms.cjs.map +1 -1
  92. package/dist/llms.d.cts +1 -2
  93. package/dist/llms.d.cts.map +1 -1
  94. package/dist/llms.d.ts +1 -2
  95. package/dist/llms.d.ts.map +1 -1
  96. package/dist/llms.js +1 -1
  97. package/dist/llms.js.map +1 -1
  98. package/dist/tools/applyPatch.cjs +4 -0
  99. package/dist/tools/applyPatch.cjs.map +1 -1
  100. package/dist/tools/applyPatch.d.cts +1 -2
  101. package/dist/tools/applyPatch.d.cts.map +1 -1
  102. package/dist/tools/applyPatch.d.ts +1 -2
  103. package/dist/tools/applyPatch.d.ts.map +1 -1
  104. package/dist/tools/applyPatch.js +1 -1
  105. package/dist/tools/applyPatch.js.map +1 -1
  106. package/dist/tools/codeInterpreter.cjs.map +1 -1
  107. package/dist/tools/codeInterpreter.d.cts +0 -1
  108. package/dist/tools/codeInterpreter.d.cts.map +1 -1
  109. package/dist/tools/codeInterpreter.d.ts +0 -1
  110. package/dist/tools/codeInterpreter.d.ts.map +1 -1
  111. package/dist/tools/codeInterpreter.js.map +1 -1
  112. package/dist/tools/computerUse.cjs +1 -0
  113. package/dist/tools/computerUse.cjs.map +1 -1
  114. package/dist/tools/computerUse.d.cts +1 -2
  115. package/dist/tools/computerUse.d.cts.map +1 -1
  116. package/dist/tools/computerUse.d.ts +1 -2
  117. package/dist/tools/computerUse.d.ts.map +1 -1
  118. package/dist/tools/computerUse.js +1 -1
  119. package/dist/tools/computerUse.js.map +1 -1
  120. package/dist/tools/custom.cjs.map +1 -1
  121. package/dist/tools/custom.d.cts +1 -2
  122. package/dist/tools/custom.d.cts.map +1 -1
  123. package/dist/tools/custom.d.ts +1 -2
  124. package/dist/tools/custom.d.ts.map +1 -1
  125. package/dist/tools/custom.js.map +1 -1
  126. package/dist/tools/dalle.cjs.map +1 -1
  127. package/dist/tools/dalle.d.cts +0 -1
  128. package/dist/tools/dalle.d.cts.map +1 -1
  129. package/dist/tools/dalle.d.ts +0 -1
  130. package/dist/tools/dalle.d.ts.map +1 -1
  131. package/dist/tools/dalle.js.map +1 -1
  132. package/dist/tools/fileSearch.cjs.map +1 -1
  133. package/dist/tools/fileSearch.d.cts +0 -1
  134. package/dist/tools/fileSearch.d.cts.map +1 -1
  135. package/dist/tools/fileSearch.d.ts +0 -1
  136. package/dist/tools/fileSearch.d.ts.map +1 -1
  137. package/dist/tools/fileSearch.js.map +1 -1
  138. package/dist/tools/imageGeneration.cjs.map +1 -1
  139. package/dist/tools/imageGeneration.d.cts +0 -1
  140. package/dist/tools/imageGeneration.d.cts.map +1 -1
  141. package/dist/tools/imageGeneration.d.ts +0 -1
  142. package/dist/tools/imageGeneration.d.ts.map +1 -1
  143. package/dist/tools/imageGeneration.js.map +1 -1
  144. package/dist/tools/index.cjs +2 -1
  145. package/dist/tools/index.cjs.map +1 -1
  146. package/dist/tools/index.d.cts +1 -2
  147. package/dist/tools/index.d.cts.map +1 -1
  148. package/dist/tools/index.d.ts +1 -2
  149. package/dist/tools/index.d.ts.map +1 -1
  150. package/dist/tools/index.js +2 -2
  151. package/dist/tools/index.js.map +1 -1
  152. package/dist/tools/localShell.cjs +2 -0
  153. package/dist/tools/localShell.cjs.map +1 -1
  154. package/dist/tools/localShell.d.cts +1 -2
  155. package/dist/tools/localShell.d.cts.map +1 -1
  156. package/dist/tools/localShell.d.ts +1 -2
  157. package/dist/tools/localShell.d.ts.map +1 -1
  158. package/dist/tools/localShell.js +1 -1
  159. package/dist/tools/localShell.js.map +1 -1
  160. package/dist/tools/mcp.cjs.map +1 -1
  161. package/dist/tools/mcp.d.cts +0 -1
  162. package/dist/tools/mcp.d.cts.map +1 -1
  163. package/dist/tools/mcp.d.ts +0 -1
  164. package/dist/tools/mcp.d.ts.map +1 -1
  165. package/dist/tools/mcp.js.map +1 -1
  166. package/dist/tools/shell.cjs +1 -0
  167. package/dist/tools/shell.cjs.map +1 -1
  168. package/dist/tools/shell.d.cts +1 -2
  169. package/dist/tools/shell.d.cts.map +1 -1
  170. package/dist/tools/shell.d.ts +1 -2
  171. package/dist/tools/shell.d.ts.map +1 -1
  172. package/dist/tools/shell.js +1 -1
  173. package/dist/tools/shell.js.map +1 -1
  174. package/dist/tools/toolSearch.cjs.map +1 -1
  175. package/dist/tools/toolSearch.d.cts +0 -1
  176. package/dist/tools/toolSearch.d.cts.map +1 -1
  177. package/dist/tools/toolSearch.d.ts +0 -1
  178. package/dist/tools/toolSearch.d.ts.map +1 -1
  179. package/dist/tools/toolSearch.js.map +1 -1
  180. package/dist/tools/webSearch.cjs.map +1 -1
  181. package/dist/tools/webSearch.d.cts +1 -2
  182. package/dist/tools/webSearch.d.cts.map +1 -1
  183. package/dist/tools/webSearch.d.ts +1 -2
  184. package/dist/tools/webSearch.d.ts.map +1 -1
  185. package/dist/tools/webSearch.js.map +1 -1
  186. package/dist/types.d.cts +0 -1
  187. package/dist/types.d.cts.map +1 -1
  188. package/dist/types.d.ts +0 -1
  189. package/dist/types.d.ts.map +1 -1
  190. package/dist/utils/azure.cjs.map +1 -1
  191. package/dist/utils/azure.d.cts.map +1 -1
  192. package/dist/utils/azure.d.ts.map +1 -1
  193. package/dist/utils/azure.js.map +1 -1
  194. package/dist/utils/client.cjs.map +1 -1
  195. package/dist/utils/client.d.cts.map +1 -1
  196. package/dist/utils/client.d.ts.map +1 -1
  197. package/dist/utils/client.js.map +1 -1
  198. package/dist/utils/errors.cjs.map +1 -1
  199. package/dist/utils/errors.js.map +1 -1
  200. package/dist/utils/misc.cjs +2 -0
  201. package/dist/utils/misc.cjs.map +1 -1
  202. package/dist/utils/misc.d.cts +0 -1
  203. package/dist/utils/misc.d.cts.map +1 -1
  204. package/dist/utils/misc.d.ts +0 -1
  205. package/dist/utils/misc.d.ts.map +1 -1
  206. package/dist/utils/misc.js +1 -1
  207. package/dist/utils/misc.js.map +1 -1
  208. package/dist/utils/output.cjs.map +1 -1
  209. package/dist/utils/output.js.map +1 -1
  210. package/dist/utils/prompts.cjs.map +1 -1
  211. package/dist/utils/prompts.d.cts +0 -1
  212. package/dist/utils/prompts.d.cts.map +1 -1
  213. package/dist/utils/prompts.d.ts +0 -1
  214. package/dist/utils/prompts.d.ts.map +1 -1
  215. package/dist/utils/prompts.js.map +1 -1
  216. package/dist/utils/responses_stream_events.cjs.map +1 -1
  217. package/dist/utils/responses_stream_events.d.cts +0 -1
  218. package/dist/utils/responses_stream_events.d.cts.map +1 -1
  219. package/dist/utils/responses_stream_events.d.ts +0 -1
  220. package/dist/utils/responses_stream_events.d.ts.map +1 -1
  221. package/dist/utils/responses_stream_events.js.map +1 -1
  222. package/dist/utils/tools.cjs.map +1 -1
  223. package/dist/utils/tools.d.cts +2 -0
  224. package/dist/utils/tools.d.cts.map +1 -1
  225. package/dist/utils/tools.d.ts +2 -0
  226. package/dist/utils/tools.d.ts.map +1 -1
  227. package/dist/utils/tools.js.map +1 -1
  228. package/package.json +6 -6
@@ -1 +1 @@
1
- {"version":3,"file":"imageGeneration.cjs","names":[],"sources":["../../src/tools/imageGeneration.ts"],"sourcesContent":["import { OpenAI as OpenAIClient } from \"openai\";\nimport type { ServerTool } from \"@langchain/core/tools\";\n\n/**\n * Optional mask for inpainting. Allows you to specify areas of the image\n * that should be regenerated.\n */\nexport interface ImageGenerationInputMask {\n /**\n * Base64-encoded mask image URL.\n */\n imageUrl?: string;\n /**\n * File ID for the mask image (uploaded via OpenAI File API).\n */\n fileId?: string;\n}\n\n/**\n * Options for the Image Generation tool.\n */\nexport interface ImageGenerationOptions {\n /**\n * Whether to generate a new image or edit an existing image.\n * - `generate`: Generate a new image from scratch\n * - `edit`: Edit an existing image\n * - `auto`: Let the model decide based on the input\n * @default \"auto\"\n */\n action?: \"generate\" | \"edit\" | \"auto\";\n\n /**\n * Background type for the generated image.\n * - `transparent`: Generate image with transparent background\n * - `opaque`: Generate image with opaque background\n * - `auto`: Let the model decide based on the prompt\n * @default \"auto\"\n */\n background?: \"transparent\" | \"opaque\" | \"auto\";\n\n /**\n * Control how much effort the model will exert to match the style and features,\n * especially facial features, of input images. This parameter is only supported\n * for `gpt-image-1`. Unsupported for `gpt-image-1-mini`.\n * - `high`: Higher fidelity to input images\n * - `low`: Lower fidelity to input images\n * @default \"low\"\n */\n inputFidelity?: \"high\" | \"low\";\n\n /**\n * Optional mask for inpainting. Use this to specify areas of an image\n * that should be regenerated.\n */\n inputImageMask?: ImageGenerationInputMask;\n\n /**\n * The image generation model to use.\n * @default \"gpt-image-1\"\n */\n model?: \"gpt-image-1\" | \"gpt-image-1-mini\" | \"gpt-image-1.5\";\n\n /**\n * Moderation level for the generated image.\n * - `auto`: Standard moderation\n * - `low`: Less restrictive moderation\n * @default \"auto\"\n */\n moderation?: \"auto\" | \"low\";\n\n /**\n * Compression level for the output image (0-100).\n * Only applies to JPEG and WebP formats.\n * @default 100\n */\n outputCompression?: number;\n\n /**\n * The output format of the generated image.\n * @default \"png\"\n */\n outputFormat?: \"png\" | \"webp\" | \"jpeg\";\n\n /**\n * Number of partial images to generate in streaming mode (0-3).\n * When set, the model will return partial images as they are generated,\n * providing faster visual feedback.\n * @default 0\n */\n partialImages?: number;\n\n /**\n * The quality of the generated image.\n * - `low`: Faster generation, lower quality\n * - `medium`: Balanced generation time and quality\n * - `high`: Slower generation, higher quality\n * - `auto`: Let the model decide based on the prompt\n * @default \"auto\"\n */\n quality?: \"low\" | \"medium\" | \"high\" | \"auto\";\n\n /**\n * The size of the generated image.\n * - `1024x1024`: Square format\n * - `1024x1536`: Portrait format\n * - `1536x1024`: Landscape format\n * - `auto`: Let the model decide based on the prompt\n * @default \"auto\"\n */\n size?: \"1024x1024\" | \"1024x1536\" | \"1536x1024\" | \"auto\";\n}\n\n/**\n * OpenAI Image Generation tool type for the Responses API.\n */\nexport type ImageGenerationTool = OpenAIClient.Responses.Tool.ImageGeneration;\n\n/**\n * Converts input mask options to the API format.\n */\nfunction convertInputImageMask(\n mask: ImageGenerationInputMask | undefined\n): ImageGenerationTool[\"input_image_mask\"] {\n if (!mask) return undefined;\n return {\n image_url: mask.imageUrl,\n file_id: mask.fileId,\n };\n}\n\n/**\n * Creates an Image Generation tool that allows models to generate or edit images\n * using text prompts and optional image inputs.\n *\n * The image generation tool leverages the GPT Image model and automatically\n * optimizes text inputs for improved performance. When included in a request,\n * the model can decide when and how to generate images as part of the conversation.\n *\n * **Key Features**:\n * - Generate images from text descriptions\n * - Edit existing images with text instructions\n * - Multi-turn image editing by referencing previous responses\n * - Configurable output options (size, quality, format)\n * - Streaming support for partial image generation\n *\n * **Prompting Tips**:\n * - Use terms like \"draw\" or \"edit\" in your prompt for best results\n * - For combining images, say \"edit the first image by adding this element\" instead of \"combine\"\n *\n * @see {@link https://platform.openai.com/docs/guides/tools-image-generation | OpenAI Image Generation Documentation}\n *\n * @param options - Configuration options for the Image Generation tool\n * @returns An Image Generation tool definition to be passed to the OpenAI Responses API\n *\n * @example\n * ```typescript\n * import { ChatOpenAI, tools } from \"@langchain/openai\";\n *\n * const model = new ChatOpenAI({ model: \"gpt-4o\" });\n *\n * // Basic usage - generate an image\n * const response = await model.invoke(\n * \"Generate an image of a gray tabby cat hugging an otter with an orange scarf\",\n * { tools: [tools.imageGeneration()] }\n * );\n *\n * // Access the generated image\n * const imageData = response.additional_kwargs.tool_outputs?.find(\n * (output) => output.type === \"image_generation_call\"\n * );\n * if (imageData?.result) {\n * // imageData.result contains the base64-encoded image\n * const fs = await import(\"fs\");\n * fs.writeFileSync(\"output.png\", Buffer.from(imageData.result, \"base64\"));\n * }\n *\n * // With custom options\n * const response = await model.invoke(\n * \"Draw a beautiful sunset over mountains\",\n * {\n * tools: [tools.imageGeneration({\n * size: \"1536x1024\", // Landscape format\n * quality: \"high\", // Higher quality output\n * outputFormat: \"jpeg\", // JPEG format\n * outputCompression: 90, // 90% compression\n * })]\n * }\n * );\n *\n * // With transparent background\n * const response = await model.invoke(\n * \"Create a logo with a transparent background\",\n * {\n * tools: [tools.imageGeneration({\n * background: \"transparent\",\n * outputFormat: \"png\",\n * })]\n * }\n * );\n *\n * // Force the model to use image generation\n * const response = await model.invoke(\n * \"A serene lake at dawn\",\n * {\n * tools: [tools.imageGeneration()],\n * tool_choice: { type: \"image_generation\" },\n * }\n * );\n *\n * // Enable streaming with partial images\n * const response = await model.invoke(\n * \"Draw a detailed fantasy castle\",\n * {\n * tools: [tools.imageGeneration({\n * partialImages: 2, // Get 2 partial images during generation\n * })]\n * }\n * );\n * ```\n *\n * @remarks\n * - Supported models: gpt-4o, gpt-4o-mini, gpt-4.1, gpt-4.1-mini, gpt-4.1-nano, o3\n * - The image generation process always uses `gpt-image-1` model internally\n * - The model will automatically revise prompts for improved performance\n * - Access the revised prompt via `revised_prompt` field in the output\n * - Multi-turn editing is supported by passing previous response messages\n */\nexport function imageGeneration(options?: ImageGenerationOptions): ServerTool {\n return {\n type: \"image_generation\",\n action: options?.action,\n background: options?.background,\n input_fidelity: options?.inputFidelity,\n input_image_mask: convertInputImageMask(options?.inputImageMask),\n model: options?.model,\n moderation: options?.moderation,\n output_compression: options?.outputCompression,\n output_format: options?.outputFormat,\n partial_images: options?.partialImages,\n quality: options?.quality,\n size: options?.size,\n } satisfies ImageGenerationTool;\n}\n"],"mappings":";;;;AAwHA,SAAS,sBACP,MACyC;AACzC,KAAI,CAAC,KAAM,QAAO,KAAA;AAClB,QAAO;EACL,WAAW,KAAK;EAChB,SAAS,KAAK;EACf;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoGH,SAAgB,gBAAgB,SAA8C;AAC5E,QAAO;EACL,MAAM;EACN,QAAQ,SAAS;EACjB,YAAY,SAAS;EACrB,gBAAgB,SAAS;EACzB,kBAAkB,sBAAsB,SAAS,eAAe;EAChE,OAAO,SAAS;EAChB,YAAY,SAAS;EACrB,oBAAoB,SAAS;EAC7B,eAAe,SAAS;EACxB,gBAAgB,SAAS;EACzB,SAAS,SAAS;EAClB,MAAM,SAAS;EAChB"}
1
+ {"version":3,"file":"imageGeneration.cjs","names":[],"sources":["../../src/tools/imageGeneration.ts"],"sourcesContent":["import { OpenAI as OpenAIClient } from \"openai\";\nimport type { ServerTool } from \"@langchain/core/tools\";\n\n/**\n * Optional mask for inpainting. Allows you to specify areas of the image\n * that should be regenerated.\n */\nexport interface ImageGenerationInputMask {\n /**\n * Base64-encoded mask image URL.\n */\n imageUrl?: string;\n /**\n * File ID for the mask image (uploaded via OpenAI File API).\n */\n fileId?: string;\n}\n\n/**\n * Options for the Image Generation tool.\n */\nexport interface ImageGenerationOptions {\n /**\n * Whether to generate a new image or edit an existing image.\n * - `generate`: Generate a new image from scratch\n * - `edit`: Edit an existing image\n * - `auto`: Let the model decide based on the input\n * @default \"auto\"\n */\n action?: \"generate\" | \"edit\" | \"auto\";\n\n /**\n * Background type for the generated image.\n * - `transparent`: Generate image with transparent background\n * - `opaque`: Generate image with opaque background\n * - `auto`: Let the model decide based on the prompt\n * @default \"auto\"\n */\n background?: \"transparent\" | \"opaque\" | \"auto\";\n\n /**\n * Control how much effort the model will exert to match the style and features,\n * especially facial features, of input images. This parameter is only supported\n * for `gpt-image-1`. Unsupported for `gpt-image-1-mini`.\n * - `high`: Higher fidelity to input images\n * - `low`: Lower fidelity to input images\n * @default \"low\"\n */\n inputFidelity?: \"high\" | \"low\";\n\n /**\n * Optional mask for inpainting. Use this to specify areas of an image\n * that should be regenerated.\n */\n inputImageMask?: ImageGenerationInputMask;\n\n /**\n * The image generation model to use.\n * @default \"gpt-image-1\"\n */\n model?: \"gpt-image-1\" | \"gpt-image-1-mini\" | \"gpt-image-1.5\";\n\n /**\n * Moderation level for the generated image.\n * - `auto`: Standard moderation\n * - `low`: Less restrictive moderation\n * @default \"auto\"\n */\n moderation?: \"auto\" | \"low\";\n\n /**\n * Compression level for the output image (0-100).\n * Only applies to JPEG and WebP formats.\n * @default 100\n */\n outputCompression?: number;\n\n /**\n * The output format of the generated image.\n * @default \"png\"\n */\n outputFormat?: \"png\" | \"webp\" | \"jpeg\";\n\n /**\n * Number of partial images to generate in streaming mode (0-3).\n * When set, the model will return partial images as they are generated,\n * providing faster visual feedback.\n * @default 0\n */\n partialImages?: number;\n\n /**\n * The quality of the generated image.\n * - `low`: Faster generation, lower quality\n * - `medium`: Balanced generation time and quality\n * - `high`: Slower generation, higher quality\n * - `auto`: Let the model decide based on the prompt\n * @default \"auto\"\n */\n quality?: \"low\" | \"medium\" | \"high\" | \"auto\";\n\n /**\n * The size of the generated image.\n * - `1024x1024`: Square format\n * - `1024x1536`: Portrait format\n * - `1536x1024`: Landscape format\n * - `auto`: Let the model decide based on the prompt\n * @default \"auto\"\n */\n size?: \"1024x1024\" | \"1024x1536\" | \"1536x1024\" | \"auto\";\n}\n\n/**\n * OpenAI Image Generation tool type for the Responses API.\n */\nexport type ImageGenerationTool = OpenAIClient.Responses.Tool.ImageGeneration;\n\n/**\n * Converts input mask options to the API format.\n */\nfunction convertInputImageMask(\n mask: ImageGenerationInputMask | undefined\n): ImageGenerationTool[\"input_image_mask\"] {\n if (!mask) return undefined;\n return {\n image_url: mask.imageUrl,\n file_id: mask.fileId,\n };\n}\n\n/**\n * Creates an Image Generation tool that allows models to generate or edit images\n * using text prompts and optional image inputs.\n *\n * The image generation tool leverages the GPT Image model and automatically\n * optimizes text inputs for improved performance. When included in a request,\n * the model can decide when and how to generate images as part of the conversation.\n *\n * **Key Features**:\n * - Generate images from text descriptions\n * - Edit existing images with text instructions\n * - Multi-turn image editing by referencing previous responses\n * - Configurable output options (size, quality, format)\n * - Streaming support for partial image generation\n *\n * **Prompting Tips**:\n * - Use terms like \"draw\" or \"edit\" in your prompt for best results\n * - For combining images, say \"edit the first image by adding this element\" instead of \"combine\"\n *\n * @see {@link https://platform.openai.com/docs/guides/tools-image-generation | OpenAI Image Generation Documentation}\n *\n * @param options - Configuration options for the Image Generation tool\n * @returns An Image Generation tool definition to be passed to the OpenAI Responses API\n *\n * @example\n * ```typescript\n * import { ChatOpenAI, tools } from \"@langchain/openai\";\n *\n * const model = new ChatOpenAI({ model: \"gpt-4o\" });\n *\n * // Basic usage - generate an image\n * const response = await model.invoke(\n * \"Generate an image of a gray tabby cat hugging an otter with an orange scarf\",\n * { tools: [tools.imageGeneration()] }\n * );\n *\n * // Access the generated image\n * const imageData = response.additional_kwargs.tool_outputs?.find(\n * (output) => output.type === \"image_generation_call\"\n * );\n * if (imageData?.result) {\n * // imageData.result contains the base64-encoded image\n * const fs = await import(\"fs\");\n * fs.writeFileSync(\"output.png\", Buffer.from(imageData.result, \"base64\"));\n * }\n *\n * // With custom options\n * const response = await model.invoke(\n * \"Draw a beautiful sunset over mountains\",\n * {\n * tools: [tools.imageGeneration({\n * size: \"1536x1024\", // Landscape format\n * quality: \"high\", // Higher quality output\n * outputFormat: \"jpeg\", // JPEG format\n * outputCompression: 90, // 90% compression\n * })]\n * }\n * );\n *\n * // With transparent background\n * const response = await model.invoke(\n * \"Create a logo with a transparent background\",\n * {\n * tools: [tools.imageGeneration({\n * background: \"transparent\",\n * outputFormat: \"png\",\n * })]\n * }\n * );\n *\n * // Force the model to use image generation\n * const response = await model.invoke(\n * \"A serene lake at dawn\",\n * {\n * tools: [tools.imageGeneration()],\n * tool_choice: { type: \"image_generation\" },\n * }\n * );\n *\n * // Enable streaming with partial images\n * const response = await model.invoke(\n * \"Draw a detailed fantasy castle\",\n * {\n * tools: [tools.imageGeneration({\n * partialImages: 2, // Get 2 partial images during generation\n * })]\n * }\n * );\n * ```\n *\n * @remarks\n * - Supported models: gpt-4o, gpt-4o-mini, gpt-4.1, gpt-4.1-mini, gpt-4.1-nano, o3\n * - The image generation process always uses `gpt-image-1` model internally\n * - The model will automatically revise prompts for improved performance\n * - Access the revised prompt via `revised_prompt` field in the output\n * - Multi-turn editing is supported by passing previous response messages\n */\nexport function imageGeneration(options?: ImageGenerationOptions): ServerTool {\n return {\n type: \"image_generation\",\n action: options?.action,\n background: options?.background,\n input_fidelity: options?.inputFidelity,\n input_image_mask: convertInputImageMask(options?.inputImageMask),\n model: options?.model,\n moderation: options?.moderation,\n output_compression: options?.outputCompression,\n output_format: options?.outputFormat,\n partial_images: options?.partialImages,\n quality: options?.quality,\n size: options?.size,\n } satisfies ImageGenerationTool;\n}\n"],"mappings":";;;;AAwHA,SAAS,sBACP,MACyC;CACzC,IAAI,CAAC,MAAM,OAAO,KAAA;CAClB,OAAO;EACL,WAAW,KAAK;EAChB,SAAS,KAAK;CAChB;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmGA,SAAgB,gBAAgB,SAA8C;CAC5E,OAAO;EACL,MAAM;EACN,QAAQ,SAAS;EACjB,YAAY,SAAS;EACrB,gBAAgB,SAAS;EACzB,kBAAkB,sBAAsB,SAAS,cAAc;EAC/D,OAAO,SAAS;EAChB,YAAY,SAAS;EACrB,oBAAoB,SAAS;EAC7B,eAAe,SAAS;EACxB,gBAAgB,SAAS;EACzB,SAAS,SAAS;EAClB,MAAM,SAAS;CACjB;AACF"}
@@ -1,6 +1,5 @@
1
1
  import { OpenAI } from "openai";
2
2
  import { ServerTool } from "@langchain/core/tools";
3
-
4
3
  //#region src/tools/imageGeneration.d.ts
5
4
  /**
6
5
  * Optional mask for inpainting. Allows you to specify areas of the image
@@ -1 +1 @@
1
- {"version":3,"file":"imageGeneration.d.cts","names":[],"sources":["../../src/tools/imageGeneration.ts"],"mappings":";;;;;;AAOA;;UAAiB,wBAAA;EAIf;;AAUF;EAVE,QAAA;;;;EAIA,MAAA;AAAA;;;;UAMe,sBAAA;EAsDf;;;;;;;EA9CA,MAAA;EAsF6B;;;;;;;EA7E7B,UAAA;EA6E2E;AAgH7E;;;;;;;EAnLE,aAAA;EAmL2E;;;;EA7K3E,cAAA,GAAiB,wBAAA;;;;;EAMjB,KAAA;;;;;;;EAQA,UAAA;;;;;;EAOA,iBAAA;;;;;EAMA,YAAA;;;;;;;EAQA,aAAA;;;;;;;;;EAUA,OAAA;;;;;;;;;EAUA,IAAA;AAAA;;;;KAMU,mBAAA,GAAsB,MAAA,CAAa,SAAA,CAAU,IAAA,CAAK,eAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAgH9C,eAAA,CAAgB,OAAA,GAAU,sBAAA,GAAyB,UAAA"}
1
+ {"version":3,"file":"imageGeneration.d.cts","names":[],"sources":["../../src/tools/imageGeneration.ts"],"mappings":";;;;;;;UAOiB;;;;EAIf;;;;EAIA;;;;;UAMe;;;;;;;;EAQf;;;;;;;;EASA;;;;;;;;;EAUA;;;;;EAMA,iBAAiB;;;;;EAMjB;;;;;;;EAQA;;;;;;EAOA;;;;;EAMA;;;;;;;EAQA;;;;;;;;;EAUA;;;;;;;;;EAUA;;;;;KAMU,sBAAsB,OAAa,UAAU,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAgH9C,gBAAgB,UAAU,yBAAyB"}
@@ -1,6 +1,5 @@
1
1
  import { OpenAI } from "openai";
2
2
  import { ServerTool } from "@langchain/core/tools";
3
-
4
3
  //#region src/tools/imageGeneration.d.ts
5
4
  /**
6
5
  * Optional mask for inpainting. Allows you to specify areas of the image
@@ -1 +1 @@
1
- {"version":3,"file":"imageGeneration.d.ts","names":[],"sources":["../../src/tools/imageGeneration.ts"],"mappings":";;;;;;AAOA;;UAAiB,wBAAA;EAIf;;AAUF;EAVE,QAAA;;;;EAIA,MAAA;AAAA;;;;UAMe,sBAAA;EAsDf;;;;;;;EA9CA,MAAA;EAsF6B;;;;;;;EA7E7B,UAAA;EA6E2E;AAgH7E;;;;;;;EAnLE,aAAA;EAmL2E;;;;EA7K3E,cAAA,GAAiB,wBAAA;;;;;EAMjB,KAAA;;;;;;;EAQA,UAAA;;;;;;EAOA,iBAAA;;;;;EAMA,YAAA;;;;;;;EAQA,aAAA;;;;;;;;;EAUA,OAAA;;;;;;;;;EAUA,IAAA;AAAA;;;;KAMU,mBAAA,GAAsB,MAAA,CAAa,SAAA,CAAU,IAAA,CAAK,eAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAgH9C,eAAA,CAAgB,OAAA,GAAU,sBAAA,GAAyB,UAAA"}
1
+ {"version":3,"file":"imageGeneration.d.ts","names":[],"sources":["../../src/tools/imageGeneration.ts"],"mappings":";;;;;;;UAOiB;;;;EAIf;;;;EAIA;;;;;UAMe;;;;;;;;EAQf;;;;;;;;EASA;;;;;;;;;EAUA;;;;;EAMA,iBAAiB;;;;;EAMjB;;;;;;;EAQA;;;;;;EAOA;;;;;EAMA;;;;;;;EAQA;;;;;;;;;EAUA;;;;;;;;;EAUA;;;;;KAMU,sBAAsB,OAAa,UAAU,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAgH9C,gBAAgB,UAAU,yBAAyB"}
@@ -1 +1 @@
1
- {"version":3,"file":"imageGeneration.js","names":[],"sources":["../../src/tools/imageGeneration.ts"],"sourcesContent":["import { OpenAI as OpenAIClient } from \"openai\";\nimport type { ServerTool } from \"@langchain/core/tools\";\n\n/**\n * Optional mask for inpainting. Allows you to specify areas of the image\n * that should be regenerated.\n */\nexport interface ImageGenerationInputMask {\n /**\n * Base64-encoded mask image URL.\n */\n imageUrl?: string;\n /**\n * File ID for the mask image (uploaded via OpenAI File API).\n */\n fileId?: string;\n}\n\n/**\n * Options for the Image Generation tool.\n */\nexport interface ImageGenerationOptions {\n /**\n * Whether to generate a new image or edit an existing image.\n * - `generate`: Generate a new image from scratch\n * - `edit`: Edit an existing image\n * - `auto`: Let the model decide based on the input\n * @default \"auto\"\n */\n action?: \"generate\" | \"edit\" | \"auto\";\n\n /**\n * Background type for the generated image.\n * - `transparent`: Generate image with transparent background\n * - `opaque`: Generate image with opaque background\n * - `auto`: Let the model decide based on the prompt\n * @default \"auto\"\n */\n background?: \"transparent\" | \"opaque\" | \"auto\";\n\n /**\n * Control how much effort the model will exert to match the style and features,\n * especially facial features, of input images. This parameter is only supported\n * for `gpt-image-1`. Unsupported for `gpt-image-1-mini`.\n * - `high`: Higher fidelity to input images\n * - `low`: Lower fidelity to input images\n * @default \"low\"\n */\n inputFidelity?: \"high\" | \"low\";\n\n /**\n * Optional mask for inpainting. Use this to specify areas of an image\n * that should be regenerated.\n */\n inputImageMask?: ImageGenerationInputMask;\n\n /**\n * The image generation model to use.\n * @default \"gpt-image-1\"\n */\n model?: \"gpt-image-1\" | \"gpt-image-1-mini\" | \"gpt-image-1.5\";\n\n /**\n * Moderation level for the generated image.\n * - `auto`: Standard moderation\n * - `low`: Less restrictive moderation\n * @default \"auto\"\n */\n moderation?: \"auto\" | \"low\";\n\n /**\n * Compression level for the output image (0-100).\n * Only applies to JPEG and WebP formats.\n * @default 100\n */\n outputCompression?: number;\n\n /**\n * The output format of the generated image.\n * @default \"png\"\n */\n outputFormat?: \"png\" | \"webp\" | \"jpeg\";\n\n /**\n * Number of partial images to generate in streaming mode (0-3).\n * When set, the model will return partial images as they are generated,\n * providing faster visual feedback.\n * @default 0\n */\n partialImages?: number;\n\n /**\n * The quality of the generated image.\n * - `low`: Faster generation, lower quality\n * - `medium`: Balanced generation time and quality\n * - `high`: Slower generation, higher quality\n * - `auto`: Let the model decide based on the prompt\n * @default \"auto\"\n */\n quality?: \"low\" | \"medium\" | \"high\" | \"auto\";\n\n /**\n * The size of the generated image.\n * - `1024x1024`: Square format\n * - `1024x1536`: Portrait format\n * - `1536x1024`: Landscape format\n * - `auto`: Let the model decide based on the prompt\n * @default \"auto\"\n */\n size?: \"1024x1024\" | \"1024x1536\" | \"1536x1024\" | \"auto\";\n}\n\n/**\n * OpenAI Image Generation tool type for the Responses API.\n */\nexport type ImageGenerationTool = OpenAIClient.Responses.Tool.ImageGeneration;\n\n/**\n * Converts input mask options to the API format.\n */\nfunction convertInputImageMask(\n mask: ImageGenerationInputMask | undefined\n): ImageGenerationTool[\"input_image_mask\"] {\n if (!mask) return undefined;\n return {\n image_url: mask.imageUrl,\n file_id: mask.fileId,\n };\n}\n\n/**\n * Creates an Image Generation tool that allows models to generate or edit images\n * using text prompts and optional image inputs.\n *\n * The image generation tool leverages the GPT Image model and automatically\n * optimizes text inputs for improved performance. When included in a request,\n * the model can decide when and how to generate images as part of the conversation.\n *\n * **Key Features**:\n * - Generate images from text descriptions\n * - Edit existing images with text instructions\n * - Multi-turn image editing by referencing previous responses\n * - Configurable output options (size, quality, format)\n * - Streaming support for partial image generation\n *\n * **Prompting Tips**:\n * - Use terms like \"draw\" or \"edit\" in your prompt for best results\n * - For combining images, say \"edit the first image by adding this element\" instead of \"combine\"\n *\n * @see {@link https://platform.openai.com/docs/guides/tools-image-generation | OpenAI Image Generation Documentation}\n *\n * @param options - Configuration options for the Image Generation tool\n * @returns An Image Generation tool definition to be passed to the OpenAI Responses API\n *\n * @example\n * ```typescript\n * import { ChatOpenAI, tools } from \"@langchain/openai\";\n *\n * const model = new ChatOpenAI({ model: \"gpt-4o\" });\n *\n * // Basic usage - generate an image\n * const response = await model.invoke(\n * \"Generate an image of a gray tabby cat hugging an otter with an orange scarf\",\n * { tools: [tools.imageGeneration()] }\n * );\n *\n * // Access the generated image\n * const imageData = response.additional_kwargs.tool_outputs?.find(\n * (output) => output.type === \"image_generation_call\"\n * );\n * if (imageData?.result) {\n * // imageData.result contains the base64-encoded image\n * const fs = await import(\"fs\");\n * fs.writeFileSync(\"output.png\", Buffer.from(imageData.result, \"base64\"));\n * }\n *\n * // With custom options\n * const response = await model.invoke(\n * \"Draw a beautiful sunset over mountains\",\n * {\n * tools: [tools.imageGeneration({\n * size: \"1536x1024\", // Landscape format\n * quality: \"high\", // Higher quality output\n * outputFormat: \"jpeg\", // JPEG format\n * outputCompression: 90, // 90% compression\n * })]\n * }\n * );\n *\n * // With transparent background\n * const response = await model.invoke(\n * \"Create a logo with a transparent background\",\n * {\n * tools: [tools.imageGeneration({\n * background: \"transparent\",\n * outputFormat: \"png\",\n * })]\n * }\n * );\n *\n * // Force the model to use image generation\n * const response = await model.invoke(\n * \"A serene lake at dawn\",\n * {\n * tools: [tools.imageGeneration()],\n * tool_choice: { type: \"image_generation\" },\n * }\n * );\n *\n * // Enable streaming with partial images\n * const response = await model.invoke(\n * \"Draw a detailed fantasy castle\",\n * {\n * tools: [tools.imageGeneration({\n * partialImages: 2, // Get 2 partial images during generation\n * })]\n * }\n * );\n * ```\n *\n * @remarks\n * - Supported models: gpt-4o, gpt-4o-mini, gpt-4.1, gpt-4.1-mini, gpt-4.1-nano, o3\n * - The image generation process always uses `gpt-image-1` model internally\n * - The model will automatically revise prompts for improved performance\n * - Access the revised prompt via `revised_prompt` field in the output\n * - Multi-turn editing is supported by passing previous response messages\n */\nexport function imageGeneration(options?: ImageGenerationOptions): ServerTool {\n return {\n type: \"image_generation\",\n action: options?.action,\n background: options?.background,\n input_fidelity: options?.inputFidelity,\n input_image_mask: convertInputImageMask(options?.inputImageMask),\n model: options?.model,\n moderation: options?.moderation,\n output_compression: options?.outputCompression,\n output_format: options?.outputFormat,\n partial_images: options?.partialImages,\n quality: options?.quality,\n size: options?.size,\n } satisfies ImageGenerationTool;\n}\n"],"mappings":";;;;AAwHA,SAAS,sBACP,MACyC;AACzC,KAAI,CAAC,KAAM,QAAO,KAAA;AAClB,QAAO;EACL,WAAW,KAAK;EAChB,SAAS,KAAK;EACf;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoGH,SAAgB,gBAAgB,SAA8C;AAC5E,QAAO;EACL,MAAM;EACN,QAAQ,SAAS;EACjB,YAAY,SAAS;EACrB,gBAAgB,SAAS;EACzB,kBAAkB,sBAAsB,SAAS,eAAe;EAChE,OAAO,SAAS;EAChB,YAAY,SAAS;EACrB,oBAAoB,SAAS;EAC7B,eAAe,SAAS;EACxB,gBAAgB,SAAS;EACzB,SAAS,SAAS;EAClB,MAAM,SAAS;EAChB"}
1
+ {"version":3,"file":"imageGeneration.js","names":[],"sources":["../../src/tools/imageGeneration.ts"],"sourcesContent":["import { OpenAI as OpenAIClient } from \"openai\";\nimport type { ServerTool } from \"@langchain/core/tools\";\n\n/**\n * Optional mask for inpainting. Allows you to specify areas of the image\n * that should be regenerated.\n */\nexport interface ImageGenerationInputMask {\n /**\n * Base64-encoded mask image URL.\n */\n imageUrl?: string;\n /**\n * File ID for the mask image (uploaded via OpenAI File API).\n */\n fileId?: string;\n}\n\n/**\n * Options for the Image Generation tool.\n */\nexport interface ImageGenerationOptions {\n /**\n * Whether to generate a new image or edit an existing image.\n * - `generate`: Generate a new image from scratch\n * - `edit`: Edit an existing image\n * - `auto`: Let the model decide based on the input\n * @default \"auto\"\n */\n action?: \"generate\" | \"edit\" | \"auto\";\n\n /**\n * Background type for the generated image.\n * - `transparent`: Generate image with transparent background\n * - `opaque`: Generate image with opaque background\n * - `auto`: Let the model decide based on the prompt\n * @default \"auto\"\n */\n background?: \"transparent\" | \"opaque\" | \"auto\";\n\n /**\n * Control how much effort the model will exert to match the style and features,\n * especially facial features, of input images. This parameter is only supported\n * for `gpt-image-1`. Unsupported for `gpt-image-1-mini`.\n * - `high`: Higher fidelity to input images\n * - `low`: Lower fidelity to input images\n * @default \"low\"\n */\n inputFidelity?: \"high\" | \"low\";\n\n /**\n * Optional mask for inpainting. Use this to specify areas of an image\n * that should be regenerated.\n */\n inputImageMask?: ImageGenerationInputMask;\n\n /**\n * The image generation model to use.\n * @default \"gpt-image-1\"\n */\n model?: \"gpt-image-1\" | \"gpt-image-1-mini\" | \"gpt-image-1.5\";\n\n /**\n * Moderation level for the generated image.\n * - `auto`: Standard moderation\n * - `low`: Less restrictive moderation\n * @default \"auto\"\n */\n moderation?: \"auto\" | \"low\";\n\n /**\n * Compression level for the output image (0-100).\n * Only applies to JPEG and WebP formats.\n * @default 100\n */\n outputCompression?: number;\n\n /**\n * The output format of the generated image.\n * @default \"png\"\n */\n outputFormat?: \"png\" | \"webp\" | \"jpeg\";\n\n /**\n * Number of partial images to generate in streaming mode (0-3).\n * When set, the model will return partial images as they are generated,\n * providing faster visual feedback.\n * @default 0\n */\n partialImages?: number;\n\n /**\n * The quality of the generated image.\n * - `low`: Faster generation, lower quality\n * - `medium`: Balanced generation time and quality\n * - `high`: Slower generation, higher quality\n * - `auto`: Let the model decide based on the prompt\n * @default \"auto\"\n */\n quality?: \"low\" | \"medium\" | \"high\" | \"auto\";\n\n /**\n * The size of the generated image.\n * - `1024x1024`: Square format\n * - `1024x1536`: Portrait format\n * - `1536x1024`: Landscape format\n * - `auto`: Let the model decide based on the prompt\n * @default \"auto\"\n */\n size?: \"1024x1024\" | \"1024x1536\" | \"1536x1024\" | \"auto\";\n}\n\n/**\n * OpenAI Image Generation tool type for the Responses API.\n */\nexport type ImageGenerationTool = OpenAIClient.Responses.Tool.ImageGeneration;\n\n/**\n * Converts input mask options to the API format.\n */\nfunction convertInputImageMask(\n mask: ImageGenerationInputMask | undefined\n): ImageGenerationTool[\"input_image_mask\"] {\n if (!mask) return undefined;\n return {\n image_url: mask.imageUrl,\n file_id: mask.fileId,\n };\n}\n\n/**\n * Creates an Image Generation tool that allows models to generate or edit images\n * using text prompts and optional image inputs.\n *\n * The image generation tool leverages the GPT Image model and automatically\n * optimizes text inputs for improved performance. When included in a request,\n * the model can decide when and how to generate images as part of the conversation.\n *\n * **Key Features**:\n * - Generate images from text descriptions\n * - Edit existing images with text instructions\n * - Multi-turn image editing by referencing previous responses\n * - Configurable output options (size, quality, format)\n * - Streaming support for partial image generation\n *\n * **Prompting Tips**:\n * - Use terms like \"draw\" or \"edit\" in your prompt for best results\n * - For combining images, say \"edit the first image by adding this element\" instead of \"combine\"\n *\n * @see {@link https://platform.openai.com/docs/guides/tools-image-generation | OpenAI Image Generation Documentation}\n *\n * @param options - Configuration options for the Image Generation tool\n * @returns An Image Generation tool definition to be passed to the OpenAI Responses API\n *\n * @example\n * ```typescript\n * import { ChatOpenAI, tools } from \"@langchain/openai\";\n *\n * const model = new ChatOpenAI({ model: \"gpt-4o\" });\n *\n * // Basic usage - generate an image\n * const response = await model.invoke(\n * \"Generate an image of a gray tabby cat hugging an otter with an orange scarf\",\n * { tools: [tools.imageGeneration()] }\n * );\n *\n * // Access the generated image\n * const imageData = response.additional_kwargs.tool_outputs?.find(\n * (output) => output.type === \"image_generation_call\"\n * );\n * if (imageData?.result) {\n * // imageData.result contains the base64-encoded image\n * const fs = await import(\"fs\");\n * fs.writeFileSync(\"output.png\", Buffer.from(imageData.result, \"base64\"));\n * }\n *\n * // With custom options\n * const response = await model.invoke(\n * \"Draw a beautiful sunset over mountains\",\n * {\n * tools: [tools.imageGeneration({\n * size: \"1536x1024\", // Landscape format\n * quality: \"high\", // Higher quality output\n * outputFormat: \"jpeg\", // JPEG format\n * outputCompression: 90, // 90% compression\n * })]\n * }\n * );\n *\n * // With transparent background\n * const response = await model.invoke(\n * \"Create a logo with a transparent background\",\n * {\n * tools: [tools.imageGeneration({\n * background: \"transparent\",\n * outputFormat: \"png\",\n * })]\n * }\n * );\n *\n * // Force the model to use image generation\n * const response = await model.invoke(\n * \"A serene lake at dawn\",\n * {\n * tools: [tools.imageGeneration()],\n * tool_choice: { type: \"image_generation\" },\n * }\n * );\n *\n * // Enable streaming with partial images\n * const response = await model.invoke(\n * \"Draw a detailed fantasy castle\",\n * {\n * tools: [tools.imageGeneration({\n * partialImages: 2, // Get 2 partial images during generation\n * })]\n * }\n * );\n * ```\n *\n * @remarks\n * - Supported models: gpt-4o, gpt-4o-mini, gpt-4.1, gpt-4.1-mini, gpt-4.1-nano, o3\n * - The image generation process always uses `gpt-image-1` model internally\n * - The model will automatically revise prompts for improved performance\n * - Access the revised prompt via `revised_prompt` field in the output\n * - Multi-turn editing is supported by passing previous response messages\n */\nexport function imageGeneration(options?: ImageGenerationOptions): ServerTool {\n return {\n type: \"image_generation\",\n action: options?.action,\n background: options?.background,\n input_fidelity: options?.inputFidelity,\n input_image_mask: convertInputImageMask(options?.inputImageMask),\n model: options?.model,\n moderation: options?.moderation,\n output_compression: options?.outputCompression,\n output_format: options?.outputFormat,\n partial_images: options?.partialImages,\n quality: options?.quality,\n size: options?.size,\n } satisfies ImageGenerationTool;\n}\n"],"mappings":";;;;AAwHA,SAAS,sBACP,MACyC;CACzC,IAAI,CAAC,MAAM,OAAO,KAAA;CAClB,OAAO;EACL,WAAW,KAAK;EAChB,SAAS,KAAK;CAChB;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmGA,SAAgB,gBAAgB,SAA8C;CAC5E,OAAO;EACL,MAAM;EACN,QAAQ,SAAS;EACjB,YAAY,SAAS;EACrB,gBAAgB,SAAS;EACzB,kBAAkB,sBAAsB,SAAS,cAAc;EAC/D,OAAO,SAAS;EAChB,YAAY,SAAS;EACrB,oBAAoB,SAAS;EAC7B,eAAe,SAAS;EACxB,gBAAgB,SAAS;EACzB,SAAS,SAAS;EAClB,MAAM,SAAS;CACjB;AACF"}
@@ -1,4 +1,4 @@
1
- require("./dalle.cjs");
1
+ const require_dalle = require("./dalle.cjs");
2
2
  const require_webSearch = require("./webSearch.cjs");
3
3
  const require_mcp = require("./mcp.cjs");
4
4
  const require_codeInterpreter = require("./codeInterpreter.cjs");
@@ -23,6 +23,7 @@ const tools = {
23
23
  toolSearch: require_toolSearch.toolSearch
24
24
  };
25
25
  //#endregion
26
+ exports.DallEAPIWrapper = require_dalle.DallEAPIWrapper;
26
27
  exports.tools = tools;
27
28
 
28
29
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":[],"sources":["../../src/tools/index.ts"],"sourcesContent":["export * from \"./dalle.js\";\n\nimport { webSearch } from \"./webSearch.js\";\nexport type {\n WebSearchTool,\n WebSearchFilters,\n WebSearchOptions,\n} from \"./webSearch.js\";\n\nimport { mcp } from \"./mcp.js\";\nexport type {\n McpTool,\n McpConnectorId,\n McpToolFilter,\n McpApprovalFilter,\n McpRemoteServerOptions,\n McpConnectorOptions,\n} from \"./mcp.js\";\n\nimport { codeInterpreter } from \"./codeInterpreter.js\";\nexport type {\n CodeInterpreterTool,\n CodeInterpreterOptions,\n CodeInterpreterAutoContainer,\n CodeInterpreterMemoryLimit,\n} from \"./codeInterpreter.js\";\n\nimport { fileSearch } from \"./fileSearch.js\";\nexport type {\n FileSearchTool,\n FileSearchOptions,\n FileSearchFilter,\n FileSearchComparisonFilter,\n FileSearchCompoundFilter,\n FileSearchComparisonType,\n FileSearchRankingOptions,\n FileSearchHybridSearchWeights,\n} from \"./fileSearch.js\";\n\nimport { imageGeneration } from \"./imageGeneration.js\";\nexport type {\n ImageGenerationTool,\n ImageGenerationOptions,\n ImageGenerationInputMask,\n} from \"./imageGeneration.js\";\n\nimport { computerUse } from \"./computerUse.js\";\nexport type {\n ComputerUseTool,\n ComputerUseInput,\n ComputerUseOptions,\n ComputerUseEnvironment,\n ComputerUseAction,\n ComputerUseClickAction,\n ComputerUseDoubleClickAction,\n ComputerUseDragAction,\n ComputerUseKeypressAction,\n ComputerUseMoveAction,\n ComputerUseScreenshotAction,\n ComputerUseScrollAction,\n ComputerUseTypeAction,\n ComputerUseWaitAction,\n} from \"./computerUse.js\";\n\nimport { localShell } from \"./localShell.js\";\nexport type {\n LocalShellTool,\n LocalShellOptions,\n LocalShellAction,\n} from \"./localShell.js\";\n\nimport { shell } from \"./shell.js\";\nexport type {\n ShellTool,\n ShellOptions,\n ShellAction,\n ShellResult,\n ShellCommandOutput,\n ShellCallOutcome,\n} from \"./shell.js\";\n\nimport { applyPatch } from \"./applyPatch.js\";\nexport type {\n ApplyPatchTool,\n ApplyPatchOptions,\n ApplyPatchOperation,\n ApplyPatchCreateFileOperation,\n ApplyPatchUpdateFileOperation,\n ApplyPatchDeleteFileOperation,\n} from \"./applyPatch.js\";\n\nimport { toolSearch } from \"./toolSearch.js\";\nexport type { ToolSearchTool, ToolSearchOptions } from \"./toolSearch.js\";\n\nexport const tools = {\n webSearch,\n mcp,\n codeInterpreter,\n fileSearch,\n imageGeneration,\n computerUse,\n localShell,\n shell,\n applyPatch,\n toolSearch,\n};\n"],"mappings":";;;;;;;;;;;;AA8FA,MAAa,QAAQ;CACnB,WAAA,kBAAA;CACA,KAAA,YAAA;CACA,iBAAA,wBAAA;CACA,YAAA,mBAAA;CACA,iBAAA,wBAAA;CACA,aAAA,oBAAA;CACA,YAAA,mBAAA;CACA,OAAA,cAAA;CACA,YAAA,mBAAA;CACA,YAAA,mBAAA;CACD"}
1
+ {"version":3,"file":"index.cjs","names":[],"sources":["../../src/tools/index.ts"],"sourcesContent":["export * from \"./dalle.js\";\n\nimport { webSearch } from \"./webSearch.js\";\nexport type {\n WebSearchTool,\n WebSearchFilters,\n WebSearchOptions,\n} from \"./webSearch.js\";\n\nimport { mcp } from \"./mcp.js\";\nexport type {\n McpTool,\n McpConnectorId,\n McpToolFilter,\n McpApprovalFilter,\n McpRemoteServerOptions,\n McpConnectorOptions,\n} from \"./mcp.js\";\n\nimport { codeInterpreter } from \"./codeInterpreter.js\";\nexport type {\n CodeInterpreterTool,\n CodeInterpreterOptions,\n CodeInterpreterAutoContainer,\n CodeInterpreterMemoryLimit,\n} from \"./codeInterpreter.js\";\n\nimport { fileSearch } from \"./fileSearch.js\";\nexport type {\n FileSearchTool,\n FileSearchOptions,\n FileSearchFilter,\n FileSearchComparisonFilter,\n FileSearchCompoundFilter,\n FileSearchComparisonType,\n FileSearchRankingOptions,\n FileSearchHybridSearchWeights,\n} from \"./fileSearch.js\";\n\nimport { imageGeneration } from \"./imageGeneration.js\";\nexport type {\n ImageGenerationTool,\n ImageGenerationOptions,\n ImageGenerationInputMask,\n} from \"./imageGeneration.js\";\n\nimport { computerUse } from \"./computerUse.js\";\nexport type {\n ComputerUseTool,\n ComputerUseInput,\n ComputerUseOptions,\n ComputerUseEnvironment,\n ComputerUseAction,\n ComputerUseClickAction,\n ComputerUseDoubleClickAction,\n ComputerUseDragAction,\n ComputerUseKeypressAction,\n ComputerUseMoveAction,\n ComputerUseScreenshotAction,\n ComputerUseScrollAction,\n ComputerUseTypeAction,\n ComputerUseWaitAction,\n} from \"./computerUse.js\";\n\nimport { localShell } from \"./localShell.js\";\nexport type {\n LocalShellTool,\n LocalShellOptions,\n LocalShellAction,\n} from \"./localShell.js\";\n\nimport { shell } from \"./shell.js\";\nexport type {\n ShellTool,\n ShellOptions,\n ShellAction,\n ShellResult,\n ShellCommandOutput,\n ShellCallOutcome,\n} from \"./shell.js\";\n\nimport { applyPatch } from \"./applyPatch.js\";\nexport type {\n ApplyPatchTool,\n ApplyPatchOptions,\n ApplyPatchOperation,\n ApplyPatchCreateFileOperation,\n ApplyPatchUpdateFileOperation,\n ApplyPatchDeleteFileOperation,\n} from \"./applyPatch.js\";\n\nimport { toolSearch } from \"./toolSearch.js\";\nexport type { ToolSearchTool, ToolSearchOptions } from \"./toolSearch.js\";\n\nexport const tools = {\n webSearch,\n mcp,\n codeInterpreter,\n fileSearch,\n imageGeneration,\n computerUse,\n localShell,\n shell,\n applyPatch,\n toolSearch,\n};\n"],"mappings":";;;;;;;;;;;;AA8FA,MAAa,QAAQ;CACnB,WAAA,kBAAA;CACA,KAAA,YAAA;CACA,iBAAA,wBAAA;CACA,YAAA,mBAAA;CACA,iBAAA,wBAAA;CACA,aAAA,oBAAA;CACA,YAAA,mBAAA;CACA,OAAA,cAAA;CACA,YAAA,mBAAA;CACA,YAAA,mBAAA;AACF"}
@@ -9,7 +9,6 @@ import { LocalShellAction, LocalShellOptions, LocalShellTool, localShell } from
9
9
  import { ShellAction, ShellCallOutcome, ShellCommandOutput, ShellOptions, ShellResult, ShellTool, shell } from "./shell.cjs";
10
10
  import { ApplyPatchCreateFileOperation, ApplyPatchDeleteFileOperation, ApplyPatchOperation, ApplyPatchOptions, ApplyPatchTool, ApplyPatchUpdateFileOperation, applyPatch } from "./applyPatch.cjs";
11
11
  import { ToolSearchOptions, ToolSearchTool, toolSearch } from "./toolSearch.cjs";
12
-
13
12
  //#region src/tools/index.d.ts
14
13
  declare const tools: {
15
14
  webSearch: typeof webSearch;
@@ -24,5 +23,5 @@ declare const tools: {
24
23
  toolSearch: typeof toolSearch;
25
24
  };
26
25
  //#endregion
27
- export { tools };
26
+ export { type ApplyPatchCreateFileOperation, type ApplyPatchDeleteFileOperation, type ApplyPatchOperation, type ApplyPatchOptions, type ApplyPatchTool, type ApplyPatchUpdateFileOperation, type CodeInterpreterAutoContainer, type CodeInterpreterMemoryLimit, type CodeInterpreterOptions, type CodeInterpreterTool, type ComputerUseAction, type ComputerUseClickAction, type ComputerUseDoubleClickAction, type ComputerUseDragAction, type ComputerUseEnvironment, type ComputerUseInput, type ComputerUseKeypressAction, type ComputerUseMoveAction, type ComputerUseOptions, type ComputerUseScreenshotAction, type ComputerUseScrollAction, type ComputerUseTool, type ComputerUseTypeAction, type ComputerUseWaitAction, DallEAPIWrapper, DallEAPIWrapperParams, type FileSearchComparisonFilter, type FileSearchComparisonType, type FileSearchCompoundFilter, type FileSearchFilter, type FileSearchHybridSearchWeights, type FileSearchOptions, type FileSearchRankingOptions, type FileSearchTool, type ImageGenerationInputMask, type ImageGenerationOptions, type ImageGenerationTool, type LocalShellAction, type LocalShellOptions, type LocalShellTool, type McpApprovalFilter, type McpConnectorId, type McpConnectorOptions, type McpRemoteServerOptions, type McpTool, type McpToolFilter, OpenAIImageModelId, type ShellAction, type ShellCallOutcome, type ShellCommandOutput, type ShellOptions, type ShellResult, type ShellTool, type ToolSearchOptions, type ToolSearchTool, type WebSearchFilters, type WebSearchOptions, type WebSearchTool, tools };
28
27
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../../src/tools/index.ts"],"mappings":";;;;;;;;;;;;;cA8Fa,KAAA"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../../src/tools/index.ts"],"mappings":";;;;;;;;;;;;cA8Fa"}
@@ -9,7 +9,6 @@ import { LocalShellAction, LocalShellOptions, LocalShellTool, localShell } from
9
9
  import { ShellAction, ShellCallOutcome, ShellCommandOutput, ShellOptions, ShellResult, ShellTool, shell } from "./shell.js";
10
10
  import { ApplyPatchCreateFileOperation, ApplyPatchDeleteFileOperation, ApplyPatchOperation, ApplyPatchOptions, ApplyPatchTool, ApplyPatchUpdateFileOperation, applyPatch } from "./applyPatch.js";
11
11
  import { ToolSearchOptions, ToolSearchTool, toolSearch } from "./toolSearch.js";
12
-
13
12
  //#region src/tools/index.d.ts
14
13
  declare const tools: {
15
14
  webSearch: typeof webSearch;
@@ -24,5 +23,5 @@ declare const tools: {
24
23
  toolSearch: typeof toolSearch;
25
24
  };
26
25
  //#endregion
27
- export { tools };
26
+ export { type ApplyPatchCreateFileOperation, type ApplyPatchDeleteFileOperation, type ApplyPatchOperation, type ApplyPatchOptions, type ApplyPatchTool, type ApplyPatchUpdateFileOperation, type CodeInterpreterAutoContainer, type CodeInterpreterMemoryLimit, type CodeInterpreterOptions, type CodeInterpreterTool, type ComputerUseAction, type ComputerUseClickAction, type ComputerUseDoubleClickAction, type ComputerUseDragAction, type ComputerUseEnvironment, type ComputerUseInput, type ComputerUseKeypressAction, type ComputerUseMoveAction, type ComputerUseOptions, type ComputerUseScreenshotAction, type ComputerUseScrollAction, type ComputerUseTool, type ComputerUseTypeAction, type ComputerUseWaitAction, DallEAPIWrapper, DallEAPIWrapperParams, type FileSearchComparisonFilter, type FileSearchComparisonType, type FileSearchCompoundFilter, type FileSearchFilter, type FileSearchHybridSearchWeights, type FileSearchOptions, type FileSearchRankingOptions, type FileSearchTool, type ImageGenerationInputMask, type ImageGenerationOptions, type ImageGenerationTool, type LocalShellAction, type LocalShellOptions, type LocalShellTool, type McpApprovalFilter, type McpConnectorId, type McpConnectorOptions, type McpRemoteServerOptions, type McpTool, type McpToolFilter, OpenAIImageModelId, type ShellAction, type ShellCallOutcome, type ShellCommandOutput, type ShellOptions, type ShellResult, type ShellTool, type ToolSearchOptions, type ToolSearchTool, type WebSearchFilters, type WebSearchOptions, type WebSearchTool, tools };
28
27
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/tools/index.ts"],"mappings":";;;;;;;;;;;;;cA8Fa,KAAA"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/tools/index.ts"],"mappings":";;;;;;;;;;;;cA8Fa"}
@@ -1,4 +1,4 @@
1
- import "./dalle.js";
1
+ import { DallEAPIWrapper } from "./dalle.js";
2
2
  import { webSearch } from "./webSearch.js";
3
3
  import { mcp } from "./mcp.js";
4
4
  import { codeInterpreter } from "./codeInterpreter.js";
@@ -23,6 +23,6 @@ const tools = {
23
23
  toolSearch
24
24
  };
25
25
  //#endregion
26
- export { tools };
26
+ export { DallEAPIWrapper, tools };
27
27
 
28
28
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/tools/index.ts"],"sourcesContent":["export * from \"./dalle.js\";\n\nimport { webSearch } from \"./webSearch.js\";\nexport type {\n WebSearchTool,\n WebSearchFilters,\n WebSearchOptions,\n} from \"./webSearch.js\";\n\nimport { mcp } from \"./mcp.js\";\nexport type {\n McpTool,\n McpConnectorId,\n McpToolFilter,\n McpApprovalFilter,\n McpRemoteServerOptions,\n McpConnectorOptions,\n} from \"./mcp.js\";\n\nimport { codeInterpreter } from \"./codeInterpreter.js\";\nexport type {\n CodeInterpreterTool,\n CodeInterpreterOptions,\n CodeInterpreterAutoContainer,\n CodeInterpreterMemoryLimit,\n} from \"./codeInterpreter.js\";\n\nimport { fileSearch } from \"./fileSearch.js\";\nexport type {\n FileSearchTool,\n FileSearchOptions,\n FileSearchFilter,\n FileSearchComparisonFilter,\n FileSearchCompoundFilter,\n FileSearchComparisonType,\n FileSearchRankingOptions,\n FileSearchHybridSearchWeights,\n} from \"./fileSearch.js\";\n\nimport { imageGeneration } from \"./imageGeneration.js\";\nexport type {\n ImageGenerationTool,\n ImageGenerationOptions,\n ImageGenerationInputMask,\n} from \"./imageGeneration.js\";\n\nimport { computerUse } from \"./computerUse.js\";\nexport type {\n ComputerUseTool,\n ComputerUseInput,\n ComputerUseOptions,\n ComputerUseEnvironment,\n ComputerUseAction,\n ComputerUseClickAction,\n ComputerUseDoubleClickAction,\n ComputerUseDragAction,\n ComputerUseKeypressAction,\n ComputerUseMoveAction,\n ComputerUseScreenshotAction,\n ComputerUseScrollAction,\n ComputerUseTypeAction,\n ComputerUseWaitAction,\n} from \"./computerUse.js\";\n\nimport { localShell } from \"./localShell.js\";\nexport type {\n LocalShellTool,\n LocalShellOptions,\n LocalShellAction,\n} from \"./localShell.js\";\n\nimport { shell } from \"./shell.js\";\nexport type {\n ShellTool,\n ShellOptions,\n ShellAction,\n ShellResult,\n ShellCommandOutput,\n ShellCallOutcome,\n} from \"./shell.js\";\n\nimport { applyPatch } from \"./applyPatch.js\";\nexport type {\n ApplyPatchTool,\n ApplyPatchOptions,\n ApplyPatchOperation,\n ApplyPatchCreateFileOperation,\n ApplyPatchUpdateFileOperation,\n ApplyPatchDeleteFileOperation,\n} from \"./applyPatch.js\";\n\nimport { toolSearch } from \"./toolSearch.js\";\nexport type { ToolSearchTool, ToolSearchOptions } from \"./toolSearch.js\";\n\nexport const tools = {\n webSearch,\n mcp,\n codeInterpreter,\n fileSearch,\n imageGeneration,\n computerUse,\n localShell,\n shell,\n applyPatch,\n toolSearch,\n};\n"],"mappings":";;;;;;;;;;;;AA8FA,MAAa,QAAQ;CACnB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/tools/index.ts"],"sourcesContent":["export * from \"./dalle.js\";\n\nimport { webSearch } from \"./webSearch.js\";\nexport type {\n WebSearchTool,\n WebSearchFilters,\n WebSearchOptions,\n} from \"./webSearch.js\";\n\nimport { mcp } from \"./mcp.js\";\nexport type {\n McpTool,\n McpConnectorId,\n McpToolFilter,\n McpApprovalFilter,\n McpRemoteServerOptions,\n McpConnectorOptions,\n} from \"./mcp.js\";\n\nimport { codeInterpreter } from \"./codeInterpreter.js\";\nexport type {\n CodeInterpreterTool,\n CodeInterpreterOptions,\n CodeInterpreterAutoContainer,\n CodeInterpreterMemoryLimit,\n} from \"./codeInterpreter.js\";\n\nimport { fileSearch } from \"./fileSearch.js\";\nexport type {\n FileSearchTool,\n FileSearchOptions,\n FileSearchFilter,\n FileSearchComparisonFilter,\n FileSearchCompoundFilter,\n FileSearchComparisonType,\n FileSearchRankingOptions,\n FileSearchHybridSearchWeights,\n} from \"./fileSearch.js\";\n\nimport { imageGeneration } from \"./imageGeneration.js\";\nexport type {\n ImageGenerationTool,\n ImageGenerationOptions,\n ImageGenerationInputMask,\n} from \"./imageGeneration.js\";\n\nimport { computerUse } from \"./computerUse.js\";\nexport type {\n ComputerUseTool,\n ComputerUseInput,\n ComputerUseOptions,\n ComputerUseEnvironment,\n ComputerUseAction,\n ComputerUseClickAction,\n ComputerUseDoubleClickAction,\n ComputerUseDragAction,\n ComputerUseKeypressAction,\n ComputerUseMoveAction,\n ComputerUseScreenshotAction,\n ComputerUseScrollAction,\n ComputerUseTypeAction,\n ComputerUseWaitAction,\n} from \"./computerUse.js\";\n\nimport { localShell } from \"./localShell.js\";\nexport type {\n LocalShellTool,\n LocalShellOptions,\n LocalShellAction,\n} from \"./localShell.js\";\n\nimport { shell } from \"./shell.js\";\nexport type {\n ShellTool,\n ShellOptions,\n ShellAction,\n ShellResult,\n ShellCommandOutput,\n ShellCallOutcome,\n} from \"./shell.js\";\n\nimport { applyPatch } from \"./applyPatch.js\";\nexport type {\n ApplyPatchTool,\n ApplyPatchOptions,\n ApplyPatchOperation,\n ApplyPatchCreateFileOperation,\n ApplyPatchUpdateFileOperation,\n ApplyPatchDeleteFileOperation,\n} from \"./applyPatch.js\";\n\nimport { toolSearch } from \"./toolSearch.js\";\nexport type { ToolSearchTool, ToolSearchOptions } from \"./toolSearch.js\";\n\nexport const tools = {\n webSearch,\n mcp,\n codeInterpreter,\n fileSearch,\n imageGeneration,\n computerUse,\n localShell,\n shell,\n applyPatch,\n toolSearch,\n};\n"],"mappings":";;;;;;;;;;;;AA8FA,MAAa,QAAQ;CACnB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF"}
@@ -138,6 +138,8 @@ function localShell(options) {
138
138
  return shellTool;
139
139
  }
140
140
  //#endregion
141
+ exports.LocalShellActionSchema = LocalShellActionSchema;
142
+ exports.LocalShellExecActionSchema = LocalShellExecActionSchema;
141
143
  exports.localShell = localShell;
142
144
 
143
145
  //# sourceMappingURL=localShell.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"localShell.cjs","names":["z"],"sources":["../../src/tools/localShell.ts"],"sourcesContent":["import { z } from \"zod/v4\";\nimport { OpenAI as OpenAIClient } from \"openai\";\nimport { tool, type DynamicStructuredTool } from \"@langchain/core/tools\";\n\n/**\n * Re-export action type from OpenAI SDK for convenience.\n * The action contains command details like argv tokens, environment variables,\n * working directory, timeout, and user.\n */\nexport type LocalShellAction =\n OpenAIClient.Responses.ResponseOutputItem.LocalShellCall.Action;\n\n// Zod schema for local shell exec action\nexport const LocalShellExecActionSchema = z.object({\n type: z.literal(\"exec\"),\n command: z.array(z.string()),\n env: z.record(z.string(), z.string()).optional(),\n working_directory: z.string().optional(),\n timeout_ms: z.number().optional(),\n user: z.string().optional(),\n});\n\n// Schema for all local shell actions (currently only exec)\nexport const LocalShellActionSchema = z.union([LocalShellExecActionSchema]);\n\n/**\n * Options for the Local Shell tool.\n */\nexport interface LocalShellOptions {\n /**\n * Optional execute function that handles shell command execution.\n * This function receives the action input and should return the command output\n * (stdout + stderr combined).\n *\n * If not provided, you'll need to handle action execution manually by\n * checking `local_shell_call` outputs in the response.\n *\n * @example\n * ```typescript\n * execute: async (action) => {\n * const result = await exec(action.command.join(' '), {\n * cwd: action.working_directory,\n * env: { ...process.env, ...action.env },\n * timeout: action.timeout_ms,\n * });\n * return result.stdout + result.stderr;\n * }\n * ```\n */\n execute: (action: LocalShellAction) => string | Promise<string>;\n}\n\n/**\n * OpenAI Local Shell tool type for the Responses API.\n */\nexport type LocalShellTool = OpenAIClient.Responses.Tool.LocalShell;\n\nconst TOOL_NAME = \"local_shell\";\n\n/**\n * Creates a Local Shell tool that allows models to run shell commands locally\n * on a machine you provide. Commands are executed inside your own runtime—\n * the API only returns the instructions, but does not execute them on OpenAI infrastructure.\n *\n * **Important**: The local shell tool is designed to work with\n * [Codex CLI](https://github.com/openai/codex) and the `codex-mini-latest` model.\n *\n * **How it works**:\n * The tool operates in a continuous loop:\n * 1. Model sends shell commands (`local_shell_call` with `exec` action)\n * 2. Your code executes the command locally\n * 3. You return the output back to the model\n * 4. Repeat until the task is complete\n *\n * **Security Warning**: Running arbitrary shell commands can be dangerous.\n * Always sandbox execution or add strict allow/deny-lists before forwarding\n * a command to the system shell.\n *\n * @see {@link https://platform.openai.com/docs/guides/tools-local-shell | OpenAI Local Shell Documentation}\n *\n * @param options - Optional configuration for the Local Shell tool\n * @returns A Local Shell tool that can be passed to `bindTools`\n *\n * @example\n * ```typescript\n * import { ChatOpenAI, tools } from \"@langchain/openai\";\n * import { exec } from \"child_process\";\n * import { promisify } from \"util\";\n *\n * const execAsync = promisify(exec);\n * const model = new ChatOpenAI({ model: \"codex-mini-latest\" });\n *\n * // With execute callback for automatic command handling\n * const shell = tools.localShell({\n * execute: async (action) => {\n * const { command, env, working_directory, timeout_ms } = action;\n * const result = await execAsync(command.join(' '), {\n * cwd: working_directory ?? process.cwd(),\n * env: { ...process.env, ...env },\n * timeout: timeout_ms ?? undefined,\n * });\n * return result.stdout + result.stderr;\n * },\n * });\n *\n * const llmWithShell = model.bindTools([shell]);\n * const response = await llmWithShell.invoke(\n * \"List files in the current directory\"\n * );\n * ```\n *\n * @example\n * ```typescript\n * // Without execute callback (manual handling)\n * const shell = tools.localShell();\n *\n * const response = await model.invoke(\"List files\", {\n * tools: [shell],\n * });\n *\n * // Access the shell call from the response\n * const shellCall = response.additional_kwargs.tool_outputs?.find(\n * (output) => output.type === \"local_shell_call\"\n * );\n * if (shellCall) {\n * console.log(\"Command to execute:\", shellCall.action.command);\n * // Execute the command manually, then send back the output\n * }\n * ```\n *\n * @example\n * ```typescript\n * // Full shell loop example\n * async function shellLoop(model, task) {\n * let response = await model.invoke(task, {\n * tools: [tools.localShell()],\n * });\n *\n * while (true) {\n * const shellCall = response.additional_kwargs.tool_outputs?.find(\n * (output) => output.type === \"local_shell_call\"\n * );\n *\n * if (!shellCall) break;\n *\n * // Execute command (with proper sandboxing!)\n * const output = await executeCommand(shellCall.action);\n *\n * // Send output back to model\n * response = await model.invoke([\n * response,\n * {\n * type: \"local_shell_call_output\",\n * id: shellCall.call_id,\n * output: output,\n * },\n * ], {\n * tools: [tools.localShell()],\n * });\n * }\n *\n * return response;\n * }\n * ```\n *\n * @remarks\n * - Only available through the Responses API (not Chat Completions)\n * - Designed for use with `codex-mini-latest` model\n * - Commands are provided as argv tokens in `action.command`\n * - Action includes: `command`, `env`, `working_directory`, `timeout_ms`, `user`\n * - Always sandbox or validate commands before execution\n * - The `timeout_ms` from the model is only a hint—enforce your own limits\n */\nexport function localShell(options: LocalShellOptions) {\n const shellTool = tool(options.execute, {\n name: TOOL_NAME,\n description:\n \"Execute shell commands locally on the machine. Commands are provided as argv tokens.\",\n schema: LocalShellActionSchema,\n });\n\n shellTool.extras = {\n ...(shellTool.extras ?? {}),\n providerToolDefinition: {\n type: \"local_shell\",\n } satisfies LocalShellTool,\n };\n\n return shellTool as DynamicStructuredTool<\n typeof LocalShellActionSchema,\n LocalShellAction,\n unknown,\n string\n >;\n}\n"],"mappings":";;;AAaA,MAAa,6BAA6BA,OAAAA,EAAE,OAAO;CACjD,MAAMA,OAAAA,EAAE,QAAQ,OAAO;CACvB,SAASA,OAAAA,EAAE,MAAMA,OAAAA,EAAE,QAAQ,CAAC;CAC5B,KAAKA,OAAAA,EAAE,OAAOA,OAAAA,EAAE,QAAQ,EAAEA,OAAAA,EAAE,QAAQ,CAAC,CAAC,UAAU;CAChD,mBAAmBA,OAAAA,EAAE,QAAQ,CAAC,UAAU;CACxC,YAAYA,OAAAA,EAAE,QAAQ,CAAC,UAAU;CACjC,MAAMA,OAAAA,EAAE,QAAQ,CAAC,UAAU;CAC5B,CAAC;AAGF,MAAa,yBAAyBA,OAAAA,EAAE,MAAM,CAAC,2BAA2B,CAAC;AAkC3E,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoHlB,SAAgB,WAAW,SAA4B;CACrD,MAAM,aAAA,GAAA,sBAAA,MAAiB,QAAQ,SAAS;EACtC,MAAM;EACN,aACE;EACF,QAAQ;EACT,CAAC;AAEF,WAAU,SAAS;EACjB,GAAI,UAAU,UAAU,EAAE;EAC1B,wBAAwB,EACtB,MAAM,eACP;EACF;AAED,QAAO"}
1
+ {"version":3,"file":"localShell.cjs","names":["z"],"sources":["../../src/tools/localShell.ts"],"sourcesContent":["import { z } from \"zod/v4\";\nimport { OpenAI as OpenAIClient } from \"openai\";\nimport { tool, type DynamicStructuredTool } from \"@langchain/core/tools\";\n\n/**\n * Re-export action type from OpenAI SDK for convenience.\n * The action contains command details like argv tokens, environment variables,\n * working directory, timeout, and user.\n */\nexport type LocalShellAction =\n OpenAIClient.Responses.ResponseOutputItem.LocalShellCall.Action;\n\n// Zod schema for local shell exec action\nexport const LocalShellExecActionSchema = z.object({\n type: z.literal(\"exec\"),\n command: z.array(z.string()),\n env: z.record(z.string(), z.string()).optional(),\n working_directory: z.string().optional(),\n timeout_ms: z.number().optional(),\n user: z.string().optional(),\n});\n\n// Schema for all local shell actions (currently only exec)\nexport const LocalShellActionSchema = z.union([LocalShellExecActionSchema]);\n\n/**\n * Options for the Local Shell tool.\n */\nexport interface LocalShellOptions {\n /**\n * Optional execute function that handles shell command execution.\n * This function receives the action input and should return the command output\n * (stdout + stderr combined).\n *\n * If not provided, you'll need to handle action execution manually by\n * checking `local_shell_call` outputs in the response.\n *\n * @example\n * ```typescript\n * execute: async (action) => {\n * const result = await exec(action.command.join(' '), {\n * cwd: action.working_directory,\n * env: { ...process.env, ...action.env },\n * timeout: action.timeout_ms,\n * });\n * return result.stdout + result.stderr;\n * }\n * ```\n */\n execute: (action: LocalShellAction) => string | Promise<string>;\n}\n\n/**\n * OpenAI Local Shell tool type for the Responses API.\n */\nexport type LocalShellTool = OpenAIClient.Responses.Tool.LocalShell;\n\nconst TOOL_NAME = \"local_shell\";\n\n/**\n * Creates a Local Shell tool that allows models to run shell commands locally\n * on a machine you provide. Commands are executed inside your own runtime—\n * the API only returns the instructions, but does not execute them on OpenAI infrastructure.\n *\n * **Important**: The local shell tool is designed to work with\n * [Codex CLI](https://github.com/openai/codex) and the `codex-mini-latest` model.\n *\n * **How it works**:\n * The tool operates in a continuous loop:\n * 1. Model sends shell commands (`local_shell_call` with `exec` action)\n * 2. Your code executes the command locally\n * 3. You return the output back to the model\n * 4. Repeat until the task is complete\n *\n * **Security Warning**: Running arbitrary shell commands can be dangerous.\n * Always sandbox execution or add strict allow/deny-lists before forwarding\n * a command to the system shell.\n *\n * @see {@link https://platform.openai.com/docs/guides/tools-local-shell | OpenAI Local Shell Documentation}\n *\n * @param options - Optional configuration for the Local Shell tool\n * @returns A Local Shell tool that can be passed to `bindTools`\n *\n * @example\n * ```typescript\n * import { ChatOpenAI, tools } from \"@langchain/openai\";\n * import { exec } from \"child_process\";\n * import { promisify } from \"util\";\n *\n * const execAsync = promisify(exec);\n * const model = new ChatOpenAI({ model: \"codex-mini-latest\" });\n *\n * // With execute callback for automatic command handling\n * const shell = tools.localShell({\n * execute: async (action) => {\n * const { command, env, working_directory, timeout_ms } = action;\n * const result = await execAsync(command.join(' '), {\n * cwd: working_directory ?? process.cwd(),\n * env: { ...process.env, ...env },\n * timeout: timeout_ms ?? undefined,\n * });\n * return result.stdout + result.stderr;\n * },\n * });\n *\n * const llmWithShell = model.bindTools([shell]);\n * const response = await llmWithShell.invoke(\n * \"List files in the current directory\"\n * );\n * ```\n *\n * @example\n * ```typescript\n * // Without execute callback (manual handling)\n * const shell = tools.localShell();\n *\n * const response = await model.invoke(\"List files\", {\n * tools: [shell],\n * });\n *\n * // Access the shell call from the response\n * const shellCall = response.additional_kwargs.tool_outputs?.find(\n * (output) => output.type === \"local_shell_call\"\n * );\n * if (shellCall) {\n * console.log(\"Command to execute:\", shellCall.action.command);\n * // Execute the command manually, then send back the output\n * }\n * ```\n *\n * @example\n * ```typescript\n * // Full shell loop example\n * async function shellLoop(model, task) {\n * let response = await model.invoke(task, {\n * tools: [tools.localShell()],\n * });\n *\n * while (true) {\n * const shellCall = response.additional_kwargs.tool_outputs?.find(\n * (output) => output.type === \"local_shell_call\"\n * );\n *\n * if (!shellCall) break;\n *\n * // Execute command (with proper sandboxing!)\n * const output = await executeCommand(shellCall.action);\n *\n * // Send output back to model\n * response = await model.invoke([\n * response,\n * {\n * type: \"local_shell_call_output\",\n * id: shellCall.call_id,\n * output: output,\n * },\n * ], {\n * tools: [tools.localShell()],\n * });\n * }\n *\n * return response;\n * }\n * ```\n *\n * @remarks\n * - Only available through the Responses API (not Chat Completions)\n * - Designed for use with `codex-mini-latest` model\n * - Commands are provided as argv tokens in `action.command`\n * - Action includes: `command`, `env`, `working_directory`, `timeout_ms`, `user`\n * - Always sandbox or validate commands before execution\n * - The `timeout_ms` from the model is only a hint—enforce your own limits\n */\nexport function localShell(options: LocalShellOptions) {\n const shellTool = tool(options.execute, {\n name: TOOL_NAME,\n description:\n \"Execute shell commands locally on the machine. Commands are provided as argv tokens.\",\n schema: LocalShellActionSchema,\n });\n\n shellTool.extras = {\n ...(shellTool.extras ?? {}),\n providerToolDefinition: {\n type: \"local_shell\",\n } satisfies LocalShellTool,\n };\n\n return shellTool as DynamicStructuredTool<\n typeof LocalShellActionSchema,\n LocalShellAction,\n unknown,\n string\n >;\n}\n"],"mappings":";;;AAaA,MAAa,6BAA6BA,OAAAA,EAAE,OAAO;CACjD,MAAMA,OAAAA,EAAE,QAAQ,MAAM;CACtB,SAASA,OAAAA,EAAE,MAAMA,OAAAA,EAAE,OAAO,CAAC;CAC3B,KAAKA,OAAAA,EAAE,OAAOA,OAAAA,EAAE,OAAO,GAAGA,OAAAA,EAAE,OAAO,CAAC,CAAC,CAAC,SAAS;CAC/C,mBAAmBA,OAAAA,EAAE,OAAO,CAAC,CAAC,SAAS;CACvC,YAAYA,OAAAA,EAAE,OAAO,CAAC,CAAC,SAAS;CAChC,MAAMA,OAAAA,EAAE,OAAO,CAAC,CAAC,SAAS;AAC5B,CAAC;AAGD,MAAa,yBAAyBA,OAAAA,EAAE,MAAM,CAAC,0BAA0B,CAAC;AAkC1E,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoHlB,SAAgB,WAAW,SAA4B;CACrD,MAAM,aAAA,GAAA,sBAAA,KAAA,CAAiB,QAAQ,SAAS;EACtC,MAAM;EACN,aACE;EACF,QAAQ;CACV,CAAC;CAED,UAAU,SAAS;EACjB,GAAI,UAAU,UAAU,CAAC;EACzB,wBAAwB,EACtB,MAAM,cACR;CACF;CAEA,OAAO;AAMT"}
@@ -1,7 +1,6 @@
1
1
  import { OpenAI } from "openai";
2
2
  import { DynamicStructuredTool } from "@langchain/core/tools";
3
3
  import { z } from "zod/v4";
4
-
5
4
  //#region src/tools/localShell.d.ts
6
5
  /**
7
6
  * Re-export action type from OpenAI SDK for convenience.
@@ -163,5 +162,5 @@ type LocalShellTool = OpenAI.Responses.Tool.LocalShell;
163
162
  */
164
163
  declare function localShell(options: LocalShellOptions): DynamicStructuredTool<typeof LocalShellActionSchema, LocalShellAction, unknown, string>;
165
164
  //#endregion
166
- export { LocalShellAction, LocalShellOptions, LocalShellTool, localShell };
165
+ export { LocalShellAction, LocalShellActionSchema, LocalShellOptions, LocalShellTool, localShell };
167
166
  //# sourceMappingURL=localShell.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"localShell.d.cts","names":[],"sources":["../../src/tools/localShell.ts"],"mappings":";;;;;;;AASA;;;KAAY,gBAAA,GACV,MAAA,CAAa,SAAA,CAAU,kBAAA,CAAmB,cAAA,CAAe,MAAA;AAAA,cAa9C,sBAAA,EAAsB,CAAA,CAAA,QAAA,WAAA,CAAA,CAAA,SAAA;;;;;;;;;;;UAKlB,iBAAA;;;;;;;;;;;;;;;;;;;;;EAqBf,OAAA,GAAU,MAAA,EAAQ,gBAAA,cAA8B,OAAA;AAAA;;;;KAMtC,cAAA,GAAiB,MAAA,CAAa,SAAA,CAAU,IAAA,CAAK,UAAA;;;;;;;;;;;;;;;;;;;;;;;;AA3BzD;;;;;;;;;;AA2BA;;;;;;;;;;AAsHA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAgB,UAAA,CAAW,OAAA,EAAS,iBAAA,GAed,qBAAA,QACX,sBAAA,EACP,gBAAA"}
1
+ {"version":3,"file":"localShell.d.cts","names":[],"sources":["../../src/tools/localShell.ts"],"mappings":";;;;;;;;;KASY,mBACV,OAAa,UAAU,mBAAmB,eAAe;cAa9C,wBAAsB,EAAA,mBAAA,EAAA;;;;;;;GAAwC,EAAA,KAAA;;;;UAK1D;;;;;;;;;;;;;;;;;;;;;EAqBf,UAAU,QAAQ,8BAA8B;;;;;KAMtC,iBAAiB,OAAa,UAAU,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAsHzC,WAAW,SAAS,oBAed,6BACX,wBACP"}
@@ -1,7 +1,6 @@
1
1
  import { OpenAI } from "openai";
2
2
  import { DynamicStructuredTool } from "@langchain/core/tools";
3
3
  import { z } from "zod/v4";
4
-
5
4
  //#region src/tools/localShell.d.ts
6
5
  /**
7
6
  * Re-export action type from OpenAI SDK for convenience.
@@ -163,5 +162,5 @@ type LocalShellTool = OpenAI.Responses.Tool.LocalShell;
163
162
  */
164
163
  declare function localShell(options: LocalShellOptions): DynamicStructuredTool<typeof LocalShellActionSchema, LocalShellAction, unknown, string>;
165
164
  //#endregion
166
- export { LocalShellAction, LocalShellOptions, LocalShellTool, localShell };
165
+ export { LocalShellAction, LocalShellActionSchema, LocalShellOptions, LocalShellTool, localShell };
167
166
  //# sourceMappingURL=localShell.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"localShell.d.ts","names":[],"sources":["../../src/tools/localShell.ts"],"mappings":";;;;;;;AASA;;;KAAY,gBAAA,GACV,MAAA,CAAa,SAAA,CAAU,kBAAA,CAAmB,cAAA,CAAe,MAAA;AAAA,cAa9C,sBAAA,EAAsB,CAAA,CAAA,QAAA,WAAA,CAAA,CAAA,SAAA;;;;;;;;;;;UAKlB,iBAAA;;;;;;;;;;;;;;;;;;;;;EAqBf,OAAA,GAAU,MAAA,EAAQ,gBAAA,cAA8B,OAAA;AAAA;;;;KAMtC,cAAA,GAAiB,MAAA,CAAa,SAAA,CAAU,IAAA,CAAK,UAAA;;;;;;;;;;;;;;;;;;;;;;;;AA3BzD;;;;;;;;;;AA2BA;;;;;;;;;;AAsHA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAgB,UAAA,CAAW,OAAA,EAAS,iBAAA,GAed,qBAAA,QACX,sBAAA,EACP,gBAAA"}
1
+ {"version":3,"file":"localShell.d.ts","names":[],"sources":["../../src/tools/localShell.ts"],"mappings":";;;;;;;;;KASY,mBACV,OAAa,UAAU,mBAAmB,eAAe;cAa9C,wBAAsB,EAAA,mBAAA,EAAA;;;;;;;GAAwC,EAAA,KAAA;;;;UAK1D;;;;;;;;;;;;;;;;;;;;;EAqBf,UAAU,QAAQ,8BAA8B;;;;;KAMtC,iBAAiB,OAAa,UAAU,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAsHzC,WAAW,SAAS,oBAed,6BACX,wBACP"}
@@ -138,6 +138,6 @@ function localShell(options) {
138
138
  return shellTool;
139
139
  }
140
140
  //#endregion
141
- export { localShell };
141
+ export { LocalShellActionSchema, LocalShellExecActionSchema, localShell };
142
142
 
143
143
  //# sourceMappingURL=localShell.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"localShell.js","names":[],"sources":["../../src/tools/localShell.ts"],"sourcesContent":["import { z } from \"zod/v4\";\nimport { OpenAI as OpenAIClient } from \"openai\";\nimport { tool, type DynamicStructuredTool } from \"@langchain/core/tools\";\n\n/**\n * Re-export action type from OpenAI SDK for convenience.\n * The action contains command details like argv tokens, environment variables,\n * working directory, timeout, and user.\n */\nexport type LocalShellAction =\n OpenAIClient.Responses.ResponseOutputItem.LocalShellCall.Action;\n\n// Zod schema for local shell exec action\nexport const LocalShellExecActionSchema = z.object({\n type: z.literal(\"exec\"),\n command: z.array(z.string()),\n env: z.record(z.string(), z.string()).optional(),\n working_directory: z.string().optional(),\n timeout_ms: z.number().optional(),\n user: z.string().optional(),\n});\n\n// Schema for all local shell actions (currently only exec)\nexport const LocalShellActionSchema = z.union([LocalShellExecActionSchema]);\n\n/**\n * Options for the Local Shell tool.\n */\nexport interface LocalShellOptions {\n /**\n * Optional execute function that handles shell command execution.\n * This function receives the action input and should return the command output\n * (stdout + stderr combined).\n *\n * If not provided, you'll need to handle action execution manually by\n * checking `local_shell_call` outputs in the response.\n *\n * @example\n * ```typescript\n * execute: async (action) => {\n * const result = await exec(action.command.join(' '), {\n * cwd: action.working_directory,\n * env: { ...process.env, ...action.env },\n * timeout: action.timeout_ms,\n * });\n * return result.stdout + result.stderr;\n * }\n * ```\n */\n execute: (action: LocalShellAction) => string | Promise<string>;\n}\n\n/**\n * OpenAI Local Shell tool type for the Responses API.\n */\nexport type LocalShellTool = OpenAIClient.Responses.Tool.LocalShell;\n\nconst TOOL_NAME = \"local_shell\";\n\n/**\n * Creates a Local Shell tool that allows models to run shell commands locally\n * on a machine you provide. Commands are executed inside your own runtime—\n * the API only returns the instructions, but does not execute them on OpenAI infrastructure.\n *\n * **Important**: The local shell tool is designed to work with\n * [Codex CLI](https://github.com/openai/codex) and the `codex-mini-latest` model.\n *\n * **How it works**:\n * The tool operates in a continuous loop:\n * 1. Model sends shell commands (`local_shell_call` with `exec` action)\n * 2. Your code executes the command locally\n * 3. You return the output back to the model\n * 4. Repeat until the task is complete\n *\n * **Security Warning**: Running arbitrary shell commands can be dangerous.\n * Always sandbox execution or add strict allow/deny-lists before forwarding\n * a command to the system shell.\n *\n * @see {@link https://platform.openai.com/docs/guides/tools-local-shell | OpenAI Local Shell Documentation}\n *\n * @param options - Optional configuration for the Local Shell tool\n * @returns A Local Shell tool that can be passed to `bindTools`\n *\n * @example\n * ```typescript\n * import { ChatOpenAI, tools } from \"@langchain/openai\";\n * import { exec } from \"child_process\";\n * import { promisify } from \"util\";\n *\n * const execAsync = promisify(exec);\n * const model = new ChatOpenAI({ model: \"codex-mini-latest\" });\n *\n * // With execute callback for automatic command handling\n * const shell = tools.localShell({\n * execute: async (action) => {\n * const { command, env, working_directory, timeout_ms } = action;\n * const result = await execAsync(command.join(' '), {\n * cwd: working_directory ?? process.cwd(),\n * env: { ...process.env, ...env },\n * timeout: timeout_ms ?? undefined,\n * });\n * return result.stdout + result.stderr;\n * },\n * });\n *\n * const llmWithShell = model.bindTools([shell]);\n * const response = await llmWithShell.invoke(\n * \"List files in the current directory\"\n * );\n * ```\n *\n * @example\n * ```typescript\n * // Without execute callback (manual handling)\n * const shell = tools.localShell();\n *\n * const response = await model.invoke(\"List files\", {\n * tools: [shell],\n * });\n *\n * // Access the shell call from the response\n * const shellCall = response.additional_kwargs.tool_outputs?.find(\n * (output) => output.type === \"local_shell_call\"\n * );\n * if (shellCall) {\n * console.log(\"Command to execute:\", shellCall.action.command);\n * // Execute the command manually, then send back the output\n * }\n * ```\n *\n * @example\n * ```typescript\n * // Full shell loop example\n * async function shellLoop(model, task) {\n * let response = await model.invoke(task, {\n * tools: [tools.localShell()],\n * });\n *\n * while (true) {\n * const shellCall = response.additional_kwargs.tool_outputs?.find(\n * (output) => output.type === \"local_shell_call\"\n * );\n *\n * if (!shellCall) break;\n *\n * // Execute command (with proper sandboxing!)\n * const output = await executeCommand(shellCall.action);\n *\n * // Send output back to model\n * response = await model.invoke([\n * response,\n * {\n * type: \"local_shell_call_output\",\n * id: shellCall.call_id,\n * output: output,\n * },\n * ], {\n * tools: [tools.localShell()],\n * });\n * }\n *\n * return response;\n * }\n * ```\n *\n * @remarks\n * - Only available through the Responses API (not Chat Completions)\n * - Designed for use with `codex-mini-latest` model\n * - Commands are provided as argv tokens in `action.command`\n * - Action includes: `command`, `env`, `working_directory`, `timeout_ms`, `user`\n * - Always sandbox or validate commands before execution\n * - The `timeout_ms` from the model is only a hint—enforce your own limits\n */\nexport function localShell(options: LocalShellOptions) {\n const shellTool = tool(options.execute, {\n name: TOOL_NAME,\n description:\n \"Execute shell commands locally on the machine. Commands are provided as argv tokens.\",\n schema: LocalShellActionSchema,\n });\n\n shellTool.extras = {\n ...(shellTool.extras ?? {}),\n providerToolDefinition: {\n type: \"local_shell\",\n } satisfies LocalShellTool,\n };\n\n return shellTool as DynamicStructuredTool<\n typeof LocalShellActionSchema,\n LocalShellAction,\n unknown,\n string\n >;\n}\n"],"mappings":";;;AAaA,MAAa,6BAA6B,EAAE,OAAO;CACjD,MAAM,EAAE,QAAQ,OAAO;CACvB,SAAS,EAAE,MAAM,EAAE,QAAQ,CAAC;CAC5B,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,QAAQ,CAAC,CAAC,UAAU;CAChD,mBAAmB,EAAE,QAAQ,CAAC,UAAU;CACxC,YAAY,EAAE,QAAQ,CAAC,UAAU;CACjC,MAAM,EAAE,QAAQ,CAAC,UAAU;CAC5B,CAAC;AAGF,MAAa,yBAAyB,EAAE,MAAM,CAAC,2BAA2B,CAAC;AAkC3E,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoHlB,SAAgB,WAAW,SAA4B;CACrD,MAAM,YAAY,KAAK,QAAQ,SAAS;EACtC,MAAM;EACN,aACE;EACF,QAAQ;EACT,CAAC;AAEF,WAAU,SAAS;EACjB,GAAI,UAAU,UAAU,EAAE;EAC1B,wBAAwB,EACtB,MAAM,eACP;EACF;AAED,QAAO"}
1
+ {"version":3,"file":"localShell.js","names":[],"sources":["../../src/tools/localShell.ts"],"sourcesContent":["import { z } from \"zod/v4\";\nimport { OpenAI as OpenAIClient } from \"openai\";\nimport { tool, type DynamicStructuredTool } from \"@langchain/core/tools\";\n\n/**\n * Re-export action type from OpenAI SDK for convenience.\n * The action contains command details like argv tokens, environment variables,\n * working directory, timeout, and user.\n */\nexport type LocalShellAction =\n OpenAIClient.Responses.ResponseOutputItem.LocalShellCall.Action;\n\n// Zod schema for local shell exec action\nexport const LocalShellExecActionSchema = z.object({\n type: z.literal(\"exec\"),\n command: z.array(z.string()),\n env: z.record(z.string(), z.string()).optional(),\n working_directory: z.string().optional(),\n timeout_ms: z.number().optional(),\n user: z.string().optional(),\n});\n\n// Schema for all local shell actions (currently only exec)\nexport const LocalShellActionSchema = z.union([LocalShellExecActionSchema]);\n\n/**\n * Options for the Local Shell tool.\n */\nexport interface LocalShellOptions {\n /**\n * Optional execute function that handles shell command execution.\n * This function receives the action input and should return the command output\n * (stdout + stderr combined).\n *\n * If not provided, you'll need to handle action execution manually by\n * checking `local_shell_call` outputs in the response.\n *\n * @example\n * ```typescript\n * execute: async (action) => {\n * const result = await exec(action.command.join(' '), {\n * cwd: action.working_directory,\n * env: { ...process.env, ...action.env },\n * timeout: action.timeout_ms,\n * });\n * return result.stdout + result.stderr;\n * }\n * ```\n */\n execute: (action: LocalShellAction) => string | Promise<string>;\n}\n\n/**\n * OpenAI Local Shell tool type for the Responses API.\n */\nexport type LocalShellTool = OpenAIClient.Responses.Tool.LocalShell;\n\nconst TOOL_NAME = \"local_shell\";\n\n/**\n * Creates a Local Shell tool that allows models to run shell commands locally\n * on a machine you provide. Commands are executed inside your own runtime—\n * the API only returns the instructions, but does not execute them on OpenAI infrastructure.\n *\n * **Important**: The local shell tool is designed to work with\n * [Codex CLI](https://github.com/openai/codex) and the `codex-mini-latest` model.\n *\n * **How it works**:\n * The tool operates in a continuous loop:\n * 1. Model sends shell commands (`local_shell_call` with `exec` action)\n * 2. Your code executes the command locally\n * 3. You return the output back to the model\n * 4. Repeat until the task is complete\n *\n * **Security Warning**: Running arbitrary shell commands can be dangerous.\n * Always sandbox execution or add strict allow/deny-lists before forwarding\n * a command to the system shell.\n *\n * @see {@link https://platform.openai.com/docs/guides/tools-local-shell | OpenAI Local Shell Documentation}\n *\n * @param options - Optional configuration for the Local Shell tool\n * @returns A Local Shell tool that can be passed to `bindTools`\n *\n * @example\n * ```typescript\n * import { ChatOpenAI, tools } from \"@langchain/openai\";\n * import { exec } from \"child_process\";\n * import { promisify } from \"util\";\n *\n * const execAsync = promisify(exec);\n * const model = new ChatOpenAI({ model: \"codex-mini-latest\" });\n *\n * // With execute callback for automatic command handling\n * const shell = tools.localShell({\n * execute: async (action) => {\n * const { command, env, working_directory, timeout_ms } = action;\n * const result = await execAsync(command.join(' '), {\n * cwd: working_directory ?? process.cwd(),\n * env: { ...process.env, ...env },\n * timeout: timeout_ms ?? undefined,\n * });\n * return result.stdout + result.stderr;\n * },\n * });\n *\n * const llmWithShell = model.bindTools([shell]);\n * const response = await llmWithShell.invoke(\n * \"List files in the current directory\"\n * );\n * ```\n *\n * @example\n * ```typescript\n * // Without execute callback (manual handling)\n * const shell = tools.localShell();\n *\n * const response = await model.invoke(\"List files\", {\n * tools: [shell],\n * });\n *\n * // Access the shell call from the response\n * const shellCall = response.additional_kwargs.tool_outputs?.find(\n * (output) => output.type === \"local_shell_call\"\n * );\n * if (shellCall) {\n * console.log(\"Command to execute:\", shellCall.action.command);\n * // Execute the command manually, then send back the output\n * }\n * ```\n *\n * @example\n * ```typescript\n * // Full shell loop example\n * async function shellLoop(model, task) {\n * let response = await model.invoke(task, {\n * tools: [tools.localShell()],\n * });\n *\n * while (true) {\n * const shellCall = response.additional_kwargs.tool_outputs?.find(\n * (output) => output.type === \"local_shell_call\"\n * );\n *\n * if (!shellCall) break;\n *\n * // Execute command (with proper sandboxing!)\n * const output = await executeCommand(shellCall.action);\n *\n * // Send output back to model\n * response = await model.invoke([\n * response,\n * {\n * type: \"local_shell_call_output\",\n * id: shellCall.call_id,\n * output: output,\n * },\n * ], {\n * tools: [tools.localShell()],\n * });\n * }\n *\n * return response;\n * }\n * ```\n *\n * @remarks\n * - Only available through the Responses API (not Chat Completions)\n * - Designed for use with `codex-mini-latest` model\n * - Commands are provided as argv tokens in `action.command`\n * - Action includes: `command`, `env`, `working_directory`, `timeout_ms`, `user`\n * - Always sandbox or validate commands before execution\n * - The `timeout_ms` from the model is only a hint—enforce your own limits\n */\nexport function localShell(options: LocalShellOptions) {\n const shellTool = tool(options.execute, {\n name: TOOL_NAME,\n description:\n \"Execute shell commands locally on the machine. Commands are provided as argv tokens.\",\n schema: LocalShellActionSchema,\n });\n\n shellTool.extras = {\n ...(shellTool.extras ?? {}),\n providerToolDefinition: {\n type: \"local_shell\",\n } satisfies LocalShellTool,\n };\n\n return shellTool as DynamicStructuredTool<\n typeof LocalShellActionSchema,\n LocalShellAction,\n unknown,\n string\n >;\n}\n"],"mappings":";;;AAaA,MAAa,6BAA6B,EAAE,OAAO;CACjD,MAAM,EAAE,QAAQ,MAAM;CACtB,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC;CAC3B,KAAK,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,SAAS;CAC/C,mBAAmB,EAAE,OAAO,CAAC,CAAC,SAAS;CACvC,YAAY,EAAE,OAAO,CAAC,CAAC,SAAS;CAChC,MAAM,EAAE,OAAO,CAAC,CAAC,SAAS;AAC5B,CAAC;AAGD,MAAa,yBAAyB,EAAE,MAAM,CAAC,0BAA0B,CAAC;AAkC1E,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoHlB,SAAgB,WAAW,SAA4B;CACrD,MAAM,YAAY,KAAK,QAAQ,SAAS;EACtC,MAAM;EACN,aACE;EACF,QAAQ;CACV,CAAC;CAED,UAAU,SAAS;EACjB,GAAI,UAAU,UAAU,CAAC;EACzB,wBAAwB,EACtB,MAAM,cACR;CACF;CAEA,OAAO;AAMT"}
@@ -1 +1 @@
1
- {"version":3,"file":"mcp.cjs","names":[],"sources":["../../src/tools/mcp.ts"],"sourcesContent":["import { OpenAI as OpenAIClient } from \"openai\";\nimport type { ServerTool } from \"@langchain/core/tools\";\n\n/**\n * Available connector IDs for OpenAI's built-in service connectors.\n * These are OpenAI-maintained MCP wrappers for popular services.\n */\nexport type McpConnectorId =\n | \"connector_dropbox\"\n | \"connector_gmail\"\n | \"connector_googlecalendar\"\n | \"connector_googledrive\"\n | \"connector_microsoftteams\"\n | \"connector_outlookcalendar\"\n | \"connector_outlookemail\"\n | \"connector_sharepoint\";\n\n/**\n * Filter object to specify which tools are allowed.\n */\nexport interface McpToolFilter {\n /**\n * List of allowed tool names.\n */\n toolNames?: string[];\n /**\n * Indicates whether or not a tool modifies data or is read-only.\n * If an MCP server is annotated with `readOnlyHint`, it will match this filter.\n */\n readOnly?: boolean;\n}\n\n/**\n * Filter object for approval requirements.\n */\nexport interface McpApprovalFilter {\n /**\n * Tools that always require approval before execution.\n */\n always?: McpToolFilter;\n /**\n * Tools that never require approval.\n */\n never?: McpToolFilter;\n}\n\n/**\n * Base options shared between remote MCP servers and connectors.\n */\ninterface McpBaseOptions {\n /**\n * A label for this MCP server, used to identify it in tool calls.\n */\n serverLabel: string;\n /**\n * List of allowed tool names or a filter object.\n * Use this to limit which tools from the MCP server are available to the model.\n */\n allowedTools?: string[] | McpToolFilter;\n /**\n * An OAuth access token for authentication with the MCP server.\n * Your application must handle the OAuth authorization flow and provide the token here.\n */\n authorization?: string;\n /**\n * Optional HTTP headers to send to the MCP server.\n * Use for authentication or other purposes.\n */\n headers?: Record<string, string>;\n /**\n * Specify which of the MCP server's tools require approval before execution.\n * - `\"always\"`: All tools require approval\n * - `\"never\"`: No tools require approval\n * - `McpApprovalFilter`: Fine-grained control over which tools require approval\n *\n * @default \"always\" (approval required for all tools)\n */\n requireApproval?: \"always\" | \"never\" | McpApprovalFilter;\n /**\n * Optional description of the MCP server, used to provide more context to the model.\n */\n serverDescription?: string;\n}\n\n/**\n * Options for connecting to a remote MCP server via URL.\n */\nexport interface McpRemoteServerOptions extends McpBaseOptions {\n /**\n * The URL for the MCP server.\n * The server must implement the Streamable HTTP or HTTP/SSE transport protocol.\n */\n serverUrl: string;\n}\n\n/**\n * Options for connecting to an OpenAI-maintained service connector.\n */\nexport interface McpConnectorOptions extends McpBaseOptions {\n /**\n * Identifier for the service connector.\n * These are OpenAI-maintained MCP wrappers for popular services.\n *\n * Available connectors:\n * - `connector_dropbox`: Dropbox file access\n * - `connector_gmail`: Gmail email access\n * - `connector_googlecalendar`: Google Calendar access\n * - `connector_googledrive`: Google Drive file access\n * - `connector_microsoftteams`: Microsoft Teams access\n * - `connector_outlookcalendar`: Outlook Calendar access\n * - `connector_outlookemail`: Outlook Email access\n * - `connector_sharepoint`: SharePoint file access\n */\n connectorId: McpConnectorId;\n}\n\n/**\n * OpenAI MCP tool type for the Responses API.\n */\nexport type McpTool = OpenAIClient.Responses.Tool.Mcp;\n\n/**\n * Converts a McpToolFilter to the API format.\n */\nfunction convertToolFilter(\n filter: McpToolFilter\n): OpenAIClient.Responses.Tool.Mcp.McpToolFilter {\n return {\n tool_names: filter.toolNames,\n read_only: filter.readOnly,\n };\n}\n\n/**\n * Converts allowed_tools option to API format.\n */\nfunction convertAllowedTools(\n allowedTools: string[] | McpToolFilter | undefined\n): Array<string> | OpenAIClient.Responses.Tool.Mcp.McpToolFilter | undefined {\n if (!allowedTools) return undefined;\n if (Array.isArray(allowedTools)) return allowedTools;\n return convertToolFilter(allowedTools);\n}\n\n/**\n * Converts require_approval option to API format.\n */\nfunction convertRequireApproval(\n requireApproval: \"always\" | \"never\" | McpApprovalFilter | undefined\n):\n | OpenAIClient.Responses.Tool.Mcp.McpToolApprovalFilter\n | \"always\"\n | \"never\"\n | undefined {\n if (!requireApproval) return undefined;\n if (typeof requireApproval === \"string\") return requireApproval;\n return {\n always: requireApproval.always\n ? convertToolFilter(requireApproval.always)\n : undefined,\n never: requireApproval.never\n ? convertToolFilter(requireApproval.never)\n : undefined,\n };\n}\n\n/**\n * Creates an MCP tool that connects to a remote MCP server or OpenAI service connector.\n * This allows OpenAI models to access external tools and services via the Model Context Protocol.\n *\n * There are two ways to use MCP tools:\n * 1. **Remote MCP servers**: Connect to any server on the public Internet that implements\n * the MCP protocol using `serverUrl`.\n * 2. **Connectors**: Use OpenAI-maintained MCP wrappers for popular services like\n * Google Workspace or Dropbox using `connectorId`.\n *\n * @see {@link https://platform.openai.com/docs/guides/tools-remote-mcp | OpenAI MCP Documentation}\n *\n * @param options - Configuration options for the MCP tool\n * @returns An MCP tool definition to be passed to the OpenAI Responses API\n *\n * @example\n * ```typescript\n * import { ChatOpenAI, tools } from \"@langchain/openai\";\n *\n * const model = new ChatOpenAI({ model: \"gpt-4o\" });\n *\n * // Using a remote MCP server\n * const response = await model.invoke(\"Roll 2d4+1\", {\n * tools: [tools.mcp({\n * serverLabel: \"dmcp\",\n * serverDescription: \"A D&D MCP server for dice rolling\",\n * serverUrl: \"https://dmcp-server.deno.dev/sse\",\n * requireApproval: \"never\",\n * })],\n * });\n *\n * // Using a connector (e.g., Google Calendar)\n * const calendarResponse = await model.invoke(\"What's on my calendar today?\", {\n * tools: [tools.mcp({\n * serverLabel: \"google_calendar\",\n * connectorId: \"connector_googlecalendar\",\n * authorization: \"<oauth-access-token>\",\n * requireApproval: \"never\",\n * })],\n * });\n *\n * // With tool filtering - only allow specific tools\n * const filteredResponse = await model.invoke(\"Roll some dice\", {\n * tools: [tools.mcp({\n * serverLabel: \"dmcp\",\n * serverUrl: \"https://dmcp-server.deno.dev/sse\",\n * allowedTools: [\"roll\"], // Only allow the \"roll\" tool\n * requireApproval: \"never\",\n * })],\n * });\n *\n * // With fine-grained approval control\n * const controlledResponse = await model.invoke(\"Search and modify files\", {\n * tools: [tools.mcp({\n * serverLabel: \"deepwiki\",\n * serverUrl: \"https://mcp.deepwiki.com/mcp\",\n * requireApproval: {\n * never: { toolNames: [\"ask_question\", \"read_wiki_structure\"] },\n * // All other tools will require approval\n * },\n * })],\n * });\n * ```\n */\nexport function mcp(options: McpRemoteServerOptions): ServerTool;\nexport function mcp(options: McpConnectorOptions): ServerTool;\nexport function mcp(\n options: McpRemoteServerOptions | McpConnectorOptions\n): ServerTool {\n const baseConfig: McpTool = {\n type: \"mcp\",\n server_label: options.serverLabel,\n allowed_tools: convertAllowedTools(options.allowedTools),\n authorization: options.authorization,\n headers: options.headers,\n require_approval: convertRequireApproval(options.requireApproval),\n server_description: options.serverDescription,\n };\n\n if (\"serverUrl\" in options) {\n return {\n ...baseConfig,\n server_url: options.serverUrl,\n } satisfies McpTool;\n }\n\n return {\n ...baseConfig,\n connector_id: options.connectorId,\n } satisfies McpTool;\n}\n"],"mappings":";;;;AA4HA,SAAS,kBACP,QAC+C;AAC/C,QAAO;EACL,YAAY,OAAO;EACnB,WAAW,OAAO;EACnB;;;;;AAMH,SAAS,oBACP,cAC2E;AAC3E,KAAI,CAAC,aAAc,QAAO,KAAA;AAC1B,KAAI,MAAM,QAAQ,aAAa,CAAE,QAAO;AACxC,QAAO,kBAAkB,aAAa;;;;;AAMxC,SAAS,uBACP,iBAKY;AACZ,KAAI,CAAC,gBAAiB,QAAO,KAAA;AAC7B,KAAI,OAAO,oBAAoB,SAAU,QAAO;AAChD,QAAO;EACL,QAAQ,gBAAgB,SACpB,kBAAkB,gBAAgB,OAAO,GACzC,KAAA;EACJ,OAAO,gBAAgB,QACnB,kBAAkB,gBAAgB,MAAM,GACxC,KAAA;EACL;;AAqEH,SAAgB,IACd,SACY;CACZ,MAAM,aAAsB;EAC1B,MAAM;EACN,cAAc,QAAQ;EACtB,eAAe,oBAAoB,QAAQ,aAAa;EACxD,eAAe,QAAQ;EACvB,SAAS,QAAQ;EACjB,kBAAkB,uBAAuB,QAAQ,gBAAgB;EACjE,oBAAoB,QAAQ;EAC7B;AAED,KAAI,eAAe,QACjB,QAAO;EACL,GAAG;EACH,YAAY,QAAQ;EACrB;AAGH,QAAO;EACL,GAAG;EACH,cAAc,QAAQ;EACvB"}
1
+ {"version":3,"file":"mcp.cjs","names":[],"sources":["../../src/tools/mcp.ts"],"sourcesContent":["import { OpenAI as OpenAIClient } from \"openai\";\nimport type { ServerTool } from \"@langchain/core/tools\";\n\n/**\n * Available connector IDs for OpenAI's built-in service connectors.\n * These are OpenAI-maintained MCP wrappers for popular services.\n */\nexport type McpConnectorId =\n | \"connector_dropbox\"\n | \"connector_gmail\"\n | \"connector_googlecalendar\"\n | \"connector_googledrive\"\n | \"connector_microsoftteams\"\n | \"connector_outlookcalendar\"\n | \"connector_outlookemail\"\n | \"connector_sharepoint\";\n\n/**\n * Filter object to specify which tools are allowed.\n */\nexport interface McpToolFilter {\n /**\n * List of allowed tool names.\n */\n toolNames?: string[];\n /**\n * Indicates whether or not a tool modifies data or is read-only.\n * If an MCP server is annotated with `readOnlyHint`, it will match this filter.\n */\n readOnly?: boolean;\n}\n\n/**\n * Filter object for approval requirements.\n */\nexport interface McpApprovalFilter {\n /**\n * Tools that always require approval before execution.\n */\n always?: McpToolFilter;\n /**\n * Tools that never require approval.\n */\n never?: McpToolFilter;\n}\n\n/**\n * Base options shared between remote MCP servers and connectors.\n */\ninterface McpBaseOptions {\n /**\n * A label for this MCP server, used to identify it in tool calls.\n */\n serverLabel: string;\n /**\n * List of allowed tool names or a filter object.\n * Use this to limit which tools from the MCP server are available to the model.\n */\n allowedTools?: string[] | McpToolFilter;\n /**\n * An OAuth access token for authentication with the MCP server.\n * Your application must handle the OAuth authorization flow and provide the token here.\n */\n authorization?: string;\n /**\n * Optional HTTP headers to send to the MCP server.\n * Use for authentication or other purposes.\n */\n headers?: Record<string, string>;\n /**\n * Specify which of the MCP server's tools require approval before execution.\n * - `\"always\"`: All tools require approval\n * - `\"never\"`: No tools require approval\n * - `McpApprovalFilter`: Fine-grained control over which tools require approval\n *\n * @default \"always\" (approval required for all tools)\n */\n requireApproval?: \"always\" | \"never\" | McpApprovalFilter;\n /**\n * Optional description of the MCP server, used to provide more context to the model.\n */\n serverDescription?: string;\n}\n\n/**\n * Options for connecting to a remote MCP server via URL.\n */\nexport interface McpRemoteServerOptions extends McpBaseOptions {\n /**\n * The URL for the MCP server.\n * The server must implement the Streamable HTTP or HTTP/SSE transport protocol.\n */\n serverUrl: string;\n}\n\n/**\n * Options for connecting to an OpenAI-maintained service connector.\n */\nexport interface McpConnectorOptions extends McpBaseOptions {\n /**\n * Identifier for the service connector.\n * These are OpenAI-maintained MCP wrappers for popular services.\n *\n * Available connectors:\n * - `connector_dropbox`: Dropbox file access\n * - `connector_gmail`: Gmail email access\n * - `connector_googlecalendar`: Google Calendar access\n * - `connector_googledrive`: Google Drive file access\n * - `connector_microsoftteams`: Microsoft Teams access\n * - `connector_outlookcalendar`: Outlook Calendar access\n * - `connector_outlookemail`: Outlook Email access\n * - `connector_sharepoint`: SharePoint file access\n */\n connectorId: McpConnectorId;\n}\n\n/**\n * OpenAI MCP tool type for the Responses API.\n */\nexport type McpTool = OpenAIClient.Responses.Tool.Mcp;\n\n/**\n * Converts a McpToolFilter to the API format.\n */\nfunction convertToolFilter(\n filter: McpToolFilter\n): OpenAIClient.Responses.Tool.Mcp.McpToolFilter {\n return {\n tool_names: filter.toolNames,\n read_only: filter.readOnly,\n };\n}\n\n/**\n * Converts allowed_tools option to API format.\n */\nfunction convertAllowedTools(\n allowedTools: string[] | McpToolFilter | undefined\n): Array<string> | OpenAIClient.Responses.Tool.Mcp.McpToolFilter | undefined {\n if (!allowedTools) return undefined;\n if (Array.isArray(allowedTools)) return allowedTools;\n return convertToolFilter(allowedTools);\n}\n\n/**\n * Converts require_approval option to API format.\n */\nfunction convertRequireApproval(\n requireApproval: \"always\" | \"never\" | McpApprovalFilter | undefined\n):\n | OpenAIClient.Responses.Tool.Mcp.McpToolApprovalFilter\n | \"always\"\n | \"never\"\n | undefined {\n if (!requireApproval) return undefined;\n if (typeof requireApproval === \"string\") return requireApproval;\n return {\n always: requireApproval.always\n ? convertToolFilter(requireApproval.always)\n : undefined,\n never: requireApproval.never\n ? convertToolFilter(requireApproval.never)\n : undefined,\n };\n}\n\n/**\n * Creates an MCP tool that connects to a remote MCP server or OpenAI service connector.\n * This allows OpenAI models to access external tools and services via the Model Context Protocol.\n *\n * There are two ways to use MCP tools:\n * 1. **Remote MCP servers**: Connect to any server on the public Internet that implements\n * the MCP protocol using `serverUrl`.\n * 2. **Connectors**: Use OpenAI-maintained MCP wrappers for popular services like\n * Google Workspace or Dropbox using `connectorId`.\n *\n * @see {@link https://platform.openai.com/docs/guides/tools-remote-mcp | OpenAI MCP Documentation}\n *\n * @param options - Configuration options for the MCP tool\n * @returns An MCP tool definition to be passed to the OpenAI Responses API\n *\n * @example\n * ```typescript\n * import { ChatOpenAI, tools } from \"@langchain/openai\";\n *\n * const model = new ChatOpenAI({ model: \"gpt-4o\" });\n *\n * // Using a remote MCP server\n * const response = await model.invoke(\"Roll 2d4+1\", {\n * tools: [tools.mcp({\n * serverLabel: \"dmcp\",\n * serverDescription: \"A D&D MCP server for dice rolling\",\n * serverUrl: \"https://dmcp-server.deno.dev/sse\",\n * requireApproval: \"never\",\n * })],\n * });\n *\n * // Using a connector (e.g., Google Calendar)\n * const calendarResponse = await model.invoke(\"What's on my calendar today?\", {\n * tools: [tools.mcp({\n * serverLabel: \"google_calendar\",\n * connectorId: \"connector_googlecalendar\",\n * authorization: \"<oauth-access-token>\",\n * requireApproval: \"never\",\n * })],\n * });\n *\n * // With tool filtering - only allow specific tools\n * const filteredResponse = await model.invoke(\"Roll some dice\", {\n * tools: [tools.mcp({\n * serverLabel: \"dmcp\",\n * serverUrl: \"https://dmcp-server.deno.dev/sse\",\n * allowedTools: [\"roll\"], // Only allow the \"roll\" tool\n * requireApproval: \"never\",\n * })],\n * });\n *\n * // With fine-grained approval control\n * const controlledResponse = await model.invoke(\"Search and modify files\", {\n * tools: [tools.mcp({\n * serverLabel: \"deepwiki\",\n * serverUrl: \"https://mcp.deepwiki.com/mcp\",\n * requireApproval: {\n * never: { toolNames: [\"ask_question\", \"read_wiki_structure\"] },\n * // All other tools will require approval\n * },\n * })],\n * });\n * ```\n */\nexport function mcp(options: McpRemoteServerOptions): ServerTool;\nexport function mcp(options: McpConnectorOptions): ServerTool;\nexport function mcp(\n options: McpRemoteServerOptions | McpConnectorOptions\n): ServerTool {\n const baseConfig: McpTool = {\n type: \"mcp\",\n server_label: options.serverLabel,\n allowed_tools: convertAllowedTools(options.allowedTools),\n authorization: options.authorization,\n headers: options.headers,\n require_approval: convertRequireApproval(options.requireApproval),\n server_description: options.serverDescription,\n };\n\n if (\"serverUrl\" in options) {\n return {\n ...baseConfig,\n server_url: options.serverUrl,\n } satisfies McpTool;\n }\n\n return {\n ...baseConfig,\n connector_id: options.connectorId,\n } satisfies McpTool;\n}\n"],"mappings":";;;;AA4HA,SAAS,kBACP,QAC+C;CAC/C,OAAO;EACL,YAAY,OAAO;EACnB,WAAW,OAAO;CACpB;AACF;;;;AAKA,SAAS,oBACP,cAC2E;CAC3E,IAAI,CAAC,cAAc,OAAO,KAAA;CAC1B,IAAI,MAAM,QAAQ,YAAY,GAAG,OAAO;CACxC,OAAO,kBAAkB,YAAY;AACvC;;;;AAKA,SAAS,uBACP,iBAKY;CACZ,IAAI,CAAC,iBAAiB,OAAO,KAAA;CAC7B,IAAI,OAAO,oBAAoB,UAAU,OAAO;CAChD,OAAO;EACL,QAAQ,gBAAgB,SACpB,kBAAkB,gBAAgB,MAAM,IACxC,KAAA;EACJ,OAAO,gBAAgB,QACnB,kBAAkB,gBAAgB,KAAK,IACvC,KAAA;CACN;AACF;AAoEA,SAAgB,IACd,SACY;CACZ,MAAM,aAAsB;EAC1B,MAAM;EACN,cAAc,QAAQ;EACtB,eAAe,oBAAoB,QAAQ,YAAY;EACvD,eAAe,QAAQ;EACvB,SAAS,QAAQ;EACjB,kBAAkB,uBAAuB,QAAQ,eAAe;EAChE,oBAAoB,QAAQ;CAC9B;CAEA,IAAI,eAAe,SACjB,OAAO;EACL,GAAG;EACH,YAAY,QAAQ;CACtB;CAGF,OAAO;EACL,GAAG;EACH,cAAc,QAAQ;CACxB;AACF"}
@@ -1,6 +1,5 @@
1
1
  import { OpenAI } from "openai";
2
2
  import { ServerTool } from "@langchain/core/tools";
3
-
4
3
  //#region src/tools/mcp.d.ts
5
4
  /**
6
5
  * Available connector IDs for OpenAI's built-in service connectors.
@@ -1 +1 @@
1
- {"version":3,"file":"mcp.d.cts","names":[],"sources":["../../src/tools/mcp.ts"],"mappings":";;;;;;AAOA;;KAAY,cAAA;;;AAaZ;UAAiB,aAAA;;;;EAIf,SAAA;EAWgC;;;;EANhC,QAAA;AAAA;;;;UAMe,iBAAA;EAcO;;;EAVtB,MAAA,GAAS,aAAA;EAsC8B;;;EAlCvC,KAAA,GAAQ,aAAA;AAAA;;;;UAMA,cAAA;EA4BR;;;EAxBA,WAAA;EA4BiB;AAMnB;;;EA7BE,YAAA,cAA0B,aAAA;EAkCjB;AAMX;;;EAnCE,aAAA;EAmC2C;;;;EA9B3C,OAAA,GAAU,MAAA;EAmDA;;;;;;;;EA1CV,eAAA,wBAAuC,iBAAA;EA0CY;AA+GrD;;EArJE,iBAAA;AAAA;;;;UAMe,sBAAA,SAA+B,cAAA;EA+IgB;AAChE;;;EA3IE,SAAA;AAAA;;;;UAMe,mBAAA,SAA4B,cAAA;;;;;;;;;;;;;;;EAe3C,WAAA,EAAa,cAAA;AAAA;;;;KAMH,OAAA,GAAU,MAAA,CAAa,SAAA,CAAU,IAAA,CAAK,GAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA+GlC,GAAA,CAAI,OAAA,EAAS,sBAAA,GAAyB,UAAA;AAAA,iBACtC,GAAA,CAAI,OAAA,EAAS,mBAAA,GAAsB,UAAA"}
1
+ {"version":3,"file":"mcp.d.cts","names":[],"sources":["../../src/tools/mcp.ts"],"mappings":";;;;;;;KAOY;;;;UAaK;;;;EAIf;;;;;EAKA;;;;;UAMe;;;;EAIf,SAAS;;;;EAIT,QAAQ;;;;;UAMA;;;;EAIR;;;;;EAKA,0BAA0B;;;;;EAK1B;;;;;EAKA,UAAU;;;;;;;;;EASV,uCAAuC;;;;EAIvC;;;;;UAMe,+BAA+B;;;;;EAK9C;;;;;UAMe,4BAA4B;;;;;;;;;;;;;;;EAe3C,aAAa;;;;;KAMH,UAAU,OAAa,UAAU,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA+GlC,IAAI,SAAS,yBAAyB;iBACtC,IAAI,SAAS,sBAAsB"}
@@ -1,6 +1,5 @@
1
1
  import { OpenAI } from "openai";
2
2
  import { ServerTool } from "@langchain/core/tools";
3
-
4
3
  //#region src/tools/mcp.d.ts
5
4
  /**
6
5
  * Available connector IDs for OpenAI's built-in service connectors.
@@ -1 +1 @@
1
- {"version":3,"file":"mcp.d.ts","names":[],"sources":["../../src/tools/mcp.ts"],"mappings":";;;;;;AAOA;;KAAY,cAAA;;;AAaZ;UAAiB,aAAA;;;;EAIf,SAAA;EAWgC;;;;EANhC,QAAA;AAAA;;;;UAMe,iBAAA;EAcO;;;EAVtB,MAAA,GAAS,aAAA;EAsC8B;;;EAlCvC,KAAA,GAAQ,aAAA;AAAA;;;;UAMA,cAAA;EA4BR;;;EAxBA,WAAA;EA4BiB;AAMnB;;;EA7BE,YAAA,cAA0B,aAAA;EAkCjB;AAMX;;;EAnCE,aAAA;EAmC2C;;;;EA9B3C,OAAA,GAAU,MAAA;EAmDA;;;;;;;;EA1CV,eAAA,wBAAuC,iBAAA;EA0CY;AA+GrD;;EArJE,iBAAA;AAAA;;;;UAMe,sBAAA,SAA+B,cAAA;EA+IgB;AAChE;;;EA3IE,SAAA;AAAA;;;;UAMe,mBAAA,SAA4B,cAAA;;;;;;;;;;;;;;;EAe3C,WAAA,EAAa,cAAA;AAAA;;;;KAMH,OAAA,GAAU,MAAA,CAAa,SAAA,CAAU,IAAA,CAAK,GAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA+GlC,GAAA,CAAI,OAAA,EAAS,sBAAA,GAAyB,UAAA;AAAA,iBACtC,GAAA,CAAI,OAAA,EAAS,mBAAA,GAAsB,UAAA"}
1
+ {"version":3,"file":"mcp.d.ts","names":[],"sources":["../../src/tools/mcp.ts"],"mappings":";;;;;;;KAOY;;;;UAaK;;;;EAIf;;;;;EAKA;;;;;UAMe;;;;EAIf,SAAS;;;;EAIT,QAAQ;;;;;UAMA;;;;EAIR;;;;;EAKA,0BAA0B;;;;;EAK1B;;;;;EAKA,UAAU;;;;;;;;;EASV,uCAAuC;;;;EAIvC;;;;;UAMe,+BAA+B;;;;;EAK9C;;;;;UAMe,4BAA4B;;;;;;;;;;;;;;;EAe3C,aAAa;;;;;KAMH,UAAU,OAAa,UAAU,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA+GlC,IAAI,SAAS,yBAAyB;iBACtC,IAAI,SAAS,sBAAsB"}
@@ -1 +1 @@
1
- {"version":3,"file":"mcp.js","names":[],"sources":["../../src/tools/mcp.ts"],"sourcesContent":["import { OpenAI as OpenAIClient } from \"openai\";\nimport type { ServerTool } from \"@langchain/core/tools\";\n\n/**\n * Available connector IDs for OpenAI's built-in service connectors.\n * These are OpenAI-maintained MCP wrappers for popular services.\n */\nexport type McpConnectorId =\n | \"connector_dropbox\"\n | \"connector_gmail\"\n | \"connector_googlecalendar\"\n | \"connector_googledrive\"\n | \"connector_microsoftteams\"\n | \"connector_outlookcalendar\"\n | \"connector_outlookemail\"\n | \"connector_sharepoint\";\n\n/**\n * Filter object to specify which tools are allowed.\n */\nexport interface McpToolFilter {\n /**\n * List of allowed tool names.\n */\n toolNames?: string[];\n /**\n * Indicates whether or not a tool modifies data or is read-only.\n * If an MCP server is annotated with `readOnlyHint`, it will match this filter.\n */\n readOnly?: boolean;\n}\n\n/**\n * Filter object for approval requirements.\n */\nexport interface McpApprovalFilter {\n /**\n * Tools that always require approval before execution.\n */\n always?: McpToolFilter;\n /**\n * Tools that never require approval.\n */\n never?: McpToolFilter;\n}\n\n/**\n * Base options shared between remote MCP servers and connectors.\n */\ninterface McpBaseOptions {\n /**\n * A label for this MCP server, used to identify it in tool calls.\n */\n serverLabel: string;\n /**\n * List of allowed tool names or a filter object.\n * Use this to limit which tools from the MCP server are available to the model.\n */\n allowedTools?: string[] | McpToolFilter;\n /**\n * An OAuth access token for authentication with the MCP server.\n * Your application must handle the OAuth authorization flow and provide the token here.\n */\n authorization?: string;\n /**\n * Optional HTTP headers to send to the MCP server.\n * Use for authentication or other purposes.\n */\n headers?: Record<string, string>;\n /**\n * Specify which of the MCP server's tools require approval before execution.\n * - `\"always\"`: All tools require approval\n * - `\"never\"`: No tools require approval\n * - `McpApprovalFilter`: Fine-grained control over which tools require approval\n *\n * @default \"always\" (approval required for all tools)\n */\n requireApproval?: \"always\" | \"never\" | McpApprovalFilter;\n /**\n * Optional description of the MCP server, used to provide more context to the model.\n */\n serverDescription?: string;\n}\n\n/**\n * Options for connecting to a remote MCP server via URL.\n */\nexport interface McpRemoteServerOptions extends McpBaseOptions {\n /**\n * The URL for the MCP server.\n * The server must implement the Streamable HTTP or HTTP/SSE transport protocol.\n */\n serverUrl: string;\n}\n\n/**\n * Options for connecting to an OpenAI-maintained service connector.\n */\nexport interface McpConnectorOptions extends McpBaseOptions {\n /**\n * Identifier for the service connector.\n * These are OpenAI-maintained MCP wrappers for popular services.\n *\n * Available connectors:\n * - `connector_dropbox`: Dropbox file access\n * - `connector_gmail`: Gmail email access\n * - `connector_googlecalendar`: Google Calendar access\n * - `connector_googledrive`: Google Drive file access\n * - `connector_microsoftteams`: Microsoft Teams access\n * - `connector_outlookcalendar`: Outlook Calendar access\n * - `connector_outlookemail`: Outlook Email access\n * - `connector_sharepoint`: SharePoint file access\n */\n connectorId: McpConnectorId;\n}\n\n/**\n * OpenAI MCP tool type for the Responses API.\n */\nexport type McpTool = OpenAIClient.Responses.Tool.Mcp;\n\n/**\n * Converts a McpToolFilter to the API format.\n */\nfunction convertToolFilter(\n filter: McpToolFilter\n): OpenAIClient.Responses.Tool.Mcp.McpToolFilter {\n return {\n tool_names: filter.toolNames,\n read_only: filter.readOnly,\n };\n}\n\n/**\n * Converts allowed_tools option to API format.\n */\nfunction convertAllowedTools(\n allowedTools: string[] | McpToolFilter | undefined\n): Array<string> | OpenAIClient.Responses.Tool.Mcp.McpToolFilter | undefined {\n if (!allowedTools) return undefined;\n if (Array.isArray(allowedTools)) return allowedTools;\n return convertToolFilter(allowedTools);\n}\n\n/**\n * Converts require_approval option to API format.\n */\nfunction convertRequireApproval(\n requireApproval: \"always\" | \"never\" | McpApprovalFilter | undefined\n):\n | OpenAIClient.Responses.Tool.Mcp.McpToolApprovalFilter\n | \"always\"\n | \"never\"\n | undefined {\n if (!requireApproval) return undefined;\n if (typeof requireApproval === \"string\") return requireApproval;\n return {\n always: requireApproval.always\n ? convertToolFilter(requireApproval.always)\n : undefined,\n never: requireApproval.never\n ? convertToolFilter(requireApproval.never)\n : undefined,\n };\n}\n\n/**\n * Creates an MCP tool that connects to a remote MCP server or OpenAI service connector.\n * This allows OpenAI models to access external tools and services via the Model Context Protocol.\n *\n * There are two ways to use MCP tools:\n * 1. **Remote MCP servers**: Connect to any server on the public Internet that implements\n * the MCP protocol using `serverUrl`.\n * 2. **Connectors**: Use OpenAI-maintained MCP wrappers for popular services like\n * Google Workspace or Dropbox using `connectorId`.\n *\n * @see {@link https://platform.openai.com/docs/guides/tools-remote-mcp | OpenAI MCP Documentation}\n *\n * @param options - Configuration options for the MCP tool\n * @returns An MCP tool definition to be passed to the OpenAI Responses API\n *\n * @example\n * ```typescript\n * import { ChatOpenAI, tools } from \"@langchain/openai\";\n *\n * const model = new ChatOpenAI({ model: \"gpt-4o\" });\n *\n * // Using a remote MCP server\n * const response = await model.invoke(\"Roll 2d4+1\", {\n * tools: [tools.mcp({\n * serverLabel: \"dmcp\",\n * serverDescription: \"A D&D MCP server for dice rolling\",\n * serverUrl: \"https://dmcp-server.deno.dev/sse\",\n * requireApproval: \"never\",\n * })],\n * });\n *\n * // Using a connector (e.g., Google Calendar)\n * const calendarResponse = await model.invoke(\"What's on my calendar today?\", {\n * tools: [tools.mcp({\n * serverLabel: \"google_calendar\",\n * connectorId: \"connector_googlecalendar\",\n * authorization: \"<oauth-access-token>\",\n * requireApproval: \"never\",\n * })],\n * });\n *\n * // With tool filtering - only allow specific tools\n * const filteredResponse = await model.invoke(\"Roll some dice\", {\n * tools: [tools.mcp({\n * serverLabel: \"dmcp\",\n * serverUrl: \"https://dmcp-server.deno.dev/sse\",\n * allowedTools: [\"roll\"], // Only allow the \"roll\" tool\n * requireApproval: \"never\",\n * })],\n * });\n *\n * // With fine-grained approval control\n * const controlledResponse = await model.invoke(\"Search and modify files\", {\n * tools: [tools.mcp({\n * serverLabel: \"deepwiki\",\n * serverUrl: \"https://mcp.deepwiki.com/mcp\",\n * requireApproval: {\n * never: { toolNames: [\"ask_question\", \"read_wiki_structure\"] },\n * // All other tools will require approval\n * },\n * })],\n * });\n * ```\n */\nexport function mcp(options: McpRemoteServerOptions): ServerTool;\nexport function mcp(options: McpConnectorOptions): ServerTool;\nexport function mcp(\n options: McpRemoteServerOptions | McpConnectorOptions\n): ServerTool {\n const baseConfig: McpTool = {\n type: \"mcp\",\n server_label: options.serverLabel,\n allowed_tools: convertAllowedTools(options.allowedTools),\n authorization: options.authorization,\n headers: options.headers,\n require_approval: convertRequireApproval(options.requireApproval),\n server_description: options.serverDescription,\n };\n\n if (\"serverUrl\" in options) {\n return {\n ...baseConfig,\n server_url: options.serverUrl,\n } satisfies McpTool;\n }\n\n return {\n ...baseConfig,\n connector_id: options.connectorId,\n } satisfies McpTool;\n}\n"],"mappings":";;;;AA4HA,SAAS,kBACP,QAC+C;AAC/C,QAAO;EACL,YAAY,OAAO;EACnB,WAAW,OAAO;EACnB;;;;;AAMH,SAAS,oBACP,cAC2E;AAC3E,KAAI,CAAC,aAAc,QAAO,KAAA;AAC1B,KAAI,MAAM,QAAQ,aAAa,CAAE,QAAO;AACxC,QAAO,kBAAkB,aAAa;;;;;AAMxC,SAAS,uBACP,iBAKY;AACZ,KAAI,CAAC,gBAAiB,QAAO,KAAA;AAC7B,KAAI,OAAO,oBAAoB,SAAU,QAAO;AAChD,QAAO;EACL,QAAQ,gBAAgB,SACpB,kBAAkB,gBAAgB,OAAO,GACzC,KAAA;EACJ,OAAO,gBAAgB,QACnB,kBAAkB,gBAAgB,MAAM,GACxC,KAAA;EACL;;AAqEH,SAAgB,IACd,SACY;CACZ,MAAM,aAAsB;EAC1B,MAAM;EACN,cAAc,QAAQ;EACtB,eAAe,oBAAoB,QAAQ,aAAa;EACxD,eAAe,QAAQ;EACvB,SAAS,QAAQ;EACjB,kBAAkB,uBAAuB,QAAQ,gBAAgB;EACjE,oBAAoB,QAAQ;EAC7B;AAED,KAAI,eAAe,QACjB,QAAO;EACL,GAAG;EACH,YAAY,QAAQ;EACrB;AAGH,QAAO;EACL,GAAG;EACH,cAAc,QAAQ;EACvB"}
1
+ {"version":3,"file":"mcp.js","names":[],"sources":["../../src/tools/mcp.ts"],"sourcesContent":["import { OpenAI as OpenAIClient } from \"openai\";\nimport type { ServerTool } from \"@langchain/core/tools\";\n\n/**\n * Available connector IDs for OpenAI's built-in service connectors.\n * These are OpenAI-maintained MCP wrappers for popular services.\n */\nexport type McpConnectorId =\n | \"connector_dropbox\"\n | \"connector_gmail\"\n | \"connector_googlecalendar\"\n | \"connector_googledrive\"\n | \"connector_microsoftteams\"\n | \"connector_outlookcalendar\"\n | \"connector_outlookemail\"\n | \"connector_sharepoint\";\n\n/**\n * Filter object to specify which tools are allowed.\n */\nexport interface McpToolFilter {\n /**\n * List of allowed tool names.\n */\n toolNames?: string[];\n /**\n * Indicates whether or not a tool modifies data or is read-only.\n * If an MCP server is annotated with `readOnlyHint`, it will match this filter.\n */\n readOnly?: boolean;\n}\n\n/**\n * Filter object for approval requirements.\n */\nexport interface McpApprovalFilter {\n /**\n * Tools that always require approval before execution.\n */\n always?: McpToolFilter;\n /**\n * Tools that never require approval.\n */\n never?: McpToolFilter;\n}\n\n/**\n * Base options shared between remote MCP servers and connectors.\n */\ninterface McpBaseOptions {\n /**\n * A label for this MCP server, used to identify it in tool calls.\n */\n serverLabel: string;\n /**\n * List of allowed tool names or a filter object.\n * Use this to limit which tools from the MCP server are available to the model.\n */\n allowedTools?: string[] | McpToolFilter;\n /**\n * An OAuth access token for authentication with the MCP server.\n * Your application must handle the OAuth authorization flow and provide the token here.\n */\n authorization?: string;\n /**\n * Optional HTTP headers to send to the MCP server.\n * Use for authentication or other purposes.\n */\n headers?: Record<string, string>;\n /**\n * Specify which of the MCP server's tools require approval before execution.\n * - `\"always\"`: All tools require approval\n * - `\"never\"`: No tools require approval\n * - `McpApprovalFilter`: Fine-grained control over which tools require approval\n *\n * @default \"always\" (approval required for all tools)\n */\n requireApproval?: \"always\" | \"never\" | McpApprovalFilter;\n /**\n * Optional description of the MCP server, used to provide more context to the model.\n */\n serverDescription?: string;\n}\n\n/**\n * Options for connecting to a remote MCP server via URL.\n */\nexport interface McpRemoteServerOptions extends McpBaseOptions {\n /**\n * The URL for the MCP server.\n * The server must implement the Streamable HTTP or HTTP/SSE transport protocol.\n */\n serverUrl: string;\n}\n\n/**\n * Options for connecting to an OpenAI-maintained service connector.\n */\nexport interface McpConnectorOptions extends McpBaseOptions {\n /**\n * Identifier for the service connector.\n * These are OpenAI-maintained MCP wrappers for popular services.\n *\n * Available connectors:\n * - `connector_dropbox`: Dropbox file access\n * - `connector_gmail`: Gmail email access\n * - `connector_googlecalendar`: Google Calendar access\n * - `connector_googledrive`: Google Drive file access\n * - `connector_microsoftteams`: Microsoft Teams access\n * - `connector_outlookcalendar`: Outlook Calendar access\n * - `connector_outlookemail`: Outlook Email access\n * - `connector_sharepoint`: SharePoint file access\n */\n connectorId: McpConnectorId;\n}\n\n/**\n * OpenAI MCP tool type for the Responses API.\n */\nexport type McpTool = OpenAIClient.Responses.Tool.Mcp;\n\n/**\n * Converts a McpToolFilter to the API format.\n */\nfunction convertToolFilter(\n filter: McpToolFilter\n): OpenAIClient.Responses.Tool.Mcp.McpToolFilter {\n return {\n tool_names: filter.toolNames,\n read_only: filter.readOnly,\n };\n}\n\n/**\n * Converts allowed_tools option to API format.\n */\nfunction convertAllowedTools(\n allowedTools: string[] | McpToolFilter | undefined\n): Array<string> | OpenAIClient.Responses.Tool.Mcp.McpToolFilter | undefined {\n if (!allowedTools) return undefined;\n if (Array.isArray(allowedTools)) return allowedTools;\n return convertToolFilter(allowedTools);\n}\n\n/**\n * Converts require_approval option to API format.\n */\nfunction convertRequireApproval(\n requireApproval: \"always\" | \"never\" | McpApprovalFilter | undefined\n):\n | OpenAIClient.Responses.Tool.Mcp.McpToolApprovalFilter\n | \"always\"\n | \"never\"\n | undefined {\n if (!requireApproval) return undefined;\n if (typeof requireApproval === \"string\") return requireApproval;\n return {\n always: requireApproval.always\n ? convertToolFilter(requireApproval.always)\n : undefined,\n never: requireApproval.never\n ? convertToolFilter(requireApproval.never)\n : undefined,\n };\n}\n\n/**\n * Creates an MCP tool that connects to a remote MCP server or OpenAI service connector.\n * This allows OpenAI models to access external tools and services via the Model Context Protocol.\n *\n * There are two ways to use MCP tools:\n * 1. **Remote MCP servers**: Connect to any server on the public Internet that implements\n * the MCP protocol using `serverUrl`.\n * 2. **Connectors**: Use OpenAI-maintained MCP wrappers for popular services like\n * Google Workspace or Dropbox using `connectorId`.\n *\n * @see {@link https://platform.openai.com/docs/guides/tools-remote-mcp | OpenAI MCP Documentation}\n *\n * @param options - Configuration options for the MCP tool\n * @returns An MCP tool definition to be passed to the OpenAI Responses API\n *\n * @example\n * ```typescript\n * import { ChatOpenAI, tools } from \"@langchain/openai\";\n *\n * const model = new ChatOpenAI({ model: \"gpt-4o\" });\n *\n * // Using a remote MCP server\n * const response = await model.invoke(\"Roll 2d4+1\", {\n * tools: [tools.mcp({\n * serverLabel: \"dmcp\",\n * serverDescription: \"A D&D MCP server for dice rolling\",\n * serverUrl: \"https://dmcp-server.deno.dev/sse\",\n * requireApproval: \"never\",\n * })],\n * });\n *\n * // Using a connector (e.g., Google Calendar)\n * const calendarResponse = await model.invoke(\"What's on my calendar today?\", {\n * tools: [tools.mcp({\n * serverLabel: \"google_calendar\",\n * connectorId: \"connector_googlecalendar\",\n * authorization: \"<oauth-access-token>\",\n * requireApproval: \"never\",\n * })],\n * });\n *\n * // With tool filtering - only allow specific tools\n * const filteredResponse = await model.invoke(\"Roll some dice\", {\n * tools: [tools.mcp({\n * serverLabel: \"dmcp\",\n * serverUrl: \"https://dmcp-server.deno.dev/sse\",\n * allowedTools: [\"roll\"], // Only allow the \"roll\" tool\n * requireApproval: \"never\",\n * })],\n * });\n *\n * // With fine-grained approval control\n * const controlledResponse = await model.invoke(\"Search and modify files\", {\n * tools: [tools.mcp({\n * serverLabel: \"deepwiki\",\n * serverUrl: \"https://mcp.deepwiki.com/mcp\",\n * requireApproval: {\n * never: { toolNames: [\"ask_question\", \"read_wiki_structure\"] },\n * // All other tools will require approval\n * },\n * })],\n * });\n * ```\n */\nexport function mcp(options: McpRemoteServerOptions): ServerTool;\nexport function mcp(options: McpConnectorOptions): ServerTool;\nexport function mcp(\n options: McpRemoteServerOptions | McpConnectorOptions\n): ServerTool {\n const baseConfig: McpTool = {\n type: \"mcp\",\n server_label: options.serverLabel,\n allowed_tools: convertAllowedTools(options.allowedTools),\n authorization: options.authorization,\n headers: options.headers,\n require_approval: convertRequireApproval(options.requireApproval),\n server_description: options.serverDescription,\n };\n\n if (\"serverUrl\" in options) {\n return {\n ...baseConfig,\n server_url: options.serverUrl,\n } satisfies McpTool;\n }\n\n return {\n ...baseConfig,\n connector_id: options.connectorId,\n } satisfies McpTool;\n}\n"],"mappings":";;;;AA4HA,SAAS,kBACP,QAC+C;CAC/C,OAAO;EACL,YAAY,OAAO;EACnB,WAAW,OAAO;CACpB;AACF;;;;AAKA,SAAS,oBACP,cAC2E;CAC3E,IAAI,CAAC,cAAc,OAAO,KAAA;CAC1B,IAAI,MAAM,QAAQ,YAAY,GAAG,OAAO;CACxC,OAAO,kBAAkB,YAAY;AACvC;;;;AAKA,SAAS,uBACP,iBAKY;CACZ,IAAI,CAAC,iBAAiB,OAAO,KAAA;CAC7B,IAAI,OAAO,oBAAoB,UAAU,OAAO;CAChD,OAAO;EACL,QAAQ,gBAAgB,SACpB,kBAAkB,gBAAgB,MAAM,IACxC,KAAA;EACJ,OAAO,gBAAgB,QACnB,kBAAkB,gBAAgB,KAAK,IACvC,KAAA;CACN;AACF;AAoEA,SAAgB,IACd,SACY;CACZ,MAAM,aAAsB;EAC1B,MAAM;EACN,cAAc,QAAQ;EACtB,eAAe,oBAAoB,QAAQ,YAAY;EACvD,eAAe,QAAQ;EACvB,SAAS,QAAQ;EACjB,kBAAkB,uBAAuB,QAAQ,eAAe;EAChE,oBAAoB,QAAQ;CAC9B;CAEA,IAAI,eAAe,SACjB,OAAO;EACL,GAAG;EACH,YAAY,QAAQ;CACtB;CAGF,OAAO;EACL,GAAG;EACH,cAAc,QAAQ;CACxB;AACF"}
@@ -156,6 +156,7 @@ function shell(options) {
156
156
  return shellTool;
157
157
  }
158
158
  //#endregion
159
+ exports.ShellActionSchema = ShellActionSchema;
159
160
  exports.shell = shell;
160
161
 
161
162
  //# sourceMappingURL=shell.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"shell.cjs","names":["z"],"sources":["../../src/tools/shell.ts"],"sourcesContent":["import { z } from \"zod/v4\";\nimport { OpenAI as OpenAIClient } from \"openai\";\nimport { tool, type DynamicStructuredTool } from \"@langchain/core/tools\";\n\n/**\n * Re-export action type from OpenAI SDK for convenience.\n * The action contains command details like commands array, timeout, and max output length.\n */\nexport type ShellAction =\n OpenAIClient.Responses.ResponseFunctionShellToolCall.Action;\n\n// Zod schema for shell action\nexport const ShellActionSchema = z.object({\n commands: z.array(z.string()).describe(\"Array of shell commands to execute\"),\n timeout_ms: z\n .number()\n .optional()\n .describe(\"Optional timeout in milliseconds for the commands\"),\n max_output_length: z\n .number()\n .optional()\n .describe(\n \"Optional maximum number of characters to return from each command\"\n ),\n});\n\n/**\n * Result of a single shell command execution.\n * Contains stdout, stderr, and the outcome (exit code or timeout).\n */\nexport type ShellCommandOutput =\n OpenAIClient.Responses.ResponseFunctionShellCallOutputContent;\n\n/**\n * Outcome type for shell command execution - either exit with code or timeout.\n */\nexport type ShellCallOutcome = ShellCommandOutput[\"outcome\"];\n\n/**\n * Result of executing shell commands.\n * Contains an array of outputs (one per command) and the max_output_length parameter.\n */\nexport interface ShellResult {\n /**\n * Array of command outputs. Each entry corresponds to a command from the action.\n * The order should match the order of commands in the action.\n */\n output: ShellCommandOutput[];\n /**\n * The max_output_length from the action, which must be passed back to the API.\n * If not provided in the action, can be omitted.\n */\n maxOutputLength?: number | null;\n}\n\n/**\n * Options for the Shell tool.\n */\nexport interface ShellOptions {\n /**\n * Execute function that handles shell command execution.\n * This function receives the action input containing the commands and limits,\n * and should return a ShellResult with stdout, stderr, and outcome for each command.\n *\n * @example\n * ```typescript\n * execute: async (action) => {\n * const outputs = await Promise.all(\n * action.commands.map(async (cmd) => {\n * try {\n * const { stdout, stderr } = await exec(cmd, {\n * timeout: action.timeout_ms ?? undefined,\n * });\n * return {\n * stdout,\n * stderr,\n * outcome: { type: \"exit\" as const, exit_code: 0 },\n * };\n * } catch (error) {\n * const timedOut = error.killed && error.signal === \"SIGTERM\";\n * return {\n * stdout: error.stdout ?? \"\",\n * stderr: error.stderr ?? String(error),\n * outcome: timedOut\n * ? { type: \"timeout\" as const }\n * : { type: \"exit\" as const, exit_code: error.code ?? 1 },\n * };\n * }\n * })\n * );\n * return {\n * output: outputs,\n * maxOutputLength: action.max_output_length,\n * };\n * }\n * ```\n */\n execute: (action: ShellAction) => ShellResult | Promise<ShellResult>;\n}\n\n/**\n * OpenAI Shell tool type for the Responses API.\n */\nexport type ShellTool = OpenAIClient.Responses.FunctionShellTool;\n\nconst TOOL_NAME = \"shell\";\n\n/**\n * Creates a Shell tool that allows models to run shell commands through your integration.\n *\n * The shell tool allows the model to interact with your local computer through a controlled\n * command-line interface. The model proposes shell commands; your integration executes them\n * and returns the outputs. This creates a simple plan-execute loop that lets models inspect\n * the system, run utilities, and gather data until they can finish the task.\n *\n * **Important**: The shell tool is available through the Responses API for use with `GPT-5.1`.\n * It is not available on other models, or via the Chat Completions API.\n *\n * **When to use**:\n * - **Automating filesystem or process diagnostics** – For example, \"find the largest PDF\n * under ~/Documents\" or \"show running gunicorn processes.\"\n * - **Extending the model's capabilities** – Using built-in UNIX utilities, python runtime\n * and other CLIs in your environment.\n * - **Running multi-step build and test flows** – Chaining commands like `pip install` and `pytest`.\n * - **Complex agentic coding workflows** – Using other tools like `apply_patch` to complete\n * workflows that involve complex file operations.\n *\n * **How it works**:\n * The tool operates in a continuous loop:\n * 1. Model sends shell commands (`shell_call` with `commands` array)\n * 2. Your code executes the commands (can be concurrent)\n * 3. You return stdout, stderr, and outcome for each command\n * 4. Repeat until the task is complete\n *\n * **Security Warning**: Running arbitrary shell commands can be dangerous.\n * Always sandbox execution or add strict allow/deny-lists before forwarding\n * a command to the system shell.\n *\n * @see {@link https://platform.openai.com/docs/guides/tools-shell | OpenAI Shell Documentation}\n * @see {@link https://github.com/openai/codex | Codex CLI} for reference implementation.\n *\n * @param options - Configuration for the Shell tool\n * @returns A Shell tool that can be passed to `bindTools`\n *\n * @example\n * ```typescript\n * import { ChatOpenAI, tools } from \"@langchain/openai\";\n * import { exec } from \"child_process/promises\";\n *\n * const model = new ChatOpenAI({ model: \"gpt-5.1\" });\n *\n * // With execute callback for automatic command handling\n * const shellTool = tools.shell({\n * execute: async (action) => {\n * const outputs = await Promise.all(\n * action.commands.map(async (cmd) => {\n * try {\n * const { stdout, stderr } = await exec(cmd, {\n * timeout: action.timeout_ms ?? undefined,\n * });\n * return {\n * stdout,\n * stderr,\n * outcome: { type: \"exit\" as const, exit_code: 0 },\n * };\n * } catch (error) {\n * const timedOut = error.killed && error.signal === \"SIGTERM\";\n * return {\n * stdout: error.stdout ?? \"\",\n * stderr: error.stderr ?? String(error),\n * outcome: timedOut\n * ? { type: \"timeout\" as const }\n * : { type: \"exit\" as const, exit_code: error.code ?? 1 },\n * };\n * }\n * })\n * );\n * return {\n * output: outputs,\n * maxOutputLength: action.max_output_length,\n * };\n * },\n * });\n *\n * const llmWithShell = model.bindTools([shellTool]);\n * const response = await llmWithShell.invoke(\n * \"Find the largest PDF file in ~/Documents\"\n * );\n * ```\n *\n * @example\n * ```typescript\n * // Full shell loop example\n * async function shellLoop(model, task) {\n * let response = await model.invoke(task, {\n * tools: [tools.shell({ execute: myExecutor })],\n * });\n *\n * while (true) {\n * const shellCall = response.additional_kwargs.tool_outputs?.find(\n * (output) => output.type === \"shell_call\"\n * );\n *\n * if (!shellCall) break;\n *\n * // Execute commands (with proper sandboxing!)\n * const result = await executeCommands(shellCall.action);\n *\n * // Send output back to model\n * response = await model.invoke([\n * response,\n * {\n * type: \"shell_call_output\",\n * call_id: shellCall.call_id,\n * output: result.output,\n * max_output_length: result.maxOutputLength,\n * },\n * ], {\n * tools: [tools.shell({ execute: myExecutor })],\n * });\n * }\n *\n * return response;\n * }\n * ```\n *\n * @remarks\n * - Only available through the Responses API (not Chat Completions)\n * - Designed for use with `gpt-5.1` model\n * - Commands are provided as an array of strings that can be executed concurrently\n * - Action includes: `commands`, `timeout_ms`, `max_output_length`\n * - Always sandbox or validate commands before execution\n * - The `timeout_ms` from the model is only a hint—enforce your own limits\n * - If `max_output_length` exists in the action, always pass it back in the output\n * - Many CLI tools return non-zero exit codes for warnings; still capture stdout/stderr\n */\nexport function shell(options: ShellOptions) {\n // Wrapper that converts ShellResult to string for LangChain tool compatibility\n const executeWrapper = async (action: ShellAction): Promise<string> => {\n const result = await options.execute(action);\n // Return a JSON string representation for the tool result\n return JSON.stringify({\n output: result.output,\n max_output_length: result.maxOutputLength,\n });\n };\n\n const shellTool = tool(executeWrapper, {\n name: TOOL_NAME,\n description:\n \"Execute shell commands in a managed environment. Commands can be run concurrently.\",\n schema: ShellActionSchema,\n });\n\n shellTool.extras = {\n ...(shellTool.extras ?? {}),\n providerToolDefinition: {\n type: \"shell\",\n } satisfies ShellTool,\n };\n\n return shellTool as DynamicStructuredTool<\n typeof ShellActionSchema,\n ShellAction,\n unknown,\n string\n >;\n}\n"],"mappings":";;;AAYA,MAAa,oBAAoBA,OAAAA,EAAE,OAAO;CACxC,UAAUA,OAAAA,EAAE,MAAMA,OAAAA,EAAE,QAAQ,CAAC,CAAC,SAAS,qCAAqC;CAC5E,YAAYA,OAAAA,EACT,QAAQ,CACR,UAAU,CACV,SAAS,oDAAoD;CAChE,mBAAmBA,OAAAA,EAChB,QAAQ,CACR,UAAU,CACV,SACC,oEACD;CACJ,CAAC;AAiFF,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmIlB,SAAgB,MAAM,SAAuB;CAE3C,MAAM,iBAAiB,OAAO,WAAyC;EACrE,MAAM,SAAS,MAAM,QAAQ,QAAQ,OAAO;AAE5C,SAAO,KAAK,UAAU;GACpB,QAAQ,OAAO;GACf,mBAAmB,OAAO;GAC3B,CAAC;;CAGJ,MAAM,aAAA,GAAA,sBAAA,MAAiB,gBAAgB;EACrC,MAAM;EACN,aACE;EACF,QAAQ;EACT,CAAC;AAEF,WAAU,SAAS;EACjB,GAAI,UAAU,UAAU,EAAE;EAC1B,wBAAwB,EACtB,MAAM,SACP;EACF;AAED,QAAO"}
1
+ {"version":3,"file":"shell.cjs","names":["z"],"sources":["../../src/tools/shell.ts"],"sourcesContent":["import { z } from \"zod/v4\";\nimport { OpenAI as OpenAIClient } from \"openai\";\nimport { tool, type DynamicStructuredTool } from \"@langchain/core/tools\";\n\n/**\n * Re-export action type from OpenAI SDK for convenience.\n * The action contains command details like commands array, timeout, and max output length.\n */\nexport type ShellAction =\n OpenAIClient.Responses.ResponseFunctionShellToolCall.Action;\n\n// Zod schema for shell action\nexport const ShellActionSchema = z.object({\n commands: z.array(z.string()).describe(\"Array of shell commands to execute\"),\n timeout_ms: z\n .number()\n .optional()\n .describe(\"Optional timeout in milliseconds for the commands\"),\n max_output_length: z\n .number()\n .optional()\n .describe(\n \"Optional maximum number of characters to return from each command\"\n ),\n});\n\n/**\n * Result of a single shell command execution.\n * Contains stdout, stderr, and the outcome (exit code or timeout).\n */\nexport type ShellCommandOutput =\n OpenAIClient.Responses.ResponseFunctionShellCallOutputContent;\n\n/**\n * Outcome type for shell command execution - either exit with code or timeout.\n */\nexport type ShellCallOutcome = ShellCommandOutput[\"outcome\"];\n\n/**\n * Result of executing shell commands.\n * Contains an array of outputs (one per command) and the max_output_length parameter.\n */\nexport interface ShellResult {\n /**\n * Array of command outputs. Each entry corresponds to a command from the action.\n * The order should match the order of commands in the action.\n */\n output: ShellCommandOutput[];\n /**\n * The max_output_length from the action, which must be passed back to the API.\n * If not provided in the action, can be omitted.\n */\n maxOutputLength?: number | null;\n}\n\n/**\n * Options for the Shell tool.\n */\nexport interface ShellOptions {\n /**\n * Execute function that handles shell command execution.\n * This function receives the action input containing the commands and limits,\n * and should return a ShellResult with stdout, stderr, and outcome for each command.\n *\n * @example\n * ```typescript\n * execute: async (action) => {\n * const outputs = await Promise.all(\n * action.commands.map(async (cmd) => {\n * try {\n * const { stdout, stderr } = await exec(cmd, {\n * timeout: action.timeout_ms ?? undefined,\n * });\n * return {\n * stdout,\n * stderr,\n * outcome: { type: \"exit\" as const, exit_code: 0 },\n * };\n * } catch (error) {\n * const timedOut = error.killed && error.signal === \"SIGTERM\";\n * return {\n * stdout: error.stdout ?? \"\",\n * stderr: error.stderr ?? String(error),\n * outcome: timedOut\n * ? { type: \"timeout\" as const }\n * : { type: \"exit\" as const, exit_code: error.code ?? 1 },\n * };\n * }\n * })\n * );\n * return {\n * output: outputs,\n * maxOutputLength: action.max_output_length,\n * };\n * }\n * ```\n */\n execute: (action: ShellAction) => ShellResult | Promise<ShellResult>;\n}\n\n/**\n * OpenAI Shell tool type for the Responses API.\n */\nexport type ShellTool = OpenAIClient.Responses.FunctionShellTool;\n\nconst TOOL_NAME = \"shell\";\n\n/**\n * Creates a Shell tool that allows models to run shell commands through your integration.\n *\n * The shell tool allows the model to interact with your local computer through a controlled\n * command-line interface. The model proposes shell commands; your integration executes them\n * and returns the outputs. This creates a simple plan-execute loop that lets models inspect\n * the system, run utilities, and gather data until they can finish the task.\n *\n * **Important**: The shell tool is available through the Responses API for use with `GPT-5.1`.\n * It is not available on other models, or via the Chat Completions API.\n *\n * **When to use**:\n * - **Automating filesystem or process diagnostics** – For example, \"find the largest PDF\n * under ~/Documents\" or \"show running gunicorn processes.\"\n * - **Extending the model's capabilities** – Using built-in UNIX utilities, python runtime\n * and other CLIs in your environment.\n * - **Running multi-step build and test flows** – Chaining commands like `pip install` and `pytest`.\n * - **Complex agentic coding workflows** – Using other tools like `apply_patch` to complete\n * workflows that involve complex file operations.\n *\n * **How it works**:\n * The tool operates in a continuous loop:\n * 1. Model sends shell commands (`shell_call` with `commands` array)\n * 2. Your code executes the commands (can be concurrent)\n * 3. You return stdout, stderr, and outcome for each command\n * 4. Repeat until the task is complete\n *\n * **Security Warning**: Running arbitrary shell commands can be dangerous.\n * Always sandbox execution or add strict allow/deny-lists before forwarding\n * a command to the system shell.\n *\n * @see {@link https://platform.openai.com/docs/guides/tools-shell | OpenAI Shell Documentation}\n * @see {@link https://github.com/openai/codex | Codex CLI} for reference implementation.\n *\n * @param options - Configuration for the Shell tool\n * @returns A Shell tool that can be passed to `bindTools`\n *\n * @example\n * ```typescript\n * import { ChatOpenAI, tools } from \"@langchain/openai\";\n * import { exec } from \"child_process/promises\";\n *\n * const model = new ChatOpenAI({ model: \"gpt-5.1\" });\n *\n * // With execute callback for automatic command handling\n * const shellTool = tools.shell({\n * execute: async (action) => {\n * const outputs = await Promise.all(\n * action.commands.map(async (cmd) => {\n * try {\n * const { stdout, stderr } = await exec(cmd, {\n * timeout: action.timeout_ms ?? undefined,\n * });\n * return {\n * stdout,\n * stderr,\n * outcome: { type: \"exit\" as const, exit_code: 0 },\n * };\n * } catch (error) {\n * const timedOut = error.killed && error.signal === \"SIGTERM\";\n * return {\n * stdout: error.stdout ?? \"\",\n * stderr: error.stderr ?? String(error),\n * outcome: timedOut\n * ? { type: \"timeout\" as const }\n * : { type: \"exit\" as const, exit_code: error.code ?? 1 },\n * };\n * }\n * })\n * );\n * return {\n * output: outputs,\n * maxOutputLength: action.max_output_length,\n * };\n * },\n * });\n *\n * const llmWithShell = model.bindTools([shellTool]);\n * const response = await llmWithShell.invoke(\n * \"Find the largest PDF file in ~/Documents\"\n * );\n * ```\n *\n * @example\n * ```typescript\n * // Full shell loop example\n * async function shellLoop(model, task) {\n * let response = await model.invoke(task, {\n * tools: [tools.shell({ execute: myExecutor })],\n * });\n *\n * while (true) {\n * const shellCall = response.additional_kwargs.tool_outputs?.find(\n * (output) => output.type === \"shell_call\"\n * );\n *\n * if (!shellCall) break;\n *\n * // Execute commands (with proper sandboxing!)\n * const result = await executeCommands(shellCall.action);\n *\n * // Send output back to model\n * response = await model.invoke([\n * response,\n * {\n * type: \"shell_call_output\",\n * call_id: shellCall.call_id,\n * output: result.output,\n * max_output_length: result.maxOutputLength,\n * },\n * ], {\n * tools: [tools.shell({ execute: myExecutor })],\n * });\n * }\n *\n * return response;\n * }\n * ```\n *\n * @remarks\n * - Only available through the Responses API (not Chat Completions)\n * - Designed for use with `gpt-5.1` model\n * - Commands are provided as an array of strings that can be executed concurrently\n * - Action includes: `commands`, `timeout_ms`, `max_output_length`\n * - Always sandbox or validate commands before execution\n * - The `timeout_ms` from the model is only a hint—enforce your own limits\n * - If `max_output_length` exists in the action, always pass it back in the output\n * - Many CLI tools return non-zero exit codes for warnings; still capture stdout/stderr\n */\nexport function shell(options: ShellOptions) {\n // Wrapper that converts ShellResult to string for LangChain tool compatibility\n const executeWrapper = async (action: ShellAction): Promise<string> => {\n const result = await options.execute(action);\n // Return a JSON string representation for the tool result\n return JSON.stringify({\n output: result.output,\n max_output_length: result.maxOutputLength,\n });\n };\n\n const shellTool = tool(executeWrapper, {\n name: TOOL_NAME,\n description:\n \"Execute shell commands in a managed environment. Commands can be run concurrently.\",\n schema: ShellActionSchema,\n });\n\n shellTool.extras = {\n ...(shellTool.extras ?? {}),\n providerToolDefinition: {\n type: \"shell\",\n } satisfies ShellTool,\n };\n\n return shellTool as DynamicStructuredTool<\n typeof ShellActionSchema,\n ShellAction,\n unknown,\n string\n >;\n}\n"],"mappings":";;;AAYA,MAAa,oBAAoBA,OAAAA,EAAE,OAAO;CACxC,UAAUA,OAAAA,EAAE,MAAMA,OAAAA,EAAE,OAAO,CAAC,CAAC,CAAC,SAAS,oCAAoC;CAC3E,YAAYA,OAAAA,EACT,OAAO,CAAC,CACR,SAAS,CAAC,CACV,SAAS,mDAAmD;CAC/D,mBAAmBA,OAAAA,EAChB,OAAO,CAAC,CACR,SAAS,CAAC,CACV,SACC,mEACF;AACJ,CAAC;AAiFD,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmIlB,SAAgB,MAAM,SAAuB;CAE3C,MAAM,iBAAiB,OAAO,WAAyC;EACrE,MAAM,SAAS,MAAM,QAAQ,QAAQ,MAAM;EAE3C,OAAO,KAAK,UAAU;GACpB,QAAQ,OAAO;GACf,mBAAmB,OAAO;EAC5B,CAAC;CACH;CAEA,MAAM,aAAA,GAAA,sBAAA,KAAA,CAAiB,gBAAgB;EACrC,MAAM;EACN,aACE;EACF,QAAQ;CACV,CAAC;CAED,UAAU,SAAS;EACjB,GAAI,UAAU,UAAU,CAAC;EACzB,wBAAwB,EACtB,MAAM,QACR;CACF;CAEA,OAAO;AAMT"}