@crewai-ts/core 0.1.13 → 0.2.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/dist/agent.d.ts +16 -18
- package/dist/auth.cjs +598 -0
- package/dist/auth.js +40 -0
- package/dist/{chunk-3PVW4JKT.js → chunk-C43UEMCX.js} +6712 -7268
- package/dist/chunk-CCOE6MLE.js +896 -0
- package/dist/chunk-HFQTF332.js +4455 -0
- package/dist/{chunk-BE4JYKSG.js → chunk-MM4ROIFG.js} +12 -1490
- package/dist/chunk-RH43TNKN.js +238 -0
- package/dist/chunk-S477WFUT.js +565 -0
- package/dist/chunk-SB7ADUQA.js +110 -0
- package/dist/chunk-T32G6KDW.js +40 -0
- package/dist/crew.d.ts +24 -26
- package/dist/events.cjs +7513 -0
- package/dist/events.js +406 -0
- package/dist/experimental-conversational.cjs +272 -0
- package/dist/experimental-conversational.js +26 -0
- package/dist/feature-hooks.cjs +149 -0
- package/dist/feature-hooks.d.ts +94 -0
- package/dist/feature-hooks.js +36 -0
- package/dist/index.cjs +33923 -64381
- package/dist/index.d.ts +2 -15
- package/dist/index.js +16720 -49562
- package/dist/input-provider.d.ts +3 -4
- package/dist/lite-agent.d.ts +4 -4
- package/dist/llm.cjs +7467 -0
- package/dist/llm.d.ts +0 -4
- package/dist/llm.js +225 -0
- package/dist/optional-yaml.d.ts +8 -0
- package/dist/project.d.ts +1 -1
- package/dist/schema-utils.cjs +968 -0
- package/dist/schema-utils.d.ts +1 -1
- package/dist/schema-utils.js +102 -0
- package/dist/state-provider-core.js +3 -2
- package/dist/task.d.ts +3 -4
- package/dist/tools.cjs +6872 -0
- package/dist/tools.d.ts +0 -60
- package/dist/tools.js +114 -0
- package/dist/types.cjs +68 -0
- package/dist/types.js +14 -0
- package/package.json +52 -111
- package/dist/a2a.d.ts +0 -1684
- package/dist/a2ui-schemas.d.ts +0 -3312
- package/dist/a2ui.d.ts +0 -379
- package/dist/flow-conversation.d.ts +0 -90
- package/dist/flow-definition.d.ts +0 -195
- package/dist/flow-persistence.d.ts +0 -107
- package/dist/flow-visualization.d.ts +0 -77
- package/dist/flow.d.ts +0 -927
- package/dist/knowledge.d.ts +0 -353
- package/dist/mcp-DS7UMYAM.js +0 -62
- package/dist/mcp.d.ts +0 -315
- package/dist/memory.d.ts +0 -915
- package/dist/openai-completion.d.ts +0 -327
- package/dist/provider-completions.d.ts +0 -596
- package/dist/rag.d.ts +0 -1074
|
@@ -0,0 +1,896 @@
|
|
|
1
|
+
// src/schema-utils.ts
|
|
2
|
+
var JsonSchemaInfo = class JsonSchemaInfo2 {
|
|
3
|
+
name;
|
|
4
|
+
strict = true;
|
|
5
|
+
schema;
|
|
6
|
+
constructor(options) {
|
|
7
|
+
this.name = options.name;
|
|
8
|
+
this.schema = options.schema;
|
|
9
|
+
void options.strict;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
var ModelDescription = class ModelDescription2 {
|
|
13
|
+
type = "json_schema";
|
|
14
|
+
json_schema;
|
|
15
|
+
constructor(options) {
|
|
16
|
+
this.json_schema = options.json_schema instanceof JsonSchemaInfo ? options.json_schema : new JsonSchemaInfo(options.json_schema);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
var FORMAT_TYPE_MAP = {
|
|
20
|
+
"date-time": "string",
|
|
21
|
+
date: "string",
|
|
22
|
+
time: "string",
|
|
23
|
+
duration: "string"
|
|
24
|
+
};
|
|
25
|
+
var OPENAI_SUPPORTED_FORMATS = /* @__PURE__ */ new Set(["date-time", "date", "time", "duration"]);
|
|
26
|
+
var STRICT_METADATA_KEYS = [
|
|
27
|
+
"title",
|
|
28
|
+
"default",
|
|
29
|
+
"examples",
|
|
30
|
+
"example",
|
|
31
|
+
"$comment",
|
|
32
|
+
"readOnly",
|
|
33
|
+
"writeOnly",
|
|
34
|
+
"deprecated"
|
|
35
|
+
];
|
|
36
|
+
var CLAUDE_STRICT_UNSUPPORTED = [
|
|
37
|
+
"minimum",
|
|
38
|
+
"maximum",
|
|
39
|
+
"exclusiveMinimum",
|
|
40
|
+
"exclusiveMaximum",
|
|
41
|
+
"multipleOf",
|
|
42
|
+
"minLength",
|
|
43
|
+
"maxLength",
|
|
44
|
+
"pattern",
|
|
45
|
+
"minItems",
|
|
46
|
+
"maxItems",
|
|
47
|
+
"uniqueItems",
|
|
48
|
+
"minContains",
|
|
49
|
+
"maxContains",
|
|
50
|
+
"minProperties",
|
|
51
|
+
"maxProperties",
|
|
52
|
+
"patternProperties",
|
|
53
|
+
"propertyNames",
|
|
54
|
+
"dependentRequired",
|
|
55
|
+
"dependentSchemas"
|
|
56
|
+
];
|
|
57
|
+
function isSchemaRecord(value) {
|
|
58
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
59
|
+
}
|
|
60
|
+
function isUnknownArray(value) {
|
|
61
|
+
return Array.isArray(value);
|
|
62
|
+
}
|
|
63
|
+
function cloneSchema(value) {
|
|
64
|
+
return structuredClone(value);
|
|
65
|
+
}
|
|
66
|
+
function localDefName(ref) {
|
|
67
|
+
const prefix = "#/$defs/";
|
|
68
|
+
return ref.startsWith(prefix) ? ref.slice(prefix.length) : null;
|
|
69
|
+
}
|
|
70
|
+
function walkSchema(value, visitor, seen = /* @__PURE__ */ new WeakSet()) {
|
|
71
|
+
if (Array.isArray(value)) {
|
|
72
|
+
if (seen.has(value)) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
seen.add(value);
|
|
76
|
+
for (const item of value) {
|
|
77
|
+
walkSchema(item, visitor, seen);
|
|
78
|
+
}
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (!isSchemaRecord(value)) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (seen.has(value)) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
seen.add(value);
|
|
88
|
+
visitor(value);
|
|
89
|
+
for (const child of Object.values(value)) {
|
|
90
|
+
walkSchema(child, visitor, seen);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function resolveRefs(schema) {
|
|
94
|
+
const defs = isSchemaRecord(schema.$defs) ? schema.$defs : {};
|
|
95
|
+
const schemaCopy = cloneSchema(schema);
|
|
96
|
+
const expanding = /* @__PURE__ */ new Set();
|
|
97
|
+
function resolveNode(node) {
|
|
98
|
+
if (Array.isArray(node)) {
|
|
99
|
+
return node.map((item) => resolveNode(item));
|
|
100
|
+
}
|
|
101
|
+
if (!isSchemaRecord(node)) {
|
|
102
|
+
return node;
|
|
103
|
+
}
|
|
104
|
+
const ref = node.$ref;
|
|
105
|
+
if (typeof ref === "string") {
|
|
106
|
+
const defName = localDefName(ref);
|
|
107
|
+
if (defName) {
|
|
108
|
+
const defSchema = defs[defName];
|
|
109
|
+
if (!isSchemaRecord(defSchema)) {
|
|
110
|
+
throw new Error(`Definition '${defName}' not found in $defs.`);
|
|
111
|
+
}
|
|
112
|
+
if (expanding.has(defName)) {
|
|
113
|
+
const stub = { type: typeof defSchema.type === "string" ? defSchema.type : "object" };
|
|
114
|
+
if (typeof defSchema.description === "string") {
|
|
115
|
+
stub.description = defSchema.description;
|
|
116
|
+
}
|
|
117
|
+
return stub;
|
|
118
|
+
}
|
|
119
|
+
expanding.add(defName);
|
|
120
|
+
try {
|
|
121
|
+
return resolveNode(cloneSchema(defSchema));
|
|
122
|
+
} finally {
|
|
123
|
+
expanding.delete(defName);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return Object.fromEntries(Object.entries(node).map(([key, value]) => [key, resolveNode(value)]));
|
|
128
|
+
}
|
|
129
|
+
return resolveNode(schemaCopy);
|
|
130
|
+
}
|
|
131
|
+
function addKeyInDictRecursively(schema, key, value, criteria) {
|
|
132
|
+
walkSchema(schema, (node) => {
|
|
133
|
+
if (criteria(node) && !(key in node)) {
|
|
134
|
+
node[key] = value;
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
return schema;
|
|
138
|
+
}
|
|
139
|
+
function forceAdditionalPropertiesFalse(schema) {
|
|
140
|
+
walkSchema(schema, (node) => {
|
|
141
|
+
if (node.type === "object") {
|
|
142
|
+
node.additionalProperties = false;
|
|
143
|
+
node.properties ??= {};
|
|
144
|
+
node.required ??= [];
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
return schema;
|
|
148
|
+
}
|
|
149
|
+
function stripUnsupportedFormats(schema) {
|
|
150
|
+
walkSchema(schema, (node) => {
|
|
151
|
+
if (typeof node.format === "string" && !OPENAI_SUPPORTED_FORMATS.has(node.format)) {
|
|
152
|
+
delete node.format;
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
return schema;
|
|
156
|
+
}
|
|
157
|
+
function ensureTypeInSchemas(schema) {
|
|
158
|
+
walkSchema(schema, (node) => {
|
|
159
|
+
for (const key of ["anyOf", "oneOf"]) {
|
|
160
|
+
const variants = node[key];
|
|
161
|
+
if (!isUnknownArray(variants)) {
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
for (let index = 0; index < variants.length; index += 1) {
|
|
165
|
+
const variant = variants[index];
|
|
166
|
+
if (isSchemaRecord(variant) && Object.keys(variant).length === 0) {
|
|
167
|
+
variants[index] = { type: "object" };
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
return schema;
|
|
173
|
+
}
|
|
174
|
+
function fixDiscriminatorMappings(schema) {
|
|
175
|
+
const properties = isSchemaRecord(schema.properties) ? schema.properties : null;
|
|
176
|
+
const output = properties && isSchemaRecord(properties.output) ? properties.output : null;
|
|
177
|
+
const discriminator = output && isSchemaRecord(output.discriminator) ? output.discriminator : null;
|
|
178
|
+
const mapping = discriminator && isSchemaRecord(discriminator.mapping) ? discriminator.mapping : null;
|
|
179
|
+
if (!discriminator || !mapping) {
|
|
180
|
+
return schema;
|
|
181
|
+
}
|
|
182
|
+
discriminator.mapping = Object.fromEntries(
|
|
183
|
+
Object.entries(mapping).map(([key, value]) => [key, typeof value === "string" ? value.split("/").at(-1) : value])
|
|
184
|
+
);
|
|
185
|
+
return schema;
|
|
186
|
+
}
|
|
187
|
+
function addConstToOneOfVariants(schema) {
|
|
188
|
+
const copy = cloneSchema(schema);
|
|
189
|
+
walkSchema(copy, (node) => {
|
|
190
|
+
const variants = node.oneOf;
|
|
191
|
+
const discriminator = isSchemaRecord(node.discriminator) ? node.discriminator : null;
|
|
192
|
+
const mapping = discriminator && isSchemaRecord(discriminator.mapping) ? discriminator.mapping : null;
|
|
193
|
+
const propertyName = discriminator ? discriminator.propertyName : void 0;
|
|
194
|
+
if (!Array.isArray(variants) || typeof propertyName !== "string" || !mapping) {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
for (const variant of variants) {
|
|
198
|
+
if (!isSchemaRecord(variant) || !isSchemaRecord(variant.properties)) {
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
const variantTitle = typeof variant.title === "string" ? variant.title : "";
|
|
202
|
+
const match = Object.entries(mapping).find(([, schemaName]) => {
|
|
203
|
+
return typeof schemaName === "string" && (variantTitle === schemaName || variantTitle.endsWith(schemaName));
|
|
204
|
+
});
|
|
205
|
+
if (!match) {
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
const target = variant.properties[propertyName];
|
|
209
|
+
if (isSchemaRecord(target)) {
|
|
210
|
+
target.const = match[0];
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
return copy;
|
|
215
|
+
}
|
|
216
|
+
function convertOneOfToAnyOf(schema) {
|
|
217
|
+
walkSchema(schema, (node) => {
|
|
218
|
+
if ("oneOf" in node) {
|
|
219
|
+
node.anyOf = node.oneOf;
|
|
220
|
+
delete node.oneOf;
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
return schema;
|
|
224
|
+
}
|
|
225
|
+
function ensureAllPropertiesRequired(schema) {
|
|
226
|
+
walkSchema(schema, (node) => {
|
|
227
|
+
if (node.type === "object" && isSchemaRecord(node.properties) && Object.keys(node.properties).length > 0) {
|
|
228
|
+
node.required = Object.keys(node.properties);
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
return schema;
|
|
232
|
+
}
|
|
233
|
+
function stripNullFromTypes(schema) {
|
|
234
|
+
walkSchema(schema, (node) => {
|
|
235
|
+
const anyOf = node.anyOf;
|
|
236
|
+
if (Array.isArray(anyOf)) {
|
|
237
|
+
const nonNull = anyOf.filter((option) => !isSchemaRecord(option) || option.type !== "null");
|
|
238
|
+
if (nonNull.length === 1 && isSchemaRecord(nonNull[0])) {
|
|
239
|
+
delete node.anyOf;
|
|
240
|
+
Object.assign(node, nonNull[0]);
|
|
241
|
+
} else if (nonNull.length > 1) {
|
|
242
|
+
node.anyOf = nonNull;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
const typeValue = node.type;
|
|
246
|
+
if (Array.isArray(typeValue) && typeValue.includes("null")) {
|
|
247
|
+
const nonNullTypes = typeValue.filter((entry) => entry !== "null");
|
|
248
|
+
if (nonNullTypes.length === 1) {
|
|
249
|
+
node.type = nonNullTypes[0];
|
|
250
|
+
} else if (nonNullTypes.length > 1) {
|
|
251
|
+
node.type = nonNullTypes;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
return schema;
|
|
256
|
+
}
|
|
257
|
+
function stripKeysRecursive(schema, keys) {
|
|
258
|
+
walkSchema(schema, (node) => {
|
|
259
|
+
for (const key of keys) {
|
|
260
|
+
Reflect.deleteProperty(node, key);
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
return schema;
|
|
264
|
+
}
|
|
265
|
+
var _strip_keys_recursive = stripKeysRecursive;
|
|
266
|
+
function liftTopLevelAnyOf(schema) {
|
|
267
|
+
for (const key of ["anyOf", "oneOf", "allOf"]) {
|
|
268
|
+
const variants = schema[key];
|
|
269
|
+
if (!isUnknownArray(variants)) {
|
|
270
|
+
continue;
|
|
271
|
+
}
|
|
272
|
+
const objectVariants = variants.filter((variant) => {
|
|
273
|
+
return isSchemaRecord(variant) && variant.type === "object";
|
|
274
|
+
});
|
|
275
|
+
if (objectVariants.length === 1) {
|
|
276
|
+
Reflect.deleteProperty(schema, key);
|
|
277
|
+
Object.assign(schema, cloneSchema(objectVariants[0]));
|
|
278
|
+
break;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return schema;
|
|
282
|
+
}
|
|
283
|
+
function commonStrictPipeline(params) {
|
|
284
|
+
let sanitized = resolveRefs(cloneSchema(params));
|
|
285
|
+
delete sanitized.$defs;
|
|
286
|
+
sanitized = convertOneOfToAnyOf(sanitized);
|
|
287
|
+
sanitized = ensureTypeInSchemas(sanitized);
|
|
288
|
+
sanitized = forceAdditionalPropertiesFalse(sanitized);
|
|
289
|
+
sanitized = ensureAllPropertiesRequired(sanitized);
|
|
290
|
+
return stripKeysRecursive(sanitized, STRICT_METADATA_KEYS);
|
|
291
|
+
}
|
|
292
|
+
var _common_strict_pipeline = commonStrictPipeline;
|
|
293
|
+
function sanitizeToolParamsForOpenAIStrict(params) {
|
|
294
|
+
if (!isSchemaRecord(params)) {
|
|
295
|
+
return params;
|
|
296
|
+
}
|
|
297
|
+
return stripUnsupportedFormats(commonStrictPipeline(params));
|
|
298
|
+
}
|
|
299
|
+
function sanitizeToolParamsForAnthropicStrict(params) {
|
|
300
|
+
if (!isSchemaRecord(params)) {
|
|
301
|
+
return params;
|
|
302
|
+
}
|
|
303
|
+
let sanitized = liftTopLevelAnyOf(commonStrictPipeline(params));
|
|
304
|
+
sanitized = stripKeysRecursive(sanitized, CLAUDE_STRICT_UNSUPPORTED);
|
|
305
|
+
return stripUnsupportedFormats(sanitized);
|
|
306
|
+
}
|
|
307
|
+
function sanitizeToolParamsForBedrockStrict(params) {
|
|
308
|
+
return sanitizeToolParamsForAnthropicStrict(params);
|
|
309
|
+
}
|
|
310
|
+
function describeValue(value) {
|
|
311
|
+
if (typeof value === "string") {
|
|
312
|
+
return JSON.stringify(value);
|
|
313
|
+
}
|
|
314
|
+
if (typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") {
|
|
315
|
+
return String(value);
|
|
316
|
+
}
|
|
317
|
+
if (value === null) {
|
|
318
|
+
return "null";
|
|
319
|
+
}
|
|
320
|
+
if (typeof value === "undefined") {
|
|
321
|
+
return "undefined";
|
|
322
|
+
}
|
|
323
|
+
if (typeof value === "symbol") {
|
|
324
|
+
return value.toString();
|
|
325
|
+
}
|
|
326
|
+
if (typeof value === "function") {
|
|
327
|
+
return value.name ? `[function ${value.name}]` : "[function]";
|
|
328
|
+
}
|
|
329
|
+
return JSON.stringify(value);
|
|
330
|
+
}
|
|
331
|
+
function buildRichFieldDescription(propSchema) {
|
|
332
|
+
const parts = [];
|
|
333
|
+
if (typeof propSchema.description === "string" && propSchema.description.length > 0) {
|
|
334
|
+
parts.push(propSchema.description);
|
|
335
|
+
}
|
|
336
|
+
if (typeof propSchema.format === "string" && propSchema.format.length > 0) {
|
|
337
|
+
parts.push(`Format: ${propSchema.format}`);
|
|
338
|
+
}
|
|
339
|
+
if (Array.isArray(propSchema.enum) && propSchema.enum.length > 0) {
|
|
340
|
+
parts.push(`Allowed values: [${propSchema.enum.map((value) => describeValue(value)).join(", ")}]`);
|
|
341
|
+
}
|
|
342
|
+
if (typeof propSchema.pattern === "string" && propSchema.pattern.length > 0) {
|
|
343
|
+
parts.push(`Pattern: ${propSchema.pattern}`);
|
|
344
|
+
}
|
|
345
|
+
if (propSchema.minimum !== void 0) {
|
|
346
|
+
parts.push(`Minimum: ${describeValue(propSchema.minimum)}`);
|
|
347
|
+
}
|
|
348
|
+
if (propSchema.maximum !== void 0) {
|
|
349
|
+
parts.push(`Maximum: ${describeValue(propSchema.maximum)}`);
|
|
350
|
+
}
|
|
351
|
+
if (propSchema.minLength !== void 0) {
|
|
352
|
+
parts.push(`Min length: ${describeValue(propSchema.minLength)}`);
|
|
353
|
+
}
|
|
354
|
+
if (propSchema.maxLength !== void 0) {
|
|
355
|
+
parts.push(`Max length: ${describeValue(propSchema.maxLength)}`);
|
|
356
|
+
}
|
|
357
|
+
if (Array.isArray(propSchema.examples) && propSchema.examples.length > 0) {
|
|
358
|
+
parts.push(`Examples: ${propSchema.examples.slice(0, 3).map((value) => describeValue(value)).join(", ")}`);
|
|
359
|
+
}
|
|
360
|
+
return parts.join(". ");
|
|
361
|
+
}
|
|
362
|
+
function _inline_top_level_ref(schema, rootSchema = schema) {
|
|
363
|
+
const copy = cloneSchema(schema);
|
|
364
|
+
const ref = copy.$ref;
|
|
365
|
+
const defName = typeof ref === "string" ? localDefName(ref) : null;
|
|
366
|
+
const defs = isSchemaRecord(copy.$defs) ? copy.$defs : isSchemaRecord(rootSchema.$defs) ? rootSchema.$defs : {};
|
|
367
|
+
const defSchema = defName ? defs[defName] : null;
|
|
368
|
+
if (isSchemaRecord(defSchema)) {
|
|
369
|
+
const resolved = cloneSchema(defSchema);
|
|
370
|
+
resolved.$defs ??= defs;
|
|
371
|
+
return resolved;
|
|
372
|
+
}
|
|
373
|
+
return copy;
|
|
374
|
+
}
|
|
375
|
+
function _process_oneof(schema) {
|
|
376
|
+
return addConstToOneOfVariants(schema);
|
|
377
|
+
}
|
|
378
|
+
function generateModelDescription(name, schema, options = {}) {
|
|
379
|
+
let jsonSchema = forceAdditionalPropertiesFalse(cloneSchema(schema));
|
|
380
|
+
jsonSchema = stripUnsupportedFormats(jsonSchema);
|
|
381
|
+
jsonSchema = ensureTypeInSchemas(jsonSchema);
|
|
382
|
+
jsonSchema = resolveRefs(jsonSchema);
|
|
383
|
+
delete jsonSchema.$defs;
|
|
384
|
+
jsonSchema = fixDiscriminatorMappings(jsonSchema);
|
|
385
|
+
jsonSchema = convertOneOfToAnyOf(jsonSchema);
|
|
386
|
+
jsonSchema = ensureAllPropertiesRequired(jsonSchema);
|
|
387
|
+
if (options.stripNullTypes ?? true) {
|
|
388
|
+
jsonSchema = stripNullFromTypes(jsonSchema);
|
|
389
|
+
}
|
|
390
|
+
return {
|
|
391
|
+
type: "json_schema",
|
|
392
|
+
json_schema: {
|
|
393
|
+
name,
|
|
394
|
+
strict: true,
|
|
395
|
+
schema: jsonSchema
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
var resolve_refs = resolveRefs;
|
|
400
|
+
var add_key_in_dict_recursively = addKeyInDictRecursively;
|
|
401
|
+
var force_additional_properties_false = forceAdditionalPropertiesFalse;
|
|
402
|
+
var strip_unsupported_formats = stripUnsupportedFormats;
|
|
403
|
+
var ensure_type_in_schemas = ensureTypeInSchemas;
|
|
404
|
+
var fix_discriminator_mappings = fixDiscriminatorMappings;
|
|
405
|
+
var add_const_to_oneof_variants = addConstToOneOfVariants;
|
|
406
|
+
var convert_oneof_to_anyof = convertOneOfToAnyOf;
|
|
407
|
+
var ensure_all_properties_required = ensureAllPropertiesRequired;
|
|
408
|
+
var strip_null_from_types = stripNullFromTypes;
|
|
409
|
+
var lift_top_level_anyof = liftTopLevelAnyOf;
|
|
410
|
+
var sanitize_tool_params_for_openai_strict = sanitizeToolParamsForOpenAIStrict;
|
|
411
|
+
var sanitize_tool_params_for_anthropic_strict = sanitizeToolParamsForAnthropicStrict;
|
|
412
|
+
var sanitize_tool_params_for_bedrock_strict = sanitizeToolParamsForBedrockStrict;
|
|
413
|
+
var build_rich_field_description = buildRichFieldDescription;
|
|
414
|
+
var generate_model_description = generateModelDescription;
|
|
415
|
+
function serializeModelClass(model) {
|
|
416
|
+
if (typeof model === "function") {
|
|
417
|
+
return { title: model.name || "Model", type: "object" };
|
|
418
|
+
}
|
|
419
|
+
if (model && typeof model === "object" && "schema" in model) {
|
|
420
|
+
const schema = model.schema;
|
|
421
|
+
return schema && typeof schema === "object" && !Array.isArray(schema) ? schema : {};
|
|
422
|
+
}
|
|
423
|
+
return {};
|
|
424
|
+
}
|
|
425
|
+
var serialize_model_class = serializeModelClass;
|
|
426
|
+
function coerceCreateModelOptions(value) {
|
|
427
|
+
if (!isSchemaRecord(value)) {
|
|
428
|
+
return {};
|
|
429
|
+
}
|
|
430
|
+
const options = {};
|
|
431
|
+
if (isSchemaRecord(value.rootSchema)) {
|
|
432
|
+
options.rootSchema = value.rootSchema;
|
|
433
|
+
}
|
|
434
|
+
if (isSchemaRecord(value.root_schema)) {
|
|
435
|
+
options.root_schema = value.root_schema;
|
|
436
|
+
}
|
|
437
|
+
if (typeof value.modelName === "string") {
|
|
438
|
+
options.modelName = value.modelName;
|
|
439
|
+
}
|
|
440
|
+
if (typeof value.model_name === "string") {
|
|
441
|
+
options.model_name = value.model_name;
|
|
442
|
+
}
|
|
443
|
+
if (typeof value.enrichDescriptions === "boolean") {
|
|
444
|
+
options.enrichDescriptions = value.enrichDescriptions;
|
|
445
|
+
}
|
|
446
|
+
if (typeof value.enrich_descriptions === "boolean") {
|
|
447
|
+
options.enrich_descriptions = value.enrich_descriptions;
|
|
448
|
+
}
|
|
449
|
+
return options;
|
|
450
|
+
}
|
|
451
|
+
function createValidationError(path, message) {
|
|
452
|
+
return new Error(`${path}: ${message}`);
|
|
453
|
+
}
|
|
454
|
+
function schemaTypeMatches(schema, expected) {
|
|
455
|
+
return schema.type === expected || Array.isArray(schema.type) && schema.type.includes(expected);
|
|
456
|
+
}
|
|
457
|
+
function numericConstraint(schema, key) {
|
|
458
|
+
const value = schema[key];
|
|
459
|
+
return typeof value === "number" && !Number.isNaN(value) ? value : null;
|
|
460
|
+
}
|
|
461
|
+
function isValidDateString(value) {
|
|
462
|
+
const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value);
|
|
463
|
+
if (!match) {
|
|
464
|
+
return false;
|
|
465
|
+
}
|
|
466
|
+
const year = Number(match[1]);
|
|
467
|
+
const month = Number(match[2]);
|
|
468
|
+
const day = Number(match[3]);
|
|
469
|
+
const date = new Date(Date.UTC(year, month - 1, day));
|
|
470
|
+
return date.getUTCFullYear() === year && date.getUTCMonth() === month - 1 && date.getUTCDate() === day;
|
|
471
|
+
}
|
|
472
|
+
function dateFromDateString(value) {
|
|
473
|
+
const [year, month, day] = value.split("-").map((part) => Number(part));
|
|
474
|
+
return new Date(Date.UTC(year ?? 0, (month ?? 1) - 1, day ?? 1));
|
|
475
|
+
}
|
|
476
|
+
function isValidTimeString(value) {
|
|
477
|
+
const match = /^(\d{2}):(\d{2})(?::(\d{2})(?:\.\d+)?)?$/.exec(value);
|
|
478
|
+
if (!match) {
|
|
479
|
+
return false;
|
|
480
|
+
}
|
|
481
|
+
const hour = Number(match[1]);
|
|
482
|
+
const minute = Number(match[2]);
|
|
483
|
+
const second = match[3] === void 0 ? 0 : Number(match[3]);
|
|
484
|
+
return hour >= 0 && hour <= 23 && minute >= 0 && minute <= 59 && second >= 0 && second <= 59;
|
|
485
|
+
}
|
|
486
|
+
function assertStringFormat(schema, value, path) {
|
|
487
|
+
if (schema.format === "date" && !isValidDateString(value)) {
|
|
488
|
+
throw createValidationError(path, "format date");
|
|
489
|
+
}
|
|
490
|
+
if (schema.format === "date-time" && Number.isNaN(Date.parse(value))) {
|
|
491
|
+
throw createValidationError(path, "format date-time");
|
|
492
|
+
}
|
|
493
|
+
if (schema.format === "time" && !isValidTimeString(value)) {
|
|
494
|
+
throw createValidationError(path, "format time");
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
function coerceFormattedString(schema, value) {
|
|
498
|
+
if (schema.format === "date") {
|
|
499
|
+
return dateFromDateString(value);
|
|
500
|
+
}
|
|
501
|
+
if (schema.format === "date-time") {
|
|
502
|
+
return new Date(value);
|
|
503
|
+
}
|
|
504
|
+
return value;
|
|
505
|
+
}
|
|
506
|
+
function isDateFormatSchema(schema) {
|
|
507
|
+
return schema.format === "date" || schema.format === "date-time";
|
|
508
|
+
}
|
|
509
|
+
function assertStringConstraints(schema, value, path) {
|
|
510
|
+
assertStringFormat(schema, value, path);
|
|
511
|
+
const minLength = numericConstraint(schema, "minLength");
|
|
512
|
+
if (minLength !== null && value.length < minLength) {
|
|
513
|
+
throw createValidationError(path, `minLength ${String(minLength)}`);
|
|
514
|
+
}
|
|
515
|
+
const maxLength = numericConstraint(schema, "maxLength");
|
|
516
|
+
if (maxLength !== null && value.length > maxLength) {
|
|
517
|
+
throw createValidationError(path, `maxLength ${String(maxLength)}`);
|
|
518
|
+
}
|
|
519
|
+
if (typeof schema.pattern === "string" && !new RegExp(schema.pattern).test(value)) {
|
|
520
|
+
throw createValidationError(path, `pattern ${schema.pattern}`);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
function assertNumberConstraints(schema, value, path) {
|
|
524
|
+
const minimum = numericConstraint(schema, "minimum");
|
|
525
|
+
if (minimum !== null && value < minimum) {
|
|
526
|
+
throw createValidationError(path, `minimum ${String(minimum)}`);
|
|
527
|
+
}
|
|
528
|
+
const exclusiveMinimum = numericConstraint(schema, "exclusiveMinimum");
|
|
529
|
+
if (exclusiveMinimum !== null && value <= exclusiveMinimum) {
|
|
530
|
+
throw createValidationError(path, `exclusiveMinimum ${String(exclusiveMinimum)}`);
|
|
531
|
+
}
|
|
532
|
+
const maximum = numericConstraint(schema, "maximum");
|
|
533
|
+
if (maximum !== null && value > maximum) {
|
|
534
|
+
throw createValidationError(path, `maximum ${String(maximum)}`);
|
|
535
|
+
}
|
|
536
|
+
const exclusiveMaximum = numericConstraint(schema, "exclusiveMaximum");
|
|
537
|
+
if (exclusiveMaximum !== null && value >= exclusiveMaximum) {
|
|
538
|
+
throw createValidationError(path, `exclusiveMaximum ${String(exclusiveMaximum)}`);
|
|
539
|
+
}
|
|
540
|
+
const multipleOf = numericConstraint(schema, "multipleOf");
|
|
541
|
+
if (multipleOf !== null && multipleOf !== 0 && Math.abs(value / multipleOf - Math.round(value / multipleOf)) > Number.EPSILON) {
|
|
542
|
+
throw createValidationError(path, `multipleOf ${String(multipleOf)}`);
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
function effectiveSchema(schema, rootSchema) {
|
|
546
|
+
if (typeof schema.$ref === "string") {
|
|
547
|
+
const resolved = _resolve_ref(schema.$ref, rootSchema);
|
|
548
|
+
if (isSchemaRecord(schema.$defs) && !("$defs" in resolved)) {
|
|
549
|
+
resolved.$defs = schema.$defs;
|
|
550
|
+
}
|
|
551
|
+
return resolved;
|
|
552
|
+
}
|
|
553
|
+
if (Array.isArray(schema.allOf)) {
|
|
554
|
+
return _merge_all_of_schemas(schema.allOf.filter(isSchemaRecord), rootSchema);
|
|
555
|
+
}
|
|
556
|
+
return schema;
|
|
557
|
+
}
|
|
558
|
+
var SUPPORTED_SCHEMA_TYPES = /* @__PURE__ */ new Set(["null", "string", "integer", "number", "boolean", "array", "object"]);
|
|
559
|
+
function validateSupportedSchemaTypes(schema, rootSchema, seen = /* @__PURE__ */ new WeakSet(), seenRefs = /* @__PURE__ */ new Set()) {
|
|
560
|
+
if (seen.has(schema)) {
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
seen.add(schema);
|
|
564
|
+
if (typeof schema.$ref === "string") {
|
|
565
|
+
if (seenRefs.has(schema.$ref)) {
|
|
566
|
+
return;
|
|
567
|
+
}
|
|
568
|
+
const nextSeenRefs = new Set(seenRefs);
|
|
569
|
+
nextSeenRefs.add(schema.$ref);
|
|
570
|
+
validateSupportedSchemaTypes(_resolve_ref(schema.$ref, rootSchema), rootSchema, seen, nextSeenRefs);
|
|
571
|
+
return;
|
|
572
|
+
}
|
|
573
|
+
const resolved = effectiveSchema(schema, rootSchema);
|
|
574
|
+
if (resolved !== schema) {
|
|
575
|
+
validateSupportedSchemaTypes(resolved, rootSchema, seen, seenRefs);
|
|
576
|
+
return;
|
|
577
|
+
}
|
|
578
|
+
const typeValue = resolved.type;
|
|
579
|
+
if (typeof typeValue === "string" && !SUPPORTED_SCHEMA_TYPES.has(typeValue)) {
|
|
580
|
+
throw new Error(`Unsupported JSON schema type: ${typeValue} from ${JSON.stringify(resolved)}`);
|
|
581
|
+
}
|
|
582
|
+
if (Array.isArray(typeValue)) {
|
|
583
|
+
for (const entry of typeValue) {
|
|
584
|
+
if (typeof entry === "string" && !SUPPORTED_SCHEMA_TYPES.has(entry)) {
|
|
585
|
+
throw new Error(`Unsupported JSON schema type: ${entry} from ${JSON.stringify(resolved)}`);
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
for (const key of ["anyOf", "oneOf", "allOf"]) {
|
|
590
|
+
const variants = resolved[key];
|
|
591
|
+
if (!Array.isArray(variants)) {
|
|
592
|
+
continue;
|
|
593
|
+
}
|
|
594
|
+
for (const variant of variants) {
|
|
595
|
+
if (isSchemaRecord(variant)) {
|
|
596
|
+
validateSupportedSchemaTypes(variant, rootSchema, seen, seenRefs);
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
if (isSchemaRecord(resolved.items)) {
|
|
601
|
+
validateSupportedSchemaTypes(resolved.items, rootSchema, seen, seenRefs);
|
|
602
|
+
}
|
|
603
|
+
if (isSchemaRecord(resolved.properties)) {
|
|
604
|
+
for (const value of Object.values(resolved.properties)) {
|
|
605
|
+
if (isSchemaRecord(value)) {
|
|
606
|
+
validateSupportedSchemaTypes(value, rootSchema, seen, seenRefs);
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
function validateSchemaValue(schema, value, path, rootSchema, seen = /* @__PURE__ */ new Set()) {
|
|
612
|
+
const resolved = effectiveSchema(schema, rootSchema);
|
|
613
|
+
if (seen.has(resolved)) {
|
|
614
|
+
return value;
|
|
615
|
+
}
|
|
616
|
+
const nextSeen = new Set(seen);
|
|
617
|
+
nextSeen.add(resolved);
|
|
618
|
+
const variants = Array.isArray(resolved.anyOf) ? resolved.anyOf : Array.isArray(resolved.oneOf) ? resolved.oneOf : null;
|
|
619
|
+
if (variants) {
|
|
620
|
+
const errors = [];
|
|
621
|
+
for (const variant of variants) {
|
|
622
|
+
if (!isSchemaRecord(variant)) {
|
|
623
|
+
continue;
|
|
624
|
+
}
|
|
625
|
+
try {
|
|
626
|
+
return validateSchemaValue(variant, value, path, rootSchema, nextSeen);
|
|
627
|
+
} catch (error) {
|
|
628
|
+
errors.push(error instanceof Error ? error.message : String(error));
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
throw createValidationError(path, `value did not match any schema${errors.length > 0 ? ` (${errors.join("; ")})` : ""}`);
|
|
632
|
+
}
|
|
633
|
+
if ("const" in resolved && value !== resolved.const) {
|
|
634
|
+
throw createValidationError(path, `expected const ${describeValue(resolved.const)}`);
|
|
635
|
+
}
|
|
636
|
+
if (Array.isArray(resolved.enum) && !resolved.enum.includes(value)) {
|
|
637
|
+
throw createValidationError(path, `expected one of ${resolved.enum.map((entry) => describeValue(entry)).join(", ")}`);
|
|
638
|
+
}
|
|
639
|
+
const typeValue = resolved.type;
|
|
640
|
+
if (Array.isArray(typeValue)) {
|
|
641
|
+
const errors = [];
|
|
642
|
+
for (const type of typeValue) {
|
|
643
|
+
if (typeof type !== "string") {
|
|
644
|
+
continue;
|
|
645
|
+
}
|
|
646
|
+
try {
|
|
647
|
+
return validateSchemaValue({ ...resolved, type }, value, path, rootSchema, nextSeen);
|
|
648
|
+
} catch (error) {
|
|
649
|
+
errors.push(error instanceof Error ? error.message : String(error));
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
throw createValidationError(path, `value did not match any declared type${errors.length > 0 ? ` (${errors.join("; ")})` : ""}`);
|
|
653
|
+
}
|
|
654
|
+
switch (typeValue) {
|
|
655
|
+
case void 0:
|
|
656
|
+
return value;
|
|
657
|
+
case "null":
|
|
658
|
+
if (value !== null) {
|
|
659
|
+
throw createValidationError(path, "expected null");
|
|
660
|
+
}
|
|
661
|
+
return null;
|
|
662
|
+
case "string":
|
|
663
|
+
if (value instanceof Date && isDateFormatSchema(resolved)) {
|
|
664
|
+
if (Number.isNaN(value.getTime())) {
|
|
665
|
+
throw createValidationError(path, `format ${String(resolved.format)}`);
|
|
666
|
+
}
|
|
667
|
+
return value;
|
|
668
|
+
}
|
|
669
|
+
if (typeof value !== "string") {
|
|
670
|
+
throw createValidationError(path, "expected string");
|
|
671
|
+
}
|
|
672
|
+
assertStringConstraints(resolved, value, path);
|
|
673
|
+
return coerceFormattedString(resolved, value);
|
|
674
|
+
case "integer":
|
|
675
|
+
if (typeof value !== "number" || !Number.isInteger(value)) {
|
|
676
|
+
throw createValidationError(path, "expected integer");
|
|
677
|
+
}
|
|
678
|
+
assertNumberConstraints(resolved, value, path);
|
|
679
|
+
return value;
|
|
680
|
+
case "number":
|
|
681
|
+
if (typeof value !== "number" || Number.isNaN(value)) {
|
|
682
|
+
throw createValidationError(path, "expected number");
|
|
683
|
+
}
|
|
684
|
+
assertNumberConstraints(resolved, value, path);
|
|
685
|
+
return value;
|
|
686
|
+
case "boolean":
|
|
687
|
+
if (typeof value !== "boolean") {
|
|
688
|
+
throw createValidationError(path, "expected boolean");
|
|
689
|
+
}
|
|
690
|
+
return value;
|
|
691
|
+
case "array": {
|
|
692
|
+
if (!Array.isArray(value)) {
|
|
693
|
+
throw createValidationError(path, "expected array");
|
|
694
|
+
}
|
|
695
|
+
const itemSchema = isSchemaRecord(resolved.items) ? resolved.items : null;
|
|
696
|
+
const items = value;
|
|
697
|
+
return itemSchema ? items.map((item, index) => validateSchemaValue(itemSchema, item, `${path}.${String(index)}`, rootSchema, nextSeen)) : items.slice();
|
|
698
|
+
}
|
|
699
|
+
case "object": {
|
|
700
|
+
if (!isSchemaRecord(value)) {
|
|
701
|
+
throw createValidationError(path, "expected object");
|
|
702
|
+
}
|
|
703
|
+
const properties = isSchemaRecord(resolved.properties) ? resolved.properties : null;
|
|
704
|
+
if (!properties) {
|
|
705
|
+
return { ...value };
|
|
706
|
+
}
|
|
707
|
+
if (resolved.additionalProperties === false) {
|
|
708
|
+
for (const key of Object.keys(value)) {
|
|
709
|
+
if (!(key in properties)) {
|
|
710
|
+
throw createValidationError(`${path}.${key}`, "extra field not permitted");
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
const required = Array.isArray(resolved.required) ? resolved.required.filter((entry) => typeof entry === "string") : [];
|
|
715
|
+
const output = {};
|
|
716
|
+
for (const [propertyName, propertySchema] of Object.entries(properties)) {
|
|
717
|
+
if (!isSchemaRecord(propertySchema)) {
|
|
718
|
+
continue;
|
|
719
|
+
}
|
|
720
|
+
if (!(propertyName in value)) {
|
|
721
|
+
if (required.includes(propertyName)) {
|
|
722
|
+
throw createValidationError(`${path}.${propertyName}`, "field required");
|
|
723
|
+
}
|
|
724
|
+
output[propertyName] = null;
|
|
725
|
+
continue;
|
|
726
|
+
}
|
|
727
|
+
output[propertyName] = validateSchemaValue(propertySchema, value[propertyName], `${path}.${propertyName}`, rootSchema, nextSeen);
|
|
728
|
+
}
|
|
729
|
+
return output;
|
|
730
|
+
}
|
|
731
|
+
default:
|
|
732
|
+
throw new Error(`Unsupported JSON schema type: ${String(typeValue)}`);
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
function buildModelFields(schema, rootSchema, enrichDescriptions) {
|
|
736
|
+
const properties = isSchemaRecord(schema.properties) ? schema.properties : {};
|
|
737
|
+
const required = Array.isArray(schema.required) ? schema.required.filter((entry) => typeof entry === "string") : [];
|
|
738
|
+
const fields = {};
|
|
739
|
+
for (const [name, propertySchema] of Object.entries(properties)) {
|
|
740
|
+
if (!isSchemaRecord(propertySchema)) {
|
|
741
|
+
continue;
|
|
742
|
+
}
|
|
743
|
+
const resolved = effectiveSchema(propertySchema, rootSchema);
|
|
744
|
+
const description = enrichDescriptions ? buildRichFieldDescription(resolved) : typeof resolved.description === "string" ? resolved.description : null;
|
|
745
|
+
const field = {
|
|
746
|
+
name,
|
|
747
|
+
required: required.includes(name),
|
|
748
|
+
description,
|
|
749
|
+
schema: resolved
|
|
750
|
+
};
|
|
751
|
+
if (typeof propertySchema.$ref !== "string" && schemaTypeMatches(resolved, "object") && isSchemaRecord(resolved.properties)) {
|
|
752
|
+
field.annotation = createModelFromSchema(resolved, {
|
|
753
|
+
rootSchema,
|
|
754
|
+
modelName: typeof resolved.title === "string" ? resolved.title : `${name[0]?.toUpperCase() ?? "Nested"}${name.slice(1)}`,
|
|
755
|
+
enrichDescriptions
|
|
756
|
+
});
|
|
757
|
+
}
|
|
758
|
+
fields[name] = field;
|
|
759
|
+
}
|
|
760
|
+
return fields;
|
|
761
|
+
}
|
|
762
|
+
function createModelFromSchema(schemaOrName, schemaOrOptions = {}, maybeOptions = {}) {
|
|
763
|
+
let schema;
|
|
764
|
+
let options;
|
|
765
|
+
let explicitModelName;
|
|
766
|
+
if (typeof schemaOrName === "string") {
|
|
767
|
+
explicitModelName = schemaOrName;
|
|
768
|
+
schema = isSchemaRecord(schemaOrOptions) ? schemaOrOptions : {};
|
|
769
|
+
options = maybeOptions;
|
|
770
|
+
} else {
|
|
771
|
+
explicitModelName = null;
|
|
772
|
+
schema = schemaOrName;
|
|
773
|
+
options = coerceCreateModelOptions(schemaOrOptions);
|
|
774
|
+
}
|
|
775
|
+
const modelName = explicitModelName ?? options.modelName ?? options.model_name ?? (typeof schema.title === "string" ? schema.title : "DynamicModel");
|
|
776
|
+
const enrichDescriptions = options.enrichDescriptions ?? options.enrich_descriptions ?? false;
|
|
777
|
+
const rootSchema = forceAdditionalPropertiesFalse(cloneSchema(options.rootSchema ?? options.root_schema ?? schema));
|
|
778
|
+
const resolvedSchema = forceAdditionalPropertiesFalse(_inline_top_level_ref(cloneSchema(schema), rootSchema));
|
|
779
|
+
const normalizedSchema = Array.isArray(resolvedSchema.allOf) ? _merge_all_of_schemas(resolvedSchema.allOf.filter(isSchemaRecord), resolvedSchema) : resolvedSchema;
|
|
780
|
+
const effectiveRoot = isSchemaRecord(normalizedSchema.$defs) ? normalizedSchema : rootSchema;
|
|
781
|
+
validateSupportedSchemaTypes(normalizedSchema, effectiveRoot);
|
|
782
|
+
const modelFields = buildModelFields(normalizedSchema, effectiveRoot, enrichDescriptions);
|
|
783
|
+
return {
|
|
784
|
+
name: modelName,
|
|
785
|
+
__name__: modelName,
|
|
786
|
+
schema: normalizedSchema,
|
|
787
|
+
model_fields: modelFields,
|
|
788
|
+
modelFields,
|
|
789
|
+
modelValidate(value) {
|
|
790
|
+
return validateSchemaValue(normalizedSchema, value, modelName, effectiveRoot);
|
|
791
|
+
},
|
|
792
|
+
model_validate(value) {
|
|
793
|
+
return this.modelValidate(value);
|
|
794
|
+
}
|
|
795
|
+
};
|
|
796
|
+
}
|
|
797
|
+
var create_model_from_schema = createModelFromSchema;
|
|
798
|
+
function _resolve_ref(ref, rootSchema) {
|
|
799
|
+
const defName = localDefName(ref);
|
|
800
|
+
const defs = isSchemaRecord(rootSchema.$defs) ? rootSchema.$defs : {};
|
|
801
|
+
const defSchema = defName ? defs[defName] : null;
|
|
802
|
+
if (!isSchemaRecord(defSchema)) {
|
|
803
|
+
throw new Error(`Definition '${defName ?? ref}' not found in $defs.`);
|
|
804
|
+
}
|
|
805
|
+
return cloneSchema(defSchema);
|
|
806
|
+
}
|
|
807
|
+
function _merge_all_of_schemas(schemas, rootSchema = {}) {
|
|
808
|
+
const merged = { type: "object", properties: {}, required: [] };
|
|
809
|
+
const requiredValues = (value) => Array.isArray(value) ? value.filter((entry) => typeof entry === "string") : [];
|
|
810
|
+
for (const schema of schemas) {
|
|
811
|
+
const resolved = typeof schema.$ref === "string" ? _resolve_ref(schema.$ref, rootSchema) : schema;
|
|
812
|
+
Object.assign(merged, cloneSchema(resolved), {
|
|
813
|
+
properties: {
|
|
814
|
+
...isSchemaRecord(merged.properties) ? merged.properties : {},
|
|
815
|
+
...isSchemaRecord(resolved.properties) ? resolved.properties : {}
|
|
816
|
+
},
|
|
817
|
+
required: [...requiredValues(merged.required), ...requiredValues(resolved.required)]
|
|
818
|
+
});
|
|
819
|
+
}
|
|
820
|
+
merged.required = [...new Set(requiredValues(merged.required))];
|
|
821
|
+
return merged;
|
|
822
|
+
}
|
|
823
|
+
function _json_schema_to_pydantic_type(schema) {
|
|
824
|
+
const typeValue = schema.type;
|
|
825
|
+
if (typeof typeValue === "string") {
|
|
826
|
+
return typeValue;
|
|
827
|
+
}
|
|
828
|
+
if (Array.isArray(typeValue)) {
|
|
829
|
+
return typeValue.filter((entry) => typeof entry === "string").join(" | ") || "unknown";
|
|
830
|
+
}
|
|
831
|
+
return "unknown";
|
|
832
|
+
}
|
|
833
|
+
function _json_schema_to_pydantic_field(name, schema, required = []) {
|
|
834
|
+
return {
|
|
835
|
+
name,
|
|
836
|
+
type: _json_schema_to_pydantic_type(schema),
|
|
837
|
+
required: required.includes(name),
|
|
838
|
+
schema
|
|
839
|
+
};
|
|
840
|
+
}
|
|
841
|
+
function _build_model_from_schema(schema, _effectiveRoot = schema, options = {}) {
|
|
842
|
+
void _effectiveRoot;
|
|
843
|
+
return createModelFromSchema(options.model_name ?? (typeof schema.title === "string" ? schema.title : "DynamicModel"), schema);
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
export {
|
|
847
|
+
JsonSchemaInfo,
|
|
848
|
+
ModelDescription,
|
|
849
|
+
FORMAT_TYPE_MAP,
|
|
850
|
+
OPENAI_SUPPORTED_FORMATS,
|
|
851
|
+
resolveRefs,
|
|
852
|
+
addKeyInDictRecursively,
|
|
853
|
+
forceAdditionalPropertiesFalse,
|
|
854
|
+
stripUnsupportedFormats,
|
|
855
|
+
ensureTypeInSchemas,
|
|
856
|
+
fixDiscriminatorMappings,
|
|
857
|
+
addConstToOneOfVariants,
|
|
858
|
+
convertOneOfToAnyOf,
|
|
859
|
+
ensureAllPropertiesRequired,
|
|
860
|
+
stripNullFromTypes,
|
|
861
|
+
_strip_keys_recursive,
|
|
862
|
+
liftTopLevelAnyOf,
|
|
863
|
+
_common_strict_pipeline,
|
|
864
|
+
sanitizeToolParamsForOpenAIStrict,
|
|
865
|
+
sanitizeToolParamsForAnthropicStrict,
|
|
866
|
+
sanitizeToolParamsForBedrockStrict,
|
|
867
|
+
buildRichFieldDescription,
|
|
868
|
+
_inline_top_level_ref,
|
|
869
|
+
_process_oneof,
|
|
870
|
+
generateModelDescription,
|
|
871
|
+
resolve_refs,
|
|
872
|
+
add_key_in_dict_recursively,
|
|
873
|
+
force_additional_properties_false,
|
|
874
|
+
strip_unsupported_formats,
|
|
875
|
+
ensure_type_in_schemas,
|
|
876
|
+
fix_discriminator_mappings,
|
|
877
|
+
add_const_to_oneof_variants,
|
|
878
|
+
convert_oneof_to_anyof,
|
|
879
|
+
ensure_all_properties_required,
|
|
880
|
+
strip_null_from_types,
|
|
881
|
+
lift_top_level_anyof,
|
|
882
|
+
sanitize_tool_params_for_openai_strict,
|
|
883
|
+
sanitize_tool_params_for_anthropic_strict,
|
|
884
|
+
sanitize_tool_params_for_bedrock_strict,
|
|
885
|
+
build_rich_field_description,
|
|
886
|
+
generate_model_description,
|
|
887
|
+
serializeModelClass,
|
|
888
|
+
serialize_model_class,
|
|
889
|
+
createModelFromSchema,
|
|
890
|
+
create_model_from_schema,
|
|
891
|
+
_resolve_ref,
|
|
892
|
+
_merge_all_of_schemas,
|
|
893
|
+
_json_schema_to_pydantic_type,
|
|
894
|
+
_json_schema_to_pydantic_field,
|
|
895
|
+
_build_model_from_schema
|
|
896
|
+
};
|