@ai-sdk-tool/parser 3.1.2 → 3.2.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/{chunk-TQT6XSP7.js → chunk-PIUBQRFC.js} +166 -1374
- package/dist/chunk-PIUBQRFC.js.map +1 -0
- package/dist/community.cjs +216 -1310
- package/dist/community.cjs.map +1 -1
- package/dist/community.js +1 -1
- package/dist/index.cjs +168 -1388
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -171
- package/dist/index.d.ts +9 -171
- package/dist/index.js +1 -25
- package/package.json +11 -9
- package/dist/chunk-TQT6XSP7.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -17,6 +17,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
}
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
20
21
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
22
|
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
23
|
// file that has been converted to a CommonJS file using a Babel-
|
|
@@ -30,17 +31,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
31
|
// src/index.ts
|
|
31
32
|
var src_exports = {};
|
|
32
33
|
__export(src_exports, {
|
|
33
|
-
applyHeuristicPipeline: () => applyHeuristicPipeline,
|
|
34
|
-
balanceTagsHeuristic: () => balanceTagsHeuristic,
|
|
35
34
|
createDynamicIfThenElseSchema: () => createDynamicIfThenElseSchema,
|
|
36
|
-
createIntermediateCall: () => createIntermediateCall,
|
|
37
35
|
createToolMiddleware: () => createToolMiddleware,
|
|
38
36
|
decodeOriginalTools: () => decodeOriginalTools,
|
|
39
|
-
dedupeShellStringTagsHeuristic: () => dedupeShellStringTagsHeuristic,
|
|
40
|
-
defaultPipelineConfig: () => defaultPipelineConfig,
|
|
41
37
|
encodeOriginalTools: () => encodeOriginalTools,
|
|
42
|
-
|
|
43
|
-
escapeRegExp: () => escapeRegExp2,
|
|
38
|
+
escapeRegExp: () => escapeRegExp,
|
|
44
39
|
extractOnErrorOption: () => extractOnErrorOption,
|
|
45
40
|
extractToolNamesFromOriginalTools: () => extractToolNamesFromOriginalTools,
|
|
46
41
|
getDebugLevel: () => getDebugLevel,
|
|
@@ -56,14 +51,8 @@ __export(src_exports, {
|
|
|
56
51
|
logParsedChunk: () => logParsedChunk,
|
|
57
52
|
logParsedSummary: () => logParsedSummary,
|
|
58
53
|
logRawChunk: () => logRawChunk,
|
|
59
|
-
mergePipelineConfigs: () => mergePipelineConfigs,
|
|
60
|
-
normalizeCloseTagsHeuristic: () => normalizeCloseTagsHeuristic,
|
|
61
54
|
originalToolsSchema: () => originalToolsSchema,
|
|
62
|
-
parse: () => parse2,
|
|
63
|
-
repairAgainstSchemaHeuristic: () => repairAgainstSchemaHeuristic,
|
|
64
|
-
stringify: () => stringify,
|
|
65
55
|
toolChoiceStream: () => toolChoiceStream,
|
|
66
|
-
transform: () => transform,
|
|
67
56
|
transformParams: () => transformParams,
|
|
68
57
|
wrapGenerate: () => wrapGenerate,
|
|
69
58
|
wrapStream: () => wrapStream,
|
|
@@ -73,473 +62,10 @@ __export(src_exports, {
|
|
|
73
62
|
yamlToolMiddleware: () => yamlToolMiddleware
|
|
74
63
|
});
|
|
75
64
|
module.exports = __toCommonJS(src_exports);
|
|
65
|
+
__reExport(src_exports, require("@ai-sdk-tool/rjson"), module.exports);
|
|
76
66
|
|
|
77
|
-
// src/core/
|
|
78
|
-
|
|
79
|
-
if (result.rawSegment !== void 0) {
|
|
80
|
-
return { ...current, rawSegment: result.rawSegment };
|
|
81
|
-
}
|
|
82
|
-
return current;
|
|
83
|
-
}
|
|
84
|
-
function applyParsedUpdate(current, result) {
|
|
85
|
-
if (result.parsed !== void 0) {
|
|
86
|
-
return { ...current, parsed: result.parsed };
|
|
87
|
-
}
|
|
88
|
-
return current;
|
|
89
|
-
}
|
|
90
|
-
function applyWarningsUpdate(current, result) {
|
|
91
|
-
var _a, _b;
|
|
92
|
-
if (result.warnings && result.warnings.length > 0) {
|
|
93
|
-
const meta = (_a = current.meta) != null ? _a : {};
|
|
94
|
-
const existingWarnings = (_b = meta.warnings) != null ? _b : [];
|
|
95
|
-
return {
|
|
96
|
-
...current,
|
|
97
|
-
meta: { ...meta, warnings: [...existingWarnings, ...result.warnings] }
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
return current;
|
|
101
|
-
}
|
|
102
|
-
function attemptReparse(current, result, reparseCount, maxReparses, parse4) {
|
|
103
|
-
if (!result.reparse || result.rawSegment === void 0 || reparseCount >= maxReparses) {
|
|
104
|
-
return { state: current, newCount: reparseCount };
|
|
105
|
-
}
|
|
106
|
-
try {
|
|
107
|
-
const reparsed = parse4(result.rawSegment, current.schema);
|
|
108
|
-
return {
|
|
109
|
-
state: { ...current, parsed: reparsed, errors: [] },
|
|
110
|
-
newCount: reparseCount + 1
|
|
111
|
-
};
|
|
112
|
-
} catch (error) {
|
|
113
|
-
return {
|
|
114
|
-
state: { ...current, errors: [...current.errors, error] },
|
|
115
|
-
newCount: reparseCount + 1
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
function executePhase(ctx, heuristics, options) {
|
|
120
|
-
var _a;
|
|
121
|
-
let current = ctx;
|
|
122
|
-
let reparseCount = 0;
|
|
123
|
-
const maxReparses = (_a = options.maxReparses) != null ? _a : 2;
|
|
124
|
-
for (const heuristic of heuristics) {
|
|
125
|
-
if (!heuristic.applies(current)) {
|
|
126
|
-
continue;
|
|
127
|
-
}
|
|
128
|
-
const result = heuristic.run(current);
|
|
129
|
-
current = applyRawSegmentUpdate(current, result);
|
|
130
|
-
current = applyParsedUpdate(current, result);
|
|
131
|
-
current = applyWarningsUpdate(current, result);
|
|
132
|
-
const reparseResult = attemptReparse(
|
|
133
|
-
current,
|
|
134
|
-
result,
|
|
135
|
-
reparseCount,
|
|
136
|
-
maxReparses,
|
|
137
|
-
options.parse
|
|
138
|
-
);
|
|
139
|
-
current = reparseResult.state;
|
|
140
|
-
reparseCount = reparseResult.newCount;
|
|
141
|
-
if (result.stop) {
|
|
142
|
-
break;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
return current;
|
|
146
|
-
}
|
|
147
|
-
function applyHeuristicPipeline(ctx, config, options) {
|
|
148
|
-
let current = ctx;
|
|
149
|
-
if (config.preParse && config.preParse.length > 0) {
|
|
150
|
-
current = executePhase(current, config.preParse, options);
|
|
151
|
-
}
|
|
152
|
-
if (current.parsed === null && current.errors.length === 0) {
|
|
153
|
-
try {
|
|
154
|
-
const parsed = options.parse(current.rawSegment, current.schema);
|
|
155
|
-
current = { ...current, parsed, errors: [] };
|
|
156
|
-
} catch (error) {
|
|
157
|
-
current = { ...current, errors: [error] };
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
if (current.errors.length > 0 && config.fallbackReparse && config.fallbackReparse.length > 0) {
|
|
161
|
-
current = executePhase(current, config.fallbackReparse, options);
|
|
162
|
-
}
|
|
163
|
-
if (current.parsed !== null && config.postParse && config.postParse.length > 0) {
|
|
164
|
-
current = executePhase(current, config.postParse, options);
|
|
165
|
-
}
|
|
166
|
-
return current;
|
|
167
|
-
}
|
|
168
|
-
function createIntermediateCall(toolName, rawSegment, schema) {
|
|
169
|
-
return {
|
|
170
|
-
toolName,
|
|
171
|
-
schema,
|
|
172
|
-
rawSegment,
|
|
173
|
-
parsed: null,
|
|
174
|
-
errors: [],
|
|
175
|
-
meta: { originalContent: rawSegment }
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
function mergePipelineConfigs(...configs) {
|
|
179
|
-
var _a, _b, _c;
|
|
180
|
-
const result = {
|
|
181
|
-
preParse: [],
|
|
182
|
-
fallbackReparse: [],
|
|
183
|
-
postParse: []
|
|
184
|
-
};
|
|
185
|
-
for (const config of configs) {
|
|
186
|
-
if (config.preParse) {
|
|
187
|
-
result.preParse = [...(_a = result.preParse) != null ? _a : [], ...config.preParse];
|
|
188
|
-
}
|
|
189
|
-
if (config.fallbackReparse) {
|
|
190
|
-
result.fallbackReparse = [
|
|
191
|
-
...(_b = result.fallbackReparse) != null ? _b : [],
|
|
192
|
-
...config.fallbackReparse
|
|
193
|
-
];
|
|
194
|
-
}
|
|
195
|
-
if (config.postParse) {
|
|
196
|
-
result.postParse = [...(_c = result.postParse) != null ? _c : [], ...config.postParse];
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
return result;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
// src/core/heuristics/xml-defaults.ts
|
|
203
|
-
var import_rxml = require("@ai-sdk-tool/rxml");
|
|
204
|
-
var MALFORMED_CLOSE_RE_G = /<\/\s+([A-Za-z0-9_:-]+)\s*>/g;
|
|
205
|
-
var MALFORMED_CLOSE_RE = /<\/\s+([A-Za-z0-9_:-]+)\s*>/;
|
|
206
|
-
var STATUS_TO_STEP_BOUNDARY_RE = /<\/status>\s*<step>/g;
|
|
207
|
-
var WHITESPACE_REGEX = /\s/;
|
|
208
|
-
var NAME_CHAR_RE = /[A-Za-z0-9_:-]/;
|
|
209
|
-
var NAME_START_CHAR_RE = /[A-Za-z_:]/;
|
|
210
|
-
var STEP_TAG_RE = /<step>([\s\S]*?)<\/step>/i;
|
|
211
|
-
var STATUS_TAG_RE = /<status>([\s\S]*?)<\/status>/i;
|
|
212
|
-
var normalizeCloseTagsHeuristic = {
|
|
213
|
-
id: "normalize-close-tags",
|
|
214
|
-
phase: "pre-parse",
|
|
215
|
-
applies: () => true,
|
|
216
|
-
run: (ctx) => {
|
|
217
|
-
const normalized = ctx.rawSegment.replace(MALFORMED_CLOSE_RE_G, "</$1>");
|
|
218
|
-
if (normalized !== ctx.rawSegment) {
|
|
219
|
-
return { rawSegment: normalized };
|
|
220
|
-
}
|
|
221
|
-
return {};
|
|
222
|
-
}
|
|
223
|
-
};
|
|
224
|
-
var escapeInvalidLtHeuristic = {
|
|
225
|
-
id: "escape-invalid-lt",
|
|
226
|
-
phase: "pre-parse",
|
|
227
|
-
applies: () => true,
|
|
228
|
-
run: (ctx) => {
|
|
229
|
-
const escaped = escapeInvalidLt(ctx.rawSegment);
|
|
230
|
-
if (escaped !== ctx.rawSegment) {
|
|
231
|
-
return { rawSegment: escaped };
|
|
232
|
-
}
|
|
233
|
-
return {};
|
|
234
|
-
}
|
|
235
|
-
};
|
|
236
|
-
var balanceTagsHeuristic = {
|
|
237
|
-
id: "balance-tags",
|
|
238
|
-
phase: "fallback-reparse",
|
|
239
|
-
applies: (ctx) => {
|
|
240
|
-
var _a;
|
|
241
|
-
const original = ((_a = ctx.meta) == null ? void 0 : _a.originalContent) || ctx.rawSegment;
|
|
242
|
-
const normalized = original.replace(MALFORMED_CLOSE_RE_G, "</$1>");
|
|
243
|
-
const balanced = balanceTags(original);
|
|
244
|
-
const hasMalformedClose = MALFORMED_CLOSE_RE.test(original);
|
|
245
|
-
if (!hasMalformedClose && balanced.length > normalized.length) {
|
|
246
|
-
return false;
|
|
247
|
-
}
|
|
248
|
-
return balanced !== normalized;
|
|
249
|
-
},
|
|
250
|
-
run: (ctx) => {
|
|
251
|
-
var _a;
|
|
252
|
-
const original = ((_a = ctx.meta) == null ? void 0 : _a.originalContent) || ctx.rawSegment;
|
|
253
|
-
const balanced = balanceTags(original);
|
|
254
|
-
const escaped = escapeInvalidLt(balanced);
|
|
255
|
-
return { rawSegment: escaped, reparse: true };
|
|
256
|
-
}
|
|
257
|
-
};
|
|
258
|
-
var dedupeShellStringTagsHeuristic = {
|
|
259
|
-
id: "dedupe-shell-string-tags",
|
|
260
|
-
phase: "fallback-reparse",
|
|
261
|
-
applies: (ctx) => shouldDeduplicateStringTags(ctx.schema),
|
|
262
|
-
run: (ctx) => {
|
|
263
|
-
const names = getStringPropertyNames(ctx.schema);
|
|
264
|
-
let deduped = ctx.rawSegment;
|
|
265
|
-
for (const key of names) {
|
|
266
|
-
deduped = dedupeSingleTag(deduped, key);
|
|
267
|
-
}
|
|
268
|
-
if (deduped !== ctx.rawSegment) {
|
|
269
|
-
return { rawSegment: deduped, reparse: true };
|
|
270
|
-
}
|
|
271
|
-
return {};
|
|
272
|
-
}
|
|
273
|
-
};
|
|
274
|
-
var repairAgainstSchemaHeuristic = {
|
|
275
|
-
id: "repair-against-schema",
|
|
276
|
-
phase: "post-parse",
|
|
277
|
-
applies: (ctx) => ctx.parsed !== null && typeof ctx.parsed === "object",
|
|
278
|
-
run: (ctx) => {
|
|
279
|
-
const repaired = repairParsedAgainstSchema(ctx.parsed, ctx.schema);
|
|
280
|
-
if (repaired !== ctx.parsed) {
|
|
281
|
-
return { parsed: repaired };
|
|
282
|
-
}
|
|
283
|
-
return {};
|
|
284
|
-
}
|
|
285
|
-
};
|
|
286
|
-
var defaultPipelineConfig = {
|
|
287
|
-
preParse: [normalizeCloseTagsHeuristic, escapeInvalidLtHeuristic],
|
|
288
|
-
fallbackReparse: [balanceTagsHeuristic, dedupeShellStringTagsHeuristic],
|
|
289
|
-
postParse: [repairAgainstSchemaHeuristic]
|
|
290
|
-
};
|
|
291
|
-
var INDEX_TAG_RE = /^<(\d+)(?:>|\/?>)/;
|
|
292
|
-
function isIndexTagAt(xml, pos) {
|
|
293
|
-
const remaining = xml.slice(pos);
|
|
294
|
-
return INDEX_TAG_RE.test(remaining);
|
|
295
|
-
}
|
|
296
|
-
function escapeInvalidLt(xml) {
|
|
297
|
-
const len = xml.length;
|
|
298
|
-
let out = "";
|
|
299
|
-
for (let i = 0; i < len; i += 1) {
|
|
300
|
-
const ch = xml[i];
|
|
301
|
-
if (ch === "<") {
|
|
302
|
-
const next = i + 1 < len ? xml[i + 1] : "";
|
|
303
|
-
const isValidStart = NAME_START_CHAR_RE.test(next) || next === "/" || next === "!" || next === "?";
|
|
304
|
-
const isIndexTag = !isValidStart && isIndexTagAt(xml, i);
|
|
305
|
-
if (!(isValidStart || isIndexTag)) {
|
|
306
|
-
out += "<";
|
|
307
|
-
continue;
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
out += ch;
|
|
311
|
-
}
|
|
312
|
-
return out;
|
|
313
|
-
}
|
|
314
|
-
function balanceTags(xml) {
|
|
315
|
-
const src = xml.replace(MALFORMED_CLOSE_RE_G, "</$1>").replace(STATUS_TO_STEP_BOUNDARY_RE, "</status></step><step>");
|
|
316
|
-
let i = 0;
|
|
317
|
-
const len = src.length;
|
|
318
|
-
const out = [];
|
|
319
|
-
const stack = [];
|
|
320
|
-
while (i < len) {
|
|
321
|
-
const lt = src.indexOf("<", i);
|
|
322
|
-
if (lt === -1) {
|
|
323
|
-
out.push(src.slice(i));
|
|
324
|
-
break;
|
|
325
|
-
}
|
|
326
|
-
out.push(src.slice(i, lt));
|
|
327
|
-
if (lt + 1 >= len) {
|
|
328
|
-
break;
|
|
329
|
-
}
|
|
330
|
-
const next = src[lt + 1];
|
|
331
|
-
if (next === "!" || next === "?") {
|
|
332
|
-
i = handleSpecialTagSegment(src, lt, out);
|
|
333
|
-
continue;
|
|
334
|
-
}
|
|
335
|
-
if (next === "/") {
|
|
336
|
-
i = handleClosingTagSegment(src, lt, out, stack);
|
|
337
|
-
continue;
|
|
338
|
-
}
|
|
339
|
-
i = handleOpeningTagSegment(src, lt, out, stack);
|
|
340
|
-
}
|
|
341
|
-
for (let k = stack.length - 1; k >= 0; k -= 1) {
|
|
342
|
-
out.push(`</${stack[k]}>`);
|
|
343
|
-
}
|
|
344
|
-
return out.join("");
|
|
345
|
-
}
|
|
346
|
-
function skipWs(s, p, len) {
|
|
347
|
-
let idx = p;
|
|
348
|
-
while (idx < len && WHITESPACE_REGEX.test(s[idx])) {
|
|
349
|
-
idx += 1;
|
|
350
|
-
}
|
|
351
|
-
return idx;
|
|
352
|
-
}
|
|
353
|
-
function parseTagNameAt(s, p, len) {
|
|
354
|
-
let idx = p;
|
|
355
|
-
const start = idx;
|
|
356
|
-
while (idx < len && NAME_CHAR_RE.test(s[idx])) {
|
|
357
|
-
idx += 1;
|
|
358
|
-
}
|
|
359
|
-
return { name: s.slice(start, idx), pos: idx };
|
|
360
|
-
}
|
|
361
|
-
function handleSpecialTagSegment(src, lt, out) {
|
|
362
|
-
const gt = src.indexOf(">", lt + 1);
|
|
363
|
-
if (gt === -1) {
|
|
364
|
-
out.push(src.slice(lt));
|
|
365
|
-
return src.length;
|
|
366
|
-
}
|
|
367
|
-
out.push(src.slice(lt, gt + 1));
|
|
368
|
-
return gt + 1;
|
|
369
|
-
}
|
|
370
|
-
function handleClosingTagSegment(src, lt, out, stack) {
|
|
371
|
-
const len = src.length;
|
|
372
|
-
let p = skipWs(src, lt + 2, len);
|
|
373
|
-
const { name, pos } = parseTagNameAt(src, p, len);
|
|
374
|
-
p = pos;
|
|
375
|
-
const gt = src.indexOf(">", p);
|
|
376
|
-
const closingText = gt === -1 ? src.slice(lt) : src.slice(lt, gt + 1);
|
|
377
|
-
const idx = stack.lastIndexOf(name);
|
|
378
|
-
if (idx !== -1) {
|
|
379
|
-
for (let k = stack.length - 1; k > idx; k -= 1) {
|
|
380
|
-
out.push(`</${stack[k]}>`);
|
|
381
|
-
stack.pop();
|
|
382
|
-
}
|
|
383
|
-
out.push(closingText);
|
|
384
|
-
stack.pop();
|
|
385
|
-
}
|
|
386
|
-
return gt === -1 ? len : gt + 1;
|
|
387
|
-
}
|
|
388
|
-
function handleOpeningTagSegment(src, lt, out, stack) {
|
|
389
|
-
const len = src.length;
|
|
390
|
-
let p = skipWs(src, lt + 1, len);
|
|
391
|
-
const nameStart = p;
|
|
392
|
-
const parsed = parseTagNameAt(src, p, len);
|
|
393
|
-
p = parsed.pos;
|
|
394
|
-
const name = src.slice(nameStart, p);
|
|
395
|
-
const q = src.indexOf(">", p);
|
|
396
|
-
if (q === -1) {
|
|
397
|
-
out.push(src.slice(lt));
|
|
398
|
-
return len;
|
|
399
|
-
}
|
|
400
|
-
let r = q - 1;
|
|
401
|
-
while (r >= nameStart && WHITESPACE_REGEX.test(src[r])) {
|
|
402
|
-
r -= 1;
|
|
403
|
-
}
|
|
404
|
-
const selfClosing = src[r] === "/";
|
|
405
|
-
out.push(src.slice(lt, q + 1));
|
|
406
|
-
if (!selfClosing && name) {
|
|
407
|
-
stack.push(name);
|
|
408
|
-
}
|
|
409
|
-
return q + 1;
|
|
410
|
-
}
|
|
411
|
-
function extractSchemaProperties(schema) {
|
|
412
|
-
const unwrapped = (0, import_rxml.unwrapJsonSchema)(schema);
|
|
413
|
-
if (!unwrapped || typeof unwrapped !== "object") {
|
|
414
|
-
return void 0;
|
|
415
|
-
}
|
|
416
|
-
return unwrapped.properties;
|
|
417
|
-
}
|
|
418
|
-
function shouldDeduplicateStringTags(schema) {
|
|
419
|
-
const props = extractSchemaProperties(schema);
|
|
420
|
-
if (!props) {
|
|
421
|
-
return false;
|
|
422
|
-
}
|
|
423
|
-
const commandRaw = props.command;
|
|
424
|
-
if (!commandRaw) {
|
|
425
|
-
return false;
|
|
426
|
-
}
|
|
427
|
-
const command = (0, import_rxml.unwrapJsonSchema)(commandRaw);
|
|
428
|
-
return (command == null ? void 0 : command.type) === "array";
|
|
429
|
-
}
|
|
430
|
-
function getStringPropertyNames(schema) {
|
|
431
|
-
const props = extractSchemaProperties(schema);
|
|
432
|
-
if (!props) {
|
|
433
|
-
return [];
|
|
434
|
-
}
|
|
435
|
-
const names = [];
|
|
436
|
-
for (const key of Object.keys(props)) {
|
|
437
|
-
const prop = (0, import_rxml.unwrapJsonSchema)(props[key]);
|
|
438
|
-
if ((prop == null ? void 0 : prop.type) === "string") {
|
|
439
|
-
names.push(key);
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
return names;
|
|
443
|
-
}
|
|
444
|
-
function escapeRegExp(s) {
|
|
445
|
-
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
446
|
-
}
|
|
447
|
-
function dedupeSingleTag(xml, key) {
|
|
448
|
-
var _a, _b;
|
|
449
|
-
const escaped = escapeRegExp(key);
|
|
450
|
-
const re = new RegExp(`<${escaped}>([\\s\\S]*?)<\\/${escaped}>`, "g");
|
|
451
|
-
const matches = Array.from(xml.matchAll(re));
|
|
452
|
-
if (matches.length <= 1) {
|
|
453
|
-
return xml;
|
|
454
|
-
}
|
|
455
|
-
const last = matches.at(-1);
|
|
456
|
-
let result = "";
|
|
457
|
-
let cursor = 0;
|
|
458
|
-
for (const m of matches) {
|
|
459
|
-
const idx = (_a = m.index) != null ? _a : 0;
|
|
460
|
-
result += xml.slice(cursor, idx);
|
|
461
|
-
if (last && idx === ((_b = last.index) != null ? _b : -1)) {
|
|
462
|
-
result += m[0];
|
|
463
|
-
}
|
|
464
|
-
cursor = idx + m[0].length;
|
|
465
|
-
}
|
|
466
|
-
result += xml.slice(cursor);
|
|
467
|
-
return result;
|
|
468
|
-
}
|
|
469
|
-
function repairParsedAgainstSchema(input, schema) {
|
|
470
|
-
if (!input || typeof input !== "object") {
|
|
471
|
-
return input;
|
|
472
|
-
}
|
|
473
|
-
const properties = extractSchemaProperties(schema);
|
|
474
|
-
if (!properties) {
|
|
475
|
-
return input;
|
|
476
|
-
}
|
|
477
|
-
applySchemaProps(input, properties);
|
|
478
|
-
return input;
|
|
479
|
-
}
|
|
480
|
-
function applySchemaProps(obj, properties) {
|
|
481
|
-
for (const key of Object.keys(obj)) {
|
|
482
|
-
const propSchema = properties[key];
|
|
483
|
-
if (!propSchema) {
|
|
484
|
-
continue;
|
|
485
|
-
}
|
|
486
|
-
const prop = (0, import_rxml.unwrapJsonSchema)(propSchema);
|
|
487
|
-
if ((prop == null ? void 0 : prop.type) === "array" && prop.items) {
|
|
488
|
-
const itemSchema = (0, import_rxml.unwrapJsonSchema)(prop.items);
|
|
489
|
-
obj[key] = coerceArrayItems(obj[key], itemSchema);
|
|
490
|
-
continue;
|
|
491
|
-
}
|
|
492
|
-
if ((prop == null ? void 0 : prop.type) === "object") {
|
|
493
|
-
const val = obj[key];
|
|
494
|
-
if (val && typeof val === "object") {
|
|
495
|
-
obj[key] = repairParsedAgainstSchema(val, prop);
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
function coerceArrayItems(val, itemSchema) {
|
|
501
|
-
if (!Array.isArray(val)) {
|
|
502
|
-
return val;
|
|
503
|
-
}
|
|
504
|
-
return val.map((v) => coerceArrayItem(v, itemSchema));
|
|
505
|
-
}
|
|
506
|
-
function coerceArrayItem(v, itemSchema) {
|
|
507
|
-
const itemType = itemSchema == null ? void 0 : itemSchema.type;
|
|
508
|
-
if (typeof v === "string" && itemType === "object") {
|
|
509
|
-
const parsed = tryParseStringToSchemaObject(v, itemSchema);
|
|
510
|
-
if (parsed !== null) {
|
|
511
|
-
return parsed;
|
|
512
|
-
}
|
|
513
|
-
const fallback = extractStepStatusFromString(
|
|
514
|
-
v.replace(MALFORMED_CLOSE_RE_G, "</$1>")
|
|
515
|
-
);
|
|
516
|
-
if (fallback) {
|
|
517
|
-
return fallback;
|
|
518
|
-
}
|
|
519
|
-
return v;
|
|
520
|
-
}
|
|
521
|
-
if (v && typeof v === "object" && itemType === "object") {
|
|
522
|
-
return repairParsedAgainstSchema(v, itemSchema);
|
|
523
|
-
}
|
|
524
|
-
return v;
|
|
525
|
-
}
|
|
526
|
-
function tryParseStringToSchemaObject(xml, itemSchema) {
|
|
527
|
-
try {
|
|
528
|
-
const normalized = xml.replace(MALFORMED_CLOSE_RE_G, "</$1>");
|
|
529
|
-
const fixed = (0, import_rxml.parse)(normalized, itemSchema, { noChildNodes: [] });
|
|
530
|
-
return typeof fixed === "string" ? null : fixed;
|
|
531
|
-
} catch (e) {
|
|
532
|
-
return null;
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
function extractStepStatusFromString(normXml) {
|
|
536
|
-
const stepMatch = normXml.match(STEP_TAG_RE);
|
|
537
|
-
const statusMatch = normXml.match(STATUS_TAG_RE);
|
|
538
|
-
if (stepMatch && statusMatch) {
|
|
539
|
-
return { step: stepMatch[1], status: statusMatch[1] };
|
|
540
|
-
}
|
|
541
|
-
return null;
|
|
542
|
-
}
|
|
67
|
+
// src/core/protocols/json-protocol.ts
|
|
68
|
+
var import_rjson = require("@ai-sdk-tool/rjson");
|
|
543
69
|
|
|
544
70
|
// src/core/utils/debug.ts
|
|
545
71
|
var LINE_SPLIT_REGEX = /\r?\n/;
|
|
@@ -720,680 +246,15 @@ function generateId() {
|
|
|
720
246
|
}
|
|
721
247
|
|
|
722
248
|
// src/core/utils/regex.ts
|
|
723
|
-
function
|
|
249
|
+
function escapeRegExp(literal) {
|
|
724
250
|
return literal.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
725
251
|
}
|
|
726
252
|
|
|
727
|
-
// src/core/utils/robust-json.ts
|
|
728
|
-
var WHITESPACE_TEST_REGEX = /\s/;
|
|
729
|
-
var WHITESPACE_REGEX2 = /^\s+/;
|
|
730
|
-
var OBJECT_START_REGEX = /^\{/;
|
|
731
|
-
var OBJECT_END_REGEX = /^\}/;
|
|
732
|
-
var ARRAY_START_REGEX = /^\[/;
|
|
733
|
-
var ARRAY_END_REGEX = /^\]/;
|
|
734
|
-
var COMMA_REGEX = /^,/;
|
|
735
|
-
var COLON_REGEX = /^:/;
|
|
736
|
-
var KEYWORD_REGEX = /^(?:true|false|null)/;
|
|
737
|
-
var NUMBER_REGEX = /^-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?/;
|
|
738
|
-
var STRING_DOUBLE_REGEX = /^"(?:[^"\\]|\\["bnrtf\\/]|\\u[0-9a-fA-F]{4})*"/;
|
|
739
|
-
var STRING_SINGLE_REGEX = /^'((?:[^'\\]|\\['bnrtf\\/]|\\u[0-9a-fA-F]{4})*)'/;
|
|
740
|
-
var COMMENT_SINGLE_REGEX = /^\/\/.*?(?:\r\n|\r|\n)/;
|
|
741
|
-
var COMMENT_MULTI_REGEX = /^\/\*[\s\S]*?\*\//;
|
|
742
|
-
var IDENTIFIER_REGEX = /^[$a-zA-Z0-9_\-+.*?!|&%^/#\\]+/;
|
|
743
|
-
function some(array, f) {
|
|
744
|
-
let acc = false;
|
|
745
|
-
for (let i = 0; i < array.length; i += 1) {
|
|
746
|
-
const result = f(array[i], i, array);
|
|
747
|
-
acc = result === void 0 ? false : result;
|
|
748
|
-
if (acc) {
|
|
749
|
-
return acc;
|
|
750
|
-
}
|
|
751
|
-
}
|
|
752
|
-
return acc;
|
|
753
|
-
}
|
|
754
|
-
function makeLexer(tokenSpecs) {
|
|
755
|
-
return (contents) => {
|
|
756
|
-
const tokens = [];
|
|
757
|
-
let line = 1;
|
|
758
|
-
let remainingContents = contents;
|
|
759
|
-
function findToken() {
|
|
760
|
-
const result = some(tokenSpecs, (tokenSpec) => {
|
|
761
|
-
const m = tokenSpec.re.exec(remainingContents);
|
|
762
|
-
if (m) {
|
|
763
|
-
const raw = m[0];
|
|
764
|
-
remainingContents = remainingContents.slice(raw.length);
|
|
765
|
-
return {
|
|
766
|
-
raw,
|
|
767
|
-
matched: tokenSpec.f(m)
|
|
768
|
-
// Process the match using the spec's function
|
|
769
|
-
};
|
|
770
|
-
}
|
|
771
|
-
return;
|
|
772
|
-
});
|
|
773
|
-
return result === false ? void 0 : result;
|
|
774
|
-
}
|
|
775
|
-
while (remainingContents !== "") {
|
|
776
|
-
const matched = findToken();
|
|
777
|
-
if (!matched) {
|
|
778
|
-
const err = new SyntaxError(
|
|
779
|
-
`Unexpected character: ${remainingContents[0]}; input: ${remainingContents.substr(
|
|
780
|
-
0,
|
|
781
|
-
100
|
|
782
|
-
)}`
|
|
783
|
-
);
|
|
784
|
-
err.line = line;
|
|
785
|
-
throw err;
|
|
786
|
-
}
|
|
787
|
-
const tokenWithLine = matched.matched;
|
|
788
|
-
tokenWithLine.line = line;
|
|
789
|
-
line += matched.raw.replace(/[^\n]/g, "").length;
|
|
790
|
-
tokens.push(tokenWithLine);
|
|
791
|
-
}
|
|
792
|
-
return tokens;
|
|
793
|
-
};
|
|
794
|
-
}
|
|
795
|
-
function fStringSingle(m) {
|
|
796
|
-
const content = m[1].replace(
|
|
797
|
-
/([^'\\]|\\['bnrtf\\]|\\u[0-9a-fA-F]{4})/g,
|
|
798
|
-
(mm) => {
|
|
799
|
-
if (mm === '"') {
|
|
800
|
-
return '\\"';
|
|
801
|
-
}
|
|
802
|
-
if (mm === "\\'") {
|
|
803
|
-
return "'";
|
|
804
|
-
}
|
|
805
|
-
return mm;
|
|
806
|
-
}
|
|
807
|
-
);
|
|
808
|
-
const match = `"${content}"`;
|
|
809
|
-
return {
|
|
810
|
-
type: "string",
|
|
811
|
-
match,
|
|
812
|
-
// The transformed, double-quoted string representation
|
|
813
|
-
// Use JSON.parse on the transformed string to handle escape sequences correctly
|
|
814
|
-
value: JSON.parse(match)
|
|
815
|
-
};
|
|
816
|
-
}
|
|
817
|
-
function fStringDouble(m) {
|
|
818
|
-
return {
|
|
819
|
-
type: "string",
|
|
820
|
-
match: m[0],
|
|
821
|
-
// The raw matched string (including quotes)
|
|
822
|
-
value: JSON.parse(m[0])
|
|
823
|
-
// Use JSON.parse to handle escapes and get the value
|
|
824
|
-
};
|
|
825
|
-
}
|
|
826
|
-
function fIdentifier(m) {
|
|
827
|
-
const value = m[0];
|
|
828
|
-
const match = '"' + value.replace(/\\/g, "\\\\").replace(/"/g, '\\"') + // Escape backslashes and quotes
|
|
829
|
-
'"';
|
|
830
|
-
return {
|
|
831
|
-
type: "string",
|
|
832
|
-
// Treat identifiers as strings
|
|
833
|
-
value,
|
|
834
|
-
// The original identifier name
|
|
835
|
-
match
|
|
836
|
-
// The double-quoted string representation
|
|
837
|
-
};
|
|
838
|
-
}
|
|
839
|
-
function fComment(m) {
|
|
840
|
-
const match = m[0].replace(
|
|
841
|
-
/./g,
|
|
842
|
-
(c) => WHITESPACE_TEST_REGEX.test(c) ? c : " "
|
|
843
|
-
);
|
|
844
|
-
return {
|
|
845
|
-
type: " ",
|
|
846
|
-
// Represent comments as whitespace tokens
|
|
847
|
-
match,
|
|
848
|
-
// String containing original newlines and spaces for other chars
|
|
849
|
-
value: void 0
|
|
850
|
-
// Comments don't have a semantic value
|
|
851
|
-
};
|
|
852
|
-
}
|
|
853
|
-
function fNumber(m) {
|
|
854
|
-
return {
|
|
855
|
-
type: "number",
|
|
856
|
-
match: m[0],
|
|
857
|
-
// The raw matched number string
|
|
858
|
-
value: Number.parseFloat(m[0])
|
|
859
|
-
// Convert string to number
|
|
860
|
-
};
|
|
861
|
-
}
|
|
862
|
-
function fKeyword(m) {
|
|
863
|
-
let value;
|
|
864
|
-
switch (m[0]) {
|
|
865
|
-
case "null":
|
|
866
|
-
value = null;
|
|
867
|
-
break;
|
|
868
|
-
case "true":
|
|
869
|
-
value = true;
|
|
870
|
-
break;
|
|
871
|
-
case "false":
|
|
872
|
-
value = false;
|
|
873
|
-
break;
|
|
874
|
-
default:
|
|
875
|
-
throw new Error(`Unexpected keyword: ${m[0]}`);
|
|
876
|
-
}
|
|
877
|
-
return {
|
|
878
|
-
type: "atom",
|
|
879
|
-
// Use 'atom' type for these literals
|
|
880
|
-
match: m[0],
|
|
881
|
-
// The raw matched keyword
|
|
882
|
-
value
|
|
883
|
-
// The corresponding JavaScript value
|
|
884
|
-
};
|
|
885
|
-
}
|
|
886
|
-
function makeTokenSpecs(relaxed) {
|
|
887
|
-
function f(type) {
|
|
888
|
-
return (m) => {
|
|
889
|
-
return { type, match: m[0], value: void 0 };
|
|
890
|
-
};
|
|
891
|
-
}
|
|
892
|
-
let tokenSpecs = [
|
|
893
|
-
{ re: WHITESPACE_REGEX2, f: f(" ") },
|
|
894
|
-
// Whitespace
|
|
895
|
-
{ re: OBJECT_START_REGEX, f: f("{") },
|
|
896
|
-
// Object start
|
|
897
|
-
{ re: OBJECT_END_REGEX, f: f("}") },
|
|
898
|
-
// Object end
|
|
899
|
-
{ re: ARRAY_START_REGEX, f: f("[") },
|
|
900
|
-
// Array start
|
|
901
|
-
{ re: ARRAY_END_REGEX, f: f("]") },
|
|
902
|
-
// Array end
|
|
903
|
-
{ re: COMMA_REGEX, f: f(",") },
|
|
904
|
-
// Comma separator
|
|
905
|
-
{ re: COLON_REGEX, f: f(":") },
|
|
906
|
-
// Key-value separator
|
|
907
|
-
{ re: KEYWORD_REGEX, f: fKeyword },
|
|
908
|
-
// Keywords
|
|
909
|
-
// Number: optional sign, digits, optional decimal part, optional exponent
|
|
910
|
-
{ re: NUMBER_REGEX, f: fNumber },
|
|
911
|
-
// String: double-quoted, handles escapes
|
|
912
|
-
{ re: STRING_DOUBLE_REGEX, f: fStringDouble }
|
|
913
|
-
];
|
|
914
|
-
if (relaxed) {
|
|
915
|
-
tokenSpecs = tokenSpecs.concat([
|
|
916
|
-
// Single-quoted strings
|
|
917
|
-
{
|
|
918
|
-
re: STRING_SINGLE_REGEX,
|
|
919
|
-
f: fStringSingle
|
|
920
|
-
},
|
|
921
|
-
// Single-line comments (// ...)
|
|
922
|
-
{ re: COMMENT_SINGLE_REGEX, f: fComment },
|
|
923
|
-
// Multi-line comments (/* ... */)
|
|
924
|
-
{ re: COMMENT_MULTI_REGEX, f: fComment },
|
|
925
|
-
// Unquoted identifiers (treated as strings)
|
|
926
|
-
// Allows letters, numbers, _, -, +, ., *, ?, !, |, &, %, ^, /, #, \
|
|
927
|
-
{ re: IDENTIFIER_REGEX, f: fIdentifier }
|
|
928
|
-
// Note: The order matters here. Identifiers are checked after keywords/numbers.
|
|
929
|
-
]);
|
|
930
|
-
}
|
|
931
|
-
return tokenSpecs;
|
|
932
|
-
}
|
|
933
|
-
var lexer = makeLexer(makeTokenSpecs(true));
|
|
934
|
-
var strictLexer = makeLexer(makeTokenSpecs(false));
|
|
935
|
-
function previousNWSToken(tokens, index) {
|
|
936
|
-
let currentIndex = index;
|
|
937
|
-
for (; currentIndex >= 0; currentIndex -= 1) {
|
|
938
|
-
if (tokens[currentIndex].type !== " ") {
|
|
939
|
-
return currentIndex;
|
|
940
|
-
}
|
|
941
|
-
}
|
|
942
|
-
return;
|
|
943
|
-
}
|
|
944
|
-
function stripTrailingComma(tokens) {
|
|
945
|
-
const res = [];
|
|
946
|
-
tokens.forEach((token, index) => {
|
|
947
|
-
if (index > 0 && (token.type === "]" || token.type === "}")) {
|
|
948
|
-
const prevNWSTokenIndex = previousNWSToken(res, res.length - 1);
|
|
949
|
-
if (prevNWSTokenIndex !== void 0 && res[prevNWSTokenIndex].type === ",") {
|
|
950
|
-
const preCommaIndex = previousNWSToken(res, prevNWSTokenIndex - 1);
|
|
951
|
-
if (preCommaIndex !== void 0 && res[preCommaIndex].type !== "[" && res[preCommaIndex].type !== "{") {
|
|
952
|
-
res[prevNWSTokenIndex] = {
|
|
953
|
-
type: " ",
|
|
954
|
-
match: " ",
|
|
955
|
-
// Represent as a single space
|
|
956
|
-
value: void 0,
|
|
957
|
-
// Whitespace has no value
|
|
958
|
-
line: res[prevNWSTokenIndex].line
|
|
959
|
-
// Preserve original line number
|
|
960
|
-
};
|
|
961
|
-
}
|
|
962
|
-
}
|
|
963
|
-
}
|
|
964
|
-
res.push(token);
|
|
965
|
-
});
|
|
966
|
-
return res;
|
|
967
|
-
}
|
|
968
|
-
function transform(text) {
|
|
969
|
-
let tokens = lexer(text);
|
|
970
|
-
tokens = stripTrailingComma(tokens);
|
|
971
|
-
return tokens.reduce((str, token) => str + token.match, "");
|
|
972
|
-
}
|
|
973
|
-
function popToken(tokens, state) {
|
|
974
|
-
var _a, _b;
|
|
975
|
-
const token = tokens[state.pos];
|
|
976
|
-
state.pos += 1;
|
|
977
|
-
if (!token) {
|
|
978
|
-
const lastLine = tokens.length !== 0 ? (_b = (_a = tokens.at(-1)) == null ? void 0 : _a.line) != null ? _b : 1 : 1;
|
|
979
|
-
return { type: "eof", match: "", value: void 0, line: lastLine };
|
|
980
|
-
}
|
|
981
|
-
return token;
|
|
982
|
-
}
|
|
983
|
-
function strToken(token) {
|
|
984
|
-
switch (token.type) {
|
|
985
|
-
case "atom":
|
|
986
|
-
case "string":
|
|
987
|
-
case "number":
|
|
988
|
-
return `${token.type} ${token.match}`;
|
|
989
|
-
case "eof":
|
|
990
|
-
return "end-of-file";
|
|
991
|
-
default:
|
|
992
|
-
return `'${token.type}'`;
|
|
993
|
-
}
|
|
994
|
-
}
|
|
995
|
-
function skipColon(tokens, state) {
|
|
996
|
-
const colon = popToken(tokens, state);
|
|
997
|
-
if (colon.type !== ":") {
|
|
998
|
-
const message = `Unexpected token: ${strToken(colon)}, expected ':'`;
|
|
999
|
-
if (state.tolerant) {
|
|
1000
|
-
state.warnings.push({
|
|
1001
|
-
message,
|
|
1002
|
-
line: colon.line
|
|
1003
|
-
});
|
|
1004
|
-
state.pos -= 1;
|
|
1005
|
-
} else {
|
|
1006
|
-
const err = new SyntaxError(message);
|
|
1007
|
-
err.line = colon.line;
|
|
1008
|
-
throw err;
|
|
1009
|
-
}
|
|
1010
|
-
}
|
|
1011
|
-
}
|
|
1012
|
-
function skipPunctuation(tokens, state, valid) {
|
|
1013
|
-
const punctuation = [",", ":", "]", "}"];
|
|
1014
|
-
let token = popToken(tokens, state);
|
|
1015
|
-
while (true) {
|
|
1016
|
-
if (valid == null ? void 0 : valid.includes(token.type)) {
|
|
1017
|
-
return token;
|
|
1018
|
-
}
|
|
1019
|
-
if (token.type === "eof") {
|
|
1020
|
-
return token;
|
|
1021
|
-
}
|
|
1022
|
-
if (punctuation.includes(token.type)) {
|
|
1023
|
-
const message = `Unexpected token: ${strToken(
|
|
1024
|
-
token
|
|
1025
|
-
)}, expected '[', '{', number, string or atom`;
|
|
1026
|
-
if (state.tolerant) {
|
|
1027
|
-
state.warnings.push({
|
|
1028
|
-
message,
|
|
1029
|
-
line: token.line
|
|
1030
|
-
});
|
|
1031
|
-
token = popToken(tokens, state);
|
|
1032
|
-
} else {
|
|
1033
|
-
const err = new SyntaxError(message);
|
|
1034
|
-
err.line = token.line;
|
|
1035
|
-
throw err;
|
|
1036
|
-
}
|
|
1037
|
-
} else {
|
|
1038
|
-
return token;
|
|
1039
|
-
}
|
|
1040
|
-
}
|
|
1041
|
-
}
|
|
1042
|
-
function raiseError(state, token, message) {
|
|
1043
|
-
if (state.tolerant) {
|
|
1044
|
-
state.warnings.push({
|
|
1045
|
-
message,
|
|
1046
|
-
line: token.line
|
|
1047
|
-
});
|
|
1048
|
-
} else {
|
|
1049
|
-
const err = new SyntaxError(message);
|
|
1050
|
-
err.line = token.line;
|
|
1051
|
-
throw err;
|
|
1052
|
-
}
|
|
1053
|
-
}
|
|
1054
|
-
function raiseUnexpected(state, token, expected) {
|
|
1055
|
-
raiseError(
|
|
1056
|
-
state,
|
|
1057
|
-
token,
|
|
1058
|
-
`Unexpected token: ${strToken(token)}, expected ${expected}`
|
|
1059
|
-
);
|
|
1060
|
-
}
|
|
1061
|
-
function checkDuplicates(state, obj, token) {
|
|
1062
|
-
const key = String(token.value);
|
|
1063
|
-
if (!state.duplicate && Object.hasOwn(obj, key)) {
|
|
1064
|
-
raiseError(state, token, `Duplicate key: ${key}`);
|
|
1065
|
-
}
|
|
1066
|
-
}
|
|
1067
|
-
function appendPair(state, obj, key, value) {
|
|
1068
|
-
const finalValue = state.reviver ? state.reviver(key, value) : value;
|
|
1069
|
-
if (finalValue !== void 0) {
|
|
1070
|
-
obj[key] = finalValue;
|
|
1071
|
-
}
|
|
1072
|
-
}
|
|
1073
|
-
function parsePair(tokens, state, obj) {
|
|
1074
|
-
let token = skipPunctuation(tokens, state, [":", "string", "number", "atom"]);
|
|
1075
|
-
let value;
|
|
1076
|
-
if (token.type !== "string") {
|
|
1077
|
-
raiseUnexpected(state, token, "string key");
|
|
1078
|
-
if (state.tolerant) {
|
|
1079
|
-
switch (token.type) {
|
|
1080
|
-
case ":":
|
|
1081
|
-
token = {
|
|
1082
|
-
type: "string",
|
|
1083
|
-
value: "null",
|
|
1084
|
-
match: '"null"',
|
|
1085
|
-
line: token.line
|
|
1086
|
-
};
|
|
1087
|
-
state.pos -= 1;
|
|
1088
|
-
break;
|
|
1089
|
-
case "number":
|
|
1090
|
-
// Use number as string key
|
|
1091
|
-
case "atom":
|
|
1092
|
-
token = {
|
|
1093
|
-
type: "string",
|
|
1094
|
-
value: String(token.value),
|
|
1095
|
-
match: `"${token.value}"`,
|
|
1096
|
-
line: token.line
|
|
1097
|
-
};
|
|
1098
|
-
break;
|
|
1099
|
-
case "[":
|
|
1100
|
-
// Assume missing key before an array
|
|
1101
|
-
case "{":
|
|
1102
|
-
state.pos -= 1;
|
|
1103
|
-
value = parseAny(tokens, state);
|
|
1104
|
-
checkDuplicates(state, obj, {
|
|
1105
|
-
type: "string",
|
|
1106
|
-
value: "null",
|
|
1107
|
-
match: '"null"',
|
|
1108
|
-
line: token.line
|
|
1109
|
-
});
|
|
1110
|
-
appendPair(state, obj, "null", value);
|
|
1111
|
-
return;
|
|
1112
|
-
// Finished parsing this "pair"
|
|
1113
|
-
case "eof":
|
|
1114
|
-
return;
|
|
1115
|
-
// Cannot recover
|
|
1116
|
-
default:
|
|
1117
|
-
return;
|
|
1118
|
-
}
|
|
1119
|
-
} else {
|
|
1120
|
-
return;
|
|
1121
|
-
}
|
|
1122
|
-
}
|
|
1123
|
-
checkDuplicates(state, obj, token);
|
|
1124
|
-
const key = String(token.value);
|
|
1125
|
-
skipColon(tokens, state);
|
|
1126
|
-
value = parseAny(tokens, state);
|
|
1127
|
-
appendPair(state, obj, key, value);
|
|
1128
|
-
}
|
|
1129
|
-
function parseElement(tokens, state, arr) {
|
|
1130
|
-
const key = arr.length;
|
|
1131
|
-
const value = parseAny(tokens, state);
|
|
1132
|
-
arr[key] = state.reviver ? state.reviver(String(key), value) : value;
|
|
1133
|
-
}
|
|
1134
|
-
function parseObject(tokens, state) {
|
|
1135
|
-
const obj = {};
|
|
1136
|
-
return parseMany(tokens, state, obj, {
|
|
1137
|
-
skip: [":", "}"],
|
|
1138
|
-
// Initially skip over colon or closing brace (for empty/tolerant cases)
|
|
1139
|
-
elementParser: parsePair,
|
|
1140
|
-
// Use parsePair to parse each key-value element
|
|
1141
|
-
elementName: "string key",
|
|
1142
|
-
// Expected element type for errors
|
|
1143
|
-
endSymbol: "}"
|
|
1144
|
-
// The closing token for an object
|
|
1145
|
-
});
|
|
1146
|
-
}
|
|
1147
|
-
function parseArray(tokens, state) {
|
|
1148
|
-
const arr = [];
|
|
1149
|
-
return parseMany(tokens, state, arr, {
|
|
1150
|
-
skip: ["]"],
|
|
1151
|
-
// Initially skip over closing bracket (for empty/tolerant cases)
|
|
1152
|
-
elementParser: parseElement,
|
|
1153
|
-
// Use parseElement to parse each array item
|
|
1154
|
-
elementName: "json value",
|
|
1155
|
-
// Expected element type for errors
|
|
1156
|
-
endSymbol: "]"
|
|
1157
|
-
// The closing token for an array
|
|
1158
|
-
});
|
|
1159
|
-
}
|
|
1160
|
-
function handleInvalidToken(token, state, opts, result) {
|
|
1161
|
-
raiseUnexpected(state, token, `',' or '${opts.endSymbol}'`);
|
|
1162
|
-
if (state.tolerant) {
|
|
1163
|
-
if (token.type === "eof") {
|
|
1164
|
-
return result;
|
|
1165
|
-
}
|
|
1166
|
-
state.pos -= 1;
|
|
1167
|
-
return null;
|
|
1168
|
-
}
|
|
1169
|
-
return result;
|
|
1170
|
-
}
|
|
1171
|
-
function handleCommaToken(params) {
|
|
1172
|
-
const { token, tokens, state, opts, result } = params;
|
|
1173
|
-
const nextToken = tokens[state.pos];
|
|
1174
|
-
if (state.tolerant && nextToken && nextToken.type === opts.endSymbol) {
|
|
1175
|
-
raiseError(state, token, `Trailing comma before '${opts.endSymbol}'`);
|
|
1176
|
-
popToken(tokens, state);
|
|
1177
|
-
return result;
|
|
1178
|
-
}
|
|
1179
|
-
opts.elementParser(tokens, state, result);
|
|
1180
|
-
return null;
|
|
1181
|
-
}
|
|
1182
|
-
function parseManyInitialElement(tokens, state, result, opts) {
|
|
1183
|
-
const token = skipPunctuation(tokens, state, opts.skip);
|
|
1184
|
-
if (token.type === "eof") {
|
|
1185
|
-
raiseUnexpected(state, token, `'${opts.endSymbol}' or ${opts.elementName}`);
|
|
1186
|
-
return result;
|
|
1187
|
-
}
|
|
1188
|
-
if (token.type === opts.endSymbol) {
|
|
1189
|
-
return result;
|
|
1190
|
-
}
|
|
1191
|
-
state.pos -= 1;
|
|
1192
|
-
opts.elementParser(tokens, state, result);
|
|
1193
|
-
return;
|
|
1194
|
-
}
|
|
1195
|
-
function parseManyProcessToken(params) {
|
|
1196
|
-
const { token, tokens, state, opts, result } = params;
|
|
1197
|
-
if (token.type !== opts.endSymbol && token.type !== ",") {
|
|
1198
|
-
const handledResult = handleInvalidToken(token, state, opts, result);
|
|
1199
|
-
if (handledResult !== null) {
|
|
1200
|
-
return handledResult;
|
|
1201
|
-
}
|
|
1202
|
-
}
|
|
1203
|
-
if (token.type === opts.endSymbol) {
|
|
1204
|
-
return result;
|
|
1205
|
-
}
|
|
1206
|
-
if (token.type === ",") {
|
|
1207
|
-
const handledResult = handleCommaToken({
|
|
1208
|
-
token,
|
|
1209
|
-
tokens,
|
|
1210
|
-
state,
|
|
1211
|
-
opts,
|
|
1212
|
-
result
|
|
1213
|
-
});
|
|
1214
|
-
if (handledResult !== null) {
|
|
1215
|
-
return handledResult;
|
|
1216
|
-
}
|
|
1217
|
-
return;
|
|
1218
|
-
}
|
|
1219
|
-
opts.elementParser(tokens, state, result);
|
|
1220
|
-
return;
|
|
1221
|
-
}
|
|
1222
|
-
function parseMany(tokens, state, result, opts) {
|
|
1223
|
-
const initialResult = parseManyInitialElement(tokens, state, result, opts);
|
|
1224
|
-
if (initialResult !== void 0) {
|
|
1225
|
-
return initialResult;
|
|
1226
|
-
}
|
|
1227
|
-
while (true) {
|
|
1228
|
-
const token = popToken(tokens, state);
|
|
1229
|
-
const processedResult = parseManyProcessToken({
|
|
1230
|
-
token,
|
|
1231
|
-
tokens,
|
|
1232
|
-
state,
|
|
1233
|
-
opts,
|
|
1234
|
-
result
|
|
1235
|
-
});
|
|
1236
|
-
if (processedResult !== void 0) {
|
|
1237
|
-
return processedResult;
|
|
1238
|
-
}
|
|
1239
|
-
}
|
|
1240
|
-
}
|
|
1241
|
-
function endChecks(tokens, state, ret) {
|
|
1242
|
-
if (state.pos < tokens.length) {
|
|
1243
|
-
if (state.tolerant) {
|
|
1244
|
-
skipPunctuation(tokens, state);
|
|
1245
|
-
}
|
|
1246
|
-
if (state.pos < tokens.length) {
|
|
1247
|
-
raiseError(
|
|
1248
|
-
state,
|
|
1249
|
-
tokens[state.pos],
|
|
1250
|
-
`Unexpected token: ${strToken(tokens[state.pos])}, expected end-of-input`
|
|
1251
|
-
);
|
|
1252
|
-
}
|
|
1253
|
-
}
|
|
1254
|
-
if (state.tolerant && state.warnings.length > 0) {
|
|
1255
|
-
const message = state.warnings.length === 1 ? state.warnings[0].message : `${state.warnings.length} parse warnings`;
|
|
1256
|
-
const err = new SyntaxError(message);
|
|
1257
|
-
err.line = state.warnings[0].line;
|
|
1258
|
-
err.warnings = state.warnings;
|
|
1259
|
-
err.obj = ret;
|
|
1260
|
-
throw err;
|
|
1261
|
-
}
|
|
1262
|
-
}
|
|
1263
|
-
function parseAny(tokens, state, end = false) {
|
|
1264
|
-
const token = skipPunctuation(tokens, state);
|
|
1265
|
-
let ret;
|
|
1266
|
-
if (token.type === "eof") {
|
|
1267
|
-
if (end) {
|
|
1268
|
-
raiseUnexpected(state, token, "json value");
|
|
1269
|
-
}
|
|
1270
|
-
raiseUnexpected(state, token, "json value");
|
|
1271
|
-
return;
|
|
1272
|
-
}
|
|
1273
|
-
switch (token.type) {
|
|
1274
|
-
case "{":
|
|
1275
|
-
ret = parseObject(tokens, state);
|
|
1276
|
-
break;
|
|
1277
|
-
case "[":
|
|
1278
|
-
ret = parseArray(tokens, state);
|
|
1279
|
-
break;
|
|
1280
|
-
case "string":
|
|
1281
|
-
// String literal
|
|
1282
|
-
case "number":
|
|
1283
|
-
// Number literal
|
|
1284
|
-
case "atom":
|
|
1285
|
-
ret = token.value;
|
|
1286
|
-
break;
|
|
1287
|
-
default:
|
|
1288
|
-
raiseUnexpected(state, token, "json value");
|
|
1289
|
-
if (state.tolerant) {
|
|
1290
|
-
ret = null;
|
|
1291
|
-
} else {
|
|
1292
|
-
return;
|
|
1293
|
-
}
|
|
1294
|
-
}
|
|
1295
|
-
if (end) {
|
|
1296
|
-
ret = state.reviver ? state.reviver("", ret) : ret;
|
|
1297
|
-
endChecks(tokens, state, ret);
|
|
1298
|
-
}
|
|
1299
|
-
return ret;
|
|
1300
|
-
}
|
|
1301
|
-
function normalizeParseOptions(optsOrReviver) {
|
|
1302
|
-
var _a;
|
|
1303
|
-
let options = {};
|
|
1304
|
-
if (typeof optsOrReviver === "function") {
|
|
1305
|
-
options.reviver = optsOrReviver;
|
|
1306
|
-
} else if (optsOrReviver !== null && typeof optsOrReviver === "object") {
|
|
1307
|
-
options = { ...optsOrReviver };
|
|
1308
|
-
} else if (optsOrReviver !== void 0) {
|
|
1309
|
-
throw new TypeError(
|
|
1310
|
-
"Second argument must be a reviver function or an options object."
|
|
1311
|
-
);
|
|
1312
|
-
}
|
|
1313
|
-
if (options.relaxed === void 0) {
|
|
1314
|
-
if (options.warnings === true || options.tolerant === true) {
|
|
1315
|
-
options.relaxed = true;
|
|
1316
|
-
} else if (options.warnings === false && options.tolerant === false) {
|
|
1317
|
-
options.relaxed = false;
|
|
1318
|
-
} else {
|
|
1319
|
-
options.relaxed = true;
|
|
1320
|
-
}
|
|
1321
|
-
}
|
|
1322
|
-
options.tolerant = options.tolerant || options.warnings;
|
|
1323
|
-
options.duplicate = (_a = options.duplicate) != null ? _a : false;
|
|
1324
|
-
return options;
|
|
1325
|
-
}
|
|
1326
|
-
function createParseState(options) {
|
|
1327
|
-
var _a, _b;
|
|
1328
|
-
return {
|
|
1329
|
-
pos: 0,
|
|
1330
|
-
reviver: options.reviver,
|
|
1331
|
-
tolerant: (_a = options.tolerant) != null ? _a : false,
|
|
1332
|
-
duplicate: (_b = options.duplicate) != null ? _b : false,
|
|
1333
|
-
warnings: []
|
|
1334
|
-
};
|
|
1335
|
-
}
|
|
1336
|
-
function parseWithCustomParser(text, options) {
|
|
1337
|
-
const lexerToUse = options.relaxed ? lexer : strictLexer;
|
|
1338
|
-
let tokens = lexerToUse(text);
|
|
1339
|
-
if (options.relaxed) {
|
|
1340
|
-
tokens = stripTrailingComma(tokens);
|
|
1341
|
-
}
|
|
1342
|
-
tokens = tokens.filter((token) => token.type !== " ");
|
|
1343
|
-
const state = createParseState(options);
|
|
1344
|
-
return parseAny(tokens, state, true);
|
|
1345
|
-
}
|
|
1346
|
-
function parseWithTransform(text, options) {
|
|
1347
|
-
let tokens = lexer(text);
|
|
1348
|
-
tokens = stripTrailingComma(tokens);
|
|
1349
|
-
const newtext = tokens.reduce((str, token) => str + token.match, "");
|
|
1350
|
-
return JSON.parse(
|
|
1351
|
-
newtext,
|
|
1352
|
-
options.reviver
|
|
1353
|
-
);
|
|
1354
|
-
}
|
|
1355
|
-
function parse2(text, optsOrReviver) {
|
|
1356
|
-
const options = normalizeParseOptions(optsOrReviver);
|
|
1357
|
-
if (!(options.relaxed || options.warnings || options.tolerant) && options.duplicate) {
|
|
1358
|
-
return JSON.parse(
|
|
1359
|
-
text,
|
|
1360
|
-
options.reviver
|
|
1361
|
-
);
|
|
1362
|
-
}
|
|
1363
|
-
if (options.warnings || options.tolerant || !options.duplicate) {
|
|
1364
|
-
return parseWithCustomParser(text, options);
|
|
1365
|
-
}
|
|
1366
|
-
return parseWithTransform(text, options);
|
|
1367
|
-
}
|
|
1368
|
-
function stringifyPair(obj, key) {
|
|
1369
|
-
return `${JSON.stringify(key)}:${stringify(obj[key])}`;
|
|
1370
|
-
}
|
|
1371
|
-
function stringify(obj) {
|
|
1372
|
-
const type = typeof obj;
|
|
1373
|
-
if (type === "string" || type === "number" || type === "boolean" || obj === null) {
|
|
1374
|
-
return JSON.stringify(obj);
|
|
1375
|
-
}
|
|
1376
|
-
if (type === "undefined") {
|
|
1377
|
-
return "null";
|
|
1378
|
-
}
|
|
1379
|
-
if (Array.isArray(obj)) {
|
|
1380
|
-
const elements = obj.map(stringify).join(",");
|
|
1381
|
-
return `[${elements}]`;
|
|
1382
|
-
}
|
|
1383
|
-
if (type === "object") {
|
|
1384
|
-
const keys = Object.keys(obj);
|
|
1385
|
-
keys.sort();
|
|
1386
|
-
const pairs = keys.map((key) => stringifyPair(obj, key)).join(",");
|
|
1387
|
-
return `{${pairs}}`;
|
|
1388
|
-
}
|
|
1389
|
-
return "null";
|
|
1390
|
-
}
|
|
1391
|
-
|
|
1392
253
|
// src/core/protocols/json-protocol.ts
|
|
1393
254
|
function processToolCallJson(toolCallJson, fullMatch, processedElements, options) {
|
|
1394
255
|
var _a, _b;
|
|
1395
256
|
try {
|
|
1396
|
-
const parsedToolCall =
|
|
257
|
+
const parsedToolCall = (0, import_rjson.parse)(toolCallJson);
|
|
1397
258
|
processedElements.push({
|
|
1398
259
|
type: "tool-call",
|
|
1399
260
|
toolCallId: generateId(),
|
|
@@ -1521,7 +382,7 @@ function emitToolCall(context) {
|
|
|
1521
382
|
var _a, _b;
|
|
1522
383
|
const { state, controller, toolCallStart, toolCallEnd, options } = context;
|
|
1523
384
|
try {
|
|
1524
|
-
const parsedToolCall =
|
|
385
|
+
const parsedToolCall = (0, import_rjson.parse)(state.currentToolCallJson);
|
|
1525
386
|
closeTextBlock(state, controller);
|
|
1526
387
|
controller.enqueue({
|
|
1527
388
|
type: "tool-call",
|
|
@@ -1632,8 +493,8 @@ var jsonProtocol = ({
|
|
|
1632
493
|
text,
|
|
1633
494
|
options
|
|
1634
495
|
}) {
|
|
1635
|
-
const startEsc =
|
|
1636
|
-
const endEsc =
|
|
496
|
+
const startEsc = escapeRegExp(toolCallStart);
|
|
497
|
+
const endEsc = escapeRegExp(toolCallEnd);
|
|
1637
498
|
const toolCallRegex = new RegExp(
|
|
1638
499
|
`${startEsc}([\0-\uFFFF]*?)${endEsc}`,
|
|
1639
500
|
"gs"
|
|
@@ -1692,8 +553,8 @@ var jsonProtocol = ({
|
|
|
1692
553
|
});
|
|
1693
554
|
},
|
|
1694
555
|
extractToolCallSegments({ text }) {
|
|
1695
|
-
const startEsc =
|
|
1696
|
-
const endEsc =
|
|
556
|
+
const startEsc = escapeRegExp(toolCallStart);
|
|
557
|
+
const endEsc = escapeRegExp(toolCallEnd);
|
|
1697
558
|
const regex = new RegExp(`${startEsc}([\0-\uFFFF]*?)${endEsc}`, "gs");
|
|
1698
559
|
const segments = [];
|
|
1699
560
|
let m = regex.exec(text);
|
|
@@ -1714,93 +575,48 @@ function isTCMProtocolFactory(protocol) {
|
|
|
1714
575
|
}
|
|
1715
576
|
|
|
1716
577
|
// src/core/protocols/xml-protocol.ts
|
|
1717
|
-
var
|
|
1718
|
-
var
|
|
1719
|
-
var
|
|
1720
|
-
var
|
|
578
|
+
var import_rxml = require("@ai-sdk-tool/rxml");
|
|
579
|
+
var NAME_CHAR_RE = /[A-Za-z0-9_:-]/;
|
|
580
|
+
var WHITESPACE_REGEX = /\s/;
|
|
581
|
+
var REGEX_ESCAPE_RE = /[.*+?^${}()|[\]\\]/g;
|
|
582
|
+
function escapeRegExp2(value) {
|
|
583
|
+
return value.replace(REGEX_ESCAPE_RE, "\\$&");
|
|
584
|
+
}
|
|
1721
585
|
function getToolSchema(tools, toolName) {
|
|
1722
586
|
var _a;
|
|
1723
587
|
return (_a = tools.find((t) => t.name === toolName)) == null ? void 0 : _a.inputSchema;
|
|
1724
588
|
}
|
|
1725
|
-
function
|
|
1726
|
-
|
|
1727
|
-
}
|
|
1728
|
-
function tryParseSecondaryXml(content, toolSchema, options) {
|
|
1729
|
-
const balanced = balanceTags(content);
|
|
1730
|
-
try {
|
|
1731
|
-
let parsed = (0, import_rxml2.parse)(balanced, toolSchema, {
|
|
1732
|
-
onError: options == null ? void 0 : options.onError,
|
|
1733
|
-
noChildNodes: []
|
|
1734
|
-
});
|
|
1735
|
-
parsed = repairParsedAgainstSchema(parsed, toolSchema);
|
|
1736
|
-
return parsed;
|
|
1737
|
-
} catch (e) {
|
|
1738
|
-
if (shouldDeduplicateStringTags(toolSchema)) {
|
|
1739
|
-
const names = getStringPropertyNames(toolSchema);
|
|
1740
|
-
let deduped = balanced;
|
|
1741
|
-
for (const key of names) {
|
|
1742
|
-
deduped = dedupeSingleTag(deduped, key);
|
|
1743
|
-
}
|
|
1744
|
-
if (deduped !== balanced) {
|
|
1745
|
-
try {
|
|
1746
|
-
let reparsed = (0, import_rxml2.parse)(deduped, toolSchema, {
|
|
1747
|
-
onError: options == null ? void 0 : options.onError,
|
|
1748
|
-
noChildNodes: []
|
|
1749
|
-
});
|
|
1750
|
-
reparsed = repairParsedAgainstSchema(reparsed, toolSchema);
|
|
1751
|
-
return reparsed;
|
|
1752
|
-
} catch (e2) {
|
|
1753
|
-
return null;
|
|
1754
|
-
}
|
|
1755
|
-
}
|
|
1756
|
-
}
|
|
1757
|
-
return null;
|
|
1758
|
-
}
|
|
1759
|
-
}
|
|
1760
|
-
function processToolCallWithPipeline(params) {
|
|
1761
|
-
var _a;
|
|
1762
|
-
const {
|
|
1763
|
-
toolCall,
|
|
1764
|
-
tools,
|
|
1765
|
-
options,
|
|
1766
|
-
text,
|
|
1767
|
-
processedElements,
|
|
1768
|
-
pipelineConfig = defaultPipelineConfig2,
|
|
1769
|
-
maxReparses
|
|
1770
|
-
} = params;
|
|
589
|
+
function processToolCall(params) {
|
|
590
|
+
var _a, _b;
|
|
591
|
+
const { toolCall, tools, options, text, processedElements, parseOptions } = params;
|
|
1771
592
|
const toolSchema = getToolSchema(tools, toolCall.toolName);
|
|
1772
|
-
const
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
parse: (xml, schema) => (0, import_rxml2.parse)(xml, schema, { onError: options == null ? void 0 : options.onError, noChildNodes: [] }),
|
|
1779
|
-
onError: options == null ? void 0 : options.onError,
|
|
1780
|
-
maxReparses
|
|
1781
|
-
});
|
|
1782
|
-
if (result.parsed !== null) {
|
|
593
|
+
const parseConfig = {
|
|
594
|
+
...parseOptions != null ? parseOptions : {},
|
|
595
|
+
onError: (_a = options == null ? void 0 : options.onError) != null ? _a : parseOptions == null ? void 0 : parseOptions.onError
|
|
596
|
+
};
|
|
597
|
+
try {
|
|
598
|
+
const parsed = (0, import_rxml.parse)(toolCall.content, toolSchema, parseConfig);
|
|
1783
599
|
processedElements.push({
|
|
1784
600
|
type: "tool-call",
|
|
1785
601
|
toolCallId: generateId(),
|
|
1786
602
|
toolName: toolCall.toolName,
|
|
1787
|
-
input: JSON.stringify(
|
|
603
|
+
input: JSON.stringify(parsed)
|
|
1788
604
|
});
|
|
1789
|
-
}
|
|
605
|
+
} catch (error) {
|
|
1790
606
|
const originalCallText = text.substring(
|
|
1791
607
|
toolCall.startIndex,
|
|
1792
608
|
toolCall.endIndex
|
|
1793
609
|
);
|
|
1794
|
-
(
|
|
610
|
+
(_b = options == null ? void 0 : options.onError) == null ? void 0 : _b.call(
|
|
1795
611
|
options,
|
|
1796
612
|
`Could not process XML tool call: ${toolCall.toolName}`,
|
|
1797
|
-
{ toolCall: originalCallText, error
|
|
613
|
+
{ toolCall: originalCallText, error }
|
|
1798
614
|
);
|
|
1799
615
|
processedElements.push({ type: "text", text: originalCallText });
|
|
1800
616
|
}
|
|
1801
617
|
}
|
|
1802
618
|
function handleStreamingToolCallEnd(params) {
|
|
1803
|
-
var _a;
|
|
619
|
+
var _a, _b;
|
|
1804
620
|
const {
|
|
1805
621
|
toolContent,
|
|
1806
622
|
currentToolCall,
|
|
@@ -1808,51 +624,27 @@ function handleStreamingToolCallEnd(params) {
|
|
|
1808
624
|
options,
|
|
1809
625
|
ctrl,
|
|
1810
626
|
flushText,
|
|
1811
|
-
|
|
1812
|
-
maxReparses
|
|
627
|
+
parseOptions
|
|
1813
628
|
} = params;
|
|
1814
629
|
const toolSchema = getToolSchema(tools, currentToolCall.name);
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
toolContent,
|
|
1820
|
-
toolSchema
|
|
1821
|
-
);
|
|
1822
|
-
const result = applyHeuristicPipeline(ctx, pipelineConfig, {
|
|
1823
|
-
parse: (xml, schema) => (0, import_rxml2.parse)(xml, schema, { onError: options == null ? void 0 : options.onError, noChildNodes: [] }),
|
|
1824
|
-
onError: options == null ? void 0 : options.onError,
|
|
1825
|
-
maxReparses
|
|
1826
|
-
});
|
|
1827
|
-
parsedResult = result.parsed;
|
|
1828
|
-
} else {
|
|
1829
|
-
try {
|
|
1830
|
-
const primary = escapeInvalidLt(normalizeCloseTags(toolContent));
|
|
1831
|
-
const parsed = (0, import_rxml2.parse)(primary, toolSchema, {
|
|
1832
|
-
onError: options == null ? void 0 : options.onError,
|
|
1833
|
-
noChildNodes: []
|
|
1834
|
-
});
|
|
1835
|
-
parsedResult = repairParsedAgainstSchema(parsed, toolSchema);
|
|
1836
|
-
} catch (e) {
|
|
1837
|
-
parsedResult = tryParseSecondaryXml(
|
|
1838
|
-
toolContent,
|
|
1839
|
-
toolSchema,
|
|
1840
|
-
options != null ? options : {}
|
|
1841
|
-
);
|
|
1842
|
-
}
|
|
1843
|
-
}
|
|
630
|
+
const parseConfig = {
|
|
631
|
+
...parseOptions != null ? parseOptions : {},
|
|
632
|
+
onError: (_a = options == null ? void 0 : options.onError) != null ? _a : parseOptions == null ? void 0 : parseOptions.onError
|
|
633
|
+
};
|
|
1844
634
|
flushText(ctrl);
|
|
1845
|
-
|
|
635
|
+
try {
|
|
636
|
+
const parsedResult = (0, import_rxml.parse)(toolContent, toolSchema, parseConfig);
|
|
1846
637
|
ctrl.enqueue({
|
|
1847
638
|
type: "tool-call",
|
|
1848
639
|
toolCallId: generateId(),
|
|
1849
640
|
toolName: currentToolCall.name,
|
|
1850
641
|
input: JSON.stringify(parsedResult)
|
|
1851
642
|
});
|
|
1852
|
-
}
|
|
643
|
+
} catch (error) {
|
|
1853
644
|
const original = `<${currentToolCall.name}>${toolContent}</${currentToolCall.name}>`;
|
|
1854
|
-
(
|
|
1855
|
-
toolCall: original
|
|
645
|
+
(_b = options == null ? void 0 : options.onError) == null ? void 0 : _b.call(options, "Could not process streaming XML tool call", {
|
|
646
|
+
toolCall: original,
|
|
647
|
+
error
|
|
1856
648
|
});
|
|
1857
649
|
flushText(ctrl, original);
|
|
1858
650
|
}
|
|
@@ -1891,11 +683,11 @@ function consumeClosingTag(text, lt) {
|
|
|
1891
683
|
}
|
|
1892
684
|
function consumeOpenTag(text, lt) {
|
|
1893
685
|
let p = lt + 1;
|
|
1894
|
-
while (p < text.length &&
|
|
686
|
+
while (p < text.length && WHITESPACE_REGEX.test(text[p])) {
|
|
1895
687
|
p += 1;
|
|
1896
688
|
}
|
|
1897
689
|
const nameStart = p;
|
|
1898
|
-
while (p < text.length &&
|
|
690
|
+
while (p < text.length && NAME_CHAR_RE.test(text.charAt(p))) {
|
|
1899
691
|
p += 1;
|
|
1900
692
|
}
|
|
1901
693
|
const name = text.slice(nameStart, p);
|
|
@@ -1904,7 +696,7 @@ function consumeOpenTag(text, lt) {
|
|
|
1904
696
|
return null;
|
|
1905
697
|
}
|
|
1906
698
|
let r = q - 1;
|
|
1907
|
-
while (r >= nameStart &&
|
|
699
|
+
while (r >= nameStart && WHITESPACE_REGEX.test(text[r])) {
|
|
1908
700
|
r -= 1;
|
|
1909
701
|
}
|
|
1910
702
|
const selfClosing = text[r] === "/";
|
|
@@ -1933,11 +725,11 @@ function nextTagToken(text, fromPos) {
|
|
|
1933
725
|
if (next === "/") {
|
|
1934
726
|
const closing = consumeClosingTag(text, lt);
|
|
1935
727
|
let p = lt + 2;
|
|
1936
|
-
while (p < text.length &&
|
|
728
|
+
while (p < text.length && WHITESPACE_REGEX.test(text[p])) {
|
|
1937
729
|
p += 1;
|
|
1938
730
|
}
|
|
1939
731
|
const nameStart = p;
|
|
1940
|
-
while (p < text.length &&
|
|
732
|
+
while (p < text.length && NAME_CHAR_RE.test(text.charAt(p))) {
|
|
1941
733
|
p += 1;
|
|
1942
734
|
}
|
|
1943
735
|
const name = text.slice(nameStart, p);
|
|
@@ -1954,49 +746,90 @@ function nextTagToken(text, fromPos) {
|
|
|
1954
746
|
nextPos: open.nextPos
|
|
1955
747
|
};
|
|
1956
748
|
}
|
|
749
|
+
function findNextToolTag(text, searchIndex, startTag, selfTag) {
|
|
750
|
+
const openIdx = text.indexOf(startTag, searchIndex);
|
|
751
|
+
const selfIdx = text.indexOf(selfTag, searchIndex);
|
|
752
|
+
if (openIdx === -1 && selfIdx === -1) {
|
|
753
|
+
return null;
|
|
754
|
+
}
|
|
755
|
+
const isSelfClosing = selfIdx !== -1 && (openIdx === -1 || selfIdx < openIdx);
|
|
756
|
+
return {
|
|
757
|
+
tagStart: isSelfClosing ? selfIdx : openIdx,
|
|
758
|
+
isSelfClosing
|
|
759
|
+
};
|
|
760
|
+
}
|
|
761
|
+
function findLastCloseTagStart(segment, toolName) {
|
|
762
|
+
const closeTagPattern = new RegExp(
|
|
763
|
+
`</\\s*${escapeRegExp2(toolName)}\\s*>`,
|
|
764
|
+
"g"
|
|
765
|
+
);
|
|
766
|
+
let closeTagStart = -1;
|
|
767
|
+
let match = closeTagPattern.exec(segment);
|
|
768
|
+
while (match !== null) {
|
|
769
|
+
closeTagStart = match.index;
|
|
770
|
+
match = closeTagPattern.exec(segment);
|
|
771
|
+
}
|
|
772
|
+
if (closeTagStart === -1) {
|
|
773
|
+
return segment.lastIndexOf("<");
|
|
774
|
+
}
|
|
775
|
+
return closeTagStart;
|
|
776
|
+
}
|
|
777
|
+
function pushSelfClosingToolCall(toolCalls, toolName, text, tagStart, selfTag) {
|
|
778
|
+
const endIndex = tagStart + selfTag.length;
|
|
779
|
+
toolCalls.push({
|
|
780
|
+
toolName,
|
|
781
|
+
startIndex: tagStart,
|
|
782
|
+
endIndex,
|
|
783
|
+
content: "",
|
|
784
|
+
segment: text.substring(tagStart, endIndex)
|
|
785
|
+
});
|
|
786
|
+
return endIndex;
|
|
787
|
+
}
|
|
788
|
+
function appendOpenToolCallIfComplete(toolCalls, text, toolName, tagStart, startTag) {
|
|
789
|
+
const contentStart = tagStart + startTag.length;
|
|
790
|
+
const fullTagEnd = findClosingTagEndFlexible(text, contentStart, toolName);
|
|
791
|
+
if (fullTagEnd === -1 || fullTagEnd <= contentStart) {
|
|
792
|
+
return contentStart;
|
|
793
|
+
}
|
|
794
|
+
const segment = text.substring(tagStart, fullTagEnd);
|
|
795
|
+
const closeTagStart = findLastCloseTagStart(segment, toolName);
|
|
796
|
+
const inner = closeTagStart === -1 ? segment.slice(startTag.length) : segment.slice(startTag.length, closeTagStart);
|
|
797
|
+
toolCalls.push({
|
|
798
|
+
toolName,
|
|
799
|
+
startIndex: tagStart,
|
|
800
|
+
endIndex: fullTagEnd,
|
|
801
|
+
content: inner,
|
|
802
|
+
segment
|
|
803
|
+
});
|
|
804
|
+
return fullTagEnd;
|
|
805
|
+
}
|
|
1957
806
|
function findToolCallsForName(text, toolName) {
|
|
1958
|
-
var _a;
|
|
1959
807
|
const toolCalls = [];
|
|
808
|
+
const startTag = `<${toolName}>`;
|
|
809
|
+
const selfTag = `<${toolName}/>`;
|
|
1960
810
|
let searchIndex = 0;
|
|
1961
811
|
while (searchIndex < text.length) {
|
|
1962
|
-
const
|
|
1963
|
-
|
|
1964
|
-
const openIdx = text.indexOf(startTag, searchIndex);
|
|
1965
|
-
const selfIdx = text.indexOf(selfTag, searchIndex);
|
|
1966
|
-
if (openIdx === -1 && selfIdx === -1) {
|
|
812
|
+
const match = findNextToolTag(text, searchIndex, startTag, selfTag);
|
|
813
|
+
if (match === null) {
|
|
1967
814
|
break;
|
|
1968
815
|
}
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
const endIndex = tagStart + selfTag.length;
|
|
1973
|
-
const segment = text.substring(tagStart, endIndex);
|
|
1974
|
-
toolCalls.push({
|
|
816
|
+
if (match.isSelfClosing) {
|
|
817
|
+
searchIndex = pushSelfClosingToolCall(
|
|
818
|
+
toolCalls,
|
|
1975
819
|
toolName,
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
});
|
|
1981
|
-
searchIndex = endIndex;
|
|
820
|
+
text,
|
|
821
|
+
match.tagStart,
|
|
822
|
+
selfTag
|
|
823
|
+
);
|
|
1982
824
|
continue;
|
|
1983
825
|
}
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
startIndex: tagStart,
|
|
1992
|
-
endIndex: fullTagEnd,
|
|
1993
|
-
content: inner,
|
|
1994
|
-
segment
|
|
1995
|
-
});
|
|
1996
|
-
searchIndex = fullTagEnd;
|
|
1997
|
-
} else {
|
|
1998
|
-
searchIndex = contentStart;
|
|
1999
|
-
}
|
|
826
|
+
searchIndex = appendOpenToolCallIfComplete(
|
|
827
|
+
toolCalls,
|
|
828
|
+
text,
|
|
829
|
+
toolName,
|
|
830
|
+
match.tagStart,
|
|
831
|
+
startTag
|
|
832
|
+
);
|
|
2000
833
|
}
|
|
2001
834
|
return toolCalls;
|
|
2002
835
|
}
|
|
@@ -2073,16 +906,20 @@ function processToolCallInBuffer(params) {
|
|
|
2073
906
|
controller,
|
|
2074
907
|
flushText,
|
|
2075
908
|
setBuffer,
|
|
2076
|
-
|
|
2077
|
-
maxReparses
|
|
909
|
+
parseOptions
|
|
2078
910
|
} = params;
|
|
2079
|
-
const
|
|
2080
|
-
|
|
2081
|
-
|
|
911
|
+
const endTagPattern = new RegExp(
|
|
912
|
+
`</\\s*${escapeRegExp2(currentToolCall.name)}\\s*>`
|
|
913
|
+
);
|
|
914
|
+
const endMatch = endTagPattern.exec(buffer);
|
|
915
|
+
if (!endMatch || endMatch.index === void 0) {
|
|
2082
916
|
return { buffer, currentToolCall, shouldBreak: true };
|
|
2083
917
|
}
|
|
918
|
+
const endIdx = endMatch.index;
|
|
919
|
+
const endPos = endIdx + endMatch[0].length;
|
|
2084
920
|
const content = buffer.substring(0, endIdx);
|
|
2085
|
-
|
|
921
|
+
const remainder = buffer.substring(endPos);
|
|
922
|
+
setBuffer(remainder);
|
|
2086
923
|
handleStreamingToolCallEnd({
|
|
2087
924
|
toolContent: content,
|
|
2088
925
|
currentToolCall,
|
|
@@ -2090,11 +927,10 @@ function processToolCallInBuffer(params) {
|
|
|
2090
927
|
options,
|
|
2091
928
|
ctrl: controller,
|
|
2092
929
|
flushText,
|
|
2093
|
-
|
|
2094
|
-
maxReparses
|
|
930
|
+
parseOptions
|
|
2095
931
|
});
|
|
2096
932
|
return {
|
|
2097
|
-
buffer:
|
|
933
|
+
buffer: remainder,
|
|
2098
934
|
currentToolCall: null,
|
|
2099
935
|
shouldBreak: false
|
|
2100
936
|
};
|
|
@@ -2107,8 +943,7 @@ function processNoToolCallInBuffer(params) {
|
|
|
2107
943
|
flushText,
|
|
2108
944
|
tools,
|
|
2109
945
|
options,
|
|
2110
|
-
|
|
2111
|
-
maxReparses,
|
|
946
|
+
parseOptions,
|
|
2112
947
|
setBuffer
|
|
2113
948
|
} = params;
|
|
2114
949
|
const {
|
|
@@ -2143,8 +978,7 @@ function processNoToolCallInBuffer(params) {
|
|
|
2143
978
|
options,
|
|
2144
979
|
ctrl: controller,
|
|
2145
980
|
flushText,
|
|
2146
|
-
|
|
2147
|
-
maxReparses
|
|
981
|
+
parseOptions
|
|
2148
982
|
});
|
|
2149
983
|
return {
|
|
2150
984
|
buffer: newBuffer2,
|
|
@@ -2163,7 +997,7 @@ function processNoToolCallInBuffer(params) {
|
|
|
2163
997
|
shouldContinue: true
|
|
2164
998
|
};
|
|
2165
999
|
}
|
|
2166
|
-
function createProcessBufferHandler(getBuffer, setBuffer, getCurrentToolCall, setCurrentToolCall, tools, options, toolNames, flushText,
|
|
1000
|
+
function createProcessBufferHandler(getBuffer, setBuffer, getCurrentToolCall, setCurrentToolCall, tools, options, toolNames, flushText, parseOptions) {
|
|
2167
1001
|
return (controller) => {
|
|
2168
1002
|
while (true) {
|
|
2169
1003
|
const currentToolCall = getCurrentToolCall();
|
|
@@ -2176,8 +1010,7 @@ function createProcessBufferHandler(getBuffer, setBuffer, getCurrentToolCall, se
|
|
|
2176
1010
|
controller,
|
|
2177
1011
|
flushText,
|
|
2178
1012
|
setBuffer,
|
|
2179
|
-
|
|
2180
|
-
maxReparses
|
|
1013
|
+
parseOptions
|
|
2181
1014
|
});
|
|
2182
1015
|
setBuffer(result.buffer);
|
|
2183
1016
|
setCurrentToolCall(result.currentToolCall);
|
|
@@ -2192,8 +1025,7 @@ function createProcessBufferHandler(getBuffer, setBuffer, getCurrentToolCall, se
|
|
|
2192
1025
|
flushText,
|
|
2193
1026
|
tools,
|
|
2194
1027
|
options,
|
|
2195
|
-
|
|
2196
|
-
maxReparses,
|
|
1028
|
+
parseOptions,
|
|
2197
1029
|
setBuffer
|
|
2198
1030
|
});
|
|
2199
1031
|
setBuffer(result.buffer);
|
|
@@ -2210,43 +1042,12 @@ function createProcessBufferHandler(getBuffer, setBuffer, getCurrentToolCall, se
|
|
|
2210
1042
|
};
|
|
2211
1043
|
}
|
|
2212
1044
|
var xmlProtocol = (protocolOptions) => {
|
|
2213
|
-
var _a
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
fallbackReparse: [],
|
|
2220
|
-
postParse: []
|
|
2221
|
-
};
|
|
2222
|
-
for (const h of protocolOptions.heuristics) {
|
|
2223
|
-
if (h.phase === "pre-parse") {
|
|
2224
|
-
(_a = heuristicsConfig.preParse) == null ? void 0 : _a.push(h);
|
|
2225
|
-
} else if (h.phase === "fallback-reparse") {
|
|
2226
|
-
(_b = heuristicsConfig.fallbackReparse) == null ? void 0 : _b.push(h);
|
|
2227
|
-
} else if (h.phase === "post-parse") {
|
|
2228
|
-
(_c = heuristicsConfig.postParse) == null ? void 0 : _c.push(h);
|
|
2229
|
-
}
|
|
2230
|
-
}
|
|
2231
|
-
if (pipelineConfig) {
|
|
2232
|
-
pipelineConfig = {
|
|
2233
|
-
preParse: [
|
|
2234
|
-
...(_d = pipelineConfig.preParse) != null ? _d : [],
|
|
2235
|
-
...(_e = heuristicsConfig.preParse) != null ? _e : []
|
|
2236
|
-
],
|
|
2237
|
-
fallbackReparse: [
|
|
2238
|
-
...(_f = pipelineConfig.fallbackReparse) != null ? _f : [],
|
|
2239
|
-
...(_g = heuristicsConfig.fallbackReparse) != null ? _g : []
|
|
2240
|
-
],
|
|
2241
|
-
postParse: [
|
|
2242
|
-
...(_h = pipelineConfig.postParse) != null ? _h : [],
|
|
2243
|
-
...(_i = heuristicsConfig.postParse) != null ? _i : []
|
|
2244
|
-
]
|
|
2245
|
-
};
|
|
2246
|
-
} else {
|
|
2247
|
-
pipelineConfig = heuristicsConfig;
|
|
2248
|
-
}
|
|
2249
|
-
}
|
|
1045
|
+
var _a;
|
|
1046
|
+
const parseOptions = {
|
|
1047
|
+
repair: true,
|
|
1048
|
+
noChildNodes: [],
|
|
1049
|
+
...(_a = protocolOptions == null ? void 0 : protocolOptions.parseOptions) != null ? _a : {}
|
|
1050
|
+
};
|
|
2250
1051
|
return {
|
|
2251
1052
|
formatTools({ tools, toolSystemPromptTemplate }) {
|
|
2252
1053
|
return toolSystemPromptTemplate(tools || []);
|
|
@@ -2260,7 +1061,7 @@ var xmlProtocol = (protocolOptions) => {
|
|
|
2260
1061
|
args = toolCall.input;
|
|
2261
1062
|
}
|
|
2262
1063
|
}
|
|
2263
|
-
return (0,
|
|
1064
|
+
return (0, import_rxml.stringify)(toolCall.toolName, args, {
|
|
2264
1065
|
suppressEmptyNode: false,
|
|
2265
1066
|
format: true,
|
|
2266
1067
|
minimalEscaping: true
|
|
@@ -2281,14 +1082,13 @@ var xmlProtocol = (protocolOptions) => {
|
|
|
2281
1082
|
text: text.substring(currentIndex, tc.startIndex)
|
|
2282
1083
|
});
|
|
2283
1084
|
}
|
|
2284
|
-
|
|
1085
|
+
processToolCall({
|
|
2285
1086
|
toolCall: tc,
|
|
2286
1087
|
tools,
|
|
2287
1088
|
options,
|
|
2288
1089
|
text,
|
|
2289
1090
|
processedElements,
|
|
2290
|
-
|
|
2291
|
-
maxReparses
|
|
1091
|
+
parseOptions
|
|
2292
1092
|
});
|
|
2293
1093
|
currentIndex = tc.endIndex;
|
|
2294
1094
|
}
|
|
@@ -2329,8 +1129,7 @@ var xmlProtocol = (protocolOptions) => {
|
|
|
2329
1129
|
options,
|
|
2330
1130
|
toolNames,
|
|
2331
1131
|
flushText,
|
|
2332
|
-
|
|
2333
|
-
maxReparses
|
|
1132
|
+
parseOptions
|
|
2334
1133
|
);
|
|
2335
1134
|
return new TransformStream({
|
|
2336
1135
|
transform(chunk, controller) {
|
|
@@ -2380,8 +1179,8 @@ var xmlProtocol = (protocolOptions) => {
|
|
|
2380
1179
|
|
|
2381
1180
|
// src/core/protocols/yaml-protocol.ts
|
|
2382
1181
|
var import_yaml = __toESM(require("yaml"), 1);
|
|
2383
|
-
var
|
|
2384
|
-
var
|
|
1182
|
+
var NAME_CHAR_RE2 = /[A-Za-z0-9_:-]/;
|
|
1183
|
+
var WHITESPACE_REGEX2 = /\s/;
|
|
2385
1184
|
var LEADING_WHITESPACE_RE = /^(\s*)/;
|
|
2386
1185
|
function findClosingTagEnd(text, contentStart, toolName) {
|
|
2387
1186
|
let pos = contentStart;
|
|
@@ -2398,11 +1197,11 @@ function findClosingTagEnd(text, contentStart, toolName) {
|
|
|
2398
1197
|
break;
|
|
2399
1198
|
}
|
|
2400
1199
|
let p = ltIdx + 2;
|
|
2401
|
-
while (p < gtIdx &&
|
|
1200
|
+
while (p < gtIdx && WHITESPACE_REGEX2.test(text[p])) {
|
|
2402
1201
|
p++;
|
|
2403
1202
|
}
|
|
2404
1203
|
const nameStart = p;
|
|
2405
|
-
while (p < gtIdx &&
|
|
1204
|
+
while (p < gtIdx && NAME_CHAR_RE2.test(text.charAt(p))) {
|
|
2406
1205
|
p++;
|
|
2407
1206
|
}
|
|
2408
1207
|
const name = text.slice(nameStart, p);
|
|
@@ -2418,11 +1217,11 @@ function findClosingTagEnd(text, contentStart, toolName) {
|
|
|
2418
1217
|
pos = gtIdx === -1 ? text.length : gtIdx + 1;
|
|
2419
1218
|
} else {
|
|
2420
1219
|
let p = ltIdx + 1;
|
|
2421
|
-
while (p < text.length &&
|
|
1220
|
+
while (p < text.length && WHITESPACE_REGEX2.test(text[p])) {
|
|
2422
1221
|
p++;
|
|
2423
1222
|
}
|
|
2424
1223
|
const nameStart = p;
|
|
2425
|
-
while (p < text.length &&
|
|
1224
|
+
while (p < text.length && NAME_CHAR_RE2.test(text.charAt(p))) {
|
|
2426
1225
|
p++;
|
|
2427
1226
|
}
|
|
2428
1227
|
const name = text.slice(nameStart, p);
|
|
@@ -2431,7 +1230,7 @@ function findClosingTagEnd(text, contentStart, toolName) {
|
|
|
2431
1230
|
break;
|
|
2432
1231
|
}
|
|
2433
1232
|
let r = gtIdx - 1;
|
|
2434
|
-
while (r >= nameStart &&
|
|
1233
|
+
while (r >= nameStart && WHITESPACE_REGEX2.test(text[r])) {
|
|
2435
1234
|
r--;
|
|
2436
1235
|
}
|
|
2437
1236
|
const selfClosing = text[r] === "/";
|
|
@@ -2936,7 +1735,7 @@ function hasInputProperty(obj) {
|
|
|
2936
1735
|
|
|
2937
1736
|
// src/generate-handler.ts
|
|
2938
1737
|
var import_provider_utils = require("@ai-sdk/provider-utils");
|
|
2939
|
-
var
|
|
1738
|
+
var import_schema_coerce = require("@ai-sdk-tool/schema-coerce");
|
|
2940
1739
|
function parseToolChoiceJson(text, providerOptions) {
|
|
2941
1740
|
var _a;
|
|
2942
1741
|
try {
|
|
@@ -3098,7 +1897,7 @@ function fixToolCallWithSchema(part, tools) {
|
|
|
3098
1897
|
args = part.input;
|
|
3099
1898
|
}
|
|
3100
1899
|
const schema = (_a = tools.find((t) => t.name === part.toolName)) == null ? void 0 : _a.inputSchema;
|
|
3101
|
-
const coerced = (0,
|
|
1900
|
+
const coerced = (0, import_schema_coerce.coerceBySchema)(args, schema);
|
|
3102
1901
|
return {
|
|
3103
1902
|
...part,
|
|
3104
1903
|
input: JSON.stringify(coerced != null ? coerced : {})
|
|
@@ -3762,20 +2561,12 @@ function createToolMiddleware({
|
|
|
3762
2561
|
const resolvedProtocol = isTCMProtocolFactory(protocol) ? protocol() : protocol;
|
|
3763
2562
|
return {
|
|
3764
2563
|
specificationVersion: "v3",
|
|
3765
|
-
wrapStream: ({ doStream, doGenerate, params }) => {
|
|
3766
|
-
|
|
3767
|
-
|
|
3768
|
-
|
|
3769
|
-
|
|
3770
|
-
|
|
3771
|
-
}
|
|
3772
|
-
return wrapStream({
|
|
3773
|
-
protocol: resolvedProtocol,
|
|
3774
|
-
doStream,
|
|
3775
|
-
doGenerate,
|
|
3776
|
-
params
|
|
3777
|
-
});
|
|
3778
|
-
},
|
|
2564
|
+
wrapStream: ({ doStream, doGenerate, params }) => wrapStream({
|
|
2565
|
+
protocol: resolvedProtocol,
|
|
2566
|
+
doStream,
|
|
2567
|
+
doGenerate,
|
|
2568
|
+
params
|
|
2569
|
+
}),
|
|
3779
2570
|
wrapGenerate: async ({ doGenerate, params }) => wrapGenerate({
|
|
3780
2571
|
protocol: resolvedProtocol,
|
|
3781
2572
|
doGenerate,
|
|
@@ -3809,16 +2600,10 @@ var yamlToolMiddleware = createToolMiddleware({
|
|
|
3809
2600
|
});
|
|
3810
2601
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3811
2602
|
0 && (module.exports = {
|
|
3812
|
-
applyHeuristicPipeline,
|
|
3813
|
-
balanceTagsHeuristic,
|
|
3814
2603
|
createDynamicIfThenElseSchema,
|
|
3815
|
-
createIntermediateCall,
|
|
3816
2604
|
createToolMiddleware,
|
|
3817
2605
|
decodeOriginalTools,
|
|
3818
|
-
dedupeShellStringTagsHeuristic,
|
|
3819
|
-
defaultPipelineConfig,
|
|
3820
2606
|
encodeOriginalTools,
|
|
3821
|
-
escapeInvalidLtHeuristic,
|
|
3822
2607
|
escapeRegExp,
|
|
3823
2608
|
extractOnErrorOption,
|
|
3824
2609
|
extractToolNamesFromOriginalTools,
|
|
@@ -3835,20 +2620,15 @@ var yamlToolMiddleware = createToolMiddleware({
|
|
|
3835
2620
|
logParsedChunk,
|
|
3836
2621
|
logParsedSummary,
|
|
3837
2622
|
logRawChunk,
|
|
3838
|
-
mergePipelineConfigs,
|
|
3839
|
-
normalizeCloseTagsHeuristic,
|
|
3840
2623
|
originalToolsSchema,
|
|
3841
|
-
parse,
|
|
3842
|
-
repairAgainstSchemaHeuristic,
|
|
3843
|
-
stringify,
|
|
3844
2624
|
toolChoiceStream,
|
|
3845
|
-
transform,
|
|
3846
2625
|
transformParams,
|
|
3847
2626
|
wrapGenerate,
|
|
3848
2627
|
wrapStream,
|
|
3849
2628
|
xmlProtocol,
|
|
3850
2629
|
xmlToolMiddleware,
|
|
3851
2630
|
yamlProtocol,
|
|
3852
|
-
yamlToolMiddleware
|
|
2631
|
+
yamlToolMiddleware,
|
|
2632
|
+
...require("@ai-sdk-tool/rjson")
|
|
3853
2633
|
});
|
|
3854
2634
|
//# sourceMappingURL=index.cjs.map
|