@langchain/openai 1.2.13 → 1.3.0-dev-1773698445534
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.
- package/dist/azure/chat_models/common.cjs +2 -3
- package/dist/azure/chat_models/common.cjs.map +1 -1
- package/dist/azure/chat_models/common.d.ts +0 -1
- package/dist/azure/chat_models/common.d.ts.map +1 -1
- package/dist/azure/chat_models/common.js +1 -2
- package/dist/azure/chat_models/common.js.map +1 -1
- package/dist/azure/chat_models/completions.cjs +3 -4
- package/dist/azure/chat_models/completions.cjs.map +1 -1
- package/dist/azure/chat_models/completions.js +1 -2
- package/dist/azure/chat_models/completions.js.map +1 -1
- package/dist/azure/chat_models/index.cjs +5 -6
- package/dist/azure/chat_models/index.cjs.map +1 -1
- package/dist/azure/chat_models/index.js +1 -2
- package/dist/azure/chat_models/index.js.map +1 -1
- package/dist/azure/chat_models/responses.cjs +3 -4
- package/dist/azure/chat_models/responses.cjs.map +1 -1
- package/dist/azure/chat_models/responses.js +1 -2
- package/dist/azure/chat_models/responses.js.map +1 -1
- package/dist/azure/embeddings.cjs +4 -5
- package/dist/azure/embeddings.cjs.map +1 -1
- package/dist/azure/embeddings.d.cts +2 -2
- package/dist/azure/embeddings.d.cts.map +1 -1
- package/dist/azure/embeddings.d.ts +2 -2
- package/dist/azure/embeddings.d.ts.map +1 -1
- package/dist/azure/embeddings.js +1 -2
- package/dist/azure/embeddings.js.map +1 -1
- package/dist/azure/llms.cjs +3 -4
- package/dist/azure/llms.cjs.map +1 -1
- package/dist/azure/llms.js +1 -2
- package/dist/azure/llms.js.map +1 -1
- package/dist/chat_models/base.cjs +15 -10
- package/dist/chat_models/base.cjs.map +1 -1
- package/dist/chat_models/base.d.cts +20 -20
- package/dist/chat_models/base.d.cts.map +1 -1
- package/dist/chat_models/base.d.ts +20 -20
- package/dist/chat_models/base.d.ts.map +1 -1
- package/dist/chat_models/base.js +11 -6
- package/dist/chat_models/base.js.map +1 -1
- package/dist/chat_models/completions.cjs +6 -7
- package/dist/chat_models/completions.cjs.map +1 -1
- package/dist/chat_models/completions.d.cts +6 -6
- package/dist/chat_models/completions.d.cts.map +1 -1
- package/dist/chat_models/completions.d.ts +6 -6
- package/dist/chat_models/completions.d.ts.map +1 -1
- package/dist/chat_models/completions.js +1 -2
- package/dist/chat_models/completions.js.map +1 -1
- package/dist/chat_models/index.cjs +6 -7
- package/dist/chat_models/index.cjs.map +1 -1
- package/dist/chat_models/index.js +1 -2
- package/dist/chat_models/index.js.map +1 -1
- package/dist/chat_models/profiles.cjs +1 -2
- package/dist/chat_models/profiles.cjs.map +1 -1
- package/dist/chat_models/profiles.js +1 -1
- package/dist/chat_models/responses.cjs +17 -14
- package/dist/chat_models/responses.cjs.map +1 -1
- package/dist/chat_models/responses.d.cts +8 -8
- package/dist/chat_models/responses.d.cts.map +1 -1
- package/dist/chat_models/responses.d.ts +8 -8
- package/dist/chat_models/responses.d.ts.map +1 -1
- package/dist/chat_models/responses.js +13 -10
- package/dist/chat_models/responses.js.map +1 -1
- package/dist/converters/completions.cjs +3 -4
- package/dist/converters/completions.cjs.map +1 -1
- package/dist/converters/completions.d.cts +8 -8
- package/dist/converters/completions.d.cts.map +1 -1
- package/dist/converters/completions.d.ts +8 -8
- package/dist/converters/completions.d.ts.map +1 -1
- package/dist/converters/completions.js +1 -2
- package/dist/converters/completions.js.map +1 -1
- package/dist/converters/index.cjs +2 -2
- package/dist/converters/index.js +3 -4
- package/dist/converters/responses.cjs +15 -11
- package/dist/converters/responses.cjs.map +1 -1
- package/dist/converters/responses.d.cts +8 -8
- package/dist/converters/responses.d.cts.map +1 -1
- package/dist/converters/responses.d.ts +8 -8
- package/dist/converters/responses.d.ts.map +1 -1
- package/dist/converters/responses.js +12 -8
- package/dist/converters/responses.js.map +1 -1
- package/dist/embeddings.cjs +3 -4
- package/dist/embeddings.cjs.map +1 -1
- package/dist/embeddings.d.cts +4 -4
- package/dist/embeddings.d.cts.map +1 -1
- package/dist/embeddings.d.ts +4 -4
- package/dist/embeddings.d.ts.map +1 -1
- package/dist/embeddings.js +3 -4
- package/dist/embeddings.js.map +1 -1
- package/dist/index.cjs +33 -34
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -2
- package/dist/llms.cjs +4 -5
- package/dist/llms.cjs.map +1 -1
- package/dist/llms.d.cts +7 -7
- package/dist/llms.d.cts.map +1 -1
- package/dist/llms.d.ts +7 -7
- package/dist/llms.d.ts.map +1 -1
- package/dist/llms.js +4 -5
- package/dist/llms.js.map +1 -1
- package/dist/tools/applyPatch.cjs +1 -2
- package/dist/tools/applyPatch.cjs.map +1 -1
- package/dist/tools/applyPatch.d.cts +6 -6
- package/dist/tools/applyPatch.d.cts.map +1 -1
- package/dist/tools/applyPatch.d.ts +6 -6
- package/dist/tools/applyPatch.d.ts.map +1 -1
- package/dist/tools/applyPatch.js +1 -2
- package/dist/tools/applyPatch.js.map +1 -1
- package/dist/tools/codeInterpreter.cjs +1 -2
- package/dist/tools/codeInterpreter.cjs.map +1 -1
- package/dist/tools/codeInterpreter.d.cts +2 -2
- package/dist/tools/codeInterpreter.d.cts.map +1 -1
- package/dist/tools/codeInterpreter.d.ts +2 -2
- package/dist/tools/codeInterpreter.d.ts.map +1 -1
- package/dist/tools/codeInterpreter.js +1 -1
- package/dist/tools/computerUse.cjs +1 -2
- package/dist/tools/computerUse.cjs.map +1 -1
- package/dist/tools/computerUse.d.cts +12 -12
- package/dist/tools/computerUse.d.cts.map +1 -1
- package/dist/tools/computerUse.d.ts +12 -12
- package/dist/tools/computerUse.d.ts.map +1 -1
- package/dist/tools/computerUse.js +1 -2
- package/dist/tools/computerUse.js.map +1 -1
- package/dist/tools/custom.cjs +1 -2
- package/dist/tools/custom.cjs.map +1 -1
- package/dist/tools/custom.d.cts +2 -2
- package/dist/tools/custom.d.cts.map +1 -1
- package/dist/tools/custom.d.ts +2 -2
- package/dist/tools/custom.d.ts.map +1 -1
- package/dist/tools/custom.js +1 -2
- package/dist/tools/custom.js.map +1 -1
- package/dist/tools/dalle.cjs +1 -2
- package/dist/tools/dalle.cjs.map +1 -1
- package/dist/tools/dalle.d.cts +3 -3
- package/dist/tools/dalle.d.cts.map +1 -1
- package/dist/tools/dalle.d.ts +3 -3
- package/dist/tools/dalle.d.ts.map +1 -1
- package/dist/tools/dalle.js +3 -4
- package/dist/tools/dalle.js.map +1 -1
- package/dist/tools/fileSearch.cjs +1 -2
- package/dist/tools/fileSearch.cjs.map +1 -1
- package/dist/tools/fileSearch.d.cts +2 -2
- package/dist/tools/fileSearch.d.cts.map +1 -1
- package/dist/tools/fileSearch.d.ts +2 -2
- package/dist/tools/fileSearch.d.ts.map +1 -1
- package/dist/tools/fileSearch.js +1 -1
- package/dist/tools/fileSearch.js.map +1 -1
- package/dist/tools/imageGeneration.cjs +1 -2
- package/dist/tools/imageGeneration.cjs.map +1 -1
- package/dist/tools/imageGeneration.d.cts +2 -2
- package/dist/tools/imageGeneration.d.cts.map +1 -1
- package/dist/tools/imageGeneration.d.ts +2 -2
- package/dist/tools/imageGeneration.d.ts.map +1 -1
- package/dist/tools/imageGeneration.js +1 -1
- package/dist/tools/imageGeneration.js.map +1 -1
- package/dist/tools/index.cjs +14 -13
- package/dist/tools/index.cjs.map +1 -1
- package/dist/tools/index.d.cts +2 -0
- package/dist/tools/index.d.cts.map +1 -1
- package/dist/tools/index.d.ts +2 -0
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +5 -4
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/localShell.cjs +1 -2
- package/dist/tools/localShell.cjs.map +1 -1
- package/dist/tools/localShell.d.cts +4 -4
- package/dist/tools/localShell.d.cts.map +1 -1
- package/dist/tools/localShell.d.ts +4 -4
- package/dist/tools/localShell.d.ts.map +1 -1
- package/dist/tools/localShell.js +1 -2
- package/dist/tools/localShell.js.map +1 -1
- package/dist/tools/mcp.cjs +1 -2
- package/dist/tools/mcp.cjs.map +1 -1
- package/dist/tools/mcp.d.cts +2 -2
- package/dist/tools/mcp.d.cts.map +1 -1
- package/dist/tools/mcp.d.ts +2 -2
- package/dist/tools/mcp.d.ts.map +1 -1
- package/dist/tools/mcp.js +1 -1
- package/dist/tools/mcp.js.map +1 -1
- package/dist/tools/shell.cjs +1 -2
- package/dist/tools/shell.cjs.map +1 -1
- package/dist/tools/shell.d.cts +5 -5
- package/dist/tools/shell.d.cts.map +1 -1
- package/dist/tools/shell.d.ts +5 -5
- package/dist/tools/shell.d.ts.map +1 -1
- package/dist/tools/shell.js +1 -2
- package/dist/tools/shell.js.map +1 -1
- package/dist/tools/toolSearch.cjs +67 -0
- package/dist/tools/toolSearch.cjs.map +1 -0
- package/dist/tools/toolSearch.d.cts +79 -0
- package/dist/tools/toolSearch.d.cts.map +1 -0
- package/dist/tools/toolSearch.d.ts +79 -0
- package/dist/tools/toolSearch.d.ts.map +1 -0
- package/dist/tools/toolSearch.js +67 -0
- package/dist/tools/toolSearch.js.map +1 -0
- package/dist/tools/webSearch.cjs +1 -2
- package/dist/tools/webSearch.cjs.map +1 -1
- package/dist/tools/webSearch.d.cts +2 -2
- package/dist/tools/webSearch.d.cts.map +1 -1
- package/dist/tools/webSearch.d.ts +2 -2
- package/dist/tools/webSearch.d.ts.map +1 -1
- package/dist/tools/webSearch.js +1 -1
- package/dist/tools/webSearch.js.map +1 -1
- package/dist/types.d.cts +10 -10
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.ts +10 -10
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/azure.cjs +2 -3
- package/dist/utils/azure.cjs.map +1 -1
- package/dist/utils/azure.js +1 -2
- package/dist/utils/azure.js.map +1 -1
- package/dist/utils/client.cjs +2 -3
- package/dist/utils/client.cjs.map +1 -1
- package/dist/utils/client.js +1 -2
- package/dist/utils/client.js.map +1 -1
- package/dist/utils/errors.cjs +1 -2
- package/dist/utils/errors.cjs.map +1 -1
- package/dist/utils/errors.js +1 -1
- package/dist/utils/errors.js.map +1 -1
- package/dist/utils/misc.cjs +1 -2
- package/dist/utils/misc.cjs.map +1 -1
- package/dist/utils/misc.d.cts +2 -2
- package/dist/utils/misc.d.cts.map +1 -1
- package/dist/utils/misc.d.ts +2 -2
- package/dist/utils/misc.d.ts.map +1 -1
- package/dist/utils/misc.js +1 -2
- package/dist/utils/misc.js.map +1 -1
- package/dist/utils/output.cjs +1 -2
- package/dist/utils/output.cjs.map +1 -1
- package/dist/utils/output.js +1 -2
- package/dist/utils/output.js.map +1 -1
- package/dist/utils/prompts.cjs +2 -3
- package/dist/utils/prompts.cjs.map +1 -1
- package/dist/utils/prompts.d.cts +2 -2
- package/dist/utils/prompts.d.cts.map +1 -1
- package/dist/utils/prompts.d.ts +2 -2
- package/dist/utils/prompts.d.ts.map +1 -1
- package/dist/utils/prompts.js +1 -2
- package/dist/utils/prompts.js.map +1 -1
- package/dist/utils/tools.cjs +3 -4
- package/dist/utils/tools.cjs.map +1 -1
- package/dist/utils/tools.d.cts +5 -5
- package/dist/utils/tools.d.cts.map +1 -1
- package/dist/utils/tools.d.ts +5 -6
- package/dist/utils/tools.d.ts.map +1 -1
- package/dist/utils/tools.js +3 -4
- package/dist/utils/tools.js.map +1 -1
- package/package.json +5 -5
|
@@ -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;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;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"}
|
package/dist/tools/index.cjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
const require_webSearch = require(
|
|
3
|
-
const require_mcp = require(
|
|
4
|
-
const require_codeInterpreter = require(
|
|
5
|
-
const require_fileSearch = require(
|
|
6
|
-
const require_imageGeneration = require(
|
|
7
|
-
const require_computerUse = require(
|
|
8
|
-
const require_localShell = require(
|
|
9
|
-
const require_shell = require(
|
|
10
|
-
const require_applyPatch = require(
|
|
11
|
-
|
|
1
|
+
require("./dalle.cjs");
|
|
2
|
+
const require_webSearch = require("./webSearch.cjs");
|
|
3
|
+
const require_mcp = require("./mcp.cjs");
|
|
4
|
+
const require_codeInterpreter = require("./codeInterpreter.cjs");
|
|
5
|
+
const require_fileSearch = require("./fileSearch.cjs");
|
|
6
|
+
const require_imageGeneration = require("./imageGeneration.cjs");
|
|
7
|
+
const require_computerUse = require("./computerUse.cjs");
|
|
8
|
+
const require_localShell = require("./localShell.cjs");
|
|
9
|
+
const require_shell = require("./shell.cjs");
|
|
10
|
+
const require_applyPatch = require("./applyPatch.cjs");
|
|
11
|
+
const require_toolSearch = require("./toolSearch.cjs");
|
|
12
12
|
//#region src/tools/index.ts
|
|
13
13
|
const tools = {
|
|
14
14
|
webSearch: require_webSearch.webSearch,
|
|
@@ -19,9 +19,10 @@ const tools = {
|
|
|
19
19
|
computerUse: require_computerUse.computerUse,
|
|
20
20
|
localShell: require_localShell.localShell,
|
|
21
21
|
shell: require_shell.shell,
|
|
22
|
-
applyPatch: require_applyPatch.applyPatch
|
|
22
|
+
applyPatch: require_applyPatch.applyPatch,
|
|
23
|
+
toolSearch: require_toolSearch.toolSearch
|
|
23
24
|
};
|
|
24
|
-
|
|
25
25
|
//#endregion
|
|
26
26
|
exports.tools = tools;
|
|
27
|
+
|
|
27
28
|
//# sourceMappingURL=index.cjs.map
|
package/dist/tools/index.cjs.map
CHANGED
|
@@ -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\nexport const tools = {\n webSearch,\n mcp,\n codeInterpreter,\n fileSearch,\n imageGeneration,\n computerUse,\n localShell,\n shell,\n applyPatch,\n};\n"],"mappings":";;;;;;;;;;;;
|
|
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"}
|
package/dist/tools/index.d.cts
CHANGED
|
@@ -8,6 +8,7 @@ import { ComputerUseAction, ComputerUseClickAction, ComputerUseDoubleClickAction
|
|
|
8
8
|
import { LocalShellAction, LocalShellOptions, LocalShellTool, localShell } from "./localShell.cjs";
|
|
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
|
+
import { ToolSearchOptions, ToolSearchTool, toolSearch } from "./toolSearch.cjs";
|
|
11
12
|
|
|
12
13
|
//#region src/tools/index.d.ts
|
|
13
14
|
declare const tools: {
|
|
@@ -20,6 +21,7 @@ declare const tools: {
|
|
|
20
21
|
localShell: typeof localShell;
|
|
21
22
|
shell: typeof shell;
|
|
22
23
|
applyPatch: typeof applyPatch;
|
|
24
|
+
toolSearch: typeof toolSearch;
|
|
23
25
|
};
|
|
24
26
|
//#endregion
|
|
25
27
|
export { tools };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/tools/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/tools/index.ts"],"mappings":";;;;;;;;;;;;;cA8Fa,KAAA"}
|
package/dist/tools/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { ComputerUseAction, ComputerUseClickAction, ComputerUseDoubleClickAction
|
|
|
8
8
|
import { LocalShellAction, LocalShellOptions, LocalShellTool, localShell } from "./localShell.js";
|
|
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
|
+
import { ToolSearchOptions, ToolSearchTool, toolSearch } from "./toolSearch.js";
|
|
11
12
|
|
|
12
13
|
//#region src/tools/index.d.ts
|
|
13
14
|
declare const tools: {
|
|
@@ -20,6 +21,7 @@ declare const tools: {
|
|
|
20
21
|
localShell: typeof localShell;
|
|
21
22
|
shell: typeof shell;
|
|
22
23
|
applyPatch: typeof applyPatch;
|
|
24
|
+
toolSearch: typeof toolSearch;
|
|
23
25
|
};
|
|
24
26
|
//#endregion
|
|
25
27
|
export { tools };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/tools/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/tools/index.ts"],"mappings":";;;;;;;;;;;;;cA8Fa,KAAA"}
|
package/dist/tools/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "./dalle.js";
|
|
2
2
|
import { webSearch } from "./webSearch.js";
|
|
3
3
|
import { mcp } from "./mcp.js";
|
|
4
4
|
import { codeInterpreter } from "./codeInterpreter.js";
|
|
@@ -8,7 +8,7 @@ import { computerUse } from "./computerUse.js";
|
|
|
8
8
|
import { localShell } from "./localShell.js";
|
|
9
9
|
import { shell } from "./shell.js";
|
|
10
10
|
import { applyPatch } from "./applyPatch.js";
|
|
11
|
-
|
|
11
|
+
import { toolSearch } from "./toolSearch.js";
|
|
12
12
|
//#region src/tools/index.ts
|
|
13
13
|
const tools = {
|
|
14
14
|
webSearch,
|
|
@@ -19,9 +19,10 @@ const tools = {
|
|
|
19
19
|
computerUse,
|
|
20
20
|
localShell,
|
|
21
21
|
shell,
|
|
22
|
-
applyPatch
|
|
22
|
+
applyPatch,
|
|
23
|
+
toolSearch
|
|
23
24
|
};
|
|
24
|
-
|
|
25
25
|
//#endregion
|
|
26
26
|
export { tools };
|
|
27
|
+
|
|
27
28
|
//# sourceMappingURL=index.js.map
|
package/dist/tools/index.js.map
CHANGED
|
@@ -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\nexport const tools = {\n webSearch,\n mcp,\n codeInterpreter,\n fileSearch,\n imageGeneration,\n computerUse,\n localShell,\n shell,\n applyPatch,\n};\n"],"mappings":";;;;;;;;;;;;
|
|
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,6 +1,5 @@
|
|
|
1
1
|
let _langchain_core_tools = require("@langchain/core/tools");
|
|
2
2
|
let zod_v4 = require("zod/v4");
|
|
3
|
-
|
|
4
3
|
//#region src/tools/localShell.ts
|
|
5
4
|
const LocalShellExecActionSchema = zod_v4.z.object({
|
|
6
5
|
type: zod_v4.z.literal("exec"),
|
|
@@ -138,7 +137,7 @@ function localShell(options) {
|
|
|
138
137
|
};
|
|
139
138
|
return shellTool;
|
|
140
139
|
}
|
|
141
|
-
|
|
142
140
|
//#endregion
|
|
143
141
|
exports.localShell = localShell;
|
|
142
|
+
|
|
144
143
|
//# 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":"
|
|
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,4 +1,4 @@
|
|
|
1
|
-
import { OpenAI
|
|
1
|
+
import { OpenAI } from "openai";
|
|
2
2
|
import { DynamicStructuredTool } from "@langchain/core/tools";
|
|
3
3
|
import { z } from "zod/v4";
|
|
4
4
|
|
|
@@ -8,7 +8,7 @@ import { z } from "zod/v4";
|
|
|
8
8
|
* The action contains command details like argv tokens, environment variables,
|
|
9
9
|
* working directory, timeout, and user.
|
|
10
10
|
*/
|
|
11
|
-
type LocalShellAction = OpenAI
|
|
11
|
+
type LocalShellAction = OpenAI.Responses.ResponseOutputItem.LocalShellCall.Action;
|
|
12
12
|
/**
|
|
13
13
|
* Options for the Local Shell tool.
|
|
14
14
|
*/
|
|
@@ -38,7 +38,7 @@ interface LocalShellOptions {
|
|
|
38
38
|
/**
|
|
39
39
|
* OpenAI Local Shell tool type for the Responses API.
|
|
40
40
|
*/
|
|
41
|
-
type LocalShellTool = OpenAI
|
|
41
|
+
type LocalShellTool = OpenAI.Responses.Tool.LocalShell;
|
|
42
42
|
/**
|
|
43
43
|
* Creates a Local Shell tool that allows models to run shell commands locally
|
|
44
44
|
* on a machine you provide. Commands are executed inside your own runtime—
|
|
@@ -160,7 +160,7 @@ declare function localShell(options: LocalShellOptions): DynamicStructuredTool<z
|
|
|
160
160
|
working_directory: z.ZodOptional<z.ZodString>;
|
|
161
161
|
timeout_ms: z.ZodOptional<z.ZodNumber>;
|
|
162
162
|
user: z.ZodOptional<z.ZodString>;
|
|
163
|
-
}, z.core.$strip>]>, OpenAI
|
|
163
|
+
}, z.core.$strip>]>, OpenAI.Responses.ResponseOutputItem.LocalShellCall.Action, unknown, string, unknown, string>;
|
|
164
164
|
//#endregion
|
|
165
165
|
export { LocalShellAction, LocalShellOptions, LocalShellTool, localShell };
|
|
166
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,
|
|
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;;AA6C3D;;UA3BiB,iBAAA;EA2BkD;;;;;;;AAsHnE;;;;;;;;;;;;;EA5HE,OAAA,GAAU,MAAA,EAAQ,gBAAA,cAA8B,OAAA;AAAA;;;;KAMtC,cAAA,GAAiB,MAAA,CAAa,SAAA,CAAU,IAAA,CAAK,UAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAsHzC,UAAA,CAAW,OAAA,EAAS,iBAAA,GAAiB,qBAAA,CAAA,CAAA,CAAA,QAAA,WAAA,CAAA,CAAA,SAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OpenAI
|
|
1
|
+
import { OpenAI } from "openai";
|
|
2
2
|
import { DynamicStructuredTool } from "@langchain/core/tools";
|
|
3
3
|
import { z } from "zod/v4";
|
|
4
4
|
|
|
@@ -8,7 +8,7 @@ import { z } from "zod/v4";
|
|
|
8
8
|
* The action contains command details like argv tokens, environment variables,
|
|
9
9
|
* working directory, timeout, and user.
|
|
10
10
|
*/
|
|
11
|
-
type LocalShellAction = OpenAI
|
|
11
|
+
type LocalShellAction = OpenAI.Responses.ResponseOutputItem.LocalShellCall.Action;
|
|
12
12
|
/**
|
|
13
13
|
* Options for the Local Shell tool.
|
|
14
14
|
*/
|
|
@@ -38,7 +38,7 @@ interface LocalShellOptions {
|
|
|
38
38
|
/**
|
|
39
39
|
* OpenAI Local Shell tool type for the Responses API.
|
|
40
40
|
*/
|
|
41
|
-
type LocalShellTool = OpenAI
|
|
41
|
+
type LocalShellTool = OpenAI.Responses.Tool.LocalShell;
|
|
42
42
|
/**
|
|
43
43
|
* Creates a Local Shell tool that allows models to run shell commands locally
|
|
44
44
|
* on a machine you provide. Commands are executed inside your own runtime—
|
|
@@ -160,7 +160,7 @@ declare function localShell(options: LocalShellOptions): DynamicStructuredTool<z
|
|
|
160
160
|
working_directory: z.ZodOptional<z.ZodString>;
|
|
161
161
|
timeout_ms: z.ZodOptional<z.ZodNumber>;
|
|
162
162
|
user: z.ZodOptional<z.ZodString>;
|
|
163
|
-
}, z.core.$strip>]>, OpenAI
|
|
163
|
+
}, z.core.$strip>]>, OpenAI.Responses.ResponseOutputItem.LocalShellCall.Action, unknown, string, unknown, string>;
|
|
164
164
|
//#endregion
|
|
165
165
|
export { LocalShellAction, LocalShellOptions, LocalShellTool, localShell };
|
|
166
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,
|
|
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;;AA6C3D;;UA3BiB,iBAAA;EA2BkD;;;;;;;AAsHnE;;;;;;;;;;;;;EA5HE,OAAA,GAAU,MAAA,EAAQ,gBAAA,cAA8B,OAAA;AAAA;;;;KAMtC,cAAA,GAAiB,MAAA,CAAa,SAAA,CAAU,IAAA,CAAK,UAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAsHzC,UAAA,CAAW,OAAA,EAAS,iBAAA,GAAiB,qBAAA,CAAA,CAAA,CAAA,QAAA,WAAA,CAAA,CAAA,SAAA"}
|
package/dist/tools/localShell.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { tool } from "@langchain/core/tools";
|
|
2
2
|
import { z } from "zod/v4";
|
|
3
|
-
|
|
4
3
|
//#region src/tools/localShell.ts
|
|
5
4
|
const LocalShellExecActionSchema = z.object({
|
|
6
5
|
type: z.literal("exec"),
|
|
@@ -138,7 +137,7 @@ function localShell(options) {
|
|
|
138
137
|
};
|
|
139
138
|
return shellTool;
|
|
140
139
|
}
|
|
141
|
-
|
|
142
140
|
//#endregion
|
|
143
141
|
export { localShell };
|
|
142
|
+
|
|
144
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":"
|
|
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"}
|
package/dist/tools/mcp.cjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
//#region src/tools/mcp.ts
|
|
3
2
|
/**
|
|
4
3
|
* Converts a McpToolFilter to the API format.
|
|
@@ -47,7 +46,7 @@ function mcp(options) {
|
|
|
47
46
|
connector_id: options.connectorId
|
|
48
47
|
};
|
|
49
48
|
}
|
|
50
|
-
|
|
51
49
|
//#endregion
|
|
52
50
|
exports.mcp = mcp;
|
|
51
|
+
|
|
53
52
|
//# sourceMappingURL=mcp.cjs.map
|
package/dist/tools/mcp.cjs.map
CHANGED
|
@@ -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":"
|
|
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"}
|
package/dist/tools/mcp.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OpenAI
|
|
1
|
+
import { OpenAI } from "openai";
|
|
2
2
|
import { ServerTool } from "@langchain/core/tools";
|
|
3
3
|
|
|
4
4
|
//#region src/tools/mcp.d.ts
|
|
@@ -104,7 +104,7 @@ interface McpConnectorOptions extends McpBaseOptions {
|
|
|
104
104
|
/**
|
|
105
105
|
* OpenAI MCP tool type for the Responses API.
|
|
106
106
|
*/
|
|
107
|
-
type McpTool = OpenAI
|
|
107
|
+
type McpTool = OpenAI.Responses.Tool.Mcp;
|
|
108
108
|
/**
|
|
109
109
|
* Creates an MCP tool that connects to a remote MCP server or OpenAI service connector.
|
|
110
110
|
* This allows OpenAI models to access external tools and services via the Model Context Protocol.
|
package/dist/tools/mcp.d.cts.map
CHANGED
|
@@ -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,
|
|
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"}
|
package/dist/tools/mcp.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OpenAI
|
|
1
|
+
import { OpenAI } from "openai";
|
|
2
2
|
import { ServerTool } from "@langchain/core/tools";
|
|
3
3
|
|
|
4
4
|
//#region src/tools/mcp.d.ts
|
|
@@ -104,7 +104,7 @@ interface McpConnectorOptions extends McpBaseOptions {
|
|
|
104
104
|
/**
|
|
105
105
|
* OpenAI MCP tool type for the Responses API.
|
|
106
106
|
*/
|
|
107
|
-
type McpTool = OpenAI
|
|
107
|
+
type McpTool = OpenAI.Responses.Tool.Mcp;
|
|
108
108
|
/**
|
|
109
109
|
* Creates an MCP tool that connects to a remote MCP server or OpenAI service connector.
|
|
110
110
|
* This allows OpenAI models to access external tools and services via the Model Context Protocol.
|
package/dist/tools/mcp.d.ts.map
CHANGED
|
@@ -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,
|
|
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"}
|
package/dist/tools/mcp.js
CHANGED
package/dist/tools/mcp.js.map
CHANGED
|
@@ -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;AAC1B,KAAI,MAAM,QAAQ,aAAa,CAAE,QAAO;AACxC,QAAO,kBAAkB,aAAa;;;;;AAMxC,SAAS,uBACP,iBAKY;AACZ,KAAI,CAAC,gBAAiB,QAAO;AAC7B,KAAI,OAAO,oBAAoB,SAAU,QAAO;AAChD,QAAO;EACL,QAAQ,gBAAgB,SACpB,kBAAkB,gBAAgB,OAAO,GACzC;EACJ,OAAO,gBAAgB,QACnB,kBAAkB,gBAAgB,MAAM,GACxC;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;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"}
|
package/dist/tools/shell.cjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
let _langchain_core_tools = require("@langchain/core/tools");
|
|
2
2
|
let zod_v4 = require("zod/v4");
|
|
3
|
-
|
|
4
3
|
//#region src/tools/shell.ts
|
|
5
4
|
const ShellActionSchema = zod_v4.z.object({
|
|
6
5
|
commands: zod_v4.z.array(zod_v4.z.string()).describe("Array of shell commands to execute"),
|
|
@@ -156,7 +155,7 @@ function shell(options) {
|
|
|
156
155
|
};
|
|
157
156
|
return shellTool;
|
|
158
157
|
}
|
|
159
|
-
|
|
160
158
|
//#endregion
|
|
161
159
|
exports.shell = shell;
|
|
160
|
+
|
|
162
161
|
//# sourceMappingURL=shell.cjs.map
|