@contractspec/lib.ai-agent 1.57.0 → 1.59.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/agent-factory.d.ts +67 -71
- package/dist/agent/agent-factory.d.ts.map +1 -1
- package/dist/agent/agent-factory.js +658 -100
- package/dist/agent/agent.test.d.ts +2 -0
- package/dist/agent/agent.test.d.ts.map +1 -0
- package/dist/agent/contract-spec-agent.d.ts +48 -52
- package/dist/agent/contract-spec-agent.d.ts.map +1 -1
- package/dist/agent/contract-spec-agent.js +605 -146
- package/dist/agent/index.d.ts +4 -4
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/index.js +2102 -4
- package/dist/agent/json-runner.d.ts +15 -19
- package/dist/agent/json-runner.d.ts.map +1 -1
- package/dist/agent/json-runner.js +672 -57
- package/dist/agent/json-runner.test.d.ts +2 -0
- package/dist/agent/json-runner.test.d.ts.map +1 -0
- package/dist/agent/unified-agent.d.ts +132 -109
- package/dist/agent/unified-agent.d.ts.map +1 -1
- package/dist/agent/unified-agent.js +2011 -293
- package/dist/approval/index.d.ts +3 -2
- package/dist/approval/index.d.ts.map +1 -0
- package/dist/approval/index.js +128 -2
- package/dist/approval/workflow.d.ts +106 -110
- package/dist/approval/workflow.d.ts.map +1 -1
- package/dist/approval/workflow.js +126 -157
- package/dist/exporters/claude-agent-exporter.d.ts +50 -48
- package/dist/exporters/claude-agent-exporter.d.ts.map +1 -1
- package/dist/exporters/claude-agent-exporter.js +258 -203
- package/dist/exporters/index.d.ts +28 -4
- package/dist/exporters/index.d.ts.map +1 -0
- package/dist/exporters/index.js +737 -3
- package/dist/exporters/opencode-exporter.d.ts +47 -45
- package/dist/exporters/opencode-exporter.d.ts.map +1 -1
- package/dist/exporters/opencode-exporter.js +507 -191
- package/dist/exporters/types.d.ts +171 -169
- package/dist/exporters/types.d.ts.map +1 -1
- package/dist/exporters/types.js +1 -0
- package/dist/index.d.ts +15 -39
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3337 -32
- package/dist/interop/index.d.ts +48 -4
- package/dist/interop/index.d.ts.map +1 -0
- package/dist/interop/index.js +709 -3
- package/dist/interop/spec-consumer.d.ts +57 -53
- package/dist/interop/spec-consumer.d.ts.map +1 -1
- package/dist/interop/spec-consumer.js +302 -282
- package/dist/interop/tool-consumer.d.ts +57 -53
- package/dist/interop/tool-consumer.d.ts.map +1 -1
- package/dist/interop/tool-consumer.js +412 -213
- package/dist/interop/types.d.ts +173 -171
- package/dist/interop/types.d.ts.map +1 -1
- package/dist/interop/types.js +1 -0
- package/dist/knowledge/index.d.ts +2 -2
- package/dist/knowledge/index.d.ts.map +1 -0
- package/dist/knowledge/index.js +66 -2
- package/dist/knowledge/injector.d.ts +16 -20
- package/dist/knowledge/injector.d.ts.map +1 -1
- package/dist/knowledge/injector.js +56 -47
- package/dist/memory/in-memory.d.ts +15 -19
- package/dist/memory/in-memory.d.ts.map +1 -1
- package/dist/memory/in-memory.js +152 -46
- package/dist/memory/index.d.ts +3 -3
- package/dist/memory/index.d.ts.map +1 -0
- package/dist/memory/index.js +155 -3
- package/dist/memory/manager.d.ts +32 -36
- package/dist/memory/manager.d.ts.map +1 -1
- package/dist/memory/manager.js +96 -70
- package/dist/memory/memory.test.d.ts +2 -0
- package/dist/memory/memory.test.d.ts.map +1 -0
- package/dist/node/agent/agent-factory.js +661 -0
- package/dist/node/agent/contract-spec-agent.js +607 -0
- package/dist/node/agent/index.js +2103 -0
- package/dist/node/agent/json-runner.js +684 -0
- package/dist/node/agent/unified-agent.js +2019 -0
- package/dist/node/approval/index.js +129 -0
- package/dist/node/approval/workflow.js +129 -0
- package/dist/node/exporters/claude-agent-exporter.js +265 -0
- package/dist/node/exporters/index.js +738 -0
- package/dist/node/exporters/opencode-exporter.js +516 -0
- package/dist/node/exporters/types.js +0 -0
- package/dist/node/index.js +3337 -0
- package/dist/node/interop/index.js +710 -0
- package/dist/node/interop/spec-consumer.js +307 -0
- package/dist/node/interop/tool-consumer.js +419 -0
- package/dist/node/interop/types.js +0 -0
- package/dist/node/knowledge/index.js +67 -0
- package/dist/node/knowledge/injector.js +67 -0
- package/dist/node/memory/in-memory.js +154 -0
- package/dist/node/memory/index.js +156 -0
- package/dist/node/memory/manager.js +105 -0
- package/dist/node/providers/claude-agent-sdk/adapter.js +624 -0
- package/dist/node/providers/claude-agent-sdk/index.js +673 -0
- package/dist/node/providers/claude-agent-sdk/session-bridge.js +149 -0
- package/dist/node/providers/claude-agent-sdk/tool-bridge.js +118 -0
- package/dist/node/providers/index.js +1261 -0
- package/dist/node/providers/opencode-sdk/adapter.js +669 -0
- package/dist/node/providers/opencode-sdk/agent-bridge.js +299 -0
- package/dist/node/providers/opencode-sdk/index.js +703 -0
- package/dist/node/providers/opencode-sdk/tool-bridge.js +141 -0
- package/dist/node/providers/registry.js +89 -0
- package/dist/node/providers/types.js +56 -0
- package/dist/node/schema/index.js +195 -0
- package/dist/node/schema/json-schema-to-zod.js +152 -0
- package/dist/node/schema/schema-output.js +190 -0
- package/dist/node/session/index.js +90 -0
- package/dist/node/session/store.js +90 -0
- package/dist/node/spec/index.js +85 -0
- package/dist/node/spec/registry.js +56 -0
- package/dist/node/spec/spec.js +44 -0
- package/dist/node/telemetry/adapter.js +85 -0
- package/dist/node/telemetry/index.js +86 -0
- package/dist/node/tools/index.js +345 -0
- package/dist/node/tools/knowledge-tool.js +74 -0
- package/dist/node/tools/mcp-client.js +47 -0
- package/dist/node/tools/mcp-server.js +205 -0
- package/dist/node/tools/tool-adapter.js +197 -0
- package/dist/node/types.js +0 -0
- package/dist/providers/claude-agent-sdk/adapter.d.ts +60 -52
- package/dist/providers/claude-agent-sdk/adapter.d.ts.map +1 -1
- package/dist/providers/claude-agent-sdk/adapter.js +622 -304
- package/dist/providers/claude-agent-sdk/index.d.ts +22 -4
- package/dist/providers/claude-agent-sdk/index.d.ts.map +1 -0
- package/dist/providers/claude-agent-sdk/index.js +672 -4
- package/dist/providers/claude-agent-sdk/session-bridge.d.ts +43 -40
- package/dist/providers/claude-agent-sdk/session-bridge.d.ts.map +1 -1
- package/dist/providers/claude-agent-sdk/session-bridge.js +121 -130
- package/dist/providers/claude-agent-sdk/tool-bridge.d.ts +63 -60
- package/dist/providers/claude-agent-sdk/tool-bridge.d.ts.map +1 -1
- package/dist/providers/claude-agent-sdk/tool-bridge.js +104 -108
- package/dist/providers/index.d.ts +28 -7
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +1261 -8
- package/dist/providers/opencode-sdk/adapter.d.ts +56 -48
- package/dist/providers/opencode-sdk/adapter.d.ts.map +1 -1
- package/dist/providers/opencode-sdk/adapter.js +667 -274
- package/dist/providers/opencode-sdk/agent-bridge.d.ts +62 -57
- package/dist/providers/opencode-sdk/agent-bridge.d.ts.map +1 -1
- package/dist/providers/opencode-sdk/agent-bridge.js +289 -155
- package/dist/providers/opencode-sdk/index.d.ts +22 -4
- package/dist/providers/opencode-sdk/index.d.ts.map +1 -0
- package/dist/providers/opencode-sdk/index.js +702 -4
- package/dist/providers/opencode-sdk/tool-bridge.d.ts +41 -42
- package/dist/providers/opencode-sdk/tool-bridge.d.ts.map +1 -1
- package/dist/providers/opencode-sdk/tool-bridge.js +121 -107
- package/dist/providers/registry.d.ts +10 -11
- package/dist/providers/registry.d.ts.map +1 -1
- package/dist/providers/registry.js +86 -49
- package/dist/providers/types.d.ts +169 -166
- package/dist/providers/types.d.ts.map +1 -1
- package/dist/providers/types.js +54 -42
- package/dist/schema/index.d.ts +3 -3
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +194 -3
- package/dist/schema/json-schema-to-zod.d.ts +23 -26
- package/dist/schema/json-schema-to-zod.d.ts.map +1 -1
- package/dist/schema/json-schema-to-zod.js +138 -110
- package/dist/schema/schema-output.d.ts +29 -32
- package/dist/schema/schema-output.d.ts.map +1 -1
- package/dist/schema/schema-output.js +178 -53
- package/dist/session/index.d.ts +2 -2
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/index.js +89 -2
- package/dist/session/store.d.ts +51 -55
- package/dist/session/store.d.ts.map +1 -1
- package/dist/session/store.js +85 -74
- package/dist/spec/index.d.ts +3 -3
- package/dist/spec/index.d.ts.map +1 -0
- package/dist/spec/index.js +84 -3
- package/dist/spec/registry.d.ts +32 -36
- package/dist/spec/registry.d.ts.map +1 -1
- package/dist/spec/registry.js +51 -60
- package/dist/spec/spec.d.ts +80 -84
- package/dist/spec/spec.d.ts.map +1 -1
- package/dist/spec/spec.js +40 -26
- package/dist/telemetry/adapter.d.ts +33 -37
- package/dist/telemetry/adapter.d.ts.map +1 -1
- package/dist/telemetry/adapter.js +78 -96
- package/dist/telemetry/index.d.ts +2 -2
- package/dist/telemetry/index.d.ts.map +1 -0
- package/dist/telemetry/index.js +85 -2
- package/dist/tools/index.d.ts +5 -5
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +344 -5
- package/dist/tools/knowledge-tool.d.ts +4 -8
- package/dist/tools/knowledge-tool.d.ts.map +1 -1
- package/dist/tools/knowledge-tool.js +68 -48
- package/dist/tools/mcp-client.d.ts +17 -21
- package/dist/tools/mcp-client.d.ts.map +1 -1
- package/dist/tools/mcp-client.js +42 -53
- package/dist/tools/mcp-server.d.ts +14 -18
- package/dist/tools/mcp-server.d.ts.map +1 -1
- package/dist/tools/mcp-server.js +200 -64
- package/dist/tools/tool-adapter.d.ts +7 -11
- package/dist/tools/tool-adapter.d.ts.map +1 -1
- package/dist/tools/tool-adapter.js +187 -70
- package/dist/tools/tools.test.d.ts +2 -0
- package/dist/tools/tools.test.d.ts.map +1 -0
- package/dist/types.d.ts +108 -111
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -0
- package/package.json +448 -90
- package/dist/_virtual/_rolldown/runtime.js +0 -8
- package/dist/agent/agent-factory.js.map +0 -1
- package/dist/agent/contract-spec-agent.js.map +0 -1
- package/dist/agent/json-runner.js.map +0 -1
- package/dist/agent/unified-agent.js.map +0 -1
- package/dist/approval/workflow.js.map +0 -1
- package/dist/exporters/claude-agent-exporter.js.map +0 -1
- package/dist/exporters/opencode-exporter.js.map +0 -1
- package/dist/interop/spec-consumer.js.map +0 -1
- package/dist/interop/tool-consumer.js.map +0 -1
- package/dist/knowledge/injector.js.map +0 -1
- package/dist/memory/in-memory.js.map +0 -1
- package/dist/memory/manager.js.map +0 -1
- package/dist/providers/claude-agent-sdk/adapter.js.map +0 -1
- package/dist/providers/claude-agent-sdk/session-bridge.js.map +0 -1
- package/dist/providers/claude-agent-sdk/tool-bridge.js.map +0 -1
- package/dist/providers/opencode-sdk/adapter.js.map +0 -1
- package/dist/providers/opencode-sdk/agent-bridge.js.map +0 -1
- package/dist/providers/opencode-sdk/tool-bridge.js.map +0 -1
- package/dist/providers/registry.js.map +0 -1
- package/dist/providers/types.js.map +0 -1
- package/dist/schema/json-schema-to-zod.js.map +0 -1
- package/dist/schema/schema-output.js.map +0 -1
- package/dist/session/store.js.map +0 -1
- package/dist/spec/registry.js.map +0 -1
- package/dist/spec/spec.js.map +0 -1
- package/dist/telemetry/adapter.js.map +0 -1
- package/dist/tools/knowledge-tool.js.map +0 -1
- package/dist/tools/mcp-client.js.map +0 -1
- package/dist/tools/mcp-server.js.map +0 -1
- package/dist/tools/tool-adapter.js.map +0 -1
package/dist/schema/index.js
CHANGED
|
@@ -1,4 +1,195 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// @bun
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __export = (target, all) => {
|
|
4
|
+
for (var name in all)
|
|
5
|
+
__defProp(target, name, {
|
|
6
|
+
get: all[name],
|
|
7
|
+
enumerable: true,
|
|
8
|
+
configurable: true,
|
|
9
|
+
set: (newValue) => all[name] = () => newValue
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
13
|
+
var __require = import.meta.require;
|
|
3
14
|
|
|
4
|
-
|
|
15
|
+
// src/schema/json-schema-to-zod.ts
|
|
16
|
+
import { z } from "zod";
|
|
17
|
+
function jsonSchemaToZod(schema) {
|
|
18
|
+
const s = schema;
|
|
19
|
+
const makeNullable = (zodSchema) => {
|
|
20
|
+
return s.nullable ? z.union([zodSchema, z.null()]) : zodSchema;
|
|
21
|
+
};
|
|
22
|
+
if (s.const !== undefined) {
|
|
23
|
+
return z.literal(s.const);
|
|
24
|
+
}
|
|
25
|
+
if (s.enum) {
|
|
26
|
+
const values = s.enum;
|
|
27
|
+
return makeNullable(z.enum(values.map(String)));
|
|
28
|
+
}
|
|
29
|
+
if (s.anyOf && s.anyOf.length > 0) {
|
|
30
|
+
const schemas = s.anyOf.map((sub) => jsonSchemaToZod(sub));
|
|
31
|
+
if (schemas.length === 1)
|
|
32
|
+
return schemas[0] ?? z.unknown();
|
|
33
|
+
return z.union([
|
|
34
|
+
schemas[0] ?? z.unknown(),
|
|
35
|
+
schemas[1] ?? z.unknown(),
|
|
36
|
+
...schemas.slice(2)
|
|
37
|
+
]);
|
|
38
|
+
}
|
|
39
|
+
if (s.oneOf && s.oneOf.length > 0) {
|
|
40
|
+
const schemas = s.oneOf.map((sub) => jsonSchemaToZod(sub));
|
|
41
|
+
if (schemas.length === 1)
|
|
42
|
+
return schemas[0] ?? z.unknown();
|
|
43
|
+
return z.union([
|
|
44
|
+
schemas[0] ?? z.unknown(),
|
|
45
|
+
schemas[1] ?? z.unknown(),
|
|
46
|
+
...schemas.slice(2)
|
|
47
|
+
]);
|
|
48
|
+
}
|
|
49
|
+
if (s.allOf && s.allOf.length > 0) {
|
|
50
|
+
const schemas = s.allOf.map((sub) => jsonSchemaToZod(sub));
|
|
51
|
+
return schemas.reduce((acc, curr) => z.intersection(acc, curr));
|
|
52
|
+
}
|
|
53
|
+
switch (s.type) {
|
|
54
|
+
case "string":
|
|
55
|
+
return makeNullable(buildStringSchema(s));
|
|
56
|
+
case "number":
|
|
57
|
+
case "integer":
|
|
58
|
+
return makeNullable(buildNumberSchema(s));
|
|
59
|
+
case "boolean":
|
|
60
|
+
return makeNullable(z.boolean());
|
|
61
|
+
case "null":
|
|
62
|
+
return z.null();
|
|
63
|
+
case "array":
|
|
64
|
+
return makeNullable(buildArraySchema(s));
|
|
65
|
+
case "object":
|
|
66
|
+
return makeNullable(buildObjectSchema(s));
|
|
67
|
+
default:
|
|
68
|
+
return z.unknown();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function buildStringSchema(schema) {
|
|
72
|
+
let zodSchema = z.string();
|
|
73
|
+
if (schema.description) {
|
|
74
|
+
zodSchema = zodSchema.describe(schema.description);
|
|
75
|
+
}
|
|
76
|
+
switch (schema.format) {
|
|
77
|
+
case "email":
|
|
78
|
+
zodSchema = zodSchema.email();
|
|
79
|
+
break;
|
|
80
|
+
case "uri":
|
|
81
|
+
case "url":
|
|
82
|
+
zodSchema = zodSchema.url();
|
|
83
|
+
break;
|
|
84
|
+
case "uuid":
|
|
85
|
+
zodSchema = zodSchema.uuid();
|
|
86
|
+
break;
|
|
87
|
+
case "date-time":
|
|
88
|
+
zodSchema = zodSchema.datetime();
|
|
89
|
+
break;
|
|
90
|
+
case "date":
|
|
91
|
+
zodSchema = zodSchema.date();
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
if (schema.minLength !== undefined) {
|
|
95
|
+
zodSchema = zodSchema.min(schema.minLength);
|
|
96
|
+
}
|
|
97
|
+
if (schema.maxLength !== undefined) {
|
|
98
|
+
zodSchema = zodSchema.max(schema.maxLength);
|
|
99
|
+
}
|
|
100
|
+
if (schema.pattern) {
|
|
101
|
+
zodSchema = zodSchema.regex(new RegExp(schema.pattern));
|
|
102
|
+
}
|
|
103
|
+
return zodSchema;
|
|
104
|
+
}
|
|
105
|
+
function buildNumberSchema(schema) {
|
|
106
|
+
let zodSchema = schema.type === "integer" ? z.number().int() : z.number();
|
|
107
|
+
if (schema.description) {
|
|
108
|
+
zodSchema = zodSchema.describe(schema.description);
|
|
109
|
+
}
|
|
110
|
+
if (schema.minimum !== undefined) {
|
|
111
|
+
zodSchema = zodSchema.min(schema.minimum);
|
|
112
|
+
}
|
|
113
|
+
if (schema.maximum !== undefined) {
|
|
114
|
+
zodSchema = zodSchema.max(schema.maximum);
|
|
115
|
+
}
|
|
116
|
+
return zodSchema;
|
|
117
|
+
}
|
|
118
|
+
function buildArraySchema(schema) {
|
|
119
|
+
const itemsSchema = schema.items ? jsonSchemaToZod(schema.items) : z.unknown();
|
|
120
|
+
let zodSchema = z.array(itemsSchema);
|
|
121
|
+
if (schema.description) {
|
|
122
|
+
zodSchema = zodSchema.describe(schema.description);
|
|
123
|
+
}
|
|
124
|
+
return zodSchema;
|
|
125
|
+
}
|
|
126
|
+
function buildObjectSchema(schema) {
|
|
127
|
+
const properties = schema.properties ?? {};
|
|
128
|
+
const required = new Set(schema.required ?? []);
|
|
129
|
+
const shape = {};
|
|
130
|
+
for (const [key, propSchema] of Object.entries(properties)) {
|
|
131
|
+
const zodProp = jsonSchemaToZod(propSchema);
|
|
132
|
+
shape[key] = required.has(key) ? zodProp : zodProp.optional();
|
|
133
|
+
}
|
|
134
|
+
let zodSchema = z.object(shape);
|
|
135
|
+
if (schema.description) {
|
|
136
|
+
zodSchema = zodSchema.describe(schema.description);
|
|
137
|
+
}
|
|
138
|
+
return zodSchema;
|
|
139
|
+
}
|
|
140
|
+
function jsonSchemaToZodSafe(schema) {
|
|
141
|
+
if (!schema || Object.keys(schema).length === 0) {
|
|
142
|
+
return z.object({});
|
|
143
|
+
}
|
|
144
|
+
return jsonSchemaToZod(schema);
|
|
145
|
+
}
|
|
146
|
+
var init_json_schema_to_zod = () => {};
|
|
147
|
+
|
|
148
|
+
// src/schema/schema-output.ts
|
|
149
|
+
init_json_schema_to_zod();
|
|
150
|
+
import { Output } from "ai";
|
|
151
|
+
function jsonSchemaToOutput(schema) {
|
|
152
|
+
const zodSchema = jsonSchemaToZod(schema);
|
|
153
|
+
return Output.object({
|
|
154
|
+
schema: zodSchema
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
function jsonSchemaToArrayOutput(itemSchema) {
|
|
158
|
+
const zodSchema = jsonSchemaToZod(itemSchema);
|
|
159
|
+
return Output.array({
|
|
160
|
+
element: zodSchema
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
function enumToChoiceOutput(choices) {
|
|
164
|
+
return Output.choice({
|
|
165
|
+
options: choices
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
function zodToOutput(schema) {
|
|
169
|
+
return Output.object({
|
|
170
|
+
schema
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
function textOutput() {
|
|
174
|
+
return Output.text();
|
|
175
|
+
}
|
|
176
|
+
var SchemaOutput = {
|
|
177
|
+
fromJsonSchema: jsonSchemaToOutput,
|
|
178
|
+
arrayFromJsonSchema: jsonSchemaToArrayOutput,
|
|
179
|
+
fromEnum: enumToChoiceOutput,
|
|
180
|
+
fromZod: zodToOutput,
|
|
181
|
+
text: textOutput
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
// src/schema/index.ts
|
|
185
|
+
init_json_schema_to_zod();
|
|
186
|
+
export {
|
|
187
|
+
zodToOutput,
|
|
188
|
+
textOutput,
|
|
189
|
+
jsonSchemaToZodSafe,
|
|
190
|
+
jsonSchemaToZod,
|
|
191
|
+
jsonSchemaToOutput,
|
|
192
|
+
jsonSchemaToArrayOutput,
|
|
193
|
+
enumToChoiceOutput,
|
|
194
|
+
SchemaOutput
|
|
195
|
+
};
|
|
@@ -1,29 +1,27 @@
|
|
|
1
|
-
import { ZodType } from
|
|
2
|
-
|
|
3
|
-
//#region src/schema/json-schema-to-zod.d.ts
|
|
1
|
+
import { type ZodType } from 'zod';
|
|
4
2
|
/**
|
|
5
3
|
* JSON Schema type definitions for conversion.
|
|
6
4
|
*/
|
|
7
5
|
interface JsonSchema {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
6
|
+
type?: string;
|
|
7
|
+
properties?: Record<string, JsonSchema>;
|
|
8
|
+
required?: string[];
|
|
9
|
+
items?: JsonSchema;
|
|
10
|
+
enum?: (string | number | boolean)[];
|
|
11
|
+
const?: unknown;
|
|
12
|
+
anyOf?: JsonSchema[];
|
|
13
|
+
oneOf?: JsonSchema[];
|
|
14
|
+
allOf?: JsonSchema[];
|
|
15
|
+
description?: string;
|
|
16
|
+
default?: unknown;
|
|
17
|
+
minimum?: number;
|
|
18
|
+
maximum?: number;
|
|
19
|
+
minLength?: number;
|
|
20
|
+
maxLength?: number;
|
|
21
|
+
pattern?: string;
|
|
22
|
+
format?: string;
|
|
23
|
+
nullable?: boolean;
|
|
24
|
+
[key: string]: unknown;
|
|
27
25
|
}
|
|
28
26
|
/**
|
|
29
27
|
* Convert a JSON Schema to a Zod schema.
|
|
@@ -41,14 +39,13 @@ interface JsonSchema {
|
|
|
41
39
|
* @param schema - JSON Schema object
|
|
42
40
|
* @returns Zod schema
|
|
43
41
|
*/
|
|
44
|
-
declare function jsonSchemaToZod(schema: JsonSchema | Record<string, unknown>): ZodType;
|
|
42
|
+
export declare function jsonSchemaToZod(schema: JsonSchema | Record<string, unknown>): ZodType;
|
|
45
43
|
/**
|
|
46
44
|
* Convert a JSON Schema to a Zod schema with a default empty object fallback.
|
|
47
45
|
*
|
|
48
46
|
* @param schema - Optional JSON Schema object
|
|
49
47
|
* @returns Zod schema (defaults to empty object schema)
|
|
50
48
|
*/
|
|
51
|
-
declare function jsonSchemaToZodSafe(schema?: Record<string, unknown>): ZodType;
|
|
52
|
-
|
|
53
|
-
export { jsonSchemaToZod, jsonSchemaToZodSafe };
|
|
49
|
+
export declare function jsonSchemaToZodSafe(schema?: Record<string, unknown>): ZodType;
|
|
50
|
+
export {};
|
|
54
51
|
//# sourceMappingURL=json-schema-to-zod.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-schema-to-zod.d.ts","
|
|
1
|
+
{"version":3,"file":"json-schema-to-zod.d.ts","sourceRoot":"","sources":["../../src/schema/json-schema-to-zod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAK,KAAK,OAAO,EAAE,MAAM,KAAK,CAAC;AAEtC;;GAEG;AACH,UAAU,UAAU;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IACxC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB,IAAI,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,EAAE,CAAC;IACrC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,KAAK,CAAC,EAAE,UAAU,EAAE,CAAC;IACrB,KAAK,CAAC,EAAE,UAAU,EAAE,CAAC;IACrB,KAAK,CAAC,EAAE,UAAU,EAAE,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC3C,OAAO,CAqET;AA8FD;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAK7E"}
|
|
@@ -1,124 +1,152 @@
|
|
|
1
|
-
|
|
1
|
+
// @bun
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __export = (target, all) => {
|
|
4
|
+
for (var name in all)
|
|
5
|
+
__defProp(target, name, {
|
|
6
|
+
get: all[name],
|
|
7
|
+
enumerable: true,
|
|
8
|
+
configurable: true,
|
|
9
|
+
set: (newValue) => all[name] = () => newValue
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
13
|
+
var __require = import.meta.require;
|
|
2
14
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* Convert a JSON Schema to a Zod schema.
|
|
6
|
-
*
|
|
7
|
-
* Supports common JSON Schema types and constraints:
|
|
8
|
-
* - string, number, integer, boolean, null
|
|
9
|
-
* - object with properties and required
|
|
10
|
-
* - array with items
|
|
11
|
-
* - enum and const
|
|
12
|
-
* - anyOf, oneOf, allOf
|
|
13
|
-
* - format constraints (email, uri, uuid, date-time)
|
|
14
|
-
* - numeric constraints (minimum, maximum)
|
|
15
|
-
* - string constraints (minLength, maxLength, pattern)
|
|
16
|
-
*
|
|
17
|
-
* @param schema - JSON Schema object
|
|
18
|
-
* @returns Zod schema
|
|
19
|
-
*/
|
|
15
|
+
// src/schema/json-schema-to-zod.ts
|
|
16
|
+
import { z } from "zod";
|
|
20
17
|
function jsonSchemaToZod(schema) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
18
|
+
const s = schema;
|
|
19
|
+
const makeNullable = (zodSchema) => {
|
|
20
|
+
return s.nullable ? z.union([zodSchema, z.null()]) : zodSchema;
|
|
21
|
+
};
|
|
22
|
+
if (s.const !== undefined) {
|
|
23
|
+
return z.literal(s.const);
|
|
24
|
+
}
|
|
25
|
+
if (s.enum) {
|
|
26
|
+
const values = s.enum;
|
|
27
|
+
return makeNullable(z.enum(values.map(String)));
|
|
28
|
+
}
|
|
29
|
+
if (s.anyOf && s.anyOf.length > 0) {
|
|
30
|
+
const schemas = s.anyOf.map((sub) => jsonSchemaToZod(sub));
|
|
31
|
+
if (schemas.length === 1)
|
|
32
|
+
return schemas[0] ?? z.unknown();
|
|
33
|
+
return z.union([
|
|
34
|
+
schemas[0] ?? z.unknown(),
|
|
35
|
+
schemas[1] ?? z.unknown(),
|
|
36
|
+
...schemas.slice(2)
|
|
37
|
+
]);
|
|
38
|
+
}
|
|
39
|
+
if (s.oneOf && s.oneOf.length > 0) {
|
|
40
|
+
const schemas = s.oneOf.map((sub) => jsonSchemaToZod(sub));
|
|
41
|
+
if (schemas.length === 1)
|
|
42
|
+
return schemas[0] ?? z.unknown();
|
|
43
|
+
return z.union([
|
|
44
|
+
schemas[0] ?? z.unknown(),
|
|
45
|
+
schemas[1] ?? z.unknown(),
|
|
46
|
+
...schemas.slice(2)
|
|
47
|
+
]);
|
|
48
|
+
}
|
|
49
|
+
if (s.allOf && s.allOf.length > 0) {
|
|
50
|
+
const schemas = s.allOf.map((sub) => jsonSchemaToZod(sub));
|
|
51
|
+
return schemas.reduce((acc, curr) => z.intersection(acc, curr));
|
|
52
|
+
}
|
|
53
|
+
switch (s.type) {
|
|
54
|
+
case "string":
|
|
55
|
+
return makeNullable(buildStringSchema(s));
|
|
56
|
+
case "number":
|
|
57
|
+
case "integer":
|
|
58
|
+
return makeNullable(buildNumberSchema(s));
|
|
59
|
+
case "boolean":
|
|
60
|
+
return makeNullable(z.boolean());
|
|
61
|
+
case "null":
|
|
62
|
+
return z.null();
|
|
63
|
+
case "array":
|
|
64
|
+
return makeNullable(buildArraySchema(s));
|
|
65
|
+
case "object":
|
|
66
|
+
return makeNullable(buildObjectSchema(s));
|
|
67
|
+
default:
|
|
68
|
+
return z.unknown();
|
|
69
|
+
}
|
|
59
70
|
}
|
|
60
71
|
function buildStringSchema(schema) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
72
|
+
let zodSchema = z.string();
|
|
73
|
+
if (schema.description) {
|
|
74
|
+
zodSchema = zodSchema.describe(schema.description);
|
|
75
|
+
}
|
|
76
|
+
switch (schema.format) {
|
|
77
|
+
case "email":
|
|
78
|
+
zodSchema = zodSchema.email();
|
|
79
|
+
break;
|
|
80
|
+
case "uri":
|
|
81
|
+
case "url":
|
|
82
|
+
zodSchema = zodSchema.url();
|
|
83
|
+
break;
|
|
84
|
+
case "uuid":
|
|
85
|
+
zodSchema = zodSchema.uuid();
|
|
86
|
+
break;
|
|
87
|
+
case "date-time":
|
|
88
|
+
zodSchema = zodSchema.datetime();
|
|
89
|
+
break;
|
|
90
|
+
case "date":
|
|
91
|
+
zodSchema = zodSchema.date();
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
if (schema.minLength !== undefined) {
|
|
95
|
+
zodSchema = zodSchema.min(schema.minLength);
|
|
96
|
+
}
|
|
97
|
+
if (schema.maxLength !== undefined) {
|
|
98
|
+
zodSchema = zodSchema.max(schema.maxLength);
|
|
99
|
+
}
|
|
100
|
+
if (schema.pattern) {
|
|
101
|
+
zodSchema = zodSchema.regex(new RegExp(schema.pattern));
|
|
102
|
+
}
|
|
103
|
+
return zodSchema;
|
|
85
104
|
}
|
|
86
105
|
function buildNumberSchema(schema) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
106
|
+
let zodSchema = schema.type === "integer" ? z.number().int() : z.number();
|
|
107
|
+
if (schema.description) {
|
|
108
|
+
zodSchema = zodSchema.describe(schema.description);
|
|
109
|
+
}
|
|
110
|
+
if (schema.minimum !== undefined) {
|
|
111
|
+
zodSchema = zodSchema.min(schema.minimum);
|
|
112
|
+
}
|
|
113
|
+
if (schema.maximum !== undefined) {
|
|
114
|
+
zodSchema = zodSchema.max(schema.maximum);
|
|
115
|
+
}
|
|
116
|
+
return zodSchema;
|
|
92
117
|
}
|
|
93
118
|
function buildArraySchema(schema) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
119
|
+
const itemsSchema = schema.items ? jsonSchemaToZod(schema.items) : z.unknown();
|
|
120
|
+
let zodSchema = z.array(itemsSchema);
|
|
121
|
+
if (schema.description) {
|
|
122
|
+
zodSchema = zodSchema.describe(schema.description);
|
|
123
|
+
}
|
|
124
|
+
return zodSchema;
|
|
98
125
|
}
|
|
99
126
|
function buildObjectSchema(schema) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
127
|
+
const properties = schema.properties ?? {};
|
|
128
|
+
const required = new Set(schema.required ?? []);
|
|
129
|
+
const shape = {};
|
|
130
|
+
for (const [key, propSchema] of Object.entries(properties)) {
|
|
131
|
+
const zodProp = jsonSchemaToZod(propSchema);
|
|
132
|
+
shape[key] = required.has(key) ? zodProp : zodProp.optional();
|
|
133
|
+
}
|
|
134
|
+
let zodSchema = z.object(shape);
|
|
135
|
+
if (schema.description) {
|
|
136
|
+
zodSchema = zodSchema.describe(schema.description);
|
|
137
|
+
}
|
|
138
|
+
return zodSchema;
|
|
110
139
|
}
|
|
111
|
-
/**
|
|
112
|
-
* Convert a JSON Schema to a Zod schema with a default empty object fallback.
|
|
113
|
-
*
|
|
114
|
-
* @param schema - Optional JSON Schema object
|
|
115
|
-
* @returns Zod schema (defaults to empty object schema)
|
|
116
|
-
*/
|
|
117
140
|
function jsonSchemaToZodSafe(schema) {
|
|
118
|
-
|
|
119
|
-
|
|
141
|
+
if (!schema || Object.keys(schema).length === 0) {
|
|
142
|
+
return z.object({});
|
|
143
|
+
}
|
|
144
|
+
return jsonSchemaToZod(schema);
|
|
120
145
|
}
|
|
146
|
+
var init_json_schema_to_zod = () => {};
|
|
147
|
+
init_json_schema_to_zod();
|
|
121
148
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
149
|
+
export {
|
|
150
|
+
jsonSchemaToZodSafe,
|
|
151
|
+
jsonSchemaToZod
|
|
152
|
+
};
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { Output } from
|
|
2
|
-
import { ZodType } from
|
|
3
|
-
|
|
4
|
-
//#region src/schema/schema-output.d.ts
|
|
1
|
+
import { Output } from 'ai';
|
|
2
|
+
import { type ZodType } from 'zod';
|
|
5
3
|
/**
|
|
6
4
|
* Bridge between ContractSpec SchemaModel and AI SDK Output.
|
|
7
5
|
*
|
|
@@ -18,59 +16,58 @@ type TextOutputReturn = ReturnType<typeof Output.text>;
|
|
|
18
16
|
* @param schema - JSON Schema object
|
|
19
17
|
* @returns AI SDK Output configuration
|
|
20
18
|
*/
|
|
21
|
-
declare function jsonSchemaToOutput(schema: Record<string, unknown>): ObjectOutputReturn;
|
|
19
|
+
export declare function jsonSchemaToOutput(schema: Record<string, unknown>): ObjectOutputReturn;
|
|
22
20
|
/**
|
|
23
21
|
* Create an AI SDK Output.array from a JSON Schema items definition.
|
|
24
22
|
*
|
|
25
23
|
* @param itemSchema - JSON Schema for array items
|
|
26
24
|
* @returns AI SDK Output configuration
|
|
27
25
|
*/
|
|
28
|
-
declare function jsonSchemaToArrayOutput(itemSchema: Record<string, unknown>): ArrayOutputReturn;
|
|
26
|
+
export declare function jsonSchemaToArrayOutput(itemSchema: Record<string, unknown>): ArrayOutputReturn;
|
|
29
27
|
/**
|
|
30
28
|
* Create an AI SDK Output.choice from enum values.
|
|
31
29
|
*
|
|
32
30
|
* @param choices - Array of choice values
|
|
33
31
|
* @returns AI SDK Output configuration
|
|
34
32
|
*/
|
|
35
|
-
declare function enumToChoiceOutput(choices: string[]): ChoiceOutputReturn;
|
|
33
|
+
export declare function enumToChoiceOutput(choices: string[]): ChoiceOutputReturn;
|
|
36
34
|
/**
|
|
37
35
|
* Create an AI SDK Output from a Zod schema directly.
|
|
38
36
|
*
|
|
39
37
|
* @param schema - Zod schema
|
|
40
38
|
* @returns AI SDK Output configuration
|
|
41
39
|
*/
|
|
42
|
-
declare function zodToOutput<T extends ZodType>(schema: T): ObjectOutputReturn;
|
|
40
|
+
export declare function zodToOutput<T extends ZodType>(schema: T): ObjectOutputReturn;
|
|
43
41
|
/**
|
|
44
42
|
* Create a simple text output configuration.
|
|
45
43
|
*
|
|
46
44
|
* @returns AI SDK Output configuration for text
|
|
47
45
|
*/
|
|
48
|
-
declare function textOutput(): TextOutputReturn;
|
|
46
|
+
export declare function textOutput(): TextOutputReturn;
|
|
49
47
|
/**
|
|
50
48
|
* Output builder that can be used fluently.
|
|
51
49
|
*/
|
|
52
|
-
declare const SchemaOutput: {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
50
|
+
export declare const SchemaOutput: {
|
|
51
|
+
/**
|
|
52
|
+
* Create an object output from JSON Schema.
|
|
53
|
+
*/
|
|
54
|
+
readonly fromJsonSchema: typeof jsonSchemaToOutput;
|
|
55
|
+
/**
|
|
56
|
+
* Create an array output from JSON Schema.
|
|
57
|
+
*/
|
|
58
|
+
readonly arrayFromJsonSchema: typeof jsonSchemaToArrayOutput;
|
|
59
|
+
/**
|
|
60
|
+
* Create a choice output from enum.
|
|
61
|
+
*/
|
|
62
|
+
readonly fromEnum: typeof enumToChoiceOutput;
|
|
63
|
+
/**
|
|
64
|
+
* Create an output from Zod schema.
|
|
65
|
+
*/
|
|
66
|
+
readonly fromZod: typeof zodToOutput;
|
|
67
|
+
/**
|
|
68
|
+
* Create a text output.
|
|
69
|
+
*/
|
|
70
|
+
readonly text: typeof textOutput;
|
|
73
71
|
};
|
|
74
|
-
|
|
75
|
-
export { SchemaOutput, enumToChoiceOutput, jsonSchemaToArrayOutput, jsonSchemaToOutput, textOutput, zodToOutput };
|
|
72
|
+
export {};
|
|
76
73
|
//# sourceMappingURL=schema-output.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-output.d.ts","
|
|
1
|
+
{"version":3,"file":"schema-output.d.ts","sourceRoot":"","sources":["../../src/schema/schema-output.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAC5B,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,KAAK,CAAC;AAGnC;;;;;GAKG;AAGH,KAAK,kBAAkB,GAAG,UAAU,CAAC,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC;AAC3D,KAAK,iBAAiB,GAAG,UAAU,CAAC,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACzD,KAAK,kBAAkB,GAAG,UAAU,CAAC,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC;AAC3D,KAAK,gBAAgB,GAAG,UAAU,CAAC,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC;AAEvD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B,kBAAkB,CAKpB;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAClC,iBAAiB,CAKnB;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,kBAAkB,CAIxE;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,OAAO,EAAE,MAAM,EAAE,CAAC,GAAG,kBAAkB,CAI5E;AAED;;;;GAIG;AACH,wBAAgB,UAAU,IAAI,gBAAgB,CAE7C;AAED;;GAEG;AACH,eAAO,MAAM,YAAY;IACvB;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;CAEK,CAAC"}
|