@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 @@
|
|
|
1
|
+
{"version":3,"file":"http-request.test.js","sourceRoot":"","sources":["../../../../vended_tools/http_request/__tests__/http-request.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AACxE,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAEhD,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;IAChC,MAAM,aAAa,GAAG,UAAU,CAAC,KAAK,CAAA;IAEtC,UAAU,CAAC,GAAG,EAAE;QACd,EAAE,CAAC,aAAa,EAAE,CAAA;IACpB,CAAC,CAAC,CAAA;IAEF,SAAS,CAAC,GAAG,EAAE;QACb,UAAU,CAAC,KAAK,GAAG,aAAa,CAAA;IAClC,CAAC,CAAC,CAAA;IAEF,QAAQ,CAAC,IAAI,CAAC;QACZ,EAAE,MAAM,EAAE,KAAc,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE;QACzD,EAAE,MAAM,EAAE,MAAe,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,SAAS,EAAE;QAC/D,EAAE,MAAM,EAAE,KAAc,EAAE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4
|
+
* Supports all standard HTTP methods (GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS)
|
|
5
|
+
* and provides comprehensive request configuration including headers, body, and timeout.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* // With agent
|
|
10
|
+
* const agent = new Agent({ tools: [httpRequest] })
|
|
11
|
+
* await agent.invoke('Make a GET request to https://api.example.com/data')
|
|
12
|
+
*
|
|
13
|
+
* // Direct usage
|
|
14
|
+
* const response = await httpRequest.invoke({
|
|
15
|
+
* method: 'POST',
|
|
16
|
+
* url: 'https://api.example.com/users',
|
|
17
|
+
* headers: { 'Content-Type': 'application/json' },
|
|
18
|
+
* body: '{"name":"test"}',
|
|
19
|
+
* timeout: 10
|
|
20
|
+
* })
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare const httpRequest: import("../../src/index.js").InvokableTool<{
|
|
24
|
+
method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "HEAD" | "OPTIONS";
|
|
25
|
+
url: string;
|
|
26
|
+
headers?: Record<string, string> | undefined;
|
|
27
|
+
body?: string | undefined;
|
|
28
|
+
timeout?: number | undefined;
|
|
29
|
+
}, {
|
|
30
|
+
status: number;
|
|
31
|
+
statusText: string;
|
|
32
|
+
headers: Record<string, string>;
|
|
33
|
+
body: string;
|
|
34
|
+
}>;
|
|
35
|
+
//# sourceMappingURL=http-request.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-request.d.ts","sourceRoot":"","sources":["../../../vended_tools/http_request/http-request.ts"],"names":[],"mappings":"AAiBA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,WAAW;;;;;;;;;;;EAmEtB,CAAA"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/* eslint-env browser, node */
|
|
2
|
+
import { tool } from '../../src/tools/zod-tool.js';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
/**
|
|
5
|
+
* Zod schema for HTTP request input validation.
|
|
6
|
+
*/
|
|
7
|
+
const httpRequestInputSchema = z.object({
|
|
8
|
+
method: z
|
|
9
|
+
.enum(['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'])
|
|
10
|
+
.describe('HTTP method to use for the request'),
|
|
11
|
+
url: z.string().url().describe('URL to send the request to'),
|
|
12
|
+
headers: z.record(z.string(), z.string()).optional().describe('Optional HTTP headers as key-value pairs'),
|
|
13
|
+
body: z.string().optional().describe('Optional request body as a string'),
|
|
14
|
+
timeout: z.number().positive().optional().describe('Optional timeout in seconds (default: 30)'),
|
|
15
|
+
});
|
|
16
|
+
/**
|
|
17
|
+
* HTTP request tool for making HTTP requests to external APIs.
|
|
18
|
+
*
|
|
19
|
+
* Supports all standard HTTP methods (GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS)
|
|
20
|
+
* and provides comprehensive request configuration including headers, body, and timeout.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* // With agent
|
|
25
|
+
* const agent = new Agent({ tools: [httpRequest] })
|
|
26
|
+
* await agent.invoke('Make a GET request to https://api.example.com/data')
|
|
27
|
+
*
|
|
28
|
+
* // Direct usage
|
|
29
|
+
* const response = await httpRequest.invoke({
|
|
30
|
+
* method: 'POST',
|
|
31
|
+
* url: 'https://api.example.com/users',
|
|
32
|
+
* headers: { 'Content-Type': 'application/json' },
|
|
33
|
+
* body: '{"name":"test"}',
|
|
34
|
+
* timeout: 10
|
|
35
|
+
* })
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export const httpRequest = tool({
|
|
39
|
+
name: 'http_request',
|
|
40
|
+
description: 'Makes HTTP requests to external APIs. Supports GET, POST, PUT, DELETE, PATCH, HEAD, and OPTIONS methods. Returns response with status, headers, and body.',
|
|
41
|
+
inputSchema: httpRequestInputSchema,
|
|
42
|
+
callback: async (input) => {
|
|
43
|
+
const { method, url, headers, body, timeout = 30 } = input;
|
|
44
|
+
// Create AbortController for timeout
|
|
45
|
+
const controller = new AbortController();
|
|
46
|
+
const timeoutId = globalThis.setTimeout(() => controller.abort(), timeout * 1000);
|
|
47
|
+
try {
|
|
48
|
+
// Build fetch options
|
|
49
|
+
const fetchOptions = {
|
|
50
|
+
method,
|
|
51
|
+
signal: controller.signal,
|
|
52
|
+
};
|
|
53
|
+
// Only add headers and body if they are defined
|
|
54
|
+
if (headers !== undefined) {
|
|
55
|
+
fetchOptions.headers = headers;
|
|
56
|
+
}
|
|
57
|
+
if (body !== undefined) {
|
|
58
|
+
fetchOptions.body = body;
|
|
59
|
+
}
|
|
60
|
+
// Make the fetch request
|
|
61
|
+
const response = await globalThis.fetch(url, fetchOptions);
|
|
62
|
+
// Clear the timeout
|
|
63
|
+
globalThis.clearTimeout(timeoutId);
|
|
64
|
+
// Get response body as text
|
|
65
|
+
const responseBody = await response.text();
|
|
66
|
+
// Convert headers to plain object
|
|
67
|
+
const responseHeaders = {};
|
|
68
|
+
response.headers.forEach((value, key) => {
|
|
69
|
+
responseHeaders[key] = value;
|
|
70
|
+
});
|
|
71
|
+
// Check if response was successful
|
|
72
|
+
if (!response.ok) {
|
|
73
|
+
throw new Error(`HTTP ${response.status} ${response.statusText}: ${method} ${url}`);
|
|
74
|
+
}
|
|
75
|
+
// Return successful response as JSON-serializable object
|
|
76
|
+
return {
|
|
77
|
+
status: response.status,
|
|
78
|
+
statusText: response.statusText,
|
|
79
|
+
headers: responseHeaders,
|
|
80
|
+
body: responseBody,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
// Clear timeout on error
|
|
85
|
+
globalThis.clearTimeout(timeoutId);
|
|
86
|
+
// Handle abort/timeout error
|
|
87
|
+
if (error instanceof Error && error.name === 'AbortError') {
|
|
88
|
+
throw new Error(`Request timed out after ${timeout} seconds: ${method} ${url}`);
|
|
89
|
+
}
|
|
90
|
+
// Re-throw other errors (network errors, HTTP errors, etc.)
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
//# sourceMappingURL=http-request.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-request.js","sourceRoot":"","sources":["../../../vended_tools/http_request/http-request.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAA;AAClD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB;;GAEG;AACH,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC;IACtC,MAAM,EAAE,CAAC;SACN,IAAI,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;SAClE,QAAQ,CAAC,oCAAoC,CAAC;IACjD,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,4BAA4B,CAAC;IAC5D,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,0CAA0C,CAAC;IACzG,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,mCAAmC,CAAC;IACzE,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,2CAA2C,CAAC;CAChG,CAAC,CAAA;AAEF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,CAAC;IAC9B,IAAI,EAAE,cAAc;IACpB,WAAW,EACT,2JAA2J;IAC7J,WAAW,EAAE,sBAAsB;IACnC,QAAQ,EAAE,KAAK,EAA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AC,UAAU,KAAK,MAAM,IAAI,GAAG,EAAE,CAAC,CAAA;YACrF,CAAC;YAED,yDAAyD;YACzD,OAAO;gBACL,MAAM,EAAE,QAAQ,CAAC,MAAM;gBACvB,UAAU,EAAE,QAAQ,CAAC,UAAU;gBAC/B,OAAO,EAAE,eAAe;gBACxB,IAAI,EAAE,YAAY;aACnB,CAAA;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,yBAAyB;YACzB,UAAU,CAAC,YAAY,CAAC,SAAS,CAAC,CAAA;YAElC,6BAA6B;YAC7B,IAAI,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;gBAC1D,MAAM,IAAI,KAAK,CAAC,2BAA2B,OAAO,aAAa,MAAM,IAAI,GAAG,EAAE,CAAC,CAAA;YACjF,CAAC;YAED,4DAA4D;YAC5D,MAAM,KAAK,CAAA;QACb,CAAC;IACH,CAAC;CACF,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../vended_tools/http_request/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,YAAY,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../vended_tools/http_request/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Input parameters for HTTP request.
|
|
3
|
+
*/
|
|
4
|
+
export interface HttpRequestInput {
|
|
5
|
+
/**
|
|
6
|
+
* HTTP method to use for the request.
|
|
7
|
+
*/
|
|
8
|
+
method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS';
|
|
9
|
+
/**
|
|
10
|
+
* URL to send the request to.
|
|
11
|
+
*/
|
|
12
|
+
url: string;
|
|
13
|
+
/**
|
|
14
|
+
* Optional HTTP headers as key-value pairs.
|
|
15
|
+
*/
|
|
16
|
+
headers?: Record<string, string>;
|
|
17
|
+
/**
|
|
18
|
+
* Optional request body as a string.
|
|
19
|
+
*/
|
|
20
|
+
body?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Optional timeout in seconds (default: 30).
|
|
23
|
+
*/
|
|
24
|
+
timeout?: number;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Output from HTTP request containing response details.
|
|
28
|
+
*/
|
|
29
|
+
export interface HttpRequestOutput {
|
|
30
|
+
/**
|
|
31
|
+
* HTTP status code.
|
|
32
|
+
*/
|
|
33
|
+
status: number;
|
|
34
|
+
/**
|
|
35
|
+
* HTTP status text.
|
|
36
|
+
*/
|
|
37
|
+
statusText: string;
|
|
38
|
+
/**
|
|
39
|
+
* Response headers as key-value pairs.
|
|
40
|
+
*/
|
|
41
|
+
headers: Record<string, string>;
|
|
42
|
+
/**
|
|
43
|
+
* Response body as text.
|
|
44
|
+
*/
|
|
45
|
+
body: string;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../vended_tools/http_request/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,CAAA;IAExE;;OAEG;IACH,GAAG,EAAE,MAAM,CAAA;IAEX;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAEhC;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IAEb;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,MAAM,EAAE,MAAM,CAAA;IAEd;;OAEG;IACH,UAAU,EAAE,MAAM,CAAA;IAElB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAE/B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;CACb"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../vended_tools/http_request/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notebook.test.d.ts","sourceRoot":"","sources":["../../../../vended_tools/notebook/__tests__/notebook.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { notebook } from '../notebook.js';
|
|
3
|
+
import { AgentState } from '../../../src/agent/state.js';
|
|
4
|
+
describe('notebook tool', () => {
|
|
5
|
+
// Helper to create fresh state and context for each test
|
|
6
|
+
const createFreshContext = () => {
|
|
7
|
+
const state = new AgentState({ notebooks: {} });
|
|
8
|
+
const context = {
|
|
9
|
+
toolUse: {
|
|
10
|
+
name: 'notebook',
|
|
11
|
+
toolUseId: 'test-id',
|
|
12
|
+
input: {},
|
|
13
|
+
},
|
|
14
|
+
agent: { state, messages: [] },
|
|
15
|
+
};
|
|
16
|
+
return { state, context };
|
|
17
|
+
};
|
|
18
|
+
describe('create oper ation', () => {
|
|
19
|
+
it('creates an empty notebook with default name', async () => {
|
|
20
|
+
const { state, context } = createFreshContext();
|
|
21
|
+
const result = await notebook.invoke({ mode: 'create' }, context);
|
|
22
|
+
expect(result).toBe("Created notebook 'default' (empty)");
|
|
23
|
+
const notebooks = state.get('notebooks');
|
|
24
|
+
expect(notebooks.default).toBe('');
|
|
25
|
+
});
|
|
26
|
+
it('creates an empty notebook with custom name', async () => {
|
|
27
|
+
const { state, context } = createFreshContext();
|
|
28
|
+
const result = await notebook.invoke({ mode: 'create', name: 'notes' }, context);
|
|
29
|
+
expect(result).toBe("Created notebook 'notes' (empty)");
|
|
30
|
+
const notebooks = state.get('notebooks');
|
|
31
|
+
expect(notebooks.notes).toBe('');
|
|
32
|
+
});
|
|
33
|
+
it('creates a notebook with initial content', async () => {
|
|
34
|
+
const { state, context } = createFreshContext();
|
|
35
|
+
const content = '# My Notes\n\nFirst entry';
|
|
36
|
+
const result = await notebook.invoke({ mode: 'create', name: 'notes', newStr: content }, context);
|
|
37
|
+
expect(result).toBe("Created notebook 'notes' with specified content");
|
|
38
|
+
const notebooks = state.get('notebooks');
|
|
39
|
+
expect(notebooks.notes).toBe(content);
|
|
40
|
+
});
|
|
41
|
+
it('overwrites existing notebook on create', async () => {
|
|
42
|
+
const { state, context } = createFreshContext();
|
|
43
|
+
state.set('notebooks', { notes: 'Old content' });
|
|
44
|
+
const result = await notebook.invoke({ mode: 'create', name: 'notes', newStr: 'New content' }, context);
|
|
45
|
+
expect(result).toBe("Created notebook 'notes' with specified content");
|
|
46
|
+
const notebooks = state.get('notebooks');
|
|
47
|
+
expect(notebooks.notes).toBe('New content');
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
describe('list operation', () => {
|
|
51
|
+
it('lists default notebook when initialized', async () => {
|
|
52
|
+
const { state, context } = createFreshContext();
|
|
53
|
+
// Initialize notebooks with default
|
|
54
|
+
state.set('notebooks', { default: '' });
|
|
55
|
+
const result = await notebook.invoke({ mode: 'list' }, context);
|
|
56
|
+
expect(result).toContain('default: Empty');
|
|
57
|
+
});
|
|
58
|
+
it('lists multiple notebooks with line counts', async () => {
|
|
59
|
+
const { state, context } = createFreshContext();
|
|
60
|
+
state.set('notebooks', {
|
|
61
|
+
default: '',
|
|
62
|
+
notes: 'Line 1\nLine 2\nLine 3',
|
|
63
|
+
todo: 'Single line',
|
|
64
|
+
});
|
|
65
|
+
const result = await notebook.invoke({ mode: 'list' }, context);
|
|
66
|
+
expect(result).toContain('default: Empty');
|
|
67
|
+
expect(result).toContain('notes: 3 lines');
|
|
68
|
+
expect(result).toContain('todo: 1 lines');
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
describe('read operation', () => {
|
|
72
|
+
it('reads entire notebook with default name', async () => {
|
|
73
|
+
const { state, context } = createFreshContext();
|
|
74
|
+
state.set('notebooks', { default: 'Line 1\nLine 2\nLine 3\nLine 4\nLine 5' });
|
|
75
|
+
const result = await notebook.invoke({ mode: 'read' }, context);
|
|
76
|
+
expect(result).toBe('Line 1\nLine 2\nLine 3\nLine 4\nLine 5');
|
|
77
|
+
});
|
|
78
|
+
it('reads entire notebook with custom name', async () => {
|
|
79
|
+
const { state, context } = createFreshContext();
|
|
80
|
+
state.set('notebooks', { notes: 'Content here' });
|
|
81
|
+
const result = await notebook.invoke({ mode: 'read', name: 'notes' }, context);
|
|
82
|
+
expect(result).toBe('Content here');
|
|
83
|
+
});
|
|
84
|
+
it('reads empty notebook', async () => {
|
|
85
|
+
const { state, context } = createFreshContext();
|
|
86
|
+
state.set('notebooks', { empty: '' });
|
|
87
|
+
const result = await notebook.invoke({ mode: 'read', name: 'empty' }, context);
|
|
88
|
+
expect(result).toBe("Notebook 'empty' is empty");
|
|
89
|
+
});
|
|
90
|
+
it('throws error for non-existent notebook', async () => {
|
|
91
|
+
const { context } = createFreshContext();
|
|
92
|
+
await expect(notebook.invoke({ mode: 'read', name: 'missing' }, context)).rejects.toThrow("Notebook 'missing' not found");
|
|
93
|
+
});
|
|
94
|
+
it('reads specific line range', async () => {
|
|
95
|
+
const { state, context } = createFreshContext();
|
|
96
|
+
state.set('notebooks', { default: 'Line 1\nLine 2\nLine 3\nLine 4\nLine 5' });
|
|
97
|
+
const result = await notebook.invoke({ mode: 'read', readRange: [2, 4] }, context);
|
|
98
|
+
expect(result).toBe('2: Line 2\n3: Line 3\n4: Line 4');
|
|
99
|
+
});
|
|
100
|
+
it('reads line range with negative start index', async () => {
|
|
101
|
+
const { state, context } = createFreshContext();
|
|
102
|
+
state.set('notebooks', { default: 'Line 1\nLine 2\nLine 3\nLine 4\nLine 5' });
|
|
103
|
+
const result = await notebook.invoke({ mode: 'read', readRange: [-3, 5] }, context);
|
|
104
|
+
expect(result).toBe('3: Line 3\n4: Line 4\n5: Line 5');
|
|
105
|
+
});
|
|
106
|
+
it('reads line range with negative end index', async () => {
|
|
107
|
+
const { state, context } = createFreshContext();
|
|
108
|
+
state.set('notebooks', { default: 'Line 1\nLine 2\nLine 3\nLine 4\nLine 5' });
|
|
109
|
+
const result = await notebook.invoke({ mode: 'read', readRange: [1, -2] }, context);
|
|
110
|
+
expect(result).toBe('1: Line 1\n2: Line 2\n3: Line 3\n4: Line 4');
|
|
111
|
+
});
|
|
112
|
+
it('reads line range with both negative indices', async () => {
|
|
113
|
+
const { state, context } = createFreshContext();
|
|
114
|
+
state.set('notebooks', { default: 'Line 1\nLine 2\nLine 3\nLine 4\nLine 5' });
|
|
115
|
+
const result = await notebook.invoke({ mode: 'read', readRange: [-2, -1] }, context);
|
|
116
|
+
expect(result).toBe('4: Line 4\n5: Line 5');
|
|
117
|
+
});
|
|
118
|
+
it('returns no valid lines for out of range', async () => {
|
|
119
|
+
const { state, context } = createFreshContext();
|
|
120
|
+
state.set('notebooks', { default: 'Line 1\nLine 2\nLine 3\nLine 4\nLine 5' });
|
|
121
|
+
const result = await notebook.invoke({ mode: 'read', readRange: [10, 20] }, context);
|
|
122
|
+
expect(result).toBe('No valid lines found in range');
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
describe('write operation - string replacement', () => {
|
|
126
|
+
it('replaces text in default notebook', async () => {
|
|
127
|
+
const { state, context } = createFreshContext();
|
|
128
|
+
state.set('notebooks', { default: '# Todo List\n\n[ ] Task 1\n[ ] Task 2\n[x] Task 3' });
|
|
129
|
+
const result = await notebook.invoke({
|
|
130
|
+
mode: 'write',
|
|
131
|
+
oldStr: '[ ] Task 1',
|
|
132
|
+
newStr: '[x] Task 1',
|
|
133
|
+
}, context);
|
|
134
|
+
expect(result).toBe("Replaced text in notebook 'default'");
|
|
135
|
+
const notebooks = state.get('notebooks');
|
|
136
|
+
expect(notebooks.default).toBe('# Todo List\n\n[x] Task 1\n[ ] Task 2\n[x] Task 3');
|
|
137
|
+
});
|
|
138
|
+
it('replaces text in custom notebook', async () => {
|
|
139
|
+
const { state, context } = createFreshContext();
|
|
140
|
+
state.set('notebooks', { notes: 'Original text' });
|
|
141
|
+
const result = await notebook.invoke({
|
|
142
|
+
mode: 'write',
|
|
143
|
+
name: 'notes',
|
|
144
|
+
oldStr: 'Original',
|
|
145
|
+
newStr: 'Updated',
|
|
146
|
+
}, context);
|
|
147
|
+
expect(result).toBe("Replaced text in notebook 'notes'");
|
|
148
|
+
const notebooks = state.get('notebooks');
|
|
149
|
+
expect(notebooks.notes).toBe('Updated text');
|
|
150
|
+
});
|
|
151
|
+
it('replaces multiline text', async () => {
|
|
152
|
+
const { state, context } = createFreshContext();
|
|
153
|
+
state.set('notebooks', { default: '# Todo List\n\n[ ] Task 1\n[ ] Task 2\n[x] Task 3' });
|
|
154
|
+
const result = await notebook.invoke({
|
|
155
|
+
mode: 'write',
|
|
156
|
+
oldStr: '[ ] Task 1\n[ ] Task 2',
|
|
157
|
+
newStr: '[x] Task 1\n[x] Task 2',
|
|
158
|
+
}, context);
|
|
159
|
+
expect(result).toBe("Replaced text in notebook 'default'");
|
|
160
|
+
const notebooks = state.get('notebooks');
|
|
161
|
+
expect(notebooks.default).toBe('# Todo List\n\n[x] Task 1\n[x] Task 2\n[x] Task 3');
|
|
162
|
+
});
|
|
163
|
+
it('throws error if old string not found', async () => {
|
|
164
|
+
const { state, context } = createFreshContext();
|
|
165
|
+
state.set('notebooks', { default: '# Todo List\n\n[ ] Task 1\n[ ] Task 2\n[x] Task 3' });
|
|
166
|
+
await expect(notebook.invoke({
|
|
167
|
+
mode: 'write',
|
|
168
|
+
oldStr: 'Nonexistent',
|
|
169
|
+
newStr: 'New',
|
|
170
|
+
}, context)).rejects.toThrow("String 'Nonexistent' not found in notebook 'default'");
|
|
171
|
+
});
|
|
172
|
+
it('throws error for non-existent notebook', async () => {
|
|
173
|
+
const { context } = createFreshContext();
|
|
174
|
+
await expect(notebook.invoke({
|
|
175
|
+
mode: 'write',
|
|
176
|
+
name: 'missing',
|
|
177
|
+
oldStr: 'Old',
|
|
178
|
+
newStr: 'New',
|
|
179
|
+
}, context)).rejects.toThrow("Notebook 'missing' not found");
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
describe('write operation - line insertion', () => {
|
|
183
|
+
it('inserts after line number', async () => {
|
|
184
|
+
const { state, context } = createFreshContext();
|
|
185
|
+
state.set('notebooks', { default: 'Line 1\nLine 2\nLine 3' });
|
|
186
|
+
const result = await notebook.invoke({
|
|
187
|
+
mode: 'write',
|
|
188
|
+
insertLine: 2,
|
|
189
|
+
newStr: 'Inserted line',
|
|
190
|
+
}, context);
|
|
191
|
+
expect(result).toBe("Inserted text at line 3 in notebook 'default'");
|
|
192
|
+
const notebooks = state.get('notebooks');
|
|
193
|
+
expect(notebooks.default).toBe('Line 1\nLine 2\nInserted line\nLine 3');
|
|
194
|
+
});
|
|
195
|
+
it('inserts at beginning (after line 0)', async () => {
|
|
196
|
+
const { state, context } = createFreshContext();
|
|
197
|
+
state.set('notebooks', { default: 'Line 1\nLine 2\nLine 3' });
|
|
198
|
+
const result = await notebook.invoke({
|
|
199
|
+
mode: 'write',
|
|
200
|
+
insertLine: 0,
|
|
201
|
+
newStr: 'First line',
|
|
202
|
+
}, context);
|
|
203
|
+
expect(result).toBe("Inserted text at line 1 in notebook 'default'");
|
|
204
|
+
const notebooks = state.get('notebooks');
|
|
205
|
+
expect(notebooks.default).toBe('First line\nLine 1\nLine 2\nLine 3');
|
|
206
|
+
});
|
|
207
|
+
it('appends to end with negative index', async () => {
|
|
208
|
+
const { state, context } = createFreshContext();
|
|
209
|
+
state.set('notebooks', { default: 'Line 1\nLine 2\nLine 3' });
|
|
210
|
+
const result = await notebook.invoke({
|
|
211
|
+
mode: 'write',
|
|
212
|
+
insertLine: -1,
|
|
213
|
+
newStr: 'Last line',
|
|
214
|
+
}, context);
|
|
215
|
+
expect(result).toBe("Inserted text at line 4 in notebook 'default'");
|
|
216
|
+
const notebooks = state.get('notebooks');
|
|
217
|
+
expect(notebooks.default).toBe('Line 1\nLine 2\nLine 3\nLast line');
|
|
218
|
+
});
|
|
219
|
+
it('inserts after negative line index', async () => {
|
|
220
|
+
const { state, context } = createFreshContext();
|
|
221
|
+
state.set('notebooks', { default: 'Line 1\nLine 2\nLine 3' });
|
|
222
|
+
const result = await notebook.invoke({
|
|
223
|
+
mode: 'write',
|
|
224
|
+
insertLine: -2,
|
|
225
|
+
newStr: 'Before last',
|
|
226
|
+
}, context);
|
|
227
|
+
expect(result).toBe("Inserted text at line 3 in notebook 'default'");
|
|
228
|
+
const notebooks = state.get('notebooks');
|
|
229
|
+
expect(notebooks.default).toBe('Line 1\nLine 2\nBefore last\nLine 3');
|
|
230
|
+
});
|
|
231
|
+
it('inserts after text search', async () => {
|
|
232
|
+
const { state, context } = createFreshContext();
|
|
233
|
+
state.set('notebooks', { default: 'Line 1\nLine 2\nLine 3' });
|
|
234
|
+
const result = await notebook.invoke({
|
|
235
|
+
mode: 'write',
|
|
236
|
+
insertLine: 'Line 1',
|
|
237
|
+
newStr: 'After Line 1',
|
|
238
|
+
}, context);
|
|
239
|
+
expect(result).toBe("Inserted text at line 2 in notebook 'default'");
|
|
240
|
+
const notebooks = state.get('notebooks');
|
|
241
|
+
expect(notebooks.default).toBe('Line 1\nAfter Line 1\nLine 2\nLine 3');
|
|
242
|
+
});
|
|
243
|
+
it('inserts after partial text match', async () => {
|
|
244
|
+
const { state, context } = createFreshContext();
|
|
245
|
+
state.set('notebooks', { default: 'Line 1\nLine 2\nLine 3' });
|
|
246
|
+
const result = await notebook.invoke({
|
|
247
|
+
mode: 'write',
|
|
248
|
+
insertLine: '2',
|
|
249
|
+
newStr: 'After match',
|
|
250
|
+
}, context);
|
|
251
|
+
expect(result).toBe("Inserted text at line 3 in notebook 'default'");
|
|
252
|
+
const notebooks = state.get('notebooks');
|
|
253
|
+
expect(notebooks.default).toBe('Line 1\nLine 2\nAfter match\nLine 3');
|
|
254
|
+
});
|
|
255
|
+
it('throws error if search text not found', async () => {
|
|
256
|
+
const { state, context } = createFreshContext();
|
|
257
|
+
state.set('notebooks', { default: 'Line 1\nLine 2\nLine 3' });
|
|
258
|
+
await expect(notebook.invoke({
|
|
259
|
+
mode: 'write',
|
|
260
|
+
insertLine: 'Nonexistent',
|
|
261
|
+
newStr: 'New line',
|
|
262
|
+
}, context)).rejects.toThrow("Text 'Nonexistent' not found in notebook 'default'");
|
|
263
|
+
});
|
|
264
|
+
it('throws error for line number out of range', async () => {
|
|
265
|
+
const { state, context } = createFreshContext();
|
|
266
|
+
state.set('notebooks', { default: 'Line 1\nLine 2\nLine 3' });
|
|
267
|
+
await expect(notebook.invoke({
|
|
268
|
+
mode: 'write',
|
|
269
|
+
insertLine: 100,
|
|
270
|
+
newStr: 'New line',
|
|
271
|
+
}, context)).rejects.toThrow('Line number out of range');
|
|
272
|
+
});
|
|
273
|
+
it('inserts into custom notebook', async () => {
|
|
274
|
+
const { state, context } = createFreshContext();
|
|
275
|
+
state.set('notebooks', { notes: 'First\nSecond' });
|
|
276
|
+
const result = await notebook.invoke({
|
|
277
|
+
mode: 'write',
|
|
278
|
+
name: 'notes',
|
|
279
|
+
insertLine: 1,
|
|
280
|
+
newStr: 'Middle',
|
|
281
|
+
}, context);
|
|
282
|
+
expect(result).toBe("Inserted text at line 2 in notebook 'notes'");
|
|
283
|
+
const notebooks = state.get('notebooks');
|
|
284
|
+
expect(notebooks.notes).toBe('First\nMiddle\nSecond');
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
describe('clear operation', () => {
|
|
288
|
+
it('clears default notebook', async () => {
|
|
289
|
+
const { state, context } = createFreshContext();
|
|
290
|
+
state.set('notebooks', { default: 'Some content' });
|
|
291
|
+
const result = await notebook.invoke({ mode: 'clear' }, context);
|
|
292
|
+
expect(result).toBe("Cleared notebook 'default'");
|
|
293
|
+
const notebooks = state.get('notebooks');
|
|
294
|
+
expect(notebooks.default).toBe('');
|
|
295
|
+
});
|
|
296
|
+
it('clears custom notebook', async () => {
|
|
297
|
+
const { state, context } = createFreshContext();
|
|
298
|
+
state.set('notebooks', { notes: 'More content' });
|
|
299
|
+
const result = await notebook.invoke({ mode: 'clear', name: 'notes' }, context);
|
|
300
|
+
expect(result).toBe("Cleared notebook 'notes'");
|
|
301
|
+
const notebooks = state.get('notebooks');
|
|
302
|
+
expect(notebooks.notes).toBe('');
|
|
303
|
+
});
|
|
304
|
+
it('throws error for non-existent notebook', async () => {
|
|
305
|
+
const { context } = createFreshContext();
|
|
306
|
+
await expect(notebook.invoke({ mode: 'clear', name: 'missing' }, context)).rejects.toThrow("Notebook 'missing' not found");
|
|
307
|
+
});
|
|
308
|
+
it('clearing does not affect other notebooks', async () => {
|
|
309
|
+
const { state, context } = createFreshContext();
|
|
310
|
+
state.set('notebooks', { default: 'Some content', notes: 'More content' });
|
|
311
|
+
await notebook.invoke({ mode: 'clear', name: 'notes' }, context);
|
|
312
|
+
const notebooks = state.get('notebooks');
|
|
313
|
+
expect(notebooks.default).toBe('Some content');
|
|
314
|
+
});
|
|
315
|
+
});
|
|
316
|
+
describe('state persistence', () => {
|
|
317
|
+
it('persists notebooks across operations', async () => {
|
|
318
|
+
const { state, context } = createFreshContext();
|
|
319
|
+
// Create notebook
|
|
320
|
+
await notebook.invoke({ mode: 'create', name: 'notes', newStr: 'Initial' }, context);
|
|
321
|
+
let notebooks = state.get('notebooks');
|
|
322
|
+
expect(notebooks.notes).toBe('Initial');
|
|
323
|
+
// Write to notebook - use oldStr/newStr instead of insertLine for appending
|
|
324
|
+
await notebook.invoke({ mode: 'write', name: 'notes', oldStr: 'Initial', newStr: 'Initial\nAdded' }, context);
|
|
325
|
+
notebooks = state.get('notebooks');
|
|
326
|
+
expect(notebooks.notes).toBe('Initial\nAdded');
|
|
327
|
+
// Read notebook
|
|
328
|
+
const content = await notebook.invoke({ mode: 'read', name: 'notes' }, context);
|
|
329
|
+
expect(content).toBe('Initial\nAdded');
|
|
330
|
+
// Verify state is still intact
|
|
331
|
+
notebooks = state.get('notebooks');
|
|
332
|
+
expect(notebooks.notes).toBe('Initial\nAdded');
|
|
333
|
+
});
|
|
334
|
+
it('initializes default notebook if state is empty', async () => {
|
|
335
|
+
const { state, context } = createFreshContext();
|
|
336
|
+
const result = await notebook.invoke({ mode: 'list' }, context);
|
|
337
|
+
expect(result).toContain('default: Empty');
|
|
338
|
+
const notebooks = state.get('notebooks');
|
|
339
|
+
expect(notebooks.default).toBe('');
|
|
340
|
+
});
|
|
341
|
+
});
|
|
342
|
+
describe('validation errors', () => {
|
|
343
|
+
it('requires context', async () => {
|
|
344
|
+
await expect(notebook.invoke({ mode: 'list' })).rejects.toThrow('Tool context is required');
|
|
345
|
+
});
|
|
346
|
+
it('rejects write without newStr for replacement', async () => {
|
|
347
|
+
const { context } = createFreshContext();
|
|
348
|
+
await expect(notebook.invoke({
|
|
349
|
+
mode: 'write',
|
|
350
|
+
oldStr: 'Old',
|
|
351
|
+
// Missing newStr
|
|
352
|
+
}, context)).rejects.toThrow();
|
|
353
|
+
});
|
|
354
|
+
it('rejects write without newStr for insertion', async () => {
|
|
355
|
+
const { context } = createFreshContext();
|
|
356
|
+
await expect(notebook.invoke({
|
|
357
|
+
mode: 'write',
|
|
358
|
+
insertLine: 1,
|
|
359
|
+
// Missing newStr
|
|
360
|
+
}, context)).rejects.toThrow();
|
|
361
|
+
});
|
|
362
|
+
it('rejects write without valid operation parameters', async () => {
|
|
363
|
+
const { context } = createFreshContext();
|
|
364
|
+
await expect(notebook.invoke({
|
|
365
|
+
mode: 'write',
|
|
366
|
+
// Missing both replacement and insertion params
|
|
367
|
+
}, context)).rejects.toThrow();
|
|
368
|
+
});
|
|
369
|
+
});
|
|
370
|
+
});
|
|
371
|
+
//# sourceMappingURL=notebook.test.js.map
|