@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.js
CHANGED
|
@@ -15,6 +15,20 @@ function parseClientRuntimeContext(runtimeContext) {
|
|
|
15
15
|
}
|
|
16
16
|
return void 0;
|
|
17
17
|
}
|
|
18
|
+
function base64RuntimeContext(runtimeContext) {
|
|
19
|
+
if (runtimeContext) {
|
|
20
|
+
return btoa(JSON.stringify(runtimeContext));
|
|
21
|
+
}
|
|
22
|
+
return void 0;
|
|
23
|
+
}
|
|
24
|
+
function runtimeContextQueryString(runtimeContext) {
|
|
25
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
26
|
+
if (!runtimeContextParam) return "";
|
|
27
|
+
const searchParams = new URLSearchParams();
|
|
28
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
29
|
+
const queryString = searchParams.toString();
|
|
30
|
+
return queryString ? `?${queryString}` : "";
|
|
31
|
+
}
|
|
18
32
|
function isZodType(value) {
|
|
19
33
|
return typeof value === "object" && value !== null && "_def" in value && "parse" in value && typeof value.parse === "function" && "safeParse" in value && typeof value.safeParse === "function";
|
|
20
34
|
}
|
|
@@ -26,7 +40,7 @@ function zodToJsonSchema(zodSchema) {
|
|
|
26
40
|
const fn = "toJSONSchema";
|
|
27
41
|
return z[fn].call(z, zodSchema);
|
|
28
42
|
}
|
|
29
|
-
return originalZodToJsonSchema(zodSchema, { $refStrategy: "
|
|
43
|
+
return originalZodToJsonSchema(zodSchema, { $refStrategy: "relative" });
|
|
30
44
|
}
|
|
31
45
|
|
|
32
46
|
// src/utils/process-client-tools.ts
|
|
@@ -59,7 +73,7 @@ function processClientTools(clientTools) {
|
|
|
59
73
|
}
|
|
60
74
|
|
|
61
75
|
// src/utils/process-mastra-stream.ts
|
|
62
|
-
async function
|
|
76
|
+
async function sharedProcessMastraStream({
|
|
63
77
|
stream,
|
|
64
78
|
onChunk
|
|
65
79
|
}) {
|
|
@@ -77,7 +91,7 @@ async function processMastraStream({
|
|
|
77
91
|
if (line.startsWith("data: ")) {
|
|
78
92
|
const data = line.slice(6);
|
|
79
93
|
if (data === "[DONE]") {
|
|
80
|
-
console.
|
|
94
|
+
console.info("\u{1F3C1} Stream finished");
|
|
81
95
|
return;
|
|
82
96
|
}
|
|
83
97
|
try {
|
|
@@ -93,6 +107,24 @@ async function processMastraStream({
|
|
|
93
107
|
reader.releaseLock();
|
|
94
108
|
}
|
|
95
109
|
}
|
|
110
|
+
async function processMastraNetworkStream({
|
|
111
|
+
stream,
|
|
112
|
+
onChunk
|
|
113
|
+
}) {
|
|
114
|
+
return sharedProcessMastraStream({
|
|
115
|
+
stream,
|
|
116
|
+
onChunk
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
async function processMastraStream({
|
|
120
|
+
stream,
|
|
121
|
+
onChunk
|
|
122
|
+
}) {
|
|
123
|
+
return sharedProcessMastraStream({
|
|
124
|
+
stream,
|
|
125
|
+
onChunk
|
|
126
|
+
});
|
|
127
|
+
}
|
|
96
128
|
|
|
97
129
|
// src/resources/base.ts
|
|
98
130
|
var BaseResource = class {
|
|
@@ -181,7 +213,9 @@ async function executeToolCallAndRespond({
|
|
|
181
213
|
resourceId,
|
|
182
214
|
threadId,
|
|
183
215
|
runtimeContext,
|
|
184
|
-
tracingContext: { currentSpan: void 0 }
|
|
216
|
+
tracingContext: { currentSpan: void 0 },
|
|
217
|
+
suspend: async () => {
|
|
218
|
+
}
|
|
185
219
|
},
|
|
186
220
|
{
|
|
187
221
|
messages: response.messages,
|
|
@@ -189,11 +223,7 @@ async function executeToolCallAndRespond({
|
|
|
189
223
|
}
|
|
190
224
|
);
|
|
191
225
|
const updatedMessages = [
|
|
192
|
-
|
|
193
|
-
role: "user",
|
|
194
|
-
content: params.messages
|
|
195
|
-
},
|
|
196
|
-
...response.response.messages,
|
|
226
|
+
...response.response.messages || [],
|
|
197
227
|
{
|
|
198
228
|
role: "tool",
|
|
199
229
|
content: [
|
|
@@ -255,17 +285,21 @@ var AgentVoice = class extends BaseResource {
|
|
|
255
285
|
}
|
|
256
286
|
/**
|
|
257
287
|
* Get available speakers for the agent's voice provider
|
|
288
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
289
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
258
290
|
* @returns Promise containing list of available speakers
|
|
259
291
|
*/
|
|
260
|
-
getSpeakers() {
|
|
261
|
-
return this.request(`/api/agents/${this.agentId}/voice/speakers`);
|
|
292
|
+
getSpeakers(runtimeContext) {
|
|
293
|
+
return this.request(`/api/agents/${this.agentId}/voice/speakers${runtimeContextQueryString(runtimeContext)}`);
|
|
262
294
|
}
|
|
263
295
|
/**
|
|
264
296
|
* Get the listener configuration for the agent's voice provider
|
|
297
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
298
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
265
299
|
* @returns Promise containing a check if the agent has listening capabilities
|
|
266
300
|
*/
|
|
267
|
-
getListener() {
|
|
268
|
-
return this.request(`/api/agents/${this.agentId}/voice/listener`);
|
|
301
|
+
getListener(runtimeContext) {
|
|
302
|
+
return this.request(`/api/agents/${this.agentId}/voice/listener${runtimeContextQueryString(runtimeContext)}`);
|
|
269
303
|
}
|
|
270
304
|
};
|
|
271
305
|
var Agent = class extends BaseResource {
|
|
@@ -277,14 +311,15 @@ var Agent = class extends BaseResource {
|
|
|
277
311
|
voice;
|
|
278
312
|
/**
|
|
279
313
|
* Retrieves details about the agent
|
|
314
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
280
315
|
* @returns Promise containing agent details including model and instructions
|
|
281
316
|
*/
|
|
282
|
-
details() {
|
|
283
|
-
return this.request(`/api/agents/${this.agentId}`);
|
|
317
|
+
details(runtimeContext) {
|
|
318
|
+
return this.request(`/api/agents/${this.agentId}${runtimeContextQueryString(runtimeContext)}`);
|
|
284
319
|
}
|
|
285
320
|
async generate(params) {
|
|
286
321
|
console.warn(
|
|
287
|
-
"Deprecation NOTICE:Generate method will switch to use generateVNext implementation September
|
|
322
|
+
"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."
|
|
288
323
|
);
|
|
289
324
|
return this.generateLegacy(params);
|
|
290
325
|
}
|
|
@@ -319,7 +354,9 @@ var Agent = class extends BaseResource {
|
|
|
319
354
|
resourceId,
|
|
320
355
|
threadId,
|
|
321
356
|
runtimeContext,
|
|
322
|
-
tracingContext: { currentSpan: void 0 }
|
|
357
|
+
tracingContext: { currentSpan: void 0 },
|
|
358
|
+
suspend: async () => {
|
|
359
|
+
}
|
|
323
360
|
},
|
|
324
361
|
{
|
|
325
362
|
messages: response.messages,
|
|
@@ -327,10 +364,6 @@ var Agent = class extends BaseResource {
|
|
|
327
364
|
}
|
|
328
365
|
);
|
|
329
366
|
const updatedMessages = [
|
|
330
|
-
{
|
|
331
|
-
role: "user",
|
|
332
|
-
content: params.messages
|
|
333
|
-
},
|
|
334
367
|
...response.response.messages,
|
|
335
368
|
{
|
|
336
369
|
role: "tool",
|
|
@@ -353,12 +386,25 @@ var Agent = class extends BaseResource {
|
|
|
353
386
|
}
|
|
354
387
|
return response;
|
|
355
388
|
}
|
|
356
|
-
async generateVNext(
|
|
389
|
+
async generateVNext(messagesOrParams, options) {
|
|
390
|
+
let params;
|
|
391
|
+
if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
|
|
392
|
+
params = messagesOrParams;
|
|
393
|
+
} else {
|
|
394
|
+
params = {
|
|
395
|
+
messages: messagesOrParams,
|
|
396
|
+
...options
|
|
397
|
+
};
|
|
398
|
+
}
|
|
357
399
|
const processedParams = {
|
|
358
400
|
...params,
|
|
359
401
|
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
360
402
|
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
361
|
-
clientTools: processClientTools(params.clientTools)
|
|
403
|
+
clientTools: processClientTools(params.clientTools),
|
|
404
|
+
structuredOutput: params.structuredOutput ? {
|
|
405
|
+
...params.structuredOutput,
|
|
406
|
+
schema: zodToJsonSchema(params.structuredOutput.schema)
|
|
407
|
+
} : void 0
|
|
362
408
|
};
|
|
363
409
|
const { runId, resourceId, threadId, runtimeContext } = processedParams;
|
|
364
410
|
const response = await this.request(
|
|
@@ -650,7 +696,7 @@ var Agent = class extends BaseResource {
|
|
|
650
696
|
*/
|
|
651
697
|
async stream(params) {
|
|
652
698
|
console.warn(
|
|
653
|
-
"Deprecation NOTICE:\nStream method will switch to use streamVNext implementation September
|
|
699
|
+
"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."
|
|
654
700
|
);
|
|
655
701
|
return this.streamLegacy(params);
|
|
656
702
|
}
|
|
@@ -988,9 +1034,11 @@ var Agent = class extends BaseResource {
|
|
|
988
1034
|
if (toolCall) {
|
|
989
1035
|
toolCalls.push(toolCall);
|
|
990
1036
|
}
|
|
1037
|
+
let shouldExecuteClientTool = false;
|
|
991
1038
|
for (const toolCall2 of toolCalls) {
|
|
992
1039
|
const clientTool = processedParams.clientTools?.[toolCall2.toolName];
|
|
993
1040
|
if (clientTool && clientTool.execute) {
|
|
1041
|
+
shouldExecuteClientTool = true;
|
|
994
1042
|
const result = await clientTool.execute(
|
|
995
1043
|
{
|
|
996
1044
|
context: toolCall2?.args,
|
|
@@ -999,7 +1047,9 @@ var Agent = class extends BaseResource {
|
|
|
999
1047
|
threadId: processedParams.threadId,
|
|
1000
1048
|
runtimeContext: processedParams.runtimeContext,
|
|
1001
1049
|
// TODO: Pass proper tracing context when client-js supports tracing
|
|
1002
|
-
tracingContext: { currentSpan: void 0 }
|
|
1050
|
+
tracingContext: { currentSpan: void 0 },
|
|
1051
|
+
suspend: async () => {
|
|
1052
|
+
}
|
|
1003
1053
|
},
|
|
1004
1054
|
{
|
|
1005
1055
|
messages: response.messages,
|
|
@@ -1025,9 +1075,7 @@ var Agent = class extends BaseResource {
|
|
|
1025
1075
|
toolInvocation.state = "result";
|
|
1026
1076
|
toolInvocation.result = result;
|
|
1027
1077
|
}
|
|
1028
|
-
const
|
|
1029
|
-
const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
|
|
1030
|
-
const updatedMessages = lastMessage != null ? [...messageArray, ...messages.filter((m) => m.id !== lastMessage.id), lastMessage] : [...messageArray, ...messages];
|
|
1078
|
+
const updatedMessages = lastMessage != null ? [...messages.filter((m) => m.id !== lastMessage.id), lastMessage] : [...messages];
|
|
1031
1079
|
this.processStreamResponse_vNext(
|
|
1032
1080
|
{
|
|
1033
1081
|
...processedParams,
|
|
@@ -1039,6 +1087,11 @@ var Agent = class extends BaseResource {
|
|
|
1039
1087
|
});
|
|
1040
1088
|
}
|
|
1041
1089
|
}
|
|
1090
|
+
if (!shouldExecuteClientTool) {
|
|
1091
|
+
setTimeout(() => {
|
|
1092
|
+
writable.close();
|
|
1093
|
+
}, 0);
|
|
1094
|
+
}
|
|
1042
1095
|
} else {
|
|
1043
1096
|
setTimeout(() => {
|
|
1044
1097
|
writable.close();
|
|
@@ -1054,12 +1107,49 @@ var Agent = class extends BaseResource {
|
|
|
1054
1107
|
}
|
|
1055
1108
|
return response;
|
|
1056
1109
|
}
|
|
1057
|
-
async
|
|
1110
|
+
async network(params) {
|
|
1111
|
+
const response = await this.request(`/api/agents/${this.agentId}/network`, {
|
|
1112
|
+
method: "POST",
|
|
1113
|
+
body: params,
|
|
1114
|
+
stream: true
|
|
1115
|
+
});
|
|
1116
|
+
if (!response.body) {
|
|
1117
|
+
throw new Error("No response body");
|
|
1118
|
+
}
|
|
1119
|
+
const streamResponse = new Response(response.body, {
|
|
1120
|
+
status: response.status,
|
|
1121
|
+
statusText: response.statusText,
|
|
1122
|
+
headers: response.headers
|
|
1123
|
+
});
|
|
1124
|
+
streamResponse.processDataStream = async ({
|
|
1125
|
+
onChunk
|
|
1126
|
+
}) => {
|
|
1127
|
+
await processMastraNetworkStream({
|
|
1128
|
+
stream: streamResponse.body,
|
|
1129
|
+
onChunk
|
|
1130
|
+
});
|
|
1131
|
+
};
|
|
1132
|
+
return streamResponse;
|
|
1133
|
+
}
|
|
1134
|
+
async streamVNext(messagesOrParams, options) {
|
|
1135
|
+
let params;
|
|
1136
|
+
if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
|
|
1137
|
+
params = messagesOrParams;
|
|
1138
|
+
} else {
|
|
1139
|
+
params = {
|
|
1140
|
+
messages: messagesOrParams,
|
|
1141
|
+
...options
|
|
1142
|
+
};
|
|
1143
|
+
}
|
|
1058
1144
|
const processedParams = {
|
|
1059
1145
|
...params,
|
|
1060
1146
|
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
1061
1147
|
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
1062
|
-
clientTools: processClientTools(params.clientTools)
|
|
1148
|
+
clientTools: processClientTools(params.clientTools),
|
|
1149
|
+
structuredOutput: params.structuredOutput ? {
|
|
1150
|
+
...params.structuredOutput,
|
|
1151
|
+
schema: zodToJsonSchema(params.structuredOutput.schema)
|
|
1152
|
+
} : void 0
|
|
1063
1153
|
};
|
|
1064
1154
|
const { readable, writable } = new TransformStream();
|
|
1065
1155
|
const response = await this.processStreamResponse_vNext(processedParams, writable);
|
|
@@ -1126,7 +1216,9 @@ var Agent = class extends BaseResource {
|
|
|
1126
1216
|
threadId: processedParams.threadId,
|
|
1127
1217
|
runtimeContext: processedParams.runtimeContext,
|
|
1128
1218
|
// TODO: Pass proper tracing context when client-js supports tracing
|
|
1129
|
-
tracingContext: { currentSpan: void 0 }
|
|
1219
|
+
tracingContext: { currentSpan: void 0 },
|
|
1220
|
+
suspend: async () => {
|
|
1221
|
+
}
|
|
1130
1222
|
},
|
|
1131
1223
|
{
|
|
1132
1224
|
messages: response.messages,
|
|
@@ -1164,12 +1256,10 @@ var Agent = class extends BaseResource {
|
|
|
1164
1256
|
} finally {
|
|
1165
1257
|
writer.releaseLock();
|
|
1166
1258
|
}
|
|
1167
|
-
const originalMessages = processedParams.messages;
|
|
1168
|
-
const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
|
|
1169
1259
|
this.processStreamResponse(
|
|
1170
1260
|
{
|
|
1171
1261
|
...processedParams,
|
|
1172
|
-
messages: [...
|
|
1262
|
+
messages: [...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
|
|
1173
1263
|
},
|
|
1174
1264
|
writable
|
|
1175
1265
|
).catch((error) => {
|
|
@@ -1195,10 +1285,11 @@ var Agent = class extends BaseResource {
|
|
|
1195
1285
|
/**
|
|
1196
1286
|
* Gets details about a specific tool available to the agent
|
|
1197
1287
|
* @param toolId - ID of the tool to retrieve
|
|
1288
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1198
1289
|
* @returns Promise containing tool details
|
|
1199
1290
|
*/
|
|
1200
|
-
getTool(toolId) {
|
|
1201
|
-
return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
|
|
1291
|
+
getTool(toolId, runtimeContext) {
|
|
1292
|
+
return this.request(`/api/agents/${this.agentId}/tools/${toolId}${runtimeContextQueryString(runtimeContext)}`);
|
|
1202
1293
|
}
|
|
1203
1294
|
/**
|
|
1204
1295
|
* Executes a tool for the agent
|
|
@@ -1209,7 +1300,7 @@ var Agent = class extends BaseResource {
|
|
|
1209
1300
|
executeTool(toolId, params) {
|
|
1210
1301
|
const body = {
|
|
1211
1302
|
data: params.data,
|
|
1212
|
-
runtimeContext:
|
|
1303
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1213
1304
|
};
|
|
1214
1305
|
return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
|
|
1215
1306
|
method: "POST",
|
|
@@ -1218,17 +1309,19 @@ var Agent = class extends BaseResource {
|
|
|
1218
1309
|
}
|
|
1219
1310
|
/**
|
|
1220
1311
|
* Retrieves evaluation results for the agent
|
|
1312
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1221
1313
|
* @returns Promise containing agent evaluations
|
|
1222
1314
|
*/
|
|
1223
|
-
evals() {
|
|
1224
|
-
return this.request(`/api/agents/${this.agentId}/evals/ci`);
|
|
1315
|
+
evals(runtimeContext) {
|
|
1316
|
+
return this.request(`/api/agents/${this.agentId}/evals/ci${runtimeContextQueryString(runtimeContext)}`);
|
|
1225
1317
|
}
|
|
1226
1318
|
/**
|
|
1227
1319
|
* Retrieves live evaluation results for the agent
|
|
1320
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1228
1321
|
* @returns Promise containing live agent evaluations
|
|
1229
1322
|
*/
|
|
1230
|
-
liveEvals() {
|
|
1231
|
-
return this.request(`/api/agents/${this.agentId}/evals/live`);
|
|
1323
|
+
liveEvals(runtimeContext) {
|
|
1324
|
+
return this.request(`/api/agents/${this.agentId}/evals/live${runtimeContextQueryString(runtimeContext)}`);
|
|
1232
1325
|
}
|
|
1233
1326
|
/**
|
|
1234
1327
|
* Updates the model for the agent
|
|
@@ -1241,61 +1334,27 @@ var Agent = class extends BaseResource {
|
|
|
1241
1334
|
body: params
|
|
1242
1335
|
});
|
|
1243
1336
|
}
|
|
1244
|
-
};
|
|
1245
|
-
var Network = class extends BaseResource {
|
|
1246
|
-
constructor(options, networkId) {
|
|
1247
|
-
super(options);
|
|
1248
|
-
this.networkId = networkId;
|
|
1249
|
-
}
|
|
1250
1337
|
/**
|
|
1251
|
-
*
|
|
1252
|
-
* @
|
|
1253
|
-
|
|
1254
|
-
details() {
|
|
1255
|
-
return this.request(`/api/networks/${this.networkId}`);
|
|
1256
|
-
}
|
|
1257
|
-
/**
|
|
1258
|
-
* Generates a response from the agent
|
|
1259
|
-
* @param params - Generation parameters including prompt
|
|
1260
|
-
* @returns Promise containing the generated response
|
|
1338
|
+
* Updates the model for the agent in the model list
|
|
1339
|
+
* @param params - Parameters for updating the model
|
|
1340
|
+
* @returns Promise containing the updated model
|
|
1261
1341
|
*/
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
...params,
|
|
1265
|
-
output: zodToJsonSchema(params.output),
|
|
1266
|
-
experimental_output: zodToJsonSchema(params.experimental_output)
|
|
1267
|
-
};
|
|
1268
|
-
return this.request(`/api/networks/${this.networkId}/generate`, {
|
|
1342
|
+
updateModelInModelList({ modelConfigId, ...params }) {
|
|
1343
|
+
return this.request(`/api/agents/${this.agentId}/models/${modelConfigId}`, {
|
|
1269
1344
|
method: "POST",
|
|
1270
|
-
body:
|
|
1345
|
+
body: params
|
|
1271
1346
|
});
|
|
1272
1347
|
}
|
|
1273
1348
|
/**
|
|
1274
|
-
*
|
|
1275
|
-
* @param params -
|
|
1276
|
-
* @returns Promise containing the
|
|
1349
|
+
* Reorders the models for the agent
|
|
1350
|
+
* @param params - Parameters for reordering the model list
|
|
1351
|
+
* @returns Promise containing the updated model list
|
|
1277
1352
|
*/
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
...params,
|
|
1281
|
-
output: zodToJsonSchema(params.output),
|
|
1282
|
-
experimental_output: zodToJsonSchema(params.experimental_output)
|
|
1283
|
-
};
|
|
1284
|
-
const response = await this.request(`/api/networks/${this.networkId}/stream`, {
|
|
1353
|
+
reorderModelList(params) {
|
|
1354
|
+
return this.request(`/api/agents/${this.agentId}/models/reorder`, {
|
|
1285
1355
|
method: "POST",
|
|
1286
|
-
body:
|
|
1287
|
-
stream: true
|
|
1356
|
+
body: params
|
|
1288
1357
|
});
|
|
1289
|
-
if (!response.body) {
|
|
1290
|
-
throw new Error("No response body");
|
|
1291
|
-
}
|
|
1292
|
-
response.processDataStream = async (options = {}) => {
|
|
1293
|
-
await processDataStream({
|
|
1294
|
-
stream: response.body,
|
|
1295
|
-
...options
|
|
1296
|
-
});
|
|
1297
|
-
};
|
|
1298
|
-
return response;
|
|
1299
1358
|
}
|
|
1300
1359
|
};
|
|
1301
1360
|
|
|
@@ -1386,10 +1445,13 @@ var Vector = class extends BaseResource {
|
|
|
1386
1445
|
/**
|
|
1387
1446
|
* Retrieves details about a specific vector index
|
|
1388
1447
|
* @param indexName - Name of the index to get details for
|
|
1448
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1389
1449
|
* @returns Promise containing vector index details
|
|
1390
1450
|
*/
|
|
1391
|
-
details(indexName) {
|
|
1392
|
-
return this.request(
|
|
1451
|
+
details(indexName, runtimeContext) {
|
|
1452
|
+
return this.request(
|
|
1453
|
+
`/api/vector/${this.vectorName}/indexes/${indexName}${runtimeContextQueryString(runtimeContext)}`
|
|
1454
|
+
);
|
|
1393
1455
|
}
|
|
1394
1456
|
/**
|
|
1395
1457
|
* Deletes a vector index
|
|
@@ -1403,10 +1465,11 @@ var Vector = class extends BaseResource {
|
|
|
1403
1465
|
}
|
|
1404
1466
|
/**
|
|
1405
1467
|
* Retrieves a list of all available indexes
|
|
1468
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1406
1469
|
* @returns Promise containing array of index names
|
|
1407
1470
|
*/
|
|
1408
|
-
getIndexes() {
|
|
1409
|
-
return this.request(`/api/vector/${this.vectorName}/indexes`);
|
|
1471
|
+
getIndexes(runtimeContext) {
|
|
1472
|
+
return this.request(`/api/vector/${this.vectorName}/indexes${runtimeContextQueryString(runtimeContext)}`);
|
|
1410
1473
|
}
|
|
1411
1474
|
/**
|
|
1412
1475
|
* Creates a new vector index
|
|
@@ -1443,187 +1506,6 @@ var Vector = class extends BaseResource {
|
|
|
1443
1506
|
}
|
|
1444
1507
|
};
|
|
1445
1508
|
|
|
1446
|
-
// src/resources/legacy-workflow.ts
|
|
1447
|
-
var RECORD_SEPARATOR = "";
|
|
1448
|
-
var LegacyWorkflow = class extends BaseResource {
|
|
1449
|
-
constructor(options, workflowId) {
|
|
1450
|
-
super(options);
|
|
1451
|
-
this.workflowId = workflowId;
|
|
1452
|
-
}
|
|
1453
|
-
/**
|
|
1454
|
-
* Retrieves details about the legacy workflow
|
|
1455
|
-
* @returns Promise containing legacy workflow details including steps and graphs
|
|
1456
|
-
*/
|
|
1457
|
-
details() {
|
|
1458
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}`);
|
|
1459
|
-
}
|
|
1460
|
-
/**
|
|
1461
|
-
* Retrieves all runs for a legacy workflow
|
|
1462
|
-
* @param params - Parameters for filtering runs
|
|
1463
|
-
* @returns Promise containing legacy workflow runs array
|
|
1464
|
-
*/
|
|
1465
|
-
runs(params) {
|
|
1466
|
-
const searchParams = new URLSearchParams();
|
|
1467
|
-
if (params?.fromDate) {
|
|
1468
|
-
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
1469
|
-
}
|
|
1470
|
-
if (params?.toDate) {
|
|
1471
|
-
searchParams.set("toDate", params.toDate.toISOString());
|
|
1472
|
-
}
|
|
1473
|
-
if (params?.limit) {
|
|
1474
|
-
searchParams.set("limit", String(params.limit));
|
|
1475
|
-
}
|
|
1476
|
-
if (params?.offset) {
|
|
1477
|
-
searchParams.set("offset", String(params.offset));
|
|
1478
|
-
}
|
|
1479
|
-
if (params?.resourceId) {
|
|
1480
|
-
searchParams.set("resourceId", params.resourceId);
|
|
1481
|
-
}
|
|
1482
|
-
if (searchParams.size) {
|
|
1483
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/runs?${searchParams}`);
|
|
1484
|
-
} else {
|
|
1485
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/runs`);
|
|
1486
|
-
}
|
|
1487
|
-
}
|
|
1488
|
-
/**
|
|
1489
|
-
* Creates a new legacy workflow run
|
|
1490
|
-
* @returns Promise containing the generated run ID
|
|
1491
|
-
*/
|
|
1492
|
-
createRun(params) {
|
|
1493
|
-
const searchParams = new URLSearchParams();
|
|
1494
|
-
if (!!params?.runId) {
|
|
1495
|
-
searchParams.set("runId", params.runId);
|
|
1496
|
-
}
|
|
1497
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/create-run?${searchParams.toString()}`, {
|
|
1498
|
-
method: "POST"
|
|
1499
|
-
});
|
|
1500
|
-
}
|
|
1501
|
-
/**
|
|
1502
|
-
* Starts a legacy workflow run synchronously without waiting for the workflow to complete
|
|
1503
|
-
* @param params - Object containing the runId and triggerData
|
|
1504
|
-
* @returns Promise containing success message
|
|
1505
|
-
*/
|
|
1506
|
-
start(params) {
|
|
1507
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/start?runId=${params.runId}`, {
|
|
1508
|
-
method: "POST",
|
|
1509
|
-
body: params?.triggerData
|
|
1510
|
-
});
|
|
1511
|
-
}
|
|
1512
|
-
/**
|
|
1513
|
-
* Resumes a suspended legacy workflow step synchronously without waiting for the workflow to complete
|
|
1514
|
-
* @param stepId - ID of the step to resume
|
|
1515
|
-
* @param runId - ID of the legacy workflow run
|
|
1516
|
-
* @param context - Context to resume the legacy workflow with
|
|
1517
|
-
* @returns Promise containing the legacy workflow resume results
|
|
1518
|
-
*/
|
|
1519
|
-
resume({
|
|
1520
|
-
stepId,
|
|
1521
|
-
runId,
|
|
1522
|
-
context
|
|
1523
|
-
}) {
|
|
1524
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/resume?runId=${runId}`, {
|
|
1525
|
-
method: "POST",
|
|
1526
|
-
body: {
|
|
1527
|
-
stepId,
|
|
1528
|
-
context
|
|
1529
|
-
}
|
|
1530
|
-
});
|
|
1531
|
-
}
|
|
1532
|
-
/**
|
|
1533
|
-
* Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
|
|
1534
|
-
* @param params - Object containing the optional runId and triggerData
|
|
1535
|
-
* @returns Promise containing the workflow execution results
|
|
1536
|
-
*/
|
|
1537
|
-
startAsync(params) {
|
|
1538
|
-
const searchParams = new URLSearchParams();
|
|
1539
|
-
if (!!params?.runId) {
|
|
1540
|
-
searchParams.set("runId", params.runId);
|
|
1541
|
-
}
|
|
1542
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
1543
|
-
method: "POST",
|
|
1544
|
-
body: params?.triggerData
|
|
1545
|
-
});
|
|
1546
|
-
}
|
|
1547
|
-
/**
|
|
1548
|
-
* Resumes a suspended legacy workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
1549
|
-
* @param params - Object containing the runId, stepId, and context
|
|
1550
|
-
* @returns Promise containing the workflow resume results
|
|
1551
|
-
*/
|
|
1552
|
-
resumeAsync(params) {
|
|
1553
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
1554
|
-
method: "POST",
|
|
1555
|
-
body: {
|
|
1556
|
-
stepId: params.stepId,
|
|
1557
|
-
context: params.context
|
|
1558
|
-
}
|
|
1559
|
-
});
|
|
1560
|
-
}
|
|
1561
|
-
/**
|
|
1562
|
-
* Creates an async generator that processes a readable stream and yields records
|
|
1563
|
-
* separated by the Record Separator character (\x1E)
|
|
1564
|
-
*
|
|
1565
|
-
* @param stream - The readable stream to process
|
|
1566
|
-
* @returns An async generator that yields parsed records
|
|
1567
|
-
*/
|
|
1568
|
-
async *streamProcessor(stream) {
|
|
1569
|
-
const reader = stream.getReader();
|
|
1570
|
-
let doneReading = false;
|
|
1571
|
-
let buffer = "";
|
|
1572
|
-
try {
|
|
1573
|
-
while (!doneReading) {
|
|
1574
|
-
const { done, value } = await reader.read();
|
|
1575
|
-
doneReading = done;
|
|
1576
|
-
if (done && !value) continue;
|
|
1577
|
-
try {
|
|
1578
|
-
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
1579
|
-
const chunks = (buffer + decoded).split(RECORD_SEPARATOR);
|
|
1580
|
-
buffer = chunks.pop() || "";
|
|
1581
|
-
for (const chunk of chunks) {
|
|
1582
|
-
if (chunk) {
|
|
1583
|
-
if (typeof chunk === "string") {
|
|
1584
|
-
try {
|
|
1585
|
-
const parsedChunk = JSON.parse(chunk);
|
|
1586
|
-
yield parsedChunk;
|
|
1587
|
-
} catch {
|
|
1588
|
-
}
|
|
1589
|
-
}
|
|
1590
|
-
}
|
|
1591
|
-
}
|
|
1592
|
-
} catch {
|
|
1593
|
-
}
|
|
1594
|
-
}
|
|
1595
|
-
if (buffer) {
|
|
1596
|
-
try {
|
|
1597
|
-
yield JSON.parse(buffer);
|
|
1598
|
-
} catch {
|
|
1599
|
-
}
|
|
1600
|
-
}
|
|
1601
|
-
} finally {
|
|
1602
|
-
reader.cancel().catch(() => {
|
|
1603
|
-
});
|
|
1604
|
-
}
|
|
1605
|
-
}
|
|
1606
|
-
/**
|
|
1607
|
-
* Watches legacy workflow transitions in real-time
|
|
1608
|
-
* @param runId - Optional run ID to filter the watch stream
|
|
1609
|
-
* @returns AsyncGenerator that yields parsed records from the legacy workflow watch stream
|
|
1610
|
-
*/
|
|
1611
|
-
async watch({ runId }, onRecord) {
|
|
1612
|
-
const response = await this.request(`/api/workflows/legacy/${this.workflowId}/watch?runId=${runId}`, {
|
|
1613
|
-
stream: true
|
|
1614
|
-
});
|
|
1615
|
-
if (!response.ok) {
|
|
1616
|
-
throw new Error(`Failed to watch legacy workflow: ${response.statusText}`);
|
|
1617
|
-
}
|
|
1618
|
-
if (!response.body) {
|
|
1619
|
-
throw new Error("Response body is null");
|
|
1620
|
-
}
|
|
1621
|
-
for await (const record of this.streamProcessor(response.body)) {
|
|
1622
|
-
onRecord(record);
|
|
1623
|
-
}
|
|
1624
|
-
}
|
|
1625
|
-
};
|
|
1626
|
-
|
|
1627
1509
|
// src/resources/tool.ts
|
|
1628
1510
|
var Tool = class extends BaseResource {
|
|
1629
1511
|
constructor(options, toolId) {
|
|
@@ -1632,10 +1514,11 @@ var Tool = class extends BaseResource {
|
|
|
1632
1514
|
}
|
|
1633
1515
|
/**
|
|
1634
1516
|
* Retrieves details about the tool
|
|
1517
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1635
1518
|
* @returns Promise containing tool details including description and schemas
|
|
1636
1519
|
*/
|
|
1637
|
-
details() {
|
|
1638
|
-
return this.request(`/api/tools/${this.toolId}`);
|
|
1520
|
+
details(runtimeContext) {
|
|
1521
|
+
return this.request(`/api/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
|
|
1639
1522
|
}
|
|
1640
1523
|
/**
|
|
1641
1524
|
* Executes the tool with the provided parameters
|
|
@@ -1659,7 +1542,7 @@ var Tool = class extends BaseResource {
|
|
|
1659
1542
|
};
|
|
1660
1543
|
|
|
1661
1544
|
// src/resources/workflow.ts
|
|
1662
|
-
var
|
|
1545
|
+
var RECORD_SEPARATOR = "";
|
|
1663
1546
|
var Workflow = class extends BaseResource {
|
|
1664
1547
|
constructor(options, workflowId) {
|
|
1665
1548
|
super(options);
|
|
@@ -1683,7 +1566,7 @@ var Workflow = class extends BaseResource {
|
|
|
1683
1566
|
if (done && !value) continue;
|
|
1684
1567
|
try {
|
|
1685
1568
|
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
1686
|
-
const chunks = (buffer + decoded).split(
|
|
1569
|
+
const chunks = (buffer + decoded).split(RECORD_SEPARATOR);
|
|
1687
1570
|
buffer = chunks.pop() || "";
|
|
1688
1571
|
for (const chunk of chunks) {
|
|
1689
1572
|
if (chunk) {
|
|
@@ -1712,17 +1595,20 @@ var Workflow = class extends BaseResource {
|
|
|
1712
1595
|
}
|
|
1713
1596
|
/**
|
|
1714
1597
|
* Retrieves details about the workflow
|
|
1598
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1715
1599
|
* @returns Promise containing workflow details including steps and graphs
|
|
1716
1600
|
*/
|
|
1717
|
-
details() {
|
|
1718
|
-
return this.request(`/api/workflows/${this.workflowId}`);
|
|
1601
|
+
details(runtimeContext) {
|
|
1602
|
+
return this.request(`/api/workflows/${this.workflowId}${runtimeContextQueryString(runtimeContext)}`);
|
|
1719
1603
|
}
|
|
1720
1604
|
/**
|
|
1721
1605
|
* Retrieves all runs for a workflow
|
|
1722
1606
|
* @param params - Parameters for filtering runs
|
|
1607
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1723
1608
|
* @returns Promise containing workflow runs array
|
|
1724
1609
|
*/
|
|
1725
|
-
runs(params) {
|
|
1610
|
+
runs(params, runtimeContext) {
|
|
1611
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
1726
1612
|
const searchParams = new URLSearchParams();
|
|
1727
1613
|
if (params?.fromDate) {
|
|
1728
1614
|
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
@@ -1739,6 +1625,9 @@ var Workflow = class extends BaseResource {
|
|
|
1739
1625
|
if (params?.resourceId) {
|
|
1740
1626
|
searchParams.set("resourceId", params.resourceId);
|
|
1741
1627
|
}
|
|
1628
|
+
if (runtimeContextParam) {
|
|
1629
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
1630
|
+
}
|
|
1742
1631
|
if (searchParams.size) {
|
|
1743
1632
|
return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
|
|
1744
1633
|
} else {
|
|
@@ -1748,18 +1637,22 @@ var Workflow = class extends BaseResource {
|
|
|
1748
1637
|
/**
|
|
1749
1638
|
* Retrieves a specific workflow run by its ID
|
|
1750
1639
|
* @param runId - The ID of the workflow run to retrieve
|
|
1640
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1751
1641
|
* @returns Promise containing the workflow run details
|
|
1752
1642
|
*/
|
|
1753
|
-
runById(runId) {
|
|
1754
|
-
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}`);
|
|
1643
|
+
runById(runId, runtimeContext) {
|
|
1644
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}${runtimeContextQueryString(runtimeContext)}`);
|
|
1755
1645
|
}
|
|
1756
1646
|
/**
|
|
1757
1647
|
* Retrieves the execution result for a specific workflow run by its ID
|
|
1758
1648
|
* @param runId - The ID of the workflow run to retrieve the execution result for
|
|
1649
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1759
1650
|
* @returns Promise containing the workflow run execution result
|
|
1760
1651
|
*/
|
|
1761
|
-
runExecutionResult(runId) {
|
|
1762
|
-
return this.request(
|
|
1652
|
+
runExecutionResult(runId, runtimeContext) {
|
|
1653
|
+
return this.request(
|
|
1654
|
+
`/api/workflows/${this.workflowId}/runs/${runId}/execution-result${runtimeContextQueryString(runtimeContext)}`
|
|
1655
|
+
);
|
|
1763
1656
|
}
|
|
1764
1657
|
/**
|
|
1765
1658
|
* Cancels a specific workflow run by its ID
|
|
@@ -1782,27 +1675,83 @@ var Workflow = class extends BaseResource {
|
|
|
1782
1675
|
body: { event: params.event, data: params.data }
|
|
1783
1676
|
});
|
|
1784
1677
|
}
|
|
1678
|
+
/**
|
|
1679
|
+
* @deprecated Use createRunAsync() instead.
|
|
1680
|
+
* @throws {Error} Always throws an error directing users to use createRunAsync()
|
|
1681
|
+
*/
|
|
1682
|
+
async createRun(_params) {
|
|
1683
|
+
throw new Error(
|
|
1684
|
+
"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."
|
|
1685
|
+
);
|
|
1686
|
+
}
|
|
1785
1687
|
/**
|
|
1786
1688
|
* Creates a new workflow run
|
|
1787
1689
|
* @param params - Optional object containing the optional runId
|
|
1788
|
-
* @returns Promise containing the runId of the created run
|
|
1690
|
+
* @returns Promise containing the runId of the created run with methods to control execution
|
|
1789
1691
|
*/
|
|
1790
|
-
|
|
1692
|
+
async createRunAsync(params) {
|
|
1791
1693
|
const searchParams = new URLSearchParams();
|
|
1792
1694
|
if (!!params?.runId) {
|
|
1793
1695
|
searchParams.set("runId", params.runId);
|
|
1794
1696
|
}
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1697
|
+
const res = await this.request(
|
|
1698
|
+
`/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`,
|
|
1699
|
+
{
|
|
1700
|
+
method: "POST"
|
|
1701
|
+
}
|
|
1702
|
+
);
|
|
1703
|
+
const runId = res.runId;
|
|
1704
|
+
return {
|
|
1705
|
+
runId,
|
|
1706
|
+
start: async (p) => {
|
|
1707
|
+
return this.start({
|
|
1708
|
+
runId,
|
|
1709
|
+
inputData: p.inputData,
|
|
1710
|
+
runtimeContext: p.runtimeContext,
|
|
1711
|
+
tracingOptions: p.tracingOptions
|
|
1712
|
+
});
|
|
1713
|
+
},
|
|
1714
|
+
startAsync: async (p) => {
|
|
1715
|
+
return this.startAsync({
|
|
1716
|
+
runId,
|
|
1717
|
+
inputData: p.inputData,
|
|
1718
|
+
runtimeContext: p.runtimeContext,
|
|
1719
|
+
tracingOptions: p.tracingOptions
|
|
1720
|
+
});
|
|
1721
|
+
},
|
|
1722
|
+
watch: async (onRecord) => {
|
|
1723
|
+
return this.watch({ runId }, onRecord);
|
|
1724
|
+
},
|
|
1725
|
+
stream: async (p) => {
|
|
1726
|
+
return this.stream({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
|
|
1727
|
+
},
|
|
1728
|
+
resume: async (p) => {
|
|
1729
|
+
return this.resume({
|
|
1730
|
+
runId,
|
|
1731
|
+
step: p.step,
|
|
1732
|
+
resumeData: p.resumeData,
|
|
1733
|
+
runtimeContext: p.runtimeContext,
|
|
1734
|
+
tracingOptions: p.tracingOptions
|
|
1735
|
+
});
|
|
1736
|
+
},
|
|
1737
|
+
resumeAsync: async (p) => {
|
|
1738
|
+
return this.resumeAsync({
|
|
1739
|
+
runId,
|
|
1740
|
+
step: p.step,
|
|
1741
|
+
resumeData: p.resumeData,
|
|
1742
|
+
runtimeContext: p.runtimeContext,
|
|
1743
|
+
tracingOptions: p.tracingOptions
|
|
1744
|
+
});
|
|
1745
|
+
},
|
|
1746
|
+
resumeStreamVNext: async (p) => {
|
|
1747
|
+
return this.resumeStreamVNext({
|
|
1748
|
+
runId,
|
|
1749
|
+
step: p.step,
|
|
1750
|
+
resumeData: p.resumeData,
|
|
1751
|
+
runtimeContext: p.runtimeContext
|
|
1752
|
+
});
|
|
1753
|
+
}
|
|
1754
|
+
};
|
|
1806
1755
|
}
|
|
1807
1756
|
/**
|
|
1808
1757
|
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
@@ -1813,7 +1762,7 @@ var Workflow = class extends BaseResource {
|
|
|
1813
1762
|
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1814
1763
|
return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
|
|
1815
1764
|
method: "POST",
|
|
1816
|
-
body: { inputData: params?.inputData, runtimeContext }
|
|
1765
|
+
body: { inputData: params?.inputData, runtimeContext, tracingOptions: params.tracingOptions }
|
|
1817
1766
|
});
|
|
1818
1767
|
}
|
|
1819
1768
|
/**
|
|
@@ -1825,16 +1774,17 @@ var Workflow = class extends BaseResource {
|
|
|
1825
1774
|
step,
|
|
1826
1775
|
runId,
|
|
1827
1776
|
resumeData,
|
|
1777
|
+
tracingOptions,
|
|
1828
1778
|
...rest
|
|
1829
1779
|
}) {
|
|
1830
1780
|
const runtimeContext = parseClientRuntimeContext(rest.runtimeContext);
|
|
1831
1781
|
return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
|
|
1832
1782
|
method: "POST",
|
|
1833
|
-
stream: true,
|
|
1834
1783
|
body: {
|
|
1835
1784
|
step,
|
|
1836
1785
|
resumeData,
|
|
1837
|
-
runtimeContext
|
|
1786
|
+
runtimeContext,
|
|
1787
|
+
tracingOptions
|
|
1838
1788
|
}
|
|
1839
1789
|
});
|
|
1840
1790
|
}
|
|
@@ -1851,7 +1801,7 @@ var Workflow = class extends BaseResource {
|
|
|
1851
1801
|
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1852
1802
|
return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
1853
1803
|
method: "POST",
|
|
1854
|
-
body: { inputData: params.inputData, runtimeContext }
|
|
1804
|
+
body: { inputData: params.inputData, runtimeContext, tracingOptions: params.tracingOptions }
|
|
1855
1805
|
});
|
|
1856
1806
|
}
|
|
1857
1807
|
/**
|
|
@@ -1874,7 +1824,7 @@ var Workflow = class extends BaseResource {
|
|
|
1874
1824
|
}
|
|
1875
1825
|
);
|
|
1876
1826
|
if (!response.ok) {
|
|
1877
|
-
throw new Error(`Failed to stream
|
|
1827
|
+
throw new Error(`Failed to stream workflow: ${response.statusText}`);
|
|
1878
1828
|
}
|
|
1879
1829
|
if (!response.body) {
|
|
1880
1830
|
throw new Error("Response body is null");
|
|
@@ -1886,7 +1836,54 @@ var Workflow = class extends BaseResource {
|
|
|
1886
1836
|
async transform(chunk, controller) {
|
|
1887
1837
|
try {
|
|
1888
1838
|
const decoded = new TextDecoder().decode(chunk);
|
|
1889
|
-
const chunks = decoded.split(
|
|
1839
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
1840
|
+
for (const chunk2 of chunks) {
|
|
1841
|
+
if (chunk2) {
|
|
1842
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
1843
|
+
try {
|
|
1844
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
1845
|
+
controller.enqueue(parsedChunk);
|
|
1846
|
+
failedChunk = void 0;
|
|
1847
|
+
} catch {
|
|
1848
|
+
failedChunk = newChunk;
|
|
1849
|
+
}
|
|
1850
|
+
}
|
|
1851
|
+
}
|
|
1852
|
+
} catch {
|
|
1853
|
+
}
|
|
1854
|
+
}
|
|
1855
|
+
});
|
|
1856
|
+
return response.body.pipeThrough(transformStream);
|
|
1857
|
+
}
|
|
1858
|
+
/**
|
|
1859
|
+
* Observes workflow stream for a workflow run
|
|
1860
|
+
* @param params - Object containing the runId
|
|
1861
|
+
* @returns Promise containing the workflow execution results
|
|
1862
|
+
*/
|
|
1863
|
+
async observeStream(params) {
|
|
1864
|
+
const searchParams = new URLSearchParams();
|
|
1865
|
+
searchParams.set("runId", params.runId);
|
|
1866
|
+
const response = await this.request(
|
|
1867
|
+
`/api/workflows/${this.workflowId}/observe-stream?${searchParams.toString()}`,
|
|
1868
|
+
{
|
|
1869
|
+
method: "POST",
|
|
1870
|
+
stream: true
|
|
1871
|
+
}
|
|
1872
|
+
);
|
|
1873
|
+
if (!response.ok) {
|
|
1874
|
+
throw new Error(`Failed to observe workflow stream: ${response.statusText}`);
|
|
1875
|
+
}
|
|
1876
|
+
if (!response.body) {
|
|
1877
|
+
throw new Error("Response body is null");
|
|
1878
|
+
}
|
|
1879
|
+
let failedChunk = void 0;
|
|
1880
|
+
const transformStream = new TransformStream({
|
|
1881
|
+
start() {
|
|
1882
|
+
},
|
|
1883
|
+
async transform(chunk, controller) {
|
|
1884
|
+
try {
|
|
1885
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
1886
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
1890
1887
|
for (const chunk2 of chunks) {
|
|
1891
1888
|
if (chunk2) {
|
|
1892
1889
|
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
@@ -1920,7 +1917,7 @@ var Workflow = class extends BaseResource {
|
|
|
1920
1917
|
`/api/workflows/${this.workflowId}/streamVNext?${searchParams.toString()}`,
|
|
1921
1918
|
{
|
|
1922
1919
|
method: "POST",
|
|
1923
|
-
body: { inputData: params.inputData, runtimeContext },
|
|
1920
|
+
body: { inputData: params.inputData, runtimeContext, closeOnSuspend: params.closeOnSuspend },
|
|
1924
1921
|
stream: true
|
|
1925
1922
|
}
|
|
1926
1923
|
);
|
|
@@ -1937,7 +1934,7 @@ var Workflow = class extends BaseResource {
|
|
|
1937
1934
|
async transform(chunk, controller) {
|
|
1938
1935
|
try {
|
|
1939
1936
|
const decoded = new TextDecoder().decode(chunk);
|
|
1940
|
-
const chunks = decoded.split(
|
|
1937
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
1941
1938
|
for (const chunk2 of chunks) {
|
|
1942
1939
|
if (chunk2) {
|
|
1943
1940
|
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
@@ -1968,7 +1965,25 @@ var Workflow = class extends BaseResource {
|
|
|
1968
1965
|
body: {
|
|
1969
1966
|
step: params.step,
|
|
1970
1967
|
resumeData: params.resumeData,
|
|
1971
|
-
runtimeContext
|
|
1968
|
+
runtimeContext,
|
|
1969
|
+
tracingOptions: params.tracingOptions
|
|
1970
|
+
}
|
|
1971
|
+
});
|
|
1972
|
+
}
|
|
1973
|
+
/**
|
|
1974
|
+
* Resumes a suspended workflow step that uses streamVNext asynchronously and returns a promise that resolves when the workflow is complete
|
|
1975
|
+
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
1976
|
+
* @returns Promise containing the workflow resume results
|
|
1977
|
+
*/
|
|
1978
|
+
resumeStreamVNext(params) {
|
|
1979
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1980
|
+
return this.request(`/api/workflows/${this.workflowId}/resume-stream?runId=${params.runId}`, {
|
|
1981
|
+
method: "POST",
|
|
1982
|
+
body: {
|
|
1983
|
+
step: params.step,
|
|
1984
|
+
resumeData: params.resumeData,
|
|
1985
|
+
runtimeContext,
|
|
1986
|
+
tracingOptions: params.tracingOptions
|
|
1972
1987
|
}
|
|
1973
1988
|
});
|
|
1974
1989
|
}
|
|
@@ -2008,7 +2023,7 @@ var Workflow = class extends BaseResource {
|
|
|
2008
2023
|
async start(controller) {
|
|
2009
2024
|
try {
|
|
2010
2025
|
for await (const record of records) {
|
|
2011
|
-
const json = JSON.stringify(record) +
|
|
2026
|
+
const json = JSON.stringify(record) + RECORD_SEPARATOR;
|
|
2012
2027
|
controller.enqueue(encoder.encode(json));
|
|
2013
2028
|
}
|
|
2014
2029
|
controller.close();
|
|
@@ -2106,10 +2121,11 @@ var MCPTool = class extends BaseResource {
|
|
|
2106
2121
|
}
|
|
2107
2122
|
/**
|
|
2108
2123
|
* Retrieves details about this specific tool from the MCP server.
|
|
2124
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2109
2125
|
* @returns Promise containing the tool's information (name, description, schema).
|
|
2110
2126
|
*/
|
|
2111
|
-
details() {
|
|
2112
|
-
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}`);
|
|
2127
|
+
details(runtimeContext) {
|
|
2128
|
+
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
|
|
2113
2129
|
}
|
|
2114
2130
|
/**
|
|
2115
2131
|
* Executes this specific tool on the MCP server.
|
|
@@ -2130,7 +2146,7 @@ var MCPTool = class extends BaseResource {
|
|
|
2130
2146
|
};
|
|
2131
2147
|
|
|
2132
2148
|
// src/resources/agent-builder.ts
|
|
2133
|
-
var
|
|
2149
|
+
var RECORD_SEPARATOR2 = "";
|
|
2134
2150
|
var AgentBuilder = class extends BaseResource {
|
|
2135
2151
|
constructor(options, actionId) {
|
|
2136
2152
|
super(options);
|
|
@@ -2165,11 +2181,20 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2165
2181
|
};
|
|
2166
2182
|
}
|
|
2167
2183
|
}
|
|
2184
|
+
/**
|
|
2185
|
+
* @deprecated Use createRunAsync() instead.
|
|
2186
|
+
* @throws {Error} Always throws an error directing users to use createRunAsync()
|
|
2187
|
+
*/
|
|
2188
|
+
async createRun(_params) {
|
|
2189
|
+
throw new Error(
|
|
2190
|
+
"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."
|
|
2191
|
+
);
|
|
2192
|
+
}
|
|
2168
2193
|
/**
|
|
2169
2194
|
* Creates a new agent builder action run and returns the runId.
|
|
2170
2195
|
* This calls `/api/agent-builder/:actionId/create-run`.
|
|
2171
2196
|
*/
|
|
2172
|
-
async
|
|
2197
|
+
async createRunAsync(params) {
|
|
2173
2198
|
const searchParams = new URLSearchParams();
|
|
2174
2199
|
if (!!params?.runId) {
|
|
2175
2200
|
searchParams.set("runId", params.runId);
|
|
@@ -2179,14 +2204,6 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2179
2204
|
method: "POST"
|
|
2180
2205
|
});
|
|
2181
2206
|
}
|
|
2182
|
-
/**
|
|
2183
|
-
* Creates a new workflow run (alias for createRun)
|
|
2184
|
-
* @param params - Optional object containing the optional runId
|
|
2185
|
-
* @returns Promise containing the runId of the created run
|
|
2186
|
-
*/
|
|
2187
|
-
createRunAsync(params) {
|
|
2188
|
-
return this.createRun(params);
|
|
2189
|
-
}
|
|
2190
2207
|
/**
|
|
2191
2208
|
* Starts agent builder action asynchronously and waits for completion.
|
|
2192
2209
|
* This calls `/api/agent-builder/:actionId/start-async`.
|
|
@@ -2269,7 +2286,7 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2269
2286
|
if (done && !value) continue;
|
|
2270
2287
|
try {
|
|
2271
2288
|
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
2272
|
-
const chunks = (buffer + decoded).split(
|
|
2289
|
+
const chunks = (buffer + decoded).split(RECORD_SEPARATOR2);
|
|
2273
2290
|
buffer = chunks.pop() || "";
|
|
2274
2291
|
for (const chunk of chunks) {
|
|
2275
2292
|
if (chunk) {
|
|
@@ -2326,7 +2343,7 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2326
2343
|
async transform(chunk, controller) {
|
|
2327
2344
|
try {
|
|
2328
2345
|
const decoded = new TextDecoder().decode(chunk);
|
|
2329
|
-
const chunks = decoded.split(
|
|
2346
|
+
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
2330
2347
|
for (const chunk2 of chunks) {
|
|
2331
2348
|
if (chunk2) {
|
|
2332
2349
|
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
@@ -2375,7 +2392,7 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2375
2392
|
async transform(chunk, controller) {
|
|
2376
2393
|
try {
|
|
2377
2394
|
const decoded = new TextDecoder().decode(chunk);
|
|
2378
|
-
const chunks = decoded.split(
|
|
2395
|
+
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
2379
2396
|
for (const chunk2 of chunks) {
|
|
2380
2397
|
if (chunk2) {
|
|
2381
2398
|
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
@@ -2518,7 +2535,7 @@ var Observability = class extends BaseResource {
|
|
|
2518
2535
|
getTraces(params) {
|
|
2519
2536
|
const { pagination, filters } = params;
|
|
2520
2537
|
const { page, perPage, dateRange } = pagination || {};
|
|
2521
|
-
const { name, spanType } = filters || {};
|
|
2538
|
+
const { name, spanType, entityId, entityType } = filters || {};
|
|
2522
2539
|
const searchParams = new URLSearchParams();
|
|
2523
2540
|
if (page !== void 0) {
|
|
2524
2541
|
searchParams.set("page", String(page));
|
|
@@ -2532,6 +2549,10 @@ var Observability = class extends BaseResource {
|
|
|
2532
2549
|
if (spanType !== void 0) {
|
|
2533
2550
|
searchParams.set("spanType", String(spanType));
|
|
2534
2551
|
}
|
|
2552
|
+
if (entityId && entityType) {
|
|
2553
|
+
searchParams.set("entityId", entityId);
|
|
2554
|
+
searchParams.set("entityType", entityType);
|
|
2555
|
+
}
|
|
2535
2556
|
if (dateRange) {
|
|
2536
2557
|
const dateRangeStr = JSON.stringify({
|
|
2537
2558
|
start: dateRange.start instanceof Date ? dateRange.start.toISOString() : dateRange.start,
|
|
@@ -2542,6 +2563,31 @@ var Observability = class extends BaseResource {
|
|
|
2542
2563
|
const queryString = searchParams.toString();
|
|
2543
2564
|
return this.request(`/api/observability/traces${queryString ? `?${queryString}` : ""}`);
|
|
2544
2565
|
}
|
|
2566
|
+
/**
|
|
2567
|
+
* Retrieves scores by trace ID and span ID
|
|
2568
|
+
* @param params - Parameters containing trace ID, span ID, and pagination options
|
|
2569
|
+
* @returns Promise containing scores and pagination info
|
|
2570
|
+
*/
|
|
2571
|
+
getScoresBySpan(params) {
|
|
2572
|
+
const { traceId, spanId, page, perPage } = params;
|
|
2573
|
+
const searchParams = new URLSearchParams();
|
|
2574
|
+
if (page !== void 0) {
|
|
2575
|
+
searchParams.set("page", String(page));
|
|
2576
|
+
}
|
|
2577
|
+
if (perPage !== void 0) {
|
|
2578
|
+
searchParams.set("perPage", String(perPage));
|
|
2579
|
+
}
|
|
2580
|
+
const queryString = searchParams.toString();
|
|
2581
|
+
return this.request(
|
|
2582
|
+
`/api/observability/traces/${encodeURIComponent(traceId)}/${encodeURIComponent(spanId)}/scores${queryString ? `?${queryString}` : ""}`
|
|
2583
|
+
);
|
|
2584
|
+
}
|
|
2585
|
+
score(params) {
|
|
2586
|
+
return this.request(`/api/observability/traces/score`, {
|
|
2587
|
+
method: "POST",
|
|
2588
|
+
body: { ...params }
|
|
2589
|
+
});
|
|
2590
|
+
}
|
|
2545
2591
|
};
|
|
2546
2592
|
|
|
2547
2593
|
// src/resources/network-memory-thread.ts
|
|
@@ -2608,7 +2654,7 @@ var NetworkMemoryThread = class extends BaseResource {
|
|
|
2608
2654
|
};
|
|
2609
2655
|
|
|
2610
2656
|
// src/resources/vNextNetwork.ts
|
|
2611
|
-
var
|
|
2657
|
+
var RECORD_SEPARATOR3 = "";
|
|
2612
2658
|
var VNextNetwork = class extends BaseResource {
|
|
2613
2659
|
constructor(options, networkId) {
|
|
2614
2660
|
super(options);
|
|
@@ -2616,10 +2662,11 @@ var VNextNetwork = class extends BaseResource {
|
|
|
2616
2662
|
}
|
|
2617
2663
|
/**
|
|
2618
2664
|
* Retrieves details about the network
|
|
2665
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2619
2666
|
* @returns Promise containing vNext network details
|
|
2620
2667
|
*/
|
|
2621
|
-
details() {
|
|
2622
|
-
return this.request(`/api/networks/v-next/${this.networkId}`);
|
|
2668
|
+
details(runtimeContext) {
|
|
2669
|
+
return this.request(`/api/networks/v-next/${this.networkId}${runtimeContextQueryString(runtimeContext)}`);
|
|
2623
2670
|
}
|
|
2624
2671
|
/**
|
|
2625
2672
|
* Generates a response from the v-next network
|
|
@@ -2660,7 +2707,7 @@ var VNextNetwork = class extends BaseResource {
|
|
|
2660
2707
|
if (done && !value) continue;
|
|
2661
2708
|
try {
|
|
2662
2709
|
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
2663
|
-
const chunks = (buffer + decoded).split(
|
|
2710
|
+
const chunks = (buffer + decoded).split(RECORD_SEPARATOR3);
|
|
2664
2711
|
buffer = chunks.pop() || "";
|
|
2665
2712
|
for (const chunk of chunks) {
|
|
2666
2713
|
if (chunk) {
|
|
@@ -2754,10 +2801,17 @@ var MastraClient = class extends BaseResource {
|
|
|
2754
2801
|
}
|
|
2755
2802
|
/**
|
|
2756
2803
|
* Retrieves all available agents
|
|
2804
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2757
2805
|
* @returns Promise containing map of agent IDs to agent details
|
|
2758
2806
|
*/
|
|
2759
|
-
getAgents() {
|
|
2760
|
-
|
|
2807
|
+
getAgents(runtimeContext) {
|
|
2808
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
2809
|
+
const searchParams = new URLSearchParams();
|
|
2810
|
+
if (runtimeContextParam) {
|
|
2811
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
2812
|
+
}
|
|
2813
|
+
const queryString = searchParams.toString();
|
|
2814
|
+
return this.request(`/api/agents${queryString ? `?${queryString}` : ""}`);
|
|
2761
2815
|
}
|
|
2762
2816
|
/**
|
|
2763
2817
|
* Gets an agent instance by ID
|
|
@@ -2775,6 +2829,14 @@ var MastraClient = class extends BaseResource {
|
|
|
2775
2829
|
getMemoryThreads(params) {
|
|
2776
2830
|
return this.request(`/api/memory/threads?resourceid=${params.resourceId}&agentId=${params.agentId}`);
|
|
2777
2831
|
}
|
|
2832
|
+
/**
|
|
2833
|
+
* Retrieves memory config for a resource
|
|
2834
|
+
* @param params - Parameters containing the resource ID
|
|
2835
|
+
* @returns Promise containing array of memory threads
|
|
2836
|
+
*/
|
|
2837
|
+
getMemoryConfig(params) {
|
|
2838
|
+
return this.request(`/api/memory/config?agentId=${params.agentId}`);
|
|
2839
|
+
}
|
|
2778
2840
|
/**
|
|
2779
2841
|
* Creates a new memory thread
|
|
2780
2842
|
* @param params - Parameters for creating the memory thread
|
|
@@ -2791,6 +2853,24 @@ var MastraClient = class extends BaseResource {
|
|
|
2791
2853
|
getMemoryThread(threadId, agentId) {
|
|
2792
2854
|
return new MemoryThread(this.options, threadId, agentId);
|
|
2793
2855
|
}
|
|
2856
|
+
getThreadMessages(threadId, opts = {}) {
|
|
2857
|
+
let url = "";
|
|
2858
|
+
if (opts.agentId) {
|
|
2859
|
+
url = `/api/memory/threads/${threadId}/messages?agentId=${opts.agentId}`;
|
|
2860
|
+
} else if (opts.networkId) {
|
|
2861
|
+
url = `/api/memory/network/threads/${threadId}/messages?networkId=${opts.networkId}`;
|
|
2862
|
+
}
|
|
2863
|
+
return this.request(url);
|
|
2864
|
+
}
|
|
2865
|
+
deleteThread(threadId, opts = {}) {
|
|
2866
|
+
let url = "";
|
|
2867
|
+
if (opts.agentId) {
|
|
2868
|
+
url = `/api/memory/threads/${threadId}?agentId=${opts.agentId}`;
|
|
2869
|
+
} else if (opts.networkId) {
|
|
2870
|
+
url = `/api/memory/network/threads/${threadId}?networkId=${opts.networkId}`;
|
|
2871
|
+
}
|
|
2872
|
+
return this.request(url, { method: "DELETE" });
|
|
2873
|
+
}
|
|
2794
2874
|
/**
|
|
2795
2875
|
* Saves messages to memory
|
|
2796
2876
|
* @param params - Parameters containing messages to save
|
|
@@ -2853,10 +2933,17 @@ var MastraClient = class extends BaseResource {
|
|
|
2853
2933
|
}
|
|
2854
2934
|
/**
|
|
2855
2935
|
* Retrieves all available tools
|
|
2936
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2856
2937
|
* @returns Promise containing map of tool IDs to tool details
|
|
2857
2938
|
*/
|
|
2858
|
-
getTools() {
|
|
2859
|
-
|
|
2939
|
+
getTools(runtimeContext) {
|
|
2940
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
2941
|
+
const searchParams = new URLSearchParams();
|
|
2942
|
+
if (runtimeContextParam) {
|
|
2943
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
2944
|
+
}
|
|
2945
|
+
const queryString = searchParams.toString();
|
|
2946
|
+
return this.request(`/api/tools${queryString ? `?${queryString}` : ""}`);
|
|
2860
2947
|
}
|
|
2861
2948
|
/**
|
|
2862
2949
|
* Gets a tool instance by ID
|
|
@@ -2866,27 +2953,19 @@ var MastraClient = class extends BaseResource {
|
|
|
2866
2953
|
getTool(toolId) {
|
|
2867
2954
|
return new Tool(this.options, toolId);
|
|
2868
2955
|
}
|
|
2869
|
-
/**
|
|
2870
|
-
* Retrieves all available legacy workflows
|
|
2871
|
-
* @returns Promise containing map of legacy workflow IDs to legacy workflow details
|
|
2872
|
-
*/
|
|
2873
|
-
getLegacyWorkflows() {
|
|
2874
|
-
return this.request("/api/workflows/legacy");
|
|
2875
|
-
}
|
|
2876
|
-
/**
|
|
2877
|
-
* Gets a legacy workflow instance by ID
|
|
2878
|
-
* @param workflowId - ID of the legacy workflow to retrieve
|
|
2879
|
-
* @returns Legacy Workflow instance
|
|
2880
|
-
*/
|
|
2881
|
-
getLegacyWorkflow(workflowId) {
|
|
2882
|
-
return new LegacyWorkflow(this.options, workflowId);
|
|
2883
|
-
}
|
|
2884
2956
|
/**
|
|
2885
2957
|
* Retrieves all available workflows
|
|
2958
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2886
2959
|
* @returns Promise containing map of workflow IDs to workflow details
|
|
2887
2960
|
*/
|
|
2888
|
-
getWorkflows() {
|
|
2889
|
-
|
|
2961
|
+
getWorkflows(runtimeContext) {
|
|
2962
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
2963
|
+
const searchParams = new URLSearchParams();
|
|
2964
|
+
if (runtimeContextParam) {
|
|
2965
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
2966
|
+
}
|
|
2967
|
+
const queryString = searchParams.toString();
|
|
2968
|
+
return this.request(`/api/workflows${queryString ? `?${queryString}` : ""}`);
|
|
2890
2969
|
}
|
|
2891
2970
|
/**
|
|
2892
2971
|
* Gets a workflow instance by ID
|
|
@@ -3054,13 +3133,6 @@ var MastraClient = class extends BaseResource {
|
|
|
3054
3133
|
return this.request(`/api/telemetry`);
|
|
3055
3134
|
}
|
|
3056
3135
|
}
|
|
3057
|
-
/**
|
|
3058
|
-
* Retrieves all available networks
|
|
3059
|
-
* @returns Promise containing map of network IDs to network details
|
|
3060
|
-
*/
|
|
3061
|
-
getNetworks() {
|
|
3062
|
-
return this.request("/api/networks");
|
|
3063
|
-
}
|
|
3064
3136
|
/**
|
|
3065
3137
|
* Retrieves all available vNext networks
|
|
3066
3138
|
* @returns Promise containing map of vNext network IDs to vNext network details
|
|
@@ -3068,14 +3140,6 @@ var MastraClient = class extends BaseResource {
|
|
|
3068
3140
|
getVNextNetworks() {
|
|
3069
3141
|
return this.request("/api/networks/v-next");
|
|
3070
3142
|
}
|
|
3071
|
-
/**
|
|
3072
|
-
* Gets a network instance by ID
|
|
3073
|
-
* @param networkId - ID of the network to retrieve
|
|
3074
|
-
* @returns Network instance
|
|
3075
|
-
*/
|
|
3076
|
-
getNetwork(networkId) {
|
|
3077
|
-
return new Network(this.options, networkId);
|
|
3078
|
-
}
|
|
3079
3143
|
/**
|
|
3080
3144
|
* Gets a vNext network instance by ID
|
|
3081
3145
|
* @param networkId - ID of the vNext network to retrieve
|
|
@@ -3188,7 +3252,7 @@ var MastraClient = class extends BaseResource {
|
|
|
3188
3252
|
* @returns Promise containing the scorer
|
|
3189
3253
|
*/
|
|
3190
3254
|
getScorer(scorerId) {
|
|
3191
|
-
return this.request(`/api/scores/scorers/${scorerId}`);
|
|
3255
|
+
return this.request(`/api/scores/scorers/${encodeURIComponent(scorerId)}`);
|
|
3192
3256
|
}
|
|
3193
3257
|
getScoresByScorerId(params) {
|
|
3194
3258
|
const { page, perPage, scorerId, entityId, entityType } = params;
|
|
@@ -3206,7 +3270,7 @@ var MastraClient = class extends BaseResource {
|
|
|
3206
3270
|
searchParams.set("perPage", String(perPage));
|
|
3207
3271
|
}
|
|
3208
3272
|
const queryString = searchParams.toString();
|
|
3209
|
-
return this.request(`/api/scores/scorer/${scorerId}${queryString ? `?${queryString}` : ""}`);
|
|
3273
|
+
return this.request(`/api/scores/scorer/${encodeURIComponent(scorerId)}${queryString ? `?${queryString}` : ""}`);
|
|
3210
3274
|
}
|
|
3211
3275
|
/**
|
|
3212
3276
|
* Retrieves scores by run ID
|
|
@@ -3223,7 +3287,7 @@ var MastraClient = class extends BaseResource {
|
|
|
3223
3287
|
searchParams.set("perPage", String(perPage));
|
|
3224
3288
|
}
|
|
3225
3289
|
const queryString = searchParams.toString();
|
|
3226
|
-
return this.request(`/api/scores/run/${runId}${queryString ? `?${queryString}` : ""}`);
|
|
3290
|
+
return this.request(`/api/scores/run/${encodeURIComponent(runId)}${queryString ? `?${queryString}` : ""}`);
|
|
3227
3291
|
}
|
|
3228
3292
|
/**
|
|
3229
3293
|
* Retrieves scores by entity ID and type
|
|
@@ -3240,7 +3304,9 @@ var MastraClient = class extends BaseResource {
|
|
|
3240
3304
|
searchParams.set("perPage", String(perPage));
|
|
3241
3305
|
}
|
|
3242
3306
|
const queryString = searchParams.toString();
|
|
3243
|
-
return this.request(
|
|
3307
|
+
return this.request(
|
|
3308
|
+
`/api/scores/entity/${encodeURIComponent(entityType)}/${encodeURIComponent(entityId)}${queryString ? `?${queryString}` : ""}`
|
|
3309
|
+
);
|
|
3244
3310
|
}
|
|
3245
3311
|
/**
|
|
3246
3312
|
* Saves a score
|
|
@@ -3266,8 +3332,33 @@ var MastraClient = class extends BaseResource {
|
|
|
3266
3332
|
getAITraces(params) {
|
|
3267
3333
|
return this.observability.getTraces(params);
|
|
3268
3334
|
}
|
|
3335
|
+
getScoresBySpan(params) {
|
|
3336
|
+
return this.observability.getScoresBySpan(params);
|
|
3337
|
+
}
|
|
3338
|
+
score(params) {
|
|
3339
|
+
return this.observability.score(params);
|
|
3340
|
+
}
|
|
3341
|
+
};
|
|
3342
|
+
|
|
3343
|
+
// src/tools.ts
|
|
3344
|
+
var ClientTool = class {
|
|
3345
|
+
id;
|
|
3346
|
+
description;
|
|
3347
|
+
inputSchema;
|
|
3348
|
+
outputSchema;
|
|
3349
|
+
execute;
|
|
3350
|
+
constructor(opts) {
|
|
3351
|
+
this.id = opts.id;
|
|
3352
|
+
this.description = opts.description;
|
|
3353
|
+
this.inputSchema = opts.inputSchema;
|
|
3354
|
+
this.outputSchema = opts.outputSchema;
|
|
3355
|
+
this.execute = opts.execute;
|
|
3356
|
+
}
|
|
3269
3357
|
};
|
|
3358
|
+
function createTool(opts) {
|
|
3359
|
+
return new ClientTool(opts);
|
|
3360
|
+
}
|
|
3270
3361
|
|
|
3271
|
-
export { MastraClient };
|
|
3362
|
+
export { ClientTool, MastraClient, createTool };
|
|
3272
3363
|
//# sourceMappingURL=index.js.map
|
|
3273
3364
|
//# sourceMappingURL=index.js.map
|