@illuma-ai/agents 1.1.20 → 1.1.22
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/dist/cjs/graphs/Graph.cjs +12 -1
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/graphs/MultiAgentGraph.cjs +85 -1
- package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/index.cjs +14 -0
- package/dist/cjs/llm/bedrock/index.cjs.map +1 -1
- package/dist/cjs/run.cjs +20 -9
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +12 -1
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/graphs/MultiAgentGraph.mjs +85 -1
- package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -1
- package/dist/esm/llm/bedrock/index.mjs +14 -0
- package/dist/esm/llm/bedrock/index.mjs.map +1 -1
- package/dist/esm/run.mjs +20 -9
- package/dist/esm/run.mjs.map +1 -1
- package/dist/types/graphs/MultiAgentGraph.d.ts +17 -0
- package/package.json +1 -1
- package/src/graphs/Graph.ts +12 -1
- package/src/graphs/MultiAgentGraph.ts +105 -1
- package/src/graphs/__tests__/multi-agent-delegate.test.ts +191 -0
- package/src/llm/bedrock/index.ts +17 -0
- package/src/run.ts +20 -11
- package/src/scripts/test-bedrock-handoff-autonomous.ts +231 -0
- package/src/agents/AgentContext.js +0 -782
- package/src/agents/AgentContext.test.js +0 -421
- package/src/agents/__tests__/AgentContext.test.js +0 -678
- package/src/agents/__tests__/resolveStructuredOutputMode.test.js +0 -117
- package/src/common/enum.js +0 -192
- package/src/common/index.js +0 -3
- package/src/events.js +0 -166
- package/src/graphs/Graph.js +0 -1857
- package/src/graphs/MultiAgentGraph.js +0 -1092
- package/src/graphs/__tests__/structured-output.integration.test.js +0 -624
- package/src/graphs/__tests__/structured-output.test.js +0 -144
- package/src/graphs/contextManagement.e2e.test.js +0 -718
- package/src/graphs/contextManagement.test.js +0 -485
- package/src/graphs/handoffValidation.test.js +0 -276
- package/src/graphs/index.js +0 -3
- package/src/index.js +0 -28
- package/src/instrumentation.js +0 -21
- package/src/llm/anthropic/index.js +0 -319
- package/src/llm/anthropic/types.js +0 -46
- package/src/llm/anthropic/utils/message_inputs.js +0 -627
- package/src/llm/anthropic/utils/message_outputs.js +0 -290
- package/src/llm/anthropic/utils/output_parsers.js +0 -89
- package/src/llm/anthropic/utils/tools.js +0 -25
- package/src/llm/bedrock/__tests__/bedrock-caching.test.js +0 -392
- package/src/llm/bedrock/index.js +0 -303
- package/src/llm/bedrock/types.js +0 -2
- package/src/llm/bedrock/utils/index.js +0 -6
- package/src/llm/bedrock/utils/message_inputs.js +0 -463
- package/src/llm/bedrock/utils/message_outputs.js +0 -269
- package/src/llm/fake.js +0 -92
- package/src/llm/google/index.js +0 -215
- package/src/llm/google/types.js +0 -12
- package/src/llm/google/utils/common.js +0 -670
- package/src/llm/google/utils/tools.js +0 -111
- package/src/llm/google/utils/zod_to_genai_parameters.js +0 -47
- package/src/llm/openai/index.js +0 -1033
- package/src/llm/openai/types.js +0 -2
- package/src/llm/openai/utils/index.js +0 -756
- package/src/llm/openai/utils/isReasoningModel.test.js +0 -79
- package/src/llm/openrouter/index.js +0 -261
- package/src/llm/openrouter/reasoning.test.js +0 -181
- package/src/llm/providers.js +0 -36
- package/src/llm/text.js +0 -65
- package/src/llm/vertexai/index.js +0 -402
- package/src/messages/__tests__/tools.test.js +0 -392
- package/src/messages/cache.js +0 -404
- package/src/messages/cache.test.js +0 -1167
- package/src/messages/content.js +0 -48
- package/src/messages/content.test.js +0 -314
- package/src/messages/core.js +0 -359
- package/src/messages/ensureThinkingBlock.test.js +0 -997
- package/src/messages/format.js +0 -973
- package/src/messages/formatAgentMessages.test.js +0 -2278
- package/src/messages/formatAgentMessages.tools.test.js +0 -362
- package/src/messages/formatMessage.test.js +0 -608
- package/src/messages/ids.js +0 -18
- package/src/messages/index.js +0 -9
- package/src/messages/labelContentByAgent.test.js +0 -725
- package/src/messages/prune.js +0 -438
- package/src/messages/reducer.js +0 -60
- package/src/messages/shiftIndexTokenCountMap.test.js +0 -63
- package/src/messages/summarize.js +0 -146
- package/src/messages/summarize.test.js +0 -332
- package/src/messages/tools.js +0 -90
- package/src/mockStream.js +0 -81
- package/src/prompts/collab.js +0 -7
- package/src/prompts/index.js +0 -3
- package/src/prompts/taskmanager.js +0 -58
- package/src/run.js +0 -427
- package/src/schemas/index.js +0 -3
- package/src/schemas/schema-preparation.test.js +0 -370
- package/src/schemas/validate.js +0 -314
- package/src/schemas/validate.test.js +0 -264
- package/src/scripts/abort.js +0 -127
- package/src/scripts/ant_web_search.js +0 -130
- package/src/scripts/ant_web_search_edge_case.js +0 -133
- package/src/scripts/ant_web_search_error_edge_case.js +0 -119
- package/src/scripts/args.js +0 -41
- package/src/scripts/bedrock-cache-debug.js +0 -186
- package/src/scripts/bedrock-content-aggregation-test.js +0 -195
- package/src/scripts/bedrock-merge-test.js +0 -80
- package/src/scripts/bedrock-parallel-tools-test.js +0 -150
- package/src/scripts/caching.js +0 -106
- package/src/scripts/cli.js +0 -152
- package/src/scripts/cli2.js +0 -119
- package/src/scripts/cli3.js +0 -163
- package/src/scripts/cli4.js +0 -165
- package/src/scripts/cli5.js +0 -165
- package/src/scripts/code_exec.js +0 -171
- package/src/scripts/code_exec_files.js +0 -180
- package/src/scripts/code_exec_multi_session.js +0 -185
- package/src/scripts/code_exec_ptc.js +0 -265
- package/src/scripts/code_exec_session.js +0 -217
- package/src/scripts/code_exec_simple.js +0 -120
- package/src/scripts/content.js +0 -111
- package/src/scripts/empty_input.js +0 -125
- package/src/scripts/handoff-test.js +0 -96
- package/src/scripts/image.js +0 -138
- package/src/scripts/memory.js +0 -83
- package/src/scripts/multi-agent-chain.js +0 -271
- package/src/scripts/multi-agent-conditional.js +0 -185
- package/src/scripts/multi-agent-document-review-chain.js +0 -171
- package/src/scripts/multi-agent-hybrid-flow.js +0 -264
- package/src/scripts/multi-agent-parallel-start.js +0 -214
- package/src/scripts/multi-agent-parallel.js +0 -346
- package/src/scripts/multi-agent-sequence.js +0 -184
- package/src/scripts/multi-agent-supervisor.js +0 -324
- package/src/scripts/multi-agent-test.js +0 -147
- package/src/scripts/parallel-asymmetric-tools-test.js +0 -202
- package/src/scripts/parallel-full-metadata-test.js +0 -176
- package/src/scripts/parallel-tools-test.js +0 -256
- package/src/scripts/programmatic_exec.js +0 -277
- package/src/scripts/programmatic_exec_agent.js +0 -168
- package/src/scripts/search.js +0 -118
- package/src/scripts/sequential-full-metadata-test.js +0 -143
- package/src/scripts/simple.js +0 -174
- package/src/scripts/single-agent-metadata-test.js +0 -152
- package/src/scripts/stream.js +0 -113
- package/src/scripts/test-custom-prompt-key.js +0 -132
- package/src/scripts/test-handoff-input.js +0 -143
- package/src/scripts/test-handoff-preamble.js +0 -227
- package/src/scripts/test-handoff-steering.js +0 -353
- package/src/scripts/test-multi-agent-list-handoff.js +0 -318
- package/src/scripts/test-parallel-agent-labeling.js +0 -253
- package/src/scripts/test-parallel-handoffs.js +0 -229
- package/src/scripts/test-thinking-handoff-bedrock.js +0 -132
- package/src/scripts/test-thinking-handoff.js +0 -132
- package/src/scripts/test-thinking-to-thinking-handoff-bedrock.js +0 -140
- package/src/scripts/test-tool-before-handoff-role-order.js +0 -223
- package/src/scripts/test-tools-before-handoff.js +0 -187
- package/src/scripts/test_code_api.js +0 -263
- package/src/scripts/thinking-bedrock.js +0 -128
- package/src/scripts/thinking-vertexai.js +0 -130
- package/src/scripts/thinking.js +0 -134
- package/src/scripts/tool_search.js +0 -114
- package/src/scripts/tools.js +0 -125
- package/src/specs/agent-handoffs-bedrock.integration.test.js +0 -280
- package/src/specs/agent-handoffs.test.js +0 -924
- package/src/specs/anthropic.simple.test.js +0 -287
- package/src/specs/azure.simple.test.js +0 -381
- package/src/specs/cache.simple.test.js +0 -282
- package/src/specs/custom-event-await.test.js +0 -148
- package/src/specs/deepseek.simple.test.js +0 -189
- package/src/specs/emergency-prune.test.js +0 -308
- package/src/specs/moonshot.simple.test.js +0 -237
- package/src/specs/observability.integration.test.js +0 -1337
- package/src/specs/openai.simple.test.js +0 -233
- package/src/specs/openrouter.simple.test.js +0 -202
- package/src/specs/prune.test.js +0 -733
- package/src/specs/reasoning.test.js +0 -144
- package/src/specs/spec.utils.js +0 -4
- package/src/specs/thinking-handoff.test.js +0 -486
- package/src/specs/thinking-prune.test.js +0 -600
- package/src/specs/token-distribution-edge-case.test.js +0 -246
- package/src/specs/token-memoization.test.js +0 -32
- package/src/specs/tokens.test.js +0 -49
- package/src/specs/tool-error.test.js +0 -139
- package/src/splitStream.js +0 -204
- package/src/splitStream.test.js +0 -504
- package/src/stream.js +0 -650
- package/src/stream.test.js +0 -225
- package/src/test/mockTools.js +0 -340
- package/src/tools/BrowserTools.js +0 -245
- package/src/tools/Calculator.js +0 -38
- package/src/tools/Calculator.test.js +0 -225
- package/src/tools/CodeExecutor.js +0 -233
- package/src/tools/ProgrammaticToolCalling.js +0 -602
- package/src/tools/StreamingToolCallBuffer.js +0 -179
- package/src/tools/ToolNode.js +0 -930
- package/src/tools/ToolSearch.js +0 -904
- package/src/tools/__tests__/BrowserTools.test.js +0 -306
- package/src/tools/__tests__/ProgrammaticToolCalling.integration.test.js +0 -276
- package/src/tools/__tests__/ProgrammaticToolCalling.test.js +0 -807
- package/src/tools/__tests__/StreamingToolCallBuffer.test.js +0 -175
- package/src/tools/__tests__/ToolApproval.test.js +0 -675
- package/src/tools/__tests__/ToolNode.recovery.test.js +0 -200
- package/src/tools/__tests__/ToolNode.session.test.js +0 -319
- package/src/tools/__tests__/ToolSearch.integration.test.js +0 -125
- package/src/tools/__tests__/ToolSearch.test.js +0 -812
- package/src/tools/__tests__/handlers.test.js +0 -799
- package/src/tools/__tests__/truncation-recovery.integration.test.js +0 -362
- package/src/tools/handlers.js +0 -306
- package/src/tools/schema.js +0 -25
- package/src/tools/search/anthropic.js +0 -34
- package/src/tools/search/content.js +0 -116
- package/src/tools/search/content.test.js +0 -133
- package/src/tools/search/firecrawl.js +0 -173
- package/src/tools/search/format.js +0 -198
- package/src/tools/search/highlights.js +0 -241
- package/src/tools/search/index.js +0 -3
- package/src/tools/search/jina-reranker.test.js +0 -106
- package/src/tools/search/rerankers.js +0 -165
- package/src/tools/search/schema.js +0 -102
- package/src/tools/search/search.js +0 -561
- package/src/tools/search/serper-scraper.js +0 -126
- package/src/tools/search/test.js +0 -129
- package/src/tools/search/tool.js +0 -453
- package/src/tools/search/types.js +0 -2
- package/src/tools/search/utils.js +0 -59
- package/src/types/graph.js +0 -24
- package/src/types/graph.test.js +0 -192
- package/src/types/index.js +0 -7
- package/src/types/llm.js +0 -2
- package/src/types/messages.js +0 -2
- package/src/types/run.js +0 -2
- package/src/types/stream.js +0 -2
- package/src/types/tools.js +0 -2
- package/src/utils/contextAnalytics.js +0 -79
- package/src/utils/contextAnalytics.test.js +0 -166
- package/src/utils/events.js +0 -26
- package/src/utils/graph.js +0 -11
- package/src/utils/handlers.js +0 -65
- package/src/utils/index.js +0 -10
- package/src/utils/llm.js +0 -21
- package/src/utils/llmConfig.js +0 -205
- package/src/utils/logging.js +0 -37
- package/src/utils/misc.js +0 -51
- package/src/utils/run.js +0 -69
- package/src/utils/schema.js +0 -21
- package/src/utils/title.js +0 -119
- package/src/utils/tokens.js +0 -92
- package/src/utils/toonFormat.js +0 -379
|
@@ -1,370 +0,0 @@
|
|
|
1
|
-
// src/schemas/schema-preparation.test.ts
|
|
2
|
-
import { prepareSchemaForProvider } from './validate';
|
|
3
|
-
import { Providers } from '@/common';
|
|
4
|
-
describe('prepareSchemaForProvider', () => {
|
|
5
|
-
describe('basic passthrough', () => {
|
|
6
|
-
it('returns schema unchanged when strict is false', () => {
|
|
7
|
-
const schema = {
|
|
8
|
-
type: 'object',
|
|
9
|
-
properties: {
|
|
10
|
-
name: { type: 'string' },
|
|
11
|
-
},
|
|
12
|
-
};
|
|
13
|
-
const { schema: result, warnings } = prepareSchemaForProvider(schema, Providers.OPENAI, false);
|
|
14
|
-
expect(result).toEqual(schema);
|
|
15
|
-
expect(warnings).toEqual([]);
|
|
16
|
-
});
|
|
17
|
-
it('returns schema with additionalProperties already set', () => {
|
|
18
|
-
const schema = {
|
|
19
|
-
type: 'object',
|
|
20
|
-
properties: {
|
|
21
|
-
name: { type: 'string' },
|
|
22
|
-
},
|
|
23
|
-
required: ['name'],
|
|
24
|
-
additionalProperties: false,
|
|
25
|
-
};
|
|
26
|
-
const { schema: result } = prepareSchemaForProvider(schema, Providers.OPENAI);
|
|
27
|
-
expect(result.additionalProperties).toBe(false);
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
describe('additionalProperties enforcement', () => {
|
|
31
|
-
it('adds additionalProperties: false to root object', () => {
|
|
32
|
-
const schema = {
|
|
33
|
-
type: 'object',
|
|
34
|
-
properties: {
|
|
35
|
-
name: { type: 'string' },
|
|
36
|
-
},
|
|
37
|
-
};
|
|
38
|
-
const { schema: result, warnings } = prepareSchemaForProvider(schema, Providers.ANTHROPIC);
|
|
39
|
-
expect(result.additionalProperties).toBe(false);
|
|
40
|
-
// Root object doesn't produce a warning for additionalProperties
|
|
41
|
-
});
|
|
42
|
-
it('adds additionalProperties: false to nested objects', () => {
|
|
43
|
-
const schema = {
|
|
44
|
-
type: 'object',
|
|
45
|
-
properties: {
|
|
46
|
-
address: {
|
|
47
|
-
type: 'object',
|
|
48
|
-
properties: {
|
|
49
|
-
street: { type: 'string' },
|
|
50
|
-
city: { type: 'string' },
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
additionalProperties: false,
|
|
55
|
-
};
|
|
56
|
-
const { schema: result, warnings } = prepareSchemaForProvider(schema, Providers.OPENAI);
|
|
57
|
-
const addressProp = result.properties.address;
|
|
58
|
-
expect(addressProp.additionalProperties).toBe(false);
|
|
59
|
-
expect(warnings.some(w => w.includes('additionalProperties'))).toBe(true);
|
|
60
|
-
});
|
|
61
|
-
it('adds additionalProperties: false to deeply nested objects', () => {
|
|
62
|
-
const schema = {
|
|
63
|
-
type: 'object',
|
|
64
|
-
properties: {
|
|
65
|
-
level1: {
|
|
66
|
-
type: 'object',
|
|
67
|
-
properties: {
|
|
68
|
-
level2: {
|
|
69
|
-
type: 'object',
|
|
70
|
-
properties: {
|
|
71
|
-
value: { type: 'string' },
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
},
|
|
75
|
-
},
|
|
76
|
-
},
|
|
77
|
-
additionalProperties: false,
|
|
78
|
-
};
|
|
79
|
-
const { schema: result } = prepareSchemaForProvider(schema, Providers.ANTHROPIC);
|
|
80
|
-
const level1 = result.properties.level1;
|
|
81
|
-
expect(level1.additionalProperties).toBe(false);
|
|
82
|
-
const level2 = level1.properties.level2;
|
|
83
|
-
expect(level2.additionalProperties).toBe(false);
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
describe('required properties enforcement', () => {
|
|
87
|
-
it('adds all properties to required when missing', () => {
|
|
88
|
-
const schema = {
|
|
89
|
-
type: 'object',
|
|
90
|
-
properties: {
|
|
91
|
-
name: { type: 'string' },
|
|
92
|
-
age: { type: 'number' },
|
|
93
|
-
},
|
|
94
|
-
};
|
|
95
|
-
const { schema: result, warnings } = prepareSchemaForProvider(schema, Providers.OPENAI);
|
|
96
|
-
expect(result.required).toEqual(expect.arrayContaining(['name', 'age']));
|
|
97
|
-
expect(warnings.some(w => w.includes('required'))).toBe(true);
|
|
98
|
-
});
|
|
99
|
-
it('adds missing properties to existing required array', () => {
|
|
100
|
-
const schema = {
|
|
101
|
-
type: 'object',
|
|
102
|
-
properties: {
|
|
103
|
-
name: { type: 'string' },
|
|
104
|
-
age: { type: 'number' },
|
|
105
|
-
email: { type: 'string' },
|
|
106
|
-
},
|
|
107
|
-
required: ['name'],
|
|
108
|
-
};
|
|
109
|
-
const { schema: result } = prepareSchemaForProvider(schema, Providers.ANTHROPIC);
|
|
110
|
-
expect(result.required).toEqual(expect.arrayContaining(['name', 'age', 'email']));
|
|
111
|
-
});
|
|
112
|
-
it('does not duplicate already-required properties', () => {
|
|
113
|
-
const schema = {
|
|
114
|
-
type: 'object',
|
|
115
|
-
properties: {
|
|
116
|
-
name: { type: 'string' },
|
|
117
|
-
age: { type: 'number' },
|
|
118
|
-
},
|
|
119
|
-
required: ['name', 'age'],
|
|
120
|
-
};
|
|
121
|
-
const { schema: result } = prepareSchemaForProvider(schema, Providers.OPENAI);
|
|
122
|
-
expect(result.required).toEqual(['name', 'age']);
|
|
123
|
-
});
|
|
124
|
-
it('adds required to nested objects', () => {
|
|
125
|
-
const schema = {
|
|
126
|
-
type: 'object',
|
|
127
|
-
properties: {
|
|
128
|
-
person: {
|
|
129
|
-
type: 'object',
|
|
130
|
-
properties: {
|
|
131
|
-
name: { type: 'string' },
|
|
132
|
-
age: { type: 'number' },
|
|
133
|
-
},
|
|
134
|
-
},
|
|
135
|
-
},
|
|
136
|
-
additionalProperties: false,
|
|
137
|
-
};
|
|
138
|
-
const { schema: result } = prepareSchemaForProvider(schema, Providers.OPENAI);
|
|
139
|
-
const person = result.properties.person;
|
|
140
|
-
expect(person.required).toEqual(expect.arrayContaining(['name', 'age']));
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
describe('numeric constraint stripping', () => {
|
|
144
|
-
it('strips minimum/maximum from number properties', () => {
|
|
145
|
-
const schema = {
|
|
146
|
-
type: 'object',
|
|
147
|
-
properties: {
|
|
148
|
-
age: { type: 'number', minimum: 0, maximum: 150 },
|
|
149
|
-
},
|
|
150
|
-
required: ['age'],
|
|
151
|
-
additionalProperties: false,
|
|
152
|
-
};
|
|
153
|
-
const { schema: result, warnings } = prepareSchemaForProvider(schema, Providers.ANTHROPIC);
|
|
154
|
-
const ageProp = result.properties.age;
|
|
155
|
-
expect(ageProp.minimum).toBeUndefined();
|
|
156
|
-
expect(ageProp.maximum).toBeUndefined();
|
|
157
|
-
expect(ageProp.description).toContain('minimum: 0');
|
|
158
|
-
expect(ageProp.description).toContain('maximum: 150');
|
|
159
|
-
expect(warnings.some(w => w.includes('minimum'))).toBe(true);
|
|
160
|
-
expect(warnings.some(w => w.includes('maximum'))).toBe(true);
|
|
161
|
-
});
|
|
162
|
-
it('strips multipleOf from integer properties', () => {
|
|
163
|
-
const schema = {
|
|
164
|
-
type: 'object',
|
|
165
|
-
properties: {
|
|
166
|
-
count: { type: 'integer', multipleOf: 5 },
|
|
167
|
-
},
|
|
168
|
-
required: ['count'],
|
|
169
|
-
additionalProperties: false,
|
|
170
|
-
};
|
|
171
|
-
const { schema: result, warnings } = prepareSchemaForProvider(schema, Providers.OPENAI);
|
|
172
|
-
const countProp = result.properties.count;
|
|
173
|
-
expect(countProp.multipleOf).toBeUndefined();
|
|
174
|
-
expect(countProp.description).toContain('multipleOf: 5');
|
|
175
|
-
expect(warnings.some(w => w.includes('multipleOf'))).toBe(true);
|
|
176
|
-
});
|
|
177
|
-
it('appends to existing description when stripping constraints', () => {
|
|
178
|
-
const schema = {
|
|
179
|
-
type: 'object',
|
|
180
|
-
properties: {
|
|
181
|
-
score: { type: 'number', description: 'User score', minimum: 0, maximum: 100 },
|
|
182
|
-
},
|
|
183
|
-
required: ['score'],
|
|
184
|
-
additionalProperties: false,
|
|
185
|
-
};
|
|
186
|
-
const { schema: result } = prepareSchemaForProvider(schema, Providers.ANTHROPIC);
|
|
187
|
-
const scoreProp = result.properties.score;
|
|
188
|
-
expect(scoreProp.description).toContain('User score');
|
|
189
|
-
expect(scoreProp.description).toContain('minimum: 0');
|
|
190
|
-
});
|
|
191
|
-
});
|
|
192
|
-
describe('string constraint stripping', () => {
|
|
193
|
-
it('strips minLength/maxLength from string properties', () => {
|
|
194
|
-
const schema = {
|
|
195
|
-
type: 'object',
|
|
196
|
-
properties: {
|
|
197
|
-
name: { type: 'string', minLength: 1, maxLength: 100 },
|
|
198
|
-
},
|
|
199
|
-
required: ['name'],
|
|
200
|
-
additionalProperties: false,
|
|
201
|
-
};
|
|
202
|
-
const { schema: result, warnings } = prepareSchemaForProvider(schema, Providers.OPENAI);
|
|
203
|
-
const nameProp = result.properties.name;
|
|
204
|
-
expect(nameProp.minLength).toBeUndefined();
|
|
205
|
-
expect(nameProp.maxLength).toBeUndefined();
|
|
206
|
-
expect(nameProp.description).toContain('minLength: 1');
|
|
207
|
-
expect(nameProp.description).toContain('maxLength: 100');
|
|
208
|
-
expect(warnings.length).toBeGreaterThan(0);
|
|
209
|
-
});
|
|
210
|
-
it('strips pattern from string properties', () => {
|
|
211
|
-
const schema = {
|
|
212
|
-
type: 'object',
|
|
213
|
-
properties: {
|
|
214
|
-
email: { type: 'string', pattern: '^[a-z]+@[a-z]+\\.[a-z]+$' },
|
|
215
|
-
},
|
|
216
|
-
required: ['email'],
|
|
217
|
-
additionalProperties: false,
|
|
218
|
-
};
|
|
219
|
-
const { schema: result } = prepareSchemaForProvider(schema, Providers.ANTHROPIC);
|
|
220
|
-
const emailProp = result.properties.email;
|
|
221
|
-
expect(emailProp.pattern).toBeUndefined();
|
|
222
|
-
expect(emailProp.description).toContain('pattern:');
|
|
223
|
-
});
|
|
224
|
-
});
|
|
225
|
-
describe('array constraint stripping', () => {
|
|
226
|
-
it('strips minItems/maxItems from array properties', () => {
|
|
227
|
-
const schema = {
|
|
228
|
-
type: 'object',
|
|
229
|
-
properties: {
|
|
230
|
-
tags: { type: 'array', items: { type: 'string' }, minItems: 1, maxItems: 10 },
|
|
231
|
-
},
|
|
232
|
-
required: ['tags'],
|
|
233
|
-
additionalProperties: false,
|
|
234
|
-
};
|
|
235
|
-
const { schema: result, warnings } = prepareSchemaForProvider(schema, Providers.OPENAI);
|
|
236
|
-
const tagsProp = result.properties.tags;
|
|
237
|
-
expect(tagsProp.minItems).toBeUndefined();
|
|
238
|
-
expect(tagsProp.maxItems).toBeUndefined();
|
|
239
|
-
expect(tagsProp.description).toContain('minItems: 1');
|
|
240
|
-
expect(warnings.some(w => w.includes('minItems'))).toBe(true);
|
|
241
|
-
});
|
|
242
|
-
});
|
|
243
|
-
describe('array items with object schemas', () => {
|
|
244
|
-
it('prepares object schemas inside array items', () => {
|
|
245
|
-
const schema = {
|
|
246
|
-
type: 'object',
|
|
247
|
-
properties: {
|
|
248
|
-
people: {
|
|
249
|
-
type: 'array',
|
|
250
|
-
items: {
|
|
251
|
-
type: 'object',
|
|
252
|
-
properties: {
|
|
253
|
-
name: { type: 'string' },
|
|
254
|
-
age: { type: 'number' },
|
|
255
|
-
},
|
|
256
|
-
},
|
|
257
|
-
},
|
|
258
|
-
},
|
|
259
|
-
additionalProperties: false,
|
|
260
|
-
};
|
|
261
|
-
const { schema: result } = prepareSchemaForProvider(schema, Providers.OPENAI);
|
|
262
|
-
const peopleProp = result.properties.people;
|
|
263
|
-
const items = peopleProp.items;
|
|
264
|
-
expect(items.additionalProperties).toBe(false);
|
|
265
|
-
expect(items.required).toEqual(expect.arrayContaining(['name', 'age']));
|
|
266
|
-
});
|
|
267
|
-
});
|
|
268
|
-
describe('anyOf handling', () => {
|
|
269
|
-
it('prepares object schemas within anyOf', () => {
|
|
270
|
-
const schema = {
|
|
271
|
-
type: 'object',
|
|
272
|
-
properties: {
|
|
273
|
-
result: {
|
|
274
|
-
anyOf: [
|
|
275
|
-
{ type: 'object', properties: { value: { type: 'string' } } },
|
|
276
|
-
{ type: 'null' },
|
|
277
|
-
],
|
|
278
|
-
},
|
|
279
|
-
},
|
|
280
|
-
additionalProperties: false,
|
|
281
|
-
};
|
|
282
|
-
const { schema: result } = prepareSchemaForProvider(schema, Providers.ANTHROPIC);
|
|
283
|
-
const resultProp = result.properties.result;
|
|
284
|
-
const anyOf = resultProp.anyOf;
|
|
285
|
-
const objectVariant = anyOf.find(v => v.type === 'object');
|
|
286
|
-
expect(objectVariant?.additionalProperties).toBe(false);
|
|
287
|
-
});
|
|
288
|
-
});
|
|
289
|
-
describe('$defs handling', () => {
|
|
290
|
-
it('prepares schemas in $defs', () => {
|
|
291
|
-
const schema = {
|
|
292
|
-
type: 'object',
|
|
293
|
-
properties: {
|
|
294
|
-
item: { $ref: '#/$defs/Item' },
|
|
295
|
-
},
|
|
296
|
-
$defs: {
|
|
297
|
-
Item: {
|
|
298
|
-
type: 'object',
|
|
299
|
-
properties: {
|
|
300
|
-
id: { type: 'string' },
|
|
301
|
-
name: { type: 'string' },
|
|
302
|
-
},
|
|
303
|
-
},
|
|
304
|
-
},
|
|
305
|
-
additionalProperties: false,
|
|
306
|
-
};
|
|
307
|
-
const { schema: result } = prepareSchemaForProvider(schema, Providers.OPENAI);
|
|
308
|
-
const defs = result.$defs;
|
|
309
|
-
expect(defs.Item.additionalProperties).toBe(false);
|
|
310
|
-
expect(defs.Item.required).toEqual(expect.arrayContaining(['id', 'name']));
|
|
311
|
-
});
|
|
312
|
-
});
|
|
313
|
-
describe('nesting depth warnings', () => {
|
|
314
|
-
it('warns when nesting exceeds OpenAI limit of 5', () => {
|
|
315
|
-
// Build a deeply nested schema
|
|
316
|
-
let innermost = { type: 'string' };
|
|
317
|
-
for (let i = 0; i < 7; i++) {
|
|
318
|
-
innermost = {
|
|
319
|
-
type: 'object',
|
|
320
|
-
properties: { nested: innermost },
|
|
321
|
-
additionalProperties: false,
|
|
322
|
-
required: ['nested'],
|
|
323
|
-
};
|
|
324
|
-
}
|
|
325
|
-
const { warnings } = prepareSchemaForProvider(innermost, Providers.OPENAI);
|
|
326
|
-
expect(warnings.some(w => w.includes('nesting depth') && w.includes('exceeds'))).toBe(true);
|
|
327
|
-
});
|
|
328
|
-
it('does not warn about nesting depth for Anthropic', () => {
|
|
329
|
-
let innermost = { type: 'string' };
|
|
330
|
-
for (let i = 0; i < 7; i++) {
|
|
331
|
-
innermost = {
|
|
332
|
-
type: 'object',
|
|
333
|
-
properties: { nested: innermost },
|
|
334
|
-
additionalProperties: false,
|
|
335
|
-
required: ['nested'],
|
|
336
|
-
};
|
|
337
|
-
}
|
|
338
|
-
const { warnings } = prepareSchemaForProvider(innermost, Providers.ANTHROPIC);
|
|
339
|
-
expect(warnings.some(w => w.includes('nesting depth'))).toBe(false);
|
|
340
|
-
});
|
|
341
|
-
});
|
|
342
|
-
describe('provider-specific behavior', () => {
|
|
343
|
-
it('works correctly for Bedrock', () => {
|
|
344
|
-
const schema = {
|
|
345
|
-
type: 'object',
|
|
346
|
-
properties: {
|
|
347
|
-
name: { type: 'string', maxLength: 50 },
|
|
348
|
-
score: { type: 'number', minimum: 0 },
|
|
349
|
-
},
|
|
350
|
-
};
|
|
351
|
-
const { schema: result } = prepareSchemaForProvider(schema, Providers.BEDROCK);
|
|
352
|
-
expect(result.additionalProperties).toBe(false);
|
|
353
|
-
expect(result.required).toEqual(expect.arrayContaining(['name', 'score']));
|
|
354
|
-
const nameProp = result.properties.name;
|
|
355
|
-
expect(nameProp.maxLength).toBeUndefined();
|
|
356
|
-
});
|
|
357
|
-
it('does not mutate the original schema', () => {
|
|
358
|
-
const schema = {
|
|
359
|
-
type: 'object',
|
|
360
|
-
properties: {
|
|
361
|
-
name: { type: 'string', minLength: 1 },
|
|
362
|
-
},
|
|
363
|
-
};
|
|
364
|
-
const original = JSON.parse(JSON.stringify(schema));
|
|
365
|
-
prepareSchemaForProvider(schema, Providers.OPENAI);
|
|
366
|
-
expect(schema).toEqual(original);
|
|
367
|
-
});
|
|
368
|
-
});
|
|
369
|
-
});
|
|
370
|
-
//# sourceMappingURL=schema-preparation.test.js.map
|
package/src/schemas/validate.js
DELETED
|
@@ -1,314 +0,0 @@
|
|
|
1
|
-
import { Providers } from '@/common';
|
|
2
|
-
/**
|
|
3
|
-
* Validates structured output against a JSON Schema.
|
|
4
|
-
*
|
|
5
|
-
* @param output - The output to validate
|
|
6
|
-
* @param schema - JSON Schema to validate against
|
|
7
|
-
* @returns Validation result with success flag and data or error
|
|
8
|
-
*/
|
|
9
|
-
export function validateStructuredOutput(output, schema) {
|
|
10
|
-
try {
|
|
11
|
-
// Parse output if it's a string
|
|
12
|
-
const data = typeof output === 'string' ? JSON.parse(output) : output;
|
|
13
|
-
// Basic JSON Schema validation
|
|
14
|
-
const errors = validateAgainstJsonSchema(data, schema);
|
|
15
|
-
if (errors.length > 0) {
|
|
16
|
-
return {
|
|
17
|
-
success: false,
|
|
18
|
-
error: `Validation failed: ${errors.join('; ')}`,
|
|
19
|
-
raw: data,
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
return {
|
|
23
|
-
success: true,
|
|
24
|
-
data: data,
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
catch (e) {
|
|
28
|
-
return {
|
|
29
|
-
success: false,
|
|
30
|
-
error: `Failed to parse output: ${e.message}`,
|
|
31
|
-
raw: output,
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Validates data against a JSON Schema (simplified implementation).
|
|
37
|
-
* For complex schemas, consider using ajv or similar library.
|
|
38
|
-
*/
|
|
39
|
-
function validateAgainstJsonSchema(data, schema, path = '') {
|
|
40
|
-
const errors = [];
|
|
41
|
-
if (schema.type === 'object' && typeof data !== 'object') {
|
|
42
|
-
errors.push(`${path || 'root'}: expected object, got ${typeof data}`);
|
|
43
|
-
return errors;
|
|
44
|
-
}
|
|
45
|
-
if (schema.type === 'array' && !Array.isArray(data)) {
|
|
46
|
-
errors.push(`${path || 'root'}: expected array, got ${typeof data}`);
|
|
47
|
-
return errors;
|
|
48
|
-
}
|
|
49
|
-
if (schema.type === 'string' && typeof data !== 'string') {
|
|
50
|
-
errors.push(`${path || 'root'}: expected string, got ${typeof data}`);
|
|
51
|
-
return errors;
|
|
52
|
-
}
|
|
53
|
-
if (schema.type === 'number' && typeof data !== 'number') {
|
|
54
|
-
errors.push(`${path || 'root'}: expected number, got ${typeof data}`);
|
|
55
|
-
return errors;
|
|
56
|
-
}
|
|
57
|
-
if (schema.type === 'boolean' && typeof data !== 'boolean') {
|
|
58
|
-
errors.push(`${path || 'root'}: expected boolean, got ${typeof data}`);
|
|
59
|
-
return errors;
|
|
60
|
-
}
|
|
61
|
-
// Validate required properties
|
|
62
|
-
if (schema.type === 'object' &&
|
|
63
|
-
Array.isArray(schema.required) &&
|
|
64
|
-
typeof data === 'object' &&
|
|
65
|
-
data !== null) {
|
|
66
|
-
for (const requiredProp of schema.required) {
|
|
67
|
-
if (!(requiredProp in data)) {
|
|
68
|
-
errors.push(`${path || 'root'}: missing required property '${requiredProp}'`);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
// Validate nested properties
|
|
73
|
-
if (schema.type === 'object' &&
|
|
74
|
-
schema.properties &&
|
|
75
|
-
typeof data === 'object' &&
|
|
76
|
-
data !== null) {
|
|
77
|
-
const properties = schema.properties;
|
|
78
|
-
for (const [key, propSchema] of Object.entries(properties)) {
|
|
79
|
-
if (key in data) {
|
|
80
|
-
const nestedErrors = validateAgainstJsonSchema(data[key], propSchema, path ? `${path}.${key}` : key);
|
|
81
|
-
errors.push(...nestedErrors);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
// Validate array items
|
|
86
|
-
if (schema.type === 'array' && schema.items && Array.isArray(data)) {
|
|
87
|
-
const itemSchema = schema.items;
|
|
88
|
-
for (let i = 0; i < data.length; i++) {
|
|
89
|
-
const nestedErrors = validateAgainstJsonSchema(data[i], itemSchema, `${path || 'root'}[${i}]`);
|
|
90
|
-
errors.push(...nestedErrors);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
// Validate enum values
|
|
94
|
-
if (schema.enum && Array.isArray(schema.enum)) {
|
|
95
|
-
if (!schema.enum.includes(data)) {
|
|
96
|
-
errors.push(`${path || 'root'}: value '${data}' not in enum [${schema.enum.join(', ')}]`);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return errors;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Converts a Zod schema to JSON Schema format.
|
|
103
|
-
* This is a simplified converter for common types.
|
|
104
|
-
*/
|
|
105
|
-
export function zodToJsonSchema(zodSchema) {
|
|
106
|
-
// Use the zod-to-json-schema library if available
|
|
107
|
-
// For now, provide a basic implementation
|
|
108
|
-
try {
|
|
109
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
110
|
-
const { zodToJsonSchema: convert } = require('zod-to-json-schema');
|
|
111
|
-
return convert(zodSchema);
|
|
112
|
-
}
|
|
113
|
-
catch {
|
|
114
|
-
// Fallback: return a generic object schema
|
|
115
|
-
return {
|
|
116
|
-
type: 'object',
|
|
117
|
-
additionalProperties: true,
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Creates a structured output error message for retry.
|
|
123
|
-
*/
|
|
124
|
-
export function createValidationErrorMessage(result, customMessage) {
|
|
125
|
-
if (customMessage) {
|
|
126
|
-
return customMessage;
|
|
127
|
-
}
|
|
128
|
-
return `The response did not match the expected schema. Error: ${result.error}. Please try again and ensure your response exactly matches the required format.`;
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Checks if a value is a valid JSON Schema object.
|
|
132
|
-
*/
|
|
133
|
-
export function isValidJsonSchema(value) {
|
|
134
|
-
if (typeof value !== 'object' || value === null) {
|
|
135
|
-
return false;
|
|
136
|
-
}
|
|
137
|
-
const schema = value;
|
|
138
|
-
// Basic check: must have a type or properties
|
|
139
|
-
return (typeof schema.type === 'string' ||
|
|
140
|
-
typeof schema.properties === 'object' ||
|
|
141
|
-
typeof schema.$schema === 'string');
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Normalizes a JSON Schema by adding defaults and cleaning up.
|
|
145
|
-
*/
|
|
146
|
-
export function normalizeJsonSchema(schema, config) {
|
|
147
|
-
const normalized = { ...schema };
|
|
148
|
-
// Ensure type is set
|
|
149
|
-
if (!normalized.type && normalized.properties) {
|
|
150
|
-
normalized.type = 'object';
|
|
151
|
-
}
|
|
152
|
-
// Add title from config name
|
|
153
|
-
if (config?.name && !normalized.title) {
|
|
154
|
-
normalized.title = config.name;
|
|
155
|
-
}
|
|
156
|
-
// Add description from config
|
|
157
|
-
if (config?.description && !normalized.description) {
|
|
158
|
-
normalized.description = config.description;
|
|
159
|
-
}
|
|
160
|
-
// Enable additionalProperties: false for strict mode
|
|
161
|
-
if (config?.strict !== false && normalized.type === 'object') {
|
|
162
|
-
normalized.additionalProperties = normalized.additionalProperties ?? false;
|
|
163
|
-
}
|
|
164
|
-
return normalized;
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* Keywords unsupported by native structured output providers.
|
|
168
|
-
* These are stripped from schemas and moved to description fields when strict mode is enabled.
|
|
169
|
-
*/
|
|
170
|
-
const UNSUPPORTED_NUMERIC_KEYWORDS = ['minimum', 'maximum', 'exclusiveMinimum', 'exclusiveMaximum', 'multipleOf'];
|
|
171
|
-
const UNSUPPORTED_STRING_KEYWORDS = ['minLength', 'maxLength', 'pattern', 'format'];
|
|
172
|
-
const UNSUPPORTED_ARRAY_KEYWORDS = ['minItems', 'maxItems', 'uniqueItems'];
|
|
173
|
-
const UNSUPPORTED_OBJECT_KEYWORDS = ['minProperties', 'maxProperties', 'patternProperties'];
|
|
174
|
-
/**
|
|
175
|
-
* Prepares a JSON Schema for a specific provider's native structured output API.
|
|
176
|
-
*
|
|
177
|
-
* This function normalizes the schema to comply with provider-specific requirements:
|
|
178
|
-
* - Adds `additionalProperties: false` recursively to all objects (required by all providers in strict mode)
|
|
179
|
-
* - Ensures all properties are listed in `required` (required by OpenAI and Anthropic)
|
|
180
|
-
* - Strips unsupported constraint keywords (minimum, maxLength, etc.) and moves them to description
|
|
181
|
-
* - Returns warnings for any modifications made
|
|
182
|
-
*
|
|
183
|
-
* @param schema - The original JSON Schema
|
|
184
|
-
* @param provider - The LLM provider
|
|
185
|
-
* @param strict - Whether strict mode is enabled (default: true)
|
|
186
|
-
* @returns The prepared schema and any warnings
|
|
187
|
-
*/
|
|
188
|
-
export function prepareSchemaForProvider(schema, provider, strict = true) {
|
|
189
|
-
const warnings = [];
|
|
190
|
-
if (!strict) {
|
|
191
|
-
return { schema: { ...schema }, warnings };
|
|
192
|
-
}
|
|
193
|
-
const prepared = prepareObjectRecursive(schema, '', provider, warnings);
|
|
194
|
-
return { schema: prepared, warnings };
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* Recursively prepares a schema node for native structured output.
|
|
198
|
-
*/
|
|
199
|
-
function prepareObjectRecursive(schema, path, provider, warnings, depth = 0) {
|
|
200
|
-
const result = { ...schema };
|
|
201
|
-
const currentPath = path || 'root';
|
|
202
|
-
// Warn on deep nesting (OpenAI limit is 5)
|
|
203
|
-
if (depth > 5 && (provider === Providers.OPENAI || provider === Providers.AZURE)) {
|
|
204
|
-
warnings.push(`${currentPath}: nesting depth ${depth} exceeds OpenAI's limit of 5 levels`);
|
|
205
|
-
}
|
|
206
|
-
// Handle object type
|
|
207
|
-
if (result.type === 'object' || (result.properties && !result.type)) {
|
|
208
|
-
if (!result.type) {
|
|
209
|
-
result.type = 'object';
|
|
210
|
-
}
|
|
211
|
-
// Add additionalProperties: false
|
|
212
|
-
if (result.additionalProperties !== false) {
|
|
213
|
-
result.additionalProperties = false;
|
|
214
|
-
if (path) {
|
|
215
|
-
warnings.push(`${currentPath}: set additionalProperties to false for strict mode`);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
// Ensure all properties are in required
|
|
219
|
-
if (result.properties && typeof result.properties === 'object') {
|
|
220
|
-
const properties = result.properties;
|
|
221
|
-
const propertyNames = Object.keys(properties);
|
|
222
|
-
const currentRequired = Array.isArray(result.required) ? result.required : [];
|
|
223
|
-
const missingRequired = propertyNames.filter(name => !currentRequired.includes(name));
|
|
224
|
-
if (missingRequired.length > 0) {
|
|
225
|
-
result.required = [...currentRequired, ...missingRequired];
|
|
226
|
-
warnings.push(`${currentPath}: added ${missingRequired.join(', ')} to required (all properties must be required for strict mode; use type union with null for optional fields)`);
|
|
227
|
-
}
|
|
228
|
-
// Recursively prepare nested properties
|
|
229
|
-
const preparedProperties = {};
|
|
230
|
-
for (const [key, propSchema] of Object.entries(properties)) {
|
|
231
|
-
preparedProperties[key] = preparePropertySchema(propSchema, path ? `${path}.${key}` : key, provider, warnings, depth + 1);
|
|
232
|
-
}
|
|
233
|
-
result.properties = preparedProperties;
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
// Handle array type
|
|
237
|
-
if (result.type === 'array' && result.items && typeof result.items === 'object') {
|
|
238
|
-
result.items = preparePropertySchema(result.items, `${currentPath}[]`, provider, warnings, depth + 1);
|
|
239
|
-
// Strip unsupported array keywords
|
|
240
|
-
for (const keyword of UNSUPPORTED_ARRAY_KEYWORDS) {
|
|
241
|
-
if (keyword in result) {
|
|
242
|
-
appendToDescription(result, `${keyword}: ${result[keyword]}`);
|
|
243
|
-
delete result[keyword];
|
|
244
|
-
warnings.push(`${currentPath}: moved unsupported keyword '${keyword}' to description`);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
// Handle anyOf
|
|
249
|
-
if (Array.isArray(result.anyOf)) {
|
|
250
|
-
result.anyOf = result.anyOf.map((variant, i) => preparePropertySchema(variant, `${currentPath}.anyOf[${i}]`, provider, warnings, depth + 1));
|
|
251
|
-
}
|
|
252
|
-
// Handle $defs / definitions
|
|
253
|
-
for (const defsKey of ['$defs', 'definitions']) {
|
|
254
|
-
if (result[defsKey] && typeof result[defsKey] === 'object') {
|
|
255
|
-
const defs = result[defsKey];
|
|
256
|
-
const preparedDefs = {};
|
|
257
|
-
for (const [key, defSchema] of Object.entries(defs)) {
|
|
258
|
-
preparedDefs[key] = preparePropertySchema(defSchema, `${defsKey}.${key}`, provider, warnings, depth);
|
|
259
|
-
}
|
|
260
|
-
result[defsKey] = preparedDefs;
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
return result;
|
|
264
|
-
}
|
|
265
|
-
/**
|
|
266
|
-
* Prepares a single property schema, stripping unsupported keywords based on type.
|
|
267
|
-
*/
|
|
268
|
-
function preparePropertySchema(schema, path, provider, warnings, depth) {
|
|
269
|
-
const result = { ...schema };
|
|
270
|
-
// Strip unsupported numeric keywords
|
|
271
|
-
if (result.type === 'number' || result.type === 'integer') {
|
|
272
|
-
for (const keyword of UNSUPPORTED_NUMERIC_KEYWORDS) {
|
|
273
|
-
if (keyword in result) {
|
|
274
|
-
appendToDescription(result, `${keyword}: ${result[keyword]}`);
|
|
275
|
-
delete result[keyword];
|
|
276
|
-
warnings.push(`${path}: moved unsupported keyword '${keyword}' to description`);
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
// Strip unsupported string keywords
|
|
281
|
-
if (result.type === 'string') {
|
|
282
|
-
for (const keyword of UNSUPPORTED_STRING_KEYWORDS) {
|
|
283
|
-
if (keyword in result) {
|
|
284
|
-
appendToDescription(result, `${keyword}: ${result[keyword]}`);
|
|
285
|
-
delete result[keyword];
|
|
286
|
-
warnings.push(`${path}: moved unsupported keyword '${keyword}' to description`);
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
// Strip unsupported object keywords
|
|
291
|
-
if (result.type === 'object') {
|
|
292
|
-
for (const keyword of UNSUPPORTED_OBJECT_KEYWORDS) {
|
|
293
|
-
if (keyword in result) {
|
|
294
|
-
appendToDescription(result, `${keyword}: ${result[keyword]}`);
|
|
295
|
-
delete result[keyword];
|
|
296
|
-
warnings.push(`${path}: moved unsupported keyword '${keyword}' to description`);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
// Recursively handle nested objects and arrays
|
|
301
|
-
if (result.type === 'object' || result.properties || result.type === 'array' || result.anyOf || result.$defs || result.definitions) {
|
|
302
|
-
return prepareObjectRecursive(result, path, provider, warnings, depth);
|
|
303
|
-
}
|
|
304
|
-
return result;
|
|
305
|
-
}
|
|
306
|
-
/**
|
|
307
|
-
* Appends a constraint description to the schema's description field.
|
|
308
|
-
*/
|
|
309
|
-
function appendToDescription(schema, constraint) {
|
|
310
|
-
const existing = typeof schema.description === 'string' ? schema.description : '';
|
|
311
|
-
const constraintNote = `[Constraint: ${constraint}]`;
|
|
312
|
-
schema.description = existing ? `${existing} ${constraintNote}` : constraintNote;
|
|
313
|
-
}
|
|
314
|
-
//# sourceMappingURL=validate.js.map
|