@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
package/dist/community.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -49,7 +49,6 @@ __export(src_exports, {
|
|
|
49
49
|
hermesToolMiddleware: () => hermesToolMiddleware,
|
|
50
50
|
isProtocolFactory: () => isProtocolFactory,
|
|
51
51
|
isTCMProtocolFactory: () => isTCMProtocolFactory,
|
|
52
|
-
isToolCallContent: () => isToolCallContent,
|
|
53
52
|
isToolChoiceActive: () => isToolChoiceActive,
|
|
54
53
|
isToolResultPart: () => isToolResultPart,
|
|
55
54
|
jsonProtocol: () => jsonProtocol,
|
|
@@ -409,12 +408,15 @@ function handleOpeningTagSegment(src, lt, out, stack) {
|
|
|
409
408
|
}
|
|
410
409
|
return q + 1;
|
|
411
410
|
}
|
|
412
|
-
function
|
|
411
|
+
function extractSchemaProperties(schema) {
|
|
413
412
|
const unwrapped = (0, import_rxml.unwrapJsonSchema)(schema);
|
|
414
413
|
if (!unwrapped || typeof unwrapped !== "object") {
|
|
415
|
-
return
|
|
414
|
+
return void 0;
|
|
416
415
|
}
|
|
417
|
-
|
|
416
|
+
return unwrapped.properties;
|
|
417
|
+
}
|
|
418
|
+
function shouldDeduplicateStringTags(schema) {
|
|
419
|
+
const props = extractSchemaProperties(schema);
|
|
418
420
|
if (!props) {
|
|
419
421
|
return false;
|
|
420
422
|
}
|
|
@@ -426,21 +428,14 @@ function shouldDeduplicateStringTags(schema) {
|
|
|
426
428
|
return (command == null ? void 0 : command.type) === "array";
|
|
427
429
|
}
|
|
428
430
|
function getStringPropertyNames(schema) {
|
|
429
|
-
const
|
|
430
|
-
if (!unwrapped || typeof unwrapped !== "object") {
|
|
431
|
-
return [];
|
|
432
|
-
}
|
|
433
|
-
const props = unwrapped.properties;
|
|
431
|
+
const props = extractSchemaProperties(schema);
|
|
434
432
|
if (!props) {
|
|
435
433
|
return [];
|
|
436
434
|
}
|
|
437
435
|
const names = [];
|
|
438
436
|
for (const key of Object.keys(props)) {
|
|
439
|
-
const prop = (0, import_rxml.unwrapJsonSchema)(
|
|
440
|
-
|
|
441
|
-
);
|
|
442
|
-
const type = prop.type;
|
|
443
|
-
if (type === "string") {
|
|
437
|
+
const prop = (0, import_rxml.unwrapJsonSchema)(props[key]);
|
|
438
|
+
if ((prop == null ? void 0 : prop.type) === "string") {
|
|
444
439
|
names.push(key);
|
|
445
440
|
}
|
|
446
441
|
}
|
|
@@ -475,11 +470,7 @@ function repairParsedAgainstSchema(input, schema) {
|
|
|
475
470
|
if (!input || typeof input !== "object") {
|
|
476
471
|
return input;
|
|
477
472
|
}
|
|
478
|
-
const
|
|
479
|
-
if (!unwrapped || typeof unwrapped !== "object") {
|
|
480
|
-
return input;
|
|
481
|
-
}
|
|
482
|
-
const properties = unwrapped.properties;
|
|
473
|
+
const properties = extractSchemaProperties(schema);
|
|
483
474
|
if (!properties) {
|
|
484
475
|
return input;
|
|
485
476
|
}
|
|
@@ -493,14 +484,12 @@ function applySchemaProps(obj, properties) {
|
|
|
493
484
|
continue;
|
|
494
485
|
}
|
|
495
486
|
const prop = (0, import_rxml.unwrapJsonSchema)(propSchema);
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
const itemSchemaRaw = prop.items;
|
|
499
|
-
const itemSchema = (0, import_rxml.unwrapJsonSchema)(itemSchemaRaw);
|
|
487
|
+
if ((prop == null ? void 0 : prop.type) === "array" && prop.items) {
|
|
488
|
+
const itemSchema = (0, import_rxml.unwrapJsonSchema)(prop.items);
|
|
500
489
|
obj[key] = coerceArrayItems(obj[key], itemSchema);
|
|
501
490
|
continue;
|
|
502
491
|
}
|
|
503
|
-
if (
|
|
492
|
+
if ((prop == null ? void 0 : prop.type) === "object") {
|
|
504
493
|
const val = obj[key];
|
|
505
494
|
if (val && typeof val === "object") {
|
|
506
495
|
obj[key] = repairParsedAgainstSchema(val, prop);
|
|
@@ -1627,10 +1616,12 @@ var jsonProtocol = ({
|
|
|
1627
1616
|
},
|
|
1628
1617
|
formatToolCall(toolCall) {
|
|
1629
1618
|
let args = {};
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1619
|
+
if (toolCall.input != null) {
|
|
1620
|
+
try {
|
|
1621
|
+
args = JSON.parse(toolCall.input);
|
|
1622
|
+
} catch (e) {
|
|
1623
|
+
args = toolCall.input;
|
|
1624
|
+
}
|
|
1634
1625
|
}
|
|
1635
1626
|
return `${toolCallStart}${JSON.stringify({
|
|
1636
1627
|
name: toolCall.toolName,
|
|
@@ -2262,14 +2253,17 @@ var xmlProtocol = (protocolOptions) => {
|
|
|
2262
2253
|
},
|
|
2263
2254
|
formatToolCall(toolCall) {
|
|
2264
2255
|
let args = {};
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2256
|
+
if (toolCall.input != null) {
|
|
2257
|
+
try {
|
|
2258
|
+
args = JSON.parse(toolCall.input);
|
|
2259
|
+
} catch (e) {
|
|
2260
|
+
args = toolCall.input;
|
|
2261
|
+
}
|
|
2269
2262
|
}
|
|
2270
2263
|
return (0, import_rxml2.stringify)(toolCall.toolName, args, {
|
|
2271
2264
|
suppressEmptyNode: false,
|
|
2272
|
-
format:
|
|
2265
|
+
format: true,
|
|
2266
|
+
minimalEscaping: true
|
|
2273
2267
|
});
|
|
2274
2268
|
},
|
|
2275
2269
|
parseGeneratedText({ text, tools, options }) {
|
|
@@ -2659,10 +2653,12 @@ var yamlProtocol = (_protocolOptions) => {
|
|
|
2659
2653
|
},
|
|
2660
2654
|
formatToolCall(toolCall) {
|
|
2661
2655
|
let args = {};
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2656
|
+
if (toolCall.input != null) {
|
|
2657
|
+
try {
|
|
2658
|
+
args = JSON.parse(toolCall.input);
|
|
2659
|
+
} catch (e) {
|
|
2660
|
+
args = { value: toolCall.input };
|
|
2661
|
+
}
|
|
2666
2662
|
}
|
|
2667
2663
|
const yamlContent = import_yaml.default.stringify(args);
|
|
2668
2664
|
return `<${toolCall.toolName}>
|
|
@@ -2927,13 +2923,12 @@ function isToolChoiceActive(params) {
|
|
|
2927
2923
|
}
|
|
2928
2924
|
|
|
2929
2925
|
// src/core/utils/type-guards.ts
|
|
2930
|
-
function isToolCallContent(content) {
|
|
2931
|
-
return content.type === "tool-call" && typeof content.toolName === "string" && // input may be a JSON string or an already-parsed object depending on provider/runtime
|
|
2932
|
-
(typeof content.input === "string" || typeof content.input === "object");
|
|
2933
|
-
}
|
|
2934
2926
|
function isToolResultPart(content) {
|
|
2927
|
+
if (!content || typeof content !== "object") {
|
|
2928
|
+
return false;
|
|
2929
|
+
}
|
|
2935
2930
|
const c = content;
|
|
2936
|
-
return
|
|
2931
|
+
return c.type === "tool-result" && typeof c.toolName === "string" && typeof c.toolCallId === "string" && "output" in c;
|
|
2937
2932
|
}
|
|
2938
2933
|
function hasInputProperty(obj) {
|
|
2939
2934
|
return typeof obj === "object" && obj !== null && "input" in obj;
|
|
@@ -3092,18 +3087,17 @@ function fixToolCallWithSchema(part, tools) {
|
|
|
3092
3087
|
if (part.type !== "tool-call") {
|
|
3093
3088
|
return part;
|
|
3094
3089
|
}
|
|
3095
|
-
const tc = part;
|
|
3096
3090
|
let args = {};
|
|
3097
|
-
if (typeof
|
|
3091
|
+
if (typeof part.input === "string") {
|
|
3098
3092
|
try {
|
|
3099
|
-
args = JSON.parse(
|
|
3093
|
+
args = JSON.parse(part.input);
|
|
3100
3094
|
} catch (e) {
|
|
3101
3095
|
return part;
|
|
3102
3096
|
}
|
|
3103
|
-
} else if (
|
|
3104
|
-
args =
|
|
3097
|
+
} else if (part.input && typeof part.input === "object") {
|
|
3098
|
+
args = part.input;
|
|
3105
3099
|
}
|
|
3106
|
-
const schema = (_a = tools.find((t) => t.name ===
|
|
3100
|
+
const schema = (_a = tools.find((t) => t.name === part.toolName)) == null ? void 0 : _a.inputSchema;
|
|
3107
3101
|
const coerced = (0, import_rxml3.coerceBySchema)(args, schema);
|
|
3108
3102
|
return {
|
|
3109
3103
|
...part,
|
|
@@ -3598,26 +3592,29 @@ function processAssistantContent(content, resolvedProtocol, providerOptions) {
|
|
|
3598
3592
|
var _a;
|
|
3599
3593
|
const newContent = [];
|
|
3600
3594
|
for (const item of content) {
|
|
3601
|
-
|
|
3602
|
-
|
|
3603
|
-
|
|
3604
|
-
|
|
3605
|
-
|
|
3606
|
-
|
|
3607
|
-
|
|
3608
|
-
|
|
3609
|
-
|
|
3610
|
-
|
|
3611
|
-
|
|
3612
|
-
|
|
3613
|
-
options
|
|
3614
|
-
|
|
3615
|
-
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
|
-
|
|
3595
|
+
switch (item.type) {
|
|
3596
|
+
case "tool-call":
|
|
3597
|
+
newContent.push({
|
|
3598
|
+
type: "text",
|
|
3599
|
+
text: resolvedProtocol.formatToolCall(item)
|
|
3600
|
+
});
|
|
3601
|
+
break;
|
|
3602
|
+
case "text":
|
|
3603
|
+
case "reasoning":
|
|
3604
|
+
newContent.push(item);
|
|
3605
|
+
break;
|
|
3606
|
+
default: {
|
|
3607
|
+
const options = extractOnErrorOption(providerOptions);
|
|
3608
|
+
(_a = options == null ? void 0 : options.onError) == null ? void 0 : _a.call(
|
|
3609
|
+
options,
|
|
3610
|
+
"tool-call-middleware: unknown assistant content; stringifying for provider compatibility",
|
|
3611
|
+
{ content: item }
|
|
3612
|
+
);
|
|
3613
|
+
newContent.push({
|
|
3614
|
+
type: "text",
|
|
3615
|
+
text: JSON.stringify(item)
|
|
3616
|
+
});
|
|
3617
|
+
}
|
|
3621
3618
|
}
|
|
3622
3619
|
}
|
|
3623
3620
|
const onlyText = newContent.every((c) => c.type === "text");
|
|
@@ -3831,7 +3828,6 @@ var yamlToolMiddleware = createToolMiddleware({
|
|
|
3831
3828
|
hermesToolMiddleware,
|
|
3832
3829
|
isProtocolFactory,
|
|
3833
3830
|
isTCMProtocolFactory,
|
|
3834
|
-
isToolCallContent,
|
|
3835
3831
|
isToolChoiceActive,
|
|
3836
3832
|
isToolResultPart,
|
|
3837
3833
|
jsonProtocol,
|