@strands-agents/sdk 0.5.0 → 0.7.0
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 +64 -0
- package/dist/src/__fixtures__/agent-helpers.d.ts +37 -4
- package/dist/src/__fixtures__/agent-helpers.d.ts.map +1 -1
- package/dist/src/__fixtures__/agent-helpers.js +31 -4
- package/dist/src/__fixtures__/agent-helpers.js.map +1 -1
- package/dist/src/__fixtures__/metrics-helpers.d.ts +55 -0
- package/dist/src/__fixtures__/metrics-helpers.d.ts.map +1 -0
- package/dist/src/__fixtures__/metrics-helpers.js +57 -0
- package/dist/src/__fixtures__/metrics-helpers.js.map +1 -0
- package/dist/src/__fixtures__/mock-message-model.d.ts +8 -4
- package/dist/src/__fixtures__/mock-message-model.d.ts.map +1 -1
- package/dist/src/__fixtures__/mock-message-model.js +25 -7
- package/dist/src/__fixtures__/mock-message-model.js.map +1 -1
- package/dist/src/__fixtures__/mock-meter.d.ts +32 -0
- package/dist/src/__fixtures__/mock-meter.d.ts.map +1 -0
- package/dist/src/__fixtures__/mock-meter.js +47 -0
- package/dist/src/__fixtures__/mock-meter.js.map +1 -0
- package/dist/src/__fixtures__/mock-plugin.d.ts +13 -0
- package/dist/src/__fixtures__/mock-plugin.d.ts.map +1 -0
- package/dist/src/__fixtures__/{mock-hook-provider.js → mock-plugin.js} +8 -5
- package/dist/src/__fixtures__/mock-plugin.js.map +1 -0
- package/dist/src/__fixtures__/mock-storage-provider.d.ts +5 -0
- package/dist/src/__fixtures__/mock-storage-provider.d.ts.map +1 -1
- package/dist/src/__fixtures__/mock-storage-provider.js +23 -6
- package/dist/src/__fixtures__/mock-storage-provider.js.map +1 -1
- package/dist/src/__fixtures__/slim-types.d.ts +2 -1
- package/dist/src/__fixtures__/slim-types.d.ts.map +1 -1
- package/dist/src/__fixtures__/tool-helpers.d.ts.map +1 -1
- package/dist/src/__fixtures__/tool-helpers.js +5 -2
- package/dist/src/__fixtures__/tool-helpers.js.map +1 -1
- package/dist/src/__tests__/index.test.js +21 -0
- package/dist/src/__tests__/index.test.js.map +1 -1
- package/dist/src/__tests__/mcp.test.js +45 -15
- package/dist/src/__tests__/mcp.test.js.map +1 -1
- package/dist/src/__tests__/mime.test.d.ts +2 -0
- package/dist/src/__tests__/mime.test.d.ts.map +1 -0
- package/dist/src/__tests__/mime.test.js +83 -0
- package/dist/src/__tests__/mime.test.js.map +1 -0
- package/dist/src/__tests__/state-store.test.d.ts +2 -0
- package/dist/src/__tests__/state-store.test.d.ts.map +1 -0
- package/dist/src/__tests__/{app-state.test.js → state-store.test.js} +86 -51
- package/dist/src/__tests__/state-store.test.js.map +1 -0
- package/dist/src/a2a/__tests__/a2a-agent.test.d.ts +2 -0
- package/dist/src/a2a/__tests__/a2a-agent.test.d.ts.map +1 -0
- package/dist/src/a2a/__tests__/a2a-agent.test.js +364 -0
- package/dist/src/a2a/__tests__/a2a-agent.test.js.map +1 -0
- package/dist/src/a2a/__tests__/adapters.test.d.ts +2 -0
- package/dist/src/a2a/__tests__/adapters.test.d.ts.map +1 -0
- package/dist/src/a2a/__tests__/adapters.test.js +151 -0
- package/dist/src/a2a/__tests__/adapters.test.js.map +1 -0
- package/dist/src/a2a/__tests__/executor.test.d.ts +2 -0
- package/dist/src/a2a/__tests__/executor.test.d.ts.map +1 -0
- package/dist/src/a2a/__tests__/executor.test.js +196 -0
- package/dist/src/a2a/__tests__/executor.test.js.map +1 -0
- package/dist/src/a2a/__tests__/server.test.d.ts +2 -0
- package/dist/src/a2a/__tests__/server.test.d.ts.map +1 -0
- package/dist/src/a2a/__tests__/server.test.js +51 -0
- package/dist/src/a2a/__tests__/server.test.js.map +1 -0
- package/dist/src/a2a/__tests__/server.test.node.d.ts +2 -0
- package/dist/src/a2a/__tests__/server.test.node.d.ts.map +1 -0
- package/dist/src/a2a/__tests__/server.test.node.js +110 -0
- package/dist/src/a2a/__tests__/server.test.node.js.map +1 -0
- package/dist/src/a2a/a2a-agent.d.ts +132 -0
- package/dist/src/a2a/a2a-agent.d.ts.map +1 -0
- package/dist/src/a2a/a2a-agent.js +255 -0
- package/dist/src/a2a/a2a-agent.js.map +1 -0
- package/dist/src/a2a/adapters.d.ts +27 -0
- package/dist/src/a2a/adapters.d.ts.map +1 -0
- package/dist/src/a2a/adapters.js +175 -0
- package/dist/src/a2a/adapters.js.map +1 -0
- package/dist/src/a2a/events.d.ts +42 -0
- package/dist/src/a2a/events.d.ts.map +1 -0
- package/dist/src/a2a/events.js +35 -0
- package/dist/src/a2a/events.js.map +1 -0
- package/dist/src/a2a/executor.d.ts +57 -0
- package/dist/src/a2a/executor.d.ts.map +1 -0
- package/dist/src/a2a/executor.js +130 -0
- package/dist/src/a2a/executor.js.map +1 -0
- package/dist/src/a2a/express-server.d.ts +67 -0
- package/dist/src/a2a/express-server.d.ts.map +1 -0
- package/dist/src/a2a/express-server.js +95 -0
- package/dist/src/a2a/express-server.js.map +1 -0
- package/dist/src/a2a/index.d.ts +16 -0
- package/dist/src/a2a/index.d.ts.map +1 -0
- package/dist/src/a2a/index.js +16 -0
- package/dist/src/a2a/index.js.map +1 -0
- package/dist/src/a2a/logging.d.ts +8 -0
- package/dist/src/a2a/logging.d.ts.map +1 -0
- package/dist/src/a2a/logging.js +15 -0
- package/dist/src/a2a/logging.js.map +1 -0
- package/dist/src/a2a/server.d.ts +67 -0
- package/dist/src/a2a/server.d.ts.map +1 -0
- package/dist/src/a2a/server.js +67 -0
- package/dist/src/a2a/server.js.map +1 -0
- package/dist/src/agent/__tests__/agent.hook.test.js +87 -51
- package/dist/src/agent/__tests__/agent.hook.test.js.map +1 -1
- package/dist/src/agent/__tests__/agent.test.js +176 -101
- package/dist/src/agent/__tests__/agent.test.js.map +1 -1
- package/dist/src/agent/__tests__/agent.tracer.test.js +10 -10
- package/dist/src/agent/__tests__/agent.tracer.test.js.map +1 -1
- package/dist/src/agent/__tests__/snapshot.test.js +11 -11
- package/dist/src/agent/__tests__/snapshot.test.js.map +1 -1
- package/dist/src/agent/agent.d.ts +71 -58
- package/dist/src/agent/agent.d.ts.map +1 -1
- package/dist/src/agent/agent.js +177 -93
- package/dist/src/agent/agent.js.map +1 -1
- package/dist/src/agent/snapshot.d.ts.map +1 -1
- package/dist/src/agent/snapshot.js +3 -2
- package/dist/src/agent/snapshot.js.map +1 -1
- package/dist/src/conversation-manager/__tests__/conversation-manager.test.d.ts +2 -0
- package/dist/src/conversation-manager/__tests__/conversation-manager.test.d.ts.map +1 -0
- package/dist/src/conversation-manager/__tests__/conversation-manager.test.js +100 -0
- package/dist/src/conversation-manager/__tests__/conversation-manager.test.js.map +1 -0
- package/dist/src/conversation-manager/__tests__/null-conversation-manager.test.js +26 -10
- package/dist/src/conversation-manager/__tests__/null-conversation-manager.test.js.map +1 -1
- package/dist/src/conversation-manager/__tests__/sliding-window-conversation-manager.test.js +84 -21
- package/dist/src/conversation-manager/__tests__/sliding-window-conversation-manager.test.js.map +1 -1
- package/dist/src/conversation-manager/conversation-manager.d.ts +87 -0
- package/dist/src/conversation-manager/conversation-manager.d.ts.map +1 -0
- package/dist/src/conversation-manager/conversation-manager.js +59 -0
- package/dist/src/conversation-manager/conversation-manager.js.map +1 -0
- package/dist/src/conversation-manager/index.d.ts +1 -0
- package/dist/src/conversation-manager/index.d.ts.map +1 -1
- package/dist/src/conversation-manager/index.js +1 -0
- package/dist/src/conversation-manager/index.js.map +1 -1
- package/dist/src/conversation-manager/null-conversation-manager.d.ts +12 -8
- package/dist/src/conversation-manager/null-conversation-manager.d.ts.map +1 -1
- package/dist/src/conversation-manager/null-conversation-manager.js +13 -7
- package/dist/src/conversation-manager/null-conversation-manager.js.map +1 -1
- package/dist/src/conversation-manager/sliding-window-conversation-manager.d.ts +28 -19
- package/dist/src/conversation-manager/sliding-window-conversation-manager.d.ts.map +1 -1
- package/dist/src/conversation-manager/sliding-window-conversation-manager.js +44 -36
- package/dist/src/conversation-manager/sliding-window-conversation-manager.js.map +1 -1
- package/dist/src/errors.d.ts +6 -0
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/errors.js +9 -0
- package/dist/src/errors.js.map +1 -1
- package/dist/src/hooks/__tests__/events.test.js +2 -0
- package/dist/src/hooks/__tests__/events.test.js.map +1 -1
- package/dist/src/hooks/__tests__/registry.test.js +10 -154
- package/dist/src/hooks/__tests__/registry.test.js.map +1 -1
- package/dist/src/hooks/events.d.ts +60 -44
- package/dist/src/hooks/events.d.ts.map +1 -1
- package/dist/src/hooks/events.js +11 -11
- package/dist/src/hooks/events.js.map +1 -1
- package/dist/src/hooks/index.d.ts +4 -4
- package/dist/src/hooks/index.d.ts.map +1 -1
- package/dist/src/hooks/index.js +2 -2
- package/dist/src/hooks/registry.d.ts +1 -32
- package/dist/src/hooks/registry.d.ts.map +1 -1
- package/dist/src/hooks/registry.js +1 -47
- package/dist/src/hooks/registry.js.map +1 -1
- package/dist/src/hooks/types.d.ts +0 -31
- package/dist/src/hooks/types.d.ts.map +1 -1
- package/dist/src/index.d.ts +30 -15
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +21 -8
- package/dist/src/index.js.map +1 -1
- package/dist/src/mcp.d.ts +38 -0
- package/dist/src/mcp.d.ts.map +1 -1
- package/dist/src/mcp.js +23 -6
- package/dist/src/mcp.js.map +1 -1
- package/dist/src/mime.d.ts +24 -0
- package/dist/src/mime.d.ts.map +1 -0
- package/dist/src/mime.js +82 -0
- package/dist/src/mime.js.map +1 -0
- package/dist/src/models/__tests__/anthropic.test.js +78 -1
- package/dist/src/models/__tests__/anthropic.test.js.map +1 -1
- package/dist/src/models/__tests__/bedrock.test.js +2050 -131
- package/dist/src/models/__tests__/bedrock.test.js.map +1 -1
- package/dist/src/models/__tests__/gemini.test.js +100 -1
- package/dist/src/models/__tests__/gemini.test.js.map +1 -1
- package/dist/src/models/__tests__/model.test.js +131 -0
- package/dist/src/models/__tests__/model.test.js.map +1 -1
- package/dist/src/models/__tests__/openai.test.js +184 -32
- package/dist/src/models/__tests__/openai.test.js.map +1 -1
- package/dist/src/models/__tests__/streaming.test.d.ts +2 -0
- package/dist/src/models/__tests__/streaming.test.d.ts.map +1 -0
- package/dist/src/models/__tests__/streaming.test.js +50 -0
- package/dist/src/models/__tests__/streaming.test.js.map +1 -0
- package/dist/src/models/anthropic.d.ts.map +1 -1
- package/dist/src/models/anthropic.js +6 -7
- package/dist/src/models/anthropic.js.map +1 -1
- package/dist/src/models/bedrock.d.ts +144 -11
- package/dist/src/models/bedrock.d.ts.map +1 -1
- package/dist/src/models/bedrock.js +416 -28
- package/dist/src/models/bedrock.js.map +1 -1
- package/dist/src/models/gemini/adapters.d.ts.map +1 -1
- package/dist/src/models/gemini/adapters.js +65 -14
- package/dist/src/models/gemini/adapters.js.map +1 -1
- package/dist/src/models/model.d.ts +18 -0
- package/dist/src/models/model.d.ts.map +1 -1
- package/dist/src/models/model.js +57 -11
- package/dist/src/models/model.js.map +1 -1
- package/dist/src/models/openai.d.ts +15 -0
- package/dist/src/models/openai.d.ts.map +1 -1
- package/dist/src/models/openai.js +108 -64
- package/dist/src/models/openai.js.map +1 -1
- package/dist/src/models/streaming.d.ts +88 -2
- package/dist/src/models/streaming.d.ts.map +1 -1
- package/dist/src/models/streaming.js +26 -0
- package/dist/src/models/streaming.js.map +1 -1
- package/dist/src/multiagent/__tests__/events.test.js +41 -8
- package/dist/src/multiagent/__tests__/events.test.js.map +1 -1
- package/dist/src/multiagent/__tests__/graph.test.d.ts +2 -0
- package/dist/src/multiagent/__tests__/graph.test.d.ts.map +1 -0
- package/dist/src/multiagent/__tests__/graph.test.js +453 -0
- package/dist/src/multiagent/__tests__/graph.test.js.map +1 -0
- package/dist/src/multiagent/__tests__/nodes.test.js +34 -16
- package/dist/src/multiagent/__tests__/nodes.test.js.map +1 -1
- package/dist/src/multiagent/__tests__/queue.test.js +22 -0
- package/dist/src/multiagent/__tests__/queue.test.js.map +1 -1
- package/dist/src/multiagent/__tests__/swarm.test.d.ts +2 -0
- package/dist/src/multiagent/__tests__/swarm.test.d.ts.map +1 -0
- package/dist/src/multiagent/__tests__/swarm.test.js +264 -0
- package/dist/src/multiagent/__tests__/swarm.test.js.map +1 -0
- package/dist/src/multiagent/edge.d.ts +9 -2
- package/dist/src/multiagent/edge.d.ts.map +1 -1
- package/dist/src/multiagent/events.d.ts +63 -15
- package/dist/src/multiagent/events.d.ts.map +1 -1
- package/dist/src/multiagent/events.js +28 -3
- package/dist/src/multiagent/events.js.map +1 -1
- package/dist/src/multiagent/graph.d.ts +135 -0
- package/dist/src/multiagent/graph.d.ts.map +1 -0
- package/dist/src/multiagent/graph.js +400 -0
- package/dist/src/multiagent/graph.js.map +1 -0
- package/dist/src/multiagent/index.d.ts +8 -3
- package/dist/src/multiagent/index.d.ts.map +1 -1
- package/dist/src/multiagent/index.js +3 -1
- package/dist/src/multiagent/index.js.map +1 -1
- package/dist/src/multiagent/multiagent.d.ts +41 -0
- package/dist/src/multiagent/multiagent.d.ts.map +1 -0
- package/dist/src/multiagent/multiagent.js +2 -0
- package/dist/src/multiagent/multiagent.js.map +1 -0
- package/dist/src/multiagent/nodes.d.ts +24 -25
- package/dist/src/multiagent/nodes.d.ts.map +1 -1
- package/dist/src/multiagent/nodes.js +42 -15
- package/dist/src/multiagent/nodes.js.map +1 -1
- package/dist/src/multiagent/plugins.d.ts +70 -0
- package/dist/src/multiagent/plugins.d.ts.map +1 -0
- package/dist/src/multiagent/plugins.js +70 -0
- package/dist/src/multiagent/plugins.js.map +1 -0
- package/dist/src/multiagent/queue.d.ts +6 -0
- package/dist/src/multiagent/queue.d.ts.map +1 -1
- package/dist/src/multiagent/queue.js +13 -0
- package/dist/src/multiagent/queue.js.map +1 -1
- package/dist/src/multiagent/state.d.ts +4 -2
- package/dist/src/multiagent/state.d.ts.map +1 -1
- package/dist/src/multiagent/state.js +5 -2
- package/dist/src/multiagent/state.js.map +1 -1
- package/dist/src/multiagent/swarm.d.ts +112 -0
- package/dist/src/multiagent/swarm.d.ts.map +1 -0
- package/dist/src/multiagent/swarm.js +256 -0
- package/dist/src/multiagent/swarm.js.map +1 -0
- package/dist/src/plugins/__tests__/plugin.test.d.ts +2 -0
- package/dist/src/plugins/__tests__/plugin.test.d.ts.map +1 -0
- package/dist/src/plugins/__tests__/plugin.test.js +114 -0
- package/dist/src/plugins/__tests__/plugin.test.js.map +1 -0
- package/dist/src/plugins/__tests__/registry.test.d.ts +2 -0
- package/dist/src/plugins/__tests__/registry.test.d.ts.map +1 -0
- package/dist/src/plugins/__tests__/registry.test.js +147 -0
- package/dist/src/plugins/__tests__/registry.test.js.map +1 -0
- package/dist/src/plugins/index.d.ts +30 -0
- package/dist/src/plugins/index.d.ts.map +1 -0
- package/dist/src/plugins/index.js +30 -0
- package/dist/src/plugins/index.js.map +1 -0
- package/dist/src/plugins/plugin.d.ts +74 -0
- package/dist/src/plugins/plugin.d.ts.map +1 -0
- package/dist/src/plugins/plugin.js +8 -0
- package/dist/src/plugins/plugin.js.map +1 -0
- package/dist/src/plugins/registry.d.ts +25 -0
- package/dist/src/plugins/registry.d.ts.map +1 -0
- package/dist/src/plugins/registry.js +41 -0
- package/dist/src/plugins/registry.js.map +1 -0
- package/dist/src/registry/__tests__/tool-registry.test.d.ts +2 -0
- package/dist/src/registry/__tests__/tool-registry.test.d.ts.map +1 -0
- package/dist/src/registry/__tests__/tool-registry.test.js +124 -0
- package/dist/src/registry/__tests__/tool-registry.test.js.map +1 -0
- package/dist/src/registry/tool-registry.d.ts +32 -20
- package/dist/src/registry/tool-registry.d.ts.map +1 -1
- package/dist/src/registry/tool-registry.js +60 -158
- package/dist/src/registry/tool-registry.js.map +1 -1
- package/dist/src/session/__tests__/file-storage.test.node.js +75 -15
- package/dist/src/session/__tests__/file-storage.test.node.js.map +1 -1
- package/dist/src/session/__tests__/s3-storage.test.d.ts +2 -0
- package/dist/src/session/__tests__/s3-storage.test.d.ts.map +1 -0
- package/dist/src/session/__tests__/{s3-storage.test.node.js → s3-storage.test.js} +161 -75
- package/dist/src/session/__tests__/s3-storage.test.js.map +1 -0
- package/dist/src/session/__tests__/session-manager.test.d.ts +2 -0
- package/dist/src/session/__tests__/session-manager.test.d.ts.map +1 -0
- package/dist/src/session/__tests__/session-manager.test.js +443 -0
- package/dist/src/session/__tests__/session-manager.test.js.map +1 -0
- package/dist/src/session/__tests__/validation.test.js +28 -1
- package/dist/src/session/__tests__/validation.test.js.map +1 -1
- package/dist/src/session/file-storage.d.ts +53 -27
- package/dist/src/session/file-storage.d.ts.map +1 -1
- package/dist/src/session/file-storage.js +103 -52
- package/dist/src/session/file-storage.js.map +1 -1
- package/dist/src/session/index.d.ts +6 -14
- package/dist/src/session/index.d.ts.map +1 -1
- package/dist/src/session/index.js +4 -13
- package/dist/src/session/index.js.map +1 -1
- package/dist/src/session/s3-storage.d.ts +49 -20
- package/dist/src/session/s3-storage.d.ts.map +1 -1
- package/dist/src/session/s3-storage.js +120 -35
- package/dist/src/session/s3-storage.js.map +1 -1
- package/dist/src/session/session-manager.d.ts +87 -0
- package/dist/src/session/session-manager.d.ts.map +1 -0
- package/dist/src/session/session-manager.js +128 -0
- package/dist/src/session/session-manager.js.map +1 -0
- package/dist/src/session/storage.d.ts +20 -12
- package/dist/src/session/storage.d.ts.map +1 -1
- package/dist/src/session/types.d.ts +8 -20
- package/dist/src/session/types.d.ts.map +1 -1
- package/dist/src/session/validation.d.ts +7 -0
- package/dist/src/session/validation.d.ts.map +1 -1
- package/dist/src/session/validation.js +12 -0
- package/dist/src/session/validation.js.map +1 -1
- package/dist/src/{app-state.d.ts → state-store.d.ts} +11 -11
- package/dist/src/state-store.d.ts.map +1 -0
- package/dist/src/{app-state.js → state-store.js} +8 -7
- package/dist/src/state-store.js.map +1 -0
- package/dist/src/structured-output/__tests__/context.test.js +13 -13
- package/dist/src/structured-output/__tests__/context.test.js.map +1 -1
- package/dist/src/structured-output/context.js +1 -1
- package/dist/src/structured-output/context.js.map +1 -1
- package/dist/src/telemetry/__tests__/config.test.d.ts +2 -0
- package/dist/src/telemetry/__tests__/config.test.d.ts.map +1 -0
- package/dist/src/telemetry/__tests__/config.test.js +64 -0
- package/dist/src/telemetry/__tests__/config.test.js.map +1 -0
- package/dist/src/telemetry/__tests__/config.test.node.js +66 -36
- package/dist/src/telemetry/__tests__/config.test.node.js.map +1 -1
- package/dist/src/telemetry/__tests__/meter.test.d.ts +2 -0
- package/dist/src/telemetry/__tests__/meter.test.d.ts.map +1 -0
- package/dist/src/telemetry/__tests__/meter.test.js +624 -0
- package/dist/src/telemetry/__tests__/meter.test.js.map +1 -0
- package/dist/src/telemetry/__tests__/tracer.test.node.js +123 -2
- package/dist/src/telemetry/__tests__/tracer.test.node.js.map +1 -1
- package/dist/src/telemetry/config.d.ts +104 -23
- package/dist/src/telemetry/config.d.ts.map +1 -1
- package/dist/src/telemetry/config.js +152 -43
- package/dist/src/telemetry/config.js.map +1 -1
- package/dist/src/telemetry/index.d.ts +10 -7
- package/dist/src/telemetry/index.d.ts.map +1 -1
- package/dist/src/telemetry/index.js +9 -6
- package/dist/src/telemetry/index.js.map +1 -1
- package/dist/src/telemetry/meter.d.ts +296 -0
- package/dist/src/telemetry/meter.d.ts.map +1 -0
- package/dist/src/telemetry/meter.js +365 -0
- package/dist/src/telemetry/meter.js.map +1 -0
- package/dist/src/telemetry/tracer.d.ts +27 -0
- package/dist/src/telemetry/tracer.d.ts.map +1 -1
- package/dist/src/telemetry/tracer.js +79 -4
- package/dist/src/telemetry/tracer.js.map +1 -1
- package/dist/src/telemetry/types.d.ts +2 -0
- package/dist/src/telemetry/types.d.ts.map +1 -1
- package/dist/src/telemetry/utils.d.ts +10 -0
- package/dist/src/telemetry/utils.d.ts.map +1 -0
- package/dist/src/telemetry/utils.js +13 -0
- package/dist/src/telemetry/utils.js.map +1 -0
- package/dist/src/tools/__tests__/tool-factory.test.d.ts +2 -0
- package/dist/src/tools/__tests__/tool-factory.test.d.ts.map +1 -0
- package/dist/src/tools/__tests__/tool-factory.test.js +98 -0
- package/dist/src/tools/__tests__/tool-factory.test.js.map +1 -0
- package/dist/src/tools/__tests__/tool.test.js +22 -1
- package/dist/src/tools/__tests__/tool.test.js.map +1 -1
- package/dist/src/tools/__tests__/zod-tool.test-d.js +1 -1
- package/dist/src/tools/__tests__/zod-tool.test-d.js.map +1 -1
- package/dist/src/tools/__tests__/zod-tool.test.js +3 -4
- package/dist/src/tools/__tests__/zod-tool.test.js.map +1 -1
- package/dist/src/tools/function-tool.d.ts +26 -3
- package/dist/src/tools/function-tool.d.ts.map +1 -1
- package/dist/src/tools/function-tool.js +88 -3
- package/dist/src/tools/function-tool.js.map +1 -1
- package/dist/src/tools/tool-factory.d.ts +22 -0
- package/dist/src/tools/tool-factory.d.ts.map +1 -0
- package/dist/src/tools/tool-factory.js +55 -0
- package/dist/src/tools/tool-factory.js.map +1 -0
- package/dist/src/tools/tool.d.ts +2 -2
- package/dist/src/tools/tool.d.ts.map +1 -1
- package/dist/src/tools/zod-tool.d.ts +55 -52
- package/dist/src/tools/zod-tool.d.ts.map +1 -1
- package/dist/src/tools/zod-tool.js +7 -61
- package/dist/src/tools/zod-tool.js.map +1 -1
- package/dist/src/tsconfig.tsbuildinfo +1 -1
- package/dist/src/types/__tests__/agent.test.js +11 -0
- package/dist/src/types/__tests__/agent.test.js.map +1 -1
- package/dist/src/types/__tests__/citations.test.d.ts +2 -0
- package/dist/src/types/__tests__/citations.test.d.ts.map +1 -0
- package/dist/src/types/__tests__/citations.test.js +104 -0
- package/dist/src/types/__tests__/citations.test.js.map +1 -0
- package/dist/src/types/__tests__/media.test.js +22 -16
- package/dist/src/types/__tests__/media.test.js.map +1 -1
- package/dist/src/types/__tests__/messages.test.js +26 -0
- package/dist/src/types/__tests__/messages.test.js.map +1 -1
- package/dist/src/types/agent.d.ts +82 -7
- package/dist/src/types/agent.d.ts.map +1 -1
- package/dist/src/types/agent.js +9 -0
- package/dist/src/types/agent.js.map +1 -1
- package/dist/src/types/citations.d.ts +180 -0
- package/dist/src/types/citations.d.ts.map +1 -0
- package/dist/src/types/citations.js +45 -0
- package/dist/src/types/citations.js.map +1 -0
- package/dist/src/types/media.d.ts +27 -30
- package/dist/src/types/media.d.ts.map +1 -1
- package/dist/src/types/media.js +15 -56
- package/dist/src/types/media.js.map +1 -1
- package/dist/src/types/messages.d.ts +23 -5
- package/dist/src/types/messages.d.ts.map +1 -1
- package/dist/src/types/messages.js +26 -26
- package/dist/src/types/messages.js.map +1 -1
- package/dist/src/types/serializable.d.ts +34 -4
- package/dist/src/types/serializable.d.ts.map +1 -1
- package/dist/src/types/serializable.js +31 -2
- package/dist/src/types/serializable.js.map +1 -1
- package/dist/src/vended-tools/bash/__tests__/bash.test.node.js +5 -4
- package/dist/src/vended-tools/bash/__tests__/bash.test.node.js.map +1 -1
- package/dist/src/vended-tools/bash/bash.d.ts.map +1 -1
- package/dist/src/vended-tools/bash/bash.js +1 -2
- package/dist/src/vended-tools/bash/bash.js.map +1 -1
- package/dist/src/vended-tools/file-editor/__tests__/file-editor.test.node.d.ts.map +1 -0
- package/dist/src/vended-tools/{file_editor → file-editor}/__tests__/file-editor.test.node.js +11 -4
- package/dist/src/vended-tools/file-editor/__tests__/file-editor.test.node.js.map +1 -0
- package/dist/src/vended-tools/{file_editor → file-editor}/file-editor.d.ts +1 -1
- package/dist/src/vended-tools/{file_editor → file-editor}/file-editor.d.ts.map +1 -1
- package/dist/src/vended-tools/{file_editor → file-editor}/file-editor.js +3 -3
- package/dist/src/vended-tools/{file_editor → file-editor}/file-editor.js.map +1 -1
- package/dist/src/vended-tools/{file_editor → file-editor}/index.d.ts.map +1 -1
- package/dist/src/vended-tools/file-editor/index.js.map +1 -0
- package/dist/src/vended-tools/{file_editor → file-editor}/types.d.ts.map +1 -1
- package/dist/src/vended-tools/file-editor/types.js.map +1 -0
- package/dist/src/vended-tools/http-request/__tests__/http-request.test.d.ts.map +1 -0
- package/dist/src/vended-tools/{http_request → http-request}/__tests__/http-request.test.js.map +1 -1
- package/dist/src/vended-tools/http-request/http-request.d.ts.map +1 -0
- package/dist/src/vended-tools/{http_request → http-request}/http-request.js +1 -2
- package/dist/src/vended-tools/http-request/http-request.js.map +1 -0
- package/dist/src/vended-tools/{http_request → http-request}/index.d.ts.map +1 -1
- package/dist/src/vended-tools/http-request/index.js.map +1 -0
- package/dist/src/vended-tools/{http_request → http-request}/types.d.ts.map +1 -1
- package/dist/src/vended-tools/http-request/types.js.map +1 -0
- package/dist/src/vended-tools/notebook/__tests__/notebook.test.js +5 -4
- package/dist/src/vended-tools/notebook/__tests__/notebook.test.js.map +1 -1
- package/dist/src/vended-tools/notebook/notebook.d.ts +1 -1
- package/dist/src/vended-tools/notebook/notebook.js +2 -2
- package/dist/src/vended-tools/notebook/notebook.js.map +1 -1
- package/package.json +66 -12
- package/dist/src/__fixtures__/mock-hook-provider.d.ts +0 -10
- package/dist/src/__fixtures__/mock-hook-provider.d.ts.map +0 -1
- package/dist/src/__fixtures__/mock-hook-provider.js.map +0 -1
- package/dist/src/__tests__/app-state.test.d.ts +0 -2
- package/dist/src/__tests__/app-state.test.d.ts.map +0 -1
- package/dist/src/__tests__/app-state.test.js.map +0 -1
- package/dist/src/app-state.d.ts.map +0 -1
- package/dist/src/app-state.js.map +0 -1
- package/dist/src/multiagent/base.d.ts +0 -25
- package/dist/src/multiagent/base.d.ts.map +0 -1
- package/dist/src/multiagent/base.js +0 -2
- package/dist/src/multiagent/base.js.map +0 -1
- package/dist/src/registry/registry.d.ts +0 -117
- package/dist/src/registry/registry.d.ts.map +0 -1
- package/dist/src/registry/registry.js +0 -298
- package/dist/src/registry/registry.js.map +0 -1
- package/dist/src/session/__tests__/s3-storage.test.node.d.ts +0 -2
- package/dist/src/session/__tests__/s3-storage.test.node.d.ts.map +0 -1
- package/dist/src/session/__tests__/s3-storage.test.node.js.map +0 -1
- package/dist/src/vended-tools/file_editor/__tests__/file-editor.test.node.d.ts.map +0 -1
- package/dist/src/vended-tools/file_editor/__tests__/file-editor.test.node.js.map +0 -1
- package/dist/src/vended-tools/file_editor/index.js.map +0 -1
- package/dist/src/vended-tools/file_editor/types.js.map +0 -1
- package/dist/src/vended-tools/http_request/__tests__/http-request.test.d.ts.map +0 -1
- package/dist/src/vended-tools/http_request/http-request.d.ts.map +0 -1
- package/dist/src/vended-tools/http_request/http-request.js.map +0 -1
- package/dist/src/vended-tools/http_request/index.js.map +0 -1
- package/dist/src/vended-tools/http_request/types.js.map +0 -1
- /package/dist/src/vended-tools/{file_editor → file-editor}/__tests__/file-editor.test.node.d.ts +0 -0
- /package/dist/src/vended-tools/{file_editor → file-editor}/index.d.ts +0 -0
- /package/dist/src/vended-tools/{file_editor → file-editor}/index.js +0 -0
- /package/dist/src/vended-tools/{file_editor → file-editor}/types.d.ts +0 -0
- /package/dist/src/vended-tools/{file_editor → file-editor}/types.js +0 -0
- /package/dist/src/vended-tools/{http_request → http-request}/__tests__/http-request.test.d.ts +0 -0
- /package/dist/src/vended-tools/{http_request → http-request}/__tests__/http-request.test.js +0 -0
- /package/dist/src/vended-tools/{http_request → http-request}/http-request.d.ts +0 -0
- /package/dist/src/vended-tools/{http_request → http-request}/index.d.ts +0 -0
- /package/dist/src/vended-tools/{http_request → http-request}/index.js +0 -0
- /package/dist/src/vended-tools/{http_request → http-request}/types.d.ts +0 -0
- /package/dist/src/vended-tools/{http_request → http-request}/types.js +0 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin interface for extending agent functionality.
|
|
3
|
+
*
|
|
4
|
+
* This module defines the Plugin interface, which provides a composable way to
|
|
5
|
+
* add behavior changes to agents through hook registration and custom initialization.
|
|
6
|
+
*/
|
|
7
|
+
import type { Tool } from '../tools/tool.js';
|
|
8
|
+
import type { LocalAgent } from '../types/agent.js';
|
|
9
|
+
/**
|
|
10
|
+
* Interface for objects that extend agent functionality.
|
|
11
|
+
*
|
|
12
|
+
* Plugins provide a composable way to add behavior changes to agents by registering
|
|
13
|
+
* hook callbacks in their `initAgent` method. Each plugin must have a unique name
|
|
14
|
+
* for identification, logging, and duplicate prevention.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* class LoggingPlugin implements Plugin {
|
|
19
|
+
* get name(): string {
|
|
20
|
+
* return 'logging-plugin'
|
|
21
|
+
* }
|
|
22
|
+
*
|
|
23
|
+
* initAgent(agent: LocalAgent): void {
|
|
24
|
+
* agent.addHook(BeforeInvocationEvent, (event) => {
|
|
25
|
+
* console.log('Agent invocation started')
|
|
26
|
+
* })
|
|
27
|
+
* }
|
|
28
|
+
* }
|
|
29
|
+
*
|
|
30
|
+
* const agent = new Agent({
|
|
31
|
+
* model,
|
|
32
|
+
* plugins: [new LoggingPlugin()],
|
|
33
|
+
* })
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @example With tools
|
|
37
|
+
* ```typescript
|
|
38
|
+
* class MyToolPlugin implements Plugin {
|
|
39
|
+
* get name(): string {
|
|
40
|
+
* return 'my-tool-plugin'
|
|
41
|
+
* }
|
|
42
|
+
*
|
|
43
|
+
* getTools(): Tool[] {
|
|
44
|
+
* return [myTool]
|
|
45
|
+
* }
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export interface Plugin {
|
|
50
|
+
/**
|
|
51
|
+
* A stable string identifier for the plugin.
|
|
52
|
+
* Used for logging, duplicate detection, and plugin management.
|
|
53
|
+
*
|
|
54
|
+
* For strands-vended plugins, names should be prefixed with `strands:`.
|
|
55
|
+
*/
|
|
56
|
+
readonly name: string;
|
|
57
|
+
/**
|
|
58
|
+
* Initialize the plugin with the agent instance.
|
|
59
|
+
*
|
|
60
|
+
* Implement this method to register hooks and perform custom initialization.
|
|
61
|
+
* Tool registration from {@link getTools} is handled automatically by the PluginRegistry.
|
|
62
|
+
*
|
|
63
|
+
* @param agent - The agent instance this plugin is being attached to
|
|
64
|
+
*/
|
|
65
|
+
initAgent(agent: LocalAgent): void | Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Returns tools provided by this plugin for auto-registration.
|
|
68
|
+
* Implement to provide plugin-specific tools.
|
|
69
|
+
*
|
|
70
|
+
* @returns Array of tools to register with the agent
|
|
71
|
+
*/
|
|
72
|
+
getTools?(): Tool[];
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../src/plugins/plugin.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAEnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,MAAM,WAAW,MAAM;IACrB;;;;;OAKG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IAErB;;;;;;;OAOG;IACH,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAElD;;;;;OAKG;IACH,QAAQ,CAAC,IAAI,IAAI,EAAE,CAAA;CACpB"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin interface for extending agent functionality.
|
|
3
|
+
*
|
|
4
|
+
* This module defines the Plugin interface, which provides a composable way to
|
|
5
|
+
* add behavior changes to agents through hook registration and custom initialization.
|
|
6
|
+
*/
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../../src/plugins/plugin.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin registry for managing plugins attached to an agent.
|
|
3
|
+
*/
|
|
4
|
+
import type { Plugin } from './plugin.js';
|
|
5
|
+
import type { LocalAgent } from '../types/agent.js';
|
|
6
|
+
/**
|
|
7
|
+
* Registry for managing plugins attached to an agent.
|
|
8
|
+
*
|
|
9
|
+
* Holds pending plugins and initializes them on first use.
|
|
10
|
+
* Handles duplicate detection, tool registration, and calls each plugin's initAgent method.
|
|
11
|
+
*/
|
|
12
|
+
export declare class PluginRegistry {
|
|
13
|
+
private readonly _plugins;
|
|
14
|
+
private readonly _pending;
|
|
15
|
+
constructor(plugins?: Plugin[]);
|
|
16
|
+
/**
|
|
17
|
+
* Initialize all pending plugins with the agent.
|
|
18
|
+
* Safe to call multiple times — only runs once per pending batch.
|
|
19
|
+
*
|
|
20
|
+
* @param agent - The agent instance to initialize plugins with
|
|
21
|
+
*/
|
|
22
|
+
initialize(agent: LocalAgent): Promise<void>;
|
|
23
|
+
private _addAndInit;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../src/plugins/registry.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAEnD;;;;;GAKG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAqB;IAC9C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAU;gBAEvB,OAAO,GAAE,MAAM,EAAO;IAKlC;;;;;OAKG;IACG,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;YAOpC,WAAW;CAa1B"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin registry for managing plugins attached to an agent.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Registry for managing plugins attached to an agent.
|
|
6
|
+
*
|
|
7
|
+
* Holds pending plugins and initializes them on first use.
|
|
8
|
+
* Handles duplicate detection, tool registration, and calls each plugin's initAgent method.
|
|
9
|
+
*/
|
|
10
|
+
export class PluginRegistry {
|
|
11
|
+
_plugins;
|
|
12
|
+
_pending;
|
|
13
|
+
constructor(plugins = []) {
|
|
14
|
+
this._plugins = new Map();
|
|
15
|
+
this._pending = [...plugins];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Initialize all pending plugins with the agent.
|
|
19
|
+
* Safe to call multiple times — only runs once per pending batch.
|
|
20
|
+
*
|
|
21
|
+
* @param agent - The agent instance to initialize plugins with
|
|
22
|
+
*/
|
|
23
|
+
async initialize(agent) {
|
|
24
|
+
while (this._pending.length > 0) {
|
|
25
|
+
const plugin = this._pending.shift();
|
|
26
|
+
await this._addAndInit(plugin, agent);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
async _addAndInit(plugin, agent) {
|
|
30
|
+
if (this._plugins.has(plugin.name)) {
|
|
31
|
+
throw new Error(`plugin_name=<${plugin.name}> | plugin already registered`);
|
|
32
|
+
}
|
|
33
|
+
this._plugins.set(plugin.name, plugin);
|
|
34
|
+
const tools = plugin.getTools?.() ?? [];
|
|
35
|
+
if (tools.length > 0) {
|
|
36
|
+
agent.toolRegistry.add(tools);
|
|
37
|
+
}
|
|
38
|
+
await plugin.initAgent(agent);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../../src/plugins/registry.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH;;;;;GAKG;AACH,MAAM,OAAO,cAAc;IACR,QAAQ,CAAqB;IAC7B,QAAQ,CAAU;IAEnC,YAAY,UAAoB,EAAE;QAChC,IAAI,CAAC,QAAQ,GAAG,IAAI,GAAG,EAAE,CAAA;QACzB,IAAI,CAAC,QAAQ,GAAG,CAAC,GAAG,OAAO,CAAC,CAAA;IAC9B,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,UAAU,CAAC,KAAiB;QAChC,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAChC,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAG,CAAA;YACrC,MAAM,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;QACvC,CAAC;IACH,CAAC;IAEO,KAAK,CAAC,WAAW,CAAC,MAAc,EAAE,KAAiB;QACzD,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;YACnC,MAAM,IAAI,KAAK,CAAC,gBAAgB,MAAM,CAAC,IAAI,+BAA+B,CAAC,CAAA;QAC7E,CAAC;QACD,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;QAEtC,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,EAAE,EAAE,IAAI,EAAE,CAAA;QACvC,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACrB,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;QAC/B,CAAC;QAED,MAAM,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;IAC/B,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-registry.test.d.ts","sourceRoot":"","sources":["../../../../src/registry/__tests__/tool-registry.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach } from 'vitest';
|
|
2
|
+
import { ToolRegistry } from '../tool-registry.js';
|
|
3
|
+
import { ToolValidationError } from '../../errors.js';
|
|
4
|
+
import { ToolStreamEvent } from '../../tools/tool.js';
|
|
5
|
+
import { ToolResultBlock } from '../../types/messages.js';
|
|
6
|
+
const createMockTool = (overrides = {}) => ({
|
|
7
|
+
name: 'valid-tool',
|
|
8
|
+
description: 'A valid tool description.',
|
|
9
|
+
toolSpec: {
|
|
10
|
+
name: 'valid-tool',
|
|
11
|
+
description: 'A valid tool description.',
|
|
12
|
+
inputSchema: { type: 'object', properties: {} },
|
|
13
|
+
},
|
|
14
|
+
stream: async function* () {
|
|
15
|
+
yield new ToolStreamEvent({ data: 'mock data' });
|
|
16
|
+
return new ToolResultBlock({ toolUseId: '', status: 'success', content: [] });
|
|
17
|
+
},
|
|
18
|
+
...overrides,
|
|
19
|
+
});
|
|
20
|
+
describe('ToolRegistry', () => {
|
|
21
|
+
let registry;
|
|
22
|
+
beforeEach(() => {
|
|
23
|
+
registry = new ToolRegistry();
|
|
24
|
+
});
|
|
25
|
+
describe('add', () => {
|
|
26
|
+
it('registers a single tool', () => {
|
|
27
|
+
const tool = createMockTool();
|
|
28
|
+
registry.add(tool);
|
|
29
|
+
expect(registry.list()).toStrictEqual([tool]);
|
|
30
|
+
});
|
|
31
|
+
it('registers an array of tools', () => {
|
|
32
|
+
const tool1 = createMockTool({ name: 'tool-1' });
|
|
33
|
+
const tool2 = createMockTool({ name: 'tool-2' });
|
|
34
|
+
registry.add([tool1, tool2]);
|
|
35
|
+
expect(registry.list()).toStrictEqual([tool1, tool2]);
|
|
36
|
+
});
|
|
37
|
+
it('throws ToolValidationError for a duplicate tool name', () => {
|
|
38
|
+
registry.add(createMockTool({ name: 'duplicate' }));
|
|
39
|
+
expect(() => registry.add(createMockTool({ name: 'duplicate' }))).toThrow(ToolValidationError);
|
|
40
|
+
expect(() => registry.add(createMockTool({ name: 'duplicate' }))).toThrow("Tool with name 'duplicate' already registered");
|
|
41
|
+
});
|
|
42
|
+
it('throws ToolValidationError for an invalid tool name pattern', () => {
|
|
43
|
+
expect(() => registry.add(createMockTool({ name: 'invalid name!' }))).toThrow(ToolValidationError);
|
|
44
|
+
expect(() => registry.add(createMockTool({ name: 'invalid name!' }))).toThrow('Tool name must contain only alphanumeric characters, hyphens, and underscores');
|
|
45
|
+
});
|
|
46
|
+
it('throws ToolValidationError for a tool name that is too long', () => {
|
|
47
|
+
expect(() => registry.add(createMockTool({ name: 'a'.repeat(65) }))).toThrow(ToolValidationError);
|
|
48
|
+
expect(() => registry.add(createMockTool({ name: 'a'.repeat(65) }))).toThrow('Tool name must be between 1 and 64 characters');
|
|
49
|
+
});
|
|
50
|
+
it('throws ToolValidationError for a tool name that is too short', () => {
|
|
51
|
+
expect(() => registry.add(createMockTool({ name: '' }))).toThrow(ToolValidationError);
|
|
52
|
+
expect(() => registry.add(createMockTool({ name: '' }))).toThrow('Tool name must be between 1 and 64 characters');
|
|
53
|
+
});
|
|
54
|
+
it('throws ToolValidationError for a non-string tool name', () => {
|
|
55
|
+
// @ts-expect-error - Testing invalid type for name
|
|
56
|
+
expect(() => registry.add(createMockTool({ name: 123 }))).toThrow(ToolValidationError);
|
|
57
|
+
// @ts-expect-error - Testing invalid type for name
|
|
58
|
+
expect(() => registry.add(createMockTool({ name: 123 }))).toThrow('Tool name must be a string');
|
|
59
|
+
});
|
|
60
|
+
it('throws ToolValidationError for an invalid description', () => {
|
|
61
|
+
// @ts-expect-error - Testing invalid type for description
|
|
62
|
+
expect(() => registry.add(createMockTool({ description: 123 }))).toThrow(ToolValidationError);
|
|
63
|
+
// @ts-expect-error - Testing invalid type for description
|
|
64
|
+
expect(() => registry.add(createMockTool({ description: 123 }))).toThrow('Tool description must be a non-empty string');
|
|
65
|
+
});
|
|
66
|
+
it('throws ToolValidationError for an empty string description', () => {
|
|
67
|
+
expect(() => registry.add(createMockTool({ description: '' }))).toThrow(ToolValidationError);
|
|
68
|
+
expect(() => registry.add(createMockTool({ description: '' }))).toThrow('Tool description must be a non-empty string');
|
|
69
|
+
});
|
|
70
|
+
it('allows a tool with a null or undefined description', () => {
|
|
71
|
+
const tool1 = createMockTool({ name: 'tool-1' });
|
|
72
|
+
// @ts-expect-error - Testing explicit undefined description
|
|
73
|
+
tool1.description = undefined;
|
|
74
|
+
const tool2 = createMockTool({ name: 'tool-2' });
|
|
75
|
+
// @ts-expect-error - Testing explicit null description
|
|
76
|
+
tool2.description = null;
|
|
77
|
+
registry.add([tool1, tool2]);
|
|
78
|
+
expect(registry.list()).toHaveLength(2);
|
|
79
|
+
});
|
|
80
|
+
it('registers a tool with a name at the maximum length', () => {
|
|
81
|
+
const tool = createMockTool({ name: 'a'.repeat(64) });
|
|
82
|
+
expect(() => registry.add(tool)).not.toThrow();
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
describe('get', () => {
|
|
86
|
+
it('retrieves a tool by name', () => {
|
|
87
|
+
const tool = createMockTool({ name: 'find-me' });
|
|
88
|
+
registry.add(tool);
|
|
89
|
+
expect(registry.get('find-me')).toBe(tool);
|
|
90
|
+
});
|
|
91
|
+
it('returns undefined for a non-existent tool', () => {
|
|
92
|
+
expect(registry.get('non-existent')).toBeUndefined();
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
describe('remove', () => {
|
|
96
|
+
it('removes a tool by name', () => {
|
|
97
|
+
registry.add(createMockTool({ name: 'remove-me' }));
|
|
98
|
+
registry.remove('remove-me');
|
|
99
|
+
expect(registry.get('remove-me')).toBeUndefined();
|
|
100
|
+
});
|
|
101
|
+
it('does not throw when removing a non-existent tool', () => {
|
|
102
|
+
expect(() => registry.remove('non-existent')).not.toThrow();
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
describe('list', () => {
|
|
106
|
+
it('returns an empty array when no tools are registered', () => {
|
|
107
|
+
expect(registry.list()).toStrictEqual([]);
|
|
108
|
+
});
|
|
109
|
+
it('returns all registered tools', () => {
|
|
110
|
+
const tool1 = createMockTool({ name: 'tool-1' });
|
|
111
|
+
const tool2 = createMockTool({ name: 'tool-2' });
|
|
112
|
+
registry.add([tool1, tool2]);
|
|
113
|
+
expect(registry.list()).toStrictEqual([tool1, tool2]);
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
describe('constructor', () => {
|
|
117
|
+
it('accepts initial tools', () => {
|
|
118
|
+
const tool = createMockTool();
|
|
119
|
+
const reg = new ToolRegistry([tool]);
|
|
120
|
+
expect(reg.list()).toStrictEqual([tool]);
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
//# sourceMappingURL=tool-registry.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-registry.test.js","sourceRoot":"","sources":["../../../../src/registry/__tests__/tool-registry.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAErD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAEzD,MAAM,cAAc,GAAG,CAAC,YAA2B,EAAE,EAAQ,EAAE,CAAC,CAAC;IAC/D,IAAI,EAAE,YAAY;IAClB,WAAW,EAAE,2BAA2B;IACxC,QAAQ,EAAE;QACR,IAAI,EAAE,YAAY;QAClB,WAAW,EAAE,2BAA2B;QACxC,WAAW,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,EAAE;KAChD;IACD,MAAM,EAAE,KAAK,SAAS,CAAC;QACrB,MAAM,IAAI,eAAe,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,CAAA;QAChD,OAAO,IAAI,eAAe,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAA;IAC/E,CAAC;IACD,GAAG,SAAS;CACb,CAAC,CAAA;AAEF,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,IAAI,QAAsB,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,EAAE,CAAC,CAAC,aAAa,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAA;QACvD,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEF,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;QAC3B,EAAE,CAAC,uBAAuB,EAAE,GAAG,EAAE;YAC/B,MAAM,IAAI,GAAG,cAAc,EAAE,CAAA;YAC7B,MAAM,GAAG,GAAG,IAAI,YAAY,CAAC,CAAC,IAAI,CAAC,CAAC,CAAA;YACpC,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,CAAC,CAAA;QAC1C,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -1,35 +1,47 @@
|
|
|
1
|
-
import { Registry } from './registry.js';
|
|
2
1
|
import type { Tool } from '../tools/tool.js';
|
|
3
2
|
/**
|
|
4
|
-
*
|
|
5
|
-
* It adds validation for tool properties and ensures unique tool names.
|
|
3
|
+
* Registry for managing Tool instances with name-based CRUDL operations.
|
|
6
4
|
*/
|
|
7
|
-
export declare class ToolRegistry
|
|
5
|
+
export declare class ToolRegistry {
|
|
6
|
+
private _tools;
|
|
8
7
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* @
|
|
8
|
+
* Creates a new ToolRegistry, optionally pre-populated with tools.
|
|
9
|
+
*
|
|
10
|
+
* @param tools - Optional initial tools to register
|
|
11
|
+
*/
|
|
12
|
+
constructor(tools?: Tool[]);
|
|
13
|
+
/**
|
|
14
|
+
* Registers one or more tools.
|
|
15
|
+
*
|
|
16
|
+
* @param tool - A single tool or array of tools to register
|
|
17
|
+
* @throws ToolValidationError If a tool's properties are invalid or its name is already registered
|
|
12
18
|
*/
|
|
13
|
-
|
|
19
|
+
add(tool: Tool | Tool[]): void;
|
|
14
20
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* @param
|
|
18
|
-
* @
|
|
21
|
+
* Retrieves a tool by name.
|
|
22
|
+
*
|
|
23
|
+
* @param name - The name of the tool to retrieve
|
|
24
|
+
* @returns The tool if found, otherwise undefined
|
|
25
|
+
*/
|
|
26
|
+
get(name: string): Tool | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Removes a tool by name. No-op if the tool does not exist.
|
|
29
|
+
*
|
|
30
|
+
* @param name - The name of the tool to remove
|
|
19
31
|
*/
|
|
20
|
-
|
|
32
|
+
remove(name: string): void;
|
|
21
33
|
/**
|
|
22
|
-
*
|
|
34
|
+
* Returns all registered tools.
|
|
23
35
|
*
|
|
24
|
-
* @
|
|
25
|
-
* @returns The tool if found, otherwise undefined.
|
|
36
|
+
* @returns Array of all registered tools
|
|
26
37
|
*/
|
|
27
|
-
|
|
38
|
+
list(): Tool[];
|
|
28
39
|
/**
|
|
29
|
-
*
|
|
40
|
+
* Validates a tool before registration.
|
|
30
41
|
*
|
|
31
|
-
* @param
|
|
42
|
+
* @param tool - The tool to validate
|
|
43
|
+
* @throws ToolValidationError If the tool's properties are invalid or its name is already registered
|
|
32
44
|
*/
|
|
33
|
-
|
|
45
|
+
private _validate;
|
|
34
46
|
}
|
|
35
47
|
//# sourceMappingURL=tool-registry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-registry.d.ts","sourceRoot":"","sources":["../../../src/registry/tool-registry.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"tool-registry.d.ts","sourceRoot":"","sources":["../../../src/registry/tool-registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAG5C;;GAEG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAA+B;IAE7C;;;;OAIG;gBACS,KAAK,CAAC,EAAE,IAAI,EAAE;IAM1B;;;;;OAKG;IACH,GAAG,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,EAAE,GAAG,IAAI;IAQ9B;;;;;OAKG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS;IAInC;;;;OAIG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAI1B;;;;OAIG;IACH,IAAI,IAAI,IAAI,EAAE;IAId;;;;;OAKG;IACH,OAAO,CAAC,SAAS;CAwBlB"}
|
|
@@ -1,180 +1,82 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ToolStreamEvent } from '../tools/tool.js';
|
|
3
|
-
import { ToolResultBlock } from '../types/messages.js';
|
|
1
|
+
import { ToolValidationError } from '../errors.js';
|
|
4
2
|
/**
|
|
5
|
-
*
|
|
6
|
-
* It adds validation for tool properties and ensures unique tool names.
|
|
3
|
+
* Registry for managing Tool instances with name-based CRUDL operations.
|
|
7
4
|
*/
|
|
8
|
-
export class ToolRegistry
|
|
5
|
+
export class ToolRegistry {
|
|
6
|
+
_tools = new Map();
|
|
9
7
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* @
|
|
8
|
+
* Creates a new ToolRegistry, optionally pre-populated with tools.
|
|
9
|
+
*
|
|
10
|
+
* @param tools - Optional initial tools to register
|
|
11
|
+
*/
|
|
12
|
+
constructor(tools) {
|
|
13
|
+
if (tools) {
|
|
14
|
+
this.add(tools);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Registers one or more tools.
|
|
19
|
+
*
|
|
20
|
+
* @param tool - A single tool or array of tools to register
|
|
21
|
+
* @throws ToolValidationError If a tool's properties are invalid or its name is already registered
|
|
13
22
|
*/
|
|
14
|
-
|
|
15
|
-
|
|
23
|
+
add(tool) {
|
|
24
|
+
const tools = Array.isArray(tool) ? tool : [tool];
|
|
25
|
+
for (const t of tools) {
|
|
26
|
+
this._validate(t);
|
|
27
|
+
this._tools.set(t.name, t);
|
|
28
|
+
}
|
|
16
29
|
}
|
|
17
30
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* @param
|
|
21
|
-
* @
|
|
31
|
+
* Retrieves a tool by name.
|
|
32
|
+
*
|
|
33
|
+
* @param name - The name of the tool to retrieve
|
|
34
|
+
* @returns The tool if found, otherwise undefined
|
|
22
35
|
*/
|
|
23
|
-
|
|
24
|
-
|
|
36
|
+
get(name) {
|
|
37
|
+
return this._tools.get(name);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Removes a tool by name. No-op if the tool does not exist.
|
|
41
|
+
*
|
|
42
|
+
* @param name - The name of the tool to remove
|
|
43
|
+
*/
|
|
44
|
+
remove(name) {
|
|
45
|
+
this._tools.delete(name);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Returns all registered tools.
|
|
49
|
+
*
|
|
50
|
+
* @returns Array of all registered tools
|
|
51
|
+
*/
|
|
52
|
+
list() {
|
|
53
|
+
return Array.from(this._tools.values());
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Validates a tool before registration.
|
|
57
|
+
*
|
|
58
|
+
* @param tool - The tool to validate
|
|
59
|
+
* @throws ToolValidationError If the tool's properties are invalid or its name is already registered
|
|
60
|
+
*/
|
|
61
|
+
_validate(tool) {
|
|
25
62
|
if (typeof tool.name !== 'string') {
|
|
26
|
-
throw new
|
|
63
|
+
throw new ToolValidationError('Tool name must be a string');
|
|
27
64
|
}
|
|
28
|
-
// Validate tool name length (1-64 characters)
|
|
29
65
|
if (tool.name.length < 1 || tool.name.length > 64) {
|
|
30
|
-
throw new
|
|
66
|
+
throw new ToolValidationError('Tool name must be between 1 and 64 characters');
|
|
31
67
|
}
|
|
32
|
-
// Validate tool name pattern
|
|
33
68
|
const validNamePattern = /^[a-zA-Z0-9_-]+$/;
|
|
34
69
|
if (!validNamePattern.test(tool.name)) {
|
|
35
|
-
throw new
|
|
70
|
+
throw new ToolValidationError('Tool name must contain only alphanumeric characters, hyphens, and underscores');
|
|
36
71
|
}
|
|
37
|
-
// Validate tool description if present
|
|
38
72
|
if (tool.description !== undefined && tool.description !== null) {
|
|
39
73
|
if (typeof tool.description !== 'string' || tool.description.length < 1) {
|
|
40
|
-
throw new
|
|
74
|
+
throw new ToolValidationError('Tool description must be a non-empty string');
|
|
41
75
|
}
|
|
42
76
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (hasDuplicate) {
|
|
46
|
-
throw new ValidationError(`Tool with name '${tool.name}' already registered`);
|
|
77
|
+
if (this._tools.has(tool.name)) {
|
|
78
|
+
throw new ToolValidationError(`Tool with name '${tool.name}' already registered`);
|
|
47
79
|
}
|
|
48
80
|
}
|
|
49
|
-
/**
|
|
50
|
-
* Retrieves the first tool that matches the given name.
|
|
51
|
-
*
|
|
52
|
-
* @param name - The name of the tool to retrieve.
|
|
53
|
-
* @returns The tool if found, otherwise undefined.
|
|
54
|
-
*/
|
|
55
|
-
getByName(name) {
|
|
56
|
-
return this.values().find((tool) => tool.name === name);
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Finds and removes the first tool that matches the given name.
|
|
60
|
-
*
|
|
61
|
-
* @param name - The name of the tool to remove.
|
|
62
|
-
*/
|
|
63
|
-
removeByName(name) {
|
|
64
|
-
this.findRemove((tool) => tool.name === name);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
// Unit tests
|
|
68
|
-
if (import.meta.vitest) {
|
|
69
|
-
const { describe, it, expect, beforeEach } = import.meta.vitest;
|
|
70
|
-
// Mock Tool definition for testing purposes
|
|
71
|
-
const createMockTool = (overrides = {}) => ({
|
|
72
|
-
name: 'valid-tool',
|
|
73
|
-
description: 'A valid tool description.',
|
|
74
|
-
toolSpec: {
|
|
75
|
-
name: 'valid-tool',
|
|
76
|
-
description: 'A valid tool description.',
|
|
77
|
-
inputSchema: { type: 'object', properties: {} },
|
|
78
|
-
},
|
|
79
|
-
stream: async function* () {
|
|
80
|
-
// Mock stream implementation
|
|
81
|
-
yield new ToolStreamEvent({ data: 'mock data' });
|
|
82
|
-
return new ToolResultBlock({ toolUseId: '', status: 'success', content: [] });
|
|
83
|
-
},
|
|
84
|
-
...overrides,
|
|
85
|
-
});
|
|
86
|
-
describe('ToolRegistry', () => {
|
|
87
|
-
let registry;
|
|
88
|
-
beforeEach(() => {
|
|
89
|
-
registry = new ToolRegistry();
|
|
90
|
-
});
|
|
91
|
-
it('should register a valid tool successfully', () => {
|
|
92
|
-
const tool = createMockTool();
|
|
93
|
-
expect(() => registry.add(tool)).not.toThrow();
|
|
94
|
-
expect(registry.values()).toHaveLength(1);
|
|
95
|
-
expect(registry.values()[0]?.name).toBe('valid-tool');
|
|
96
|
-
});
|
|
97
|
-
it('should throw ValidationError for a duplicate tool name', () => {
|
|
98
|
-
const tool1 = createMockTool({ name: 'duplicate-name' });
|
|
99
|
-
const tool2 = createMockTool({ name: 'duplicate-name' });
|
|
100
|
-
registry.add(tool1);
|
|
101
|
-
expect(() => registry.add(tool2)).toThrow(ValidationError);
|
|
102
|
-
expect(() => registry.add(tool2)).toThrow("Tool with name 'duplicate-name' already registered");
|
|
103
|
-
});
|
|
104
|
-
it('should throw ValidationError for an invalid tool name pattern', () => {
|
|
105
|
-
const tool = createMockTool({ name: 'invalid name!' });
|
|
106
|
-
expect(() => registry.add(tool)).toThrow(ValidationError);
|
|
107
|
-
expect(() => registry.add(tool)).toThrow('Tool name must contain only alphanumeric characters, hyphens, and underscores');
|
|
108
|
-
});
|
|
109
|
-
it('should throw ValidationError for a tool name that is too long', () => {
|
|
110
|
-
const longName = 'a'.repeat(65);
|
|
111
|
-
const tool = createMockTool({ name: longName });
|
|
112
|
-
expect(() => registry.add(tool)).toThrow(ValidationError);
|
|
113
|
-
expect(() => registry.add(tool)).toThrow('Tool name must be between 1 and 64 characters');
|
|
114
|
-
});
|
|
115
|
-
it('should throw ValidationError for a tool name that is too short', () => {
|
|
116
|
-
const tool = createMockTool({ name: '' });
|
|
117
|
-
expect(() => registry.add(tool)).toThrow(ValidationError);
|
|
118
|
-
expect(() => registry.add(tool)).toThrow('Tool name must be between 1 and 64 characters');
|
|
119
|
-
});
|
|
120
|
-
it('should throw ValidationError for an invalid description', () => {
|
|
121
|
-
// @ts-expect-error - Testing invalid type for description
|
|
122
|
-
const tool = createMockTool({ description: 123 });
|
|
123
|
-
expect(() => registry.add(tool)).toThrow(ValidationError);
|
|
124
|
-
expect(() => registry.add(tool)).toThrow('Tool description must be a non-empty string');
|
|
125
|
-
});
|
|
126
|
-
it('should throw ValidationError for an empty string description', () => {
|
|
127
|
-
const tool = createMockTool({ description: '' });
|
|
128
|
-
expect(() => registry.add(tool)).toThrow(ValidationError);
|
|
129
|
-
expect(() => registry.add(tool)).toThrow('Tool description must be a non-empty string');
|
|
130
|
-
});
|
|
131
|
-
it('should allow a tool with a null or undefined description', () => {
|
|
132
|
-
const tool1 = createMockTool();
|
|
133
|
-
// @ts-expect-error - Testing explicit undefined description
|
|
134
|
-
tool1.description = undefined;
|
|
135
|
-
const tool2 = createMockTool();
|
|
136
|
-
tool2.name = 'another-valid-tool';
|
|
137
|
-
// @ts-expect-error - Testing explicit null description
|
|
138
|
-
tool2.description = null;
|
|
139
|
-
expect(() => registry.add(tool1)).not.toThrow();
|
|
140
|
-
expect(() => registry.add(tool2)).not.toThrow();
|
|
141
|
-
});
|
|
142
|
-
it('should retrieve a tool by its name', () => {
|
|
143
|
-
const tool = createMockTool({ name: 'find-me' });
|
|
144
|
-
registry.add(tool);
|
|
145
|
-
const foundTool = registry.getByName('find-me');
|
|
146
|
-
expect(foundTool).toBe(tool);
|
|
147
|
-
});
|
|
148
|
-
it('should return undefined when getting a tool by a name that does not exist', () => {
|
|
149
|
-
const foundTool = registry.getByName('non-existent');
|
|
150
|
-
expect(foundTool).toBeUndefined();
|
|
151
|
-
});
|
|
152
|
-
it('should remove a tool by its name', () => {
|
|
153
|
-
const tool = createMockTool({ name: 'remove-me' });
|
|
154
|
-
registry.add(tool);
|
|
155
|
-
expect(registry.getByName('remove-me')).toBeDefined();
|
|
156
|
-
registry.removeByName('remove-me');
|
|
157
|
-
expect(registry.getByName('remove-me')).toBeUndefined();
|
|
158
|
-
});
|
|
159
|
-
it('should not throw when removing a tool by a name that does not exist', () => {
|
|
160
|
-
expect(() => registry.removeByName('non-existent')).not.toThrow();
|
|
161
|
-
});
|
|
162
|
-
it('should generate a valid ToolIdentifier', () => {
|
|
163
|
-
const tool = createMockTool();
|
|
164
|
-
const id = registry['generateId'](tool);
|
|
165
|
-
expect(id).toBe(tool);
|
|
166
|
-
});
|
|
167
|
-
it('should register a tool with a name at the maximum length', () => {
|
|
168
|
-
const longName = 'a'.repeat(64);
|
|
169
|
-
const tool = createMockTool({ name: longName });
|
|
170
|
-
expect(() => registry.add(tool)).not.toThrow();
|
|
171
|
-
});
|
|
172
|
-
it('should throw ValidationError for a non-string tool name', () => {
|
|
173
|
-
// @ts-expect-error - Testing invalid type for name
|
|
174
|
-
const tool = createMockTool({ name: 123 });
|
|
175
|
-
expect(() => registry.add(tool)).toThrow(ValidationError);
|
|
176
|
-
expect(() => registry.add(tool)).toThrow('Tool name must be a string');
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
81
|
}
|
|
180
82
|
//# sourceMappingURL=tool-registry.js.map
|