{"version":3,"file":"textEditor.cjs","names":["TextEditor20250728CommandSchema"],"sources":["../../src/tools/textEditor.ts"],"sourcesContent":["import Anthropic from \"@anthropic-ai/sdk\";\nimport { tool } from \"@langchain/core/tools\";\nimport type { DynamicStructuredTool, ToolRuntime } from \"@langchain/core/tools\";\n\nimport {\n  TextEditor20250728CommandSchema,\n  type TextEditor20250728Command,\n} from \"./types.js\";\n\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/**\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 function textEditor_20250728(options?: TextEditor20250728Options) {\n  const name = \"str_replace_based_edit_tool\";\n  const textEditorTool = tool(\n    options?.execute as (\n      input: unknown,\n      runtime: ToolRuntime<unknown, unknown>\n    ) => string | Promise<string>,\n    {\n      name,\n      description: \"A tool for editing text files\",\n      schema: TextEditor20250728CommandSchema,\n    }\n  );\n\n  textEditorTool.extras = {\n    ...(textEditorTool.extras ?? {}),\n    providerToolDefinition: {\n      type: \"text_editor_20250728\",\n      name,\n      ...(options?.maxCharacters !== undefined && {\n        max_characters: options.maxCharacters,\n      }),\n    } satisfies Anthropic.Beta.Messages.BetaToolTextEditor20250728,\n  };\n\n  return textEditorTool as DynamicStructuredTool<\n    typeof TextEditor20250728CommandSchema,\n    TextEditor20250728Command,\n    unknown,\n    string | Promise<string>\n  >;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8EA,SAAgB,oBAAoB,SAAqC;CACvE,MAAM,OAAO;CACb,MAAM,kBAAA,GAAA,sBAAA,MACJ,SAAS,SAIT;EACE;EACA,aAAa;EACb,QAAQA,cAAAA;EACT,CACF;AAED,gBAAe,SAAS;EACtB,GAAI,eAAe,UAAU,EAAE;EAC/B,wBAAwB;GACtB,MAAM;GACN;GACA,GAAI,SAAS,kBAAkB,KAAA,KAAa,EAC1C,gBAAgB,QAAQ,eACzB;GACF;EACF;AAED,QAAO"}