@strands-agents/sdk 1.0.0-rc.4 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -15
- package/dist/src/__fixtures__/agent-helpers.d.ts +6 -0
- package/dist/src/__fixtures__/agent-helpers.d.ts.map +1 -1
- package/dist/src/__fixtures__/agent-helpers.js +3 -1
- package/dist/src/__fixtures__/agent-helpers.js.map +1 -1
- package/dist/src/__fixtures__/mock-plugin.d.ts.map +1 -1
- package/dist/src/__fixtures__/mock-plugin.js +3 -1
- package/dist/src/__fixtures__/mock-plugin.js.map +1 -1
- package/dist/src/__fixtures__/tool-helpers.d.ts +3 -1
- package/dist/src/__fixtures__/tool-helpers.d.ts.map +1 -1
- package/dist/src/__fixtures__/tool-helpers.js +3 -1
- package/dist/src/__fixtures__/tool-helpers.js.map +1 -1
- package/dist/src/__tests__/mcp.test.js +274 -1
- package/dist/src/__tests__/mcp.test.js.map +1 -1
- package/dist/src/a2a/__tests__/events.test.js +2 -0
- package/dist/src/a2a/__tests__/events.test.js.map +1 -1
- package/dist/src/a2a/__tests__/executor.test.js +16 -5
- package/dist/src/a2a/__tests__/executor.test.js.map +1 -1
- package/dist/src/a2a/a2a-agent.d.ts +8 -3
- package/dist/src/a2a/a2a-agent.d.ts.map +1 -1
- package/dist/src/a2a/a2a-agent.js +12 -6
- package/dist/src/a2a/a2a-agent.js.map +1 -1
- package/dist/src/a2a/executor.d.ts +13 -0
- package/dist/src/a2a/executor.d.ts.map +1 -1
- package/dist/src/a2a/executor.js +19 -1
- package/dist/src/a2a/executor.js.map +1 -1
- package/dist/src/agent/__tests__/agent-as-tool.invocation-state.test.d.ts +2 -0
- package/dist/src/agent/__tests__/agent-as-tool.invocation-state.test.d.ts.map +1 -0
- package/dist/src/agent/__tests__/agent-as-tool.invocation-state.test.js +23 -0
- package/dist/src/agent/__tests__/agent-as-tool.invocation-state.test.js.map +1 -0
- package/dist/src/agent/__tests__/agent.cancel.test.js +1 -1
- package/dist/src/agent/__tests__/agent.cancel.test.js.map +1 -1
- package/dist/src/agent/__tests__/agent.concurrent.test.d.ts +2 -0
- package/dist/src/agent/__tests__/agent.concurrent.test.d.ts.map +1 -0
- package/dist/src/agent/__tests__/agent.concurrent.test.js +488 -0
- package/dist/src/agent/__tests__/agent.concurrent.test.js.map +1 -0
- package/dist/src/agent/__tests__/agent.hook.test.js +174 -12
- package/dist/src/agent/__tests__/agent.hook.test.js.map +1 -1
- package/dist/src/agent/__tests__/agent.invocation-state.test.d.ts +2 -0
- package/dist/src/agent/__tests__/agent.invocation-state.test.d.ts.map +1 -0
- package/dist/src/agent/__tests__/agent.invocation-state.test.js +219 -0
- package/dist/src/agent/__tests__/agent.invocation-state.test.js.map +1 -0
- package/dist/src/agent/__tests__/agent.stateful-model.test.d.ts +2 -0
- package/dist/src/agent/__tests__/agent.stateful-model.test.d.ts.map +1 -0
- package/dist/src/agent/__tests__/agent.stateful-model.test.js +169 -0
- package/dist/src/agent/__tests__/agent.stateful-model.test.js.map +1 -0
- package/dist/src/agent/__tests__/agent.test.js +99 -2
- package/dist/src/agent/__tests__/agent.test.js.map +1 -1
- package/dist/src/agent/__tests__/agent.tracer.test.node.js +39 -0
- package/dist/src/agent/__tests__/agent.tracer.test.node.js.map +1 -1
- package/dist/src/agent/__tests__/snapshot.test.js +5 -4
- package/dist/src/agent/__tests__/snapshot.test.js.map +1 -1
- package/dist/src/agent/agent-as-tool.d.ts.map +1 -1
- package/dist/src/agent/agent-as-tool.js +4 -2
- package/dist/src/agent/agent-as-tool.js.map +1 -1
- package/dist/src/agent/agent.d.ts +75 -1
- package/dist/src/agent/agent.d.ts.map +1 -1
- package/dist/src/agent/agent.js +323 -83
- package/dist/src/agent/agent.js.map +1 -1
- package/dist/src/agent/snapshot.d.ts +2 -2
- package/dist/src/agent/snapshot.d.ts.map +1 -1
- package/dist/src/agent/snapshot.js +8 -2
- package/dist/src/agent/snapshot.js.map +1 -1
- package/dist/src/conversation-manager/__tests__/conversation-manager.test.js +4 -4
- package/dist/src/conversation-manager/__tests__/conversation-manager.test.js.map +1 -1
- package/dist/src/conversation-manager/__tests__/null-conversation-manager.test.js +2 -2
- package/dist/src/conversation-manager/__tests__/null-conversation-manager.test.js.map +1 -1
- package/dist/src/conversation-manager/__tests__/sliding-window-conversation-manager.test.js +8 -3
- package/dist/src/conversation-manager/__tests__/sliding-window-conversation-manager.test.js.map +1 -1
- package/dist/src/conversation-manager/__tests__/summarizing-conversation-manager.test.js +1 -0
- package/dist/src/conversation-manager/__tests__/summarizing-conversation-manager.test.js.map +1 -1
- package/dist/src/errors.d.ts +11 -0
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/errors.js +12 -0
- package/dist/src/errors.js.map +1 -1
- package/dist/src/hooks/__tests__/events.test.js +177 -70
- package/dist/src/hooks/__tests__/events.test.js.map +1 -1
- package/dist/src/hooks/__tests__/registry.test.js +16 -16
- package/dist/src/hooks/__tests__/registry.test.js.map +1 -1
- package/dist/src/hooks/events.d.ts +95 -25
- package/dist/src/hooks/events.d.ts.map +1 -1
- package/dist/src/hooks/events.js +98 -23
- package/dist/src/hooks/events.js.map +1 -1
- package/dist/src/index.d.ts +6 -5
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/logging/__tests__/warn-once.test.d.ts +2 -0
- package/dist/src/logging/__tests__/warn-once.test.d.ts.map +1 -0
- package/dist/src/logging/__tests__/warn-once.test.js +30 -0
- package/dist/src/logging/__tests__/warn-once.test.js.map +1 -0
- package/dist/src/logging/warn-once.d.ts +13 -0
- package/dist/src/logging/warn-once.d.ts.map +1 -0
- package/dist/src/logging/warn-once.js +18 -0
- package/dist/src/logging/warn-once.js.map +1 -0
- package/dist/src/mcp.d.ts +20 -1
- package/dist/src/mcp.d.ts.map +1 -1
- package/dist/src/mcp.js +10 -1
- package/dist/src/mcp.js.map +1 -1
- package/dist/src/mime.d.ts +2 -1
- package/dist/src/mime.d.ts.map +1 -1
- package/dist/src/mime.js +1 -0
- package/dist/src/mime.js.map +1 -1
- package/dist/src/models/__tests__/anthropic.test.js +99 -1
- package/dist/src/models/__tests__/anthropic.test.js.map +1 -1
- package/dist/src/models/__tests__/bedrock.test.js +123 -2
- package/dist/src/models/__tests__/bedrock.test.js.map +1 -1
- package/dist/src/models/__tests__/google.test.js +88 -0
- package/dist/src/models/__tests__/google.test.js.map +1 -1
- package/dist/src/models/__tests__/model.test.js +149 -1
- package/dist/src/models/__tests__/model.test.js.map +1 -1
- package/dist/src/models/anthropic.d.ts +18 -1
- package/dist/src/models/anthropic.d.ts.map +1 -1
- package/dist/src/models/anthropic.js +40 -6
- package/dist/src/models/anthropic.js.map +1 -1
- package/dist/src/models/bedrock.d.ts +12 -1
- package/dist/src/models/bedrock.d.ts.map +1 -1
- package/dist/src/models/bedrock.js +45 -11
- package/dist/src/models/bedrock.js.map +1 -1
- package/dist/src/models/defaults.d.ts +37 -0
- package/dist/src/models/defaults.d.ts.map +1 -0
- package/dist/src/models/defaults.js +41 -0
- package/dist/src/models/defaults.js.map +1 -0
- package/dist/src/models/google/model.d.ts +14 -1
- package/dist/src/models/google/model.d.ts.map +1 -1
- package/dist/src/models/google/model.js +50 -6
- package/dist/src/models/google/model.js.map +1 -1
- package/dist/src/models/model.d.ts +56 -0
- package/dist/src/models/model.d.ts.map +1 -1
- package/dist/src/models/model.js +120 -0
- package/dist/src/models/model.js.map +1 -1
- package/dist/src/models/openai/__tests__/chat.test.d.ts +2 -0
- package/dist/src/models/openai/__tests__/chat.test.d.ts.map +1 -0
- package/dist/src/models/{__tests__/openai.test.js → openai/__tests__/chat.test.js} +84 -7
- package/dist/src/models/openai/__tests__/chat.test.js.map +1 -0
- package/dist/src/models/openai/__tests__/responses.test.d.ts +2 -0
- package/dist/src/models/openai/__tests__/responses.test.d.ts.map +1 -0
- package/dist/src/models/openai/__tests__/responses.test.js +668 -0
- package/dist/src/models/openai/__tests__/responses.test.js.map +1 -0
- package/dist/src/models/openai/chat-adapter.d.ts +33 -0
- package/dist/src/models/openai/chat-adapter.d.ts.map +1 -0
- package/dist/src/models/openai/chat-adapter.js +383 -0
- package/dist/src/models/openai/chat-adapter.js.map +1 -0
- package/dist/src/models/openai/errors.d.ts +16 -0
- package/dist/src/models/openai/errors.d.ts.map +1 -0
- package/dist/src/models/openai/errors.js +40 -0
- package/dist/src/models/openai/errors.js.map +1 -0
- package/dist/src/models/openai/formatting.d.ts +18 -0
- package/dist/src/models/openai/formatting.d.ts.map +1 -0
- package/dist/src/models/openai/formatting.js +38 -0
- package/dist/src/models/openai/formatting.js.map +1 -0
- package/dist/src/models/openai/index.d.ts +19 -0
- package/dist/src/models/openai/index.d.ts.map +1 -0
- package/dist/src/models/openai/index.js +18 -0
- package/dist/src/models/openai/index.js.map +1 -0
- package/dist/src/models/openai/model.d.ts +77 -0
- package/dist/src/models/openai/model.d.ts.map +1 -0
- package/dist/src/models/openai/model.js +211 -0
- package/dist/src/models/openai/model.js.map +1 -0
- package/dist/src/models/openai/responses-adapter.d.ts +78 -0
- package/dist/src/models/openai/responses-adapter.d.ts.map +1 -0
- package/dist/src/models/openai/responses-adapter.js +467 -0
- package/dist/src/models/openai/responses-adapter.js.map +1 -0
- package/dist/src/models/openai/types.d.ts +131 -0
- package/dist/src/models/openai/types.d.ts.map +1 -0
- package/dist/src/models/openai/types.js +5 -0
- package/dist/src/models/openai/types.js.map +1 -0
- package/dist/src/multiagent/__tests__/events.test.js +122 -28
- package/dist/src/multiagent/__tests__/events.test.js.map +1 -1
- package/dist/src/multiagent/__tests__/graph.invocation-state.test.d.ts +2 -0
- package/dist/src/multiagent/__tests__/graph.invocation-state.test.d.ts.map +1 -0
- package/dist/src/multiagent/__tests__/graph.invocation-state.test.js +95 -0
- package/dist/src/multiagent/__tests__/graph.invocation-state.test.js.map +1 -0
- package/dist/src/multiagent/__tests__/nodes.test.js +5 -2
- package/dist/src/multiagent/__tests__/nodes.test.js.map +1 -1
- package/dist/src/multiagent/__tests__/swarm.invocation-state.test.d.ts +2 -0
- package/dist/src/multiagent/__tests__/swarm.invocation-state.test.d.ts.map +1 -0
- package/dist/src/multiagent/__tests__/swarm.invocation-state.test.js +56 -0
- package/dist/src/multiagent/__tests__/swarm.invocation-state.test.js.map +1 -0
- package/dist/src/multiagent/events.d.ts +19 -1
- package/dist/src/multiagent/events.d.ts.map +1 -1
- package/dist/src/multiagent/events.js +18 -0
- package/dist/src/multiagent/events.js.map +1 -1
- package/dist/src/multiagent/graph.d.ts +5 -3
- package/dist/src/multiagent/graph.d.ts.map +1 -1
- package/dist/src/multiagent/graph.js +22 -15
- package/dist/src/multiagent/graph.js.map +1 -1
- package/dist/src/multiagent/index.d.ts +1 -1
- package/dist/src/multiagent/index.d.ts.map +1 -1
- package/dist/src/multiagent/multiagent.d.ts +16 -3
- package/dist/src/multiagent/multiagent.d.ts.map +1 -1
- package/dist/src/multiagent/nodes.d.ts +10 -3
- package/dist/src/multiagent/nodes.d.ts.map +1 -1
- package/dist/src/multiagent/nodes.js +28 -6
- package/dist/src/multiagent/nodes.js.map +1 -1
- package/dist/src/multiagent/swarm.d.ts +5 -3
- package/dist/src/multiagent/swarm.d.ts.map +1 -1
- package/dist/src/multiagent/swarm.js +22 -16
- package/dist/src/multiagent/swarm.js.map +1 -1
- package/dist/src/plugins/__tests__/registry.test.js +1 -1
- package/dist/src/plugins/__tests__/registry.test.js.map +1 -1
- package/dist/src/plugins/model-plugin.d.ts +20 -0
- package/dist/src/plugins/model-plugin.d.ts.map +1 -0
- package/dist/src/plugins/model-plugin.js +29 -0
- package/dist/src/plugins/model-plugin.js.map +1 -0
- package/dist/src/session/__tests__/session-manager.test.js +13 -11
- package/dist/src/session/__tests__/session-manager.test.js.map +1 -1
- package/dist/src/session/session-manager.d.ts.map +1 -1
- package/dist/src/session/session-manager.js +9 -0
- package/dist/src/session/session-manager.js.map +1 -1
- package/dist/src/telemetry/__tests__/config.test.js +6 -6
- package/dist/src/telemetry/__tests__/config.test.js.map +1 -1
- package/dist/src/telemetry/__tests__/config.test.node.js +16 -11
- package/dist/src/telemetry/__tests__/config.test.node.js.map +1 -1
- package/dist/src/telemetry/__tests__/meter.test.js +23 -0
- package/dist/src/telemetry/__tests__/meter.test.js.map +1 -1
- package/dist/src/telemetry/config.d.ts +9 -3
- package/dist/src/telemetry/config.d.ts.map +1 -1
- package/dist/src/telemetry/config.js +44 -69
- package/dist/src/telemetry/config.js.map +1 -1
- package/dist/src/telemetry/meter.d.ts +15 -0
- package/dist/src/telemetry/meter.d.ts.map +1 -1
- package/dist/src/telemetry/meter.js +14 -0
- package/dist/src/telemetry/meter.js.map +1 -1
- package/dist/src/tools/mcp-tool.d.ts +24 -3
- package/dist/src/tools/mcp-tool.d.ts.map +1 -1
- package/dist/src/tools/mcp-tool.js +105 -14
- package/dist/src/tools/mcp-tool.js.map +1 -1
- package/dist/src/tools/tool.d.ts +11 -1
- package/dist/src/tools/tool.d.ts.map +1 -1
- package/dist/src/tools/tool.js.map +1 -1
- package/dist/src/tsconfig.tsbuildinfo +1 -1
- package/dist/src/types/__tests__/agent.test.js +48 -0
- package/dist/src/types/__tests__/agent.test.js.map +1 -1
- package/dist/src/types/agent.d.ts +55 -6
- package/dist/src/types/agent.d.ts.map +1 -1
- package/dist/src/types/agent.js +22 -6
- package/dist/src/types/agent.js.map +1 -1
- package/dist/src/types/elicitation.d.ts +15 -0
- package/dist/src/types/elicitation.d.ts.map +1 -0
- package/dist/src/types/elicitation.js +2 -0
- package/dist/src/types/elicitation.js.map +1 -0
- package/dist/src/vended-plugins/skills/__tests__/agent-skills.test.node.js +37 -33
- package/dist/src/vended-plugins/skills/__tests__/agent-skills.test.node.js.map +1 -1
- package/dist/src/vended-plugins/skills/agent-skills.d.ts +8 -8
- package/dist/src/vended-plugins/skills/agent-skills.d.ts.map +1 -1
- package/dist/src/vended-plugins/skills/agent-skills.js +5 -5
- package/dist/src/vended-plugins/skills/agent-skills.js.map +1 -1
- package/dist/src/vended-plugins/skills/index.d.ts +5 -5
- package/dist/src/vended-plugins/skills/index.d.ts.map +1 -1
- package/dist/src/vended-plugins/skills/index.js +4 -4
- package/dist/src/vended-plugins/skills/index.js.map +1 -1
- package/dist/src/vended-tools/bash/__tests__/bash.test.node.js +1 -0
- package/dist/src/vended-tools/bash/__tests__/bash.test.node.js.map +1 -1
- package/dist/src/vended-tools/file-editor/__tests__/file-editor.test.node.js +1 -0
- package/dist/src/vended-tools/file-editor/__tests__/file-editor.test.node.js.map +1 -1
- package/dist/src/vended-tools/notebook/__tests__/notebook.test.js +1 -0
- package/dist/src/vended-tools/notebook/__tests__/notebook.test.js.map +1 -1
- package/package.json +28 -26
- package/dist/src/models/__tests__/openai.test.d.ts +0 -2
- package/dist/src/models/__tests__/openai.test.d.ts.map +0 -1
- package/dist/src/models/__tests__/openai.test.js.map +0 -1
- package/dist/src/models/openai.d.ts +0 -312
- package/dist/src/models/openai.d.ts.map +0 -1
- package/dist/src/models/openai.js +0 -789
- package/dist/src/models/openai.js.map +0 -1
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
<a href="https://github.com/strands-agents/sdk-typescript/graphs/commit-activity"><img alt="GitHub commit activity" src="https://img.shields.io/github/commit-activity/m/strands-agents/sdk-typescript"/></a>
|
|
18
18
|
<a href="https://github.com/strands-agents/sdk-typescript/issues"><img alt="GitHub open issues" src="https://img.shields.io/github/issues/strands-agents/sdk-typescript"/></a>
|
|
19
19
|
<a href="https://github.com/strands-agents/sdk-typescript/pulls"><img alt="GitHub open pull requests" src="https://img.shields.io/github/issues-pr/strands-agents/sdk-typescript"/></a>
|
|
20
|
-
<a href="https://github.com/strands-agents/sdk-typescript/blob/main/LICENSE"><img alt="License" src="https://img.shields.io/github/license/strands-agents/sdk-typescript"/></a>
|
|
20
|
+
<a href="https://github.com/strands-agents/sdk-typescript/blob/main/LICENSE.APACHE"><img alt="License" src="https://img.shields.io/github/license/strands-agents/sdk-typescript"/></a>
|
|
21
21
|
<a href="https://www.npmjs.com/package/@strands-agents/sdk"><img alt="NPM Version" src="https://img.shields.io/npm/v/@strands-agents/sdk"/></a>
|
|
22
22
|
</div>
|
|
23
23
|
|
|
@@ -297,7 +297,7 @@ const swarm = new Swarm({
|
|
|
297
297
|
const result = await swarm.invoke('What is the largest ocean?')
|
|
298
298
|
```
|
|
299
299
|
|
|
300
|
-
Both patterns support streaming via `.stream()` for real-time access to handoff and node execution events. See the [examples](./examples/) directory for complete working samples.
|
|
300
|
+
Both patterns support streaming via `.stream()` for real-time access to handoff and node execution events. See the [examples](./strands-ts/examples/) directory for complete working samples.
|
|
301
301
|
|
|
302
302
|
---
|
|
303
303
|
|
|
@@ -306,11 +306,11 @@ Both patterns support streaming via `.stream()` for real-time access to handoff
|
|
|
306
306
|
For detailed guidance, tutorials, and concept overviews, please visit:
|
|
307
307
|
|
|
308
308
|
- **[Official Documentation](https://strandsagents.com/)**: Comprehensive guides and tutorials
|
|
309
|
-
- **[API Reference](https://strandsagents.com/
|
|
310
|
-
- **[Examples](./examples/)**: Sample applications
|
|
311
|
-
- **[First Agent](./examples/first-agent/)**: Basic Node.js agent
|
|
312
|
-
- **[MCP](./examples/mcp/)**: MCP integration example
|
|
313
|
-
- **[Browser Agent](./examples/browser-agent/)**: Browser-based agent with DOM manipulation
|
|
309
|
+
- **[API Reference](https://strandsagents.com/docs/api/typescript/)**: Complete API documentation
|
|
310
|
+
- **[Examples](./strands-ts/examples/)**: Sample applications
|
|
311
|
+
- **[First Agent](./strands-ts/examples/first-agent/)**: Basic Node.js agent
|
|
312
|
+
- **[MCP](./strands-ts/examples/mcp/)**: MCP integration example
|
|
313
|
+
- **[Browser Agent](./strands-ts/examples/browser-agent/)**: Browser-based agent with DOM manipulation
|
|
314
314
|
|
|
315
315
|
- **[Contributing Guide](CONTRIBUTING.md)**: Development setup and guidelines
|
|
316
316
|
|
|
@@ -330,7 +330,7 @@ We welcome contributions! See our [Contributing Guide](CONTRIBUTING.md) for deta
|
|
|
330
330
|
|
|
331
331
|
## License
|
|
332
332
|
|
|
333
|
-
This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details.
|
|
333
|
+
This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE.APACHE) file for details.
|
|
334
334
|
|
|
335
335
|
---
|
|
336
336
|
|
|
@@ -338,10 +338,3 @@ This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENS
|
|
|
338
338
|
|
|
339
339
|
See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more information on reporting security issues.
|
|
340
340
|
|
|
341
|
-
---
|
|
342
|
-
|
|
343
|
-
## ⚠️ Preview Status
|
|
344
|
-
|
|
345
|
-
Strands Agents is currently in public preview. During this period:
|
|
346
|
-
- APIs may change as we refine the SDK
|
|
347
|
-
- We welcome feedback and contributions
|
|
@@ -94,6 +94,12 @@ export interface AgentResultMatcher extends Omit<LoopMetricsMatcher, 'cycleCount
|
|
|
94
94
|
* When omitted, asserts traces array exists with at least one element.
|
|
95
95
|
*/
|
|
96
96
|
traceCount?: number;
|
|
97
|
+
/**
|
|
98
|
+
* Expected `invocationState` on the result. When provided, the full object
|
|
99
|
+
* must match exactly — extra keys fail. When omitted, only asserts
|
|
100
|
+
* `invocationState` is present (any object).
|
|
101
|
+
*/
|
|
102
|
+
invocationState?: Record<string, unknown>;
|
|
97
103
|
}
|
|
98
104
|
/**
|
|
99
105
|
* Creates an asymmetric matcher that validates AgentResult structure and values.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-helpers.d.ts","sourceRoot":"","sources":["../../../src/__fixtures__/agent-helpers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,EAAE,OAAO,EAAa,MAAM,sBAAsB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C,CAAC,SAAS,aAAa,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAM1G;AAED;;GAEG;AACH,MAAM,WAAW,kBAAmB,SAAQ,IAAI,CAAC,kBAAkB,EAAE,YAAY,CAAC;IAChF;;OAEG;IACH,UAAU,EAAE,UAAU,CAAA;IAEtB;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IAEpB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAA;IAElB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IAEnB;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAC1C;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,kBAAkB,GAAG,WAAW,CAgC1E"}
|
|
@@ -20,6 +20,7 @@ export function createMockAgent(data) {
|
|
|
20
20
|
return {
|
|
21
21
|
messages: data?.messages ?? [],
|
|
22
22
|
appState: new StateStore(data?.appState ?? {}),
|
|
23
|
+
modelState: new StateStore(),
|
|
23
24
|
toolRegistry: data?.toolRegistry ?? new ToolRegistry(),
|
|
24
25
|
cancelSignal: new AbortController().signal,
|
|
25
26
|
addHook: (eventType, callback) => {
|
|
@@ -74,7 +75,7 @@ export async function invokeTrackedHook(agent, event) {
|
|
|
74
75
|
* ```
|
|
75
76
|
*/
|
|
76
77
|
export function expectAgentResult(options) {
|
|
77
|
-
const { stopReason, messageText, cycleCount, traceCount, toolNames, usage } = options;
|
|
78
|
+
const { stopReason, messageText, cycleCount, traceCount, toolNames, usage, invocationState } = options;
|
|
78
79
|
const expectedLastMessage = messageText
|
|
79
80
|
? expect.objectContaining({
|
|
80
81
|
role: 'assistant',
|
|
@@ -98,6 +99,7 @@ export function expectAgentResult(options) {
|
|
|
98
99
|
lastMessage: expectedLastMessage,
|
|
99
100
|
metrics: expectLoopMetrics(metricsOptions),
|
|
100
101
|
traces: expectedTraces,
|
|
102
|
+
invocationState: invocationState ?? expect.any(Object),
|
|
101
103
|
});
|
|
102
104
|
}
|
|
103
105
|
//# sourceMappingURL=agent-helpers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-helpers.js","sourceRoot":"","sources":["../../../src/__fixtures__/agent-helpers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAI/B,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAEzD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAE9C,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAG3D,OAAO,EAAE,iBAAiB,EAA2B,MAAM,sBAAsB,CAAA;AAqCjF;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAAC,IAAoB;IAClD,MAAM,YAAY,GAAkB,EAAE,CAAA;IACtC,OAAO;QACL,QAAQ,EAAE,IAAI,EAAE,QAAQ,IAAI,EAAE;QAC9B,QAAQ,EAAE,IAAI,UAAU,CAAC,IAAI,EAAE,QAAQ,IAAI,EAAE,CAAC;QAC9C,YAAY,EAAE,IAAI,EAAE,YAAY,IAAI,IAAI,YAAY,EAAE;QACtD,YAAY,EAAE,IAAI,eAAe,EAAE,CAAC,MAAM;QAC1C,OAAO,EAAE,CAA0B,SAAsC,EAAE,QAAyB,EAAE,EAAE;YACtG,YAAY,CAAC,IAAI,CAAC;gBAChB,SAAS,EAAE,SAAoD;gBAC/D,QAAQ,EAAE,QAAuC;aAClD,CAAC,CAAA;YACF,OAAO,GAAG,EAAE,GAAE,CAAC,CAAA;QACjB,CAAC;QACD,GAAG,IAAI,EAAE,KAAK;QACd,YAAY;KACW,CAAA;AAC3B,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAC,IAAU,EAAE,IAAY;IAClD,OAAO,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AE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"mock-plugin.d.ts","sourceRoot":"","sources":["../../../src/__fixtures__/mock-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAiBnD;;GAEG;AACH,qBAAa,UAAW,YAAW,MAAM;IACvC,WAAW,EAAE,aAAa,EAAE,CAAK;IAEjC,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI;IAuBlC,KAAK,IAAI,IAAI;CAGd"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { InitializedEvent, BeforeInvocationEvent, AfterInvocationEvent, MessageAddedEvent, BeforeToolsEvent, AfterToolsEvent, BeforeToolCallEvent, AfterToolCallEvent, BeforeModelCallEvent, AfterModelCallEvent, } from '../hooks/index.js';
|
|
1
|
+
import { InitializedEvent, BeforeInvocationEvent, AfterInvocationEvent, MessageAddedEvent, BeforeToolsEvent, AfterToolsEvent, BeforeToolCallEvent, AfterToolCallEvent, BeforeModelCallEvent, AfterModelCallEvent, ToolResultEvent, ToolStreamUpdateEvent, } from '../hooks/index.js';
|
|
2
2
|
/**
|
|
3
3
|
* Mock plugin that records all hookable event invocations for testing.
|
|
4
4
|
*/
|
|
@@ -19,6 +19,8 @@ export class MockPlugin {
|
|
|
19
19
|
AfterToolCallEvent,
|
|
20
20
|
BeforeModelCallEvent,
|
|
21
21
|
AfterModelCallEvent,
|
|
22
|
+
ToolResultEvent,
|
|
23
|
+
ToolStreamUpdateEvent,
|
|
22
24
|
];
|
|
23
25
|
for (const eventType of eventTypes) {
|
|
24
26
|
agent.addHook(eventType, (e) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mock-plugin.js","sourceRoot":"","sources":["../../../src/__fixtures__/mock-plugin.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,gBAAgB,EAChB,qBAAqB,EACrB,oBAAoB,EACpB,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,kBAAkB,EAClB,oBAAoB,EACpB,mBAAmB,
|
|
1
|
+
{"version":3,"file":"mock-plugin.js","sourceRoot":"","sources":["../../../src/__fixtures__/mock-plugin.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,gBAAgB,EAChB,qBAAqB,EACrB,oBAAoB,EACpB,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,kBAAkB,EAClB,oBAAoB,EACpB,mBAAmB,EACnB,eAAe,EACf,qBAAqB,GACtB,MAAM,mBAAmB,CAAA;AAG1B;;GAEG;AACH,MAAM,OAAO,UAAU;IACrB,WAAW,GAAoB,EAAE,CAAA;IAEjC,IAAI,IAAI;QACN,OAAO,aAAa,CAAA;IACtB,CAAC;IAED,SAAS,CAAC,KAAiB;QACzB,MAAM,UAAU,GAA+B;YAC7C,gBAAgB;YAChB,qBAAqB;YACrB,oBAAoB;YACpB,iBAAiB;YACjB,gBAAgB;YAChB,eAAe;YACf,mBAAmB;YACnB,kBAAkB;YAClB,oBAAoB;YACpB,mBAAmB;YACnB,eAAe;YACf,qBAAqB;SACtB,CAAA;QAED,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;YACnC,KAAK,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC,EAAE,EAAE;gBAC7B,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;YAC1B,CAAC,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;IAED,KAAK;QACH,IAAI,CAAC,WAAW,GAAG,EAAE,CAAA;IACvB,CAAC;CACF"}
|
|
@@ -5,18 +5,20 @@
|
|
|
5
5
|
import type { Tool, ToolContext } from '../tools/tool.js';
|
|
6
6
|
import type { JSONValue } from '../types/json.js';
|
|
7
7
|
import type { PlainToolResultBlock } from './slim-types.js';
|
|
8
|
+
import type { InvocationState } from '../types/agent.js';
|
|
8
9
|
/**
|
|
9
10
|
* Helper to create a mock ToolContext for testing.
|
|
10
11
|
*
|
|
11
12
|
* @param toolUse - The tool use request
|
|
12
13
|
* @param appState - Optional initial app state
|
|
14
|
+
* @param invocationState - Optional initial invocation state
|
|
13
15
|
* @returns Mock ToolContext object
|
|
14
16
|
*/
|
|
15
17
|
export declare function createMockContext(toolUse: {
|
|
16
18
|
name: string;
|
|
17
19
|
toolUseId: string;
|
|
18
20
|
input: JSONValue;
|
|
19
|
-
}, appState?: Record<string, JSONValue
|
|
21
|
+
}, appState?: Record<string, JSONValue>, invocationState?: InvocationState): ToolContext;
|
|
20
22
|
/**
|
|
21
23
|
* Result function type for createMockTool - accepts plain objects or class instances.
|
|
22
24
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-helpers.d.ts","sourceRoot":"","sources":["../../../src/__fixtures__/tool-helpers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAEzD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAGjD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"tool-helpers.d.ts","sourceRoot":"","sources":["../../../src/__fixtures__/tool-helpers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAEzD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAGjD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAc,MAAM,mBAAmB,CAAA;AAEpE;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,SAAS,CAAA;CAAE,EAC9D,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,EACpC,eAAe,CAAC,EAAE,eAAe,GAChC,WAAW,CAYb;AAED;;GAEG;AACH,KAAK,YAAY,GAAG,MAAM,oBAAoB,GAAG,cAAc,CAAC,KAAK,EAAE,oBAAoB,EAAE,KAAK,CAAC,CAAA;AAEnG;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,GAAG,IAAI,CA8BzE;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAWpD"}
|
|
@@ -10,9 +10,10 @@ import { ToolRegistry } from '../registry/tool-registry.js';
|
|
|
10
10
|
*
|
|
11
11
|
* @param toolUse - The tool use request
|
|
12
12
|
* @param appState - Optional initial app state
|
|
13
|
+
* @param invocationState - Optional initial invocation state
|
|
13
14
|
* @returns Mock ToolContext object
|
|
14
15
|
*/
|
|
15
|
-
export function createMockContext(toolUse, appState) {
|
|
16
|
+
export function createMockContext(toolUse, appState, invocationState) {
|
|
16
17
|
return {
|
|
17
18
|
toolUse,
|
|
18
19
|
agent: {
|
|
@@ -22,6 +23,7 @@ export function createMockContext(toolUse, appState) {
|
|
|
22
23
|
toolRegistry: new ToolRegistry(),
|
|
23
24
|
addHook: () => () => { },
|
|
24
25
|
},
|
|
26
|
+
invocationState: invocationState ?? {},
|
|
25
27
|
};
|
|
26
28
|
}
|
|
27
29
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-helpers.js","sourceRoot":"","sources":["../../../src/__fixtures__/tool-helpers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAEtD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAI3D
|
|
1
|
+
{"version":3,"file":"tool-helpers.js","sourceRoot":"","sources":["../../../src/__fixtures__/tool-helpers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAEtD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAI3D;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB,CAC/B,OAA8D,EAC9D,QAAoC,EACpC,eAAiC;IAEjC,OAAO;QACL,OAAO;QACP,KAAK,EAAE;YACL,EAAE,EAAE,YAAY;YAChB,QAAQ,EAAE,IAAI,UAAU,CAAC,QAAQ,CAAC;YAClC,QAAQ,EAAE,EAAE;YACZ,YAAY,EAAE,IAAI,YAAY,EAAE;YAChC,OAAO,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE,GAAE,CAAC;SACC;QAC1B,eAAe,EAAE,eAAe,IAAI,EAAE;KACvC,CAAA;AACH,CAAC;AAOD;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,IAAY,EAAE,QAAsB;IACjE,OAAO;QACL,IAAI;QACJ,WAAW,EAAE,aAAa,IAAI,EAAE;QAChC,QAAQ,EAAE;YACR,IAAI;YACJ,WAAW,EAAE,aAAa,IAAI,EAAE;YAChC,WAAW,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,EAAE;SAChD;QACD,yCAAyC;QACzC,KAAK,CAAC,CAAC,MAAM,CAAC,QAAQ;YACpB,MAAM,MAAM,GAAG,QAAQ,EAAE,CAAA;YACzB,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,IAAI,MAAM,CAAC,aAAa,IAAI,MAAM,EAAE,CAAC;gBACpF,mCAAmC;gBACnC,MAAM,GAAG,GAAG,MAAuD,CAAA;gBACnE,IAAI,IAAI,GAAG,KAAK,CAAA;gBAChB,OAAO,CAAC,IAAI,EAAE,CAAC;oBACb,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAA;oBAChD,IAAI,GAAG,MAAM,IAAI,KAAK,CAAA;oBACtB,IAAI,IAAI,EAAE,CAAC;wBACT,OAAO,KAAK,CAAA;oBACd,CAAC;gBACH,CAAC;gBACD,6DAA6D;gBAC7D,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAA;YACjD,CAAC;iBAAM,CAAC;gBACN,OAAO,MAAyB,CAAA;YAClC,CAAC;QACH,CAAC;KACF,CAAA;AACH,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAa;IAC5C,MAAM,QAAQ,GAAG,IAAI,IAAI,UAAU,CAAC,MAAM,CAAC,UAAU,EAAE,CAAA;IACvD,OAAO,cAAc,CACnB,QAAQ,EACR,GAAG,EAAE,CACH,IAAI,eAAe,CAAC;QAClB,SAAS,EAAE,SAAS;QACpB,MAAM,EAAE,SAAkB;QAC1B,OAAO,EAAE,EAAE;KACZ,CAAC,CACL,CAAA;AACH,CAAC"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
2
|
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
3
|
+
import { McpError, ErrorCode, ElicitRequestSchema, UrlElicitationRequiredError, } from '@modelcontextprotocol/sdk/types.js';
|
|
3
4
|
import { McpClient } from '../mcp.js';
|
|
4
5
|
import { McpTool } from '../tools/mcp-tool.js';
|
|
5
6
|
import { JsonBlock } from '../types/messages.js';
|
|
7
|
+
import { ImageBlock } from '../types/media.js';
|
|
6
8
|
import { context, propagation, trace, TraceFlags } from '@opentelemetry/api';
|
|
7
9
|
/**
|
|
8
10
|
* Helper to create a mock async generator that yields a result message.
|
|
@@ -20,6 +22,7 @@ vi.mock('@modelcontextprotocol/sdk/client/index.js', () => ({
|
|
|
20
22
|
close: vi.fn(),
|
|
21
23
|
listTools: vi.fn(),
|
|
22
24
|
callTool: vi.fn(),
|
|
25
|
+
setRequestHandler: vi.fn(),
|
|
23
26
|
experimental: {
|
|
24
27
|
tasks: {
|
|
25
28
|
callToolStream: vi.fn(),
|
|
@@ -80,6 +83,22 @@ describe('MCP Integration', () => {
|
|
|
80
83
|
afterEach(() => {
|
|
81
84
|
vi.restoreAllMocks();
|
|
82
85
|
});
|
|
86
|
+
function createElicitationClient(callback) {
|
|
87
|
+
const resultsLengthBefore = vi.mocked(Client).mock.results.length;
|
|
88
|
+
const elicitClient = new McpClient({
|
|
89
|
+
applicationName: 'TestApp',
|
|
90
|
+
transport: mockTransport,
|
|
91
|
+
elicitationCallback: callback,
|
|
92
|
+
});
|
|
93
|
+
const elicitSdkClientMock = vi.mocked(Client).mock.results[resultsLengthBefore].value;
|
|
94
|
+
return { elicitClient, elicitSdkClientMock };
|
|
95
|
+
}
|
|
96
|
+
async function connectAndGetElicitationHandler(callback) {
|
|
97
|
+
const { elicitClient, elicitSdkClientMock } = createElicitationClient(callback);
|
|
98
|
+
await elicitClient.connect();
|
|
99
|
+
const handler = elicitSdkClientMock.setRequestHandler.mock.calls[0][1];
|
|
100
|
+
return { handler, elicitSdkClientMock };
|
|
101
|
+
}
|
|
83
102
|
describe('McpClient', () => {
|
|
84
103
|
let client;
|
|
85
104
|
let sdkClientMock;
|
|
@@ -91,7 +110,7 @@ describe('MCP Integration', () => {
|
|
|
91
110
|
sdkClientMock = vi.mocked(Client).mock.results[0].value;
|
|
92
111
|
});
|
|
93
112
|
it('initializes SDK client with correct configuration', () => {
|
|
94
|
-
expect(Client).toHaveBeenCalledWith({ name: 'TestApp', version: '0.0.1' });
|
|
113
|
+
expect(Client).toHaveBeenCalledWith({ name: 'TestApp', version: '0.0.1' }, undefined);
|
|
95
114
|
});
|
|
96
115
|
it('injects trace context into tool arguments when active span exists', async () => {
|
|
97
116
|
mockActiveSpan();
|
|
@@ -227,6 +246,88 @@ describe('MCP Integration', () => {
|
|
|
227
246
|
expect(sdkClientMock.close).toHaveBeenCalled();
|
|
228
247
|
expect(mockTransport.close).toHaveBeenCalled();
|
|
229
248
|
});
|
|
249
|
+
it('registers elicitation handler before connecting when callback is provided', async () => {
|
|
250
|
+
const resultsLengthBefore = vi.mocked(Client).mock.results.length;
|
|
251
|
+
const callback = vi.fn();
|
|
252
|
+
const elicitClient = new McpClient({
|
|
253
|
+
applicationName: 'TestApp',
|
|
254
|
+
transport: mockTransport,
|
|
255
|
+
elicitationCallback: callback,
|
|
256
|
+
});
|
|
257
|
+
const elicitSdkClientMock = vi.mocked(Client).mock.results[resultsLengthBefore].value;
|
|
258
|
+
await elicitClient.connect();
|
|
259
|
+
expect(elicitSdkClientMock.setRequestHandler).toHaveBeenCalledWith(ElicitRequestSchema, expect.any(Function));
|
|
260
|
+
const setHandlerOrder = elicitSdkClientMock.setRequestHandler.mock.invocationCallOrder[0];
|
|
261
|
+
const connectOrder = elicitSdkClientMock.connect.mock.invocationCallOrder[0];
|
|
262
|
+
expect(setHandlerOrder).toBeLessThan(connectOrder);
|
|
263
|
+
});
|
|
264
|
+
it('does not register elicitation handler when no callback is provided', async () => {
|
|
265
|
+
await client.connect();
|
|
266
|
+
expect(sdkClientMock.setRequestHandler).not.toHaveBeenCalled();
|
|
267
|
+
});
|
|
268
|
+
it('passes elicitation capabilities to Client when callback is provided', () => {
|
|
269
|
+
const callback = vi.fn();
|
|
270
|
+
new McpClient({
|
|
271
|
+
applicationName: 'TestApp',
|
|
272
|
+
transport: mockTransport,
|
|
273
|
+
elicitationCallback: callback,
|
|
274
|
+
});
|
|
275
|
+
const lastCall = vi.mocked(Client).mock.calls.at(-1);
|
|
276
|
+
expect(lastCall[1]).toEqual({ capabilities: { elicitation: { form: {}, url: {} } } });
|
|
277
|
+
});
|
|
278
|
+
it('elicitation handler returns accepted result with content', async () => {
|
|
279
|
+
const callbackResult = { action: 'accept', content: { username: 'alice' } };
|
|
280
|
+
const callback = vi.fn().mockResolvedValue(callbackResult);
|
|
281
|
+
const { handler } = await connectAndGetElicitationHandler(callback);
|
|
282
|
+
const request = {
|
|
283
|
+
method: 'elicitation/create',
|
|
284
|
+
params: { message: 'Enter username', requestedSchema: { type: 'object' } },
|
|
285
|
+
};
|
|
286
|
+
const extra = { signal: new AbortController().signal };
|
|
287
|
+
const result = await handler(request, extra);
|
|
288
|
+
expect(callback).toHaveBeenCalledWith(extra, request.params);
|
|
289
|
+
expect(result).toEqual({ action: 'accept', content: { username: 'alice' } });
|
|
290
|
+
});
|
|
291
|
+
it.each([{ action: 'decline' }, { action: 'cancel' }])('elicitation handler returns $action result', async (callbackResult) => {
|
|
292
|
+
const callback = vi.fn().mockResolvedValue(callbackResult);
|
|
293
|
+
const { handler } = await connectAndGetElicitationHandler(callback);
|
|
294
|
+
const request = {
|
|
295
|
+
method: 'elicitation/create',
|
|
296
|
+
params: { message: 'Enter username', requestedSchema: { type: 'object' } },
|
|
297
|
+
};
|
|
298
|
+
const extra = { signal: new AbortController().signal };
|
|
299
|
+
const result = await handler(request, extra);
|
|
300
|
+
expect(callback).toHaveBeenCalledWith(extra, request.params);
|
|
301
|
+
expect(result).toEqual({ action: callbackResult.action });
|
|
302
|
+
});
|
|
303
|
+
it('elicitation handler works for URL mode params', async () => {
|
|
304
|
+
const callbackResult = { action: 'accept' };
|
|
305
|
+
const callback = vi.fn().mockResolvedValue(callbackResult);
|
|
306
|
+
const { handler } = await connectAndGetElicitationHandler(callback);
|
|
307
|
+
const request = {
|
|
308
|
+
method: 'elicitation/create',
|
|
309
|
+
params: {
|
|
310
|
+
mode: 'url',
|
|
311
|
+
message: 'Please authenticate',
|
|
312
|
+
url: 'https://example.com/auth',
|
|
313
|
+
elicitationId: 'elicit-123',
|
|
314
|
+
},
|
|
315
|
+
};
|
|
316
|
+
const extra = { signal: new AbortController().signal };
|
|
317
|
+
const result = await handler(request, extra);
|
|
318
|
+
expect(callback).toHaveBeenCalledWith(extra, request.params);
|
|
319
|
+
expect(result).toEqual({ action: 'accept' });
|
|
320
|
+
});
|
|
321
|
+
it('elicitation callback errors propagate', async () => {
|
|
322
|
+
const callback = vi.fn().mockRejectedValue(new Error('User cancelled'));
|
|
323
|
+
const { handler } = await connectAndGetElicitationHandler(callback);
|
|
324
|
+
const request = {
|
|
325
|
+
method: 'elicitation/create',
|
|
326
|
+
params: { message: 'Confirm?' },
|
|
327
|
+
};
|
|
328
|
+
const extra = { signal: new AbortController().signal };
|
|
329
|
+
await expect(handler(request, extra)).rejects.toThrow('User cancelled');
|
|
330
|
+
});
|
|
230
331
|
});
|
|
231
332
|
describe('McpTool', () => {
|
|
232
333
|
const mockClientWrapper = { callTool: vi.fn() };
|
|
@@ -239,6 +340,7 @@ describe('MCP Integration', () => {
|
|
|
239
340
|
const toolContext = {
|
|
240
341
|
toolUse: { toolUseId: 'id-123', name: 'weather', input: { city: 'NYC' } },
|
|
241
342
|
agent: {},
|
|
343
|
+
invocationState: {},
|
|
242
344
|
};
|
|
243
345
|
it('returns text results on success', async () => {
|
|
244
346
|
vi.mocked(mockClientWrapper.callTool).mockResolvedValue({
|
|
@@ -285,6 +387,177 @@ describe('MCP Integration', () => {
|
|
|
285
387
|
expect(result.status).toBe('error');
|
|
286
388
|
expect(result.content[0].text).toContain('missing content array');
|
|
287
389
|
});
|
|
390
|
+
it('maps MCP image content to ImageBlock', async () => {
|
|
391
|
+
// "iVBOR..." is a minimal base64 PNG prefix
|
|
392
|
+
const base64Data = 'iVBORw0KGgoAAAANSUhEUg==';
|
|
393
|
+
vi.mocked(mockClientWrapper.callTool).mockResolvedValue({
|
|
394
|
+
content: [{ type: 'image', data: base64Data, mimeType: 'image/png' }],
|
|
395
|
+
});
|
|
396
|
+
const result = await runTool(tool.stream(toolContext));
|
|
397
|
+
expect(result.status).toBe('success');
|
|
398
|
+
expect(result.content).toHaveLength(1);
|
|
399
|
+
const imageBlock = result.content[0];
|
|
400
|
+
expect(imageBlock).toBeInstanceOf(ImageBlock);
|
|
401
|
+
expect(imageBlock.format).toBe('png');
|
|
402
|
+
expect(imageBlock.source.type).toBe('imageSourceBytes');
|
|
403
|
+
});
|
|
404
|
+
it('falls back to JsonBlock for unsupported image mime type', async () => {
|
|
405
|
+
vi.mocked(mockClientWrapper.callTool).mockResolvedValue({
|
|
406
|
+
content: [{ type: 'image', data: 'abc123', mimeType: 'image/bmp' }],
|
|
407
|
+
});
|
|
408
|
+
const result = await runTool(tool.stream(toolContext));
|
|
409
|
+
expect(result.content[0]).toBeInstanceOf(JsonBlock);
|
|
410
|
+
});
|
|
411
|
+
it('falls back to JsonBlock for image content missing data', async () => {
|
|
412
|
+
vi.mocked(mockClientWrapper.callTool).mockResolvedValue({
|
|
413
|
+
content: [{ type: 'image', mimeType: 'image/png' }],
|
|
414
|
+
});
|
|
415
|
+
const result = await runTool(tool.stream(toolContext));
|
|
416
|
+
expect(result.content[0]).toBeInstanceOf(JsonBlock);
|
|
417
|
+
});
|
|
418
|
+
it('maps MCP text resource to TextBlock', async () => {
|
|
419
|
+
vi.mocked(mockClientWrapper.callTool).mockResolvedValue({
|
|
420
|
+
content: [
|
|
421
|
+
{ type: 'resource', resource: { uri: 'file:///doc.txt', text: 'hello world', mimeType: 'text/plain' } },
|
|
422
|
+
],
|
|
423
|
+
});
|
|
424
|
+
const result = await runTool(tool.stream(toolContext));
|
|
425
|
+
expect(result.status).toBe('success');
|
|
426
|
+
expect(result.content[0].text).toBe('hello world');
|
|
427
|
+
});
|
|
428
|
+
it('maps MCP blob resource with image mime type to ImageBlock', async () => {
|
|
429
|
+
const base64Data = 'iVBORw0KGgoAAAANSUhEUg==';
|
|
430
|
+
vi.mocked(mockClientWrapper.callTool).mockResolvedValue({
|
|
431
|
+
content: [{ type: 'resource', resource: { uri: 'file:///img.png', blob: base64Data, mimeType: 'image/jpeg' } }],
|
|
432
|
+
});
|
|
433
|
+
const result = await runTool(tool.stream(toolContext));
|
|
434
|
+
expect(result.content[0]).toBeInstanceOf(ImageBlock);
|
|
435
|
+
expect(result.content[0].format).toBe('jpeg');
|
|
436
|
+
});
|
|
437
|
+
it('falls back to JsonBlock for blob resource with non-image mime type', async () => {
|
|
438
|
+
vi.mocked(mockClientWrapper.callTool).mockResolvedValue({
|
|
439
|
+
content: [
|
|
440
|
+
{ type: 'resource', resource: { uri: 'file:///doc.pdf', blob: 'abc123', mimeType: 'application/pdf' } },
|
|
441
|
+
],
|
|
442
|
+
});
|
|
443
|
+
const result = await runTool(tool.stream(toolContext));
|
|
444
|
+
expect(result.content[0]).toBeInstanceOf(JsonBlock);
|
|
445
|
+
});
|
|
446
|
+
it('falls back to JsonBlock for resource with neither text nor blob', async () => {
|
|
447
|
+
vi.mocked(mockClientWrapper.callTool).mockResolvedValue({
|
|
448
|
+
content: [{ type: 'resource', resource: { uri: 'file:///unknown' } }],
|
|
449
|
+
});
|
|
450
|
+
const result = await runTool(tool.stream(toolContext));
|
|
451
|
+
expect(result.content[0]).toBeInstanceOf(JsonBlock);
|
|
452
|
+
});
|
|
453
|
+
it('handles mixed content types in a single result', async () => {
|
|
454
|
+
const base64Data = 'iVBORw0KGgoAAAANSUhEUg==';
|
|
455
|
+
vi.mocked(mockClientWrapper.callTool).mockResolvedValue({
|
|
456
|
+
content: [
|
|
457
|
+
{ type: 'text', text: 'Here is the image:' },
|
|
458
|
+
{ type: 'image', data: base64Data, mimeType: 'image/png' },
|
|
459
|
+
{ type: 'resource', resource: { uri: 'file:///notes.txt', text: 'Some notes' } },
|
|
460
|
+
],
|
|
461
|
+
});
|
|
462
|
+
const result = await runTool(tool.stream(toolContext));
|
|
463
|
+
expect(result.content).toHaveLength(3);
|
|
464
|
+
expect(result.content[0].text).toBe('Here is the image:');
|
|
465
|
+
expect(result.content[1]).toBeInstanceOf(ImageBlock);
|
|
466
|
+
expect(result.content[2].text).toBe('Some notes');
|
|
467
|
+
});
|
|
468
|
+
it('surfaces elicitation data for McpError with code -32042', async () => {
|
|
469
|
+
const elicitations = [
|
|
470
|
+
{
|
|
471
|
+
mode: 'url',
|
|
472
|
+
message: 'Please authorize with GitHub',
|
|
473
|
+
elicitationId: 'e-123',
|
|
474
|
+
url: 'https://github.com/login/oauth/authorize?client_id=abc',
|
|
475
|
+
},
|
|
476
|
+
];
|
|
477
|
+
const mcpError = new McpError(ErrorCode.UrlElicitationRequired, 'Authorization required', { elicitations });
|
|
478
|
+
vi.mocked(mockClientWrapper.callTool).mockRejectedValue(mcpError);
|
|
479
|
+
const result = await runTool(tool.stream(toolContext));
|
|
480
|
+
expect(result.status).toBe('error');
|
|
481
|
+
expect(result.content[0].text).toBe(`MCP Elicitation required: [${String(mcpError)}] with data ${JSON.stringify(elicitations)}`);
|
|
482
|
+
});
|
|
483
|
+
it('surfaces multiple elicitations for McpError with code -32042', async () => {
|
|
484
|
+
const elicitations = [
|
|
485
|
+
{
|
|
486
|
+
mode: 'url',
|
|
487
|
+
message: 'Authorize with GitHub',
|
|
488
|
+
elicitationId: 'e-1',
|
|
489
|
+
url: 'https://github.com/login/oauth/authorize',
|
|
490
|
+
},
|
|
491
|
+
{
|
|
492
|
+
mode: 'url',
|
|
493
|
+
message: 'Authorize with Google',
|
|
494
|
+
elicitationId: 'e-2',
|
|
495
|
+
url: 'https://accounts.google.com/o/oauth2/auth',
|
|
496
|
+
},
|
|
497
|
+
];
|
|
498
|
+
const mcpError = new McpError(ErrorCode.UrlElicitationRequired, 'Authorization required', { elicitations });
|
|
499
|
+
vi.mocked(mockClientWrapper.callTool).mockRejectedValue(mcpError);
|
|
500
|
+
const result = await runTool(tool.stream(toolContext));
|
|
501
|
+
expect(result.status).toBe('error');
|
|
502
|
+
expect(result.content[0].text).toBe(`MCP Elicitation required: [${String(mcpError)}] with data ${JSON.stringify(elicitations)}`);
|
|
503
|
+
});
|
|
504
|
+
it('falls through to generic error for McpError -32042 with malformed data', async () => {
|
|
505
|
+
const mcpError = new McpError(ErrorCode.UrlElicitationRequired, 'Authorization required', {
|
|
506
|
+
unexpected: 'shape',
|
|
507
|
+
});
|
|
508
|
+
vi.mocked(mockClientWrapper.callTool).mockRejectedValue(mcpError);
|
|
509
|
+
const result = await runTool(tool.stream(toolContext));
|
|
510
|
+
expect(result.status).toBe('error');
|
|
511
|
+
expect(result.content[0].text).toBe('MCP error -32042: Authorization required');
|
|
512
|
+
});
|
|
513
|
+
it('surfaces elicitation data for UrlElicitationRequiredError', async () => {
|
|
514
|
+
const elicitations = [
|
|
515
|
+
{
|
|
516
|
+
mode: 'url',
|
|
517
|
+
message: 'Please authorize',
|
|
518
|
+
elicitationId: 'e-1',
|
|
519
|
+
url: 'https://example.com/auth',
|
|
520
|
+
},
|
|
521
|
+
];
|
|
522
|
+
const error = new UrlElicitationRequiredError(elicitations, 'Auth required');
|
|
523
|
+
vi.mocked(mockClientWrapper.callTool).mockRejectedValue(error);
|
|
524
|
+
const result = await runTool(tool.stream(toolContext));
|
|
525
|
+
expect(result.status).toBe('error');
|
|
526
|
+
expect(result.content[0].text).toContain('MCP Elicitation required');
|
|
527
|
+
expect(result.content[0].text).toContain('https://example.com/auth');
|
|
528
|
+
});
|
|
529
|
+
it('falls through to generic error for McpError -32042 with undefined data', async () => {
|
|
530
|
+
const mcpError = new McpError(ErrorCode.UrlElicitationRequired, 'Auth required');
|
|
531
|
+
vi.mocked(mockClientWrapper.callTool).mockRejectedValue(mcpError);
|
|
532
|
+
const result = await runTool(tool.stream(toolContext));
|
|
533
|
+
expect(result.status).toBe('error');
|
|
534
|
+
expect(result.content[0].text).toBe('MCP error -32042: Auth required');
|
|
535
|
+
});
|
|
536
|
+
it('falls through to generic error for McpError -32042 with non-array elicitations', async () => {
|
|
537
|
+
const mcpError = new McpError(ErrorCode.UrlElicitationRequired, 'Auth required', {
|
|
538
|
+
elicitations: 'not-an-array',
|
|
539
|
+
});
|
|
540
|
+
vi.mocked(mockClientWrapper.callTool).mockRejectedValue(mcpError);
|
|
541
|
+
const result = await runTool(tool.stream(toolContext));
|
|
542
|
+
expect(result.status).toBe('error');
|
|
543
|
+
expect(result.content[0].text).toBe('MCP error -32042: Auth required');
|
|
544
|
+
});
|
|
545
|
+
it('falls through to generic error for McpError -32042 with empty elicitations', async () => {
|
|
546
|
+
const mcpError = new McpError(ErrorCode.UrlElicitationRequired, 'Auth required', {
|
|
547
|
+
elicitations: [],
|
|
548
|
+
});
|
|
549
|
+
vi.mocked(mockClientWrapper.callTool).mockRejectedValue(mcpError);
|
|
550
|
+
const result = await runTool(tool.stream(toolContext));
|
|
551
|
+
expect(result.status).toBe('error');
|
|
552
|
+
expect(result.content[0].text).toBe('MCP error -32042: Auth required');
|
|
553
|
+
});
|
|
554
|
+
it('falls through to generic error for McpError with a different code', async () => {
|
|
555
|
+
const mcpError = new McpError(ErrorCode.InvalidRequest, 'Bad request');
|
|
556
|
+
vi.mocked(mockClientWrapper.callTool).mockRejectedValue(mcpError);
|
|
557
|
+
const result = await runTool(tool.stream(toolContext));
|
|
558
|
+
expect(result.status).toBe('error');
|
|
559
|
+
expect(result.content[0].text).toBe('MCP error -32600: Bad request');
|
|
560
|
+
});
|
|
288
561
|
});
|
|
289
562
|
});
|
|
290
563
|
//# sourceMappingURL=mcp.test.js.map
|