@mastra/client-js 0.0.0-remove-unused-import-20250909212718 → 0.0.0-roamin-openaivoice-speak-options-passing-20250926163614
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 +270 -3
- package/README.md +2 -6
- package/dist/client.d.ts +36 -27
- package/dist/client.d.ts.map +1 -1
- package/dist/index.cjs +379 -355
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +378 -356
- package/dist/index.js.map +1 -1
- package/dist/resources/agent-builder.d.ts +5 -6
- package/dist/resources/agent-builder.d.ts.map +1 -1
- package/dist/resources/agent.d.ts +48 -12
- package/dist/resources/agent.d.ts.map +1 -1
- package/dist/resources/index.d.ts +0 -2
- package/dist/resources/index.d.ts.map +1 -1
- package/dist/resources/mcp-tool.d.ts +2 -1
- package/dist/resources/mcp-tool.d.ts.map +1 -1
- package/dist/resources/observability.d.ts +10 -0
- package/dist/resources/observability.d.ts.map +1 -1
- package/dist/resources/tool.d.ts +2 -1
- package/dist/resources/tool.d.ts.map +1 -1
- package/dist/resources/vNextNetwork.d.ts +2 -1
- package/dist/resources/vNextNetwork.d.ts.map +1 -1
- package/dist/resources/vector.d.ts +5 -2
- package/dist/resources/vector.d.ts.map +1 -1
- package/dist/resources/workflow.d.ts +96 -11
- package/dist/resources/workflow.d.ts.map +1 -1
- package/dist/tools.d.ts +22 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/types.d.ts +51 -43
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/process-mastra-stream.d.ts +5 -1
- package/dist/utils/process-mastra-stream.d.ts.map +1 -1
- package/package.json +5 -6
- package/dist/resources/legacy-workflow.d.ts +0 -87
- package/dist/resources/legacy-workflow.d.ts.map +0 -1
- package/dist/resources/network.d.ts +0 -30
- package/dist/resources/network.d.ts.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -21,6 +21,20 @@ function parseClientRuntimeContext(runtimeContext$1) {
|
|
|
21
21
|
}
|
|
22
22
|
return void 0;
|
|
23
23
|
}
|
|
24
|
+
function base64RuntimeContext(runtimeContext) {
|
|
25
|
+
if (runtimeContext) {
|
|
26
|
+
return btoa(JSON.stringify(runtimeContext));
|
|
27
|
+
}
|
|
28
|
+
return void 0;
|
|
29
|
+
}
|
|
30
|
+
function runtimeContextQueryString(runtimeContext) {
|
|
31
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
32
|
+
if (!runtimeContextParam) return "";
|
|
33
|
+
const searchParams = new URLSearchParams();
|
|
34
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
35
|
+
const queryString = searchParams.toString();
|
|
36
|
+
return queryString ? `?${queryString}` : "";
|
|
37
|
+
}
|
|
24
38
|
function isZodType(value) {
|
|
25
39
|
return typeof value === "object" && value !== null && "_def" in value && "parse" in value && typeof value.parse === "function" && "safeParse" in value && typeof value.safeParse === "function";
|
|
26
40
|
}
|
|
@@ -32,7 +46,7 @@ function zodToJsonSchema(zodSchema) {
|
|
|
32
46
|
const fn = "toJSONSchema";
|
|
33
47
|
return zod.z[fn].call(zod.z, zodSchema);
|
|
34
48
|
}
|
|
35
|
-
return originalZodToJsonSchema__default.default(zodSchema, { $refStrategy: "
|
|
49
|
+
return originalZodToJsonSchema__default.default(zodSchema, { $refStrategy: "relative" });
|
|
36
50
|
}
|
|
37
51
|
|
|
38
52
|
// src/utils/process-client-tools.ts
|
|
@@ -65,7 +79,7 @@ function processClientTools(clientTools) {
|
|
|
65
79
|
}
|
|
66
80
|
|
|
67
81
|
// src/utils/process-mastra-stream.ts
|
|
68
|
-
async function
|
|
82
|
+
async function sharedProcessMastraStream({
|
|
69
83
|
stream,
|
|
70
84
|
onChunk
|
|
71
85
|
}) {
|
|
@@ -83,7 +97,7 @@ async function processMastraStream({
|
|
|
83
97
|
if (line.startsWith("data: ")) {
|
|
84
98
|
const data = line.slice(6);
|
|
85
99
|
if (data === "[DONE]") {
|
|
86
|
-
console.
|
|
100
|
+
console.info("\u{1F3C1} Stream finished");
|
|
87
101
|
return;
|
|
88
102
|
}
|
|
89
103
|
try {
|
|
@@ -99,6 +113,24 @@ async function processMastraStream({
|
|
|
99
113
|
reader.releaseLock();
|
|
100
114
|
}
|
|
101
115
|
}
|
|
116
|
+
async function processMastraNetworkStream({
|
|
117
|
+
stream,
|
|
118
|
+
onChunk
|
|
119
|
+
}) {
|
|
120
|
+
return sharedProcessMastraStream({
|
|
121
|
+
stream,
|
|
122
|
+
onChunk
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
async function processMastraStream({
|
|
126
|
+
stream,
|
|
127
|
+
onChunk
|
|
128
|
+
}) {
|
|
129
|
+
return sharedProcessMastraStream({
|
|
130
|
+
stream,
|
|
131
|
+
onChunk
|
|
132
|
+
});
|
|
133
|
+
}
|
|
102
134
|
|
|
103
135
|
// src/resources/base.ts
|
|
104
136
|
var BaseResource = class {
|
|
@@ -187,7 +219,9 @@ async function executeToolCallAndRespond({
|
|
|
187
219
|
resourceId,
|
|
188
220
|
threadId,
|
|
189
221
|
runtimeContext,
|
|
190
|
-
tracingContext: { currentSpan: void 0 }
|
|
222
|
+
tracingContext: { currentSpan: void 0 },
|
|
223
|
+
suspend: async () => {
|
|
224
|
+
}
|
|
191
225
|
},
|
|
192
226
|
{
|
|
193
227
|
messages: response.messages,
|
|
@@ -195,11 +229,7 @@ async function executeToolCallAndRespond({
|
|
|
195
229
|
}
|
|
196
230
|
);
|
|
197
231
|
const updatedMessages = [
|
|
198
|
-
|
|
199
|
-
role: "user",
|
|
200
|
-
content: params.messages
|
|
201
|
-
},
|
|
202
|
-
...response.response.messages,
|
|
232
|
+
...response.response.messages || [],
|
|
203
233
|
{
|
|
204
234
|
role: "tool",
|
|
205
235
|
content: [
|
|
@@ -261,17 +291,21 @@ var AgentVoice = class extends BaseResource {
|
|
|
261
291
|
}
|
|
262
292
|
/**
|
|
263
293
|
* Get available speakers for the agent's voice provider
|
|
294
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
295
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
264
296
|
* @returns Promise containing list of available speakers
|
|
265
297
|
*/
|
|
266
|
-
getSpeakers() {
|
|
267
|
-
return this.request(`/api/agents/${this.agentId}/voice/speakers`);
|
|
298
|
+
getSpeakers(runtimeContext) {
|
|
299
|
+
return this.request(`/api/agents/${this.agentId}/voice/speakers${runtimeContextQueryString(runtimeContext)}`);
|
|
268
300
|
}
|
|
269
301
|
/**
|
|
270
302
|
* Get the listener configuration for the agent's voice provider
|
|
303
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
304
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
271
305
|
* @returns Promise containing a check if the agent has listening capabilities
|
|
272
306
|
*/
|
|
273
|
-
getListener() {
|
|
274
|
-
return this.request(`/api/agents/${this.agentId}/voice/listener`);
|
|
307
|
+
getListener(runtimeContext) {
|
|
308
|
+
return this.request(`/api/agents/${this.agentId}/voice/listener${runtimeContextQueryString(runtimeContext)}`);
|
|
275
309
|
}
|
|
276
310
|
};
|
|
277
311
|
var Agent = class extends BaseResource {
|
|
@@ -283,14 +317,15 @@ var Agent = class extends BaseResource {
|
|
|
283
317
|
voice;
|
|
284
318
|
/**
|
|
285
319
|
* Retrieves details about the agent
|
|
320
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
286
321
|
* @returns Promise containing agent details including model and instructions
|
|
287
322
|
*/
|
|
288
|
-
details() {
|
|
289
|
-
return this.request(`/api/agents/${this.agentId}`);
|
|
323
|
+
details(runtimeContext) {
|
|
324
|
+
return this.request(`/api/agents/${this.agentId}${runtimeContextQueryString(runtimeContext)}`);
|
|
290
325
|
}
|
|
291
326
|
async generate(params) {
|
|
292
327
|
console.warn(
|
|
293
|
-
"Deprecation NOTICE:Generate method will switch to use generateVNext implementation September
|
|
328
|
+
"Deprecation NOTICE:Generate method will switch to use generateVNext implementation September 30th, 2025. Please use generateLegacy if you don't want to upgrade just yet."
|
|
294
329
|
);
|
|
295
330
|
return this.generateLegacy(params);
|
|
296
331
|
}
|
|
@@ -325,7 +360,9 @@ var Agent = class extends BaseResource {
|
|
|
325
360
|
resourceId,
|
|
326
361
|
threadId,
|
|
327
362
|
runtimeContext,
|
|
328
|
-
tracingContext: { currentSpan: void 0 }
|
|
363
|
+
tracingContext: { currentSpan: void 0 },
|
|
364
|
+
suspend: async () => {
|
|
365
|
+
}
|
|
329
366
|
},
|
|
330
367
|
{
|
|
331
368
|
messages: response.messages,
|
|
@@ -333,10 +370,6 @@ var Agent = class extends BaseResource {
|
|
|
333
370
|
}
|
|
334
371
|
);
|
|
335
372
|
const updatedMessages = [
|
|
336
|
-
{
|
|
337
|
-
role: "user",
|
|
338
|
-
content: params.messages
|
|
339
|
-
},
|
|
340
373
|
...response.response.messages,
|
|
341
374
|
{
|
|
342
375
|
role: "tool",
|
|
@@ -359,7 +392,16 @@ var Agent = class extends BaseResource {
|
|
|
359
392
|
}
|
|
360
393
|
return response;
|
|
361
394
|
}
|
|
362
|
-
async generateVNext(
|
|
395
|
+
async generateVNext(messagesOrParams, options) {
|
|
396
|
+
let params;
|
|
397
|
+
if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
|
|
398
|
+
params = messagesOrParams;
|
|
399
|
+
} else {
|
|
400
|
+
params = {
|
|
401
|
+
messages: messagesOrParams,
|
|
402
|
+
...options
|
|
403
|
+
};
|
|
404
|
+
}
|
|
363
405
|
const processedParams = {
|
|
364
406
|
...params,
|
|
365
407
|
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
@@ -660,7 +702,7 @@ var Agent = class extends BaseResource {
|
|
|
660
702
|
*/
|
|
661
703
|
async stream(params) {
|
|
662
704
|
console.warn(
|
|
663
|
-
"Deprecation NOTICE:\nStream method will switch to use streamVNext implementation September
|
|
705
|
+
"Deprecation NOTICE:\nStream method will switch to use streamVNext implementation September 30th, 2025. Please use streamLegacy if you don't want to upgrade just yet."
|
|
664
706
|
);
|
|
665
707
|
return this.streamLegacy(params);
|
|
666
708
|
}
|
|
@@ -1009,7 +1051,9 @@ var Agent = class extends BaseResource {
|
|
|
1009
1051
|
threadId: processedParams.threadId,
|
|
1010
1052
|
runtimeContext: processedParams.runtimeContext,
|
|
1011
1053
|
// TODO: Pass proper tracing context when client-js supports tracing
|
|
1012
|
-
tracingContext: { currentSpan: void 0 }
|
|
1054
|
+
tracingContext: { currentSpan: void 0 },
|
|
1055
|
+
suspend: async () => {
|
|
1056
|
+
}
|
|
1013
1057
|
},
|
|
1014
1058
|
{
|
|
1015
1059
|
messages: response.messages,
|
|
@@ -1035,9 +1079,7 @@ var Agent = class extends BaseResource {
|
|
|
1035
1079
|
toolInvocation.state = "result";
|
|
1036
1080
|
toolInvocation.result = result;
|
|
1037
1081
|
}
|
|
1038
|
-
const
|
|
1039
|
-
const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
|
|
1040
|
-
const updatedMessages = lastMessage != null ? [...messageArray, ...messages.filter((m) => m.id !== lastMessage.id), lastMessage] : [...messageArray, ...messages];
|
|
1082
|
+
const updatedMessages = lastMessage != null ? [...messages.filter((m) => m.id !== lastMessage.id), lastMessage] : [...messages];
|
|
1041
1083
|
this.processStreamResponse_vNext(
|
|
1042
1084
|
{
|
|
1043
1085
|
...processedParams,
|
|
@@ -1064,7 +1106,40 @@ var Agent = class extends BaseResource {
|
|
|
1064
1106
|
}
|
|
1065
1107
|
return response;
|
|
1066
1108
|
}
|
|
1067
|
-
async
|
|
1109
|
+
async network(params) {
|
|
1110
|
+
const response = await this.request(`/api/agents/${this.agentId}/network`, {
|
|
1111
|
+
method: "POST",
|
|
1112
|
+
body: params,
|
|
1113
|
+
stream: true
|
|
1114
|
+
});
|
|
1115
|
+
if (!response.body) {
|
|
1116
|
+
throw new Error("No response body");
|
|
1117
|
+
}
|
|
1118
|
+
const streamResponse = new Response(response.body, {
|
|
1119
|
+
status: response.status,
|
|
1120
|
+
statusText: response.statusText,
|
|
1121
|
+
headers: response.headers
|
|
1122
|
+
});
|
|
1123
|
+
streamResponse.processDataStream = async ({
|
|
1124
|
+
onChunk
|
|
1125
|
+
}) => {
|
|
1126
|
+
await processMastraNetworkStream({
|
|
1127
|
+
stream: streamResponse.body,
|
|
1128
|
+
onChunk
|
|
1129
|
+
});
|
|
1130
|
+
};
|
|
1131
|
+
return streamResponse;
|
|
1132
|
+
}
|
|
1133
|
+
async streamVNext(messagesOrParams, options) {
|
|
1134
|
+
let params;
|
|
1135
|
+
if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
|
|
1136
|
+
params = messagesOrParams;
|
|
1137
|
+
} else {
|
|
1138
|
+
params = {
|
|
1139
|
+
messages: messagesOrParams,
|
|
1140
|
+
...options
|
|
1141
|
+
};
|
|
1142
|
+
}
|
|
1068
1143
|
const processedParams = {
|
|
1069
1144
|
...params,
|
|
1070
1145
|
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
@@ -1140,7 +1215,9 @@ var Agent = class extends BaseResource {
|
|
|
1140
1215
|
threadId: processedParams.threadId,
|
|
1141
1216
|
runtimeContext: processedParams.runtimeContext,
|
|
1142
1217
|
// TODO: Pass proper tracing context when client-js supports tracing
|
|
1143
|
-
tracingContext: { currentSpan: void 0 }
|
|
1218
|
+
tracingContext: { currentSpan: void 0 },
|
|
1219
|
+
suspend: async () => {
|
|
1220
|
+
}
|
|
1144
1221
|
},
|
|
1145
1222
|
{
|
|
1146
1223
|
messages: response.messages,
|
|
@@ -1178,12 +1255,10 @@ var Agent = class extends BaseResource {
|
|
|
1178
1255
|
} finally {
|
|
1179
1256
|
writer.releaseLock();
|
|
1180
1257
|
}
|
|
1181
|
-
const originalMessages = processedParams.messages;
|
|
1182
|
-
const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
|
|
1183
1258
|
this.processStreamResponse(
|
|
1184
1259
|
{
|
|
1185
1260
|
...processedParams,
|
|
1186
|
-
messages: [...
|
|
1261
|
+
messages: [...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
|
|
1187
1262
|
},
|
|
1188
1263
|
writable
|
|
1189
1264
|
).catch((error) => {
|
|
@@ -1209,10 +1284,11 @@ var Agent = class extends BaseResource {
|
|
|
1209
1284
|
/**
|
|
1210
1285
|
* Gets details about a specific tool available to the agent
|
|
1211
1286
|
* @param toolId - ID of the tool to retrieve
|
|
1287
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1212
1288
|
* @returns Promise containing tool details
|
|
1213
1289
|
*/
|
|
1214
|
-
getTool(toolId) {
|
|
1215
|
-
return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
|
|
1290
|
+
getTool(toolId, runtimeContext) {
|
|
1291
|
+
return this.request(`/api/agents/${this.agentId}/tools/${toolId}${runtimeContextQueryString(runtimeContext)}`);
|
|
1216
1292
|
}
|
|
1217
1293
|
/**
|
|
1218
1294
|
* Executes a tool for the agent
|
|
@@ -1223,7 +1299,7 @@ var Agent = class extends BaseResource {
|
|
|
1223
1299
|
executeTool(toolId, params) {
|
|
1224
1300
|
const body = {
|
|
1225
1301
|
data: params.data,
|
|
1226
|
-
runtimeContext:
|
|
1302
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1227
1303
|
};
|
|
1228
1304
|
return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
|
|
1229
1305
|
method: "POST",
|
|
@@ -1232,17 +1308,19 @@ var Agent = class extends BaseResource {
|
|
|
1232
1308
|
}
|
|
1233
1309
|
/**
|
|
1234
1310
|
* Retrieves evaluation results for the agent
|
|
1311
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1235
1312
|
* @returns Promise containing agent evaluations
|
|
1236
1313
|
*/
|
|
1237
|
-
evals() {
|
|
1238
|
-
return this.request(`/api/agents/${this.agentId}/evals/ci`);
|
|
1314
|
+
evals(runtimeContext) {
|
|
1315
|
+
return this.request(`/api/agents/${this.agentId}/evals/ci${runtimeContextQueryString(runtimeContext)}`);
|
|
1239
1316
|
}
|
|
1240
1317
|
/**
|
|
1241
1318
|
* Retrieves live evaluation results for the agent
|
|
1319
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1242
1320
|
* @returns Promise containing live agent evaluations
|
|
1243
1321
|
*/
|
|
1244
|
-
liveEvals() {
|
|
1245
|
-
return this.request(`/api/agents/${this.agentId}/evals/live`);
|
|
1322
|
+
liveEvals(runtimeContext) {
|
|
1323
|
+
return this.request(`/api/agents/${this.agentId}/evals/live${runtimeContextQueryString(runtimeContext)}`);
|
|
1246
1324
|
}
|
|
1247
1325
|
/**
|
|
1248
1326
|
* Updates the model for the agent
|
|
@@ -1255,61 +1333,27 @@ var Agent = class extends BaseResource {
|
|
|
1255
1333
|
body: params
|
|
1256
1334
|
});
|
|
1257
1335
|
}
|
|
1258
|
-
};
|
|
1259
|
-
var Network = class extends BaseResource {
|
|
1260
|
-
constructor(options, networkId) {
|
|
1261
|
-
super(options);
|
|
1262
|
-
this.networkId = networkId;
|
|
1263
|
-
}
|
|
1264
1336
|
/**
|
|
1265
|
-
*
|
|
1266
|
-
* @
|
|
1267
|
-
|
|
1268
|
-
details() {
|
|
1269
|
-
return this.request(`/api/networks/${this.networkId}`);
|
|
1270
|
-
}
|
|
1271
|
-
/**
|
|
1272
|
-
* Generates a response from the agent
|
|
1273
|
-
* @param params - Generation parameters including prompt
|
|
1274
|
-
* @returns Promise containing the generated response
|
|
1337
|
+
* Updates the model for the agent in the model list
|
|
1338
|
+
* @param params - Parameters for updating the model
|
|
1339
|
+
* @returns Promise containing the updated model
|
|
1275
1340
|
*/
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
...params,
|
|
1279
|
-
output: zodToJsonSchema(params.output),
|
|
1280
|
-
experimental_output: zodToJsonSchema(params.experimental_output)
|
|
1281
|
-
};
|
|
1282
|
-
return this.request(`/api/networks/${this.networkId}/generate`, {
|
|
1341
|
+
updateModelInModelList({ modelConfigId, ...params }) {
|
|
1342
|
+
return this.request(`/api/agents/${this.agentId}/models/${modelConfigId}`, {
|
|
1283
1343
|
method: "POST",
|
|
1284
|
-
body:
|
|
1344
|
+
body: params
|
|
1285
1345
|
});
|
|
1286
1346
|
}
|
|
1287
1347
|
/**
|
|
1288
|
-
*
|
|
1289
|
-
* @param params -
|
|
1290
|
-
* @returns Promise containing the
|
|
1348
|
+
* Reorders the models for the agent
|
|
1349
|
+
* @param params - Parameters for reordering the model list
|
|
1350
|
+
* @returns Promise containing the updated model list
|
|
1291
1351
|
*/
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
...params,
|
|
1295
|
-
output: zodToJsonSchema(params.output),
|
|
1296
|
-
experimental_output: zodToJsonSchema(params.experimental_output)
|
|
1297
|
-
};
|
|
1298
|
-
const response = await this.request(`/api/networks/${this.networkId}/stream`, {
|
|
1352
|
+
reorderModelList(params) {
|
|
1353
|
+
return this.request(`/api/agents/${this.agentId}/models/reorder`, {
|
|
1299
1354
|
method: "POST",
|
|
1300
|
-
body:
|
|
1301
|
-
stream: true
|
|
1355
|
+
body: params
|
|
1302
1356
|
});
|
|
1303
|
-
if (!response.body) {
|
|
1304
|
-
throw new Error("No response body");
|
|
1305
|
-
}
|
|
1306
|
-
response.processDataStream = async (options = {}) => {
|
|
1307
|
-
await uiUtils.processDataStream({
|
|
1308
|
-
stream: response.body,
|
|
1309
|
-
...options
|
|
1310
|
-
});
|
|
1311
|
-
};
|
|
1312
|
-
return response;
|
|
1313
1357
|
}
|
|
1314
1358
|
};
|
|
1315
1359
|
|
|
@@ -1400,10 +1444,13 @@ var Vector = class extends BaseResource {
|
|
|
1400
1444
|
/**
|
|
1401
1445
|
* Retrieves details about a specific vector index
|
|
1402
1446
|
* @param indexName - Name of the index to get details for
|
|
1447
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1403
1448
|
* @returns Promise containing vector index details
|
|
1404
1449
|
*/
|
|
1405
|
-
details(indexName) {
|
|
1406
|
-
return this.request(
|
|
1450
|
+
details(indexName, runtimeContext) {
|
|
1451
|
+
return this.request(
|
|
1452
|
+
`/api/vector/${this.vectorName}/indexes/${indexName}${runtimeContextQueryString(runtimeContext)}`
|
|
1453
|
+
);
|
|
1407
1454
|
}
|
|
1408
1455
|
/**
|
|
1409
1456
|
* Deletes a vector index
|
|
@@ -1417,10 +1464,11 @@ var Vector = class extends BaseResource {
|
|
|
1417
1464
|
}
|
|
1418
1465
|
/**
|
|
1419
1466
|
* Retrieves a list of all available indexes
|
|
1467
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1420
1468
|
* @returns Promise containing array of index names
|
|
1421
1469
|
*/
|
|
1422
|
-
getIndexes() {
|
|
1423
|
-
return this.request(`/api/vector/${this.vectorName}/indexes`);
|
|
1470
|
+
getIndexes(runtimeContext) {
|
|
1471
|
+
return this.request(`/api/vector/${this.vectorName}/indexes${runtimeContextQueryString(runtimeContext)}`);
|
|
1424
1472
|
}
|
|
1425
1473
|
/**
|
|
1426
1474
|
* Creates a new vector index
|
|
@@ -1457,187 +1505,6 @@ var Vector = class extends BaseResource {
|
|
|
1457
1505
|
}
|
|
1458
1506
|
};
|
|
1459
1507
|
|
|
1460
|
-
// src/resources/legacy-workflow.ts
|
|
1461
|
-
var RECORD_SEPARATOR = "";
|
|
1462
|
-
var LegacyWorkflow = class extends BaseResource {
|
|
1463
|
-
constructor(options, workflowId) {
|
|
1464
|
-
super(options);
|
|
1465
|
-
this.workflowId = workflowId;
|
|
1466
|
-
}
|
|
1467
|
-
/**
|
|
1468
|
-
* Retrieves details about the legacy workflow
|
|
1469
|
-
* @returns Promise containing legacy workflow details including steps and graphs
|
|
1470
|
-
*/
|
|
1471
|
-
details() {
|
|
1472
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}`);
|
|
1473
|
-
}
|
|
1474
|
-
/**
|
|
1475
|
-
* Retrieves all runs for a legacy workflow
|
|
1476
|
-
* @param params - Parameters for filtering runs
|
|
1477
|
-
* @returns Promise containing legacy workflow runs array
|
|
1478
|
-
*/
|
|
1479
|
-
runs(params) {
|
|
1480
|
-
const searchParams = new URLSearchParams();
|
|
1481
|
-
if (params?.fromDate) {
|
|
1482
|
-
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
1483
|
-
}
|
|
1484
|
-
if (params?.toDate) {
|
|
1485
|
-
searchParams.set("toDate", params.toDate.toISOString());
|
|
1486
|
-
}
|
|
1487
|
-
if (params?.limit) {
|
|
1488
|
-
searchParams.set("limit", String(params.limit));
|
|
1489
|
-
}
|
|
1490
|
-
if (params?.offset) {
|
|
1491
|
-
searchParams.set("offset", String(params.offset));
|
|
1492
|
-
}
|
|
1493
|
-
if (params?.resourceId) {
|
|
1494
|
-
searchParams.set("resourceId", params.resourceId);
|
|
1495
|
-
}
|
|
1496
|
-
if (searchParams.size) {
|
|
1497
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/runs?${searchParams}`);
|
|
1498
|
-
} else {
|
|
1499
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/runs`);
|
|
1500
|
-
}
|
|
1501
|
-
}
|
|
1502
|
-
/**
|
|
1503
|
-
* Creates a new legacy workflow run
|
|
1504
|
-
* @returns Promise containing the generated run ID
|
|
1505
|
-
*/
|
|
1506
|
-
createRun(params) {
|
|
1507
|
-
const searchParams = new URLSearchParams();
|
|
1508
|
-
if (!!params?.runId) {
|
|
1509
|
-
searchParams.set("runId", params.runId);
|
|
1510
|
-
}
|
|
1511
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/create-run?${searchParams.toString()}`, {
|
|
1512
|
-
method: "POST"
|
|
1513
|
-
});
|
|
1514
|
-
}
|
|
1515
|
-
/**
|
|
1516
|
-
* Starts a legacy workflow run synchronously without waiting for the workflow to complete
|
|
1517
|
-
* @param params - Object containing the runId and triggerData
|
|
1518
|
-
* @returns Promise containing success message
|
|
1519
|
-
*/
|
|
1520
|
-
start(params) {
|
|
1521
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/start?runId=${params.runId}`, {
|
|
1522
|
-
method: "POST",
|
|
1523
|
-
body: params?.triggerData
|
|
1524
|
-
});
|
|
1525
|
-
}
|
|
1526
|
-
/**
|
|
1527
|
-
* Resumes a suspended legacy workflow step synchronously without waiting for the workflow to complete
|
|
1528
|
-
* @param stepId - ID of the step to resume
|
|
1529
|
-
* @param runId - ID of the legacy workflow run
|
|
1530
|
-
* @param context - Context to resume the legacy workflow with
|
|
1531
|
-
* @returns Promise containing the legacy workflow resume results
|
|
1532
|
-
*/
|
|
1533
|
-
resume({
|
|
1534
|
-
stepId,
|
|
1535
|
-
runId,
|
|
1536
|
-
context
|
|
1537
|
-
}) {
|
|
1538
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/resume?runId=${runId}`, {
|
|
1539
|
-
method: "POST",
|
|
1540
|
-
body: {
|
|
1541
|
-
stepId,
|
|
1542
|
-
context
|
|
1543
|
-
}
|
|
1544
|
-
});
|
|
1545
|
-
}
|
|
1546
|
-
/**
|
|
1547
|
-
* Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
|
|
1548
|
-
* @param params - Object containing the optional runId and triggerData
|
|
1549
|
-
* @returns Promise containing the workflow execution results
|
|
1550
|
-
*/
|
|
1551
|
-
startAsync(params) {
|
|
1552
|
-
const searchParams = new URLSearchParams();
|
|
1553
|
-
if (!!params?.runId) {
|
|
1554
|
-
searchParams.set("runId", params.runId);
|
|
1555
|
-
}
|
|
1556
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
1557
|
-
method: "POST",
|
|
1558
|
-
body: params?.triggerData
|
|
1559
|
-
});
|
|
1560
|
-
}
|
|
1561
|
-
/**
|
|
1562
|
-
* Resumes a suspended legacy workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
1563
|
-
* @param params - Object containing the runId, stepId, and context
|
|
1564
|
-
* @returns Promise containing the workflow resume results
|
|
1565
|
-
*/
|
|
1566
|
-
resumeAsync(params) {
|
|
1567
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
1568
|
-
method: "POST",
|
|
1569
|
-
body: {
|
|
1570
|
-
stepId: params.stepId,
|
|
1571
|
-
context: params.context
|
|
1572
|
-
}
|
|
1573
|
-
});
|
|
1574
|
-
}
|
|
1575
|
-
/**
|
|
1576
|
-
* Creates an async generator that processes a readable stream and yields records
|
|
1577
|
-
* separated by the Record Separator character (\x1E)
|
|
1578
|
-
*
|
|
1579
|
-
* @param stream - The readable stream to process
|
|
1580
|
-
* @returns An async generator that yields parsed records
|
|
1581
|
-
*/
|
|
1582
|
-
async *streamProcessor(stream) {
|
|
1583
|
-
const reader = stream.getReader();
|
|
1584
|
-
let doneReading = false;
|
|
1585
|
-
let buffer = "";
|
|
1586
|
-
try {
|
|
1587
|
-
while (!doneReading) {
|
|
1588
|
-
const { done, value } = await reader.read();
|
|
1589
|
-
doneReading = done;
|
|
1590
|
-
if (done && !value) continue;
|
|
1591
|
-
try {
|
|
1592
|
-
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
1593
|
-
const chunks = (buffer + decoded).split(RECORD_SEPARATOR);
|
|
1594
|
-
buffer = chunks.pop() || "";
|
|
1595
|
-
for (const chunk of chunks) {
|
|
1596
|
-
if (chunk) {
|
|
1597
|
-
if (typeof chunk === "string") {
|
|
1598
|
-
try {
|
|
1599
|
-
const parsedChunk = JSON.parse(chunk);
|
|
1600
|
-
yield parsedChunk;
|
|
1601
|
-
} catch {
|
|
1602
|
-
}
|
|
1603
|
-
}
|
|
1604
|
-
}
|
|
1605
|
-
}
|
|
1606
|
-
} catch {
|
|
1607
|
-
}
|
|
1608
|
-
}
|
|
1609
|
-
if (buffer) {
|
|
1610
|
-
try {
|
|
1611
|
-
yield JSON.parse(buffer);
|
|
1612
|
-
} catch {
|
|
1613
|
-
}
|
|
1614
|
-
}
|
|
1615
|
-
} finally {
|
|
1616
|
-
reader.cancel().catch(() => {
|
|
1617
|
-
});
|
|
1618
|
-
}
|
|
1619
|
-
}
|
|
1620
|
-
/**
|
|
1621
|
-
* Watches legacy workflow transitions in real-time
|
|
1622
|
-
* @param runId - Optional run ID to filter the watch stream
|
|
1623
|
-
* @returns AsyncGenerator that yields parsed records from the legacy workflow watch stream
|
|
1624
|
-
*/
|
|
1625
|
-
async watch({ runId }, onRecord) {
|
|
1626
|
-
const response = await this.request(`/api/workflows/legacy/${this.workflowId}/watch?runId=${runId}`, {
|
|
1627
|
-
stream: true
|
|
1628
|
-
});
|
|
1629
|
-
if (!response.ok) {
|
|
1630
|
-
throw new Error(`Failed to watch legacy workflow: ${response.statusText}`);
|
|
1631
|
-
}
|
|
1632
|
-
if (!response.body) {
|
|
1633
|
-
throw new Error("Response body is null");
|
|
1634
|
-
}
|
|
1635
|
-
for await (const record of this.streamProcessor(response.body)) {
|
|
1636
|
-
onRecord(record);
|
|
1637
|
-
}
|
|
1638
|
-
}
|
|
1639
|
-
};
|
|
1640
|
-
|
|
1641
1508
|
// src/resources/tool.ts
|
|
1642
1509
|
var Tool = class extends BaseResource {
|
|
1643
1510
|
constructor(options, toolId) {
|
|
@@ -1646,10 +1513,11 @@ var Tool = class extends BaseResource {
|
|
|
1646
1513
|
}
|
|
1647
1514
|
/**
|
|
1648
1515
|
* Retrieves details about the tool
|
|
1516
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1649
1517
|
* @returns Promise containing tool details including description and schemas
|
|
1650
1518
|
*/
|
|
1651
|
-
details() {
|
|
1652
|
-
return this.request(`/api/tools/${this.toolId}`);
|
|
1519
|
+
details(runtimeContext) {
|
|
1520
|
+
return this.request(`/api/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
|
|
1653
1521
|
}
|
|
1654
1522
|
/**
|
|
1655
1523
|
* Executes the tool with the provided parameters
|
|
@@ -1673,7 +1541,7 @@ var Tool = class extends BaseResource {
|
|
|
1673
1541
|
};
|
|
1674
1542
|
|
|
1675
1543
|
// src/resources/workflow.ts
|
|
1676
|
-
var
|
|
1544
|
+
var RECORD_SEPARATOR = "";
|
|
1677
1545
|
var Workflow = class extends BaseResource {
|
|
1678
1546
|
constructor(options, workflowId) {
|
|
1679
1547
|
super(options);
|
|
@@ -1697,7 +1565,7 @@ var Workflow = class extends BaseResource {
|
|
|
1697
1565
|
if (done && !value) continue;
|
|
1698
1566
|
try {
|
|
1699
1567
|
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
1700
|
-
const chunks = (buffer + decoded).split(
|
|
1568
|
+
const chunks = (buffer + decoded).split(RECORD_SEPARATOR);
|
|
1701
1569
|
buffer = chunks.pop() || "";
|
|
1702
1570
|
for (const chunk of chunks) {
|
|
1703
1571
|
if (chunk) {
|
|
@@ -1726,17 +1594,20 @@ var Workflow = class extends BaseResource {
|
|
|
1726
1594
|
}
|
|
1727
1595
|
/**
|
|
1728
1596
|
* Retrieves details about the workflow
|
|
1597
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1729
1598
|
* @returns Promise containing workflow details including steps and graphs
|
|
1730
1599
|
*/
|
|
1731
|
-
details() {
|
|
1732
|
-
return this.request(`/api/workflows/${this.workflowId}`);
|
|
1600
|
+
details(runtimeContext) {
|
|
1601
|
+
return this.request(`/api/workflows/${this.workflowId}${runtimeContextQueryString(runtimeContext)}`);
|
|
1733
1602
|
}
|
|
1734
1603
|
/**
|
|
1735
1604
|
* Retrieves all runs for a workflow
|
|
1736
1605
|
* @param params - Parameters for filtering runs
|
|
1606
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1737
1607
|
* @returns Promise containing workflow runs array
|
|
1738
1608
|
*/
|
|
1739
|
-
runs(params) {
|
|
1609
|
+
runs(params, runtimeContext) {
|
|
1610
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
1740
1611
|
const searchParams = new URLSearchParams();
|
|
1741
1612
|
if (params?.fromDate) {
|
|
1742
1613
|
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
@@ -1753,6 +1624,9 @@ var Workflow = class extends BaseResource {
|
|
|
1753
1624
|
if (params?.resourceId) {
|
|
1754
1625
|
searchParams.set("resourceId", params.resourceId);
|
|
1755
1626
|
}
|
|
1627
|
+
if (runtimeContextParam) {
|
|
1628
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
1629
|
+
}
|
|
1756
1630
|
if (searchParams.size) {
|
|
1757
1631
|
return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
|
|
1758
1632
|
} else {
|
|
@@ -1762,18 +1636,22 @@ var Workflow = class extends BaseResource {
|
|
|
1762
1636
|
/**
|
|
1763
1637
|
* Retrieves a specific workflow run by its ID
|
|
1764
1638
|
* @param runId - The ID of the workflow run to retrieve
|
|
1639
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1765
1640
|
* @returns Promise containing the workflow run details
|
|
1766
1641
|
*/
|
|
1767
|
-
runById(runId) {
|
|
1768
|
-
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}`);
|
|
1642
|
+
runById(runId, runtimeContext) {
|
|
1643
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}${runtimeContextQueryString(runtimeContext)}`);
|
|
1769
1644
|
}
|
|
1770
1645
|
/**
|
|
1771
1646
|
* Retrieves the execution result for a specific workflow run by its ID
|
|
1772
1647
|
* @param runId - The ID of the workflow run to retrieve the execution result for
|
|
1648
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1773
1649
|
* @returns Promise containing the workflow run execution result
|
|
1774
1650
|
*/
|
|
1775
|
-
runExecutionResult(runId) {
|
|
1776
|
-
return this.request(
|
|
1651
|
+
runExecutionResult(runId, runtimeContext) {
|
|
1652
|
+
return this.request(
|
|
1653
|
+
`/api/workflows/${this.workflowId}/runs/${runId}/execution-result${runtimeContextQueryString(runtimeContext)}`
|
|
1654
|
+
);
|
|
1777
1655
|
}
|
|
1778
1656
|
/**
|
|
1779
1657
|
* Cancels a specific workflow run by its ID
|
|
@@ -1796,27 +1674,61 @@ var Workflow = class extends BaseResource {
|
|
|
1796
1674
|
body: { event: params.event, data: params.data }
|
|
1797
1675
|
});
|
|
1798
1676
|
}
|
|
1677
|
+
/**
|
|
1678
|
+
* @deprecated Use createRunAsync() instead.
|
|
1679
|
+
* @throws {Error} Always throws an error directing users to use createRunAsync()
|
|
1680
|
+
*/
|
|
1681
|
+
async createRun(_params) {
|
|
1682
|
+
throw new Error(
|
|
1683
|
+
"createRun() has been deprecated. Please use createRunAsync() instead.\n\nMigration guide:\n Before: const run = workflow.createRun();\n After: const run = await workflow.createRunAsync();\n\nNote: createRunAsync() is an async method, so make sure your calling function is async."
|
|
1684
|
+
);
|
|
1685
|
+
}
|
|
1799
1686
|
/**
|
|
1800
1687
|
* Creates a new workflow run
|
|
1801
1688
|
* @param params - Optional object containing the optional runId
|
|
1802
|
-
* @returns Promise containing the runId of the created run
|
|
1689
|
+
* @returns Promise containing the runId of the created run with methods to control execution
|
|
1803
1690
|
*/
|
|
1804
|
-
|
|
1691
|
+
async createRunAsync(params) {
|
|
1805
1692
|
const searchParams = new URLSearchParams();
|
|
1806
1693
|
if (!!params?.runId) {
|
|
1807
1694
|
searchParams.set("runId", params.runId);
|
|
1808
1695
|
}
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1696
|
+
const res = await this.request(
|
|
1697
|
+
`/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`,
|
|
1698
|
+
{
|
|
1699
|
+
method: "POST"
|
|
1700
|
+
}
|
|
1701
|
+
);
|
|
1702
|
+
const runId = res.runId;
|
|
1703
|
+
return {
|
|
1704
|
+
runId,
|
|
1705
|
+
start: async (p) => {
|
|
1706
|
+
return this.start({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
|
|
1707
|
+
},
|
|
1708
|
+
startAsync: async (p) => {
|
|
1709
|
+
return this.startAsync({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
|
|
1710
|
+
},
|
|
1711
|
+
watch: async (onRecord) => {
|
|
1712
|
+
return this.watch({ runId }, onRecord);
|
|
1713
|
+
},
|
|
1714
|
+
stream: async (p) => {
|
|
1715
|
+
return this.stream({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
|
|
1716
|
+
},
|
|
1717
|
+
resume: async (p) => {
|
|
1718
|
+
return this.resume({ runId, step: p.step, resumeData: p.resumeData, runtimeContext: p.runtimeContext });
|
|
1719
|
+
},
|
|
1720
|
+
resumeAsync: async (p) => {
|
|
1721
|
+
return this.resumeAsync({ runId, step: p.step, resumeData: p.resumeData, runtimeContext: p.runtimeContext });
|
|
1722
|
+
},
|
|
1723
|
+
resumeStreamVNext: async (p) => {
|
|
1724
|
+
return this.resumeStreamVNext({
|
|
1725
|
+
runId,
|
|
1726
|
+
step: p.step,
|
|
1727
|
+
resumeData: p.resumeData,
|
|
1728
|
+
runtimeContext: p.runtimeContext
|
|
1729
|
+
});
|
|
1730
|
+
}
|
|
1731
|
+
};
|
|
1820
1732
|
}
|
|
1821
1733
|
/**
|
|
1822
1734
|
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
@@ -1844,7 +1756,6 @@ var Workflow = class extends BaseResource {
|
|
|
1844
1756
|
const runtimeContext = parseClientRuntimeContext(rest.runtimeContext);
|
|
1845
1757
|
return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
|
|
1846
1758
|
method: "POST",
|
|
1847
|
-
stream: true,
|
|
1848
1759
|
body: {
|
|
1849
1760
|
step,
|
|
1850
1761
|
resumeData,
|
|
@@ -1888,7 +1799,7 @@ var Workflow = class extends BaseResource {
|
|
|
1888
1799
|
}
|
|
1889
1800
|
);
|
|
1890
1801
|
if (!response.ok) {
|
|
1891
|
-
throw new Error(`Failed to stream
|
|
1802
|
+
throw new Error(`Failed to stream workflow: ${response.statusText}`);
|
|
1892
1803
|
}
|
|
1893
1804
|
if (!response.body) {
|
|
1894
1805
|
throw new Error("Response body is null");
|
|
@@ -1900,7 +1811,54 @@ var Workflow = class extends BaseResource {
|
|
|
1900
1811
|
async transform(chunk, controller) {
|
|
1901
1812
|
try {
|
|
1902
1813
|
const decoded = new TextDecoder().decode(chunk);
|
|
1903
|
-
const chunks = decoded.split(
|
|
1814
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
1815
|
+
for (const chunk2 of chunks) {
|
|
1816
|
+
if (chunk2) {
|
|
1817
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
1818
|
+
try {
|
|
1819
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
1820
|
+
controller.enqueue(parsedChunk);
|
|
1821
|
+
failedChunk = void 0;
|
|
1822
|
+
} catch {
|
|
1823
|
+
failedChunk = newChunk;
|
|
1824
|
+
}
|
|
1825
|
+
}
|
|
1826
|
+
}
|
|
1827
|
+
} catch {
|
|
1828
|
+
}
|
|
1829
|
+
}
|
|
1830
|
+
});
|
|
1831
|
+
return response.body.pipeThrough(transformStream);
|
|
1832
|
+
}
|
|
1833
|
+
/**
|
|
1834
|
+
* Observes workflow stream for a workflow run
|
|
1835
|
+
* @param params - Object containing the runId
|
|
1836
|
+
* @returns Promise containing the workflow execution results
|
|
1837
|
+
*/
|
|
1838
|
+
async observeStream(params) {
|
|
1839
|
+
const searchParams = new URLSearchParams();
|
|
1840
|
+
searchParams.set("runId", params.runId);
|
|
1841
|
+
const response = await this.request(
|
|
1842
|
+
`/api/workflows/${this.workflowId}/observe-stream?${searchParams.toString()}`,
|
|
1843
|
+
{
|
|
1844
|
+
method: "POST",
|
|
1845
|
+
stream: true
|
|
1846
|
+
}
|
|
1847
|
+
);
|
|
1848
|
+
if (!response.ok) {
|
|
1849
|
+
throw new Error(`Failed to observe workflow stream: ${response.statusText}`);
|
|
1850
|
+
}
|
|
1851
|
+
if (!response.body) {
|
|
1852
|
+
throw new Error("Response body is null");
|
|
1853
|
+
}
|
|
1854
|
+
let failedChunk = void 0;
|
|
1855
|
+
const transformStream = new TransformStream({
|
|
1856
|
+
start() {
|
|
1857
|
+
},
|
|
1858
|
+
async transform(chunk, controller) {
|
|
1859
|
+
try {
|
|
1860
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
1861
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
1904
1862
|
for (const chunk2 of chunks) {
|
|
1905
1863
|
if (chunk2) {
|
|
1906
1864
|
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
@@ -1934,7 +1892,7 @@ var Workflow = class extends BaseResource {
|
|
|
1934
1892
|
`/api/workflows/${this.workflowId}/streamVNext?${searchParams.toString()}`,
|
|
1935
1893
|
{
|
|
1936
1894
|
method: "POST",
|
|
1937
|
-
body: { inputData: params.inputData, runtimeContext },
|
|
1895
|
+
body: { inputData: params.inputData, runtimeContext, closeOnSuspend: params.closeOnSuspend },
|
|
1938
1896
|
stream: true
|
|
1939
1897
|
}
|
|
1940
1898
|
);
|
|
@@ -1951,7 +1909,7 @@ var Workflow = class extends BaseResource {
|
|
|
1951
1909
|
async transform(chunk, controller) {
|
|
1952
1910
|
try {
|
|
1953
1911
|
const decoded = new TextDecoder().decode(chunk);
|
|
1954
|
-
const chunks = decoded.split(
|
|
1912
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
1955
1913
|
for (const chunk2 of chunks) {
|
|
1956
1914
|
if (chunk2) {
|
|
1957
1915
|
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
@@ -1986,6 +1944,22 @@ var Workflow = class extends BaseResource {
|
|
|
1986
1944
|
}
|
|
1987
1945
|
});
|
|
1988
1946
|
}
|
|
1947
|
+
/**
|
|
1948
|
+
* Resumes a suspended workflow step that uses streamVNext asynchronously and returns a promise that resolves when the workflow is complete
|
|
1949
|
+
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
1950
|
+
* @returns Promise containing the workflow resume results
|
|
1951
|
+
*/
|
|
1952
|
+
resumeStreamVNext(params) {
|
|
1953
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1954
|
+
return this.request(`/api/workflows/${this.workflowId}/resume-stream?runId=${params.runId}`, {
|
|
1955
|
+
method: "POST",
|
|
1956
|
+
body: {
|
|
1957
|
+
step: params.step,
|
|
1958
|
+
resumeData: params.resumeData,
|
|
1959
|
+
runtimeContext
|
|
1960
|
+
}
|
|
1961
|
+
});
|
|
1962
|
+
}
|
|
1989
1963
|
/**
|
|
1990
1964
|
* Watches workflow transitions in real-time
|
|
1991
1965
|
* @param runId - Optional run ID to filter the watch stream
|
|
@@ -2022,7 +1996,7 @@ var Workflow = class extends BaseResource {
|
|
|
2022
1996
|
async start(controller) {
|
|
2023
1997
|
try {
|
|
2024
1998
|
for await (const record of records) {
|
|
2025
|
-
const json = JSON.stringify(record) +
|
|
1999
|
+
const json = JSON.stringify(record) + RECORD_SEPARATOR;
|
|
2026
2000
|
controller.enqueue(encoder.encode(json));
|
|
2027
2001
|
}
|
|
2028
2002
|
controller.close();
|
|
@@ -2120,10 +2094,11 @@ var MCPTool = class extends BaseResource {
|
|
|
2120
2094
|
}
|
|
2121
2095
|
/**
|
|
2122
2096
|
* Retrieves details about this specific tool from the MCP server.
|
|
2097
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2123
2098
|
* @returns Promise containing the tool's information (name, description, schema).
|
|
2124
2099
|
*/
|
|
2125
|
-
details() {
|
|
2126
|
-
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}`);
|
|
2100
|
+
details(runtimeContext) {
|
|
2101
|
+
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
|
|
2127
2102
|
}
|
|
2128
2103
|
/**
|
|
2129
2104
|
* Executes this specific tool on the MCP server.
|
|
@@ -2144,7 +2119,7 @@ var MCPTool = class extends BaseResource {
|
|
|
2144
2119
|
};
|
|
2145
2120
|
|
|
2146
2121
|
// src/resources/agent-builder.ts
|
|
2147
|
-
var
|
|
2122
|
+
var RECORD_SEPARATOR2 = "";
|
|
2148
2123
|
var AgentBuilder = class extends BaseResource {
|
|
2149
2124
|
constructor(options, actionId) {
|
|
2150
2125
|
super(options);
|
|
@@ -2179,11 +2154,20 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2179
2154
|
};
|
|
2180
2155
|
}
|
|
2181
2156
|
}
|
|
2157
|
+
/**
|
|
2158
|
+
* @deprecated Use createRunAsync() instead.
|
|
2159
|
+
* @throws {Error} Always throws an error directing users to use createRunAsync()
|
|
2160
|
+
*/
|
|
2161
|
+
async createRun(_params) {
|
|
2162
|
+
throw new Error(
|
|
2163
|
+
"createRun() has been deprecated. Please use createRunAsync() instead.\n\nMigration guide:\n Before: const run = agentBuilder.createRun();\n After: const run = await agentBuilder.createRunAsync();\n\nNote: createRunAsync() is an async method, so make sure your calling function is async."
|
|
2164
|
+
);
|
|
2165
|
+
}
|
|
2182
2166
|
/**
|
|
2183
2167
|
* Creates a new agent builder action run and returns the runId.
|
|
2184
2168
|
* This calls `/api/agent-builder/:actionId/create-run`.
|
|
2185
2169
|
*/
|
|
2186
|
-
async
|
|
2170
|
+
async createRunAsync(params) {
|
|
2187
2171
|
const searchParams = new URLSearchParams();
|
|
2188
2172
|
if (!!params?.runId) {
|
|
2189
2173
|
searchParams.set("runId", params.runId);
|
|
@@ -2193,14 +2177,6 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2193
2177
|
method: "POST"
|
|
2194
2178
|
});
|
|
2195
2179
|
}
|
|
2196
|
-
/**
|
|
2197
|
-
* Creates a new workflow run (alias for createRun)
|
|
2198
|
-
* @param params - Optional object containing the optional runId
|
|
2199
|
-
* @returns Promise containing the runId of the created run
|
|
2200
|
-
*/
|
|
2201
|
-
createRunAsync(params) {
|
|
2202
|
-
return this.createRun(params);
|
|
2203
|
-
}
|
|
2204
2180
|
/**
|
|
2205
2181
|
* Starts agent builder action asynchronously and waits for completion.
|
|
2206
2182
|
* This calls `/api/agent-builder/:actionId/start-async`.
|
|
@@ -2283,7 +2259,7 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2283
2259
|
if (done && !value) continue;
|
|
2284
2260
|
try {
|
|
2285
2261
|
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
2286
|
-
const chunks = (buffer + decoded).split(
|
|
2262
|
+
const chunks = (buffer + decoded).split(RECORD_SEPARATOR2);
|
|
2287
2263
|
buffer = chunks.pop() || "";
|
|
2288
2264
|
for (const chunk of chunks) {
|
|
2289
2265
|
if (chunk) {
|
|
@@ -2340,7 +2316,7 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2340
2316
|
async transform(chunk, controller) {
|
|
2341
2317
|
try {
|
|
2342
2318
|
const decoded = new TextDecoder().decode(chunk);
|
|
2343
|
-
const chunks = decoded.split(
|
|
2319
|
+
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
2344
2320
|
for (const chunk2 of chunks) {
|
|
2345
2321
|
if (chunk2) {
|
|
2346
2322
|
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
@@ -2389,7 +2365,7 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2389
2365
|
async transform(chunk, controller) {
|
|
2390
2366
|
try {
|
|
2391
2367
|
const decoded = new TextDecoder().decode(chunk);
|
|
2392
|
-
const chunks = decoded.split(
|
|
2368
|
+
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
2393
2369
|
for (const chunk2 of chunks) {
|
|
2394
2370
|
if (chunk2) {
|
|
2395
2371
|
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
@@ -2560,6 +2536,12 @@ var Observability = class extends BaseResource {
|
|
|
2560
2536
|
const queryString = searchParams.toString();
|
|
2561
2537
|
return this.request(`/api/observability/traces${queryString ? `?${queryString}` : ""}`);
|
|
2562
2538
|
}
|
|
2539
|
+
score(params) {
|
|
2540
|
+
return this.request(`/api/observability/traces/score`, {
|
|
2541
|
+
method: "POST",
|
|
2542
|
+
body: { ...params }
|
|
2543
|
+
});
|
|
2544
|
+
}
|
|
2563
2545
|
};
|
|
2564
2546
|
|
|
2565
2547
|
// src/resources/network-memory-thread.ts
|
|
@@ -2626,7 +2608,7 @@ var NetworkMemoryThread = class extends BaseResource {
|
|
|
2626
2608
|
};
|
|
2627
2609
|
|
|
2628
2610
|
// src/resources/vNextNetwork.ts
|
|
2629
|
-
var
|
|
2611
|
+
var RECORD_SEPARATOR3 = "";
|
|
2630
2612
|
var VNextNetwork = class extends BaseResource {
|
|
2631
2613
|
constructor(options, networkId) {
|
|
2632
2614
|
super(options);
|
|
@@ -2634,10 +2616,11 @@ var VNextNetwork = class extends BaseResource {
|
|
|
2634
2616
|
}
|
|
2635
2617
|
/**
|
|
2636
2618
|
* Retrieves details about the network
|
|
2619
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2637
2620
|
* @returns Promise containing vNext network details
|
|
2638
2621
|
*/
|
|
2639
|
-
details() {
|
|
2640
|
-
return this.request(`/api/networks/v-next/${this.networkId}`);
|
|
2622
|
+
details(runtimeContext) {
|
|
2623
|
+
return this.request(`/api/networks/v-next/${this.networkId}${runtimeContextQueryString(runtimeContext)}`);
|
|
2641
2624
|
}
|
|
2642
2625
|
/**
|
|
2643
2626
|
* Generates a response from the v-next network
|
|
@@ -2678,7 +2661,7 @@ var VNextNetwork = class extends BaseResource {
|
|
|
2678
2661
|
if (done && !value) continue;
|
|
2679
2662
|
try {
|
|
2680
2663
|
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
2681
|
-
const chunks = (buffer + decoded).split(
|
|
2664
|
+
const chunks = (buffer + decoded).split(RECORD_SEPARATOR3);
|
|
2682
2665
|
buffer = chunks.pop() || "";
|
|
2683
2666
|
for (const chunk of chunks) {
|
|
2684
2667
|
if (chunk) {
|
|
@@ -2772,10 +2755,17 @@ var MastraClient = class extends BaseResource {
|
|
|
2772
2755
|
}
|
|
2773
2756
|
/**
|
|
2774
2757
|
* Retrieves all available agents
|
|
2758
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2775
2759
|
* @returns Promise containing map of agent IDs to agent details
|
|
2776
2760
|
*/
|
|
2777
|
-
getAgents() {
|
|
2778
|
-
|
|
2761
|
+
getAgents(runtimeContext) {
|
|
2762
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
2763
|
+
const searchParams = new URLSearchParams();
|
|
2764
|
+
if (runtimeContextParam) {
|
|
2765
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
2766
|
+
}
|
|
2767
|
+
const queryString = searchParams.toString();
|
|
2768
|
+
return this.request(`/api/agents${queryString ? `?${queryString}` : ""}`);
|
|
2779
2769
|
}
|
|
2780
2770
|
/**
|
|
2781
2771
|
* Gets an agent instance by ID
|
|
@@ -2793,6 +2783,14 @@ var MastraClient = class extends BaseResource {
|
|
|
2793
2783
|
getMemoryThreads(params) {
|
|
2794
2784
|
return this.request(`/api/memory/threads?resourceid=${params.resourceId}&agentId=${params.agentId}`);
|
|
2795
2785
|
}
|
|
2786
|
+
/**
|
|
2787
|
+
* Retrieves memory config for a resource
|
|
2788
|
+
* @param params - Parameters containing the resource ID
|
|
2789
|
+
* @returns Promise containing array of memory threads
|
|
2790
|
+
*/
|
|
2791
|
+
getMemoryConfig(params) {
|
|
2792
|
+
return this.request(`/api/memory/config?agentId=${params.agentId}`);
|
|
2793
|
+
}
|
|
2796
2794
|
/**
|
|
2797
2795
|
* Creates a new memory thread
|
|
2798
2796
|
* @param params - Parameters for creating the memory thread
|
|
@@ -2809,6 +2807,24 @@ var MastraClient = class extends BaseResource {
|
|
|
2809
2807
|
getMemoryThread(threadId, agentId) {
|
|
2810
2808
|
return new MemoryThread(this.options, threadId, agentId);
|
|
2811
2809
|
}
|
|
2810
|
+
getThreadMessages(threadId, opts = {}) {
|
|
2811
|
+
let url = "";
|
|
2812
|
+
if (opts.agentId) {
|
|
2813
|
+
url = `/api/memory/threads/${threadId}/messages?agentId=${opts.agentId}`;
|
|
2814
|
+
} else if (opts.networkId) {
|
|
2815
|
+
url = `/api/memory/network/threads/${threadId}/messages?networkId=${opts.networkId}`;
|
|
2816
|
+
}
|
|
2817
|
+
return this.request(url);
|
|
2818
|
+
}
|
|
2819
|
+
deleteThread(threadId, opts = {}) {
|
|
2820
|
+
let url = "";
|
|
2821
|
+
if (opts.agentId) {
|
|
2822
|
+
url = `/api/memory/threads/${threadId}?agentId=${opts.agentId}`;
|
|
2823
|
+
} else if (opts.networkId) {
|
|
2824
|
+
url = `/api/memory/network/threads/${threadId}?networkId=${opts.networkId}`;
|
|
2825
|
+
}
|
|
2826
|
+
return this.request(url, { method: "DELETE" });
|
|
2827
|
+
}
|
|
2812
2828
|
/**
|
|
2813
2829
|
* Saves messages to memory
|
|
2814
2830
|
* @param params - Parameters containing messages to save
|
|
@@ -2871,10 +2887,17 @@ var MastraClient = class extends BaseResource {
|
|
|
2871
2887
|
}
|
|
2872
2888
|
/**
|
|
2873
2889
|
* Retrieves all available tools
|
|
2890
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2874
2891
|
* @returns Promise containing map of tool IDs to tool details
|
|
2875
2892
|
*/
|
|
2876
|
-
getTools() {
|
|
2877
|
-
|
|
2893
|
+
getTools(runtimeContext) {
|
|
2894
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
2895
|
+
const searchParams = new URLSearchParams();
|
|
2896
|
+
if (runtimeContextParam) {
|
|
2897
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
2898
|
+
}
|
|
2899
|
+
const queryString = searchParams.toString();
|
|
2900
|
+
return this.request(`/api/tools${queryString ? `?${queryString}` : ""}`);
|
|
2878
2901
|
}
|
|
2879
2902
|
/**
|
|
2880
2903
|
* Gets a tool instance by ID
|
|
@@ -2884,27 +2907,19 @@ var MastraClient = class extends BaseResource {
|
|
|
2884
2907
|
getTool(toolId) {
|
|
2885
2908
|
return new Tool(this.options, toolId);
|
|
2886
2909
|
}
|
|
2887
|
-
/**
|
|
2888
|
-
* Retrieves all available legacy workflows
|
|
2889
|
-
* @returns Promise containing map of legacy workflow IDs to legacy workflow details
|
|
2890
|
-
*/
|
|
2891
|
-
getLegacyWorkflows() {
|
|
2892
|
-
return this.request("/api/workflows/legacy");
|
|
2893
|
-
}
|
|
2894
|
-
/**
|
|
2895
|
-
* Gets a legacy workflow instance by ID
|
|
2896
|
-
* @param workflowId - ID of the legacy workflow to retrieve
|
|
2897
|
-
* @returns Legacy Workflow instance
|
|
2898
|
-
*/
|
|
2899
|
-
getLegacyWorkflow(workflowId) {
|
|
2900
|
-
return new LegacyWorkflow(this.options, workflowId);
|
|
2901
|
-
}
|
|
2902
2910
|
/**
|
|
2903
2911
|
* Retrieves all available workflows
|
|
2912
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2904
2913
|
* @returns Promise containing map of workflow IDs to workflow details
|
|
2905
2914
|
*/
|
|
2906
|
-
getWorkflows() {
|
|
2907
|
-
|
|
2915
|
+
getWorkflows(runtimeContext) {
|
|
2916
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
2917
|
+
const searchParams = new URLSearchParams();
|
|
2918
|
+
if (runtimeContextParam) {
|
|
2919
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
2920
|
+
}
|
|
2921
|
+
const queryString = searchParams.toString();
|
|
2922
|
+
return this.request(`/api/workflows${queryString ? `?${queryString}` : ""}`);
|
|
2908
2923
|
}
|
|
2909
2924
|
/**
|
|
2910
2925
|
* Gets a workflow instance by ID
|
|
@@ -3072,13 +3087,6 @@ var MastraClient = class extends BaseResource {
|
|
|
3072
3087
|
return this.request(`/api/telemetry`);
|
|
3073
3088
|
}
|
|
3074
3089
|
}
|
|
3075
|
-
/**
|
|
3076
|
-
* Retrieves all available networks
|
|
3077
|
-
* @returns Promise containing map of network IDs to network details
|
|
3078
|
-
*/
|
|
3079
|
-
getNetworks() {
|
|
3080
|
-
return this.request("/api/networks");
|
|
3081
|
-
}
|
|
3082
3090
|
/**
|
|
3083
3091
|
* Retrieves all available vNext networks
|
|
3084
3092
|
* @returns Promise containing map of vNext network IDs to vNext network details
|
|
@@ -3086,14 +3094,6 @@ var MastraClient = class extends BaseResource {
|
|
|
3086
3094
|
getVNextNetworks() {
|
|
3087
3095
|
return this.request("/api/networks/v-next");
|
|
3088
3096
|
}
|
|
3089
|
-
/**
|
|
3090
|
-
* Gets a network instance by ID
|
|
3091
|
-
* @param networkId - ID of the network to retrieve
|
|
3092
|
-
* @returns Network instance
|
|
3093
|
-
*/
|
|
3094
|
-
getNetwork(networkId) {
|
|
3095
|
-
return new Network(this.options, networkId);
|
|
3096
|
-
}
|
|
3097
3097
|
/**
|
|
3098
3098
|
* Gets a vNext network instance by ID
|
|
3099
3099
|
* @param networkId - ID of the vNext network to retrieve
|
|
@@ -3284,8 +3284,32 @@ var MastraClient = class extends BaseResource {
|
|
|
3284
3284
|
getAITraces(params) {
|
|
3285
3285
|
return this.observability.getTraces(params);
|
|
3286
3286
|
}
|
|
3287
|
+
score(params) {
|
|
3288
|
+
return this.observability.score(params);
|
|
3289
|
+
}
|
|
3287
3290
|
};
|
|
3288
3291
|
|
|
3292
|
+
// src/tools.ts
|
|
3293
|
+
var ClientTool = class {
|
|
3294
|
+
id;
|
|
3295
|
+
description;
|
|
3296
|
+
inputSchema;
|
|
3297
|
+
outputSchema;
|
|
3298
|
+
execute;
|
|
3299
|
+
constructor(opts) {
|
|
3300
|
+
this.id = opts.id;
|
|
3301
|
+
this.description = opts.description;
|
|
3302
|
+
this.inputSchema = opts.inputSchema;
|
|
3303
|
+
this.outputSchema = opts.outputSchema;
|
|
3304
|
+
this.execute = opts.execute;
|
|
3305
|
+
}
|
|
3306
|
+
};
|
|
3307
|
+
function createTool(opts) {
|
|
3308
|
+
return new ClientTool(opts);
|
|
3309
|
+
}
|
|
3310
|
+
|
|
3311
|
+
exports.ClientTool = ClientTool;
|
|
3289
3312
|
exports.MastraClient = MastraClient;
|
|
3313
|
+
exports.createTool = createTool;
|
|
3290
3314
|
//# sourceMappingURL=index.cjs.map
|
|
3291
3315
|
//# sourceMappingURL=index.cjs.map
|