@mastra/client-js 0.0.0-iterate-traces-ui-again-20250912091900 → 0.0.0-just-snapshot-20251014192224
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 +380 -3
- package/README.md +6 -10
- package/dist/client.d.ts +35 -39
- package/dist/client.d.ts.map +1 -1
- package/dist/index.cjs +521 -606
- 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 +520 -607
- 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 +54 -36
- 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/vector.d.ts +5 -2
- package/dist/resources/vector.d.ts.map +1 -1
- package/dist/resources/workflow.d.ts +119 -19
- 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 +58 -48
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -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/resources/vNextNetwork.d.ts +0 -42
- package/dist/resources/vNextNetwork.d.ts.map +0 -1
package/dist/index.js
CHANGED
|
@@ -21,6 +21,14 @@ function base64RuntimeContext(runtimeContext) {
|
|
|
21
21
|
}
|
|
22
22
|
return void 0;
|
|
23
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
|
+
}
|
|
24
32
|
function isZodType(value) {
|
|
25
33
|
return typeof value === "object" && value !== null && "_def" in value && "parse" in value && typeof value.parse === "function" && "safeParse" in value && typeof value.safeParse === "function";
|
|
26
34
|
}
|
|
@@ -83,7 +91,7 @@ async function sharedProcessMastraStream({
|
|
|
83
91
|
if (line.startsWith("data: ")) {
|
|
84
92
|
const data = line.slice(6);
|
|
85
93
|
if (data === "[DONE]") {
|
|
86
|
-
console.
|
|
94
|
+
console.info("\u{1F3C1} Stream finished");
|
|
87
95
|
return;
|
|
88
96
|
}
|
|
89
97
|
try {
|
|
@@ -205,7 +213,9 @@ async function executeToolCallAndRespond({
|
|
|
205
213
|
resourceId,
|
|
206
214
|
threadId,
|
|
207
215
|
runtimeContext,
|
|
208
|
-
tracingContext: { currentSpan: void 0 }
|
|
216
|
+
tracingContext: { currentSpan: void 0 },
|
|
217
|
+
suspend: async () => {
|
|
218
|
+
}
|
|
209
219
|
},
|
|
210
220
|
{
|
|
211
221
|
messages: response.messages,
|
|
@@ -213,11 +223,7 @@ async function executeToolCallAndRespond({
|
|
|
213
223
|
}
|
|
214
224
|
);
|
|
215
225
|
const updatedMessages = [
|
|
216
|
-
|
|
217
|
-
role: "user",
|
|
218
|
-
content: params.messages
|
|
219
|
-
},
|
|
220
|
-
...response.response.messages,
|
|
226
|
+
...response.response.messages || [],
|
|
221
227
|
{
|
|
222
228
|
role: "tool",
|
|
223
229
|
content: [
|
|
@@ -280,30 +286,20 @@ var AgentVoice = class extends BaseResource {
|
|
|
280
286
|
/**
|
|
281
287
|
* Get available speakers for the agent's voice provider
|
|
282
288
|
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
289
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
283
290
|
* @returns Promise containing list of available speakers
|
|
284
291
|
*/
|
|
285
292
|
getSpeakers(runtimeContext) {
|
|
286
|
-
|
|
287
|
-
const searchParams = new URLSearchParams();
|
|
288
|
-
if (runtimeContextParam) {
|
|
289
|
-
searchParams.set("runtimeContext", runtimeContextParam);
|
|
290
|
-
}
|
|
291
|
-
const queryString = searchParams.toString();
|
|
292
|
-
return this.request(`/api/agents/${this.agentId}/voice/speakers${queryString ? `?${queryString}` : ""}`);
|
|
293
|
+
return this.request(`/api/agents/${this.agentId}/voice/speakers${runtimeContextQueryString(runtimeContext)}`);
|
|
293
294
|
}
|
|
294
295
|
/**
|
|
295
296
|
* Get the listener configuration for the agent's voice provider
|
|
296
297
|
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
298
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
297
299
|
* @returns Promise containing a check if the agent has listening capabilities
|
|
298
300
|
*/
|
|
299
301
|
getListener(runtimeContext) {
|
|
300
|
-
|
|
301
|
-
const searchParams = new URLSearchParams();
|
|
302
|
-
if (runtimeContextParam) {
|
|
303
|
-
searchParams.set("runtimeContext", runtimeContextParam);
|
|
304
|
-
}
|
|
305
|
-
const queryString = searchParams.toString();
|
|
306
|
-
return this.request(`/api/agents/${this.agentId}/voice/listener${queryString ? `?${queryString}` : ""}`);
|
|
302
|
+
return this.request(`/api/agents/${this.agentId}/voice/listener${runtimeContextQueryString(runtimeContext)}`);
|
|
307
303
|
}
|
|
308
304
|
};
|
|
309
305
|
var Agent = class extends BaseResource {
|
|
@@ -315,23 +311,11 @@ var Agent = class extends BaseResource {
|
|
|
315
311
|
voice;
|
|
316
312
|
/**
|
|
317
313
|
* Retrieves details about the agent
|
|
318
|
-
* @param runtimeContext -
|
|
314
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
319
315
|
* @returns Promise containing agent details including model and instructions
|
|
320
316
|
*/
|
|
321
317
|
details(runtimeContext) {
|
|
322
|
-
|
|
323
|
-
const searchParams = new URLSearchParams();
|
|
324
|
-
if (runtimeContextParam) {
|
|
325
|
-
searchParams.set("runtimeContext", runtimeContextParam);
|
|
326
|
-
}
|
|
327
|
-
const queryString = searchParams.toString();
|
|
328
|
-
return this.request(`/api/agents/${this.agentId}${queryString ? `?${queryString}` : ""}`);
|
|
329
|
-
}
|
|
330
|
-
async generate(params) {
|
|
331
|
-
console.warn(
|
|
332
|
-
"Deprecation NOTICE:Generate method will switch to use generateVNext implementation September 23rd, 2025. Please use generateLegacy if you don't want to upgrade just yet."
|
|
333
|
-
);
|
|
334
|
-
return this.generateLegacy(params);
|
|
318
|
+
return this.request(`/api/agents/${this.agentId}${runtimeContextQueryString(runtimeContext)}`);
|
|
335
319
|
}
|
|
336
320
|
async generateLegacy(params) {
|
|
337
321
|
const processedParams = {
|
|
@@ -364,7 +348,9 @@ var Agent = class extends BaseResource {
|
|
|
364
348
|
resourceId,
|
|
365
349
|
threadId,
|
|
366
350
|
runtimeContext,
|
|
367
|
-
tracingContext: { currentSpan: void 0 }
|
|
351
|
+
tracingContext: { currentSpan: void 0 },
|
|
352
|
+
suspend: async () => {
|
|
353
|
+
}
|
|
368
354
|
},
|
|
369
355
|
{
|
|
370
356
|
messages: response.messages,
|
|
@@ -372,10 +358,6 @@ var Agent = class extends BaseResource {
|
|
|
372
358
|
}
|
|
373
359
|
);
|
|
374
360
|
const updatedMessages = [
|
|
375
|
-
{
|
|
376
|
-
role: "user",
|
|
377
|
-
content: params.messages
|
|
378
|
-
},
|
|
379
361
|
...response.response.messages,
|
|
380
362
|
{
|
|
381
363
|
role: "tool",
|
|
@@ -398,7 +380,16 @@ var Agent = class extends BaseResource {
|
|
|
398
380
|
}
|
|
399
381
|
return response;
|
|
400
382
|
}
|
|
401
|
-
async
|
|
383
|
+
async generate(messagesOrParams, options) {
|
|
384
|
+
let params;
|
|
385
|
+
if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
|
|
386
|
+
params = messagesOrParams;
|
|
387
|
+
} else {
|
|
388
|
+
params = {
|
|
389
|
+
messages: messagesOrParams,
|
|
390
|
+
...options
|
|
391
|
+
};
|
|
392
|
+
}
|
|
402
393
|
const processedParams = {
|
|
403
394
|
...params,
|
|
404
395
|
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
@@ -411,7 +402,7 @@ var Agent = class extends BaseResource {
|
|
|
411
402
|
};
|
|
412
403
|
const { runId, resourceId, threadId, runtimeContext } = processedParams;
|
|
413
404
|
const response = await this.request(
|
|
414
|
-
`/api/agents/${this.agentId}/generate
|
|
405
|
+
`/api/agents/${this.agentId}/generate`,
|
|
415
406
|
{
|
|
416
407
|
method: "POST",
|
|
417
408
|
body: processedParams
|
|
@@ -425,7 +416,7 @@ var Agent = class extends BaseResource {
|
|
|
425
416
|
resourceId,
|
|
426
417
|
threadId,
|
|
427
418
|
runtimeContext,
|
|
428
|
-
respondFn: this.
|
|
419
|
+
respondFn: this.generate.bind(this)
|
|
429
420
|
});
|
|
430
421
|
}
|
|
431
422
|
return response;
|
|
@@ -692,17 +683,6 @@ var Agent = class extends BaseResource {
|
|
|
692
683
|
});
|
|
693
684
|
onFinish?.({ message, finishReason, usage });
|
|
694
685
|
}
|
|
695
|
-
/**
|
|
696
|
-
* Streams a response from the agent
|
|
697
|
-
* @param params - Stream parameters including prompt
|
|
698
|
-
* @returns Promise containing the enhanced Response object with processDataStream method
|
|
699
|
-
*/
|
|
700
|
-
async stream(params) {
|
|
701
|
-
console.warn(
|
|
702
|
-
"Deprecation NOTICE:\nStream method will switch to use streamVNext implementation September 23rd, 2025. Please use streamLegacy if you don't want to upgrade just yet."
|
|
703
|
-
);
|
|
704
|
-
return this.streamLegacy(params);
|
|
705
|
-
}
|
|
706
686
|
/**
|
|
707
687
|
* Streams a response from the agent
|
|
708
688
|
* @param params - Stream parameters including prompt
|
|
@@ -717,7 +697,7 @@ var Agent = class extends BaseResource {
|
|
|
717
697
|
clientTools: processClientTools(params.clientTools)
|
|
718
698
|
};
|
|
719
699
|
const { readable, writable } = new TransformStream();
|
|
720
|
-
const response = await this.
|
|
700
|
+
const response = await this.processStreamResponseLegacy(processedParams, writable);
|
|
721
701
|
const streamResponse = new Response(readable, {
|
|
722
702
|
status: response.status,
|
|
723
703
|
statusText: response.statusText,
|
|
@@ -804,6 +784,14 @@ var Agent = class extends BaseResource {
|
|
|
804
784
|
// but this is completely wrong and this fn is probably broken. Remove ":any" and you'll see a bunch of type errors
|
|
805
785
|
onChunk: async (chunk) => {
|
|
806
786
|
switch (chunk.type) {
|
|
787
|
+
case "tripwire": {
|
|
788
|
+
message.parts.push({
|
|
789
|
+
type: "text",
|
|
790
|
+
text: chunk.payload.tripwireReason
|
|
791
|
+
});
|
|
792
|
+
execUpdate();
|
|
793
|
+
break;
|
|
794
|
+
}
|
|
807
795
|
case "step-start": {
|
|
808
796
|
if (!replaceLastMessage) {
|
|
809
797
|
message.id = chunk.payload.messageId;
|
|
@@ -984,8 +972,8 @@ var Agent = class extends BaseResource {
|
|
|
984
972
|
});
|
|
985
973
|
onFinish?.({ message, finishReason, usage });
|
|
986
974
|
}
|
|
987
|
-
async
|
|
988
|
-
const response = await this.request(`/api/agents/${this.agentId}/stream
|
|
975
|
+
async processStreamResponse(processedParams, writable) {
|
|
976
|
+
const response = await this.request(`/api/agents/${this.agentId}/stream`, {
|
|
989
977
|
method: "POST",
|
|
990
978
|
body: processedParams,
|
|
991
979
|
stream: true
|
|
@@ -1000,18 +988,17 @@ var Agent = class extends BaseResource {
|
|
|
1000
988
|
streamForWritable.pipeTo(
|
|
1001
989
|
new WritableStream({
|
|
1002
990
|
async write(chunk) {
|
|
991
|
+
let writer;
|
|
1003
992
|
try {
|
|
993
|
+
writer = writable.getWriter();
|
|
1004
994
|
const text = new TextDecoder().decode(chunk);
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
995
|
+
const lines = text.split("\n\n");
|
|
996
|
+
const readableLines = lines.filter((line) => line !== "[DONE]").join("\n\n");
|
|
997
|
+
await writer.write(new TextEncoder().encode(readableLines));
|
|
1008
998
|
} catch {
|
|
1009
|
-
|
|
1010
|
-
const writer = writable.getWriter();
|
|
1011
|
-
try {
|
|
1012
|
-
await writer.write(chunk);
|
|
999
|
+
await writer?.write(chunk);
|
|
1013
1000
|
} finally {
|
|
1014
|
-
writer
|
|
1001
|
+
writer?.releaseLock();
|
|
1015
1002
|
}
|
|
1016
1003
|
}
|
|
1017
1004
|
}),
|
|
@@ -1037,9 +1024,11 @@ var Agent = class extends BaseResource {
|
|
|
1037
1024
|
if (toolCall) {
|
|
1038
1025
|
toolCalls.push(toolCall);
|
|
1039
1026
|
}
|
|
1027
|
+
let shouldExecuteClientTool = false;
|
|
1040
1028
|
for (const toolCall2 of toolCalls) {
|
|
1041
1029
|
const clientTool = processedParams.clientTools?.[toolCall2.toolName];
|
|
1042
1030
|
if (clientTool && clientTool.execute) {
|
|
1031
|
+
shouldExecuteClientTool = true;
|
|
1043
1032
|
const result = await clientTool.execute(
|
|
1044
1033
|
{
|
|
1045
1034
|
context: toolCall2?.args,
|
|
@@ -1048,7 +1037,9 @@ var Agent = class extends BaseResource {
|
|
|
1048
1037
|
threadId: processedParams.threadId,
|
|
1049
1038
|
runtimeContext: processedParams.runtimeContext,
|
|
1050
1039
|
// TODO: Pass proper tracing context when client-js supports tracing
|
|
1051
|
-
tracingContext: { currentSpan: void 0 }
|
|
1040
|
+
tracingContext: { currentSpan: void 0 },
|
|
1041
|
+
suspend: async () => {
|
|
1042
|
+
}
|
|
1052
1043
|
},
|
|
1053
1044
|
{
|
|
1054
1045
|
messages: response.messages,
|
|
@@ -1074,10 +1065,8 @@ var Agent = class extends BaseResource {
|
|
|
1074
1065
|
toolInvocation.state = "result";
|
|
1075
1066
|
toolInvocation.result = result;
|
|
1076
1067
|
}
|
|
1077
|
-
const
|
|
1078
|
-
|
|
1079
|
-
const updatedMessages = lastMessage != null ? [...messageArray, ...messages.filter((m) => m.id !== lastMessage.id), lastMessage] : [...messageArray, ...messages];
|
|
1080
|
-
this.processStreamResponse_vNext(
|
|
1068
|
+
const updatedMessages = lastMessage != null ? [...messages.filter((m) => m.id !== lastMessage.id), lastMessage] : [...messages];
|
|
1069
|
+
this.processStreamResponse(
|
|
1081
1070
|
{
|
|
1082
1071
|
...processedParams,
|
|
1083
1072
|
messages: updatedMessages
|
|
@@ -1088,6 +1077,11 @@ var Agent = class extends BaseResource {
|
|
|
1088
1077
|
});
|
|
1089
1078
|
}
|
|
1090
1079
|
}
|
|
1080
|
+
if (!shouldExecuteClientTool) {
|
|
1081
|
+
setTimeout(() => {
|
|
1082
|
+
writable.close();
|
|
1083
|
+
}, 0);
|
|
1084
|
+
}
|
|
1091
1085
|
} else {
|
|
1092
1086
|
setTimeout(() => {
|
|
1093
1087
|
writable.close();
|
|
@@ -1127,7 +1121,16 @@ var Agent = class extends BaseResource {
|
|
|
1127
1121
|
};
|
|
1128
1122
|
return streamResponse;
|
|
1129
1123
|
}
|
|
1130
|
-
async
|
|
1124
|
+
async stream(messagesOrParams, options) {
|
|
1125
|
+
let params;
|
|
1126
|
+
if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
|
|
1127
|
+
params = messagesOrParams;
|
|
1128
|
+
} else {
|
|
1129
|
+
params = {
|
|
1130
|
+
messages: messagesOrParams,
|
|
1131
|
+
...options
|
|
1132
|
+
};
|
|
1133
|
+
}
|
|
1131
1134
|
const processedParams = {
|
|
1132
1135
|
...params,
|
|
1133
1136
|
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
@@ -1139,7 +1142,7 @@ var Agent = class extends BaseResource {
|
|
|
1139
1142
|
} : void 0
|
|
1140
1143
|
};
|
|
1141
1144
|
const { readable, writable } = new TransformStream();
|
|
1142
|
-
const response = await this.
|
|
1145
|
+
const response = await this.processStreamResponse(processedParams, writable);
|
|
1143
1146
|
const streamResponse = new Response(readable, {
|
|
1144
1147
|
status: response.status,
|
|
1145
1148
|
statusText: response.statusText,
|
|
@@ -1158,7 +1161,7 @@ var Agent = class extends BaseResource {
|
|
|
1158
1161
|
/**
|
|
1159
1162
|
* Processes the stream response and handles tool calls
|
|
1160
1163
|
*/
|
|
1161
|
-
async
|
|
1164
|
+
async processStreamResponseLegacy(processedParams, writable) {
|
|
1162
1165
|
const response = await this.request(`/api/agents/${this.agentId}/stream-legacy`, {
|
|
1163
1166
|
method: "POST",
|
|
1164
1167
|
body: processedParams,
|
|
@@ -1203,7 +1206,9 @@ var Agent = class extends BaseResource {
|
|
|
1203
1206
|
threadId: processedParams.threadId,
|
|
1204
1207
|
runtimeContext: processedParams.runtimeContext,
|
|
1205
1208
|
// TODO: Pass proper tracing context when client-js supports tracing
|
|
1206
|
-
tracingContext: { currentSpan: void 0 }
|
|
1209
|
+
tracingContext: { currentSpan: void 0 },
|
|
1210
|
+
suspend: async () => {
|
|
1211
|
+
}
|
|
1207
1212
|
},
|
|
1208
1213
|
{
|
|
1209
1214
|
messages: response.messages,
|
|
@@ -1241,12 +1246,10 @@ var Agent = class extends BaseResource {
|
|
|
1241
1246
|
} finally {
|
|
1242
1247
|
writer.releaseLock();
|
|
1243
1248
|
}
|
|
1244
|
-
|
|
1245
|
-
const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
|
|
1246
|
-
this.processStreamResponse(
|
|
1249
|
+
this.processStreamResponseLegacy(
|
|
1247
1250
|
{
|
|
1248
1251
|
...processedParams,
|
|
1249
|
-
messages: [...
|
|
1252
|
+
messages: [...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
|
|
1250
1253
|
},
|
|
1251
1254
|
writable
|
|
1252
1255
|
).catch((error) => {
|
|
@@ -1276,13 +1279,7 @@ var Agent = class extends BaseResource {
|
|
|
1276
1279
|
* @returns Promise containing tool details
|
|
1277
1280
|
*/
|
|
1278
1281
|
getTool(toolId, runtimeContext) {
|
|
1279
|
-
|
|
1280
|
-
const searchParams = new URLSearchParams();
|
|
1281
|
-
if (runtimeContextParam) {
|
|
1282
|
-
searchParams.set("runtimeContext", runtimeContextParam);
|
|
1283
|
-
}
|
|
1284
|
-
const queryString = searchParams.toString();
|
|
1285
|
-
return this.request(`/api/agents/${this.agentId}/tools/${toolId}${queryString ? `?${queryString}` : ""}`);
|
|
1282
|
+
return this.request(`/api/agents/${this.agentId}/tools/${toolId}${runtimeContextQueryString(runtimeContext)}`);
|
|
1286
1283
|
}
|
|
1287
1284
|
/**
|
|
1288
1285
|
* Executes a tool for the agent
|
|
@@ -1306,13 +1303,7 @@ var Agent = class extends BaseResource {
|
|
|
1306
1303
|
* @returns Promise containing agent evaluations
|
|
1307
1304
|
*/
|
|
1308
1305
|
evals(runtimeContext) {
|
|
1309
|
-
|
|
1310
|
-
const searchParams = new URLSearchParams();
|
|
1311
|
-
if (runtimeContextParam) {
|
|
1312
|
-
searchParams.set("runtimeContext", runtimeContextParam);
|
|
1313
|
-
}
|
|
1314
|
-
const queryString = searchParams.toString();
|
|
1315
|
-
return this.request(`/api/agents/${this.agentId}/evals/ci${queryString ? `?${queryString}` : ""}`);
|
|
1306
|
+
return this.request(`/api/agents/${this.agentId}/evals/ci${runtimeContextQueryString(runtimeContext)}`);
|
|
1316
1307
|
}
|
|
1317
1308
|
/**
|
|
1318
1309
|
* Retrieves live evaluation results for the agent
|
|
@@ -1320,13 +1311,7 @@ var Agent = class extends BaseResource {
|
|
|
1320
1311
|
* @returns Promise containing live agent evaluations
|
|
1321
1312
|
*/
|
|
1322
1313
|
liveEvals(runtimeContext) {
|
|
1323
|
-
|
|
1324
|
-
const searchParams = new URLSearchParams();
|
|
1325
|
-
if (runtimeContextParam) {
|
|
1326
|
-
searchParams.set("runtimeContext", runtimeContextParam);
|
|
1327
|
-
}
|
|
1328
|
-
const queryString = searchParams.toString();
|
|
1329
|
-
return this.request(`/api/agents/${this.agentId}/evals/live${queryString ? `?${queryString}` : ""}`);
|
|
1314
|
+
return this.request(`/api/agents/${this.agentId}/evals/live${runtimeContextQueryString(runtimeContext)}`);
|
|
1330
1315
|
}
|
|
1331
1316
|
/**
|
|
1332
1317
|
* Updates the model for the agent
|
|
@@ -1339,61 +1324,33 @@ var Agent = class extends BaseResource {
|
|
|
1339
1324
|
body: params
|
|
1340
1325
|
});
|
|
1341
1326
|
}
|
|
1342
|
-
};
|
|
1343
|
-
var Network = class extends BaseResource {
|
|
1344
|
-
constructor(options, networkId) {
|
|
1345
|
-
super(options);
|
|
1346
|
-
this.networkId = networkId;
|
|
1347
|
-
}
|
|
1348
1327
|
/**
|
|
1349
|
-
*
|
|
1350
|
-
* @
|
|
1351
|
-
|
|
1352
|
-
details() {
|
|
1353
|
-
return this.request(`/api/networks/${this.networkId}`);
|
|
1354
|
-
}
|
|
1355
|
-
/**
|
|
1356
|
-
* Generates a response from the agent
|
|
1357
|
-
* @param params - Generation parameters including prompt
|
|
1358
|
-
* @returns Promise containing the generated response
|
|
1328
|
+
* Updates the model for the agent in the model list
|
|
1329
|
+
* @param params - Parameters for updating the model
|
|
1330
|
+
* @returns Promise containing the updated model
|
|
1359
1331
|
*/
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
...params,
|
|
1363
|
-
output: zodToJsonSchema(params.output),
|
|
1364
|
-
experimental_output: zodToJsonSchema(params.experimental_output)
|
|
1365
|
-
};
|
|
1366
|
-
return this.request(`/api/networks/${this.networkId}/generate`, {
|
|
1332
|
+
updateModelInModelList({ modelConfigId, ...params }) {
|
|
1333
|
+
return this.request(`/api/agents/${this.agentId}/models/${modelConfigId}`, {
|
|
1367
1334
|
method: "POST",
|
|
1368
|
-
body:
|
|
1335
|
+
body: params
|
|
1369
1336
|
});
|
|
1370
1337
|
}
|
|
1371
1338
|
/**
|
|
1372
|
-
*
|
|
1373
|
-
* @param params -
|
|
1374
|
-
* @returns Promise containing the
|
|
1339
|
+
* Reorders the models for the agent
|
|
1340
|
+
* @param params - Parameters for reordering the model list
|
|
1341
|
+
* @returns Promise containing the updated model list
|
|
1375
1342
|
*/
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
...params,
|
|
1379
|
-
output: zodToJsonSchema(params.output),
|
|
1380
|
-
experimental_output: zodToJsonSchema(params.experimental_output)
|
|
1381
|
-
};
|
|
1382
|
-
const response = await this.request(`/api/networks/${this.networkId}/stream`, {
|
|
1343
|
+
reorderModelList(params) {
|
|
1344
|
+
return this.request(`/api/agents/${this.agentId}/models/reorder`, {
|
|
1383
1345
|
method: "POST",
|
|
1384
|
-
body:
|
|
1385
|
-
stream: true
|
|
1346
|
+
body: params
|
|
1386
1347
|
});
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
...options
|
|
1394
|
-
});
|
|
1395
|
-
};
|
|
1396
|
-
return response;
|
|
1348
|
+
}
|
|
1349
|
+
async generateVNext(_messagesOrParams, _options) {
|
|
1350
|
+
throw new Error("generateVNext has been renamed to generate. Please use generate instead.");
|
|
1351
|
+
}
|
|
1352
|
+
async streamVNext(_messagesOrParams, _options) {
|
|
1353
|
+
throw new Error("streamVNext has been renamed to stream. Please use stream instead.");
|
|
1397
1354
|
}
|
|
1398
1355
|
};
|
|
1399
1356
|
|
|
@@ -1484,10 +1441,13 @@ var Vector = class extends BaseResource {
|
|
|
1484
1441
|
/**
|
|
1485
1442
|
* Retrieves details about a specific vector index
|
|
1486
1443
|
* @param indexName - Name of the index to get details for
|
|
1444
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1487
1445
|
* @returns Promise containing vector index details
|
|
1488
1446
|
*/
|
|
1489
|
-
details(indexName) {
|
|
1490
|
-
return this.request(
|
|
1447
|
+
details(indexName, runtimeContext) {
|
|
1448
|
+
return this.request(
|
|
1449
|
+
`/api/vector/${this.vectorName}/indexes/${indexName}${runtimeContextQueryString(runtimeContext)}`
|
|
1450
|
+
);
|
|
1491
1451
|
}
|
|
1492
1452
|
/**
|
|
1493
1453
|
* Deletes a vector index
|
|
@@ -1501,10 +1461,11 @@ var Vector = class extends BaseResource {
|
|
|
1501
1461
|
}
|
|
1502
1462
|
/**
|
|
1503
1463
|
* Retrieves a list of all available indexes
|
|
1464
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1504
1465
|
* @returns Promise containing array of index names
|
|
1505
1466
|
*/
|
|
1506
|
-
getIndexes() {
|
|
1507
|
-
return this.request(`/api/vector/${this.vectorName}/indexes`);
|
|
1467
|
+
getIndexes(runtimeContext) {
|
|
1468
|
+
return this.request(`/api/vector/${this.vectorName}/indexes${runtimeContextQueryString(runtimeContext)}`);
|
|
1508
1469
|
}
|
|
1509
1470
|
/**
|
|
1510
1471
|
* Creates a new vector index
|
|
@@ -1541,123 +1502,50 @@ var Vector = class extends BaseResource {
|
|
|
1541
1502
|
}
|
|
1542
1503
|
};
|
|
1543
1504
|
|
|
1544
|
-
// src/resources/
|
|
1545
|
-
var
|
|
1546
|
-
|
|
1547
|
-
constructor(options, workflowId) {
|
|
1505
|
+
// src/resources/tool.ts
|
|
1506
|
+
var Tool = class extends BaseResource {
|
|
1507
|
+
constructor(options, toolId) {
|
|
1548
1508
|
super(options);
|
|
1549
|
-
this.
|
|
1550
|
-
}
|
|
1551
|
-
/**
|
|
1552
|
-
* Retrieves details about the legacy workflow
|
|
1553
|
-
* @returns Promise containing legacy workflow details including steps and graphs
|
|
1554
|
-
*/
|
|
1555
|
-
details() {
|
|
1556
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}`);
|
|
1557
|
-
}
|
|
1558
|
-
/**
|
|
1559
|
-
* Retrieves all runs for a legacy workflow
|
|
1560
|
-
* @param params - Parameters for filtering runs
|
|
1561
|
-
* @returns Promise containing legacy workflow runs array
|
|
1562
|
-
*/
|
|
1563
|
-
runs(params) {
|
|
1564
|
-
const searchParams = new URLSearchParams();
|
|
1565
|
-
if (params?.fromDate) {
|
|
1566
|
-
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
1567
|
-
}
|
|
1568
|
-
if (params?.toDate) {
|
|
1569
|
-
searchParams.set("toDate", params.toDate.toISOString());
|
|
1570
|
-
}
|
|
1571
|
-
if (params?.limit) {
|
|
1572
|
-
searchParams.set("limit", String(params.limit));
|
|
1573
|
-
}
|
|
1574
|
-
if (params?.offset) {
|
|
1575
|
-
searchParams.set("offset", String(params.offset));
|
|
1576
|
-
}
|
|
1577
|
-
if (params?.resourceId) {
|
|
1578
|
-
searchParams.set("resourceId", params.resourceId);
|
|
1579
|
-
}
|
|
1580
|
-
if (searchParams.size) {
|
|
1581
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/runs?${searchParams}`);
|
|
1582
|
-
} else {
|
|
1583
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/runs`);
|
|
1584
|
-
}
|
|
1585
|
-
}
|
|
1586
|
-
/**
|
|
1587
|
-
* Creates a new legacy workflow run
|
|
1588
|
-
* @returns Promise containing the generated run ID
|
|
1589
|
-
*/
|
|
1590
|
-
createRun(params) {
|
|
1591
|
-
const searchParams = new URLSearchParams();
|
|
1592
|
-
if (!!params?.runId) {
|
|
1593
|
-
searchParams.set("runId", params.runId);
|
|
1594
|
-
}
|
|
1595
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/create-run?${searchParams.toString()}`, {
|
|
1596
|
-
method: "POST"
|
|
1597
|
-
});
|
|
1598
|
-
}
|
|
1599
|
-
/**
|
|
1600
|
-
* Starts a legacy workflow run synchronously without waiting for the workflow to complete
|
|
1601
|
-
* @param params - Object containing the runId and triggerData
|
|
1602
|
-
* @returns Promise containing success message
|
|
1603
|
-
*/
|
|
1604
|
-
start(params) {
|
|
1605
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/start?runId=${params.runId}`, {
|
|
1606
|
-
method: "POST",
|
|
1607
|
-
body: params?.triggerData
|
|
1608
|
-
});
|
|
1509
|
+
this.toolId = toolId;
|
|
1609
1510
|
}
|
|
1610
1511
|
/**
|
|
1611
|
-
*
|
|
1612
|
-
* @param
|
|
1613
|
-
* @
|
|
1614
|
-
* @param context - Context to resume the legacy workflow with
|
|
1615
|
-
* @returns Promise containing the legacy workflow resume results
|
|
1512
|
+
* Retrieves details about the tool
|
|
1513
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1514
|
+
* @returns Promise containing tool details including description and schemas
|
|
1616
1515
|
*/
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
runId,
|
|
1620
|
-
context
|
|
1621
|
-
}) {
|
|
1622
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/resume?runId=${runId}`, {
|
|
1623
|
-
method: "POST",
|
|
1624
|
-
body: {
|
|
1625
|
-
stepId,
|
|
1626
|
-
context
|
|
1627
|
-
}
|
|
1628
|
-
});
|
|
1516
|
+
details(runtimeContext) {
|
|
1517
|
+
return this.request(`/api/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
|
|
1629
1518
|
}
|
|
1630
1519
|
/**
|
|
1631
|
-
*
|
|
1632
|
-
* @param params -
|
|
1633
|
-
* @returns Promise containing the
|
|
1520
|
+
* Executes the tool with the provided parameters
|
|
1521
|
+
* @param params - Parameters required for tool execution
|
|
1522
|
+
* @returns Promise containing the tool execution results
|
|
1634
1523
|
*/
|
|
1635
|
-
|
|
1636
|
-
const
|
|
1637
|
-
if (
|
|
1638
|
-
|
|
1524
|
+
execute(params) {
|
|
1525
|
+
const url = new URLSearchParams();
|
|
1526
|
+
if (params.runId) {
|
|
1527
|
+
url.set("runId", params.runId);
|
|
1639
1528
|
}
|
|
1640
|
-
|
|
1529
|
+
const body = {
|
|
1530
|
+
data: params.data,
|
|
1531
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1532
|
+
};
|
|
1533
|
+
return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
|
|
1641
1534
|
method: "POST",
|
|
1642
|
-
body
|
|
1535
|
+
body
|
|
1643
1536
|
});
|
|
1644
1537
|
}
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
body: {
|
|
1654
|
-
stepId: params.stepId,
|
|
1655
|
-
context: params.context
|
|
1656
|
-
}
|
|
1657
|
-
});
|
|
1538
|
+
};
|
|
1539
|
+
|
|
1540
|
+
// src/resources/workflow.ts
|
|
1541
|
+
var RECORD_SEPARATOR = "";
|
|
1542
|
+
var Workflow = class extends BaseResource {
|
|
1543
|
+
constructor(options, workflowId) {
|
|
1544
|
+
super(options);
|
|
1545
|
+
this.workflowId = workflowId;
|
|
1658
1546
|
}
|
|
1659
1547
|
/**
|
|
1660
|
-
* Creates an async generator that processes a readable stream and yields records
|
|
1548
|
+
* Creates an async generator that processes a readable stream and yields workflow records
|
|
1661
1549
|
* separated by the Record Separator character (\x1E)
|
|
1662
1550
|
*
|
|
1663
1551
|
* @param stream - The readable stream to process
|
|
@@ -1702,128 +1590,24 @@ var LegacyWorkflow = class extends BaseResource {
|
|
|
1702
1590
|
}
|
|
1703
1591
|
}
|
|
1704
1592
|
/**
|
|
1705
|
-
*
|
|
1706
|
-
* @param
|
|
1707
|
-
* @returns
|
|
1708
|
-
*/
|
|
1709
|
-
async watch({ runId }, onRecord) {
|
|
1710
|
-
const response = await this.request(`/api/workflows/legacy/${this.workflowId}/watch?runId=${runId}`, {
|
|
1711
|
-
stream: true
|
|
1712
|
-
});
|
|
1713
|
-
if (!response.ok) {
|
|
1714
|
-
throw new Error(`Failed to watch legacy workflow: ${response.statusText}`);
|
|
1715
|
-
}
|
|
1716
|
-
if (!response.body) {
|
|
1717
|
-
throw new Error("Response body is null");
|
|
1718
|
-
}
|
|
1719
|
-
for await (const record of this.streamProcessor(response.body)) {
|
|
1720
|
-
onRecord(record);
|
|
1721
|
-
}
|
|
1722
|
-
}
|
|
1723
|
-
};
|
|
1724
|
-
|
|
1725
|
-
// src/resources/tool.ts
|
|
1726
|
-
var Tool = class extends BaseResource {
|
|
1727
|
-
constructor(options, toolId) {
|
|
1728
|
-
super(options);
|
|
1729
|
-
this.toolId = toolId;
|
|
1730
|
-
}
|
|
1731
|
-
/**
|
|
1732
|
-
* Retrieves details about the tool
|
|
1733
|
-
* @returns Promise containing tool details including description and schemas
|
|
1593
|
+
* Retrieves details about the workflow
|
|
1594
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1595
|
+
* @returns Promise containing workflow details including steps and graphs
|
|
1734
1596
|
*/
|
|
1735
|
-
details() {
|
|
1736
|
-
return this.request(`/api/
|
|
1597
|
+
details(runtimeContext) {
|
|
1598
|
+
return this.request(`/api/workflows/${this.workflowId}${runtimeContextQueryString(runtimeContext)}`);
|
|
1737
1599
|
}
|
|
1738
1600
|
/**
|
|
1739
|
-
*
|
|
1740
|
-
* @param params - Parameters
|
|
1741
|
-
* @
|
|
1601
|
+
* Retrieves all runs for a workflow
|
|
1602
|
+
* @param params - Parameters for filtering runs
|
|
1603
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1604
|
+
* @returns Promise containing workflow runs array
|
|
1742
1605
|
*/
|
|
1743
|
-
|
|
1744
|
-
const
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
const body = {
|
|
1749
|
-
data: params.data,
|
|
1750
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1751
|
-
};
|
|
1752
|
-
return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
|
|
1753
|
-
method: "POST",
|
|
1754
|
-
body
|
|
1755
|
-
});
|
|
1756
|
-
}
|
|
1757
|
-
};
|
|
1758
|
-
|
|
1759
|
-
// src/resources/workflow.ts
|
|
1760
|
-
var RECORD_SEPARATOR2 = "";
|
|
1761
|
-
var Workflow = class extends BaseResource {
|
|
1762
|
-
constructor(options, workflowId) {
|
|
1763
|
-
super(options);
|
|
1764
|
-
this.workflowId = workflowId;
|
|
1765
|
-
}
|
|
1766
|
-
/**
|
|
1767
|
-
* Creates an async generator that processes a readable stream and yields workflow records
|
|
1768
|
-
* separated by the Record Separator character (\x1E)
|
|
1769
|
-
*
|
|
1770
|
-
* @param stream - The readable stream to process
|
|
1771
|
-
* @returns An async generator that yields parsed records
|
|
1772
|
-
*/
|
|
1773
|
-
async *streamProcessor(stream) {
|
|
1774
|
-
const reader = stream.getReader();
|
|
1775
|
-
let doneReading = false;
|
|
1776
|
-
let buffer = "";
|
|
1777
|
-
try {
|
|
1778
|
-
while (!doneReading) {
|
|
1779
|
-
const { done, value } = await reader.read();
|
|
1780
|
-
doneReading = done;
|
|
1781
|
-
if (done && !value) continue;
|
|
1782
|
-
try {
|
|
1783
|
-
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
1784
|
-
const chunks = (buffer + decoded).split(RECORD_SEPARATOR2);
|
|
1785
|
-
buffer = chunks.pop() || "";
|
|
1786
|
-
for (const chunk of chunks) {
|
|
1787
|
-
if (chunk) {
|
|
1788
|
-
if (typeof chunk === "string") {
|
|
1789
|
-
try {
|
|
1790
|
-
const parsedChunk = JSON.parse(chunk);
|
|
1791
|
-
yield parsedChunk;
|
|
1792
|
-
} catch {
|
|
1793
|
-
}
|
|
1794
|
-
}
|
|
1795
|
-
}
|
|
1796
|
-
}
|
|
1797
|
-
} catch {
|
|
1798
|
-
}
|
|
1799
|
-
}
|
|
1800
|
-
if (buffer) {
|
|
1801
|
-
try {
|
|
1802
|
-
yield JSON.parse(buffer);
|
|
1803
|
-
} catch {
|
|
1804
|
-
}
|
|
1805
|
-
}
|
|
1806
|
-
} finally {
|
|
1807
|
-
reader.cancel().catch(() => {
|
|
1808
|
-
});
|
|
1809
|
-
}
|
|
1810
|
-
}
|
|
1811
|
-
/**
|
|
1812
|
-
* Retrieves details about the workflow
|
|
1813
|
-
* @returns Promise containing workflow details including steps and graphs
|
|
1814
|
-
*/
|
|
1815
|
-
details() {
|
|
1816
|
-
return this.request(`/api/workflows/${this.workflowId}`);
|
|
1817
|
-
}
|
|
1818
|
-
/**
|
|
1819
|
-
* Retrieves all runs for a workflow
|
|
1820
|
-
* @param params - Parameters for filtering runs
|
|
1821
|
-
* @returns Promise containing workflow runs array
|
|
1822
|
-
*/
|
|
1823
|
-
runs(params) {
|
|
1824
|
-
const searchParams = new URLSearchParams();
|
|
1825
|
-
if (params?.fromDate) {
|
|
1826
|
-
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
1606
|
+
runs(params, runtimeContext) {
|
|
1607
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
1608
|
+
const searchParams = new URLSearchParams();
|
|
1609
|
+
if (params?.fromDate) {
|
|
1610
|
+
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
1827
1611
|
}
|
|
1828
1612
|
if (params?.toDate) {
|
|
1829
1613
|
searchParams.set("toDate", params.toDate.toISOString());
|
|
@@ -1837,6 +1621,9 @@ var Workflow = class extends BaseResource {
|
|
|
1837
1621
|
if (params?.resourceId) {
|
|
1838
1622
|
searchParams.set("resourceId", params.resourceId);
|
|
1839
1623
|
}
|
|
1624
|
+
if (runtimeContextParam) {
|
|
1625
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
1626
|
+
}
|
|
1840
1627
|
if (searchParams.size) {
|
|
1841
1628
|
return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
|
|
1842
1629
|
} else {
|
|
@@ -1846,18 +1633,22 @@ var Workflow = class extends BaseResource {
|
|
|
1846
1633
|
/**
|
|
1847
1634
|
* Retrieves a specific workflow run by its ID
|
|
1848
1635
|
* @param runId - The ID of the workflow run to retrieve
|
|
1636
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1849
1637
|
* @returns Promise containing the workflow run details
|
|
1850
1638
|
*/
|
|
1851
|
-
runById(runId) {
|
|
1852
|
-
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}`);
|
|
1639
|
+
runById(runId, runtimeContext) {
|
|
1640
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}${runtimeContextQueryString(runtimeContext)}`);
|
|
1853
1641
|
}
|
|
1854
1642
|
/**
|
|
1855
1643
|
* Retrieves the execution result for a specific workflow run by its ID
|
|
1856
1644
|
* @param runId - The ID of the workflow run to retrieve the execution result for
|
|
1645
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1857
1646
|
* @returns Promise containing the workflow run execution result
|
|
1858
1647
|
*/
|
|
1859
|
-
runExecutionResult(runId) {
|
|
1860
|
-
return this.request(
|
|
1648
|
+
runExecutionResult(runId, runtimeContext) {
|
|
1649
|
+
return this.request(
|
|
1650
|
+
`/api/workflows/${this.workflowId}/runs/${runId}/execution-result${runtimeContextQueryString(runtimeContext)}`
|
|
1651
|
+
);
|
|
1861
1652
|
}
|
|
1862
1653
|
/**
|
|
1863
1654
|
* Cancels a specific workflow run by its ID
|
|
@@ -1880,27 +1671,83 @@ var Workflow = class extends BaseResource {
|
|
|
1880
1671
|
body: { event: params.event, data: params.data }
|
|
1881
1672
|
});
|
|
1882
1673
|
}
|
|
1674
|
+
/**
|
|
1675
|
+
* @deprecated Use createRunAsync() instead.
|
|
1676
|
+
* @throws {Error} Always throws an error directing users to use createRunAsync()
|
|
1677
|
+
*/
|
|
1678
|
+
async createRun(_params) {
|
|
1679
|
+
throw new Error(
|
|
1680
|
+
"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."
|
|
1681
|
+
);
|
|
1682
|
+
}
|
|
1883
1683
|
/**
|
|
1884
1684
|
* Creates a new workflow run
|
|
1885
1685
|
* @param params - Optional object containing the optional runId
|
|
1886
|
-
* @returns Promise containing the runId of the created run
|
|
1686
|
+
* @returns Promise containing the runId of the created run with methods to control execution
|
|
1887
1687
|
*/
|
|
1888
|
-
|
|
1688
|
+
async createRunAsync(params) {
|
|
1889
1689
|
const searchParams = new URLSearchParams();
|
|
1890
1690
|
if (!!params?.runId) {
|
|
1891
1691
|
searchParams.set("runId", params.runId);
|
|
1892
1692
|
}
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1693
|
+
const res = await this.request(
|
|
1694
|
+
`/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`,
|
|
1695
|
+
{
|
|
1696
|
+
method: "POST"
|
|
1697
|
+
}
|
|
1698
|
+
);
|
|
1699
|
+
const runId = res.runId;
|
|
1700
|
+
return {
|
|
1701
|
+
runId,
|
|
1702
|
+
start: async (p) => {
|
|
1703
|
+
return this.start({
|
|
1704
|
+
runId,
|
|
1705
|
+
inputData: p.inputData,
|
|
1706
|
+
runtimeContext: p.runtimeContext,
|
|
1707
|
+
tracingOptions: p.tracingOptions
|
|
1708
|
+
});
|
|
1709
|
+
},
|
|
1710
|
+
startAsync: async (p) => {
|
|
1711
|
+
return this.startAsync({
|
|
1712
|
+
runId,
|
|
1713
|
+
inputData: p.inputData,
|
|
1714
|
+
runtimeContext: p.runtimeContext,
|
|
1715
|
+
tracingOptions: p.tracingOptions
|
|
1716
|
+
});
|
|
1717
|
+
},
|
|
1718
|
+
watch: async (onRecord) => {
|
|
1719
|
+
return this.watch({ runId }, onRecord);
|
|
1720
|
+
},
|
|
1721
|
+
stream: async (p) => {
|
|
1722
|
+
return this.stream({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
|
|
1723
|
+
},
|
|
1724
|
+
resume: async (p) => {
|
|
1725
|
+
return this.resume({
|
|
1726
|
+
runId,
|
|
1727
|
+
step: p.step,
|
|
1728
|
+
resumeData: p.resumeData,
|
|
1729
|
+
runtimeContext: p.runtimeContext,
|
|
1730
|
+
tracingOptions: p.tracingOptions
|
|
1731
|
+
});
|
|
1732
|
+
},
|
|
1733
|
+
resumeAsync: async (p) => {
|
|
1734
|
+
return this.resumeAsync({
|
|
1735
|
+
runId,
|
|
1736
|
+
step: p.step,
|
|
1737
|
+
resumeData: p.resumeData,
|
|
1738
|
+
runtimeContext: p.runtimeContext,
|
|
1739
|
+
tracingOptions: p.tracingOptions
|
|
1740
|
+
});
|
|
1741
|
+
},
|
|
1742
|
+
resumeStreamVNext: async (p) => {
|
|
1743
|
+
return this.resumeStreamVNext({
|
|
1744
|
+
runId,
|
|
1745
|
+
step: p.step,
|
|
1746
|
+
resumeData: p.resumeData,
|
|
1747
|
+
runtimeContext: p.runtimeContext
|
|
1748
|
+
});
|
|
1749
|
+
}
|
|
1750
|
+
};
|
|
1904
1751
|
}
|
|
1905
1752
|
/**
|
|
1906
1753
|
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
@@ -1911,7 +1758,7 @@ var Workflow = class extends BaseResource {
|
|
|
1911
1758
|
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1912
1759
|
return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
|
|
1913
1760
|
method: "POST",
|
|
1914
|
-
body: { inputData: params?.inputData, runtimeContext }
|
|
1761
|
+
body: { inputData: params?.inputData, runtimeContext, tracingOptions: params.tracingOptions }
|
|
1915
1762
|
});
|
|
1916
1763
|
}
|
|
1917
1764
|
/**
|
|
@@ -1923,16 +1770,17 @@ var Workflow = class extends BaseResource {
|
|
|
1923
1770
|
step,
|
|
1924
1771
|
runId,
|
|
1925
1772
|
resumeData,
|
|
1773
|
+
tracingOptions,
|
|
1926
1774
|
...rest
|
|
1927
1775
|
}) {
|
|
1928
1776
|
const runtimeContext = parseClientRuntimeContext(rest.runtimeContext);
|
|
1929
1777
|
return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
|
|
1930
1778
|
method: "POST",
|
|
1931
|
-
stream: true,
|
|
1932
1779
|
body: {
|
|
1933
1780
|
step,
|
|
1934
1781
|
resumeData,
|
|
1935
|
-
runtimeContext
|
|
1782
|
+
runtimeContext,
|
|
1783
|
+
tracingOptions
|
|
1936
1784
|
}
|
|
1937
1785
|
});
|
|
1938
1786
|
}
|
|
@@ -1949,7 +1797,7 @@ var Workflow = class extends BaseResource {
|
|
|
1949
1797
|
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1950
1798
|
return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
1951
1799
|
method: "POST",
|
|
1952
|
-
body: { inputData: params.inputData, runtimeContext }
|
|
1800
|
+
body: { inputData: params.inputData, runtimeContext, tracingOptions: params.tracingOptions }
|
|
1953
1801
|
});
|
|
1954
1802
|
}
|
|
1955
1803
|
/**
|
|
@@ -1967,12 +1815,12 @@ var Workflow = class extends BaseResource {
|
|
|
1967
1815
|
`/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
|
|
1968
1816
|
{
|
|
1969
1817
|
method: "POST",
|
|
1970
|
-
body: { inputData: params.inputData, runtimeContext },
|
|
1818
|
+
body: { inputData: params.inputData, runtimeContext, tracingOptions: params.tracingOptions },
|
|
1971
1819
|
stream: true
|
|
1972
1820
|
}
|
|
1973
1821
|
);
|
|
1974
1822
|
if (!response.ok) {
|
|
1975
|
-
throw new Error(`Failed to stream
|
|
1823
|
+
throw new Error(`Failed to stream workflow: ${response.statusText}`);
|
|
1976
1824
|
}
|
|
1977
1825
|
if (!response.body) {
|
|
1978
1826
|
throw new Error("Response body is null");
|
|
@@ -1984,7 +1832,54 @@ var Workflow = class extends BaseResource {
|
|
|
1984
1832
|
async transform(chunk, controller) {
|
|
1985
1833
|
try {
|
|
1986
1834
|
const decoded = new TextDecoder().decode(chunk);
|
|
1987
|
-
const chunks = decoded.split(
|
|
1835
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
1836
|
+
for (const chunk2 of chunks) {
|
|
1837
|
+
if (chunk2) {
|
|
1838
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
1839
|
+
try {
|
|
1840
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
1841
|
+
controller.enqueue(parsedChunk);
|
|
1842
|
+
failedChunk = void 0;
|
|
1843
|
+
} catch {
|
|
1844
|
+
failedChunk = newChunk;
|
|
1845
|
+
}
|
|
1846
|
+
}
|
|
1847
|
+
}
|
|
1848
|
+
} catch {
|
|
1849
|
+
}
|
|
1850
|
+
}
|
|
1851
|
+
});
|
|
1852
|
+
return response.body.pipeThrough(transformStream);
|
|
1853
|
+
}
|
|
1854
|
+
/**
|
|
1855
|
+
* Observes workflow stream for a workflow run
|
|
1856
|
+
* @param params - Object containing the runId
|
|
1857
|
+
* @returns Promise containing the workflow execution results
|
|
1858
|
+
*/
|
|
1859
|
+
async observeStream(params) {
|
|
1860
|
+
const searchParams = new URLSearchParams();
|
|
1861
|
+
searchParams.set("runId", params.runId);
|
|
1862
|
+
const response = await this.request(
|
|
1863
|
+
`/api/workflows/${this.workflowId}/observe-stream?${searchParams.toString()}`,
|
|
1864
|
+
{
|
|
1865
|
+
method: "POST",
|
|
1866
|
+
stream: true
|
|
1867
|
+
}
|
|
1868
|
+
);
|
|
1869
|
+
if (!response.ok) {
|
|
1870
|
+
throw new Error(`Failed to observe workflow stream: ${response.statusText}`);
|
|
1871
|
+
}
|
|
1872
|
+
if (!response.body) {
|
|
1873
|
+
throw new Error("Response body is null");
|
|
1874
|
+
}
|
|
1875
|
+
let failedChunk = void 0;
|
|
1876
|
+
const transformStream = new TransformStream({
|
|
1877
|
+
start() {
|
|
1878
|
+
},
|
|
1879
|
+
async transform(chunk, controller) {
|
|
1880
|
+
try {
|
|
1881
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
1882
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
1988
1883
|
for (const chunk2 of chunks) {
|
|
1989
1884
|
if (chunk2) {
|
|
1990
1885
|
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
@@ -2018,7 +1913,12 @@ var Workflow = class extends BaseResource {
|
|
|
2018
1913
|
`/api/workflows/${this.workflowId}/streamVNext?${searchParams.toString()}`,
|
|
2019
1914
|
{
|
|
2020
1915
|
method: "POST",
|
|
2021
|
-
body: {
|
|
1916
|
+
body: {
|
|
1917
|
+
inputData: params.inputData,
|
|
1918
|
+
runtimeContext,
|
|
1919
|
+
closeOnSuspend: params.closeOnSuspend,
|
|
1920
|
+
tracingOptions: params.tracingOptions
|
|
1921
|
+
},
|
|
2022
1922
|
stream: true
|
|
2023
1923
|
}
|
|
2024
1924
|
);
|
|
@@ -2035,7 +1935,54 @@ var Workflow = class extends BaseResource {
|
|
|
2035
1935
|
async transform(chunk, controller) {
|
|
2036
1936
|
try {
|
|
2037
1937
|
const decoded = new TextDecoder().decode(chunk);
|
|
2038
|
-
const chunks = decoded.split(
|
|
1938
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
1939
|
+
for (const chunk2 of chunks) {
|
|
1940
|
+
if (chunk2) {
|
|
1941
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
1942
|
+
try {
|
|
1943
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
1944
|
+
controller.enqueue(parsedChunk);
|
|
1945
|
+
failedChunk = void 0;
|
|
1946
|
+
} catch {
|
|
1947
|
+
failedChunk = newChunk;
|
|
1948
|
+
}
|
|
1949
|
+
}
|
|
1950
|
+
}
|
|
1951
|
+
} catch {
|
|
1952
|
+
}
|
|
1953
|
+
}
|
|
1954
|
+
});
|
|
1955
|
+
return response.body.pipeThrough(transformStream);
|
|
1956
|
+
}
|
|
1957
|
+
/**
|
|
1958
|
+
* Observes workflow vNext stream for a workflow run
|
|
1959
|
+
* @param params - Object containing the runId
|
|
1960
|
+
* @returns Promise containing the workflow execution results
|
|
1961
|
+
*/
|
|
1962
|
+
async observeStreamVNext(params) {
|
|
1963
|
+
const searchParams = new URLSearchParams();
|
|
1964
|
+
searchParams.set("runId", params.runId);
|
|
1965
|
+
const response = await this.request(
|
|
1966
|
+
`/api/workflows/${this.workflowId}/observe-streamVNext?${searchParams.toString()}`,
|
|
1967
|
+
{
|
|
1968
|
+
method: "POST",
|
|
1969
|
+
stream: true
|
|
1970
|
+
}
|
|
1971
|
+
);
|
|
1972
|
+
if (!response.ok) {
|
|
1973
|
+
throw new Error(`Failed to observe stream vNext workflow: ${response.statusText}`);
|
|
1974
|
+
}
|
|
1975
|
+
if (!response.body) {
|
|
1976
|
+
throw new Error("Response body is null");
|
|
1977
|
+
}
|
|
1978
|
+
let failedChunk = void 0;
|
|
1979
|
+
const transformStream = new TransformStream({
|
|
1980
|
+
start() {
|
|
1981
|
+
},
|
|
1982
|
+
async transform(chunk, controller) {
|
|
1983
|
+
try {
|
|
1984
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
1985
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
2039
1986
|
for (const chunk2 of chunks) {
|
|
2040
1987
|
if (chunk2) {
|
|
2041
1988
|
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
@@ -2066,9 +2013,64 @@ var Workflow = class extends BaseResource {
|
|
|
2066
2013
|
body: {
|
|
2067
2014
|
step: params.step,
|
|
2068
2015
|
resumeData: params.resumeData,
|
|
2069
|
-
runtimeContext
|
|
2016
|
+
runtimeContext,
|
|
2017
|
+
tracingOptions: params.tracingOptions
|
|
2018
|
+
}
|
|
2019
|
+
});
|
|
2020
|
+
}
|
|
2021
|
+
/**
|
|
2022
|
+
* Resumes a suspended workflow step that uses streamVNext asynchronously and returns a promise that resolves when the workflow is complete
|
|
2023
|
+
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
2024
|
+
* @returns Promise containing the workflow resume results
|
|
2025
|
+
*/
|
|
2026
|
+
async resumeStreamVNext(params) {
|
|
2027
|
+
const searchParams = new URLSearchParams();
|
|
2028
|
+
searchParams.set("runId", params.runId);
|
|
2029
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
2030
|
+
const response = await this.request(
|
|
2031
|
+
`/api/workflows/${this.workflowId}/resume-stream?${searchParams.toString()}`,
|
|
2032
|
+
{
|
|
2033
|
+
method: "POST",
|
|
2034
|
+
body: {
|
|
2035
|
+
step: params.step,
|
|
2036
|
+
resumeData: params.resumeData,
|
|
2037
|
+
runtimeContext,
|
|
2038
|
+
tracingOptions: params.tracingOptions
|
|
2039
|
+
},
|
|
2040
|
+
stream: true
|
|
2041
|
+
}
|
|
2042
|
+
);
|
|
2043
|
+
if (!response.ok) {
|
|
2044
|
+
throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
|
|
2045
|
+
}
|
|
2046
|
+
if (!response.body) {
|
|
2047
|
+
throw new Error("Response body is null");
|
|
2048
|
+
}
|
|
2049
|
+
let failedChunk = void 0;
|
|
2050
|
+
const transformStream = new TransformStream({
|
|
2051
|
+
start() {
|
|
2052
|
+
},
|
|
2053
|
+
async transform(chunk, controller) {
|
|
2054
|
+
try {
|
|
2055
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
2056
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
2057
|
+
for (const chunk2 of chunks) {
|
|
2058
|
+
if (chunk2) {
|
|
2059
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
2060
|
+
try {
|
|
2061
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
2062
|
+
controller.enqueue(parsedChunk);
|
|
2063
|
+
failedChunk = void 0;
|
|
2064
|
+
} catch {
|
|
2065
|
+
failedChunk = newChunk;
|
|
2066
|
+
}
|
|
2067
|
+
}
|
|
2068
|
+
}
|
|
2069
|
+
} catch {
|
|
2070
|
+
}
|
|
2070
2071
|
}
|
|
2071
2072
|
});
|
|
2073
|
+
return response.body.pipeThrough(transformStream);
|
|
2072
2074
|
}
|
|
2073
2075
|
/**
|
|
2074
2076
|
* Watches workflow transitions in real-time
|
|
@@ -2106,7 +2108,7 @@ var Workflow = class extends BaseResource {
|
|
|
2106
2108
|
async start(controller) {
|
|
2107
2109
|
try {
|
|
2108
2110
|
for await (const record of records) {
|
|
2109
|
-
const json = JSON.stringify(record) +
|
|
2111
|
+
const json = JSON.stringify(record) + RECORD_SEPARATOR;
|
|
2110
2112
|
controller.enqueue(encoder.encode(json));
|
|
2111
2113
|
}
|
|
2112
2114
|
controller.close();
|
|
@@ -2204,10 +2206,11 @@ var MCPTool = class extends BaseResource {
|
|
|
2204
2206
|
}
|
|
2205
2207
|
/**
|
|
2206
2208
|
* Retrieves details about this specific tool from the MCP server.
|
|
2209
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2207
2210
|
* @returns Promise containing the tool's information (name, description, schema).
|
|
2208
2211
|
*/
|
|
2209
|
-
details() {
|
|
2210
|
-
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}`);
|
|
2212
|
+
details(runtimeContext) {
|
|
2213
|
+
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
|
|
2211
2214
|
}
|
|
2212
2215
|
/**
|
|
2213
2216
|
* Executes this specific tool on the MCP server.
|
|
@@ -2228,7 +2231,7 @@ var MCPTool = class extends BaseResource {
|
|
|
2228
2231
|
};
|
|
2229
2232
|
|
|
2230
2233
|
// src/resources/agent-builder.ts
|
|
2231
|
-
var
|
|
2234
|
+
var RECORD_SEPARATOR2 = "";
|
|
2232
2235
|
var AgentBuilder = class extends BaseResource {
|
|
2233
2236
|
constructor(options, actionId) {
|
|
2234
2237
|
super(options);
|
|
@@ -2263,11 +2266,20 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2263
2266
|
};
|
|
2264
2267
|
}
|
|
2265
2268
|
}
|
|
2269
|
+
/**
|
|
2270
|
+
* @deprecated Use createRunAsync() instead.
|
|
2271
|
+
* @throws {Error} Always throws an error directing users to use createRunAsync()
|
|
2272
|
+
*/
|
|
2273
|
+
async createRun(_params) {
|
|
2274
|
+
throw new Error(
|
|
2275
|
+
"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."
|
|
2276
|
+
);
|
|
2277
|
+
}
|
|
2266
2278
|
/**
|
|
2267
2279
|
* Creates a new agent builder action run and returns the runId.
|
|
2268
2280
|
* This calls `/api/agent-builder/:actionId/create-run`.
|
|
2269
2281
|
*/
|
|
2270
|
-
async
|
|
2282
|
+
async createRunAsync(params) {
|
|
2271
2283
|
const searchParams = new URLSearchParams();
|
|
2272
2284
|
if (!!params?.runId) {
|
|
2273
2285
|
searchParams.set("runId", params.runId);
|
|
@@ -2277,14 +2289,6 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2277
2289
|
method: "POST"
|
|
2278
2290
|
});
|
|
2279
2291
|
}
|
|
2280
|
-
/**
|
|
2281
|
-
* Creates a new workflow run (alias for createRun)
|
|
2282
|
-
* @param params - Optional object containing the optional runId
|
|
2283
|
-
* @returns Promise containing the runId of the created run
|
|
2284
|
-
*/
|
|
2285
|
-
createRunAsync(params) {
|
|
2286
|
-
return this.createRun(params);
|
|
2287
|
-
}
|
|
2288
2292
|
/**
|
|
2289
2293
|
* Starts agent builder action asynchronously and waits for completion.
|
|
2290
2294
|
* This calls `/api/agent-builder/:actionId/start-async`.
|
|
@@ -2367,7 +2371,7 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2367
2371
|
if (done && !value) continue;
|
|
2368
2372
|
try {
|
|
2369
2373
|
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
2370
|
-
const chunks = (buffer + decoded).split(
|
|
2374
|
+
const chunks = (buffer + decoded).split(RECORD_SEPARATOR2);
|
|
2371
2375
|
buffer = chunks.pop() || "";
|
|
2372
2376
|
for (const chunk of chunks) {
|
|
2373
2377
|
if (chunk) {
|
|
@@ -2424,7 +2428,7 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2424
2428
|
async transform(chunk, controller) {
|
|
2425
2429
|
try {
|
|
2426
2430
|
const decoded = new TextDecoder().decode(chunk);
|
|
2427
|
-
const chunks = decoded.split(
|
|
2431
|
+
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
2428
2432
|
for (const chunk2 of chunks) {
|
|
2429
2433
|
if (chunk2) {
|
|
2430
2434
|
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
@@ -2473,7 +2477,7 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2473
2477
|
async transform(chunk, controller) {
|
|
2474
2478
|
try {
|
|
2475
2479
|
const decoded = new TextDecoder().decode(chunk);
|
|
2476
|
-
const chunks = decoded.split(
|
|
2480
|
+
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
2477
2481
|
for (const chunk2 of chunks) {
|
|
2478
2482
|
if (chunk2) {
|
|
2479
2483
|
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
@@ -2644,6 +2648,31 @@ var Observability = class extends BaseResource {
|
|
|
2644
2648
|
const queryString = searchParams.toString();
|
|
2645
2649
|
return this.request(`/api/observability/traces${queryString ? `?${queryString}` : ""}`);
|
|
2646
2650
|
}
|
|
2651
|
+
/**
|
|
2652
|
+
* Retrieves scores by trace ID and span ID
|
|
2653
|
+
* @param params - Parameters containing trace ID, span ID, and pagination options
|
|
2654
|
+
* @returns Promise containing scores and pagination info
|
|
2655
|
+
*/
|
|
2656
|
+
getScoresBySpan(params) {
|
|
2657
|
+
const { traceId, spanId, page, perPage } = params;
|
|
2658
|
+
const searchParams = new URLSearchParams();
|
|
2659
|
+
if (page !== void 0) {
|
|
2660
|
+
searchParams.set("page", String(page));
|
|
2661
|
+
}
|
|
2662
|
+
if (perPage !== void 0) {
|
|
2663
|
+
searchParams.set("perPage", String(perPage));
|
|
2664
|
+
}
|
|
2665
|
+
const queryString = searchParams.toString();
|
|
2666
|
+
return this.request(
|
|
2667
|
+
`/api/observability/traces/${encodeURIComponent(traceId)}/${encodeURIComponent(spanId)}/scores${queryString ? `?${queryString}` : ""}`
|
|
2668
|
+
);
|
|
2669
|
+
}
|
|
2670
|
+
score(params) {
|
|
2671
|
+
return this.request(`/api/observability/traces/score`, {
|
|
2672
|
+
method: "POST",
|
|
2673
|
+
body: { ...params }
|
|
2674
|
+
});
|
|
2675
|
+
}
|
|
2647
2676
|
};
|
|
2648
2677
|
|
|
2649
2678
|
// src/resources/network-memory-thread.ts
|
|
@@ -2709,144 +2738,6 @@ var NetworkMemoryThread = class extends BaseResource {
|
|
|
2709
2738
|
}
|
|
2710
2739
|
};
|
|
2711
2740
|
|
|
2712
|
-
// src/resources/vNextNetwork.ts
|
|
2713
|
-
var RECORD_SEPARATOR4 = "";
|
|
2714
|
-
var VNextNetwork = class extends BaseResource {
|
|
2715
|
-
constructor(options, networkId) {
|
|
2716
|
-
super(options);
|
|
2717
|
-
this.networkId = networkId;
|
|
2718
|
-
}
|
|
2719
|
-
/**
|
|
2720
|
-
* Retrieves details about the network
|
|
2721
|
-
* @returns Promise containing vNext network details
|
|
2722
|
-
*/
|
|
2723
|
-
details() {
|
|
2724
|
-
return this.request(`/api/networks/v-next/${this.networkId}`);
|
|
2725
|
-
}
|
|
2726
|
-
/**
|
|
2727
|
-
* Generates a response from the v-next network
|
|
2728
|
-
* @param params - Generation parameters including message
|
|
2729
|
-
* @returns Promise containing the generated response
|
|
2730
|
-
*/
|
|
2731
|
-
generate(params) {
|
|
2732
|
-
return this.request(`/api/networks/v-next/${this.networkId}/generate`, {
|
|
2733
|
-
method: "POST",
|
|
2734
|
-
body: {
|
|
2735
|
-
...params,
|
|
2736
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
2737
|
-
}
|
|
2738
|
-
});
|
|
2739
|
-
}
|
|
2740
|
-
/**
|
|
2741
|
-
* Generates a response from the v-next network using multiple primitives
|
|
2742
|
-
* @param params - Generation parameters including message
|
|
2743
|
-
* @returns Promise containing the generated response
|
|
2744
|
-
*/
|
|
2745
|
-
loop(params) {
|
|
2746
|
-
return this.request(`/api/networks/v-next/${this.networkId}/loop`, {
|
|
2747
|
-
method: "POST",
|
|
2748
|
-
body: {
|
|
2749
|
-
...params,
|
|
2750
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
2751
|
-
}
|
|
2752
|
-
});
|
|
2753
|
-
}
|
|
2754
|
-
async *streamProcessor(stream) {
|
|
2755
|
-
const reader = stream.getReader();
|
|
2756
|
-
let doneReading = false;
|
|
2757
|
-
let buffer = "";
|
|
2758
|
-
try {
|
|
2759
|
-
while (!doneReading) {
|
|
2760
|
-
const { done, value } = await reader.read();
|
|
2761
|
-
doneReading = done;
|
|
2762
|
-
if (done && !value) continue;
|
|
2763
|
-
try {
|
|
2764
|
-
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
2765
|
-
const chunks = (buffer + decoded).split(RECORD_SEPARATOR4);
|
|
2766
|
-
buffer = chunks.pop() || "";
|
|
2767
|
-
for (const chunk of chunks) {
|
|
2768
|
-
if (chunk) {
|
|
2769
|
-
if (typeof chunk === "string") {
|
|
2770
|
-
try {
|
|
2771
|
-
const parsedChunk = JSON.parse(chunk);
|
|
2772
|
-
yield parsedChunk;
|
|
2773
|
-
} catch {
|
|
2774
|
-
}
|
|
2775
|
-
}
|
|
2776
|
-
}
|
|
2777
|
-
}
|
|
2778
|
-
} catch {
|
|
2779
|
-
}
|
|
2780
|
-
}
|
|
2781
|
-
if (buffer) {
|
|
2782
|
-
try {
|
|
2783
|
-
yield JSON.parse(buffer);
|
|
2784
|
-
} catch {
|
|
2785
|
-
}
|
|
2786
|
-
}
|
|
2787
|
-
} finally {
|
|
2788
|
-
reader.cancel().catch(() => {
|
|
2789
|
-
});
|
|
2790
|
-
}
|
|
2791
|
-
}
|
|
2792
|
-
/**
|
|
2793
|
-
* Streams a response from the v-next network
|
|
2794
|
-
* @param params - Stream parameters including message
|
|
2795
|
-
* @returns Promise containing the results
|
|
2796
|
-
*/
|
|
2797
|
-
async stream(params, onRecord) {
|
|
2798
|
-
const response = await this.request(`/api/networks/v-next/${this.networkId}/stream`, {
|
|
2799
|
-
method: "POST",
|
|
2800
|
-
body: {
|
|
2801
|
-
...params,
|
|
2802
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
2803
|
-
},
|
|
2804
|
-
stream: true
|
|
2805
|
-
});
|
|
2806
|
-
if (!response.ok) {
|
|
2807
|
-
throw new Error(`Failed to stream vNext network: ${response.statusText}`);
|
|
2808
|
-
}
|
|
2809
|
-
if (!response.body) {
|
|
2810
|
-
throw new Error("Response body is null");
|
|
2811
|
-
}
|
|
2812
|
-
for await (const record of this.streamProcessor(response.body)) {
|
|
2813
|
-
if (typeof record === "string") {
|
|
2814
|
-
onRecord(JSON.parse(record));
|
|
2815
|
-
} else {
|
|
2816
|
-
onRecord(record);
|
|
2817
|
-
}
|
|
2818
|
-
}
|
|
2819
|
-
}
|
|
2820
|
-
/**
|
|
2821
|
-
* Streams a response from the v-next network loop
|
|
2822
|
-
* @param params - Stream parameters including message
|
|
2823
|
-
* @returns Promise containing the results
|
|
2824
|
-
*/
|
|
2825
|
-
async loopStream(params, onRecord) {
|
|
2826
|
-
const response = await this.request(`/api/networks/v-next/${this.networkId}/loop-stream`, {
|
|
2827
|
-
method: "POST",
|
|
2828
|
-
body: {
|
|
2829
|
-
...params,
|
|
2830
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
2831
|
-
},
|
|
2832
|
-
stream: true
|
|
2833
|
-
});
|
|
2834
|
-
if (!response.ok) {
|
|
2835
|
-
throw new Error(`Failed to stream vNext network loop: ${response.statusText}`);
|
|
2836
|
-
}
|
|
2837
|
-
if (!response.body) {
|
|
2838
|
-
throw new Error("Response body is null");
|
|
2839
|
-
}
|
|
2840
|
-
for await (const record of this.streamProcessor(response.body)) {
|
|
2841
|
-
if (typeof record === "string") {
|
|
2842
|
-
onRecord(JSON.parse(record));
|
|
2843
|
-
} else {
|
|
2844
|
-
onRecord(record);
|
|
2845
|
-
}
|
|
2846
|
-
}
|
|
2847
|
-
}
|
|
2848
|
-
};
|
|
2849
|
-
|
|
2850
2741
|
// src/client.ts
|
|
2851
2742
|
var MastraClient = class extends BaseResource {
|
|
2852
2743
|
observability;
|
|
@@ -2856,7 +2747,7 @@ var MastraClient = class extends BaseResource {
|
|
|
2856
2747
|
}
|
|
2857
2748
|
/**
|
|
2858
2749
|
* Retrieves all available agents
|
|
2859
|
-
* @param runtimeContext -
|
|
2750
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2860
2751
|
* @returns Promise containing map of agent IDs to agent details
|
|
2861
2752
|
*/
|
|
2862
2753
|
getAgents(runtimeContext) {
|
|
@@ -2884,6 +2775,14 @@ var MastraClient = class extends BaseResource {
|
|
|
2884
2775
|
getMemoryThreads(params) {
|
|
2885
2776
|
return this.request(`/api/memory/threads?resourceid=${params.resourceId}&agentId=${params.agentId}`);
|
|
2886
2777
|
}
|
|
2778
|
+
/**
|
|
2779
|
+
* Retrieves memory config for a resource
|
|
2780
|
+
* @param params - Parameters containing the resource ID
|
|
2781
|
+
* @returns Promise containing array of memory threads
|
|
2782
|
+
*/
|
|
2783
|
+
getMemoryConfig(params) {
|
|
2784
|
+
return this.request(`/api/memory/config?agentId=${params.agentId}`);
|
|
2785
|
+
}
|
|
2887
2786
|
/**
|
|
2888
2787
|
* Creates a new memory thread
|
|
2889
2788
|
* @param params - Parameters for creating the memory thread
|
|
@@ -2900,6 +2799,24 @@ var MastraClient = class extends BaseResource {
|
|
|
2900
2799
|
getMemoryThread(threadId, agentId) {
|
|
2901
2800
|
return new MemoryThread(this.options, threadId, agentId);
|
|
2902
2801
|
}
|
|
2802
|
+
getThreadMessages(threadId, opts = {}) {
|
|
2803
|
+
let url = "";
|
|
2804
|
+
if (opts.agentId) {
|
|
2805
|
+
url = `/api/memory/threads/${threadId}/messages?agentId=${opts.agentId}`;
|
|
2806
|
+
} else if (opts.networkId) {
|
|
2807
|
+
url = `/api/memory/network/threads/${threadId}/messages?networkId=${opts.networkId}`;
|
|
2808
|
+
}
|
|
2809
|
+
return this.request(url);
|
|
2810
|
+
}
|
|
2811
|
+
deleteThread(threadId, opts = {}) {
|
|
2812
|
+
let url = "";
|
|
2813
|
+
if (opts.agentId) {
|
|
2814
|
+
url = `/api/memory/threads/${threadId}?agentId=${opts.agentId}`;
|
|
2815
|
+
} else if (opts.networkId) {
|
|
2816
|
+
url = `/api/memory/network/threads/${threadId}?networkId=${opts.networkId}`;
|
|
2817
|
+
}
|
|
2818
|
+
return this.request(url, { method: "DELETE" });
|
|
2819
|
+
}
|
|
2903
2820
|
/**
|
|
2904
2821
|
* Saves messages to memory
|
|
2905
2822
|
* @param params - Parameters containing messages to save
|
|
@@ -2962,10 +2879,17 @@ var MastraClient = class extends BaseResource {
|
|
|
2962
2879
|
}
|
|
2963
2880
|
/**
|
|
2964
2881
|
* Retrieves all available tools
|
|
2882
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2965
2883
|
* @returns Promise containing map of tool IDs to tool details
|
|
2966
2884
|
*/
|
|
2967
|
-
getTools() {
|
|
2968
|
-
|
|
2885
|
+
getTools(runtimeContext) {
|
|
2886
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
2887
|
+
const searchParams = new URLSearchParams();
|
|
2888
|
+
if (runtimeContextParam) {
|
|
2889
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
2890
|
+
}
|
|
2891
|
+
const queryString = searchParams.toString();
|
|
2892
|
+
return this.request(`/api/tools${queryString ? `?${queryString}` : ""}`);
|
|
2969
2893
|
}
|
|
2970
2894
|
/**
|
|
2971
2895
|
* Gets a tool instance by ID
|
|
@@ -2975,27 +2899,19 @@ var MastraClient = class extends BaseResource {
|
|
|
2975
2899
|
getTool(toolId) {
|
|
2976
2900
|
return new Tool(this.options, toolId);
|
|
2977
2901
|
}
|
|
2978
|
-
/**
|
|
2979
|
-
* Retrieves all available legacy workflows
|
|
2980
|
-
* @returns Promise containing map of legacy workflow IDs to legacy workflow details
|
|
2981
|
-
*/
|
|
2982
|
-
getLegacyWorkflows() {
|
|
2983
|
-
return this.request("/api/workflows/legacy");
|
|
2984
|
-
}
|
|
2985
|
-
/**
|
|
2986
|
-
* Gets a legacy workflow instance by ID
|
|
2987
|
-
* @param workflowId - ID of the legacy workflow to retrieve
|
|
2988
|
-
* @returns Legacy Workflow instance
|
|
2989
|
-
*/
|
|
2990
|
-
getLegacyWorkflow(workflowId) {
|
|
2991
|
-
return new LegacyWorkflow(this.options, workflowId);
|
|
2992
|
-
}
|
|
2993
2902
|
/**
|
|
2994
2903
|
* Retrieves all available workflows
|
|
2904
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2995
2905
|
* @returns Promise containing map of workflow IDs to workflow details
|
|
2996
2906
|
*/
|
|
2997
|
-
getWorkflows() {
|
|
2998
|
-
|
|
2907
|
+
getWorkflows(runtimeContext) {
|
|
2908
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
2909
|
+
const searchParams = new URLSearchParams();
|
|
2910
|
+
if (runtimeContextParam) {
|
|
2911
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
2912
|
+
}
|
|
2913
|
+
const queryString = searchParams.toString();
|
|
2914
|
+
return this.request(`/api/workflows${queryString ? `?${queryString}` : ""}`);
|
|
2999
2915
|
}
|
|
3000
2916
|
/**
|
|
3001
2917
|
* Gets a workflow instance by ID
|
|
@@ -3163,36 +3079,6 @@ var MastraClient = class extends BaseResource {
|
|
|
3163
3079
|
return this.request(`/api/telemetry`);
|
|
3164
3080
|
}
|
|
3165
3081
|
}
|
|
3166
|
-
/**
|
|
3167
|
-
* Retrieves all available networks
|
|
3168
|
-
* @returns Promise containing map of network IDs to network details
|
|
3169
|
-
*/
|
|
3170
|
-
getNetworks() {
|
|
3171
|
-
return this.request("/api/networks");
|
|
3172
|
-
}
|
|
3173
|
-
/**
|
|
3174
|
-
* Retrieves all available vNext networks
|
|
3175
|
-
* @returns Promise containing map of vNext network IDs to vNext network details
|
|
3176
|
-
*/
|
|
3177
|
-
getVNextNetworks() {
|
|
3178
|
-
return this.request("/api/networks/v-next");
|
|
3179
|
-
}
|
|
3180
|
-
/**
|
|
3181
|
-
* Gets a network instance by ID
|
|
3182
|
-
* @param networkId - ID of the network to retrieve
|
|
3183
|
-
* @returns Network instance
|
|
3184
|
-
*/
|
|
3185
|
-
getNetwork(networkId) {
|
|
3186
|
-
return new Network(this.options, networkId);
|
|
3187
|
-
}
|
|
3188
|
-
/**
|
|
3189
|
-
* Gets a vNext network instance by ID
|
|
3190
|
-
* @param networkId - ID of the vNext network to retrieve
|
|
3191
|
-
* @returns vNext Network instance
|
|
3192
|
-
*/
|
|
3193
|
-
getVNextNetwork(networkId) {
|
|
3194
|
-
return new VNextNetwork(this.options, networkId);
|
|
3195
|
-
}
|
|
3196
3082
|
/**
|
|
3197
3083
|
* Retrieves a list of available MCP servers.
|
|
3198
3084
|
* @param params - Optional parameters for pagination (limit, offset).
|
|
@@ -3297,7 +3183,7 @@ var MastraClient = class extends BaseResource {
|
|
|
3297
3183
|
* @returns Promise containing the scorer
|
|
3298
3184
|
*/
|
|
3299
3185
|
getScorer(scorerId) {
|
|
3300
|
-
return this.request(`/api/scores/scorers/${scorerId}`);
|
|
3186
|
+
return this.request(`/api/scores/scorers/${encodeURIComponent(scorerId)}`);
|
|
3301
3187
|
}
|
|
3302
3188
|
getScoresByScorerId(params) {
|
|
3303
3189
|
const { page, perPage, scorerId, entityId, entityType } = params;
|
|
@@ -3315,7 +3201,7 @@ var MastraClient = class extends BaseResource {
|
|
|
3315
3201
|
searchParams.set("perPage", String(perPage));
|
|
3316
3202
|
}
|
|
3317
3203
|
const queryString = searchParams.toString();
|
|
3318
|
-
return this.request(`/api/scores/scorer/${scorerId}${queryString ? `?${queryString}` : ""}`);
|
|
3204
|
+
return this.request(`/api/scores/scorer/${encodeURIComponent(scorerId)}${queryString ? `?${queryString}` : ""}`);
|
|
3319
3205
|
}
|
|
3320
3206
|
/**
|
|
3321
3207
|
* Retrieves scores by run ID
|
|
@@ -3332,7 +3218,7 @@ var MastraClient = class extends BaseResource {
|
|
|
3332
3218
|
searchParams.set("perPage", String(perPage));
|
|
3333
3219
|
}
|
|
3334
3220
|
const queryString = searchParams.toString();
|
|
3335
|
-
return this.request(`/api/scores/run/${runId}${queryString ? `?${queryString}` : ""}`);
|
|
3221
|
+
return this.request(`/api/scores/run/${encodeURIComponent(runId)}${queryString ? `?${queryString}` : ""}`);
|
|
3336
3222
|
}
|
|
3337
3223
|
/**
|
|
3338
3224
|
* Retrieves scores by entity ID and type
|
|
@@ -3349,7 +3235,9 @@ var MastraClient = class extends BaseResource {
|
|
|
3349
3235
|
searchParams.set("perPage", String(perPage));
|
|
3350
3236
|
}
|
|
3351
3237
|
const queryString = searchParams.toString();
|
|
3352
|
-
return this.request(
|
|
3238
|
+
return this.request(
|
|
3239
|
+
`/api/scores/entity/${encodeURIComponent(entityType)}/${encodeURIComponent(entityId)}${queryString ? `?${queryString}` : ""}`
|
|
3240
|
+
);
|
|
3353
3241
|
}
|
|
3354
3242
|
/**
|
|
3355
3243
|
* Saves a score
|
|
@@ -3375,8 +3263,33 @@ var MastraClient = class extends BaseResource {
|
|
|
3375
3263
|
getAITraces(params) {
|
|
3376
3264
|
return this.observability.getTraces(params);
|
|
3377
3265
|
}
|
|
3266
|
+
getScoresBySpan(params) {
|
|
3267
|
+
return this.observability.getScoresBySpan(params);
|
|
3268
|
+
}
|
|
3269
|
+
score(params) {
|
|
3270
|
+
return this.observability.score(params);
|
|
3271
|
+
}
|
|
3272
|
+
};
|
|
3273
|
+
|
|
3274
|
+
// src/tools.ts
|
|
3275
|
+
var ClientTool = class {
|
|
3276
|
+
id;
|
|
3277
|
+
description;
|
|
3278
|
+
inputSchema;
|
|
3279
|
+
outputSchema;
|
|
3280
|
+
execute;
|
|
3281
|
+
constructor(opts) {
|
|
3282
|
+
this.id = opts.id;
|
|
3283
|
+
this.description = opts.description;
|
|
3284
|
+
this.inputSchema = opts.inputSchema;
|
|
3285
|
+
this.outputSchema = opts.outputSchema;
|
|
3286
|
+
this.execute = opts.execute;
|
|
3287
|
+
}
|
|
3378
3288
|
};
|
|
3289
|
+
function createTool(opts) {
|
|
3290
|
+
return new ClientTool(opts);
|
|
3291
|
+
}
|
|
3379
3292
|
|
|
3380
|
-
export { MastraClient };
|
|
3293
|
+
export { ClientTool, MastraClient, createTool };
|
|
3381
3294
|
//# sourceMappingURL=index.js.map
|
|
3382
3295
|
//# sourceMappingURL=index.js.map
|