@mastra/client-js 0.0.0-issue-7087-20250910004053 → 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 +431 -3
- package/README.md +6 -10
- package/dist/client.d.ts +37 -39
- package/dist/client.d.ts.map +1 -1
- package/dist/index.cjs +559 -547
- 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 +558 -548
- 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 +72 -43
- 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 +65 -48
- 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/resources/vNextNetwork.d.ts +0 -42
- package/dist/resources/vNextNetwork.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,16 +311,11 @@ 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}`);
|
|
284
|
-
}
|
|
285
|
-
async generate(params) {
|
|
286
|
-
console.warn(
|
|
287
|
-
"Deprecation NOTICE:Generate method will switch to use generateVNext implementation September 16th. Please use generateLegacy if you don't want to upgrade just yet."
|
|
288
|
-
);
|
|
289
|
-
return this.generateLegacy(params);
|
|
317
|
+
details(runtimeContext) {
|
|
318
|
+
return this.request(`/api/agents/${this.agentId}${runtimeContextQueryString(runtimeContext)}`);
|
|
290
319
|
}
|
|
291
320
|
async generateLegacy(params) {
|
|
292
321
|
const processedParams = {
|
|
@@ -319,7 +348,9 @@ var Agent = class extends BaseResource {
|
|
|
319
348
|
resourceId,
|
|
320
349
|
threadId,
|
|
321
350
|
runtimeContext,
|
|
322
|
-
tracingContext: { currentSpan: void 0 }
|
|
351
|
+
tracingContext: { currentSpan: void 0 },
|
|
352
|
+
suspend: async () => {
|
|
353
|
+
}
|
|
323
354
|
},
|
|
324
355
|
{
|
|
325
356
|
messages: response.messages,
|
|
@@ -327,10 +358,6 @@ var Agent = class extends BaseResource {
|
|
|
327
358
|
}
|
|
328
359
|
);
|
|
329
360
|
const updatedMessages = [
|
|
330
|
-
{
|
|
331
|
-
role: "user",
|
|
332
|
-
content: params.messages
|
|
333
|
-
},
|
|
334
361
|
...response.response.messages,
|
|
335
362
|
{
|
|
336
363
|
role: "tool",
|
|
@@ -353,7 +380,16 @@ var Agent = class extends BaseResource {
|
|
|
353
380
|
}
|
|
354
381
|
return response;
|
|
355
382
|
}
|
|
356
|
-
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
|
+
}
|
|
357
393
|
const processedParams = {
|
|
358
394
|
...params,
|
|
359
395
|
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
@@ -366,7 +402,7 @@ var Agent = class extends BaseResource {
|
|
|
366
402
|
};
|
|
367
403
|
const { runId, resourceId, threadId, runtimeContext } = processedParams;
|
|
368
404
|
const response = await this.request(
|
|
369
|
-
`/api/agents/${this.agentId}/generate
|
|
405
|
+
`/api/agents/${this.agentId}/generate`,
|
|
370
406
|
{
|
|
371
407
|
method: "POST",
|
|
372
408
|
body: processedParams
|
|
@@ -380,7 +416,7 @@ var Agent = class extends BaseResource {
|
|
|
380
416
|
resourceId,
|
|
381
417
|
threadId,
|
|
382
418
|
runtimeContext,
|
|
383
|
-
respondFn: this.
|
|
419
|
+
respondFn: this.generate.bind(this)
|
|
384
420
|
});
|
|
385
421
|
}
|
|
386
422
|
return response;
|
|
@@ -647,17 +683,6 @@ var Agent = class extends BaseResource {
|
|
|
647
683
|
});
|
|
648
684
|
onFinish?.({ message, finishReason, usage });
|
|
649
685
|
}
|
|
650
|
-
/**
|
|
651
|
-
* Streams a response from the agent
|
|
652
|
-
* @param params - Stream parameters including prompt
|
|
653
|
-
* @returns Promise containing the enhanced Response object with processDataStream method
|
|
654
|
-
*/
|
|
655
|
-
async stream(params) {
|
|
656
|
-
console.warn(
|
|
657
|
-
"Deprecation NOTICE:\nStream method will switch to use streamVNext implementation September 16th. Please use streamLegacy if you don't want to upgrade just yet."
|
|
658
|
-
);
|
|
659
|
-
return this.streamLegacy(params);
|
|
660
|
-
}
|
|
661
686
|
/**
|
|
662
687
|
* Streams a response from the agent
|
|
663
688
|
* @param params - Stream parameters including prompt
|
|
@@ -672,7 +697,7 @@ var Agent = class extends BaseResource {
|
|
|
672
697
|
clientTools: processClientTools(params.clientTools)
|
|
673
698
|
};
|
|
674
699
|
const { readable, writable } = new TransformStream();
|
|
675
|
-
const response = await this.
|
|
700
|
+
const response = await this.processStreamResponseLegacy(processedParams, writable);
|
|
676
701
|
const streamResponse = new Response(readable, {
|
|
677
702
|
status: response.status,
|
|
678
703
|
statusText: response.statusText,
|
|
@@ -759,6 +784,14 @@ var Agent = class extends BaseResource {
|
|
|
759
784
|
// but this is completely wrong and this fn is probably broken. Remove ":any" and you'll see a bunch of type errors
|
|
760
785
|
onChunk: async (chunk) => {
|
|
761
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
|
+
}
|
|
762
795
|
case "step-start": {
|
|
763
796
|
if (!replaceLastMessage) {
|
|
764
797
|
message.id = chunk.payload.messageId;
|
|
@@ -939,8 +972,8 @@ var Agent = class extends BaseResource {
|
|
|
939
972
|
});
|
|
940
973
|
onFinish?.({ message, finishReason, usage });
|
|
941
974
|
}
|
|
942
|
-
async
|
|
943
|
-
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`, {
|
|
944
977
|
method: "POST",
|
|
945
978
|
body: processedParams,
|
|
946
979
|
stream: true
|
|
@@ -955,18 +988,17 @@ var Agent = class extends BaseResource {
|
|
|
955
988
|
streamForWritable.pipeTo(
|
|
956
989
|
new WritableStream({
|
|
957
990
|
async write(chunk) {
|
|
991
|
+
let writer;
|
|
958
992
|
try {
|
|
993
|
+
writer = writable.getWriter();
|
|
959
994
|
const text = new TextDecoder().decode(chunk);
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
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));
|
|
963
998
|
} catch {
|
|
964
|
-
|
|
965
|
-
const writer = writable.getWriter();
|
|
966
|
-
try {
|
|
967
|
-
await writer.write(chunk);
|
|
999
|
+
await writer?.write(chunk);
|
|
968
1000
|
} finally {
|
|
969
|
-
writer
|
|
1001
|
+
writer?.releaseLock();
|
|
970
1002
|
}
|
|
971
1003
|
}
|
|
972
1004
|
}),
|
|
@@ -992,9 +1024,11 @@ var Agent = class extends BaseResource {
|
|
|
992
1024
|
if (toolCall) {
|
|
993
1025
|
toolCalls.push(toolCall);
|
|
994
1026
|
}
|
|
1027
|
+
let shouldExecuteClientTool = false;
|
|
995
1028
|
for (const toolCall2 of toolCalls) {
|
|
996
1029
|
const clientTool = processedParams.clientTools?.[toolCall2.toolName];
|
|
997
1030
|
if (clientTool && clientTool.execute) {
|
|
1031
|
+
shouldExecuteClientTool = true;
|
|
998
1032
|
const result = await clientTool.execute(
|
|
999
1033
|
{
|
|
1000
1034
|
context: toolCall2?.args,
|
|
@@ -1003,7 +1037,9 @@ var Agent = class extends BaseResource {
|
|
|
1003
1037
|
threadId: processedParams.threadId,
|
|
1004
1038
|
runtimeContext: processedParams.runtimeContext,
|
|
1005
1039
|
// TODO: Pass proper tracing context when client-js supports tracing
|
|
1006
|
-
tracingContext: { currentSpan: void 0 }
|
|
1040
|
+
tracingContext: { currentSpan: void 0 },
|
|
1041
|
+
suspend: async () => {
|
|
1042
|
+
}
|
|
1007
1043
|
},
|
|
1008
1044
|
{
|
|
1009
1045
|
messages: response.messages,
|
|
@@ -1029,10 +1065,8 @@ var Agent = class extends BaseResource {
|
|
|
1029
1065
|
toolInvocation.state = "result";
|
|
1030
1066
|
toolInvocation.result = result;
|
|
1031
1067
|
}
|
|
1032
|
-
const
|
|
1033
|
-
|
|
1034
|
-
const updatedMessages = lastMessage != null ? [...messageArray, ...messages.filter((m) => m.id !== lastMessage.id), lastMessage] : [...messageArray, ...messages];
|
|
1035
|
-
this.processStreamResponse_vNext(
|
|
1068
|
+
const updatedMessages = lastMessage != null ? [...messages.filter((m) => m.id !== lastMessage.id), lastMessage] : [...messages];
|
|
1069
|
+
this.processStreamResponse(
|
|
1036
1070
|
{
|
|
1037
1071
|
...processedParams,
|
|
1038
1072
|
messages: updatedMessages
|
|
@@ -1043,6 +1077,11 @@ var Agent = class extends BaseResource {
|
|
|
1043
1077
|
});
|
|
1044
1078
|
}
|
|
1045
1079
|
}
|
|
1080
|
+
if (!shouldExecuteClientTool) {
|
|
1081
|
+
setTimeout(() => {
|
|
1082
|
+
writable.close();
|
|
1083
|
+
}, 0);
|
|
1084
|
+
}
|
|
1046
1085
|
} else {
|
|
1047
1086
|
setTimeout(() => {
|
|
1048
1087
|
writable.close();
|
|
@@ -1058,7 +1097,40 @@ var Agent = class extends BaseResource {
|
|
|
1058
1097
|
}
|
|
1059
1098
|
return response;
|
|
1060
1099
|
}
|
|
1061
|
-
async
|
|
1100
|
+
async network(params) {
|
|
1101
|
+
const response = await this.request(`/api/agents/${this.agentId}/network`, {
|
|
1102
|
+
method: "POST",
|
|
1103
|
+
body: params,
|
|
1104
|
+
stream: true
|
|
1105
|
+
});
|
|
1106
|
+
if (!response.body) {
|
|
1107
|
+
throw new Error("No response body");
|
|
1108
|
+
}
|
|
1109
|
+
const streamResponse = new Response(response.body, {
|
|
1110
|
+
status: response.status,
|
|
1111
|
+
statusText: response.statusText,
|
|
1112
|
+
headers: response.headers
|
|
1113
|
+
});
|
|
1114
|
+
streamResponse.processDataStream = async ({
|
|
1115
|
+
onChunk
|
|
1116
|
+
}) => {
|
|
1117
|
+
await processMastraNetworkStream({
|
|
1118
|
+
stream: streamResponse.body,
|
|
1119
|
+
onChunk
|
|
1120
|
+
});
|
|
1121
|
+
};
|
|
1122
|
+
return streamResponse;
|
|
1123
|
+
}
|
|
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
|
+
}
|
|
1062
1134
|
const processedParams = {
|
|
1063
1135
|
...params,
|
|
1064
1136
|
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
@@ -1070,7 +1142,7 @@ var Agent = class extends BaseResource {
|
|
|
1070
1142
|
} : void 0
|
|
1071
1143
|
};
|
|
1072
1144
|
const { readable, writable } = new TransformStream();
|
|
1073
|
-
const response = await this.
|
|
1145
|
+
const response = await this.processStreamResponse(processedParams, writable);
|
|
1074
1146
|
const streamResponse = new Response(readable, {
|
|
1075
1147
|
status: response.status,
|
|
1076
1148
|
statusText: response.statusText,
|
|
@@ -1089,7 +1161,7 @@ var Agent = class extends BaseResource {
|
|
|
1089
1161
|
/**
|
|
1090
1162
|
* Processes the stream response and handles tool calls
|
|
1091
1163
|
*/
|
|
1092
|
-
async
|
|
1164
|
+
async processStreamResponseLegacy(processedParams, writable) {
|
|
1093
1165
|
const response = await this.request(`/api/agents/${this.agentId}/stream-legacy`, {
|
|
1094
1166
|
method: "POST",
|
|
1095
1167
|
body: processedParams,
|
|
@@ -1134,7 +1206,9 @@ var Agent = class extends BaseResource {
|
|
|
1134
1206
|
threadId: processedParams.threadId,
|
|
1135
1207
|
runtimeContext: processedParams.runtimeContext,
|
|
1136
1208
|
// TODO: Pass proper tracing context when client-js supports tracing
|
|
1137
|
-
tracingContext: { currentSpan: void 0 }
|
|
1209
|
+
tracingContext: { currentSpan: void 0 },
|
|
1210
|
+
suspend: async () => {
|
|
1211
|
+
}
|
|
1138
1212
|
},
|
|
1139
1213
|
{
|
|
1140
1214
|
messages: response.messages,
|
|
@@ -1172,12 +1246,10 @@ var Agent = class extends BaseResource {
|
|
|
1172
1246
|
} finally {
|
|
1173
1247
|
writer.releaseLock();
|
|
1174
1248
|
}
|
|
1175
|
-
|
|
1176
|
-
const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
|
|
1177
|
-
this.processStreamResponse(
|
|
1249
|
+
this.processStreamResponseLegacy(
|
|
1178
1250
|
{
|
|
1179
1251
|
...processedParams,
|
|
1180
|
-
messages: [...
|
|
1252
|
+
messages: [...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
|
|
1181
1253
|
},
|
|
1182
1254
|
writable
|
|
1183
1255
|
).catch((error) => {
|
|
@@ -1203,10 +1275,11 @@ var Agent = class extends BaseResource {
|
|
|
1203
1275
|
/**
|
|
1204
1276
|
* Gets details about a specific tool available to the agent
|
|
1205
1277
|
* @param toolId - ID of the tool to retrieve
|
|
1278
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1206
1279
|
* @returns Promise containing tool details
|
|
1207
1280
|
*/
|
|
1208
|
-
getTool(toolId) {
|
|
1209
|
-
return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
|
|
1281
|
+
getTool(toolId, runtimeContext) {
|
|
1282
|
+
return this.request(`/api/agents/${this.agentId}/tools/${toolId}${runtimeContextQueryString(runtimeContext)}`);
|
|
1210
1283
|
}
|
|
1211
1284
|
/**
|
|
1212
1285
|
* Executes a tool for the agent
|
|
@@ -1217,7 +1290,7 @@ var Agent = class extends BaseResource {
|
|
|
1217
1290
|
executeTool(toolId, params) {
|
|
1218
1291
|
const body = {
|
|
1219
1292
|
data: params.data,
|
|
1220
|
-
runtimeContext:
|
|
1293
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1221
1294
|
};
|
|
1222
1295
|
return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
|
|
1223
1296
|
method: "POST",
|
|
@@ -1226,17 +1299,19 @@ var Agent = class extends BaseResource {
|
|
|
1226
1299
|
}
|
|
1227
1300
|
/**
|
|
1228
1301
|
* Retrieves evaluation results for the agent
|
|
1302
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1229
1303
|
* @returns Promise containing agent evaluations
|
|
1230
1304
|
*/
|
|
1231
|
-
evals() {
|
|
1232
|
-
return this.request(`/api/agents/${this.agentId}/evals/ci`);
|
|
1305
|
+
evals(runtimeContext) {
|
|
1306
|
+
return this.request(`/api/agents/${this.agentId}/evals/ci${runtimeContextQueryString(runtimeContext)}`);
|
|
1233
1307
|
}
|
|
1234
1308
|
/**
|
|
1235
1309
|
* Retrieves live evaluation results for the agent
|
|
1310
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1236
1311
|
* @returns Promise containing live agent evaluations
|
|
1237
1312
|
*/
|
|
1238
|
-
liveEvals() {
|
|
1239
|
-
return this.request(`/api/agents/${this.agentId}/evals/live`);
|
|
1313
|
+
liveEvals(runtimeContext) {
|
|
1314
|
+
return this.request(`/api/agents/${this.agentId}/evals/live${runtimeContextQueryString(runtimeContext)}`);
|
|
1240
1315
|
}
|
|
1241
1316
|
/**
|
|
1242
1317
|
* Updates the model for the agent
|
|
@@ -1249,61 +1324,33 @@ var Agent = class extends BaseResource {
|
|
|
1249
1324
|
body: params
|
|
1250
1325
|
});
|
|
1251
1326
|
}
|
|
1252
|
-
};
|
|
1253
|
-
var Network = class extends BaseResource {
|
|
1254
|
-
constructor(options, networkId) {
|
|
1255
|
-
super(options);
|
|
1256
|
-
this.networkId = networkId;
|
|
1257
|
-
}
|
|
1258
|
-
/**
|
|
1259
|
-
* Retrieves details about the network
|
|
1260
|
-
* @returns Promise containing network details
|
|
1261
|
-
*/
|
|
1262
|
-
details() {
|
|
1263
|
-
return this.request(`/api/networks/${this.networkId}`);
|
|
1264
|
-
}
|
|
1265
1327
|
/**
|
|
1266
|
-
*
|
|
1267
|
-
* @param params -
|
|
1268
|
-
* @returns Promise containing the
|
|
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
|
|
1269
1331
|
*/
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
...params,
|
|
1273
|
-
output: zodToJsonSchema(params.output),
|
|
1274
|
-
experimental_output: zodToJsonSchema(params.experimental_output)
|
|
1275
|
-
};
|
|
1276
|
-
return this.request(`/api/networks/${this.networkId}/generate`, {
|
|
1332
|
+
updateModelInModelList({ modelConfigId, ...params }) {
|
|
1333
|
+
return this.request(`/api/agents/${this.agentId}/models/${modelConfigId}`, {
|
|
1277
1334
|
method: "POST",
|
|
1278
|
-
body:
|
|
1335
|
+
body: params
|
|
1279
1336
|
});
|
|
1280
1337
|
}
|
|
1281
1338
|
/**
|
|
1282
|
-
*
|
|
1283
|
-
* @param params -
|
|
1284
|
-
* @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
|
|
1285
1342
|
*/
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
...params,
|
|
1289
|
-
output: zodToJsonSchema(params.output),
|
|
1290
|
-
experimental_output: zodToJsonSchema(params.experimental_output)
|
|
1291
|
-
};
|
|
1292
|
-
const response = await this.request(`/api/networks/${this.networkId}/stream`, {
|
|
1343
|
+
reorderModelList(params) {
|
|
1344
|
+
return this.request(`/api/agents/${this.agentId}/models/reorder`, {
|
|
1293
1345
|
method: "POST",
|
|
1294
|
-
body:
|
|
1295
|
-
stream: true
|
|
1346
|
+
body: params
|
|
1296
1347
|
});
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
...options
|
|
1304
|
-
});
|
|
1305
|
-
};
|
|
1306
|
-
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.");
|
|
1307
1354
|
}
|
|
1308
1355
|
};
|
|
1309
1356
|
|
|
@@ -1394,10 +1441,13 @@ var Vector = class extends BaseResource {
|
|
|
1394
1441
|
/**
|
|
1395
1442
|
* Retrieves details about a specific vector index
|
|
1396
1443
|
* @param indexName - Name of the index to get details for
|
|
1444
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1397
1445
|
* @returns Promise containing vector index details
|
|
1398
1446
|
*/
|
|
1399
|
-
details(indexName) {
|
|
1400
|
-
return this.request(
|
|
1447
|
+
details(indexName, runtimeContext) {
|
|
1448
|
+
return this.request(
|
|
1449
|
+
`/api/vector/${this.vectorName}/indexes/${indexName}${runtimeContextQueryString(runtimeContext)}`
|
|
1450
|
+
);
|
|
1401
1451
|
}
|
|
1402
1452
|
/**
|
|
1403
1453
|
* Deletes a vector index
|
|
@@ -1411,10 +1461,11 @@ var Vector = class extends BaseResource {
|
|
|
1411
1461
|
}
|
|
1412
1462
|
/**
|
|
1413
1463
|
* Retrieves a list of all available indexes
|
|
1464
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1414
1465
|
* @returns Promise containing array of index names
|
|
1415
1466
|
*/
|
|
1416
|
-
getIndexes() {
|
|
1417
|
-
return this.request(`/api/vector/${this.vectorName}/indexes`);
|
|
1467
|
+
getIndexes(runtimeContext) {
|
|
1468
|
+
return this.request(`/api/vector/${this.vectorName}/indexes${runtimeContextQueryString(runtimeContext)}`);
|
|
1418
1469
|
}
|
|
1419
1470
|
/**
|
|
1420
1471
|
* Creates a new vector index
|
|
@@ -1451,187 +1502,6 @@ var Vector = class extends BaseResource {
|
|
|
1451
1502
|
}
|
|
1452
1503
|
};
|
|
1453
1504
|
|
|
1454
|
-
// src/resources/legacy-workflow.ts
|
|
1455
|
-
var RECORD_SEPARATOR = "";
|
|
1456
|
-
var LegacyWorkflow = class extends BaseResource {
|
|
1457
|
-
constructor(options, workflowId) {
|
|
1458
|
-
super(options);
|
|
1459
|
-
this.workflowId = workflowId;
|
|
1460
|
-
}
|
|
1461
|
-
/**
|
|
1462
|
-
* Retrieves details about the legacy workflow
|
|
1463
|
-
* @returns Promise containing legacy workflow details including steps and graphs
|
|
1464
|
-
*/
|
|
1465
|
-
details() {
|
|
1466
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}`);
|
|
1467
|
-
}
|
|
1468
|
-
/**
|
|
1469
|
-
* Retrieves all runs for a legacy workflow
|
|
1470
|
-
* @param params - Parameters for filtering runs
|
|
1471
|
-
* @returns Promise containing legacy workflow runs array
|
|
1472
|
-
*/
|
|
1473
|
-
runs(params) {
|
|
1474
|
-
const searchParams = new URLSearchParams();
|
|
1475
|
-
if (params?.fromDate) {
|
|
1476
|
-
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
1477
|
-
}
|
|
1478
|
-
if (params?.toDate) {
|
|
1479
|
-
searchParams.set("toDate", params.toDate.toISOString());
|
|
1480
|
-
}
|
|
1481
|
-
if (params?.limit) {
|
|
1482
|
-
searchParams.set("limit", String(params.limit));
|
|
1483
|
-
}
|
|
1484
|
-
if (params?.offset) {
|
|
1485
|
-
searchParams.set("offset", String(params.offset));
|
|
1486
|
-
}
|
|
1487
|
-
if (params?.resourceId) {
|
|
1488
|
-
searchParams.set("resourceId", params.resourceId);
|
|
1489
|
-
}
|
|
1490
|
-
if (searchParams.size) {
|
|
1491
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/runs?${searchParams}`);
|
|
1492
|
-
} else {
|
|
1493
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/runs`);
|
|
1494
|
-
}
|
|
1495
|
-
}
|
|
1496
|
-
/**
|
|
1497
|
-
* Creates a new legacy workflow run
|
|
1498
|
-
* @returns Promise containing the generated run ID
|
|
1499
|
-
*/
|
|
1500
|
-
createRun(params) {
|
|
1501
|
-
const searchParams = new URLSearchParams();
|
|
1502
|
-
if (!!params?.runId) {
|
|
1503
|
-
searchParams.set("runId", params.runId);
|
|
1504
|
-
}
|
|
1505
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/create-run?${searchParams.toString()}`, {
|
|
1506
|
-
method: "POST"
|
|
1507
|
-
});
|
|
1508
|
-
}
|
|
1509
|
-
/**
|
|
1510
|
-
* Starts a legacy workflow run synchronously without waiting for the workflow to complete
|
|
1511
|
-
* @param params - Object containing the runId and triggerData
|
|
1512
|
-
* @returns Promise containing success message
|
|
1513
|
-
*/
|
|
1514
|
-
start(params) {
|
|
1515
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/start?runId=${params.runId}`, {
|
|
1516
|
-
method: "POST",
|
|
1517
|
-
body: params?.triggerData
|
|
1518
|
-
});
|
|
1519
|
-
}
|
|
1520
|
-
/**
|
|
1521
|
-
* Resumes a suspended legacy workflow step synchronously without waiting for the workflow to complete
|
|
1522
|
-
* @param stepId - ID of the step to resume
|
|
1523
|
-
* @param runId - ID of the legacy workflow run
|
|
1524
|
-
* @param context - Context to resume the legacy workflow with
|
|
1525
|
-
* @returns Promise containing the legacy workflow resume results
|
|
1526
|
-
*/
|
|
1527
|
-
resume({
|
|
1528
|
-
stepId,
|
|
1529
|
-
runId,
|
|
1530
|
-
context
|
|
1531
|
-
}) {
|
|
1532
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/resume?runId=${runId}`, {
|
|
1533
|
-
method: "POST",
|
|
1534
|
-
body: {
|
|
1535
|
-
stepId,
|
|
1536
|
-
context
|
|
1537
|
-
}
|
|
1538
|
-
});
|
|
1539
|
-
}
|
|
1540
|
-
/**
|
|
1541
|
-
* Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
|
|
1542
|
-
* @param params - Object containing the optional runId and triggerData
|
|
1543
|
-
* @returns Promise containing the workflow execution results
|
|
1544
|
-
*/
|
|
1545
|
-
startAsync(params) {
|
|
1546
|
-
const searchParams = new URLSearchParams();
|
|
1547
|
-
if (!!params?.runId) {
|
|
1548
|
-
searchParams.set("runId", params.runId);
|
|
1549
|
-
}
|
|
1550
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
1551
|
-
method: "POST",
|
|
1552
|
-
body: params?.triggerData
|
|
1553
|
-
});
|
|
1554
|
-
}
|
|
1555
|
-
/**
|
|
1556
|
-
* Resumes a suspended legacy workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
1557
|
-
* @param params - Object containing the runId, stepId, and context
|
|
1558
|
-
* @returns Promise containing the workflow resume results
|
|
1559
|
-
*/
|
|
1560
|
-
resumeAsync(params) {
|
|
1561
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
1562
|
-
method: "POST",
|
|
1563
|
-
body: {
|
|
1564
|
-
stepId: params.stepId,
|
|
1565
|
-
context: params.context
|
|
1566
|
-
}
|
|
1567
|
-
});
|
|
1568
|
-
}
|
|
1569
|
-
/**
|
|
1570
|
-
* Creates an async generator that processes a readable stream and yields records
|
|
1571
|
-
* separated by the Record Separator character (\x1E)
|
|
1572
|
-
*
|
|
1573
|
-
* @param stream - The readable stream to process
|
|
1574
|
-
* @returns An async generator that yields parsed records
|
|
1575
|
-
*/
|
|
1576
|
-
async *streamProcessor(stream) {
|
|
1577
|
-
const reader = stream.getReader();
|
|
1578
|
-
let doneReading = false;
|
|
1579
|
-
let buffer = "";
|
|
1580
|
-
try {
|
|
1581
|
-
while (!doneReading) {
|
|
1582
|
-
const { done, value } = await reader.read();
|
|
1583
|
-
doneReading = done;
|
|
1584
|
-
if (done && !value) continue;
|
|
1585
|
-
try {
|
|
1586
|
-
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
1587
|
-
const chunks = (buffer + decoded).split(RECORD_SEPARATOR);
|
|
1588
|
-
buffer = chunks.pop() || "";
|
|
1589
|
-
for (const chunk of chunks) {
|
|
1590
|
-
if (chunk) {
|
|
1591
|
-
if (typeof chunk === "string") {
|
|
1592
|
-
try {
|
|
1593
|
-
const parsedChunk = JSON.parse(chunk);
|
|
1594
|
-
yield parsedChunk;
|
|
1595
|
-
} catch {
|
|
1596
|
-
}
|
|
1597
|
-
}
|
|
1598
|
-
}
|
|
1599
|
-
}
|
|
1600
|
-
} catch {
|
|
1601
|
-
}
|
|
1602
|
-
}
|
|
1603
|
-
if (buffer) {
|
|
1604
|
-
try {
|
|
1605
|
-
yield JSON.parse(buffer);
|
|
1606
|
-
} catch {
|
|
1607
|
-
}
|
|
1608
|
-
}
|
|
1609
|
-
} finally {
|
|
1610
|
-
reader.cancel().catch(() => {
|
|
1611
|
-
});
|
|
1612
|
-
}
|
|
1613
|
-
}
|
|
1614
|
-
/**
|
|
1615
|
-
* Watches legacy workflow transitions in real-time
|
|
1616
|
-
* @param runId - Optional run ID to filter the watch stream
|
|
1617
|
-
* @returns AsyncGenerator that yields parsed records from the legacy workflow watch stream
|
|
1618
|
-
*/
|
|
1619
|
-
async watch({ runId }, onRecord) {
|
|
1620
|
-
const response = await this.request(`/api/workflows/legacy/${this.workflowId}/watch?runId=${runId}`, {
|
|
1621
|
-
stream: true
|
|
1622
|
-
});
|
|
1623
|
-
if (!response.ok) {
|
|
1624
|
-
throw new Error(`Failed to watch legacy workflow: ${response.statusText}`);
|
|
1625
|
-
}
|
|
1626
|
-
if (!response.body) {
|
|
1627
|
-
throw new Error("Response body is null");
|
|
1628
|
-
}
|
|
1629
|
-
for await (const record of this.streamProcessor(response.body)) {
|
|
1630
|
-
onRecord(record);
|
|
1631
|
-
}
|
|
1632
|
-
}
|
|
1633
|
-
};
|
|
1634
|
-
|
|
1635
1505
|
// src/resources/tool.ts
|
|
1636
1506
|
var Tool = class extends BaseResource {
|
|
1637
1507
|
constructor(options, toolId) {
|
|
@@ -1640,10 +1510,11 @@ var Tool = class extends BaseResource {
|
|
|
1640
1510
|
}
|
|
1641
1511
|
/**
|
|
1642
1512
|
* Retrieves details about the tool
|
|
1513
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1643
1514
|
* @returns Promise containing tool details including description and schemas
|
|
1644
1515
|
*/
|
|
1645
|
-
details() {
|
|
1646
|
-
return this.request(`/api/tools/${this.toolId}`);
|
|
1516
|
+
details(runtimeContext) {
|
|
1517
|
+
return this.request(`/api/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
|
|
1647
1518
|
}
|
|
1648
1519
|
/**
|
|
1649
1520
|
* Executes the tool with the provided parameters
|
|
@@ -1667,7 +1538,7 @@ var Tool = class extends BaseResource {
|
|
|
1667
1538
|
};
|
|
1668
1539
|
|
|
1669
1540
|
// src/resources/workflow.ts
|
|
1670
|
-
var
|
|
1541
|
+
var RECORD_SEPARATOR = "";
|
|
1671
1542
|
var Workflow = class extends BaseResource {
|
|
1672
1543
|
constructor(options, workflowId) {
|
|
1673
1544
|
super(options);
|
|
@@ -1691,7 +1562,7 @@ var Workflow = class extends BaseResource {
|
|
|
1691
1562
|
if (done && !value) continue;
|
|
1692
1563
|
try {
|
|
1693
1564
|
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
1694
|
-
const chunks = (buffer + decoded).split(
|
|
1565
|
+
const chunks = (buffer + decoded).split(RECORD_SEPARATOR);
|
|
1695
1566
|
buffer = chunks.pop() || "";
|
|
1696
1567
|
for (const chunk of chunks) {
|
|
1697
1568
|
if (chunk) {
|
|
@@ -1720,17 +1591,20 @@ var Workflow = class extends BaseResource {
|
|
|
1720
1591
|
}
|
|
1721
1592
|
/**
|
|
1722
1593
|
* Retrieves details about the workflow
|
|
1594
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1723
1595
|
* @returns Promise containing workflow details including steps and graphs
|
|
1724
1596
|
*/
|
|
1725
|
-
details() {
|
|
1726
|
-
return this.request(`/api/workflows/${this.workflowId}`);
|
|
1597
|
+
details(runtimeContext) {
|
|
1598
|
+
return this.request(`/api/workflows/${this.workflowId}${runtimeContextQueryString(runtimeContext)}`);
|
|
1727
1599
|
}
|
|
1728
1600
|
/**
|
|
1729
1601
|
* Retrieves all runs for a workflow
|
|
1730
1602
|
* @param params - Parameters for filtering runs
|
|
1603
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1731
1604
|
* @returns Promise containing workflow runs array
|
|
1732
1605
|
*/
|
|
1733
|
-
runs(params) {
|
|
1606
|
+
runs(params, runtimeContext) {
|
|
1607
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
1734
1608
|
const searchParams = new URLSearchParams();
|
|
1735
1609
|
if (params?.fromDate) {
|
|
1736
1610
|
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
@@ -1747,6 +1621,9 @@ var Workflow = class extends BaseResource {
|
|
|
1747
1621
|
if (params?.resourceId) {
|
|
1748
1622
|
searchParams.set("resourceId", params.resourceId);
|
|
1749
1623
|
}
|
|
1624
|
+
if (runtimeContextParam) {
|
|
1625
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
1626
|
+
}
|
|
1750
1627
|
if (searchParams.size) {
|
|
1751
1628
|
return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
|
|
1752
1629
|
} else {
|
|
@@ -1756,18 +1633,22 @@ var Workflow = class extends BaseResource {
|
|
|
1756
1633
|
/**
|
|
1757
1634
|
* Retrieves a specific workflow run by its ID
|
|
1758
1635
|
* @param runId - The ID of the workflow run to retrieve
|
|
1636
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1759
1637
|
* @returns Promise containing the workflow run details
|
|
1760
1638
|
*/
|
|
1761
|
-
runById(runId) {
|
|
1762
|
-
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)}`);
|
|
1763
1641
|
}
|
|
1764
1642
|
/**
|
|
1765
1643
|
* Retrieves the execution result for a specific workflow run by its ID
|
|
1766
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
|
|
1767
1646
|
* @returns Promise containing the workflow run execution result
|
|
1768
1647
|
*/
|
|
1769
|
-
runExecutionResult(runId) {
|
|
1770
|
-
return this.request(
|
|
1648
|
+
runExecutionResult(runId, runtimeContext) {
|
|
1649
|
+
return this.request(
|
|
1650
|
+
`/api/workflows/${this.workflowId}/runs/${runId}/execution-result${runtimeContextQueryString(runtimeContext)}`
|
|
1651
|
+
);
|
|
1771
1652
|
}
|
|
1772
1653
|
/**
|
|
1773
1654
|
* Cancels a specific workflow run by its ID
|
|
@@ -1791,26 +1672,82 @@ var Workflow = class extends BaseResource {
|
|
|
1791
1672
|
});
|
|
1792
1673
|
}
|
|
1793
1674
|
/**
|
|
1794
|
-
*
|
|
1795
|
-
* @
|
|
1796
|
-
* @returns Promise containing the runId of the created run
|
|
1675
|
+
* @deprecated Use createRunAsync() instead.
|
|
1676
|
+
* @throws {Error} Always throws an error directing users to use createRunAsync()
|
|
1797
1677
|
*/
|
|
1798
|
-
createRun(
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
}
|
|
1803
|
-
return this.request(`/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`, {
|
|
1804
|
-
method: "POST"
|
|
1805
|
-
});
|
|
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
|
+
);
|
|
1806
1682
|
}
|
|
1807
1683
|
/**
|
|
1808
|
-
* Creates a new workflow run
|
|
1684
|
+
* Creates a new workflow run
|
|
1809
1685
|
* @param params - Optional object containing the optional runId
|
|
1810
|
-
* @returns Promise containing the runId of the created run
|
|
1686
|
+
* @returns Promise containing the runId of the created run with methods to control execution
|
|
1811
1687
|
*/
|
|
1812
|
-
createRunAsync(params) {
|
|
1813
|
-
|
|
1688
|
+
async createRunAsync(params) {
|
|
1689
|
+
const searchParams = new URLSearchParams();
|
|
1690
|
+
if (!!params?.runId) {
|
|
1691
|
+
searchParams.set("runId", params.runId);
|
|
1692
|
+
}
|
|
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
|
+
};
|
|
1814
1751
|
}
|
|
1815
1752
|
/**
|
|
1816
1753
|
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
@@ -1821,7 +1758,7 @@ var Workflow = class extends BaseResource {
|
|
|
1821
1758
|
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1822
1759
|
return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
|
|
1823
1760
|
method: "POST",
|
|
1824
|
-
body: { inputData: params?.inputData, runtimeContext }
|
|
1761
|
+
body: { inputData: params?.inputData, runtimeContext, tracingOptions: params.tracingOptions }
|
|
1825
1762
|
});
|
|
1826
1763
|
}
|
|
1827
1764
|
/**
|
|
@@ -1833,16 +1770,17 @@ var Workflow = class extends BaseResource {
|
|
|
1833
1770
|
step,
|
|
1834
1771
|
runId,
|
|
1835
1772
|
resumeData,
|
|
1773
|
+
tracingOptions,
|
|
1836
1774
|
...rest
|
|
1837
1775
|
}) {
|
|
1838
1776
|
const runtimeContext = parseClientRuntimeContext(rest.runtimeContext);
|
|
1839
1777
|
return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
|
|
1840
1778
|
method: "POST",
|
|
1841
|
-
stream: true,
|
|
1842
1779
|
body: {
|
|
1843
1780
|
step,
|
|
1844
1781
|
resumeData,
|
|
1845
|
-
runtimeContext
|
|
1782
|
+
runtimeContext,
|
|
1783
|
+
tracingOptions
|
|
1846
1784
|
}
|
|
1847
1785
|
});
|
|
1848
1786
|
}
|
|
@@ -1859,7 +1797,7 @@ var Workflow = class extends BaseResource {
|
|
|
1859
1797
|
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1860
1798
|
return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
1861
1799
|
method: "POST",
|
|
1862
|
-
body: { inputData: params.inputData, runtimeContext }
|
|
1800
|
+
body: { inputData: params.inputData, runtimeContext, tracingOptions: params.tracingOptions }
|
|
1863
1801
|
});
|
|
1864
1802
|
}
|
|
1865
1803
|
/**
|
|
@@ -1877,12 +1815,12 @@ var Workflow = class extends BaseResource {
|
|
|
1877
1815
|
`/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
|
|
1878
1816
|
{
|
|
1879
1817
|
method: "POST",
|
|
1880
|
-
body: { inputData: params.inputData, runtimeContext },
|
|
1818
|
+
body: { inputData: params.inputData, runtimeContext, tracingOptions: params.tracingOptions },
|
|
1881
1819
|
stream: true
|
|
1882
1820
|
}
|
|
1883
1821
|
);
|
|
1884
1822
|
if (!response.ok) {
|
|
1885
|
-
throw new Error(`Failed to stream
|
|
1823
|
+
throw new Error(`Failed to stream workflow: ${response.statusText}`);
|
|
1886
1824
|
}
|
|
1887
1825
|
if (!response.body) {
|
|
1888
1826
|
throw new Error("Response body is null");
|
|
@@ -1894,7 +1832,54 @@ var Workflow = class extends BaseResource {
|
|
|
1894
1832
|
async transform(chunk, controller) {
|
|
1895
1833
|
try {
|
|
1896
1834
|
const decoded = new TextDecoder().decode(chunk);
|
|
1897
|
-
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);
|
|
1898
1883
|
for (const chunk2 of chunks) {
|
|
1899
1884
|
if (chunk2) {
|
|
1900
1885
|
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
@@ -1928,7 +1913,12 @@ var Workflow = class extends BaseResource {
|
|
|
1928
1913
|
`/api/workflows/${this.workflowId}/streamVNext?${searchParams.toString()}`,
|
|
1929
1914
|
{
|
|
1930
1915
|
method: "POST",
|
|
1931
|
-
body: {
|
|
1916
|
+
body: {
|
|
1917
|
+
inputData: params.inputData,
|
|
1918
|
+
runtimeContext,
|
|
1919
|
+
closeOnSuspend: params.closeOnSuspend,
|
|
1920
|
+
tracingOptions: params.tracingOptions
|
|
1921
|
+
},
|
|
1932
1922
|
stream: true
|
|
1933
1923
|
}
|
|
1934
1924
|
);
|
|
@@ -1945,7 +1935,54 @@ var Workflow = class extends BaseResource {
|
|
|
1945
1935
|
async transform(chunk, controller) {
|
|
1946
1936
|
try {
|
|
1947
1937
|
const decoded = new TextDecoder().decode(chunk);
|
|
1948
|
-
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);
|
|
1949
1986
|
for (const chunk2 of chunks) {
|
|
1950
1987
|
if (chunk2) {
|
|
1951
1988
|
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
@@ -1976,9 +2013,64 @@ var Workflow = class extends BaseResource {
|
|
|
1976
2013
|
body: {
|
|
1977
2014
|
step: params.step,
|
|
1978
2015
|
resumeData: params.resumeData,
|
|
1979
|
-
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
|
+
}
|
|
1980
2071
|
}
|
|
1981
2072
|
});
|
|
2073
|
+
return response.body.pipeThrough(transformStream);
|
|
1982
2074
|
}
|
|
1983
2075
|
/**
|
|
1984
2076
|
* Watches workflow transitions in real-time
|
|
@@ -2016,7 +2108,7 @@ var Workflow = class extends BaseResource {
|
|
|
2016
2108
|
async start(controller) {
|
|
2017
2109
|
try {
|
|
2018
2110
|
for await (const record of records) {
|
|
2019
|
-
const json = JSON.stringify(record) +
|
|
2111
|
+
const json = JSON.stringify(record) + RECORD_SEPARATOR;
|
|
2020
2112
|
controller.enqueue(encoder.encode(json));
|
|
2021
2113
|
}
|
|
2022
2114
|
controller.close();
|
|
@@ -2114,10 +2206,11 @@ var MCPTool = class extends BaseResource {
|
|
|
2114
2206
|
}
|
|
2115
2207
|
/**
|
|
2116
2208
|
* Retrieves details about this specific tool from the MCP server.
|
|
2209
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2117
2210
|
* @returns Promise containing the tool's information (name, description, schema).
|
|
2118
2211
|
*/
|
|
2119
|
-
details() {
|
|
2120
|
-
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)}`);
|
|
2121
2214
|
}
|
|
2122
2215
|
/**
|
|
2123
2216
|
* Executes this specific tool on the MCP server.
|
|
@@ -2138,7 +2231,7 @@ var MCPTool = class extends BaseResource {
|
|
|
2138
2231
|
};
|
|
2139
2232
|
|
|
2140
2233
|
// src/resources/agent-builder.ts
|
|
2141
|
-
var
|
|
2234
|
+
var RECORD_SEPARATOR2 = "";
|
|
2142
2235
|
var AgentBuilder = class extends BaseResource {
|
|
2143
2236
|
constructor(options, actionId) {
|
|
2144
2237
|
super(options);
|
|
@@ -2173,11 +2266,20 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2173
2266
|
};
|
|
2174
2267
|
}
|
|
2175
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
|
+
}
|
|
2176
2278
|
/**
|
|
2177
2279
|
* Creates a new agent builder action run and returns the runId.
|
|
2178
2280
|
* This calls `/api/agent-builder/:actionId/create-run`.
|
|
2179
2281
|
*/
|
|
2180
|
-
async
|
|
2282
|
+
async createRunAsync(params) {
|
|
2181
2283
|
const searchParams = new URLSearchParams();
|
|
2182
2284
|
if (!!params?.runId) {
|
|
2183
2285
|
searchParams.set("runId", params.runId);
|
|
@@ -2187,14 +2289,6 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2187
2289
|
method: "POST"
|
|
2188
2290
|
});
|
|
2189
2291
|
}
|
|
2190
|
-
/**
|
|
2191
|
-
* Creates a new workflow run (alias for createRun)
|
|
2192
|
-
* @param params - Optional object containing the optional runId
|
|
2193
|
-
* @returns Promise containing the runId of the created run
|
|
2194
|
-
*/
|
|
2195
|
-
createRunAsync(params) {
|
|
2196
|
-
return this.createRun(params);
|
|
2197
|
-
}
|
|
2198
2292
|
/**
|
|
2199
2293
|
* Starts agent builder action asynchronously and waits for completion.
|
|
2200
2294
|
* This calls `/api/agent-builder/:actionId/start-async`.
|
|
@@ -2277,7 +2371,7 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2277
2371
|
if (done && !value) continue;
|
|
2278
2372
|
try {
|
|
2279
2373
|
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
2280
|
-
const chunks = (buffer + decoded).split(
|
|
2374
|
+
const chunks = (buffer + decoded).split(RECORD_SEPARATOR2);
|
|
2281
2375
|
buffer = chunks.pop() || "";
|
|
2282
2376
|
for (const chunk of chunks) {
|
|
2283
2377
|
if (chunk) {
|
|
@@ -2334,7 +2428,7 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2334
2428
|
async transform(chunk, controller) {
|
|
2335
2429
|
try {
|
|
2336
2430
|
const decoded = new TextDecoder().decode(chunk);
|
|
2337
|
-
const chunks = decoded.split(
|
|
2431
|
+
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
2338
2432
|
for (const chunk2 of chunks) {
|
|
2339
2433
|
if (chunk2) {
|
|
2340
2434
|
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
@@ -2383,7 +2477,7 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2383
2477
|
async transform(chunk, controller) {
|
|
2384
2478
|
try {
|
|
2385
2479
|
const decoded = new TextDecoder().decode(chunk);
|
|
2386
|
-
const chunks = decoded.split(
|
|
2480
|
+
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
2387
2481
|
for (const chunk2 of chunks) {
|
|
2388
2482
|
if (chunk2) {
|
|
2389
2483
|
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
@@ -2554,6 +2648,31 @@ var Observability = class extends BaseResource {
|
|
|
2554
2648
|
const queryString = searchParams.toString();
|
|
2555
2649
|
return this.request(`/api/observability/traces${queryString ? `?${queryString}` : ""}`);
|
|
2556
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
|
+
}
|
|
2557
2676
|
};
|
|
2558
2677
|
|
|
2559
2678
|
// src/resources/network-memory-thread.ts
|
|
@@ -2619,144 +2738,6 @@ var NetworkMemoryThread = class extends BaseResource {
|
|
|
2619
2738
|
}
|
|
2620
2739
|
};
|
|
2621
2740
|
|
|
2622
|
-
// src/resources/vNextNetwork.ts
|
|
2623
|
-
var RECORD_SEPARATOR4 = "";
|
|
2624
|
-
var VNextNetwork = class extends BaseResource {
|
|
2625
|
-
constructor(options, networkId) {
|
|
2626
|
-
super(options);
|
|
2627
|
-
this.networkId = networkId;
|
|
2628
|
-
}
|
|
2629
|
-
/**
|
|
2630
|
-
* Retrieves details about the network
|
|
2631
|
-
* @returns Promise containing vNext network details
|
|
2632
|
-
*/
|
|
2633
|
-
details() {
|
|
2634
|
-
return this.request(`/api/networks/v-next/${this.networkId}`);
|
|
2635
|
-
}
|
|
2636
|
-
/**
|
|
2637
|
-
* Generates a response from the v-next network
|
|
2638
|
-
* @param params - Generation parameters including message
|
|
2639
|
-
* @returns Promise containing the generated response
|
|
2640
|
-
*/
|
|
2641
|
-
generate(params) {
|
|
2642
|
-
return this.request(`/api/networks/v-next/${this.networkId}/generate`, {
|
|
2643
|
-
method: "POST",
|
|
2644
|
-
body: {
|
|
2645
|
-
...params,
|
|
2646
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
2647
|
-
}
|
|
2648
|
-
});
|
|
2649
|
-
}
|
|
2650
|
-
/**
|
|
2651
|
-
* Generates a response from the v-next network using multiple primitives
|
|
2652
|
-
* @param params - Generation parameters including message
|
|
2653
|
-
* @returns Promise containing the generated response
|
|
2654
|
-
*/
|
|
2655
|
-
loop(params) {
|
|
2656
|
-
return this.request(`/api/networks/v-next/${this.networkId}/loop`, {
|
|
2657
|
-
method: "POST",
|
|
2658
|
-
body: {
|
|
2659
|
-
...params,
|
|
2660
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
2661
|
-
}
|
|
2662
|
-
});
|
|
2663
|
-
}
|
|
2664
|
-
async *streamProcessor(stream) {
|
|
2665
|
-
const reader = stream.getReader();
|
|
2666
|
-
let doneReading = false;
|
|
2667
|
-
let buffer = "";
|
|
2668
|
-
try {
|
|
2669
|
-
while (!doneReading) {
|
|
2670
|
-
const { done, value } = await reader.read();
|
|
2671
|
-
doneReading = done;
|
|
2672
|
-
if (done && !value) continue;
|
|
2673
|
-
try {
|
|
2674
|
-
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
2675
|
-
const chunks = (buffer + decoded).split(RECORD_SEPARATOR4);
|
|
2676
|
-
buffer = chunks.pop() || "";
|
|
2677
|
-
for (const chunk of chunks) {
|
|
2678
|
-
if (chunk) {
|
|
2679
|
-
if (typeof chunk === "string") {
|
|
2680
|
-
try {
|
|
2681
|
-
const parsedChunk = JSON.parse(chunk);
|
|
2682
|
-
yield parsedChunk;
|
|
2683
|
-
} catch {
|
|
2684
|
-
}
|
|
2685
|
-
}
|
|
2686
|
-
}
|
|
2687
|
-
}
|
|
2688
|
-
} catch {
|
|
2689
|
-
}
|
|
2690
|
-
}
|
|
2691
|
-
if (buffer) {
|
|
2692
|
-
try {
|
|
2693
|
-
yield JSON.parse(buffer);
|
|
2694
|
-
} catch {
|
|
2695
|
-
}
|
|
2696
|
-
}
|
|
2697
|
-
} finally {
|
|
2698
|
-
reader.cancel().catch(() => {
|
|
2699
|
-
});
|
|
2700
|
-
}
|
|
2701
|
-
}
|
|
2702
|
-
/**
|
|
2703
|
-
* Streams a response from the v-next network
|
|
2704
|
-
* @param params - Stream parameters including message
|
|
2705
|
-
* @returns Promise containing the results
|
|
2706
|
-
*/
|
|
2707
|
-
async stream(params, onRecord) {
|
|
2708
|
-
const response = await this.request(`/api/networks/v-next/${this.networkId}/stream`, {
|
|
2709
|
-
method: "POST",
|
|
2710
|
-
body: {
|
|
2711
|
-
...params,
|
|
2712
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
2713
|
-
},
|
|
2714
|
-
stream: true
|
|
2715
|
-
});
|
|
2716
|
-
if (!response.ok) {
|
|
2717
|
-
throw new Error(`Failed to stream vNext network: ${response.statusText}`);
|
|
2718
|
-
}
|
|
2719
|
-
if (!response.body) {
|
|
2720
|
-
throw new Error("Response body is null");
|
|
2721
|
-
}
|
|
2722
|
-
for await (const record of this.streamProcessor(response.body)) {
|
|
2723
|
-
if (typeof record === "string") {
|
|
2724
|
-
onRecord(JSON.parse(record));
|
|
2725
|
-
} else {
|
|
2726
|
-
onRecord(record);
|
|
2727
|
-
}
|
|
2728
|
-
}
|
|
2729
|
-
}
|
|
2730
|
-
/**
|
|
2731
|
-
* Streams a response from the v-next network loop
|
|
2732
|
-
* @param params - Stream parameters including message
|
|
2733
|
-
* @returns Promise containing the results
|
|
2734
|
-
*/
|
|
2735
|
-
async loopStream(params, onRecord) {
|
|
2736
|
-
const response = await this.request(`/api/networks/v-next/${this.networkId}/loop-stream`, {
|
|
2737
|
-
method: "POST",
|
|
2738
|
-
body: {
|
|
2739
|
-
...params,
|
|
2740
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
2741
|
-
},
|
|
2742
|
-
stream: true
|
|
2743
|
-
});
|
|
2744
|
-
if (!response.ok) {
|
|
2745
|
-
throw new Error(`Failed to stream vNext network loop: ${response.statusText}`);
|
|
2746
|
-
}
|
|
2747
|
-
if (!response.body) {
|
|
2748
|
-
throw new Error("Response body is null");
|
|
2749
|
-
}
|
|
2750
|
-
for await (const record of this.streamProcessor(response.body)) {
|
|
2751
|
-
if (typeof record === "string") {
|
|
2752
|
-
onRecord(JSON.parse(record));
|
|
2753
|
-
} else {
|
|
2754
|
-
onRecord(record);
|
|
2755
|
-
}
|
|
2756
|
-
}
|
|
2757
|
-
}
|
|
2758
|
-
};
|
|
2759
|
-
|
|
2760
2741
|
// src/client.ts
|
|
2761
2742
|
var MastraClient = class extends BaseResource {
|
|
2762
2743
|
observability;
|
|
@@ -2766,10 +2747,17 @@ var MastraClient = class extends BaseResource {
|
|
|
2766
2747
|
}
|
|
2767
2748
|
/**
|
|
2768
2749
|
* Retrieves all available agents
|
|
2750
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2769
2751
|
* @returns Promise containing map of agent IDs to agent details
|
|
2770
2752
|
*/
|
|
2771
|
-
getAgents() {
|
|
2772
|
-
|
|
2753
|
+
getAgents(runtimeContext) {
|
|
2754
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
2755
|
+
const searchParams = new URLSearchParams();
|
|
2756
|
+
if (runtimeContextParam) {
|
|
2757
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
2758
|
+
}
|
|
2759
|
+
const queryString = searchParams.toString();
|
|
2760
|
+
return this.request(`/api/agents${queryString ? `?${queryString}` : ""}`);
|
|
2773
2761
|
}
|
|
2774
2762
|
/**
|
|
2775
2763
|
* Gets an agent instance by ID
|
|
@@ -2787,6 +2775,14 @@ var MastraClient = class extends BaseResource {
|
|
|
2787
2775
|
getMemoryThreads(params) {
|
|
2788
2776
|
return this.request(`/api/memory/threads?resourceid=${params.resourceId}&agentId=${params.agentId}`);
|
|
2789
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
|
+
}
|
|
2790
2786
|
/**
|
|
2791
2787
|
* Creates a new memory thread
|
|
2792
2788
|
* @param params - Parameters for creating the memory thread
|
|
@@ -2803,6 +2799,24 @@ var MastraClient = class extends BaseResource {
|
|
|
2803
2799
|
getMemoryThread(threadId, agentId) {
|
|
2804
2800
|
return new MemoryThread(this.options, threadId, agentId);
|
|
2805
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
|
+
}
|
|
2806
2820
|
/**
|
|
2807
2821
|
* Saves messages to memory
|
|
2808
2822
|
* @param params - Parameters containing messages to save
|
|
@@ -2865,10 +2879,17 @@ var MastraClient = class extends BaseResource {
|
|
|
2865
2879
|
}
|
|
2866
2880
|
/**
|
|
2867
2881
|
* Retrieves all available tools
|
|
2882
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2868
2883
|
* @returns Promise containing map of tool IDs to tool details
|
|
2869
2884
|
*/
|
|
2870
|
-
getTools() {
|
|
2871
|
-
|
|
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}` : ""}`);
|
|
2872
2893
|
}
|
|
2873
2894
|
/**
|
|
2874
2895
|
* Gets a tool instance by ID
|
|
@@ -2878,27 +2899,19 @@ var MastraClient = class extends BaseResource {
|
|
|
2878
2899
|
getTool(toolId) {
|
|
2879
2900
|
return new Tool(this.options, toolId);
|
|
2880
2901
|
}
|
|
2881
|
-
/**
|
|
2882
|
-
* Retrieves all available legacy workflows
|
|
2883
|
-
* @returns Promise containing map of legacy workflow IDs to legacy workflow details
|
|
2884
|
-
*/
|
|
2885
|
-
getLegacyWorkflows() {
|
|
2886
|
-
return this.request("/api/workflows/legacy");
|
|
2887
|
-
}
|
|
2888
|
-
/**
|
|
2889
|
-
* Gets a legacy workflow instance by ID
|
|
2890
|
-
* @param workflowId - ID of the legacy workflow to retrieve
|
|
2891
|
-
* @returns Legacy Workflow instance
|
|
2892
|
-
*/
|
|
2893
|
-
getLegacyWorkflow(workflowId) {
|
|
2894
|
-
return new LegacyWorkflow(this.options, workflowId);
|
|
2895
|
-
}
|
|
2896
2902
|
/**
|
|
2897
2903
|
* Retrieves all available workflows
|
|
2904
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2898
2905
|
* @returns Promise containing map of workflow IDs to workflow details
|
|
2899
2906
|
*/
|
|
2900
|
-
getWorkflows() {
|
|
2901
|
-
|
|
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}` : ""}`);
|
|
2902
2915
|
}
|
|
2903
2916
|
/**
|
|
2904
2917
|
* Gets a workflow instance by ID
|
|
@@ -3066,36 +3079,6 @@ var MastraClient = class extends BaseResource {
|
|
|
3066
3079
|
return this.request(`/api/telemetry`);
|
|
3067
3080
|
}
|
|
3068
3081
|
}
|
|
3069
|
-
/**
|
|
3070
|
-
* Retrieves all available networks
|
|
3071
|
-
* @returns Promise containing map of network IDs to network details
|
|
3072
|
-
*/
|
|
3073
|
-
getNetworks() {
|
|
3074
|
-
return this.request("/api/networks");
|
|
3075
|
-
}
|
|
3076
|
-
/**
|
|
3077
|
-
* Retrieves all available vNext networks
|
|
3078
|
-
* @returns Promise containing map of vNext network IDs to vNext network details
|
|
3079
|
-
*/
|
|
3080
|
-
getVNextNetworks() {
|
|
3081
|
-
return this.request("/api/networks/v-next");
|
|
3082
|
-
}
|
|
3083
|
-
/**
|
|
3084
|
-
* Gets a network instance by ID
|
|
3085
|
-
* @param networkId - ID of the network to retrieve
|
|
3086
|
-
* @returns Network instance
|
|
3087
|
-
*/
|
|
3088
|
-
getNetwork(networkId) {
|
|
3089
|
-
return new Network(this.options, networkId);
|
|
3090
|
-
}
|
|
3091
|
-
/**
|
|
3092
|
-
* Gets a vNext network instance by ID
|
|
3093
|
-
* @param networkId - ID of the vNext network to retrieve
|
|
3094
|
-
* @returns vNext Network instance
|
|
3095
|
-
*/
|
|
3096
|
-
getVNextNetwork(networkId) {
|
|
3097
|
-
return new VNextNetwork(this.options, networkId);
|
|
3098
|
-
}
|
|
3099
3082
|
/**
|
|
3100
3083
|
* Retrieves a list of available MCP servers.
|
|
3101
3084
|
* @param params - Optional parameters for pagination (limit, offset).
|
|
@@ -3200,7 +3183,7 @@ var MastraClient = class extends BaseResource {
|
|
|
3200
3183
|
* @returns Promise containing the scorer
|
|
3201
3184
|
*/
|
|
3202
3185
|
getScorer(scorerId) {
|
|
3203
|
-
return this.request(`/api/scores/scorers/${scorerId}`);
|
|
3186
|
+
return this.request(`/api/scores/scorers/${encodeURIComponent(scorerId)}`);
|
|
3204
3187
|
}
|
|
3205
3188
|
getScoresByScorerId(params) {
|
|
3206
3189
|
const { page, perPage, scorerId, entityId, entityType } = params;
|
|
@@ -3218,7 +3201,7 @@ var MastraClient = class extends BaseResource {
|
|
|
3218
3201
|
searchParams.set("perPage", String(perPage));
|
|
3219
3202
|
}
|
|
3220
3203
|
const queryString = searchParams.toString();
|
|
3221
|
-
return this.request(`/api/scores/scorer/${scorerId}${queryString ? `?${queryString}` : ""}`);
|
|
3204
|
+
return this.request(`/api/scores/scorer/${encodeURIComponent(scorerId)}${queryString ? `?${queryString}` : ""}`);
|
|
3222
3205
|
}
|
|
3223
3206
|
/**
|
|
3224
3207
|
* Retrieves scores by run ID
|
|
@@ -3235,7 +3218,7 @@ var MastraClient = class extends BaseResource {
|
|
|
3235
3218
|
searchParams.set("perPage", String(perPage));
|
|
3236
3219
|
}
|
|
3237
3220
|
const queryString = searchParams.toString();
|
|
3238
|
-
return this.request(`/api/scores/run/${runId}${queryString ? `?${queryString}` : ""}`);
|
|
3221
|
+
return this.request(`/api/scores/run/${encodeURIComponent(runId)}${queryString ? `?${queryString}` : ""}`);
|
|
3239
3222
|
}
|
|
3240
3223
|
/**
|
|
3241
3224
|
* Retrieves scores by entity ID and type
|
|
@@ -3252,7 +3235,9 @@ var MastraClient = class extends BaseResource {
|
|
|
3252
3235
|
searchParams.set("perPage", String(perPage));
|
|
3253
3236
|
}
|
|
3254
3237
|
const queryString = searchParams.toString();
|
|
3255
|
-
return this.request(
|
|
3238
|
+
return this.request(
|
|
3239
|
+
`/api/scores/entity/${encodeURIComponent(entityType)}/${encodeURIComponent(entityId)}${queryString ? `?${queryString}` : ""}`
|
|
3240
|
+
);
|
|
3256
3241
|
}
|
|
3257
3242
|
/**
|
|
3258
3243
|
* Saves a score
|
|
@@ -3278,8 +3263,33 @@ var MastraClient = class extends BaseResource {
|
|
|
3278
3263
|
getAITraces(params) {
|
|
3279
3264
|
return this.observability.getTraces(params);
|
|
3280
3265
|
}
|
|
3266
|
+
getScoresBySpan(params) {
|
|
3267
|
+
return this.observability.getScoresBySpan(params);
|
|
3268
|
+
}
|
|
3269
|
+
score(params) {
|
|
3270
|
+
return this.observability.score(params);
|
|
3271
|
+
}
|
|
3281
3272
|
};
|
|
3282
3273
|
|
|
3283
|
-
|
|
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
|
+
}
|
|
3288
|
+
};
|
|
3289
|
+
function createTool(opts) {
|
|
3290
|
+
return new ClientTool(opts);
|
|
3291
|
+
}
|
|
3292
|
+
|
|
3293
|
+
export { ClientTool, MastraClient, createTool };
|
|
3284
3294
|
//# sourceMappingURL=index.js.map
|
|
3285
3295
|
//# sourceMappingURL=index.js.map
|