@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
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { createErrorResult, Tool } from './tool.js';
|
|
2
2
|
import { ToolStreamEvent } from './tool.js';
|
|
3
3
|
import { deepCopy } from '../types/json.js';
|
|
4
|
-
import { JsonBlock, TextBlock, ToolResultBlock } from '../types/messages.js';
|
|
4
|
+
import { JsonBlock, TextBlock, ToolResultBlock, toolResultContentFromData, } from '../types/messages.js';
|
|
5
|
+
import { DocumentBlock, ImageBlock, VideoBlock } from '../types/media.js';
|
|
5
6
|
/**
|
|
6
7
|
* A Tool implementation that wraps a callback function and handles all ToolResultBlock conversion.
|
|
7
8
|
*
|
|
@@ -134,16 +135,42 @@ export class FunctionTool extends Tool {
|
|
|
134
135
|
return createErrorResult(error, toolUse.toolUseId);
|
|
135
136
|
}
|
|
136
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* Invokes the tool directly with raw input and returns the unwrapped result.
|
|
140
|
+
*
|
|
141
|
+
* Unlike stream(), this method:
|
|
142
|
+
* - Returns the raw result (not wrapped in ToolResult)
|
|
143
|
+
* - Consumes async generators and returns the generator's return value
|
|
144
|
+
* - Lets errors throw naturally (not wrapped in error ToolResult)
|
|
145
|
+
*
|
|
146
|
+
* @param input - The input parameters for the tool
|
|
147
|
+
* @param context - Optional tool execution context
|
|
148
|
+
* @returns The unwrapped result
|
|
149
|
+
*/
|
|
150
|
+
async invoke(input, context) {
|
|
151
|
+
const result = this._callback(input, context);
|
|
152
|
+
if (result && typeof result === 'object' && Symbol.asyncIterator in result) {
|
|
153
|
+
const generator = result;
|
|
154
|
+
let iterResult = await generator.next();
|
|
155
|
+
while (!iterResult.done) {
|
|
156
|
+
iterResult = await generator.next();
|
|
157
|
+
}
|
|
158
|
+
return iterResult.value;
|
|
159
|
+
}
|
|
160
|
+
return (await result);
|
|
161
|
+
}
|
|
137
162
|
/**
|
|
138
163
|
* Wraps a value in a ToolResultBlock with success status.
|
|
139
164
|
*
|
|
140
165
|
* Due to AWS Bedrock limitations (only accepts objects as JSON content), the following
|
|
141
166
|
* rules are applied:
|
|
167
|
+
* - Content blocks (TextBlock, JsonBlock, ImageBlock, VideoBlock, DocumentBlock) → passed through directly
|
|
168
|
+
* - Arrays of content blocks → used directly as content array
|
|
142
169
|
* - Strings → TextBlock
|
|
143
170
|
* - Numbers, Booleans → TextBlock (converted to string)
|
|
144
171
|
* - null, undefined → TextBlock (special string representation)
|
|
145
172
|
* - Objects → JsonBlock (with deep copy)
|
|
146
|
-
* - Arrays → JsonBlock wrapped in \{ $value: array \} (with deep copy)
|
|
173
|
+
* - Arrays (non-content blocks) → JsonBlock wrapped in \{ $value: array \} (with deep copy)
|
|
147
174
|
*
|
|
148
175
|
* @param value - The value to wrap (can be any type)
|
|
149
176
|
* @param toolUseId - The tool use ID for the ToolResultBlock
|
|
@@ -151,6 +178,14 @@ export class FunctionTool extends Tool {
|
|
|
151
178
|
*/
|
|
152
179
|
_wrapInToolResult(value, toolUseId) {
|
|
153
180
|
try {
|
|
181
|
+
// Handle media blocks - pass through directly
|
|
182
|
+
if (value instanceof DocumentBlock || value instanceof ImageBlock || value instanceof VideoBlock) {
|
|
183
|
+
return new ToolResultBlock({
|
|
184
|
+
toolUseId,
|
|
185
|
+
status: 'success',
|
|
186
|
+
content: [value],
|
|
187
|
+
});
|
|
188
|
+
}
|
|
154
189
|
// Handle null with special string representation as text content
|
|
155
190
|
if (value === null) {
|
|
156
191
|
return new ToolResultBlock({
|
|
@@ -167,6 +202,15 @@ export class FunctionTool extends Tool {
|
|
|
167
202
|
content: [new TextBlock('<undefined>')],
|
|
168
203
|
});
|
|
169
204
|
}
|
|
205
|
+
// Handle content blocks - class instances or plain data objects
|
|
206
|
+
const contentBlock = this._asToolResultContent(value);
|
|
207
|
+
if (contentBlock) {
|
|
208
|
+
return new ToolResultBlock({
|
|
209
|
+
toolUseId,
|
|
210
|
+
status: 'success',
|
|
211
|
+
content: [contentBlock],
|
|
212
|
+
});
|
|
213
|
+
}
|
|
170
214
|
// Handle primitives (strings, numbers, booleans) as text content
|
|
171
215
|
// Bedrock doesn't accept primitives as JSON content, so we convert all to strings
|
|
172
216
|
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
|
|
@@ -176,8 +220,20 @@ export class FunctionTool extends Tool {
|
|
|
176
220
|
content: [new TextBlock(String(value))],
|
|
177
221
|
});
|
|
178
222
|
}
|
|
179
|
-
// Handle arrays
|
|
223
|
+
// Handle arrays
|
|
180
224
|
if (Array.isArray(value)) {
|
|
225
|
+
// Check if array contains only content blocks (class instances or plain data objects)
|
|
226
|
+
if (value.length > 0) {
|
|
227
|
+
const converted = value.map((item) => this._asToolResultContent(item));
|
|
228
|
+
if (converted.every((item) => item !== undefined)) {
|
|
229
|
+
return new ToolResultBlock({
|
|
230
|
+
toolUseId,
|
|
231
|
+
status: 'success',
|
|
232
|
+
content: converted,
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
// Otherwise wrap in object { $value: array }
|
|
181
237
|
const copiedValue = deepCopy(value);
|
|
182
238
|
return new ToolResultBlock({
|
|
183
239
|
toolUseId,
|
|
@@ -198,5 +254,34 @@ export class FunctionTool extends Tool {
|
|
|
198
254
|
return createErrorResult(error, toolUseId);
|
|
199
255
|
}
|
|
200
256
|
}
|
|
257
|
+
/**
|
|
258
|
+
* Converts a value to a ToolResultContent instance if it matches a known content type.
|
|
259
|
+
* Accepts both class instances and plain data objects.
|
|
260
|
+
*
|
|
261
|
+
* @param value - Value to check and convert
|
|
262
|
+
* @returns ToolResultContent instance, or undefined if not a recognized content type
|
|
263
|
+
*/
|
|
264
|
+
_asToolResultContent(value) {
|
|
265
|
+
if (typeof value !== 'object')
|
|
266
|
+
return undefined;
|
|
267
|
+
// Class instances — pass through
|
|
268
|
+
if (value instanceof TextBlock ||
|
|
269
|
+
value instanceof JsonBlock ||
|
|
270
|
+
value instanceof ImageBlock ||
|
|
271
|
+
value instanceof VideoBlock ||
|
|
272
|
+
value instanceof DocumentBlock) {
|
|
273
|
+
return value;
|
|
274
|
+
}
|
|
275
|
+
// Plain data objects — require exactly one key to match the discriminated
|
|
276
|
+
// union shape; multi-key objects fall through to JsonBlock instead.
|
|
277
|
+
try {
|
|
278
|
+
if (Object.keys(value).length !== 1)
|
|
279
|
+
return undefined;
|
|
280
|
+
return toolResultContentFromData(value);
|
|
281
|
+
}
|
|
282
|
+
catch {
|
|
283
|
+
return undefined;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
201
286
|
}
|
|
202
287
|
//# sourceMappingURL=function-tool.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"function-tool.js","sourceRoot":"","sources":["../../../src/tools/function-tool.ts"],"names":[],"mappings":"AAAA,OAAO,E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AClE,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,SAAS,CAAA;QAClB,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { InvokableTool } from './tool.js';
|
|
2
|
+
import type { FunctionToolConfig } from './function-tool.js';
|
|
3
|
+
import type { JSONValue } from '../types/json.js';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { type ZodToolConfig } from './zod-tool.js';
|
|
6
|
+
/**
|
|
7
|
+
* Creates an InvokableTool from a Zod schema and callback function.
|
|
8
|
+
*
|
|
9
|
+
* @typeParam TInput - Zod schema type for input validation
|
|
10
|
+
* @typeParam TReturn - Return type of the callback function
|
|
11
|
+
* @param config - Tool configuration with Zod schema
|
|
12
|
+
* @returns An InvokableTool with typed input and output
|
|
13
|
+
*/
|
|
14
|
+
export declare function tool<TInput extends z.ZodType, TReturn extends JSONValue = JSONValue>(config: ZodToolConfig<TInput, TReturn>): InvokableTool<z.infer<TInput>, TReturn>;
|
|
15
|
+
/**
|
|
16
|
+
* Creates an InvokableTool from a JSON schema and callback function.
|
|
17
|
+
*
|
|
18
|
+
* @param config - Tool configuration with optional JSON schema
|
|
19
|
+
* @returns An InvokableTool with unknown input
|
|
20
|
+
*/
|
|
21
|
+
export declare function tool(config: FunctionToolConfig): InvokableTool<unknown, JSONValue>;
|
|
22
|
+
//# sourceMappingURL=tool-factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-factory.d.ts","sourceRoot":"","sources":["../../../src/tools/tool-factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAE9C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AAC5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAW,KAAK,aAAa,EAAE,MAAM,eAAe,CAAA;AAY3D;;;;;;;GAOG;AACH,wBAAgB,IAAI,CAAC,MAAM,SAAS,CAAC,CAAC,OAAO,EAAE,OAAO,SAAS,SAAS,GAAG,SAAS,EAClF,MAAM,EAAE,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC,GACrC,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,CAAA;AAE1C;;;;;GAKG;AACH,wBAAgB,IAAI,CAAC,MAAM,EAAE,kBAAkB,GAAG,aAAa,CAAC,OAAO,EAAE,SAAS,CAAC,CAAA"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { FunctionTool } from './function-tool.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { ZodTool } from './zod-tool.js';
|
|
4
|
+
/**
|
|
5
|
+
* Checks whether a value is a Zod schema type.
|
|
6
|
+
*
|
|
7
|
+
* @param value - The value to check
|
|
8
|
+
* @returns True if the value is a Zod schema
|
|
9
|
+
*/
|
|
10
|
+
function isZodType(value) {
|
|
11
|
+
return value instanceof z.ZodType;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Creates an InvokableTool from either a Zod schema or JSON schema configuration.
|
|
15
|
+
*
|
|
16
|
+
* When a Zod schema is provided as `inputSchema`, input is validated at runtime and
|
|
17
|
+
* the callback receives typed input. When a JSON schema (or no schema) is provided,
|
|
18
|
+
* the callback receives `unknown` input with no runtime validation.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* import { tool } from '@strands-agents/sdk'
|
|
23
|
+
* import { z } from 'zod'
|
|
24
|
+
*
|
|
25
|
+
* // With Zod schema (typed + validated)
|
|
26
|
+
* const calculator = tool({
|
|
27
|
+
* name: 'calculator',
|
|
28
|
+
* description: 'Adds two numbers',
|
|
29
|
+
* inputSchema: z.object({ a: z.number(), b: z.number() }),
|
|
30
|
+
* callback: (input) => input.a + input.b,
|
|
31
|
+
* })
|
|
32
|
+
*
|
|
33
|
+
* // With JSON schema (untyped, no validation)
|
|
34
|
+
* const greeter = tool({
|
|
35
|
+
* name: 'greeter',
|
|
36
|
+
* description: 'Greets a person',
|
|
37
|
+
* inputSchema: {
|
|
38
|
+
* type: 'object',
|
|
39
|
+
* properties: { name: { type: 'string' } },
|
|
40
|
+
* required: ['name'],
|
|
41
|
+
* },
|
|
42
|
+
* callback: (input) => `Hello, ${(input as { name: string }).name}!`,
|
|
43
|
+
* })
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @param config - Tool configuration
|
|
47
|
+
* @returns An InvokableTool that implements the Tool interface with invoke() method
|
|
48
|
+
*/
|
|
49
|
+
export function tool(config) {
|
|
50
|
+
if (config.inputSchema && isZodType(config.inputSchema)) {
|
|
51
|
+
return new ZodTool(config);
|
|
52
|
+
}
|
|
53
|
+
return new FunctionTool(config);
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=tool-factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-factory.js","sourceRoot":"","sources":["../../../src/tools/tool-factory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAGjD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,OAAO,EAAsB,MAAM,eAAe,CAAA;AAE3D;;;;;GAKG;AACH,SAAS,SAAS,CAAC,KAAc;IAC/B,OAAO,KAAK,YAAY,CAAC,CAAC,OAAO,CAAA;AACnC,CAAC;AAsBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAM,UAAU,IAAI,CAClB,MAA4E;IAE5E,IAAI,MAAM,CAAC,WAAW,IAAI,SAAS,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC;QACxD,OAAO,IAAI,OAAO,CAAC,MAA6C,CAAC,CAAA;IACnE,CAAC;IAED,OAAO,IAAI,YAAY,CAAC,MAA4B,CAAC,CAAA;AACvD,CAAC"}
|
package/dist/src/tools/tool.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ToolSpec, ToolUse } from './types.js';
|
|
2
2
|
import { ToolResultBlock } from '../types/messages.js';
|
|
3
|
-
import type {
|
|
3
|
+
import type { LocalAgent } from '../types/agent.js';
|
|
4
4
|
export type { ToolSpec } from './types.js';
|
|
5
5
|
/**
|
|
6
6
|
* Context provided to tool implementations during execution.
|
|
@@ -16,7 +16,7 @@ export interface ToolContext {
|
|
|
16
16
|
* The agent instance that is executing this tool.
|
|
17
17
|
* Provides access to agent state and other agent-level information.
|
|
18
18
|
*/
|
|
19
|
-
agent:
|
|
19
|
+
agent: LocalAgent;
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
22
|
* Data for a tool stream event.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../../../src/tools/tool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AACnD,OAAO,EAAa,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACjE,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../../../src/tools/tool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AACnD,OAAO,EAAa,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACjE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAGnD,YAAY,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAE1C;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B;;;OAGG;IACH,OAAO,EAAE,OAAO,CAAA;IAEhB;;;OAGG;IACH,KAAK,EAAE,UAAU,CAAA;CAClB;AAED;;G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InvokableTool, ToolContext, ToolStreamGenerator } from './tool.js';
|
|
2
|
+
import { Tool } from './tool.js';
|
|
3
|
+
import type { ToolSpec } from './types.js';
|
|
2
4
|
import type { JSONValue } from '../types/json.js';
|
|
3
5
|
import { z } from 'zod';
|
|
4
6
|
/**
|
|
@@ -11,7 +13,7 @@ type ZodInferred<TInput> = TInput extends z.ZodType ? z.infer<TInput> : never;
|
|
|
11
13
|
* @typeParam TInput - Zod schema type for input validation
|
|
12
14
|
* @typeParam TReturn - Return type of the callback function
|
|
13
15
|
*/
|
|
14
|
-
export interface
|
|
16
|
+
export interface ZodToolConfig<TInput extends z.ZodType | undefined, TReturn extends JSONValue = JSONValue> {
|
|
15
17
|
/** The name of the tool */
|
|
16
18
|
name: string;
|
|
17
19
|
/** A description of what the tool does (optional) */
|
|
@@ -31,56 +33,57 @@ export interface ToolConfig<TInput extends z.ZodType | undefined, TReturn extend
|
|
|
31
33
|
callback: (input: ZodInferred<TInput>, context?: ToolContext) => AsyncGenerator<unknown, TReturn, never> | Promise<TReturn> | TReturn;
|
|
32
34
|
}
|
|
33
35
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* The tool() function validates input against the schema and generates JSON schema
|
|
37
|
-
* for model providers using Zod v4's built-in z.toJSONSchema() method.
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* ```typescript
|
|
41
|
-
* import { tool } from '@strands-agents/sdk'
|
|
42
|
-
* import { z } from 'zod'
|
|
43
|
-
*
|
|
44
|
-
* // Tool with input parameters
|
|
45
|
-
* const calculator = tool({
|
|
46
|
-
* name: 'calculator',
|
|
47
|
-
* description: 'Performs basic arithmetic',
|
|
48
|
-
* inputSchema: z.object({
|
|
49
|
-
* operation: z.enum(['add', 'subtract', 'multiply', 'divide']),
|
|
50
|
-
* a: z.number(),
|
|
51
|
-
* b: z.number()
|
|
52
|
-
* }),
|
|
53
|
-
* callback: (input) => {
|
|
54
|
-
* switch (input.operation) {
|
|
55
|
-
* case 'add': return input.a + input.b
|
|
56
|
-
* case 'subtract': return input.a - input.b
|
|
57
|
-
* case 'multiply': return input.a * input.b
|
|
58
|
-
* case 'divide': return input.a / input.b
|
|
59
|
-
* }
|
|
60
|
-
* }
|
|
61
|
-
* })
|
|
62
|
-
*
|
|
63
|
-
* // Tool without input (omit inputSchema)
|
|
64
|
-
* const getStatus = tool({
|
|
65
|
-
* name: 'getStatus',
|
|
66
|
-
* description: 'Gets system status',
|
|
67
|
-
* callback: () => ({ status: 'operational', uptime: 99.9 })
|
|
68
|
-
* })
|
|
69
|
-
*
|
|
70
|
-
* // Direct invocation
|
|
71
|
-
* const result = await calculator.invoke({ operation: 'add', a: 5, b: 3 })
|
|
72
|
-
*
|
|
73
|
-
* // Agent usage
|
|
74
|
-
* for await (const event of calculator.stream(context)) {
|
|
75
|
-
* console.log(event)
|
|
76
|
-
* }
|
|
77
|
-
* ```
|
|
78
|
-
*
|
|
79
|
-
* @typeParam TInput - Zod schema type for input validation
|
|
80
|
-
* @typeParam TReturn - Return type of the callback function
|
|
81
|
-
* @param config - Tool configuration
|
|
82
|
-
* @returns An InvokableTool that implements the Tool interface with invoke() method
|
|
36
|
+
* Zod-based tool implementation.
|
|
37
|
+
* Extends Tool abstract class and implements InvokableTool interface.
|
|
83
38
|
*/
|
|
84
|
-
export declare
|
|
39
|
+
export declare class ZodTool<TInput extends z.ZodType | undefined, TReturn extends JSONValue = JSONValue> extends Tool implements InvokableTool<ZodInferred<TInput>, TReturn> {
|
|
40
|
+
/**
|
|
41
|
+
* Internal FunctionTool for delegating stream operations.
|
|
42
|
+
*/
|
|
43
|
+
private readonly _functionTool;
|
|
44
|
+
/**
|
|
45
|
+
* Zod schema for input validation.
|
|
46
|
+
* Note: undefined is normalized to z.void() in constructor, so this is always defined.
|
|
47
|
+
*/
|
|
48
|
+
private readonly _inputSchema;
|
|
49
|
+
/**
|
|
50
|
+
* User callback function.
|
|
51
|
+
*/
|
|
52
|
+
private readonly _callback;
|
|
53
|
+
constructor(config: ZodToolConfig<TInput, TReturn>);
|
|
54
|
+
/**
|
|
55
|
+
* The unique name of the tool.
|
|
56
|
+
*/
|
|
57
|
+
get name(): string;
|
|
58
|
+
/**
|
|
59
|
+
* Human-readable description of what the tool does.
|
|
60
|
+
*/
|
|
61
|
+
get description(): string;
|
|
62
|
+
/**
|
|
63
|
+
* OpenAPI JSON specification for the tool.
|
|
64
|
+
*/
|
|
65
|
+
get toolSpec(): ToolSpec;
|
|
66
|
+
/**
|
|
67
|
+
* Executes the tool with streaming support.
|
|
68
|
+
* Delegates to internal FunctionTool implementation.
|
|
69
|
+
*
|
|
70
|
+
* @param toolContext - Context information including the tool use request and invocation state
|
|
71
|
+
* @returns Async generator that yields ToolStreamEvents and returns a ToolResultBlock
|
|
72
|
+
*/
|
|
73
|
+
stream(toolContext: ToolContext): ToolStreamGenerator;
|
|
74
|
+
/**
|
|
75
|
+
* Invokes the tool directly with type-safe input and returns the unwrapped result.
|
|
76
|
+
*
|
|
77
|
+
* Unlike stream(), this method:
|
|
78
|
+
* - Returns the raw result (not wrapped in ToolResult)
|
|
79
|
+
* - Consumes async generators and returns only the final value
|
|
80
|
+
* - Lets errors throw naturally (not wrapped in error ToolResult)
|
|
81
|
+
*
|
|
82
|
+
* @param input - The input parameters for the tool
|
|
83
|
+
* @param context - Optional tool execution context
|
|
84
|
+
* @returns The unwrapped result
|
|
85
|
+
*/
|
|
86
|
+
invoke(input: ZodInferred<TInput>, context?: ToolContext): Promise<TReturn>;
|
|
87
|
+
}
|
|
85
88
|
export {};
|
|
86
89
|
//# sourceMappingURL=zod-tool.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zod-tool.d.ts","sourceRoot":"","sources":["../../../src/tools/zod-tool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"zod-tool.d.ts","sourceRoot":"","sources":["../../../src/tools/zod-tool.ts"],"names":[],"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CAAW;IAExC;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,SAAS,CAG+C;gBAE7D,MAAM,EAAE,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC;IAyClD;;OAEG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;OAEG;IACH,IAAI,WAAW,IAAI,MAAM,CAExB;IAED;;OAEG;IACH,IAAI,QAAQ,IAAI,QAAQ,CAEvB;IAED;;;;;;OAMG;IACH,MAAM,CAAC,WAAW,EAAE,WAAW,GAAG,mBAAmB;IAIrD;;;;;;;;;;;OAWG;IACG,MAAM,CAAC,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;CAoBlF"}
|
|
@@ -3,10 +3,10 @@ import { FunctionTool } from './function-tool.js';
|
|
|
3
3
|
import { z, ZodVoid } from 'zod';
|
|
4
4
|
import { zodSchemaToJsonSchema } from '../utils/zod.js';
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Zod-based tool implementation.
|
|
7
7
|
* Extends Tool abstract class and implements InvokableTool interface.
|
|
8
8
|
*/
|
|
9
|
-
class ZodTool extends Tool {
|
|
9
|
+
export class ZodTool extends Tool {
|
|
10
10
|
/**
|
|
11
11
|
* Internal FunctionTool for delegating stream operations.
|
|
12
12
|
*/
|
|
@@ -98,12 +98,12 @@ class ZodTool extends Tool {
|
|
|
98
98
|
const result = this._callback(validatedInput, context);
|
|
99
99
|
// Handle different return types
|
|
100
100
|
if (result && typeof result === 'object' && Symbol.asyncIterator in result) {
|
|
101
|
-
|
|
102
|
-
let
|
|
103
|
-
|
|
104
|
-
|
|
101
|
+
const generator = result;
|
|
102
|
+
let iterResult = await generator.next();
|
|
103
|
+
while (!iterResult.done) {
|
|
104
|
+
iterResult = await generator.next();
|
|
105
105
|
}
|
|
106
|
-
return
|
|
106
|
+
return iterResult.value;
|
|
107
107
|
}
|
|
108
108
|
else {
|
|
109
109
|
// Regular value or Promise - return directly
|
|
@@ -111,58 +111,4 @@ class ZodTool extends Tool {
|
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
|
-
/**
|
|
115
|
-
* Creates an InvokableTool from a Zod schema and callback function.
|
|
116
|
-
*
|
|
117
|
-
* The tool() function validates input against the schema and generates JSON schema
|
|
118
|
-
* for model providers using Zod v4's built-in z.toJSONSchema() method.
|
|
119
|
-
*
|
|
120
|
-
* @example
|
|
121
|
-
* ```typescript
|
|
122
|
-
* import { tool } from '@strands-agents/sdk'
|
|
123
|
-
* import { z } from 'zod'
|
|
124
|
-
*
|
|
125
|
-
* // Tool with input parameters
|
|
126
|
-
* const calculator = tool({
|
|
127
|
-
* name: 'calculator',
|
|
128
|
-
* description: 'Performs basic arithmetic',
|
|
129
|
-
* inputSchema: z.object({
|
|
130
|
-
* operation: z.enum(['add', 'subtract', 'multiply', 'divide']),
|
|
131
|
-
* a: z.number(),
|
|
132
|
-
* b: z.number()
|
|
133
|
-
* }),
|
|
134
|
-
* callback: (input) => {
|
|
135
|
-
* switch (input.operation) {
|
|
136
|
-
* case 'add': return input.a + input.b
|
|
137
|
-
* case 'subtract': return input.a - input.b
|
|
138
|
-
* case 'multiply': return input.a * input.b
|
|
139
|
-
* case 'divide': return input.a / input.b
|
|
140
|
-
* }
|
|
141
|
-
* }
|
|
142
|
-
* })
|
|
143
|
-
*
|
|
144
|
-
* // Tool without input (omit inputSchema)
|
|
145
|
-
* const getStatus = tool({
|
|
146
|
-
* name: 'getStatus',
|
|
147
|
-
* description: 'Gets system status',
|
|
148
|
-
* callback: () => ({ status: 'operational', uptime: 99.9 })
|
|
149
|
-
* })
|
|
150
|
-
*
|
|
151
|
-
* // Direct invocation
|
|
152
|
-
* const result = await calculator.invoke({ operation: 'add', a: 5, b: 3 })
|
|
153
|
-
*
|
|
154
|
-
* // Agent usage
|
|
155
|
-
* for await (const event of calculator.stream(context)) {
|
|
156
|
-
* console.log(event)
|
|
157
|
-
* }
|
|
158
|
-
* ```
|
|
159
|
-
*
|
|
160
|
-
* @typeParam TInput - Zod schema type for input validation
|
|
161
|
-
* @typeParam TReturn - Return type of the callback function
|
|
162
|
-
* @param config - Tool configuration
|
|
163
|
-
* @returns An InvokableTool that implements the Tool interface with invoke() method
|
|
164
|
-
*/
|
|
165
|
-
export function tool(config) {
|
|
166
|
-
return new ZodTool(config);
|
|
167
|
-
}
|
|
168
114
|
//# sourceMappingURL=zod-tool.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zod-tool.js","sourceRoot":"","sources":["../../../src/tools/zod-tool.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAGhC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AAChC,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AAuCvD;;;GAGG;AACH,MAAM,
|
|
1
|
+
{"version":3,"file":"zod-tool.js","sourceRoot":"","sources":["../../../src/tools/zod-tool.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAGhC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AAChC,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AAuCvD;;;GAGG;AACH,MAAM,OAAO,OACX,SAAQ,IAAI;IAGZ;;OAEG;IACc,aAAa,CAAc;IAE5C;;;OAGG;IACc,YAAY,CAAW;IAExC;;OAEG;IACc,SAAS,CAG+C;IAEzE,YAAY,MAAsC;QAChD,KAAK,EAAE,CAAA;QACP,MAAM,EAAE,IAAI,EAAE,WAAW,GAAG,EAAE,EAAE,WAAW,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAA;QA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