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