@ai-sdk-tool/parser 3.1.0 → 3.1.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/{chunk-JVQVEA3K.js → chunk-WX5U7G6L.js} +64 -68
- package/dist/chunk-WX5U7G6L.js.map +1 -0
- package/dist/community.cjs +59 -67
- package/dist/community.cjs.map +1 -1
- package/dist/community.js +1 -1
- package/dist/index.cjs +63 -68
- 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.cjs
CHANGED
|
@@ -346,12 +346,15 @@ function handleOpeningTagSegment(src, lt, out, stack) {
|
|
|
346
346
|
}
|
|
347
347
|
return q + 1;
|
|
348
348
|
}
|
|
349
|
-
function
|
|
349
|
+
function extractSchemaProperties(schema) {
|
|
350
350
|
const unwrapped = (0, import_rxml.unwrapJsonSchema)(schema);
|
|
351
351
|
if (!unwrapped || typeof unwrapped !== "object") {
|
|
352
|
-
return
|
|
352
|
+
return void 0;
|
|
353
353
|
}
|
|
354
|
-
|
|
354
|
+
return unwrapped.properties;
|
|
355
|
+
}
|
|
356
|
+
function shouldDeduplicateStringTags(schema) {
|
|
357
|
+
const props = extractSchemaProperties(schema);
|
|
355
358
|
if (!props) {
|
|
356
359
|
return false;
|
|
357
360
|
}
|
|
@@ -363,21 +366,14 @@ function shouldDeduplicateStringTags(schema) {
|
|
|
363
366
|
return (command == null ? void 0 : command.type) === "array";
|
|
364
367
|
}
|
|
365
368
|
function getStringPropertyNames(schema) {
|
|
366
|
-
const
|
|
367
|
-
if (!unwrapped || typeof unwrapped !== "object") {
|
|
368
|
-
return [];
|
|
369
|
-
}
|
|
370
|
-
const props = unwrapped.properties;
|
|
369
|
+
const props = extractSchemaProperties(schema);
|
|
371
370
|
if (!props) {
|
|
372
371
|
return [];
|
|
373
372
|
}
|
|
374
373
|
const names = [];
|
|
375
374
|
for (const key of Object.keys(props)) {
|
|
376
|
-
const prop = (0, import_rxml.unwrapJsonSchema)(
|
|
377
|
-
|
|
378
|
-
);
|
|
379
|
-
const type = prop.type;
|
|
380
|
-
if (type === "string") {
|
|
375
|
+
const prop = (0, import_rxml.unwrapJsonSchema)(props[key]);
|
|
376
|
+
if ((prop == null ? void 0 : prop.type) === "string") {
|
|
381
377
|
names.push(key);
|
|
382
378
|
}
|
|
383
379
|
}
|
|
@@ -412,11 +408,7 @@ function repairParsedAgainstSchema(input, schema) {
|
|
|
412
408
|
if (!input || typeof input !== "object") {
|
|
413
409
|
return input;
|
|
414
410
|
}
|
|
415
|
-
const
|
|
416
|
-
if (!unwrapped || typeof unwrapped !== "object") {
|
|
417
|
-
return input;
|
|
418
|
-
}
|
|
419
|
-
const properties = unwrapped.properties;
|
|
411
|
+
const properties = extractSchemaProperties(schema);
|
|
420
412
|
if (!properties) {
|
|
421
413
|
return input;
|
|
422
414
|
}
|
|
@@ -430,14 +422,12 @@ function applySchemaProps(obj, properties) {
|
|
|
430
422
|
continue;
|
|
431
423
|
}
|
|
432
424
|
const prop = (0, import_rxml.unwrapJsonSchema)(propSchema);
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
const itemSchemaRaw = prop.items;
|
|
436
|
-
const itemSchema = (0, import_rxml.unwrapJsonSchema)(itemSchemaRaw);
|
|
425
|
+
if ((prop == null ? void 0 : prop.type) === "array" && prop.items) {
|
|
426
|
+
const itemSchema = (0, import_rxml.unwrapJsonSchema)(prop.items);
|
|
437
427
|
obj[key] = coerceArrayItems(obj[key], itemSchema);
|
|
438
428
|
continue;
|
|
439
429
|
}
|
|
440
|
-
if (
|
|
430
|
+
if ((prop == null ? void 0 : prop.type) === "object") {
|
|
441
431
|
const val = obj[key];
|
|
442
432
|
if (val && typeof val === "object") {
|
|
443
433
|
obj[key] = repairParsedAgainstSchema(val, prop);
|
|
@@ -1536,10 +1526,12 @@ var jsonProtocol = ({
|
|
|
1536
1526
|
},
|
|
1537
1527
|
formatToolCall(toolCall) {
|
|
1538
1528
|
let args = {};
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1529
|
+
if (toolCall.input != null) {
|
|
1530
|
+
try {
|
|
1531
|
+
args = JSON.parse(toolCall.input);
|
|
1532
|
+
} catch (e) {
|
|
1533
|
+
args = toolCall.input;
|
|
1534
|
+
}
|
|
1543
1535
|
}
|
|
1544
1536
|
return `${toolCallStart}${JSON.stringify({
|
|
1545
1537
|
name: toolCall.toolName,
|
|
@@ -2168,10 +2160,12 @@ var xmlProtocol = (protocolOptions) => {
|
|
|
2168
2160
|
},
|
|
2169
2161
|
formatToolCall(toolCall) {
|
|
2170
2162
|
let args = {};
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2163
|
+
if (toolCall.input != null) {
|
|
2164
|
+
try {
|
|
2165
|
+
args = JSON.parse(toolCall.input);
|
|
2166
|
+
} catch (e) {
|
|
2167
|
+
args = toolCall.input;
|
|
2168
|
+
}
|
|
2175
2169
|
}
|
|
2176
2170
|
return (0, import_rxml2.stringify)(toolCall.toolName, args, {
|
|
2177
2171
|
suppressEmptyNode: false,
|
|
@@ -2565,10 +2559,12 @@ var yamlProtocol = (_protocolOptions) => {
|
|
|
2565
2559
|
},
|
|
2566
2560
|
formatToolCall(toolCall) {
|
|
2567
2561
|
let args = {};
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2562
|
+
if (toolCall.input != null) {
|
|
2563
|
+
try {
|
|
2564
|
+
args = JSON.parse(toolCall.input);
|
|
2565
|
+
} catch (e) {
|
|
2566
|
+
args = { value: toolCall.input };
|
|
2567
|
+
}
|
|
2572
2568
|
}
|
|
2573
2569
|
const yamlContent = import_yaml.default.stringify(args);
|
|
2574
2570
|
return `<${toolCall.toolName}>
|
|
@@ -2829,12 +2825,6 @@ function isToolChoiceActive(params) {
|
|
|
2829
2825
|
return !!(typeof params.providerOptions === "object" && params.providerOptions !== null && typeof ((_c = params.providerOptions) == null ? void 0 : _c.toolCallMiddleware) === "object" && toolChoice && typeof toolChoice === "object" && (toolChoice.type === "tool" || toolChoice.type === "required"));
|
|
2830
2826
|
}
|
|
2831
2827
|
|
|
2832
|
-
// src/core/utils/type-guards.ts
|
|
2833
|
-
function isToolCallContent(content) {
|
|
2834
|
-
return content.type === "tool-call" && typeof content.toolName === "string" && // input may be a JSON string or an already-parsed object depending on provider/runtime
|
|
2835
|
-
(typeof content.input === "string" || typeof content.input === "object");
|
|
2836
|
-
}
|
|
2837
|
-
|
|
2838
2828
|
// src/generate-handler.ts
|
|
2839
2829
|
var import_provider_utils = require("@ai-sdk/provider-utils");
|
|
2840
2830
|
var import_rxml3 = require("@ai-sdk-tool/rxml");
|
|
@@ -2988,18 +2978,17 @@ function fixToolCallWithSchema(part, tools) {
|
|
|
2988
2978
|
if (part.type !== "tool-call") {
|
|
2989
2979
|
return part;
|
|
2990
2980
|
}
|
|
2991
|
-
const tc = part;
|
|
2992
2981
|
let args = {};
|
|
2993
|
-
if (typeof
|
|
2982
|
+
if (typeof part.input === "string") {
|
|
2994
2983
|
try {
|
|
2995
|
-
args = JSON.parse(
|
|
2984
|
+
args = JSON.parse(part.input);
|
|
2996
2985
|
} catch (e) {
|
|
2997
2986
|
return part;
|
|
2998
2987
|
}
|
|
2999
|
-
} else if (
|
|
3000
|
-
args =
|
|
2988
|
+
} else if (part.input && typeof part.input === "object") {
|
|
2989
|
+
args = part.input;
|
|
3001
2990
|
}
|
|
3002
|
-
const schema = (_a = tools.find((t) => t.name ===
|
|
2991
|
+
const schema = (_a = tools.find((t) => t.name === part.toolName)) == null ? void 0 : _a.inputSchema;
|
|
3003
2992
|
const coerced = (0, import_rxml3.coerceBySchema)(args, schema);
|
|
3004
2993
|
return {
|
|
3005
2994
|
...part,
|
|
@@ -3494,26 +3483,29 @@ function processAssistantContent(content, resolvedProtocol, providerOptions) {
|
|
|
3494
3483
|
var _a;
|
|
3495
3484
|
const newContent = [];
|
|
3496
3485
|
for (const item of content) {
|
|
3497
|
-
|
|
3498
|
-
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
options
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
|
|
3486
|
+
switch (item.type) {
|
|
3487
|
+
case "tool-call":
|
|
3488
|
+
newContent.push({
|
|
3489
|
+
type: "text",
|
|
3490
|
+
text: resolvedProtocol.formatToolCall(item)
|
|
3491
|
+
});
|
|
3492
|
+
break;
|
|
3493
|
+
case "text":
|
|
3494
|
+
case "reasoning":
|
|
3495
|
+
newContent.push(item);
|
|
3496
|
+
break;
|
|
3497
|
+
default: {
|
|
3498
|
+
const options = extractOnErrorOption(providerOptions);
|
|
3499
|
+
(_a = options == null ? void 0 : options.onError) == null ? void 0 : _a.call(
|
|
3500
|
+
options,
|
|
3501
|
+
"tool-call-middleware: unknown assistant content; stringifying for provider compatibility",
|
|
3502
|
+
{ content: item }
|
|
3503
|
+
);
|
|
3504
|
+
newContent.push({
|
|
3505
|
+
type: "text",
|
|
3506
|
+
text: JSON.stringify(item)
|
|
3507
|
+
});
|
|
3508
|
+
}
|
|
3517
3509
|
}
|
|
3518
3510
|
}
|
|
3519
3511
|
const onlyText = newContent.every((c) => c.type === "text");
|