@ai-sdk-tool/parser 3.1.0 → 3.1.2
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/{chunk-JVQVEA3K.js → chunk-TQT6XSP7.js} +66 -69
- package/dist/chunk-TQT6XSP7.js.map +1 -0
- package/dist/community.cjs +61 -68
- package/dist/community.cjs.map +1 -1
- package/dist/community.js +1 -1
- package/dist/index.cjs +65 -69
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -3
- package/package.json +5 -5
- package/dist/chunk-JVQVEA3K.js.map +0 -1
|
@@ -332,12 +332,15 @@ function handleOpeningTagSegment(src, lt, out, stack) {
|
|
|
332
332
|
}
|
|
333
333
|
return q + 1;
|
|
334
334
|
}
|
|
335
|
-
function
|
|
335
|
+
function extractSchemaProperties(schema) {
|
|
336
336
|
const unwrapped = unwrapJsonSchema(schema);
|
|
337
337
|
if (!unwrapped || typeof unwrapped !== "object") {
|
|
338
|
-
return
|
|
338
|
+
return void 0;
|
|
339
339
|
}
|
|
340
|
-
|
|
340
|
+
return unwrapped.properties;
|
|
341
|
+
}
|
|
342
|
+
function shouldDeduplicateStringTags(schema) {
|
|
343
|
+
const props = extractSchemaProperties(schema);
|
|
341
344
|
if (!props) {
|
|
342
345
|
return false;
|
|
343
346
|
}
|
|
@@ -349,21 +352,14 @@ function shouldDeduplicateStringTags(schema) {
|
|
|
349
352
|
return (command == null ? void 0 : command.type) === "array";
|
|
350
353
|
}
|
|
351
354
|
function getStringPropertyNames(schema) {
|
|
352
|
-
const
|
|
353
|
-
if (!unwrapped || typeof unwrapped !== "object") {
|
|
354
|
-
return [];
|
|
355
|
-
}
|
|
356
|
-
const props = unwrapped.properties;
|
|
355
|
+
const props = extractSchemaProperties(schema);
|
|
357
356
|
if (!props) {
|
|
358
357
|
return [];
|
|
359
358
|
}
|
|
360
359
|
const names = [];
|
|
361
360
|
for (const key of Object.keys(props)) {
|
|
362
|
-
const prop = unwrapJsonSchema(
|
|
363
|
-
|
|
364
|
-
);
|
|
365
|
-
const type = prop.type;
|
|
366
|
-
if (type === "string") {
|
|
361
|
+
const prop = unwrapJsonSchema(props[key]);
|
|
362
|
+
if ((prop == null ? void 0 : prop.type) === "string") {
|
|
367
363
|
names.push(key);
|
|
368
364
|
}
|
|
369
365
|
}
|
|
@@ -398,11 +394,7 @@ function repairParsedAgainstSchema(input, schema) {
|
|
|
398
394
|
if (!input || typeof input !== "object") {
|
|
399
395
|
return input;
|
|
400
396
|
}
|
|
401
|
-
const
|
|
402
|
-
if (!unwrapped || typeof unwrapped !== "object") {
|
|
403
|
-
return input;
|
|
404
|
-
}
|
|
405
|
-
const properties = unwrapped.properties;
|
|
397
|
+
const properties = extractSchemaProperties(schema);
|
|
406
398
|
if (!properties) {
|
|
407
399
|
return input;
|
|
408
400
|
}
|
|
@@ -416,14 +408,12 @@ function applySchemaProps(obj, properties) {
|
|
|
416
408
|
continue;
|
|
417
409
|
}
|
|
418
410
|
const prop = unwrapJsonSchema(propSchema);
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
const itemSchemaRaw = prop.items;
|
|
422
|
-
const itemSchema = unwrapJsonSchema(itemSchemaRaw);
|
|
411
|
+
if ((prop == null ? void 0 : prop.type) === "array" && prop.items) {
|
|
412
|
+
const itemSchema = unwrapJsonSchema(prop.items);
|
|
423
413
|
obj[key] = coerceArrayItems(obj[key], itemSchema);
|
|
424
414
|
continue;
|
|
425
415
|
}
|
|
426
|
-
if (
|
|
416
|
+
if ((prop == null ? void 0 : prop.type) === "object") {
|
|
427
417
|
const val = obj[key];
|
|
428
418
|
if (val && typeof val === "object") {
|
|
429
419
|
obj[key] = repairParsedAgainstSchema(val, prop);
|
|
@@ -1550,10 +1540,12 @@ var jsonProtocol = ({
|
|
|
1550
1540
|
},
|
|
1551
1541
|
formatToolCall(toolCall) {
|
|
1552
1542
|
let args = {};
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1543
|
+
if (toolCall.input != null) {
|
|
1544
|
+
try {
|
|
1545
|
+
args = JSON.parse(toolCall.input);
|
|
1546
|
+
} catch (e) {
|
|
1547
|
+
args = toolCall.input;
|
|
1548
|
+
}
|
|
1557
1549
|
}
|
|
1558
1550
|
return `${toolCallStart}${JSON.stringify({
|
|
1559
1551
|
name: toolCall.toolName,
|
|
@@ -2185,14 +2177,17 @@ var xmlProtocol = (protocolOptions) => {
|
|
|
2185
2177
|
},
|
|
2186
2178
|
formatToolCall(toolCall) {
|
|
2187
2179
|
let args = {};
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2180
|
+
if (toolCall.input != null) {
|
|
2181
|
+
try {
|
|
2182
|
+
args = JSON.parse(toolCall.input);
|
|
2183
|
+
} catch (e) {
|
|
2184
|
+
args = toolCall.input;
|
|
2185
|
+
}
|
|
2192
2186
|
}
|
|
2193
2187
|
return stringify2(toolCall.toolName, args, {
|
|
2194
2188
|
suppressEmptyNode: false,
|
|
2195
|
-
format:
|
|
2189
|
+
format: true,
|
|
2190
|
+
minimalEscaping: true
|
|
2196
2191
|
});
|
|
2197
2192
|
},
|
|
2198
2193
|
parseGeneratedText({ text, tools, options }) {
|
|
@@ -2582,10 +2577,12 @@ var yamlProtocol = (_protocolOptions) => {
|
|
|
2582
2577
|
},
|
|
2583
2578
|
formatToolCall(toolCall) {
|
|
2584
2579
|
let args = {};
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2580
|
+
if (toolCall.input != null) {
|
|
2581
|
+
try {
|
|
2582
|
+
args = JSON.parse(toolCall.input);
|
|
2583
|
+
} catch (e) {
|
|
2584
|
+
args = { value: toolCall.input };
|
|
2585
|
+
}
|
|
2589
2586
|
}
|
|
2590
2587
|
const yamlContent = YAML.stringify(args);
|
|
2591
2588
|
return `<${toolCall.toolName}>
|
|
@@ -2850,13 +2847,12 @@ function isToolChoiceActive(params) {
|
|
|
2850
2847
|
}
|
|
2851
2848
|
|
|
2852
2849
|
// src/core/utils/type-guards.ts
|
|
2853
|
-
function isToolCallContent(content) {
|
|
2854
|
-
return content.type === "tool-call" && typeof content.toolName === "string" && // input may be a JSON string or an already-parsed object depending on provider/runtime
|
|
2855
|
-
(typeof content.input === "string" || typeof content.input === "object");
|
|
2856
|
-
}
|
|
2857
2850
|
function isToolResultPart(content) {
|
|
2851
|
+
if (!content || typeof content !== "object") {
|
|
2852
|
+
return false;
|
|
2853
|
+
}
|
|
2858
2854
|
const c = content;
|
|
2859
|
-
return
|
|
2855
|
+
return c.type === "tool-result" && typeof c.toolName === "string" && typeof c.toolCallId === "string" && "output" in c;
|
|
2860
2856
|
}
|
|
2861
2857
|
function hasInputProperty(obj) {
|
|
2862
2858
|
return typeof obj === "object" && obj !== null && "input" in obj;
|
|
@@ -3015,18 +3011,17 @@ function fixToolCallWithSchema(part, tools) {
|
|
|
3015
3011
|
if (part.type !== "tool-call") {
|
|
3016
3012
|
return part;
|
|
3017
3013
|
}
|
|
3018
|
-
const tc = part;
|
|
3019
3014
|
let args = {};
|
|
3020
|
-
if (typeof
|
|
3015
|
+
if (typeof part.input === "string") {
|
|
3021
3016
|
try {
|
|
3022
|
-
args = JSON.parse(
|
|
3017
|
+
args = JSON.parse(part.input);
|
|
3023
3018
|
} catch (e) {
|
|
3024
3019
|
return part;
|
|
3025
3020
|
}
|
|
3026
|
-
} else if (
|
|
3027
|
-
args =
|
|
3021
|
+
} else if (part.input && typeof part.input === "object") {
|
|
3022
|
+
args = part.input;
|
|
3028
3023
|
}
|
|
3029
|
-
const schema = (_a = tools.find((t) => t.name ===
|
|
3024
|
+
const schema = (_a = tools.find((t) => t.name === part.toolName)) == null ? void 0 : _a.inputSchema;
|
|
3030
3025
|
const coerced = coerceBySchema(args, schema);
|
|
3031
3026
|
return {
|
|
3032
3027
|
...part,
|
|
@@ -3521,26 +3516,29 @@ function processAssistantContent(content, resolvedProtocol, providerOptions) {
|
|
|
3521
3516
|
var _a;
|
|
3522
3517
|
const newContent = [];
|
|
3523
3518
|
for (const item of content) {
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
options
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
|
|
3542
|
-
|
|
3543
|
-
|
|
3519
|
+
switch (item.type) {
|
|
3520
|
+
case "tool-call":
|
|
3521
|
+
newContent.push({
|
|
3522
|
+
type: "text",
|
|
3523
|
+
text: resolvedProtocol.formatToolCall(item)
|
|
3524
|
+
});
|
|
3525
|
+
break;
|
|
3526
|
+
case "text":
|
|
3527
|
+
case "reasoning":
|
|
3528
|
+
newContent.push(item);
|
|
3529
|
+
break;
|
|
3530
|
+
default: {
|
|
3531
|
+
const options = extractOnErrorOption(providerOptions);
|
|
3532
|
+
(_a = options == null ? void 0 : options.onError) == null ? void 0 : _a.call(
|
|
3533
|
+
options,
|
|
3534
|
+
"tool-call-middleware: unknown assistant content; stringifying for provider compatibility",
|
|
3535
|
+
{ content: item }
|
|
3536
|
+
);
|
|
3537
|
+
newContent.push({
|
|
3538
|
+
type: "text",
|
|
3539
|
+
text: JSON.stringify(item)
|
|
3540
|
+
});
|
|
3541
|
+
}
|
|
3544
3542
|
}
|
|
3545
3543
|
}
|
|
3546
3544
|
const onlyText = newContent.every((c) => c.type === "text");
|
|
@@ -3766,7 +3764,6 @@ export {
|
|
|
3766
3764
|
decodeOriginalTools,
|
|
3767
3765
|
extractToolNamesFromOriginalTools,
|
|
3768
3766
|
isToolChoiceActive,
|
|
3769
|
-
isToolCallContent,
|
|
3770
3767
|
isToolResultPart,
|
|
3771
3768
|
hasInputProperty,
|
|
3772
3769
|
wrapGenerate,
|
|
@@ -3778,4 +3775,4 @@ export {
|
|
|
3778
3775
|
xmlToolMiddleware,
|
|
3779
3776
|
yamlToolMiddleware
|
|
3780
3777
|
};
|
|
3781
|
-
//# sourceMappingURL=chunk-
|
|
3778
|
+
//# sourceMappingURL=chunk-TQT6XSP7.js.map
|