@dex-ai/sdk 0.1.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +308 -0
- package/dist/agent.d.ts +181 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +41 -0
- package/dist/agent.js.map +1 -0
- package/dist/context.d.ts +68 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +8 -0
- package/dist/context.js.map +1 -0
- package/dist/create-agent.d.ts +7 -0
- package/dist/create-agent.d.ts.map +1 -0
- package/dist/create-agent.js +205 -0
- package/dist/create-agent.js.map +1 -0
- package/dist/extension.d.ts +162 -0
- package/dist/extension.d.ts.map +1 -0
- package/dist/extension.js +20 -0
- package/dist/extension.js.map +1 -0
- package/dist/generate.d.ts +10 -0
- package/dist/generate.d.ts.map +1 -0
- package/dist/generate.js +839 -0
- package/dist/generate.js.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/message.d.ts +89 -0
- package/dist/message.d.ts.map +1 -0
- package/dist/message.js +17 -0
- package/dist/message.js.map +1 -0
- package/dist/messages.d.ts +98 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +339 -0
- package/dist/messages.js.map +1 -0
- package/dist/model.d.ts +39 -0
- package/dist/model.d.ts.map +1 -0
- package/dist/model.js +11 -0
- package/dist/model.js.map +1 -0
- package/dist/provider.d.ts +157 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +39 -0
- package/dist/provider.js.map +1 -0
- package/dist/resolve-schema.d.ts +44 -0
- package/dist/resolve-schema.d.ts.map +1 -0
- package/dist/resolve-schema.js +367 -0
- package/dist/resolve-schema.js.map +1 -0
- package/dist/schema.d.ts +80 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +90 -0
- package/dist/schema.js.map +1 -0
- package/dist/tool-dispatch.d.ts +24 -0
- package/dist/tool-dispatch.d.ts.map +1 -0
- package/dist/tool-dispatch.js +120 -0
- package/dist/tool-dispatch.js.map +1 -0
- package/dist/tool-result-cache.d.ts +43 -0
- package/dist/tool-result-cache.d.ts.map +1 -0
- package/dist/tool-result-cache.js +118 -0
- package/dist/tool-result-cache.js.map +1 -0
- package/dist/tool.d.ts +96 -0
- package/dist/tool.d.ts.map +1 -0
- package/dist/tool.js +29 -0
- package/dist/tool.js.map +1 -0
- package/dist/util.d.ts +26 -0
- package/dist/util.d.ts.map +1 -0
- package/dist/util.js +104 -0
- package/dist/util.js.map +1 -0
- package/package.json +41 -0
- package/src/agent.ts +235 -0
- package/src/context.ts +82 -0
- package/src/create-agent.ts +237 -0
- package/src/extension.ts +244 -0
- package/src/generate.ts +943 -0
- package/src/index.ts +113 -0
- package/src/message.ts +114 -0
- package/src/messages.test.ts +299 -0
- package/src/messages.ts +423 -0
- package/src/model.ts +43 -0
- package/src/provider.ts +187 -0
- package/src/resolve-schema.test.ts +351 -0
- package/src/resolve-schema.ts +426 -0
- package/src/schema.ts +131 -0
- package/src/tool-dispatch.ts +166 -0
- package/src/tool-result-cache.test.ts +182 -0
- package/src/tool-result-cache.ts +164 -0
- package/src/tool.ts +110 -0
- package/src/util.ts +110 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-schema.d.ts","sourceRoot":"","sources":["../src/resolve-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEtC,gEAAgE;AAChE,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEvD,8CAA8C;AAC9C,MAAM,WAAW,oBAAoB;IACpC,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,OAAO,GAAG,SAAS,CAAC;CAC9B;AAKD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,gBAAgB,GAAG,gBAAgB,CAY5E;AAoPD;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAClC,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC,EAC7B,IAAI,CAAC,EAAE;IAAE,aAAa,CAAC,EAAE,MAAM,CAAA;CAAE,GAC/B,oBAAoB,EAAE,CAmFxB"}
|
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* resolveJsonSchema — resolve a StandardSchemaV1 to a JSON Schema object.
|
|
3
|
+
*
|
|
4
|
+
* This is the SDK's single point of truth for schema → JSON Schema conversion.
|
|
5
|
+
* It handles:
|
|
6
|
+
* 1. Pre-computed `~standard.jsonSchema` (fast path — already resolved)
|
|
7
|
+
* 2. Zod v4 native `toJSONSchema()` (schema carries its own converter)
|
|
8
|
+
* 3. Zod v3 via `zod-to-json-schema` (legacy path)
|
|
9
|
+
* 4. Any Standard Schema with `~standard.schema` field
|
|
10
|
+
*
|
|
11
|
+
* The result is cached on the schema object so repeated calls are free.
|
|
12
|
+
*
|
|
13
|
+
* Providers should call `resolveJsonSchema(tool.parameters)` instead of
|
|
14
|
+
* doing their own Zod import gymnastics.
|
|
15
|
+
*/
|
|
16
|
+
/** WeakMap cache so we resolve each schema object only once. */
|
|
17
|
+
const cache = new WeakMap();
|
|
18
|
+
/**
|
|
19
|
+
* Resolve a Standard Schema to a JSON Schema object.
|
|
20
|
+
*
|
|
21
|
+
* Call this from providers when building API requests. It handles all
|
|
22
|
+
* supported schema libraries transparently.
|
|
23
|
+
*/
|
|
24
|
+
export function resolveJsonSchema(schema) {
|
|
25
|
+
if (!schema)
|
|
26
|
+
return { type: "object", properties: {} };
|
|
27
|
+
// Check cache first
|
|
28
|
+
const cached = cache.get(schema);
|
|
29
|
+
if (cached)
|
|
30
|
+
return cached;
|
|
31
|
+
let result = doResolve(schema);
|
|
32
|
+
result = sanitize(result);
|
|
33
|
+
cache.set(schema, result);
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
/* ------------------------------------------------------------------ */
|
|
37
|
+
/* Resolution strategies */
|
|
38
|
+
/* ------------------------------------------------------------------ */
|
|
39
|
+
function doResolve(schema) {
|
|
40
|
+
const std = schema["~standard"];
|
|
41
|
+
// 1. Fast path: pre-computed jsonSchema (set by SDK Schema builder or manually)
|
|
42
|
+
if (std?.jsonSchema && typeof std.jsonSchema === "object") {
|
|
43
|
+
const js = std.jsonSchema;
|
|
44
|
+
// Validate it looks like actual JSON Schema (not Zod v4's types descriptor)
|
|
45
|
+
if (looksLikeJsonSchema(js))
|
|
46
|
+
return { ...js };
|
|
47
|
+
}
|
|
48
|
+
// 2. Zod v4 path: schema has toJSONSchema on its module
|
|
49
|
+
if (std?.vendor === "zod") {
|
|
50
|
+
const resolved = tryZodV4(schema);
|
|
51
|
+
if (resolved)
|
|
52
|
+
return resolved;
|
|
53
|
+
}
|
|
54
|
+
// 3. Zod v3 path: try zod-to-json-schema
|
|
55
|
+
const zodV3Result = tryZodV3(schema);
|
|
56
|
+
if (zodV3Result)
|
|
57
|
+
return zodV3Result;
|
|
58
|
+
// 4. Fallback: ~standard.schema field (some libs put raw JSON Schema here)
|
|
59
|
+
if (std?.schema && typeof std.schema === "object") {
|
|
60
|
+
return { ...std.schema };
|
|
61
|
+
}
|
|
62
|
+
// Nothing worked — return empty object schema
|
|
63
|
+
return { type: "object", properties: {} };
|
|
64
|
+
}
|
|
65
|
+
/* ------------------------------------------------------------------ */
|
|
66
|
+
/* Zod v4: use its native toJSONSchema */
|
|
67
|
+
/* ------------------------------------------------------------------ */
|
|
68
|
+
function tryZodV4(schema) {
|
|
69
|
+
try {
|
|
70
|
+
// Zod v4 schemas have a _zod property with their registry
|
|
71
|
+
const zod = schema;
|
|
72
|
+
// Strategy A: try importing from zod/v4/core which has toJSONSchema
|
|
73
|
+
// The schema object in Zod v4 has `_zod.def` — we can use the Zod module
|
|
74
|
+
// that created it if it's accessible.
|
|
75
|
+
if (zod._zod?.def) {
|
|
76
|
+
// Try to get toJSONSchema from the zod module that created this schema.
|
|
77
|
+
// Zod v4 schemas are created by a specific zod instance — the instance
|
|
78
|
+
// may expose toJSONSchema.
|
|
79
|
+
try {
|
|
80
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
81
|
+
const zodMod = require("zod");
|
|
82
|
+
if (typeof zodMod.toJSONSchema === "function") {
|
|
83
|
+
const raw = zodMod.toJSONSchema(schema);
|
|
84
|
+
if (raw && typeof raw === "object" && Object.keys(raw).length > 0) {
|
|
85
|
+
return stripMeta(raw);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
// zod not resolvable from SDK context — try alternative
|
|
91
|
+
}
|
|
92
|
+
// Try zod/v4/core
|
|
93
|
+
try {
|
|
94
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
95
|
+
const zodCore = require("zod/v4/core");
|
|
96
|
+
if (typeof zodCore.toJSONSchema === "function") {
|
|
97
|
+
const raw = zodCore.toJSONSchema(schema);
|
|
98
|
+
if (raw && typeof raw === "object" && Object.keys(raw).length > 0) {
|
|
99
|
+
return stripMeta(raw);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
// not available
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
// Strategy B: Zod v4 may also export from main entry
|
|
108
|
+
try {
|
|
109
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
110
|
+
const { toJSONSchema } = require("zod");
|
|
111
|
+
if (typeof toJSONSchema === "function") {
|
|
112
|
+
const raw = toJSONSchema(schema);
|
|
113
|
+
if (raw && typeof raw === "object" && Object.keys(raw).length > 0) {
|
|
114
|
+
return stripMeta(raw);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
// not available
|
|
120
|
+
}
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/* ------------------------------------------------------------------ */
|
|
128
|
+
/* Zod v3: use zod-to-json-schema */
|
|
129
|
+
/* ------------------------------------------------------------------ */
|
|
130
|
+
function tryZodV3(schema) {
|
|
131
|
+
try {
|
|
132
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
133
|
+
const { zodToJsonSchema } = require("zod-to-json-schema");
|
|
134
|
+
const raw = zodToJsonSchema(schema, {
|
|
135
|
+
target: "openApi3",
|
|
136
|
+
$refStrategy: "none",
|
|
137
|
+
});
|
|
138
|
+
if (raw && typeof raw === "object" && Object.keys(raw).length > 0) {
|
|
139
|
+
return stripMeta(raw);
|
|
140
|
+
}
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/* ------------------------------------------------------------------ */
|
|
148
|
+
/* Sanitization — clean up for Anthropic/Bedrock compatibility */
|
|
149
|
+
/* ------------------------------------------------------------------ */
|
|
150
|
+
/**
|
|
151
|
+
* Sanitize JSON Schema for maximum provider compatibility.
|
|
152
|
+
*
|
|
153
|
+
* Handles:
|
|
154
|
+
* - Strips $schema, additionalProperties (Bedrock rejects these)
|
|
155
|
+
* - Converts anyOf: [{type: X}, {type: "null"}] → {type: X} (Bedrock no anyOf)
|
|
156
|
+
* - Converts draft-04 boolean exclusiveMinimum/Maximum to numeric form
|
|
157
|
+
* - Converts type: ["string", "null"] → type: "string"
|
|
158
|
+
*/
|
|
159
|
+
function sanitize(obj) {
|
|
160
|
+
if (obj === null || typeof obj !== "object")
|
|
161
|
+
return obj;
|
|
162
|
+
if (Array.isArray(obj))
|
|
163
|
+
return obj.map(sanitize);
|
|
164
|
+
const src = obj;
|
|
165
|
+
const result = {};
|
|
166
|
+
const hasExclMin = src.exclusiveMinimum === true && typeof src.minimum === "number";
|
|
167
|
+
const hasExclMax = src.exclusiveMaximum === true && typeof src.maximum === "number";
|
|
168
|
+
for (const [key, value] of Object.entries(src)) {
|
|
169
|
+
// Strip meta fields that providers reject
|
|
170
|
+
if (key === "$schema")
|
|
171
|
+
continue;
|
|
172
|
+
if (key === "additionalProperties")
|
|
173
|
+
continue;
|
|
174
|
+
// Draft-04 boolean exclusiveMinimum → numeric
|
|
175
|
+
if (key === "exclusiveMinimum" && value === true) {
|
|
176
|
+
result.exclusiveMinimum = src.minimum;
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
if (key === "exclusiveMaximum" && value === true) {
|
|
180
|
+
result.exclusiveMaximum = src.maximum;
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
if (key === "minimum" && hasExclMin)
|
|
184
|
+
continue;
|
|
185
|
+
if (key === "maximum" && hasExclMax)
|
|
186
|
+
continue;
|
|
187
|
+
// type: ["string", "null"] → "string"
|
|
188
|
+
if (key === "type" && Array.isArray(value)) {
|
|
189
|
+
const nonNull = value.filter((t) => t !== "null");
|
|
190
|
+
result[key] = nonNull.length === 1 ? nonNull[0] : nonNull;
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
// anyOf: [{...}, {type: "null"}] → unwrap non-null branch
|
|
194
|
+
if (key === "anyOf" && Array.isArray(value)) {
|
|
195
|
+
const nonNull = value.filter((v) => !(v && typeof v === "object" && v.type === "null"));
|
|
196
|
+
if (nonNull.length === 1) {
|
|
197
|
+
// Merge the non-null branch into current level
|
|
198
|
+
const inner = sanitize(nonNull[0]);
|
|
199
|
+
Object.assign(result, inner);
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
result[key] = nonNull.map(sanitize);
|
|
203
|
+
}
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
// Recurse into nested objects/arrays
|
|
207
|
+
result[key] = typeof value === "object" ? sanitize(value) : value;
|
|
208
|
+
}
|
|
209
|
+
return result;
|
|
210
|
+
}
|
|
211
|
+
/* ------------------------------------------------------------------ */
|
|
212
|
+
/* Helpers */
|
|
213
|
+
/* ------------------------------------------------------------------ */
|
|
214
|
+
/** Strip $schema from top-level output */
|
|
215
|
+
function stripMeta(raw) {
|
|
216
|
+
if (!raw || typeof raw !== "object")
|
|
217
|
+
return raw;
|
|
218
|
+
const { $schema, ...rest } = raw;
|
|
219
|
+
return rest;
|
|
220
|
+
}
|
|
221
|
+
/** Check if an object looks like a JSON Schema (has structural keys, not functions). */
|
|
222
|
+
function looksLikeJsonSchema(obj) {
|
|
223
|
+
const keys = Object.keys(obj);
|
|
224
|
+
if (keys.length === 0)
|
|
225
|
+
return false;
|
|
226
|
+
// JSON Schema objects have keys like type, properties, items, enum, anyOf, etc.
|
|
227
|
+
// Reject objects whose values are functions (like Zod v4's {input: fn, output: fn})
|
|
228
|
+
const jsonSchemaKeys = new Set([
|
|
229
|
+
"type",
|
|
230
|
+
"properties",
|
|
231
|
+
"required",
|
|
232
|
+
"items",
|
|
233
|
+
"enum",
|
|
234
|
+
"const",
|
|
235
|
+
"anyOf",
|
|
236
|
+
"oneOf",
|
|
237
|
+
"allOf",
|
|
238
|
+
"not",
|
|
239
|
+
"$ref",
|
|
240
|
+
"description",
|
|
241
|
+
"default",
|
|
242
|
+
"title",
|
|
243
|
+
"minimum",
|
|
244
|
+
"maximum",
|
|
245
|
+
"exclusiveMinimum",
|
|
246
|
+
"exclusiveMaximum",
|
|
247
|
+
"minLength",
|
|
248
|
+
"maxLength",
|
|
249
|
+
"pattern",
|
|
250
|
+
"minItems",
|
|
251
|
+
"maxItems",
|
|
252
|
+
"uniqueItems",
|
|
253
|
+
"$schema",
|
|
254
|
+
"additionalProperties",
|
|
255
|
+
"format",
|
|
256
|
+
]);
|
|
257
|
+
return keys.some((k) => jsonSchemaKeys.has(k));
|
|
258
|
+
}
|
|
259
|
+
/* ------------------------------------------------------------------ */
|
|
260
|
+
/* Tool schema validation */
|
|
261
|
+
/* ------------------------------------------------------------------ */
|
|
262
|
+
/**
|
|
263
|
+
* Validate tool schemas eagerly. Returns diagnostics for tools whose
|
|
264
|
+
* schemas cannot be resolved or produce degenerate JSON Schema.
|
|
265
|
+
*
|
|
266
|
+
* Call at agent startup or tool collection time to surface bad schemas
|
|
267
|
+
* immediately rather than getting opaque 502s from providers at runtime.
|
|
268
|
+
*/
|
|
269
|
+
export function validateToolSchemas(tools, opts) {
|
|
270
|
+
const diagnostics = [];
|
|
271
|
+
for (const tool of tools) {
|
|
272
|
+
if (!tool.parameters) {
|
|
273
|
+
diagnostics.push({
|
|
274
|
+
toolName: tool.name,
|
|
275
|
+
extensionName: opts?.extensionName,
|
|
276
|
+
issue: "Tool has no parameters schema",
|
|
277
|
+
severity: "warning",
|
|
278
|
+
});
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
try {
|
|
282
|
+
const schema = resolveJsonSchema(tool.parameters);
|
|
283
|
+
// Check if author pre-computed jsonSchema (fast path) — trust it
|
|
284
|
+
const std = tool.parameters["~standard"];
|
|
285
|
+
const hasPrecomputed = std?.jsonSchema && typeof std.jsonSchema === "object";
|
|
286
|
+
// Empty schema = resolution failed silently
|
|
287
|
+
if (!schema.type &&
|
|
288
|
+
!schema.properties &&
|
|
289
|
+
!schema.anyOf &&
|
|
290
|
+
!schema.oneOf &&
|
|
291
|
+
!schema.allOf) {
|
|
292
|
+
diagnostics.push({
|
|
293
|
+
toolName: tool.name,
|
|
294
|
+
extensionName: opts?.extensionName,
|
|
295
|
+
issue: "Schema resolved to empty object — likely a Zod version mismatch. " +
|
|
296
|
+
"Ensure zod-to-json-schema supports your Zod version, or use @dex-ai/sdk Schema builder.",
|
|
297
|
+
severity: "error",
|
|
298
|
+
});
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
// Check for type: "object" with no properties — schema conversion likely failed
|
|
302
|
+
// UNLESS the author explicitly pre-computed it (via Schema.fromJsonSchema or ~standard.jsonSchema)
|
|
303
|
+
if (!hasPrecomputed &&
|
|
304
|
+
schema.type === "object" &&
|
|
305
|
+
schema.properties &&
|
|
306
|
+
Object.keys(schema.properties).length === 0) {
|
|
307
|
+
diagnostics.push({
|
|
308
|
+
toolName: tool.name,
|
|
309
|
+
extensionName: opts?.extensionName,
|
|
310
|
+
issue: "Schema resolved to object with no properties — schema conversion likely failed. " +
|
|
311
|
+
"Ensure zod-to-json-schema supports your Zod version, or use @dex-ai/sdk Schema builder.",
|
|
312
|
+
severity: "error",
|
|
313
|
+
});
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
// Warn about remaining anyOf/oneOf (Bedrock incompatible)
|
|
317
|
+
const unsupported = findUnsupportedPatterns(schema);
|
|
318
|
+
for (const pattern of unsupported) {
|
|
319
|
+
diagnostics.push({
|
|
320
|
+
toolName: tool.name,
|
|
321
|
+
extensionName: opts?.extensionName,
|
|
322
|
+
issue: `Schema contains ${pattern} which some providers (Bedrock) do not support`,
|
|
323
|
+
severity: "warning",
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
catch (err) {
|
|
328
|
+
diagnostics.push({
|
|
329
|
+
toolName: tool.name,
|
|
330
|
+
extensionName: opts?.extensionName,
|
|
331
|
+
issue: `Schema resolution threw: ${err instanceof Error ? err.message : String(err)}`,
|
|
332
|
+
severity: "error",
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
return diagnostics;
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Recursively find JSON Schema patterns that are known to be unsupported
|
|
340
|
+
* by restrictive providers (AWS Bedrock).
|
|
341
|
+
*/
|
|
342
|
+
function findUnsupportedPatterns(obj, path = "") {
|
|
343
|
+
if (obj === null || typeof obj !== "object" || Array.isArray(obj))
|
|
344
|
+
return [];
|
|
345
|
+
const patterns = [];
|
|
346
|
+
const src = obj;
|
|
347
|
+
// anyOf with multiple non-null branches (nullable was already stripped by sanitize)
|
|
348
|
+
if (src.anyOf &&
|
|
349
|
+
Array.isArray(src.anyOf) &&
|
|
350
|
+
src.anyOf.length > 1) {
|
|
351
|
+
patterns.push(`anyOf${path ? " at " + path : ""}`);
|
|
352
|
+
}
|
|
353
|
+
if (src.oneOf && Array.isArray(src.oneOf)) {
|
|
354
|
+
patterns.push(`oneOf${path ? " at " + path : ""}`);
|
|
355
|
+
}
|
|
356
|
+
// Recurse into properties, items, etc.
|
|
357
|
+
if (src.properties && typeof src.properties === "object") {
|
|
358
|
+
for (const [key, val] of Object.entries(src.properties)) {
|
|
359
|
+
patterns.push(...findUnsupportedPatterns(val, `${path}.${key}`));
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
if (src.items && typeof src.items === "object" && !Array.isArray(src.items)) {
|
|
363
|
+
patterns.push(...findUnsupportedPatterns(src.items, `${path}[]`));
|
|
364
|
+
}
|
|
365
|
+
return patterns;
|
|
366
|
+
}
|
|
367
|
+
//# sourceMappingURL=resolve-schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-schema.js","sourceRoot":"","sources":["../src/resolve-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAgBH,gEAAgE;AAChE,MAAM,KAAK,GAAG,IAAI,OAAO,EAA4B,CAAC;AAEtD;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAwB;IACzD,IAAI,CAAC,MAAM;QAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC;IAEvD,oBAAoB;IACpB,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,MAAgB,CAAC,CAAC;IAC3C,IAAI,MAAM;QAAE,OAAO,MAAM,CAAC;IAE1B,IAAI,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;IAC/B,MAAM,GAAG,QAA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CAAC;IACpD,CAAC;IAED,uCAAuC;IACvC,IAAI,GAAG,CAAC,UAAU,IAAI,OAAO,GAAG,CAAC,UAAU,KAAK,QAAQ,EAAE,CAAC;QAC1D,KAAK,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,MAAM,CAAC,OAAO,CACtC,GAAG,CAAC,UAAqC,CACzC,EAAE,CAAC;YACH,QAAQ,CAAC,IAAI,CAAC,GAAG,uBAAuB,CAAC,GAAG,EAAE,GAAG,IAAI,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC;QAClE,CAAC;IACF,CAAC;IACD,IAAI,GAAG,CAAC,KAAK,IAAI,OAAO,GAAG,CAAC,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;QAC7E,QAAQ,CAAC,IAAI,CAAC,GAAG,uBAAuB,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC;IACnE,CAAC;IAED,OAAO,QAAQ,CAAC;AACjB,CAAC"}
|
package/dist/schema.d.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Re-export of the Standard Schema v1 interface.
|
|
3
|
+
*
|
|
4
|
+
* We do not take a runtime dependency on `@standard-schema/spec` — only the
|
|
5
|
+
* type surface, inlined here so dex-sdk has zero runtime deps. Any schema
|
|
6
|
+
* library that implements Standard Schema (zod v3.24+, valibot, arktype,
|
|
7
|
+
* effect/schema, etc.) will satisfy this.
|
|
8
|
+
*
|
|
9
|
+
* Spec: https://standardschema.dev
|
|
10
|
+
*/
|
|
11
|
+
import type { JsonSchemaObject } from "./resolve-schema";
|
|
12
|
+
/** A single element of a Standard Schema issue path. */
|
|
13
|
+
export type PathSegment = {
|
|
14
|
+
readonly key: PropertyKey;
|
|
15
|
+
};
|
|
16
|
+
/** One validation issue. */
|
|
17
|
+
export interface StandardSchemaIssue {
|
|
18
|
+
readonly message: string;
|
|
19
|
+
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
20
|
+
}
|
|
21
|
+
export type SuccessResult<Output> = {
|
|
22
|
+
readonly value: Output;
|
|
23
|
+
};
|
|
24
|
+
export type FailureResult = {
|
|
25
|
+
readonly issues: ReadonlyArray<StandardSchemaIssue>;
|
|
26
|
+
};
|
|
27
|
+
export type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
28
|
+
export interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
29
|
+
readonly "~standard": {
|
|
30
|
+
readonly version: 1;
|
|
31
|
+
readonly vendor: string;
|
|
32
|
+
readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
|
|
33
|
+
readonly types?: {
|
|
34
|
+
readonly input: Input;
|
|
35
|
+
readonly output: Output;
|
|
36
|
+
} | undefined;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export type InferInput<S> = S extends StandardSchemaV1<infer I, unknown> ? I : never;
|
|
40
|
+
export type InferOutput<S> = S extends StandardSchemaV1<unknown, infer O> ? O : never;
|
|
41
|
+
/**
|
|
42
|
+
* Create a StandardSchemaV1 from a raw JSON Schema object.
|
|
43
|
+
*
|
|
44
|
+
* Use this when you don't want a Zod/Valibot dependency — just provide
|
|
45
|
+
* the JSON Schema directly. The resulting object satisfies StandardSchemaV1
|
|
46
|
+
* so it works with `Tool.define({ parameters: Schema.fromJsonSchema({...}) })`.
|
|
47
|
+
*
|
|
48
|
+
* Note: no runtime validation is performed (validate always succeeds).
|
|
49
|
+
* The schema is used purely for declaring the tool's input shape to the model.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* import { Schema, Tool } from "@dex-ai/sdk";
|
|
54
|
+
*
|
|
55
|
+
* const myTool = Tool.define({
|
|
56
|
+
* name: "read_file",
|
|
57
|
+
* parameters: Schema.fromJsonSchema({
|
|
58
|
+
* type: "object",
|
|
59
|
+
* properties: {
|
|
60
|
+
* path: { type: "string", description: "File path" },
|
|
61
|
+
* lineStart: { type: "integer", minimum: 1 },
|
|
62
|
+
* },
|
|
63
|
+
* required: ["path"],
|
|
64
|
+
* }),
|
|
65
|
+
* execute(input) { ... }
|
|
66
|
+
* });
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export declare const Schema: {
|
|
70
|
+
/**
|
|
71
|
+
* Wrap a JSON Schema object as a StandardSchemaV1.
|
|
72
|
+
* Input type is `unknown` (no compile-time inference).
|
|
73
|
+
*
|
|
74
|
+
* Performs lightweight runtime validation:
|
|
75
|
+
* - Ensures value is an object (when schema type is "object")
|
|
76
|
+
* - Checks `required` fields are present and non-undefined
|
|
77
|
+
*/
|
|
78
|
+
fromJsonSchema<Input = unknown>(jsonSchema: JsonSchemaObject): StandardSchemaV1<Input>;
|
|
79
|
+
};
|
|
80
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEzD,wDAAwD;AACxD,MAAM,MAAM,WAAW,GAAG;IAAE,QAAQ,CAAC,GAAG,EAAE,WAAW,CAAA;CAAE,CAAC;AAExD,4BAA4B;AAC5B,MAAM,WAAW,mBAAmB;IACnC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,CAAC,EAAE,aAAa,CAAC,WAAW,GAAG,WAAW,CAAC,GAAG,SAAS,CAAC;CACrE;AAED,MAAM,MAAM,aAAa,CAAC,MAAM,IAAI;IAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAC/D,MAAM,MAAM,aAAa,GAAG;IAC3B,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC,mBAAmB,CAAC,CAAC;CACpD,CAAC;AACF,MAAM,MAAM,MAAM,CAAC,MAAM,IAAI,aAAa,CAAC,MAAM,CAAC,GAAG,aAAa,CAAC;AAEnE,MAAM,WAAW,gBAAgB,CAAC,KAAK,GAAG,OAAO,EAAE,MAAM,GAAG,KAAK;IAChE,QAAQ,CAAC,WAAW,EAAE;QACrB,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;QACpB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;QACxB,QAAQ,CAAC,QAAQ,EAAE,CAClB,KAAK,EAAE,OAAO,KACV,MAAM,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;QAC9C,QAAQ,CAAC,KAAK,CAAC,EACZ;YAAE,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;YAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;SAAE,GAClD,SAAS,CAAC;KACb,CAAC;CACF;AAED,MAAM,MAAM,UAAU,CAAC,CAAC,IACvB,CAAC,SAAS,gBAAgB,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAC1D,MAAM,MAAM,WAAW,CAAC,CAAC,IACxB,CAAC,SAAS,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAM1D;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,MAAM;IAClB;;;;;;;OAOG;mBACY,KAAK,wBACP,gBAAgB,GAC1B,gBAAgB,CAAC,KAAK,CAAC;CAyC1B,CAAC"}
|
package/dist/schema.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Re-export of the Standard Schema v1 interface.
|
|
3
|
+
*
|
|
4
|
+
* We do not take a runtime dependency on `@standard-schema/spec` — only the
|
|
5
|
+
* type surface, inlined here so dex-sdk has zero runtime deps. Any schema
|
|
6
|
+
* library that implements Standard Schema (zod v3.24+, valibot, arktype,
|
|
7
|
+
* effect/schema, etc.) will satisfy this.
|
|
8
|
+
*
|
|
9
|
+
* Spec: https://standardschema.dev
|
|
10
|
+
*/
|
|
11
|
+
/* ------------------------------------------------------------------ */
|
|
12
|
+
/* Schema — zero-dependency helpers to create StandardSchemaV1 objects */
|
|
13
|
+
/* ------------------------------------------------------------------ */
|
|
14
|
+
/**
|
|
15
|
+
* Create a StandardSchemaV1 from a raw JSON Schema object.
|
|
16
|
+
*
|
|
17
|
+
* Use this when you don't want a Zod/Valibot dependency — just provide
|
|
18
|
+
* the JSON Schema directly. The resulting object satisfies StandardSchemaV1
|
|
19
|
+
* so it works with `Tool.define({ parameters: Schema.fromJsonSchema({...}) })`.
|
|
20
|
+
*
|
|
21
|
+
* Note: no runtime validation is performed (validate always succeeds).
|
|
22
|
+
* The schema is used purely for declaring the tool's input shape to the model.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* import { Schema, Tool } from "@dex-ai/sdk";
|
|
27
|
+
*
|
|
28
|
+
* const myTool = Tool.define({
|
|
29
|
+
* name: "read_file",
|
|
30
|
+
* parameters: Schema.fromJsonSchema({
|
|
31
|
+
* type: "object",
|
|
32
|
+
* properties: {
|
|
33
|
+
* path: { type: "string", description: "File path" },
|
|
34
|
+
* lineStart: { type: "integer", minimum: 1 },
|
|
35
|
+
* },
|
|
36
|
+
* required: ["path"],
|
|
37
|
+
* }),
|
|
38
|
+
* execute(input) { ... }
|
|
39
|
+
* });
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export const Schema = {
|
|
43
|
+
/**
|
|
44
|
+
* Wrap a JSON Schema object as a StandardSchemaV1.
|
|
45
|
+
* Input type is `unknown` (no compile-time inference).
|
|
46
|
+
*
|
|
47
|
+
* Performs lightweight runtime validation:
|
|
48
|
+
* - Ensures value is an object (when schema type is "object")
|
|
49
|
+
* - Checks `required` fields are present and non-undefined
|
|
50
|
+
*/
|
|
51
|
+
fromJsonSchema(jsonSchema) {
|
|
52
|
+
return {
|
|
53
|
+
"~standard": {
|
|
54
|
+
version: 1,
|
|
55
|
+
vendor: "dex",
|
|
56
|
+
validate: (value) => {
|
|
57
|
+
// Basic structural validation for object schemas
|
|
58
|
+
if (jsonSchema.type === "object") {
|
|
59
|
+
if (value == null || typeof value !== "object") {
|
|
60
|
+
return {
|
|
61
|
+
issues: [
|
|
62
|
+
{
|
|
63
|
+
message: "Expected an object but received " +
|
|
64
|
+
(value === null ? "null" : typeof value),
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
const required = jsonSchema.required;
|
|
70
|
+
if (required?.length) {
|
|
71
|
+
const obj = value;
|
|
72
|
+
const missing = required.filter((k) => !(k in obj) || obj[k] === undefined);
|
|
73
|
+
if (missing.length > 0) {
|
|
74
|
+
return {
|
|
75
|
+
issues: missing.map((k) => ({
|
|
76
|
+
message: `Missing required field: "${k}"`,
|
|
77
|
+
path: [k],
|
|
78
|
+
})),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return { value: value };
|
|
84
|
+
},
|
|
85
|
+
jsonSchema,
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAqCH,wEAAwE;AACxE,0EAA0E;AAC1E,wEAAwE;AAExE;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG;IACrB;;;;;;;OAOG;IACH,cAAc,CACb,UAA4B;QAE5B,OAAO;YACN,WAAW,EAAE;gBACZ,OAAO,EAAE,CAAC;gBACV,MAAM,EAAE,KAAK;gBACb,QAAQ,EAAE,CAAC,KAAc,EAAiB,EAAE;oBAC3C,iDAAiD;oBACjD,IAAI,UAAU,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;wBAClC,IAAI,KAAK,IAAI,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;4BAChD,OAAO;gCACN,MAAM,EAAE;oCACP;wCACC,OAAO,EACN,kCAAkC;4CAClC,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,KAAK,CAAC;qCACzC;iCACD;6BACD,CAAC;wBACH,CAAC;wBACD,MAAM,QAAQ,GAAG,UAAU,CAAC,QAAgC,CAAC;wBAC7D,IAAI,QAAQ,EAAE,MAAM,EAAE,CAAC;4BACtB,MAAM,GAAG,GAAG,KAAgC,CAAC;4BAC7C,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,CAC9B,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,SAAS,CAC1C,CAAC;4BACF,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gCACxB,OAAO;oCACN,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;wCAC3B,OAAO,EAAE,4BAA4B,CAAC,GAAG;wCACzC,IAAI,EAAE,CAAC,CAAC,CAAC;qCACT,CAAC,CAAC;iCACH,CAAC;4BACH,CAAC;wBACF,CAAC;oBACF,CAAC;oBACD,OAAO,EAAE,KAAK,EAAE,KAAc,EAAE,CAAC;gBAClC,CAAC;gBACD,UAAU;aAC8B;SACzC,CAAC;IACH,CAAC;CACD,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** Dispatch one tool call: validate input → execute → return result. */
|
|
2
|
+
import type { AnyTool, Extension, GenerateContext, ToolCall, ToolResult, ToolOutput, ExecuteResult, ErrorSource } from "./index";
|
|
3
|
+
import { type ResolvedCacheConfig } from "./tool-result-cache";
|
|
4
|
+
/** Wrap an execute() return value into a ToolOutput tagged variant. */
|
|
5
|
+
export declare function toToolOutput(result: ExecuteResult<unknown>): ToolOutput;
|
|
6
|
+
export interface DispatchOptions {
|
|
7
|
+
readonly call: ToolCall;
|
|
8
|
+
readonly tool: AnyTool;
|
|
9
|
+
readonly extensions: ReadonlyArray<Extension>;
|
|
10
|
+
readonly gctx: GenerateContext;
|
|
11
|
+
readonly reportError: (err: unknown, source: ErrorSource) => Promise<void>;
|
|
12
|
+
readonly cacheConfig?: ResolvedCacheConfig;
|
|
13
|
+
}
|
|
14
|
+
export interface DispatchOutcome {
|
|
15
|
+
result: ToolResult;
|
|
16
|
+
shortCircuited: boolean;
|
|
17
|
+
executeError?: unknown;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Validate and execute a tool call. Tool-start/tool-stop events are handled
|
|
21
|
+
* by the generate loop — this function only does validation + execution.
|
|
22
|
+
*/
|
|
23
|
+
export declare function dispatchTool(opts: DispatchOptions): Promise<DispatchOutcome>;
|
|
24
|
+
//# sourceMappingURL=tool-dispatch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-dispatch.d.ts","sourceRoot":"","sources":["../src/tool-dispatch.ts"],"names":[],"mappings":"AAAA,wEAAwE;AAExE,OAAO,KAAK,EACX,OAAO,EACP,SAAS,EACT,eAAe,EACf,QAAQ,EACR,UAAU,EACV,UAAU,EACV,aAAa,EACb,WAAW,EACX,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAgB,KAAK,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAgE7E,uEAAuE;AACvE,wBAAgB,YAAY,CAAC,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,GAAG,UAAU,CAcvE;AAED,MAAM,WAAW,eAAe;IAC/B,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,UAAU,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;IAC9C,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAC;IAC/B,QAAQ,CAAC,WAAW,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3E,QAAQ,CAAC,WAAW,CAAC,EAAE,mBAAmB,CAAC;CAC3C;AAED,MAAM,WAAW,eAAe;IAC/B,MAAM,EAAE,UAAU,CAAC;IACnB,cAAc,EAAE,OAAO,CAAC;IACxB,YAAY,CAAC,EAAE,OAAO,CAAC;CACvB;AAED;;;GAGG;AACH,wBAAsB,YAAY,CACjC,IAAI,EAAE,eAAe,GACnB,OAAO,CAAC,eAAe,CAAC,CAkD1B"}
|