@mastra/client-js 1.8.4 → 1.8.5-alpha.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/CHANGELOG.md +8 -0
- package/dist/_types/@internal_ai-sdk-v5/dist/index.d.ts +33 -46
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +18 -1073
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +16 -1071
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -1,1068 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var uiUtils = require('@ai-sdk/ui-utils');
|
|
3
4
|
var uuid = require('@lukeed/uuid');
|
|
4
5
|
var error = require('@mastra/core/error');
|
|
5
6
|
var schema = require('@mastra/schema-compat/schema');
|
|
6
7
|
var requestContext = require('@mastra/core/request-context');
|
|
7
8
|
var zodToJson = require('@mastra/schema-compat/zod-to-json');
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
var __defProp = Object.defineProperty;
|
|
11
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
14
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
15
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
16
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
17
|
-
};
|
|
18
|
-
var __copyProps = (to, from, except, desc) => {
|
|
19
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
-
for (let key of __getOwnPropNames(from))
|
|
21
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
-
}
|
|
24
|
-
return to;
|
|
25
|
-
};
|
|
26
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
27
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
28
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
29
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
30
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
31
|
-
__defProp(target, "default", { value: mod, enumerable: true }) ,
|
|
32
|
-
mod
|
|
33
|
-
));
|
|
34
|
-
|
|
35
|
-
// ../../node_modules/.pnpm/secure-json-parse@2.7.0/node_modules/secure-json-parse/index.js
|
|
36
|
-
var require_secure_json_parse = __commonJS({
|
|
37
|
-
"../../node_modules/.pnpm/secure-json-parse@2.7.0/node_modules/secure-json-parse/index.js"(exports$1, module) {
|
|
38
|
-
var hasBuffer = typeof Buffer !== "undefined";
|
|
39
|
-
var suspectProtoRx = /"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*:/;
|
|
40
|
-
var suspectConstructorRx = /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/;
|
|
41
|
-
function _parse(text, reviver, options) {
|
|
42
|
-
if (options == null) {
|
|
43
|
-
if (reviver !== null && typeof reviver === "object") {
|
|
44
|
-
options = reviver;
|
|
45
|
-
reviver = void 0;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
if (hasBuffer && Buffer.isBuffer(text)) {
|
|
49
|
-
text = text.toString();
|
|
50
|
-
}
|
|
51
|
-
if (text && text.charCodeAt(0) === 65279) {
|
|
52
|
-
text = text.slice(1);
|
|
53
|
-
}
|
|
54
|
-
const obj = JSON.parse(text, reviver);
|
|
55
|
-
if (obj === null || typeof obj !== "object") {
|
|
56
|
-
return obj;
|
|
57
|
-
}
|
|
58
|
-
const protoAction = options && options.protoAction || "error";
|
|
59
|
-
const constructorAction = options && options.constructorAction || "error";
|
|
60
|
-
if (protoAction === "ignore" && constructorAction === "ignore") {
|
|
61
|
-
return obj;
|
|
62
|
-
}
|
|
63
|
-
if (protoAction !== "ignore" && constructorAction !== "ignore") {
|
|
64
|
-
if (suspectProtoRx.test(text) === false && suspectConstructorRx.test(text) === false) {
|
|
65
|
-
return obj;
|
|
66
|
-
}
|
|
67
|
-
} else if (protoAction !== "ignore" && constructorAction === "ignore") {
|
|
68
|
-
if (suspectProtoRx.test(text) === false) {
|
|
69
|
-
return obj;
|
|
70
|
-
}
|
|
71
|
-
} else {
|
|
72
|
-
if (suspectConstructorRx.test(text) === false) {
|
|
73
|
-
return obj;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return filter(obj, { protoAction, constructorAction, safe: options && options.safe });
|
|
77
|
-
}
|
|
78
|
-
function filter(obj, { protoAction = "error", constructorAction = "error", safe } = {}) {
|
|
79
|
-
let next = [obj];
|
|
80
|
-
while (next.length) {
|
|
81
|
-
const nodes = next;
|
|
82
|
-
next = [];
|
|
83
|
-
for (const node of nodes) {
|
|
84
|
-
if (protoAction !== "ignore" && Object.prototype.hasOwnProperty.call(node, "__proto__")) {
|
|
85
|
-
if (safe === true) {
|
|
86
|
-
return null;
|
|
87
|
-
} else if (protoAction === "error") {
|
|
88
|
-
throw new SyntaxError("Object contains forbidden prototype property");
|
|
89
|
-
}
|
|
90
|
-
delete node.__proto__;
|
|
91
|
-
}
|
|
92
|
-
if (constructorAction !== "ignore" && Object.prototype.hasOwnProperty.call(node, "constructor") && Object.prototype.hasOwnProperty.call(node.constructor, "prototype")) {
|
|
93
|
-
if (safe === true) {
|
|
94
|
-
return null;
|
|
95
|
-
} else if (constructorAction === "error") {
|
|
96
|
-
throw new SyntaxError("Object contains forbidden prototype property");
|
|
97
|
-
}
|
|
98
|
-
delete node.constructor;
|
|
99
|
-
}
|
|
100
|
-
for (const key in node) {
|
|
101
|
-
const value = node[key];
|
|
102
|
-
if (value && typeof value === "object") {
|
|
103
|
-
next.push(value);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
return obj;
|
|
109
|
-
}
|
|
110
|
-
function parse(text, reviver, options) {
|
|
111
|
-
const stackTraceLimit = Error.stackTraceLimit;
|
|
112
|
-
Error.stackTraceLimit = 0;
|
|
113
|
-
try {
|
|
114
|
-
return _parse(text, reviver, options);
|
|
115
|
-
} finally {
|
|
116
|
-
Error.stackTraceLimit = stackTraceLimit;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
function safeParse(text, reviver) {
|
|
120
|
-
const stackTraceLimit = Error.stackTraceLimit;
|
|
121
|
-
Error.stackTraceLimit = 0;
|
|
122
|
-
try {
|
|
123
|
-
return _parse(text, reviver, { safe: true });
|
|
124
|
-
} catch (_e) {
|
|
125
|
-
return null;
|
|
126
|
-
} finally {
|
|
127
|
-
Error.stackTraceLimit = stackTraceLimit;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
module.exports = parse;
|
|
131
|
-
module.exports.default = parse;
|
|
132
|
-
module.exports.parse = parse;
|
|
133
|
-
module.exports.safeParse = safeParse;
|
|
134
|
-
module.exports.scan = filter;
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
// ../../node_modules/.pnpm/@ai-sdk+provider@1.1.3/node_modules/@ai-sdk/provider/dist/index.mjs
|
|
139
|
-
var marker = "vercel.ai.error";
|
|
140
|
-
var symbol = Symbol.for(marker);
|
|
141
|
-
var _a;
|
|
142
|
-
var _AISDKError = class _AISDKError2 extends Error {
|
|
143
|
-
/**
|
|
144
|
-
* Creates an AI SDK Error.
|
|
145
|
-
*
|
|
146
|
-
* @param {Object} params - The parameters for creating the error.
|
|
147
|
-
* @param {string} params.name - The name of the error.
|
|
148
|
-
* @param {string} params.message - The error message.
|
|
149
|
-
* @param {unknown} [params.cause] - The underlying cause of the error.
|
|
150
|
-
*/
|
|
151
|
-
constructor({
|
|
152
|
-
name: name14,
|
|
153
|
-
message,
|
|
154
|
-
cause
|
|
155
|
-
}) {
|
|
156
|
-
super(message);
|
|
157
|
-
this[_a] = true;
|
|
158
|
-
this.name = name14;
|
|
159
|
-
this.cause = cause;
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Checks if the given error is an AI SDK Error.
|
|
163
|
-
* @param {unknown} error - The error to check.
|
|
164
|
-
* @returns {boolean} True if the error is an AI SDK Error, false otherwise.
|
|
165
|
-
*/
|
|
166
|
-
static isInstance(error) {
|
|
167
|
-
return _AISDKError2.hasMarker(error, marker);
|
|
168
|
-
}
|
|
169
|
-
static hasMarker(error, marker15) {
|
|
170
|
-
const markerSymbol = Symbol.for(marker15);
|
|
171
|
-
return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
_a = symbol;
|
|
175
|
-
var AISDKError = _AISDKError;
|
|
176
|
-
function getErrorMessage(error) {
|
|
177
|
-
if (error == null) {
|
|
178
|
-
return "unknown error";
|
|
179
|
-
}
|
|
180
|
-
if (typeof error === "string") {
|
|
181
|
-
return error;
|
|
182
|
-
}
|
|
183
|
-
if (error instanceof Error) {
|
|
184
|
-
return error.message;
|
|
185
|
-
}
|
|
186
|
-
return JSON.stringify(error);
|
|
187
|
-
}
|
|
188
|
-
var name3 = "AI_InvalidArgumentError";
|
|
189
|
-
var marker4 = `vercel.ai.error.${name3}`;
|
|
190
|
-
var symbol4 = Symbol.for(marker4);
|
|
191
|
-
var _a4;
|
|
192
|
-
var InvalidArgumentError = class extends AISDKError {
|
|
193
|
-
constructor({
|
|
194
|
-
message,
|
|
195
|
-
cause,
|
|
196
|
-
argument
|
|
197
|
-
}) {
|
|
198
|
-
super({ name: name3, message, cause });
|
|
199
|
-
this[_a4] = true;
|
|
200
|
-
this.argument = argument;
|
|
201
|
-
}
|
|
202
|
-
static isInstance(error) {
|
|
203
|
-
return AISDKError.hasMarker(error, marker4);
|
|
204
|
-
}
|
|
205
|
-
};
|
|
206
|
-
_a4 = symbol4;
|
|
207
|
-
var name6 = "AI_JSONParseError";
|
|
208
|
-
var marker7 = `vercel.ai.error.${name6}`;
|
|
209
|
-
var symbol7 = Symbol.for(marker7);
|
|
210
|
-
var _a7;
|
|
211
|
-
var JSONParseError = class extends AISDKError {
|
|
212
|
-
constructor({ text, cause }) {
|
|
213
|
-
super({
|
|
214
|
-
name: name6,
|
|
215
|
-
message: `JSON parsing failed: Text: ${text}.
|
|
216
|
-
Error message: ${getErrorMessage(cause)}`,
|
|
217
|
-
cause
|
|
218
|
-
});
|
|
219
|
-
this[_a7] = true;
|
|
220
|
-
this.text = text;
|
|
221
|
-
}
|
|
222
|
-
static isInstance(error) {
|
|
223
|
-
return AISDKError.hasMarker(error, marker7);
|
|
224
|
-
}
|
|
225
|
-
};
|
|
226
|
-
_a7 = symbol7;
|
|
227
|
-
var name12 = "AI_TypeValidationError";
|
|
228
|
-
var marker13 = `vercel.ai.error.${name12}`;
|
|
229
|
-
var symbol13 = Symbol.for(marker13);
|
|
230
|
-
var _a13;
|
|
231
|
-
var _TypeValidationError = class _TypeValidationError2 extends AISDKError {
|
|
232
|
-
constructor({ value, cause }) {
|
|
233
|
-
super({
|
|
234
|
-
name: name12,
|
|
235
|
-
message: `Type validation failed: Value: ${JSON.stringify(value)}.
|
|
236
|
-
Error message: ${getErrorMessage(cause)}`,
|
|
237
|
-
cause
|
|
238
|
-
});
|
|
239
|
-
this[_a13] = true;
|
|
240
|
-
this.value = value;
|
|
241
|
-
}
|
|
242
|
-
static isInstance(error) {
|
|
243
|
-
return AISDKError.hasMarker(error, marker13);
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* Wraps an error into a TypeValidationError.
|
|
247
|
-
* If the cause is already a TypeValidationError with the same value, it returns the cause.
|
|
248
|
-
* Otherwise, it creates a new TypeValidationError.
|
|
249
|
-
*
|
|
250
|
-
* @param {Object} params - The parameters for wrapping the error.
|
|
251
|
-
* @param {unknown} params.value - The value that failed validation.
|
|
252
|
-
* @param {unknown} params.cause - The original error or cause of the validation failure.
|
|
253
|
-
* @returns {TypeValidationError} A TypeValidationError instance.
|
|
254
|
-
*/
|
|
255
|
-
static wrap({
|
|
256
|
-
value,
|
|
257
|
-
cause
|
|
258
|
-
}) {
|
|
259
|
-
return _TypeValidationError2.isInstance(cause) && cause.value === value ? cause : new _TypeValidationError2({ value, cause });
|
|
260
|
-
}
|
|
261
|
-
};
|
|
262
|
-
_a13 = symbol13;
|
|
263
|
-
var TypeValidationError = _TypeValidationError;
|
|
264
|
-
|
|
265
|
-
// ../../node_modules/.pnpm/nanoid@3.3.11/node_modules/nanoid/non-secure/index.js
|
|
266
|
-
var customAlphabet = (alphabet, defaultSize = 21) => {
|
|
267
|
-
return (size = defaultSize) => {
|
|
268
|
-
let id = "";
|
|
269
|
-
let i = size | 0;
|
|
270
|
-
while (i--) {
|
|
271
|
-
id += alphabet[Math.random() * alphabet.length | 0];
|
|
272
|
-
}
|
|
273
|
-
return id;
|
|
274
|
-
};
|
|
275
|
-
};
|
|
276
|
-
|
|
277
|
-
// ../../node_modules/.pnpm/@ai-sdk+provider-utils@2.2.8_zod@4.3.6/node_modules/@ai-sdk/provider-utils/dist/index.mjs
|
|
278
|
-
var import_secure_json_parse = __toESM(require_secure_json_parse());
|
|
279
|
-
var createIdGenerator = ({
|
|
280
|
-
prefix,
|
|
281
|
-
size: defaultSize = 16,
|
|
282
|
-
alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
|
|
283
|
-
separator = "-"
|
|
284
|
-
} = {}) => {
|
|
285
|
-
const generator = customAlphabet(alphabet, defaultSize);
|
|
286
|
-
if (prefix == null) {
|
|
287
|
-
return generator;
|
|
288
|
-
}
|
|
289
|
-
if (alphabet.includes(separator)) {
|
|
290
|
-
throw new InvalidArgumentError({
|
|
291
|
-
argument: "separator",
|
|
292
|
-
message: `The separator "${separator}" must not be part of the alphabet "${alphabet}".`
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
|
-
return (size) => `${prefix}${separator}${generator(size)}`;
|
|
296
|
-
};
|
|
297
|
-
createIdGenerator();
|
|
298
|
-
var validatorSymbol = /* @__PURE__ */ Symbol.for("vercel.ai.validator");
|
|
299
|
-
function validator(validate) {
|
|
300
|
-
return { [validatorSymbol]: true, validate };
|
|
301
|
-
}
|
|
302
|
-
function isValidator(value) {
|
|
303
|
-
return typeof value === "object" && value !== null && validatorSymbol in value && value[validatorSymbol] === true && "validate" in value;
|
|
304
|
-
}
|
|
305
|
-
function asValidator(value) {
|
|
306
|
-
return isValidator(value) ? value : zodValidator(value);
|
|
307
|
-
}
|
|
308
|
-
function zodValidator(zodSchema) {
|
|
309
|
-
return validator((value) => {
|
|
310
|
-
const result = zodSchema.safeParse(value);
|
|
311
|
-
return result.success ? { success: true, value: result.data } : { success: false, error: result.error };
|
|
312
|
-
});
|
|
313
|
-
}
|
|
314
|
-
function safeValidateTypes({
|
|
315
|
-
value,
|
|
316
|
-
schema
|
|
317
|
-
}) {
|
|
318
|
-
const validator2 = asValidator(schema);
|
|
319
|
-
try {
|
|
320
|
-
if (validator2.validate == null) {
|
|
321
|
-
return { success: true, value };
|
|
322
|
-
}
|
|
323
|
-
const result = validator2.validate(value);
|
|
324
|
-
if (result.success) {
|
|
325
|
-
return result;
|
|
326
|
-
}
|
|
327
|
-
return {
|
|
328
|
-
success: false,
|
|
329
|
-
error: TypeValidationError.wrap({ value, cause: result.error })
|
|
330
|
-
};
|
|
331
|
-
} catch (error) {
|
|
332
|
-
return {
|
|
333
|
-
success: false,
|
|
334
|
-
error: TypeValidationError.wrap({ value, cause: error })
|
|
335
|
-
};
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
function safeParseJSON({
|
|
339
|
-
text,
|
|
340
|
-
schema
|
|
341
|
-
}) {
|
|
342
|
-
try {
|
|
343
|
-
const value = import_secure_json_parse.default.parse(text);
|
|
344
|
-
if (schema == null) {
|
|
345
|
-
return { success: true, value, rawValue: value };
|
|
346
|
-
}
|
|
347
|
-
const validationResult = safeValidateTypes({ value, schema });
|
|
348
|
-
return validationResult.success ? { ...validationResult, rawValue: value } : validationResult;
|
|
349
|
-
} catch (error) {
|
|
350
|
-
return {
|
|
351
|
-
success: false,
|
|
352
|
-
error: JSONParseError.isInstance(error) ? error : new JSONParseError({ text, cause: error })
|
|
353
|
-
};
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
// ../../node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@4.3.6/node_modules/zod-to-json-schema/dist/esm/parsers/string.js
|
|
358
|
-
new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");
|
|
359
|
-
function fixJson(input) {
|
|
360
|
-
const stack = ["ROOT"];
|
|
361
|
-
let lastValidIndex = -1;
|
|
362
|
-
let literalStart = null;
|
|
363
|
-
function processValueStart(char, i, swapState) {
|
|
364
|
-
{
|
|
365
|
-
switch (char) {
|
|
366
|
-
case '"': {
|
|
367
|
-
lastValidIndex = i;
|
|
368
|
-
stack.pop();
|
|
369
|
-
stack.push(swapState);
|
|
370
|
-
stack.push("INSIDE_STRING");
|
|
371
|
-
break;
|
|
372
|
-
}
|
|
373
|
-
case "f":
|
|
374
|
-
case "t":
|
|
375
|
-
case "n": {
|
|
376
|
-
lastValidIndex = i;
|
|
377
|
-
literalStart = i;
|
|
378
|
-
stack.pop();
|
|
379
|
-
stack.push(swapState);
|
|
380
|
-
stack.push("INSIDE_LITERAL");
|
|
381
|
-
break;
|
|
382
|
-
}
|
|
383
|
-
case "-": {
|
|
384
|
-
stack.pop();
|
|
385
|
-
stack.push(swapState);
|
|
386
|
-
stack.push("INSIDE_NUMBER");
|
|
387
|
-
break;
|
|
388
|
-
}
|
|
389
|
-
case "0":
|
|
390
|
-
case "1":
|
|
391
|
-
case "2":
|
|
392
|
-
case "3":
|
|
393
|
-
case "4":
|
|
394
|
-
case "5":
|
|
395
|
-
case "6":
|
|
396
|
-
case "7":
|
|
397
|
-
case "8":
|
|
398
|
-
case "9": {
|
|
399
|
-
lastValidIndex = i;
|
|
400
|
-
stack.pop();
|
|
401
|
-
stack.push(swapState);
|
|
402
|
-
stack.push("INSIDE_NUMBER");
|
|
403
|
-
break;
|
|
404
|
-
}
|
|
405
|
-
case "{": {
|
|
406
|
-
lastValidIndex = i;
|
|
407
|
-
stack.pop();
|
|
408
|
-
stack.push(swapState);
|
|
409
|
-
stack.push("INSIDE_OBJECT_START");
|
|
410
|
-
break;
|
|
411
|
-
}
|
|
412
|
-
case "[": {
|
|
413
|
-
lastValidIndex = i;
|
|
414
|
-
stack.pop();
|
|
415
|
-
stack.push(swapState);
|
|
416
|
-
stack.push("INSIDE_ARRAY_START");
|
|
417
|
-
break;
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
function processAfterObjectValue(char, i) {
|
|
423
|
-
switch (char) {
|
|
424
|
-
case ",": {
|
|
425
|
-
stack.pop();
|
|
426
|
-
stack.push("INSIDE_OBJECT_AFTER_COMMA");
|
|
427
|
-
break;
|
|
428
|
-
}
|
|
429
|
-
case "}": {
|
|
430
|
-
lastValidIndex = i;
|
|
431
|
-
stack.pop();
|
|
432
|
-
break;
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
function processAfterArrayValue(char, i) {
|
|
437
|
-
switch (char) {
|
|
438
|
-
case ",": {
|
|
439
|
-
stack.pop();
|
|
440
|
-
stack.push("INSIDE_ARRAY_AFTER_COMMA");
|
|
441
|
-
break;
|
|
442
|
-
}
|
|
443
|
-
case "]": {
|
|
444
|
-
lastValidIndex = i;
|
|
445
|
-
stack.pop();
|
|
446
|
-
break;
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
for (let i = 0; i < input.length; i++) {
|
|
451
|
-
const char = input[i];
|
|
452
|
-
const currentState = stack[stack.length - 1];
|
|
453
|
-
switch (currentState) {
|
|
454
|
-
case "ROOT":
|
|
455
|
-
processValueStart(char, i, "FINISH");
|
|
456
|
-
break;
|
|
457
|
-
case "INSIDE_OBJECT_START": {
|
|
458
|
-
switch (char) {
|
|
459
|
-
case '"': {
|
|
460
|
-
stack.pop();
|
|
461
|
-
stack.push("INSIDE_OBJECT_KEY");
|
|
462
|
-
break;
|
|
463
|
-
}
|
|
464
|
-
case "}": {
|
|
465
|
-
lastValidIndex = i;
|
|
466
|
-
stack.pop();
|
|
467
|
-
break;
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
break;
|
|
471
|
-
}
|
|
472
|
-
case "INSIDE_OBJECT_AFTER_COMMA": {
|
|
473
|
-
switch (char) {
|
|
474
|
-
case '"': {
|
|
475
|
-
stack.pop();
|
|
476
|
-
stack.push("INSIDE_OBJECT_KEY");
|
|
477
|
-
break;
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
break;
|
|
481
|
-
}
|
|
482
|
-
case "INSIDE_OBJECT_KEY": {
|
|
483
|
-
switch (char) {
|
|
484
|
-
case '"': {
|
|
485
|
-
stack.pop();
|
|
486
|
-
stack.push("INSIDE_OBJECT_AFTER_KEY");
|
|
487
|
-
break;
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
break;
|
|
491
|
-
}
|
|
492
|
-
case "INSIDE_OBJECT_AFTER_KEY": {
|
|
493
|
-
switch (char) {
|
|
494
|
-
case ":": {
|
|
495
|
-
stack.pop();
|
|
496
|
-
stack.push("INSIDE_OBJECT_BEFORE_VALUE");
|
|
497
|
-
break;
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
break;
|
|
501
|
-
}
|
|
502
|
-
case "INSIDE_OBJECT_BEFORE_VALUE": {
|
|
503
|
-
processValueStart(char, i, "INSIDE_OBJECT_AFTER_VALUE");
|
|
504
|
-
break;
|
|
505
|
-
}
|
|
506
|
-
case "INSIDE_OBJECT_AFTER_VALUE": {
|
|
507
|
-
processAfterObjectValue(char, i);
|
|
508
|
-
break;
|
|
509
|
-
}
|
|
510
|
-
case "INSIDE_STRING": {
|
|
511
|
-
switch (char) {
|
|
512
|
-
case '"': {
|
|
513
|
-
stack.pop();
|
|
514
|
-
lastValidIndex = i;
|
|
515
|
-
break;
|
|
516
|
-
}
|
|
517
|
-
case "\\": {
|
|
518
|
-
stack.push("INSIDE_STRING_ESCAPE");
|
|
519
|
-
break;
|
|
520
|
-
}
|
|
521
|
-
default: {
|
|
522
|
-
lastValidIndex = i;
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
break;
|
|
526
|
-
}
|
|
527
|
-
case "INSIDE_ARRAY_START": {
|
|
528
|
-
switch (char) {
|
|
529
|
-
case "]": {
|
|
530
|
-
lastValidIndex = i;
|
|
531
|
-
stack.pop();
|
|
532
|
-
break;
|
|
533
|
-
}
|
|
534
|
-
default: {
|
|
535
|
-
lastValidIndex = i;
|
|
536
|
-
processValueStart(char, i, "INSIDE_ARRAY_AFTER_VALUE");
|
|
537
|
-
break;
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
break;
|
|
541
|
-
}
|
|
542
|
-
case "INSIDE_ARRAY_AFTER_VALUE": {
|
|
543
|
-
switch (char) {
|
|
544
|
-
case ",": {
|
|
545
|
-
stack.pop();
|
|
546
|
-
stack.push("INSIDE_ARRAY_AFTER_COMMA");
|
|
547
|
-
break;
|
|
548
|
-
}
|
|
549
|
-
case "]": {
|
|
550
|
-
lastValidIndex = i;
|
|
551
|
-
stack.pop();
|
|
552
|
-
break;
|
|
553
|
-
}
|
|
554
|
-
default: {
|
|
555
|
-
lastValidIndex = i;
|
|
556
|
-
break;
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
break;
|
|
560
|
-
}
|
|
561
|
-
case "INSIDE_ARRAY_AFTER_COMMA": {
|
|
562
|
-
processValueStart(char, i, "INSIDE_ARRAY_AFTER_VALUE");
|
|
563
|
-
break;
|
|
564
|
-
}
|
|
565
|
-
case "INSIDE_STRING_ESCAPE": {
|
|
566
|
-
stack.pop();
|
|
567
|
-
lastValidIndex = i;
|
|
568
|
-
break;
|
|
569
|
-
}
|
|
570
|
-
case "INSIDE_NUMBER": {
|
|
571
|
-
switch (char) {
|
|
572
|
-
case "0":
|
|
573
|
-
case "1":
|
|
574
|
-
case "2":
|
|
575
|
-
case "3":
|
|
576
|
-
case "4":
|
|
577
|
-
case "5":
|
|
578
|
-
case "6":
|
|
579
|
-
case "7":
|
|
580
|
-
case "8":
|
|
581
|
-
case "9": {
|
|
582
|
-
lastValidIndex = i;
|
|
583
|
-
break;
|
|
584
|
-
}
|
|
585
|
-
case "e":
|
|
586
|
-
case "E":
|
|
587
|
-
case "-":
|
|
588
|
-
case ".": {
|
|
589
|
-
break;
|
|
590
|
-
}
|
|
591
|
-
case ",": {
|
|
592
|
-
stack.pop();
|
|
593
|
-
if (stack[stack.length - 1] === "INSIDE_ARRAY_AFTER_VALUE") {
|
|
594
|
-
processAfterArrayValue(char, i);
|
|
595
|
-
}
|
|
596
|
-
if (stack[stack.length - 1] === "INSIDE_OBJECT_AFTER_VALUE") {
|
|
597
|
-
processAfterObjectValue(char, i);
|
|
598
|
-
}
|
|
599
|
-
break;
|
|
600
|
-
}
|
|
601
|
-
case "}": {
|
|
602
|
-
stack.pop();
|
|
603
|
-
if (stack[stack.length - 1] === "INSIDE_OBJECT_AFTER_VALUE") {
|
|
604
|
-
processAfterObjectValue(char, i);
|
|
605
|
-
}
|
|
606
|
-
break;
|
|
607
|
-
}
|
|
608
|
-
case "]": {
|
|
609
|
-
stack.pop();
|
|
610
|
-
if (stack[stack.length - 1] === "INSIDE_ARRAY_AFTER_VALUE") {
|
|
611
|
-
processAfterArrayValue(char, i);
|
|
612
|
-
}
|
|
613
|
-
break;
|
|
614
|
-
}
|
|
615
|
-
default: {
|
|
616
|
-
stack.pop();
|
|
617
|
-
break;
|
|
618
|
-
}
|
|
619
|
-
}
|
|
620
|
-
break;
|
|
621
|
-
}
|
|
622
|
-
case "INSIDE_LITERAL": {
|
|
623
|
-
const partialLiteral = input.substring(literalStart, i + 1);
|
|
624
|
-
if (!"false".startsWith(partialLiteral) && !"true".startsWith(partialLiteral) && !"null".startsWith(partialLiteral)) {
|
|
625
|
-
stack.pop();
|
|
626
|
-
if (stack[stack.length - 1] === "INSIDE_OBJECT_AFTER_VALUE") {
|
|
627
|
-
processAfterObjectValue(char, i);
|
|
628
|
-
} else if (stack[stack.length - 1] === "INSIDE_ARRAY_AFTER_VALUE") {
|
|
629
|
-
processAfterArrayValue(char, i);
|
|
630
|
-
}
|
|
631
|
-
} else {
|
|
632
|
-
lastValidIndex = i;
|
|
633
|
-
}
|
|
634
|
-
break;
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
}
|
|
638
|
-
let result = input.slice(0, lastValidIndex + 1);
|
|
639
|
-
for (let i = stack.length - 1; i >= 0; i--) {
|
|
640
|
-
const state = stack[i];
|
|
641
|
-
switch (state) {
|
|
642
|
-
case "INSIDE_STRING": {
|
|
643
|
-
result += '"';
|
|
644
|
-
break;
|
|
645
|
-
}
|
|
646
|
-
case "INSIDE_OBJECT_KEY":
|
|
647
|
-
case "INSIDE_OBJECT_AFTER_KEY":
|
|
648
|
-
case "INSIDE_OBJECT_AFTER_COMMA":
|
|
649
|
-
case "INSIDE_OBJECT_START":
|
|
650
|
-
case "INSIDE_OBJECT_BEFORE_VALUE":
|
|
651
|
-
case "INSIDE_OBJECT_AFTER_VALUE": {
|
|
652
|
-
result += "}";
|
|
653
|
-
break;
|
|
654
|
-
}
|
|
655
|
-
case "INSIDE_ARRAY_START":
|
|
656
|
-
case "INSIDE_ARRAY_AFTER_COMMA":
|
|
657
|
-
case "INSIDE_ARRAY_AFTER_VALUE": {
|
|
658
|
-
result += "]";
|
|
659
|
-
break;
|
|
660
|
-
}
|
|
661
|
-
case "INSIDE_LITERAL": {
|
|
662
|
-
const partialLiteral = input.substring(literalStart, input.length);
|
|
663
|
-
if ("true".startsWith(partialLiteral)) {
|
|
664
|
-
result += "true".slice(partialLiteral.length);
|
|
665
|
-
} else if ("false".startsWith(partialLiteral)) {
|
|
666
|
-
result += "false".slice(partialLiteral.length);
|
|
667
|
-
} else if ("null".startsWith(partialLiteral)) {
|
|
668
|
-
result += "null".slice(partialLiteral.length);
|
|
669
|
-
}
|
|
670
|
-
}
|
|
671
|
-
}
|
|
672
|
-
}
|
|
673
|
-
return result;
|
|
674
|
-
}
|
|
675
|
-
function parsePartialJson(jsonText) {
|
|
676
|
-
if (jsonText === void 0) {
|
|
677
|
-
return { value: void 0, state: "undefined-input" };
|
|
678
|
-
}
|
|
679
|
-
let result = safeParseJSON({ text: jsonText });
|
|
680
|
-
if (result.success) {
|
|
681
|
-
return { value: result.value, state: "successful-parse" };
|
|
682
|
-
}
|
|
683
|
-
result = safeParseJSON({ text: fixJson(jsonText) });
|
|
684
|
-
if (result.success) {
|
|
685
|
-
return { value: result.value, state: "repaired-parse" };
|
|
686
|
-
}
|
|
687
|
-
return { value: void 0, state: "failed-parse" };
|
|
688
|
-
}
|
|
689
|
-
var textStreamPart2 = {
|
|
690
|
-
code: "0",
|
|
691
|
-
name: "text",
|
|
692
|
-
parse: (value) => {
|
|
693
|
-
if (typeof value !== "string") {
|
|
694
|
-
throw new Error('"text" parts expect a string value.');
|
|
695
|
-
}
|
|
696
|
-
return { type: "text", value };
|
|
697
|
-
}
|
|
698
|
-
};
|
|
699
|
-
var dataStreamPart = {
|
|
700
|
-
code: "2",
|
|
701
|
-
name: "data",
|
|
702
|
-
parse: (value) => {
|
|
703
|
-
if (!Array.isArray(value)) {
|
|
704
|
-
throw new Error('"data" parts expect an array value.');
|
|
705
|
-
}
|
|
706
|
-
return { type: "data", value };
|
|
707
|
-
}
|
|
708
|
-
};
|
|
709
|
-
var errorStreamPart2 = {
|
|
710
|
-
code: "3",
|
|
711
|
-
name: "error",
|
|
712
|
-
parse: (value) => {
|
|
713
|
-
if (typeof value !== "string") {
|
|
714
|
-
throw new Error('"error" parts expect a string value.');
|
|
715
|
-
}
|
|
716
|
-
return { type: "error", value };
|
|
717
|
-
}
|
|
718
|
-
};
|
|
719
|
-
var messageAnnotationsStreamPart = {
|
|
720
|
-
code: "8",
|
|
721
|
-
name: "message_annotations",
|
|
722
|
-
parse: (value) => {
|
|
723
|
-
if (!Array.isArray(value)) {
|
|
724
|
-
throw new Error('"message_annotations" parts expect an array value.');
|
|
725
|
-
}
|
|
726
|
-
return { type: "message_annotations", value };
|
|
727
|
-
}
|
|
728
|
-
};
|
|
729
|
-
var toolCallStreamPart = {
|
|
730
|
-
code: "9",
|
|
731
|
-
name: "tool_call",
|
|
732
|
-
parse: (value) => {
|
|
733
|
-
if (value == null || typeof value !== "object" || !("toolCallId" in value) || typeof value.toolCallId !== "string" || !("toolName" in value) || typeof value.toolName !== "string" || !("args" in value) || typeof value.args !== "object") {
|
|
734
|
-
throw new Error(
|
|
735
|
-
'"tool_call" parts expect an object with a "toolCallId", "toolName", and "args" property.'
|
|
736
|
-
);
|
|
737
|
-
}
|
|
738
|
-
return {
|
|
739
|
-
type: "tool_call",
|
|
740
|
-
value
|
|
741
|
-
};
|
|
742
|
-
}
|
|
743
|
-
};
|
|
744
|
-
var toolResultStreamPart = {
|
|
745
|
-
code: "a",
|
|
746
|
-
name: "tool_result",
|
|
747
|
-
parse: (value) => {
|
|
748
|
-
if (value == null || typeof value !== "object" || !("toolCallId" in value) || typeof value.toolCallId !== "string" || !("result" in value)) {
|
|
749
|
-
throw new Error(
|
|
750
|
-
'"tool_result" parts expect an object with a "toolCallId" and a "result" property.'
|
|
751
|
-
);
|
|
752
|
-
}
|
|
753
|
-
return {
|
|
754
|
-
type: "tool_result",
|
|
755
|
-
value
|
|
756
|
-
};
|
|
757
|
-
}
|
|
758
|
-
};
|
|
759
|
-
var toolCallStreamingStartStreamPart = {
|
|
760
|
-
code: "b",
|
|
761
|
-
name: "tool_call_streaming_start",
|
|
762
|
-
parse: (value) => {
|
|
763
|
-
if (value == null || typeof value !== "object" || !("toolCallId" in value) || typeof value.toolCallId !== "string" || !("toolName" in value) || typeof value.toolName !== "string") {
|
|
764
|
-
throw new Error(
|
|
765
|
-
'"tool_call_streaming_start" parts expect an object with a "toolCallId" and "toolName" property.'
|
|
766
|
-
);
|
|
767
|
-
}
|
|
768
|
-
return {
|
|
769
|
-
type: "tool_call_streaming_start",
|
|
770
|
-
value
|
|
771
|
-
};
|
|
772
|
-
}
|
|
773
|
-
};
|
|
774
|
-
var toolCallDeltaStreamPart = {
|
|
775
|
-
code: "c",
|
|
776
|
-
name: "tool_call_delta",
|
|
777
|
-
parse: (value) => {
|
|
778
|
-
if (value == null || typeof value !== "object" || !("toolCallId" in value) || typeof value.toolCallId !== "string" || !("argsTextDelta" in value) || typeof value.argsTextDelta !== "string") {
|
|
779
|
-
throw new Error(
|
|
780
|
-
'"tool_call_delta" parts expect an object with a "toolCallId" and "argsTextDelta" property.'
|
|
781
|
-
);
|
|
782
|
-
}
|
|
783
|
-
return {
|
|
784
|
-
type: "tool_call_delta",
|
|
785
|
-
value
|
|
786
|
-
};
|
|
787
|
-
}
|
|
788
|
-
};
|
|
789
|
-
var finishMessageStreamPart = {
|
|
790
|
-
code: "d",
|
|
791
|
-
name: "finish_message",
|
|
792
|
-
parse: (value) => {
|
|
793
|
-
if (value == null || typeof value !== "object" || !("finishReason" in value) || typeof value.finishReason !== "string") {
|
|
794
|
-
throw new Error(
|
|
795
|
-
'"finish_message" parts expect an object with a "finishReason" property.'
|
|
796
|
-
);
|
|
797
|
-
}
|
|
798
|
-
const result = {
|
|
799
|
-
finishReason: value.finishReason
|
|
800
|
-
};
|
|
801
|
-
if ("usage" in value && value.usage != null && typeof value.usage === "object" && "promptTokens" in value.usage && "completionTokens" in value.usage) {
|
|
802
|
-
result.usage = {
|
|
803
|
-
promptTokens: typeof value.usage.promptTokens === "number" ? value.usage.promptTokens : Number.NaN,
|
|
804
|
-
completionTokens: typeof value.usage.completionTokens === "number" ? value.usage.completionTokens : Number.NaN
|
|
805
|
-
};
|
|
806
|
-
}
|
|
807
|
-
return {
|
|
808
|
-
type: "finish_message",
|
|
809
|
-
value: result
|
|
810
|
-
};
|
|
811
|
-
}
|
|
812
|
-
};
|
|
813
|
-
var finishStepStreamPart = {
|
|
814
|
-
code: "e",
|
|
815
|
-
name: "finish_step",
|
|
816
|
-
parse: (value) => {
|
|
817
|
-
if (value == null || typeof value !== "object" || !("finishReason" in value) || typeof value.finishReason !== "string") {
|
|
818
|
-
throw new Error(
|
|
819
|
-
'"finish_step" parts expect an object with a "finishReason" property.'
|
|
820
|
-
);
|
|
821
|
-
}
|
|
822
|
-
const result = {
|
|
823
|
-
finishReason: value.finishReason,
|
|
824
|
-
isContinued: false
|
|
825
|
-
};
|
|
826
|
-
if ("usage" in value && value.usage != null && typeof value.usage === "object" && "promptTokens" in value.usage && "completionTokens" in value.usage) {
|
|
827
|
-
result.usage = {
|
|
828
|
-
promptTokens: typeof value.usage.promptTokens === "number" ? value.usage.promptTokens : Number.NaN,
|
|
829
|
-
completionTokens: typeof value.usage.completionTokens === "number" ? value.usage.completionTokens : Number.NaN
|
|
830
|
-
};
|
|
831
|
-
}
|
|
832
|
-
if ("isContinued" in value && typeof value.isContinued === "boolean") {
|
|
833
|
-
result.isContinued = value.isContinued;
|
|
834
|
-
}
|
|
835
|
-
return {
|
|
836
|
-
type: "finish_step",
|
|
837
|
-
value: result
|
|
838
|
-
};
|
|
839
|
-
}
|
|
840
|
-
};
|
|
841
|
-
var startStepStreamPart = {
|
|
842
|
-
code: "f",
|
|
843
|
-
name: "start_step",
|
|
844
|
-
parse: (value) => {
|
|
845
|
-
if (value == null || typeof value !== "object" || !("messageId" in value) || typeof value.messageId !== "string") {
|
|
846
|
-
throw new Error(
|
|
847
|
-
'"start_step" parts expect an object with an "id" property.'
|
|
848
|
-
);
|
|
849
|
-
}
|
|
850
|
-
return {
|
|
851
|
-
type: "start_step",
|
|
852
|
-
value: {
|
|
853
|
-
messageId: value.messageId
|
|
854
|
-
}
|
|
855
|
-
};
|
|
856
|
-
}
|
|
857
|
-
};
|
|
858
|
-
var reasoningStreamPart = {
|
|
859
|
-
code: "g",
|
|
860
|
-
name: "reasoning",
|
|
861
|
-
parse: (value) => {
|
|
862
|
-
if (typeof value !== "string") {
|
|
863
|
-
throw new Error('"reasoning" parts expect a string value.');
|
|
864
|
-
}
|
|
865
|
-
return { type: "reasoning", value };
|
|
866
|
-
}
|
|
867
|
-
};
|
|
868
|
-
var sourcePart = {
|
|
869
|
-
code: "h",
|
|
870
|
-
name: "source",
|
|
871
|
-
parse: (value) => {
|
|
872
|
-
if (value == null || typeof value !== "object") {
|
|
873
|
-
throw new Error('"source" parts expect a Source object.');
|
|
874
|
-
}
|
|
875
|
-
return {
|
|
876
|
-
type: "source",
|
|
877
|
-
value
|
|
878
|
-
};
|
|
879
|
-
}
|
|
880
|
-
};
|
|
881
|
-
var redactedReasoningStreamPart = {
|
|
882
|
-
code: "i",
|
|
883
|
-
name: "redacted_reasoning",
|
|
884
|
-
parse: (value) => {
|
|
885
|
-
if (value == null || typeof value !== "object" || !("data" in value) || typeof value.data !== "string") {
|
|
886
|
-
throw new Error(
|
|
887
|
-
'"redacted_reasoning" parts expect an object with a "data" property.'
|
|
888
|
-
);
|
|
889
|
-
}
|
|
890
|
-
return { type: "redacted_reasoning", value: { data: value.data } };
|
|
891
|
-
}
|
|
892
|
-
};
|
|
893
|
-
var reasoningSignatureStreamPart = {
|
|
894
|
-
code: "j",
|
|
895
|
-
name: "reasoning_signature",
|
|
896
|
-
parse: (value) => {
|
|
897
|
-
if (value == null || typeof value !== "object" || !("signature" in value) || typeof value.signature !== "string") {
|
|
898
|
-
throw new Error(
|
|
899
|
-
'"reasoning_signature" parts expect an object with a "signature" property.'
|
|
900
|
-
);
|
|
901
|
-
}
|
|
902
|
-
return {
|
|
903
|
-
type: "reasoning_signature",
|
|
904
|
-
value: { signature: value.signature }
|
|
905
|
-
};
|
|
906
|
-
}
|
|
907
|
-
};
|
|
908
|
-
var fileStreamPart = {
|
|
909
|
-
code: "k",
|
|
910
|
-
name: "file",
|
|
911
|
-
parse: (value) => {
|
|
912
|
-
if (value == null || typeof value !== "object" || !("data" in value) || typeof value.data !== "string" || !("mimeType" in value) || typeof value.mimeType !== "string") {
|
|
913
|
-
throw new Error(
|
|
914
|
-
'"file" parts expect an object with a "data" and "mimeType" property.'
|
|
915
|
-
);
|
|
916
|
-
}
|
|
917
|
-
return { type: "file", value };
|
|
918
|
-
}
|
|
919
|
-
};
|
|
920
|
-
var dataStreamParts = [
|
|
921
|
-
textStreamPart2,
|
|
922
|
-
dataStreamPart,
|
|
923
|
-
errorStreamPart2,
|
|
924
|
-
messageAnnotationsStreamPart,
|
|
925
|
-
toolCallStreamPart,
|
|
926
|
-
toolResultStreamPart,
|
|
927
|
-
toolCallStreamingStartStreamPart,
|
|
928
|
-
toolCallDeltaStreamPart,
|
|
929
|
-
finishMessageStreamPart,
|
|
930
|
-
finishStepStreamPart,
|
|
931
|
-
startStepStreamPart,
|
|
932
|
-
reasoningStreamPart,
|
|
933
|
-
sourcePart,
|
|
934
|
-
redactedReasoningStreamPart,
|
|
935
|
-
reasoningSignatureStreamPart,
|
|
936
|
-
fileStreamPart
|
|
937
|
-
];
|
|
938
|
-
var dataStreamPartsByCode = Object.fromEntries(
|
|
939
|
-
dataStreamParts.map((part) => [part.code, part])
|
|
940
|
-
);
|
|
941
|
-
Object.fromEntries(
|
|
942
|
-
dataStreamParts.map((part) => [part.name, part.code])
|
|
943
|
-
);
|
|
944
|
-
var validCodes2 = dataStreamParts.map((part) => part.code);
|
|
945
|
-
var parseDataStreamPart = (line) => {
|
|
946
|
-
const firstSeparatorIndex = line.indexOf(":");
|
|
947
|
-
if (firstSeparatorIndex === -1) {
|
|
948
|
-
throw new Error("Failed to parse stream string. No separator found.");
|
|
949
|
-
}
|
|
950
|
-
const prefix = line.slice(0, firstSeparatorIndex);
|
|
951
|
-
if (!validCodes2.includes(prefix)) {
|
|
952
|
-
throw new Error(`Failed to parse stream string. Invalid code ${prefix}.`);
|
|
953
|
-
}
|
|
954
|
-
const code = prefix;
|
|
955
|
-
const textValue = line.slice(firstSeparatorIndex + 1);
|
|
956
|
-
const jsonValue = JSON.parse(textValue);
|
|
957
|
-
return dataStreamPartsByCode[code].parse(jsonValue);
|
|
958
|
-
};
|
|
959
|
-
var NEWLINE = "\n".charCodeAt(0);
|
|
960
|
-
function concatChunks(chunks, totalLength) {
|
|
961
|
-
const concatenatedChunks = new Uint8Array(totalLength);
|
|
962
|
-
let offset = 0;
|
|
963
|
-
for (const chunk of chunks) {
|
|
964
|
-
concatenatedChunks.set(chunk, offset);
|
|
965
|
-
offset += chunk.length;
|
|
966
|
-
}
|
|
967
|
-
chunks.length = 0;
|
|
968
|
-
return concatenatedChunks;
|
|
969
|
-
}
|
|
970
|
-
async function processDataStream({
|
|
971
|
-
stream,
|
|
972
|
-
onTextPart,
|
|
973
|
-
onReasoningPart,
|
|
974
|
-
onReasoningSignaturePart,
|
|
975
|
-
onRedactedReasoningPart,
|
|
976
|
-
onSourcePart,
|
|
977
|
-
onFilePart,
|
|
978
|
-
onDataPart,
|
|
979
|
-
onErrorPart,
|
|
980
|
-
onToolCallStreamingStartPart,
|
|
981
|
-
onToolCallDeltaPart,
|
|
982
|
-
onToolCallPart,
|
|
983
|
-
onToolResultPart,
|
|
984
|
-
onMessageAnnotationsPart,
|
|
985
|
-
onFinishMessagePart,
|
|
986
|
-
onFinishStepPart,
|
|
987
|
-
onStartStepPart
|
|
988
|
-
}) {
|
|
989
|
-
const reader = stream.getReader();
|
|
990
|
-
const decoder = new TextDecoder();
|
|
991
|
-
const chunks = [];
|
|
992
|
-
let totalLength = 0;
|
|
993
|
-
while (true) {
|
|
994
|
-
const { value } = await reader.read();
|
|
995
|
-
if (value) {
|
|
996
|
-
chunks.push(value);
|
|
997
|
-
totalLength += value.length;
|
|
998
|
-
if (value[value.length - 1] !== NEWLINE) {
|
|
999
|
-
continue;
|
|
1000
|
-
}
|
|
1001
|
-
}
|
|
1002
|
-
if (chunks.length === 0) {
|
|
1003
|
-
break;
|
|
1004
|
-
}
|
|
1005
|
-
const concatenatedChunks = concatChunks(chunks, totalLength);
|
|
1006
|
-
totalLength = 0;
|
|
1007
|
-
const streamParts = decoder.decode(concatenatedChunks, { stream: true }).split("\n").filter((line) => line !== "").map(parseDataStreamPart);
|
|
1008
|
-
for (const { type, value: value2 } of streamParts) {
|
|
1009
|
-
switch (type) {
|
|
1010
|
-
case "text":
|
|
1011
|
-
await (onTextPart == null ? void 0 : onTextPart(value2));
|
|
1012
|
-
break;
|
|
1013
|
-
case "reasoning":
|
|
1014
|
-
await (onReasoningPart == null ? void 0 : onReasoningPart(value2));
|
|
1015
|
-
break;
|
|
1016
|
-
case "reasoning_signature":
|
|
1017
|
-
await (onReasoningSignaturePart == null ? void 0 : onReasoningSignaturePart(value2));
|
|
1018
|
-
break;
|
|
1019
|
-
case "redacted_reasoning":
|
|
1020
|
-
await (onRedactedReasoningPart == null ? void 0 : onRedactedReasoningPart(value2));
|
|
1021
|
-
break;
|
|
1022
|
-
case "file":
|
|
1023
|
-
await (onFilePart == null ? void 0 : onFilePart(value2));
|
|
1024
|
-
break;
|
|
1025
|
-
case "source":
|
|
1026
|
-
await (onSourcePart == null ? void 0 : onSourcePart(value2));
|
|
1027
|
-
break;
|
|
1028
|
-
case "data":
|
|
1029
|
-
await (onDataPart == null ? void 0 : onDataPart(value2));
|
|
1030
|
-
break;
|
|
1031
|
-
case "error":
|
|
1032
|
-
await (onErrorPart == null ? void 0 : onErrorPart(value2));
|
|
1033
|
-
break;
|
|
1034
|
-
case "message_annotations":
|
|
1035
|
-
await (onMessageAnnotationsPart == null ? void 0 : onMessageAnnotationsPart(value2));
|
|
1036
|
-
break;
|
|
1037
|
-
case "tool_call_streaming_start":
|
|
1038
|
-
await (onToolCallStreamingStartPart == null ? void 0 : onToolCallStreamingStartPart(value2));
|
|
1039
|
-
break;
|
|
1040
|
-
case "tool_call_delta":
|
|
1041
|
-
await (onToolCallDeltaPart == null ? void 0 : onToolCallDeltaPart(value2));
|
|
1042
|
-
break;
|
|
1043
|
-
case "tool_call":
|
|
1044
|
-
await (onToolCallPart == null ? void 0 : onToolCallPart(value2));
|
|
1045
|
-
break;
|
|
1046
|
-
case "tool_result":
|
|
1047
|
-
await (onToolResultPart == null ? void 0 : onToolResultPart(value2));
|
|
1048
|
-
break;
|
|
1049
|
-
case "finish_message":
|
|
1050
|
-
await (onFinishMessagePart == null ? void 0 : onFinishMessagePart(value2));
|
|
1051
|
-
break;
|
|
1052
|
-
case "finish_step":
|
|
1053
|
-
await (onFinishStepPart == null ? void 0 : onFinishStepPart(value2));
|
|
1054
|
-
break;
|
|
1055
|
-
case "start_step":
|
|
1056
|
-
await (onStartStepPart == null ? void 0 : onStartStepPart(value2));
|
|
1057
|
-
break;
|
|
1058
|
-
default: {
|
|
1059
|
-
const exhaustiveCheck = type;
|
|
1060
|
-
throw new Error(`Unknown stream part type: ${exhaustiveCheck}`);
|
|
1061
|
-
}
|
|
1062
|
-
}
|
|
1063
|
-
}
|
|
1064
|
-
}
|
|
1065
|
-
}
|
|
10
|
+
// src/resources/agent.ts
|
|
1066
11
|
function normalizeRoutePath(path) {
|
|
1067
12
|
let normalized = path.trim();
|
|
1068
13
|
if (normalized.includes("..") || normalized.includes("?") || normalized.includes("#")) {
|
|
@@ -1149,7 +94,7 @@ function requestContextQueryString(requestContext, delimiter = "?") {
|
|
|
1149
94
|
function isZodType(value) {
|
|
1150
95
|
return typeof value === "object" && value !== null && "_def" in value && "parse" in value && typeof value.parse === "function" && "safeParse" in value && typeof value.safeParse === "function";
|
|
1151
96
|
}
|
|
1152
|
-
function
|
|
97
|
+
function zodToJsonSchema(zodSchema) {
|
|
1153
98
|
if (!isZodType(zodSchema)) {
|
|
1154
99
|
return zodSchema;
|
|
1155
100
|
}
|
|
@@ -1169,11 +114,11 @@ function processClientTools(clientTools) {
|
|
|
1169
114
|
{
|
|
1170
115
|
...value,
|
|
1171
116
|
// Serialize parameters (Vercel v4 tool format)
|
|
1172
|
-
...tool.parameters !== void 0 ? { parameters:
|
|
117
|
+
...tool.parameters !== void 0 ? { parameters: zodToJsonSchema(tool.parameters) } : {},
|
|
1173
118
|
// Serialize inputSchema (Mastra tool, ClientTool, or Vercel v5 tool format)
|
|
1174
|
-
...tool.inputSchema !== void 0 ? { inputSchema:
|
|
119
|
+
...tool.inputSchema !== void 0 ? { inputSchema: zodToJsonSchema(tool.inputSchema) } : {},
|
|
1175
120
|
// Serialize outputSchema
|
|
1176
|
-
...tool.outputSchema !== void 0 ? { outputSchema:
|
|
121
|
+
...tool.outputSchema !== void 0 ? { outputSchema: zodToJsonSchema(tool.outputSchema) } : {}
|
|
1177
122
|
}
|
|
1178
123
|
];
|
|
1179
124
|
})
|
|
@@ -1480,8 +425,8 @@ var Agent = class extends BaseResource {
|
|
|
1480
425
|
async generateLegacy(params) {
|
|
1481
426
|
const processedParams = {
|
|
1482
427
|
...params,
|
|
1483
|
-
output: params.output ?
|
|
1484
|
-
experimental_output: params.experimental_output ?
|
|
428
|
+
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
429
|
+
experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
|
|
1485
430
|
requestContext: parseClientRequestContext(params.requestContext),
|
|
1486
431
|
clientTools: processClientTools(params.clientTools)
|
|
1487
432
|
};
|
|
@@ -1637,7 +582,7 @@ var Agent = class extends BaseResource {
|
|
|
1637
582
|
replaceLastMessage
|
|
1638
583
|
});
|
|
1639
584
|
}
|
|
1640
|
-
await processDataStream({
|
|
585
|
+
await uiUtils.processDataStream({
|
|
1641
586
|
stream,
|
|
1642
587
|
onTextPart(value) {
|
|
1643
588
|
if (currentTextPart == null) {
|
|
@@ -1734,7 +679,7 @@ var Agent = class extends BaseResource {
|
|
|
1734
679
|
onToolCallDeltaPart(value) {
|
|
1735
680
|
const partialToolCall = partialToolCalls[value.toolCallId];
|
|
1736
681
|
partialToolCall.text += value.argsTextDelta;
|
|
1737
|
-
const { value: partialArgs } = parsePartialJson(partialToolCall.text);
|
|
682
|
+
const { value: partialArgs } = uiUtils.parsePartialJson(partialToolCall.text);
|
|
1738
683
|
const invocation = {
|
|
1739
684
|
state: "partial-call",
|
|
1740
685
|
step: partialToolCall.step,
|
|
@@ -1840,8 +785,8 @@ var Agent = class extends BaseResource {
|
|
|
1840
785
|
async streamLegacy(params) {
|
|
1841
786
|
const processedParams = {
|
|
1842
787
|
...params,
|
|
1843
|
-
output: params.output ?
|
|
1844
|
-
experimental_output: params.experimental_output ?
|
|
788
|
+
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
789
|
+
experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
|
|
1845
790
|
requestContext: parseClientRequestContext(params.requestContext),
|
|
1846
791
|
clientTools: processClientTools(params.clientTools)
|
|
1847
792
|
};
|
|
@@ -1853,7 +798,7 @@ var Agent = class extends BaseResource {
|
|
|
1853
798
|
headers: response.headers
|
|
1854
799
|
});
|
|
1855
800
|
streamResponse.processDataStream = async (options = {}) => {
|
|
1856
|
-
await processDataStream({
|
|
801
|
+
await uiUtils.processDataStream({
|
|
1857
802
|
stream: streamResponse.body,
|
|
1858
803
|
...options
|
|
1859
804
|
});
|
|
@@ -2059,7 +1004,7 @@ var Agent = class extends BaseResource {
|
|
|
2059
1004
|
case "tool-call-delta": {
|
|
2060
1005
|
const partialToolCall = partialToolCalls[chunk.payload.toolCallId];
|
|
2061
1006
|
partialToolCall.text += chunk.payload.argsTextDelta;
|
|
2062
|
-
const { value: partialArgs } = parsePartialJson(partialToolCall.text);
|
|
1007
|
+
const { value: partialArgs } = uiUtils.parsePartialJson(partialToolCall.text);
|
|
2063
1008
|
const invocation = {
|
|
2064
1009
|
state: "partial-call",
|
|
2065
1010
|
step: partialToolCall.step,
|
|
@@ -2263,7 +1208,7 @@ var Agent = class extends BaseResource {
|
|
|
2263
1208
|
requestContext: parseClientRequestContext(params.requestContext),
|
|
2264
1209
|
structuredOutput: params.structuredOutput ? {
|
|
2265
1210
|
...params.structuredOutput,
|
|
2266
|
-
schema:
|
|
1211
|
+
schema: zodToJsonSchema(params.structuredOutput.schema)
|
|
2267
1212
|
} : void 0
|
|
2268
1213
|
};
|
|
2269
1214
|
const response = await this.request(`/agents/${this.agentId}/network`, {
|
|
@@ -3905,7 +2850,7 @@ var Observability = class extends BaseResource {
|
|
|
3905
2850
|
getTraces(params) {
|
|
3906
2851
|
const { pagination, filters } = params;
|
|
3907
2852
|
const { page, perPage, dateRange } = pagination || {};
|
|
3908
|
-
const { name
|
|
2853
|
+
const { name, spanType, entityId, entityType } = filters || {};
|
|
3909
2854
|
const searchParams = new URLSearchParams();
|
|
3910
2855
|
if (page !== void 0) {
|
|
3911
2856
|
searchParams.set("page", String(page));
|
|
@@ -3913,8 +2858,8 @@ var Observability = class extends BaseResource {
|
|
|
3913
2858
|
if (perPage !== void 0) {
|
|
3914
2859
|
searchParams.set("perPage", String(perPage));
|
|
3915
2860
|
}
|
|
3916
|
-
if (
|
|
3917
|
-
searchParams.set("name",
|
|
2861
|
+
if (name) {
|
|
2862
|
+
searchParams.set("name", name);
|
|
3918
2863
|
}
|
|
3919
2864
|
if (spanType !== void 0) {
|
|
3920
2865
|
searchParams.set("spanType", String(spanType));
|