@strands-agents/sdk 0.7.0 → 1.0.0-rc.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/README.md +7 -7
- package/dist/src/__fixtures__/agent-helpers.d.ts +44 -0
- package/dist/src/__fixtures__/agent-helpers.d.ts.map +1 -1
- package/dist/src/__fixtures__/agent-helpers.js +45 -0
- 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.map +1 -1
- package/dist/src/__fixtures__/tool-helpers.js +1 -0
- package/dist/src/__fixtures__/tool-helpers.js.map +1 -1
- package/dist/src/a2a/__tests__/events.test.d.ts +2 -0
- package/dist/src/a2a/__tests__/events.test.d.ts.map +1 -0
- package/dist/src/a2a/__tests__/events.test.js +66 -0
- package/dist/src/a2a/__tests__/events.test.js.map +1 -0
- package/dist/src/a2a/a2a-agent.d.ts.map +1 -1
- package/dist/src/a2a/a2a-agent.js +1 -1
- package/dist/src/a2a/a2a-agent.js.map +1 -1
- package/dist/src/a2a/events.d.ts +2 -0
- package/dist/src/a2a/events.d.ts.map +1 -1
- package/dist/src/a2a/events.js +6 -0
- package/dist/src/a2a/events.js.map +1 -1
- package/dist/src/a2a/index.d.ts +0 -1
- package/dist/src/a2a/index.d.ts.map +1 -1
- package/dist/src/a2a/index.js +0 -1
- package/dist/src/a2a/index.js.map +1 -1
- package/dist/src/a2a/server.d.ts +1 -1
- package/dist/src/a2a/server.js +1 -1
- package/dist/src/agent/__tests__/agent.hook.test.js +229 -1
- package/dist/src/agent/__tests__/agent.hook.test.js.map +1 -1
- package/dist/src/agent/__tests__/agent.test.js +215 -42
- package/dist/src/agent/__tests__/agent.test.js.map +1 -1
- package/dist/src/agent/__tests__/agent.tracer.test.node.d.ts +2 -0
- package/dist/src/agent/__tests__/agent.tracer.test.node.d.ts.map +1 -0
- package/dist/src/agent/__tests__/{agent.tracer.test.js → agent.tracer.test.node.js} +52 -40
- package/dist/src/agent/__tests__/agent.tracer.test.node.js.map +1 -0
- package/dist/src/agent/__tests__/printer.test.js +7 -7
- package/dist/src/agent/__tests__/printer.test.js.map +1 -1
- package/dist/src/agent/__tests__/snapshot.test.js +39 -2
- package/dist/src/agent/__tests__/snapshot.test.js.map +1 -1
- package/dist/src/agent/agent.d.ts +16 -1
- package/dist/src/agent/agent.d.ts.map +1 -1
- package/dist/src/agent/agent.js +170 -94
- package/dist/src/agent/agent.js.map +1 -1
- package/dist/src/agent/printer.d.ts.map +1 -1
- package/dist/src/agent/printer.js +3 -0
- package/dist/src/agent/printer.js.map +1 -1
- package/dist/src/agent/snapshot.d.ts +3 -3
- package/dist/src/agent/snapshot.d.ts.map +1 -1
- package/dist/src/agent/snapshot.js +14 -7
- package/dist/src/agent/snapshot.js.map +1 -1
- package/dist/src/conversation-manager/__tests__/sliding-window-conversation-manager.test.js +72 -46
- package/dist/src/conversation-manager/__tests__/sliding-window-conversation-manager.test.js.map +1 -1
- package/dist/src/conversation-manager/sliding-window-conversation-manager.d.ts.map +1 -1
- package/dist/src/conversation-manager/sliding-window-conversation-manager.js +14 -7
- package/dist/src/conversation-manager/sliding-window-conversation-manager.js.map +1 -1
- package/dist/src/errors.d.ts +8 -0
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/errors.js +11 -0
- package/dist/src/errors.js.map +1 -1
- package/dist/src/hooks/__tests__/events.test.js +387 -0
- package/dist/src/hooks/__tests__/events.test.js.map +1 -1
- package/dist/src/hooks/events.d.ts +104 -0
- package/dist/src/hooks/events.d.ts.map +1 -1
- package/dist/src/hooks/events.js +137 -0
- package/dist/src/hooks/events.js.map +1 -1
- package/dist/src/index.d.ts +2 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +4 -4
- package/dist/src/index.js.map +1 -1
- package/dist/src/models/__tests__/anthropic.test.js +1 -2
- package/dist/src/models/__tests__/anthropic.test.js.map +1 -1
- package/dist/src/models/__tests__/bedrock.test.js +18 -18
- package/dist/src/models/__tests__/bedrock.test.js.map +1 -1
- package/dist/src/models/__tests__/google.test.d.ts +2 -0
- package/dist/src/models/__tests__/google.test.d.ts.map +1 -0
- package/dist/src/models/__tests__/{gemini.test.js → google.test.js} +55 -21
- package/dist/src/models/__tests__/google.test.js.map +1 -0
- package/dist/src/models/__tests__/openai.test.js +78 -71
- package/dist/src/models/__tests__/openai.test.js.map +1 -1
- package/dist/src/models/anthropic.d.ts.map +1 -1
- package/dist/src/models/anthropic.js +8 -7
- package/dist/src/models/anthropic.js.map +1 -1
- package/dist/src/models/bedrock.d.ts +3 -3
- package/dist/src/models/bedrock.d.ts.map +1 -1
- package/dist/src/models/bedrock.js +7 -7
- package/dist/src/models/bedrock.js.map +1 -1
- package/dist/src/models/{gemini → google}/adapters.d.ts +3 -3
- package/dist/src/models/{gemini → google}/adapters.d.ts.map +1 -1
- package/dist/src/models/{gemini → google}/adapters.js +1 -1
- package/dist/src/models/{gemini → google}/adapters.js.map +1 -1
- package/dist/src/models/{gemini → google}/errors.d.ts +7 -7
- package/dist/src/models/google/errors.d.ts.map +1 -0
- package/dist/src/models/{gemini → google}/errors.js +11 -5
- package/dist/src/models/google/errors.js.map +1 -0
- package/dist/src/models/google/index.d.ts +15 -0
- package/dist/src/models/google/index.d.ts.map +1 -0
- package/dist/src/models/google/index.js +15 -0
- package/dist/src/models/google/index.js.map +1 -0
- package/dist/src/models/{gemini → google}/model.d.ts +18 -18
- package/dist/src/models/{gemini → google}/model.d.ts.map +1 -1
- package/dist/src/models/{gemini → google}/model.js +22 -19
- package/dist/src/models/google/model.js.map +1 -0
- package/dist/src/models/{gemini → google}/types.d.ts +9 -9
- package/dist/src/models/{gemini → google}/types.d.ts.map +1 -1
- package/dist/src/models/google/types.js +5 -0
- package/dist/src/models/google/types.js.map +1 -0
- package/dist/src/models/model.js +2 -2
- package/dist/src/models/model.js.map +1 -1
- package/dist/src/models/openai.d.ts +29 -11
- package/dist/src/models/openai.d.ts.map +1 -1
- package/dist/src/models/openai.js +25 -15
- package/dist/src/models/openai.js.map +1 -1
- package/dist/src/models/streaming.d.ts +13 -0
- package/dist/src/models/streaming.d.ts.map +1 -1
- package/dist/src/models/streaming.js +29 -0
- package/dist/src/models/streaming.js.map +1 -1
- package/dist/src/multiagent/__tests__/events.test.js +177 -0
- package/dist/src/multiagent/__tests__/events.test.js.map +1 -1
- package/dist/src/multiagent/__tests__/graph.tracer.test.d.ts +2 -0
- package/dist/src/multiagent/__tests__/graph.tracer.test.d.ts.map +1 -0
- package/dist/src/multiagent/__tests__/graph.tracer.test.js +204 -0
- package/dist/src/multiagent/__tests__/graph.tracer.test.js.map +1 -0
- package/dist/src/multiagent/__tests__/nodes.test.js +48 -5
- package/dist/src/multiagent/__tests__/nodes.test.js.map +1 -1
- package/dist/src/multiagent/__tests__/swarm.test.js +34 -6
- package/dist/src/multiagent/__tests__/swarm.test.js.map +1 -1
- package/dist/src/multiagent/__tests__/swarm.tracer.test.d.ts +2 -0
- package/dist/src/multiagent/__tests__/swarm.tracer.test.d.ts.map +1 -0
- package/dist/src/multiagent/__tests__/swarm.tracer.test.js +235 -0
- package/dist/src/multiagent/__tests__/swarm.tracer.test.js.map +1 -0
- package/dist/src/multiagent/events.d.ts +14 -0
- package/dist/src/multiagent/events.d.ts.map +1 -1
- package/dist/src/multiagent/events.js +34 -0
- package/dist/src/multiagent/events.js.map +1 -1
- package/dist/src/multiagent/graph.d.ts +4 -0
- package/dist/src/multiagent/graph.d.ts.map +1 -1
- package/dist/src/multiagent/graph.js +42 -16
- 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/index.js.map +1 -1
- package/dist/src/multiagent/nodes.d.ts +23 -9
- package/dist/src/multiagent/nodes.d.ts.map +1 -1
- package/dist/src/multiagent/nodes.js +25 -14
- package/dist/src/multiagent/nodes.js.map +1 -1
- package/dist/src/multiagent/state.d.ts +8 -3
- package/dist/src/multiagent/state.d.ts.map +1 -1
- package/dist/src/multiagent/state.js +18 -4
- package/dist/src/multiagent/state.js.map +1 -1
- package/dist/src/multiagent/swarm.d.ts +15 -1
- package/dist/src/multiagent/swarm.d.ts.map +1 -1
- package/dist/src/multiagent/swarm.js +71 -30
- package/dist/src/multiagent/swarm.js.map +1 -1
- package/dist/src/session/__tests__/session-manager.test.js +36 -0
- package/dist/src/session/__tests__/session-manager.test.js.map +1 -1
- package/dist/src/session/session-manager.d.ts +2 -3
- package/dist/src/session/session-manager.d.ts.map +1 -1
- package/dist/src/session/session-manager.js +11 -9
- package/dist/src/session/session-manager.js.map +1 -1
- package/dist/src/telemetry/__tests__/local-trace.test.d.ts +2 -0
- package/dist/src/telemetry/__tests__/local-trace.test.d.ts.map +1 -0
- package/dist/src/telemetry/__tests__/local-trace.test.js +158 -0
- package/dist/src/telemetry/__tests__/local-trace.test.js.map +1 -0
- package/dist/src/telemetry/__tests__/tracer.test.node.js +28 -0
- package/dist/src/telemetry/__tests__/tracer.test.node.js.map +1 -1
- package/dist/src/telemetry/config.js +1 -1
- package/dist/src/telemetry/config.js.map +1 -1
- package/dist/src/telemetry/meter.d.ts +0 -13
- package/dist/src/telemetry/meter.d.ts.map +1 -1
- package/dist/src/telemetry/meter.js +8 -36
- package/dist/src/telemetry/meter.js.map +1 -1
- package/dist/src/telemetry/tracer.d.ts +107 -18
- package/dist/src/telemetry/tracer.d.ts.map +1 -1
- package/dist/src/telemetry/tracer.js +245 -33
- package/dist/src/telemetry/tracer.js.map +1 -1
- package/dist/src/telemetry/types.d.ts +49 -0
- package/dist/src/telemetry/types.d.ts.map +1 -1
- package/dist/src/tools/__tests__/structured-output-tool.test.d.ts +2 -0
- package/dist/src/tools/__tests__/structured-output-tool.test.d.ts.map +1 -0
- package/dist/src/tools/__tests__/structured-output-tool.test.js +84 -0
- package/dist/src/tools/__tests__/structured-output-tool.test.js.map +1 -0
- package/dist/src/tools/structured-output-tool.d.ts +41 -0
- package/dist/src/tools/structured-output-tool.d.ts.map +1 -0
- package/dist/src/tools/structured-output-tool.js +82 -0
- package/dist/src/tools/structured-output-tool.js.map +1 -0
- package/dist/src/tools/zod-tool.js +1 -1
- package/dist/src/tools/zod-tool.js.map +1 -1
- package/dist/src/{utils/zod.d.ts → tools/zod-utils.d.ts} +1 -1
- package/dist/src/tools/zod-utils.d.ts.map +1 -0
- package/dist/src/{utils/zod.js → tools/zod-utils.js} +1 -1
- package/dist/src/tools/zod-utils.js.map +1 -0
- package/dist/src/tsconfig.tsbuildinfo +1 -1
- package/dist/src/types/__tests__/agent.test.js +127 -0
- package/dist/src/types/__tests__/agent.test.js.map +1 -1
- package/dist/src/types/agent.d.ts +27 -1
- package/dist/src/types/agent.d.ts.map +1 -1
- package/dist/src/types/agent.js +26 -0
- package/dist/src/types/agent.js.map +1 -1
- package/dist/src/vended-tools/bash/__tests__/bash.test.node.js +12 -0
- package/dist/src/vended-tools/bash/__tests__/bash.test.node.js.map +1 -1
- package/dist/src/vended-tools/bash/bash.d.ts.map +1 -1
- package/dist/src/vended-tools/bash/bash.js +16 -14
- package/dist/src/vended-tools/bash/bash.js.map +1 -1
- package/package.json +12 -8
- package/dist/src/agent/__tests__/agent.tracer.test.d.ts +0 -2
- package/dist/src/agent/__tests__/agent.tracer.test.d.ts.map +0 -1
- package/dist/src/agent/__tests__/agent.tracer.test.js.map +0 -1
- package/dist/src/models/__tests__/gemini.test.d.ts +0 -2
- package/dist/src/models/__tests__/gemini.test.d.ts.map +0 -1
- package/dist/src/models/__tests__/gemini.test.js.map +0 -1
- package/dist/src/models/gemini/errors.d.ts.map +0 -1
- package/dist/src/models/gemini/errors.js.map +0 -1
- package/dist/src/models/gemini/model.js.map +0 -1
- package/dist/src/models/gemini/types.js +0 -5
- package/dist/src/models/gemini/types.js.map +0 -1
- package/dist/src/structured-output/__tests__/context.test.d.ts +0 -2
- package/dist/src/structured-output/__tests__/context.test.d.ts.map +0 -1
- package/dist/src/structured-output/__tests__/context.test.js +0 -201
- package/dist/src/structured-output/__tests__/context.test.js.map +0 -1
- package/dist/src/structured-output/__tests__/exceptions.test.d.ts +0 -2
- package/dist/src/structured-output/__tests__/exceptions.test.d.ts.map +0 -1
- package/dist/src/structured-output/__tests__/exceptions.test.js +0 -103
- package/dist/src/structured-output/__tests__/exceptions.test.js.map +0 -1
- package/dist/src/structured-output/__tests__/tool.test.d.ts +0 -2
- package/dist/src/structured-output/__tests__/tool.test.d.ts.map +0 -1
- package/dist/src/structured-output/__tests__/tool.test.js +0 -256
- package/dist/src/structured-output/__tests__/tool.test.js.map +0 -1
- package/dist/src/structured-output/__tests__/utils.test.d.ts +0 -2
- package/dist/src/structured-output/__tests__/utils.test.d.ts.map +0 -1
- package/dist/src/structured-output/__tests__/utils.test.js +0 -183
- package/dist/src/structured-output/__tests__/utils.test.js.map +0 -1
- package/dist/src/structured-output/context.d.ts +0 -91
- package/dist/src/structured-output/context.d.ts.map +0 -1
- package/dist/src/structured-output/context.js +0 -112
- package/dist/src/structured-output/context.js.map +0 -1
- package/dist/src/structured-output/exceptions.d.ts +0 -18
- package/dist/src/structured-output/exceptions.d.ts.map +0 -1
- package/dist/src/structured-output/exceptions.js +0 -28
- package/dist/src/structured-output/exceptions.js.map +0 -1
- package/dist/src/structured-output/tool.d.ts +0 -33
- package/dist/src/structured-output/tool.d.ts.map +0 -1
- package/dist/src/structured-output/tool.js +0 -73
- package/dist/src/structured-output/tool.js.map +0 -1
- package/dist/src/structured-output/utils.d.ts +0 -23
- package/dist/src/structured-output/utils.d.ts.map +0 -1
- package/dist/src/structured-output/utils.js +0 -104
- package/dist/src/structured-output/utils.js.map +0 -1
- package/dist/src/utils/zod.d.ts.map +0 -1
- package/dist/src/utils/zod.js.map +0 -1
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
import { StructuredOutputTool } from '../tool.js';
|
|
4
|
-
import { StructuredOutputContext } from '../context.js';
|
|
5
|
-
import { TextBlock, ToolResultBlock } from '../../types/messages.js';
|
|
6
|
-
describe('StructuredOutputTool', () => {
|
|
7
|
-
describe('constructor', () => {
|
|
8
|
-
it('creates tool with schema and name', () => {
|
|
9
|
-
const schema = z.object({ name: z.string() });
|
|
10
|
-
const context = new StructuredOutputContext(schema);
|
|
11
|
-
const tool = new StructuredOutputTool(schema, 'TestTool', context);
|
|
12
|
-
expect(tool.name).toBe('TestTool');
|
|
13
|
-
expect(tool.description).toContain('StructuredOutputTool');
|
|
14
|
-
expect(tool.toolSpec).toBeDefined();
|
|
15
|
-
});
|
|
16
|
-
it('sets tool spec from schema', () => {
|
|
17
|
-
const schema = z.object({ name: z.string(), age: z.number() });
|
|
18
|
-
const context = new StructuredOutputContext(schema);
|
|
19
|
-
const tool = new StructuredOutputTool(schema, 'TestTool', context);
|
|
20
|
-
expect(tool.toolSpec.name).toBe('TestTool');
|
|
21
|
-
expect(tool.toolSpec.inputSchema).toBeDefined();
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
describe('stream', () => {
|
|
25
|
-
it('validates and stores valid input', async () => {
|
|
26
|
-
const schema = z.object({ name: z.string(), age: z.number() });
|
|
27
|
-
const context = new StructuredOutputContext(schema);
|
|
28
|
-
const tool = new StructuredOutputTool(schema, 'TestTool', context);
|
|
29
|
-
const toolContext = {
|
|
30
|
-
toolUse: {
|
|
31
|
-
name: 'TestTool',
|
|
32
|
-
toolUseId: 'tool-1',
|
|
33
|
-
input: { name: 'John', age: 30 },
|
|
34
|
-
},
|
|
35
|
-
agent: {},
|
|
36
|
-
};
|
|
37
|
-
const generator = tool.stream(toolContext);
|
|
38
|
-
const result = await generator.next();
|
|
39
|
-
expect(result.done).toBe(true);
|
|
40
|
-
if (result.done) {
|
|
41
|
-
expect(result.value).toBeInstanceOf(ToolResultBlock);
|
|
42
|
-
expect(result.value.status).toBe('success');
|
|
43
|
-
expect(result.value.toolUseId).toBe('tool-1');
|
|
44
|
-
expect(context.hasResult()).toBe(true);
|
|
45
|
-
expect(context.getResult()).toEqual({ name: 'John', age: 30 });
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
it('returns error for invalid input', async () => {
|
|
49
|
-
const schema = z.object({ name: z.string(), age: z.number() });
|
|
50
|
-
const context = new StructuredOutputContext(schema);
|
|
51
|
-
const tool = new StructuredOutputTool(schema, 'TestTool', context);
|
|
52
|
-
const toolContext = {
|
|
53
|
-
toolUse: {
|
|
54
|
-
name: 'TestTool',
|
|
55
|
-
toolUseId: 'tool-1',
|
|
56
|
-
input: { name: 'John', age: 'invalid' },
|
|
57
|
-
},
|
|
58
|
-
agent: {},
|
|
59
|
-
};
|
|
60
|
-
const generator = tool.stream(toolContext);
|
|
61
|
-
const result = await generator.next();
|
|
62
|
-
expect(result.done).toBe(true);
|
|
63
|
-
if (result.done) {
|
|
64
|
-
expect(result.value).toBeInstanceOf(ToolResultBlock);
|
|
65
|
-
expect(result.value.status).toBe('error');
|
|
66
|
-
expect(result.value.toolUseId).toBe('tool-1');
|
|
67
|
-
expect(result.value.content[0]).toBeInstanceOf(TextBlock);
|
|
68
|
-
expect(result.value.content[0].text).toContain('Validation failed');
|
|
69
|
-
expect(result.value.content[0].text).toContain('age');
|
|
70
|
-
expect(context.hasResult()).toBe(false);
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
it('returns formatted validation errors', async () => {
|
|
74
|
-
const schema = z.object({
|
|
75
|
-
name: z.string(),
|
|
76
|
-
age: z.number(),
|
|
77
|
-
email: z.string().email(),
|
|
78
|
-
});
|
|
79
|
-
const context = new StructuredOutputContext(schema);
|
|
80
|
-
const tool = new StructuredOutputTool(schema, 'TestTool', context);
|
|
81
|
-
const toolContext = {
|
|
82
|
-
toolUse: {
|
|
83
|
-
name: 'TestTool',
|
|
84
|
-
toolUseId: 'tool-1',
|
|
85
|
-
input: { name: 123, age: 'invalid', email: 'not-email' },
|
|
86
|
-
},
|
|
87
|
-
agent: {},
|
|
88
|
-
};
|
|
89
|
-
const generator = tool.stream(toolContext);
|
|
90
|
-
const result = await generator.next();
|
|
91
|
-
expect(result.done).toBe(true);
|
|
92
|
-
if (result.done) {
|
|
93
|
-
expect(result.value.status).toBe('error');
|
|
94
|
-
const errorText = result.value.content[0].text;
|
|
95
|
-
expect(errorText).toContain("Field 'name':");
|
|
96
|
-
expect(errorText).toContain("Field 'age':");
|
|
97
|
-
expect(errorText).toContain("Field 'email':");
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
it('validates nested objects', async () => {
|
|
101
|
-
const schema = z.object({
|
|
102
|
-
user: z.object({
|
|
103
|
-
name: z.string(),
|
|
104
|
-
age: z.number(),
|
|
105
|
-
}),
|
|
106
|
-
});
|
|
107
|
-
const context = new StructuredOutputContext(schema);
|
|
108
|
-
const tool = new StructuredOutputTool(schema, 'TestTool', context);
|
|
109
|
-
const toolContext = {
|
|
110
|
-
toolUse: {
|
|
111
|
-
name: 'TestTool',
|
|
112
|
-
toolUseId: 'tool-1',
|
|
113
|
-
input: { user: { name: 'John', age: 30 } },
|
|
114
|
-
},
|
|
115
|
-
agent: {},
|
|
116
|
-
};
|
|
117
|
-
const generator = tool.stream(toolContext);
|
|
118
|
-
const result = await generator.next();
|
|
119
|
-
expect(result.done).toBe(true);
|
|
120
|
-
if (result.done) {
|
|
121
|
-
expect(result.value.status).toBe('success');
|
|
122
|
-
expect(context.getResult()).toEqual({ user: { name: 'John', age: 30 } });
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
it('validates arrays', async () => {
|
|
126
|
-
const schema = z.object({
|
|
127
|
-
items: z.array(z.string()),
|
|
128
|
-
});
|
|
129
|
-
const context = new StructuredOutputContext(schema);
|
|
130
|
-
const tool = new StructuredOutputTool(schema, 'TestTool', context);
|
|
131
|
-
const toolContext = {
|
|
132
|
-
toolUse: {
|
|
133
|
-
name: 'TestTool',
|
|
134
|
-
toolUseId: 'tool-1',
|
|
135
|
-
input: { items: ['a', 'b', 'c'] },
|
|
136
|
-
},
|
|
137
|
-
agent: {},
|
|
138
|
-
};
|
|
139
|
-
const generator = tool.stream(toolContext);
|
|
140
|
-
const result = await generator.next();
|
|
141
|
-
expect(result.done).toBe(true);
|
|
142
|
-
if (result.done) {
|
|
143
|
-
expect(result.value.status).toBe('success');
|
|
144
|
-
expect(context.getResult()).toEqual({ items: ['a', 'b', 'c'] });
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
it('handles optional fields', async () => {
|
|
148
|
-
const schema = z.object({
|
|
149
|
-
name: z.string(),
|
|
150
|
-
age: z.number().optional(),
|
|
151
|
-
});
|
|
152
|
-
const context = new StructuredOutputContext(schema);
|
|
153
|
-
const tool = new StructuredOutputTool(schema, 'TestTool', context);
|
|
154
|
-
const toolContext = {
|
|
155
|
-
toolUse: {
|
|
156
|
-
name: 'TestTool',
|
|
157
|
-
toolUseId: 'tool-1',
|
|
158
|
-
input: { name: 'John' },
|
|
159
|
-
},
|
|
160
|
-
agent: {},
|
|
161
|
-
};
|
|
162
|
-
const generator = tool.stream(toolContext);
|
|
163
|
-
const result = await generator.next();
|
|
164
|
-
expect(result.done).toBe(true);
|
|
165
|
-
if (result.done) {
|
|
166
|
-
expect(result.value.status).toBe('success');
|
|
167
|
-
expect(context.getResult()).toEqual({ name: 'John' });
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
it('stores error in result block on validation failure', async () => {
|
|
171
|
-
const schema = z.object({ name: z.string() });
|
|
172
|
-
const context = new StructuredOutputContext(schema);
|
|
173
|
-
const tool = new StructuredOutputTool(schema, 'TestTool', context);
|
|
174
|
-
const toolContext = {
|
|
175
|
-
toolUse: {
|
|
176
|
-
name: 'TestTool',
|
|
177
|
-
toolUseId: 'tool-1',
|
|
178
|
-
input: { name: 123 },
|
|
179
|
-
},
|
|
180
|
-
agent: {},
|
|
181
|
-
};
|
|
182
|
-
const generator = tool.stream(toolContext);
|
|
183
|
-
const result = await generator.next();
|
|
184
|
-
expect(result.done).toBe(true);
|
|
185
|
-
if (result.done) {
|
|
186
|
-
expect(result.value.error).toBeDefined();
|
|
187
|
-
expect(result.value.error).toBeInstanceOf(z.ZodError);
|
|
188
|
-
}
|
|
189
|
-
});
|
|
190
|
-
it('overwrites previous result on multiple calls', async () => {
|
|
191
|
-
const schema = z.object({ value: z.number() });
|
|
192
|
-
const context = new StructuredOutputContext(schema);
|
|
193
|
-
const tool = new StructuredOutputTool(schema, 'TestTool', context);
|
|
194
|
-
// First call
|
|
195
|
-
const toolContext1 = {
|
|
196
|
-
toolUse: {
|
|
197
|
-
name: 'TestTool',
|
|
198
|
-
toolUseId: 'tool-1',
|
|
199
|
-
input: { value: 1 },
|
|
200
|
-
},
|
|
201
|
-
agent: {},
|
|
202
|
-
};
|
|
203
|
-
const generator1 = tool.stream(toolContext1);
|
|
204
|
-
await generator1.next();
|
|
205
|
-
expect(context.getResult()).toEqual({ value: 1 });
|
|
206
|
-
// Second call
|
|
207
|
-
const toolContext2 = {
|
|
208
|
-
toolUse: {
|
|
209
|
-
name: 'TestTool',
|
|
210
|
-
toolUseId: 'tool-2',
|
|
211
|
-
input: { value: 2 },
|
|
212
|
-
},
|
|
213
|
-
agent: {},
|
|
214
|
-
};
|
|
215
|
-
const generator2 = tool.stream(toolContext2);
|
|
216
|
-
await generator2.next();
|
|
217
|
-
expect(context.getResult()).toEqual({ value: 2 });
|
|
218
|
-
expect(context.hasResult()).toBe(true);
|
|
219
|
-
});
|
|
220
|
-
it('does not store result when validation fails', async () => {
|
|
221
|
-
const schema = z.object({ value: z.number() });
|
|
222
|
-
const context = new StructuredOutputContext(schema);
|
|
223
|
-
const tool = new StructuredOutputTool(schema, 'TestTool', context);
|
|
224
|
-
// First call succeeds
|
|
225
|
-
const toolContext1 = {
|
|
226
|
-
toolUse: {
|
|
227
|
-
name: 'TestTool',
|
|
228
|
-
toolUseId: 'tool-1',
|
|
229
|
-
input: { value: 1 },
|
|
230
|
-
},
|
|
231
|
-
agent: {},
|
|
232
|
-
};
|
|
233
|
-
const generator1 = tool.stream(toolContext1);
|
|
234
|
-
await generator1.next();
|
|
235
|
-
expect(context.hasResult()).toBe(true);
|
|
236
|
-
expect(context.getResult()).toEqual({ value: 1 });
|
|
237
|
-
// Second call fails
|
|
238
|
-
const toolContext2 = {
|
|
239
|
-
toolUse: {
|
|
240
|
-
name: 'TestTool',
|
|
241
|
-
toolUseId: 'tool-2',
|
|
242
|
-
input: { value: 'invalid' },
|
|
243
|
-
},
|
|
244
|
-
agent: {},
|
|
245
|
-
};
|
|
246
|
-
const generator2 = tool.stream(toolContext2);
|
|
247
|
-
const result = await generator2.next();
|
|
248
|
-
expect(result.done).toBe(true);
|
|
249
|
-
if (result.done) {
|
|
250
|
-
expect(result.value.status).toBe('error');
|
|
251
|
-
}
|
|
252
|
-
expect(context.getResult()).toEqual({ value: 1 });
|
|
253
|
-
});
|
|
254
|
-
});
|
|
255
|
-
});
|
|
256
|
-
//# sourceMappingURL=tool.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tool.test.js","sourceRoot":"","sources":["../../../../src/structured-output/__tests__/tool.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAC7C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AACjD,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAA;AACvD,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAGpE,QAAQ,CAAC,sBAAsB,EAAE,GAAG,EAAE;IACpC,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;QAC3B,EAAE,CAAC,mCAAmC,EAAE,GAAG,EAAE;YAC3C,MAA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CAAA;QACnD,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.test.d.ts","sourceRoot":"","sources":["../../../../src/structured-output/__tests__/utils.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
import { convertSchemaToToolSpec, getSchemaDescription } from '../utils.js';
|
|
4
|
-
import { StructuredOutputException } from '../exceptions.js';
|
|
5
|
-
describe('convertSchemaToToolSpec', () => {
|
|
6
|
-
it('converts basic schema to tool spec', () => {
|
|
7
|
-
const schema = z.object({
|
|
8
|
-
name: z.string(),
|
|
9
|
-
age: z.number(),
|
|
10
|
-
});
|
|
11
|
-
const toolSpec = convertSchemaToToolSpec(schema, 'TestTool');
|
|
12
|
-
expect(toolSpec.name).toBe('TestTool');
|
|
13
|
-
expect(toolSpec.description).toContain('StructuredOutputTool');
|
|
14
|
-
expect(toolSpec.inputSchema).toStrictEqual({
|
|
15
|
-
type: 'object',
|
|
16
|
-
properties: {
|
|
17
|
-
name: { type: 'string' },
|
|
18
|
-
age: { type: 'number' },
|
|
19
|
-
},
|
|
20
|
-
required: ['name', 'age'],
|
|
21
|
-
additionalProperties: false,
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
it('includes schema description in tool spec', () => {
|
|
25
|
-
const schema = z
|
|
26
|
-
.object({
|
|
27
|
-
name: z.string(),
|
|
28
|
-
})
|
|
29
|
-
.describe('A person object');
|
|
30
|
-
const toolSpec = convertSchemaToToolSpec(schema, 'TestTool');
|
|
31
|
-
expect(toolSpec.description).toContain('A person object');
|
|
32
|
-
});
|
|
33
|
-
it('throws error for schema with refinements', () => {
|
|
34
|
-
const schema = z.object({
|
|
35
|
-
name: z.string().refine((val) => val.length > 0, 'Name cannot be empty'),
|
|
36
|
-
});
|
|
37
|
-
expect(() => convertSchemaToToolSpec(schema, 'TestTool')).toThrow(StructuredOutputException);
|
|
38
|
-
expect(() => convertSchemaToToolSpec(schema, 'TestTool')).toThrow('Zod refinements and transforms are not supported');
|
|
39
|
-
});
|
|
40
|
-
it('throws error for schema with transforms', () => {
|
|
41
|
-
const schema = z.string().transform((val) => val.toUpperCase());
|
|
42
|
-
expect(() => convertSchemaToToolSpec(schema, 'TestTool')).toThrow(StructuredOutputException);
|
|
43
|
-
expect(() => convertSchemaToToolSpec(schema, 'TestTool')).toThrow('Zod refinements and transforms are not supported');
|
|
44
|
-
});
|
|
45
|
-
it('throws error for schema with superRefine', () => {
|
|
46
|
-
const schema = z.object({ name: z.string() }).superRefine((val, ctx) => {
|
|
47
|
-
if (val.name.length === 0) {
|
|
48
|
-
ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'Name required' });
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
expect(() => convertSchemaToToolSpec(schema, 'TestTool')).toThrow(StructuredOutputException);
|
|
52
|
-
});
|
|
53
|
-
it('accepts schema with basic validations', () => {
|
|
54
|
-
const schema = z.object({
|
|
55
|
-
name: z.string().min(1).max(100),
|
|
56
|
-
age: z.number().int().positive(),
|
|
57
|
-
email: z.string().email(),
|
|
58
|
-
});
|
|
59
|
-
const toolSpec = convertSchemaToToolSpec(schema, 'TestTool');
|
|
60
|
-
expect(toolSpec.inputSchema).toMatchObject({
|
|
61
|
-
type: 'object',
|
|
62
|
-
properties: {
|
|
63
|
-
name: {
|
|
64
|
-
type: 'string',
|
|
65
|
-
minLength: 1,
|
|
66
|
-
maxLength: 100,
|
|
67
|
-
},
|
|
68
|
-
age: {
|
|
69
|
-
type: 'integer',
|
|
70
|
-
},
|
|
71
|
-
email: {
|
|
72
|
-
type: 'string',
|
|
73
|
-
format: 'email',
|
|
74
|
-
},
|
|
75
|
-
},
|
|
76
|
-
required: ['name', 'age', 'email'],
|
|
77
|
-
additionalProperties: false,
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
it('throws error for nested schema with refinements', () => {
|
|
81
|
-
const schema = z.object({
|
|
82
|
-
user: z.object({
|
|
83
|
-
name: z.string().refine((val) => val.length > 0),
|
|
84
|
-
}),
|
|
85
|
-
});
|
|
86
|
-
expect(() => convertSchemaToToolSpec(schema, 'TestTool')).toThrow(StructuredOutputException);
|
|
87
|
-
});
|
|
88
|
-
it('accepts nested schema without refinements', () => {
|
|
89
|
-
const schema = z.object({
|
|
90
|
-
user: z.object({
|
|
91
|
-
name: z.string(),
|
|
92
|
-
age: z.number(),
|
|
93
|
-
}),
|
|
94
|
-
items: z.array(z.string()),
|
|
95
|
-
});
|
|
96
|
-
const toolSpec = convertSchemaToToolSpec(schema, 'TestTool');
|
|
97
|
-
expect(toolSpec.inputSchema).toStrictEqual({
|
|
98
|
-
type: 'object',
|
|
99
|
-
properties: {
|
|
100
|
-
user: {
|
|
101
|
-
type: 'object',
|
|
102
|
-
properties: {
|
|
103
|
-
name: { type: 'string' },
|
|
104
|
-
age: { type: 'number' },
|
|
105
|
-
},
|
|
106
|
-
required: ['name', 'age'],
|
|
107
|
-
additionalProperties: false,
|
|
108
|
-
},
|
|
109
|
-
items: {
|
|
110
|
-
type: 'array',
|
|
111
|
-
items: { type: 'string' },
|
|
112
|
-
},
|
|
113
|
-
},
|
|
114
|
-
required: ['user', 'items'],
|
|
115
|
-
additionalProperties: false,
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
it('throws error for array with refinements', () => {
|
|
119
|
-
const schema = z.array(z.string().refine((val) => val.length > 0));
|
|
120
|
-
expect(() => convertSchemaToToolSpec(schema, 'TestTool')).toThrow(StructuredOutputException);
|
|
121
|
-
});
|
|
122
|
-
it('accepts union types', () => {
|
|
123
|
-
const schema = z.union([z.string(), z.number()]);
|
|
124
|
-
expect(() => convertSchemaToToolSpec(schema, 'TestTool')).not.toThrow();
|
|
125
|
-
});
|
|
126
|
-
it('accepts optional fields', () => {
|
|
127
|
-
const schema = z.object({
|
|
128
|
-
name: z.string(),
|
|
129
|
-
age: z.number().optional(),
|
|
130
|
-
});
|
|
131
|
-
const toolSpec = convertSchemaToToolSpec(schema, 'TestTool');
|
|
132
|
-
expect(toolSpec.inputSchema).toStrictEqual({
|
|
133
|
-
type: 'object',
|
|
134
|
-
properties: {
|
|
135
|
-
name: { type: 'string' },
|
|
136
|
-
age: { type: 'number' },
|
|
137
|
-
},
|
|
138
|
-
required: ['name'],
|
|
139
|
-
additionalProperties: false,
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
it('throws error for deeply nested refinements', () => {
|
|
143
|
-
const schema = z.object({
|
|
144
|
-
level1: z.object({
|
|
145
|
-
level2: z.object({
|
|
146
|
-
level3: z.string().refine((val) => val.length > 0),
|
|
147
|
-
}),
|
|
148
|
-
}),
|
|
149
|
-
});
|
|
150
|
-
expect(() => convertSchemaToToolSpec(schema, 'TestTool')).toThrow(StructuredOutputException);
|
|
151
|
-
});
|
|
152
|
-
it('throws error for refinements in union types', () => {
|
|
153
|
-
const schema = z.union([z.string().refine((val) => val.length > 0), z.number()]);
|
|
154
|
-
expect(() => convertSchemaToToolSpec(schema, 'TestTool')).toThrow(StructuredOutputException);
|
|
155
|
-
});
|
|
156
|
-
it('throws error for refinements in array items', () => {
|
|
157
|
-
const schema = z.object({
|
|
158
|
-
items: z.array(z.object({
|
|
159
|
-
name: z.string().refine((val) => val.length > 0),
|
|
160
|
-
})),
|
|
161
|
-
});
|
|
162
|
-
expect(() => convertSchemaToToolSpec(schema, 'TestTool')).toThrow(StructuredOutputException);
|
|
163
|
-
});
|
|
164
|
-
});
|
|
165
|
-
describe('getSchemaDescription', () => {
|
|
166
|
-
it('returns description from schema metadata', () => {
|
|
167
|
-
const schema = z.object({ name: z.string() }).describe('Test description');
|
|
168
|
-
const description = getSchemaDescription(schema);
|
|
169
|
-
expect(description).toBe('Test description');
|
|
170
|
-
});
|
|
171
|
-
it('returns empty string when no description', () => {
|
|
172
|
-
const schema = z.object({ name: z.string() });
|
|
173
|
-
const description = getSchemaDescription(schema);
|
|
174
|
-
expect(description).toBe('');
|
|
175
|
-
});
|
|
176
|
-
it('returns description from _def', () => {
|
|
177
|
-
const schema = z.object({ name: z.string() });
|
|
178
|
-
schema._def.description = 'Description in _def';
|
|
179
|
-
const description = getSchemaDescription(schema);
|
|
180
|
-
expect(description).toBe('Description in _def');
|
|
181
|
-
});
|
|
182
|
-
});
|
|
183
|
-
//# sourceMappingURL=utils.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.test.js","sourceRoot":"","sources":["../../../../src/structured-output/__tests__/utils.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAC7C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAC3E,OAAO,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAA;AAE5D,QAAQ,CAAC,yBAAyB,EAAE,GAAG,EAAE;IACvC,EAAE,CAAC,oCAAoC,EAAE,GAAG,EAAE;QAC5C,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;YACtB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;YAChB,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE;SAChB,CAAC,CAAA;QAEF,MAAM,QAAQ,GAAG,uBAAuB,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;QAE5D,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;QACtC,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,SAAS,CAAC,sBAAsB,CAAC,CAAA;QAC9D,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,aAAa,CAAC;YACzC,IAAI,EAAE,QAAQ;YACd,U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CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAA;IAC9C,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,0CAA0C,EAAE,GAAG,EAAE;QAClD,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;QAE7C,MAAM,WAAW,GAAG,oBAAoB,CAAC,MAAM,CAAC,CAAA;QAEhD,MAAM,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IAC9B,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,+BAA+B,EAAE,GAAG,EAAE;QACvC,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAE5C;QAAC,MAAc,CAAC,IAAI,CAAC,WAAW,GAAG,qBAAqB,CAAA;QAEzD,MAAM,WAAW,GAAG,oBAAoB,CAAC,MAAM,CAAC,CAAA;QAEhD,MAAM,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAA;IACjD,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import type { ToolRegistry } from '../registry/tool-registry.js';
|
|
3
|
-
/**
|
|
4
|
-
* Interface for structured output context operations.
|
|
5
|
-
* Allows for null object pattern implementation.
|
|
6
|
-
*/
|
|
7
|
-
export interface IStructuredOutputContext {
|
|
8
|
-
registerTool(registry: ToolRegistry): void;
|
|
9
|
-
storeResult(toolUseId: string, result: unknown): void;
|
|
10
|
-
hasResult(): boolean;
|
|
11
|
-
getResult(): unknown | undefined;
|
|
12
|
-
getToolName(): string;
|
|
13
|
-
cleanup(registry: ToolRegistry): void;
|
|
14
|
-
readonly isEnabled: boolean;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Null object implementation that does nothing.
|
|
18
|
-
* Used when no structured output schema is provided.
|
|
19
|
-
*/
|
|
20
|
-
export declare class NullStructuredOutputContext implements IStructuredOutputContext {
|
|
21
|
-
readonly isEnabled = false;
|
|
22
|
-
registerTool(_registry: ToolRegistry): void;
|
|
23
|
-
storeResult(_toolUseId: string, _result: unknown): void;
|
|
24
|
-
hasResult(): boolean;
|
|
25
|
-
getResult(): unknown | undefined;
|
|
26
|
-
getToolName(): string;
|
|
27
|
-
cleanup(_registry: ToolRegistry): void;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Context for managing structured output tool lifecycle per-invocation.
|
|
31
|
-
* Handles tool registration, result storage, and cleanup.
|
|
32
|
-
*/
|
|
33
|
-
export declare class StructuredOutputContext implements IStructuredOutputContext {
|
|
34
|
-
readonly isEnabled = true;
|
|
35
|
-
private _schema;
|
|
36
|
-
private _tool?;
|
|
37
|
-
private _result;
|
|
38
|
-
/**
|
|
39
|
-
* Creates a new StructuredOutputContext.
|
|
40
|
-
*
|
|
41
|
-
* @param schema - Zod schema for structured output
|
|
42
|
-
*/
|
|
43
|
-
constructor(schema: z.ZodSchema);
|
|
44
|
-
/**
|
|
45
|
-
* Registers the structured output tool with the tool registry.
|
|
46
|
-
*
|
|
47
|
-
* @param registry - The tool registry to register with
|
|
48
|
-
*/
|
|
49
|
-
registerTool(registry: ToolRegistry): void;
|
|
50
|
-
/**
|
|
51
|
-
* Stores the validated result from the structured output tool.
|
|
52
|
-
* If called multiple times, only the latest result is kept.
|
|
53
|
-
*
|
|
54
|
-
* @param toolUseId - The tool use ID (unused, kept for interface compatibility)
|
|
55
|
-
* @param result - The validated result
|
|
56
|
-
*/
|
|
57
|
-
storeResult(toolUseId: string, result: unknown): void;
|
|
58
|
-
/**
|
|
59
|
-
* Checks if a result has been stored.
|
|
60
|
-
*
|
|
61
|
-
* @returns true if a result has been stored
|
|
62
|
-
*/
|
|
63
|
-
hasResult(): boolean;
|
|
64
|
-
/**
|
|
65
|
-
* Retrieves the stored result, if available.
|
|
66
|
-
*
|
|
67
|
-
* @returns The validated result or undefined if not yet stored
|
|
68
|
-
*/
|
|
69
|
-
getResult(): unknown | undefined;
|
|
70
|
-
/**
|
|
71
|
-
* Gets the tool name for forcing.
|
|
72
|
-
*
|
|
73
|
-
* @returns The tool name or 'strands_structured_output' as fallback
|
|
74
|
-
*/
|
|
75
|
-
getToolName(): string;
|
|
76
|
-
/**
|
|
77
|
-
* Cleans up the structured output tool by removing it from the registry.
|
|
78
|
-
* Should be called in a finally block to ensure cleanup happens regardless of success/failure.
|
|
79
|
-
*
|
|
80
|
-
* @param registry - The tool registry to clean up from
|
|
81
|
-
*/
|
|
82
|
-
cleanup(registry: ToolRegistry): void;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Factory function to create the appropriate context based on schema presence.
|
|
86
|
-
*
|
|
87
|
-
* @param schema - Optional Zod schema for structured output
|
|
88
|
-
* @returns StructuredOutputContext if schema provided, NullStructuredOutputContext otherwise
|
|
89
|
-
*/
|
|
90
|
-
export declare function createStructuredOutputContext(schema?: z.ZodSchema): IStructuredOutputContext;
|
|
91
|
-
//# sourceMappingURL=context.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/structured-output/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAGhE;;;GAGG;AACH,MAAM,WAAW,wBAAwB;IACvC,YAAY,CAAC,QAAQ,EAAE,YAAY,GAAG,IAAI,CAAA;IAC1C,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI,CAAA;IACrD,SAAS,IAAI,OAAO,CAAA;IACpB,SAAS,IAAI,OAAO,GAAG,SAAS,CAAA;IAChC,WAAW,IAAI,MAAM,CAAA;IACrB,OAAO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