@mastra/client-js 0.0.0-stream-vnext-usage-20250908171242 → 0.0.0-suspendRuntimeContextTypeFix-20250930142630
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 +298 -3
- package/README.md +2 -6
- package/dist/client.d.ts +37 -27
- package/dist/client.d.ts.map +1 -1
- package/dist/index.cjs +459 -366
- 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 +458 -367
- 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 +47 -11
- 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 +17 -1
- 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 +107 -12
- 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 +57 -42
- 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,12 +392,25 @@ 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,
|
|
366
408
|
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
367
|
-
clientTools: processClientTools(params.clientTools)
|
|
409
|
+
clientTools: processClientTools(params.clientTools),
|
|
410
|
+
structuredOutput: params.structuredOutput ? {
|
|
411
|
+
...params.structuredOutput,
|
|
412
|
+
schema: zodToJsonSchema(params.structuredOutput.schema)
|
|
413
|
+
} : void 0
|
|
368
414
|
};
|
|
369
415
|
const { runId, resourceId, threadId, runtimeContext } = processedParams;
|
|
370
416
|
const response = await this.request(
|
|
@@ -656,7 +702,7 @@ var Agent = class extends BaseResource {
|
|
|
656
702
|
*/
|
|
657
703
|
async stream(params) {
|
|
658
704
|
console.warn(
|
|
659
|
-
"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."
|
|
660
706
|
);
|
|
661
707
|
return this.streamLegacy(params);
|
|
662
708
|
}
|
|
@@ -994,9 +1040,11 @@ var Agent = class extends BaseResource {
|
|
|
994
1040
|
if (toolCall) {
|
|
995
1041
|
toolCalls.push(toolCall);
|
|
996
1042
|
}
|
|
1043
|
+
let shouldExecuteClientTool = false;
|
|
997
1044
|
for (const toolCall2 of toolCalls) {
|
|
998
1045
|
const clientTool = processedParams.clientTools?.[toolCall2.toolName];
|
|
999
1046
|
if (clientTool && clientTool.execute) {
|
|
1047
|
+
shouldExecuteClientTool = true;
|
|
1000
1048
|
const result = await clientTool.execute(
|
|
1001
1049
|
{
|
|
1002
1050
|
context: toolCall2?.args,
|
|
@@ -1005,7 +1053,9 @@ var Agent = class extends BaseResource {
|
|
|
1005
1053
|
threadId: processedParams.threadId,
|
|
1006
1054
|
runtimeContext: processedParams.runtimeContext,
|
|
1007
1055
|
// TODO: Pass proper tracing context when client-js supports tracing
|
|
1008
|
-
tracingContext: { currentSpan: void 0 }
|
|
1056
|
+
tracingContext: { currentSpan: void 0 },
|
|
1057
|
+
suspend: async () => {
|
|
1058
|
+
}
|
|
1009
1059
|
},
|
|
1010
1060
|
{
|
|
1011
1061
|
messages: response.messages,
|
|
@@ -1031,9 +1081,7 @@ var Agent = class extends BaseResource {
|
|
|
1031
1081
|
toolInvocation.state = "result";
|
|
1032
1082
|
toolInvocation.result = result;
|
|
1033
1083
|
}
|
|
1034
|
-
const
|
|
1035
|
-
const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
|
|
1036
|
-
const updatedMessages = lastMessage != null ? [...messageArray, ...messages.filter((m) => m.id !== lastMessage.id), lastMessage] : [...messageArray, ...messages];
|
|
1084
|
+
const updatedMessages = lastMessage != null ? [...messages.filter((m) => m.id !== lastMessage.id), lastMessage] : [...messages];
|
|
1037
1085
|
this.processStreamResponse_vNext(
|
|
1038
1086
|
{
|
|
1039
1087
|
...processedParams,
|
|
@@ -1045,6 +1093,11 @@ var Agent = class extends BaseResource {
|
|
|
1045
1093
|
});
|
|
1046
1094
|
}
|
|
1047
1095
|
}
|
|
1096
|
+
if (!shouldExecuteClientTool) {
|
|
1097
|
+
setTimeout(() => {
|
|
1098
|
+
writable.close();
|
|
1099
|
+
}, 0);
|
|
1100
|
+
}
|
|
1048
1101
|
} else {
|
|
1049
1102
|
setTimeout(() => {
|
|
1050
1103
|
writable.close();
|
|
@@ -1060,12 +1113,49 @@ var Agent = class extends BaseResource {
|
|
|
1060
1113
|
}
|
|
1061
1114
|
return response;
|
|
1062
1115
|
}
|
|
1063
|
-
async
|
|
1116
|
+
async network(params) {
|
|
1117
|
+
const response = await this.request(`/api/agents/${this.agentId}/network`, {
|
|
1118
|
+
method: "POST",
|
|
1119
|
+
body: params,
|
|
1120
|
+
stream: true
|
|
1121
|
+
});
|
|
1122
|
+
if (!response.body) {
|
|
1123
|
+
throw new Error("No response body");
|
|
1124
|
+
}
|
|
1125
|
+
const streamResponse = new Response(response.body, {
|
|
1126
|
+
status: response.status,
|
|
1127
|
+
statusText: response.statusText,
|
|
1128
|
+
headers: response.headers
|
|
1129
|
+
});
|
|
1130
|
+
streamResponse.processDataStream = async ({
|
|
1131
|
+
onChunk
|
|
1132
|
+
}) => {
|
|
1133
|
+
await processMastraNetworkStream({
|
|
1134
|
+
stream: streamResponse.body,
|
|
1135
|
+
onChunk
|
|
1136
|
+
});
|
|
1137
|
+
};
|
|
1138
|
+
return streamResponse;
|
|
1139
|
+
}
|
|
1140
|
+
async streamVNext(messagesOrParams, options) {
|
|
1141
|
+
let params;
|
|
1142
|
+
if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
|
|
1143
|
+
params = messagesOrParams;
|
|
1144
|
+
} else {
|
|
1145
|
+
params = {
|
|
1146
|
+
messages: messagesOrParams,
|
|
1147
|
+
...options
|
|
1148
|
+
};
|
|
1149
|
+
}
|
|
1064
1150
|
const processedParams = {
|
|
1065
1151
|
...params,
|
|
1066
1152
|
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
1067
1153
|
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
1068
|
-
clientTools: processClientTools(params.clientTools)
|
|
1154
|
+
clientTools: processClientTools(params.clientTools),
|
|
1155
|
+
structuredOutput: params.structuredOutput ? {
|
|
1156
|
+
...params.structuredOutput,
|
|
1157
|
+
schema: zodToJsonSchema(params.structuredOutput.schema)
|
|
1158
|
+
} : void 0
|
|
1069
1159
|
};
|
|
1070
1160
|
const { readable, writable } = new TransformStream();
|
|
1071
1161
|
const response = await this.processStreamResponse_vNext(processedParams, writable);
|
|
@@ -1132,7 +1222,9 @@ var Agent = class extends BaseResource {
|
|
|
1132
1222
|
threadId: processedParams.threadId,
|
|
1133
1223
|
runtimeContext: processedParams.runtimeContext,
|
|
1134
1224
|
// TODO: Pass proper tracing context when client-js supports tracing
|
|
1135
|
-
tracingContext: { currentSpan: void 0 }
|
|
1225
|
+
tracingContext: { currentSpan: void 0 },
|
|
1226
|
+
suspend: async () => {
|
|
1227
|
+
}
|
|
1136
1228
|
},
|
|
1137
1229
|
{
|
|
1138
1230
|
messages: response.messages,
|
|
@@ -1170,12 +1262,10 @@ var Agent = class extends BaseResource {
|
|
|
1170
1262
|
} finally {
|
|
1171
1263
|
writer.releaseLock();
|
|
1172
1264
|
}
|
|
1173
|
-
const originalMessages = processedParams.messages;
|
|
1174
|
-
const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
|
|
1175
1265
|
this.processStreamResponse(
|
|
1176
1266
|
{
|
|
1177
1267
|
...processedParams,
|
|
1178
|
-
messages: [...
|
|
1268
|
+
messages: [...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
|
|
1179
1269
|
},
|
|
1180
1270
|
writable
|
|
1181
1271
|
).catch((error) => {
|
|
@@ -1201,10 +1291,11 @@ var Agent = class extends BaseResource {
|
|
|
1201
1291
|
/**
|
|
1202
1292
|
* Gets details about a specific tool available to the agent
|
|
1203
1293
|
* @param toolId - ID of the tool to retrieve
|
|
1294
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1204
1295
|
* @returns Promise containing tool details
|
|
1205
1296
|
*/
|
|
1206
|
-
getTool(toolId) {
|
|
1207
|
-
return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
|
|
1297
|
+
getTool(toolId, runtimeContext) {
|
|
1298
|
+
return this.request(`/api/agents/${this.agentId}/tools/${toolId}${runtimeContextQueryString(runtimeContext)}`);
|
|
1208
1299
|
}
|
|
1209
1300
|
/**
|
|
1210
1301
|
* Executes a tool for the agent
|
|
@@ -1215,7 +1306,7 @@ var Agent = class extends BaseResource {
|
|
|
1215
1306
|
executeTool(toolId, params) {
|
|
1216
1307
|
const body = {
|
|
1217
1308
|
data: params.data,
|
|
1218
|
-
runtimeContext:
|
|
1309
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1219
1310
|
};
|
|
1220
1311
|
return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
|
|
1221
1312
|
method: "POST",
|
|
@@ -1224,17 +1315,19 @@ var Agent = class extends BaseResource {
|
|
|
1224
1315
|
}
|
|
1225
1316
|
/**
|
|
1226
1317
|
* Retrieves evaluation results for the agent
|
|
1318
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1227
1319
|
* @returns Promise containing agent evaluations
|
|
1228
1320
|
*/
|
|
1229
|
-
evals() {
|
|
1230
|
-
return this.request(`/api/agents/${this.agentId}/evals/ci`);
|
|
1321
|
+
evals(runtimeContext) {
|
|
1322
|
+
return this.request(`/api/agents/${this.agentId}/evals/ci${runtimeContextQueryString(runtimeContext)}`);
|
|
1231
1323
|
}
|
|
1232
1324
|
/**
|
|
1233
1325
|
* Retrieves live evaluation results for the agent
|
|
1326
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1234
1327
|
* @returns Promise containing live agent evaluations
|
|
1235
1328
|
*/
|
|
1236
|
-
liveEvals() {
|
|
1237
|
-
return this.request(`/api/agents/${this.agentId}/evals/live`);
|
|
1329
|
+
liveEvals(runtimeContext) {
|
|
1330
|
+
return this.request(`/api/agents/${this.agentId}/evals/live${runtimeContextQueryString(runtimeContext)}`);
|
|
1238
1331
|
}
|
|
1239
1332
|
/**
|
|
1240
1333
|
* Updates the model for the agent
|
|
@@ -1247,61 +1340,27 @@ var Agent = class extends BaseResource {
|
|
|
1247
1340
|
body: params
|
|
1248
1341
|
});
|
|
1249
1342
|
}
|
|
1250
|
-
};
|
|
1251
|
-
var Network = class extends BaseResource {
|
|
1252
|
-
constructor(options, networkId) {
|
|
1253
|
-
super(options);
|
|
1254
|
-
this.networkId = networkId;
|
|
1255
|
-
}
|
|
1256
1343
|
/**
|
|
1257
|
-
*
|
|
1258
|
-
* @
|
|
1259
|
-
|
|
1260
|
-
details() {
|
|
1261
|
-
return this.request(`/api/networks/${this.networkId}`);
|
|
1262
|
-
}
|
|
1263
|
-
/**
|
|
1264
|
-
* Generates a response from the agent
|
|
1265
|
-
* @param params - Generation parameters including prompt
|
|
1266
|
-
* @returns Promise containing the generated response
|
|
1344
|
+
* Updates the model for the agent in the model list
|
|
1345
|
+
* @param params - Parameters for updating the model
|
|
1346
|
+
* @returns Promise containing the updated model
|
|
1267
1347
|
*/
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
...params,
|
|
1271
|
-
output: zodToJsonSchema(params.output),
|
|
1272
|
-
experimental_output: zodToJsonSchema(params.experimental_output)
|
|
1273
|
-
};
|
|
1274
|
-
return this.request(`/api/networks/${this.networkId}/generate`, {
|
|
1348
|
+
updateModelInModelList({ modelConfigId, ...params }) {
|
|
1349
|
+
return this.request(`/api/agents/${this.agentId}/models/${modelConfigId}`, {
|
|
1275
1350
|
method: "POST",
|
|
1276
|
-
body:
|
|
1351
|
+
body: params
|
|
1277
1352
|
});
|
|
1278
1353
|
}
|
|
1279
1354
|
/**
|
|
1280
|
-
*
|
|
1281
|
-
* @param params -
|
|
1282
|
-
* @returns Promise containing the
|
|
1355
|
+
* Reorders the models for the agent
|
|
1356
|
+
* @param params - Parameters for reordering the model list
|
|
1357
|
+
* @returns Promise containing the updated model list
|
|
1283
1358
|
*/
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
...params,
|
|
1287
|
-
output: zodToJsonSchema(params.output),
|
|
1288
|
-
experimental_output: zodToJsonSchema(params.experimental_output)
|
|
1289
|
-
};
|
|
1290
|
-
const response = await this.request(`/api/networks/${this.networkId}/stream`, {
|
|
1359
|
+
reorderModelList(params) {
|
|
1360
|
+
return this.request(`/api/agents/${this.agentId}/models/reorder`, {
|
|
1291
1361
|
method: "POST",
|
|
1292
|
-
body:
|
|
1293
|
-
stream: true
|
|
1362
|
+
body: params
|
|
1294
1363
|
});
|
|
1295
|
-
if (!response.body) {
|
|
1296
|
-
throw new Error("No response body");
|
|
1297
|
-
}
|
|
1298
|
-
response.processDataStream = async (options = {}) => {
|
|
1299
|
-
await uiUtils.processDataStream({
|
|
1300
|
-
stream: response.body,
|
|
1301
|
-
...options
|
|
1302
|
-
});
|
|
1303
|
-
};
|
|
1304
|
-
return response;
|
|
1305
1364
|
}
|
|
1306
1365
|
};
|
|
1307
1366
|
|
|
@@ -1392,10 +1451,13 @@ var Vector = class extends BaseResource {
|
|
|
1392
1451
|
/**
|
|
1393
1452
|
* Retrieves details about a specific vector index
|
|
1394
1453
|
* @param indexName - Name of the index to get details for
|
|
1454
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1395
1455
|
* @returns Promise containing vector index details
|
|
1396
1456
|
*/
|
|
1397
|
-
details(indexName) {
|
|
1398
|
-
return this.request(
|
|
1457
|
+
details(indexName, runtimeContext) {
|
|
1458
|
+
return this.request(
|
|
1459
|
+
`/api/vector/${this.vectorName}/indexes/${indexName}${runtimeContextQueryString(runtimeContext)}`
|
|
1460
|
+
);
|
|
1399
1461
|
}
|
|
1400
1462
|
/**
|
|
1401
1463
|
* Deletes a vector index
|
|
@@ -1409,10 +1471,11 @@ var Vector = class extends BaseResource {
|
|
|
1409
1471
|
}
|
|
1410
1472
|
/**
|
|
1411
1473
|
* Retrieves a list of all available indexes
|
|
1474
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1412
1475
|
* @returns Promise containing array of index names
|
|
1413
1476
|
*/
|
|
1414
|
-
getIndexes() {
|
|
1415
|
-
return this.request(`/api/vector/${this.vectorName}/indexes`);
|
|
1477
|
+
getIndexes(runtimeContext) {
|
|
1478
|
+
return this.request(`/api/vector/${this.vectorName}/indexes${runtimeContextQueryString(runtimeContext)}`);
|
|
1416
1479
|
}
|
|
1417
1480
|
/**
|
|
1418
1481
|
* Creates a new vector index
|
|
@@ -1449,187 +1512,6 @@ var Vector = class extends BaseResource {
|
|
|
1449
1512
|
}
|
|
1450
1513
|
};
|
|
1451
1514
|
|
|
1452
|
-
// src/resources/legacy-workflow.ts
|
|
1453
|
-
var RECORD_SEPARATOR = "";
|
|
1454
|
-
var LegacyWorkflow = class extends BaseResource {
|
|
1455
|
-
constructor(options, workflowId) {
|
|
1456
|
-
super(options);
|
|
1457
|
-
this.workflowId = workflowId;
|
|
1458
|
-
}
|
|
1459
|
-
/**
|
|
1460
|
-
* Retrieves details about the legacy workflow
|
|
1461
|
-
* @returns Promise containing legacy workflow details including steps and graphs
|
|
1462
|
-
*/
|
|
1463
|
-
details() {
|
|
1464
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}`);
|
|
1465
|
-
}
|
|
1466
|
-
/**
|
|
1467
|
-
* Retrieves all runs for a legacy workflow
|
|
1468
|
-
* @param params - Parameters for filtering runs
|
|
1469
|
-
* @returns Promise containing legacy workflow runs array
|
|
1470
|
-
*/
|
|
1471
|
-
runs(params) {
|
|
1472
|
-
const searchParams = new URLSearchParams();
|
|
1473
|
-
if (params?.fromDate) {
|
|
1474
|
-
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
1475
|
-
}
|
|
1476
|
-
if (params?.toDate) {
|
|
1477
|
-
searchParams.set("toDate", params.toDate.toISOString());
|
|
1478
|
-
}
|
|
1479
|
-
if (params?.limit) {
|
|
1480
|
-
searchParams.set("limit", String(params.limit));
|
|
1481
|
-
}
|
|
1482
|
-
if (params?.offset) {
|
|
1483
|
-
searchParams.set("offset", String(params.offset));
|
|
1484
|
-
}
|
|
1485
|
-
if (params?.resourceId) {
|
|
1486
|
-
searchParams.set("resourceId", params.resourceId);
|
|
1487
|
-
}
|
|
1488
|
-
if (searchParams.size) {
|
|
1489
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/runs?${searchParams}`);
|
|
1490
|
-
} else {
|
|
1491
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/runs`);
|
|
1492
|
-
}
|
|
1493
|
-
}
|
|
1494
|
-
/**
|
|
1495
|
-
* Creates a new legacy workflow run
|
|
1496
|
-
* @returns Promise containing the generated run ID
|
|
1497
|
-
*/
|
|
1498
|
-
createRun(params) {
|
|
1499
|
-
const searchParams = new URLSearchParams();
|
|
1500
|
-
if (!!params?.runId) {
|
|
1501
|
-
searchParams.set("runId", params.runId);
|
|
1502
|
-
}
|
|
1503
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/create-run?${searchParams.toString()}`, {
|
|
1504
|
-
method: "POST"
|
|
1505
|
-
});
|
|
1506
|
-
}
|
|
1507
|
-
/**
|
|
1508
|
-
* Starts a legacy workflow run synchronously without waiting for the workflow to complete
|
|
1509
|
-
* @param params - Object containing the runId and triggerData
|
|
1510
|
-
* @returns Promise containing success message
|
|
1511
|
-
*/
|
|
1512
|
-
start(params) {
|
|
1513
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/start?runId=${params.runId}`, {
|
|
1514
|
-
method: "POST",
|
|
1515
|
-
body: params?.triggerData
|
|
1516
|
-
});
|
|
1517
|
-
}
|
|
1518
|
-
/**
|
|
1519
|
-
* Resumes a suspended legacy workflow step synchronously without waiting for the workflow to complete
|
|
1520
|
-
* @param stepId - ID of the step to resume
|
|
1521
|
-
* @param runId - ID of the legacy workflow run
|
|
1522
|
-
* @param context - Context to resume the legacy workflow with
|
|
1523
|
-
* @returns Promise containing the legacy workflow resume results
|
|
1524
|
-
*/
|
|
1525
|
-
resume({
|
|
1526
|
-
stepId,
|
|
1527
|
-
runId,
|
|
1528
|
-
context
|
|
1529
|
-
}) {
|
|
1530
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/resume?runId=${runId}`, {
|
|
1531
|
-
method: "POST",
|
|
1532
|
-
body: {
|
|
1533
|
-
stepId,
|
|
1534
|
-
context
|
|
1535
|
-
}
|
|
1536
|
-
});
|
|
1537
|
-
}
|
|
1538
|
-
/**
|
|
1539
|
-
* Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
|
|
1540
|
-
* @param params - Object containing the optional runId and triggerData
|
|
1541
|
-
* @returns Promise containing the workflow execution results
|
|
1542
|
-
*/
|
|
1543
|
-
startAsync(params) {
|
|
1544
|
-
const searchParams = new URLSearchParams();
|
|
1545
|
-
if (!!params?.runId) {
|
|
1546
|
-
searchParams.set("runId", params.runId);
|
|
1547
|
-
}
|
|
1548
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
1549
|
-
method: "POST",
|
|
1550
|
-
body: params?.triggerData
|
|
1551
|
-
});
|
|
1552
|
-
}
|
|
1553
|
-
/**
|
|
1554
|
-
* Resumes a suspended legacy workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
1555
|
-
* @param params - Object containing the runId, stepId, and context
|
|
1556
|
-
* @returns Promise containing the workflow resume results
|
|
1557
|
-
*/
|
|
1558
|
-
resumeAsync(params) {
|
|
1559
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
1560
|
-
method: "POST",
|
|
1561
|
-
body: {
|
|
1562
|
-
stepId: params.stepId,
|
|
1563
|
-
context: params.context
|
|
1564
|
-
}
|
|
1565
|
-
});
|
|
1566
|
-
}
|
|
1567
|
-
/**
|
|
1568
|
-
* Creates an async generator that processes a readable stream and yields records
|
|
1569
|
-
* separated by the Record Separator character (\x1E)
|
|
1570
|
-
*
|
|
1571
|
-
* @param stream - The readable stream to process
|
|
1572
|
-
* @returns An async generator that yields parsed records
|
|
1573
|
-
*/
|
|
1574
|
-
async *streamProcessor(stream) {
|
|
1575
|
-
const reader = stream.getReader();
|
|
1576
|
-
let doneReading = false;
|
|
1577
|
-
let buffer = "";
|
|
1578
|
-
try {
|
|
1579
|
-
while (!doneReading) {
|
|
1580
|
-
const { done, value } = await reader.read();
|
|
1581
|
-
doneReading = done;
|
|
1582
|
-
if (done && !value) continue;
|
|
1583
|
-
try {
|
|
1584
|
-
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
1585
|
-
const chunks = (buffer + decoded).split(RECORD_SEPARATOR);
|
|
1586
|
-
buffer = chunks.pop() || "";
|
|
1587
|
-
for (const chunk of chunks) {
|
|
1588
|
-
if (chunk) {
|
|
1589
|
-
if (typeof chunk === "string") {
|
|
1590
|
-
try {
|
|
1591
|
-
const parsedChunk = JSON.parse(chunk);
|
|
1592
|
-
yield parsedChunk;
|
|
1593
|
-
} catch {
|
|
1594
|
-
}
|
|
1595
|
-
}
|
|
1596
|
-
}
|
|
1597
|
-
}
|
|
1598
|
-
} catch {
|
|
1599
|
-
}
|
|
1600
|
-
}
|
|
1601
|
-
if (buffer) {
|
|
1602
|
-
try {
|
|
1603
|
-
yield JSON.parse(buffer);
|
|
1604
|
-
} catch {
|
|
1605
|
-
}
|
|
1606
|
-
}
|
|
1607
|
-
} finally {
|
|
1608
|
-
reader.cancel().catch(() => {
|
|
1609
|
-
});
|
|
1610
|
-
}
|
|
1611
|
-
}
|
|
1612
|
-
/**
|
|
1613
|
-
* Watches legacy workflow transitions in real-time
|
|
1614
|
-
* @param runId - Optional run ID to filter the watch stream
|
|
1615
|
-
* @returns AsyncGenerator that yields parsed records from the legacy workflow watch stream
|
|
1616
|
-
*/
|
|
1617
|
-
async watch({ runId }, onRecord) {
|
|
1618
|
-
const response = await this.request(`/api/workflows/legacy/${this.workflowId}/watch?runId=${runId}`, {
|
|
1619
|
-
stream: true
|
|
1620
|
-
});
|
|
1621
|
-
if (!response.ok) {
|
|
1622
|
-
throw new Error(`Failed to watch legacy workflow: ${response.statusText}`);
|
|
1623
|
-
}
|
|
1624
|
-
if (!response.body) {
|
|
1625
|
-
throw new Error("Response body is null");
|
|
1626
|
-
}
|
|
1627
|
-
for await (const record of this.streamProcessor(response.body)) {
|
|
1628
|
-
onRecord(record);
|
|
1629
|
-
}
|
|
1630
|
-
}
|
|
1631
|
-
};
|
|
1632
|
-
|
|
1633
1515
|
// src/resources/tool.ts
|
|
1634
1516
|
var Tool = class extends BaseResource {
|
|
1635
1517
|
constructor(options, toolId) {
|
|
@@ -1638,10 +1520,11 @@ var Tool = class extends BaseResource {
|
|
|
1638
1520
|
}
|
|
1639
1521
|
/**
|
|
1640
1522
|
* Retrieves details about the tool
|
|
1523
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1641
1524
|
* @returns Promise containing tool details including description and schemas
|
|
1642
1525
|
*/
|
|
1643
|
-
details() {
|
|
1644
|
-
return this.request(`/api/tools/${this.toolId}`);
|
|
1526
|
+
details(runtimeContext) {
|
|
1527
|
+
return this.request(`/api/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
|
|
1645
1528
|
}
|
|
1646
1529
|
/**
|
|
1647
1530
|
* Executes the tool with the provided parameters
|
|
@@ -1665,7 +1548,7 @@ var Tool = class extends BaseResource {
|
|
|
1665
1548
|
};
|
|
1666
1549
|
|
|
1667
1550
|
// src/resources/workflow.ts
|
|
1668
|
-
var
|
|
1551
|
+
var RECORD_SEPARATOR = "";
|
|
1669
1552
|
var Workflow = class extends BaseResource {
|
|
1670
1553
|
constructor(options, workflowId) {
|
|
1671
1554
|
super(options);
|
|
@@ -1689,7 +1572,7 @@ var Workflow = class extends BaseResource {
|
|
|
1689
1572
|
if (done && !value) continue;
|
|
1690
1573
|
try {
|
|
1691
1574
|
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
1692
|
-
const chunks = (buffer + decoded).split(
|
|
1575
|
+
const chunks = (buffer + decoded).split(RECORD_SEPARATOR);
|
|
1693
1576
|
buffer = chunks.pop() || "";
|
|
1694
1577
|
for (const chunk of chunks) {
|
|
1695
1578
|
if (chunk) {
|
|
@@ -1718,17 +1601,20 @@ var Workflow = class extends BaseResource {
|
|
|
1718
1601
|
}
|
|
1719
1602
|
/**
|
|
1720
1603
|
* Retrieves details about the workflow
|
|
1604
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1721
1605
|
* @returns Promise containing workflow details including steps and graphs
|
|
1722
1606
|
*/
|
|
1723
|
-
details() {
|
|
1724
|
-
return this.request(`/api/workflows/${this.workflowId}`);
|
|
1607
|
+
details(runtimeContext) {
|
|
1608
|
+
return this.request(`/api/workflows/${this.workflowId}${runtimeContextQueryString(runtimeContext)}`);
|
|
1725
1609
|
}
|
|
1726
1610
|
/**
|
|
1727
1611
|
* Retrieves all runs for a workflow
|
|
1728
1612
|
* @param params - Parameters for filtering runs
|
|
1613
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1729
1614
|
* @returns Promise containing workflow runs array
|
|
1730
1615
|
*/
|
|
1731
|
-
runs(params) {
|
|
1616
|
+
runs(params, runtimeContext) {
|
|
1617
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
1732
1618
|
const searchParams = new URLSearchParams();
|
|
1733
1619
|
if (params?.fromDate) {
|
|
1734
1620
|
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
@@ -1745,6 +1631,9 @@ var Workflow = class extends BaseResource {
|
|
|
1745
1631
|
if (params?.resourceId) {
|
|
1746
1632
|
searchParams.set("resourceId", params.resourceId);
|
|
1747
1633
|
}
|
|
1634
|
+
if (runtimeContextParam) {
|
|
1635
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
1636
|
+
}
|
|
1748
1637
|
if (searchParams.size) {
|
|
1749
1638
|
return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
|
|
1750
1639
|
} else {
|
|
@@ -1754,18 +1643,22 @@ var Workflow = class extends BaseResource {
|
|
|
1754
1643
|
/**
|
|
1755
1644
|
* Retrieves a specific workflow run by its ID
|
|
1756
1645
|
* @param runId - The ID of the workflow run to retrieve
|
|
1646
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1757
1647
|
* @returns Promise containing the workflow run details
|
|
1758
1648
|
*/
|
|
1759
|
-
runById(runId) {
|
|
1760
|
-
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}`);
|
|
1649
|
+
runById(runId, runtimeContext) {
|
|
1650
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}${runtimeContextQueryString(runtimeContext)}`);
|
|
1761
1651
|
}
|
|
1762
1652
|
/**
|
|
1763
1653
|
* Retrieves the execution result for a specific workflow run by its ID
|
|
1764
1654
|
* @param runId - The ID of the workflow run to retrieve the execution result for
|
|
1655
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1765
1656
|
* @returns Promise containing the workflow run execution result
|
|
1766
1657
|
*/
|
|
1767
|
-
runExecutionResult(runId) {
|
|
1768
|
-
return this.request(
|
|
1658
|
+
runExecutionResult(runId, runtimeContext) {
|
|
1659
|
+
return this.request(
|
|
1660
|
+
`/api/workflows/${this.workflowId}/runs/${runId}/execution-result${runtimeContextQueryString(runtimeContext)}`
|
|
1661
|
+
);
|
|
1769
1662
|
}
|
|
1770
1663
|
/**
|
|
1771
1664
|
* Cancels a specific workflow run by its ID
|
|
@@ -1788,27 +1681,83 @@ var Workflow = class extends BaseResource {
|
|
|
1788
1681
|
body: { event: params.event, data: params.data }
|
|
1789
1682
|
});
|
|
1790
1683
|
}
|
|
1684
|
+
/**
|
|
1685
|
+
* @deprecated Use createRunAsync() instead.
|
|
1686
|
+
* @throws {Error} Always throws an error directing users to use createRunAsync()
|
|
1687
|
+
*/
|
|
1688
|
+
async createRun(_params) {
|
|
1689
|
+
throw new Error(
|
|
1690
|
+
"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."
|
|
1691
|
+
);
|
|
1692
|
+
}
|
|
1791
1693
|
/**
|
|
1792
1694
|
* Creates a new workflow run
|
|
1793
1695
|
* @param params - Optional object containing the optional runId
|
|
1794
|
-
* @returns Promise containing the runId of the created run
|
|
1696
|
+
* @returns Promise containing the runId of the created run with methods to control execution
|
|
1795
1697
|
*/
|
|
1796
|
-
|
|
1698
|
+
async createRunAsync(params) {
|
|
1797
1699
|
const searchParams = new URLSearchParams();
|
|
1798
1700
|
if (!!params?.runId) {
|
|
1799
1701
|
searchParams.set("runId", params.runId);
|
|
1800
1702
|
}
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1703
|
+
const res = await this.request(
|
|
1704
|
+
`/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`,
|
|
1705
|
+
{
|
|
1706
|
+
method: "POST"
|
|
1707
|
+
}
|
|
1708
|
+
);
|
|
1709
|
+
const runId = res.runId;
|
|
1710
|
+
return {
|
|
1711
|
+
runId,
|
|
1712
|
+
start: async (p) => {
|
|
1713
|
+
return this.start({
|
|
1714
|
+
runId,
|
|
1715
|
+
inputData: p.inputData,
|
|
1716
|
+
runtimeContext: p.runtimeContext,
|
|
1717
|
+
tracingOptions: p.tracingOptions
|
|
1718
|
+
});
|
|
1719
|
+
},
|
|
1720
|
+
startAsync: async (p) => {
|
|
1721
|
+
return this.startAsync({
|
|
1722
|
+
runId,
|
|
1723
|
+
inputData: p.inputData,
|
|
1724
|
+
runtimeContext: p.runtimeContext,
|
|
1725
|
+
tracingOptions: p.tracingOptions
|
|
1726
|
+
});
|
|
1727
|
+
},
|
|
1728
|
+
watch: async (onRecord) => {
|
|
1729
|
+
return this.watch({ runId }, onRecord);
|
|
1730
|
+
},
|
|
1731
|
+
stream: async (p) => {
|
|
1732
|
+
return this.stream({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
|
|
1733
|
+
},
|
|
1734
|
+
resume: async (p) => {
|
|
1735
|
+
return this.resume({
|
|
1736
|
+
runId,
|
|
1737
|
+
step: p.step,
|
|
1738
|
+
resumeData: p.resumeData,
|
|
1739
|
+
runtimeContext: p.runtimeContext,
|
|
1740
|
+
tracingOptions: p.tracingOptions
|
|
1741
|
+
});
|
|
1742
|
+
},
|
|
1743
|
+
resumeAsync: async (p) => {
|
|
1744
|
+
return this.resumeAsync({
|
|
1745
|
+
runId,
|
|
1746
|
+
step: p.step,
|
|
1747
|
+
resumeData: p.resumeData,
|
|
1748
|
+
runtimeContext: p.runtimeContext,
|
|
1749
|
+
tracingOptions: p.tracingOptions
|
|
1750
|
+
});
|
|
1751
|
+
},
|
|
1752
|
+
resumeStreamVNext: async (p) => {
|
|
1753
|
+
return this.resumeStreamVNext({
|
|
1754
|
+
runId,
|
|
1755
|
+
step: p.step,
|
|
1756
|
+
resumeData: p.resumeData,
|
|
1757
|
+
runtimeContext: p.runtimeContext
|
|
1758
|
+
});
|
|
1759
|
+
}
|
|
1760
|
+
};
|
|
1812
1761
|
}
|
|
1813
1762
|
/**
|
|
1814
1763
|
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
@@ -1819,7 +1768,7 @@ var Workflow = class extends BaseResource {
|
|
|
1819
1768
|
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1820
1769
|
return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
|
|
1821
1770
|
method: "POST",
|
|
1822
|
-
body: { inputData: params?.inputData, runtimeContext }
|
|
1771
|
+
body: { inputData: params?.inputData, runtimeContext, tracingOptions: params.tracingOptions }
|
|
1823
1772
|
});
|
|
1824
1773
|
}
|
|
1825
1774
|
/**
|
|
@@ -1831,16 +1780,17 @@ var Workflow = class extends BaseResource {
|
|
|
1831
1780
|
step,
|
|
1832
1781
|
runId,
|
|
1833
1782
|
resumeData,
|
|
1783
|
+
tracingOptions,
|
|
1834
1784
|
...rest
|
|
1835
1785
|
}) {
|
|
1836
1786
|
const runtimeContext = parseClientRuntimeContext(rest.runtimeContext);
|
|
1837
1787
|
return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
|
|
1838
1788
|
method: "POST",
|
|
1839
|
-
stream: true,
|
|
1840
1789
|
body: {
|
|
1841
1790
|
step,
|
|
1842
1791
|
resumeData,
|
|
1843
|
-
runtimeContext
|
|
1792
|
+
runtimeContext,
|
|
1793
|
+
tracingOptions
|
|
1844
1794
|
}
|
|
1845
1795
|
});
|
|
1846
1796
|
}
|
|
@@ -1857,7 +1807,7 @@ var Workflow = class extends BaseResource {
|
|
|
1857
1807
|
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1858
1808
|
return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
1859
1809
|
method: "POST",
|
|
1860
|
-
body: { inputData: params.inputData, runtimeContext }
|
|
1810
|
+
body: { inputData: params.inputData, runtimeContext, tracingOptions: params.tracingOptions }
|
|
1861
1811
|
});
|
|
1862
1812
|
}
|
|
1863
1813
|
/**
|
|
@@ -1880,7 +1830,7 @@ var Workflow = class extends BaseResource {
|
|
|
1880
1830
|
}
|
|
1881
1831
|
);
|
|
1882
1832
|
if (!response.ok) {
|
|
1883
|
-
throw new Error(`Failed to stream
|
|
1833
|
+
throw new Error(`Failed to stream workflow: ${response.statusText}`);
|
|
1884
1834
|
}
|
|
1885
1835
|
if (!response.body) {
|
|
1886
1836
|
throw new Error("Response body is null");
|
|
@@ -1892,7 +1842,54 @@ var Workflow = class extends BaseResource {
|
|
|
1892
1842
|
async transform(chunk, controller) {
|
|
1893
1843
|
try {
|
|
1894
1844
|
const decoded = new TextDecoder().decode(chunk);
|
|
1895
|
-
const chunks = decoded.split(
|
|
1845
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
1846
|
+
for (const chunk2 of chunks) {
|
|
1847
|
+
if (chunk2) {
|
|
1848
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
1849
|
+
try {
|
|
1850
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
1851
|
+
controller.enqueue(parsedChunk);
|
|
1852
|
+
failedChunk = void 0;
|
|
1853
|
+
} catch {
|
|
1854
|
+
failedChunk = newChunk;
|
|
1855
|
+
}
|
|
1856
|
+
}
|
|
1857
|
+
}
|
|
1858
|
+
} catch {
|
|
1859
|
+
}
|
|
1860
|
+
}
|
|
1861
|
+
});
|
|
1862
|
+
return response.body.pipeThrough(transformStream);
|
|
1863
|
+
}
|
|
1864
|
+
/**
|
|
1865
|
+
* Observes workflow stream for a workflow run
|
|
1866
|
+
* @param params - Object containing the runId
|
|
1867
|
+
* @returns Promise containing the workflow execution results
|
|
1868
|
+
*/
|
|
1869
|
+
async observeStream(params) {
|
|
1870
|
+
const searchParams = new URLSearchParams();
|
|
1871
|
+
searchParams.set("runId", params.runId);
|
|
1872
|
+
const response = await this.request(
|
|
1873
|
+
`/api/workflows/${this.workflowId}/observe-stream?${searchParams.toString()}`,
|
|
1874
|
+
{
|
|
1875
|
+
method: "POST",
|
|
1876
|
+
stream: true
|
|
1877
|
+
}
|
|
1878
|
+
);
|
|
1879
|
+
if (!response.ok) {
|
|
1880
|
+
throw new Error(`Failed to observe workflow stream: ${response.statusText}`);
|
|
1881
|
+
}
|
|
1882
|
+
if (!response.body) {
|
|
1883
|
+
throw new Error("Response body is null");
|
|
1884
|
+
}
|
|
1885
|
+
let failedChunk = void 0;
|
|
1886
|
+
const transformStream = new TransformStream({
|
|
1887
|
+
start() {
|
|
1888
|
+
},
|
|
1889
|
+
async transform(chunk, controller) {
|
|
1890
|
+
try {
|
|
1891
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
1892
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
1896
1893
|
for (const chunk2 of chunks) {
|
|
1897
1894
|
if (chunk2) {
|
|
1898
1895
|
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
@@ -1926,7 +1923,7 @@ var Workflow = class extends BaseResource {
|
|
|
1926
1923
|
`/api/workflows/${this.workflowId}/streamVNext?${searchParams.toString()}`,
|
|
1927
1924
|
{
|
|
1928
1925
|
method: "POST",
|
|
1929
|
-
body: { inputData: params.inputData, runtimeContext },
|
|
1926
|
+
body: { inputData: params.inputData, runtimeContext, closeOnSuspend: params.closeOnSuspend },
|
|
1930
1927
|
stream: true
|
|
1931
1928
|
}
|
|
1932
1929
|
);
|
|
@@ -1943,7 +1940,7 @@ var Workflow = class extends BaseResource {
|
|
|
1943
1940
|
async transform(chunk, controller) {
|
|
1944
1941
|
try {
|
|
1945
1942
|
const decoded = new TextDecoder().decode(chunk);
|
|
1946
|
-
const chunks = decoded.split(
|
|
1943
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
1947
1944
|
for (const chunk2 of chunks) {
|
|
1948
1945
|
if (chunk2) {
|
|
1949
1946
|
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
@@ -1974,7 +1971,25 @@ var Workflow = class extends BaseResource {
|
|
|
1974
1971
|
body: {
|
|
1975
1972
|
step: params.step,
|
|
1976
1973
|
resumeData: params.resumeData,
|
|
1977
|
-
runtimeContext
|
|
1974
|
+
runtimeContext,
|
|
1975
|
+
tracingOptions: params.tracingOptions
|
|
1976
|
+
}
|
|
1977
|
+
});
|
|
1978
|
+
}
|
|
1979
|
+
/**
|
|
1980
|
+
* Resumes a suspended workflow step that uses streamVNext asynchronously and returns a promise that resolves when the workflow is complete
|
|
1981
|
+
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
1982
|
+
* @returns Promise containing the workflow resume results
|
|
1983
|
+
*/
|
|
1984
|
+
resumeStreamVNext(params) {
|
|
1985
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1986
|
+
return this.request(`/api/workflows/${this.workflowId}/resume-stream?runId=${params.runId}`, {
|
|
1987
|
+
method: "POST",
|
|
1988
|
+
body: {
|
|
1989
|
+
step: params.step,
|
|
1990
|
+
resumeData: params.resumeData,
|
|
1991
|
+
runtimeContext,
|
|
1992
|
+
tracingOptions: params.tracingOptions
|
|
1978
1993
|
}
|
|
1979
1994
|
});
|
|
1980
1995
|
}
|
|
@@ -2014,7 +2029,7 @@ var Workflow = class extends BaseResource {
|
|
|
2014
2029
|
async start(controller) {
|
|
2015
2030
|
try {
|
|
2016
2031
|
for await (const record of records) {
|
|
2017
|
-
const json = JSON.stringify(record) +
|
|
2032
|
+
const json = JSON.stringify(record) + RECORD_SEPARATOR;
|
|
2018
2033
|
controller.enqueue(encoder.encode(json));
|
|
2019
2034
|
}
|
|
2020
2035
|
controller.close();
|
|
@@ -2112,10 +2127,11 @@ var MCPTool = class extends BaseResource {
|
|
|
2112
2127
|
}
|
|
2113
2128
|
/**
|
|
2114
2129
|
* Retrieves details about this specific tool from the MCP server.
|
|
2130
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2115
2131
|
* @returns Promise containing the tool's information (name, description, schema).
|
|
2116
2132
|
*/
|
|
2117
|
-
details() {
|
|
2118
|
-
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}`);
|
|
2133
|
+
details(runtimeContext) {
|
|
2134
|
+
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
|
|
2119
2135
|
}
|
|
2120
2136
|
/**
|
|
2121
2137
|
* Executes this specific tool on the MCP server.
|
|
@@ -2136,7 +2152,7 @@ var MCPTool = class extends BaseResource {
|
|
|
2136
2152
|
};
|
|
2137
2153
|
|
|
2138
2154
|
// src/resources/agent-builder.ts
|
|
2139
|
-
var
|
|
2155
|
+
var RECORD_SEPARATOR2 = "";
|
|
2140
2156
|
var AgentBuilder = class extends BaseResource {
|
|
2141
2157
|
constructor(options, actionId) {
|
|
2142
2158
|
super(options);
|
|
@@ -2171,11 +2187,20 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2171
2187
|
};
|
|
2172
2188
|
}
|
|
2173
2189
|
}
|
|
2190
|
+
/**
|
|
2191
|
+
* @deprecated Use createRunAsync() instead.
|
|
2192
|
+
* @throws {Error} Always throws an error directing users to use createRunAsync()
|
|
2193
|
+
*/
|
|
2194
|
+
async createRun(_params) {
|
|
2195
|
+
throw new Error(
|
|
2196
|
+
"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."
|
|
2197
|
+
);
|
|
2198
|
+
}
|
|
2174
2199
|
/**
|
|
2175
2200
|
* Creates a new agent builder action run and returns the runId.
|
|
2176
2201
|
* This calls `/api/agent-builder/:actionId/create-run`.
|
|
2177
2202
|
*/
|
|
2178
|
-
async
|
|
2203
|
+
async createRunAsync(params) {
|
|
2179
2204
|
const searchParams = new URLSearchParams();
|
|
2180
2205
|
if (!!params?.runId) {
|
|
2181
2206
|
searchParams.set("runId", params.runId);
|
|
@@ -2185,14 +2210,6 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2185
2210
|
method: "POST"
|
|
2186
2211
|
});
|
|
2187
2212
|
}
|
|
2188
|
-
/**
|
|
2189
|
-
* Creates a new workflow run (alias for createRun)
|
|
2190
|
-
* @param params - Optional object containing the optional runId
|
|
2191
|
-
* @returns Promise containing the runId of the created run
|
|
2192
|
-
*/
|
|
2193
|
-
createRunAsync(params) {
|
|
2194
|
-
return this.createRun(params);
|
|
2195
|
-
}
|
|
2196
2213
|
/**
|
|
2197
2214
|
* Starts agent builder action asynchronously and waits for completion.
|
|
2198
2215
|
* This calls `/api/agent-builder/:actionId/start-async`.
|
|
@@ -2275,7 +2292,7 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2275
2292
|
if (done && !value) continue;
|
|
2276
2293
|
try {
|
|
2277
2294
|
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
2278
|
-
const chunks = (buffer + decoded).split(
|
|
2295
|
+
const chunks = (buffer + decoded).split(RECORD_SEPARATOR2);
|
|
2279
2296
|
buffer = chunks.pop() || "";
|
|
2280
2297
|
for (const chunk of chunks) {
|
|
2281
2298
|
if (chunk) {
|
|
@@ -2332,7 +2349,7 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2332
2349
|
async transform(chunk, controller) {
|
|
2333
2350
|
try {
|
|
2334
2351
|
const decoded = new TextDecoder().decode(chunk);
|
|
2335
|
-
const chunks = decoded.split(
|
|
2352
|
+
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
2336
2353
|
for (const chunk2 of chunks) {
|
|
2337
2354
|
if (chunk2) {
|
|
2338
2355
|
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
@@ -2381,7 +2398,7 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2381
2398
|
async transform(chunk, controller) {
|
|
2382
2399
|
try {
|
|
2383
2400
|
const decoded = new TextDecoder().decode(chunk);
|
|
2384
|
-
const chunks = decoded.split(
|
|
2401
|
+
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
2385
2402
|
for (const chunk2 of chunks) {
|
|
2386
2403
|
if (chunk2) {
|
|
2387
2404
|
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
@@ -2524,7 +2541,7 @@ var Observability = class extends BaseResource {
|
|
|
2524
2541
|
getTraces(params) {
|
|
2525
2542
|
const { pagination, filters } = params;
|
|
2526
2543
|
const { page, perPage, dateRange } = pagination || {};
|
|
2527
|
-
const { name, spanType } = filters || {};
|
|
2544
|
+
const { name, spanType, entityId, entityType } = filters || {};
|
|
2528
2545
|
const searchParams = new URLSearchParams();
|
|
2529
2546
|
if (page !== void 0) {
|
|
2530
2547
|
searchParams.set("page", String(page));
|
|
@@ -2538,6 +2555,10 @@ var Observability = class extends BaseResource {
|
|
|
2538
2555
|
if (spanType !== void 0) {
|
|
2539
2556
|
searchParams.set("spanType", String(spanType));
|
|
2540
2557
|
}
|
|
2558
|
+
if (entityId && entityType) {
|
|
2559
|
+
searchParams.set("entityId", entityId);
|
|
2560
|
+
searchParams.set("entityType", entityType);
|
|
2561
|
+
}
|
|
2541
2562
|
if (dateRange) {
|
|
2542
2563
|
const dateRangeStr = JSON.stringify({
|
|
2543
2564
|
start: dateRange.start instanceof Date ? dateRange.start.toISOString() : dateRange.start,
|
|
@@ -2548,6 +2569,31 @@ var Observability = class extends BaseResource {
|
|
|
2548
2569
|
const queryString = searchParams.toString();
|
|
2549
2570
|
return this.request(`/api/observability/traces${queryString ? `?${queryString}` : ""}`);
|
|
2550
2571
|
}
|
|
2572
|
+
/**
|
|
2573
|
+
* Retrieves scores by trace ID and span ID
|
|
2574
|
+
* @param params - Parameters containing trace ID, span ID, and pagination options
|
|
2575
|
+
* @returns Promise containing scores and pagination info
|
|
2576
|
+
*/
|
|
2577
|
+
getScoresBySpan(params) {
|
|
2578
|
+
const { traceId, spanId, page, perPage } = params;
|
|
2579
|
+
const searchParams = new URLSearchParams();
|
|
2580
|
+
if (page !== void 0) {
|
|
2581
|
+
searchParams.set("page", String(page));
|
|
2582
|
+
}
|
|
2583
|
+
if (perPage !== void 0) {
|
|
2584
|
+
searchParams.set("perPage", String(perPage));
|
|
2585
|
+
}
|
|
2586
|
+
const queryString = searchParams.toString();
|
|
2587
|
+
return this.request(
|
|
2588
|
+
`/api/observability/traces/${encodeURIComponent(traceId)}/${encodeURIComponent(spanId)}/scores${queryString ? `?${queryString}` : ""}`
|
|
2589
|
+
);
|
|
2590
|
+
}
|
|
2591
|
+
score(params) {
|
|
2592
|
+
return this.request(`/api/observability/traces/score`, {
|
|
2593
|
+
method: "POST",
|
|
2594
|
+
body: { ...params }
|
|
2595
|
+
});
|
|
2596
|
+
}
|
|
2551
2597
|
};
|
|
2552
2598
|
|
|
2553
2599
|
// src/resources/network-memory-thread.ts
|
|
@@ -2614,7 +2660,7 @@ var NetworkMemoryThread = class extends BaseResource {
|
|
|
2614
2660
|
};
|
|
2615
2661
|
|
|
2616
2662
|
// src/resources/vNextNetwork.ts
|
|
2617
|
-
var
|
|
2663
|
+
var RECORD_SEPARATOR3 = "";
|
|
2618
2664
|
var VNextNetwork = class extends BaseResource {
|
|
2619
2665
|
constructor(options, networkId) {
|
|
2620
2666
|
super(options);
|
|
@@ -2622,10 +2668,11 @@ var VNextNetwork = class extends BaseResource {
|
|
|
2622
2668
|
}
|
|
2623
2669
|
/**
|
|
2624
2670
|
* Retrieves details about the network
|
|
2671
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2625
2672
|
* @returns Promise containing vNext network details
|
|
2626
2673
|
*/
|
|
2627
|
-
details() {
|
|
2628
|
-
return this.request(`/api/networks/v-next/${this.networkId}`);
|
|
2674
|
+
details(runtimeContext) {
|
|
2675
|
+
return this.request(`/api/networks/v-next/${this.networkId}${runtimeContextQueryString(runtimeContext)}`);
|
|
2629
2676
|
}
|
|
2630
2677
|
/**
|
|
2631
2678
|
* Generates a response from the v-next network
|
|
@@ -2666,7 +2713,7 @@ var VNextNetwork = class extends BaseResource {
|
|
|
2666
2713
|
if (done && !value) continue;
|
|
2667
2714
|
try {
|
|
2668
2715
|
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
2669
|
-
const chunks = (buffer + decoded).split(
|
|
2716
|
+
const chunks = (buffer + decoded).split(RECORD_SEPARATOR3);
|
|
2670
2717
|
buffer = chunks.pop() || "";
|
|
2671
2718
|
for (const chunk of chunks) {
|
|
2672
2719
|
if (chunk) {
|
|
@@ -2760,10 +2807,17 @@ var MastraClient = class extends BaseResource {
|
|
|
2760
2807
|
}
|
|
2761
2808
|
/**
|
|
2762
2809
|
* Retrieves all available agents
|
|
2810
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2763
2811
|
* @returns Promise containing map of agent IDs to agent details
|
|
2764
2812
|
*/
|
|
2765
|
-
getAgents() {
|
|
2766
|
-
|
|
2813
|
+
getAgents(runtimeContext) {
|
|
2814
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
2815
|
+
const searchParams = new URLSearchParams();
|
|
2816
|
+
if (runtimeContextParam) {
|
|
2817
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
2818
|
+
}
|
|
2819
|
+
const queryString = searchParams.toString();
|
|
2820
|
+
return this.request(`/api/agents${queryString ? `?${queryString}` : ""}`);
|
|
2767
2821
|
}
|
|
2768
2822
|
/**
|
|
2769
2823
|
* Gets an agent instance by ID
|
|
@@ -2781,6 +2835,14 @@ var MastraClient = class extends BaseResource {
|
|
|
2781
2835
|
getMemoryThreads(params) {
|
|
2782
2836
|
return this.request(`/api/memory/threads?resourceid=${params.resourceId}&agentId=${params.agentId}`);
|
|
2783
2837
|
}
|
|
2838
|
+
/**
|
|
2839
|
+
* Retrieves memory config for a resource
|
|
2840
|
+
* @param params - Parameters containing the resource ID
|
|
2841
|
+
* @returns Promise containing array of memory threads
|
|
2842
|
+
*/
|
|
2843
|
+
getMemoryConfig(params) {
|
|
2844
|
+
return this.request(`/api/memory/config?agentId=${params.agentId}`);
|
|
2845
|
+
}
|
|
2784
2846
|
/**
|
|
2785
2847
|
* Creates a new memory thread
|
|
2786
2848
|
* @param params - Parameters for creating the memory thread
|
|
@@ -2797,6 +2859,24 @@ var MastraClient = class extends BaseResource {
|
|
|
2797
2859
|
getMemoryThread(threadId, agentId) {
|
|
2798
2860
|
return new MemoryThread(this.options, threadId, agentId);
|
|
2799
2861
|
}
|
|
2862
|
+
getThreadMessages(threadId, opts = {}) {
|
|
2863
|
+
let url = "";
|
|
2864
|
+
if (opts.agentId) {
|
|
2865
|
+
url = `/api/memory/threads/${threadId}/messages?agentId=${opts.agentId}`;
|
|
2866
|
+
} else if (opts.networkId) {
|
|
2867
|
+
url = `/api/memory/network/threads/${threadId}/messages?networkId=${opts.networkId}`;
|
|
2868
|
+
}
|
|
2869
|
+
return this.request(url);
|
|
2870
|
+
}
|
|
2871
|
+
deleteThread(threadId, opts = {}) {
|
|
2872
|
+
let url = "";
|
|
2873
|
+
if (opts.agentId) {
|
|
2874
|
+
url = `/api/memory/threads/${threadId}?agentId=${opts.agentId}`;
|
|
2875
|
+
} else if (opts.networkId) {
|
|
2876
|
+
url = `/api/memory/network/threads/${threadId}?networkId=${opts.networkId}`;
|
|
2877
|
+
}
|
|
2878
|
+
return this.request(url, { method: "DELETE" });
|
|
2879
|
+
}
|
|
2800
2880
|
/**
|
|
2801
2881
|
* Saves messages to memory
|
|
2802
2882
|
* @param params - Parameters containing messages to save
|
|
@@ -2859,10 +2939,17 @@ var MastraClient = class extends BaseResource {
|
|
|
2859
2939
|
}
|
|
2860
2940
|
/**
|
|
2861
2941
|
* Retrieves all available tools
|
|
2942
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2862
2943
|
* @returns Promise containing map of tool IDs to tool details
|
|
2863
2944
|
*/
|
|
2864
|
-
getTools() {
|
|
2865
|
-
|
|
2945
|
+
getTools(runtimeContext) {
|
|
2946
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
2947
|
+
const searchParams = new URLSearchParams();
|
|
2948
|
+
if (runtimeContextParam) {
|
|
2949
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
2950
|
+
}
|
|
2951
|
+
const queryString = searchParams.toString();
|
|
2952
|
+
return this.request(`/api/tools${queryString ? `?${queryString}` : ""}`);
|
|
2866
2953
|
}
|
|
2867
2954
|
/**
|
|
2868
2955
|
* Gets a tool instance by ID
|
|
@@ -2872,27 +2959,19 @@ var MastraClient = class extends BaseResource {
|
|
|
2872
2959
|
getTool(toolId) {
|
|
2873
2960
|
return new Tool(this.options, toolId);
|
|
2874
2961
|
}
|
|
2875
|
-
/**
|
|
2876
|
-
* Retrieves all available legacy workflows
|
|
2877
|
-
* @returns Promise containing map of legacy workflow IDs to legacy workflow details
|
|
2878
|
-
*/
|
|
2879
|
-
getLegacyWorkflows() {
|
|
2880
|
-
return this.request("/api/workflows/legacy");
|
|
2881
|
-
}
|
|
2882
|
-
/**
|
|
2883
|
-
* Gets a legacy workflow instance by ID
|
|
2884
|
-
* @param workflowId - ID of the legacy workflow to retrieve
|
|
2885
|
-
* @returns Legacy Workflow instance
|
|
2886
|
-
*/
|
|
2887
|
-
getLegacyWorkflow(workflowId) {
|
|
2888
|
-
return new LegacyWorkflow(this.options, workflowId);
|
|
2889
|
-
}
|
|
2890
2962
|
/**
|
|
2891
2963
|
* Retrieves all available workflows
|
|
2964
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2892
2965
|
* @returns Promise containing map of workflow IDs to workflow details
|
|
2893
2966
|
*/
|
|
2894
|
-
getWorkflows() {
|
|
2895
|
-
|
|
2967
|
+
getWorkflows(runtimeContext) {
|
|
2968
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
2969
|
+
const searchParams = new URLSearchParams();
|
|
2970
|
+
if (runtimeContextParam) {
|
|
2971
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
2972
|
+
}
|
|
2973
|
+
const queryString = searchParams.toString();
|
|
2974
|
+
return this.request(`/api/workflows${queryString ? `?${queryString}` : ""}`);
|
|
2896
2975
|
}
|
|
2897
2976
|
/**
|
|
2898
2977
|
* Gets a workflow instance by ID
|
|
@@ -3060,13 +3139,6 @@ var MastraClient = class extends BaseResource {
|
|
|
3060
3139
|
return this.request(`/api/telemetry`);
|
|
3061
3140
|
}
|
|
3062
3141
|
}
|
|
3063
|
-
/**
|
|
3064
|
-
* Retrieves all available networks
|
|
3065
|
-
* @returns Promise containing map of network IDs to network details
|
|
3066
|
-
*/
|
|
3067
|
-
getNetworks() {
|
|
3068
|
-
return this.request("/api/networks");
|
|
3069
|
-
}
|
|
3070
3142
|
/**
|
|
3071
3143
|
* Retrieves all available vNext networks
|
|
3072
3144
|
* @returns Promise containing map of vNext network IDs to vNext network details
|
|
@@ -3074,14 +3146,6 @@ var MastraClient = class extends BaseResource {
|
|
|
3074
3146
|
getVNextNetworks() {
|
|
3075
3147
|
return this.request("/api/networks/v-next");
|
|
3076
3148
|
}
|
|
3077
|
-
/**
|
|
3078
|
-
* Gets a network instance by ID
|
|
3079
|
-
* @param networkId - ID of the network to retrieve
|
|
3080
|
-
* @returns Network instance
|
|
3081
|
-
*/
|
|
3082
|
-
getNetwork(networkId) {
|
|
3083
|
-
return new Network(this.options, networkId);
|
|
3084
|
-
}
|
|
3085
3149
|
/**
|
|
3086
3150
|
* Gets a vNext network instance by ID
|
|
3087
3151
|
* @param networkId - ID of the vNext network to retrieve
|
|
@@ -3194,7 +3258,7 @@ var MastraClient = class extends BaseResource {
|
|
|
3194
3258
|
* @returns Promise containing the scorer
|
|
3195
3259
|
*/
|
|
3196
3260
|
getScorer(scorerId) {
|
|
3197
|
-
return this.request(`/api/scores/scorers/${scorerId}`);
|
|
3261
|
+
return this.request(`/api/scores/scorers/${encodeURIComponent(scorerId)}`);
|
|
3198
3262
|
}
|
|
3199
3263
|
getScoresByScorerId(params) {
|
|
3200
3264
|
const { page, perPage, scorerId, entityId, entityType } = params;
|
|
@@ -3212,7 +3276,7 @@ var MastraClient = class extends BaseResource {
|
|
|
3212
3276
|
searchParams.set("perPage", String(perPage));
|
|
3213
3277
|
}
|
|
3214
3278
|
const queryString = searchParams.toString();
|
|
3215
|
-
return this.request(`/api/scores/scorer/${scorerId}${queryString ? `?${queryString}` : ""}`);
|
|
3279
|
+
return this.request(`/api/scores/scorer/${encodeURIComponent(scorerId)}${queryString ? `?${queryString}` : ""}`);
|
|
3216
3280
|
}
|
|
3217
3281
|
/**
|
|
3218
3282
|
* Retrieves scores by run ID
|
|
@@ -3229,7 +3293,7 @@ var MastraClient = class extends BaseResource {
|
|
|
3229
3293
|
searchParams.set("perPage", String(perPage));
|
|
3230
3294
|
}
|
|
3231
3295
|
const queryString = searchParams.toString();
|
|
3232
|
-
return this.request(`/api/scores/run/${runId}${queryString ? `?${queryString}` : ""}`);
|
|
3296
|
+
return this.request(`/api/scores/run/${encodeURIComponent(runId)}${queryString ? `?${queryString}` : ""}`);
|
|
3233
3297
|
}
|
|
3234
3298
|
/**
|
|
3235
3299
|
* Retrieves scores by entity ID and type
|
|
@@ -3246,7 +3310,9 @@ var MastraClient = class extends BaseResource {
|
|
|
3246
3310
|
searchParams.set("perPage", String(perPage));
|
|
3247
3311
|
}
|
|
3248
3312
|
const queryString = searchParams.toString();
|
|
3249
|
-
return this.request(
|
|
3313
|
+
return this.request(
|
|
3314
|
+
`/api/scores/entity/${encodeURIComponent(entityType)}/${encodeURIComponent(entityId)}${queryString ? `?${queryString}` : ""}`
|
|
3315
|
+
);
|
|
3250
3316
|
}
|
|
3251
3317
|
/**
|
|
3252
3318
|
* Saves a score
|
|
@@ -3272,8 +3338,35 @@ var MastraClient = class extends BaseResource {
|
|
|
3272
3338
|
getAITraces(params) {
|
|
3273
3339
|
return this.observability.getTraces(params);
|
|
3274
3340
|
}
|
|
3341
|
+
getScoresBySpan(params) {
|
|
3342
|
+
return this.observability.getScoresBySpan(params);
|
|
3343
|
+
}
|
|
3344
|
+
score(params) {
|
|
3345
|
+
return this.observability.score(params);
|
|
3346
|
+
}
|
|
3347
|
+
};
|
|
3348
|
+
|
|
3349
|
+
// src/tools.ts
|
|
3350
|
+
var ClientTool = class {
|
|
3351
|
+
id;
|
|
3352
|
+
description;
|
|
3353
|
+
inputSchema;
|
|
3354
|
+
outputSchema;
|
|
3355
|
+
execute;
|
|
3356
|
+
constructor(opts) {
|
|
3357
|
+
this.id = opts.id;
|
|
3358
|
+
this.description = opts.description;
|
|
3359
|
+
this.inputSchema = opts.inputSchema;
|
|
3360
|
+
this.outputSchema = opts.outputSchema;
|
|
3361
|
+
this.execute = opts.execute;
|
|
3362
|
+
}
|
|
3275
3363
|
};
|
|
3364
|
+
function createTool(opts) {
|
|
3365
|
+
return new ClientTool(opts);
|
|
3366
|
+
}
|
|
3276
3367
|
|
|
3368
|
+
exports.ClientTool = ClientTool;
|
|
3277
3369
|
exports.MastraClient = MastraClient;
|
|
3370
|
+
exports.createTool = createTool;
|
|
3278
3371
|
//# sourceMappingURL=index.cjs.map
|
|
3279
3372
|
//# sourceMappingURL=index.cjs.map
|