@mastra/client-js 0.0.0-ai-telementry-ui-20250908100313 → 0.0.0-break-rename-vnext-legacy-20250926163953
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 +305 -10
- package/README.md +6 -10
- package/dist/client.d.ts +36 -27
- package/dist/client.d.ts.map +1 -1
- package/dist/index.cjs +466 -387
- 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 +465 -388
- package/dist/index.js.map +1 -1
- package/dist/resources/agent-builder.d.ts +5 -6
- package/dist/resources/agent-builder.d.ts.map +1 -1
- package/dist/resources/agent.d.ts +48 -32
- package/dist/resources/agent.d.ts.map +1 -1
- package/dist/resources/index.d.ts +0 -2
- package/dist/resources/index.d.ts.map +1 -1
- package/dist/resources/mcp-tool.d.ts +2 -1
- package/dist/resources/mcp-tool.d.ts.map +1 -1
- package/dist/resources/observability.d.ts +10 -0
- package/dist/resources/observability.d.ts.map +1 -1
- package/dist/resources/tool.d.ts +2 -1
- package/dist/resources/tool.d.ts.map +1 -1
- package/dist/resources/vNextNetwork.d.ts +2 -1
- package/dist/resources/vNextNetwork.d.ts.map +1 -1
- package/dist/resources/vector.d.ts +5 -2
- package/dist/resources/vector.d.ts.map +1 -1
- package/dist/resources/workflow.d.ts +110 -10
- 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 +52 -43
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/process-mastra-stream.d.ts +5 -1
- package/dist/utils/process-mastra-stream.d.ts.map +1 -1
- package/package.json +5 -6
- package/dist/resources/legacy-workflow.d.ts +0 -87
- package/dist/resources/legacy-workflow.d.ts.map +0 -1
- package/dist/resources/network.d.ts +0 -30
- package/dist/resources/network.d.ts.map +0 -1
package/dist/index.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,16 +380,29 @@ 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,
|
|
360
396
|
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
361
|
-
clientTools: processClientTools(params.clientTools)
|
|
397
|
+
clientTools: processClientTools(params.clientTools),
|
|
398
|
+
structuredOutput: params.structuredOutput ? {
|
|
399
|
+
...params.structuredOutput,
|
|
400
|
+
schema: zodToJsonSchema(params.structuredOutput.schema)
|
|
401
|
+
} : void 0
|
|
362
402
|
};
|
|
363
403
|
const { runId, resourceId, threadId, runtimeContext } = processedParams;
|
|
364
404
|
const response = await this.request(
|
|
365
|
-
`/api/agents/${this.agentId}/generate
|
|
405
|
+
`/api/agents/${this.agentId}/generate`,
|
|
366
406
|
{
|
|
367
407
|
method: "POST",
|
|
368
408
|
body: processedParams
|
|
@@ -376,7 +416,7 @@ var Agent = class extends BaseResource {
|
|
|
376
416
|
resourceId,
|
|
377
417
|
threadId,
|
|
378
418
|
runtimeContext,
|
|
379
|
-
respondFn: this.
|
|
419
|
+
respondFn: this.generate.bind(this)
|
|
380
420
|
});
|
|
381
421
|
}
|
|
382
422
|
return response;
|
|
@@ -648,12 +688,6 @@ var Agent = class extends BaseResource {
|
|
|
648
688
|
* @param params - Stream parameters including prompt
|
|
649
689
|
* @returns Promise containing the enhanced Response object with processDataStream method
|
|
650
690
|
*/
|
|
651
|
-
async stream(params) {
|
|
652
|
-
console.warn(
|
|
653
|
-
"Deprecation NOTICE:\nStream method will switch to use streamVNext implementation September 16th. Please use streamLegacy if you don't want to upgrade just yet."
|
|
654
|
-
);
|
|
655
|
-
return this.streamLegacy(params);
|
|
656
|
-
}
|
|
657
691
|
/**
|
|
658
692
|
* Streams a response from the agent
|
|
659
693
|
* @param params - Stream parameters including prompt
|
|
@@ -863,7 +897,7 @@ var Agent = class extends BaseResource {
|
|
|
863
897
|
step,
|
|
864
898
|
toolCallId: chunk.payload.toolCallId,
|
|
865
899
|
toolName: chunk.payload.toolName,
|
|
866
|
-
args:
|
|
900
|
+
args: chunk.payload.args
|
|
867
901
|
};
|
|
868
902
|
message.toolInvocations.push(invocation);
|
|
869
903
|
updateToolInvocationPart(chunk.payload.toolCallId, invocation);
|
|
@@ -917,14 +951,14 @@ var Agent = class extends BaseResource {
|
|
|
917
951
|
}
|
|
918
952
|
case "step-finish": {
|
|
919
953
|
step += 1;
|
|
920
|
-
currentTextPart = chunk.payload.isContinued ? currentTextPart : void 0;
|
|
954
|
+
currentTextPart = chunk.payload.stepResult.isContinued ? currentTextPart : void 0;
|
|
921
955
|
currentReasoningPart = void 0;
|
|
922
956
|
currentReasoningTextDetail = void 0;
|
|
923
957
|
execUpdate();
|
|
924
958
|
break;
|
|
925
959
|
}
|
|
926
960
|
case "finish": {
|
|
927
|
-
finishReason = chunk.payload.
|
|
961
|
+
finishReason = chunk.payload.stepResult.reason;
|
|
928
962
|
if (chunk.payload.usage != null) {
|
|
929
963
|
usage = chunk.payload.usage;
|
|
930
964
|
}
|
|
@@ -936,7 +970,7 @@ var Agent = class extends BaseResource {
|
|
|
936
970
|
onFinish?.({ message, finishReason, usage });
|
|
937
971
|
}
|
|
938
972
|
async processStreamResponse_vNext(processedParams, writable) {
|
|
939
|
-
const response = await this.request(`/api/agents/${this.agentId}/stream
|
|
973
|
+
const response = await this.request(`/api/agents/${this.agentId}/stream`, {
|
|
940
974
|
method: "POST",
|
|
941
975
|
body: processedParams,
|
|
942
976
|
stream: true
|
|
@@ -948,9 +982,28 @@ var Agent = class extends BaseResource {
|
|
|
948
982
|
let toolCalls = [];
|
|
949
983
|
let messages = [];
|
|
950
984
|
const [streamForWritable, streamForProcessing] = response.body.tee();
|
|
951
|
-
streamForWritable.pipeTo(
|
|
952
|
-
|
|
953
|
-
|
|
985
|
+
streamForWritable.pipeTo(
|
|
986
|
+
new WritableStream({
|
|
987
|
+
async write(chunk) {
|
|
988
|
+
try {
|
|
989
|
+
const text = new TextDecoder().decode(chunk);
|
|
990
|
+
if (text.includes("[DONE]")) {
|
|
991
|
+
return;
|
|
992
|
+
}
|
|
993
|
+
} catch {
|
|
994
|
+
}
|
|
995
|
+
const writer = writable.getWriter();
|
|
996
|
+
try {
|
|
997
|
+
await writer.write(chunk);
|
|
998
|
+
} finally {
|
|
999
|
+
writer.releaseLock();
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
}),
|
|
1003
|
+
{
|
|
1004
|
+
preventClose: true
|
|
1005
|
+
}
|
|
1006
|
+
).catch((error) => {
|
|
954
1007
|
console.error("Error piping to writable stream:", error);
|
|
955
1008
|
});
|
|
956
1009
|
this.processChatResponse_vNext({
|
|
@@ -980,14 +1033,17 @@ var Agent = class extends BaseResource {
|
|
|
980
1033
|
threadId: processedParams.threadId,
|
|
981
1034
|
runtimeContext: processedParams.runtimeContext,
|
|
982
1035
|
// TODO: Pass proper tracing context when client-js supports tracing
|
|
983
|
-
tracingContext: { currentSpan: void 0 }
|
|
1036
|
+
tracingContext: { currentSpan: void 0 },
|
|
1037
|
+
suspend: async () => {
|
|
1038
|
+
}
|
|
984
1039
|
},
|
|
985
1040
|
{
|
|
986
1041
|
messages: response.messages,
|
|
987
1042
|
toolCallId: toolCall2?.toolCallId
|
|
988
1043
|
}
|
|
989
1044
|
);
|
|
990
|
-
const
|
|
1045
|
+
const lastMessageRaw = messages[messages.length - 1];
|
|
1046
|
+
const lastMessage = lastMessageRaw != null ? JSON.parse(JSON.stringify(lastMessageRaw)) : void 0;
|
|
991
1047
|
const toolInvocationPart = lastMessage?.parts?.find(
|
|
992
1048
|
(part) => part.type === "tool-invocation" && part.toolInvocation?.toolCallId === toolCall2.toolCallId
|
|
993
1049
|
);
|
|
@@ -1005,25 +1061,11 @@ var Agent = class extends BaseResource {
|
|
|
1005
1061
|
toolInvocation.state = "result";
|
|
1006
1062
|
toolInvocation.result = result;
|
|
1007
1063
|
}
|
|
1008
|
-
const
|
|
1009
|
-
try {
|
|
1010
|
-
await writer.write(
|
|
1011
|
-
new TextEncoder().encode(
|
|
1012
|
-
"a:" + JSON.stringify({
|
|
1013
|
-
toolCallId: toolCall2.toolCallId,
|
|
1014
|
-
result
|
|
1015
|
-
}) + "\n"
|
|
1016
|
-
)
|
|
1017
|
-
);
|
|
1018
|
-
} finally {
|
|
1019
|
-
writer.releaseLock();
|
|
1020
|
-
}
|
|
1021
|
-
const originalMessages = processedParams.messages;
|
|
1022
|
-
const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
|
|
1064
|
+
const updatedMessages = lastMessage != null ? [...messages.filter((m) => m.id !== lastMessage.id), lastMessage] : [...messages];
|
|
1023
1065
|
this.processStreamResponse_vNext(
|
|
1024
1066
|
{
|
|
1025
1067
|
...processedParams,
|
|
1026
|
-
messages:
|
|
1068
|
+
messages: updatedMessages
|
|
1027
1069
|
},
|
|
1028
1070
|
writable
|
|
1029
1071
|
).catch((error) => {
|
|
@@ -1046,12 +1088,49 @@ var Agent = class extends BaseResource {
|
|
|
1046
1088
|
}
|
|
1047
1089
|
return response;
|
|
1048
1090
|
}
|
|
1049
|
-
async
|
|
1091
|
+
async network(params) {
|
|
1092
|
+
const response = await this.request(`/api/agents/${this.agentId}/network`, {
|
|
1093
|
+
method: "POST",
|
|
1094
|
+
body: params,
|
|
1095
|
+
stream: true
|
|
1096
|
+
});
|
|
1097
|
+
if (!response.body) {
|
|
1098
|
+
throw new Error("No response body");
|
|
1099
|
+
}
|
|
1100
|
+
const streamResponse = new Response(response.body, {
|
|
1101
|
+
status: response.status,
|
|
1102
|
+
statusText: response.statusText,
|
|
1103
|
+
headers: response.headers
|
|
1104
|
+
});
|
|
1105
|
+
streamResponse.processDataStream = async ({
|
|
1106
|
+
onChunk
|
|
1107
|
+
}) => {
|
|
1108
|
+
await processMastraNetworkStream({
|
|
1109
|
+
stream: streamResponse.body,
|
|
1110
|
+
onChunk
|
|
1111
|
+
});
|
|
1112
|
+
};
|
|
1113
|
+
return streamResponse;
|
|
1114
|
+
}
|
|
1115
|
+
async stream(messagesOrParams, options) {
|
|
1116
|
+
let params;
|
|
1117
|
+
if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
|
|
1118
|
+
params = messagesOrParams;
|
|
1119
|
+
} else {
|
|
1120
|
+
params = {
|
|
1121
|
+
messages: messagesOrParams,
|
|
1122
|
+
...options
|
|
1123
|
+
};
|
|
1124
|
+
}
|
|
1050
1125
|
const processedParams = {
|
|
1051
1126
|
...params,
|
|
1052
1127
|
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
1053
1128
|
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
1054
|
-
clientTools: processClientTools(params.clientTools)
|
|
1129
|
+
clientTools: processClientTools(params.clientTools),
|
|
1130
|
+
structuredOutput: params.structuredOutput ? {
|
|
1131
|
+
...params.structuredOutput,
|
|
1132
|
+
schema: zodToJsonSchema(params.structuredOutput.schema)
|
|
1133
|
+
} : void 0
|
|
1055
1134
|
};
|
|
1056
1135
|
const { readable, writable } = new TransformStream();
|
|
1057
1136
|
const response = await this.processStreamResponse_vNext(processedParams, writable);
|
|
@@ -1118,7 +1197,9 @@ var Agent = class extends BaseResource {
|
|
|
1118
1197
|
threadId: processedParams.threadId,
|
|
1119
1198
|
runtimeContext: processedParams.runtimeContext,
|
|
1120
1199
|
// TODO: Pass proper tracing context when client-js supports tracing
|
|
1121
|
-
tracingContext: { currentSpan: void 0 }
|
|
1200
|
+
tracingContext: { currentSpan: void 0 },
|
|
1201
|
+
suspend: async () => {
|
|
1202
|
+
}
|
|
1122
1203
|
},
|
|
1123
1204
|
{
|
|
1124
1205
|
messages: response.messages,
|
|
@@ -1156,12 +1237,10 @@ var Agent = class extends BaseResource {
|
|
|
1156
1237
|
} finally {
|
|
1157
1238
|
writer.releaseLock();
|
|
1158
1239
|
}
|
|
1159
|
-
const originalMessages = processedParams.messages;
|
|
1160
|
-
const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
|
|
1161
1240
|
this.processStreamResponse(
|
|
1162
1241
|
{
|
|
1163
1242
|
...processedParams,
|
|
1164
|
-
messages: [...
|
|
1243
|
+
messages: [...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
|
|
1165
1244
|
},
|
|
1166
1245
|
writable
|
|
1167
1246
|
).catch((error) => {
|
|
@@ -1187,10 +1266,11 @@ var Agent = class extends BaseResource {
|
|
|
1187
1266
|
/**
|
|
1188
1267
|
* Gets details about a specific tool available to the agent
|
|
1189
1268
|
* @param toolId - ID of the tool to retrieve
|
|
1269
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1190
1270
|
* @returns Promise containing tool details
|
|
1191
1271
|
*/
|
|
1192
|
-
getTool(toolId) {
|
|
1193
|
-
return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
|
|
1272
|
+
getTool(toolId, runtimeContext) {
|
|
1273
|
+
return this.request(`/api/agents/${this.agentId}/tools/${toolId}${runtimeContextQueryString(runtimeContext)}`);
|
|
1194
1274
|
}
|
|
1195
1275
|
/**
|
|
1196
1276
|
* Executes a tool for the agent
|
|
@@ -1201,7 +1281,7 @@ var Agent = class extends BaseResource {
|
|
|
1201
1281
|
executeTool(toolId, params) {
|
|
1202
1282
|
const body = {
|
|
1203
1283
|
data: params.data,
|
|
1204
|
-
runtimeContext:
|
|
1284
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1205
1285
|
};
|
|
1206
1286
|
return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
|
|
1207
1287
|
method: "POST",
|
|
@@ -1210,17 +1290,19 @@ var Agent = class extends BaseResource {
|
|
|
1210
1290
|
}
|
|
1211
1291
|
/**
|
|
1212
1292
|
* Retrieves evaluation results for the agent
|
|
1293
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1213
1294
|
* @returns Promise containing agent evaluations
|
|
1214
1295
|
*/
|
|
1215
|
-
evals() {
|
|
1216
|
-
return this.request(`/api/agents/${this.agentId}/evals/ci`);
|
|
1296
|
+
evals(runtimeContext) {
|
|
1297
|
+
return this.request(`/api/agents/${this.agentId}/evals/ci${runtimeContextQueryString(runtimeContext)}`);
|
|
1217
1298
|
}
|
|
1218
1299
|
/**
|
|
1219
1300
|
* Retrieves live evaluation results for the agent
|
|
1301
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1220
1302
|
* @returns Promise containing live agent evaluations
|
|
1221
1303
|
*/
|
|
1222
|
-
liveEvals() {
|
|
1223
|
-
return this.request(`/api/agents/${this.agentId}/evals/live`);
|
|
1304
|
+
liveEvals(runtimeContext) {
|
|
1305
|
+
return this.request(`/api/agents/${this.agentId}/evals/live${runtimeContextQueryString(runtimeContext)}`);
|
|
1224
1306
|
}
|
|
1225
1307
|
/**
|
|
1226
1308
|
* Updates the model for the agent
|
|
@@ -1233,61 +1315,27 @@ var Agent = class extends BaseResource {
|
|
|
1233
1315
|
body: params
|
|
1234
1316
|
});
|
|
1235
1317
|
}
|
|
1236
|
-
};
|
|
1237
|
-
var Network = class extends BaseResource {
|
|
1238
|
-
constructor(options, networkId) {
|
|
1239
|
-
super(options);
|
|
1240
|
-
this.networkId = networkId;
|
|
1241
|
-
}
|
|
1242
|
-
/**
|
|
1243
|
-
* Retrieves details about the network
|
|
1244
|
-
* @returns Promise containing network details
|
|
1245
|
-
*/
|
|
1246
|
-
details() {
|
|
1247
|
-
return this.request(`/api/networks/${this.networkId}`);
|
|
1248
|
-
}
|
|
1249
1318
|
/**
|
|
1250
|
-
*
|
|
1251
|
-
* @param params -
|
|
1252
|
-
* @returns Promise containing the
|
|
1319
|
+
* Updates the model for the agent in the model list
|
|
1320
|
+
* @param params - Parameters for updating the model
|
|
1321
|
+
* @returns Promise containing the updated model
|
|
1253
1322
|
*/
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
...params,
|
|
1257
|
-
output: zodToJsonSchema(params.output),
|
|
1258
|
-
experimental_output: zodToJsonSchema(params.experimental_output)
|
|
1259
|
-
};
|
|
1260
|
-
return this.request(`/api/networks/${this.networkId}/generate`, {
|
|
1323
|
+
updateModelInModelList({ modelConfigId, ...params }) {
|
|
1324
|
+
return this.request(`/api/agents/${this.agentId}/models/${modelConfigId}`, {
|
|
1261
1325
|
method: "POST",
|
|
1262
|
-
body:
|
|
1326
|
+
body: params
|
|
1263
1327
|
});
|
|
1264
1328
|
}
|
|
1265
1329
|
/**
|
|
1266
|
-
*
|
|
1267
|
-
* @param params -
|
|
1268
|
-
* @returns Promise containing the
|
|
1330
|
+
* Reorders the models for the agent
|
|
1331
|
+
* @param params - Parameters for reordering the model list
|
|
1332
|
+
* @returns Promise containing the updated model list
|
|
1269
1333
|
*/
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
...params,
|
|
1273
|
-
output: zodToJsonSchema(params.output),
|
|
1274
|
-
experimental_output: zodToJsonSchema(params.experimental_output)
|
|
1275
|
-
};
|
|
1276
|
-
const response = await this.request(`/api/networks/${this.networkId}/stream`, {
|
|
1334
|
+
reorderModelList(params) {
|
|
1335
|
+
return this.request(`/api/agents/${this.agentId}/models/reorder`, {
|
|
1277
1336
|
method: "POST",
|
|
1278
|
-
body:
|
|
1279
|
-
stream: true
|
|
1337
|
+
body: params
|
|
1280
1338
|
});
|
|
1281
|
-
if (!response.body) {
|
|
1282
|
-
throw new Error("No response body");
|
|
1283
|
-
}
|
|
1284
|
-
response.processDataStream = async (options = {}) => {
|
|
1285
|
-
await processDataStream({
|
|
1286
|
-
stream: response.body,
|
|
1287
|
-
...options
|
|
1288
|
-
});
|
|
1289
|
-
};
|
|
1290
|
-
return response;
|
|
1291
1339
|
}
|
|
1292
1340
|
};
|
|
1293
1341
|
|
|
@@ -1378,10 +1426,13 @@ var Vector = class extends BaseResource {
|
|
|
1378
1426
|
/**
|
|
1379
1427
|
* Retrieves details about a specific vector index
|
|
1380
1428
|
* @param indexName - Name of the index to get details for
|
|
1429
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1381
1430
|
* @returns Promise containing vector index details
|
|
1382
1431
|
*/
|
|
1383
|
-
details(indexName) {
|
|
1384
|
-
return this.request(
|
|
1432
|
+
details(indexName, runtimeContext) {
|
|
1433
|
+
return this.request(
|
|
1434
|
+
`/api/vector/${this.vectorName}/indexes/${indexName}${runtimeContextQueryString(runtimeContext)}`
|
|
1435
|
+
);
|
|
1385
1436
|
}
|
|
1386
1437
|
/**
|
|
1387
1438
|
* Deletes a vector index
|
|
@@ -1395,10 +1446,11 @@ var Vector = class extends BaseResource {
|
|
|
1395
1446
|
}
|
|
1396
1447
|
/**
|
|
1397
1448
|
* Retrieves a list of all available indexes
|
|
1449
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1398
1450
|
* @returns Promise containing array of index names
|
|
1399
1451
|
*/
|
|
1400
|
-
getIndexes() {
|
|
1401
|
-
return this.request(`/api/vector/${this.vectorName}/indexes`);
|
|
1452
|
+
getIndexes(runtimeContext) {
|
|
1453
|
+
return this.request(`/api/vector/${this.vectorName}/indexes${runtimeContextQueryString(runtimeContext)}`);
|
|
1402
1454
|
}
|
|
1403
1455
|
/**
|
|
1404
1456
|
* Creates a new vector index
|
|
@@ -1435,187 +1487,6 @@ var Vector = class extends BaseResource {
|
|
|
1435
1487
|
}
|
|
1436
1488
|
};
|
|
1437
1489
|
|
|
1438
|
-
// src/resources/legacy-workflow.ts
|
|
1439
|
-
var RECORD_SEPARATOR = "";
|
|
1440
|
-
var LegacyWorkflow = class extends BaseResource {
|
|
1441
|
-
constructor(options, workflowId) {
|
|
1442
|
-
super(options);
|
|
1443
|
-
this.workflowId = workflowId;
|
|
1444
|
-
}
|
|
1445
|
-
/**
|
|
1446
|
-
* Retrieves details about the legacy workflow
|
|
1447
|
-
* @returns Promise containing legacy workflow details including steps and graphs
|
|
1448
|
-
*/
|
|
1449
|
-
details() {
|
|
1450
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}`);
|
|
1451
|
-
}
|
|
1452
|
-
/**
|
|
1453
|
-
* Retrieves all runs for a legacy workflow
|
|
1454
|
-
* @param params - Parameters for filtering runs
|
|
1455
|
-
* @returns Promise containing legacy workflow runs array
|
|
1456
|
-
*/
|
|
1457
|
-
runs(params) {
|
|
1458
|
-
const searchParams = new URLSearchParams();
|
|
1459
|
-
if (params?.fromDate) {
|
|
1460
|
-
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
1461
|
-
}
|
|
1462
|
-
if (params?.toDate) {
|
|
1463
|
-
searchParams.set("toDate", params.toDate.toISOString());
|
|
1464
|
-
}
|
|
1465
|
-
if (params?.limit) {
|
|
1466
|
-
searchParams.set("limit", String(params.limit));
|
|
1467
|
-
}
|
|
1468
|
-
if (params?.offset) {
|
|
1469
|
-
searchParams.set("offset", String(params.offset));
|
|
1470
|
-
}
|
|
1471
|
-
if (params?.resourceId) {
|
|
1472
|
-
searchParams.set("resourceId", params.resourceId);
|
|
1473
|
-
}
|
|
1474
|
-
if (searchParams.size) {
|
|
1475
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/runs?${searchParams}`);
|
|
1476
|
-
} else {
|
|
1477
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/runs`);
|
|
1478
|
-
}
|
|
1479
|
-
}
|
|
1480
|
-
/**
|
|
1481
|
-
* Creates a new legacy workflow run
|
|
1482
|
-
* @returns Promise containing the generated run ID
|
|
1483
|
-
*/
|
|
1484
|
-
createRun(params) {
|
|
1485
|
-
const searchParams = new URLSearchParams();
|
|
1486
|
-
if (!!params?.runId) {
|
|
1487
|
-
searchParams.set("runId", params.runId);
|
|
1488
|
-
}
|
|
1489
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/create-run?${searchParams.toString()}`, {
|
|
1490
|
-
method: "POST"
|
|
1491
|
-
});
|
|
1492
|
-
}
|
|
1493
|
-
/**
|
|
1494
|
-
* Starts a legacy workflow run synchronously without waiting for the workflow to complete
|
|
1495
|
-
* @param params - Object containing the runId and triggerData
|
|
1496
|
-
* @returns Promise containing success message
|
|
1497
|
-
*/
|
|
1498
|
-
start(params) {
|
|
1499
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/start?runId=${params.runId}`, {
|
|
1500
|
-
method: "POST",
|
|
1501
|
-
body: params?.triggerData
|
|
1502
|
-
});
|
|
1503
|
-
}
|
|
1504
|
-
/**
|
|
1505
|
-
* Resumes a suspended legacy workflow step synchronously without waiting for the workflow to complete
|
|
1506
|
-
* @param stepId - ID of the step to resume
|
|
1507
|
-
* @param runId - ID of the legacy workflow run
|
|
1508
|
-
* @param context - Context to resume the legacy workflow with
|
|
1509
|
-
* @returns Promise containing the legacy workflow resume results
|
|
1510
|
-
*/
|
|
1511
|
-
resume({
|
|
1512
|
-
stepId,
|
|
1513
|
-
runId,
|
|
1514
|
-
context
|
|
1515
|
-
}) {
|
|
1516
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/resume?runId=${runId}`, {
|
|
1517
|
-
method: "POST",
|
|
1518
|
-
body: {
|
|
1519
|
-
stepId,
|
|
1520
|
-
context
|
|
1521
|
-
}
|
|
1522
|
-
});
|
|
1523
|
-
}
|
|
1524
|
-
/**
|
|
1525
|
-
* Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
|
|
1526
|
-
* @param params - Object containing the optional runId and triggerData
|
|
1527
|
-
* @returns Promise containing the workflow execution results
|
|
1528
|
-
*/
|
|
1529
|
-
startAsync(params) {
|
|
1530
|
-
const searchParams = new URLSearchParams();
|
|
1531
|
-
if (!!params?.runId) {
|
|
1532
|
-
searchParams.set("runId", params.runId);
|
|
1533
|
-
}
|
|
1534
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
1535
|
-
method: "POST",
|
|
1536
|
-
body: params?.triggerData
|
|
1537
|
-
});
|
|
1538
|
-
}
|
|
1539
|
-
/**
|
|
1540
|
-
* Resumes a suspended legacy workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
1541
|
-
* @param params - Object containing the runId, stepId, and context
|
|
1542
|
-
* @returns Promise containing the workflow resume results
|
|
1543
|
-
*/
|
|
1544
|
-
resumeAsync(params) {
|
|
1545
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
1546
|
-
method: "POST",
|
|
1547
|
-
body: {
|
|
1548
|
-
stepId: params.stepId,
|
|
1549
|
-
context: params.context
|
|
1550
|
-
}
|
|
1551
|
-
});
|
|
1552
|
-
}
|
|
1553
|
-
/**
|
|
1554
|
-
* Creates an async generator that processes a readable stream and yields records
|
|
1555
|
-
* separated by the Record Separator character (\x1E)
|
|
1556
|
-
*
|
|
1557
|
-
* @param stream - The readable stream to process
|
|
1558
|
-
* @returns An async generator that yields parsed records
|
|
1559
|
-
*/
|
|
1560
|
-
async *streamProcessor(stream) {
|
|
1561
|
-
const reader = stream.getReader();
|
|
1562
|
-
let doneReading = false;
|
|
1563
|
-
let buffer = "";
|
|
1564
|
-
try {
|
|
1565
|
-
while (!doneReading) {
|
|
1566
|
-
const { done, value } = await reader.read();
|
|
1567
|
-
doneReading = done;
|
|
1568
|
-
if (done && !value) continue;
|
|
1569
|
-
try {
|
|
1570
|
-
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
1571
|
-
const chunks = (buffer + decoded).split(RECORD_SEPARATOR);
|
|
1572
|
-
buffer = chunks.pop() || "";
|
|
1573
|
-
for (const chunk of chunks) {
|
|
1574
|
-
if (chunk) {
|
|
1575
|
-
if (typeof chunk === "string") {
|
|
1576
|
-
try {
|
|
1577
|
-
const parsedChunk = JSON.parse(chunk);
|
|
1578
|
-
yield parsedChunk;
|
|
1579
|
-
} catch {
|
|
1580
|
-
}
|
|
1581
|
-
}
|
|
1582
|
-
}
|
|
1583
|
-
}
|
|
1584
|
-
} catch {
|
|
1585
|
-
}
|
|
1586
|
-
}
|
|
1587
|
-
if (buffer) {
|
|
1588
|
-
try {
|
|
1589
|
-
yield JSON.parse(buffer);
|
|
1590
|
-
} catch {
|
|
1591
|
-
}
|
|
1592
|
-
}
|
|
1593
|
-
} finally {
|
|
1594
|
-
reader.cancel().catch(() => {
|
|
1595
|
-
});
|
|
1596
|
-
}
|
|
1597
|
-
}
|
|
1598
|
-
/**
|
|
1599
|
-
* Watches legacy workflow transitions in real-time
|
|
1600
|
-
* @param runId - Optional run ID to filter the watch stream
|
|
1601
|
-
* @returns AsyncGenerator that yields parsed records from the legacy workflow watch stream
|
|
1602
|
-
*/
|
|
1603
|
-
async watch({ runId }, onRecord) {
|
|
1604
|
-
const response = await this.request(`/api/workflows/legacy/${this.workflowId}/watch?runId=${runId}`, {
|
|
1605
|
-
stream: true
|
|
1606
|
-
});
|
|
1607
|
-
if (!response.ok) {
|
|
1608
|
-
throw new Error(`Failed to watch legacy workflow: ${response.statusText}`);
|
|
1609
|
-
}
|
|
1610
|
-
if (!response.body) {
|
|
1611
|
-
throw new Error("Response body is null");
|
|
1612
|
-
}
|
|
1613
|
-
for await (const record of this.streamProcessor(response.body)) {
|
|
1614
|
-
onRecord(record);
|
|
1615
|
-
}
|
|
1616
|
-
}
|
|
1617
|
-
};
|
|
1618
|
-
|
|
1619
1490
|
// src/resources/tool.ts
|
|
1620
1491
|
var Tool = class extends BaseResource {
|
|
1621
1492
|
constructor(options, toolId) {
|
|
@@ -1624,10 +1495,11 @@ var Tool = class extends BaseResource {
|
|
|
1624
1495
|
}
|
|
1625
1496
|
/**
|
|
1626
1497
|
* Retrieves details about the tool
|
|
1498
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1627
1499
|
* @returns Promise containing tool details including description and schemas
|
|
1628
1500
|
*/
|
|
1629
|
-
details() {
|
|
1630
|
-
return this.request(`/api/tools/${this.toolId}`);
|
|
1501
|
+
details(runtimeContext) {
|
|
1502
|
+
return this.request(`/api/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
|
|
1631
1503
|
}
|
|
1632
1504
|
/**
|
|
1633
1505
|
* Executes the tool with the provided parameters
|
|
@@ -1651,7 +1523,7 @@ var Tool = class extends BaseResource {
|
|
|
1651
1523
|
};
|
|
1652
1524
|
|
|
1653
1525
|
// src/resources/workflow.ts
|
|
1654
|
-
var
|
|
1526
|
+
var RECORD_SEPARATOR = "";
|
|
1655
1527
|
var Workflow = class extends BaseResource {
|
|
1656
1528
|
constructor(options, workflowId) {
|
|
1657
1529
|
super(options);
|
|
@@ -1675,7 +1547,7 @@ var Workflow = class extends BaseResource {
|
|
|
1675
1547
|
if (done && !value) continue;
|
|
1676
1548
|
try {
|
|
1677
1549
|
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
1678
|
-
const chunks = (buffer + decoded).split(
|
|
1550
|
+
const chunks = (buffer + decoded).split(RECORD_SEPARATOR);
|
|
1679
1551
|
buffer = chunks.pop() || "";
|
|
1680
1552
|
for (const chunk of chunks) {
|
|
1681
1553
|
if (chunk) {
|
|
@@ -1704,17 +1576,20 @@ var Workflow = class extends BaseResource {
|
|
|
1704
1576
|
}
|
|
1705
1577
|
/**
|
|
1706
1578
|
* Retrieves details about the workflow
|
|
1579
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1707
1580
|
* @returns Promise containing workflow details including steps and graphs
|
|
1708
1581
|
*/
|
|
1709
|
-
details() {
|
|
1710
|
-
return this.request(`/api/workflows/${this.workflowId}`);
|
|
1582
|
+
details(runtimeContext) {
|
|
1583
|
+
return this.request(`/api/workflows/${this.workflowId}${runtimeContextQueryString(runtimeContext)}`);
|
|
1711
1584
|
}
|
|
1712
1585
|
/**
|
|
1713
1586
|
* Retrieves all runs for a workflow
|
|
1714
1587
|
* @param params - Parameters for filtering runs
|
|
1588
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1715
1589
|
* @returns Promise containing workflow runs array
|
|
1716
1590
|
*/
|
|
1717
|
-
runs(params) {
|
|
1591
|
+
runs(params, runtimeContext) {
|
|
1592
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
1718
1593
|
const searchParams = new URLSearchParams();
|
|
1719
1594
|
if (params?.fromDate) {
|
|
1720
1595
|
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
@@ -1731,6 +1606,9 @@ var Workflow = class extends BaseResource {
|
|
|
1731
1606
|
if (params?.resourceId) {
|
|
1732
1607
|
searchParams.set("resourceId", params.resourceId);
|
|
1733
1608
|
}
|
|
1609
|
+
if (runtimeContextParam) {
|
|
1610
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
1611
|
+
}
|
|
1734
1612
|
if (searchParams.size) {
|
|
1735
1613
|
return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
|
|
1736
1614
|
} else {
|
|
@@ -1740,18 +1618,22 @@ var Workflow = class extends BaseResource {
|
|
|
1740
1618
|
/**
|
|
1741
1619
|
* Retrieves a specific workflow run by its ID
|
|
1742
1620
|
* @param runId - The ID of the workflow run to retrieve
|
|
1621
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1743
1622
|
* @returns Promise containing the workflow run details
|
|
1744
1623
|
*/
|
|
1745
|
-
runById(runId) {
|
|
1746
|
-
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}`);
|
|
1624
|
+
runById(runId, runtimeContext) {
|
|
1625
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}${runtimeContextQueryString(runtimeContext)}`);
|
|
1747
1626
|
}
|
|
1748
1627
|
/**
|
|
1749
1628
|
* Retrieves the execution result for a specific workflow run by its ID
|
|
1750
1629
|
* @param runId - The ID of the workflow run to retrieve the execution result for
|
|
1630
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1751
1631
|
* @returns Promise containing the workflow run execution result
|
|
1752
1632
|
*/
|
|
1753
|
-
runExecutionResult(runId) {
|
|
1754
|
-
return this.request(
|
|
1633
|
+
runExecutionResult(runId, runtimeContext) {
|
|
1634
|
+
return this.request(
|
|
1635
|
+
`/api/workflows/${this.workflowId}/runs/${runId}/execution-result${runtimeContextQueryString(runtimeContext)}`
|
|
1636
|
+
);
|
|
1755
1637
|
}
|
|
1756
1638
|
/**
|
|
1757
1639
|
* Cancels a specific workflow run by its ID
|
|
@@ -1774,27 +1656,61 @@ var Workflow = class extends BaseResource {
|
|
|
1774
1656
|
body: { event: params.event, data: params.data }
|
|
1775
1657
|
});
|
|
1776
1658
|
}
|
|
1659
|
+
/**
|
|
1660
|
+
* @deprecated Use createRunAsync() instead.
|
|
1661
|
+
* @throws {Error} Always throws an error directing users to use createRunAsync()
|
|
1662
|
+
*/
|
|
1663
|
+
async createRun(_params) {
|
|
1664
|
+
throw new Error(
|
|
1665
|
+
"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."
|
|
1666
|
+
);
|
|
1667
|
+
}
|
|
1777
1668
|
/**
|
|
1778
1669
|
* Creates a new workflow run
|
|
1779
1670
|
* @param params - Optional object containing the optional runId
|
|
1780
|
-
* @returns Promise containing the runId of the created run
|
|
1671
|
+
* @returns Promise containing the runId of the created run with methods to control execution
|
|
1781
1672
|
*/
|
|
1782
|
-
|
|
1673
|
+
async createRunAsync(params) {
|
|
1783
1674
|
const searchParams = new URLSearchParams();
|
|
1784
1675
|
if (!!params?.runId) {
|
|
1785
1676
|
searchParams.set("runId", params.runId);
|
|
1786
1677
|
}
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1678
|
+
const res = await this.request(
|
|
1679
|
+
`/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`,
|
|
1680
|
+
{
|
|
1681
|
+
method: "POST"
|
|
1682
|
+
}
|
|
1683
|
+
);
|
|
1684
|
+
const runId = res.runId;
|
|
1685
|
+
return {
|
|
1686
|
+
runId,
|
|
1687
|
+
start: async (p) => {
|
|
1688
|
+
return this.start({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
|
|
1689
|
+
},
|
|
1690
|
+
startAsync: async (p) => {
|
|
1691
|
+
return this.startAsync({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
|
|
1692
|
+
},
|
|
1693
|
+
watch: async (onRecord) => {
|
|
1694
|
+
return this.watch({ runId }, onRecord);
|
|
1695
|
+
},
|
|
1696
|
+
stream: async (p) => {
|
|
1697
|
+
return this.stream({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
|
|
1698
|
+
},
|
|
1699
|
+
resume: async (p) => {
|
|
1700
|
+
return this.resume({ runId, step: p.step, resumeData: p.resumeData, runtimeContext: p.runtimeContext });
|
|
1701
|
+
},
|
|
1702
|
+
resumeAsync: async (p) => {
|
|
1703
|
+
return this.resumeAsync({ runId, step: p.step, resumeData: p.resumeData, runtimeContext: p.runtimeContext });
|
|
1704
|
+
},
|
|
1705
|
+
resumeStreamVNext: async (p) => {
|
|
1706
|
+
return this.resumeStreamVNext({
|
|
1707
|
+
runId,
|
|
1708
|
+
step: p.step,
|
|
1709
|
+
resumeData: p.resumeData,
|
|
1710
|
+
runtimeContext: p.runtimeContext
|
|
1711
|
+
});
|
|
1712
|
+
}
|
|
1713
|
+
};
|
|
1798
1714
|
}
|
|
1799
1715
|
/**
|
|
1800
1716
|
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
@@ -1822,7 +1738,6 @@ var Workflow = class extends BaseResource {
|
|
|
1822
1738
|
const runtimeContext = parseClientRuntimeContext(rest.runtimeContext);
|
|
1823
1739
|
return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
|
|
1824
1740
|
method: "POST",
|
|
1825
|
-
stream: true,
|
|
1826
1741
|
body: {
|
|
1827
1742
|
step,
|
|
1828
1743
|
resumeData,
|
|
@@ -1865,6 +1780,104 @@ var Workflow = class extends BaseResource {
|
|
|
1865
1780
|
stream: true
|
|
1866
1781
|
}
|
|
1867
1782
|
);
|
|
1783
|
+
if (!response.ok) {
|
|
1784
|
+
throw new Error(`Failed to stream workflow: ${response.statusText}`);
|
|
1785
|
+
}
|
|
1786
|
+
if (!response.body) {
|
|
1787
|
+
throw new Error("Response body is null");
|
|
1788
|
+
}
|
|
1789
|
+
let failedChunk = void 0;
|
|
1790
|
+
const transformStream = new TransformStream({
|
|
1791
|
+
start() {
|
|
1792
|
+
},
|
|
1793
|
+
async transform(chunk, controller) {
|
|
1794
|
+
try {
|
|
1795
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
1796
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
1797
|
+
for (const chunk2 of chunks) {
|
|
1798
|
+
if (chunk2) {
|
|
1799
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
1800
|
+
try {
|
|
1801
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
1802
|
+
controller.enqueue(parsedChunk);
|
|
1803
|
+
failedChunk = void 0;
|
|
1804
|
+
} catch {
|
|
1805
|
+
failedChunk = newChunk;
|
|
1806
|
+
}
|
|
1807
|
+
}
|
|
1808
|
+
}
|
|
1809
|
+
} catch {
|
|
1810
|
+
}
|
|
1811
|
+
}
|
|
1812
|
+
});
|
|
1813
|
+
return response.body.pipeThrough(transformStream);
|
|
1814
|
+
}
|
|
1815
|
+
/**
|
|
1816
|
+
* Observes workflow stream for a workflow run
|
|
1817
|
+
* @param params - Object containing the runId
|
|
1818
|
+
* @returns Promise containing the workflow execution results
|
|
1819
|
+
*/
|
|
1820
|
+
async observeStream(params) {
|
|
1821
|
+
const searchParams = new URLSearchParams();
|
|
1822
|
+
searchParams.set("runId", params.runId);
|
|
1823
|
+
const response = await this.request(
|
|
1824
|
+
`/api/workflows/${this.workflowId}/observe-stream?${searchParams.toString()}`,
|
|
1825
|
+
{
|
|
1826
|
+
method: "POST",
|
|
1827
|
+
stream: true
|
|
1828
|
+
}
|
|
1829
|
+
);
|
|
1830
|
+
if (!response.ok) {
|
|
1831
|
+
throw new Error(`Failed to observe workflow stream: ${response.statusText}`);
|
|
1832
|
+
}
|
|
1833
|
+
if (!response.body) {
|
|
1834
|
+
throw new Error("Response body is null");
|
|
1835
|
+
}
|
|
1836
|
+
let failedChunk = void 0;
|
|
1837
|
+
const transformStream = new TransformStream({
|
|
1838
|
+
start() {
|
|
1839
|
+
},
|
|
1840
|
+
async transform(chunk, controller) {
|
|
1841
|
+
try {
|
|
1842
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
1843
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
1844
|
+
for (const chunk2 of chunks) {
|
|
1845
|
+
if (chunk2) {
|
|
1846
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
1847
|
+
try {
|
|
1848
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
1849
|
+
controller.enqueue(parsedChunk);
|
|
1850
|
+
failedChunk = void 0;
|
|
1851
|
+
} catch {
|
|
1852
|
+
failedChunk = newChunk;
|
|
1853
|
+
}
|
|
1854
|
+
}
|
|
1855
|
+
}
|
|
1856
|
+
} catch {
|
|
1857
|
+
}
|
|
1858
|
+
}
|
|
1859
|
+
});
|
|
1860
|
+
return response.body.pipeThrough(transformStream);
|
|
1861
|
+
}
|
|
1862
|
+
/**
|
|
1863
|
+
* Starts a workflow run and returns a stream
|
|
1864
|
+
* @param params - Object containing the optional runId, inputData and runtimeContext
|
|
1865
|
+
* @returns Promise containing the workflow execution results
|
|
1866
|
+
*/
|
|
1867
|
+
async streamVNext(params) {
|
|
1868
|
+
const searchParams = new URLSearchParams();
|
|
1869
|
+
if (!!params?.runId) {
|
|
1870
|
+
searchParams.set("runId", params.runId);
|
|
1871
|
+
}
|
|
1872
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1873
|
+
const response = await this.request(
|
|
1874
|
+
`/api/workflows/${this.workflowId}/streamVNext?${searchParams.toString()}`,
|
|
1875
|
+
{
|
|
1876
|
+
method: "POST",
|
|
1877
|
+
body: { inputData: params.inputData, runtimeContext, closeOnSuspend: params.closeOnSuspend },
|
|
1878
|
+
stream: true
|
|
1879
|
+
}
|
|
1880
|
+
);
|
|
1868
1881
|
if (!response.ok) {
|
|
1869
1882
|
throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
|
|
1870
1883
|
}
|
|
@@ -1878,7 +1891,7 @@ var Workflow = class extends BaseResource {
|
|
|
1878
1891
|
async transform(chunk, controller) {
|
|
1879
1892
|
try {
|
|
1880
1893
|
const decoded = new TextDecoder().decode(chunk);
|
|
1881
|
-
const chunks = decoded.split(
|
|
1894
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
1882
1895
|
for (const chunk2 of chunks) {
|
|
1883
1896
|
if (chunk2) {
|
|
1884
1897
|
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
@@ -1913,6 +1926,22 @@ var Workflow = class extends BaseResource {
|
|
|
1913
1926
|
}
|
|
1914
1927
|
});
|
|
1915
1928
|
}
|
|
1929
|
+
/**
|
|
1930
|
+
* Resumes a suspended workflow step that uses streamVNext asynchronously and returns a promise that resolves when the workflow is complete
|
|
1931
|
+
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
1932
|
+
* @returns Promise containing the workflow resume results
|
|
1933
|
+
*/
|
|
1934
|
+
resumeStreamVNext(params) {
|
|
1935
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1936
|
+
return this.request(`/api/workflows/${this.workflowId}/resume-stream?runId=${params.runId}`, {
|
|
1937
|
+
method: "POST",
|
|
1938
|
+
body: {
|
|
1939
|
+
step: params.step,
|
|
1940
|
+
resumeData: params.resumeData,
|
|
1941
|
+
runtimeContext
|
|
1942
|
+
}
|
|
1943
|
+
});
|
|
1944
|
+
}
|
|
1916
1945
|
/**
|
|
1917
1946
|
* Watches workflow transitions in real-time
|
|
1918
1947
|
* @param runId - Optional run ID to filter the watch stream
|
|
@@ -1949,7 +1978,7 @@ var Workflow = class extends BaseResource {
|
|
|
1949
1978
|
async start(controller) {
|
|
1950
1979
|
try {
|
|
1951
1980
|
for await (const record of records) {
|
|
1952
|
-
const json = JSON.stringify(record) +
|
|
1981
|
+
const json = JSON.stringify(record) + RECORD_SEPARATOR;
|
|
1953
1982
|
controller.enqueue(encoder.encode(json));
|
|
1954
1983
|
}
|
|
1955
1984
|
controller.close();
|
|
@@ -2047,10 +2076,11 @@ var MCPTool = class extends BaseResource {
|
|
|
2047
2076
|
}
|
|
2048
2077
|
/**
|
|
2049
2078
|
* Retrieves details about this specific tool from the MCP server.
|
|
2079
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2050
2080
|
* @returns Promise containing the tool's information (name, description, schema).
|
|
2051
2081
|
*/
|
|
2052
|
-
details() {
|
|
2053
|
-
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}`);
|
|
2082
|
+
details(runtimeContext) {
|
|
2083
|
+
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
|
|
2054
2084
|
}
|
|
2055
2085
|
/**
|
|
2056
2086
|
* Executes this specific tool on the MCP server.
|
|
@@ -2071,7 +2101,7 @@ var MCPTool = class extends BaseResource {
|
|
|
2071
2101
|
};
|
|
2072
2102
|
|
|
2073
2103
|
// src/resources/agent-builder.ts
|
|
2074
|
-
var
|
|
2104
|
+
var RECORD_SEPARATOR2 = "";
|
|
2075
2105
|
var AgentBuilder = class extends BaseResource {
|
|
2076
2106
|
constructor(options, actionId) {
|
|
2077
2107
|
super(options);
|
|
@@ -2106,11 +2136,20 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2106
2136
|
};
|
|
2107
2137
|
}
|
|
2108
2138
|
}
|
|
2139
|
+
/**
|
|
2140
|
+
* @deprecated Use createRunAsync() instead.
|
|
2141
|
+
* @throws {Error} Always throws an error directing users to use createRunAsync()
|
|
2142
|
+
*/
|
|
2143
|
+
async createRun(_params) {
|
|
2144
|
+
throw new Error(
|
|
2145
|
+
"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."
|
|
2146
|
+
);
|
|
2147
|
+
}
|
|
2109
2148
|
/**
|
|
2110
2149
|
* Creates a new agent builder action run and returns the runId.
|
|
2111
2150
|
* This calls `/api/agent-builder/:actionId/create-run`.
|
|
2112
2151
|
*/
|
|
2113
|
-
async
|
|
2152
|
+
async createRunAsync(params) {
|
|
2114
2153
|
const searchParams = new URLSearchParams();
|
|
2115
2154
|
if (!!params?.runId) {
|
|
2116
2155
|
searchParams.set("runId", params.runId);
|
|
@@ -2120,14 +2159,6 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2120
2159
|
method: "POST"
|
|
2121
2160
|
});
|
|
2122
2161
|
}
|
|
2123
|
-
/**
|
|
2124
|
-
* Creates a new workflow run (alias for createRun)
|
|
2125
|
-
* @param params - Optional object containing the optional runId
|
|
2126
|
-
* @returns Promise containing the runId of the created run
|
|
2127
|
-
*/
|
|
2128
|
-
createRunAsync(params) {
|
|
2129
|
-
return this.createRun(params);
|
|
2130
|
-
}
|
|
2131
2162
|
/**
|
|
2132
2163
|
* Starts agent builder action asynchronously and waits for completion.
|
|
2133
2164
|
* This calls `/api/agent-builder/:actionId/start-async`.
|
|
@@ -2210,7 +2241,7 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2210
2241
|
if (done && !value) continue;
|
|
2211
2242
|
try {
|
|
2212
2243
|
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
2213
|
-
const chunks = (buffer + decoded).split(
|
|
2244
|
+
const chunks = (buffer + decoded).split(RECORD_SEPARATOR2);
|
|
2214
2245
|
buffer = chunks.pop() || "";
|
|
2215
2246
|
for (const chunk of chunks) {
|
|
2216
2247
|
if (chunk) {
|
|
@@ -2267,7 +2298,7 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2267
2298
|
async transform(chunk, controller) {
|
|
2268
2299
|
try {
|
|
2269
2300
|
const decoded = new TextDecoder().decode(chunk);
|
|
2270
|
-
const chunks = decoded.split(
|
|
2301
|
+
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
2271
2302
|
for (const chunk2 of chunks) {
|
|
2272
2303
|
if (chunk2) {
|
|
2273
2304
|
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
@@ -2316,7 +2347,7 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2316
2347
|
async transform(chunk, controller) {
|
|
2317
2348
|
try {
|
|
2318
2349
|
const decoded = new TextDecoder().decode(chunk);
|
|
2319
|
-
const chunks = decoded.split(
|
|
2350
|
+
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
2320
2351
|
for (const chunk2 of chunks) {
|
|
2321
2352
|
if (chunk2) {
|
|
2322
2353
|
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
@@ -2487,6 +2518,12 @@ var Observability = class extends BaseResource {
|
|
|
2487
2518
|
const queryString = searchParams.toString();
|
|
2488
2519
|
return this.request(`/api/observability/traces${queryString ? `?${queryString}` : ""}`);
|
|
2489
2520
|
}
|
|
2521
|
+
score(params) {
|
|
2522
|
+
return this.request(`/api/observability/traces/score`, {
|
|
2523
|
+
method: "POST",
|
|
2524
|
+
body: { ...params }
|
|
2525
|
+
});
|
|
2526
|
+
}
|
|
2490
2527
|
};
|
|
2491
2528
|
|
|
2492
2529
|
// src/resources/network-memory-thread.ts
|
|
@@ -2553,7 +2590,7 @@ var NetworkMemoryThread = class extends BaseResource {
|
|
|
2553
2590
|
};
|
|
2554
2591
|
|
|
2555
2592
|
// src/resources/vNextNetwork.ts
|
|
2556
|
-
var
|
|
2593
|
+
var RECORD_SEPARATOR3 = "";
|
|
2557
2594
|
var VNextNetwork = class extends BaseResource {
|
|
2558
2595
|
constructor(options, networkId) {
|
|
2559
2596
|
super(options);
|
|
@@ -2561,10 +2598,11 @@ var VNextNetwork = class extends BaseResource {
|
|
|
2561
2598
|
}
|
|
2562
2599
|
/**
|
|
2563
2600
|
* Retrieves details about the network
|
|
2601
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2564
2602
|
* @returns Promise containing vNext network details
|
|
2565
2603
|
*/
|
|
2566
|
-
details() {
|
|
2567
|
-
return this.request(`/api/networks/v-next/${this.networkId}`);
|
|
2604
|
+
details(runtimeContext) {
|
|
2605
|
+
return this.request(`/api/networks/v-next/${this.networkId}${runtimeContextQueryString(runtimeContext)}`);
|
|
2568
2606
|
}
|
|
2569
2607
|
/**
|
|
2570
2608
|
* Generates a response from the v-next network
|
|
@@ -2605,7 +2643,7 @@ var VNextNetwork = class extends BaseResource {
|
|
|
2605
2643
|
if (done && !value) continue;
|
|
2606
2644
|
try {
|
|
2607
2645
|
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
2608
|
-
const chunks = (buffer + decoded).split(
|
|
2646
|
+
const chunks = (buffer + decoded).split(RECORD_SEPARATOR3);
|
|
2609
2647
|
buffer = chunks.pop() || "";
|
|
2610
2648
|
for (const chunk of chunks) {
|
|
2611
2649
|
if (chunk) {
|
|
@@ -2699,10 +2737,17 @@ var MastraClient = class extends BaseResource {
|
|
|
2699
2737
|
}
|
|
2700
2738
|
/**
|
|
2701
2739
|
* Retrieves all available agents
|
|
2740
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2702
2741
|
* @returns Promise containing map of agent IDs to agent details
|
|
2703
2742
|
*/
|
|
2704
|
-
getAgents() {
|
|
2705
|
-
|
|
2743
|
+
getAgents(runtimeContext) {
|
|
2744
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
2745
|
+
const searchParams = new URLSearchParams();
|
|
2746
|
+
if (runtimeContextParam) {
|
|
2747
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
2748
|
+
}
|
|
2749
|
+
const queryString = searchParams.toString();
|
|
2750
|
+
return this.request(`/api/agents${queryString ? `?${queryString}` : ""}`);
|
|
2706
2751
|
}
|
|
2707
2752
|
/**
|
|
2708
2753
|
* Gets an agent instance by ID
|
|
@@ -2720,6 +2765,14 @@ var MastraClient = class extends BaseResource {
|
|
|
2720
2765
|
getMemoryThreads(params) {
|
|
2721
2766
|
return this.request(`/api/memory/threads?resourceid=${params.resourceId}&agentId=${params.agentId}`);
|
|
2722
2767
|
}
|
|
2768
|
+
/**
|
|
2769
|
+
* Retrieves memory config for a resource
|
|
2770
|
+
* @param params - Parameters containing the resource ID
|
|
2771
|
+
* @returns Promise containing array of memory threads
|
|
2772
|
+
*/
|
|
2773
|
+
getMemoryConfig(params) {
|
|
2774
|
+
return this.request(`/api/memory/config?agentId=${params.agentId}`);
|
|
2775
|
+
}
|
|
2723
2776
|
/**
|
|
2724
2777
|
* Creates a new memory thread
|
|
2725
2778
|
* @param params - Parameters for creating the memory thread
|
|
@@ -2736,6 +2789,24 @@ var MastraClient = class extends BaseResource {
|
|
|
2736
2789
|
getMemoryThread(threadId, agentId) {
|
|
2737
2790
|
return new MemoryThread(this.options, threadId, agentId);
|
|
2738
2791
|
}
|
|
2792
|
+
getThreadMessages(threadId, opts = {}) {
|
|
2793
|
+
let url = "";
|
|
2794
|
+
if (opts.agentId) {
|
|
2795
|
+
url = `/api/memory/threads/${threadId}/messages?agentId=${opts.agentId}`;
|
|
2796
|
+
} else if (opts.networkId) {
|
|
2797
|
+
url = `/api/memory/network/threads/${threadId}/messages?networkId=${opts.networkId}`;
|
|
2798
|
+
}
|
|
2799
|
+
return this.request(url);
|
|
2800
|
+
}
|
|
2801
|
+
deleteThread(threadId, opts = {}) {
|
|
2802
|
+
let url = "";
|
|
2803
|
+
if (opts.agentId) {
|
|
2804
|
+
url = `/api/memory/threads/${threadId}?agentId=${opts.agentId}`;
|
|
2805
|
+
} else if (opts.networkId) {
|
|
2806
|
+
url = `/api/memory/network/threads/${threadId}?networkId=${opts.networkId}`;
|
|
2807
|
+
}
|
|
2808
|
+
return this.request(url, { method: "DELETE" });
|
|
2809
|
+
}
|
|
2739
2810
|
/**
|
|
2740
2811
|
* Saves messages to memory
|
|
2741
2812
|
* @param params - Parameters containing messages to save
|
|
@@ -2798,10 +2869,17 @@ var MastraClient = class extends BaseResource {
|
|
|
2798
2869
|
}
|
|
2799
2870
|
/**
|
|
2800
2871
|
* Retrieves all available tools
|
|
2872
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2801
2873
|
* @returns Promise containing map of tool IDs to tool details
|
|
2802
2874
|
*/
|
|
2803
|
-
getTools() {
|
|
2804
|
-
|
|
2875
|
+
getTools(runtimeContext) {
|
|
2876
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
2877
|
+
const searchParams = new URLSearchParams();
|
|
2878
|
+
if (runtimeContextParam) {
|
|
2879
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
2880
|
+
}
|
|
2881
|
+
const queryString = searchParams.toString();
|
|
2882
|
+
return this.request(`/api/tools${queryString ? `?${queryString}` : ""}`);
|
|
2805
2883
|
}
|
|
2806
2884
|
/**
|
|
2807
2885
|
* Gets a tool instance by ID
|
|
@@ -2811,27 +2889,19 @@ var MastraClient = class extends BaseResource {
|
|
|
2811
2889
|
getTool(toolId) {
|
|
2812
2890
|
return new Tool(this.options, toolId);
|
|
2813
2891
|
}
|
|
2814
|
-
/**
|
|
2815
|
-
* Retrieves all available legacy workflows
|
|
2816
|
-
* @returns Promise containing map of legacy workflow IDs to legacy workflow details
|
|
2817
|
-
*/
|
|
2818
|
-
getLegacyWorkflows() {
|
|
2819
|
-
return this.request("/api/workflows/legacy");
|
|
2820
|
-
}
|
|
2821
|
-
/**
|
|
2822
|
-
* Gets a legacy workflow instance by ID
|
|
2823
|
-
* @param workflowId - ID of the legacy workflow to retrieve
|
|
2824
|
-
* @returns Legacy Workflow instance
|
|
2825
|
-
*/
|
|
2826
|
-
getLegacyWorkflow(workflowId) {
|
|
2827
|
-
return new LegacyWorkflow(this.options, workflowId);
|
|
2828
|
-
}
|
|
2829
2892
|
/**
|
|
2830
2893
|
* Retrieves all available workflows
|
|
2894
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2831
2895
|
* @returns Promise containing map of workflow IDs to workflow details
|
|
2832
2896
|
*/
|
|
2833
|
-
getWorkflows() {
|
|
2834
|
-
|
|
2897
|
+
getWorkflows(runtimeContext) {
|
|
2898
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
2899
|
+
const searchParams = new URLSearchParams();
|
|
2900
|
+
if (runtimeContextParam) {
|
|
2901
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
2902
|
+
}
|
|
2903
|
+
const queryString = searchParams.toString();
|
|
2904
|
+
return this.request(`/api/workflows${queryString ? `?${queryString}` : ""}`);
|
|
2835
2905
|
}
|
|
2836
2906
|
/**
|
|
2837
2907
|
* Gets a workflow instance by ID
|
|
@@ -2999,13 +3069,6 @@ var MastraClient = class extends BaseResource {
|
|
|
2999
3069
|
return this.request(`/api/telemetry`);
|
|
3000
3070
|
}
|
|
3001
3071
|
}
|
|
3002
|
-
/**
|
|
3003
|
-
* Retrieves all available networks
|
|
3004
|
-
* @returns Promise containing map of network IDs to network details
|
|
3005
|
-
*/
|
|
3006
|
-
getNetworks() {
|
|
3007
|
-
return this.request("/api/networks");
|
|
3008
|
-
}
|
|
3009
3072
|
/**
|
|
3010
3073
|
* Retrieves all available vNext networks
|
|
3011
3074
|
* @returns Promise containing map of vNext network IDs to vNext network details
|
|
@@ -3013,14 +3076,6 @@ var MastraClient = class extends BaseResource {
|
|
|
3013
3076
|
getVNextNetworks() {
|
|
3014
3077
|
return this.request("/api/networks/v-next");
|
|
3015
3078
|
}
|
|
3016
|
-
/**
|
|
3017
|
-
* Gets a network instance by ID
|
|
3018
|
-
* @param networkId - ID of the network to retrieve
|
|
3019
|
-
* @returns Network instance
|
|
3020
|
-
*/
|
|
3021
|
-
getNetwork(networkId) {
|
|
3022
|
-
return new Network(this.options, networkId);
|
|
3023
|
-
}
|
|
3024
3079
|
/**
|
|
3025
3080
|
* Gets a vNext network instance by ID
|
|
3026
3081
|
* @param networkId - ID of the vNext network to retrieve
|
|
@@ -3211,8 +3266,30 @@ var MastraClient = class extends BaseResource {
|
|
|
3211
3266
|
getAITraces(params) {
|
|
3212
3267
|
return this.observability.getTraces(params);
|
|
3213
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
|
+
}
|
|
3214
3288
|
};
|
|
3289
|
+
function createTool(opts) {
|
|
3290
|
+
return new ClientTool(opts);
|
|
3291
|
+
}
|
|
3215
3292
|
|
|
3216
|
-
export { MastraClient };
|
|
3293
|
+
export { ClientTool, MastraClient, createTool };
|
|
3217
3294
|
//# sourceMappingURL=index.js.map
|
|
3218
3295
|
//# sourceMappingURL=index.js.map
|