@mastra/client-js 1.0.0-beta.9 → 1.0.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 +1638 -0
- package/README.md +1 -3
- package/dist/_types/@ai-sdk_ui-utils/dist/index.d.ts +820 -0
- package/dist/_types/@internal_ai-sdk-v5/dist/index.d.ts +8511 -0
- package/dist/client.d.ts +56 -11
- package/dist/client.d.ts.map +1 -1
- package/dist/docs/README.md +33 -0
- package/dist/docs/SKILL.md +34 -0
- package/dist/docs/SOURCE_MAP.json +6 -0
- package/dist/docs/ai-sdk/01-reference.md +358 -0
- package/dist/docs/client-js/01-reference.md +1180 -0
- package/dist/docs/server/01-mastra-client.md +256 -0
- package/dist/docs/server/02-jwt.md +99 -0
- package/dist/docs/server/03-clerk.md +143 -0
- package/dist/docs/server/04-supabase.md +128 -0
- package/dist/docs/server/05-firebase.md +286 -0
- package/dist/docs/server/06-workos.md +201 -0
- package/dist/docs/server/07-auth0.md +233 -0
- package/dist/index.cjs +1690 -596
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1688 -594
- package/dist/index.js.map +1 -1
- package/dist/resources/agent-builder.d.ts +10 -26
- package/dist/resources/agent-builder.d.ts.map +1 -1
- package/dist/resources/agent.d.ts +43 -8
- package/dist/resources/agent.d.ts.map +1 -1
- package/dist/resources/index.d.ts +1 -0
- package/dist/resources/index.d.ts.map +1 -1
- package/dist/resources/memory-thread.d.ts +18 -3
- package/dist/resources/memory-thread.d.ts.map +1 -1
- package/dist/resources/observability.d.ts +58 -15
- package/dist/resources/observability.d.ts.map +1 -1
- package/dist/resources/processor.d.ts +20 -0
- package/dist/resources/processor.d.ts.map +1 -0
- package/dist/resources/run.d.ts +210 -0
- package/dist/resources/run.d.ts.map +1 -0
- package/dist/resources/workflow.d.ts +19 -224
- package/dist/resources/workflow.d.ts.map +1 -1
- package/dist/tools.d.ts +2 -2
- package/dist/tools.d.ts.map +1 -1
- package/dist/types.d.ts +141 -36
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/index.d.ts +26 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/package.json +13 -12
package/dist/index.js
CHANGED
|
@@ -1,11 +1,1101 @@
|
|
|
1
|
-
import { processDataStream, parsePartialJson } from '@ai-sdk/ui-utils';
|
|
2
1
|
import { v4 } from '@lukeed/uuid';
|
|
3
2
|
import { getErrorFromUnknown } from '@mastra/core/error';
|
|
4
3
|
import { RequestContext } from '@mastra/core/request-context';
|
|
5
4
|
import { isVercelTool } from '@mastra/core/tools/is-vercel-tool';
|
|
6
|
-
import { zodToJsonSchema
|
|
5
|
+
import { zodToJsonSchema } from '@mastra/schema-compat/zod-to-json';
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
var __create = Object.create;
|
|
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, 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@3.25.76/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.24.6_zod@3.25.76/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
|
+
}
|
|
1064
|
+
function isComplexValue(value) {
|
|
1065
|
+
if (value === null || value === void 0) return false;
|
|
1066
|
+
if (value instanceof Date) return false;
|
|
1067
|
+
return typeof value === "object";
|
|
1068
|
+
}
|
|
1069
|
+
function serializeQueryValue(value) {
|
|
1070
|
+
if (value instanceof Date) {
|
|
1071
|
+
return value.toISOString();
|
|
1072
|
+
}
|
|
1073
|
+
if (isComplexValue(value)) {
|
|
1074
|
+
return JSON.stringify(value, (_key, val) => {
|
|
1075
|
+
if (val instanceof Date) {
|
|
1076
|
+
return val.toISOString();
|
|
1077
|
+
}
|
|
1078
|
+
return val;
|
|
1079
|
+
});
|
|
1080
|
+
}
|
|
1081
|
+
return String(value);
|
|
1082
|
+
}
|
|
1083
|
+
function toQueryParams(params, flattenKeys = []) {
|
|
1084
|
+
const searchParams = new URLSearchParams();
|
|
1085
|
+
const keysToFlatten = flattenKeys;
|
|
1086
|
+
function addParams(obj) {
|
|
1087
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
1088
|
+
if (value === void 0 || value === null) continue;
|
|
1089
|
+
if (keysToFlatten.includes(key) && typeof value === "object" && !Array.isArray(value) && !(value instanceof Date)) {
|
|
1090
|
+
addParams(value);
|
|
1091
|
+
} else {
|
|
1092
|
+
searchParams.set(key, serializeQueryValue(value));
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
addParams(params);
|
|
1097
|
+
return searchParams.toString();
|
|
1098
|
+
}
|
|
9
1099
|
function parseClientRequestContext(requestContext) {
|
|
10
1100
|
if (requestContext) {
|
|
11
1101
|
if (requestContext instanceof RequestContext) {
|
|
@@ -32,11 +1122,11 @@ function requestContextQueryString(requestContext, delimiter = "?") {
|
|
|
32
1122
|
function isZodType(value) {
|
|
33
1123
|
return typeof value === "object" && value !== null && "_def" in value && "parse" in value && typeof value.parse === "function" && "safeParse" in value && typeof value.safeParse === "function";
|
|
34
1124
|
}
|
|
35
|
-
function
|
|
1125
|
+
function zodToJsonSchema2(zodSchema) {
|
|
36
1126
|
if (!isZodType(zodSchema)) {
|
|
37
1127
|
return zodSchema;
|
|
38
1128
|
}
|
|
39
|
-
return zodToJsonSchema
|
|
1129
|
+
return zodToJsonSchema(zodSchema);
|
|
40
1130
|
}
|
|
41
1131
|
|
|
42
1132
|
// src/utils/process-client-tools.ts
|
|
@@ -51,7 +1141,7 @@ function processClientTools(clientTools) {
|
|
|
51
1141
|
key,
|
|
52
1142
|
{
|
|
53
1143
|
...value,
|
|
54
|
-
parameters: value.parameters ?
|
|
1144
|
+
parameters: value.parameters ? zodToJsonSchema2(value.parameters) : void 0
|
|
55
1145
|
}
|
|
56
1146
|
];
|
|
57
1147
|
} else {
|
|
@@ -59,8 +1149,8 @@ function processClientTools(clientTools) {
|
|
|
59
1149
|
key,
|
|
60
1150
|
{
|
|
61
1151
|
...value,
|
|
62
|
-
inputSchema: value.inputSchema ?
|
|
63
|
-
outputSchema: value.outputSchema ?
|
|
1152
|
+
inputSchema: value.inputSchema ? zodToJsonSchema2(value.inputSchema) : void 0,
|
|
1153
|
+
outputSchema: value.outputSchema ? zodToJsonSchema2(value.outputSchema) : void 0
|
|
64
1154
|
}
|
|
65
1155
|
];
|
|
66
1156
|
}
|
|
@@ -239,10 +1329,7 @@ async function executeToolCallAndRespond({
|
|
|
239
1329
|
]
|
|
240
1330
|
}
|
|
241
1331
|
];
|
|
242
|
-
return respondFn(
|
|
243
|
-
...params,
|
|
244
|
-
messages: updatedMessages
|
|
245
|
-
});
|
|
1332
|
+
return respondFn(updatedMessages, params);
|
|
246
1333
|
}
|
|
247
1334
|
}
|
|
248
1335
|
}
|
|
@@ -330,8 +1417,8 @@ var Agent = class extends BaseResource {
|
|
|
330
1417
|
async generateLegacy(params) {
|
|
331
1418
|
const processedParams = {
|
|
332
1419
|
...params,
|
|
333
|
-
output: params.output ?
|
|
334
|
-
experimental_output: params.experimental_output ?
|
|
1420
|
+
output: params.output ? zodToJsonSchema2(params.output) : void 0,
|
|
1421
|
+
experimental_output: params.experimental_output ? zodToJsonSchema2(params.experimental_output) : void 0,
|
|
335
1422
|
requestContext: parseClientRequestContext(params.requestContext),
|
|
336
1423
|
clientTools: processClientTools(params.clientTools)
|
|
337
1424
|
};
|
|
@@ -386,26 +1473,24 @@ var Agent = class extends BaseResource {
|
|
|
386
1473
|
}
|
|
387
1474
|
return response;
|
|
388
1475
|
}
|
|
389
|
-
async generate(
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
}
|
|
394
|
-
params = {
|
|
395
|
-
messages: messagesOrParams,
|
|
396
|
-
...options
|
|
397
|
-
};
|
|
398
|
-
}
|
|
1476
|
+
async generate(messages, options) {
|
|
1477
|
+
const params = {
|
|
1478
|
+
...options,
|
|
1479
|
+
messages
|
|
1480
|
+
};
|
|
399
1481
|
const processedParams = {
|
|
400
1482
|
...params,
|
|
401
1483
|
requestContext: parseClientRequestContext(params.requestContext),
|
|
402
1484
|
clientTools: processClientTools(params.clientTools),
|
|
403
1485
|
structuredOutput: params.structuredOutput ? {
|
|
404
1486
|
...params.structuredOutput,
|
|
405
|
-
schema:
|
|
1487
|
+
schema: zodToJsonSchema2(params.structuredOutput.schema)
|
|
406
1488
|
} : void 0
|
|
407
1489
|
};
|
|
408
|
-
const {
|
|
1490
|
+
const { memory, requestContext } = processedParams;
|
|
1491
|
+
const { resource, thread } = memory ?? {};
|
|
1492
|
+
const resourceId = resource;
|
|
1493
|
+
const threadId = typeof thread === "string" ? thread : thread?.id;
|
|
409
1494
|
const response = await this.request(
|
|
410
1495
|
`/api/agents/${this.agentId}/generate`,
|
|
411
1496
|
{
|
|
@@ -695,8 +1780,8 @@ var Agent = class extends BaseResource {
|
|
|
695
1780
|
async streamLegacy(params) {
|
|
696
1781
|
const processedParams = {
|
|
697
1782
|
...params,
|
|
698
|
-
output: params.output ?
|
|
699
|
-
experimental_output: params.experimental_output ?
|
|
1783
|
+
output: params.output ? zodToJsonSchema2(params.output) : void 0,
|
|
1784
|
+
experimental_output: params.experimental_output ? zodToJsonSchema2(params.experimental_output) : void 0,
|
|
700
1785
|
requestContext: parseClientRequestContext(params.requestContext),
|
|
701
1786
|
clientTools: processClientTools(params.clientTools)
|
|
702
1787
|
};
|
|
@@ -791,7 +1876,7 @@ var Agent = class extends BaseResource {
|
|
|
791
1876
|
case "tripwire": {
|
|
792
1877
|
message.parts.push({
|
|
793
1878
|
type: "text",
|
|
794
|
-
text: chunk.payload.
|
|
1879
|
+
text: chunk.payload.reason
|
|
795
1880
|
});
|
|
796
1881
|
execUpdate();
|
|
797
1882
|
break;
|
|
@@ -1106,8 +2191,35 @@ var Agent = class extends BaseResource {
|
|
|
1106
2191
|
}
|
|
1107
2192
|
return response;
|
|
1108
2193
|
}
|
|
1109
|
-
async network(params) {
|
|
2194
|
+
async network(messages, params) {
|
|
1110
2195
|
const response = await this.request(`/api/agents/${this.agentId}/network`, {
|
|
2196
|
+
method: "POST",
|
|
2197
|
+
body: {
|
|
2198
|
+
messages,
|
|
2199
|
+
...params
|
|
2200
|
+
},
|
|
2201
|
+
stream: true
|
|
2202
|
+
});
|
|
2203
|
+
if (!response.body) {
|
|
2204
|
+
throw new Error("No response body");
|
|
2205
|
+
}
|
|
2206
|
+
const streamResponse = new Response(response.body, {
|
|
2207
|
+
status: response.status,
|
|
2208
|
+
statusText: response.statusText,
|
|
2209
|
+
headers: response.headers
|
|
2210
|
+
});
|
|
2211
|
+
streamResponse.processDataStream = async ({
|
|
2212
|
+
onChunk
|
|
2213
|
+
}) => {
|
|
2214
|
+
await processMastraNetworkStream({
|
|
2215
|
+
stream: streamResponse.body,
|
|
2216
|
+
onChunk
|
|
2217
|
+
});
|
|
2218
|
+
};
|
|
2219
|
+
return streamResponse;
|
|
2220
|
+
}
|
|
2221
|
+
async approveNetworkToolCall(params) {
|
|
2222
|
+
const response = await this.request(`/api/agents/${this.agentId}/approve-network-tool-call`, {
|
|
1111
2223
|
method: "POST",
|
|
1112
2224
|
body: params,
|
|
1113
2225
|
stream: true
|
|
@@ -1130,23 +2242,42 @@ var Agent = class extends BaseResource {
|
|
|
1130
2242
|
};
|
|
1131
2243
|
return streamResponse;
|
|
1132
2244
|
}
|
|
1133
|
-
async
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
params
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
};
|
|
2245
|
+
async declineNetworkToolCall(params) {
|
|
2246
|
+
const response = await this.request(`/api/agents/${this.agentId}/decline-network-tool-call`, {
|
|
2247
|
+
method: "POST",
|
|
2248
|
+
body: params,
|
|
2249
|
+
stream: true
|
|
2250
|
+
});
|
|
2251
|
+
if (!response.body) {
|
|
2252
|
+
throw new Error("No response body");
|
|
1142
2253
|
}
|
|
2254
|
+
const streamResponse = new Response(response.body, {
|
|
2255
|
+
status: response.status,
|
|
2256
|
+
statusText: response.statusText,
|
|
2257
|
+
headers: response.headers
|
|
2258
|
+
});
|
|
2259
|
+
streamResponse.processDataStream = async ({
|
|
2260
|
+
onChunk
|
|
2261
|
+
}) => {
|
|
2262
|
+
await processMastraNetworkStream({
|
|
2263
|
+
stream: streamResponse.body,
|
|
2264
|
+
onChunk
|
|
2265
|
+
});
|
|
2266
|
+
};
|
|
2267
|
+
return streamResponse;
|
|
2268
|
+
}
|
|
2269
|
+
async stream(messagesOrParams, options) {
|
|
2270
|
+
let params = {
|
|
2271
|
+
messages: messagesOrParams,
|
|
2272
|
+
...options
|
|
2273
|
+
};
|
|
1143
2274
|
const processedParams = {
|
|
1144
2275
|
...params,
|
|
1145
2276
|
requestContext: parseClientRequestContext(params.requestContext),
|
|
1146
2277
|
clientTools: processClientTools(params.clientTools),
|
|
1147
2278
|
structuredOutput: params.structuredOutput ? {
|
|
1148
2279
|
...params.structuredOutput,
|
|
1149
|
-
schema:
|
|
2280
|
+
schema: zodToJsonSchema2(params.structuredOutput.schema)
|
|
1150
2281
|
} : void 0
|
|
1151
2282
|
};
|
|
1152
2283
|
let readableController;
|
|
@@ -1217,6 +2348,26 @@ var Agent = class extends BaseResource {
|
|
|
1217
2348
|
};
|
|
1218
2349
|
return streamResponse;
|
|
1219
2350
|
}
|
|
2351
|
+
/**
|
|
2352
|
+
* Approves a pending tool call and returns the complete response (non-streaming).
|
|
2353
|
+
* Used when `requireToolApproval` is enabled with generate() to allow the agent to proceed.
|
|
2354
|
+
*/
|
|
2355
|
+
async approveToolCallGenerate(params) {
|
|
2356
|
+
return this.request(`/api/agents/${this.agentId}/approve-tool-call-generate`, {
|
|
2357
|
+
method: "POST",
|
|
2358
|
+
body: params
|
|
2359
|
+
});
|
|
2360
|
+
}
|
|
2361
|
+
/**
|
|
2362
|
+
* Declines a pending tool call and returns the complete response (non-streaming).
|
|
2363
|
+
* Used when `requireToolApproval` is enabled with generate() to prevent tool execution.
|
|
2364
|
+
*/
|
|
2365
|
+
async declineToolCallGenerate(params) {
|
|
2366
|
+
return this.request(`/api/agents/${this.agentId}/decline-tool-call-generate`, {
|
|
2367
|
+
method: "POST",
|
|
2368
|
+
body: params
|
|
2369
|
+
});
|
|
2370
|
+
}
|
|
1220
2371
|
/**
|
|
1221
2372
|
* Processes the stream response and handles tool calls
|
|
1222
2373
|
*/
|
|
@@ -1369,7 +2520,8 @@ var Agent = class extends BaseResource {
|
|
|
1369
2520
|
*/
|
|
1370
2521
|
resetModel() {
|
|
1371
2522
|
return this.request(`/api/agents/${this.agentId}/model/reset`, {
|
|
1372
|
-
method: "POST"
|
|
2523
|
+
method: "POST",
|
|
2524
|
+
body: {}
|
|
1373
2525
|
});
|
|
1374
2526
|
}
|
|
1375
2527
|
/**
|
|
@@ -1403,15 +2555,21 @@ var MemoryThread = class extends BaseResource {
|
|
|
1403
2555
|
this.threadId = threadId;
|
|
1404
2556
|
this.agentId = agentId;
|
|
1405
2557
|
}
|
|
2558
|
+
/**
|
|
2559
|
+
* Builds the query string for agentId (if provided)
|
|
2560
|
+
*/
|
|
2561
|
+
getAgentIdQueryParam(prefix = "?") {
|
|
2562
|
+
return this.agentId ? `${prefix}agentId=${this.agentId}` : "";
|
|
2563
|
+
}
|
|
1406
2564
|
/**
|
|
1407
2565
|
* Retrieves the memory thread details
|
|
1408
2566
|
* @param requestContext - Optional request context to pass as query parameter
|
|
1409
2567
|
* @returns Promise containing thread details including title and metadata
|
|
1410
2568
|
*/
|
|
1411
2569
|
get(requestContext) {
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
);
|
|
2570
|
+
const agentIdParam = this.getAgentIdQueryParam("?");
|
|
2571
|
+
const contextParam = requestContextQueryString(requestContext, agentIdParam ? "&" : "?");
|
|
2572
|
+
return this.request(`/api/memory/threads/${this.threadId}${agentIdParam}${contextParam}`);
|
|
1415
2573
|
}
|
|
1416
2574
|
/**
|
|
1417
2575
|
* Updates the memory thread properties
|
|
@@ -1419,13 +2577,12 @@ var MemoryThread = class extends BaseResource {
|
|
|
1419
2577
|
* @returns Promise containing updated thread details
|
|
1420
2578
|
*/
|
|
1421
2579
|
update(params) {
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
);
|
|
2580
|
+
const agentIdParam = this.getAgentIdQueryParam("?");
|
|
2581
|
+
const contextParam = requestContextQueryString(params.requestContext, agentIdParam ? "&" : "?");
|
|
2582
|
+
return this.request(`/api/memory/threads/${this.threadId}${agentIdParam}${contextParam}`, {
|
|
2583
|
+
method: "PATCH",
|
|
2584
|
+
body: params
|
|
2585
|
+
});
|
|
1429
2586
|
}
|
|
1430
2587
|
/**
|
|
1431
2588
|
* Deletes the memory thread
|
|
@@ -1433,12 +2590,11 @@ var MemoryThread = class extends BaseResource {
|
|
|
1433
2590
|
* @returns Promise containing deletion result
|
|
1434
2591
|
*/
|
|
1435
2592
|
delete(requestContext) {
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
);
|
|
2593
|
+
const agentIdParam = this.getAgentIdQueryParam("?");
|
|
2594
|
+
const contextParam = requestContextQueryString(requestContext, agentIdParam ? "&" : "?");
|
|
2595
|
+
return this.request(`/api/memory/threads/${this.threadId}${agentIdParam}${contextParam}`, {
|
|
2596
|
+
method: "DELETE"
|
|
2597
|
+
});
|
|
1442
2598
|
}
|
|
1443
2599
|
/**
|
|
1444
2600
|
* Retrieves paginated messages associated with the thread with filtering and ordering options
|
|
@@ -1448,6 +2604,7 @@ var MemoryThread = class extends BaseResource {
|
|
|
1448
2604
|
listMessages(params = {}) {
|
|
1449
2605
|
const { page, perPage, orderBy, filter, include, resourceId, requestContext } = params;
|
|
1450
2606
|
const queryParams = {};
|
|
2607
|
+
if (this.agentId) queryParams.agentId = this.agentId;
|
|
1451
2608
|
if (resourceId) queryParams.resourceId = resourceId;
|
|
1452
2609
|
if (page !== void 0) queryParams.page = String(page);
|
|
1453
2610
|
if (perPage !== void 0) queryParams.perPage = String(perPage);
|
|
@@ -1456,7 +2613,7 @@ var MemoryThread = class extends BaseResource {
|
|
|
1456
2613
|
if (include) queryParams.include = JSON.stringify(include);
|
|
1457
2614
|
const query = new URLSearchParams(queryParams);
|
|
1458
2615
|
const queryString = query.toString();
|
|
1459
|
-
const url = `/api/memory/threads/${this.threadId}/messages
|
|
2616
|
+
const url = `/api/memory/threads/${this.threadId}/messages${queryString ? `?${queryString}` : ""}${requestContextQueryString(requestContext, queryString ? "&" : "?")}`;
|
|
1460
2617
|
return this.request(url);
|
|
1461
2618
|
}
|
|
1462
2619
|
/**
|
|
@@ -1467,17 +2624,32 @@ var MemoryThread = class extends BaseResource {
|
|
|
1467
2624
|
* @returns Promise containing deletion result
|
|
1468
2625
|
*/
|
|
1469
2626
|
deleteMessages(messageIds, requestContext) {
|
|
1470
|
-
const
|
|
1471
|
-
|
|
1472
|
-
|
|
2627
|
+
const queryParams = {};
|
|
2628
|
+
if (this.agentId) queryParams.agentId = this.agentId;
|
|
2629
|
+
const query = new URLSearchParams(queryParams);
|
|
2630
|
+
const queryString = query.toString();
|
|
1473
2631
|
return this.request(
|
|
1474
|
-
`/api/memory/messages/delete
|
|
2632
|
+
`/api/memory/messages/delete${queryString ? `?${queryString}` : ""}${requestContextQueryString(requestContext, queryString ? "&" : "?")}`,
|
|
1475
2633
|
{
|
|
1476
2634
|
method: "POST",
|
|
1477
2635
|
body: { messageIds }
|
|
1478
2636
|
}
|
|
1479
2637
|
);
|
|
1480
2638
|
}
|
|
2639
|
+
/**
|
|
2640
|
+
* Clones the thread with all its messages to a new thread
|
|
2641
|
+
* @param params - Clone parameters including optional new thread ID, title, metadata, and message filters
|
|
2642
|
+
* @returns Promise containing the cloned thread and copied messages
|
|
2643
|
+
*/
|
|
2644
|
+
clone(params = {}) {
|
|
2645
|
+
const { requestContext, ...body } = params;
|
|
2646
|
+
const agentIdParam = this.getAgentIdQueryParam("?");
|
|
2647
|
+
const contextParam = requestContextQueryString(requestContext, agentIdParam ? "&" : "?");
|
|
2648
|
+
return this.request(`/api/memory/threads/${this.threadId}/clone${agentIdParam}${contextParam}`, {
|
|
2649
|
+
method: "POST",
|
|
2650
|
+
body
|
|
2651
|
+
});
|
|
2652
|
+
}
|
|
1481
2653
|
};
|
|
1482
2654
|
|
|
1483
2655
|
// src/resources/vector.ts
|
|
@@ -1585,217 +2757,209 @@ var Tool = class extends BaseResource {
|
|
|
1585
2757
|
}
|
|
1586
2758
|
};
|
|
1587
2759
|
|
|
1588
|
-
// src/resources/
|
|
1589
|
-
var
|
|
1590
|
-
|
|
1591
|
-
constructor(options, workflowId) {
|
|
2760
|
+
// src/resources/processor.ts
|
|
2761
|
+
var Processor = class extends BaseResource {
|
|
2762
|
+
constructor(options, processorId) {
|
|
1592
2763
|
super(options);
|
|
1593
|
-
this.
|
|
2764
|
+
this.processorId = processorId;
|
|
1594
2765
|
}
|
|
1595
2766
|
/**
|
|
1596
|
-
* Retrieves details about the
|
|
2767
|
+
* Retrieves details about the processor
|
|
1597
2768
|
* @param requestContext - Optional request context to pass as query parameter
|
|
1598
|
-
* @returns Promise containing
|
|
2769
|
+
* @returns Promise containing processor details including phases and configurations
|
|
1599
2770
|
*/
|
|
1600
2771
|
details(requestContext) {
|
|
1601
|
-
return this.request(`/api/
|
|
2772
|
+
return this.request(`/api/processors/${this.processorId}${requestContextQueryString(requestContext)}`);
|
|
1602
2773
|
}
|
|
1603
2774
|
/**
|
|
1604
|
-
*
|
|
1605
|
-
* @param params - Parameters for
|
|
1606
|
-
* @
|
|
1607
|
-
* @returns Promise containing workflow runs array
|
|
2775
|
+
* Executes the processor with the provided parameters
|
|
2776
|
+
* @param params - Parameters required for processor execution including phase and messages
|
|
2777
|
+
* @returns Promise containing the processor execution results
|
|
1608
2778
|
*/
|
|
1609
|
-
|
|
1610
|
-
const
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
}
|
|
1621
|
-
if (params?.perPage !== void 0) {
|
|
1622
|
-
searchParams.set("perPage", String(params.perPage));
|
|
1623
|
-
}
|
|
1624
|
-
if (params?.limit !== null && params?.limit !== void 0) {
|
|
1625
|
-
if (params.limit === false) {
|
|
1626
|
-
searchParams.set("limit", "false");
|
|
1627
|
-
} else if (typeof params.limit === "number" && params.limit > 0 && Number.isInteger(params.limit)) {
|
|
1628
|
-
searchParams.set("limit", String(params.limit));
|
|
1629
|
-
}
|
|
1630
|
-
}
|
|
1631
|
-
if (params?.offset !== null && params?.offset !== void 0 && !isNaN(Number(params?.offset))) {
|
|
1632
|
-
searchParams.set("offset", String(params.offset));
|
|
1633
|
-
}
|
|
1634
|
-
if (params?.resourceId) {
|
|
1635
|
-
searchParams.set("resourceId", params.resourceId);
|
|
1636
|
-
}
|
|
1637
|
-
if (requestContextParam) {
|
|
1638
|
-
searchParams.set("requestContext", requestContextParam);
|
|
1639
|
-
}
|
|
1640
|
-
if (searchParams.size) {
|
|
1641
|
-
return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
|
|
1642
|
-
} else {
|
|
1643
|
-
return this.request(`/api/workflows/${this.workflowId}/runs`);
|
|
1644
|
-
}
|
|
2779
|
+
execute(params) {
|
|
2780
|
+
const body = {
|
|
2781
|
+
phase: params.phase,
|
|
2782
|
+
messages: params.messages,
|
|
2783
|
+
agentId: params.agentId,
|
|
2784
|
+
requestContext: parseClientRequestContext(params.requestContext)
|
|
2785
|
+
};
|
|
2786
|
+
return this.request(`/api/processors/${this.processorId}/execute`, {
|
|
2787
|
+
method: "POST",
|
|
2788
|
+
body
|
|
2789
|
+
});
|
|
1645
2790
|
}
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
2791
|
+
};
|
|
2792
|
+
function deserializeWorkflowError(result) {
|
|
2793
|
+
if (result.status === "failed" && result.error) {
|
|
2794
|
+
result.error = getErrorFromUnknown(result.error, {
|
|
2795
|
+
fallbackMessage: "Unknown workflow error",
|
|
2796
|
+
supportSerialization: false
|
|
2797
|
+
});
|
|
2798
|
+
}
|
|
2799
|
+
return result;
|
|
2800
|
+
}
|
|
2801
|
+
var RECORD_SEPARATOR = "";
|
|
2802
|
+
var Run = class extends BaseResource {
|
|
2803
|
+
constructor(options, workflowId, runId) {
|
|
2804
|
+
super(options);
|
|
2805
|
+
this.workflowId = workflowId;
|
|
2806
|
+
this.runId = runId;
|
|
1654
2807
|
}
|
|
1655
2808
|
/**
|
|
1656
|
-
*
|
|
1657
|
-
* @param runId - The ID of the workflow run to retrieve the execution result for
|
|
1658
|
-
* @param requestContext - Optional request context to pass as query parameter
|
|
1659
|
-
* @returns Promise containing the workflow run execution result
|
|
2809
|
+
* Creates a transform stream that parses RECORD_SEPARATOR-delimited JSON chunks
|
|
1660
2810
|
*/
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
2811
|
+
createChunkTransformStream() {
|
|
2812
|
+
let failedChunk = void 0;
|
|
2813
|
+
return new TransformStream({
|
|
2814
|
+
start() {
|
|
2815
|
+
},
|
|
2816
|
+
async transform(chunk, controller) {
|
|
2817
|
+
try {
|
|
2818
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
2819
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
2820
|
+
for (const chunk2 of chunks) {
|
|
2821
|
+
if (chunk2) {
|
|
2822
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
2823
|
+
try {
|
|
2824
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
2825
|
+
controller.enqueue(parsedChunk);
|
|
2826
|
+
failedChunk = void 0;
|
|
2827
|
+
} catch {
|
|
2828
|
+
failedChunk = newChunk;
|
|
2829
|
+
}
|
|
2830
|
+
}
|
|
2831
|
+
}
|
|
2832
|
+
} catch {
|
|
2833
|
+
}
|
|
2834
|
+
}
|
|
2835
|
+
});
|
|
1665
2836
|
}
|
|
1666
2837
|
/**
|
|
1667
2838
|
* Cancels a specific workflow run by its ID
|
|
1668
|
-
* @param runId - The ID of the workflow run to cancel
|
|
1669
2839
|
* @returns Promise containing a success message
|
|
2840
|
+
* @deprecated Use `cancel()` instead
|
|
1670
2841
|
*/
|
|
1671
|
-
cancelRun(
|
|
1672
|
-
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}/cancel`, {
|
|
2842
|
+
cancelRun() {
|
|
2843
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${this.runId}/cancel`, {
|
|
1673
2844
|
method: "POST"
|
|
1674
2845
|
});
|
|
1675
2846
|
}
|
|
1676
2847
|
/**
|
|
1677
|
-
*
|
|
1678
|
-
*
|
|
1679
|
-
*
|
|
2848
|
+
* Cancels a workflow run.
|
|
2849
|
+
*
|
|
2850
|
+
* This method aborts any running steps and updates the workflow status to 'canceled' .
|
|
2851
|
+
* It works for both actively running workflows and suspended/waiting workflows.
|
|
2852
|
+
*
|
|
2853
|
+
* ## How cancellation works
|
|
2854
|
+
*
|
|
2855
|
+
* When called, the workflow will:
|
|
2856
|
+
* 1. **Trigger the abort signal** - Uses the standard Web API AbortSignal to notify running steps
|
|
2857
|
+
* 2. **Prevent subsequent steps** - No further steps will be executed
|
|
2858
|
+
*
|
|
2859
|
+
* ## Abort signal behavior
|
|
2860
|
+
*
|
|
2861
|
+
* Steps that check the `abortSignal` parameter can respond to cancellation:
|
|
2862
|
+
* - Steps can listen to the 'abort' event: `abortSignal.addEventListener('abort', callback)`
|
|
2863
|
+
* - Steps can check if already aborted: `if (abortSignal.aborted) { ... }`
|
|
2864
|
+
* - Useful for canceling timeouts, network requests, or long-running operations
|
|
2865
|
+
*
|
|
2866
|
+
* **Note:** Steps must actively check the abort signal to be canceled mid-execution.
|
|
2867
|
+
* Steps that don't check the signal will run to completion, but subsequent steps won't execute.
|
|
2868
|
+
*
|
|
2869
|
+
* @returns Promise that resolves with `{ message: 'Workflow run canceled' }` when cancellation succeeds
|
|
2870
|
+
* @throws {HTTPException} 400 - If workflow ID or run ID is missing
|
|
2871
|
+
* @throws {HTTPException} 404 - If workflow or workflow run is not found
|
|
2872
|
+
*
|
|
2873
|
+
* @example
|
|
2874
|
+
* ```typescript
|
|
2875
|
+
* const run = await workflow.createRun({ runId: 'run-123' });
|
|
2876
|
+
* await run.cancel();
|
|
2877
|
+
* // Returns: { message: 'Workflow run canceled' }
|
|
2878
|
+
* ```
|
|
2879
|
+
*
|
|
2880
|
+
* @example
|
|
2881
|
+
* ```typescript
|
|
2882
|
+
* // Example of a step that responds to cancellation
|
|
2883
|
+
* const step = createStep({
|
|
2884
|
+
* id: 'long-running-step',
|
|
2885
|
+
* execute: async ({ inputData, abortSignal, abort }) => {
|
|
2886
|
+
* const timeout = new Promise((resolve) => {
|
|
2887
|
+
* const timer = setTimeout(() => resolve('done'), 10000);
|
|
2888
|
+
*
|
|
2889
|
+
* // Clean up if canceled
|
|
2890
|
+
* abortSignal.addEventListener('abort', () => {
|
|
2891
|
+
* clearTimeout(timer);
|
|
2892
|
+
* resolve('canceled');
|
|
2893
|
+
* });
|
|
2894
|
+
* });
|
|
2895
|
+
*
|
|
2896
|
+
* const result = await timeout;
|
|
2897
|
+
*
|
|
2898
|
+
* // Check if aborted after async operation
|
|
2899
|
+
* if (abortSignal.aborted) {
|
|
2900
|
+
* return abort(); // Stop execution
|
|
2901
|
+
* }
|
|
2902
|
+
*
|
|
2903
|
+
* return { result };
|
|
2904
|
+
* }
|
|
2905
|
+
* });
|
|
2906
|
+
* ```
|
|
1680
2907
|
*/
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
}
|
|
1686
|
-
const res = await this.request(
|
|
1687
|
-
`/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`,
|
|
1688
|
-
{
|
|
1689
|
-
method: "POST"
|
|
1690
|
-
}
|
|
1691
|
-
);
|
|
1692
|
-
const runId = res.runId;
|
|
1693
|
-
return {
|
|
1694
|
-
runId,
|
|
1695
|
-
start: async (p) => {
|
|
1696
|
-
return this.start({
|
|
1697
|
-
runId,
|
|
1698
|
-
inputData: p.inputData,
|
|
1699
|
-
initialState: p.initialState,
|
|
1700
|
-
requestContext: p.requestContext,
|
|
1701
|
-
tracingOptions: p.tracingOptions
|
|
1702
|
-
});
|
|
1703
|
-
},
|
|
1704
|
-
startAsync: async (p) => {
|
|
1705
|
-
return this.startAsync({
|
|
1706
|
-
runId,
|
|
1707
|
-
inputData: p.inputData,
|
|
1708
|
-
initialState: p.initialState,
|
|
1709
|
-
requestContext: p.requestContext,
|
|
1710
|
-
tracingOptions: p.tracingOptions
|
|
1711
|
-
});
|
|
1712
|
-
},
|
|
1713
|
-
stream: async (p) => {
|
|
1714
|
-
return this.stream({
|
|
1715
|
-
runId,
|
|
1716
|
-
inputData: p.inputData,
|
|
1717
|
-
initialState: p.initialState,
|
|
1718
|
-
requestContext: p.requestContext
|
|
1719
|
-
});
|
|
1720
|
-
},
|
|
1721
|
-
resume: async (p) => {
|
|
1722
|
-
return this.resume({
|
|
1723
|
-
runId,
|
|
1724
|
-
step: p.step,
|
|
1725
|
-
resumeData: p.resumeData,
|
|
1726
|
-
requestContext: p.requestContext,
|
|
1727
|
-
tracingOptions: p.tracingOptions
|
|
1728
|
-
});
|
|
1729
|
-
},
|
|
1730
|
-
resumeAsync: async (p) => {
|
|
1731
|
-
return this.resumeAsync({
|
|
1732
|
-
runId,
|
|
1733
|
-
step: p.step,
|
|
1734
|
-
resumeData: p.resumeData,
|
|
1735
|
-
requestContext: p.requestContext,
|
|
1736
|
-
tracingOptions: p.tracingOptions
|
|
1737
|
-
});
|
|
1738
|
-
},
|
|
1739
|
-
resumeStreamVNext: async (p) => {
|
|
1740
|
-
return this.resumeStreamVNext({
|
|
1741
|
-
runId,
|
|
1742
|
-
step: p.step,
|
|
1743
|
-
resumeData: p.resumeData,
|
|
1744
|
-
requestContext: p.requestContext
|
|
1745
|
-
});
|
|
1746
|
-
}
|
|
1747
|
-
};
|
|
2908
|
+
cancel() {
|
|
2909
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${this.runId}/cancel`, {
|
|
2910
|
+
method: "POST"
|
|
2911
|
+
});
|
|
1748
2912
|
}
|
|
1749
2913
|
/**
|
|
1750
2914
|
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
1751
|
-
* @param params - Object containing the
|
|
2915
|
+
* @param params - Object containing the inputData, initialState and requestContext
|
|
1752
2916
|
* @returns Promise containing success message
|
|
1753
2917
|
*/
|
|
1754
2918
|
start(params) {
|
|
1755
2919
|
const requestContext = parseClientRequestContext(params.requestContext);
|
|
1756
|
-
return this.request(`/api/workflows/${this.workflowId}/start?runId=${
|
|
2920
|
+
return this.request(`/api/workflows/${this.workflowId}/start?runId=${this.runId}`, {
|
|
1757
2921
|
method: "POST",
|
|
1758
2922
|
body: {
|
|
1759
2923
|
inputData: params?.inputData,
|
|
1760
2924
|
initialState: params?.initialState,
|
|
1761
2925
|
requestContext,
|
|
1762
|
-
tracingOptions: params.tracingOptions
|
|
2926
|
+
tracingOptions: params.tracingOptions,
|
|
2927
|
+
perStep: params.perStep
|
|
1763
2928
|
}
|
|
1764
2929
|
});
|
|
1765
2930
|
}
|
|
1766
2931
|
/**
|
|
1767
2932
|
* Resumes a suspended workflow step synchronously without waiting for the workflow to complete
|
|
1768
|
-
* @param params - Object containing the
|
|
2933
|
+
* @param params - Object containing the step, resumeData and requestContext
|
|
1769
2934
|
* @returns Promise containing success message
|
|
1770
2935
|
*/
|
|
1771
2936
|
resume({
|
|
1772
2937
|
step,
|
|
1773
|
-
runId,
|
|
1774
2938
|
resumeData,
|
|
1775
2939
|
tracingOptions,
|
|
2940
|
+
perStep,
|
|
1776
2941
|
...rest
|
|
1777
2942
|
}) {
|
|
1778
2943
|
const requestContext = parseClientRequestContext(rest.requestContext);
|
|
1779
|
-
return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
|
|
2944
|
+
return this.request(`/api/workflows/${this.workflowId}/resume?runId=${this.runId}`, {
|
|
1780
2945
|
method: "POST",
|
|
1781
2946
|
body: {
|
|
1782
2947
|
step,
|
|
1783
2948
|
resumeData,
|
|
1784
2949
|
requestContext,
|
|
1785
|
-
tracingOptions
|
|
2950
|
+
tracingOptions,
|
|
2951
|
+
perStep
|
|
1786
2952
|
}
|
|
1787
2953
|
});
|
|
1788
2954
|
}
|
|
1789
2955
|
/**
|
|
1790
2956
|
* Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
|
|
1791
|
-
* @param params - Object containing the
|
|
2957
|
+
* @param params - Object containing the inputData, initialState and requestContext
|
|
1792
2958
|
* @returns Promise containing the workflow execution results
|
|
1793
2959
|
*/
|
|
1794
2960
|
startAsync(params) {
|
|
1795
2961
|
const searchParams = new URLSearchParams();
|
|
1796
|
-
|
|
1797
|
-
searchParams.set("runId", params.runId);
|
|
1798
|
-
}
|
|
2962
|
+
searchParams.set("runId", this.runId);
|
|
1799
2963
|
const requestContext = parseClientRequestContext(params.requestContext);
|
|
1800
2964
|
return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
1801
2965
|
method: "POST",
|
|
@@ -1803,20 +2967,20 @@ var Workflow = class extends BaseResource {
|
|
|
1803
2967
|
inputData: params.inputData,
|
|
1804
2968
|
initialState: params.initialState,
|
|
1805
2969
|
requestContext,
|
|
1806
|
-
tracingOptions: params.tracingOptions
|
|
2970
|
+
tracingOptions: params.tracingOptions,
|
|
2971
|
+
resourceId: params.resourceId,
|
|
2972
|
+
perStep: params.perStep
|
|
1807
2973
|
}
|
|
1808
|
-
});
|
|
2974
|
+
}).then(deserializeWorkflowError);
|
|
1809
2975
|
}
|
|
1810
2976
|
/**
|
|
1811
2977
|
* Starts a workflow run and returns a stream
|
|
1812
|
-
* @param params - Object containing the
|
|
2978
|
+
* @param params - Object containing the inputData, initialState and requestContext
|
|
1813
2979
|
* @returns Promise containing the workflow execution results
|
|
1814
2980
|
*/
|
|
1815
2981
|
async stream(params) {
|
|
1816
2982
|
const searchParams = new URLSearchParams();
|
|
1817
|
-
|
|
1818
|
-
searchParams.set("runId", params.runId);
|
|
1819
|
-
}
|
|
2983
|
+
searchParams.set("runId", this.runId);
|
|
1820
2984
|
const requestContext = parseClientRequestContext(params.requestContext);
|
|
1821
2985
|
const response = await this.request(
|
|
1822
2986
|
`/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
|
|
@@ -1826,7 +2990,10 @@ var Workflow = class extends BaseResource {
|
|
|
1826
2990
|
inputData: params.inputData,
|
|
1827
2991
|
initialState: params.initialState,
|
|
1828
2992
|
requestContext,
|
|
1829
|
-
tracingOptions: params.tracingOptions
|
|
2993
|
+
tracingOptions: params.tracingOptions,
|
|
2994
|
+
resourceId: params.resourceId,
|
|
2995
|
+
perStep: params.perStep,
|
|
2996
|
+
closeOnSuspend: params.closeOnSuspend
|
|
1830
2997
|
},
|
|
1831
2998
|
stream: true
|
|
1832
2999
|
}
|
|
@@ -1837,40 +3004,15 @@ var Workflow = class extends BaseResource {
|
|
|
1837
3004
|
if (!response.body) {
|
|
1838
3005
|
throw new Error("Response body is null");
|
|
1839
3006
|
}
|
|
1840
|
-
|
|
1841
|
-
const transformStream = new TransformStream({
|
|
1842
|
-
start() {
|
|
1843
|
-
},
|
|
1844
|
-
async transform(chunk, controller) {
|
|
1845
|
-
try {
|
|
1846
|
-
const decoded = new TextDecoder().decode(chunk);
|
|
1847
|
-
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
1848
|
-
for (const chunk2 of chunks) {
|
|
1849
|
-
if (chunk2) {
|
|
1850
|
-
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
1851
|
-
try {
|
|
1852
|
-
const parsedChunk = JSON.parse(newChunk);
|
|
1853
|
-
controller.enqueue(parsedChunk);
|
|
1854
|
-
failedChunk = void 0;
|
|
1855
|
-
} catch {
|
|
1856
|
-
failedChunk = newChunk;
|
|
1857
|
-
}
|
|
1858
|
-
}
|
|
1859
|
-
}
|
|
1860
|
-
} catch {
|
|
1861
|
-
}
|
|
1862
|
-
}
|
|
1863
|
-
});
|
|
1864
|
-
return response.body.pipeThrough(transformStream);
|
|
3007
|
+
return response.body.pipeThrough(this.createChunkTransformStream());
|
|
1865
3008
|
}
|
|
1866
3009
|
/**
|
|
1867
3010
|
* Observes workflow stream for a workflow run
|
|
1868
|
-
* @param params - Object containing the runId
|
|
1869
3011
|
* @returns Promise containing the workflow execution results
|
|
1870
3012
|
*/
|
|
1871
|
-
async observeStream(
|
|
3013
|
+
async observeStream() {
|
|
1872
3014
|
const searchParams = new URLSearchParams();
|
|
1873
|
-
searchParams.set("runId",
|
|
3015
|
+
searchParams.set("runId", this.runId);
|
|
1874
3016
|
const response = await this.request(
|
|
1875
3017
|
`/api/workflows/${this.workflowId}/observe-stream?${searchParams.toString()}`,
|
|
1876
3018
|
{
|
|
@@ -1884,161 +3026,34 @@ var Workflow = class extends BaseResource {
|
|
|
1884
3026
|
if (!response.body) {
|
|
1885
3027
|
throw new Error("Response body is null");
|
|
1886
3028
|
}
|
|
1887
|
-
|
|
1888
|
-
const transformStream = new TransformStream({
|
|
1889
|
-
start() {
|
|
1890
|
-
},
|
|
1891
|
-
async transform(chunk, controller) {
|
|
1892
|
-
try {
|
|
1893
|
-
const decoded = new TextDecoder().decode(chunk);
|
|
1894
|
-
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
1895
|
-
for (const chunk2 of chunks) {
|
|
1896
|
-
if (chunk2) {
|
|
1897
|
-
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
1898
|
-
try {
|
|
1899
|
-
const parsedChunk = JSON.parse(newChunk);
|
|
1900
|
-
controller.enqueue(parsedChunk);
|
|
1901
|
-
failedChunk = void 0;
|
|
1902
|
-
} catch {
|
|
1903
|
-
failedChunk = newChunk;
|
|
1904
|
-
}
|
|
1905
|
-
}
|
|
1906
|
-
}
|
|
1907
|
-
} catch {
|
|
1908
|
-
}
|
|
1909
|
-
}
|
|
1910
|
-
});
|
|
1911
|
-
return response.body.pipeThrough(transformStream);
|
|
1912
|
-
}
|
|
1913
|
-
/**
|
|
1914
|
-
* Starts a workflow run and returns a stream
|
|
1915
|
-
* @param params - Object containing the optional runId, inputData, initialState and requestContext
|
|
1916
|
-
* @returns Promise containing the workflow execution results
|
|
1917
|
-
*/
|
|
1918
|
-
async streamVNext(params) {
|
|
1919
|
-
const searchParams = new URLSearchParams();
|
|
1920
|
-
if (!!params?.runId) {
|
|
1921
|
-
searchParams.set("runId", params.runId);
|
|
1922
|
-
}
|
|
1923
|
-
const requestContext = parseClientRequestContext(params.requestContext);
|
|
1924
|
-
const response = await this.request(
|
|
1925
|
-
`/api/workflows/${this.workflowId}/streamVNext?${searchParams.toString()}`,
|
|
1926
|
-
{
|
|
1927
|
-
method: "POST",
|
|
1928
|
-
body: {
|
|
1929
|
-
inputData: params.inputData,
|
|
1930
|
-
initialState: params.initialState,
|
|
1931
|
-
requestContext,
|
|
1932
|
-
closeOnSuspend: params.closeOnSuspend,
|
|
1933
|
-
tracingOptions: params.tracingOptions
|
|
1934
|
-
},
|
|
1935
|
-
stream: true
|
|
1936
|
-
}
|
|
1937
|
-
);
|
|
1938
|
-
if (!response.ok) {
|
|
1939
|
-
throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
|
|
1940
|
-
}
|
|
1941
|
-
if (!response.body) {
|
|
1942
|
-
throw new Error("Response body is null");
|
|
1943
|
-
}
|
|
1944
|
-
let failedChunk = void 0;
|
|
1945
|
-
const transformStream = new TransformStream({
|
|
1946
|
-
start() {
|
|
1947
|
-
},
|
|
1948
|
-
async transform(chunk, controller) {
|
|
1949
|
-
try {
|
|
1950
|
-
const decoded = new TextDecoder().decode(chunk);
|
|
1951
|
-
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
1952
|
-
for (const chunk2 of chunks) {
|
|
1953
|
-
if (chunk2) {
|
|
1954
|
-
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
1955
|
-
try {
|
|
1956
|
-
const parsedChunk = JSON.parse(newChunk);
|
|
1957
|
-
controller.enqueue(parsedChunk);
|
|
1958
|
-
failedChunk = void 0;
|
|
1959
|
-
} catch {
|
|
1960
|
-
failedChunk = newChunk;
|
|
1961
|
-
}
|
|
1962
|
-
}
|
|
1963
|
-
}
|
|
1964
|
-
} catch {
|
|
1965
|
-
}
|
|
1966
|
-
}
|
|
1967
|
-
});
|
|
1968
|
-
return response.body.pipeThrough(transformStream);
|
|
1969
|
-
}
|
|
1970
|
-
/**
|
|
1971
|
-
* Observes workflow vNext stream for a workflow run
|
|
1972
|
-
* @param params - Object containing the runId
|
|
1973
|
-
* @returns Promise containing the workflow execution results
|
|
1974
|
-
*/
|
|
1975
|
-
async observeStreamVNext(params) {
|
|
1976
|
-
const searchParams = new URLSearchParams();
|
|
1977
|
-
searchParams.set("runId", params.runId);
|
|
1978
|
-
const response = await this.request(
|
|
1979
|
-
`/api/workflows/${this.workflowId}/observe-streamVNext?${searchParams.toString()}`,
|
|
1980
|
-
{
|
|
1981
|
-
method: "POST",
|
|
1982
|
-
stream: true
|
|
1983
|
-
}
|
|
1984
|
-
);
|
|
1985
|
-
if (!response.ok) {
|
|
1986
|
-
throw new Error(`Failed to observe stream vNext workflow: ${response.statusText}`);
|
|
1987
|
-
}
|
|
1988
|
-
if (!response.body) {
|
|
1989
|
-
throw new Error("Response body is null");
|
|
1990
|
-
}
|
|
1991
|
-
let failedChunk = void 0;
|
|
1992
|
-
const transformStream = new TransformStream({
|
|
1993
|
-
start() {
|
|
1994
|
-
},
|
|
1995
|
-
async transform(chunk, controller) {
|
|
1996
|
-
try {
|
|
1997
|
-
const decoded = new TextDecoder().decode(chunk);
|
|
1998
|
-
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
1999
|
-
for (const chunk2 of chunks) {
|
|
2000
|
-
if (chunk2) {
|
|
2001
|
-
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
2002
|
-
try {
|
|
2003
|
-
const parsedChunk = JSON.parse(newChunk);
|
|
2004
|
-
controller.enqueue(parsedChunk);
|
|
2005
|
-
failedChunk = void 0;
|
|
2006
|
-
} catch {
|
|
2007
|
-
failedChunk = newChunk;
|
|
2008
|
-
}
|
|
2009
|
-
}
|
|
2010
|
-
}
|
|
2011
|
-
} catch {
|
|
2012
|
-
}
|
|
2013
|
-
}
|
|
2014
|
-
});
|
|
2015
|
-
return response.body.pipeThrough(transformStream);
|
|
3029
|
+
return response.body.pipeThrough(this.createChunkTransformStream());
|
|
2016
3030
|
}
|
|
2017
3031
|
/**
|
|
2018
3032
|
* Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
2019
|
-
* @param params - Object containing the
|
|
3033
|
+
* @param params - Object containing the step, resumeData and requestContext
|
|
2020
3034
|
* @returns Promise containing the workflow resume results
|
|
2021
3035
|
*/
|
|
2022
3036
|
resumeAsync(params) {
|
|
2023
3037
|
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2024
|
-
return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${
|
|
3038
|
+
return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${this.runId}`, {
|
|
2025
3039
|
method: "POST",
|
|
2026
3040
|
body: {
|
|
2027
3041
|
step: params.step,
|
|
2028
3042
|
resumeData: params.resumeData,
|
|
2029
3043
|
requestContext,
|
|
2030
|
-
tracingOptions: params.tracingOptions
|
|
3044
|
+
tracingOptions: params.tracingOptions,
|
|
3045
|
+
perStep: params.perStep
|
|
2031
3046
|
}
|
|
2032
|
-
});
|
|
3047
|
+
}).then(deserializeWorkflowError);
|
|
2033
3048
|
}
|
|
2034
3049
|
/**
|
|
2035
|
-
* Resumes a suspended workflow step that uses
|
|
2036
|
-
* @param params - Object containing the
|
|
3050
|
+
* Resumes a suspended workflow step that uses stream asynchronously and returns a promise that resolves when the workflow is complete
|
|
3051
|
+
* @param params - Object containing the step, resumeData and requestContext
|
|
2037
3052
|
* @returns Promise containing the workflow resume results
|
|
2038
3053
|
*/
|
|
2039
|
-
async
|
|
3054
|
+
async resumeStream(params) {
|
|
2040
3055
|
const searchParams = new URLSearchParams();
|
|
2041
|
-
searchParams.set("runId",
|
|
3056
|
+
searchParams.set("runId", this.runId);
|
|
2042
3057
|
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2043
3058
|
const response = await this.request(
|
|
2044
3059
|
`/api/workflows/${this.workflowId}/resume-stream?${searchParams.toString()}`,
|
|
@@ -2048,74 +3063,28 @@ var Workflow = class extends BaseResource {
|
|
|
2048
3063
|
step: params.step,
|
|
2049
3064
|
resumeData: params.resumeData,
|
|
2050
3065
|
requestContext,
|
|
2051
|
-
tracingOptions: params.tracingOptions
|
|
3066
|
+
tracingOptions: params.tracingOptions,
|
|
3067
|
+
perStep: params.perStep
|
|
2052
3068
|
},
|
|
2053
3069
|
stream: true
|
|
2054
3070
|
}
|
|
2055
3071
|
);
|
|
2056
3072
|
if (!response.ok) {
|
|
2057
|
-
throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
|
|
2058
|
-
}
|
|
2059
|
-
if (!response.body) {
|
|
2060
|
-
throw new Error("Response body is null");
|
|
2061
|
-
}
|
|
2062
|
-
|
|
2063
|
-
const transformStream = new TransformStream({
|
|
2064
|
-
start() {
|
|
2065
|
-
},
|
|
2066
|
-
async transform(chunk, controller) {
|
|
2067
|
-
try {
|
|
2068
|
-
const decoded = new TextDecoder().decode(chunk);
|
|
2069
|
-
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
2070
|
-
for (const chunk2 of chunks) {
|
|
2071
|
-
if (chunk2) {
|
|
2072
|
-
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
2073
|
-
try {
|
|
2074
|
-
const parsedChunk = JSON.parse(newChunk);
|
|
2075
|
-
controller.enqueue(parsedChunk);
|
|
2076
|
-
failedChunk = void 0;
|
|
2077
|
-
} catch {
|
|
2078
|
-
failedChunk = newChunk;
|
|
2079
|
-
}
|
|
2080
|
-
}
|
|
2081
|
-
}
|
|
2082
|
-
} catch {
|
|
2083
|
-
}
|
|
2084
|
-
}
|
|
2085
|
-
});
|
|
2086
|
-
return response.body.pipeThrough(transformStream);
|
|
2087
|
-
}
|
|
2088
|
-
/**
|
|
2089
|
-
* Creates a new ReadableStream from an iterable or async iterable of objects,
|
|
2090
|
-
* serializing each as JSON and separating them with the record separator (\x1E).
|
|
2091
|
-
*
|
|
2092
|
-
* @param records - An iterable or async iterable of objects to stream
|
|
2093
|
-
* @returns A ReadableStream emitting the records as JSON strings separated by the record separator
|
|
2094
|
-
*/
|
|
2095
|
-
static createRecordStream(records) {
|
|
2096
|
-
const encoder = new TextEncoder();
|
|
2097
|
-
return new ReadableStream({
|
|
2098
|
-
async start(controller) {
|
|
2099
|
-
try {
|
|
2100
|
-
for await (const record of records) {
|
|
2101
|
-
const json = JSON.stringify(record) + RECORD_SEPARATOR;
|
|
2102
|
-
controller.enqueue(encoder.encode(json));
|
|
2103
|
-
}
|
|
2104
|
-
controller.close();
|
|
2105
|
-
} catch (err) {
|
|
2106
|
-
controller.error(err);
|
|
2107
|
-
}
|
|
2108
|
-
}
|
|
2109
|
-
});
|
|
3073
|
+
throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
|
|
3074
|
+
}
|
|
3075
|
+
if (!response.body) {
|
|
3076
|
+
throw new Error("Response body is null");
|
|
3077
|
+
}
|
|
3078
|
+
return response.body.pipeThrough(this.createChunkTransformStream());
|
|
2110
3079
|
}
|
|
2111
3080
|
/**
|
|
2112
3081
|
* Restarts an active workflow run synchronously without waiting for the workflow to complete
|
|
2113
|
-
* @param params - Object containing the
|
|
3082
|
+
* @param params - Object containing the requestContext
|
|
2114
3083
|
* @returns Promise containing success message
|
|
2115
3084
|
*/
|
|
2116
3085
|
restart(params) {
|
|
2117
3086
|
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2118
|
-
return this.request(`/api/workflows/${this.workflowId}/restart?runId=${
|
|
3087
|
+
return this.request(`/api/workflows/${this.workflowId}/restart?runId=${this.runId}`, {
|
|
2119
3088
|
method: "POST",
|
|
2120
3089
|
body: {
|
|
2121
3090
|
requestContext,
|
|
@@ -2125,49 +3094,27 @@ var Workflow = class extends BaseResource {
|
|
|
2125
3094
|
}
|
|
2126
3095
|
/**
|
|
2127
3096
|
* Restarts an active workflow run asynchronously
|
|
2128
|
-
* @param params -
|
|
3097
|
+
* @param params - optional object containing the requestContext
|
|
2129
3098
|
* @returns Promise containing the workflow restart results
|
|
2130
3099
|
*/
|
|
2131
3100
|
restartAsync(params) {
|
|
2132
|
-
const requestContext = parseClientRequestContext(params
|
|
2133
|
-
return this.request(`/api/workflows/${this.workflowId}/restart-async?runId=${
|
|
3101
|
+
const requestContext = parseClientRequestContext(params?.requestContext);
|
|
3102
|
+
return this.request(`/api/workflows/${this.workflowId}/restart-async?runId=${this.runId}`, {
|
|
2134
3103
|
method: "POST",
|
|
2135
3104
|
body: {
|
|
2136
3105
|
requestContext,
|
|
2137
|
-
tracingOptions: params
|
|
3106
|
+
tracingOptions: params?.tracingOptions
|
|
2138
3107
|
}
|
|
2139
|
-
});
|
|
2140
|
-
}
|
|
2141
|
-
/**
|
|
2142
|
-
* Restart all active workflow runs synchronously without waiting for the workflow to complete
|
|
2143
|
-
* @returns Promise containing success message
|
|
2144
|
-
*/
|
|
2145
|
-
restartAllActiveWorkflowRuns() {
|
|
2146
|
-
return this.request(`/api/workflows/${this.workflowId}/restart-all-active-workflow-runs`, {
|
|
2147
|
-
method: "POST"
|
|
2148
|
-
});
|
|
2149
|
-
}
|
|
2150
|
-
/**
|
|
2151
|
-
* Restart all active workflow runs asynchronously
|
|
2152
|
-
* @returns Promise containing success message
|
|
2153
|
-
*/
|
|
2154
|
-
restartAllActiveWorkflowRunsAsync() {
|
|
2155
|
-
return this.request(`/api/workflows/${this.workflowId}/restart-all-active-workflow-runs-async`, {
|
|
2156
|
-
method: "POST"
|
|
2157
|
-
});
|
|
3108
|
+
}).then(deserializeWorkflowError);
|
|
2158
3109
|
}
|
|
2159
3110
|
/**
|
|
2160
3111
|
* Time travels a workflow run synchronously without waiting for the workflow to complete
|
|
2161
|
-
* @param params - Object containing the
|
|
3112
|
+
* @param params - Object containing the step, inputData, resumeData, initialState, context, nestedStepsContext, requestContext and tracingOptions
|
|
2162
3113
|
* @returns Promise containing success message
|
|
2163
3114
|
*/
|
|
2164
|
-
timeTravel({
|
|
2165
|
-
runId,
|
|
2166
|
-
requestContext: paramsRequestContext,
|
|
2167
|
-
...params
|
|
2168
|
-
}) {
|
|
3115
|
+
timeTravel({ requestContext: paramsRequestContext, ...params }) {
|
|
2169
3116
|
const requestContext = parseClientRequestContext(paramsRequestContext);
|
|
2170
|
-
return this.request(`/api/workflows/${this.workflowId}/time-travel?runId=${runId}`, {
|
|
3117
|
+
return this.request(`/api/workflows/${this.workflowId}/time-travel?runId=${this.runId}`, {
|
|
2171
3118
|
method: "POST",
|
|
2172
3119
|
body: {
|
|
2173
3120
|
...params,
|
|
@@ -2177,32 +3124,28 @@ var Workflow = class extends BaseResource {
|
|
|
2177
3124
|
}
|
|
2178
3125
|
/**
|
|
2179
3126
|
* Time travels a workflow run asynchronously
|
|
2180
|
-
* @param params - Object containing the
|
|
3127
|
+
* @param params - Object containing the step, inputData, resumeData, initialState, context, nestedStepsContext, requestContext and tracingOptions
|
|
2181
3128
|
* @returns Promise containing the workflow time travel results
|
|
2182
3129
|
*/
|
|
2183
|
-
timeTravelAsync({
|
|
2184
|
-
runId,
|
|
2185
|
-
requestContext: paramsRequestContext,
|
|
2186
|
-
...params
|
|
2187
|
-
}) {
|
|
3130
|
+
timeTravelAsync({ requestContext: paramsRequestContext, ...params }) {
|
|
2188
3131
|
const requestContext = parseClientRequestContext(paramsRequestContext);
|
|
2189
|
-
return this.request(`/api/workflows/${this.workflowId}/time-travel-async?runId=${runId}`, {
|
|
3132
|
+
return this.request(`/api/workflows/${this.workflowId}/time-travel-async?runId=${this.runId}`, {
|
|
2190
3133
|
method: "POST",
|
|
2191
3134
|
body: {
|
|
2192
3135
|
...params,
|
|
2193
3136
|
requestContext
|
|
2194
3137
|
}
|
|
2195
|
-
});
|
|
3138
|
+
}).then(deserializeWorkflowError);
|
|
2196
3139
|
}
|
|
2197
3140
|
/**
|
|
2198
3141
|
* Time travels a workflow run and returns a stream
|
|
2199
|
-
* @param params - Object containing the
|
|
3142
|
+
* @param params - Object containing the step, inputData, resumeData, initialState, context, nestedStepsContext, requestContext and tracingOptions
|
|
2200
3143
|
* @returns Promise containing the workflow execution results
|
|
2201
3144
|
*/
|
|
2202
|
-
async timeTravelStream({
|
|
3145
|
+
async timeTravelStream({ requestContext: paramsRequestContext, ...params }) {
|
|
2203
3146
|
const requestContext = parseClientRequestContext(paramsRequestContext);
|
|
2204
3147
|
const response = await this.request(
|
|
2205
|
-
`/api/workflows/${this.workflowId}/time-travel-stream?runId=${runId}`,
|
|
3148
|
+
`/api/workflows/${this.workflowId}/time-travel-stream?runId=${this.runId}`,
|
|
2206
3149
|
{
|
|
2207
3150
|
method: "POST",
|
|
2208
3151
|
body: {
|
|
@@ -2218,31 +3161,150 @@ var Workflow = class extends BaseResource {
|
|
|
2218
3161
|
if (!response.body) {
|
|
2219
3162
|
throw new Error("Response body is null");
|
|
2220
3163
|
}
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
3164
|
+
return response.body.pipeThrough(this.createChunkTransformStream());
|
|
3165
|
+
}
|
|
3166
|
+
};
|
|
3167
|
+
|
|
3168
|
+
// src/resources/workflow.ts
|
|
3169
|
+
var RECORD_SEPARATOR2 = "";
|
|
3170
|
+
var Workflow = class extends BaseResource {
|
|
3171
|
+
constructor(options, workflowId) {
|
|
3172
|
+
super(options);
|
|
3173
|
+
this.workflowId = workflowId;
|
|
3174
|
+
}
|
|
3175
|
+
/**
|
|
3176
|
+
* Retrieves details about the workflow
|
|
3177
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
3178
|
+
* @returns Promise containing workflow details including steps and graphs
|
|
3179
|
+
*/
|
|
3180
|
+
details(requestContext) {
|
|
3181
|
+
return this.request(`/api/workflows/${this.workflowId}${requestContextQueryString(requestContext)}`);
|
|
3182
|
+
}
|
|
3183
|
+
/**
|
|
3184
|
+
* Retrieves all runs for a workflow
|
|
3185
|
+
* @param params - Parameters for filtering runs
|
|
3186
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
3187
|
+
* @returns Promise containing workflow runs array
|
|
3188
|
+
*/
|
|
3189
|
+
runs(params, requestContext) {
|
|
3190
|
+
const requestContextParam = base64RequestContext(parseClientRequestContext(requestContext));
|
|
3191
|
+
const searchParams = new URLSearchParams();
|
|
3192
|
+
if (params?.fromDate) {
|
|
3193
|
+
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
3194
|
+
}
|
|
3195
|
+
if (params?.toDate) {
|
|
3196
|
+
searchParams.set("toDate", params.toDate.toISOString());
|
|
3197
|
+
}
|
|
3198
|
+
if (params?.page !== void 0) {
|
|
3199
|
+
searchParams.set("page", String(params.page));
|
|
3200
|
+
}
|
|
3201
|
+
if (params?.perPage !== void 0) {
|
|
3202
|
+
searchParams.set("perPage", String(params.perPage));
|
|
3203
|
+
}
|
|
3204
|
+
if (params?.limit !== null && params?.limit !== void 0) {
|
|
3205
|
+
if (params.limit === false) {
|
|
3206
|
+
searchParams.set("limit", "false");
|
|
3207
|
+
} else if (typeof params.limit === "number" && params.limit > 0 && Number.isInteger(params.limit)) {
|
|
3208
|
+
searchParams.set("limit", String(params.limit));
|
|
3209
|
+
}
|
|
3210
|
+
}
|
|
3211
|
+
if (params?.offset !== null && params?.offset !== void 0 && !isNaN(Number(params?.offset))) {
|
|
3212
|
+
searchParams.set("offset", String(params.offset));
|
|
3213
|
+
}
|
|
3214
|
+
if (params?.resourceId) {
|
|
3215
|
+
searchParams.set("resourceId", params.resourceId);
|
|
3216
|
+
}
|
|
3217
|
+
if (params?.status) {
|
|
3218
|
+
searchParams.set("status", params.status);
|
|
3219
|
+
}
|
|
3220
|
+
if (requestContextParam) {
|
|
3221
|
+
searchParams.set("requestContext", requestContextParam);
|
|
3222
|
+
}
|
|
3223
|
+
if (searchParams.size) {
|
|
3224
|
+
return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
|
|
3225
|
+
} else {
|
|
3226
|
+
return this.request(`/api/workflows/${this.workflowId}/runs`);
|
|
3227
|
+
}
|
|
3228
|
+
}
|
|
3229
|
+
/**
|
|
3230
|
+
* Retrieves a specific workflow run by its ID
|
|
3231
|
+
* @param runId - The ID of the workflow run to retrieve
|
|
3232
|
+
* @param options - Optional configuration
|
|
3233
|
+
* @param options.requestContext - Optional request context to pass as query parameter
|
|
3234
|
+
* @param options.fields - Optional array of fields to return (e.g., ['result', 'steps']). Available fields: result, error, payload, steps, activeStepsPath, serializedStepGraph. Metadata fields (runId, workflowName, resourceId, createdAt, updatedAt) and status are always included.
|
|
3235
|
+
* @param options.withNestedWorkflows - Whether to include nested workflow data in steps. Defaults to true. Set to false for better performance when you don't need nested workflow details.
|
|
3236
|
+
* @returns Promise containing the workflow run details with metadata and processed execution state
|
|
3237
|
+
*/
|
|
3238
|
+
runById(runId, options) {
|
|
3239
|
+
const searchParams = new URLSearchParams();
|
|
3240
|
+
if (options?.fields && options.fields.length > 0) {
|
|
3241
|
+
searchParams.set("fields", options.fields.join(","));
|
|
3242
|
+
}
|
|
3243
|
+
if (options?.withNestedWorkflows !== void 0) {
|
|
3244
|
+
searchParams.set("withNestedWorkflows", String(options.withNestedWorkflows));
|
|
3245
|
+
}
|
|
3246
|
+
const requestContextParam = base64RequestContext(parseClientRequestContext(options?.requestContext));
|
|
3247
|
+
if (requestContextParam) {
|
|
3248
|
+
searchParams.set("requestContext", requestContextParam);
|
|
3249
|
+
}
|
|
3250
|
+
const queryString = searchParams.size > 0 ? `?${searchParams.toString()}` : "";
|
|
3251
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}${queryString}`);
|
|
3252
|
+
}
|
|
3253
|
+
/**
|
|
3254
|
+
* Deletes a specific workflow run by its ID
|
|
3255
|
+
* @param runId - The ID of the workflow run to delete
|
|
3256
|
+
* @returns Promise containing a success message
|
|
3257
|
+
*/
|
|
3258
|
+
deleteRunById(runId) {
|
|
3259
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}`, {
|
|
3260
|
+
method: "DELETE"
|
|
3261
|
+
});
|
|
3262
|
+
}
|
|
3263
|
+
/**
|
|
3264
|
+
* Creates a new workflow run
|
|
3265
|
+
* @param params - Optional object containing the optional runId
|
|
3266
|
+
* @returns Promise containing the Run instance
|
|
3267
|
+
*/
|
|
3268
|
+
async createRun(params) {
|
|
3269
|
+
const searchParams = new URLSearchParams();
|
|
3270
|
+
if (!!params?.runId) {
|
|
3271
|
+
searchParams.set("runId", params.runId);
|
|
3272
|
+
}
|
|
3273
|
+
const res = await this.request(
|
|
3274
|
+
`/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`,
|
|
3275
|
+
{
|
|
3276
|
+
method: "POST",
|
|
3277
|
+
body: {
|
|
3278
|
+
resourceId: params?.resourceId,
|
|
3279
|
+
disableScorers: params?.disableScorers
|
|
3280
|
+
}
|
|
3281
|
+
}
|
|
3282
|
+
);
|
|
3283
|
+
const run = new Run(this.options, this.workflowId, res.runId);
|
|
3284
|
+
return run;
|
|
3285
|
+
}
|
|
3286
|
+
/**
|
|
3287
|
+
* Creates a new ReadableStream from an iterable or async iterable of objects,
|
|
3288
|
+
* serializing each as JSON and separating them with the record separator (\x1E).
|
|
3289
|
+
*
|
|
3290
|
+
* @param records - An iterable or async iterable of objects to stream
|
|
3291
|
+
* @returns A ReadableStream emitting the records as JSON strings separated by the record separator
|
|
3292
|
+
*/
|
|
3293
|
+
static createRecordStream(records) {
|
|
3294
|
+
const encoder = new TextEncoder();
|
|
3295
|
+
return new ReadableStream({
|
|
3296
|
+
async start(controller) {
|
|
2226
3297
|
try {
|
|
2227
|
-
const
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
if (chunk2) {
|
|
2231
|
-
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
2232
|
-
try {
|
|
2233
|
-
const parsedChunk = JSON.parse(newChunk);
|
|
2234
|
-
controller.enqueue(parsedChunk);
|
|
2235
|
-
failedChunk = void 0;
|
|
2236
|
-
} catch {
|
|
2237
|
-
failedChunk = newChunk;
|
|
2238
|
-
}
|
|
2239
|
-
}
|
|
3298
|
+
for await (const record of records) {
|
|
3299
|
+
const json = JSON.stringify(record) + RECORD_SEPARATOR2;
|
|
3300
|
+
controller.enqueue(encoder.encode(json));
|
|
2240
3301
|
}
|
|
2241
|
-
|
|
3302
|
+
controller.close();
|
|
3303
|
+
} catch (err) {
|
|
3304
|
+
controller.error(err);
|
|
2242
3305
|
}
|
|
2243
3306
|
}
|
|
2244
3307
|
});
|
|
2245
|
-
return response.body.pipeThrough(transformStream);
|
|
2246
3308
|
}
|
|
2247
3309
|
};
|
|
2248
3310
|
|
|
@@ -2358,7 +3420,7 @@ var MCPTool = class extends BaseResource {
|
|
|
2358
3420
|
};
|
|
2359
3421
|
|
|
2360
3422
|
// src/resources/agent-builder.ts
|
|
2361
|
-
var
|
|
3423
|
+
var RECORD_SEPARATOR3 = "";
|
|
2362
3424
|
var AgentBuilder = class extends BaseResource {
|
|
2363
3425
|
constructor(options, actionId) {
|
|
2364
3426
|
super(options);
|
|
@@ -2404,7 +3466,7 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2404
3466
|
async transform(chunk, controller) {
|
|
2405
3467
|
try {
|
|
2406
3468
|
const decoded = new TextDecoder().decode(chunk);
|
|
2407
|
-
const chunks = decoded.split(
|
|
3469
|
+
const chunks = decoded.split(RECORD_SEPARATOR3);
|
|
2408
3470
|
for (const chunk2 of chunks) {
|
|
2409
3471
|
if (chunk2) {
|
|
2410
3472
|
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
@@ -2518,7 +3580,7 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2518
3580
|
if (done && !value) continue;
|
|
2519
3581
|
try {
|
|
2520
3582
|
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
2521
|
-
const chunks = (buffer + decoded).split(
|
|
3583
|
+
const chunks = (buffer + decoded).split(RECORD_SEPARATOR3);
|
|
2522
3584
|
buffer = chunks.pop() || "";
|
|
2523
3585
|
for (const chunk of chunks) {
|
|
2524
3586
|
if (chunk) {
|
|
@@ -2570,36 +3632,11 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2570
3632
|
}
|
|
2571
3633
|
return response.body.pipeThrough(this.createRecordParserTransform());
|
|
2572
3634
|
}
|
|
2573
|
-
/**
|
|
2574
|
-
* Streams agent builder action progress in real-time using VNext streaming.
|
|
2575
|
-
* This calls `/api/agent-builder/:actionId/streamVNext`.
|
|
2576
|
-
*/
|
|
2577
|
-
async streamVNext(params, runId) {
|
|
2578
|
-
const searchParams = new URLSearchParams();
|
|
2579
|
-
if (runId) {
|
|
2580
|
-
searchParams.set("runId", runId);
|
|
2581
|
-
}
|
|
2582
|
-
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2583
|
-
const { requestContext: _, ...actionParams } = params;
|
|
2584
|
-
const url = `/api/agent-builder/${this.actionId}/streamVNext${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
|
|
2585
|
-
const response = await this.request(url, {
|
|
2586
|
-
method: "POST",
|
|
2587
|
-
body: { ...actionParams, requestContext },
|
|
2588
|
-
stream: true
|
|
2589
|
-
});
|
|
2590
|
-
if (!response.ok) {
|
|
2591
|
-
throw new Error(`Failed to stream agent builder action VNext: ${response.statusText}`);
|
|
2592
|
-
}
|
|
2593
|
-
if (!response.body) {
|
|
2594
|
-
throw new Error("Response body is null");
|
|
2595
|
-
}
|
|
2596
|
-
return response.body.pipeThrough(this.createRecordParserTransform());
|
|
2597
|
-
}
|
|
2598
3635
|
/**
|
|
2599
3636
|
* Observes an existing agent builder action run stream.
|
|
2600
3637
|
* Replays cached execution from the beginning, then continues with live stream.
|
|
2601
3638
|
* This is the recommended method for recovery after page refresh/hot reload.
|
|
2602
|
-
* This calls `/api/agent-builder/:actionId/observe`
|
|
3639
|
+
* This calls `/api/agent-builder/:actionId/observe`
|
|
2603
3640
|
*/
|
|
2604
3641
|
async observeStream(params) {
|
|
2605
3642
|
const searchParams = new URLSearchParams();
|
|
@@ -2617,27 +3654,6 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2617
3654
|
}
|
|
2618
3655
|
return response.body.pipeThrough(this.createRecordParserTransform());
|
|
2619
3656
|
}
|
|
2620
|
-
/**
|
|
2621
|
-
* Observes an existing agent builder action run stream using VNext streaming API.
|
|
2622
|
-
* Replays cached execution from the beginning, then continues with live stream.
|
|
2623
|
-
* This calls `/api/agent-builder/:actionId/observe-streamVNext`.
|
|
2624
|
-
*/
|
|
2625
|
-
async observeStreamVNext(params) {
|
|
2626
|
-
const searchParams = new URLSearchParams();
|
|
2627
|
-
searchParams.set("runId", params.runId);
|
|
2628
|
-
const url = `/api/agent-builder/${this.actionId}/observe-streamVNext?${searchParams.toString()}`;
|
|
2629
|
-
const response = await this.request(url, {
|
|
2630
|
-
method: "POST",
|
|
2631
|
-
stream: true
|
|
2632
|
-
});
|
|
2633
|
-
if (!response.ok) {
|
|
2634
|
-
throw new Error(`Failed to observe agent builder action stream VNext: ${response.statusText}`);
|
|
2635
|
-
}
|
|
2636
|
-
if (!response.body) {
|
|
2637
|
-
throw new Error("Response body is null");
|
|
2638
|
-
}
|
|
2639
|
-
return response.body.pipeThrough(this.createRecordParserTransform());
|
|
2640
|
-
}
|
|
2641
3657
|
/**
|
|
2642
3658
|
* Observes an existing agent builder action run stream using legacy streaming API.
|
|
2643
3659
|
* Replays cached execution from the beginning, then continues with live stream.
|
|
@@ -2685,9 +3701,22 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2685
3701
|
/**
|
|
2686
3702
|
* Gets a specific action run by its ID.
|
|
2687
3703
|
* This calls `/api/agent-builder/:actionId/runs/:runId`.
|
|
3704
|
+
* @param runId - The ID of the action run to retrieve
|
|
3705
|
+
* @param options - Optional configuration
|
|
3706
|
+
* @param options.fields - Optional array of fields to return (e.g., ['result', 'steps']). Available fields: result, error, payload, steps, activeStepsPath, serializedStepGraph. Metadata fields (runId, workflowName, resourceId, createdAt, updatedAt) and status are always included.
|
|
3707
|
+
* @param options.withNestedWorkflows - Whether to include nested workflow data in steps. Defaults to true. Set to false for better performance when you don't need nested workflow details.
|
|
3708
|
+
* @returns Promise containing the action run details with metadata and processed execution state
|
|
2688
3709
|
*/
|
|
2689
|
-
async runById(runId) {
|
|
2690
|
-
const
|
|
3710
|
+
async runById(runId, options) {
|
|
3711
|
+
const searchParams = new URLSearchParams();
|
|
3712
|
+
if (options?.fields && options.fields.length > 0) {
|
|
3713
|
+
searchParams.set("fields", options.fields.join(","));
|
|
3714
|
+
}
|
|
3715
|
+
if (options?.withNestedWorkflows !== void 0) {
|
|
3716
|
+
searchParams.set("withNestedWorkflows", String(options.withNestedWorkflows));
|
|
3717
|
+
}
|
|
3718
|
+
const queryString = searchParams.size > 0 ? `?${searchParams.toString()}` : "";
|
|
3719
|
+
const url = `/api/agent-builder/${this.actionId}/runs/${runId}${queryString}`;
|
|
2691
3720
|
return this.request(url, {
|
|
2692
3721
|
method: "GET"
|
|
2693
3722
|
});
|
|
@@ -2736,16 +3765,6 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2736
3765
|
method: "GET"
|
|
2737
3766
|
});
|
|
2738
3767
|
}
|
|
2739
|
-
/**
|
|
2740
|
-
* Gets the execution result of an agent builder action run.
|
|
2741
|
-
* This calls `/api/agent-builder/:actionId/runs/:runId/execution-result`.
|
|
2742
|
-
*/
|
|
2743
|
-
async runExecutionResult(runId) {
|
|
2744
|
-
const url = `/api/agent-builder/${this.actionId}/runs/${runId}/execution-result`;
|
|
2745
|
-
return this.request(url, {
|
|
2746
|
-
method: "GET"
|
|
2747
|
-
});
|
|
2748
|
-
}
|
|
2749
3768
|
/**
|
|
2750
3769
|
* Cancels an agent builder action run.
|
|
2751
3770
|
* This calls `/api/agent-builder/:actionId/runs/:runId/cancel`.
|
|
@@ -2772,14 +3791,17 @@ var Observability = class extends BaseResource {
|
|
|
2772
3791
|
return this.request(`/api/observability/traces/${traceId}`);
|
|
2773
3792
|
}
|
|
2774
3793
|
/**
|
|
2775
|
-
* Retrieves paginated list of traces with optional filtering
|
|
2776
|
-
*
|
|
3794
|
+
* Retrieves paginated list of traces with optional filtering.
|
|
3795
|
+
* This is the legacy API preserved for backward compatibility.
|
|
3796
|
+
*
|
|
3797
|
+
* @param params - Parameters for pagination and filtering (legacy format)
|
|
2777
3798
|
* @returns Promise containing paginated traces and pagination info
|
|
3799
|
+
* @deprecated Use {@link listTraces} instead for new features like ordering and more filters.
|
|
2778
3800
|
*/
|
|
2779
3801
|
getTraces(params) {
|
|
2780
3802
|
const { pagination, filters } = params;
|
|
2781
3803
|
const { page, perPage, dateRange } = pagination || {};
|
|
2782
|
-
const { name, spanType, entityId, entityType } = filters || {};
|
|
3804
|
+
const { name: name14, spanType, entityId, entityType } = filters || {};
|
|
2783
3805
|
const searchParams = new URLSearchParams();
|
|
2784
3806
|
if (page !== void 0) {
|
|
2785
3807
|
searchParams.set("page", String(page));
|
|
@@ -2787,8 +3809,8 @@ var Observability = class extends BaseResource {
|
|
|
2787
3809
|
if (perPage !== void 0) {
|
|
2788
3810
|
searchParams.set("perPage", String(perPage));
|
|
2789
3811
|
}
|
|
2790
|
-
if (
|
|
2791
|
-
searchParams.set("name",
|
|
3812
|
+
if (name14) {
|
|
3813
|
+
searchParams.set("name", name14);
|
|
2792
3814
|
}
|
|
2793
3815
|
if (spanType !== void 0) {
|
|
2794
3816
|
searchParams.set("spanType", String(spanType));
|
|
@@ -2807,25 +3829,34 @@ var Observability = class extends BaseResource {
|
|
|
2807
3829
|
const queryString = searchParams.toString();
|
|
2808
3830
|
return this.request(`/api/observability/traces${queryString ? `?${queryString}` : ""}`);
|
|
2809
3831
|
}
|
|
3832
|
+
/**
|
|
3833
|
+
* Retrieves paginated list of traces with optional filtering and sorting.
|
|
3834
|
+
* This is the new API with improved filtering options.
|
|
3835
|
+
*
|
|
3836
|
+
* @param params - Parameters for pagination, filtering, and ordering
|
|
3837
|
+
* @returns Promise containing paginated traces and pagination info
|
|
3838
|
+
*/
|
|
3839
|
+
listTraces(params = {}) {
|
|
3840
|
+
const queryString = toQueryParams(params, ["filters", "pagination", "orderBy"]);
|
|
3841
|
+
return this.request(`/api/observability/traces${queryString ? `?${queryString}` : ""}`);
|
|
3842
|
+
}
|
|
2810
3843
|
/**
|
|
2811
3844
|
* Retrieves scores by trace ID and span ID
|
|
2812
3845
|
* @param params - Parameters containing trace ID, span ID, and pagination options
|
|
2813
3846
|
* @returns Promise containing scores and pagination info
|
|
2814
3847
|
*/
|
|
2815
3848
|
listScoresBySpan(params) {
|
|
2816
|
-
const { traceId, spanId,
|
|
2817
|
-
const
|
|
2818
|
-
if (page !== void 0) {
|
|
2819
|
-
searchParams.set("page", String(page));
|
|
2820
|
-
}
|
|
2821
|
-
if (perPage !== void 0) {
|
|
2822
|
-
searchParams.set("perPage", String(perPage));
|
|
2823
|
-
}
|
|
2824
|
-
const queryString = searchParams.toString();
|
|
3849
|
+
const { traceId, spanId, ...pagination } = params;
|
|
3850
|
+
const queryString = toQueryParams(pagination);
|
|
2825
3851
|
return this.request(
|
|
2826
3852
|
`/api/observability/traces/${encodeURIComponent(traceId)}/${encodeURIComponent(spanId)}/scores${queryString ? `?${queryString}` : ""}`
|
|
2827
3853
|
);
|
|
2828
3854
|
}
|
|
3855
|
+
/**
|
|
3856
|
+
* Scores one or more traces using a specified scorer.
|
|
3857
|
+
* @param params - Scorer name and targets to score
|
|
3858
|
+
* @returns Promise containing the scoring status
|
|
3859
|
+
*/
|
|
2829
3860
|
score(params) {
|
|
2830
3861
|
return this.request(`/api/observability/traces/score`, {
|
|
2831
3862
|
method: "POST",
|
|
@@ -2905,22 +3936,26 @@ var MastraClient = class extends BaseResource {
|
|
|
2905
3936
|
return new Agent(this.options, agentId);
|
|
2906
3937
|
}
|
|
2907
3938
|
/**
|
|
2908
|
-
* Lists memory threads
|
|
2909
|
-
* @param params - Parameters containing
|
|
3939
|
+
* Lists memory threads with optional filtering by resourceId and/or metadata
|
|
3940
|
+
* @param params - Parameters containing optional filters, pagination options, and request context
|
|
2910
3941
|
* @returns Promise containing paginated array of memory threads with metadata
|
|
2911
3942
|
*/
|
|
2912
|
-
async listMemoryThreads(params) {
|
|
2913
|
-
const queryParams = new URLSearchParams(
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
|
|
3943
|
+
async listMemoryThreads(params = {}) {
|
|
3944
|
+
const queryParams = new URLSearchParams();
|
|
3945
|
+
if (params.resourceId) {
|
|
3946
|
+
queryParams.set("resourceId", params.resourceId);
|
|
3947
|
+
}
|
|
3948
|
+
if (params.metadata) {
|
|
3949
|
+
queryParams.set("metadata", JSON.stringify(params.metadata));
|
|
3950
|
+
}
|
|
3951
|
+
if (params.agentId) queryParams.set("agentId", params.agentId);
|
|
3952
|
+
if (params.page !== void 0) queryParams.set("page", params.page.toString());
|
|
3953
|
+
if (params.perPage !== void 0) queryParams.set("perPage", params.perPage.toString());
|
|
3954
|
+
if (params.orderBy) queryParams.set("orderBy", params.orderBy);
|
|
3955
|
+
if (params.sortDirection) queryParams.set("sortDirection", params.sortDirection);
|
|
3956
|
+
const queryString = queryParams.toString();
|
|
2922
3957
|
const response = await this.request(
|
|
2923
|
-
`/api/memory/threads
|
|
3958
|
+
`/api/memory/threads${queryString ? `?${queryString}` : ""}${requestContextQueryString(params.requestContext, queryString ? "&" : "?")}`
|
|
2924
3959
|
);
|
|
2925
3960
|
const actualResponse = "threads" in response ? response : {
|
|
2926
3961
|
threads: response,
|
|
@@ -2955,20 +3990,29 @@ var MastraClient = class extends BaseResource {
|
|
|
2955
3990
|
/**
|
|
2956
3991
|
* Gets a memory thread instance by ID
|
|
2957
3992
|
* @param threadId - ID of the memory thread to retrieve
|
|
3993
|
+
* @param agentId - Optional agent ID. When not provided, uses storage directly
|
|
2958
3994
|
* @returns MemoryThread instance
|
|
2959
3995
|
*/
|
|
2960
3996
|
getMemoryThread({ threadId, agentId }) {
|
|
2961
3997
|
return new MemoryThread(this.options, threadId, agentId);
|
|
2962
3998
|
}
|
|
3999
|
+
/**
|
|
4000
|
+
* Lists messages for a thread.
|
|
4001
|
+
* @param threadId - ID of the thread
|
|
4002
|
+
* @param opts - Optional parameters including agentId, networkId, and requestContext
|
|
4003
|
+
* - When agentId is provided, uses the agent's memory
|
|
4004
|
+
* - When networkId is provided, uses the network endpoint
|
|
4005
|
+
* - When neither is provided, uses storage directly
|
|
4006
|
+
* @returns Promise containing the thread messages
|
|
4007
|
+
*/
|
|
2963
4008
|
listThreadMessages(threadId, opts = {}) {
|
|
2964
|
-
if (!opts.agentId && !opts.networkId) {
|
|
2965
|
-
throw new Error("Either agentId or networkId must be provided");
|
|
2966
|
-
}
|
|
2967
4009
|
let url = "";
|
|
2968
|
-
if (opts.
|
|
2969
|
-
url = `/api/memory/threads/${threadId}/messages?agentId=${opts.agentId}${requestContextQueryString(opts.requestContext, "&")}`;
|
|
2970
|
-
} else if (opts.networkId) {
|
|
4010
|
+
if (opts.networkId) {
|
|
2971
4011
|
url = `/api/memory/network/threads/${threadId}/messages?networkId=${opts.networkId}${requestContextQueryString(opts.requestContext, "&")}`;
|
|
4012
|
+
} else if (opts.agentId) {
|
|
4013
|
+
url = `/api/memory/threads/${threadId}/messages?agentId=${opts.agentId}${requestContextQueryString(opts.requestContext, "&")}`;
|
|
4014
|
+
} else {
|
|
4015
|
+
url = `/api/memory/threads/${threadId}/messages${requestContextQueryString(opts.requestContext, "?")}`;
|
|
2972
4016
|
}
|
|
2973
4017
|
return this.request(url);
|
|
2974
4018
|
}
|
|
@@ -3026,6 +4070,28 @@ var MastraClient = class extends BaseResource {
|
|
|
3026
4070
|
getTool(toolId) {
|
|
3027
4071
|
return new Tool(this.options, toolId);
|
|
3028
4072
|
}
|
|
4073
|
+
/**
|
|
4074
|
+
* Retrieves all available processors
|
|
4075
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
4076
|
+
* @returns Promise containing map of processor IDs to processor details
|
|
4077
|
+
*/
|
|
4078
|
+
listProcessors(requestContext) {
|
|
4079
|
+
const requestContextParam = base64RequestContext(parseClientRequestContext(requestContext));
|
|
4080
|
+
const searchParams = new URLSearchParams();
|
|
4081
|
+
if (requestContextParam) {
|
|
4082
|
+
searchParams.set("requestContext", requestContextParam);
|
|
4083
|
+
}
|
|
4084
|
+
const queryString = searchParams.toString();
|
|
4085
|
+
return this.request(`/api/processors${queryString ? `?${queryString}` : ""}`);
|
|
4086
|
+
}
|
|
4087
|
+
/**
|
|
4088
|
+
* Gets a processor instance by ID
|
|
4089
|
+
* @param processorId - ID of the processor to retrieve
|
|
4090
|
+
* @returns Processor instance
|
|
4091
|
+
*/
|
|
4092
|
+
getProcessor(processorId) {
|
|
4093
|
+
return new Processor(this.options, processorId);
|
|
4094
|
+
}
|
|
3029
4095
|
/**
|
|
3030
4096
|
* Retrieves all available workflows
|
|
3031
4097
|
* @param requestContext - Optional request context to pass as query parameter
|
|
@@ -3375,9 +4441,27 @@ var MastraClient = class extends BaseResource {
|
|
|
3375
4441
|
getTrace(traceId) {
|
|
3376
4442
|
return this.observability.getTrace(traceId);
|
|
3377
4443
|
}
|
|
4444
|
+
/**
|
|
4445
|
+
* Retrieves paginated list of traces with optional filtering.
|
|
4446
|
+
* This is the legacy API preserved for backward compatibility.
|
|
4447
|
+
*
|
|
4448
|
+
* @param params - Parameters for pagination and filtering (legacy format)
|
|
4449
|
+
* @returns Promise containing paginated traces and pagination info
|
|
4450
|
+
* @deprecated Use {@link listTraces} instead for new features like ordering and more filters.
|
|
4451
|
+
*/
|
|
3378
4452
|
getTraces(params) {
|
|
3379
4453
|
return this.observability.getTraces(params);
|
|
3380
4454
|
}
|
|
4455
|
+
/**
|
|
4456
|
+
* Retrieves paginated list of traces with optional filtering and sorting.
|
|
4457
|
+
* This is the new API with improved filtering options.
|
|
4458
|
+
*
|
|
4459
|
+
* @param params - Parameters for pagination, filtering, and ordering
|
|
4460
|
+
* @returns Promise containing paginated traces and pagination info
|
|
4461
|
+
*/
|
|
4462
|
+
listTraces(params = {}) {
|
|
4463
|
+
return this.observability.listTraces(params);
|
|
4464
|
+
}
|
|
3381
4465
|
listScoresBySpan(params) {
|
|
3382
4466
|
return this.observability.listScoresBySpan(params);
|
|
3383
4467
|
}
|
|
@@ -3430,6 +4514,16 @@ var MastraClient = class extends BaseResource {
|
|
|
3430
4514
|
getStoredAgent(storedAgentId) {
|
|
3431
4515
|
return new StoredAgent(this.options, storedAgentId);
|
|
3432
4516
|
}
|
|
4517
|
+
// ============================================================================
|
|
4518
|
+
// System
|
|
4519
|
+
// ============================================================================
|
|
4520
|
+
/**
|
|
4521
|
+
* Retrieves installed Mastra packages and their versions
|
|
4522
|
+
* @returns Promise containing the list of installed Mastra packages
|
|
4523
|
+
*/
|
|
4524
|
+
getSystemPackages() {
|
|
4525
|
+
return this.request("/api/system/packages");
|
|
4526
|
+
}
|
|
3433
4527
|
};
|
|
3434
4528
|
|
|
3435
4529
|
// src/tools.ts
|