@langchain/anthropic
Version:
Anthropic integrations for LangChain.js
1 lines • 15.3 kB
Source Map (JSON)
{"version":3,"file":"types.cjs","names":["z"],"sources":["../../src/tools/types.ts"],"sourcesContent":["import Anthropic from \"@anthropic-ai/sdk\";\nimport { z } from \"zod/v4\";\n\n/**\n * Memory tool command types as defined by Anthropic's memory tool API.\n * @beta\n * @see https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/memory-tool\n */\n\n// Zod schemas for memory commands\nexport const Memory20250818ViewCommandSchema = z.object({\n command: z.literal(\"view\"),\n path: z.string(),\n});\n\nexport const Memory20250818CreateCommandSchema = z.object({\n command: z.literal(\"create\"),\n path: z.string(),\n file_text: z.string(),\n});\n\nexport const Memory20250818StrReplaceCommandSchema = z.object({\n command: z.literal(\"str_replace\"),\n path: z.string(),\n old_str: z.string(),\n new_str: z.string(),\n});\n\nexport const Memory20250818InsertCommandSchema = z.object({\n command: z.literal(\"insert\"),\n path: z.string(),\n insert_line: z.number(),\n insert_text: z.string(),\n});\n\nexport const Memory20250818DeleteCommandSchema = z.object({\n command: z.literal(\"delete\"),\n path: z.string(),\n});\n\nexport const Memory20250818RenameCommandSchema = z.object({\n command: z.literal(\"rename\"),\n old_path: z.string(),\n new_path: z.string(),\n});\n\n// Discriminated union schema for all memory commands\nexport const Memory20250818CommandSchema = z.discriminatedUnion(\"command\", [\n Memory20250818ViewCommandSchema,\n Memory20250818CreateCommandSchema,\n Memory20250818StrReplaceCommandSchema,\n Memory20250818InsertCommandSchema,\n Memory20250818DeleteCommandSchema,\n Memory20250818RenameCommandSchema,\n]);\n\n// TypeScript types derived from Zod schemas\nexport type Memory20250818ViewCommand = z.infer<\n typeof Memory20250818ViewCommandSchema\n>;\nexport type Memory20250818CreateCommand = z.infer<\n typeof Memory20250818CreateCommandSchema\n>;\nexport type Memory20250818StrReplaceCommand = z.infer<\n typeof Memory20250818StrReplaceCommandSchema\n>;\nexport type Memory20250818InsertCommand = z.infer<\n typeof Memory20250818InsertCommandSchema\n>;\nexport type Memory20250818DeleteCommand = z.infer<\n typeof Memory20250818DeleteCommandSchema\n>;\nexport type Memory20250818RenameCommand = z.infer<\n typeof Memory20250818RenameCommandSchema\n>;\n\nexport type Memory20250818Command = z.infer<typeof Memory20250818CommandSchema>;\n\n/**\n * Options for creating a memory tool.\n */\nexport interface MemoryTool20250818Options {\n /**\n * Optional execute function that handles memory command execution.\n * In LangChain, this is typically handled separately when processing tool calls,\n * but this option is provided for compatibility with the AI SDK pattern.\n * Note: This option is currently unused but reserved for future use.\n */\n execute: (action: Memory20250818Command) => Promise<string> | string;\n}\n\n/**\n * Memory tool type definition.\n */\nexport type MemoryTool20250818 = Anthropic.Beta.BetaMemoryTool20250818;\n\n/**\n * Text editor tool command types for Claude 4.x models.\n * @see https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/text-editor-tool\n */\n\n// Zod schemas for text editor commands\nexport const TextEditor20250728ViewCommandSchema = z.object({\n command: z.literal(\"view\"),\n path: z.string(),\n view_range: z.tuple([z.number(), z.number()]).optional(),\n});\n\nexport const TextEditor20250728StrReplaceCommandSchema = z.object({\n command: z.literal(\"str_replace\"),\n path: z.string(),\n old_str: z.string(),\n new_str: z.string(),\n});\n\nexport const TextEditor20250728CreateCommandSchema = z.object({\n command: z.literal(\"create\"),\n path: z.string(),\n file_text: z.string(),\n});\n\nexport const TextEditor20250728InsertCommandSchema = z.object({\n command: z.literal(\"insert\"),\n path: z.string(),\n insert_line: z.number(),\n new_str: z.string(),\n});\n\n// Discriminated union schema for all text editor commands\nexport const TextEditor20250728CommandSchema = z.discriminatedUnion(\"command\", [\n TextEditor20250728ViewCommandSchema,\n TextEditor20250728StrReplaceCommandSchema,\n TextEditor20250728CreateCommandSchema,\n TextEditor20250728InsertCommandSchema,\n]);\n\n// TypeScript types derived from Zod schemas\nexport type TextEditor20250728ViewCommand = z.infer<\n typeof TextEditor20250728ViewCommandSchema\n>;\nexport type TextEditor20250728StrReplaceCommand = z.infer<\n typeof TextEditor20250728StrReplaceCommandSchema\n>;\nexport type TextEditor20250728CreateCommand = z.infer<\n typeof TextEditor20250728CreateCommandSchema\n>;\nexport type TextEditor20250728InsertCommand = z.infer<\n typeof TextEditor20250728InsertCommandSchema\n>;\nexport type TextEditor20250728Command = z.infer<\n typeof TextEditor20250728CommandSchema\n>;\n\n/**\n * Computer use tool action types for Claude Opus 4.5.\n * Includes zoom action which is not available in earlier versions.\n * @see https://platform.claude.com/docs/en/agents-and-tools/tool-use/computer-use-tool\n */\nexport type Computer20251124Action =\n | Computer20250124Action\n | ComputerZoomAction;\n\n/**\n * Computer use tool action types for Claude Sonnet 4.5, Haiku 4.5, Opus 4.1, Sonnet 4, Opus 4, and Sonnet 3.7 versions.\n * @see https://platform.claude.com/docs/en/agents-and-tools/tool-use/computer-use-tool\n */\nexport type Computer20250124Action =\n | ComputerScreenshotAction\n | ComputerLeftClickAction\n | ComputerRightClickAction\n | ComputerMiddleClickAction\n | ComputerDoubleClickAction\n | ComputerTripleClickAction\n | ComputerLeftClickDragAction\n | ComputerLeftMouseDownAction\n | ComputerLeftMouseUpAction\n | ComputerScrollAction\n | ComputerTypeAction\n | ComputerKeyAction\n | ComputerMouseMoveAction\n | ComputerHoldKeyAction\n | ComputerWaitAction;\n\n// Zod schemas for computer actions\nconst coordinateSchema = z.tuple([z.number(), z.number()]);\n\nexport const ComputerScreenshotActionSchema = z.object({\n action: z.literal(\"screenshot\"),\n});\n\nexport const ComputerLeftClickActionSchema = z.object({\n action: z.literal(\"left_click\"),\n coordinate: coordinateSchema,\n});\n\nexport const ComputerRightClickActionSchema = z.object({\n action: z.literal(\"right_click\"),\n coordinate: coordinateSchema,\n});\n\nexport const ComputerMiddleClickActionSchema = z.object({\n action: z.literal(\"middle_click\"),\n coordinate: coordinateSchema,\n});\n\nexport const ComputerDoubleClickActionSchema = z.object({\n action: z.literal(\"double_click\"),\n coordinate: coordinateSchema,\n});\n\nexport const ComputerTripleClickActionSchema = z.object({\n action: z.literal(\"triple_click\"),\n coordinate: coordinateSchema,\n});\n\nexport const ComputerLeftClickDragActionSchema = z.object({\n action: z.literal(\"left_click_drag\"),\n start_coordinate: coordinateSchema,\n end_coordinate: coordinateSchema,\n});\n\nexport const ComputerLeftMouseDownActionSchema = z.object({\n action: z.literal(\"left_mouse_down\"),\n coordinate: coordinateSchema,\n});\n\nexport const ComputerLeftMouseUpActionSchema = z.object({\n action: z.literal(\"left_mouse_up\"),\n coordinate: coordinateSchema,\n});\n\nexport const ComputerScrollActionSchema = z.object({\n action: z.literal(\"scroll\"),\n coordinate: coordinateSchema,\n scroll_direction: z.enum([\"up\", \"down\", \"left\", \"right\"]),\n scroll_amount: z.number(),\n});\n\nexport const ComputerTypeActionSchema = z.object({\n action: z.literal(\"type\"),\n text: z.string(),\n});\n\nexport const ComputerKeyActionSchema = z.object({\n action: z.literal(\"key\"),\n key: z.string(),\n});\n\nexport const ComputerMouseMoveActionSchema = z.object({\n action: z.literal(\"mouse_move\"),\n coordinate: coordinateSchema,\n});\n\nexport const ComputerHoldKeyActionSchema = z.object({\n action: z.literal(\"hold_key\"),\n key: z.string(),\n});\n\nexport const ComputerWaitActionSchema = z.object({\n action: z.literal(\"wait\"),\n duration: z.number().optional(),\n});\n\nexport const ComputerZoomActionSchema = z.object({\n action: z.literal(\"zoom\"),\n region: z.tuple([z.number(), z.number(), z.number(), z.number()]),\n});\n\n// Discriminated union schemas\nexport const Computer20250124ActionSchema = z.discriminatedUnion(\"action\", [\n ComputerScreenshotActionSchema,\n ComputerLeftClickActionSchema,\n ComputerRightClickActionSchema,\n ComputerMiddleClickActionSchema,\n ComputerDoubleClickActionSchema,\n ComputerTripleClickActionSchema,\n ComputerLeftClickDragActionSchema,\n ComputerLeftMouseDownActionSchema,\n ComputerLeftMouseUpActionSchema,\n ComputerScrollActionSchema,\n ComputerTypeActionSchema,\n ComputerKeyActionSchema,\n ComputerMouseMoveActionSchema,\n ComputerHoldKeyActionSchema,\n ComputerWaitActionSchema,\n]);\n\nexport const Computer20251124ActionSchema = z.discriminatedUnion(\"action\", [\n ComputerScreenshotActionSchema,\n ComputerLeftClickActionSchema,\n ComputerRightClickActionSchema,\n ComputerMiddleClickActionSchema,\n ComputerDoubleClickActionSchema,\n ComputerTripleClickActionSchema,\n ComputerLeftClickDragActionSchema,\n ComputerLeftMouseDownActionSchema,\n ComputerLeftMouseUpActionSchema,\n ComputerScrollActionSchema,\n ComputerTypeActionSchema,\n ComputerKeyActionSchema,\n ComputerMouseMoveActionSchema,\n ComputerHoldKeyActionSchema,\n ComputerWaitActionSchema,\n ComputerZoomActionSchema,\n]);\n\n// TypeScript types derived from Zod schemas\nexport type ComputerScreenshotAction = z.infer<\n typeof ComputerScreenshotActionSchema\n>;\n\nexport type ComputerLeftClickAction = z.infer<\n typeof ComputerLeftClickActionSchema\n>;\n\nexport type ComputerRightClickAction = z.infer<\n typeof ComputerRightClickActionSchema\n>;\n\nexport type ComputerMiddleClickAction = z.infer<\n typeof ComputerMiddleClickActionSchema\n>;\n\nexport type ComputerDoubleClickAction = z.infer<\n typeof ComputerDoubleClickActionSchema\n>;\n\nexport type ComputerTripleClickAction = z.infer<\n typeof ComputerTripleClickActionSchema\n>;\n\nexport type ComputerLeftClickDragAction = z.infer<\n typeof ComputerLeftClickDragActionSchema\n>;\n\nexport type ComputerLeftMouseDownAction = z.infer<\n typeof ComputerLeftMouseDownActionSchema\n>;\n\nexport type ComputerLeftMouseUpAction = z.infer<\n typeof ComputerLeftMouseUpActionSchema\n>;\n\nexport type ComputerScrollAction = z.infer<typeof ComputerScrollActionSchema>;\n\nexport type ComputerTypeAction = z.infer<typeof ComputerTypeActionSchema>;\n\nexport type ComputerKeyAction = z.infer<typeof ComputerKeyActionSchema>;\n\nexport type ComputerMouseMoveAction = z.infer<\n typeof ComputerMouseMoveActionSchema\n>;\n\nexport type ComputerHoldKeyAction = z.infer<typeof ComputerHoldKeyActionSchema>;\n\nexport type ComputerWaitAction = z.infer<typeof ComputerWaitActionSchema>;\n\nexport type ComputerZoomAction = z.infer<typeof ComputerZoomActionSchema>;\n\n/**\n * Bash tool command types for Claude 4 models and Claude 3.7.\n * @see https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/bash-tool\n */\n\n// Zod schemas for bash commands\nexport const Bash20250124ExecuteCommandSchema = z.object({\n command: z.string().describe(\"The bash command to run\"),\n});\n\nexport const Bash20250124RestartCommandSchema = z.object({\n restart: z.literal(true).describe(\"Set to true to restart the bash session\"),\n});\n\n// Union schema for all bash commands\nexport const Bash20250124CommandSchema = z.union([\n Bash20250124ExecuteCommandSchema,\n Bash20250124RestartCommandSchema,\n]);\n\n// TypeScript types derived from Zod schemas\nexport type Bash20250124ExecuteCommand = z.infer<\n typeof Bash20250124ExecuteCommandSchema\n>;\nexport type Bash20250124RestartCommand = z.infer<\n typeof Bash20250124RestartCommandSchema\n>;\nexport type Bash20250124Command = z.infer<typeof Bash20250124CommandSchema>;\n"],"mappings":";;;;;;;;;AAUA,MAAa,kCAAkCA,SAAE,OAAO;CACtD,SAASA,SAAE,QAAQ,OAAO;CAC1B,MAAMA,SAAE,QAAQ;AACjB,EAAC;AAEF,MAAa,oCAAoCA,SAAE,OAAO;CACxD,SAASA,SAAE,QAAQ,SAAS;CAC5B,MAAMA,SAAE,QAAQ;CAChB,WAAWA,SAAE,QAAQ;AACtB,EAAC;AAEF,MAAa,wCAAwCA,SAAE,OAAO;CAC5D,SAASA,SAAE,QAAQ,cAAc;CACjC,MAAMA,SAAE,QAAQ;CAChB,SAASA,SAAE,QAAQ;CACnB,SAASA,SAAE,QAAQ;AACpB,EAAC;AAEF,MAAa,oCAAoCA,SAAE,OAAO;CACxD,SAASA,SAAE,QAAQ,SAAS;CAC5B,MAAMA,SAAE,QAAQ;CAChB,aAAaA,SAAE,QAAQ;CACvB,aAAaA,SAAE,QAAQ;AACxB,EAAC;AAEF,MAAa,oCAAoCA,SAAE,OAAO;CACxD,SAASA,SAAE,QAAQ,SAAS;CAC5B,MAAMA,SAAE,QAAQ;AACjB,EAAC;AAEF,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