@tyvm/knowhow 0.0.159 → 0.0.161
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/README.md +6 -6
- package/package.json +2 -2
- package/ts_build/package.json +2 -2
- package/ts_build/src/chat/CliChatService.d.ts +2 -1
- package/ts_build/src/chat/CliChatService.js +29 -3
- package/ts_build/src/chat/CliChatService.js.map +1 -1
- package/ts_build/src/chat/modules/AgentModule.js +21 -17
- package/ts_build/src/chat/modules/AgentModule.js.map +1 -1
- package/ts_build/src/chat/renderer/ConsoleRenderer.js +32 -25
- package/ts_build/src/chat/renderer/ConsoleRenderer.js.map +1 -1
- package/ts_build/src/clients/anthropic.js +4 -1
- package/ts_build/src/clients/anthropic.js.map +1 -1
- package/ts_build/src/clients/contextLimits.js +13 -7
- package/ts_build/src/clients/contextLimits.js.map +1 -1
- package/ts_build/src/clients/index.js +3 -1
- package/ts_build/src/clients/index.js.map +1 -1
- package/ts_build/src/clients/openai.js +18 -5
- package/ts_build/src/clients/openai.js.map +1 -1
- package/ts_build/src/clients/pricing/anthropic.d.ts +2 -0
- package/ts_build/src/clients/pricing/anthropic.js +21 -1
- package/ts_build/src/clients/pricing/anthropic.js.map +1 -1
- package/ts_build/src/clients/pricing/openai.d.ts +2 -0
- package/ts_build/src/clients/pricing/openai.js +32 -7
- package/ts_build/src/clients/pricing/openai.js.map +1 -1
- package/ts_build/src/clients/pricing/types.d.ts +4 -0
- package/ts_build/src/clients/pricing/types.js.map +1 -1
- package/ts_build/src/clients/pricing/xai.d.ts +2 -0
- package/ts_build/src/clients/pricing/xai.js +13 -8
- package/ts_build/src/clients/pricing/xai.js.map +1 -1
- package/ts_build/src/clients/xai.js +20 -8
- package/ts_build/src/clients/xai.js.map +1 -1
- package/ts_build/src/commands/misc.js +15 -2
- package/ts_build/src/commands/misc.js.map +1 -1
- package/ts_build/src/logger.d.ts +1 -0
- package/ts_build/src/logger.js +13 -1
- package/ts_build/src/logger.js.map +1 -1
- package/ts_build/src/remotes.d.ts +2 -0
- package/ts_build/src/remotes.js +20 -2
- package/ts_build/src/remotes.js.map +1 -1
- package/ts_build/src/tunnel.js +7 -2
- package/ts_build/src/tunnel.js.map +1 -1
- package/ts_build/src/types.d.ts +12 -1
- package/ts_build/src/types.js.map +1 -1
- package/ts_build/src/utils/InputQueueManager.d.ts +8 -1
- package/ts_build/src/utils/InputQueueManager.js +74 -3
- package/ts_build/src/utils/InputQueueManager.js.map +1 -1
- package/ts_build/src/utils/index.d.ts +3 -1
- package/ts_build/src/utils/index.js +11 -3
- package/ts_build/src/utils/index.js.map +1 -1
- package/ts_build/src/worker.js +4 -1
- package/ts_build/src/worker.js.map +1 -1
- package/ts_build/src/workers/tools/listAllowedPorts.d.ts +2 -1
- package/ts_build/src/workers/tools/listAllowedPorts.js +1 -1
- package/ts_build/src/workers/tools/listAllowedPorts.js.map +1 -1
- package/CONFIG.md +0 -429
- package/PROCESSING.md +0 -450
- package/WORKER.md +0 -260
- package/autodoc/README.md +0 -324
- package/autodoc/chat-guide.md +0 -444
- package/autodoc/cli-reference.md +0 -720
- package/autodoc/config-reference.md +0 -642
- package/autodoc/embeddings-guide.md +0 -467
- package/autodoc/generate-guide.md +0 -437
- package/autodoc/language-plugin-guide.md +0 -417
- package/autodoc/modules-guide.md +0 -379
- package/autodoc/plugins-guide.md +0 -721
- package/autodoc/quickstart-guide.md +0 -126
- package/autodoc/skills-guide.md +0 -584
- package/autodoc/worker-guide.md +0 -519
- package/docs/input-queue-manager.md +0 -142
- package/docs/multi-worker-management.md +0 -142
- package/docs/shell-commands.md +0 -174
- package/jest.config.js +0 -19
- package/jest.manual.config.js +0 -19
- package/scripts/README.md +0 -119
- package/scripts/build-for-node.sh +0 -148
- package/scripts/cache-miss-debug.ts +0 -365
- package/scripts/check-isolated-deps.sh +0 -69
- package/scripts/check-model-pricing.ts +0 -509
- package/scripts/compare-openrouter-coverage.ts +0 -576
- package/scripts/migrate-usage-json.js +0 -147
- package/scripts/publish.sh +0 -86
- package/scripts/restore_keys.sh +0 -59
- package/scripts/test-repetition-hint.ts +0 -302
- package/scripts/unset_keys.sh +0 -60
- package/src/agents/base/base.ts +0 -1963
- package/src/agents/base/prompt.ts +0 -55
- package/src/agents/configurable/ConfigAgent.ts +0 -24
- package/src/agents/developer/developer.ts +0 -76
- package/src/agents/historyRollback.ts +0 -36
- package/src/agents/index.ts +0 -52
- package/src/agents/interface.ts +0 -11
- package/src/agents/patcher/codebase.md +0 -27
- package/src/agents/patcher/patcher.ts +0 -131
- package/src/agents/researcher/researcher.ts +0 -115
- package/src/agents/setup/setup.ts +0 -63
- package/src/agents/tools/addInternalTools.ts +0 -21
- package/src/agents/tools/agentCall.ts +0 -34
- package/src/agents/tools/aiClient.ts +0 -178
- package/src/agents/tools/askHuman.ts +0 -10
- package/src/agents/tools/callPlugin.ts +0 -10
- package/src/agents/tools/connectAgent.ts +0 -355
- package/src/agents/tools/embeddingSearch.ts +0 -6
- package/src/agents/tools/execCommand.ts +0 -162
- package/src/agents/tools/fileSearch.ts +0 -35
- package/src/agents/tools/finalAnswer.ts +0 -4
- package/src/agents/tools/googleSearch.ts +0 -243
- package/src/agents/tools/index.ts +0 -33
- package/src/agents/tools/language/definitions.ts +0 -105
- package/src/agents/tools/language/index.ts +0 -20
- package/src/agents/tools/lazy/definitions.ts +0 -72
- package/src/agents/tools/lazy/disableTools.ts +0 -16
- package/src/agents/tools/lazy/enableTools.ts +0 -16
- package/src/agents/tools/lazy/index.ts +0 -3
- package/src/agents/tools/lazy/listAvailableTools.ts +0 -17
- package/src/agents/tools/lintFile.ts +0 -19
- package/src/agents/tools/list.ts +0 -739
- package/src/agents/tools/loadImageAsBase64.ts +0 -83
- package/src/agents/tools/loadWebpage.ts +0 -19
- package/src/agents/tools/mcp/connectMcpServer.ts +0 -40
- package/src/agents/tools/mcp/definitions.ts +0 -67
- package/src/agents/tools/mcp/disconnectMcpServer.ts +0 -40
- package/src/agents/tools/mcp/index.ts +0 -3
- package/src/agents/tools/mcp/listAvailableMcpServers.ts +0 -28
- package/src/agents/tools/minimal/callTool.ts +0 -45
- package/src/agents/tools/minimal/definitions.ts +0 -50
- package/src/agents/tools/minimal/index.ts +0 -3
- package/src/agents/tools/minimal/inspectTools.ts +0 -27
- package/src/agents/tools/modifyFile.ts +0 -53
- package/src/agents/tools/observe.ts +0 -247
- package/src/agents/tools/patch.ts +0 -1287
- package/src/agents/tools/readBlocks.ts +0 -83
- package/src/agents/tools/readFile.ts +0 -105
- package/src/agents/tools/replyToParent.ts +0 -123
- package/src/agents/tools/runGenerate.ts +0 -210
- package/src/agents/tools/scanFile.ts +0 -16
- package/src/agents/tools/sendAgentMessage.ts +0 -139
- package/src/agents/tools/skills.ts +0 -79
- package/src/agents/tools/startAgentTask.ts +0 -393
- package/src/agents/tools/stringReplace.ts +0 -105
- package/src/agents/tools/textSearch.ts +0 -128
- package/src/agents/tools/types/fileblock.ts +0 -5
- package/src/agents/tools/visionTool.ts +0 -35
- package/src/agents/tools/waitForAgentCompleted.ts +0 -270
- package/src/agents/tools/writeFile.ts +0 -106
- package/src/agents/tools/ycmd/client.ts +0 -608
- package/src/agents/tools/ycmd/definitions.ts +0 -294
- package/src/agents/tools/ycmd/detection.ts +0 -211
- package/src/agents/tools/ycmd/index.ts +0 -11
- package/src/agents/tools/ycmd/installer.ts +0 -251
- package/src/agents/tools/ycmd/server.ts +0 -545
- package/src/agents/tools/ycmd/serverManager.ts +0 -316
- package/src/agents/tools/ycmd/tools/completion.ts +0 -113
- package/src/agents/tools/ycmd/tools/diagnostics.ts +0 -166
- package/src/agents/tools/ycmd/tools/getLocations.ts +0 -173
- package/src/agents/tools/ycmd/tools/goto.ts +0 -169
- package/src/agents/tools/ycmd/tools/refactor.ts +0 -204
- package/src/agents/tools/ycmd/tools/signature.ts +0 -174
- package/src/agents/tools/ycmd/tools/start.ts +0 -95
- package/src/agents/tools/ycmd/utils/pathUtils.ts +0 -59
- package/src/ai.ts +0 -306
- package/src/auth/browserLogin.ts +0 -406
- package/src/auth/environmentAuth.ts +0 -51
- package/src/auth/errors.ts +0 -6
- package/src/auth/jwtStore.ts +0 -70
- package/src/auth/keyAuth.ts +0 -142
- package/src/auth/keyManager.ts +0 -331
- package/src/auth/registerIdentity.ts +0 -67
- package/src/auth/spinner.ts +0 -23
- package/src/chat/CliChatService.ts +0 -438
- package/src/chat/modules/AgentModule.ts +0 -1664
- package/src/chat/modules/AskModule.ts +0 -98
- package/src/chat/modules/BaseChatModule.ts +0 -65
- package/src/chat/modules/ClipboardImageModule.ts +0 -136
- package/src/chat/modules/CustomCommandsModule.ts +0 -80
- package/src/chat/modules/InternalChatModule.ts +0 -216
- package/src/chat/modules/RemoteSyncModule.ts +0 -482
- package/src/chat/modules/RendererModule.ts +0 -139
- package/src/chat/modules/SearchModule.ts +0 -168
- package/src/chat/modules/SessionsModule.ts +0 -969
- package/src/chat/modules/SetupModule.ts +0 -185
- package/src/chat/modules/ShellCommandModule.ts +0 -98
- package/src/chat/modules/SystemModule.ts +0 -161
- package/src/chat/modules/ToolCommandModule.ts +0 -102
- package/src/chat/modules/VoiceModule.ts +0 -70
- package/src/chat/modules/index.ts +0 -8
- package/src/chat/renderer/CompactRenderer.ts +0 -229
- package/src/chat/renderer/ConsoleRenderer.ts +0 -160
- package/src/chat/renderer/FancyRenderer.ts +0 -440
- package/src/chat/renderer/PlainRenderer.ts +0 -218
- package/src/chat/renderer/index.ts +0 -6
- package/src/chat/renderer/loadRenderer.ts +0 -316
- package/src/chat/renderer/messagesToRenderEvents.ts +0 -96
- package/src/chat/renderer/types.ts +0 -99
- package/src/chat/types.ts +0 -146
- package/src/chat.ts +0 -140
- package/src/cli.ts +0 -180
- package/src/clients/anthropic.ts +0 -772
- package/src/clients/attribution.ts +0 -53
- package/src/clients/cerebras.ts +0 -10
- package/src/clients/contextLimits.ts +0 -263
- package/src/clients/copilot.ts +0 -23
- package/src/clients/deepseek.ts +0 -16
- package/src/clients/fireworks.ts +0 -71
- package/src/clients/gemini.ts +0 -1169
- package/src/clients/github.ts +0 -16
- package/src/clients/groq.ts +0 -15
- package/src/clients/http.ts +0 -719
- package/src/clients/index.ts +0 -1153
- package/src/clients/knowhow.ts +0 -130
- package/src/clients/knowhowMcp.ts +0 -118
- package/src/clients/llama.ts +0 -16
- package/src/clients/meta.ts +0 -27
- package/src/clients/mistral.ts +0 -16
- package/src/clients/nvidia.ts +0 -16
- package/src/clients/openai.ts +0 -1186
- package/src/clients/openrouter.ts +0 -24
- package/src/clients/pricing/anthropic.ts +0 -149
- package/src/clients/pricing/cerebras.ts +0 -11
- package/src/clients/pricing/copilot.ts +0 -60
- package/src/clients/pricing/deepseek.ts +0 -15
- package/src/clients/pricing/fireworks.ts +0 -182
- package/src/clients/pricing/github.ts +0 -69
- package/src/clients/pricing/google.ts +0 -385
- package/src/clients/pricing/groq.ts +0 -56
- package/src/clients/pricing/index.ts +0 -44
- package/src/clients/pricing/llama.ts +0 -18
- package/src/clients/pricing/meta.ts +0 -12
- package/src/clients/pricing/mistral.ts +0 -34
- package/src/clients/pricing/models.ts +0 -25
- package/src/clients/pricing/nvidia.ts +0 -102
- package/src/clients/pricing/openai.ts +0 -409
- package/src/clients/pricing/openrouter.ts +0 -36
- package/src/clients/pricing/qwen.ts +0 -80
- package/src/clients/pricing/types.ts +0 -125
- package/src/clients/pricing/xai.ts +0 -137
- package/src/clients/qwen.ts +0 -16
- package/src/clients/responseMetadata.ts +0 -221
- package/src/clients/types.ts +0 -531
- package/src/clients/withRetry.ts +0 -89
- package/src/clients/xai.ts +0 -693
- package/src/cloudWorker.ts +0 -394
- package/src/commands/agent.ts +0 -342
- package/src/commands/agents.ts +0 -1037
- package/src/commands/behaviors.ts +0 -47
- package/src/commands/convert.ts +0 -291
- package/src/commands/hash.ts +0 -179
- package/src/commands/mcp.ts +0 -743
- package/src/commands/misc.ts +0 -373
- package/src/commands/modules.ts +0 -704
- package/src/commands/processes.ts +0 -248
- package/src/commands/remote.ts +0 -77
- package/src/commands/replay.ts +0 -503
- package/src/commands/sandbox.ts +0 -566
- package/src/commands/services.ts +0 -168
- package/src/commands/skills.ts +0 -107
- package/src/commands/workers.ts +0 -168
- package/src/config.ts +0 -468
- package/src/conversion.ts +0 -69
- package/src/dataset/diffs/README.md +0 -12
- package/src/dataset/diffs/debug-errors.ts +0 -29
- package/src/dataset/diffs/debug.ts +0 -64
- package/src/dataset/diffs/generate.ts +0 -71
- package/src/dataset/diffs/jsonl.ts +0 -53
- package/src/dataset/diffs/test.ts +0 -194
- package/src/embeddings.ts +0 -494
- package/src/fileSync.ts +0 -369
- package/src/generate.ts +0 -529
- package/src/hashes.ts +0 -180
- package/src/index.ts +0 -261
- package/src/logger.ts +0 -197
- package/src/login.ts +0 -209
- package/src/microphone.ts +0 -141
- package/src/migrations.ts +0 -151
- package/src/plugins/AgentsMdPlugin.ts +0 -118
- package/src/plugins/GitPlugin.ts +0 -598
- package/src/plugins/LinterPlugin.ts +0 -214
- package/src/plugins/PluginBase.ts +0 -70
- package/src/plugins/SkillsPlugin.ts +0 -37
- package/src/plugins/embedding.ts +0 -82
- package/src/plugins/exec.ts +0 -70
- package/src/plugins/language.ts +0 -290
- package/src/plugins/plugins.ts +0 -175
- package/src/plugins/tmux.ts +0 -132
- package/src/plugins/types.ts +0 -36
- package/src/plugins/url.ts +0 -101
- package/src/plugins/vim.ts +0 -89
- package/src/processes/ProcessManager.ts +0 -96
- package/src/processes/managedProcessShim.ts +0 -138
- package/src/processors/Base64ImageDetector.ts +0 -502
- package/src/processors/CustomVariables.ts +0 -693
- package/src/processors/GemmaToolProcessor.ts +0 -163
- package/src/processors/HarmonyToolProcessor.ts +0 -264
- package/src/processors/JsonCompressor.ts +0 -510
- package/src/processors/MinimalToolsMessageProcessor.ts +0 -113
- package/src/processors/TokenCompressor.ts +0 -620
- package/src/processors/ToolResponseCache.ts +0 -322
- package/src/processors/XmlToolCallProcessor.ts +0 -533
- package/src/processors/index.ts +0 -14
- package/src/processors/tools/boundedToolResponse.ts +0 -49
- package/src/processors/tools/grepToolResponse.ts +0 -230
- package/src/processors/tools/index.ts +0 -23
- package/src/processors/tools/jqToolResponse.ts +0 -159
- package/src/processors/tools/listStoredToolResponses.ts +0 -124
- package/src/processors/tools/tailToolResponse.ts +0 -148
- package/src/prompts/BasicCodeDocumenter.ts +0 -1
- package/src/prompts/BasicProjectDocumenter.ts +0 -1
- package/src/prompts/EmbeddingSeachHelper.ts +0 -1
- package/src/prompts/KnowhowConfigExamples.ts +0 -376
- package/src/prompts/index.ts +0 -9
- package/src/remotes.ts +0 -110
- package/src/server/index.ts +0 -16
- package/src/services/AgentService.ts +0 -134
- package/src/services/AgentSyncFs.ts +0 -775
- package/src/services/AgentSyncKnowhowWeb.ts +0 -389
- package/src/services/BehaviorsService.ts +0 -466
- package/src/services/DockerService.ts +0 -511
- package/src/services/EmbeddingService.ts +0 -427
- package/src/services/EmbeddingsService.ts +0 -73
- package/src/services/EventService.ts +0 -279
- package/src/services/ExtensionsService.ts +0 -25
- package/src/services/KnowhowClient.ts +0 -928
- package/src/services/LazyToolsService.ts +0 -210
- package/src/services/Mcp.ts +0 -727
- package/src/services/McpServer.ts +0 -155
- package/src/services/McpWebsocketTransport.ts +0 -87
- package/src/services/MediaProcessorService.ts +0 -669
- package/src/services/MessageProcessor.ts +0 -114
- package/src/services/MinimalToolsService.ts +0 -177
- package/src/services/RuntimeReloadService.ts +0 -31
- package/src/services/S3.ts +0 -61
- package/src/services/SessionManager.ts +0 -358
- package/src/services/SkillsService.ts +0 -822
- package/src/services/SyncedAgentWatcher.ts +0 -124
- package/src/services/SyncerService.ts +0 -191
- package/src/services/TaskRegistry.ts +0 -110
- package/src/services/Tools.ts +0 -580
- package/src/services/TracingService.ts +0 -116
- package/src/services/conversion/ConversionService.ts +0 -757
- package/src/services/conversion/index.ts +0 -2
- package/src/services/conversion/types.ts +0 -87
- package/src/services/flags.ts +0 -51
- package/src/services/index.ts +0 -117
- package/src/services/modules/computerUse.ts +0 -218
- package/src/services/modules/index.ts +0 -314
- package/src/services/modules/types.ts +0 -109
- package/src/services/types.ts +0 -60
- package/src/services/watchers/FsSyncer.ts +0 -199
- package/src/services/watchers/RemoteSyncer.ts +0 -196
- package/src/services/watchers/index.ts +0 -2
- package/src/tunnel.ts +0 -243
- package/src/types.ts +0 -282
- package/src/util/Trace.ts +0 -236
- package/src/utils/InputQueueManager.ts +0 -493
- package/src/utils/errors.ts +0 -0
- package/src/utils/http.ts +0 -150
- package/src/utils/index.ts +0 -111
- package/src/worker.ts +0 -696
- package/src/workerRegistry.ts +0 -152
- package/src/workers/auth/PasskeySetup.ts +0 -181
- package/src/workers/auth/WorkerPasskeyAuth.ts +0 -190
- package/src/workers/auth/WsMiddleware.ts +0 -99
- package/src/workers/auth/authMiddleware.ts +0 -104
- package/src/workers/auth/types.ts +0 -70
- package/src/workers/tools/getChallenge.ts +0 -33
- package/src/workers/tools/index.ts +0 -20
- package/src/workers/tools/listAllowedPorts.ts +0 -30
- package/src/workers/tools/lock.ts +0 -31
- package/src/workers/tools/reloadConfig.ts +0 -84
- package/src/workers/tools/unlock.ts +0 -116
- package/tests/XmlToolCallProcessor.test.ts +0 -468
- package/tests/agents/interrupt.test.ts +0 -200
- package/tests/agents/observe-base.test.ts +0 -183
- package/tests/agents/tools/connectAgent.test.ts +0 -138
- package/tests/agents/tools/observe.test.ts +0 -179
- package/tests/agents/tools/readFile.test.ts +0 -88
- package/tests/agents/tools/replyToParent.test.ts +0 -125
- package/tests/agents/tools/sendAgentMessage.test.ts +0 -99
- package/tests/agents/tools/waitForAgentCompleted.test.ts +0 -147
- package/tests/chat/detach-attach-rendering.test.ts +0 -315
- package/tests/clients/AIClient.test.ts +0 -668
- package/tests/clients/anthropic.test.ts +0 -202
- package/tests/clients/contextLimits.test.ts +0 -97
- package/tests/clients/fireworks.test.ts +0 -65
- package/tests/clients/openai.images.test.ts +0 -105
- package/tests/clients/pricing.test.ts +0 -206
- package/tests/clients/reasoningEffort.test.ts +0 -140
- package/tests/compressor/bigstring.test.ts +0 -450
- package/tests/compressor/bigstring.txt +0 -1
- package/tests/compressor/githubjson.txt +0 -1
- package/tests/compressor/toolResponseCache.test.ts +0 -304
- package/tests/compressor/usageBase64.json +0 -159
- package/tests/compressor/usageBase64.test.ts +0 -175
- package/tests/fixtures/fake-secret.txt +0 -1
- package/tests/manual/agent-events/run-test.ts +0 -203
- package/tests/manual/browser-login/README.md +0 -189
- package/tests/manual/browser-login/test_browser_login_basic.ts +0 -115
- package/tests/manual/browser-login/test_cli_integration.ts +0 -169
- package/tests/manual/browser-login/test_cross_platform_browser.ts +0 -186
- package/tests/manual/browser-login/test_error_scenarios.ts +0 -223
- package/tests/manual/cli/no-env.sh +0 -274
- package/tests/manual/clients/completions.json +0 -1151
- package/tests/manual/clients/completions.test.ts +0 -198
- package/tests/manual/file-edits/figma.test.ts +0 -3
- package/tests/manual/file-edits/fileblocks/readwrite.test.ts +0 -100
- package/tests/manual/file-edits/patching/input.txt +0 -145
- package/tests/manual/file-edits/patching/output.txt +0 -145
- package/tests/manual/file-edits/patching/patch.txt +0 -15
- package/tests/manual/file-edits/patching/unseen.txt +0 -80
- package/tests/manual/file-edits/patching.test.ts +0 -139
- package/tests/manual/modalities/README.md +0 -157
- package/tests/manual/modalities/google.modalities.test.ts +0 -335
- package/tests/manual/modalities/openai.modalities.test.ts +0 -329
- package/tests/manual/modalities/streaming.test.ts +0 -260
- package/tests/manual/modalities/xai.modalities.test.ts +0 -294
- package/tests/manual/test-concurrent-ask.ts +0 -43
- package/tests/manual/ycmd/debug_diagnostics_test.ts +0 -127
- package/tests/manual/ycmd/fixtures/debug_diagnostics.ts +0 -26
- package/tests/manual/ycmd/fixtures/file_change_test.ts +0 -17
- package/tests/manual/ycmd/minimal_advanced_test.ts +0 -108
- package/tests/manual/ycmd/simple_diagnostics_test.ts +0 -61
- package/tests/manual/ycmd/simple_test.ts +0 -74
- package/tests/manual/ycmd/test-typescript-sample.ts +0 -34
- package/tests/manual/ycmd/test_advanced_features.ts +0 -407
- package/tests/manual/ycmd/test_advanced_with_tools.ts +0 -320
- package/tests/manual/ycmd/test_comprehensive_typescript.ts +0 -179
- package/tests/manual/ycmd/test_diagnostics_file_changes.ts +0 -249
- package/tests/manual/ycmd/test_diagnostics_fix.ts +0 -99
- package/tests/manual/ycmd/test_diagnostics_simple.ts +0 -100
- package/tests/manual/ycmd/test_diagnostics_timing.ts +0 -120
- package/tests/manual/ycmd/test_discover_commands.ts +0 -310
- package/tests/manual/ycmd/test_endpoints.ts +0 -115
- package/tests/manual/ycmd/test_final_comprehensive.ts +0 -218
- package/tests/manual/ycmd/test_final_validation.ts +0 -150
- package/tests/manual/ycmd/test_implementation.js +0 -42
- package/tests/manual/ycmd/test_individual_ycmd_tool.ts +0 -39
- package/tests/manual/ycmd/test_server_manager.ts +0 -52
- package/tests/manual/ycmd/test_simple_debug.ts +0 -86
- package/tests/manual/ycmd/test_tsserver_workflow.js +0 -83
- package/tests/manual/ycmd/test_tsserver_workflow.ts +0 -122
- package/tests/manual/ycmd/test_typescript_simple.ts +0 -48
- package/tests/manual/ycmd/test_typescript_ycmd.ts +0 -105
- package/tests/manual/ycmd/test_workspace_config.ts +0 -90
- package/tests/manual/ycmd/test_ycmd_auto_start.ts +0 -137
- package/tests/manual/ycmd/test_ycmd_comprehensive.ts +0 -73
- package/tests/manual/ycmd/test_ycmd_connection.py +0 -10
- package/tests/manual/ycmd/test_ycmd_direct.ts +0 -142
- package/tests/manual/ycmd/test_ycmd_experiment.ts +0 -48
- package/tests/manual/ycmd/test_ycmd_final.ts +0 -200
- package/tests/manual/ycmd/test_ycmd_fixed.py +0 -18
- package/tests/manual/ycmd/test_ycmd_integration.ts +0 -112
- package/tests/manual/ycmd/test_ycmd_simple.ts +0 -45
- package/tests/manual/ycmd/test_ycmd_usage.py +0 -27
- package/tests/manual/ycmd/working_simple_test.ts +0 -134
- package/tests/patching/corrupted.test.ts +0 -78
- package/tests/patching/fixtures/transcript-mangles/agent-sync-fs-nested-catch.json +0 -9
- package/tests/patching/fixtures/transcript-mangles/automation-functions-crossed.json +0 -9
- package/tests/patching/fixtures/transcript-mangles/fruit-ninja-confirmed-retirement.json +0 -8
- package/tests/patching/imports.patch.txt +0 -11
- package/tests/patching/imports.test.ts +0 -43
- package/tests/patching/imports.txt +0 -11
- package/tests/patching/interface.patch.txt +0 -15
- package/tests/patching/interface.txt +0 -7
- package/tests/patching/patchFileOutput.test.ts +0 -328
- package/tests/patching/regression-2026.test.ts +0 -752
- package/tests/patching/transcriptMangleRegression.test.ts +0 -125
- package/tests/plugins/language/languagePlugin-content-triggers.test.ts +0 -346
- package/tests/plugins/language/languagePlugin-integration.test.ts +0 -471
- package/tests/plugins/language/languagePlugin.test.ts +0 -385
- package/tests/processes/managedProcessShim.test.ts +0 -59
- package/tests/processors/Base64ImageDetector.test.ts +0 -979
- package/tests/processors/CustomVariables.test.ts +0 -981
- package/tests/processors/CustomVariablesBenchmark.test.ts +0 -237
- package/tests/processors/HarmonyToolProcessor.test.ts +0 -490
- package/tests/processors/TokenCompressor.test.ts +0 -674
- package/tests/processors/ToolResponseCache.test.ts +0 -864
- package/tests/processors/tools/boundedRetrievalTools.test.ts +0 -68
- package/tests/processors/tools/grepToolResponse.test.ts +0 -159
- package/tests/services/ConversionService.test.ts +0 -154
- package/tests/services/DockerService.test.ts +0 -24
- package/tests/services/Tools.test.ts +0 -1738
- package/tests/services/ToolsService.setFunction.test.ts +0 -68
- package/tests/services/WorkerReloadConfig.test.ts +0 -141
- package/tests/test.spec.ts +0 -163
- package/tests/unit/InputQueueManager.test.ts +0 -174
- package/tests/unit/McpWebsocketTransport.test.ts +0 -56
- package/tests/unit/agents/historyRollback.test.ts +0 -53
- package/tests/unit/agents/tools/loadImageAsBase64.test.ts +0 -44
- package/tests/unit/auth/jwtStore.test.ts +0 -55
- package/tests/unit/auth/keyAuth.test.ts +0 -152
- package/tests/unit/auth/keyManager.test.ts +0 -130
- package/tests/unit/auth/registerIdentity.test.ts +0 -99
- package/tests/unit/chat/ToolCommandModule.test.ts +0 -71
- package/tests/unit/chat/historyCommandArgs.test.ts +0 -37
- package/tests/unit/clients/AIClient.test.ts +0 -454
- package/tests/unit/clients/anthropic.responseMetadata.test.ts +0 -81
- package/tests/unit/clients/attribution.test.ts +0 -185
- package/tests/unit/clients/http.responseMetadata.test.ts +0 -86
- package/tests/unit/clients/openai.responseMetadata.test.ts +0 -90
- package/tests/unit/clients/responseMetadata.test.ts +0 -123
- package/tests/unit/clients/withRetry.test.ts +0 -319
- package/tests/unit/commands/agents.test.ts +0 -111
- package/tests/unit/commands/github-credentials.test.ts +0 -210
- package/tests/unit/commands/misc.test.ts +0 -85
- package/tests/unit/commands/remote.test.ts +0 -79
- package/tests/unit/commands/sandbox.test.ts +0 -350
- package/tests/unit/hashes.test.ts +0 -23
- package/tests/unit/input-queue.test.ts +0 -80
- package/tests/unit/login.test.ts +0 -218
- package/tests/unit/modules/moduleLoading.test.ts +0 -305
- package/tests/unit/plugins/pluginLoading.test.ts +0 -97
- package/tests/unit/services/AgentSyncKnowhowWeb.test.ts +0 -38
- package/tests/unit/services/KnowhowClient.test.ts +0 -84
- package/tests/unit/services/LazyToolsService.test.ts +0 -53
- package/tests/unit/services/Mcp.test.ts +0 -56
- package/tests/unit/services/MinimalToolsService.test.ts +0 -424
- package/tests/unit/services/RuntimeReloadService.test.ts +0 -29
- package/tests/unit/services/SessionManager.test.ts +0 -43
- package/tests/unit/services/SyncedAgentWatcher.test.ts +0 -89
- package/tests/unit/services/SyncerService.test.ts +0 -45
- package/tests/unit/tunnel.test.ts +0 -51
- package/tests/unit/util/Trace.test.ts +0 -119
- package/tests/unit/utils/http.test.ts +0 -43
- package/ts_build/tests/XmlToolCallProcessor.test.d.ts +0 -1
- package/ts_build/tests/XmlToolCallProcessor.test.js +0 -376
- package/ts_build/tests/XmlToolCallProcessor.test.js.map +0 -1
- package/ts_build/tests/agents/interrupt.test.d.ts +0 -14
- package/ts_build/tests/agents/interrupt.test.js +0 -136
- package/ts_build/tests/agents/interrupt.test.js.map +0 -1
- package/ts_build/tests/agents/observe-base.test.d.ts +0 -1
- package/ts_build/tests/agents/observe-base.test.js +0 -149
- package/ts_build/tests/agents/observe-base.test.js.map +0 -1
- package/ts_build/tests/agents/tools/connectAgent.test.d.ts +0 -1
- package/ts_build/tests/agents/tools/connectAgent.test.js +0 -142
- package/ts_build/tests/agents/tools/connectAgent.test.js.map +0 -1
- package/ts_build/tests/agents/tools/observe.test.d.ts +0 -1
- package/ts_build/tests/agents/tools/observe.test.js +0 -148
- package/ts_build/tests/agents/tools/observe.test.js.map +0 -1
- package/ts_build/tests/agents/tools/readFile.test.d.ts +0 -1
- package/ts_build/tests/agents/tools/readFile.test.js +0 -90
- package/ts_build/tests/agents/tools/readFile.test.js.map +0 -1
- package/ts_build/tests/agents/tools/replyToParent.test.d.ts +0 -1
- package/ts_build/tests/agents/tools/replyToParent.test.js +0 -116
- package/ts_build/tests/agents/tools/replyToParent.test.js.map +0 -1
- package/ts_build/tests/agents/tools/sendAgentMessage.test.d.ts +0 -1
- package/ts_build/tests/agents/tools/sendAgentMessage.test.js +0 -112
- package/ts_build/tests/agents/tools/sendAgentMessage.test.js.map +0 -1
- package/ts_build/tests/agents/tools/waitForAgentCompleted.test.d.ts +0 -1
- package/ts_build/tests/agents/tools/waitForAgentCompleted.test.js +0 -147
- package/ts_build/tests/agents/tools/waitForAgentCompleted.test.js.map +0 -1
- package/ts_build/tests/chat/detach-attach-rendering.test.d.ts +0 -1
- package/ts_build/tests/chat/detach-attach-rendering.test.js +0 -168
- package/ts_build/tests/chat/detach-attach-rendering.test.js.map +0 -1
- package/ts_build/tests/clients/AIClient.test.d.ts +0 -1
- package/ts_build/tests/clients/AIClient.test.js +0 -483
- package/ts_build/tests/clients/AIClient.test.js.map +0 -1
- package/ts_build/tests/clients/anthropic.test.d.ts +0 -1
- package/ts_build/tests/clients/anthropic.test.js +0 -159
- package/ts_build/tests/clients/anthropic.test.js.map +0 -1
- package/ts_build/tests/clients/contextLimits.test.d.ts +0 -1
- package/ts_build/tests/clients/contextLimits.test.js +0 -69
- package/ts_build/tests/clients/contextLimits.test.js.map +0 -1
- package/ts_build/tests/clients/fireworks.test.d.ts +0 -1
- package/ts_build/tests/clients/fireworks.test.js +0 -65
- package/ts_build/tests/clients/fireworks.test.js.map +0 -1
- package/ts_build/tests/clients/openai.images.test.d.ts +0 -1
- package/ts_build/tests/clients/openai.images.test.js +0 -94
- package/ts_build/tests/clients/openai.images.test.js.map +0 -1
- package/ts_build/tests/clients/pricing.test.d.ts +0 -1
- package/ts_build/tests/clients/pricing.test.js +0 -124
- package/ts_build/tests/clients/pricing.test.js.map +0 -1
- package/ts_build/tests/clients/reasoningEffort.test.d.ts +0 -1
- package/ts_build/tests/clients/reasoningEffort.test.js +0 -116
- package/ts_build/tests/clients/reasoningEffort.test.js.map +0 -1
- package/ts_build/tests/compressor/bigstring.test.d.ts +0 -1
- package/ts_build/tests/compressor/bigstring.test.js +0 -275
- package/ts_build/tests/compressor/bigstring.test.js.map +0 -1
- package/ts_build/tests/compressor/toolResponseCache.test.d.ts +0 -1
- package/ts_build/tests/compressor/toolResponseCache.test.js +0 -250
- package/ts_build/tests/compressor/toolResponseCache.test.js.map +0 -1
- package/ts_build/tests/compressor/usageBase64.test.d.ts +0 -1
- package/ts_build/tests/compressor/usageBase64.test.js +0 -109
- package/ts_build/tests/compressor/usageBase64.test.js.map +0 -1
- package/ts_build/tests/manual/agent-events/run-test.d.ts +0 -2
- package/ts_build/tests/manual/agent-events/run-test.js +0 -148
- package/ts_build/tests/manual/agent-events/run-test.js.map +0 -1
- package/ts_build/tests/manual/browser-login/test_browser_login_basic.d.ts +0 -2
- package/ts_build/tests/manual/browser-login/test_browser_login_basic.js +0 -118
- package/ts_build/tests/manual/browser-login/test_browser_login_basic.js.map +0 -1
- package/ts_build/tests/manual/browser-login/test_cli_integration.d.ts +0 -2
- package/ts_build/tests/manual/browser-login/test_cli_integration.js +0 -163
- package/ts_build/tests/manual/browser-login/test_cli_integration.js.map +0 -1
- package/ts_build/tests/manual/browser-login/test_cross_platform_browser.d.ts +0 -2
- package/ts_build/tests/manual/browser-login/test_cross_platform_browser.js +0 -169
- package/ts_build/tests/manual/browser-login/test_cross_platform_browser.js.map +0 -1
- package/ts_build/tests/manual/browser-login/test_error_scenarios.d.ts +0 -2
- package/ts_build/tests/manual/browser-login/test_error_scenarios.js +0 -207
- package/ts_build/tests/manual/browser-login/test_error_scenarios.js.map +0 -1
- package/ts_build/tests/manual/clients/completions.test.d.ts +0 -1
- package/ts_build/tests/manual/clients/completions.test.js +0 -151
- package/ts_build/tests/manual/clients/completions.test.js.map +0 -1
- package/ts_build/tests/manual/file-edits/figma.test.d.ts +0 -0
- package/ts_build/tests/manual/file-edits/figma.test.js +0 -2
- package/ts_build/tests/manual/file-edits/figma.test.js.map +0 -1
- package/ts_build/tests/manual/file-edits/fileblocks/readwrite.test.d.ts +0 -1
- package/ts_build/tests/manual/file-edits/fileblocks/readwrite.test.js +0 -110
- package/ts_build/tests/manual/file-edits/fileblocks/readwrite.test.js.map +0 -1
- package/ts_build/tests/manual/file-edits/patching.test.d.ts +0 -1
- package/ts_build/tests/manual/file-edits/patching.test.js +0 -129
- package/ts_build/tests/manual/file-edits/patching.test.js.map +0 -1
- package/ts_build/tests/manual/modalities/google.modalities.test.d.ts +0 -1
- package/ts_build/tests/manual/modalities/google.modalities.test.js +0 -262
- package/ts_build/tests/manual/modalities/google.modalities.test.js.map +0 -1
- package/ts_build/tests/manual/modalities/openai.modalities.test.d.ts +0 -1
- package/ts_build/tests/manual/modalities/openai.modalities.test.js +0 -262
- package/ts_build/tests/manual/modalities/openai.modalities.test.js.map +0 -1
- package/ts_build/tests/manual/modalities/streaming.test.d.ts +0 -1
- package/ts_build/tests/manual/modalities/streaming.test.js +0 -216
- package/ts_build/tests/manual/modalities/streaming.test.js.map +0 -1
- package/ts_build/tests/manual/modalities/xai.modalities.test.d.ts +0 -1
- package/ts_build/tests/manual/modalities/xai.modalities.test.js +0 -219
- package/ts_build/tests/manual/modalities/xai.modalities.test.js.map +0 -1
- package/ts_build/tests/manual/test-concurrent-ask.d.ts +0 -1
- package/ts_build/tests/manual/test-concurrent-ask.js +0 -22
- package/ts_build/tests/manual/test-concurrent-ask.js.map +0 -1
- package/ts_build/tests/manual/ycmd/debug_diagnostics_test.d.ts +0 -1
- package/ts_build/tests/manual/ycmd/debug_diagnostics_test.js +0 -124
- package/ts_build/tests/manual/ycmd/debug_diagnostics_test.js.map +0 -1
- package/ts_build/tests/manual/ycmd/minimal_advanced_test.d.ts +0 -2
- package/ts_build/tests/manual/ycmd/minimal_advanced_test.js +0 -114
- package/ts_build/tests/manual/ycmd/minimal_advanced_test.js.map +0 -1
- package/ts_build/tests/manual/ycmd/simple_diagnostics_test.d.ts +0 -1
- package/ts_build/tests/manual/ycmd/simple_diagnostics_test.js +0 -84
- package/ts_build/tests/manual/ycmd/simple_diagnostics_test.js.map +0 -1
- package/ts_build/tests/manual/ycmd/simple_test.d.ts +0 -2
- package/ts_build/tests/manual/ycmd/simple_test.js +0 -92
- package/ts_build/tests/manual/ycmd/simple_test.js.map +0 -1
- package/ts_build/tests/manual/ycmd/test-typescript-sample.d.ts +0 -14
- package/ts_build/tests/manual/ycmd/test-typescript-sample.js +0 -20
- package/ts_build/tests/manual/ycmd/test-typescript-sample.js.map +0 -1
- package/ts_build/tests/manual/ycmd/test_advanced_features.d.ts +0 -2
- package/ts_build/tests/manual/ycmd/test_advanced_features.js +0 -306
- package/ts_build/tests/manual/ycmd/test_advanced_features.js.map +0 -1
- package/ts_build/tests/manual/ycmd/test_advanced_with_tools.d.ts +0 -3
- package/ts_build/tests/manual/ycmd/test_advanced_with_tools.js +0 -271
- package/ts_build/tests/manual/ycmd/test_advanced_with_tools.js.map +0 -1
- package/ts_build/tests/manual/ycmd/test_comprehensive_typescript.d.ts +0 -2
- package/ts_build/tests/manual/ycmd/test_comprehensive_typescript.js +0 -196
- package/ts_build/tests/manual/ycmd/test_comprehensive_typescript.js.map +0 -1
- package/ts_build/tests/manual/ycmd/test_diagnostics_file_changes.d.ts +0 -1
- package/ts_build/tests/manual/ycmd/test_diagnostics_file_changes.js +0 -184
- package/ts_build/tests/manual/ycmd/test_diagnostics_file_changes.js.map +0 -1
- package/ts_build/tests/manual/ycmd/test_diagnostics_fix.d.ts +0 -2
- package/ts_build/tests/manual/ycmd/test_diagnostics_fix.js +0 -116
- package/ts_build/tests/manual/ycmd/test_diagnostics_fix.js.map +0 -1
- package/ts_build/tests/manual/ycmd/test_diagnostics_simple.d.ts +0 -1
- package/ts_build/tests/manual/ycmd/test_diagnostics_simple.js +0 -114
- package/ts_build/tests/manual/ycmd/test_diagnostics_simple.js.map +0 -1
- package/ts_build/tests/manual/ycmd/test_diagnostics_timing.d.ts +0 -1
- package/ts_build/tests/manual/ycmd/test_diagnostics_timing.js +0 -129
- package/ts_build/tests/manual/ycmd/test_diagnostics_timing.js.map +0 -1
- package/ts_build/tests/manual/ycmd/test_discover_commands.d.ts +0 -2
- package/ts_build/tests/manual/ycmd/test_discover_commands.js +0 -252
- package/ts_build/tests/manual/ycmd/test_discover_commands.js.map +0 -1
- package/ts_build/tests/manual/ycmd/test_endpoints.d.ts +0 -2
- package/ts_build/tests/manual/ycmd/test_endpoints.js +0 -130
- package/ts_build/tests/manual/ycmd/test_endpoints.js.map +0 -1
- package/ts_build/tests/manual/ycmd/test_final_comprehensive.d.ts +0 -2
- package/ts_build/tests/manual/ycmd/test_final_comprehensive.js +0 -231
- package/ts_build/tests/manual/ycmd/test_final_comprehensive.js.map +0 -1
- package/ts_build/tests/manual/ycmd/test_final_validation.d.ts +0 -2
- package/ts_build/tests/manual/ycmd/test_final_validation.js +0 -170
- package/ts_build/tests/manual/ycmd/test_final_validation.js.map +0 -1
- package/ts_build/tests/manual/ycmd/test_individual_ycmd_tool.d.ts +0 -2
- package/ts_build/tests/manual/ycmd/test_individual_ycmd_tool.js +0 -37
- package/ts_build/tests/manual/ycmd/test_individual_ycmd_tool.js.map +0 -1
- package/ts_build/tests/manual/ycmd/test_server_manager.d.ts +0 -1
- package/ts_build/tests/manual/ycmd/test_server_manager.js +0 -38
- package/ts_build/tests/manual/ycmd/test_server_manager.js.map +0 -1
- package/ts_build/tests/manual/ycmd/test_simple_debug.d.ts +0 -2
- package/ts_build/tests/manual/ycmd/test_simple_debug.js +0 -109
- package/ts_build/tests/manual/ycmd/test_simple_debug.js.map +0 -1
- package/ts_build/tests/manual/ycmd/test_tsserver_workflow.d.ts +0 -1
- package/ts_build/tests/manual/ycmd/test_tsserver_workflow.js +0 -138
- package/ts_build/tests/manual/ycmd/test_tsserver_workflow.js.map +0 -1
- package/ts_build/tests/manual/ycmd/test_typescript_simple.d.ts +0 -1
- package/ts_build/tests/manual/ycmd/test_typescript_simple.js +0 -76
- package/ts_build/tests/manual/ycmd/test_typescript_simple.js.map +0 -1
- package/ts_build/tests/manual/ycmd/test_typescript_ycmd.d.ts +0 -1
- package/ts_build/tests/manual/ycmd/test_typescript_ycmd.js +0 -115
- package/ts_build/tests/manual/ycmd/test_typescript_ycmd.js.map +0 -1
- package/ts_build/tests/manual/ycmd/test_workspace_config.d.ts +0 -1
- package/ts_build/tests/manual/ycmd/test_workspace_config.js +0 -99
- package/ts_build/tests/manual/ycmd/test_workspace_config.js.map +0 -1
- package/ts_build/tests/manual/ycmd/test_ycmd_auto_start.d.ts +0 -2
- package/ts_build/tests/manual/ycmd/test_ycmd_auto_start.js +0 -140
- package/ts_build/tests/manual/ycmd/test_ycmd_auto_start.js.map +0 -1
- package/ts_build/tests/manual/ycmd/test_ycmd_comprehensive.d.ts +0 -1
- package/ts_build/tests/manual/ycmd/test_ycmd_comprehensive.js +0 -93
- package/ts_build/tests/manual/ycmd/test_ycmd_comprehensive.js.map +0 -1
- package/ts_build/tests/manual/ycmd/test_ycmd_direct.d.ts +0 -2
- package/ts_build/tests/manual/ycmd/test_ycmd_direct.js +0 -159
- package/ts_build/tests/manual/ycmd/test_ycmd_direct.js.map +0 -1
- package/ts_build/tests/manual/ycmd/test_ycmd_experiment.d.ts +0 -15
- package/ts_build/tests/manual/ycmd/test_ycmd_experiment.js +0 -68
- package/ts_build/tests/manual/ycmd/test_ycmd_experiment.js.map +0 -1
- package/ts_build/tests/manual/ycmd/test_ycmd_final.d.ts +0 -2
- package/ts_build/tests/manual/ycmd/test_ycmd_final.js +0 -205
- package/ts_build/tests/manual/ycmd/test_ycmd_final.js.map +0 -1
- package/ts_build/tests/manual/ycmd/test_ycmd_integration.d.ts +0 -3
- package/ts_build/tests/manual/ycmd/test_ycmd_integration.js +0 -119
- package/ts_build/tests/manual/ycmd/test_ycmd_integration.js.map +0 -1
- package/ts_build/tests/manual/ycmd/test_ycmd_simple.d.ts +0 -2
- package/ts_build/tests/manual/ycmd/test_ycmd_simple.js +0 -36
- package/ts_build/tests/manual/ycmd/test_ycmd_simple.js.map +0 -1
- package/ts_build/tests/manual/ycmd/working_simple_test.d.ts +0 -2
- package/ts_build/tests/manual/ycmd/working_simple_test.js +0 -144
- package/ts_build/tests/manual/ycmd/working_simple_test.js.map +0 -1
- package/ts_build/tests/patching/corrupted.test.d.ts +0 -1
- package/ts_build/tests/patching/corrupted.test.js +0 -53
- package/ts_build/tests/patching/corrupted.test.js.map +0 -1
- package/ts_build/tests/patching/imports.test.d.ts +0 -1
- package/ts_build/tests/patching/imports.test.js +0 -71
- package/ts_build/tests/patching/imports.test.js.map +0 -1
- package/ts_build/tests/patching/patchFileOutput.test.d.ts +0 -1
- package/ts_build/tests/patching/patchFileOutput.test.js +0 -269
- package/ts_build/tests/patching/patchFileOutput.test.js.map +0 -1
- package/ts_build/tests/patching/regression-2026.test.d.ts +0 -1
- package/ts_build/tests/patching/regression-2026.test.js +0 -528
- package/ts_build/tests/patching/regression-2026.test.js.map +0 -1
- package/ts_build/tests/patching/transcriptMangleRegression.test.d.ts +0 -1
- package/ts_build/tests/patching/transcriptMangleRegression.test.js +0 -104
- package/ts_build/tests/patching/transcriptMangleRegression.test.js.map +0 -1
- package/ts_build/tests/plugins/language/languagePlugin-content-triggers.test.d.ts +0 -1
- package/ts_build/tests/plugins/language/languagePlugin-content-triggers.test.js +0 -294
- package/ts_build/tests/plugins/language/languagePlugin-content-triggers.test.js.map +0 -1
- package/ts_build/tests/plugins/language/languagePlugin-integration.test.d.ts +0 -1
- package/ts_build/tests/plugins/language/languagePlugin-integration.test.js +0 -343
- package/ts_build/tests/plugins/language/languagePlugin-integration.test.js.map +0 -1
- package/ts_build/tests/plugins/language/languagePlugin.test.d.ts +0 -1
- package/ts_build/tests/plugins/language/languagePlugin.test.js +0 -315
- package/ts_build/tests/plugins/language/languagePlugin.test.js.map +0 -1
- package/ts_build/tests/processes/managedProcessShim.test.d.ts +0 -1
- package/ts_build/tests/processes/managedProcessShim.test.js +0 -92
- package/ts_build/tests/processes/managedProcessShim.test.js.map +0 -1
- package/ts_build/tests/processors/Base64ImageDetector.test.d.ts +0 -1
- package/ts_build/tests/processors/Base64ImageDetector.test.js +0 -792
- package/ts_build/tests/processors/Base64ImageDetector.test.js.map +0 -1
- package/ts_build/tests/processors/CustomVariables.test.d.ts +0 -1
- package/ts_build/tests/processors/CustomVariables.test.js +0 -764
- package/ts_build/tests/processors/CustomVariables.test.js.map +0 -1
- package/ts_build/tests/processors/CustomVariablesBenchmark.test.d.ts +0 -1
- package/ts_build/tests/processors/CustomVariablesBenchmark.test.js +0 -179
- package/ts_build/tests/processors/CustomVariablesBenchmark.test.js.map +0 -1
- package/ts_build/tests/processors/HarmonyToolProcessor.test.d.ts +0 -1
- package/ts_build/tests/processors/HarmonyToolProcessor.test.js +0 -382
- package/ts_build/tests/processors/HarmonyToolProcessor.test.js.map +0 -1
- package/ts_build/tests/processors/TokenCompressor.test.d.ts +0 -1
- package/ts_build/tests/processors/TokenCompressor.test.js +0 -473
- package/ts_build/tests/processors/TokenCompressor.test.js.map +0 -1
- package/ts_build/tests/processors/ToolResponseCache.test.d.ts +0 -1
- package/ts_build/tests/processors/ToolResponseCache.test.js +0 -657
- package/ts_build/tests/processors/ToolResponseCache.test.js.map +0 -1
- package/ts_build/tests/processors/tools/boundedRetrievalTools.test.d.ts +0 -1
- package/ts_build/tests/processors/tools/boundedRetrievalTools.test.js +0 -57
- package/ts_build/tests/processors/tools/boundedRetrievalTools.test.js.map +0 -1
- package/ts_build/tests/processors/tools/grepToolResponse.test.d.ts +0 -1
- package/ts_build/tests/processors/tools/grepToolResponse.test.js +0 -77
- package/ts_build/tests/processors/tools/grepToolResponse.test.js.map +0 -1
- package/ts_build/tests/services/ConversionService.test.d.ts +0 -1
- package/ts_build/tests/services/ConversionService.test.js +0 -154
- package/ts_build/tests/services/ConversionService.test.js.map +0 -1
- package/ts_build/tests/services/DockerService.test.d.ts +0 -1
- package/ts_build/tests/services/DockerService.test.js +0 -22
- package/ts_build/tests/services/DockerService.test.js.map +0 -1
- package/ts_build/tests/services/Tools.test.d.ts +0 -1
- package/ts_build/tests/services/Tools.test.js +0 -1365
- package/ts_build/tests/services/Tools.test.js.map +0 -1
- package/ts_build/tests/services/ToolsService.setFunction.test.d.ts +0 -1
- package/ts_build/tests/services/ToolsService.setFunction.test.js +0 -51
- package/ts_build/tests/services/ToolsService.setFunction.test.js.map +0 -1
- package/ts_build/tests/services/WorkerReloadConfig.test.d.ts +0 -1
- package/ts_build/tests/services/WorkerReloadConfig.test.js +0 -86
- package/ts_build/tests/services/WorkerReloadConfig.test.js.map +0 -1
- package/ts_build/tests/test.spec.d.ts +0 -1
- package/ts_build/tests/test.spec.js +0 -139
- package/ts_build/tests/test.spec.js.map +0 -1
- package/ts_build/tests/unit/InputQueueManager.test.d.ts +0 -1
- package/ts_build/tests/unit/InputQueueManager.test.js +0 -104
- package/ts_build/tests/unit/InputQueueManager.test.js.map +0 -1
- package/ts_build/tests/unit/McpWebsocketTransport.test.d.ts +0 -1
- package/ts_build/tests/unit/McpWebsocketTransport.test.js +0 -47
- package/ts_build/tests/unit/McpWebsocketTransport.test.js.map +0 -1
- package/ts_build/tests/unit/agents/historyRollback.test.d.ts +0 -1
- package/ts_build/tests/unit/agents/historyRollback.test.js +0 -42
- package/ts_build/tests/unit/agents/historyRollback.test.js.map +0 -1
- package/ts_build/tests/unit/agents/tools/loadImageAsBase64.test.d.ts +0 -1
- package/ts_build/tests/unit/agents/tools/loadImageAsBase64.test.js +0 -67
- package/ts_build/tests/unit/agents/tools/loadImageAsBase64.test.js.map +0 -1
- package/ts_build/tests/unit/auth/jwtStore.test.d.ts +0 -1
- package/ts_build/tests/unit/auth/jwtStore.test.js +0 -46
- package/ts_build/tests/unit/auth/jwtStore.test.js.map +0 -1
- package/ts_build/tests/unit/auth/keyAuth.test.d.ts +0 -1
- package/ts_build/tests/unit/auth/keyAuth.test.js +0 -118
- package/ts_build/tests/unit/auth/keyAuth.test.js.map +0 -1
- package/ts_build/tests/unit/auth/keyManager.test.d.ts +0 -1
- package/ts_build/tests/unit/auth/keyManager.test.js +0 -96
- package/ts_build/tests/unit/auth/keyManager.test.js.map +0 -1
- package/ts_build/tests/unit/auth/registerIdentity.test.d.ts +0 -1
- package/ts_build/tests/unit/auth/registerIdentity.test.js +0 -92
- package/ts_build/tests/unit/auth/registerIdentity.test.js.map +0 -1
- package/ts_build/tests/unit/chat/ToolCommandModule.test.d.ts +0 -1
- package/ts_build/tests/unit/chat/ToolCommandModule.test.js +0 -61
- package/ts_build/tests/unit/chat/ToolCommandModule.test.js.map +0 -1
- package/ts_build/tests/unit/chat/historyCommandArgs.test.d.ts +0 -1
- package/ts_build/tests/unit/chat/historyCommandArgs.test.js +0 -29
- package/ts_build/tests/unit/chat/historyCommandArgs.test.js.map +0 -1
- package/ts_build/tests/unit/clients/AIClient.test.d.ts +0 -1
- package/ts_build/tests/unit/clients/AIClient.test.js +0 -342
- package/ts_build/tests/unit/clients/AIClient.test.js.map +0 -1
- package/ts_build/tests/unit/clients/anthropic.responseMetadata.test.d.ts +0 -1
- package/ts_build/tests/unit/clients/anthropic.responseMetadata.test.js +0 -77
- package/ts_build/tests/unit/clients/anthropic.responseMetadata.test.js.map +0 -1
- package/ts_build/tests/unit/clients/attribution.test.d.ts +0 -1
- package/ts_build/tests/unit/clients/attribution.test.js +0 -153
- package/ts_build/tests/unit/clients/attribution.test.js.map +0 -1
- package/ts_build/tests/unit/clients/http.responseMetadata.test.d.ts +0 -1
- package/ts_build/tests/unit/clients/http.responseMetadata.test.js +0 -77
- package/ts_build/tests/unit/clients/http.responseMetadata.test.js.map +0 -1
- package/ts_build/tests/unit/clients/openai.responseMetadata.test.d.ts +0 -1
- package/ts_build/tests/unit/clients/openai.responseMetadata.test.js +0 -86
- package/ts_build/tests/unit/clients/openai.responseMetadata.test.js.map +0 -1
- package/ts_build/tests/unit/clients/responseMetadata.test.d.ts +0 -1
- package/ts_build/tests/unit/clients/responseMetadata.test.js +0 -96
- package/ts_build/tests/unit/clients/responseMetadata.test.js.map +0 -1
- package/ts_build/tests/unit/clients/withRetry.test.d.ts +0 -1
- package/ts_build/tests/unit/clients/withRetry.test.js +0 -225
- package/ts_build/tests/unit/clients/withRetry.test.js.map +0 -1
- package/ts_build/tests/unit/commands/agents.test.d.ts +0 -1
- package/ts_build/tests/unit/commands/agents.test.js +0 -119
- package/ts_build/tests/unit/commands/agents.test.js.map +0 -1
- package/ts_build/tests/unit/commands/github-credentials.test.d.ts +0 -1
- package/ts_build/tests/unit/commands/github-credentials.test.js +0 -145
- package/ts_build/tests/unit/commands/github-credentials.test.js.map +0 -1
- package/ts_build/tests/unit/commands/misc.test.d.ts +0 -1
- package/ts_build/tests/unit/commands/misc.test.js +0 -70
- package/ts_build/tests/unit/commands/misc.test.js.map +0 -1
- package/ts_build/tests/unit/commands/remote.test.d.ts +0 -1
- package/ts_build/tests/unit/commands/remote.test.js +0 -70
- package/ts_build/tests/unit/commands/remote.test.js.map +0 -1
- package/ts_build/tests/unit/commands/sandbox.test.d.ts +0 -1
- package/ts_build/tests/unit/commands/sandbox.test.js +0 -258
- package/ts_build/tests/unit/commands/sandbox.test.js.map +0 -1
- package/ts_build/tests/unit/hashes.test.d.ts +0 -1
- package/ts_build/tests/unit/hashes.test.js +0 -25
- package/ts_build/tests/unit/hashes.test.js.map +0 -1
- package/ts_build/tests/unit/input-queue.test.d.ts +0 -1
- package/ts_build/tests/unit/input-queue.test.js +0 -32
- package/ts_build/tests/unit/input-queue.test.js.map +0 -1
- package/ts_build/tests/unit/login.test.d.ts +0 -1
- package/ts_build/tests/unit/login.test.js +0 -166
- package/ts_build/tests/unit/login.test.js.map +0 -1
- package/ts_build/tests/unit/modules/moduleLoading.test.d.ts +0 -1
- package/ts_build/tests/unit/modules/moduleLoading.test.js +0 -272
- package/ts_build/tests/unit/modules/moduleLoading.test.js.map +0 -1
- package/ts_build/tests/unit/plugins/pluginLoading.test.d.ts +0 -1
- package/ts_build/tests/unit/plugins/pluginLoading.test.js +0 -117
- package/ts_build/tests/unit/plugins/pluginLoading.test.js.map +0 -1
- package/ts_build/tests/unit/services/AgentSyncKnowhowWeb.test.d.ts +0 -1
- package/ts_build/tests/unit/services/AgentSyncKnowhowWeb.test.js +0 -32
- package/ts_build/tests/unit/services/AgentSyncKnowhowWeb.test.js.map +0 -1
- package/ts_build/tests/unit/services/KnowhowClient.test.d.ts +0 -1
- package/ts_build/tests/unit/services/KnowhowClient.test.js +0 -69
- package/ts_build/tests/unit/services/KnowhowClient.test.js.map +0 -1
- package/ts_build/tests/unit/services/LazyToolsService.test.d.ts +0 -1
- package/ts_build/tests/unit/services/LazyToolsService.test.js +0 -47
- package/ts_build/tests/unit/services/LazyToolsService.test.js.map +0 -1
- package/ts_build/tests/unit/services/Mcp.test.d.ts +0 -1
- package/ts_build/tests/unit/services/Mcp.test.js +0 -45
- package/ts_build/tests/unit/services/Mcp.test.js.map +0 -1
- package/ts_build/tests/unit/services/MinimalToolsService.test.d.ts +0 -1
- package/ts_build/tests/unit/services/MinimalToolsService.test.js +0 -320
- package/ts_build/tests/unit/services/MinimalToolsService.test.js.map +0 -1
- package/ts_build/tests/unit/services/RuntimeReloadService.test.d.ts +0 -1
- package/ts_build/tests/unit/services/RuntimeReloadService.test.js +0 -26
- package/ts_build/tests/unit/services/RuntimeReloadService.test.js.map +0 -1
- package/ts_build/tests/unit/services/SessionManager.test.d.ts +0 -1
- package/ts_build/tests/unit/services/SessionManager.test.js +0 -72
- package/ts_build/tests/unit/services/SessionManager.test.js.map +0 -1
- package/ts_build/tests/unit/services/SyncedAgentWatcher.test.d.ts +0 -1
- package/ts_build/tests/unit/services/SyncedAgentWatcher.test.js +0 -78
- package/ts_build/tests/unit/services/SyncedAgentWatcher.test.js.map +0 -1
- package/ts_build/tests/unit/services/SyncerService.test.d.ts +0 -1
- package/ts_build/tests/unit/services/SyncerService.test.js +0 -40
- package/ts_build/tests/unit/services/SyncerService.test.js.map +0 -1
- package/ts_build/tests/unit/tunnel.test.d.ts +0 -1
- package/ts_build/tests/unit/tunnel.test.js +0 -47
- package/ts_build/tests/unit/tunnel.test.js.map +0 -1
- package/ts_build/tests/unit/util/Trace.test.d.ts +0 -1
- package/ts_build/tests/unit/util/Trace.test.js +0 -107
- package/ts_build/tests/unit/util/Trace.test.js.map +0 -1
- package/ts_build/tests/unit/utils/http.test.d.ts +0 -1
- package/ts_build/tests/unit/utils/http.test.js +0 -69
- package/ts_build/tests/unit/utils/http.test.js.map +0 -1
- package/tsconfig.json +0 -34
- package/tslint.json +0 -11
|
@@ -1,1738 +0,0 @@
|
|
|
1
|
-
import { ToolsService, ToolContext, ToolCallContext } from "../../src/services/Tools";
|
|
2
|
-
import { Tool, ToolCall } from "../../src/clients/types";
|
|
3
|
-
import { createPatternMatcher } from "../../src/services/types";
|
|
4
|
-
import { AgentService } from "../../src/services/AgentService";
|
|
5
|
-
import { EventService } from "../../src/services/EventService";
|
|
6
|
-
import { AIClient } from "../../src/clients";
|
|
7
|
-
import { PluginService } from "../../src/plugins/plugins";
|
|
8
|
-
|
|
9
|
-
describe("ToolsService", () => {
|
|
10
|
-
let toolsService: ToolsService;
|
|
11
|
-
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
toolsService = new ToolsService();
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
describe("constructor", () => {
|
|
17
|
-
it("should initialize with empty context when no context is provided", () => {
|
|
18
|
-
const service = new ToolsService();
|
|
19
|
-
const context = service.getContext();
|
|
20
|
-
|
|
21
|
-
expect(context).toBeDefined();
|
|
22
|
-
expect(context.Tools).toBe(service);
|
|
23
|
-
expect(context.Agents).toBeUndefined();
|
|
24
|
-
expect(context.Events).toBeUndefined();
|
|
25
|
-
expect(context.Clients).toBeUndefined();
|
|
26
|
-
expect(context.Plugins).toBeUndefined();
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it("should initialize with provided context", () => {
|
|
30
|
-
const mockAgents = {} as AgentService;
|
|
31
|
-
const mockEvents = {} as EventService;
|
|
32
|
-
const initialContext: ToolContext = {
|
|
33
|
-
Agents: mockAgents,
|
|
34
|
-
Events: mockEvents,
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
const service = new ToolsService(initialContext);
|
|
38
|
-
const context = service.getContext();
|
|
39
|
-
|
|
40
|
-
expect(context.Tools).toBe(service);
|
|
41
|
-
expect(context.Agents).toBe(mockAgents);
|
|
42
|
-
expect(context.Events).toBe(mockEvents);
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
describe("context management", () => {
|
|
47
|
-
it("should set and get context", () => {
|
|
48
|
-
const mockContext: ToolContext = {
|
|
49
|
-
Agents: {} as AgentService,
|
|
50
|
-
metadata: { test: "value" },
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
toolsService.setContext(mockContext);
|
|
54
|
-
const context = toolsService.getContext();
|
|
55
|
-
|
|
56
|
-
expect(context.Tools).toBe(toolsService);
|
|
57
|
-
expect(context.Agents).toBe(mockContext.Agents);
|
|
58
|
-
expect(context.metadata).toEqual({ test: "value" });
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it("should add context properties", () => {
|
|
62
|
-
const mockAgents = {} as AgentService;
|
|
63
|
-
|
|
64
|
-
toolsService.addContext("Agents", mockAgents);
|
|
65
|
-
const context = toolsService.getContext();
|
|
66
|
-
|
|
67
|
-
expect(context.Agents).toBe(mockAgents);
|
|
68
|
-
expect(context.Tools).toBe(toolsService);
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
describe("tool management", () => {
|
|
73
|
-
const mockTool: Tool = {
|
|
74
|
-
type: "function",
|
|
75
|
-
function: {
|
|
76
|
-
name: "testTool",
|
|
77
|
-
description: "A test tool",
|
|
78
|
-
parameters: {
|
|
79
|
-
type: "object",
|
|
80
|
-
properties: {
|
|
81
|
-
input: { type: "string", description: "Test input" },
|
|
82
|
-
},
|
|
83
|
-
required: ["input"],
|
|
84
|
-
},
|
|
85
|
-
},
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
it("should add a single tool", () => {
|
|
89
|
-
toolsService.addTool(mockTool);
|
|
90
|
-
|
|
91
|
-
expect(toolsService.getTools()).toContain(mockTool);
|
|
92
|
-
expect(toolsService.getToolNames()).toContain("testTool");
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it("should add multiple tools", () => {
|
|
96
|
-
const tool2: Tool = {
|
|
97
|
-
type: "function",
|
|
98
|
-
function: {
|
|
99
|
-
name: "testTool2",
|
|
100
|
-
description: "Another test tool",
|
|
101
|
-
parameters: {
|
|
102
|
-
type: "object",
|
|
103
|
-
properties: {},
|
|
104
|
-
required: [],
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
toolsService.addTools([mockTool, tool2]);
|
|
110
|
-
|
|
111
|
-
expect(toolsService.getTools()).toHaveLength(2);
|
|
112
|
-
expect(toolsService.getToolNames()).toEqual(["testTool", "testTool2"]);
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it("should prevent duplicate tool names", () => {
|
|
116
|
-
toolsService.addTool(mockTool);
|
|
117
|
-
toolsService.addTools([mockTool]); // Try to add same tool again
|
|
118
|
-
|
|
119
|
-
expect(toolsService.getTools()).toHaveLength(1);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it("should get tool by name", () => {
|
|
123
|
-
toolsService.addTool(mockTool);
|
|
124
|
-
|
|
125
|
-
const retrievedTool = toolsService.getTool("testTool");
|
|
126
|
-
expect(retrievedTool).toBe(mockTool);
|
|
127
|
-
|
|
128
|
-
const nonExistentTool = toolsService.getTool("nonExistent");
|
|
129
|
-
expect(nonExistentTool).toBeUndefined();
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it("should get tools by names", () => {
|
|
133
|
-
const tool2: Tool = {
|
|
134
|
-
type: "function",
|
|
135
|
-
function: {
|
|
136
|
-
name: "testTool2",
|
|
137
|
-
description: "Another test tool",
|
|
138
|
-
parameters: {
|
|
139
|
-
type: "object",
|
|
140
|
-
properties: {},
|
|
141
|
-
required: [],
|
|
142
|
-
},
|
|
143
|
-
},
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
toolsService.addTools([mockTool, tool2]);
|
|
147
|
-
|
|
148
|
-
const selectedTools = toolsService.getToolsByNames(["testTool"]);
|
|
149
|
-
expect(selectedTools).toHaveLength(1);
|
|
150
|
-
expect(selectedTools[0]).toBe(mockTool);
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
describe("function management", () => {
|
|
155
|
-
it("should set and get functions", () => {
|
|
156
|
-
const testFunction = jest.fn().mockReturnValue("test result");
|
|
157
|
-
|
|
158
|
-
toolsService.setFunction("testFunc", testFunction);
|
|
159
|
-
const retrievedFunction = toolsService.getFunction("testFunc");
|
|
160
|
-
|
|
161
|
-
expect(retrievedFunction).toBeDefined();
|
|
162
|
-
expect(typeof retrievedFunction).toBe("function");
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
it("should add multiple functions", () => {
|
|
166
|
-
const functions = {
|
|
167
|
-
func1: jest.fn(),
|
|
168
|
-
func2: jest.fn(),
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
toolsService.addFunctions(functions);
|
|
172
|
-
|
|
173
|
-
expect(toolsService.getFunction("func1")).toBeDefined();
|
|
174
|
-
expect(toolsService.getFunction("func2")).toBeDefined();
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
it("should set multiple functions by names and functions arrays", () => {
|
|
178
|
-
const func1 = jest.fn();
|
|
179
|
-
const func2 = jest.fn();
|
|
180
|
-
|
|
181
|
-
toolsService.setFunctions(["test1", "test2"], [func1, func2]);
|
|
182
|
-
|
|
183
|
-
expect(toolsService.getFunction("test1")).toBeDefined();
|
|
184
|
-
expect(toolsService.getFunction("test2")).toBeDefined();
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
it("should define tools and functions together", () => {
|
|
188
|
-
const mockTool: Tool = {
|
|
189
|
-
type: "function",
|
|
190
|
-
function: {
|
|
191
|
-
name: "combinedTool",
|
|
192
|
-
parameters: {
|
|
193
|
-
type: "object",
|
|
194
|
-
properties: {},
|
|
195
|
-
required: [],
|
|
196
|
-
},
|
|
197
|
-
},
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
const mockFunction = jest.fn();
|
|
201
|
-
|
|
202
|
-
toolsService.defineTools([mockTool], { combinedTool: mockFunction });
|
|
203
|
-
|
|
204
|
-
expect(toolsService.getTool("combinedTool")).toBe(mockTool);
|
|
205
|
-
expect(toolsService.getFunction("combinedTool")).toBeDefined();
|
|
206
|
-
});
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
describe("copyToolsFrom", () => {
|
|
210
|
-
it("should copy tools and functions from another ToolsService", () => {
|
|
211
|
-
const sourceService = new ToolsService();
|
|
212
|
-
const mockTool: Tool = {
|
|
213
|
-
type: "function",
|
|
214
|
-
function: {
|
|
215
|
-
name: "sourceTool",
|
|
216
|
-
parameters: {
|
|
217
|
-
type: "object",
|
|
218
|
-
properties: {},
|
|
219
|
-
required: [],
|
|
220
|
-
},
|
|
221
|
-
},
|
|
222
|
-
};
|
|
223
|
-
const mockFunction = jest.fn();
|
|
224
|
-
|
|
225
|
-
sourceService.addTool(mockTool);
|
|
226
|
-
sourceService.setFunction("sourceTool", mockFunction);
|
|
227
|
-
|
|
228
|
-
toolsService.copyToolsFrom(["sourceTool"], sourceService);
|
|
229
|
-
|
|
230
|
-
expect(toolsService.getTool("sourceTool")).toEqual(mockTool);
|
|
231
|
-
expect(toolsService.getFunction("sourceTool")).toBeDefined();
|
|
232
|
-
});
|
|
233
|
-
});
|
|
234
|
-
describe("callTool", () => {
|
|
235
|
-
const mockTool: Tool = {
|
|
236
|
-
type: "function",
|
|
237
|
-
function: {
|
|
238
|
-
name: "testTool",
|
|
239
|
-
description: "A test tool",
|
|
240
|
-
parameters: {
|
|
241
|
-
type: "object",
|
|
242
|
-
properties: {
|
|
243
|
-
input: { type: "string", description: "Test input" },
|
|
244
|
-
optional: { type: "string", description: "Optional input" },
|
|
245
|
-
},
|
|
246
|
-
required: ["input"],
|
|
247
|
-
},
|
|
248
|
-
},
|
|
249
|
-
};
|
|
250
|
-
|
|
251
|
-
const mockToolCall: ToolCall = {
|
|
252
|
-
id: "call_123",
|
|
253
|
-
type: "function",
|
|
254
|
-
function: {
|
|
255
|
-
name: "testTool",
|
|
256
|
-
arguments: JSON.stringify({ input: "test value" }),
|
|
257
|
-
},
|
|
258
|
-
};
|
|
259
|
-
|
|
260
|
-
beforeEach(() => {
|
|
261
|
-
toolsService.addTool(mockTool);
|
|
262
|
-
jest.clearAllMocks();
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
it("should successfully call a tool with correct arguments", async () => {
|
|
266
|
-
const mockFunction = jest.fn().mockResolvedValue("success result");
|
|
267
|
-
toolsService.setFunction("testTool", mockFunction);
|
|
268
|
-
|
|
269
|
-
const result = await toolsService.callTool(mockToolCall);
|
|
270
|
-
|
|
271
|
-
// By default (no `usesContext`), tools do NOT receive `_ctx`.
|
|
272
|
-
expect(mockFunction).toHaveBeenCalledWith(
|
|
273
|
-
expect.objectContaining({ input: "test value" })
|
|
274
|
-
);
|
|
275
|
-
expect(mockFunction.mock.calls[0][0]._ctx).toBeUndefined();
|
|
276
|
-
expect(result.toolMessages).toHaveLength(1);
|
|
277
|
-
expect(result.toolMessages[0]).toEqual({
|
|
278
|
-
tool_call_id: "call_123",
|
|
279
|
-
role: "tool",
|
|
280
|
-
name: "testTool",
|
|
281
|
-
content: "success result",
|
|
282
|
-
});
|
|
283
|
-
expect(result.functionResp).toBe("success result");
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
it("should handle positional arguments", async () => {
|
|
287
|
-
const positionalTool: Tool = {
|
|
288
|
-
type: "function",
|
|
289
|
-
function: {
|
|
290
|
-
name: "positionalTool",
|
|
291
|
-
parameters: {
|
|
292
|
-
type: "object",
|
|
293
|
-
positional: true,
|
|
294
|
-
properties: {
|
|
295
|
-
arg1: { type: "string" },
|
|
296
|
-
arg2: { type: "number" },
|
|
297
|
-
},
|
|
298
|
-
required: ["arg1", "arg2"],
|
|
299
|
-
},
|
|
300
|
-
},
|
|
301
|
-
};
|
|
302
|
-
|
|
303
|
-
const positionalCall: ToolCall = {
|
|
304
|
-
id: "call_456",
|
|
305
|
-
type: "function",
|
|
306
|
-
function: {
|
|
307
|
-
name: "positionalTool",
|
|
308
|
-
arguments: JSON.stringify({ arg1: "hello", arg2: 42 }),
|
|
309
|
-
},
|
|
310
|
-
};
|
|
311
|
-
|
|
312
|
-
const mockFunction = jest.fn().mockResolvedValue("positional result");
|
|
313
|
-
|
|
314
|
-
toolsService.addTool(positionalTool);
|
|
315
|
-
toolsService.setFunction("positionalTool", mockFunction);
|
|
316
|
-
|
|
317
|
-
await toolsService.callTool(positionalCall);
|
|
318
|
-
|
|
319
|
-
// By default (no `usesContext`), positional tools receive ONLY their
|
|
320
|
-
// declared positional args — no trailing `_ctx`.
|
|
321
|
-
expect(mockFunction).toHaveBeenCalledWith("hello", 42);
|
|
322
|
-
});
|
|
323
|
-
|
|
324
|
-
it("should handle tool not enabled error", async () => {
|
|
325
|
-
const mockFunction = jest.fn();
|
|
326
|
-
toolsService.setFunction("testTool", mockFunction);
|
|
327
|
-
|
|
328
|
-
const result = await toolsService.callTool(mockToolCall, ["otherTool"]);
|
|
329
|
-
|
|
330
|
-
expect(mockFunction).not.toHaveBeenCalled();
|
|
331
|
-
expect(result.toolMessages[0].name).toBe("error");
|
|
332
|
-
expect(result.toolMessages[0].content).toContain("not enabled");
|
|
333
|
-
expect(result.functionResp).toBeUndefined();
|
|
334
|
-
});
|
|
335
|
-
|
|
336
|
-
it("should handle tool definition not found", async () => {
|
|
337
|
-
const unknownToolCall: ToolCall = {
|
|
338
|
-
id: "call_unknown",
|
|
339
|
-
type: "function",
|
|
340
|
-
function: {
|
|
341
|
-
name: "unknownTool",
|
|
342
|
-
arguments: "{}",
|
|
343
|
-
},
|
|
344
|
-
};
|
|
345
|
-
|
|
346
|
-
const result = await toolsService.callTool(unknownToolCall);
|
|
347
|
-
|
|
348
|
-
expect(result.toolMessages[0].name).toBe("error");
|
|
349
|
-
expect(result.toolMessages[0].content).toContain("not enabled");
|
|
350
|
-
});
|
|
351
|
-
|
|
352
|
-
it("should handle function implementation not found", async () => {
|
|
353
|
-
// Tool is defined but no function implementation
|
|
354
|
-
const result = await toolsService.callTool(mockToolCall);
|
|
355
|
-
|
|
356
|
-
expect(result.toolMessages[0].name).toBe("error");
|
|
357
|
-
expect(result.toolMessages[0].content).toContain("not found");
|
|
358
|
-
});
|
|
359
|
-
|
|
360
|
-
it("should handle function execution errors", async () => {
|
|
361
|
-
const mockFunction = jest
|
|
362
|
-
.fn()
|
|
363
|
-
.mockRejectedValue(new Error("Function failed"));
|
|
364
|
-
toolsService.setFunction("testTool", mockFunction);
|
|
365
|
-
|
|
366
|
-
const result = await toolsService.callTool(mockToolCall);
|
|
367
|
-
|
|
368
|
-
expect(result.toolMessages[0].name).toBe("error");
|
|
369
|
-
expect(result.toolMessages[0].content).toContain(
|
|
370
|
-
"ERROR: Function failed"
|
|
371
|
-
);
|
|
372
|
-
expect(result.functionResp).toBeUndefined();
|
|
373
|
-
});
|
|
374
|
-
|
|
375
|
-
it("should handle object responses by converting to JSON", async () => {
|
|
376
|
-
const mockFunction = jest
|
|
377
|
-
.fn()
|
|
378
|
-
.mockResolvedValue({ key: "value", nested: { data: 123 } });
|
|
379
|
-
toolsService.setFunction("testTool", mockFunction);
|
|
380
|
-
|
|
381
|
-
const result = await toolsService.callTool(mockToolCall);
|
|
382
|
-
|
|
383
|
-
expect(result.toolMessages[0].content).toBe(
|
|
384
|
-
JSON.stringify({ key: "value", nested: { data: 123 } }, null, 2)
|
|
385
|
-
);
|
|
386
|
-
});
|
|
387
|
-
|
|
388
|
-
it("should handle multi_tool_use.parallel special case", async () => {
|
|
389
|
-
const parallelTool: Tool = {
|
|
390
|
-
type: "function",
|
|
391
|
-
function: {
|
|
392
|
-
name: "multi_tool_use.parallel",
|
|
393
|
-
parameters: {
|
|
394
|
-
type: "object",
|
|
395
|
-
properties: {},
|
|
396
|
-
required: [],
|
|
397
|
-
},
|
|
398
|
-
},
|
|
399
|
-
};
|
|
400
|
-
|
|
401
|
-
const parallelCall: ToolCall = {
|
|
402
|
-
id: "call_parallel",
|
|
403
|
-
type: "function",
|
|
404
|
-
function: {
|
|
405
|
-
name: "multi_tool_use.parallel",
|
|
406
|
-
arguments: JSON.stringify([
|
|
407
|
-
{ recipient_name: "tool1.action", parameters: {} },
|
|
408
|
-
{ recipient_name: "tool2.action", parameters: {} },
|
|
409
|
-
]),
|
|
410
|
-
},
|
|
411
|
-
};
|
|
412
|
-
|
|
413
|
-
const mockFunction = jest.fn().mockResolvedValue(["result1", "result2"]);
|
|
414
|
-
|
|
415
|
-
toolsService.addTool(parallelTool);
|
|
416
|
-
toolsService.setFunction("multi_tool_use.parallel", mockFunction);
|
|
417
|
-
|
|
418
|
-
const result = await toolsService.callTool(parallelCall);
|
|
419
|
-
|
|
420
|
-
expect(result.toolMessages).toHaveLength(2);
|
|
421
|
-
expect(result.toolMessages[0].tool_call_id).toBe("call_parallel_0");
|
|
422
|
-
expect(result.toolMessages[1].tool_call_id).toBe("call_parallel_1");
|
|
423
|
-
expect(result.toolMessages[0].name).toBe("action");
|
|
424
|
-
expect(result.toolMessages[1].name).toBe("action");
|
|
425
|
-
});
|
|
426
|
-
|
|
427
|
-
it("should handle string arguments that need parsing", async () => {
|
|
428
|
-
const toolCallWithStringArgs: ToolCall = {
|
|
429
|
-
id: "call_string",
|
|
430
|
-
type: "function",
|
|
431
|
-
function: {
|
|
432
|
-
name: "testTool",
|
|
433
|
-
arguments: '{"input": "escaped\\nstring"}',
|
|
434
|
-
},
|
|
435
|
-
};
|
|
436
|
-
|
|
437
|
-
const mockFunction = jest.fn().mockResolvedValue("success");
|
|
438
|
-
toolsService.setFunction("testTool", mockFunction);
|
|
439
|
-
|
|
440
|
-
await toolsService.callTool(toolCallWithStringArgs);
|
|
441
|
-
|
|
442
|
-
expect(mockFunction).toHaveBeenCalledWith(
|
|
443
|
-
expect.objectContaining({ input: "escaped\nstring" })
|
|
444
|
-
);
|
|
445
|
-
// testTool does not opt into context, so no `_ctx` is injected.
|
|
446
|
-
expect(mockFunction.mock.calls[0][0]._ctx).toBeUndefined();
|
|
447
|
-
});
|
|
448
|
-
});
|
|
449
|
-
describe("Tool Override System", () => {
|
|
450
|
-
const mockTool: Tool = {
|
|
451
|
-
type: "function",
|
|
452
|
-
function: {
|
|
453
|
-
name: "overridableTool",
|
|
454
|
-
description: "A tool that can be overridden",
|
|
455
|
-
parameters: {
|
|
456
|
-
type: "object",
|
|
457
|
-
properties: {
|
|
458
|
-
input: { type: "string" },
|
|
459
|
-
},
|
|
460
|
-
required: ["input"],
|
|
461
|
-
},
|
|
462
|
-
},
|
|
463
|
-
};
|
|
464
|
-
|
|
465
|
-
beforeEach(() => {
|
|
466
|
-
toolsService.addTool(mockTool);
|
|
467
|
-
jest.clearAllMocks();
|
|
468
|
-
});
|
|
469
|
-
|
|
470
|
-
it("should register override with string pattern", () => {
|
|
471
|
-
const overrideFunction = jest.fn().mockResolvedValue("override result");
|
|
472
|
-
|
|
473
|
-
toolsService.registerOverride("overridableTool", overrideFunction);
|
|
474
|
-
|
|
475
|
-
expect(() => toolsService.getFunction("overridableTool")).not.toThrow();
|
|
476
|
-
});
|
|
477
|
-
|
|
478
|
-
it("should register override with regex pattern", () => {
|
|
479
|
-
const overrideFunction = jest.fn().mockResolvedValue("regex override");
|
|
480
|
-
const pattern = /^overridable/;
|
|
481
|
-
|
|
482
|
-
toolsService.registerOverride(pattern, overrideFunction);
|
|
483
|
-
|
|
484
|
-
expect(() => toolsService.getFunction("overridableTool")).not.toThrow();
|
|
485
|
-
});
|
|
486
|
-
|
|
487
|
-
it("should execute override function instead of original", async () => {
|
|
488
|
-
const originalFunction = jest.fn().mockResolvedValue("original result");
|
|
489
|
-
const overrideFunction = jest.fn().mockResolvedValue("override result");
|
|
490
|
-
|
|
491
|
-
toolsService.setFunction("overridableTool", originalFunction);
|
|
492
|
-
toolsService.registerOverride("overridableTool", overrideFunction);
|
|
493
|
-
|
|
494
|
-
const toolCall: ToolCall = {
|
|
495
|
-
id: "call_override",
|
|
496
|
-
type: "function",
|
|
497
|
-
function: {
|
|
498
|
-
name: "overridableTool",
|
|
499
|
-
arguments: JSON.stringify({ input: "test" }),
|
|
500
|
-
},
|
|
501
|
-
};
|
|
502
|
-
|
|
503
|
-
const result = await toolsService.callTool(toolCall);
|
|
504
|
-
|
|
505
|
-
// overridableTool does not opt into context, so args have no `_ctx`;
|
|
506
|
-
// the override receives them in an array.
|
|
507
|
-
expect(overrideFunction).toHaveBeenCalledWith(
|
|
508
|
-
[expect.objectContaining({ input: "test" })],
|
|
509
|
-
expect.any(Object)
|
|
510
|
-
);
|
|
511
|
-
expect(originalFunction).not.toHaveBeenCalled();
|
|
512
|
-
expect(result.functionResp).toBe("override result");
|
|
513
|
-
});
|
|
514
|
-
|
|
515
|
-
it("should handle override priority ordering", async () => {
|
|
516
|
-
const override1 = jest.fn().mockResolvedValue("override1");
|
|
517
|
-
const override2 = jest.fn().mockResolvedValue("override2");
|
|
518
|
-
|
|
519
|
-
// Register with different priorities
|
|
520
|
-
toolsService.registerOverride("overridableTool", override1, 1);
|
|
521
|
-
toolsService.registerOverride("overridableTool", override2, 2);
|
|
522
|
-
|
|
523
|
-
// Higher priority should be used
|
|
524
|
-
const func = toolsService.getFunction("overridableTool");
|
|
525
|
-
// Function should be bound version of override2, test by calling it
|
|
526
|
-
expect(await func({})).toBe("override2");
|
|
527
|
-
});
|
|
528
|
-
|
|
529
|
-
it("should handle pattern matching with wildcards", async () => {
|
|
530
|
-
const overrideFunction = jest.fn().mockResolvedValue("wildcard override");
|
|
531
|
-
|
|
532
|
-
toolsService.registerOverride("overrid*Tool", overrideFunction);
|
|
533
|
-
|
|
534
|
-
const func = toolsService.getFunction("overridableTool");
|
|
535
|
-
// Function should be bound version of override, test by calling it
|
|
536
|
-
expect(await func({})).toBe("wildcard override");
|
|
537
|
-
});
|
|
538
|
-
|
|
539
|
-
it("should remove overrides", async () => {
|
|
540
|
-
const originalFunction = jest.fn().mockResolvedValue("original");
|
|
541
|
-
const overrideFunction = jest.fn().mockResolvedValue("override");
|
|
542
|
-
|
|
543
|
-
toolsService.setFunction("overridableTool", originalFunction);
|
|
544
|
-
toolsService.registerOverride("overridableTool", overrideFunction);
|
|
545
|
-
|
|
546
|
-
// Override should be active
|
|
547
|
-
const overriddenFunc = toolsService.getFunction("overridableTool");
|
|
548
|
-
expect(await overriddenFunc({})).toBe("override");
|
|
549
|
-
|
|
550
|
-
toolsService.removeOverride("overridableTool");
|
|
551
|
-
|
|
552
|
-
// Should return to original
|
|
553
|
-
const restoredFunc = toolsService.getFunction("overridableTool");
|
|
554
|
-
expect(await restoredFunc({})).toBe("original");
|
|
555
|
-
});
|
|
556
|
-
|
|
557
|
-
it("should preserve original functions when override is registered", async () => {
|
|
558
|
-
const originalFunction = jest.fn().mockResolvedValue("original");
|
|
559
|
-
const overrideFunction = jest.fn().mockResolvedValue("override");
|
|
560
|
-
|
|
561
|
-
toolsService.setFunction("overridableTool", originalFunction);
|
|
562
|
-
toolsService.registerOverride("overridableTool", overrideFunction);
|
|
563
|
-
|
|
564
|
-
const originalStored =
|
|
565
|
-
toolsService.getOriginalFunction("overridableTool");
|
|
566
|
-
// Original function should still be the same function (not bound)
|
|
567
|
-
expect(await originalStored!({})).toBe("original");
|
|
568
|
-
});
|
|
569
|
-
});
|
|
570
|
-
|
|
571
|
-
describe("Tool Wrapper System", () => {
|
|
572
|
-
const mockTool: Tool = {
|
|
573
|
-
type: "function",
|
|
574
|
-
function: {
|
|
575
|
-
name: "wrappableTool",
|
|
576
|
-
description: "A tool that can be wrapped",
|
|
577
|
-
parameters: {
|
|
578
|
-
type: "object",
|
|
579
|
-
properties: {
|
|
580
|
-
input: { type: "string" },
|
|
581
|
-
},
|
|
582
|
-
required: ["input"],
|
|
583
|
-
},
|
|
584
|
-
},
|
|
585
|
-
};
|
|
586
|
-
|
|
587
|
-
beforeEach(() => {
|
|
588
|
-
toolsService.addTool(mockTool);
|
|
589
|
-
jest.clearAllMocks();
|
|
590
|
-
});
|
|
591
|
-
|
|
592
|
-
it("should register wrapper with string pattern", () => {
|
|
593
|
-
const wrapperFunction = jest
|
|
594
|
-
.fn()
|
|
595
|
-
.mockImplementation((originalFn, args) => {
|
|
596
|
-
return originalFn(args);
|
|
597
|
-
});
|
|
598
|
-
|
|
599
|
-
toolsService.registerWrapper("wrappableTool", wrapperFunction);
|
|
600
|
-
|
|
601
|
-
expect(() => toolsService.getFunction("wrappableTool")).not.toThrow();
|
|
602
|
-
});
|
|
603
|
-
|
|
604
|
-
it("should register wrapper with regex pattern", () => {
|
|
605
|
-
const wrapperFunction = jest
|
|
606
|
-
.fn()
|
|
607
|
-
.mockImplementation((originalFn, args) => {
|
|
608
|
-
return originalFn(args);
|
|
609
|
-
});
|
|
610
|
-
const pattern = /^wrappable/;
|
|
611
|
-
|
|
612
|
-
toolsService.registerWrapper(pattern, wrapperFunction);
|
|
613
|
-
|
|
614
|
-
expect(() => toolsService.getFunction("wrappableTool")).not.toThrow();
|
|
615
|
-
});
|
|
616
|
-
|
|
617
|
-
it("should execute wrapper function with original function", async () => {
|
|
618
|
-
const originalFunction = jest.fn().mockResolvedValue("original result");
|
|
619
|
-
const wrapperFunction = jest
|
|
620
|
-
.fn()
|
|
621
|
-
.mockImplementation(async (originalFn, args, tool) => {
|
|
622
|
-
// args is now an array of arguments
|
|
623
|
-
const result = await originalFn(...args);
|
|
624
|
-
return `wrapped: ${result}`;
|
|
625
|
-
});
|
|
626
|
-
|
|
627
|
-
toolsService.setFunction("wrappableTool", originalFunction);
|
|
628
|
-
toolsService.registerWrapper("wrappableTool", wrapperFunction);
|
|
629
|
-
|
|
630
|
-
const toolCall: ToolCall = {
|
|
631
|
-
id: "call_wrapper",
|
|
632
|
-
type: "function",
|
|
633
|
-
function: {
|
|
634
|
-
name: "wrappableTool",
|
|
635
|
-
arguments: JSON.stringify({ input: "test" }),
|
|
636
|
-
},
|
|
637
|
-
};
|
|
638
|
-
|
|
639
|
-
const result = await toolsService.callTool(toolCall);
|
|
640
|
-
|
|
641
|
-
expect(wrapperFunction).toHaveBeenCalled();
|
|
642
|
-
expect(originalFunction).toHaveBeenCalledWith(
|
|
643
|
-
expect.objectContaining({ input: "test" })
|
|
644
|
-
);
|
|
645
|
-
expect(result.functionResp).toBe("wrapped: original result");
|
|
646
|
-
});
|
|
647
|
-
|
|
648
|
-
it("should handle wrapper priority ordering", () => {
|
|
649
|
-
const originalFunction = jest.fn().mockResolvedValue("original");
|
|
650
|
-
const wrapper1 = jest.fn().mockImplementation((fn, args) => fn(args));
|
|
651
|
-
const wrapper2 = jest.fn().mockImplementation((fn, args) => fn(args));
|
|
652
|
-
|
|
653
|
-
toolsService.setFunction("wrappableTool", originalFunction);
|
|
654
|
-
toolsService.registerWrapper("wrappableTool", wrapper1, 1);
|
|
655
|
-
toolsService.registerWrapper("wrappableTool", wrapper2, 2);
|
|
656
|
-
|
|
657
|
-
// Should use higher priority wrapper
|
|
658
|
-
const func = toolsService.getFunction("wrappableTool");
|
|
659
|
-
expect(func).not.toBe(originalFunction);
|
|
660
|
-
expect(func).not.toBe(wrapper1);
|
|
661
|
-
});
|
|
662
|
-
|
|
663
|
-
it("should support multiple wrapper chaining", async () => {
|
|
664
|
-
const originalFunction = jest.fn().mockResolvedValue("original");
|
|
665
|
-
|
|
666
|
-
const wrapper1 = jest
|
|
667
|
-
.fn()
|
|
668
|
-
.mockImplementation(async (originalFn, args) => {
|
|
669
|
-
const result = await originalFn(args);
|
|
670
|
-
return `wrapper1(${result})`;
|
|
671
|
-
});
|
|
672
|
-
|
|
673
|
-
const wrapper2 = jest
|
|
674
|
-
.fn()
|
|
675
|
-
.mockImplementation(async (originalFn, args) => {
|
|
676
|
-
const result = await originalFn(args);
|
|
677
|
-
return `wrapper2(${result})`;
|
|
678
|
-
});
|
|
679
|
-
|
|
680
|
-
toolsService.setFunction("wrappableTool", originalFunction);
|
|
681
|
-
toolsService.registerWrapper("wrappableTool", wrapper1, 1);
|
|
682
|
-
toolsService.registerWrapper("wrappableTool", wrapper2, 2);
|
|
683
|
-
|
|
684
|
-
const toolCall: ToolCall = {
|
|
685
|
-
id: "call_chained",
|
|
686
|
-
type: "function",
|
|
687
|
-
function: {
|
|
688
|
-
name: "wrappableTool",
|
|
689
|
-
arguments: JSON.stringify({ input: "test" }),
|
|
690
|
-
},
|
|
691
|
-
};
|
|
692
|
-
|
|
693
|
-
const result = await toolsService.callTool(toolCall);
|
|
694
|
-
|
|
695
|
-
expect(result.functionResp).toContain("wrapper1");
|
|
696
|
-
expect(result.functionResp).toContain("wrapper2");
|
|
697
|
-
expect(originalFunction).toHaveBeenCalled();
|
|
698
|
-
});
|
|
699
|
-
|
|
700
|
-
it("should remove wrappers", async () => {
|
|
701
|
-
const originalFunction = jest.fn().mockResolvedValue("original");
|
|
702
|
-
const wrapperFunction = jest
|
|
703
|
-
.fn()
|
|
704
|
-
.mockImplementation((fn, args) => fn(args));
|
|
705
|
-
|
|
706
|
-
toolsService.setFunction("wrappableTool", originalFunction);
|
|
707
|
-
toolsService.registerWrapper("wrappableTool", wrapperFunction);
|
|
708
|
-
|
|
709
|
-
// Wrapper should be active
|
|
710
|
-
expect(toolsService.getFunction("wrappableTool")).not.toBe(
|
|
711
|
-
originalFunction
|
|
712
|
-
);
|
|
713
|
-
|
|
714
|
-
toolsService.removeWrapper("wrappableTool");
|
|
715
|
-
|
|
716
|
-
// Should return to original
|
|
717
|
-
const restoredFunc = toolsService.getFunction("wrappableTool");
|
|
718
|
-
expect(await restoredFunc!({})).toBe("original");
|
|
719
|
-
});
|
|
720
|
-
});
|
|
721
|
-
describe("Pattern Matching", () => {
|
|
722
|
-
it("should match glob patterns with wildcards", async () => {
|
|
723
|
-
const originalFunction = jest.fn().mockResolvedValue("original");
|
|
724
|
-
const overrideFunction = jest.fn().mockResolvedValue("override");
|
|
725
|
-
|
|
726
|
-
toolsService.setFunction("testTool", originalFunction);
|
|
727
|
-
toolsService.setFunction("testHelper", originalFunction);
|
|
728
|
-
toolsService.setFunction("otherTool", originalFunction);
|
|
729
|
-
|
|
730
|
-
// Register override with glob pattern
|
|
731
|
-
toolsService.registerOverride("test*", overrideFunction);
|
|
732
|
-
|
|
733
|
-
// Should match tools starting with "test"
|
|
734
|
-
const testFunc = toolsService.getFunction("testTool");
|
|
735
|
-
const testHelperFunc = toolsService.getFunction("testHelper");
|
|
736
|
-
const otherFunc = toolsService.getFunction("otherTool");
|
|
737
|
-
expect(await testFunc!({})).toBe("override");
|
|
738
|
-
expect(await testHelperFunc!({})).toBe("override");
|
|
739
|
-
expect(await otherFunc!({})).toBe("original");
|
|
740
|
-
});
|
|
741
|
-
|
|
742
|
-
it("should match regex patterns", async () => {
|
|
743
|
-
const originalFunction = jest.fn().mockResolvedValue("original");
|
|
744
|
-
const overrideFunction = jest.fn().mockResolvedValue("override");
|
|
745
|
-
|
|
746
|
-
toolsService.setFunction("tool123", originalFunction);
|
|
747
|
-
toolsService.setFunction("tool456", originalFunction);
|
|
748
|
-
toolsService.setFunction("toolABC", originalFunction);
|
|
749
|
-
|
|
750
|
-
// Register override with regex pattern for tools ending with numbers
|
|
751
|
-
toolsService.registerOverride(/tool\d+$/, overrideFunction);
|
|
752
|
-
|
|
753
|
-
const tool123Func = toolsService.getFunction("tool123");
|
|
754
|
-
const tool456Func = toolsService.getFunction("tool456");
|
|
755
|
-
const toolABCFunc = toolsService.getFunction("toolABC");
|
|
756
|
-
expect(await tool123Func!({})).toBe("override");
|
|
757
|
-
expect(await tool456Func!({})).toBe("override");
|
|
758
|
-
expect(await toolABCFunc!({})).toBe("original");
|
|
759
|
-
});
|
|
760
|
-
|
|
761
|
-
it("should handle complex glob patterns", async () => {
|
|
762
|
-
const originalFunction = jest.fn().mockResolvedValue("original");
|
|
763
|
-
const overrideFunction = jest.fn().mockResolvedValue("override");
|
|
764
|
-
|
|
765
|
-
toolsService.setFunction("api_get_user", originalFunction);
|
|
766
|
-
toolsService.setFunction("api_post_user", originalFunction);
|
|
767
|
-
toolsService.setFunction("api_delete_user", originalFunction);
|
|
768
|
-
toolsService.setFunction("util_format", originalFunction);
|
|
769
|
-
|
|
770
|
-
// Match API tools with user operations
|
|
771
|
-
toolsService.registerOverride("api_*_user", overrideFunction);
|
|
772
|
-
|
|
773
|
-
const apiGetFunc = toolsService.getFunction("api_get_user");
|
|
774
|
-
const apiPostFunc = toolsService.getFunction("api_post_user");
|
|
775
|
-
const apiDeleteFunc = toolsService.getFunction("api_delete_user");
|
|
776
|
-
|
|
777
|
-
expect(await apiGetFunc!({})).toBe("override");
|
|
778
|
-
expect(await apiPostFunc!({})).toBe("override");
|
|
779
|
-
expect(await apiDeleteFunc!({})).toBe("override");
|
|
780
|
-
const utilFormatFunc = toolsService.getFunction("util_format");
|
|
781
|
-
expect(await utilFormatFunc!({})).toBe("original");
|
|
782
|
-
});
|
|
783
|
-
|
|
784
|
-
it("should test pattern matcher factory function directly", () => {
|
|
785
|
-
// Test string pattern matcher
|
|
786
|
-
const stringMatcher = createPatternMatcher("test*");
|
|
787
|
-
expect(stringMatcher.matches("testTool")).toBe(true);
|
|
788
|
-
expect(stringMatcher.matches("otherTool")).toBe(false);
|
|
789
|
-
|
|
790
|
-
// Test regex pattern matcher
|
|
791
|
-
const regexMatcher = createPatternMatcher(/^api_/);
|
|
792
|
-
expect(regexMatcher.matches("api_call")).toBe(true);
|
|
793
|
-
expect(regexMatcher.matches("util_call")).toBe(false);
|
|
794
|
-
});
|
|
795
|
-
});
|
|
796
|
-
|
|
797
|
-
describe("Error Handling and Edge Cases", () => {
|
|
798
|
-
it("should handle malformed tool call arguments", async () => {
|
|
799
|
-
const mockTool: Tool = {
|
|
800
|
-
type: "function",
|
|
801
|
-
function: {
|
|
802
|
-
name: "testTool",
|
|
803
|
-
parameters: { type: "object", properties: {}, required: [] },
|
|
804
|
-
},
|
|
805
|
-
};
|
|
806
|
-
|
|
807
|
-
const malformedCall: ToolCall = {
|
|
808
|
-
id: "call_malformed",
|
|
809
|
-
type: "function",
|
|
810
|
-
function: {
|
|
811
|
-
name: "testTool",
|
|
812
|
-
arguments: "invalid json {",
|
|
813
|
-
},
|
|
814
|
-
};
|
|
815
|
-
|
|
816
|
-
toolsService.addTool(mockTool);
|
|
817
|
-
toolsService.setFunction(
|
|
818
|
-
"testTool",
|
|
819
|
-
jest.fn().mockResolvedValue("result")
|
|
820
|
-
);
|
|
821
|
-
|
|
822
|
-
const result = await toolsService.callTool(malformedCall);
|
|
823
|
-
|
|
824
|
-
expect(result.toolMessages[0].name).toBe("error");
|
|
825
|
-
expect(result.toolMessages[0].content).toContain("JSON");
|
|
826
|
-
});
|
|
827
|
-
|
|
828
|
-
it("should handle tools with no parameters", async () => {
|
|
829
|
-
const noParamTool: Tool = {
|
|
830
|
-
type: "function",
|
|
831
|
-
function: {
|
|
832
|
-
name: "noParamTool",
|
|
833
|
-
description: "Tool with no parameters",
|
|
834
|
-
parameters: {
|
|
835
|
-
type: "object",
|
|
836
|
-
properties: {},
|
|
837
|
-
required: [],
|
|
838
|
-
},
|
|
839
|
-
},
|
|
840
|
-
};
|
|
841
|
-
|
|
842
|
-
const noParamCall: ToolCall = {
|
|
843
|
-
id: "call_no_param",
|
|
844
|
-
type: "function",
|
|
845
|
-
function: {
|
|
846
|
-
name: "noParamTool",
|
|
847
|
-
arguments: "{}",
|
|
848
|
-
},
|
|
849
|
-
};
|
|
850
|
-
|
|
851
|
-
const mockFunction = jest.fn().mockResolvedValue("no param result");
|
|
852
|
-
|
|
853
|
-
toolsService.addTool(noParamTool);
|
|
854
|
-
toolsService.setFunction("noParamTool", mockFunction);
|
|
855
|
-
|
|
856
|
-
const result = await toolsService.callTool(noParamCall);
|
|
857
|
-
|
|
858
|
-
expect(mockFunction).toHaveBeenCalledWith(expect.any(Object));
|
|
859
|
-
// noParamTool does not opt into context, so no `_ctx` is injected.
|
|
860
|
-
expect(mockFunction.mock.calls[0][0]._ctx).toBeUndefined();
|
|
861
|
-
expect(result.functionResp).toBe("no param result");
|
|
862
|
-
});
|
|
863
|
-
|
|
864
|
-
it("should handle tools with complex nested parameter structures", async () => {
|
|
865
|
-
const complexTool: Tool = {
|
|
866
|
-
type: "function",
|
|
867
|
-
function: {
|
|
868
|
-
name: "complexTool",
|
|
869
|
-
parameters: {
|
|
870
|
-
type: "object",
|
|
871
|
-
properties: {
|
|
872
|
-
config: {
|
|
873
|
-
type: "object",
|
|
874
|
-
properties: {
|
|
875
|
-
settings: {
|
|
876
|
-
type: "array",
|
|
877
|
-
items: {
|
|
878
|
-
type: "object",
|
|
879
|
-
properties: {
|
|
880
|
-
key: { type: "string" },
|
|
881
|
-
value: { type: "number" },
|
|
882
|
-
},
|
|
883
|
-
},
|
|
884
|
-
},
|
|
885
|
-
},
|
|
886
|
-
},
|
|
887
|
-
},
|
|
888
|
-
required: ["config"],
|
|
889
|
-
},
|
|
890
|
-
},
|
|
891
|
-
};
|
|
892
|
-
|
|
893
|
-
const complexCall: ToolCall = {
|
|
894
|
-
id: "call_complex",
|
|
895
|
-
type: "function",
|
|
896
|
-
function: {
|
|
897
|
-
name: "complexTool",
|
|
898
|
-
arguments: JSON.stringify({
|
|
899
|
-
config: {
|
|
900
|
-
settings: [
|
|
901
|
-
{ key: "timeout", value: 5000 },
|
|
902
|
-
{ key: "retries", value: 3 },
|
|
903
|
-
],
|
|
904
|
-
},
|
|
905
|
-
}),
|
|
906
|
-
},
|
|
907
|
-
};
|
|
908
|
-
|
|
909
|
-
const mockFunction = jest.fn().mockResolvedValue("complex result");
|
|
910
|
-
|
|
911
|
-
toolsService.addTool(complexTool);
|
|
912
|
-
toolsService.setFunction("complexTool", mockFunction);
|
|
913
|
-
|
|
914
|
-
const result = await toolsService.callTool(complexCall);
|
|
915
|
-
|
|
916
|
-
expect(mockFunction).toHaveBeenCalledWith(
|
|
917
|
-
expect.objectContaining({
|
|
918
|
-
config: {
|
|
919
|
-
settings: [
|
|
920
|
-
{ key: "timeout", value: 5000 },
|
|
921
|
-
{ key: "retries", value: 3 },
|
|
922
|
-
],
|
|
923
|
-
},
|
|
924
|
-
})
|
|
925
|
-
);
|
|
926
|
-
expect(result.functionResp).toBe("complex result");
|
|
927
|
-
});
|
|
928
|
-
|
|
929
|
-
it("should handle concurrent tool calls", async () => {
|
|
930
|
-
const concurrentTool: Tool = {
|
|
931
|
-
type: "function",
|
|
932
|
-
function: {
|
|
933
|
-
name: "concurrentTool",
|
|
934
|
-
parameters: {
|
|
935
|
-
type: "object",
|
|
936
|
-
properties: {
|
|
937
|
-
delay: { type: "number" },
|
|
938
|
-
},
|
|
939
|
-
required: ["delay"],
|
|
940
|
-
},
|
|
941
|
-
},
|
|
942
|
-
};
|
|
943
|
-
|
|
944
|
-
const mockFunction = jest.fn().mockImplementation(async ({ delay }) => {
|
|
945
|
-
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
946
|
-
return `completed after ${delay}ms`;
|
|
947
|
-
});
|
|
948
|
-
|
|
949
|
-
toolsService.addTool(concurrentTool);
|
|
950
|
-
toolsService.setFunction("concurrentTool", mockFunction);
|
|
951
|
-
|
|
952
|
-
const call1: ToolCall = {
|
|
953
|
-
id: "call_1",
|
|
954
|
-
type: "function",
|
|
955
|
-
function: {
|
|
956
|
-
name: "concurrentTool",
|
|
957
|
-
arguments: JSON.stringify({ delay: 100 }),
|
|
958
|
-
},
|
|
959
|
-
};
|
|
960
|
-
|
|
961
|
-
const call2: ToolCall = {
|
|
962
|
-
id: "call_2",
|
|
963
|
-
type: "function",
|
|
964
|
-
function: {
|
|
965
|
-
name: "concurrentTool",
|
|
966
|
-
arguments: JSON.stringify({ delay: 50 }),
|
|
967
|
-
},
|
|
968
|
-
};
|
|
969
|
-
|
|
970
|
-
const [result1, result2] = await Promise.all([
|
|
971
|
-
toolsService.callTool(call1),
|
|
972
|
-
toolsService.callTool(call2),
|
|
973
|
-
]);
|
|
974
|
-
|
|
975
|
-
expect(result1.functionResp).toBe("completed after 100ms");
|
|
976
|
-
expect(result2.functionResp).toBe("completed after 50ms");
|
|
977
|
-
expect(mockFunction).toHaveBeenCalledTimes(2);
|
|
978
|
-
});
|
|
979
|
-
|
|
980
|
-
it("should handle undefined and null function responses", async () => {
|
|
981
|
-
// Test undefined response with separate tool
|
|
982
|
-
const undefinedTool: Tool = {
|
|
983
|
-
type: "function",
|
|
984
|
-
function: {
|
|
985
|
-
name: "undefinedTool",
|
|
986
|
-
parameters: { type: "object", properties: {}, required: [] },
|
|
987
|
-
},
|
|
988
|
-
};
|
|
989
|
-
|
|
990
|
-
const undefinedCall: ToolCall = {
|
|
991
|
-
id: "call_undefined",
|
|
992
|
-
type: "function",
|
|
993
|
-
function: {
|
|
994
|
-
name: "undefinedTool",
|
|
995
|
-
arguments: "{}",
|
|
996
|
-
},
|
|
997
|
-
};
|
|
998
|
-
|
|
999
|
-
toolsService.addTool(undefinedTool);
|
|
1000
|
-
toolsService.setFunction(
|
|
1001
|
-
"undefinedTool",
|
|
1002
|
-
jest.fn().mockResolvedValue(undefined)
|
|
1003
|
-
);
|
|
1004
|
-
let result = await toolsService.callTool(undefinedCall);
|
|
1005
|
-
expect(result.toolMessages[0].content).toBe("undefined");
|
|
1006
|
-
|
|
1007
|
-
// Test null response with separate tool
|
|
1008
|
-
const nullTool: Tool = {
|
|
1009
|
-
type: "function",
|
|
1010
|
-
function: {
|
|
1011
|
-
name: "nullTool",
|
|
1012
|
-
parameters: { type: "object", properties: {}, required: [] },
|
|
1013
|
-
},
|
|
1014
|
-
};
|
|
1015
|
-
|
|
1016
|
-
const nullCall: ToolCall = {
|
|
1017
|
-
id: "call_null",
|
|
1018
|
-
type: "function",
|
|
1019
|
-
function: {
|
|
1020
|
-
name: "nullTool",
|
|
1021
|
-
arguments: "{}",
|
|
1022
|
-
},
|
|
1023
|
-
};
|
|
1024
|
-
|
|
1025
|
-
toolsService.addTool(nullTool);
|
|
1026
|
-
toolsService.setFunction("nullTool", jest.fn().mockResolvedValue(null));
|
|
1027
|
-
result = await toolsService.callTool(nullCall);
|
|
1028
|
-
expect(result.toolMessages[0].content).toBe("null");
|
|
1029
|
-
});
|
|
1030
|
-
});
|
|
1031
|
-
|
|
1032
|
-
describe("Integration Tests", () => {
|
|
1033
|
-
it("should handle complete workflow with override and wrapper", async () => {
|
|
1034
|
-
const baseTool: Tool = {
|
|
1035
|
-
type: "function",
|
|
1036
|
-
function: {
|
|
1037
|
-
name: "workflowTool",
|
|
1038
|
-
parameters: {
|
|
1039
|
-
type: "object",
|
|
1040
|
-
properties: {
|
|
1041
|
-
input: { type: "string" },
|
|
1042
|
-
},
|
|
1043
|
-
required: ["input"],
|
|
1044
|
-
},
|
|
1045
|
-
},
|
|
1046
|
-
};
|
|
1047
|
-
|
|
1048
|
-
const originalFunction = jest.fn().mockResolvedValue("original");
|
|
1049
|
-
const wrapperFunction = jest
|
|
1050
|
-
.fn()
|
|
1051
|
-
.mockImplementation(async (originalFn, args) => {
|
|
1052
|
-
const result = await originalFn(args);
|
|
1053
|
-
return `wrapped: ${result}`;
|
|
1054
|
-
});
|
|
1055
|
-
const overrideFunction = jest.fn().mockResolvedValue("override");
|
|
1056
|
-
|
|
1057
|
-
toolsService.addTool(baseTool);
|
|
1058
|
-
toolsService.setFunction("workflowTool", originalFunction);
|
|
1059
|
-
toolsService.registerWrapper("workflowTool", wrapperFunction);
|
|
1060
|
-
toolsService.registerOverride("workflowTool", overrideFunction);
|
|
1061
|
-
|
|
1062
|
-
const toolCall: ToolCall = {
|
|
1063
|
-
id: "call_workflow",
|
|
1064
|
-
type: "function",
|
|
1065
|
-
function: {
|
|
1066
|
-
name: "workflowTool",
|
|
1067
|
-
arguments: JSON.stringify({ input: "test" }),
|
|
1068
|
-
},
|
|
1069
|
-
};
|
|
1070
|
-
|
|
1071
|
-
const result = await toolsService.callTool(toolCall);
|
|
1072
|
-
|
|
1073
|
-
// Override should take precedence over wrapper
|
|
1074
|
-
expect(overrideFunction).toHaveBeenCalled();
|
|
1075
|
-
expect(wrapperFunction).not.toHaveBeenCalled();
|
|
1076
|
-
expect(originalFunction).not.toHaveBeenCalled();
|
|
1077
|
-
expect(result.functionResp).toBe("override");
|
|
1078
|
-
});
|
|
1079
|
-
|
|
1080
|
-
it("should maintain tool state across multiple operations", () => {
|
|
1081
|
-
const tools: Tool[] = [
|
|
1082
|
-
{
|
|
1083
|
-
type: "function",
|
|
1084
|
-
function: {
|
|
1085
|
-
name: "tool1",
|
|
1086
|
-
parameters: { type: "object", properties: {}, required: [] },
|
|
1087
|
-
},
|
|
1088
|
-
},
|
|
1089
|
-
{
|
|
1090
|
-
type: "function",
|
|
1091
|
-
function: {
|
|
1092
|
-
name: "tool2",
|
|
1093
|
-
parameters: { type: "object", properties: {}, required: [] },
|
|
1094
|
-
},
|
|
1095
|
-
},
|
|
1096
|
-
];
|
|
1097
|
-
|
|
1098
|
-
toolsService.addTools(tools);
|
|
1099
|
-
expect(toolsService.getToolsByNames(["tool1", "tool2"])).toHaveLength(2);
|
|
1100
|
-
|
|
1101
|
-
toolsService.setFunction("tool1", jest.fn());
|
|
1102
|
-
toolsService.setFunction("tool2", jest.fn());
|
|
1103
|
-
|
|
1104
|
-
expect(toolsService.getFunction("tool1")).toBeDefined();
|
|
1105
|
-
expect(toolsService.getFunction("tool2")).toBeDefined();
|
|
1106
|
-
|
|
1107
|
-
// Copy to new service
|
|
1108
|
-
const newService = new ToolsService();
|
|
1109
|
-
newService.copyToolsFrom(["tool1", "tool2"], toolsService);
|
|
1110
|
-
|
|
1111
|
-
expect(newService.getToolsByNames(["tool1", "tool2"])).toHaveLength(2);
|
|
1112
|
-
});
|
|
1113
|
-
|
|
1114
|
-
describe("Function Binding", () => {
|
|
1115
|
-
let toolsService: ToolsService;
|
|
1116
|
-
let mockContext: ToolContext;
|
|
1117
|
-
|
|
1118
|
-
beforeEach(() => {
|
|
1119
|
-
mockContext = {
|
|
1120
|
-
metadata: { testKey: "testValue" },
|
|
1121
|
-
};
|
|
1122
|
-
toolsService = new ToolsService(mockContext);
|
|
1123
|
-
});
|
|
1124
|
-
|
|
1125
|
-
describe("this binding in tool functions", () => {
|
|
1126
|
-
it("should bind functions so 'this' refers to ToolsService instance", async () => {
|
|
1127
|
-
const testTool: Tool = {
|
|
1128
|
-
type: "function",
|
|
1129
|
-
function: {
|
|
1130
|
-
name: "testThisBinding",
|
|
1131
|
-
description: "Test function that accesses this",
|
|
1132
|
-
parameters: {
|
|
1133
|
-
type: "object",
|
|
1134
|
-
properties: {
|
|
1135
|
-
message: { type: "string" },
|
|
1136
|
-
},
|
|
1137
|
-
},
|
|
1138
|
-
},
|
|
1139
|
-
};
|
|
1140
|
-
|
|
1141
|
-
function testFunction(this: ToolsService, args: { message: string }) {
|
|
1142
|
-
// This function should have 'this' bound to the ToolsService instance
|
|
1143
|
-
if (!this || typeof this.getContext !== "function") {
|
|
1144
|
-
throw new Error("'this' is not bound to ToolsService instance");
|
|
1145
|
-
}
|
|
1146
|
-
const context = this.getContext();
|
|
1147
|
-
return {
|
|
1148
|
-
message: args.message,
|
|
1149
|
-
contextMetadata: context.metadata,
|
|
1150
|
-
hasThisBinding: true,
|
|
1151
|
-
};
|
|
1152
|
-
}
|
|
1153
|
-
|
|
1154
|
-
toolsService.addTool(testTool);
|
|
1155
|
-
toolsService.setFunction("testThisBinding", testFunction);
|
|
1156
|
-
|
|
1157
|
-
const toolCall: ToolCall = {
|
|
1158
|
-
id: "test-call-1",
|
|
1159
|
-
type: "function",
|
|
1160
|
-
function: {
|
|
1161
|
-
name: "testThisBinding",
|
|
1162
|
-
arguments: JSON.stringify({ message: "test" }),
|
|
1163
|
-
},
|
|
1164
|
-
};
|
|
1165
|
-
|
|
1166
|
-
const result = await toolsService.callTool(toolCall);
|
|
1167
|
-
|
|
1168
|
-
expect(result.functionResp.hasThisBinding).toBe(true);
|
|
1169
|
-
expect(result.functionResp.contextMetadata).toEqual({
|
|
1170
|
-
testKey: "testValue",
|
|
1171
|
-
});
|
|
1172
|
-
expect(result.functionResp.message).toBe("test");
|
|
1173
|
-
});
|
|
1174
|
-
|
|
1175
|
-
it("should allow tool functions to call other tools via this.callTool", async () => {
|
|
1176
|
-
const helperTool: Tool = {
|
|
1177
|
-
type: "function",
|
|
1178
|
-
function: {
|
|
1179
|
-
name: "helperTool",
|
|
1180
|
-
description: "Helper tool",
|
|
1181
|
-
parameters: {
|
|
1182
|
-
type: "object",
|
|
1183
|
-
properties: {
|
|
1184
|
-
value: { type: "string" },
|
|
1185
|
-
},
|
|
1186
|
-
},
|
|
1187
|
-
},
|
|
1188
|
-
};
|
|
1189
|
-
|
|
1190
|
-
const mainTool: Tool = {
|
|
1191
|
-
type: "function",
|
|
1192
|
-
function: {
|
|
1193
|
-
name: "mainTool",
|
|
1194
|
-
description: "Main tool that calls helper",
|
|
1195
|
-
parameters: {
|
|
1196
|
-
type: "object",
|
|
1197
|
-
properties: {
|
|
1198
|
-
input: { type: "string" },
|
|
1199
|
-
},
|
|
1200
|
-
},
|
|
1201
|
-
},
|
|
1202
|
-
};
|
|
1203
|
-
|
|
1204
|
-
function helperFunction(args: { value: string }) {
|
|
1205
|
-
return `Helper processed: ${args.value}`;
|
|
1206
|
-
}
|
|
1207
|
-
|
|
1208
|
-
async function mainFunction(
|
|
1209
|
-
this: ToolsService,
|
|
1210
|
-
args: { input: string }
|
|
1211
|
-
) {
|
|
1212
|
-
if (!this || typeof this.callTool !== "function") {
|
|
1213
|
-
throw new Error("'this' is not bound to ToolsService instance");
|
|
1214
|
-
}
|
|
1215
|
-
|
|
1216
|
-
const helperCall: ToolCall = {
|
|
1217
|
-
id: "helper-call",
|
|
1218
|
-
type: "function",
|
|
1219
|
-
function: {
|
|
1220
|
-
name: "helperTool",
|
|
1221
|
-
arguments: JSON.stringify({ value: args.input }),
|
|
1222
|
-
},
|
|
1223
|
-
};
|
|
1224
|
-
|
|
1225
|
-
const helperResult = await this.callTool(helperCall);
|
|
1226
|
-
return `Main tool result: ${helperResult.functionResp}`;
|
|
1227
|
-
}
|
|
1228
|
-
|
|
1229
|
-
toolsService.addTool(helperTool);
|
|
1230
|
-
toolsService.addTool(mainTool);
|
|
1231
|
-
toolsService.setFunction("helperTool", helperFunction);
|
|
1232
|
-
toolsService.setFunction("mainTool", mainFunction);
|
|
1233
|
-
|
|
1234
|
-
const toolCall: ToolCall = {
|
|
1235
|
-
id: "test-call-2",
|
|
1236
|
-
type: "function",
|
|
1237
|
-
function: {
|
|
1238
|
-
name: "mainTool",
|
|
1239
|
-
arguments: JSON.stringify({ input: "test data" }),
|
|
1240
|
-
},
|
|
1241
|
-
};
|
|
1242
|
-
|
|
1243
|
-
const result = await toolsService.callTool(toolCall);
|
|
1244
|
-
|
|
1245
|
-
expect(result.functionResp).toBe(
|
|
1246
|
-
"Main tool result: Helper processed: test data"
|
|
1247
|
-
);
|
|
1248
|
-
});
|
|
1249
|
-
|
|
1250
|
-
it("should maintain binding through overrides", async () => {
|
|
1251
|
-
const testTool: Tool = {
|
|
1252
|
-
type: "function",
|
|
1253
|
-
function: {
|
|
1254
|
-
name: "bindingTestTool",
|
|
1255
|
-
description: "Test tool for binding with overrides",
|
|
1256
|
-
parameters: {
|
|
1257
|
-
type: "object",
|
|
1258
|
-
properties: {
|
|
1259
|
-
data: { type: "string" },
|
|
1260
|
-
},
|
|
1261
|
-
},
|
|
1262
|
-
},
|
|
1263
|
-
};
|
|
1264
|
-
|
|
1265
|
-
function originalFunction(
|
|
1266
|
-
this: ToolsService,
|
|
1267
|
-
args: { data: string }
|
|
1268
|
-
) {
|
|
1269
|
-
if (!this || typeof this.getContext !== "function") {
|
|
1270
|
-
throw new Error(
|
|
1271
|
-
"'this' is not bound to ToolsService instance in original"
|
|
1272
|
-
);
|
|
1273
|
-
}
|
|
1274
|
-
return `Original: ${args.data}`;
|
|
1275
|
-
}
|
|
1276
|
-
|
|
1277
|
-
const overrideFunction = function (
|
|
1278
|
-
this: ToolsService,
|
|
1279
|
-
originalArgs: any[],
|
|
1280
|
-
originalTool: Tool
|
|
1281
|
-
) {
|
|
1282
|
-
if (!this || typeof this.getContext !== "function") {
|
|
1283
|
-
throw new Error(
|
|
1284
|
-
"'this' is not bound to ToolsService instance in override"
|
|
1285
|
-
);
|
|
1286
|
-
}
|
|
1287
|
-
return `Override: ${originalArgs[0].data}`;
|
|
1288
|
-
};
|
|
1289
|
-
|
|
1290
|
-
toolsService.addTool(testTool);
|
|
1291
|
-
toolsService.setFunction("bindingTestTool", originalFunction);
|
|
1292
|
-
toolsService.registerOverride("bindingTestTool", overrideFunction);
|
|
1293
|
-
|
|
1294
|
-
const toolCall: ToolCall = {
|
|
1295
|
-
id: "test-call-3",
|
|
1296
|
-
type: "function",
|
|
1297
|
-
function: {
|
|
1298
|
-
name: "bindingTestTool",
|
|
1299
|
-
arguments: JSON.stringify({ data: "test" }),
|
|
1300
|
-
},
|
|
1301
|
-
};
|
|
1302
|
-
|
|
1303
|
-
const result = await toolsService.callTool(toolCall);
|
|
1304
|
-
|
|
1305
|
-
expect(result.functionResp).toBe("Override: test");
|
|
1306
|
-
});
|
|
1307
|
-
|
|
1308
|
-
it("should maintain binding through wrappers", async () => {
|
|
1309
|
-
const testTool: Tool = {
|
|
1310
|
-
type: "function",
|
|
1311
|
-
function: {
|
|
1312
|
-
name: "wrapperBindingTest",
|
|
1313
|
-
description: "Test tool for binding with wrappers",
|
|
1314
|
-
parameters: {
|
|
1315
|
-
type: "object",
|
|
1316
|
-
properties: {
|
|
1317
|
-
value: { type: "string" },
|
|
1318
|
-
},
|
|
1319
|
-
},
|
|
1320
|
-
},
|
|
1321
|
-
};
|
|
1322
|
-
|
|
1323
|
-
function baseFunction(this: ToolsService, args: { value: string }) {
|
|
1324
|
-
if (!this || typeof this.getContext !== "function") {
|
|
1325
|
-
throw new Error(
|
|
1326
|
-
"'this' is not bound to ToolsService instance in base function"
|
|
1327
|
-
);
|
|
1328
|
-
}
|
|
1329
|
-
return `Base: ${args.value}`;
|
|
1330
|
-
}
|
|
1331
|
-
|
|
1332
|
-
const wrapper = (originalFunc: Function, args: any, tool: Tool) => {
|
|
1333
|
-
// The wrapper should preserve the binding, args is now an array
|
|
1334
|
-
// We need to spread the args array when calling the function
|
|
1335
|
-
const result = originalFunc.call(toolsService, ...args);
|
|
1336
|
-
return `Wrapped: ${result}`;
|
|
1337
|
-
};
|
|
1338
|
-
|
|
1339
|
-
toolsService.addTool(testTool);
|
|
1340
|
-
toolsService.setFunction("wrapperBindingTest", baseFunction);
|
|
1341
|
-
toolsService.registerWrapper("wrapperBindingTest", wrapper);
|
|
1342
|
-
|
|
1343
|
-
const toolCall: ToolCall = {
|
|
1344
|
-
id: "test-call-4",
|
|
1345
|
-
type: "function",
|
|
1346
|
-
function: {
|
|
1347
|
-
name: "wrapperBindingTest",
|
|
1348
|
-
arguments: JSON.stringify({ value: "test" }),
|
|
1349
|
-
},
|
|
1350
|
-
};
|
|
1351
|
-
|
|
1352
|
-
const result = await toolsService.callTool(toolCall);
|
|
1353
|
-
|
|
1354
|
-
expect(result.functionResp).toBe("Wrapped: Base: test");
|
|
1355
|
-
});
|
|
1356
|
-
});
|
|
1357
|
-
});
|
|
1358
|
-
});
|
|
1359
|
-
|
|
1360
|
-
describe("endsWith Tool Name Resolution", () => {
|
|
1361
|
-
it("should register tool with complex prefix", () => {
|
|
1362
|
-
const complexTool: Tool = {
|
|
1363
|
-
type: "function",
|
|
1364
|
-
function: {
|
|
1365
|
-
name: "mcp_server_prefix_actualTool",
|
|
1366
|
-
description: "A tool with a complex prefix",
|
|
1367
|
-
parameters: {
|
|
1368
|
-
type: "object",
|
|
1369
|
-
properties: {
|
|
1370
|
-
input: { type: "string", description: "Test input" },
|
|
1371
|
-
},
|
|
1372
|
-
required: ["input"],
|
|
1373
|
-
},
|
|
1374
|
-
},
|
|
1375
|
-
};
|
|
1376
|
-
|
|
1377
|
-
toolsService.addTool(complexTool);
|
|
1378
|
-
|
|
1379
|
-
expect(toolsService.getTools()).toContain(complexTool);
|
|
1380
|
-
expect(toolsService.getToolNames()).toContain("mcp_server_prefix_actualTool");
|
|
1381
|
-
});
|
|
1382
|
-
|
|
1383
|
-
it("should find tool using endsWith matching", () => {
|
|
1384
|
-
const complexTool: Tool = {
|
|
1385
|
-
type: "function",
|
|
1386
|
-
function: {
|
|
1387
|
-
name: "mcp_server_prefix_actualTool",
|
|
1388
|
-
description: "A tool with a complex prefix",
|
|
1389
|
-
parameters: {
|
|
1390
|
-
type: "object",
|
|
1391
|
-
properties: {
|
|
1392
|
-
input: { type: "string", description: "Test input" },
|
|
1393
|
-
},
|
|
1394
|
-
required: ["input"],
|
|
1395
|
-
},
|
|
1396
|
-
},
|
|
1397
|
-
};
|
|
1398
|
-
|
|
1399
|
-
toolsService.addTool(complexTool);
|
|
1400
|
-
|
|
1401
|
-
// Should find tool by partial name (suffix)
|
|
1402
|
-
const foundTool = toolsService.getTool("actualTool");
|
|
1403
|
-
expect(foundTool).toBeDefined();
|
|
1404
|
-
expect(foundTool.function.name).toBe("mcp_server_prefix_actualTool");
|
|
1405
|
-
});
|
|
1406
|
-
|
|
1407
|
-
it("should call tool using partial name with endsWith", async () => {
|
|
1408
|
-
const complexTool: Tool = {
|
|
1409
|
-
type: "function",
|
|
1410
|
-
function: {
|
|
1411
|
-
name: "mcp_server_prefix_testFunction",
|
|
1412
|
-
description: "A tool with a complex prefix",
|
|
1413
|
-
parameters: {
|
|
1414
|
-
type: "object",
|
|
1415
|
-
properties: {
|
|
1416
|
-
message: { type: "string", description: "Test message" },
|
|
1417
|
-
},
|
|
1418
|
-
required: ["message"],
|
|
1419
|
-
},
|
|
1420
|
-
},
|
|
1421
|
-
};
|
|
1422
|
-
|
|
1423
|
-
const testFunction = (args: { message: string }) => {
|
|
1424
|
-
return `Received: ${args.message}`;
|
|
1425
|
-
};
|
|
1426
|
-
|
|
1427
|
-
toolsService.addTool(complexTool);
|
|
1428
|
-
toolsService.setFunction("mcp_server_prefix_testFunction", testFunction);
|
|
1429
|
-
|
|
1430
|
-
const toolCall: ToolCall = {
|
|
1431
|
-
id: "test-endsWith-1",
|
|
1432
|
-
type: "function",
|
|
1433
|
-
function: {
|
|
1434
|
-
name: "testFunction",
|
|
1435
|
-
arguments: JSON.stringify({ message: "Hello" }),
|
|
1436
|
-
},
|
|
1437
|
-
};
|
|
1438
|
-
|
|
1439
|
-
const result = await toolsService.callTool(toolCall, [
|
|
1440
|
-
"mcp_server_prefix_testFunction",
|
|
1441
|
-
]);
|
|
1442
|
-
|
|
1443
|
-
expect(result.functionResp).toBe("Received: Hello");
|
|
1444
|
-
expect(result.functionName).toBe("testFunction");
|
|
1445
|
-
});
|
|
1446
|
-
|
|
1447
|
-
it("should execute function correctly with endsWith resolution", async () => {
|
|
1448
|
-
const complexTool: Tool = {
|
|
1449
|
-
type: "function",
|
|
1450
|
-
function: {
|
|
1451
|
-
name: "complex_prefix_myTool",
|
|
1452
|
-
description: "Test tool with prefix",
|
|
1453
|
-
parameters: {
|
|
1454
|
-
type: "object",
|
|
1455
|
-
properties: {
|
|
1456
|
-
value: { type: "number", description: "A number" },
|
|
1457
|
-
},
|
|
1458
|
-
required: ["value"],
|
|
1459
|
-
},
|
|
1460
|
-
},
|
|
1461
|
-
};
|
|
1462
|
-
|
|
1463
|
-
const myFunction = (args: { value: number }) => {
|
|
1464
|
-
return args.value * 2;
|
|
1465
|
-
};
|
|
1466
|
-
|
|
1467
|
-
toolsService.addTool(complexTool);
|
|
1468
|
-
toolsService.setFunction("complex_prefix_myTool", myFunction);
|
|
1469
|
-
|
|
1470
|
-
const toolCall: ToolCall = {
|
|
1471
|
-
id: "test-endsWith-2",
|
|
1472
|
-
type: "function",
|
|
1473
|
-
function: {
|
|
1474
|
-
name: "myTool",
|
|
1475
|
-
arguments: JSON.stringify({ value: 5 }),
|
|
1476
|
-
},
|
|
1477
|
-
};
|
|
1478
|
-
|
|
1479
|
-
const result = await toolsService.callTool(toolCall, [
|
|
1480
|
-
"complex_prefix_myTool",
|
|
1481
|
-
]);
|
|
1482
|
-
|
|
1483
|
-
expect(result.functionResp).toBe(10);
|
|
1484
|
-
expect(result.functionName).toBe("myTool");
|
|
1485
|
-
});
|
|
1486
|
-
|
|
1487
|
-
it("should handle multiple tools with same suffix", () => {
|
|
1488
|
-
const tool1: Tool = {
|
|
1489
|
-
type: "function",
|
|
1490
|
-
function: {
|
|
1491
|
-
name: "prefix_a_sharedTool",
|
|
1492
|
-
description: "First tool",
|
|
1493
|
-
parameters: { type: "object", properties: {} },
|
|
1494
|
-
},
|
|
1495
|
-
};
|
|
1496
|
-
|
|
1497
|
-
const tool2: Tool = {
|
|
1498
|
-
type: "function",
|
|
1499
|
-
function: {
|
|
1500
|
-
name: "prefix_b_sharedTool",
|
|
1501
|
-
description: "Second tool",
|
|
1502
|
-
parameters: { type: "object", properties: {} },
|
|
1503
|
-
},
|
|
1504
|
-
};
|
|
1505
|
-
|
|
1506
|
-
toolsService.addTool(tool1);
|
|
1507
|
-
toolsService.addTool(tool2);
|
|
1508
|
-
|
|
1509
|
-
// getTool should return the first matching tool
|
|
1510
|
-
const foundTool = toolsService.getTool("sharedTool");
|
|
1511
|
-
expect(foundTool).toBeDefined();
|
|
1512
|
-
expect(foundTool.function.name).toMatch(/_sharedTool$/);
|
|
1513
|
-
});
|
|
1514
|
-
|
|
1515
|
-
it("should return first matching tool (no exact match priority)", () => {
|
|
1516
|
-
// The implementation does NOT prioritize exact matches
|
|
1517
|
-
// It returns the first tool that matches either exactly or via endsWith
|
|
1518
|
-
const prefixedTool: Tool = {
|
|
1519
|
-
type: "function",
|
|
1520
|
-
function: {
|
|
1521
|
-
name: "prefix_myTool",
|
|
1522
|
-
description: "Prefixed tool",
|
|
1523
|
-
parameters: { type: "object", properties: {} },
|
|
1524
|
-
},
|
|
1525
|
-
};
|
|
1526
|
-
|
|
1527
|
-
const exactMatchTool: Tool = {
|
|
1528
|
-
type: "function",
|
|
1529
|
-
function: {
|
|
1530
|
-
name: "myTool",
|
|
1531
|
-
description: "Exact match tool",
|
|
1532
|
-
parameters: { type: "object", properties: {} },
|
|
1533
|
-
},
|
|
1534
|
-
};
|
|
1535
|
-
|
|
1536
|
-
// Add prefixed tool first
|
|
1537
|
-
toolsService.addTool(prefixedTool);
|
|
1538
|
-
|
|
1539
|
-
// When we search for "myTool", it will find prefixedTool first
|
|
1540
|
-
// because "prefix_myTool".endsWith("myTool") is true
|
|
1541
|
-
let foundTool = toolsService.getTool("myTool");
|
|
1542
|
-
expect(foundTool).toBeDefined();
|
|
1543
|
-
expect(foundTool.function.name).toBe("prefix_myTool");
|
|
1544
|
-
|
|
1545
|
-
// Now add exact match tool
|
|
1546
|
-
toolsService.addTool(exactMatchTool);
|
|
1547
|
-
|
|
1548
|
-
// It will still find prefixedTool first (first in array)
|
|
1549
|
-
foundTool = toolsService.getTool("myTool");
|
|
1550
|
-
expect(foundTool).toBeDefined();
|
|
1551
|
-
expect(foundTool.function.name).toBe("prefix_myTool");
|
|
1552
|
-
});
|
|
1553
|
-
|
|
1554
|
-
it("should return undefined for non-matching partial name", () => {
|
|
1555
|
-
const tool: Tool = {
|
|
1556
|
-
type: "function",
|
|
1557
|
-
function: {
|
|
1558
|
-
name: "mcp_server_myTool",
|
|
1559
|
-
description: "A tool",
|
|
1560
|
-
parameters: { type: "object", properties: {} },
|
|
1561
|
-
},
|
|
1562
|
-
};
|
|
1563
|
-
|
|
1564
|
-
toolsService.addTool(tool);
|
|
1565
|
-
|
|
1566
|
-
const foundTool = toolsService.getTool("nonExistent");
|
|
1567
|
-
expect(foundTool).toBeUndefined();
|
|
1568
|
-
});
|
|
1569
|
-
|
|
1570
|
-
it("should work with getToolsByNames using endsWith logic for prefix stripping", () => {
|
|
1571
|
-
// Note: getToolsByNames uses endsWith logic for prefix stripping!
|
|
1572
|
-
// It checks if the TOOL name ends with the INPUT name
|
|
1573
|
-
// So to find "mcp_prefix_tool1", you can search with just "tool1"
|
|
1574
|
-
const tool1: Tool = {
|
|
1575
|
-
type: "function",
|
|
1576
|
-
function: { name: "tool1", description: "", parameters: { type: "object", properties: {} } },
|
|
1577
|
-
};
|
|
1578
|
-
const tool2: Tool = {
|
|
1579
|
-
type: "function",
|
|
1580
|
-
function: { name: "tool2", description: "", parameters: { type: "object", properties: {} } },
|
|
1581
|
-
};
|
|
1582
|
-
|
|
1583
|
-
toolsService.addTools([tool1, tool2]);
|
|
1584
|
-
|
|
1585
|
-
const foundTools = toolsService.getToolsByNames(["tool1", "tool2"]);
|
|
1586
|
-
expect(foundTools).toHaveLength(2);
|
|
1587
|
-
expect(foundTools.map(t => t.function.name)).toContain("tool1");
|
|
1588
|
-
expect(foundTools.map(t => t.function.name)).toContain("tool2");
|
|
1589
|
-
});
|
|
1590
|
-
});
|
|
1591
|
-
|
|
1592
|
-
describe("_ctx per-call context threading", () => {
|
|
1593
|
-
const positionalTool: Tool = {
|
|
1594
|
-
type: "function",
|
|
1595
|
-
function: {
|
|
1596
|
-
name: "posCtxTool",
|
|
1597
|
-
parameters: {
|
|
1598
|
-
type: "object",
|
|
1599
|
-
positional: true,
|
|
1600
|
-
usesContext: true,
|
|
1601
|
-
properties: {
|
|
1602
|
-
arg1: { type: "string" },
|
|
1603
|
-
},
|
|
1604
|
-
required: ["arg1"],
|
|
1605
|
-
},
|
|
1606
|
-
},
|
|
1607
|
-
};
|
|
1608
|
-
|
|
1609
|
-
const nonPositionalTool: Tool = {
|
|
1610
|
-
type: "function",
|
|
1611
|
-
function: {
|
|
1612
|
-
name: "nonPosCtxTool",
|
|
1613
|
-
parameters: {
|
|
1614
|
-
type: "object",
|
|
1615
|
-
usesContext: true,
|
|
1616
|
-
properties: {
|
|
1617
|
-
input: { type: "string" },
|
|
1618
|
-
},
|
|
1619
|
-
required: ["input"],
|
|
1620
|
-
},
|
|
1621
|
-
},
|
|
1622
|
-
};
|
|
1623
|
-
|
|
1624
|
-
it("passes _ctx as the last positional argument for positional tools", async () => {
|
|
1625
|
-
const fn = jest.fn().mockResolvedValue("ok");
|
|
1626
|
-
toolsService.addTool(positionalTool);
|
|
1627
|
-
toolsService.setFunction("posCtxTool", fn);
|
|
1628
|
-
|
|
1629
|
-
const caller = { name: "TestAgent" };
|
|
1630
|
-
await toolsService.callTool(
|
|
1631
|
-
{
|
|
1632
|
-
id: "c1",
|
|
1633
|
-
type: "function",
|
|
1634
|
-
function: {
|
|
1635
|
-
name: "posCtxTool",
|
|
1636
|
-
arguments: JSON.stringify({ arg1: "hello" }),
|
|
1637
|
-
},
|
|
1638
|
-
},
|
|
1639
|
-
undefined,
|
|
1640
|
-
{ caller, taskId: "task-123" }
|
|
1641
|
-
);
|
|
1642
|
-
|
|
1643
|
-
const callArgs = fn.mock.calls[0];
|
|
1644
|
-
expect(callArgs[0]).toBe("hello");
|
|
1645
|
-
const ctx = callArgs[1] as ToolCallContext;
|
|
1646
|
-
expect(ctx).toBeDefined();
|
|
1647
|
-
expect(ctx.caller).toBe(caller);
|
|
1648
|
-
expect(ctx.taskId).toBe("task-123");
|
|
1649
|
-
expect(ctx.Tools).toBe(toolsService);
|
|
1650
|
-
});
|
|
1651
|
-
|
|
1652
|
-
it("merges _ctx onto the args object for non-positional tools", async () => {
|
|
1653
|
-
const fn = jest.fn().mockResolvedValue("ok");
|
|
1654
|
-
toolsService.addTool(nonPositionalTool);
|
|
1655
|
-
toolsService.setFunction("nonPosCtxTool", fn);
|
|
1656
|
-
|
|
1657
|
-
const caller = { name: "TestAgent" };
|
|
1658
|
-
await toolsService.callTool(
|
|
1659
|
-
{
|
|
1660
|
-
id: "c2",
|
|
1661
|
-
type: "function",
|
|
1662
|
-
function: {
|
|
1663
|
-
name: "nonPosCtxTool",
|
|
1664
|
-
arguments: JSON.stringify({ input: "value" }),
|
|
1665
|
-
},
|
|
1666
|
-
},
|
|
1667
|
-
undefined,
|
|
1668
|
-
{ caller, taskId: "task-456" }
|
|
1669
|
-
);
|
|
1670
|
-
|
|
1671
|
-
const argObj = fn.mock.calls[0][0];
|
|
1672
|
-
expect(argObj.input).toBe("value");
|
|
1673
|
-
expect(argObj._ctx).toBeDefined();
|
|
1674
|
-
expect(argObj._ctx.caller).toBe(caller);
|
|
1675
|
-
expect(argObj._ctx.taskId).toBe("task-456");
|
|
1676
|
-
expect(argObj._ctx.Tools).toBe(toolsService);
|
|
1677
|
-
});
|
|
1678
|
-
|
|
1679
|
-
it("still provides a _ctx (with Tools) when no callContext is passed", async () => {
|
|
1680
|
-
const fn = jest.fn().mockResolvedValue("ok");
|
|
1681
|
-
toolsService.addTool(nonPositionalTool);
|
|
1682
|
-
toolsService.setFunction("nonPosCtxTool", fn);
|
|
1683
|
-
|
|
1684
|
-
await toolsService.callTool({
|
|
1685
|
-
id: "c3",
|
|
1686
|
-
type: "function",
|
|
1687
|
-
function: {
|
|
1688
|
-
name: "nonPosCtxTool",
|
|
1689
|
-
arguments: JSON.stringify({ input: "value" }),
|
|
1690
|
-
},
|
|
1691
|
-
});
|
|
1692
|
-
|
|
1693
|
-
const argObj = fn.mock.calls[0][0];
|
|
1694
|
-
expect(argObj._ctx).toBeDefined();
|
|
1695
|
-
expect(argObj._ctx.Tools).toBe(toolsService);
|
|
1696
|
-
expect(argObj._ctx.caller).toBeUndefined();
|
|
1697
|
-
});
|
|
1698
|
-
|
|
1699
|
-
it("does not leak _ctx into the multi_tool_use.parallel extraction", async () => {
|
|
1700
|
-
// The parallel path should extract calls from the ORIGINAL args, not the
|
|
1701
|
-
// _ctx-augmented ones.
|
|
1702
|
-
const parallelTool: Tool = {
|
|
1703
|
-
type: "function",
|
|
1704
|
-
function: {
|
|
1705
|
-
name: "multi_tool_use.parallel",
|
|
1706
|
-
parameters: { type: "object", properties: {} },
|
|
1707
|
-
},
|
|
1708
|
-
};
|
|
1709
|
-
const inner = jest
|
|
1710
|
-
.fn()
|
|
1711
|
-
.mockResolvedValue(["r1", "r2"]);
|
|
1712
|
-
toolsService.addTool(parallelTool);
|
|
1713
|
-
toolsService.setFunction("multi_tool_use.parallel", inner);
|
|
1714
|
-
|
|
1715
|
-
const result = await toolsService.callTool(
|
|
1716
|
-
{
|
|
1717
|
-
id: "c4",
|
|
1718
|
-
type: "function",
|
|
1719
|
-
function: {
|
|
1720
|
-
name: "multi_tool_use.parallel",
|
|
1721
|
-
arguments: JSON.stringify([
|
|
1722
|
-
{ recipient_name: "functions.a", parameters: {} },
|
|
1723
|
-
{ recipient_name: "functions.b", parameters: {} },
|
|
1724
|
-
]),
|
|
1725
|
-
},
|
|
1726
|
-
},
|
|
1727
|
-
undefined,
|
|
1728
|
-
{ caller: {}, taskId: "t" }
|
|
1729
|
-
);
|
|
1730
|
-
|
|
1731
|
-
// Two tool messages, one per parallel call — proves extraction used the
|
|
1732
|
-
// original array shape rather than an _ctx-wrapped object.
|
|
1733
|
-
expect(result.toolMessages).toHaveLength(2);
|
|
1734
|
-
expect(result.toolMessages[0].name).toBe("a");
|
|
1735
|
-
expect(result.toolMessages[1].name).toBe("b");
|
|
1736
|
-
});
|
|
1737
|
-
});
|
|
1738
|
-
});
|