@vybestack/llxprt-code-tools 0.10.0-nightly.260613.1adad3b34
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/LICENSE +202 -0
- package/README.md +294 -0
- package/dist/.last_build +0 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/src/__tests__/fixtures/filesystem-tool-fixtures.d.ts +29 -0
- package/dist/src/__tests__/fixtures/filesystem-tool-fixtures.js +30 -0
- package/dist/src/__tests__/fixtures/filesystem-tool-fixtures.js.map +1 -0
- package/dist/src/__tests__/fixtures/key-storage-fixtures.d.ts +39 -0
- package/dist/src/__tests__/fixtures/key-storage-fixtures.js +53 -0
- package/dist/src/__tests__/fixtures/key-storage-fixtures.js.map +1 -0
- package/dist/src/__tests__/fixtures/provider-formatting-fixtures.d.ts +140 -0
- package/dist/src/__tests__/fixtures/provider-formatting-fixtures.js +157 -0
- package/dist/src/__tests__/fixtures/provider-formatting-fixtures.js.map +1 -0
- package/dist/src/__tests__/red-test-helpers.d.ts +14 -0
- package/dist/src/__tests__/red-test-helpers.js +18 -0
- package/dist/src/__tests__/red-test-helpers.js.map +1 -0
- package/dist/src/formatters/IToolFormatter.d.ts +84 -0
- package/dist/src/formatters/IToolFormatter.js +6 -0
- package/dist/src/formatters/IToolFormatter.js.map +1 -0
- package/dist/src/formatters/ToolFormatter.d.ts +94 -0
- package/dist/src/formatters/ToolFormatter.js +379 -0
- package/dist/src/formatters/ToolFormatter.js.map +1 -0
- package/dist/src/formatters/ToolIdStrategy.d.ts +79 -0
- package/dist/src/formatters/ToolIdStrategy.js +173 -0
- package/dist/src/formatters/ToolIdStrategy.js.map +1 -0
- package/dist/src/formatters/doubleEscapeUtils.d.ts +46 -0
- package/dist/src/formatters/doubleEscapeUtils.js +223 -0
- package/dist/src/formatters/doubleEscapeUtils.js.map +1 -0
- package/dist/src/formatters/index.d.ts +21 -0
- package/dist/src/formatters/index.js +12 -0
- package/dist/src/formatters/index.js.map +1 -0
- package/dist/src/formatters/toolIdNormalization.d.ts +28 -0
- package/dist/src/formatters/toolIdNormalization.js +97 -0
- package/dist/src/formatters/toolIdNormalization.js.map +1 -0
- package/dist/src/formatters/toolNameUtils.d.ts +43 -0
- package/dist/src/formatters/toolNameUtils.js +143 -0
- package/dist/src/formatters/toolNameUtils.js.map +1 -0
- package/dist/src/index.d.ts +88 -0
- package/dist/src/index.js +68 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/interfaces/IAsyncTaskService.d.ts +57 -0
- package/dist/src/interfaces/IAsyncTaskService.js +6 -0
- package/dist/src/interfaces/IAsyncTaskService.js.map +1 -0
- package/dist/src/interfaces/IIdeService.d.ts +62 -0
- package/dist/src/interfaces/IIdeService.js +6 -0
- package/dist/src/interfaces/IIdeService.js.map +1 -0
- package/dist/src/interfaces/ILspService.d.ts +54 -0
- package/dist/src/interfaces/ILspService.js +6 -0
- package/dist/src/interfaces/ILspService.js.map +1 -0
- package/dist/src/interfaces/IMcpToolService.d.ts +47 -0
- package/dist/src/interfaces/IMcpToolService.js +6 -0
- package/dist/src/interfaces/IMcpToolService.js.map +1 -0
- package/dist/src/interfaces/IPromptRegistryService.d.ts +51 -0
- package/dist/src/interfaces/IPromptRegistryService.js +6 -0
- package/dist/src/interfaces/IPromptRegistryService.js.map +1 -0
- package/dist/src/interfaces/ISettingsService.d.ts +50 -0
- package/dist/src/interfaces/ISettingsService.js +6 -0
- package/dist/src/interfaces/ISettingsService.js.map +1 -0
- package/dist/src/interfaces/IShellExecutionService.d.ts +55 -0
- package/dist/src/interfaces/IShellExecutionService.js +6 -0
- package/dist/src/interfaces/IShellExecutionService.js.map +1 -0
- package/dist/src/interfaces/IShellToolHost.d.ts +176 -0
- package/dist/src/interfaces/IShellToolHost.js +6 -0
- package/dist/src/interfaces/IShellToolHost.js.map +1 -0
- package/dist/src/interfaces/ISkillService.d.ts +69 -0
- package/dist/src/interfaces/ISkillService.js +6 -0
- package/dist/src/interfaces/ISkillService.js.map +1 -0
- package/dist/src/interfaces/IStorageService.d.ts +42 -0
- package/dist/src/interfaces/IStorageService.js +6 -0
- package/dist/src/interfaces/IStorageService.js.map +1 -0
- package/dist/src/interfaces/ISubagentService.d.ts +112 -0
- package/dist/src/interfaces/ISubagentService.js +6 -0
- package/dist/src/interfaces/ISubagentService.js.map +1 -0
- package/dist/src/interfaces/ITaskToolHost.d.ts +185 -0
- package/dist/src/interfaces/ITaskToolHost.js +6 -0
- package/dist/src/interfaces/ITaskToolHost.js.map +1 -0
- package/dist/src/interfaces/ITodoService.d.ts +79 -0
- package/dist/src/interfaces/ITodoService.js +6 -0
- package/dist/src/interfaces/ITodoService.js.map +1 -0
- package/dist/src/interfaces/IToolHost.d.ts +91 -0
- package/dist/src/interfaces/IToolHost.js +6 -0
- package/dist/src/interfaces/IToolHost.js.map +1 -0
- package/dist/src/interfaces/IToolKeyStorage.d.ts +62 -0
- package/dist/src/interfaces/IToolKeyStorage.js +6 -0
- package/dist/src/interfaces/IToolKeyStorage.js.map +1 -0
- package/dist/src/interfaces/IToolMessageBus.d.ts +63 -0
- package/dist/src/interfaces/IToolMessageBus.js +6 -0
- package/dist/src/interfaces/IToolMessageBus.js.map +1 -0
- package/dist/src/interfaces/IToolRegistryHost.d.ts +43 -0
- package/dist/src/interfaces/IToolRegistryHost.js +6 -0
- package/dist/src/interfaces/IToolRegistryHost.js.map +1 -0
- package/dist/src/interfaces/IWebSearchService.d.ts +16 -0
- package/dist/src/interfaces/IWebSearchService.js +7 -0
- package/dist/src/interfaces/IWebSearchService.js.map +1 -0
- package/dist/src/interfaces/index.d.ts +33 -0
- package/dist/src/interfaces/index.js +6 -0
- package/dist/src/interfaces/index.js.map +1 -0
- package/dist/src/tools/activate-skill.d.ts +26 -0
- package/dist/src/tools/activate-skill.js +121 -0
- package/dist/src/tools/activate-skill.js.map +1 -0
- package/dist/src/tools/apply-patch.d.ts +65 -0
- package/dist/src/tools/apply-patch.js +528 -0
- package/dist/src/tools/apply-patch.js.map +1 -0
- package/dist/src/tools/ast-edit/ast-config.d.ts +67 -0
- package/dist/src/tools/ast-edit/ast-config.js +72 -0
- package/dist/src/tools/ast-edit/ast-config.js.map +1 -0
- package/dist/src/tools/ast-edit/ast-edit-invocation.d.ts +40 -0
- package/dist/src/tools/ast-edit/ast-edit-invocation.js +410 -0
- package/dist/src/tools/ast-edit/ast-edit-invocation.js.map +1 -0
- package/dist/src/tools/ast-edit/ast-query-extractor.d.ts +21 -0
- package/dist/src/tools/ast-edit/ast-query-extractor.js +178 -0
- package/dist/src/tools/ast-edit/ast-query-extractor.js.map +1 -0
- package/dist/src/tools/ast-edit/ast-read-file-invocation.d.ts +26 -0
- package/dist/src/tools/ast-edit/ast-read-file-invocation.js +149 -0
- package/dist/src/tools/ast-edit/ast-read-file-invocation.js.map +1 -0
- package/dist/src/tools/ast-edit/constants.d.ts +30 -0
- package/dist/src/tools/ast-edit/constants.js +36 -0
- package/dist/src/tools/ast-edit/constants.js.map +1 -0
- package/dist/src/tools/ast-edit/context-collector.d.ts +25 -0
- package/dist/src/tools/ast-edit/context-collector.js +115 -0
- package/dist/src/tools/ast-edit/context-collector.js.map +1 -0
- package/dist/src/tools/ast-edit/context-optimizer.d.ts +29 -0
- package/dist/src/tools/ast-edit/context-optimizer.js +86 -0
- package/dist/src/tools/ast-edit/context-optimizer.js.map +1 -0
- package/dist/src/tools/ast-edit/cross-file-analyzer.d.ts +41 -0
- package/dist/src/tools/ast-edit/cross-file-analyzer.js +294 -0
- package/dist/src/tools/ast-edit/cross-file-analyzer.js.map +1 -0
- package/dist/src/tools/ast-edit/edit-calculator.d.ts +71 -0
- package/dist/src/tools/ast-edit/edit-calculator.js +249 -0
- package/dist/src/tools/ast-edit/edit-calculator.js.map +1 -0
- package/dist/src/tools/ast-edit/edit-helpers.d.ts +22 -0
- package/dist/src/tools/ast-edit/edit-helpers.js +36 -0
- package/dist/src/tools/ast-edit/edit-helpers.js.map +1 -0
- package/dist/src/tools/ast-edit/language-analysis.d.ts +19 -0
- package/dist/src/tools/ast-edit/language-analysis.js +123 -0
- package/dist/src/tools/ast-edit/language-analysis.js.map +1 -0
- package/dist/src/tools/ast-edit/local-context-analyzer.d.ts +84 -0
- package/dist/src/tools/ast-edit/local-context-analyzer.js +267 -0
- package/dist/src/tools/ast-edit/local-context-analyzer.js.map +1 -0
- package/dist/src/tools/ast-edit/repository-context-provider.d.ts +22 -0
- package/dist/src/tools/ast-edit/repository-context-provider.js +139 -0
- package/dist/src/tools/ast-edit/repository-context-provider.js.map +1 -0
- package/dist/src/tools/ast-edit/types.d.ts +155 -0
- package/dist/src/tools/ast-edit/types.js +7 -0
- package/dist/src/tools/ast-edit/types.js.map +1 -0
- package/dist/src/tools/ast-edit/workspace-context-provider.d.ts +22 -0
- package/dist/src/tools/ast-edit/workspace-context-provider.js +39 -0
- package/dist/src/tools/ast-edit/workspace-context-provider.js.map +1 -0
- package/dist/src/tools/ast-edit.d.ts +43 -0
- package/dist/src/tools/ast-edit.js +183 -0
- package/dist/src/tools/ast-edit.js.map +1 -0
- package/dist/src/tools/ast-grep.d.ts +22 -0
- package/dist/src/tools/ast-grep.js +291 -0
- package/dist/src/tools/ast-grep.js.map +1 -0
- package/dist/src/tools/check-async-tasks.d.ts +46 -0
- package/dist/src/tools/check-async-tasks.js +241 -0
- package/dist/src/tools/check-async-tasks.js.map +1 -0
- package/dist/src/tools/codesearch.d.ts +25 -0
- package/dist/src/tools/codesearch.js +153 -0
- package/dist/src/tools/codesearch.js.map +1 -0
- package/dist/src/tools/delete_line_range.d.ts +41 -0
- package/dist/src/tools/delete_line_range.js +238 -0
- package/dist/src/tools/delete_line_range.js.map +1 -0
- package/dist/src/tools/direct-web-fetch.d.ts +22 -0
- package/dist/src/tools/direct-web-fetch.js +215 -0
- package/dist/src/tools/direct-web-fetch.js.map +1 -0
- package/dist/src/tools/edit-utils.d.ts +53 -0
- package/dist/src/tools/edit-utils.js +250 -0
- package/dist/src/tools/edit-utils.js.map +1 -0
- package/dist/src/tools/edit.d.ts +70 -0
- package/dist/src/tools/edit.js +816 -0
- package/dist/src/tools/edit.js.map +1 -0
- package/dist/src/tools/exa-web-search.d.ts +27 -0
- package/dist/src/tools/exa-web-search.js +153 -0
- package/dist/src/tools/exa-web-search.js.map +1 -0
- package/dist/src/tools/glob.d.ts +55 -0
- package/dist/src/tools/glob.js +284 -0
- package/dist/src/tools/glob.js.map +1 -0
- package/dist/src/tools/google-web-fetch.d.ts +34 -0
- package/dist/src/tools/google-web-fetch.js +417 -0
- package/dist/src/tools/google-web-fetch.js.map +1 -0
- package/dist/src/tools/google-web-search-invocation.d.ts +53 -0
- package/dist/src/tools/google-web-search-invocation.js +180 -0
- package/dist/src/tools/google-web-search-invocation.js.map +1 -0
- package/dist/src/tools/google-web-search.d.ts +16 -0
- package/dist/src/tools/google-web-search.js +34 -0
- package/dist/src/tools/google-web-search.js.map +1 -0
- package/dist/src/tools/grep.d.ts +56 -0
- package/dist/src/tools/grep.js +883 -0
- package/dist/src/tools/grep.js.map +1 -0
- package/dist/src/tools/insert_at_line.d.ts +41 -0
- package/dist/src/tools/insert_at_line.js +287 -0
- package/dist/src/tools/insert_at_line.js.map +1 -0
- package/dist/src/tools/list-subagents.d.ts +31 -0
- package/dist/src/tools/list-subagents.js +122 -0
- package/dist/src/tools/list-subagents.js.map +1 -0
- package/dist/src/tools/ls.d.ts +71 -0
- package/dist/src/tools/ls.js +238 -0
- package/dist/src/tools/ls.js.map +1 -0
- package/dist/src/tools/memoryTool.d.ts +66 -0
- package/dist/src/tools/memoryTool.js +435 -0
- package/dist/src/tools/memoryTool.js.map +1 -0
- package/dist/src/tools/modifiable-tool.d.ts +37 -0
- package/dist/src/tools/modifiable-tool.js +120 -0
- package/dist/src/tools/modifiable-tool.js.map +1 -0
- package/dist/src/tools/read-file.d.ts +49 -0
- package/dist/src/tools/read-file.js +279 -0
- package/dist/src/tools/read-file.js.map +1 -0
- package/dist/src/tools/read-many-files.d.ts +60 -0
- package/dist/src/tools/read-many-files.js +529 -0
- package/dist/src/tools/read-many-files.js.map +1 -0
- package/dist/src/tools/read_line_range.d.ts +47 -0
- package/dist/src/tools/read_line_range.js +248 -0
- package/dist/src/tools/read_line_range.js.map +1 -0
- package/dist/src/tools/ripGrep.d.ts +41 -0
- package/dist/src/tools/ripGrep.js +395 -0
- package/dist/src/tools/ripGrep.js.map +1 -0
- package/dist/src/tools/shell.d.ts +60 -0
- package/dist/src/tools/shell.js +735 -0
- package/dist/src/tools/shell.js.map +1 -0
- package/dist/src/tools/structural-analysis.d.ts +27 -0
- package/dist/src/tools/structural-analysis.js +1089 -0
- package/dist/src/tools/structural-analysis.js.map +1 -0
- package/dist/src/tools/stubs.d.ts +10 -0
- package/dist/src/tools/stubs.js +6 -0
- package/dist/src/tools/stubs.js.map +1 -0
- package/dist/src/tools/task.d.ts +41 -0
- package/dist/src/tools/task.js +195 -0
- package/dist/src/tools/task.js.map +1 -0
- package/dist/src/tools/todo-events.d.ts +22 -0
- package/dist/src/tools/todo-events.js +24 -0
- package/dist/src/tools/todo-events.js.map +1 -0
- package/dist/src/tools/todo-pause.d.ts +29 -0
- package/dist/src/tools/todo-pause.js +172 -0
- package/dist/src/tools/todo-pause.js.map +1 -0
- package/dist/src/tools/todo-read.d.ts +18 -0
- package/dist/src/tools/todo-read.js +98 -0
- package/dist/src/tools/todo-read.js.map +1 -0
- package/dist/src/tools/todo-store.d.ts +35 -0
- package/dist/src/tools/todo-store.js +124 -0
- package/dist/src/tools/todo-store.js.map +1 -0
- package/dist/src/tools/todo-write.d.ts +29 -0
- package/dist/src/tools/todo-write.js +366 -0
- package/dist/src/tools/todo-write.js.map +1 -0
- package/dist/src/tools/tool-registry.d.ts +156 -0
- package/dist/src/tools/tool-registry.js +623 -0
- package/dist/src/tools/tool-registry.js.map +1 -0
- package/dist/src/tools/tools.d.ts +403 -0
- package/dist/src/tools/tools.js +519 -0
- package/dist/src/tools/tools.js.map +1 -0
- package/dist/src/tools/write-file.d.ts +45 -0
- package/dist/src/tools/write-file.js +320 -0
- package/dist/src/tools/write-file.js.map +1 -0
- package/dist/src/types/index.d.ts +17 -0
- package/dist/src/types/index.js +9 -0
- package/dist/src/types/index.js.map +1 -0
- package/dist/src/types/provider-content-types.d.ts +56 -0
- package/dist/src/types/provider-content-types.js +6 -0
- package/dist/src/types/provider-content-types.js.map +1 -0
- package/dist/src/types/todo-schemas.d.ts +263 -0
- package/dist/src/types/todo-schemas.js +32 -0
- package/dist/src/types/todo-schemas.js.map +1 -0
- package/dist/src/types/tool-confirmation-types.d.ts +34 -0
- package/dist/src/types/tool-confirmation-types.js +29 -0
- package/dist/src/types/tool-confirmation-types.js.map +1 -0
- package/dist/src/types/tool-context.d.ts +31 -0
- package/dist/src/types/tool-context.js +6 -0
- package/dist/src/types/tool-context.js.map +1 -0
- package/dist/src/types/tool-error.d.ts +69 -0
- package/dist/src/types/tool-error.js +94 -0
- package/dist/src/types/tool-error.js.map +1 -0
- package/dist/src/types/tool-names.d.ts +57 -0
- package/dist/src/types/tool-names.js +64 -0
- package/dist/src/types/tool-names.js.map +1 -0
- package/dist/src/utils/EmojiFilter.d.ts +134 -0
- package/dist/src/utils/EmojiFilter.js +370 -0
- package/dist/src/utils/EmojiFilter.js.map +1 -0
- package/dist/src/utils/ast-grep-utils.d.ts +42 -0
- package/dist/src/utils/ast-grep-utils.js +140 -0
- package/dist/src/utils/ast-grep-utils.js.map +1 -0
- package/dist/src/utils/debugLogger.d.ts +11 -0
- package/dist/src/utils/debugLogger.js +16 -0
- package/dist/src/utils/debugLogger.js.map +1 -0
- package/dist/src/utils/diffOptions.d.ts +14 -0
- package/dist/src/utils/diffOptions.js +46 -0
- package/dist/src/utils/diffOptions.js.map +1 -0
- package/dist/src/utils/editor.d.ts +39 -0
- package/dist/src/utils/editor.js +212 -0
- package/dist/src/utils/editor.js.map +1 -0
- package/dist/src/utils/ensure-dirs.d.ts +10 -0
- package/dist/src/utils/ensure-dirs.js +16 -0
- package/dist/src/utils/ensure-dirs.js.map +1 -0
- package/dist/src/utils/errors.d.ts +59 -0
- package/dist/src/utils/errors.js +178 -0
- package/dist/src/utils/errors.js.map +1 -0
- package/dist/src/utils/fetch.d.ts +11 -0
- package/dist/src/utils/fetch.js +74 -0
- package/dist/src/utils/fetch.js.map +1 -0
- package/dist/src/utils/fileUtils.d.ts +32 -0
- package/dist/src/utils/fileUtils.js +363 -0
- package/dist/src/utils/fileUtils.js.map +1 -0
- package/dist/src/utils/fuzzy-replacer.d.ts +61 -0
- package/dist/src/utils/fuzzy-replacer.js +492 -0
- package/dist/src/utils/fuzzy-replacer.js.map +1 -0
- package/dist/src/utils/gitLineChanges.d.ts +12 -0
- package/dist/src/utils/gitLineChanges.js +171 -0
- package/dist/src/utils/gitLineChanges.js.map +1 -0
- package/dist/src/utils/gitUtils.d.ts +6 -0
- package/dist/src/utils/gitUtils.js +31 -0
- package/dist/src/utils/gitUtils.js.map +1 -0
- package/dist/src/utils/lsp-diagnostics-helper.d.ts +27 -0
- package/dist/src/utils/lsp-diagnostics-helper.js +62 -0
- package/dist/src/utils/lsp-diagnostics-helper.js.map +1 -0
- package/dist/src/utils/mediaUtils.d.ts +38 -0
- package/dist/src/utils/mediaUtils.js +22 -0
- package/dist/src/utils/mediaUtils.js.map +1 -0
- package/dist/src/utils/pathValidation.d.ts +7 -0
- package/dist/src/utils/pathValidation.js +39 -0
- package/dist/src/utils/pathValidation.js.map +1 -0
- package/dist/src/utils/paths.d.ts +7 -0
- package/dist/src/utils/paths.js +158 -0
- package/dist/src/utils/paths.js.map +1 -0
- package/dist/src/utils/resolveTextSearchTarget.d.ts +17 -0
- package/dist/src/utils/resolveTextSearchTarget.js +45 -0
- package/dist/src/utils/resolveTextSearchTarget.js.map +1 -0
- package/dist/src/utils/retry.d.ts +17 -0
- package/dist/src/utils/retry.js +185 -0
- package/dist/src/utils/retry.js.map +1 -0
- package/dist/src/utils/ripgrepPathResolver.d.ts +23 -0
- package/dist/src/utils/ripgrepPathResolver.js +179 -0
- package/dist/src/utils/ripgrepPathResolver.js.map +1 -0
- package/dist/src/utils/safeJsonStringify.d.ts +9 -0
- package/dist/src/utils/safeJsonStringify.js +21 -0
- package/dist/src/utils/safeJsonStringify.js.map +1 -0
- package/dist/src/utils/schemaValidator.d.ts +13 -0
- package/dist/src/utils/schemaValidator.js +275 -0
- package/dist/src/utils/schemaValidator.js.map +1 -0
- package/dist/src/utils/terminalSerializer.d.ts +33 -0
- package/dist/src/utils/terminalSerializer.js +6 -0
- package/dist/src/utils/terminalSerializer.js.map +1 -0
- package/dist/src/utils/todoContextTracker.d.ts +12 -0
- package/dist/src/utils/todoContextTracker.js +28 -0
- package/dist/src/utils/todoContextTracker.js.map +1 -0
- package/dist/src/utils/todoFormatter.d.ts +24 -0
- package/dist/src/utils/todoFormatter.js +157 -0
- package/dist/src/utils/todoFormatter.js.map +1 -0
- package/dist/src/utils/todoReminderService.d.ts +22 -0
- package/dist/src/utils/todoReminderService.js +43 -0
- package/dist/src/utils/todoReminderService.js.map +1 -0
- package/dist/src/utils/tool-key-storage-facade.d.ts +32 -0
- package/dist/src/utils/tool-key-storage-facade.js +56 -0
- package/dist/src/utils/tool-key-storage-facade.js.map +1 -0
- package/dist/src/utils/tool-key-storage-types.d.ts +56 -0
- package/dist/src/utils/tool-key-storage-types.js +56 -0
- package/dist/src/utils/tool-key-storage-types.js.map +1 -0
- package/dist/src/utils/toolOutputLimiter.d.ts +29 -0
- package/dist/src/utils/toolOutputLimiter.js +107 -0
- package/dist/src/utils/toolOutputLimiter.js.map +1 -0
- package/dist/src/utils/unicodeUtils.d.ts +55 -0
- package/dist/src/utils/unicodeUtils.js +129 -0
- package/dist/src/utils/unicodeUtils.js.map +1 -0
- package/package.json +75 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @plan:PLAN-20260608-ISSUE1585.P05
|
|
3
|
+
* @requirement:REQ-API-001, REQ-TEMPORARY-INTERFACES
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Detects if a tool format should use double-escape handling.
|
|
7
|
+
* @param toolFormat - The tool format to check.
|
|
8
|
+
* @returns true if the format typically needs double-escape handling.
|
|
9
|
+
*/
|
|
10
|
+
export declare function shouldUseDoubleEscapeHandling(toolFormat: string): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Checks if a JSON string appears to be double-stringified.
|
|
13
|
+
* @param jsonString - The JSON string to check.
|
|
14
|
+
* @returns Object with detection results and corrected value if applicable.
|
|
15
|
+
*/
|
|
16
|
+
export declare function detectDoubleEscaping(jsonString: string): {
|
|
17
|
+
isDoubleEscaped: boolean;
|
|
18
|
+
correctedValue?: unknown;
|
|
19
|
+
originalValue: string;
|
|
20
|
+
detectionDetails: {
|
|
21
|
+
firstParse?: string;
|
|
22
|
+
secondParse?: unknown;
|
|
23
|
+
error?: string;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Detects double-escaping in streaming tool call chunks.
|
|
28
|
+
* @param chunk - The streaming chunk to analyze.
|
|
29
|
+
* @returns true if double-escaping patterns are detected.
|
|
30
|
+
*/
|
|
31
|
+
export declare function detectDoubleEscapingInChunk(chunk: string): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Processes tool call parameters, fixing double-escaping if detected.
|
|
34
|
+
* @param parametersString - The JSON string containing tool parameters.
|
|
35
|
+
* @param toolName - Name of the tool (for context).
|
|
36
|
+
* @param format - The tool format being used (optional).
|
|
37
|
+
* @returns Processed parameters object.
|
|
38
|
+
*/
|
|
39
|
+
export declare function processToolParameters(parametersString: string, toolName: string, format?: string): unknown;
|
|
40
|
+
/**
|
|
41
|
+
* Logs double-escaping detection in streaming chunks (no-op in tools package).
|
|
42
|
+
* @param chunk - The chunk that contains potential double-escaping.
|
|
43
|
+
* @param toolName - Name of the tool.
|
|
44
|
+
* @param format - The tool format.
|
|
45
|
+
*/
|
|
46
|
+
export declare function logDoubleEscapingInChunk(_chunk: string, _toolName: string, format: string): void;
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @plan:PLAN-20260608-ISSUE1585.P05
|
|
3
|
+
* @requirement:REQ-API-001, REQ-TEMPORARY-INTERFACES
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @license
|
|
7
|
+
* Copyright 2025 Google LLC
|
|
8
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Package-local double-escape detection and repair utilities.
|
|
12
|
+
*
|
|
13
|
+
* Handles tool call parameters that arrive double-stringified
|
|
14
|
+
* (e.g., Qwen models, GLM-4.5). This is a self-contained copy
|
|
15
|
+
* with core DebugLogger replaced by a no-op to maintain zero
|
|
16
|
+
* core imports.
|
|
17
|
+
*/
|
|
18
|
+
const noop = {
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
20
|
+
debug: (_msg) => { },
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
22
|
+
error: (_msg) => { },
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
24
|
+
warn: (_msg) => { },
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Detects if a tool format should use double-escape handling.
|
|
28
|
+
* @param toolFormat - The tool format to check.
|
|
29
|
+
* @returns true if the format typically needs double-escape handling.
|
|
30
|
+
*/
|
|
31
|
+
export function shouldUseDoubleEscapeHandling(toolFormat) {
|
|
32
|
+
return toolFormat === 'qwen';
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Fixes stringified values in a parsed object by parsing any string values
|
|
36
|
+
* that contain valid JSON objects or arrays.
|
|
37
|
+
*/
|
|
38
|
+
function fixStringifiedValues(parsed) {
|
|
39
|
+
const fixed = { ...parsed };
|
|
40
|
+
let wasDoubleEscaped = false;
|
|
41
|
+
for (const [key, value] of Object.entries(fixed)) {
|
|
42
|
+
if (typeof value !== 'string') {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
const testParse = JSON.parse(value);
|
|
47
|
+
if (typeof testParse === 'object') {
|
|
48
|
+
fixed[key] = testParse;
|
|
49
|
+
wasDoubleEscaped = true;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
// Keep original value if can't parse
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return { fixed, wasDoubleEscaped };
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Checks if a JSON string appears to be double-stringified.
|
|
60
|
+
* @param jsonString - The JSON string to check.
|
|
61
|
+
* @returns Object with detection results and corrected value if applicable.
|
|
62
|
+
*/
|
|
63
|
+
export function detectDoubleEscaping(jsonString) {
|
|
64
|
+
const result = {
|
|
65
|
+
isDoubleEscaped: false,
|
|
66
|
+
correctedValue: undefined,
|
|
67
|
+
originalValue: jsonString,
|
|
68
|
+
detectionDetails: {},
|
|
69
|
+
};
|
|
70
|
+
try {
|
|
71
|
+
const parsed = JSON.parse(jsonString);
|
|
72
|
+
if (typeof parsed === 'string') {
|
|
73
|
+
result.detectionDetails.firstParse = parsed;
|
|
74
|
+
try {
|
|
75
|
+
const doubleParsed = JSON.parse(parsed);
|
|
76
|
+
result.isDoubleEscaped = true;
|
|
77
|
+
result.correctedValue = doubleParsed;
|
|
78
|
+
result.detectionDetails.secondParse = doubleParsed;
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
result.correctedValue = parsed;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
else if (typeof parsed === 'object' && parsed !== null) {
|
|
85
|
+
const hasStringifiedValues = Object.values(parsed).some((value) => {
|
|
86
|
+
if (typeof value === 'string') {
|
|
87
|
+
try {
|
|
88
|
+
const testParse = JSON.parse(value);
|
|
89
|
+
return typeof testParse === 'object';
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return false;
|
|
96
|
+
});
|
|
97
|
+
if (hasStringifiedValues) {
|
|
98
|
+
const { fixed, wasDoubleEscaped } = fixStringifiedValues(parsed);
|
|
99
|
+
result.isDoubleEscaped = wasDoubleEscaped;
|
|
100
|
+
result.correctedValue = fixed;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
result.correctedValue = parsed;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
result.correctedValue = parsed;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
catch (parseError) {
|
|
111
|
+
result.detectionDetails.error = String(parseError);
|
|
112
|
+
}
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Detects double-escaping in streaming tool call chunks.
|
|
117
|
+
* @param chunk - The streaming chunk to analyze.
|
|
118
|
+
* @returns true if double-escaping patterns are detected.
|
|
119
|
+
*/
|
|
120
|
+
export function detectDoubleEscapingInChunk(chunk) {
|
|
121
|
+
const backslashBracket = String.raw `\\[`;
|
|
122
|
+
const doubleBackslash = String.raw `\\\\`;
|
|
123
|
+
const backslashQuote = String.raw `\\"`;
|
|
124
|
+
const startPattern = String.raw `"\\`;
|
|
125
|
+
const endPattern = String.raw `\\"`;
|
|
126
|
+
return (chunk.includes(backslashBracket) ||
|
|
127
|
+
chunk.includes(doubleBackslash) ||
|
|
128
|
+
chunk.includes(backslashQuote) ||
|
|
129
|
+
(chunk.startsWith(startPattern) && chunk.endsWith(endPattern)));
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Processes tool call parameters, fixing double-escaping if detected.
|
|
133
|
+
* @param parametersString - The JSON string containing tool parameters.
|
|
134
|
+
* @param toolName - Name of the tool (for context).
|
|
135
|
+
* @param format - The tool format being used (optional).
|
|
136
|
+
* @returns Processed parameters object.
|
|
137
|
+
*/
|
|
138
|
+
export function processToolParameters(parametersString, toolName, format) {
|
|
139
|
+
if (!parametersString.trim()) {
|
|
140
|
+
return {};
|
|
141
|
+
}
|
|
142
|
+
return tryMultipleParsingStrategies(parametersString, toolName, format);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Try multiple parsing strategies to handle tool parameters.
|
|
146
|
+
*/
|
|
147
|
+
function tryMultipleParsingStrategies(parametersString, toolName, format) {
|
|
148
|
+
// Strategy 1: Direct JSON parsing
|
|
149
|
+
try {
|
|
150
|
+
const parsed = JSON.parse(parametersString);
|
|
151
|
+
if (typeof parsed === 'string' && parsed.trim() === '') {
|
|
152
|
+
return {};
|
|
153
|
+
}
|
|
154
|
+
if (typeof parsed === 'string' && parsed.trim().startsWith('{')) {
|
|
155
|
+
// Might be double-escaped, continue to strategy 2
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
return parsed;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
// Continue to next strategy
|
|
163
|
+
}
|
|
164
|
+
// Strategy 2: Detect and repair double escaping
|
|
165
|
+
const detection = detectDoubleEscaping(parametersString);
|
|
166
|
+
const formatLabel = format || 'auto';
|
|
167
|
+
if (detection.correctedValue !== undefined) {
|
|
168
|
+
if (detection.isDoubleEscaped) {
|
|
169
|
+
noop.error(`[${formatLabel}] Fixed double-escaped parameters for ${toolName}`);
|
|
170
|
+
}
|
|
171
|
+
void formatLabel;
|
|
172
|
+
const converted = convertStringNumbersToNumbers(detection.correctedValue);
|
|
173
|
+
if (typeof converted === 'string' && converted.trim() === '') {
|
|
174
|
+
return {};
|
|
175
|
+
}
|
|
176
|
+
return converted;
|
|
177
|
+
}
|
|
178
|
+
// Strategy 3: Return original string (last resort)
|
|
179
|
+
if (detection.detectionDetails.error) {
|
|
180
|
+
noop.error(`[${formatLabel}] Failed to parse parameters for ${toolName}`);
|
|
181
|
+
}
|
|
182
|
+
return parametersString;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Converts string numbers to actual numbers in an object.
|
|
186
|
+
* Needed for models that stringify numeric parameters.
|
|
187
|
+
*/
|
|
188
|
+
function convertStringNumbersToNumbers(obj) {
|
|
189
|
+
if (obj == null)
|
|
190
|
+
return obj;
|
|
191
|
+
if (typeof obj === 'string') {
|
|
192
|
+
if (/^-?(?:\d+|\d*\.\d+)(?:[eE][+-]?\d+)?$/.test(obj)) {
|
|
193
|
+
const num = Number(obj);
|
|
194
|
+
if (Number.isFinite(num))
|
|
195
|
+
return num;
|
|
196
|
+
}
|
|
197
|
+
return obj;
|
|
198
|
+
}
|
|
199
|
+
if (Array.isArray(obj)) {
|
|
200
|
+
return obj.map(convertStringNumbersToNumbers);
|
|
201
|
+
}
|
|
202
|
+
if (typeof obj === 'object' &&
|
|
203
|
+
Object.getPrototypeOf(obj) === Object.prototype) {
|
|
204
|
+
const result = {};
|
|
205
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
206
|
+
result[key] = convertStringNumbersToNumbers(value);
|
|
207
|
+
}
|
|
208
|
+
return result;
|
|
209
|
+
}
|
|
210
|
+
return obj;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Logs double-escaping detection in streaming chunks (no-op in tools package).
|
|
214
|
+
* @param chunk - The chunk that contains potential double-escaping.
|
|
215
|
+
* @param toolName - Name of the tool.
|
|
216
|
+
* @param format - The tool format.
|
|
217
|
+
*/
|
|
218
|
+
export function logDoubleEscapingInChunk(_chunk, _toolName, format) {
|
|
219
|
+
// No-op in tools package: core's DebugLogger is not available.
|
|
220
|
+
// Detection logic still runs in detectDoubleEscapingInChunk above.
|
|
221
|
+
void format;
|
|
222
|
+
}
|
|
223
|
+
//# sourceMappingURL=doubleEscapeUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"doubleEscapeUtils.js","sourceRoot":"","sources":["../../../src/formatters/doubleEscapeUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;GAIG;AAEH;;;;;;;GAOG;AAEH,MAAM,IAAI,GAAG;IACX,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PDX-License-Identifier: Apache-2.0
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Barrel export for package-local formatter utilities.
|
|
12
|
+
*
|
|
13
|
+
* All formatters are self-contained with zero core/cli/providers imports.
|
|
14
|
+
*/
|
|
15
|
+
export type { IToolFormatter, ToolFormat, OpenAIFunction, OpenAITool, ResponsesTool, FormatterTool, ToolCallBlock, } from './IToolFormatter.js';
|
|
16
|
+
export { ToolFormatter } from './ToolFormatter.js';
|
|
17
|
+
export type { ToolIdStrategy, ToolIdMapper, ContentBlock as StrategyContentBlock, } from './ToolIdStrategy.js';
|
|
18
|
+
export { getToolIdStrategy, kimiStrategy, standardStrategy, mistralStrategy, isKimiModel, isDeepSeekReasonerModel, isMistralModel, } from './ToolIdStrategy.js';
|
|
19
|
+
export { shouldUseDoubleEscapeHandling, detectDoubleEscaping, detectDoubleEscapingInChunk, processToolParameters, logDoubleEscapingInChunk, } from './doubleEscapeUtils.js';
|
|
20
|
+
export { normalizeToolName, toSnakeCase, isValidToolName, findMatchingTool, } from './toolNameUtils.js';
|
|
21
|
+
export { normalizeToOpenAIToolId, normalizeToHistoryToolId, normalizeToAnthropicToolId, } from './toolIdNormalization.js';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @plan:PLAN-20260608-ISSUE1585.P05
|
|
3
|
+
* @requirement:REQ-API-001
|
|
4
|
+
*/
|
|
5
|
+
// --- Implementation ---
|
|
6
|
+
export { ToolFormatter } from './ToolFormatter.js';
|
|
7
|
+
export { getToolIdStrategy, kimiStrategy, standardStrategy, mistralStrategy, isKimiModel, isDeepSeekReasonerModel, isMistralModel, } from './ToolIdStrategy.js';
|
|
8
|
+
// --- Utilities ---
|
|
9
|
+
export { shouldUseDoubleEscapeHandling, detectDoubleEscaping, detectDoubleEscapingInChunk, processToolParameters, logDoubleEscapingInChunk, } from './doubleEscapeUtils.js';
|
|
10
|
+
export { normalizeToolName, toSnakeCase, isValidToolName, findMatchingTool, } from './toolNameUtils.js';
|
|
11
|
+
export { normalizeToOpenAIToolId, normalizeToHistoryToolId, normalizeToAnthropicToolId, } from './toolIdNormalization.js';
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/formatters/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAyBH,yBAAyB;AACzB,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAQnD,OAAO,EACL,iBAAiB,EACjB,YAAY,EACZ,gBAAgB,EAChB,eAAe,EACf,WAAW,EACX,uBAAuB,EACvB,cAAc,GACf,MAAM,qBAAqB,CAAC;AAE7B,oBAAoB;AACpB,OAAO,EACL,6BAA6B,EAC7B,oBAAoB,EACpB,2BAA2B,EAC3B,qBAAqB,EACrB,wBAAwB,GACzB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EACL,iBAAiB,EACjB,WAAW,EACX,eAAe,EACf,gBAAgB,GACjB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,uBAAuB,EACvB,wBAAwB,EACxB,0BAA0B,GAC3B,MAAM,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @plan:PLAN-20260608-ISSUE1585.P05
|
|
3
|
+
* @requirement:REQ-API-001, REQ-TEMPORARY-INTERFACES
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Normalizes various tool ID formats to OpenAI format (call_xxx).
|
|
7
|
+
*
|
|
8
|
+
* - hist_tool_xxx → call_xxx
|
|
9
|
+
* - toolu_xxx → call_xxx
|
|
10
|
+
* - call_xxx → call_xxx (sanitized)
|
|
11
|
+
* - unknown → call_unknown
|
|
12
|
+
*/
|
|
13
|
+
export declare function normalizeToOpenAIToolId(id: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* Normalizes various tool ID formats to history format (hist_tool_xxx).
|
|
16
|
+
*
|
|
17
|
+
* - call_xxx → hist_tool_xxx
|
|
18
|
+
* - toolu_xxx → hist_tool_xxx
|
|
19
|
+
* - hist_tool_xxx → hist_tool_xxx (sanitized)
|
|
20
|
+
*/
|
|
21
|
+
export declare function normalizeToHistoryToolId(id: string): string;
|
|
22
|
+
/**
|
|
23
|
+
* Normalizes various tool ID formats to Anthropic format (toolu_xxx).
|
|
24
|
+
*
|
|
25
|
+
* Note: Unlike OpenAI normalization (which removes invalid chars),
|
|
26
|
+
* Anthropic normalization replaces invalid chars with hyphens.
|
|
27
|
+
*/
|
|
28
|
+
export declare function normalizeToAnthropicToolId(id: string): string;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @plan:PLAN-20260608-ISSUE1585.P05
|
|
3
|
+
* @requirement:REQ-API-001, REQ-TEMPORARY-INTERFACES
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @license
|
|
7
|
+
* Copyright 2025 Vybestack LLC
|
|
8
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Package-local tool ID normalization utilities.
|
|
12
|
+
*
|
|
13
|
+
* Normalizes tool IDs between provider formats and history format.
|
|
14
|
+
* This is a self-contained copy with core debugLogger replaced
|
|
15
|
+
* by a no-op to maintain zero core imports.
|
|
16
|
+
*/
|
|
17
|
+
const SANITIZE_PATTERN = /[^a-zA-Z0-9_-]/g;
|
|
18
|
+
function sanitizeSuffix(suffix) {
|
|
19
|
+
return suffix.replace(SANITIZE_PATTERN, '');
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Normalizes various tool ID formats to OpenAI format (call_xxx).
|
|
23
|
+
*
|
|
24
|
+
* - hist_tool_xxx → call_xxx
|
|
25
|
+
* - toolu_xxx → call_xxx
|
|
26
|
+
* - call_xxx → call_xxx (sanitized)
|
|
27
|
+
* - unknown → call_unknown
|
|
28
|
+
*/
|
|
29
|
+
export function normalizeToOpenAIToolId(id) {
|
|
30
|
+
if (!id) {
|
|
31
|
+
return 'call_';
|
|
32
|
+
}
|
|
33
|
+
if (id.startsWith('call_')) {
|
|
34
|
+
const suffix = id.substring('call_'.length);
|
|
35
|
+
return `call_${sanitizeSuffix(suffix)}`;
|
|
36
|
+
}
|
|
37
|
+
let suffix = '';
|
|
38
|
+
if (id.startsWith('hist_tool_')) {
|
|
39
|
+
suffix = id.substring('hist_tool_'.length);
|
|
40
|
+
}
|
|
41
|
+
else if (id.startsWith('toolu_')) {
|
|
42
|
+
suffix = id.substring('toolu_'.length);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
suffix = id;
|
|
46
|
+
}
|
|
47
|
+
return `call_${sanitizeSuffix(suffix)}`;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Normalizes various tool ID formats to history format (hist_tool_xxx).
|
|
51
|
+
*
|
|
52
|
+
* - call_xxx → hist_tool_xxx
|
|
53
|
+
* - toolu_xxx → hist_tool_xxx
|
|
54
|
+
* - hist_tool_xxx → hist_tool_xxx (sanitized)
|
|
55
|
+
*/
|
|
56
|
+
export function normalizeToHistoryToolId(id) {
|
|
57
|
+
if (!id) {
|
|
58
|
+
return 'hist_tool_';
|
|
59
|
+
}
|
|
60
|
+
if (id.startsWith('hist_tool_')) {
|
|
61
|
+
const suffix = id.substring('hist_tool_'.length);
|
|
62
|
+
return `hist_tool_${sanitizeSuffix(suffix)}`;
|
|
63
|
+
}
|
|
64
|
+
if (id.startsWith('call_')) {
|
|
65
|
+
const suffix = id.substring('call_'.length);
|
|
66
|
+
return `hist_tool_${sanitizeSuffix(suffix)}`;
|
|
67
|
+
}
|
|
68
|
+
if (id.startsWith('toolu_')) {
|
|
69
|
+
const suffix = id.substring('toolu_'.length);
|
|
70
|
+
return `hist_tool_${sanitizeSuffix(suffix)}`;
|
|
71
|
+
}
|
|
72
|
+
return `hist_tool_${sanitizeSuffix(id)}`;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Normalizes various tool ID formats to Anthropic format (toolu_xxx).
|
|
76
|
+
*
|
|
77
|
+
* Note: Unlike OpenAI normalization (which removes invalid chars),
|
|
78
|
+
* Anthropic normalization replaces invalid chars with hyphens.
|
|
79
|
+
*/
|
|
80
|
+
export function normalizeToAnthropicToolId(id) {
|
|
81
|
+
if (!id) {
|
|
82
|
+
return 'toolu_empty';
|
|
83
|
+
}
|
|
84
|
+
if (id.startsWith('toolu_')) {
|
|
85
|
+
return id;
|
|
86
|
+
}
|
|
87
|
+
if (id.startsWith('hist_tool_')) {
|
|
88
|
+
const suffix = id.substring('hist_tool_'.length);
|
|
89
|
+
return `toolu_${suffix.replace(/[^a-zA-Z0-9_-]/g, '-')}`;
|
|
90
|
+
}
|
|
91
|
+
if (id.startsWith('call_')) {
|
|
92
|
+
const suffix = id.substring('call_'.length);
|
|
93
|
+
return `toolu_${suffix.replace(/[^a-zA-Z0-9_-]/g, '-')}`;
|
|
94
|
+
}
|
|
95
|
+
return `toolu_${id.replace(/[^a-zA-Z0-9_-]/g, '-')}`;
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=toolIdNormalization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toolIdNormalization.js","sourceRoot":"","sources":["../../../src/formatters/toolIdNormalization.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;GAIG;AAEH;;;;;;GAMG;AAEH,MAAM,gBAAgB,GAAG,iBAAiB,CAAC;AAE3C,SAAS,cAAc,CAAC,MAAc;IACpC,OAAO,MAAM,CAAC,OAAO,CAAC,gBAAgB,EAAE,EAAE,CAAC,CAAC;AAC9C,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,uBAAuB,CAAC,EAAU;IAChD,IAAI,CAAC,EAAE,EAAE,CAAC;QACR,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,IAAI,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QAC3B,MAA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11
|
+
* Package-local tool name validation and normalization utilities.
|
|
12
|
+
*
|
|
13
|
+
* Pure utility functions with zero core/cli/providers dependencies.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Normalize tool name using proven logic.
|
|
17
|
+
* Returns null if the name cannot be normalized.
|
|
18
|
+
*/
|
|
19
|
+
export declare function normalizeToolName(rawName: string): string | null;
|
|
20
|
+
/**
|
|
21
|
+
* Sentinel returned by {@link canonicalizeToolName} when the input name is
|
|
22
|
+
* blank or whitespace-only.
|
|
23
|
+
*/
|
|
24
|
+
export declare const INVALID_TOOL_NAME = "__invalid_tool_name__";
|
|
25
|
+
/**
|
|
26
|
+
* Canonicalize a tool name to its normalized snake_case identifier.
|
|
27
|
+
*
|
|
28
|
+
* Returns {@link INVALID_TOOL_NAME} for blank/whitespace-only input so callers
|
|
29
|
+
* can treat unusable names deterministically.
|
|
30
|
+
*/
|
|
31
|
+
export declare function canonicalizeToolName(rawName: string): string;
|
|
32
|
+
/**
|
|
33
|
+
* Convert string to snake_case.
|
|
34
|
+
*/
|
|
35
|
+
export declare function toSnakeCase(value: string): string;
|
|
36
|
+
/**
|
|
37
|
+
* Validate if a tool name follows proper naming conventions.
|
|
38
|
+
*/
|
|
39
|
+
export declare function isValidToolName(name: string): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Find matching tool from available tools with fuzzy matching.
|
|
42
|
+
*/
|
|
43
|
+
export declare function findMatchingTool(normalizedName: string, availableTools: string[]): string | null;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @plan:PLAN-20260608-ISSUE1585.P05
|
|
3
|
+
* @requirement:REQ-API-001, REQ-TEMPORARY-INTERFACES
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @license
|
|
7
|
+
* Copyright 2025 Google LLC
|
|
8
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Package-local tool name validation and normalization utilities.
|
|
12
|
+
*
|
|
13
|
+
* Pure utility functions with zero core/cli/providers dependencies.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Normalize tool name using proven logic.
|
|
17
|
+
* Returns null if the name cannot be normalized.
|
|
18
|
+
*/
|
|
19
|
+
export function normalizeToolName(rawName) {
|
|
20
|
+
if (!rawName) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
const trimmed = rawName.trim();
|
|
24
|
+
if (!trimmed) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
// Early return: if already normalized
|
|
28
|
+
if (isValidToolName(trimmed) && trimmed === trimmed.toLowerCase()) {
|
|
29
|
+
return trimmed;
|
|
30
|
+
}
|
|
31
|
+
const lowerTrimmed = trimmed.toLowerCase();
|
|
32
|
+
// Phase 1: Check snake_case conversion first (handles camelCase)
|
|
33
|
+
const snakeCase = toSnakeCase(trimmed);
|
|
34
|
+
if (isValidToolName(snakeCase)) {
|
|
35
|
+
return snakeCase;
|
|
36
|
+
}
|
|
37
|
+
// Phase 2: Check lowercase version
|
|
38
|
+
if (isValidToolName(lowerTrimmed)) {
|
|
39
|
+
return lowerTrimmed;
|
|
40
|
+
}
|
|
41
|
+
// Phase 3: Check original trimmed version
|
|
42
|
+
if (isValidToolName(trimmed)) {
|
|
43
|
+
return trimmed;
|
|
44
|
+
}
|
|
45
|
+
// Phase 4: Handle Tool suffix (only when necessary)
|
|
46
|
+
if (trimmed.endsWith('Tool')) {
|
|
47
|
+
const withoutSuffix = trimmed.slice(0, -4);
|
|
48
|
+
if (withoutSuffix) {
|
|
49
|
+
const lowerWithoutSuffix = withoutSuffix.toLowerCase();
|
|
50
|
+
if (isValidToolName(lowerWithoutSuffix)) {
|
|
51
|
+
return lowerWithoutSuffix;
|
|
52
|
+
}
|
|
53
|
+
const snakeWithoutSuffix = toSnakeCase(withoutSuffix);
|
|
54
|
+
if (isValidToolName(snakeWithoutSuffix)) {
|
|
55
|
+
return snakeWithoutSuffix;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Sentinel returned by {@link canonicalizeToolName} when the input name is
|
|
63
|
+
* blank or whitespace-only.
|
|
64
|
+
*/
|
|
65
|
+
export const INVALID_TOOL_NAME = '__invalid_tool_name__';
|
|
66
|
+
function hasMultipleWords(name) {
|
|
67
|
+
const withoutFirst = name.slice(1);
|
|
68
|
+
return /[A-Z]/.test(withoutFirst) || name.includes('_') || name.includes('-');
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Canonicalize a tool name to its normalized snake_case identifier.
|
|
72
|
+
*
|
|
73
|
+
* Returns {@link INVALID_TOOL_NAME} for blank/whitespace-only input so callers
|
|
74
|
+
* can treat unusable names deterministically.
|
|
75
|
+
*/
|
|
76
|
+
export function canonicalizeToolName(rawName) {
|
|
77
|
+
const trimmed = rawName.trim();
|
|
78
|
+
if (!trimmed) {
|
|
79
|
+
return INVALID_TOOL_NAME;
|
|
80
|
+
}
|
|
81
|
+
let nameToProcess = trimmed;
|
|
82
|
+
if (trimmed.endsWith('Tool') && trimmed.length > 4) {
|
|
83
|
+
const withoutTool = trimmed.slice(0, -4);
|
|
84
|
+
if (hasMultipleWords(withoutTool)) {
|
|
85
|
+
nameToProcess = withoutTool;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const normalized = normalizeToolName(nameToProcess);
|
|
89
|
+
if (normalized !== null) {
|
|
90
|
+
return normalized;
|
|
91
|
+
}
|
|
92
|
+
return toSnakeCase(nameToProcess).toLowerCase();
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Convert string to snake_case.
|
|
96
|
+
*/
|
|
97
|
+
export function toSnakeCase(value) {
|
|
98
|
+
return value
|
|
99
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1_$2')
|
|
100
|
+
.replace(/[\s-]+/g, '_')
|
|
101
|
+
.toLowerCase();
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Validate if a tool name follows proper naming conventions.
|
|
105
|
+
*/
|
|
106
|
+
export function isValidToolName(name) {
|
|
107
|
+
if (!name || name.length === 0) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
if (name.length > 100) {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
const validPattern = /^[a-zA-Z0-9_.-]+$/;
|
|
114
|
+
return validPattern.test(name);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Find matching tool from available tools with fuzzy matching.
|
|
118
|
+
*/
|
|
119
|
+
export function findMatchingTool(normalizedName, availableTools) {
|
|
120
|
+
// Direct match
|
|
121
|
+
if (availableTools.includes(normalizedName)) {
|
|
122
|
+
return normalizedName;
|
|
123
|
+
}
|
|
124
|
+
// Case-insensitive match
|
|
125
|
+
const lowerMatch = availableTools.find((tool) => tool.toLowerCase() === normalizedName.toLowerCase());
|
|
126
|
+
if (lowerMatch) {
|
|
127
|
+
return lowerMatch;
|
|
128
|
+
}
|
|
129
|
+
// Snake case match
|
|
130
|
+
const snakeCaseName = toSnakeCase(normalizedName);
|
|
131
|
+
const snakeMatch = availableTools.find((tool) => tool.toLowerCase() === snakeCaseName.toLowerCase());
|
|
132
|
+
if (snakeMatch) {
|
|
133
|
+
return snakeMatch;
|
|
134
|
+
}
|
|
135
|
+
// Partial match
|
|
136
|
+
const partialMatch = availableTools.find((tool) => {
|
|
137
|
+
const toolLower = tool.toLowerCase();
|
|
138
|
+
const nameLower = normalizedName.toLowerCase();
|
|
139
|
+
return toolLower.includes(nameLower) || nameLower.includes(toolLower);
|
|
140
|
+
});
|
|
141
|
+
return partialMatch || null;
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=toolNameUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toolNameUtils.js","sourceRoot":"","sources":["../../../src/formatters/toolNameUtils.ts"],"names":[],"mappings":"AA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