@langchain/anthropic 1.3.12 → 1.3.13
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/CHANGELOG.md +24 -0
- package/dist/chat_models.cjs +6 -2
- package/dist/chat_models.cjs.map +1 -1
- package/dist/chat_models.js +6 -2
- package/dist/chat_models.js.map +1 -1
- package/dist/tools/bash.d.ts +7 -7
- package/dist/tools/bash.d.ts.map +1 -1
- package/dist/tools/computer.d.ts +101 -101
- package/dist/tools/computer.d.ts.map +1 -1
- package/dist/tools/memory.d.ts +27 -27
- package/dist/tools/memory.d.ts.map +1 -1
- package/dist/tools/textEditor.d.ts +21 -21
- package/dist/tools/textEditor.d.ts.map +1 -1
- package/dist/utils/message_inputs.cjs +23 -0
- package/dist/utils/message_inputs.cjs.map +1 -1
- package/dist/utils/message_inputs.js +23 -0
- package/dist/utils/message_inputs.js.map +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"computer.d.ts","names":["zod_v4_core9","ToolMessage","DynamicStructuredTool","ToolRuntime","Computer20251124Action","Computer20250124Action","ComputerUseReturnType","Promise","Computer20251124Options","TState","TContext","computer_20251124","zod46","ZodLiteral","$strip","ZodObject","ZodNumber","ZodTuple","ZodEnum","ZodString","ZodOptional","ZodDiscriminatedUnion","Computer20250124Options","computer_20250124"],"sources":["../../src/tools/computer.d.ts"],"sourcesContent":["import { ToolMessage } from \"@langchain/core/messages\";\nimport type { DynamicStructuredTool, ToolRuntime } from \"@langchain/core/tools\";\nimport type { Computer20251124Action, Computer20250124Action } from \"./types.js\";\nexport type ComputerUseReturnType = string | Promise<string> | ToolMessage<any> | Promise<ToolMessage<any>>;\n/**\n * Options for the computer use tool (Claude Opus 4.5 only version).\n *\n * @template TState - The type of the state schema (when used with `ReactAgent`)\n * @template TContext - The type of the context schema (when used with `ReactAgent`)\n */\nexport interface Computer20251124Options<TState = any, TContext = any> {\n /**\n * The width of the display in pixels.\n */\n displayWidthPx: number;\n /**\n * The height of the display in pixels.\n */\n displayHeightPx: number;\n /**\n * Optional display number for X11 environments.\n */\n displayNumber?: number;\n /**\n * Enable zoom action for detailed screen region inspection.\n * When enabled, Claude can zoom into specific screen regions.\n * @default false\n */\n enableZoom?: boolean;\n /**\n * Optional execute function that handles computer action execution.\n * This function receives the action input and should return the result\n * (typically a base64-encoded screenshot or action confirmation).\n */\n execute?: (args: Computer20251124Action, runtime: ToolRuntime<TState, TContext>) => ComputerUseReturnType;\n}\n/**\n * Creates an Anthropic computer use tool for Claude Opus 4.5 that provides\n * screenshot capabilities and mouse/keyboard control for autonomous desktop interaction.\n *\n * The computer use tool enables Claude to interact with desktop environments through:\n * - **Screenshot capture**: See what's currently displayed on screen\n * - **Mouse control**: Click, drag, and move the cursor\n * - **Keyboard input**: Type text and use keyboard shortcuts\n * - **Zoom**: View specific screen regions at full resolution (when enabled)\n *\n * @warning Computer use is a beta feature with unique risks. Use a dedicated virtual machine\n * or container with minimal privileges. Avoid giving access to sensitive data.\n *\n * @see {@link https://platform.claude.com/docs/en/agents-and-tools/tool-use/computer-use-tool | Anthropic Computer Use Documentation}\n *\n * @example\n * ```typescript\n * import { ChatAnthropic, tools } from \"@langchain/anthropic\";\n *\n * const llm = new ChatAnthropic({\n * model: \"claude-opus-4-5-20251101\",\n * clientOptions: {\n * defaultHeaders: {\n * \"anthropic-beta\": \"computer-use-2025-11-24\",\n * },\n * },\n * });\n *\n * const computer = tools.computer_20251124({\n * displayWidthPx: 1024,\n * displayHeightPx: 768,\n * displayNumber: 1,\n * enableZoom: true,\n * execute: async (action) => {\n * if (action.action === \"screenshot\") {\n * // Capture and return base64-encoded screenshot\n * return captureScreenshot();\n * }\n * if (action.action === \"left_click\") {\n * // Click at the specified coordinates\n * await click(action.coordinate[0], action.coordinate[1]);\n * return captureScreenshot();\n * }\n * // Handle other actions...\n * },\n * });\n *\n * const llmWithComputer = llm.bindTools([computer]);\n * const response = await llmWithComputer.invoke(\n * \"Save a picture of a cat to my desktop.\"\n * );\n * ```\n *\n * @param options - Configuration options for the computer use tool\n * @returns The computer use tool object that can be passed to `bindTools`\n */\nexport declare function computer_20251124(options: Computer20251124Options): DynamicStructuredTool<import(\"zod\").ZodDiscriminatedUnion<[import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"screenshot\">;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"left_click\">;\n coordinate: import(\"zod\").ZodTuple<[import(\"zod\").ZodNumber, import(\"zod\").ZodNumber], null>;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"right_click\">;\n coordinate: import(\"zod\").ZodTuple<[import(\"zod\").ZodNumber, import(\"zod\").ZodNumber], null>;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"middle_click\">;\n coordinate: import(\"zod\").ZodTuple<[import(\"zod\").ZodNumber, import(\"zod\").ZodNumber], null>;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"double_click\">;\n coordinate: import(\"zod\").ZodTuple<[import(\"zod\").ZodNumber, import(\"zod\").ZodNumber], null>;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"triple_click\">;\n coordinate: import(\"zod\").ZodTuple<[import(\"zod\").ZodNumber, import(\"zod\").ZodNumber], null>;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"left_click_drag\">;\n start_coordinate: import(\"zod\").ZodTuple<[import(\"zod\").ZodNumber, import(\"zod\").ZodNumber], null>;\n end_coordinate: import(\"zod\").ZodTuple<[import(\"zod\").ZodNumber, import(\"zod\").ZodNumber], null>;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"left_mouse_down\">;\n coordinate: import(\"zod\").ZodTuple<[import(\"zod\").ZodNumber, import(\"zod\").ZodNumber], null>;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"left_mouse_up\">;\n coordinate: import(\"zod\").ZodTuple<[import(\"zod\").ZodNumber, import(\"zod\").ZodNumber], null>;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"scroll\">;\n coordinate: import(\"zod\").ZodTuple<[import(\"zod\").ZodNumber, import(\"zod\").ZodNumber], null>;\n scroll_direction: import(\"zod\").ZodEnum<{\n down: \"down\";\n left: \"left\";\n right: \"right\";\n up: \"up\";\n }>;\n scroll_amount: import(\"zod\").ZodNumber;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"type\">;\n text: import(\"zod\").ZodString;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"key\">;\n key: import(\"zod\").ZodString;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"mouse_move\">;\n coordinate: import(\"zod\").ZodTuple<[import(\"zod\").ZodNumber, import(\"zod\").ZodNumber], null>;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"hold_key\">;\n key: import(\"zod\").ZodString;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"wait\">;\n duration: import(\"zod\").ZodOptional<import(\"zod\").ZodNumber>;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"zoom\">;\n region: import(\"zod\").ZodTuple<[import(\"zod\").ZodNumber, import(\"zod\").ZodNumber, import(\"zod\").ZodNumber, import(\"zod\").ZodNumber], null>;\n}, import(\"zod/v4/core\").$strip>], \"action\">, Computer20251124Action, any, ToolMessage<any>, string>;\n/**\n * Options for the computer use tool.\n *\n * Supported models: Claude Sonnet 4.5, Haiku 4.5, Opus 4.1, Sonnet 4, Opus 4, and Sonnet 3.7 versions.\n */\nexport interface Computer20250124Options<TState = any, TContext = any> {\n /**\n * The width of the display in pixels.\n */\n displayWidthPx: number;\n /**\n * The height of the display in pixels.\n */\n displayHeightPx: number;\n /**\n * Optional display number for X11 environments.\n */\n displayNumber?: number;\n /**\n * Optional execute function that handles computer action execution.\n * This function receives the action input and should return the result\n * (typically a base64-encoded screenshot or action confirmation).\n */\n execute?: (args: Computer20250124Action, runtime: ToolRuntime<TState, TContext>) => ComputerUseReturnType;\n}\n/**\n * Creates an Anthropic computer use tool that provides screenshot capabilities and mouse/keyboard control\n * for autonomous desktop interaction.\n *\n * Supported models: Claude Sonnet 4.5, Haiku 4.5, Opus 4.1, Sonnet 4, Opus 4, and Sonnet 3.7 versions.\n *\n * The computer use tool enables Claude to interact with desktop environments through:\n * - **Screenshot capture**: See what's currently displayed on screen\n * - **Mouse control**: Click, drag, and move the cursor\n * - **Keyboard input**: Type text and use keyboard shortcuts\n *\n * @warning Computer use is a beta feature with unique risks. Use a dedicated virtual machine\n * or container with minimal privileges. Avoid giving access to sensitive data.\n *\n * @see {@link https://platform.claude.com/docs/en/agents-and-tools/tool-use/computer-use-tool | Anthropic Computer Use Documentation}\n *\n * @example\n * ```typescript\n * import { ChatAnthropic, tools } from \"@langchain/anthropic\";\n *\n * const llm = new ChatAnthropic({\n * model: \"claude-sonnet-4-5-20250929\",\n * clientOptions: {\n * defaultHeaders: {\n * \"anthropic-beta\": \"computer-use-2025-01-24\",\n * },\n * },\n * });\n *\n * const computer = tools.computer_20250124({\n * displayWidthPx: 1024,\n * displayHeightPx: 768,\n * displayNumber: 1,\n * execute: async (action) => {\n * if (action.action === \"screenshot\") {\n * // Capture and return base64-encoded screenshot\n * return captureScreenshot();\n * }\n * if (action.action === \"left_click\") {\n * // Click at the specified coordinates\n * await click(action.coordinate[0], action.coordinate[1]);\n * return captureScreenshot();\n * }\n * // Handle other actions...\n * },\n * });\n *\n * const llmWithComputer = llm.bindTools([computer]);\n * const response = await llmWithComputer.invoke(\n * \"Save a picture of a cat to my desktop.\"\n * );\n * ```\n *\n * @param options - Configuration options for the computer use tool\n * @returns The computer use tool object that can be passed to `bindTools`\n */\nexport declare function computer_20250124(options: Computer20250124Options): DynamicStructuredTool<import(\"zod\").ZodDiscriminatedUnion<[import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"screenshot\">;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"left_click\">;\n coordinate: import(\"zod\").ZodTuple<[import(\"zod\").ZodNumber, import(\"zod\").ZodNumber], null>;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"right_click\">;\n coordinate: import(\"zod\").ZodTuple<[import(\"zod\").ZodNumber, import(\"zod\").ZodNumber], null>;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"middle_click\">;\n coordinate: import(\"zod\").ZodTuple<[import(\"zod\").ZodNumber, import(\"zod\").ZodNumber], null>;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"double_click\">;\n coordinate: import(\"zod\").ZodTuple<[import(\"zod\").ZodNumber, import(\"zod\").ZodNumber], null>;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"triple_click\">;\n coordinate: import(\"zod\").ZodTuple<[import(\"zod\").ZodNumber, import(\"zod\").ZodNumber], null>;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"left_click_drag\">;\n start_coordinate: import(\"zod\").ZodTuple<[import(\"zod\").ZodNumber, import(\"zod\").ZodNumber], null>;\n end_coordinate: import(\"zod\").ZodTuple<[import(\"zod\").ZodNumber, import(\"zod\").ZodNumber], null>;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"left_mouse_down\">;\n coordinate: import(\"zod\").ZodTuple<[import(\"zod\").ZodNumber, import(\"zod\").ZodNumber], null>;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"left_mouse_up\">;\n coordinate: import(\"zod\").ZodTuple<[import(\"zod\").ZodNumber, import(\"zod\").ZodNumber], null>;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"scroll\">;\n coordinate: import(\"zod\").ZodTuple<[import(\"zod\").ZodNumber, import(\"zod\").ZodNumber], null>;\n scroll_direction: import(\"zod\").ZodEnum<{\n down: \"down\";\n left: \"left\";\n right: \"right\";\n up: \"up\";\n }>;\n scroll_amount: import(\"zod\").ZodNumber;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"type\">;\n text: import(\"zod\").ZodString;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"key\">;\n key: import(\"zod\").ZodString;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"mouse_move\">;\n coordinate: import(\"zod\").ZodTuple<[import(\"zod\").ZodNumber, import(\"zod\").ZodNumber], null>;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"hold_key\">;\n key: import(\"zod\").ZodString;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"wait\">;\n duration: import(\"zod\").ZodOptional<import(\"zod\").ZodNumber>;\n}, import(\"zod/v4/core\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","Computer20251124Action","Computer20250124Action","ComputerUseReturnType","Promise","Computer20251124Options","TState","TContext","computer_20251124","zod21","ZodLiteral","$strip","ZodObject","ZodNumber","ZodTuple","ZodEnum","ZodString","ZodOptional","ZodDiscriminatedUnion","Computer20250124Options","computer_20250124"],"sources":["../../src/tools/computer.d.ts"],"sourcesContent":["import { ToolMessage } from \"@langchain/core/messages\";\nimport type { DynamicStructuredTool, ToolRuntime } from \"@langchain/core/tools\";\nimport type { Computer20251124Action, Computer20250124Action } from \"./types.js\";\nexport type ComputerUseReturnType = string | Promise<string> | ToolMessage<any> | Promise<ToolMessage<any>>;\n/**\n * Options for the computer use tool (Claude Opus 4.5 only version).\n *\n * @template TState - The type of the state schema (when used with `ReactAgent`)\n * @template TContext - The type of the context schema (when used with `ReactAgent`)\n */\nexport interface Computer20251124Options<TState = any, TContext = any> {\n /**\n * The width of the display in pixels.\n */\n displayWidthPx: number;\n /**\n * The height of the display in pixels.\n */\n displayHeightPx: number;\n /**\n * Optional display number for X11 environments.\n */\n displayNumber?: number;\n /**\n * Enable zoom action for detailed screen region inspection.\n * When enabled, Claude can zoom into specific screen regions.\n * @default false\n */\n enableZoom?: boolean;\n /**\n * Optional execute function that handles computer action execution.\n * This function receives the action input and should return the result\n * (typically a base64-encoded screenshot or action confirmation).\n */\n execute?: (args: Computer20251124Action, runtime: ToolRuntime<TState, TContext>) => ComputerUseReturnType;\n}\n/**\n * Creates an Anthropic computer use tool for Claude Opus 4.5 that provides\n * screenshot capabilities and mouse/keyboard control for autonomous desktop interaction.\n *\n * The computer use tool enables Claude to interact with desktop environments through:\n * - **Screenshot capture**: See what's currently displayed on screen\n * - **Mouse control**: Click, drag, and move the cursor\n * - **Keyboard input**: Type text and use keyboard shortcuts\n * - **Zoom**: View specific screen regions at full resolution (when enabled)\n *\n * @warning Computer use is a beta feature with unique risks. Use a dedicated virtual machine\n * or container with minimal privileges. Avoid giving access to sensitive data.\n *\n * @see {@link https://platform.claude.com/docs/en/agents-and-tools/tool-use/computer-use-tool | Anthropic Computer Use Documentation}\n *\n * @example\n * ```typescript\n * import { ChatAnthropic, tools } from \"@langchain/anthropic\";\n *\n * const llm = new ChatAnthropic({\n * model: \"claude-opus-4-5-20251101\",\n * clientOptions: {\n * defaultHeaders: {\n * \"anthropic-beta\": \"computer-use-2025-11-24\",\n * },\n * },\n * });\n *\n * const computer = tools.computer_20251124({\n * displayWidthPx: 1024,\n * displayHeightPx: 768,\n * displayNumber: 1,\n * enableZoom: true,\n * execute: async (action) => {\n * if (action.action === \"screenshot\") {\n * // Capture and return base64-encoded screenshot\n * return captureScreenshot();\n * }\n * if (action.action === \"left_click\") {\n * // Click at the specified coordinates\n * await click(action.coordinate[0], action.coordinate[1]);\n * return captureScreenshot();\n * }\n * // Handle other actions...\n * },\n * });\n *\n * const llmWithComputer = llm.bindTools([computer]);\n * const response = await llmWithComputer.invoke(\n * \"Save a picture of a cat to my desktop.\"\n * );\n * ```\n *\n * @param options - Configuration options for the computer use tool\n * @returns The computer use tool object that can be passed to `bindTools`\n */\nexport declare function computer_20251124(options: Computer20251124Options): DynamicStructuredTool<import(\"zod\").ZodDiscriminatedUnion<[import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"screenshot\">;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"left_click\">;\n coordinate: import(\"zod\").ZodTuple<[import(\"zod\").ZodNumber, import(\"zod\").ZodNumber], null>;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"right_click\">;\n coordinate: import(\"zod\").ZodTuple<[import(\"zod\").ZodNumber, import(\"zod\").ZodNumber], null>;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"middle_click\">;\n coordinate: import(\"zod\").ZodTuple<[import(\"zod\").ZodNumber, import(\"zod\").ZodNumber], null>;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"double_click\">;\n coordinate: import(\"zod\").ZodTuple<[import(\"zod\").ZodNumber, import(\"zod\").ZodNumber], null>;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"triple_click\">;\n coordinate: import(\"zod\").ZodTuple<[import(\"zod\").ZodNumber, import(\"zod\").ZodNumber], null>;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"left_click_drag\">;\n start_coordinate: import(\"zod\").ZodTuple<[import(\"zod\").ZodNumber, import(\"zod\").ZodNumber], null>;\n end_coordinate: import(\"zod\").ZodTuple<[import(\"zod\").ZodNumber, import(\"zod\").ZodNumber], null>;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"left_mouse_down\">;\n coordinate: import(\"zod\").ZodTuple<[import(\"zod\").ZodNumber, import(\"zod\").ZodNumber], null>;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"left_mouse_up\">;\n coordinate: import(\"zod\").ZodTuple<[import(\"zod\").ZodNumber, import(\"zod\").ZodNumber], null>;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"scroll\">;\n coordinate: import(\"zod\").ZodTuple<[import(\"zod\").ZodNumber, import(\"zod\").ZodNumber], null>;\n scroll_direction: import(\"zod\").ZodEnum<{\n down: \"down\";\n left: \"left\";\n right: \"right\";\n up: \"up\";\n }>;\n scroll_amount: import(\"zod\").ZodNumber;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"type\">;\n text: import(\"zod\").ZodString;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"key\">;\n key: import(\"zod\").ZodString;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"mouse_move\">;\n coordinate: import(\"zod\").ZodTuple<[import(\"zod\").ZodNumber, import(\"zod\").ZodNumber], null>;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"hold_key\">;\n key: import(\"zod\").ZodString;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"wait\">;\n duration: import(\"zod\").ZodOptional<import(\"zod\").ZodNumber>;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"zoom\">;\n region: import(\"zod\").ZodTuple<[import(\"zod\").ZodNumber, import(\"zod\").ZodNumber, import(\"zod\").ZodNumber, import(\"zod\").ZodNumber], null>;\n}, import(\"zod/v4/core\").$strip>], \"action\">, Computer20251124Action, any, ToolMessage<any>, string>;\n/**\n * Options for the computer use tool.\n *\n * Supported models: Claude Sonnet 4.5, Haiku 4.5, Opus 4.1, Sonnet 4, Opus 4, and Sonnet 3.7 versions.\n */\nexport interface Computer20250124Options<TState = any, TContext = any> {\n /**\n * The width of the display in pixels.\n */\n displayWidthPx: number;\n /**\n * The height of the display in pixels.\n */\n displayHeightPx: number;\n /**\n * Optional display number for X11 environments.\n */\n displayNumber?: number;\n /**\n * Optional execute function that handles computer action execution.\n * This function receives the action input and should return the result\n * (typically a base64-encoded screenshot or action confirmation).\n */\n execute?: (args: Computer20250124Action, runtime: ToolRuntime<TState, TContext>) => ComputerUseReturnType;\n}\n/**\n * Creates an Anthropic computer use tool that provides screenshot capabilities and mouse/keyboard control\n * for autonomous desktop interaction.\n *\n * Supported models: Claude Sonnet 4.5, Haiku 4.5, Opus 4.1, Sonnet 4, Opus 4, and Sonnet 3.7 versions.\n *\n * The computer use tool enables Claude to interact with desktop environments through:\n * - **Screenshot capture**: See what's currently displayed on screen\n * - **Mouse control**: Click, drag, and move the cursor\n * - **Keyboard input**: Type text and use keyboard shortcuts\n *\n * @warning Computer use is a beta feature with unique risks. Use a dedicated virtual machine\n * or container with minimal privileges. Avoid giving access to sensitive data.\n *\n * @see {@link https://platform.claude.com/docs/en/agents-and-tools/tool-use/computer-use-tool | Anthropic Computer Use Documentation}\n *\n * @example\n * ```typescript\n * import { ChatAnthropic, tools } from \"@langchain/anthropic\";\n *\n * const llm = new ChatAnthropic({\n * model: \"claude-sonnet-4-5-20250929\",\n * clientOptions: {\n * defaultHeaders: {\n * \"anthropic-beta\": \"computer-use-2025-01-24\",\n * },\n * },\n * });\n *\n * const computer = tools.computer_20250124({\n * displayWidthPx: 1024,\n * displayHeightPx: 768,\n * displayNumber: 1,\n * execute: async (action) => {\n * if (action.action === \"screenshot\") {\n * // Capture and return base64-encoded screenshot\n * return captureScreenshot();\n * }\n * if (action.action === \"left_click\") {\n * // Click at the specified coordinates\n * await click(action.coordinate[0], action.coordinate[1]);\n * return captureScreenshot();\n * }\n * // Handle other actions...\n * },\n * });\n *\n * const llmWithComputer = llm.bindTools([computer]);\n * const response = await llmWithComputer.invoke(\n * \"Save a picture of a cat to my desktop.\"\n * );\n * ```\n *\n * @param options - Configuration options for the computer use tool\n * @returns The computer use tool object that can be passed to `bindTools`\n */\nexport declare function computer_20250124(options: Computer20250124Options): DynamicStructuredTool<import(\"zod\").ZodDiscriminatedUnion<[import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"screenshot\">;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"left_click\">;\n coordinate: import(\"zod\").ZodTuple<[import(\"zod\").ZodNumber, import(\"zod\").ZodNumber], null>;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"right_click\">;\n coordinate: import(\"zod\").ZodTuple<[import(\"zod\").ZodNumber, import(\"zod\").ZodNumber], null>;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"middle_click\">;\n coordinate: import(\"zod\").ZodTuple<[import(\"zod\").ZodNumber, import(\"zod\").ZodNumber], null>;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"double_click\">;\n coordinate: import(\"zod\").ZodTuple<[import(\"zod\").ZodNumber, import(\"zod\").ZodNumber], null>;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"triple_click\">;\n coordinate: import(\"zod\").ZodTuple<[import(\"zod\").ZodNumber, import(\"zod\").ZodNumber], null>;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"left_click_drag\">;\n start_coordinate: import(\"zod\").ZodTuple<[import(\"zod\").ZodNumber, import(\"zod\").ZodNumber], null>;\n end_coordinate: import(\"zod\").ZodTuple<[import(\"zod\").ZodNumber, import(\"zod\").ZodNumber], null>;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"left_mouse_down\">;\n coordinate: import(\"zod\").ZodTuple<[import(\"zod\").ZodNumber, import(\"zod\").ZodNumber], null>;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"left_mouse_up\">;\n coordinate: import(\"zod\").ZodTuple<[import(\"zod\").ZodNumber, import(\"zod\").ZodNumber], null>;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"scroll\">;\n coordinate: import(\"zod\").ZodTuple<[import(\"zod\").ZodNumber, import(\"zod\").ZodNumber], null>;\n scroll_direction: import(\"zod\").ZodEnum<{\n down: \"down\";\n left: \"left\";\n right: \"right\";\n up: \"up\";\n }>;\n scroll_amount: import(\"zod\").ZodNumber;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"type\">;\n text: import(\"zod\").ZodString;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"key\">;\n key: import(\"zod\").ZodString;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"mouse_move\">;\n coordinate: import(\"zod\").ZodTuple<[import(\"zod\").ZodNumber, import(\"zod\").ZodNumber], null>;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"hold_key\">;\n key: import(\"zod\").ZodString;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n action: import(\"zod\").ZodLiteral<\"wait\">;\n duration: import(\"zod\").ZodOptional<import(\"zod\").ZodNumber>;\n}, import(\"zod/v4/core\").$strip>], \"action\">, Computer20250124Action, any, ComputerUseReturnType, string>;\n//# sourceMappingURL=computer.d.ts.map"],"mappings":";;;;;;;KAGYM,qBAAAA,YAAiCC,kBAAkBN,mBAAmBM,QAAQN;;;;AAA1F;;;AAA0FA,UAOzEO,uBAPyEP,CAAAA,SAAAA,GAAAA,EAAAA,WAAAA,GAAAA,CAAAA,CAAAA;EAARM;AAAO;AAOzF;EAwBqBH,cAAAA,EAAAA,MAAAA;EAA6CK;;;EAAsBH,eAAAA,EAAAA,MAAAA;EAAqB;AA0D7G;;EAA0EM,aAChDC,CAAAA,EAAAA,MAAAA;EAAUb;;;;;EAGoDY,UAA1DK,CAAAA,EAAAA,OAAAA;EAAQjB;;;;;EAGkDY,OAA1DK,CAAAA,EAAAA,CAAAA,IAAAA,EAjETb,sBAiESa,EAAAA,OAAAA,EAjEwBd,WAiExBc,CAjEoCR,MAiEpCQ,EAjE4CP,QAiE5CO,CAAAA,EAAAA,GAjE0DX,qBAiE1DW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;A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BG;UAHSH,KAAAA,CAI/BC;OAAUD,KAAAA,CACbO;GAASnB,YAAAA,CACPc,MAAAA,GAGMF,KAAAA,CAHiBG;UAHSH,KAAAA,CAI/BC;cAC8DD,KAAAA,CAA1DK,UADML,KAAAA,CACkBI,SAAAA,EAASJ,KAAAA,CAAgBI,SAAAA;GAAzChB,YAAAA,CACbc,MAAAA,GAGMF,KAAAA,CAHiBG;UAHSH,KAAAA,CAI/BC;OAAUD,KAAAA,CACbO;GAASnB,YAAAA,CACPc,MAAAA,GAGMF,KAAAA,CAHiBG;UAHSH,KAAAA,CAI/BC;YACqCD,KAAAA,CAAnCQ,YADQR,KAAAA,CACkBI,SAAAA;GAAfhB,YAAAA,CACdc,MAAAA,eAAqBT,6BAA6BC"}
|
package/dist/tools/memory.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MemoryTool20250818Options } from "./types.js";
|
|
2
2
|
import { DynamicStructuredTool } from "@langchain/core/tools";
|
|
3
|
-
import * as
|
|
4
|
-
import * as
|
|
3
|
+
import * as zod175 from "zod";
|
|
4
|
+
import * as zod_v4_core36 from "zod/v4/core";
|
|
5
5
|
|
|
6
6
|
//#region src/tools/memory.d.ts
|
|
7
7
|
|
|
@@ -38,31 +38,31 @@ import * as zod_v4_core0 from "zod/v4/core";
|
|
|
38
38
|
*
|
|
39
39
|
* @see https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/memory-tool
|
|
40
40
|
*/
|
|
41
|
-
declare function memory_20250818(options?: MemoryTool20250818Options): DynamicStructuredTool<
|
|
42
|
-
command:
|
|
43
|
-
path:
|
|
44
|
-
},
|
|
45
|
-
command:
|
|
46
|
-
path:
|
|
47
|
-
file_text:
|
|
48
|
-
},
|
|
49
|
-
command:
|
|
50
|
-
path:
|
|
51
|
-
old_str:
|
|
52
|
-
new_str:
|
|
53
|
-
},
|
|
54
|
-
command:
|
|
55
|
-
path:
|
|
56
|
-
insert_line:
|
|
57
|
-
insert_text:
|
|
58
|
-
},
|
|
59
|
-
command:
|
|
60
|
-
path:
|
|
61
|
-
},
|
|
62
|
-
command:
|
|
63
|
-
old_path:
|
|
64
|
-
new_path:
|
|
65
|
-
},
|
|
41
|
+
declare function memory_20250818(options?: MemoryTool20250818Options): DynamicStructuredTool<zod175.ZodDiscriminatedUnion<[zod175.ZodObject<{
|
|
42
|
+
command: zod175.ZodLiteral<"view">;
|
|
43
|
+
path: zod175.ZodString;
|
|
44
|
+
}, zod_v4_core36.$strip>, zod175.ZodObject<{
|
|
45
|
+
command: zod175.ZodLiteral<"create">;
|
|
46
|
+
path: zod175.ZodString;
|
|
47
|
+
file_text: zod175.ZodString;
|
|
48
|
+
}, zod_v4_core36.$strip>, zod175.ZodObject<{
|
|
49
|
+
command: zod175.ZodLiteral<"str_replace">;
|
|
50
|
+
path: zod175.ZodString;
|
|
51
|
+
old_str: zod175.ZodString;
|
|
52
|
+
new_str: zod175.ZodString;
|
|
53
|
+
}, zod_v4_core36.$strip>, zod175.ZodObject<{
|
|
54
|
+
command: zod175.ZodLiteral<"insert">;
|
|
55
|
+
path: zod175.ZodString;
|
|
56
|
+
insert_line: zod175.ZodNumber;
|
|
57
|
+
insert_text: zod175.ZodString;
|
|
58
|
+
}, zod_v4_core36.$strip>, zod175.ZodObject<{
|
|
59
|
+
command: zod175.ZodLiteral<"delete">;
|
|
60
|
+
path: zod175.ZodString;
|
|
61
|
+
}, zod_v4_core36.$strip>, zod175.ZodObject<{
|
|
62
|
+
command: zod175.ZodLiteral<"rename">;
|
|
63
|
+
old_path: zod175.ZodString;
|
|
64
|
+
new_path: zod175.ZodString;
|
|
65
|
+
}, zod_v4_core36.$strip>], "command">, {
|
|
66
66
|
command: "view";
|
|
67
67
|
path: string;
|
|
68
68
|
} | {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory.d.ts","names":["
|
|
1
|
+
{"version":3,"file":"memory.d.ts","names":["zod_v4_core36","DynamicStructuredTool","MemoryTool20250818Options","memory_20250818","zod175","ZodLiteral","ZodString","$strip","ZodObject","ZodNumber","ZodDiscriminatedUnion","Promise"],"sources":["../../src/tools/memory.d.ts"],"sourcesContent":["import type { DynamicStructuredTool } from \"@langchain/core/tools\";\nimport { type MemoryTool20250818Options } from \"./types.js\";\n/**\n * Creates an Anthropic memory tool that can be used with ChatAnthropic.\n *\n * The memory tool enables Claude to store and retrieve information across conversations\n * through a memory file directory. Claude can create, read, update, and delete files that\n * persist between sessions, allowing it to build knowledge over time without keeping\n * everything in the context window.\n *\n * @example\n * ```typescript\n * import { ChatAnthropic, memory_20250818 } from \"@langchain/anthropic\";\n *\n * const llm = new ChatAnthropic({\n * model: \"claude-sonnet-4-5-20250929\"\n * });\n *\n * const memory = memory_20250818({\n * execute: async (args) => {\n * // handle memory command execution\n * // ...\n * },\n * });\n * const llmWithMemory = llm.bindTools([memory]);\n *\n * const response = await llmWithMemory.invoke(\"Remember that I like Python\");\n * ```\n *\n * @param options - Optional configuration for the memory tool (currently unused)\n * @param options.execute - Optional execute function that handles memory command execution.\n * @returns The memory tool object that can be passed to `bindTools`\n *\n * @see https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/memory-tool\n */\nexport declare function memory_20250818(options?: MemoryTool20250818Options): DynamicStructuredTool<import(\"zod\").ZodDiscriminatedUnion<[import(\"zod\").ZodObject<{\n command: import(\"zod\").ZodLiteral<\"view\">;\n path: import(\"zod\").ZodString;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n command: import(\"zod\").ZodLiteral<\"create\">;\n path: import(\"zod\").ZodString;\n file_text: import(\"zod\").ZodString;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n command: import(\"zod\").ZodLiteral<\"str_replace\">;\n path: import(\"zod\").ZodString;\n old_str: import(\"zod\").ZodString;\n new_str: import(\"zod\").ZodString;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n command: import(\"zod\").ZodLiteral<\"insert\">;\n path: import(\"zod\").ZodString;\n insert_line: import(\"zod\").ZodNumber;\n insert_text: import(\"zod\").ZodString;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n command: import(\"zod\").ZodLiteral<\"delete\">;\n path: import(\"zod\").ZodString;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n command: import(\"zod\").ZodLiteral<\"rename\">;\n old_path: import(\"zod\").ZodString;\n new_path: import(\"zod\").ZodString;\n}, import(\"zod/v4/core\").$strip>], \"command\">, {\n command: \"view\";\n path: string;\n} | {\n command: \"create\";\n path: string;\n file_text: string;\n} | {\n command: \"str_replace\";\n path: string;\n old_str: string;\n new_str: string;\n} | {\n command: \"insert\";\n path: string;\n insert_line: number;\n insert_text: string;\n} | {\n command: \"delete\";\n path: string;\n} | {\n command: \"rename\";\n old_path: string;\n new_path: string;\n}, unknown, string | Promise<string>, string>;\n//# sourceMappingURL=memory.d.ts.map"],"mappings":";;;;;;;;;;;AAmCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsBqCI,iBAtBbD,eAAAA,CAuBIG,OAAAA,CAAAA,EAvBsBJ,yBAuBtBI,CAAAA,EAvBkDL,qBAuBlDK,CAH6BF,MAAAA,CApByDM,qBAuBtFJ,CAAAA,CApBGF,MAAAA,CAHwHI,SAuB3HF,CAAAA;EAASN,OAAAA,EAvBsCI,MAAAA,CAChDC,UAuBFE,CAAAA,MAAAA,CAAAA;EAAMH,IAJiBI,EAnBXJ,MAAAA,CACbE,SAkBwBE;CAASJ,EAlBxBJ,aAAAA,CACRO,MAAAA,CAHyFG,EAOnFN,MAAAA,CAJiBI,SAHkEE,CAAAA;EAgD7FC,OAAAA,EAhD2IP,MAAAA,CAIrIC,UA4CNM,CAAAA,QAAAA,CAAAA;EAhDyDV,IAAAA,EAIzCG,MAAAA,CACbE,SALsDL;EAAqB,SAAA,EAKlEG,MAAAA,CACJE,SANsE;GAM7DN,aAAAA,CACbO,MAAAA,GAKMH,MAAAA,CALiBI;WAJSJ,MAAAA,CAK9BC;QAAUD,MAAAA,CACbE;WAASF,MAAAA,CACNE;WAASF,MAAAA,CACTE;GAASN,aAAAA,CACXO,MAAAA,GAKMH,MAAAA,CALiBI;WALSJ,MAAAA,CAM9BC;QAAUD,MAAAA,CACbE;eAASF,MAAAA,CACFK;eAASL,MAAAA,CACTE;GAASN,aAAAA,CACfO,MAAAA,GAGMH,MAAAA,CAHiBI;WALSJ,MAAAA,CAM9BC;QAAUD,MAAAA,CACbE;GAASN,aAAAA,CACRO,MAAAA,GAIMH,MAAAA,CAJiBI;WAHSJ,MAAAA,CAI9BC;YAAUD,MAAAA,CACTE;YAASF,MAAAA,CACTE;GAASN,aAAAA,CACZO,MAAAA;;;;;;;;;;;;;;;;;;;;;;;;qBAwBJI"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TextEditor20250728Command } from "./types.js";
|
|
2
2
|
import { DynamicStructuredTool } from "@langchain/core/tools";
|
|
3
|
-
import * as
|
|
4
|
-
import * as
|
|
3
|
+
import * as zod0 from "zod";
|
|
4
|
+
import * as zod_v4_core0 from "zod/v4/core";
|
|
5
5
|
|
|
6
6
|
//#region src/tools/textEditor.d.ts
|
|
7
7
|
/**
|
|
@@ -72,25 +72,25 @@ interface TextEditor20250728Options {
|
|
|
72
72
|
*
|
|
73
73
|
* @see https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/text-editor-tool
|
|
74
74
|
*/
|
|
75
|
-
declare function textEditor_20250728(options?: TextEditor20250728Options): DynamicStructuredTool<
|
|
76
|
-
command:
|
|
77
|
-
path:
|
|
78
|
-
view_range:
|
|
79
|
-
},
|
|
80
|
-
command:
|
|
81
|
-
path:
|
|
82
|
-
old_str:
|
|
83
|
-
new_str:
|
|
84
|
-
},
|
|
85
|
-
command:
|
|
86
|
-
path:
|
|
87
|
-
file_text:
|
|
88
|
-
},
|
|
89
|
-
command:
|
|
90
|
-
path:
|
|
91
|
-
insert_line:
|
|
92
|
-
new_str:
|
|
93
|
-
},
|
|
75
|
+
declare function textEditor_20250728(options?: TextEditor20250728Options): DynamicStructuredTool<zod0.ZodDiscriminatedUnion<[zod0.ZodObject<{
|
|
76
|
+
command: zod0.ZodLiteral<"view">;
|
|
77
|
+
path: zod0.ZodString;
|
|
78
|
+
view_range: zod0.ZodOptional<zod0.ZodTuple<[zod0.ZodNumber, zod0.ZodNumber], null>>;
|
|
79
|
+
}, zod_v4_core0.$strip>, zod0.ZodObject<{
|
|
80
|
+
command: zod0.ZodLiteral<"str_replace">;
|
|
81
|
+
path: zod0.ZodString;
|
|
82
|
+
old_str: zod0.ZodString;
|
|
83
|
+
new_str: zod0.ZodString;
|
|
84
|
+
}, zod_v4_core0.$strip>, zod0.ZodObject<{
|
|
85
|
+
command: zod0.ZodLiteral<"create">;
|
|
86
|
+
path: zod0.ZodString;
|
|
87
|
+
file_text: zod0.ZodString;
|
|
88
|
+
}, zod_v4_core0.$strip>, zod0.ZodObject<{
|
|
89
|
+
command: zod0.ZodLiteral<"insert">;
|
|
90
|
+
path: zod0.ZodString;
|
|
91
|
+
insert_line: zod0.ZodNumber;
|
|
92
|
+
new_str: zod0.ZodString;
|
|
93
|
+
}, zod_v4_core0.$strip>], "command">, {
|
|
94
94
|
command: "view";
|
|
95
95
|
path: string;
|
|
96
96
|
view_range?: [number, number] | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"textEditor.d.ts","names":["
|
|
1
|
+
{"version":3,"file":"textEditor.d.ts","names":["zod_v4_core0","DynamicStructuredTool","TextEditor20250728Command","TextEditor20250728Options","Promise","textEditor_20250728","zod0","ZodLiteral","ZodString","ZodNumber","ZodTuple","ZodOptional","$strip","ZodObject","ZodDiscriminatedUnion"],"sources":["../../src/tools/textEditor.d.ts"],"sourcesContent":["import type { DynamicStructuredTool } from \"@langchain/core/tools\";\nimport { type TextEditor20250728Command } from \"./types.js\";\n/**\n * Options for the text editor tool (Claude 4.x version).\n */\nexport interface TextEditor20250728Options {\n /**\n * Optional execute function that handles text editor command execution.\n * This function receives the command input and should return the result.\n */\n execute?: (args: TextEditor20250728Command) => string | Promise<string>;\n /**\n * Optional maximum characters to return when viewing files.\n * If the file content exceeds this limit, it will be truncated.\n */\n maxCharacters?: number;\n}\n/**\n * Creates an Anthropic text editor tool for Claude 4.x models that can view and modify text files.\n *\n * The text editor tool enables Claude to view and modify text files, helping debug, fix,\n * and improve code or other text documents. Claude can directly interact with files,\n * providing hands-on assistance rather than just suggesting changes.\n *\n * Available commands:\n * - `view`: Examine file contents or list directory contents\n * - `str_replace`: Replace specific text in a file\n * - `create`: Create a new file with specified content\n * - `insert`: Insert text at a specific line number\n *\n * @example\n * ```typescript\n * import { ChatAnthropic, tools } from \"@langchain/anthropic\";\n * import * as fs from \"fs\";\n *\n * const llm = new ChatAnthropic({\n * model: \"claude-sonnet-4-5-20250929\",\n * });\n *\n * const textEditor = tools.textEditor_20250728({\n * execute: async (args) => {\n * if (args.command === \"view\") {\n * const content = fs.readFileSync(args.path, \"utf-8\");\n * return content.split(\"\\n\").map((line, i) => `${i + 1}: ${line}`).join(\"\\n\");\n * }\n * if (args.command === \"str_replace\") {\n * let content = fs.readFileSync(args.path, \"utf-8\");\n * content = content.replace(args.old_str!, args.new_str!);\n * fs.writeFileSync(args.path, content);\n * return \"Successfully replaced text.\";\n * }\n * // Handle other commands...\n * return \"Command executed\";\n * },\n * maxCharacters: 10000,\n * });\n *\n * const llmWithEditor = llm.bindTools([textEditor]);\n * const response = await llmWithEditor.invoke(\n * \"There's a syntax error in my primes.py file. Can you help me fix it?\"\n * );\n * ```\n *\n * @param options - Configuration options for the text editor tool\n * @param options.execute - Function that handles text editor command execution\n * @param options.maxCharacters - Maximum characters to return when viewing files\n * @returns The text editor tool object that can be passed to `bindTools`\n *\n * @see https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/text-editor-tool\n */\nexport declare function textEditor_20250728(options?: TextEditor20250728Options): DynamicStructuredTool<import(\"zod\").ZodDiscriminatedUnion<[import(\"zod\").ZodObject<{\n command: import(\"zod\").ZodLiteral<\"view\">;\n path: import(\"zod\").ZodString;\n view_range: import(\"zod\").ZodOptional<import(\"zod\").ZodTuple<[import(\"zod\").ZodNumber, import(\"zod\").ZodNumber], null>>;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n command: import(\"zod\").ZodLiteral<\"str_replace\">;\n path: import(\"zod\").ZodString;\n old_str: import(\"zod\").ZodString;\n new_str: import(\"zod\").ZodString;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n command: import(\"zod\").ZodLiteral<\"create\">;\n path: import(\"zod\").ZodString;\n file_text: import(\"zod\").ZodString;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n command: import(\"zod\").ZodLiteral<\"insert\">;\n path: import(\"zod\").ZodString;\n insert_line: import(\"zod\").ZodNumber;\n new_str: import(\"zod\").ZodString;\n}, import(\"zod/v4/core\").$strip>], \"command\">, {\n command: \"view\";\n path: string;\n view_range?: [number, number] | undefined;\n} | {\n command: \"str_replace\";\n path: string;\n old_str: string;\n new_str: string;\n} | {\n command: \"create\";\n path: string;\n file_text: string;\n} | {\n command: \"insert\";\n path: string;\n insert_line: number;\n new_str: string;\n}, unknown, string | Promise<string>, string>;\n//# sourceMappingURL=textEditor.d.ts.map"],"mappings":";;;;;;;;;UAKiBG,yBAAAA;EAAAA;AAiEjB;;;EACqCG,OACbE,CAAAA,EAAAA,CAAAA,IAAAA,EA9DHN,yBA8DGM,EAAAA,GAAAA,MAAAA,GA9DoCJ,OA8DpCI,CAAAA,MAAAA,CAAAA;EAASF;;;;EACQN,aAChBY,CAAAA,EAAAA,MAAAA;;;;;;;;;;;;;;;;;;;;;;AAJ8E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAA/EP,mBAAAA,WAA8BF,4BAA4BF,sBAazBK,IAAAA,CAb6DQ,uBAIvFR,IAAAA,CAJ4HO;WAA5EP,IAAAA,CACpDC;QAAUD,IAAAA,CACbE;cACwCF,IAAAA,CAAlCK,YAAoFL,IAAAA,CAA1DI,UADvBJ,IAAAA,CAC+CG,SAAAA,EAASH,IAAAA,CAAgBG,SAAAA;GAAhET,YAAAA,CAChBY,MAAAA,GAKMN,IAAAA,CALiBO;WAJoHP,IAAAA,CAKzIC;QAAUD,IAAAA,CACbE;WAASF,IAAAA,CACNE;WAASF,IAAAA,CACTE;GAASR,YAAAA,CACXY,MAAAA,GAIMN,IAAAA,CAJiBO;WALSP,IAAAA,CAM9BC;QAAUD,IAAAA,CACbE;aAASF,IAAAA,CACJE;GAASR,YAAAA,CACbY,MAAAA,GAKMN,IAAAA,CALiBO;WAJSP,IAAAA,CAK9BC;QAAUD,IAAAA,CACbE;eAASF,IAAAA,CACFG;WAASH,IAAAA,CACbE;GAASR,YAAAA,CACXY,MAAAA;;;;;;;;;;;;;;;;;;qBAkBJR"}
|
|
@@ -107,6 +107,29 @@ function* _formatContentBlocks(content, toolCalls) {
|
|
|
107
107
|
source,
|
|
108
108
|
...cacheControl ? { cache_control: cacheControl } : {}
|
|
109
109
|
};
|
|
110
|
+
} else if (contentPart.type === "file") {
|
|
111
|
+
let source;
|
|
112
|
+
if ("url" in contentPart && typeof contentPart.url === "string") source = {
|
|
113
|
+
type: "url",
|
|
114
|
+
url: contentPart.url
|
|
115
|
+
};
|
|
116
|
+
else if ("data" in contentPart && (typeof contentPart.data === "string" || contentPart.data instanceof Uint8Array)) {
|
|
117
|
+
const media_type = "mimeType" in contentPart && typeof contentPart.mimeType === "string" ? contentPart.mimeType : "application/pdf";
|
|
118
|
+
const data = typeof contentPart.data === "string" ? contentPart.data : Buffer.from(contentPart.data).toString("base64");
|
|
119
|
+
source = {
|
|
120
|
+
type: "base64",
|
|
121
|
+
media_type,
|
|
122
|
+
data
|
|
123
|
+
};
|
|
124
|
+
} else if ("fileId" in contentPart && typeof contentPart.fileId === "string") source = {
|
|
125
|
+
type: "file",
|
|
126
|
+
file_id: contentPart.fileId
|
|
127
|
+
};
|
|
128
|
+
if (source) yield {
|
|
129
|
+
type: "document",
|
|
130
|
+
source,
|
|
131
|
+
...cacheControl ? { cache_control: cacheControl } : {}
|
|
132
|
+
};
|
|
110
133
|
} else if (contentPart.type === "document") yield {
|
|
111
134
|
...contentPart,
|
|
112
135
|
...cacheControl ? { cache_control: cacheControl } : {}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message_inputs.cjs","names":["imageUrl: string","parsedUrl: URL","messages: BaseMessage[]","HumanMessage","toolCall: ToolCall","content: ContentBlock[]","toolCalls?: ToolCall[]","standardContentBlockConverter","_isAnthropicImageBlockParam","_isAnthropicThinkingBlock","block: AnthropicThinkingBlockParam","_isAnthropicRedactedThinkingBlock","block: AnthropicRedactedThinkingBlockParam","_isAnthropicSearchResultBlock","block: AnthropicSearchResultBlockParam","message: BaseMessage","AIMessage","_formatStandardContent","payload: AnthropicMessageCreateParams","cacheControl: CacheControl","messages: AnthropicMessageCreateParams[\"messages\"]","result: AnthropicMessageCreateParams[\"messages\"]","content:\n | string\n | Array<\n | AnthropicTextBlockParam\n | AnthropicImageBlockParam\n | AnthropicToolUseBlockParam\n | AnthropicToolResultBlockParam\n | AnthropicDocumentBlockParam\n | AnthropicThinkingBlockParam\n | AnthropicRedactedThinkingBlockParam\n | AnthropicServerToolUseBlockParam\n | AnthropicWebSearchToolResultBlockParam\n | AnthropicSearchResultBlockParam\n >","msg: (typeof messages)[0]"],"sources":["../../src/utils/message_inputs.ts"],"sourcesContent":["/**\n * This util file contains functions for converting LangChain messages to Anthropic messages.\n */\nimport type Anthropic from \"@anthropic-ai/sdk\";\nimport {\n type BaseMessage,\n HumanMessage,\n ToolMessage,\n MessageContentComplex,\n isDataContentBlock,\n convertToProviderContentBlock,\n parseBase64DataUrl,\n ContentBlock,\n AIMessage,\n} from \"@langchain/core/messages\";\nimport { ToolCall } from \"@langchain/core/messages/tool\";\nimport {\n AnthropicImageBlockParam,\n AnthropicMessageCreateParams,\n AnthropicTextBlockParam,\n AnthropicToolResultBlockParam,\n AnthropicToolUseBlockParam,\n AnthropicDocumentBlockParam,\n AnthropicThinkingBlockParam,\n AnthropicRedactedThinkingBlockParam,\n AnthropicServerToolUseBlockParam,\n AnthropicWebSearchToolResultBlockParam,\n AnthropicSearchResultBlockParam,\n AnthropicToolResponse,\n AnthropicContainerUploadBlockParam,\n} from \"../types.js\";\nimport {\n _isAnthropicImageBlockParam,\n _isAnthropicRedactedThinkingBlock,\n _isAnthropicSearchResultBlock,\n _isAnthropicThinkingBlock,\n standardContentBlockConverter,\n} from \"./content.js\";\nimport { _formatStandardContent } from \"./standard.js\";\n\nfunction _formatImage(imageUrl: string) {\n const parsed = parseBase64DataUrl({ dataUrl: imageUrl });\n if (parsed) {\n return {\n type: \"base64\",\n media_type: parsed.mime_type,\n data: parsed.data,\n };\n }\n let parsedUrl: URL;\n\n try {\n parsedUrl = new URL(imageUrl);\n } catch {\n throw new Error(\n [\n `Malformed image URL: ${JSON.stringify(\n imageUrl\n )}. Content blocks of type 'image_url' must be a valid http, https, or base64-encoded data URL.`,\n \"Example: data:image/png;base64,/9j/4AAQSk...\",\n \"Example: https://example.com/image.jpg\",\n ].join(\"\\n\\n\")\n );\n }\n\n if (parsedUrl.protocol === \"http:\" || parsedUrl.protocol === \"https:\") {\n return {\n type: \"url\",\n url: imageUrl,\n };\n }\n\n throw new Error(\n [\n `Invalid image URL protocol: ${JSON.stringify(\n parsedUrl.protocol\n )}. Anthropic only supports images as http, https, or base64-encoded data URLs on 'image_url' content blocks.`,\n \"Example: data:image/png;base64,/9j/4AAQSk...\",\n \"Example: https://example.com/image.jpg\",\n ].join(\"\\n\\n\")\n );\n}\n\nfunction _ensureMessageContents(messages: BaseMessage[]): BaseMessage[] {\n // Merge runs of human/tool messages into single human messages with content blocks.\n const updatedMsgs = [];\n for (const message of messages) {\n if (message._getType() === \"tool\") {\n if (typeof message.content === \"string\") {\n const previousMessage = updatedMsgs[updatedMsgs.length - 1];\n if (\n previousMessage?._getType() === \"human\" &&\n Array.isArray(previousMessage.content) &&\n \"type\" in previousMessage.content[0] &&\n previousMessage.content[0].type === \"tool_result\"\n ) {\n // If the previous message was a tool result, we merge this tool message into it.\n (previousMessage.content as MessageContentComplex[]).push({\n type: \"tool_result\",\n content: message.content,\n tool_use_id: (message as ToolMessage).tool_call_id,\n });\n } else {\n // If not, we create a new human message with the tool result.\n updatedMsgs.push(\n new HumanMessage({\n content: [\n {\n type: \"tool_result\",\n content: message.content,\n tool_use_id: (message as ToolMessage).tool_call_id,\n },\n ],\n })\n );\n }\n } else {\n updatedMsgs.push(\n new HumanMessage({\n content: [\n {\n type: \"tool_result\",\n // rare case: message.content could be undefined\n ...(message.content != null\n ? { content: _formatContent(message) }\n : {}),\n tool_use_id: (message as ToolMessage).tool_call_id,\n },\n ],\n })\n );\n }\n } else {\n updatedMsgs.push(message);\n }\n }\n return updatedMsgs;\n}\n\nexport function _convertLangChainToolCallToAnthropic(\n toolCall: ToolCall\n): AnthropicToolResponse {\n if (toolCall.id === undefined) {\n throw new Error(`Anthropic requires all tool calls to have an \"id\".`);\n }\n return {\n type: \"tool_use\",\n id: toolCall.id,\n name: toolCall.name,\n input: toolCall.args,\n };\n}\n\nfunction* _formatContentBlocks(\n content: ContentBlock[],\n toolCalls?: ToolCall[]\n): Generator<Anthropic.Beta.BetaContentBlockParam> {\n const toolTypes = [\n \"bash_code_execution_tool_result\",\n \"input_json_delta\",\n \"server_tool_use\",\n \"text_editor_code_execution_tool_result\",\n \"tool_result\",\n \"tool_use\",\n \"web_search_result\",\n \"web_search_tool_result\",\n ];\n const textTypes = [\"text\", \"text_delta\"];\n for (const contentPart of content) {\n if (isDataContentBlock(contentPart)) {\n yield convertToProviderContentBlock(\n contentPart,\n standardContentBlockConverter\n );\n }\n\n const cacheControl =\n \"cache_control\" in contentPart ? contentPart.cache_control : undefined;\n\n if (contentPart.type === \"image_url\") {\n let source;\n if (typeof contentPart.image_url === \"string\") {\n source = _formatImage(contentPart.image_url);\n } else if (\n typeof contentPart.image_url === \"object\" &&\n contentPart.image_url !== null &&\n \"url\" in contentPart.image_url &&\n typeof contentPart.image_url.url === \"string\"\n ) {\n source = _formatImage(contentPart.image_url.url);\n }\n if (source) {\n yield {\n type: \"image\" as const, // Explicitly setting the type as \"image\"\n source,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n } as Anthropic.Messages.ImageBlockParam;\n }\n } else if (_isAnthropicImageBlockParam(contentPart)) {\n yield contentPart;\n } else if (contentPart.type === \"image\") {\n // Handle new ContentBlock.Multimodal.Image format\n let source;\n\n if (\"url\" in contentPart && typeof contentPart.url === \"string\") {\n // URL-based image\n source = _formatImage(contentPart.url);\n } else if (\n \"data\" in contentPart &&\n (typeof contentPart.data === \"string\" ||\n // eslint-disable-next-line no-instanceof/no-instanceof\n contentPart.data instanceof Uint8Array)\n ) {\n // Base64-based image\n const mimeType =\n \"mimeType\" in contentPart && typeof contentPart.mimeType === \"string\"\n ? contentPart.mimeType\n : \"image/jpeg\";\n const data =\n typeof contentPart.data === \"string\"\n ? contentPart.data\n : Buffer.from(contentPart.data).toString(\"base64\");\n source = {\n type: \"base64\" as const,\n media_type: mimeType as\n | \"image/jpeg\"\n | \"image/png\"\n | \"image/gif\"\n | \"image/webp\",\n data,\n };\n } else if (\n \"fileId\" in contentPart &&\n typeof contentPart.fileId === \"string\"\n ) {\n // File ID-based image\n // Note: Anthropic supports file IDs for images that have been uploaded\n // to their servers via the Files API\n source = {\n type: \"file\" as const,\n file_id: contentPart.fileId,\n };\n }\n\n if (source) {\n yield {\n type: \"image\" as const,\n source,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n } as Anthropic.Messages.ImageBlockParam;\n }\n } else if (contentPart.type === \"document\") {\n // PDF\n yield {\n ...contentPart,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n } as Anthropic.Messages.DocumentBlockParam;\n } else if (_isAnthropicThinkingBlock(contentPart)) {\n const block: AnthropicThinkingBlockParam = {\n type: \"thinking\" as const, // Explicitly setting the type as \"thinking\"\n thinking: contentPart.thinking,\n signature: contentPart.signature,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n };\n yield block;\n } else if (_isAnthropicRedactedThinkingBlock(contentPart)) {\n const block: AnthropicRedactedThinkingBlockParam = {\n type: \"redacted_thinking\" as const, // Explicitly setting the type as \"redacted_thinking\"\n data: contentPart.data,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n };\n yield block;\n } else if (_isAnthropicSearchResultBlock(contentPart)) {\n const block: AnthropicSearchResultBlockParam = {\n type: \"search_result\" as const, // Explicitly setting the type as \"search_result\"\n title: contentPart.title,\n source: contentPart.source,\n ...(\"cache_control\" in contentPart && contentPart.cache_control\n ? { cache_control: contentPart.cache_control }\n : {}),\n ...(\"citations\" in contentPart && contentPart.citations\n ? { citations: contentPart.citations }\n : {}),\n content: contentPart.content,\n };\n yield block as Anthropic.Beta.BetaSearchResultBlockParam;\n } else if (\n textTypes.find((t) => t === contentPart.type) &&\n \"text\" in contentPart\n ) {\n // Assuming contentPart is of type MessageContentText here\n yield {\n type: \"text\" as const, // Explicitly setting the type as \"text\"\n text: contentPart.text,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n ...(\"citations\" in contentPart && contentPart.citations\n ? { citations: contentPart.citations }\n : {}),\n } as Anthropic.Messages.TextBlockParam;\n } else if (toolTypes.find((t) => t === contentPart.type)) {\n const contentPartCopy = { ...contentPart };\n\n if (contentPartCopy.type === \"input_json_delta\") {\n // `input_json_delta` type only represents yielding partial tool inputs\n // and is not a valid type for Anthropic messages.\n // These blocks appear in streaming responses and should be skipped\n // as their input data is already captured in tool_calls.\n continue;\n }\n\n if (\n contentPartCopy.type === \"tool_use\" &&\n typeof contentPartCopy.input === \"string\"\n ) {\n // First, try to get the input from the corresponding tool_call.\n // This is the most reliable source since tool_calls are properly\n // consolidated from tool_call_chunks during streaming.\n const matchingToolCall = toolCalls?.find(\n (tc) => tc.id === contentPartCopy.id\n );\n if (matchingToolCall) {\n contentPartCopy.input = matchingToolCall.args;\n } else {\n // Fallback: `tool_use` content part may be followed by `input_json_delta`\n // content parts which are chunks of a stringified JSON input,\n // so we need to collect them and merge their inputs.\n const inputDeltas = content.filter(\n (nestedContentPart) =>\n nestedContentPart.index === contentPartCopy.index &&\n nestedContentPart.type === \"input_json_delta\" &&\n typeof nestedContentPart.input === \"string\"\n );\n // If no `input_json_delta` parts are found, this line will just\n // return `contentPartCopy.input`, so no additional check is needed\n contentPartCopy.input = inputDeltas.reduce(\n (accumulator, nestedContentPart) =>\n accumulator + nestedContentPart.input,\n contentPartCopy.input\n );\n }\n }\n\n if (\"index\" in contentPartCopy) {\n // Anthropic does not support passing the index field here, so we remove it.\n delete contentPartCopy.index;\n }\n\n if (\"input\" in contentPartCopy) {\n // Anthropic tool use inputs should be valid objects, when applicable.\n if (typeof contentPartCopy.input === \"string\") {\n try {\n contentPartCopy.input = JSON.parse(contentPartCopy.input);\n } catch {\n contentPartCopy.input = {};\n }\n }\n }\n // TODO: Fix when SDK types are fixed\n yield {\n ...contentPartCopy,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } as any;\n } else if (contentPart.type === \"container_upload\") {\n yield {\n ...contentPart,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n } as AnthropicContainerUploadBlockParam;\n }\n\n // Note that we are intentionally dropping any blocks that we don't\n // recognize. This is to allow for cross-compatibility between different\n // providers that may have different block types. Ie if we take a message\n // output from OpenAI and send it to Anthropic, we want to drop any blocks\n // that Anthropic doesn't understand.\n }\n}\n\nfunction _formatContent(message: BaseMessage, toolCalls?: ToolCall[]) {\n const { content } = message;\n\n if (typeof content === \"string\") {\n return content;\n } else {\n return Array.from(_formatContentBlocks(content, toolCalls));\n }\n}\n\n/**\n * Formats messages as a prompt for the model.\n * Used in LangSmith, export is important here.\n * @param messages The base messages to format as a prompt.\n * @returns The formatted prompt.\n */\nexport function _convertMessagesToAnthropicPayload(\n messages: BaseMessage[]\n): AnthropicMessageCreateParams {\n const mergedMessages = _ensureMessageContents(messages);\n let system;\n if (mergedMessages.length > 0 && mergedMessages[0]._getType() === \"system\") {\n system = messages[0].content;\n }\n const conversationMessages =\n system !== undefined ? mergedMessages.slice(1) : mergedMessages;\n const formattedMessages = conversationMessages.map((message) => {\n let role;\n if (message._getType() === \"human\") {\n role = \"user\" as const;\n } else if (message._getType() === \"ai\") {\n role = \"assistant\" as const;\n } else if (message._getType() === \"tool\") {\n role = \"user\" as const;\n } else if (message._getType() === \"system\") {\n throw new Error(\n \"System messages are only permitted as the first passed message.\"\n );\n } else {\n throw new Error(`Message type \"${message.type}\" is not supported.`);\n }\n if (\n AIMessage.isInstance(message) &&\n message.response_metadata?.output_version === \"v1\"\n ) {\n return {\n role,\n content: _formatStandardContent(message),\n };\n }\n if (AIMessage.isInstance(message) && !!message.tool_calls?.length) {\n if (typeof message.content === \"string\") {\n if (message.content === \"\") {\n return {\n role,\n content: message.tool_calls.map(\n _convertLangChainToolCallToAnthropic\n ),\n };\n } else {\n return {\n role,\n content: [\n { type: \"text\", text: message.content },\n ...message.tool_calls.map(_convertLangChainToolCallToAnthropic),\n ],\n };\n }\n } else {\n const { content } = message;\n const hasMismatchedToolCalls = !message.tool_calls.every((toolCall) =>\n content.find(\n (contentPart) =>\n (contentPart.type === \"tool_use\" ||\n contentPart.type === \"input_json_delta\" ||\n contentPart.type === \"server_tool_use\") &&\n contentPart.id === toolCall.id\n )\n );\n if (hasMismatchedToolCalls) {\n console.warn(\n `The \"tool_calls\" field on a message is only respected if content is a string.`\n );\n }\n return {\n role,\n content: _formatContent(message, message.tool_calls),\n };\n }\n } else {\n return {\n role,\n content: _formatContent(\n message,\n AIMessage.isInstance(message) ? message.tool_calls : undefined\n ),\n };\n }\n });\n return {\n messages: mergeMessages(\n formattedMessages as AnthropicMessageCreateParams[\"messages\"]\n ),\n system,\n } as AnthropicMessageCreateParams;\n}\n\n/**\n * Cache control configuration for Anthropic prompt caching.\n */\ninterface CacheControl {\n type: \"ephemeral\";\n ttl?: \"5m\" | \"1h\";\n}\n\n/**\n * Applies cache_control to the last content block of the last message in the payload.\n * This is the recommended approach for prompt caching as it applies the cache_control\n * at the final formatting layer, after all message processing is complete.\n *\n * This matches the Python langchain-anthropic implementation where cache_control\n * is applied via model_settings rather than modifying message content blocks directly.\n *\n * @param payload - The formatted Anthropic message payload\n * @param cacheControl - The cache control configuration to apply\n * @returns The payload with cache_control applied to the last content block\n */\nexport function applyCacheControlToPayload(\n payload: AnthropicMessageCreateParams,\n cacheControl: CacheControl\n): AnthropicMessageCreateParams {\n if (!payload.messages || payload.messages.length === 0) {\n return payload;\n }\n\n const messages = [...payload.messages];\n const lastMessageIndex = messages.length - 1;\n const lastMessage = messages[lastMessageIndex];\n\n if (!lastMessage) {\n return payload;\n }\n\n // Handle string content - convert to text block with cache_control\n if (typeof lastMessage.content === \"string\") {\n messages[lastMessageIndex] = {\n ...lastMessage,\n content: [\n {\n type: \"text\",\n text: lastMessage.content,\n cache_control: cacheControl,\n },\n ],\n };\n return { ...payload, messages };\n }\n\n // Handle array content - add cache_control to the last block\n if (Array.isArray(lastMessage.content) && lastMessage.content.length > 0) {\n const content = [...lastMessage.content];\n const lastBlockIndex = content.length - 1;\n const lastBlock = content[lastBlockIndex];\n\n // Add cache_control to the last block\n content[lastBlockIndex] = {\n ...lastBlock,\n cache_control: cacheControl,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } as any;\n\n messages[lastMessageIndex] = {\n ...lastMessage,\n content,\n };\n return { ...payload, messages };\n }\n\n return payload;\n}\n\nfunction mergeMessages(messages: AnthropicMessageCreateParams[\"messages\"]) {\n if (!messages || messages.length <= 1) {\n return messages;\n }\n\n const result: AnthropicMessageCreateParams[\"messages\"] = [];\n let currentMessage = messages[0];\n\n const normalizeContent = (\n content:\n | string\n | Array<\n | AnthropicTextBlockParam\n | AnthropicImageBlockParam\n | AnthropicToolUseBlockParam\n | AnthropicToolResultBlockParam\n | AnthropicDocumentBlockParam\n | AnthropicThinkingBlockParam\n | AnthropicRedactedThinkingBlockParam\n | AnthropicServerToolUseBlockParam\n | AnthropicWebSearchToolResultBlockParam\n | AnthropicSearchResultBlockParam\n >\n ): Array<\n | AnthropicTextBlockParam\n | AnthropicImageBlockParam\n | AnthropicToolUseBlockParam\n | AnthropicToolResultBlockParam\n | AnthropicDocumentBlockParam\n | AnthropicThinkingBlockParam\n | AnthropicRedactedThinkingBlockParam\n | AnthropicServerToolUseBlockParam\n | AnthropicWebSearchToolResultBlockParam\n | AnthropicSearchResultBlockParam\n > => {\n if (typeof content === \"string\") {\n return [\n {\n type: \"text\",\n text: content,\n },\n ];\n }\n return content;\n };\n\n const isToolResultMessage = (msg: (typeof messages)[0]) => {\n if (msg.role !== \"user\") return false;\n\n if (typeof msg.content === \"string\") {\n return false;\n }\n\n return (\n Array.isArray(msg.content) &&\n msg.content.every((item) => item.type === \"tool_result\")\n );\n };\n\n for (let i = 1; i < messages.length; i += 1) {\n const nextMessage = messages[i];\n\n if (\n isToolResultMessage(currentMessage) &&\n isToolResultMessage(nextMessage)\n ) {\n // Merge the messages by combining their content arrays\n currentMessage = {\n ...currentMessage,\n content: [\n ...normalizeContent(currentMessage.content),\n ...normalizeContent(nextMessage.content),\n ],\n };\n } else {\n result.push(currentMessage);\n currentMessage = nextMessage;\n }\n }\n\n result.push(currentMessage);\n return result;\n}\n"],"mappings":";;;;;;AAwCA,SAAS,aAAaA,UAAkB;CACtC,MAAM,2DAA4B,EAAE,SAAS,SAAU,EAAC;AACxD,KAAI,OACF,QAAO;EACL,MAAM;EACN,YAAY,OAAO;EACnB,MAAM,OAAO;CACd;CAEH,IAAIC;AAEJ,KAAI;EACF,YAAY,IAAI,IAAI;CACrB,QAAO;AACN,QAAM,IAAI,MACR;GACE,CAAC,qBAAqB,EAAE,KAAK,UAC3B,SACD,CAAC,6FAA6F,CAAC;GAChG;GACA;EACD,EAAC,KAAK,OAAO;CAEjB;AAED,KAAI,UAAU,aAAa,WAAW,UAAU,a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Q,SAAS,GAAG;EACxE,MAAM,UAAU,CAAC,GAAG,YAAY,OAAQ;EACxC,MAAM,iBAAiB,QAAQ,SAAS;EACxC,MAAM,YAAY,QAAQ;EAG1B,QAAQ,kBAAkB;GACxB,GAAG;GACH,eAAe;EAEhB;EAED,SAAS,oBAAoB;GAC3B,GAAG;GACH;EACD;AACD,SAAO;GAAE,GAAG;GAAS;EAAU;CAChC;AAED,QAAO;AACR;AAED,SAAS,cAAcC,UAAoD;AACzE,KAAI,CAAC,YAAY,SAAS,UAAU,EAClC,QAAO;CAGT,MAAMC,SAAmD,CAAE;CAC3D,IAAI,iBAAiB,SAAS;CAE9B,MAAM,mBAAmB,CACvBC,YAyBG;AACH,MAAI,OAAO,YAAY,SACrB,QAAO,CACL;GACE,MAAM;GACN,MAAM;EACP,CACF;AAEH,SAAO;CACR;CAED,MAAM,sBAAsB,CAACC,QAA8B;AACzD,MAAI,IAAI,SAAS,OAAQ,QAAO;AAEhC,MAAI,OAAO,IAAI,YAAY,SACzB,QAAO;AAGT,SACE,MAAM,QAAQ,IAAI,QAAQ,IAC1B,IAAI,QAAQ,MAAM,CAAC,SAAS,KAAK,SAAS,cAAc;CAE3D;AAED,MAAK,IAAI,IAAI,GAAG,IAAI,SAAS,QAAQ,KAAK,GAAG;EAC3C,MAAM,cAAc,SAAS;AAE7B,MACE,oBAAoB,eAAe,IACnC,oBAAoB,YAAY,EAGhC,iBAAiB;GACf,GAAG;GACH,SAAS,CACP,GAAG,iBAAiB,eAAe,QAAQ,EAC3C,GAAG,iBAAiB,YAAY,QAAQ,AACzC;EACF;OACI;GACL,OAAO,KAAK,eAAe;GAC3B,iBAAiB;EAClB;CACF;CAED,OAAO,KAAK,eAAe;AAC3B,QAAO;AACR"}
|
|
1
|
+
{"version":3,"file":"message_inputs.cjs","names":["imageUrl: string","parsedUrl: URL","messages: BaseMessage[]","HumanMessage","toolCall: ToolCall","content: ContentBlock[]","toolCalls?: ToolCall[]","standardContentBlockConverter","_isAnthropicImageBlockParam","source:\n | { type: \"url\"; url: string }\n | { type: \"base64\"; media_type: string; data: string }\n | { type: \"file\"; file_id: string }\n | undefined","_isAnthropicThinkingBlock","block: AnthropicThinkingBlockParam","_isAnthropicRedactedThinkingBlock","block: AnthropicRedactedThinkingBlockParam","_isAnthropicSearchResultBlock","block: AnthropicSearchResultBlockParam","message: BaseMessage","AIMessage","_formatStandardContent","payload: AnthropicMessageCreateParams","cacheControl: CacheControl","messages: AnthropicMessageCreateParams[\"messages\"]","result: AnthropicMessageCreateParams[\"messages\"]","content:\n | string\n | Array<\n | AnthropicTextBlockParam\n | AnthropicImageBlockParam\n | AnthropicToolUseBlockParam\n | AnthropicToolResultBlockParam\n | AnthropicDocumentBlockParam\n | AnthropicThinkingBlockParam\n | AnthropicRedactedThinkingBlockParam\n | AnthropicServerToolUseBlockParam\n | AnthropicWebSearchToolResultBlockParam\n | AnthropicSearchResultBlockParam\n >","msg: (typeof messages)[0]"],"sources":["../../src/utils/message_inputs.ts"],"sourcesContent":["/**\n * This util file contains functions for converting LangChain messages to Anthropic messages.\n */\nimport type Anthropic from \"@anthropic-ai/sdk\";\nimport {\n type BaseMessage,\n HumanMessage,\n ToolMessage,\n MessageContentComplex,\n isDataContentBlock,\n convertToProviderContentBlock,\n parseBase64DataUrl,\n ContentBlock,\n AIMessage,\n} from \"@langchain/core/messages\";\nimport { ToolCall } from \"@langchain/core/messages/tool\";\nimport {\n AnthropicImageBlockParam,\n AnthropicMessageCreateParams,\n AnthropicTextBlockParam,\n AnthropicToolResultBlockParam,\n AnthropicToolUseBlockParam,\n AnthropicDocumentBlockParam,\n AnthropicThinkingBlockParam,\n AnthropicRedactedThinkingBlockParam,\n AnthropicServerToolUseBlockParam,\n AnthropicWebSearchToolResultBlockParam,\n AnthropicSearchResultBlockParam,\n AnthropicToolResponse,\n AnthropicContainerUploadBlockParam,\n} from \"../types.js\";\nimport {\n _isAnthropicImageBlockParam,\n _isAnthropicRedactedThinkingBlock,\n _isAnthropicSearchResultBlock,\n _isAnthropicThinkingBlock,\n standardContentBlockConverter,\n} from \"./content.js\";\nimport { _formatStandardContent } from \"./standard.js\";\n\nfunction _formatImage(imageUrl: string) {\n const parsed = parseBase64DataUrl({ dataUrl: imageUrl });\n if (parsed) {\n return {\n type: \"base64\",\n media_type: parsed.mime_type,\n data: parsed.data,\n };\n }\n let parsedUrl: URL;\n\n try {\n parsedUrl = new URL(imageUrl);\n } catch {\n throw new Error(\n [\n `Malformed image URL: ${JSON.stringify(\n imageUrl\n )}. Content blocks of type 'image_url' must be a valid http, https, or base64-encoded data URL.`,\n \"Example: data:image/png;base64,/9j/4AAQSk...\",\n \"Example: https://example.com/image.jpg\",\n ].join(\"\\n\\n\")\n );\n }\n\n if (parsedUrl.protocol === \"http:\" || parsedUrl.protocol === \"https:\") {\n return {\n type: \"url\",\n url: imageUrl,\n };\n }\n\n throw new Error(\n [\n `Invalid image URL protocol: ${JSON.stringify(\n parsedUrl.protocol\n )}. Anthropic only supports images as http, https, or base64-encoded data URLs on 'image_url' content blocks.`,\n \"Example: data:image/png;base64,/9j/4AAQSk...\",\n \"Example: https://example.com/image.jpg\",\n ].join(\"\\n\\n\")\n );\n}\n\nfunction _ensureMessageContents(messages: BaseMessage[]): BaseMessage[] {\n // Merge runs of human/tool messages into single human messages with content blocks.\n const updatedMsgs = [];\n for (const message of messages) {\n if (message._getType() === \"tool\") {\n if (typeof message.content === \"string\") {\n const previousMessage = updatedMsgs[updatedMsgs.length - 1];\n if (\n previousMessage?._getType() === \"human\" &&\n Array.isArray(previousMessage.content) &&\n \"type\" in previousMessage.content[0] &&\n previousMessage.content[0].type === \"tool_result\"\n ) {\n // If the previous message was a tool result, we merge this tool message into it.\n (previousMessage.content as MessageContentComplex[]).push({\n type: \"tool_result\",\n content: message.content,\n tool_use_id: (message as ToolMessage).tool_call_id,\n });\n } else {\n // If not, we create a new human message with the tool result.\n updatedMsgs.push(\n new HumanMessage({\n content: [\n {\n type: \"tool_result\",\n content: message.content,\n tool_use_id: (message as ToolMessage).tool_call_id,\n },\n ],\n })\n );\n }\n } else {\n updatedMsgs.push(\n new HumanMessage({\n content: [\n {\n type: \"tool_result\",\n // rare case: message.content could be undefined\n ...(message.content != null\n ? { content: _formatContent(message) }\n : {}),\n tool_use_id: (message as ToolMessage).tool_call_id,\n },\n ],\n })\n );\n }\n } else {\n updatedMsgs.push(message);\n }\n }\n return updatedMsgs;\n}\n\nexport function _convertLangChainToolCallToAnthropic(\n toolCall: ToolCall\n): AnthropicToolResponse {\n if (toolCall.id === undefined) {\n throw new Error(`Anthropic requires all tool calls to have an \"id\".`);\n }\n return {\n type: \"tool_use\",\n id: toolCall.id,\n name: toolCall.name,\n input: toolCall.args,\n };\n}\n\nfunction* _formatContentBlocks(\n content: ContentBlock[],\n toolCalls?: ToolCall[]\n): Generator<Anthropic.Beta.BetaContentBlockParam> {\n const toolTypes = [\n \"bash_code_execution_tool_result\",\n \"input_json_delta\",\n \"server_tool_use\",\n \"text_editor_code_execution_tool_result\",\n \"tool_result\",\n \"tool_use\",\n \"web_search_result\",\n \"web_search_tool_result\",\n ];\n const textTypes = [\"text\", \"text_delta\"];\n for (const contentPart of content) {\n if (isDataContentBlock(contentPart)) {\n yield convertToProviderContentBlock(\n contentPart,\n standardContentBlockConverter\n );\n }\n\n const cacheControl =\n \"cache_control\" in contentPart ? contentPart.cache_control : undefined;\n\n if (contentPart.type === \"image_url\") {\n let source;\n if (typeof contentPart.image_url === \"string\") {\n source = _formatImage(contentPart.image_url);\n } else if (\n typeof contentPart.image_url === \"object\" &&\n contentPart.image_url !== null &&\n \"url\" in contentPart.image_url &&\n typeof contentPart.image_url.url === \"string\"\n ) {\n source = _formatImage(contentPart.image_url.url);\n }\n if (source) {\n yield {\n type: \"image\" as const, // Explicitly setting the type as \"image\"\n source,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n } as Anthropic.Messages.ImageBlockParam;\n }\n } else if (_isAnthropicImageBlockParam(contentPart)) {\n yield contentPart;\n } else if (contentPart.type === \"image\") {\n // Handle new ContentBlock.Multimodal.Image format\n let source;\n\n if (\"url\" in contentPart && typeof contentPart.url === \"string\") {\n // URL-based image\n source = _formatImage(contentPart.url);\n } else if (\n \"data\" in contentPart &&\n (typeof contentPart.data === \"string\" ||\n // eslint-disable-next-line no-instanceof/no-instanceof\n contentPart.data instanceof Uint8Array)\n ) {\n // Base64-based image\n const mimeType =\n \"mimeType\" in contentPart && typeof contentPart.mimeType === \"string\"\n ? contentPart.mimeType\n : \"image/jpeg\";\n const data =\n typeof contentPart.data === \"string\"\n ? contentPart.data\n : Buffer.from(contentPart.data).toString(\"base64\");\n source = {\n type: \"base64\" as const,\n media_type: mimeType as\n | \"image/jpeg\"\n | \"image/png\"\n | \"image/gif\"\n | \"image/webp\",\n data,\n };\n } else if (\n \"fileId\" in contentPart &&\n typeof contentPart.fileId === \"string\"\n ) {\n // File ID-based image\n // Note: Anthropic supports file IDs for images that have been uploaded\n // to their servers via the Files API\n source = {\n type: \"file\" as const,\n file_id: contentPart.fileId,\n };\n }\n\n if (source) {\n yield {\n type: \"image\" as const,\n source,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n } as Anthropic.Messages.ImageBlockParam;\n }\n } else if (contentPart.type === \"file\") {\n // Handle new ContentBlock.Multimodal.File format\n let source:\n | { type: \"url\"; url: string }\n | { type: \"base64\"; media_type: string; data: string }\n | { type: \"file\"; file_id: string }\n | undefined;\n\n if (\"url\" in contentPart && typeof contentPart.url === \"string\") {\n // File with URL\n source = {\n type: \"url\" as const,\n url: contentPart.url,\n };\n } else if (\n \"data\" in contentPart &&\n (typeof contentPart.data === \"string\" ||\n // eslint-disable-next-line no-instanceof/no-instanceof\n contentPart.data instanceof Uint8Array)\n ) {\n // File with base64 data (string or Uint8Array)\n const media_type =\n \"mimeType\" in contentPart && typeof contentPart.mimeType === \"string\"\n ? contentPart.mimeType\n : \"application/pdf\";\n const data =\n typeof contentPart.data === \"string\"\n ? contentPart.data\n : Buffer.from(contentPart.data).toString(\"base64\");\n\n source = {\n type: \"base64\" as const,\n media_type,\n data,\n };\n } else if (\n \"fileId\" in contentPart &&\n typeof contentPart.fileId === \"string\"\n ) {\n // File ID from Anthropic Files API\n // https://platform.claude.com/docs/en/build-with-claude/pdf-support#option-3-files-api\n source = {\n type: \"file\" as const,\n file_id: contentPart.fileId,\n };\n }\n\n if (source) {\n yield {\n type: \"document\" as const,\n source,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n } as Anthropic.Messages.DocumentBlockParam;\n }\n } else if (contentPart.type === \"document\") {\n // PDF\n yield {\n ...contentPart,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n } as Anthropic.Messages.DocumentBlockParam;\n } else if (_isAnthropicThinkingBlock(contentPart)) {\n const block: AnthropicThinkingBlockParam = {\n type: \"thinking\" as const, // Explicitly setting the type as \"thinking\"\n thinking: contentPart.thinking,\n signature: contentPart.signature,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n };\n yield block;\n } else if (_isAnthropicRedactedThinkingBlock(contentPart)) {\n const block: AnthropicRedactedThinkingBlockParam = {\n type: \"redacted_thinking\" as const, // Explicitly setting the type as \"redacted_thinking\"\n data: contentPart.data,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n };\n yield block;\n } else if (_isAnthropicSearchResultBlock(contentPart)) {\n const block: AnthropicSearchResultBlockParam = {\n type: \"search_result\" as const, // Explicitly setting the type as \"search_result\"\n title: contentPart.title,\n source: contentPart.source,\n ...(\"cache_control\" in contentPart && contentPart.cache_control\n ? { cache_control: contentPart.cache_control }\n : {}),\n ...(\"citations\" in contentPart && contentPart.citations\n ? { citations: contentPart.citations }\n : {}),\n content: contentPart.content,\n };\n yield block as Anthropic.Beta.BetaSearchResultBlockParam;\n } else if (\n textTypes.find((t) => t === contentPart.type) &&\n \"text\" in contentPart\n ) {\n // Assuming contentPart is of type MessageContentText here\n yield {\n type: \"text\" as const, // Explicitly setting the type as \"text\"\n text: contentPart.text,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n ...(\"citations\" in contentPart && contentPart.citations\n ? { citations: contentPart.citations }\n : {}),\n } as Anthropic.Messages.TextBlockParam;\n } else if (toolTypes.find((t) => t === contentPart.type)) {\n const contentPartCopy = { ...contentPart };\n\n if (contentPartCopy.type === \"input_json_delta\") {\n // `input_json_delta` type only represents yielding partial tool inputs\n // and is not a valid type for Anthropic messages.\n // These blocks appear in streaming responses and should be skipped\n // as their input data is already captured in tool_calls.\n continue;\n }\n\n if (\n contentPartCopy.type === \"tool_use\" &&\n typeof contentPartCopy.input === \"string\"\n ) {\n // First, try to get the input from the corresponding tool_call.\n // This is the most reliable source since tool_calls are properly\n // consolidated from tool_call_chunks during streaming.\n const matchingToolCall = toolCalls?.find(\n (tc) => tc.id === contentPartCopy.id\n );\n if (matchingToolCall) {\n contentPartCopy.input = matchingToolCall.args;\n } else {\n // Fallback: `tool_use` content part may be followed by `input_json_delta`\n // content parts which are chunks of a stringified JSON input,\n // so we need to collect them and merge their inputs.\n const inputDeltas = content.filter(\n (nestedContentPart) =>\n nestedContentPart.index === contentPartCopy.index &&\n nestedContentPart.type === \"input_json_delta\" &&\n typeof nestedContentPart.input === \"string\"\n );\n // If no `input_json_delta` parts are found, this line will just\n // return `contentPartCopy.input`, so no additional check is needed\n contentPartCopy.input = inputDeltas.reduce(\n (accumulator, nestedContentPart) =>\n accumulator + nestedContentPart.input,\n contentPartCopy.input\n );\n }\n }\n\n if (\"index\" in contentPartCopy) {\n // Anthropic does not support passing the index field here, so we remove it.\n delete contentPartCopy.index;\n }\n\n if (\"input\" in contentPartCopy) {\n // Anthropic tool use inputs should be valid objects, when applicable.\n if (typeof contentPartCopy.input === \"string\") {\n try {\n contentPartCopy.input = JSON.parse(contentPartCopy.input);\n } catch {\n contentPartCopy.input = {};\n }\n }\n }\n // TODO: Fix when SDK types are fixed\n yield {\n ...contentPartCopy,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } as any;\n } else if (contentPart.type === \"container_upload\") {\n yield {\n ...contentPart,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n } as AnthropicContainerUploadBlockParam;\n }\n\n // Note that we are intentionally dropping any blocks that we don't\n // recognize. This is to allow for cross-compatibility between different\n // providers that may have different block types. Ie if we take a message\n // output from OpenAI and send it to Anthropic, we want to drop any blocks\n // that Anthropic doesn't understand.\n }\n}\n\nfunction _formatContent(message: BaseMessage, toolCalls?: ToolCall[]) {\n const { content } = message;\n\n if (typeof content === \"string\") {\n return content;\n } else {\n return Array.from(_formatContentBlocks(content, toolCalls));\n }\n}\n\n/**\n * Formats messages as a prompt for the model.\n * Used in LangSmith, export is important here.\n * @param messages The base messages to format as a prompt.\n * @returns The formatted prompt.\n */\nexport function _convertMessagesToAnthropicPayload(\n messages: BaseMessage[]\n): AnthropicMessageCreateParams {\n const mergedMessages = _ensureMessageContents(messages);\n let system;\n if (mergedMessages.length > 0 && mergedMessages[0]._getType() === \"system\") {\n system = messages[0].content;\n }\n const conversationMessages =\n system !== undefined ? mergedMessages.slice(1) : mergedMessages;\n const formattedMessages = conversationMessages.map((message) => {\n let role;\n if (message._getType() === \"human\") {\n role = \"user\" as const;\n } else if (message._getType() === \"ai\") {\n role = \"assistant\" as const;\n } else if (message._getType() === \"tool\") {\n role = \"user\" as const;\n } else if (message._getType() === \"system\") {\n throw new Error(\n \"System messages are only permitted as the first passed message.\"\n );\n } else {\n throw new Error(`Message type \"${message.type}\" is not supported.`);\n }\n if (\n AIMessage.isInstance(message) &&\n message.response_metadata?.output_version === \"v1\"\n ) {\n return {\n role,\n content: _formatStandardContent(message),\n };\n }\n if (AIMessage.isInstance(message) && !!message.tool_calls?.length) {\n if (typeof message.content === \"string\") {\n if (message.content === \"\") {\n return {\n role,\n content: message.tool_calls.map(\n _convertLangChainToolCallToAnthropic\n ),\n };\n } else {\n return {\n role,\n content: [\n { type: \"text\", text: message.content },\n ...message.tool_calls.map(_convertLangChainToolCallToAnthropic),\n ],\n };\n }\n } else {\n const { content } = message;\n const hasMismatchedToolCalls = !message.tool_calls.every((toolCall) =>\n content.find(\n (contentPart) =>\n (contentPart.type === \"tool_use\" ||\n contentPart.type === \"input_json_delta\" ||\n contentPart.type === \"server_tool_use\") &&\n contentPart.id === toolCall.id\n )\n );\n if (hasMismatchedToolCalls) {\n console.warn(\n `The \"tool_calls\" field on a message is only respected if content is a string.`\n );\n }\n return {\n role,\n content: _formatContent(message, message.tool_calls),\n };\n }\n } else {\n return {\n role,\n content: _formatContent(\n message,\n AIMessage.isInstance(message) ? message.tool_calls : undefined\n ),\n };\n }\n });\n return {\n messages: mergeMessages(\n formattedMessages as AnthropicMessageCreateParams[\"messages\"]\n ),\n system,\n } as AnthropicMessageCreateParams;\n}\n\n/**\n * Cache control configuration for Anthropic prompt caching.\n */\ninterface CacheControl {\n type: \"ephemeral\";\n ttl?: \"5m\" | \"1h\";\n}\n\n/**\n * Applies cache_control to the last content block of the last message in the payload.\n * This is the recommended approach for prompt caching as it applies the cache_control\n * at the final formatting layer, after all message processing is complete.\n *\n * This matches the Python langchain-anthropic implementation where cache_control\n * is applied via model_settings rather than modifying message content blocks directly.\n *\n * @param payload - The formatted Anthropic message payload\n * @param cacheControl - The cache control configuration to apply\n * @returns The payload with cache_control applied to the last content block\n */\nexport function applyCacheControlToPayload(\n payload: AnthropicMessageCreateParams,\n cacheControl: CacheControl\n): AnthropicMessageCreateParams {\n if (!payload.messages || payload.messages.length === 0) {\n return payload;\n }\n\n const messages = [...payload.messages];\n const lastMessageIndex = messages.length - 1;\n const lastMessage = messages[lastMessageIndex];\n\n if (!lastMessage) {\n return payload;\n }\n\n // Handle string content - convert to text block with cache_control\n if (typeof lastMessage.content === \"string\") {\n messages[lastMessageIndex] = {\n ...lastMessage,\n content: [\n {\n type: \"text\",\n text: lastMessage.content,\n cache_control: cacheControl,\n },\n ],\n };\n return { ...payload, messages };\n }\n\n // Handle array content - add cache_control to the last block\n if (Array.isArray(lastMessage.content) && lastMessage.content.length > 0) {\n const content = [...lastMessage.content];\n const lastBlockIndex = content.length - 1;\n const lastBlock = content[lastBlockIndex];\n\n // Add cache_control to the last block\n content[lastBlockIndex] = {\n ...lastBlock,\n cache_control: cacheControl,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } as any;\n\n messages[lastMessageIndex] = {\n ...lastMessage,\n content,\n };\n return { ...payload, messages };\n }\n\n return payload;\n}\n\nfunction mergeMessages(messages: AnthropicMessageCreateParams[\"messages\"]) {\n if (!messages || messages.length <= 1) {\n return messages;\n }\n\n const result: AnthropicMessageCreateParams[\"messages\"] = [];\n let currentMessage = messages[0];\n\n const normalizeContent = (\n content:\n | string\n | Array<\n | AnthropicTextBlockParam\n | AnthropicImageBlockParam\n | AnthropicToolUseBlockParam\n | AnthropicToolResultBlockParam\n | AnthropicDocumentBlockParam\n | AnthropicThinkingBlockParam\n | AnthropicRedactedThinkingBlockParam\n | AnthropicServerToolUseBlockParam\n | AnthropicWebSearchToolResultBlockParam\n | AnthropicSearchResultBlockParam\n >\n ): Array<\n | AnthropicTextBlockParam\n | AnthropicImageBlockParam\n | AnthropicToolUseBlockParam\n | AnthropicToolResultBlockParam\n | AnthropicDocumentBlockParam\n | AnthropicThinkingBlockParam\n | AnthropicRedactedThinkingBlockParam\n | AnthropicServerToolUseBlockParam\n | AnthropicWebSearchToolResultBlockParam\n | AnthropicSearchResultBlockParam\n > => {\n if (typeof content === \"string\") {\n return [\n {\n type: \"text\",\n text: content,\n },\n ];\n }\n return content;\n };\n\n const isToolResultMessage = (msg: (typeof messages)[0]) => {\n if (msg.role !== \"user\") return false;\n\n if (typeof msg.content === \"string\") {\n return false;\n }\n\n return (\n Array.isArray(msg.content) &&\n msg.content.every((item) => item.type === \"tool_result\")\n );\n };\n\n for (let i = 1; i < messages.length; i += 1) {\n const nextMessage = messages[i];\n\n if (\n isToolResultMessage(currentMessage) &&\n isToolResultMessage(nextMessage)\n ) {\n // Merge the messages by combining their content arrays\n currentMessage = {\n ...currentMessage,\n content: [\n ...normalizeContent(currentMessage.content),\n ...normalizeContent(nextMessage.content),\n ],\n };\n } else {\n result.push(currentMessage);\n currentMessage = nextMessage;\n }\n }\n\n result.push(currentMessage);\n return result;\n}\n"],"mappings":";;;;;;AAwCA,SAAS,aAAaA,UAAkB;CACtC,MAAM,2DAA4B,EAAE,SAAS,SAAU,EAAC;AACxD,KAAI,OACF,QAAO;EACL,MAAM;EACN,YAAY,OAAO;EACnB,MAAM,OAAO;CACd;CAEH,IAAIC;AAEJ,KAAI;EACF,YAAY,IAAI,IAAI;CACrB,QAAO;AACN,QAAM,IAAI,MACR;GACE,CAAC,qBAAqB,EAAE,KAAK,UAC3B,SACD,CAAC,6FAA6F,CAAC;GAChG;GACA;EACD,EAAC,KAAK,OAAO;CAEjB;AAED,KAAI,UAAU,aAAa,WAAW,UAAU,aAAa,SAC3D,QAAO;EACL,MAAM;EACN,KAAK;CACN;AAGH,OAAM,IAAI,MACR;EACE,CAAC,4BAA4B,EAAE,KAAK,UAClC,UAAU,SACX,CAAC,2GAA2G,CAAC;EAC9G;EACA;CACD,EAAC,KAAK,OAAO;AAEjB;AAED,SAAS,uBAAuBC,UAAwC;CAEtE,MAAM,cAAc,CAAE;AACtB,MAAK,MAAM,WAAW,SACpB,KAAI,QAAQ,UAAU,KAAK,OACzB,KAAI,OAAO,QAAQ,YAAY,UAAU;EACvC,MAAM,kBAAkB,YAAY,YAAY,SAAS;AACzD,MACE,iBAAiB,UAAU,KAAK,WAChC,MAAM,QAAQ,gBAAgB,QAAQ,IACtC,UAAU,gBAAgB,QAAQ,MAClC,gBAAgB,QAAQ,GAAG,SAAS,eAGnC,gBAAgB,QAAoC,KAAK;GACxD,MAAM;GACN,SAAS,QAAQ;GACjB,aAAc,QAAwB;EACvC,EAAC;OAGF,YAAY,KACV,IAAIC,uCAAa,EACf,SAAS,CACP;GACE,MAAM;GACN,SAAS,QAAQ;GACjB,aAAc,QAAwB;EACvC,CACF,EACF,GACF;CAEJ,OACC,YAAY,K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AAkB;GACxB,GAAG;GACH,eAAe;EAEhB;EAED,SAAS,oBAAoB;GAC3B,GAAG;GACH;EACD;AACD,SAAO;GAAE,GAAG;GAAS;EAAU;CAChC;AAED,QAAO;AACR;AAED,SAAS,cAAcC,UAAoD;AACzE,KAAI,CAAC,YAAY,SAAS,UAAU,EAClC,QAAO;CAGT,MAAMC,SAAmD,CAAE;CAC3D,IAAI,iBAAiB,SAAS;CAE9B,MAAM,mBAAmB,CACvBC,YAyBG;AACH,MAAI,OAAO,YAAY,SACrB,QAAO,CACL;GACE,MAAM;GACN,MAAM;EACP,CACF;AAEH,SAAO;CACR;CAED,MAAM,sBAAsB,CAACC,QAA8B;AACzD,MAAI,IAAI,SAAS,OAAQ,QAAO;AAEhC,MAAI,OAAO,IAAI,YAAY,SACzB,QAAO;AAGT,SACE,MAAM,QAAQ,IAAI,QAAQ,IAC1B,IAAI,QAAQ,MAAM,CAAC,SAAS,KAAK,SAAS,cAAc;CAE3D;AAED,MAAK,IAAI,IAAI,GAAG,IAAI,SAAS,QAAQ,KAAK,GAAG;EAC3C,MAAM,cAAc,SAAS;AAE7B,MACE,oBAAoB,eAAe,IACnC,oBAAoB,YAAY,EAGhC,iBAAiB;GACf,GAAG;GACH,SAAS,CACP,GAAG,iBAAiB,eAAe,QAAQ,EAC3C,GAAG,iBAAiB,YAAY,QAAQ,AACzC;EACF;OACI;GACL,OAAO,KAAK,eAAe;GAC3B,iBAAiB;EAClB;CACF;CAED,OAAO,KAAK,eAAe;AAC3B,QAAO;AACR"}
|
|
@@ -106,6 +106,29 @@ function* _formatContentBlocks(content, toolCalls) {
|
|
|
106
106
|
source,
|
|
107
107
|
...cacheControl ? { cache_control: cacheControl } : {}
|
|
108
108
|
};
|
|
109
|
+
} else if (contentPart.type === "file") {
|
|
110
|
+
let source;
|
|
111
|
+
if ("url" in contentPart && typeof contentPart.url === "string") source = {
|
|
112
|
+
type: "url",
|
|
113
|
+
url: contentPart.url
|
|
114
|
+
};
|
|
115
|
+
else if ("data" in contentPart && (typeof contentPart.data === "string" || contentPart.data instanceof Uint8Array)) {
|
|
116
|
+
const media_type = "mimeType" in contentPart && typeof contentPart.mimeType === "string" ? contentPart.mimeType : "application/pdf";
|
|
117
|
+
const data = typeof contentPart.data === "string" ? contentPart.data : Buffer.from(contentPart.data).toString("base64");
|
|
118
|
+
source = {
|
|
119
|
+
type: "base64",
|
|
120
|
+
media_type,
|
|
121
|
+
data
|
|
122
|
+
};
|
|
123
|
+
} else if ("fileId" in contentPart && typeof contentPart.fileId === "string") source = {
|
|
124
|
+
type: "file",
|
|
125
|
+
file_id: contentPart.fileId
|
|
126
|
+
};
|
|
127
|
+
if (source) yield {
|
|
128
|
+
type: "document",
|
|
129
|
+
source,
|
|
130
|
+
...cacheControl ? { cache_control: cacheControl } : {}
|
|
131
|
+
};
|
|
109
132
|
} else if (contentPart.type === "document") yield {
|
|
110
133
|
...contentPart,
|
|
111
134
|
...cacheControl ? { cache_control: cacheControl } : {}
|