@strands-agents/sdk 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +175 -0
- package/README.md +185 -0
- package/dist/__fixtures__/model-test-helpers.d.ts +56 -0
- package/dist/__fixtures__/model-test-helpers.d.ts.map +1 -0
- package/dist/__fixtures__/model-test-helpers.js +85 -0
- package/dist/__fixtures__/model-test-helpers.js.map +1 -0
- package/dist/__fixtures__/tool-helpers.d.ts +15 -0
- package/dist/__fixtures__/tool-helpers.d.ts.map +1 -0
- package/dist/__fixtures__/tool-helpers.js +22 -0
- package/dist/__fixtures__/tool-helpers.js.map +1 -0
- package/dist/__tests__/errors.test.d.ts +2 -0
- package/dist/__tests__/errors.test.d.ts.map +1 -0
- package/dist/__tests__/errors.test.js +20 -0
- package/dist/__tests__/errors.test.js.map +1 -0
- package/dist/__tests__/index.test.d.ts +2 -0
- package/dist/__tests__/index.test.d.ts.map +1 -0
- package/dist/__tests__/index.test.js +27 -0
- package/dist/__tests__/index.test.js.map +1 -0
- package/dist/errors.d.ts +22 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +25 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/models/__tests__/bedrock.test.d.ts +2 -0
- package/dist/models/__tests__/bedrock.test.d.ts.map +1 -0
- package/dist/models/__tests__/bedrock.test.js +1161 -0
- package/dist/models/__tests__/bedrock.test.js.map +1 -0
- package/dist/models/__tests__/model.test.d.ts +2 -0
- package/dist/models/__tests__/model.test.d.ts.map +1 -0
- package/dist/models/__tests__/model.test.js +297 -0
- package/dist/models/__tests__/model.test.js.map +1 -0
- package/dist/models/__tests__/openai.test.d.ts +2 -0
- package/dist/models/__tests__/openai.test.d.ts.map +1 -0
- package/dist/models/__tests__/openai.test.js +1016 -0
- package/dist/models/__tests__/openai.test.js.map +1 -0
- package/dist/models/__tests__/test-utils.d.ts +10 -0
- package/dist/models/__tests__/test-utils.d.ts.map +1 -0
- package/dist/models/__tests__/test-utils.js +17 -0
- package/dist/models/__tests__/test-utils.js.map +1 -0
- package/dist/models/bedrock.d.ts +272 -0
- package/dist/models/bedrock.d.ts.map +1 -0
- package/dist/models/bedrock.js +679 -0
- package/dist/models/bedrock.js.map +1 -0
- package/dist/models/model.d.ts +89 -0
- package/dist/models/model.d.ts.map +1 -0
- package/dist/models/model.js +122 -0
- package/dist/models/model.js.map +1 -0
- package/dist/models/openai.d.ts +262 -0
- package/dist/models/openai.d.ts.map +1 -0
- package/dist/models/openai.js +625 -0
- package/dist/models/openai.js.map +1 -0
- package/dist/models/streaming.d.ts +226 -0
- package/dist/models/streaming.d.ts.map +1 -0
- package/dist/models/streaming.js +2 -0
- package/dist/models/streaming.js.map +1 -0
- package/dist/src/__fixtures__/agent-helpers.d.ts +29 -0
- package/dist/src/__fixtures__/agent-helpers.d.ts.map +1 -0
- package/dist/src/__fixtures__/agent-helpers.js +19 -0
- package/dist/src/__fixtures__/agent-helpers.js.map +1 -0
- package/dist/src/__fixtures__/environment.d.ts +12 -0
- package/dist/src/__fixtures__/environment.d.ts.map +1 -0
- package/dist/src/__fixtures__/environment.js +12 -0
- package/dist/src/__fixtures__/environment.js.map +1 -0
- package/dist/src/__fixtures__/mock-hook-provider.d.ts +14 -0
- package/dist/src/__fixtures__/mock-hook-provider.d.ts.map +1 -0
- package/dist/src/__fixtures__/mock-hook-provider.js +33 -0
- package/dist/src/__fixtures__/mock-hook-provider.js.map +1 -0
- package/dist/src/__fixtures__/mock-message-model.d.ts +93 -0
- package/dist/src/__fixtures__/mock-message-model.d.ts.map +1 -0
- package/dist/src/__fixtures__/mock-message-model.js +226 -0
- package/dist/src/__fixtures__/mock-message-model.js.map +1 -0
- package/dist/src/__fixtures__/model-test-helpers.d.ts +56 -0
- package/dist/src/__fixtures__/model-test-helpers.d.ts.map +1 -0
- package/dist/src/__fixtures__/model-test-helpers.js +85 -0
- package/dist/src/__fixtures__/model-test-helpers.js.map +1 -0
- package/dist/src/__fixtures__/tool-helpers.d.ts +37 -0
- package/dist/src/__fixtures__/tool-helpers.d.ts.map +1 -0
- package/dist/src/__fixtures__/tool-helpers.js +78 -0
- package/dist/src/__fixtures__/tool-helpers.js.map +1 -0
- package/dist/src/__tests__/errors.test.d.ts +2 -0
- package/dist/src/__tests__/errors.test.d.ts.map +1 -0
- package/dist/src/__tests__/errors.test.js +64 -0
- package/dist/src/__tests__/errors.test.js.map +1 -0
- package/dist/src/__tests__/index.test.d.ts +2 -0
- package/dist/src/__tests__/index.test.d.ts.map +1 -0
- package/dist/src/__tests__/index.test.js +27 -0
- package/dist/src/__tests__/index.test.js.map +1 -0
- package/dist/src/__tests__/mcp.test.d.ts +2 -0
- package/dist/src/__tests__/mcp.test.d.ts.map +1 -0
- package/dist/src/__tests__/mcp.test.js +166 -0
- package/dist/src/__tests__/mcp.test.js.map +1 -0
- package/dist/src/agent/__tests__/agent.hook.test.d.ts +2 -0
- package/dist/src/agent/__tests__/agent.hook.test.d.ts.map +1 -0
- package/dist/src/agent/__tests__/agent.hook.test.js +250 -0
- package/dist/src/agent/__tests__/agent.hook.test.js.map +1 -0
- package/dist/src/agent/__tests__/agent.test.d.ts +2 -0
- package/dist/src/agent/__tests__/agent.test.d.ts.map +1 -0
- package/dist/src/agent/__tests__/agent.test.js +414 -0
- package/dist/src/agent/__tests__/agent.test.js.map +1 -0
- package/dist/src/agent/__tests__/printer.test.d.ts +2 -0
- package/dist/src/agent/__tests__/printer.test.d.ts.map +1 -0
- package/dist/src/agent/__tests__/printer.test.js +152 -0
- package/dist/src/agent/__tests__/printer.test.js.map +1 -0
- package/dist/src/agent/__tests__/state.test.d.ts +2 -0
- package/dist/src/agent/__tests__/state.test.d.ts.map +1 -0
- package/dist/src/agent/__tests__/state.test.js +231 -0
- package/dist/src/agent/__tests__/state.test.js.map +1 -0
- package/dist/src/agent/agent.d.ts +207 -0
- package/dist/src/agent/agent.d.ts.map +1 -0
- package/dist/src/agent/agent.js +481 -0
- package/dist/src/agent/agent.js.map +1 -0
- package/dist/src/agent/printer.d.ts +73 -0
- package/dist/src/agent/printer.d.ts.map +1 -0
- package/dist/src/agent/printer.js +145 -0
- package/dist/src/agent/printer.js.map +1 -0
- package/dist/src/agent/state.d.ts +102 -0
- package/dist/src/agent/state.d.ts.map +1 -0
- package/dist/src/agent/state.js +73 -0
- package/dist/src/agent/state.js.map +1 -0
- package/dist/src/agent/streaming.d.ts +91 -0
- package/dist/src/agent/streaming.d.ts.map +1 -0
- package/dist/src/agent/streaming.js +2 -0
- package/dist/src/agent/streaming.js.map +1 -0
- 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 +10 -0
- package/dist/src/conversation-manager/__tests__/conversation-manager.test.js.map +1 -0
- package/dist/src/conversation-manager/__tests__/null-conversation-manager.test.d.ts +2 -0
- package/dist/src/conversation-manager/__tests__/null-conversation-manager.test.d.ts.map +1 -0
- package/dist/src/conversation-manager/__tests__/null-conversation-manager.test.js +35 -0
- package/dist/src/conversation-manager/__tests__/null-conversation-manager.test.js.map +1 -0
- package/dist/src/conversation-manager/__tests__/sliding-window-conversation-manager.test.d.ts +2 -0
- package/dist/src/conversation-manager/__tests__/sliding-window-conversation-manager.test.d.ts.map +1 -0
- package/dist/src/conversation-manager/__tests__/sliding-window-conversation-manager.test.js +553 -0
- package/dist/src/conversation-manager/__tests__/sliding-window-conversation-manager.test.js.map +1 -0
- package/dist/src/conversation-manager/conversation-manager.d.ts +73 -0
- package/dist/src/conversation-manager/conversation-manager.d.ts.map +1 -0
- package/dist/src/conversation-manager/conversation-manager.js +24 -0
- package/dist/src/conversation-manager/conversation-manager.js.map +1 -0
- package/dist/src/conversation-manager/index.d.ts +8 -0
- package/dist/src/conversation-manager/index.d.ts.map +1 -0
- package/dist/src/conversation-manager/index.js +8 -0
- package/dist/src/conversation-manager/index.js.map +1 -0
- package/dist/src/conversation-manager/null-conversation-manager.d.ts +23 -0
- package/dist/src/conversation-manager/null-conversation-manager.d.ts.map +1 -0
- package/dist/src/conversation-manager/null-conversation-manager.js +23 -0
- package/dist/src/conversation-manager/null-conversation-manager.js.map +1 -0
- package/dist/src/conversation-manager/sliding-window-conversation-manager.d.ts +105 -0
- package/dist/src/conversation-manager/sliding-window-conversation-manager.d.ts.map +1 -0
- package/dist/src/conversation-manager/sliding-window-conversation-manager.js +212 -0
- package/dist/src/conversation-manager/sliding-window-conversation-manager.js.map +1 -0
- package/dist/src/errors.d.ts +83 -0
- package/dist/src/errors.d.ts.map +1 -0
- package/dist/src/errors.js +97 -0
- package/dist/src/errors.js.map +1 -0
- package/dist/src/hooks/__tests__/events.test.d.ts +2 -0
- package/dist/src/hooks/__tests__/events.test.d.ts.map +1 -0
- package/dist/src/hooks/__tests__/events.test.js +347 -0
- package/dist/src/hooks/__tests__/events.test.js.map +1 -0
- package/dist/src/hooks/__tests__/registry.test.d.ts +2 -0
- package/dist/src/hooks/__tests__/registry.test.d.ts.map +1 -0
- package/dist/src/hooks/__tests__/registry.test.js +154 -0
- package/dist/src/hooks/__tests__/registry.test.js.map +1 -0
- package/dist/src/hooks/events.d.ts +199 -0
- package/dist/src/hooks/events.d.ts.map +1 -0
- package/dist/src/hooks/events.js +191 -0
- package/dist/src/hooks/events.js.map +1 -0
- package/dist/src/hooks/index.d.ts +11 -0
- package/dist/src/hooks/index.d.ts.map +1 -0
- package/dist/src/hooks/index.js +11 -0
- package/dist/src/hooks/index.js.map +1 -0
- package/dist/src/hooks/registry.d.ts +65 -0
- package/dist/src/hooks/registry.d.ts.map +1 -0
- package/dist/src/hooks/registry.js +65 -0
- package/dist/src/hooks/registry.js.map +1 -0
- package/dist/src/hooks/types.d.ts +49 -0
- package/dist/src/hooks/types.d.ts.map +1 -0
- package/dist/src/hooks/types.js +2 -0
- package/dist/src/hooks/types.js.map +1 -0
- package/dist/src/index.d.ts +32 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +29 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/mcp.d.ts +51 -0
- package/dist/src/mcp.d.ts.map +1 -0
- package/dist/src/mcp.js +91 -0
- package/dist/src/mcp.js.map +1 -0
- package/dist/src/models/__tests__/bedrock.test.d.ts +2 -0
- package/dist/src/models/__tests__/bedrock.test.d.ts.map +1 -0
- package/dist/src/models/__tests__/bedrock.test.js +1388 -0
- package/dist/src/models/__tests__/bedrock.test.js.map +1 -0
- package/dist/src/models/__tests__/model.test.d.ts +2 -0
- package/dist/src/models/__tests__/model.test.d.ts.map +1 -0
- package/dist/src/models/__tests__/model.test.js +342 -0
- package/dist/src/models/__tests__/model.test.js.map +1 -0
- package/dist/src/models/__tests__/openai.test.d.ts +2 -0
- package/dist/src/models/__tests__/openai.test.d.ts.map +1 -0
- package/dist/src/models/__tests__/openai.test.js +1189 -0
- package/dist/src/models/__tests__/openai.test.js.map +1 -0
- package/dist/src/models/__tests__/test-utils.d.ts +10 -0
- package/dist/src/models/__tests__/test-utils.d.ts.map +1 -0
- package/dist/src/models/__tests__/test-utils.js +17 -0
- package/dist/src/models/__tests__/test-utils.js.map +1 -0
- package/dist/src/models/bedrock.d.ts +289 -0
- package/dist/src/models/bedrock.d.ts.map +1 -0
- package/dist/src/models/bedrock.js +804 -0
- package/dist/src/models/bedrock.js.map +1 -0
- package/dist/src/models/model.d.ts +99 -0
- package/dist/src/models/model.d.ts.map +1 -0
- package/dist/src/models/model.js +169 -0
- package/dist/src/models/model.js.map +1 -0
- package/dist/src/models/openai.d.ts +262 -0
- package/dist/src/models/openai.d.ts.map +1 -0
- package/dist/src/models/openai.js +752 -0
- package/dist/src/models/openai.js.map +1 -0
- package/dist/src/models/streaming.d.ts +318 -0
- package/dist/src/models/streaming.d.ts.map +1 -0
- package/dist/src/models/streaming.js +122 -0
- package/dist/src/models/streaming.js.map +1 -0
- package/dist/src/registry/registry.d.ts +117 -0
- package/dist/src/registry/registry.d.ts.map +1 -0
- package/dist/src/registry/registry.js +298 -0
- package/dist/src/registry/registry.js.map +1 -0
- package/dist/src/registry/tool-registry.d.ts +34 -0
- package/dist/src/registry/tool-registry.d.ts.map +1 -0
- package/dist/src/registry/tool-registry.js +178 -0
- package/dist/src/registry/tool-registry.js.map +1 -0
- package/dist/src/tools/__tests__/tool.test.d.ts +2 -0
- package/dist/src/tools/__tests__/tool.test.d.ts.map +1 -0
- package/dist/src/tools/__tests__/tool.test.js +877 -0
- package/dist/src/tools/__tests__/tool.test.js.map +1 -0
- package/dist/src/tools/__tests__/zod-tool.test-d.d.ts +2 -0
- package/dist/src/tools/__tests__/zod-tool.test-d.d.ts.map +1 -0
- package/dist/src/tools/__tests__/zod-tool.test-d.js +227 -0
- package/dist/src/tools/__tests__/zod-tool.test-d.js.map +1 -0
- package/dist/src/tools/__tests__/zod-tool.test.d.ts +2 -0
- package/dist/src/tools/__tests__/zod-tool.test.d.ts.map +1 -0
- package/dist/src/tools/__tests__/zod-tool.test.js +372 -0
- package/dist/src/tools/__tests__/zod-tool.test.js.map +1 -0
- package/dist/src/tools/function-tool.d.ts +146 -0
- package/dist/src/tools/function-tool.d.ts.map +1 -0
- package/dist/src/tools/function-tool.js +188 -0
- package/dist/src/tools/function-tool.js.map +1 -0
- package/dist/src/tools/mcp-tool.d.ts +36 -0
- package/dist/src/tools/mcp-tool.d.ts.map +1 -0
- package/dist/src/tools/mcp-tool.js +78 -0
- package/dist/src/tools/mcp-tool.js.map +1 -0
- package/dist/src/tools/tool.d.ts +167 -0
- package/dist/src/tools/tool.d.ts.map +1 -0
- package/dist/src/tools/tool.js +68 -0
- package/dist/src/tools/tool.js.map +1 -0
- package/dist/src/tools/types.d.ts +62 -0
- package/dist/src/tools/types.d.ts.map +1 -0
- package/dist/src/tools/types.js +2 -0
- package/dist/src/tools/types.js.map +1 -0
- package/dist/src/tools/zod-tool.d.ts +70 -0
- package/dist/src/tools/zod-tool.d.ts.map +1 -0
- package/dist/src/tools/zod-tool.js +149 -0
- package/dist/src/tools/zod-tool.js.map +1 -0
- package/dist/src/types/__tests__/agent.test.d.ts +2 -0
- package/dist/src/types/__tests__/agent.test.d.ts.map +1 -0
- package/dist/src/types/__tests__/agent.test.js +155 -0
- package/dist/src/types/__tests__/agent.test.js.map +1 -0
- package/dist/src/types/__tests__/json.test.d.ts +2 -0
- package/dist/src/types/__tests__/json.test.d.ts.map +1 -0
- package/dist/src/types/__tests__/json.test.js +298 -0
- package/dist/src/types/__tests__/json.test.js.map +1 -0
- package/dist/src/types/__tests__/media.test.d.ts +2 -0
- package/dist/src/types/__tests__/media.test.d.ts.map +1 -0
- package/dist/src/types/__tests__/media.test.js +257 -0
- package/dist/src/types/__tests__/media.test.js.map +1 -0
- package/dist/src/types/__tests__/messages.test.d.ts +2 -0
- package/dist/src/types/__tests__/messages.test.d.ts.map +1 -0
- package/dist/src/types/__tests__/messages.test.js +364 -0
- package/dist/src/types/__tests__/messages.test.js.map +1 -0
- package/dist/src/types/__tests__/validation.test.d.ts +2 -0
- package/dist/src/types/__tests__/validation.test.d.ts.map +1 -0
- package/dist/src/types/__tests__/validation.test.js +30 -0
- package/dist/src/types/__tests__/validation.test.js.map +1 -0
- package/dist/src/types/agent.d.ts +57 -0
- package/dist/src/types/agent.d.ts.map +1 -0
- package/dist/src/types/agent.js +47 -0
- package/dist/src/types/agent.js.map +1 -0
- package/dist/src/types/json.d.ts +55 -0
- package/dist/src/types/json.d.ts.map +1 -0
- package/dist/src/types/json.js +72 -0
- package/dist/src/types/json.js.map +1 -0
- package/dist/src/types/media.d.ts +249 -0
- package/dist/src/types/media.d.ts.map +1 -0
- package/dist/src/types/media.js +173 -0
- package/dist/src/types/media.js.map +1 -0
- package/dist/src/types/messages.d.ts +438 -0
- package/dist/src/types/messages.d.ts.map +1 -0
- package/dist/src/types/messages.js +286 -0
- package/dist/src/types/messages.js.map +1 -0
- package/dist/src/types/validation.d.ts +10 -0
- package/dist/src/types/validation.d.ts.map +1 -0
- package/dist/src/types/validation.js +15 -0
- package/dist/src/types/validation.js.map +1 -0
- package/dist/tools/__tests__/registry.test.d.ts +2 -0
- package/dist/tools/__tests__/registry.test.d.ts.map +1 -0
- package/dist/tools/__tests__/registry.test.js +253 -0
- package/dist/tools/__tests__/registry.test.js.map +1 -0
- package/dist/tools/__tests__/tool.test.d.ts +2 -0
- package/dist/tools/__tests__/tool.test.d.ts.map +1 -0
- package/dist/tools/__tests__/tool.test.js +761 -0
- package/dist/tools/__tests__/tool.test.js.map +1 -0
- package/dist/tools/__tests__/zod-tool.test-d.d.ts +2 -0
- package/dist/tools/__tests__/zod-tool.test-d.d.ts.map +1 -0
- package/dist/tools/__tests__/zod-tool.test-d.js +227 -0
- package/dist/tools/__tests__/zod-tool.test-d.js.map +1 -0
- package/dist/tools/__tests__/zod-tool.test.d.ts +2 -0
- package/dist/tools/__tests__/zod-tool.test.d.ts.map +1 -0
- package/dist/tools/__tests__/zod-tool.test.js +342 -0
- package/dist/tools/__tests__/zod-tool.test.js.map +1 -0
- package/dist/tools/function-tool.d.ts +156 -0
- package/dist/tools/function-tool.d.ts.map +1 -0
- package/dist/tools/function-tool.js +237 -0
- package/dist/tools/function-tool.js.map +1 -0
- package/dist/tools/registry.d.ts +43 -0
- package/dist/tools/registry.d.ts.map +1 -0
- package/dist/tools/registry.js +82 -0
- package/dist/tools/registry.js.map +1 -0
- package/dist/tools/tool.d.ts +157 -0
- package/dist/tools/tool.d.ts.map +1 -0
- package/dist/tools/tool.js +2 -0
- package/dist/tools/tool.js.map +1 -0
- package/dist/tools/types.d.ts +119 -0
- package/dist/tools/types.d.ts.map +1 -0
- package/dist/tools/types.js +2 -0
- package/dist/tools/types.js.map +1 -0
- package/dist/tools/zod-tool.d.ts +70 -0
- package/dist/tools/zod-tool.d.ts.map +1 -0
- package/dist/tools/zod-tool.js +96 -0
- package/dist/tools/zod-tool.js.map +1 -0
- package/dist/types/__tests__/json.test.d.ts +2 -0
- package/dist/types/__tests__/json.test.d.ts.map +1 -0
- package/dist/types/__tests__/json.test.js +129 -0
- package/dist/types/__tests__/json.test.js.map +1 -0
- package/dist/types/__tests__/validation.test.d.ts +2 -0
- package/dist/types/__tests__/validation.test.d.ts.map +1 -0
- package/dist/types/__tests__/validation.test.js +30 -0
- package/dist/types/__tests__/validation.test.js.map +1 -0
- package/dist/types/json.d.ts +45 -0
- package/dist/types/json.d.ts.map +1 -0
- package/dist/types/json.js +17 -0
- package/dist/types/json.js.map +1 -0
- package/dist/types/messages.d.ts +160 -0
- package/dist/types/messages.d.ts.map +1 -0
- package/dist/types/messages.js +2 -0
- package/dist/types/messages.js.map +1 -0
- package/dist/types/validation.d.ts +10 -0
- package/dist/types/validation.d.ts.map +1 -0
- package/dist/types/validation.js +15 -0
- package/dist/types/validation.js.map +1 -0
- package/dist/vended_tools/bash/__tests__/bash.test.d.ts +2 -0
- package/dist/vended_tools/bash/__tests__/bash.test.d.ts.map +1 -0
- package/dist/vended_tools/bash/__tests__/bash.test.js +333 -0
- package/dist/vended_tools/bash/__tests__/bash.test.js.map +1 -0
- package/dist/vended_tools/bash/bash.d.ts +33 -0
- package/dist/vended_tools/bash/bash.d.ts.map +1 -0
- package/dist/vended_tools/bash/bash.js +264 -0
- package/dist/vended_tools/bash/bash.js.map +1 -0
- package/dist/vended_tools/bash/index.d.ts +7 -0
- package/dist/vended_tools/bash/index.d.ts.map +1 -0
- package/dist/vended_tools/bash/index.js +6 -0
- package/dist/vended_tools/bash/index.js.map +1 -0
- package/dist/vended_tools/bash/types.d.ts +65 -0
- package/dist/vended_tools/bash/types.d.ts.map +1 -0
- package/dist/vended_tools/bash/types.js +22 -0
- package/dist/vended_tools/bash/types.js.map +1 -0
- package/dist/vended_tools/file_editor/__tests__/file-editor.test.d.ts +2 -0
- package/dist/vended_tools/file_editor/__tests__/file-editor.test.d.ts.map +1 -0
- package/dist/vended_tools/file_editor/__tests__/file-editor.test.js +359 -0
- package/dist/vended_tools/file_editor/__tests__/file-editor.test.js.map +1 -0
- package/dist/vended_tools/file_editor/file-editor.d.ts +31 -0
- package/dist/vended_tools/file_editor/file-editor.d.ts.map +1 -0
- package/dist/vended_tools/file_editor/file-editor.js +353 -0
- package/dist/vended_tools/file_editor/file-editor.js.map +1 -0
- package/dist/vended_tools/file_editor/index.d.ts +6 -0
- package/dist/vended_tools/file_editor/index.d.ts.map +1 -0
- package/dist/vended_tools/file_editor/index.js +5 -0
- package/dist/vended_tools/file_editor/index.js.map +1 -0
- package/dist/vended_tools/file_editor/types.d.ts +61 -0
- package/dist/vended_tools/file_editor/types.d.ts.map +1 -0
- package/dist/vended_tools/file_editor/types.js +2 -0
- package/dist/vended_tools/file_editor/types.js.map +1 -0
- package/dist/vended_tools/http_request/__tests__/http-request.test.d.ts +2 -0
- package/dist/vended_tools/http_request/__tests__/http-request.test.d.ts.map +1 -0
- package/dist/vended_tools/http_request/__tests__/http-request.test.js +189 -0
- package/dist/vended_tools/http_request/__tests__/http-request.test.js.map +1 -0
- package/dist/vended_tools/http_request/http-request.d.ts +35 -0
- package/dist/vended_tools/http_request/http-request.d.ts.map +1 -0
- package/dist/vended_tools/http_request/http-request.js +95 -0
- package/dist/vended_tools/http_request/http-request.js.map +1 -0
- package/dist/vended_tools/http_request/index.d.ts +6 -0
- package/dist/vended_tools/http_request/index.d.ts.map +1 -0
- package/dist/vended_tools/http_request/index.js +5 -0
- package/dist/vended_tools/http_request/index.js.map +1 -0
- package/dist/vended_tools/http_request/types.d.ts +47 -0
- package/dist/vended_tools/http_request/types.d.ts.map +1 -0
- package/dist/vended_tools/http_request/types.js +2 -0
- package/dist/vended_tools/http_request/types.js.map +1 -0
- package/dist/vended_tools/notebook/__tests__/notebook.test.d.ts +2 -0
- package/dist/vended_tools/notebook/__tests__/notebook.test.d.ts.map +1 -0
- package/dist/vended_tools/notebook/__tests__/notebook.test.js +371 -0
- package/dist/vended_tools/notebook/__tests__/notebook.test.js.map +1 -0
- package/dist/vended_tools/notebook/index.d.ts +6 -0
- package/dist/vended_tools/notebook/index.d.ts.map +1 -0
- package/dist/vended_tools/notebook/index.js +5 -0
- package/dist/vended_tools/notebook/index.js.map +1 -0
- package/dist/vended_tools/notebook/notebook.d.ts +29 -0
- package/dist/vended_tools/notebook/notebook.d.ts.map +1 -0
- package/dist/vended_tools/notebook/notebook.js +215 -0
- package/dist/vended_tools/notebook/notebook.js.map +1 -0
- package/dist/vended_tools/notebook/types.d.ts +79 -0
- package/dist/vended_tools/notebook/types.d.ts.map +1 -0
- package/dist/vended_tools/notebook/types.js +2 -0
- package/dist/vended_tools/notebook/types.js.map +1 -0
- package/package.json +112 -0
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { deepCopy } from '../types/json';
|
|
2
|
+
/**
|
|
3
|
+
* A Tool implementation that wraps a callback function and handles all ToolResult conversion.
|
|
4
|
+
*
|
|
5
|
+
* FunctionTool allows creating tools from existing functions without needing to manually
|
|
6
|
+
* handle ToolResult formatting or error handling. It supports multiple callback patterns:
|
|
7
|
+
* - Async generators for streaming responses
|
|
8
|
+
* - Promises for async operations
|
|
9
|
+
* - Synchronous functions for immediate results
|
|
10
|
+
*
|
|
11
|
+
* All return values are automatically wrapped in ToolResult, and errors are caught and
|
|
12
|
+
* returned as error ToolResults.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* // Create a tool with streaming
|
|
17
|
+
* const streamingTool = new FunctionTool({
|
|
18
|
+
* name: 'processor',
|
|
19
|
+
* description: 'Processes data with progress updates',
|
|
20
|
+
* inputSchema: { type: 'object', properties: { data: { type: 'string' } } },
|
|
21
|
+
* callback: async function* (input: any) {
|
|
22
|
+
* yield 'Starting processing...'
|
|
23
|
+
* // Do some work
|
|
24
|
+
* yield 'Halfway done...'
|
|
25
|
+
* // More work
|
|
26
|
+
* return 'Processing complete!'
|
|
27
|
+
* }
|
|
28
|
+
* })
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export class FunctionTool {
|
|
32
|
+
/**
|
|
33
|
+
* The unique name of the tool.
|
|
34
|
+
*/
|
|
35
|
+
toolName;
|
|
36
|
+
/**
|
|
37
|
+
* Human-readable description of what the tool does.
|
|
38
|
+
*/
|
|
39
|
+
description;
|
|
40
|
+
/**
|
|
41
|
+
* OpenAPI JSON specification for the tool.
|
|
42
|
+
*/
|
|
43
|
+
toolSpec;
|
|
44
|
+
/**
|
|
45
|
+
* The callback function that implements the tool's logic.
|
|
46
|
+
*/
|
|
47
|
+
_callback;
|
|
48
|
+
/**
|
|
49
|
+
* Creates a new FunctionTool instance.
|
|
50
|
+
*
|
|
51
|
+
* @param config - Configuration object for the tool
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* const tool = new FunctionTool({
|
|
56
|
+
* name: 'greeter',
|
|
57
|
+
* description: 'Greets a person by name',
|
|
58
|
+
* inputSchema: {
|
|
59
|
+
* type: 'object',
|
|
60
|
+
* properties: { name: { type: 'string' } },
|
|
61
|
+
* required: ['name']
|
|
62
|
+
* },
|
|
63
|
+
* callback: (input: any) => `Hello, ${input.name}!`
|
|
64
|
+
* })
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
constructor(config) {
|
|
68
|
+
this.toolName = config.name;
|
|
69
|
+
this.description = config.description;
|
|
70
|
+
this.toolSpec = {
|
|
71
|
+
name: config.name,
|
|
72
|
+
description: config.description,
|
|
73
|
+
inputSchema: config.inputSchema,
|
|
74
|
+
};
|
|
75
|
+
this._callback = config.callback;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Executes the tool with streaming support.
|
|
79
|
+
* Handles all callback patterns (async generator, promise, sync) and converts results to ToolResult.
|
|
80
|
+
*
|
|
81
|
+
* @param toolContext - Context information including the tool use request and invocation state
|
|
82
|
+
* @returns Async generator that yields ToolStreamEvents and returns a ToolResult
|
|
83
|
+
*/
|
|
84
|
+
async *stream(toolContext) {
|
|
85
|
+
const { toolUse } = toolContext;
|
|
86
|
+
try {
|
|
87
|
+
const result = this._callback(toolUse.input, toolContext);
|
|
88
|
+
// Check if result is an async generator
|
|
89
|
+
if (result && typeof result === 'object' && Symbol.asyncIterator in result) {
|
|
90
|
+
// Handle async generator: yield each value as ToolStreamEvent, wrap final value in ToolResult
|
|
91
|
+
const generator = result;
|
|
92
|
+
// Iterate through all yielded values
|
|
93
|
+
let iterResult = await generator.next();
|
|
94
|
+
while (!iterResult.done) {
|
|
95
|
+
// Each yielded value becomes a ToolStreamEvent
|
|
96
|
+
yield {
|
|
97
|
+
type: 'toolStreamEvent',
|
|
98
|
+
data: iterResult.value,
|
|
99
|
+
};
|
|
100
|
+
iterResult = await generator.next();
|
|
101
|
+
}
|
|
102
|
+
// The generator's return value (when done = true) is wrapped in ToolResult
|
|
103
|
+
return this._wrapInToolResult(iterResult.value, toolUse.toolUseId);
|
|
104
|
+
}
|
|
105
|
+
else if (result instanceof Promise) {
|
|
106
|
+
// Handle promise: await and wrap in ToolResult
|
|
107
|
+
const value = await result;
|
|
108
|
+
return this._wrapInToolResult(value, toolUse.toolUseId);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
// Handle synchronous value: wrap in ToolResult
|
|
112
|
+
return this._wrapInToolResult(result, toolUse.toolUseId);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
// Handle any errors and yield as error ToolResult
|
|
117
|
+
return this._createErrorResult(error, toolUse.toolUseId);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Wraps a value in a ToolResult with success status.
|
|
122
|
+
*
|
|
123
|
+
* Due to AWS Bedrock limitations (only accepts objects as JSON content), the following
|
|
124
|
+
* rules are applied:
|
|
125
|
+
* - Strings → toolResultTextContent
|
|
126
|
+
* - Numbers, Booleans → toolResultTextContent (converted to string)
|
|
127
|
+
* - null, undefined → toolResultTextContent (special string representation)
|
|
128
|
+
* - Objects → toolResultJsonContent (with deep copy)
|
|
129
|
+
* - Arrays → toolResultJsonContent wrapped in \{ $value: array \} (with deep copy)
|
|
130
|
+
*
|
|
131
|
+
* @param value - The value to wrap (can be any type)
|
|
132
|
+
* @param toolUseId - The tool use ID for the ToolResult
|
|
133
|
+
* @returns A ToolResult containing the value
|
|
134
|
+
*/
|
|
135
|
+
_wrapInToolResult(value, toolUseId) {
|
|
136
|
+
try {
|
|
137
|
+
// Handle null with special string representation as text content
|
|
138
|
+
if (value === null) {
|
|
139
|
+
return {
|
|
140
|
+
toolUseId,
|
|
141
|
+
status: 'success',
|
|
142
|
+
content: [
|
|
143
|
+
{
|
|
144
|
+
type: 'toolResultTextContent',
|
|
145
|
+
text: '<null>',
|
|
146
|
+
},
|
|
147
|
+
],
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
// Handle undefined with special string representation as text content
|
|
151
|
+
if (value === undefined) {
|
|
152
|
+
return {
|
|
153
|
+
toolUseId,
|
|
154
|
+
status: 'success',
|
|
155
|
+
content: [
|
|
156
|
+
{
|
|
157
|
+
type: 'toolResultTextContent',
|
|
158
|
+
text: '<undefined>',
|
|
159
|
+
},
|
|
160
|
+
],
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
// Handle primitives (strings, numbers, booleans) as text content
|
|
164
|
+
// Bedrock doesn't accept primitives as JSON content, so we convert all to strings
|
|
165
|
+
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
|
|
166
|
+
return {
|
|
167
|
+
toolUseId,
|
|
168
|
+
status: 'success',
|
|
169
|
+
content: [
|
|
170
|
+
{
|
|
171
|
+
type: 'toolResultTextContent',
|
|
172
|
+
text: String(value),
|
|
173
|
+
},
|
|
174
|
+
],
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
// Handle arrays by wrapping in object { $value: array }
|
|
178
|
+
if (Array.isArray(value)) {
|
|
179
|
+
const copiedValue = deepCopy(value);
|
|
180
|
+
return {
|
|
181
|
+
toolUseId,
|
|
182
|
+
status: 'success',
|
|
183
|
+
content: [
|
|
184
|
+
{
|
|
185
|
+
type: 'toolResultJsonContent',
|
|
186
|
+
json: { $value: copiedValue },
|
|
187
|
+
},
|
|
188
|
+
],
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
// Handle objects as JSON content with deep copy
|
|
192
|
+
const copiedValue = deepCopy(value);
|
|
193
|
+
return {
|
|
194
|
+
toolUseId,
|
|
195
|
+
status: 'success',
|
|
196
|
+
content: [
|
|
197
|
+
{
|
|
198
|
+
type: 'toolResultJsonContent',
|
|
199
|
+
json: copiedValue,
|
|
200
|
+
},
|
|
201
|
+
],
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
catch (error) {
|
|
205
|
+
// If deep copy fails (circular references, non-serializable values), return error result
|
|
206
|
+
return this._createErrorResult(error, toolUseId);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Creates an error ToolResult from an error object.
|
|
211
|
+
* Ensures all errors are normalized to Error objects and includes the original error
|
|
212
|
+
* in the ToolResult for inspection by hooks, error handlers, and event loop.
|
|
213
|
+
*
|
|
214
|
+
* TODO: Implement consistent logging format as defined in #30
|
|
215
|
+
* This error should be logged to the caller using the established logging pattern.
|
|
216
|
+
*
|
|
217
|
+
* @param error - The error that occurred (can be Error object or any thrown value)
|
|
218
|
+
* @param toolUseId - The tool use ID for the ToolResult
|
|
219
|
+
* @returns A ToolResult with error status, error message content, and original error object
|
|
220
|
+
*/
|
|
221
|
+
_createErrorResult(error, toolUseId) {
|
|
222
|
+
// Ensure error is an Error object (wrap non-Error values)
|
|
223
|
+
const errorObject = error instanceof Error ? error : new Error(String(error));
|
|
224
|
+
return {
|
|
225
|
+
toolUseId,
|
|
226
|
+
status: 'error',
|
|
227
|
+
content: [
|
|
228
|
+
{
|
|
229
|
+
type: 'toolResultTextContent',
|
|
230
|
+
text: `Error: ${errorObject.message}`,
|
|
231
|
+
},
|
|
232
|
+
],
|
|
233
|
+
error: errorObject,
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
//# sourceMappingURL=function-tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"function-tool.js","sourceRoot":"","sources":["../../src/tools/function-tool.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAuDxC;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,OAAO,YAAY;IACvB;;OAEG;IACM,QAAQ,CAAQ;IAEzB;;OAEG;IACM,WAAW,CAAQ;IAE5B;;OAEG;IACM,QAAQ,CAAU;IAE3B;;OAEG;IACc,SAAS,CAAsB;IAEhD;;;;;;;;;;;;;;;;;;OAkBG;IACH,YAAY,MAA0B;QACpC,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAA;QAC3B,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAA;QACrC,IAAI,CAAC,QAAQ,GAAG;YACd,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,WAAW,EAAE,MAAM,CAAC,WAAW;YAC/B,WAAW,EAAE,MAAM,CAAC,WAAW;SAChC,CAAA;QACD,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAA;IAClC,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,CAAC,MAAM,CAAC,WAAwB;QACpC,MAAM,EAAE,OAAO,EAAE,GAAG,WAAW,CAAA;QAE/B,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,WAAW,CAAC,CAAA;YAEzD,wCAAwC;YACxC,IAAI,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,CAAC,aAAa,IAAI,MAAM,EAAE,CAAC;gBAC3E,8FAA8F;gBAC9F,MAAM,SAAS,GAAG,MAA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ACK,kBAAkB,CAAC,KAAc,EAAE,SAAiB;QAC1D,0DAA0D;QAC1D,MAAM,WAAW,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;QAE7E,OAAO;YACL,SAAS;YACT,MAAM,EAAE,OAAO;YACf,OAAO,EAAE;gBACP;oBACE,IAAI,EAAE,uBAAuB;oBAC7B,IAAI,EAAE,UAAU,WAAW,CAAC,OAAO,EAAE;iBACtC;aACF;YACD,KAAK,EAAE,WAAW;SACnB,CAAA;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Tool } from './tool';
|
|
2
|
+
/**
|
|
3
|
+
* Registry for managing Tool instances.
|
|
4
|
+
*/
|
|
5
|
+
export declare class ToolRegistry {
|
|
6
|
+
private readonly _tools;
|
|
7
|
+
/**
|
|
8
|
+
* Creates a new ToolRegistry instance with an empty registry.
|
|
9
|
+
*/
|
|
10
|
+
constructor();
|
|
11
|
+
/**
|
|
12
|
+
* Registers one or more tools with the registry.
|
|
13
|
+
* Accepts single Tool or array of Tools for convenience.
|
|
14
|
+
*
|
|
15
|
+
* @param tool - Single Tool instance or array of Tool instances to register
|
|
16
|
+
* @throws If a tool with duplicate name already exists
|
|
17
|
+
* @throws If tool name is invalid (must be 1-64 chars, alphanumeric with hyphens/underscores)
|
|
18
|
+
* @throws If tool description is empty
|
|
19
|
+
*/
|
|
20
|
+
register(tool: Tool | Tool[]): void;
|
|
21
|
+
/**
|
|
22
|
+
* Retrieves a tool by its unique name.
|
|
23
|
+
*
|
|
24
|
+
* @param name - The unique name of the tool to retrieve
|
|
25
|
+
* @returns The Tool instance, or undefined if not found
|
|
26
|
+
*/
|
|
27
|
+
get(name: string): Tool | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Removes a tool from the registry.
|
|
30
|
+
*
|
|
31
|
+
* @param name - The name of the tool to remove
|
|
32
|
+
* @throws If tool with given name doesn't exist
|
|
33
|
+
*/
|
|
34
|
+
remove(name: string): void;
|
|
35
|
+
/**
|
|
36
|
+
* Returns all registered tools as an array.
|
|
37
|
+
* Returns a copy of the internal array to prevent external mutation.
|
|
38
|
+
*
|
|
39
|
+
* @returns Array of all registered Tool instances, or empty array if no tools registered
|
|
40
|
+
*/
|
|
41
|
+
list(): Tool[];
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/tools/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAElC;;GAEG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAmB;IAE1C;;OAEG;;IAKH;;;;;;;;OAQG;IACI,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,EAAE,GAAG,IAAI;IAoC1C;;;;;OAKG;IACI,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS;IAI1C;;;;;OAKG;IACI,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IASjC;;;;;OAKG;IACI,IAAI,IAAI,IAAI,EAAE;CAGtB"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Registry for managing Tool instances.
|
|
3
|
+
*/
|
|
4
|
+
export class ToolRegistry {
|
|
5
|
+
_tools;
|
|
6
|
+
/**
|
|
7
|
+
* Creates a new ToolRegistry instance with an empty registry.
|
|
8
|
+
*/
|
|
9
|
+
constructor() {
|
|
10
|
+
this._tools = new Map();
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Registers one or more tools with the registry.
|
|
14
|
+
* Accepts single Tool or array of Tools for convenience.
|
|
15
|
+
*
|
|
16
|
+
* @param tool - Single Tool instance or array of Tool instances to register
|
|
17
|
+
* @throws If a tool with duplicate name already exists
|
|
18
|
+
* @throws If tool name is invalid (must be 1-64 chars, alphanumeric with hyphens/underscores)
|
|
19
|
+
* @throws If tool description is empty
|
|
20
|
+
*/
|
|
21
|
+
register(tool) {
|
|
22
|
+
const tools = Array.isArray(tool) ? tool : [tool];
|
|
23
|
+
for (const t of tools) {
|
|
24
|
+
// Validate tool name is a string
|
|
25
|
+
if (typeof t.toolName !== 'string') {
|
|
26
|
+
throw new Error('Tool name must be a string');
|
|
27
|
+
}
|
|
28
|
+
// Validate tool name length (1-64 characters)
|
|
29
|
+
if (t.toolName.length < 1 || t.toolName.length > 64) {
|
|
30
|
+
throw new Error('Tool name must be between 1 and 64 characters');
|
|
31
|
+
}
|
|
32
|
+
// Validate tool name pattern (alphanumeric with hyphens and underscores)
|
|
33
|
+
const validNamePattern = /^[a-zA-Z0-9_-]+$/;
|
|
34
|
+
if (!validNamePattern.test(t.toolName)) {
|
|
35
|
+
throw new Error('Tool name must contain only alphanumeric characters, hyphens, and underscores');
|
|
36
|
+
}
|
|
37
|
+
// Validate tool description if present
|
|
38
|
+
if (t.description !== undefined && t.description !== null) {
|
|
39
|
+
if (typeof t.description !== 'string' || t.description.length < 1) {
|
|
40
|
+
throw new Error('Tool description must be a non-empty string');
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// Check for duplicate names
|
|
44
|
+
if (this._tools.has(t.toolName)) {
|
|
45
|
+
throw new Error(`Tool with name '${t.toolName}' already registered`);
|
|
46
|
+
}
|
|
47
|
+
this._tools.set(t.toolName, t);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Retrieves a tool by its unique name.
|
|
52
|
+
*
|
|
53
|
+
* @param name - The unique name of the tool to retrieve
|
|
54
|
+
* @returns The Tool instance, or undefined if not found
|
|
55
|
+
*/
|
|
56
|
+
get(name) {
|
|
57
|
+
return this._tools.get(name);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Removes a tool from the registry.
|
|
61
|
+
*
|
|
62
|
+
* @param name - The name of the tool to remove
|
|
63
|
+
* @throws If tool with given name doesn't exist
|
|
64
|
+
*/
|
|
65
|
+
remove(name) {
|
|
66
|
+
// Check if tool exists
|
|
67
|
+
if (!this._tools.has(name)) {
|
|
68
|
+
throw new Error(`Tool with name '${name}' not found`);
|
|
69
|
+
}
|
|
70
|
+
this._tools.delete(name);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Returns all registered tools as an array.
|
|
74
|
+
* Returns a copy of the internal array to prevent external mutation.
|
|
75
|
+
*
|
|
76
|
+
* @returns Array of all registered Tool instances, or empty array if no tools registered
|
|
77
|
+
*/
|
|
78
|
+
list() {
|
|
79
|
+
return Array.from(this._tools.values());
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/tools/registry.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,OAAO,YAAY;IACN,MAAM,CAAmB;IAE1C;;OAEG;IACH;QACE,IAAI,CAAC,MAAM,GAAG,IAAI,GAAG,EAAgB,CAAA;IACvC,CAAC;IAED;;;;;;;;OAQG;IACI,QAAQ,CAAC,IAAmB;QACjC,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;QAEjD,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC;YACtB,iCAAiC;YACjC,IAAI,OAAO,CAAC,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;gBACnC,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAA;YAC/C,CAAC;YAED,8CAA8C;YAC9C,IAAI,CAAC,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,CA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AAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IAC1B,CAAC;IAED;;;;;OAKG;IACI,IAAI;QACT,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAA;IACzC,CAAC;CACF"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import type { ToolSpec, ToolUse, ToolResult } from './types';
|
|
2
|
+
export type { ToolSpec } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Context provided to tool implementations during execution.
|
|
5
|
+
* Contains framework-level state and information from the agent invocation.
|
|
6
|
+
*
|
|
7
|
+
* @typeParam T - Optional type for strongly typing invocationState. Callers can pass any object
|
|
8
|
+
* as invocationState (including references), but it must be a dictionary/object.
|
|
9
|
+
* T allows strong typing when desired, while Record\<string, unknown\> accepts any object.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* interface MyState {
|
|
14
|
+
* userId: string
|
|
15
|
+
* sessionId: string
|
|
16
|
+
* }
|
|
17
|
+
*
|
|
18
|
+
* const context: ToolContext<MyState> = {
|
|
19
|
+
* invocationState: {
|
|
20
|
+
* userId: 'user-123',
|
|
21
|
+
* sessionId: 'session-456'
|
|
22
|
+
* }
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export interface ToolContext<T extends Record<string, unknown> = Record<string, unknown>> {
|
|
27
|
+
/**
|
|
28
|
+
* The tool use request that triggered this tool execution.
|
|
29
|
+
* Contains the tool name, toolUseId, and input parameters.
|
|
30
|
+
*/
|
|
31
|
+
toolUse: ToolUse;
|
|
32
|
+
/**
|
|
33
|
+
* Caller-provided state from agent invocation.
|
|
34
|
+
* This allows passing context from the agent level down to tool execution.
|
|
35
|
+
*/
|
|
36
|
+
invocationState: T;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Event yielded during tool execution to report streaming progress.
|
|
40
|
+
* Tools can yield zero or more of these events before returning the final ToolResult.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* const streamEvent: ToolStreamEvent = {
|
|
45
|
+
* type: 'toolStreamEvent',
|
|
46
|
+
* data: 'Processing step 1...'
|
|
47
|
+
* }
|
|
48
|
+
*
|
|
49
|
+
* // Or with structured data
|
|
50
|
+
* const streamEvent: ToolStreamEvent = {
|
|
51
|
+
* type: 'toolStreamEvent',
|
|
52
|
+
* data: { progress: 50, message: 'Halfway complete' }
|
|
53
|
+
* }
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export interface ToolStreamEvent {
|
|
57
|
+
/**
|
|
58
|
+
* Discriminator for tool stream events.
|
|
59
|
+
*/
|
|
60
|
+
type: 'toolStreamEvent';
|
|
61
|
+
/**
|
|
62
|
+
* Caller-provided data for the progress update.
|
|
63
|
+
* Can be any type of data the tool wants to report.
|
|
64
|
+
*/
|
|
65
|
+
data?: unknown;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Type alias for the async generator returned by tool stream methods.
|
|
69
|
+
* Yields ToolStreamEvents during execution and returns a ToolResult.
|
|
70
|
+
*/
|
|
71
|
+
export type ToolStreamGenerator = AsyncGenerator<ToolStreamEvent, ToolResult, never>;
|
|
72
|
+
/**
|
|
73
|
+
* Interface for tool implementations.
|
|
74
|
+
* Tools are used by agents to interact with their environment and perform specific actions.
|
|
75
|
+
*
|
|
76
|
+
* The Tool interface provides a streaming execution model where tools can yield
|
|
77
|
+
* progress events during execution before returning a final result.
|
|
78
|
+
*
|
|
79
|
+
* Most implementations should use FunctionTool rather than implementing this interface directly.
|
|
80
|
+
*/
|
|
81
|
+
export interface Tool {
|
|
82
|
+
/**
|
|
83
|
+
* The unique name of the tool.
|
|
84
|
+
* This MUST match the name in the toolSpec.
|
|
85
|
+
*/
|
|
86
|
+
toolName: string;
|
|
87
|
+
/**
|
|
88
|
+
* Human-readable description of what the tool does.
|
|
89
|
+
* This helps the model understand when to use the tool.
|
|
90
|
+
*
|
|
91
|
+
* This MUST match the description in the toolSpec.description.
|
|
92
|
+
*/
|
|
93
|
+
description: string;
|
|
94
|
+
/**
|
|
95
|
+
* OpenAPI JSON specification for the tool.
|
|
96
|
+
* Defines the tool's name, description, and input schema.
|
|
97
|
+
*/
|
|
98
|
+
toolSpec: ToolSpec;
|
|
99
|
+
/**
|
|
100
|
+
* Executes the tool with streaming support.
|
|
101
|
+
* Yields zero or more ToolStreamEvents during execution, then returns
|
|
102
|
+
* exactly one ToolResult as the final value.
|
|
103
|
+
*
|
|
104
|
+
* @param toolContext - Context information including the tool use request and invocation state
|
|
105
|
+
* @returns Async generator that yields ToolStreamEvents and returns a ToolResult
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```typescript
|
|
109
|
+
* const context = {
|
|
110
|
+
* toolUse: {
|
|
111
|
+
* name: 'calculator',
|
|
112
|
+
* toolUseId: 'calc-123',
|
|
113
|
+
* input: { operation: 'add', a: 5, b: 3 }
|
|
114
|
+
* },
|
|
115
|
+
* invocationState: {}
|
|
116
|
+
* }
|
|
117
|
+
*
|
|
118
|
+
* // The return value is only accessible via explicit .next() calls
|
|
119
|
+
* const generator = tool.stream(context)
|
|
120
|
+
* for await (const event of generator) {
|
|
121
|
+
* // Only yields are captured here
|
|
122
|
+
* console.log('Progress:', event.data)
|
|
123
|
+
* }
|
|
124
|
+
* // Or manually handle the return value:
|
|
125
|
+
* let result = await generator.next()
|
|
126
|
+
* while (!result.done) {
|
|
127
|
+
* console.log('Progress:', result.value.data)
|
|
128
|
+
* result = await generator.next()
|
|
129
|
+
* }
|
|
130
|
+
* console.log('Final result:', result.value.status)
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
stream(toolContext: ToolContext): ToolStreamGenerator;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Extended tool interface that supports direct invocation with type-safe input and output.
|
|
137
|
+
* This interface is useful for testing and standalone tool execution.
|
|
138
|
+
*
|
|
139
|
+
* @typeParam TInput - Type for the tool's input parameters
|
|
140
|
+
* @typeParam TReturn - Type for the tool's return value
|
|
141
|
+
*/
|
|
142
|
+
export interface InvokableTool<TInput, TReturn> extends Tool {
|
|
143
|
+
/**
|
|
144
|
+
* Invokes the tool directly with type-safe input and returns the unwrapped result.
|
|
145
|
+
*
|
|
146
|
+
* Unlike stream(), this method:
|
|
147
|
+
* - Returns the raw result (not wrapped in ToolResult)
|
|
148
|
+
* - Consumes async generators and returns only the final value
|
|
149
|
+
* - Lets errors throw naturally (not wrapped in error ToolResult)
|
|
150
|
+
*
|
|
151
|
+
* @param input - The input parameters for the tool
|
|
152
|
+
* @param context - Optional tool execution context
|
|
153
|
+
* @returns The unwrapped result
|
|
154
|
+
*/
|
|
155
|
+
invoke(input: TInput, context?: ToolContext): Promise<TReturn>;
|
|
156
|
+
}
|
|
157
|
+
//# sourceMappingURL=tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../../src/tools/tool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAE5D,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAEvC;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACtF;;;OAGG;IACH,OAAO,EAAE,OAAO,CAAA;IAEhB;;;OAGG;IACH,eAAe,EAAE,CAAC,CAAA;CACnB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,IAAI,EAAE,iBAAiB,CAAA;IAEvB;;;OAGG;IACH,IAAI,CAAC,EAAE,OAAO,CAAA;CACf;AAED;;;GAGG;AACH,MAAM,MAAM,mBAAmB,GAAG,cAAc,CAAC,eAAe,EAAE,UAAU,EAAE,KAAK,CAAC,CAAA;AAEpF;;;;;;;;GAQG;AACH,MAAM,WAAW,IAAI;IACnB;;;OAGG;IACH,QAAQ,EAAE,MAAM,CAAA;IAEhB;;;;;OAKG;IACH,WAAW,EAAE,MAAM,CAAA;IAEnB;;;OAGG;IACH,QAAQ,EAAE,QAAQ,CAAA;IAElB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiCG;IACH,MAAM,CAAC,WAAW,EAAE,WAAW,GAAG,mBAAmB,CAAA;CACtD;AAED;;;;;;GAMG;AACH,MAAM,WAAW,aAAa,CAAC,MAAM,EAAE,OAAO,CAAE,SAAQ,IAAI;IAC1D;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;CAC/D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool.js","sourceRoot":"","sources":["../../src/tools/tool.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import type { JSONSchema, JSONValue } from '../types/json';
|
|
2
|
+
/**
|
|
3
|
+
* Result of a tool execution.
|
|
4
|
+
* Contains the outcome and any data returned by the tool.
|
|
5
|
+
*/
|
|
6
|
+
export interface ToolResult {
|
|
7
|
+
/**
|
|
8
|
+
* The ID of the tool use that this result corresponds to.
|
|
9
|
+
*/
|
|
10
|
+
toolUseId: string;
|
|
11
|
+
/**
|
|
12
|
+
* Status indicating success or error.
|
|
13
|
+
*/
|
|
14
|
+
status: ToolResultStatus;
|
|
15
|
+
/**
|
|
16
|
+
* Array of content blocks containing the tool's output.
|
|
17
|
+
*/
|
|
18
|
+
content: ToolResultContent[];
|
|
19
|
+
/**
|
|
20
|
+
* The original error object when status is 'error'.
|
|
21
|
+
* Available for inspection by hooks, error handlers, and event loop.
|
|
22
|
+
* Tools must wrap non-Error thrown values into Error objects.
|
|
23
|
+
*/
|
|
24
|
+
error?: Error;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Status of a tool execution.
|
|
28
|
+
* Indicates whether the tool executed successfully or encountered an error.
|
|
29
|
+
*/
|
|
30
|
+
export type ToolResultStatus = 'success' | 'error';
|
|
31
|
+
/**
|
|
32
|
+
* Content returned from a tool execution.
|
|
33
|
+
* Can be either text or structured JSON data.
|
|
34
|
+
*
|
|
35
|
+
* This is a discriminated union where the `type` field determines the content format.
|
|
36
|
+
*/
|
|
37
|
+
export type ToolResultContent = ToolResultTextContent | ToolResultJsonContent;
|
|
38
|
+
/**
|
|
39
|
+
* Text content returned from a tool execution.
|
|
40
|
+
*/
|
|
41
|
+
export interface ToolResultTextContent {
|
|
42
|
+
/**
|
|
43
|
+
* Discriminator for text content.
|
|
44
|
+
*/
|
|
45
|
+
type: 'toolResultTextContent';
|
|
46
|
+
/**
|
|
47
|
+
* Plain text result from the tool.
|
|
48
|
+
*/
|
|
49
|
+
text: string;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* JSON content returned from a tool execution.
|
|
53
|
+
*/
|
|
54
|
+
export interface ToolResultJsonContent {
|
|
55
|
+
/**
|
|
56
|
+
* Discriminator for JSON content.
|
|
57
|
+
*/
|
|
58
|
+
type: 'toolResultJsonContent';
|
|
59
|
+
/**
|
|
60
|
+
* Structured JSON result from the tool.
|
|
61
|
+
*/
|
|
62
|
+
json: JSONValue;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Specification for a tool that can be used by the model.
|
|
66
|
+
* Defines the tool's name, description, and input schema.
|
|
67
|
+
*/
|
|
68
|
+
export interface ToolSpec {
|
|
69
|
+
/**
|
|
70
|
+
* The unique name of the tool.
|
|
71
|
+
*/
|
|
72
|
+
name: string;
|
|
73
|
+
/**
|
|
74
|
+
* A description of what the tool does.
|
|
75
|
+
* This helps the model understand when to use the tool.
|
|
76
|
+
*/
|
|
77
|
+
description: string;
|
|
78
|
+
/**
|
|
79
|
+
* JSON Schema defining the expected input structure for the tool.
|
|
80
|
+
*/
|
|
81
|
+
inputSchema: JSONSchema;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Represents a tool usage request from the model.
|
|
85
|
+
* The model generates this when it wants to use a tool.
|
|
86
|
+
*/
|
|
87
|
+
export interface ToolUse {
|
|
88
|
+
/**
|
|
89
|
+
* The name of the tool to execute.
|
|
90
|
+
*/
|
|
91
|
+
name: string;
|
|
92
|
+
/**
|
|
93
|
+
* Unique identifier for this tool use instance.
|
|
94
|
+
* Used to match tool results back to their requests.
|
|
95
|
+
*/
|
|
96
|
+
toolUseId: string;
|
|
97
|
+
/**
|
|
98
|
+
* The input parameters for the tool.
|
|
99
|
+
* Must be JSON-serializable.
|
|
100
|
+
*/
|
|
101
|
+
input: JSONValue;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Specifies how the model should choose which tool to use.
|
|
105
|
+
*
|
|
106
|
+
* - `{ auto: {} }` - Let the model decide whether to use a tool
|
|
107
|
+
* - `{ any: {} }` - Force the model to use one of the available tools
|
|
108
|
+
* - `{ tool: { name: 'toolName' } }` - Force the model to use a specific tool
|
|
109
|
+
*/
|
|
110
|
+
export type ToolChoice = {
|
|
111
|
+
auto: Record<string, never>;
|
|
112
|
+
} | {
|
|
113
|
+
any: Record<string, never>;
|
|
114
|
+
} | {
|
|
115
|
+
tool: {
|
|
116
|
+
name: string;
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/tools/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAE1D;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB;;O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