@mastra/client-js 0.0.0-add-save-score-validation-on-stores-20250911031242 → 0.0.0-add-crumb-action-20251028105537
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 +527 -3
- package/README.md +6 -10
- package/dist/client.d.ts +45 -45
- package/dist/client.d.ts.map +1 -1
- package/dist/index.cjs +645 -646
- 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 +639 -642
- 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 +86 -42
- 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 +98 -97
- 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.map +1 -1
- package/package.json +6 -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.cjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var uiUtils = require('@ai-sdk/ui-utils');
|
|
4
4
|
var uuid = require('@lukeed/uuid');
|
|
5
|
+
var error = require('@mastra/core/error');
|
|
5
6
|
var runtimeContext = require('@mastra/core/runtime-context');
|
|
6
7
|
var isVercelTool = require('@mastra/core/tools/is-vercel-tool');
|
|
7
8
|
var zod = require('zod');
|
|
@@ -21,6 +22,20 @@ function parseClientRuntimeContext(runtimeContext$1) {
|
|
|
21
22
|
}
|
|
22
23
|
return void 0;
|
|
23
24
|
}
|
|
25
|
+
function base64RuntimeContext(runtimeContext) {
|
|
26
|
+
if (runtimeContext) {
|
|
27
|
+
return btoa(JSON.stringify(runtimeContext));
|
|
28
|
+
}
|
|
29
|
+
return void 0;
|
|
30
|
+
}
|
|
31
|
+
function runtimeContextQueryString(runtimeContext) {
|
|
32
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
33
|
+
if (!runtimeContextParam) return "";
|
|
34
|
+
const searchParams = new URLSearchParams();
|
|
35
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
36
|
+
const queryString = searchParams.toString();
|
|
37
|
+
return queryString ? `?${queryString}` : "";
|
|
38
|
+
}
|
|
24
39
|
function isZodType(value) {
|
|
25
40
|
return typeof value === "object" && value !== null && "_def" in value && "parse" in value && typeof value.parse === "function" && "safeParse" in value && typeof value.safeParse === "function";
|
|
26
41
|
}
|
|
@@ -83,14 +98,18 @@ async function sharedProcessMastraStream({
|
|
|
83
98
|
if (line.startsWith("data: ")) {
|
|
84
99
|
const data = line.slice(6);
|
|
85
100
|
if (data === "[DONE]") {
|
|
86
|
-
console.
|
|
101
|
+
console.info("\u{1F3C1} Stream finished");
|
|
87
102
|
return;
|
|
88
103
|
}
|
|
104
|
+
let json;
|
|
89
105
|
try {
|
|
90
|
-
|
|
91
|
-
await onChunk(json);
|
|
106
|
+
json = JSON.parse(data);
|
|
92
107
|
} catch (error) {
|
|
93
108
|
console.error("\u274C JSON parse error:", error, "Data:", data);
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
if (json) {
|
|
112
|
+
await onChunk(json);
|
|
94
113
|
}
|
|
95
114
|
}
|
|
96
115
|
}
|
|
@@ -205,7 +224,9 @@ async function executeToolCallAndRespond({
|
|
|
205
224
|
resourceId,
|
|
206
225
|
threadId,
|
|
207
226
|
runtimeContext,
|
|
208
|
-
tracingContext: { currentSpan: void 0 }
|
|
227
|
+
tracingContext: { currentSpan: void 0 },
|
|
228
|
+
suspend: async () => {
|
|
229
|
+
}
|
|
209
230
|
},
|
|
210
231
|
{
|
|
211
232
|
messages: response.messages,
|
|
@@ -213,11 +234,7 @@ async function executeToolCallAndRespond({
|
|
|
213
234
|
}
|
|
214
235
|
);
|
|
215
236
|
const updatedMessages = [
|
|
216
|
-
|
|
217
|
-
role: "user",
|
|
218
|
-
content: params.messages
|
|
219
|
-
},
|
|
220
|
-
...response.response.messages,
|
|
237
|
+
...response.response.messages || [],
|
|
221
238
|
{
|
|
222
239
|
role: "tool",
|
|
223
240
|
content: [
|
|
@@ -279,17 +296,21 @@ var AgentVoice = class extends BaseResource {
|
|
|
279
296
|
}
|
|
280
297
|
/**
|
|
281
298
|
* Get available speakers for the agent's voice provider
|
|
299
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
300
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
282
301
|
* @returns Promise containing list of available speakers
|
|
283
302
|
*/
|
|
284
|
-
getSpeakers() {
|
|
285
|
-
return this.request(`/api/agents/${this.agentId}/voice/speakers`);
|
|
303
|
+
getSpeakers(runtimeContext) {
|
|
304
|
+
return this.request(`/api/agents/${this.agentId}/voice/speakers${runtimeContextQueryString(runtimeContext)}`);
|
|
286
305
|
}
|
|
287
306
|
/**
|
|
288
307
|
* Get the listener configuration for the agent's voice provider
|
|
308
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
309
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
289
310
|
* @returns Promise containing a check if the agent has listening capabilities
|
|
290
311
|
*/
|
|
291
|
-
getListener() {
|
|
292
|
-
return this.request(`/api/agents/${this.agentId}/voice/listener`);
|
|
312
|
+
getListener(runtimeContext) {
|
|
313
|
+
return this.request(`/api/agents/${this.agentId}/voice/listener${runtimeContextQueryString(runtimeContext)}`);
|
|
293
314
|
}
|
|
294
315
|
};
|
|
295
316
|
var Agent = class extends BaseResource {
|
|
@@ -301,16 +322,17 @@ var Agent = class extends BaseResource {
|
|
|
301
322
|
voice;
|
|
302
323
|
/**
|
|
303
324
|
* Retrieves details about the agent
|
|
325
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
304
326
|
* @returns Promise containing agent details including model and instructions
|
|
305
327
|
*/
|
|
306
|
-
details() {
|
|
307
|
-
return this.request(`/api/agents/${this.agentId}`);
|
|
328
|
+
details(runtimeContext) {
|
|
329
|
+
return this.request(`/api/agents/${this.agentId}${runtimeContextQueryString(runtimeContext)}`);
|
|
308
330
|
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
331
|
+
enhanceInstructions(instructions, comment) {
|
|
332
|
+
return this.request(`/api/agents/${this.agentId}/instructions/enhance`, {
|
|
333
|
+
method: "POST",
|
|
334
|
+
body: { instructions, comment }
|
|
335
|
+
});
|
|
314
336
|
}
|
|
315
337
|
async generateLegacy(params) {
|
|
316
338
|
const processedParams = {
|
|
@@ -343,7 +365,9 @@ var Agent = class extends BaseResource {
|
|
|
343
365
|
resourceId,
|
|
344
366
|
threadId,
|
|
345
367
|
runtimeContext,
|
|
346
|
-
tracingContext: { currentSpan: void 0 }
|
|
368
|
+
tracingContext: { currentSpan: void 0 },
|
|
369
|
+
suspend: async () => {
|
|
370
|
+
}
|
|
347
371
|
},
|
|
348
372
|
{
|
|
349
373
|
messages: response.messages,
|
|
@@ -351,10 +375,6 @@ var Agent = class extends BaseResource {
|
|
|
351
375
|
}
|
|
352
376
|
);
|
|
353
377
|
const updatedMessages = [
|
|
354
|
-
{
|
|
355
|
-
role: "user",
|
|
356
|
-
content: params.messages
|
|
357
|
-
},
|
|
358
378
|
...response.response.messages,
|
|
359
379
|
{
|
|
360
380
|
role: "tool",
|
|
@@ -377,10 +397,18 @@ var Agent = class extends BaseResource {
|
|
|
377
397
|
}
|
|
378
398
|
return response;
|
|
379
399
|
}
|
|
380
|
-
async
|
|
400
|
+
async generate(messagesOrParams, options) {
|
|
401
|
+
let params;
|
|
402
|
+
if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
|
|
403
|
+
params = messagesOrParams;
|
|
404
|
+
} else {
|
|
405
|
+
params = {
|
|
406
|
+
messages: messagesOrParams,
|
|
407
|
+
...options
|
|
408
|
+
};
|
|
409
|
+
}
|
|
381
410
|
const processedParams = {
|
|
382
411
|
...params,
|
|
383
|
-
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
384
412
|
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
385
413
|
clientTools: processClientTools(params.clientTools),
|
|
386
414
|
structuredOutput: params.structuredOutput ? {
|
|
@@ -390,7 +418,7 @@ var Agent = class extends BaseResource {
|
|
|
390
418
|
};
|
|
391
419
|
const { runId, resourceId, threadId, runtimeContext } = processedParams;
|
|
392
420
|
const response = await this.request(
|
|
393
|
-
`/api/agents/${this.agentId}/generate
|
|
421
|
+
`/api/agents/${this.agentId}/generate`,
|
|
394
422
|
{
|
|
395
423
|
method: "POST",
|
|
396
424
|
body: processedParams
|
|
@@ -404,7 +432,7 @@ var Agent = class extends BaseResource {
|
|
|
404
432
|
resourceId,
|
|
405
433
|
threadId,
|
|
406
434
|
runtimeContext,
|
|
407
|
-
respondFn: this.
|
|
435
|
+
respondFn: this.generate.bind(this)
|
|
408
436
|
});
|
|
409
437
|
}
|
|
410
438
|
return response;
|
|
@@ -671,17 +699,6 @@ var Agent = class extends BaseResource {
|
|
|
671
699
|
});
|
|
672
700
|
onFinish?.({ message, finishReason, usage });
|
|
673
701
|
}
|
|
674
|
-
/**
|
|
675
|
-
* Streams a response from the agent
|
|
676
|
-
* @param params - Stream parameters including prompt
|
|
677
|
-
* @returns Promise containing the enhanced Response object with processDataStream method
|
|
678
|
-
*/
|
|
679
|
-
async stream(params) {
|
|
680
|
-
console.warn(
|
|
681
|
-
"Deprecation NOTICE:\nStream method will switch to use streamVNext implementation September 16th, 2025. Please use streamLegacy if you don't want to upgrade just yet."
|
|
682
|
-
);
|
|
683
|
-
return this.streamLegacy(params);
|
|
684
|
-
}
|
|
685
702
|
/**
|
|
686
703
|
* Streams a response from the agent
|
|
687
704
|
* @param params - Stream parameters including prompt
|
|
@@ -696,7 +713,7 @@ var Agent = class extends BaseResource {
|
|
|
696
713
|
clientTools: processClientTools(params.clientTools)
|
|
697
714
|
};
|
|
698
715
|
const { readable, writable } = new TransformStream();
|
|
699
|
-
const response = await this.
|
|
716
|
+
const response = await this.processStreamResponseLegacy(processedParams, writable);
|
|
700
717
|
const streamResponse = new Response(readable, {
|
|
701
718
|
status: response.status,
|
|
702
719
|
statusText: response.statusText,
|
|
@@ -783,6 +800,14 @@ var Agent = class extends BaseResource {
|
|
|
783
800
|
// but this is completely wrong and this fn is probably broken. Remove ":any" and you'll see a bunch of type errors
|
|
784
801
|
onChunk: async (chunk) => {
|
|
785
802
|
switch (chunk.type) {
|
|
803
|
+
case "tripwire": {
|
|
804
|
+
message.parts.push({
|
|
805
|
+
type: "text",
|
|
806
|
+
text: chunk.payload.tripwireReason
|
|
807
|
+
});
|
|
808
|
+
execUpdate();
|
|
809
|
+
break;
|
|
810
|
+
}
|
|
786
811
|
case "step-start": {
|
|
787
812
|
if (!replaceLastMessage) {
|
|
788
813
|
message.id = chunk.payload.messageId;
|
|
@@ -936,7 +961,10 @@ var Agent = class extends BaseResource {
|
|
|
936
961
|
break;
|
|
937
962
|
}
|
|
938
963
|
case "error": {
|
|
939
|
-
throw
|
|
964
|
+
throw error.getErrorFromUnknown(chunk.payload.error, {
|
|
965
|
+
fallbackMessage: "Unknown error in stream",
|
|
966
|
+
supportSerialization: false
|
|
967
|
+
});
|
|
940
968
|
}
|
|
941
969
|
case "data": {
|
|
942
970
|
data.push(...chunk.payload.data);
|
|
@@ -963,8 +991,8 @@ var Agent = class extends BaseResource {
|
|
|
963
991
|
});
|
|
964
992
|
onFinish?.({ message, finishReason, usage });
|
|
965
993
|
}
|
|
966
|
-
async
|
|
967
|
-
const response = await this.request(`/api/agents/${this.agentId}
|
|
994
|
+
async processStreamResponse(processedParams, writable, route = "stream") {
|
|
995
|
+
const response = await this.request(`/api/agents/${this.agentId}/${route}`, {
|
|
968
996
|
method: "POST",
|
|
969
997
|
body: processedParams,
|
|
970
998
|
stream: true
|
|
@@ -979,18 +1007,17 @@ var Agent = class extends BaseResource {
|
|
|
979
1007
|
streamForWritable.pipeTo(
|
|
980
1008
|
new WritableStream({
|
|
981
1009
|
async write(chunk) {
|
|
1010
|
+
let writer;
|
|
982
1011
|
try {
|
|
1012
|
+
writer = writable.getWriter();
|
|
983
1013
|
const text = new TextDecoder().decode(chunk);
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
1014
|
+
const lines = text.split("\n\n");
|
|
1015
|
+
const readableLines = lines.filter((line) => line !== "[DONE]").join("\n\n");
|
|
1016
|
+
await writer.write(new TextEncoder().encode(readableLines));
|
|
987
1017
|
} catch {
|
|
988
|
-
|
|
989
|
-
const writer = writable.getWriter();
|
|
990
|
-
try {
|
|
991
|
-
await writer.write(chunk);
|
|
1018
|
+
await writer?.write(chunk);
|
|
992
1019
|
} finally {
|
|
993
|
-
writer
|
|
1020
|
+
writer?.releaseLock();
|
|
994
1021
|
}
|
|
995
1022
|
}
|
|
996
1023
|
}),
|
|
@@ -1016,9 +1043,11 @@ var Agent = class extends BaseResource {
|
|
|
1016
1043
|
if (toolCall) {
|
|
1017
1044
|
toolCalls.push(toolCall);
|
|
1018
1045
|
}
|
|
1046
|
+
let shouldExecuteClientTool = false;
|
|
1019
1047
|
for (const toolCall2 of toolCalls) {
|
|
1020
1048
|
const clientTool = processedParams.clientTools?.[toolCall2.toolName];
|
|
1021
1049
|
if (clientTool && clientTool.execute) {
|
|
1050
|
+
shouldExecuteClientTool = true;
|
|
1022
1051
|
const result = await clientTool.execute(
|
|
1023
1052
|
{
|
|
1024
1053
|
context: toolCall2?.args,
|
|
@@ -1027,7 +1056,9 @@ var Agent = class extends BaseResource {
|
|
|
1027
1056
|
threadId: processedParams.threadId,
|
|
1028
1057
|
runtimeContext: processedParams.runtimeContext,
|
|
1029
1058
|
// TODO: Pass proper tracing context when client-js supports tracing
|
|
1030
|
-
tracingContext: { currentSpan: void 0 }
|
|
1059
|
+
tracingContext: { currentSpan: void 0 },
|
|
1060
|
+
suspend: async () => {
|
|
1061
|
+
}
|
|
1031
1062
|
},
|
|
1032
1063
|
{
|
|
1033
1064
|
messages: response.messages,
|
|
@@ -1053,10 +1084,8 @@ var Agent = class extends BaseResource {
|
|
|
1053
1084
|
toolInvocation.state = "result";
|
|
1054
1085
|
toolInvocation.result = result;
|
|
1055
1086
|
}
|
|
1056
|
-
const
|
|
1057
|
-
|
|
1058
|
-
const updatedMessages = lastMessage != null ? [...messageArray, ...messages.filter((m) => m.id !== lastMessage.id), lastMessage] : [...messageArray, ...messages];
|
|
1059
|
-
this.processStreamResponse_vNext(
|
|
1087
|
+
const updatedMessages = lastMessage != null ? [...messages.filter((m) => m.id !== lastMessage.id), lastMessage] : [...messages];
|
|
1088
|
+
this.processStreamResponse(
|
|
1060
1089
|
{
|
|
1061
1090
|
...processedParams,
|
|
1062
1091
|
messages: updatedMessages
|
|
@@ -1067,6 +1096,11 @@ var Agent = class extends BaseResource {
|
|
|
1067
1096
|
});
|
|
1068
1097
|
}
|
|
1069
1098
|
}
|
|
1099
|
+
if (!shouldExecuteClientTool) {
|
|
1100
|
+
setTimeout(() => {
|
|
1101
|
+
writable.close();
|
|
1102
|
+
}, 0);
|
|
1103
|
+
}
|
|
1070
1104
|
} else {
|
|
1071
1105
|
setTimeout(() => {
|
|
1072
1106
|
writable.close();
|
|
@@ -1106,10 +1140,18 @@ var Agent = class extends BaseResource {
|
|
|
1106
1140
|
};
|
|
1107
1141
|
return streamResponse;
|
|
1108
1142
|
}
|
|
1109
|
-
async
|
|
1143
|
+
async stream(messagesOrParams, options) {
|
|
1144
|
+
let params;
|
|
1145
|
+
if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
|
|
1146
|
+
params = messagesOrParams;
|
|
1147
|
+
} else {
|
|
1148
|
+
params = {
|
|
1149
|
+
messages: messagesOrParams,
|
|
1150
|
+
...options
|
|
1151
|
+
};
|
|
1152
|
+
}
|
|
1110
1153
|
const processedParams = {
|
|
1111
1154
|
...params,
|
|
1112
|
-
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
1113
1155
|
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
1114
1156
|
clientTools: processClientTools(params.clientTools),
|
|
1115
1157
|
structuredOutput: params.structuredOutput ? {
|
|
@@ -1118,7 +1160,43 @@ var Agent = class extends BaseResource {
|
|
|
1118
1160
|
} : void 0
|
|
1119
1161
|
};
|
|
1120
1162
|
const { readable, writable } = new TransformStream();
|
|
1121
|
-
const response = await this.
|
|
1163
|
+
const response = await this.processStreamResponse(processedParams, writable);
|
|
1164
|
+
const streamResponse = new Response(readable, {
|
|
1165
|
+
status: response.status,
|
|
1166
|
+
statusText: response.statusText,
|
|
1167
|
+
headers: response.headers
|
|
1168
|
+
});
|
|
1169
|
+
streamResponse.processDataStream = async ({
|
|
1170
|
+
onChunk
|
|
1171
|
+
}) => {
|
|
1172
|
+
await processMastraStream({
|
|
1173
|
+
stream: streamResponse.body,
|
|
1174
|
+
onChunk
|
|
1175
|
+
});
|
|
1176
|
+
};
|
|
1177
|
+
return streamResponse;
|
|
1178
|
+
}
|
|
1179
|
+
async approveToolCall(params) {
|
|
1180
|
+
const { readable, writable } = new TransformStream();
|
|
1181
|
+
const response = await this.processStreamResponse(params, writable, "approve-tool-call");
|
|
1182
|
+
const streamResponse = new Response(readable, {
|
|
1183
|
+
status: response.status,
|
|
1184
|
+
statusText: response.statusText,
|
|
1185
|
+
headers: response.headers
|
|
1186
|
+
});
|
|
1187
|
+
streamResponse.processDataStream = async ({
|
|
1188
|
+
onChunk
|
|
1189
|
+
}) => {
|
|
1190
|
+
await processMastraStream({
|
|
1191
|
+
stream: streamResponse.body,
|
|
1192
|
+
onChunk
|
|
1193
|
+
});
|
|
1194
|
+
};
|
|
1195
|
+
return streamResponse;
|
|
1196
|
+
}
|
|
1197
|
+
async declineToolCall(params) {
|
|
1198
|
+
const { readable, writable } = new TransformStream();
|
|
1199
|
+
const response = await this.processStreamResponse(params, writable, "decline-tool-call");
|
|
1122
1200
|
const streamResponse = new Response(readable, {
|
|
1123
1201
|
status: response.status,
|
|
1124
1202
|
statusText: response.statusText,
|
|
@@ -1137,7 +1215,7 @@ var Agent = class extends BaseResource {
|
|
|
1137
1215
|
/**
|
|
1138
1216
|
* Processes the stream response and handles tool calls
|
|
1139
1217
|
*/
|
|
1140
|
-
async
|
|
1218
|
+
async processStreamResponseLegacy(processedParams, writable) {
|
|
1141
1219
|
const response = await this.request(`/api/agents/${this.agentId}/stream-legacy`, {
|
|
1142
1220
|
method: "POST",
|
|
1143
1221
|
body: processedParams,
|
|
@@ -1182,7 +1260,9 @@ var Agent = class extends BaseResource {
|
|
|
1182
1260
|
threadId: processedParams.threadId,
|
|
1183
1261
|
runtimeContext: processedParams.runtimeContext,
|
|
1184
1262
|
// TODO: Pass proper tracing context when client-js supports tracing
|
|
1185
|
-
tracingContext: { currentSpan: void 0 }
|
|
1263
|
+
tracingContext: { currentSpan: void 0 },
|
|
1264
|
+
suspend: async () => {
|
|
1265
|
+
}
|
|
1186
1266
|
},
|
|
1187
1267
|
{
|
|
1188
1268
|
messages: response.messages,
|
|
@@ -1220,12 +1300,10 @@ var Agent = class extends BaseResource {
|
|
|
1220
1300
|
} finally {
|
|
1221
1301
|
writer.releaseLock();
|
|
1222
1302
|
}
|
|
1223
|
-
|
|
1224
|
-
const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
|
|
1225
|
-
this.processStreamResponse(
|
|
1303
|
+
this.processStreamResponseLegacy(
|
|
1226
1304
|
{
|
|
1227
1305
|
...processedParams,
|
|
1228
|
-
messages: [...
|
|
1306
|
+
messages: [...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
|
|
1229
1307
|
},
|
|
1230
1308
|
writable
|
|
1231
1309
|
).catch((error) => {
|
|
@@ -1251,10 +1329,11 @@ var Agent = class extends BaseResource {
|
|
|
1251
1329
|
/**
|
|
1252
1330
|
* Gets details about a specific tool available to the agent
|
|
1253
1331
|
* @param toolId - ID of the tool to retrieve
|
|
1332
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1254
1333
|
* @returns Promise containing tool details
|
|
1255
1334
|
*/
|
|
1256
|
-
getTool(toolId) {
|
|
1257
|
-
return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
|
|
1335
|
+
getTool(toolId, runtimeContext) {
|
|
1336
|
+
return this.request(`/api/agents/${this.agentId}/tools/${toolId}${runtimeContextQueryString(runtimeContext)}`);
|
|
1258
1337
|
}
|
|
1259
1338
|
/**
|
|
1260
1339
|
* Executes a tool for the agent
|
|
@@ -1265,7 +1344,7 @@ var Agent = class extends BaseResource {
|
|
|
1265
1344
|
executeTool(toolId, params) {
|
|
1266
1345
|
const body = {
|
|
1267
1346
|
data: params.data,
|
|
1268
|
-
runtimeContext:
|
|
1347
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1269
1348
|
};
|
|
1270
1349
|
return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
|
|
1271
1350
|
method: "POST",
|
|
@@ -1274,17 +1353,19 @@ var Agent = class extends BaseResource {
|
|
|
1274
1353
|
}
|
|
1275
1354
|
/**
|
|
1276
1355
|
* Retrieves evaluation results for the agent
|
|
1356
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1277
1357
|
* @returns Promise containing agent evaluations
|
|
1278
1358
|
*/
|
|
1279
|
-
evals() {
|
|
1280
|
-
return this.request(`/api/agents/${this.agentId}/evals/ci`);
|
|
1359
|
+
evals(runtimeContext) {
|
|
1360
|
+
return this.request(`/api/agents/${this.agentId}/evals/ci${runtimeContextQueryString(runtimeContext)}`);
|
|
1281
1361
|
}
|
|
1282
1362
|
/**
|
|
1283
1363
|
* Retrieves live evaluation results for the agent
|
|
1364
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1284
1365
|
* @returns Promise containing live agent evaluations
|
|
1285
1366
|
*/
|
|
1286
|
-
liveEvals() {
|
|
1287
|
-
return this.request(`/api/agents/${this.agentId}/evals/live`);
|
|
1367
|
+
liveEvals(runtimeContext) {
|
|
1368
|
+
return this.request(`/api/agents/${this.agentId}/evals/live${runtimeContextQueryString(runtimeContext)}`);
|
|
1288
1369
|
}
|
|
1289
1370
|
/**
|
|
1290
1371
|
* Updates the model for the agent
|
|
@@ -1297,61 +1378,33 @@ var Agent = class extends BaseResource {
|
|
|
1297
1378
|
body: params
|
|
1298
1379
|
});
|
|
1299
1380
|
}
|
|
1300
|
-
};
|
|
1301
|
-
var Network = class extends BaseResource {
|
|
1302
|
-
constructor(options, networkId) {
|
|
1303
|
-
super(options);
|
|
1304
|
-
this.networkId = networkId;
|
|
1305
|
-
}
|
|
1306
|
-
/**
|
|
1307
|
-
* Retrieves details about the network
|
|
1308
|
-
* @returns Promise containing network details
|
|
1309
|
-
*/
|
|
1310
|
-
details() {
|
|
1311
|
-
return this.request(`/api/networks/${this.networkId}`);
|
|
1312
|
-
}
|
|
1313
1381
|
/**
|
|
1314
|
-
*
|
|
1315
|
-
* @param params -
|
|
1316
|
-
* @returns Promise containing the
|
|
1382
|
+
* Updates the model for the agent in the model list
|
|
1383
|
+
* @param params - Parameters for updating the model
|
|
1384
|
+
* @returns Promise containing the updated model
|
|
1317
1385
|
*/
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
...params,
|
|
1321
|
-
output: zodToJsonSchema(params.output),
|
|
1322
|
-
experimental_output: zodToJsonSchema(params.experimental_output)
|
|
1323
|
-
};
|
|
1324
|
-
return this.request(`/api/networks/${this.networkId}/generate`, {
|
|
1386
|
+
updateModelInModelList({ modelConfigId, ...params }) {
|
|
1387
|
+
return this.request(`/api/agents/${this.agentId}/models/${modelConfigId}`, {
|
|
1325
1388
|
method: "POST",
|
|
1326
|
-
body:
|
|
1389
|
+
body: params
|
|
1327
1390
|
});
|
|
1328
1391
|
}
|
|
1329
1392
|
/**
|
|
1330
|
-
*
|
|
1331
|
-
* @param params -
|
|
1332
|
-
* @returns Promise containing the
|
|
1393
|
+
* Reorders the models for the agent
|
|
1394
|
+
* @param params - Parameters for reordering the model list
|
|
1395
|
+
* @returns Promise containing the updated model list
|
|
1333
1396
|
*/
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
...params,
|
|
1337
|
-
output: zodToJsonSchema(params.output),
|
|
1338
|
-
experimental_output: zodToJsonSchema(params.experimental_output)
|
|
1339
|
-
};
|
|
1340
|
-
const response = await this.request(`/api/networks/${this.networkId}/stream`, {
|
|
1397
|
+
reorderModelList(params) {
|
|
1398
|
+
return this.request(`/api/agents/${this.agentId}/models/reorder`, {
|
|
1341
1399
|
method: "POST",
|
|
1342
|
-
body:
|
|
1343
|
-
stream: true
|
|
1400
|
+
body: params
|
|
1344
1401
|
});
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
...options
|
|
1352
|
-
});
|
|
1353
|
-
};
|
|
1354
|
-
return response;
|
|
1402
|
+
}
|
|
1403
|
+
async generateVNext(_messagesOrParams, _options) {
|
|
1404
|
+
throw new Error("generateVNext has been renamed to generate. Please use generate instead.");
|
|
1405
|
+
}
|
|
1406
|
+
async streamVNext(_messagesOrParams, _options) {
|
|
1407
|
+
throw new Error("streamVNext has been renamed to stream. Please use stream instead.");
|
|
1355
1408
|
}
|
|
1356
1409
|
};
|
|
1357
1410
|
|
|
@@ -1442,10 +1495,13 @@ var Vector = class extends BaseResource {
|
|
|
1442
1495
|
/**
|
|
1443
1496
|
* Retrieves details about a specific vector index
|
|
1444
1497
|
* @param indexName - Name of the index to get details for
|
|
1498
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1445
1499
|
* @returns Promise containing vector index details
|
|
1446
1500
|
*/
|
|
1447
|
-
details(indexName) {
|
|
1448
|
-
return this.request(
|
|
1501
|
+
details(indexName, runtimeContext) {
|
|
1502
|
+
return this.request(
|
|
1503
|
+
`/api/vector/${this.vectorName}/indexes/${indexName}${runtimeContextQueryString(runtimeContext)}`
|
|
1504
|
+
);
|
|
1449
1505
|
}
|
|
1450
1506
|
/**
|
|
1451
1507
|
* Deletes a vector index
|
|
@@ -1459,10 +1515,11 @@ var Vector = class extends BaseResource {
|
|
|
1459
1515
|
}
|
|
1460
1516
|
/**
|
|
1461
1517
|
* Retrieves a list of all available indexes
|
|
1518
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1462
1519
|
* @returns Promise containing array of index names
|
|
1463
1520
|
*/
|
|
1464
|
-
getIndexes() {
|
|
1465
|
-
return this.request(`/api/vector/${this.vectorName}/indexes`);
|
|
1521
|
+
getIndexes(runtimeContext) {
|
|
1522
|
+
return this.request(`/api/vector/${this.vectorName}/indexes${runtimeContextQueryString(runtimeContext)}`);
|
|
1466
1523
|
}
|
|
1467
1524
|
/**
|
|
1468
1525
|
* Creates a new vector index
|
|
@@ -1499,123 +1556,50 @@ var Vector = class extends BaseResource {
|
|
|
1499
1556
|
}
|
|
1500
1557
|
};
|
|
1501
1558
|
|
|
1502
|
-
// src/resources/
|
|
1503
|
-
var
|
|
1504
|
-
|
|
1505
|
-
constructor(options, workflowId) {
|
|
1559
|
+
// src/resources/tool.ts
|
|
1560
|
+
var Tool = class extends BaseResource {
|
|
1561
|
+
constructor(options, toolId) {
|
|
1506
1562
|
super(options);
|
|
1507
|
-
this.
|
|
1508
|
-
}
|
|
1509
|
-
/**
|
|
1510
|
-
* Retrieves details about the legacy workflow
|
|
1511
|
-
* @returns Promise containing legacy workflow details including steps and graphs
|
|
1512
|
-
*/
|
|
1513
|
-
details() {
|
|
1514
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}`);
|
|
1515
|
-
}
|
|
1516
|
-
/**
|
|
1517
|
-
* Retrieves all runs for a legacy workflow
|
|
1518
|
-
* @param params - Parameters for filtering runs
|
|
1519
|
-
* @returns Promise containing legacy workflow runs array
|
|
1520
|
-
*/
|
|
1521
|
-
runs(params) {
|
|
1522
|
-
const searchParams = new URLSearchParams();
|
|
1523
|
-
if (params?.fromDate) {
|
|
1524
|
-
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
1525
|
-
}
|
|
1526
|
-
if (params?.toDate) {
|
|
1527
|
-
searchParams.set("toDate", params.toDate.toISOString());
|
|
1528
|
-
}
|
|
1529
|
-
if (params?.limit) {
|
|
1530
|
-
searchParams.set("limit", String(params.limit));
|
|
1531
|
-
}
|
|
1532
|
-
if (params?.offset) {
|
|
1533
|
-
searchParams.set("offset", String(params.offset));
|
|
1534
|
-
}
|
|
1535
|
-
if (params?.resourceId) {
|
|
1536
|
-
searchParams.set("resourceId", params.resourceId);
|
|
1537
|
-
}
|
|
1538
|
-
if (searchParams.size) {
|
|
1539
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/runs?${searchParams}`);
|
|
1540
|
-
} else {
|
|
1541
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/runs`);
|
|
1542
|
-
}
|
|
1543
|
-
}
|
|
1544
|
-
/**
|
|
1545
|
-
* Creates a new legacy workflow run
|
|
1546
|
-
* @returns Promise containing the generated run ID
|
|
1547
|
-
*/
|
|
1548
|
-
createRun(params) {
|
|
1549
|
-
const searchParams = new URLSearchParams();
|
|
1550
|
-
if (!!params?.runId) {
|
|
1551
|
-
searchParams.set("runId", params.runId);
|
|
1552
|
-
}
|
|
1553
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/create-run?${searchParams.toString()}`, {
|
|
1554
|
-
method: "POST"
|
|
1555
|
-
});
|
|
1556
|
-
}
|
|
1557
|
-
/**
|
|
1558
|
-
* Starts a legacy workflow run synchronously without waiting for the workflow to complete
|
|
1559
|
-
* @param params - Object containing the runId and triggerData
|
|
1560
|
-
* @returns Promise containing success message
|
|
1561
|
-
*/
|
|
1562
|
-
start(params) {
|
|
1563
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/start?runId=${params.runId}`, {
|
|
1564
|
-
method: "POST",
|
|
1565
|
-
body: params?.triggerData
|
|
1566
|
-
});
|
|
1563
|
+
this.toolId = toolId;
|
|
1567
1564
|
}
|
|
1568
1565
|
/**
|
|
1569
|
-
*
|
|
1570
|
-
* @param
|
|
1571
|
-
* @
|
|
1572
|
-
* @param context - Context to resume the legacy workflow with
|
|
1573
|
-
* @returns Promise containing the legacy workflow resume results
|
|
1566
|
+
* Retrieves details about the tool
|
|
1567
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1568
|
+
* @returns Promise containing tool details including description and schemas
|
|
1574
1569
|
*/
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
runId,
|
|
1578
|
-
context
|
|
1579
|
-
}) {
|
|
1580
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/resume?runId=${runId}`, {
|
|
1581
|
-
method: "POST",
|
|
1582
|
-
body: {
|
|
1583
|
-
stepId,
|
|
1584
|
-
context
|
|
1585
|
-
}
|
|
1586
|
-
});
|
|
1570
|
+
details(runtimeContext) {
|
|
1571
|
+
return this.request(`/api/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
|
|
1587
1572
|
}
|
|
1588
1573
|
/**
|
|
1589
|
-
*
|
|
1590
|
-
* @param params -
|
|
1591
|
-
* @returns Promise containing the
|
|
1574
|
+
* Executes the tool with the provided parameters
|
|
1575
|
+
* @param params - Parameters required for tool execution
|
|
1576
|
+
* @returns Promise containing the tool execution results
|
|
1592
1577
|
*/
|
|
1593
|
-
|
|
1594
|
-
const
|
|
1595
|
-
if (
|
|
1596
|
-
|
|
1578
|
+
execute(params) {
|
|
1579
|
+
const url = new URLSearchParams();
|
|
1580
|
+
if (params.runId) {
|
|
1581
|
+
url.set("runId", params.runId);
|
|
1597
1582
|
}
|
|
1598
|
-
|
|
1583
|
+
const body = {
|
|
1584
|
+
data: params.data,
|
|
1585
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1586
|
+
};
|
|
1587
|
+
return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
|
|
1599
1588
|
method: "POST",
|
|
1600
|
-
body
|
|
1589
|
+
body
|
|
1601
1590
|
});
|
|
1602
1591
|
}
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
body: {
|
|
1612
|
-
stepId: params.stepId,
|
|
1613
|
-
context: params.context
|
|
1614
|
-
}
|
|
1615
|
-
});
|
|
1592
|
+
};
|
|
1593
|
+
|
|
1594
|
+
// src/resources/workflow.ts
|
|
1595
|
+
var RECORD_SEPARATOR = "";
|
|
1596
|
+
var Workflow = class extends BaseResource {
|
|
1597
|
+
constructor(options, workflowId) {
|
|
1598
|
+
super(options);
|
|
1599
|
+
this.workflowId = workflowId;
|
|
1616
1600
|
}
|
|
1617
1601
|
/**
|
|
1618
|
-
* Creates an async generator that processes a readable stream and yields records
|
|
1602
|
+
* Creates an async generator that processes a readable stream and yields workflow records
|
|
1619
1603
|
* separated by the Record Separator character (\x1E)
|
|
1620
1604
|
*
|
|
1621
1605
|
* @param stream - The readable stream to process
|
|
@@ -1660,162 +1644,65 @@ var LegacyWorkflow = class extends BaseResource {
|
|
|
1660
1644
|
}
|
|
1661
1645
|
}
|
|
1662
1646
|
/**
|
|
1663
|
-
*
|
|
1664
|
-
* @param
|
|
1665
|
-
* @returns
|
|
1647
|
+
* Retrieves details about the workflow
|
|
1648
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1649
|
+
* @returns Promise containing workflow details including steps and graphs
|
|
1666
1650
|
*/
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1651
|
+
details(runtimeContext) {
|
|
1652
|
+
return this.request(`/api/workflows/${this.workflowId}${runtimeContextQueryString(runtimeContext)}`);
|
|
1653
|
+
}
|
|
1654
|
+
/**
|
|
1655
|
+
* Retrieves all runs for a workflow
|
|
1656
|
+
* @param params - Parameters for filtering runs
|
|
1657
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1658
|
+
* @returns Promise containing workflow runs array
|
|
1659
|
+
*/
|
|
1660
|
+
runs(params, runtimeContext) {
|
|
1661
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
1662
|
+
const searchParams = new URLSearchParams();
|
|
1663
|
+
if (params?.fromDate) {
|
|
1664
|
+
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
1673
1665
|
}
|
|
1674
|
-
if (
|
|
1675
|
-
|
|
1666
|
+
if (params?.toDate) {
|
|
1667
|
+
searchParams.set("toDate", params.toDate.toISOString());
|
|
1676
1668
|
}
|
|
1677
|
-
|
|
1678
|
-
|
|
1669
|
+
if (params?.limit !== null && params?.limit !== void 0 && !isNaN(Number(params?.limit))) {
|
|
1670
|
+
searchParams.set("limit", String(params.limit));
|
|
1671
|
+
}
|
|
1672
|
+
if (params?.offset !== null && params?.offset !== void 0 && !isNaN(Number(params?.offset))) {
|
|
1673
|
+
searchParams.set("offset", String(params.offset));
|
|
1674
|
+
}
|
|
1675
|
+
if (params?.resourceId) {
|
|
1676
|
+
searchParams.set("resourceId", params.resourceId);
|
|
1677
|
+
}
|
|
1678
|
+
if (runtimeContextParam) {
|
|
1679
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
1680
|
+
}
|
|
1681
|
+
if (searchParams.size) {
|
|
1682
|
+
return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
|
|
1683
|
+
} else {
|
|
1684
|
+
return this.request(`/api/workflows/${this.workflowId}/runs`);
|
|
1679
1685
|
}
|
|
1680
1686
|
}
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
/**
|
|
1690
|
-
* Retrieves details about the tool
|
|
1691
|
-
* @returns Promise containing tool details including description and schemas
|
|
1692
|
-
*/
|
|
1693
|
-
details() {
|
|
1694
|
-
return this.request(`/api/tools/${this.toolId}`);
|
|
1695
|
-
}
|
|
1696
|
-
/**
|
|
1697
|
-
* Executes the tool with the provided parameters
|
|
1698
|
-
* @param params - Parameters required for tool execution
|
|
1699
|
-
* @returns Promise containing the tool execution results
|
|
1700
|
-
*/
|
|
1701
|
-
execute(params) {
|
|
1702
|
-
const url = new URLSearchParams();
|
|
1703
|
-
if (params.runId) {
|
|
1704
|
-
url.set("runId", params.runId);
|
|
1705
|
-
}
|
|
1706
|
-
const body = {
|
|
1707
|
-
data: params.data,
|
|
1708
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1709
|
-
};
|
|
1710
|
-
return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
|
|
1711
|
-
method: "POST",
|
|
1712
|
-
body
|
|
1713
|
-
});
|
|
1714
|
-
}
|
|
1715
|
-
};
|
|
1716
|
-
|
|
1717
|
-
// src/resources/workflow.ts
|
|
1718
|
-
var RECORD_SEPARATOR2 = "";
|
|
1719
|
-
var Workflow = class extends BaseResource {
|
|
1720
|
-
constructor(options, workflowId) {
|
|
1721
|
-
super(options);
|
|
1722
|
-
this.workflowId = workflowId;
|
|
1723
|
-
}
|
|
1724
|
-
/**
|
|
1725
|
-
* Creates an async generator that processes a readable stream and yields workflow records
|
|
1726
|
-
* separated by the Record Separator character (\x1E)
|
|
1727
|
-
*
|
|
1728
|
-
* @param stream - The readable stream to process
|
|
1729
|
-
* @returns An async generator that yields parsed records
|
|
1730
|
-
*/
|
|
1731
|
-
async *streamProcessor(stream) {
|
|
1732
|
-
const reader = stream.getReader();
|
|
1733
|
-
let doneReading = false;
|
|
1734
|
-
let buffer = "";
|
|
1735
|
-
try {
|
|
1736
|
-
while (!doneReading) {
|
|
1737
|
-
const { done, value } = await reader.read();
|
|
1738
|
-
doneReading = done;
|
|
1739
|
-
if (done && !value) continue;
|
|
1740
|
-
try {
|
|
1741
|
-
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
1742
|
-
const chunks = (buffer + decoded).split(RECORD_SEPARATOR2);
|
|
1743
|
-
buffer = chunks.pop() || "";
|
|
1744
|
-
for (const chunk of chunks) {
|
|
1745
|
-
if (chunk) {
|
|
1746
|
-
if (typeof chunk === "string") {
|
|
1747
|
-
try {
|
|
1748
|
-
const parsedChunk = JSON.parse(chunk);
|
|
1749
|
-
yield parsedChunk;
|
|
1750
|
-
} catch {
|
|
1751
|
-
}
|
|
1752
|
-
}
|
|
1753
|
-
}
|
|
1754
|
-
}
|
|
1755
|
-
} catch {
|
|
1756
|
-
}
|
|
1757
|
-
}
|
|
1758
|
-
if (buffer) {
|
|
1759
|
-
try {
|
|
1760
|
-
yield JSON.parse(buffer);
|
|
1761
|
-
} catch {
|
|
1762
|
-
}
|
|
1763
|
-
}
|
|
1764
|
-
} finally {
|
|
1765
|
-
reader.cancel().catch(() => {
|
|
1766
|
-
});
|
|
1767
|
-
}
|
|
1768
|
-
}
|
|
1769
|
-
/**
|
|
1770
|
-
* Retrieves details about the workflow
|
|
1771
|
-
* @returns Promise containing workflow details including steps and graphs
|
|
1772
|
-
*/
|
|
1773
|
-
details() {
|
|
1774
|
-
return this.request(`/api/workflows/${this.workflowId}`);
|
|
1775
|
-
}
|
|
1776
|
-
/**
|
|
1777
|
-
* Retrieves all runs for a workflow
|
|
1778
|
-
* @param params - Parameters for filtering runs
|
|
1779
|
-
* @returns Promise containing workflow runs array
|
|
1780
|
-
*/
|
|
1781
|
-
runs(params) {
|
|
1782
|
-
const searchParams = new URLSearchParams();
|
|
1783
|
-
if (params?.fromDate) {
|
|
1784
|
-
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
1785
|
-
}
|
|
1786
|
-
if (params?.toDate) {
|
|
1787
|
-
searchParams.set("toDate", params.toDate.toISOString());
|
|
1788
|
-
}
|
|
1789
|
-
if (params?.limit !== null && params?.limit !== void 0 && !isNaN(Number(params?.limit))) {
|
|
1790
|
-
searchParams.set("limit", String(params.limit));
|
|
1791
|
-
}
|
|
1792
|
-
if (params?.offset !== null && params?.offset !== void 0 && !isNaN(Number(params?.offset))) {
|
|
1793
|
-
searchParams.set("offset", String(params.offset));
|
|
1794
|
-
}
|
|
1795
|
-
if (params?.resourceId) {
|
|
1796
|
-
searchParams.set("resourceId", params.resourceId);
|
|
1797
|
-
}
|
|
1798
|
-
if (searchParams.size) {
|
|
1799
|
-
return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
|
|
1800
|
-
} else {
|
|
1801
|
-
return this.request(`/api/workflows/${this.workflowId}/runs`);
|
|
1802
|
-
}
|
|
1803
|
-
}
|
|
1804
|
-
/**
|
|
1805
|
-
* Retrieves a specific workflow run by its ID
|
|
1806
|
-
* @param runId - The ID of the workflow run to retrieve
|
|
1807
|
-
* @returns Promise containing the workflow run details
|
|
1808
|
-
*/
|
|
1809
|
-
runById(runId) {
|
|
1810
|
-
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}`);
|
|
1687
|
+
/**
|
|
1688
|
+
* Retrieves a specific workflow run by its ID
|
|
1689
|
+
* @param runId - The ID of the workflow run to retrieve
|
|
1690
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1691
|
+
* @returns Promise containing the workflow run details
|
|
1692
|
+
*/
|
|
1693
|
+
runById(runId, runtimeContext) {
|
|
1694
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}${runtimeContextQueryString(runtimeContext)}`);
|
|
1811
1695
|
}
|
|
1812
1696
|
/**
|
|
1813
1697
|
* Retrieves the execution result for a specific workflow run by its ID
|
|
1814
1698
|
* @param runId - The ID of the workflow run to retrieve the execution result for
|
|
1699
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1815
1700
|
* @returns Promise containing the workflow run execution result
|
|
1816
1701
|
*/
|
|
1817
|
-
runExecutionResult(runId) {
|
|
1818
|
-
return this.request(
|
|
1702
|
+
runExecutionResult(runId, runtimeContext) {
|
|
1703
|
+
return this.request(
|
|
1704
|
+
`/api/workflows/${this.workflowId}/runs/${runId}/execution-result${runtimeContextQueryString(runtimeContext)}`
|
|
1705
|
+
);
|
|
1819
1706
|
}
|
|
1820
1707
|
/**
|
|
1821
1708
|
* Cancels a specific workflow run by its ID
|
|
@@ -1838,27 +1725,83 @@ var Workflow = class extends BaseResource {
|
|
|
1838
1725
|
body: { event: params.event, data: params.data }
|
|
1839
1726
|
});
|
|
1840
1727
|
}
|
|
1728
|
+
/**
|
|
1729
|
+
* @deprecated Use createRunAsync() instead.
|
|
1730
|
+
* @throws {Error} Always throws an error directing users to use createRunAsync()
|
|
1731
|
+
*/
|
|
1732
|
+
async createRun(_params) {
|
|
1733
|
+
throw new Error(
|
|
1734
|
+
"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."
|
|
1735
|
+
);
|
|
1736
|
+
}
|
|
1841
1737
|
/**
|
|
1842
1738
|
* Creates a new workflow run
|
|
1843
1739
|
* @param params - Optional object containing the optional runId
|
|
1844
|
-
* @returns Promise containing the runId of the created run
|
|
1740
|
+
* @returns Promise containing the runId of the created run with methods to control execution
|
|
1845
1741
|
*/
|
|
1846
|
-
|
|
1742
|
+
async createRunAsync(params) {
|
|
1847
1743
|
const searchParams = new URLSearchParams();
|
|
1848
1744
|
if (!!params?.runId) {
|
|
1849
1745
|
searchParams.set("runId", params.runId);
|
|
1850
1746
|
}
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1747
|
+
const res = await this.request(
|
|
1748
|
+
`/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`,
|
|
1749
|
+
{
|
|
1750
|
+
method: "POST"
|
|
1751
|
+
}
|
|
1752
|
+
);
|
|
1753
|
+
const runId = res.runId;
|
|
1754
|
+
return {
|
|
1755
|
+
runId,
|
|
1756
|
+
start: async (p) => {
|
|
1757
|
+
return this.start({
|
|
1758
|
+
runId,
|
|
1759
|
+
inputData: p.inputData,
|
|
1760
|
+
runtimeContext: p.runtimeContext,
|
|
1761
|
+
tracingOptions: p.tracingOptions
|
|
1762
|
+
});
|
|
1763
|
+
},
|
|
1764
|
+
startAsync: async (p) => {
|
|
1765
|
+
return this.startAsync({
|
|
1766
|
+
runId,
|
|
1767
|
+
inputData: p.inputData,
|
|
1768
|
+
runtimeContext: p.runtimeContext,
|
|
1769
|
+
tracingOptions: p.tracingOptions
|
|
1770
|
+
});
|
|
1771
|
+
},
|
|
1772
|
+
watch: async (onRecord) => {
|
|
1773
|
+
return this.watch({ runId }, onRecord);
|
|
1774
|
+
},
|
|
1775
|
+
stream: async (p) => {
|
|
1776
|
+
return this.stream({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
|
|
1777
|
+
},
|
|
1778
|
+
resume: async (p) => {
|
|
1779
|
+
return this.resume({
|
|
1780
|
+
runId,
|
|
1781
|
+
step: p.step,
|
|
1782
|
+
resumeData: p.resumeData,
|
|
1783
|
+
runtimeContext: p.runtimeContext,
|
|
1784
|
+
tracingOptions: p.tracingOptions
|
|
1785
|
+
});
|
|
1786
|
+
},
|
|
1787
|
+
resumeAsync: async (p) => {
|
|
1788
|
+
return this.resumeAsync({
|
|
1789
|
+
runId,
|
|
1790
|
+
step: p.step,
|
|
1791
|
+
resumeData: p.resumeData,
|
|
1792
|
+
runtimeContext: p.runtimeContext,
|
|
1793
|
+
tracingOptions: p.tracingOptions
|
|
1794
|
+
});
|
|
1795
|
+
},
|
|
1796
|
+
resumeStreamVNext: async (p) => {
|
|
1797
|
+
return this.resumeStreamVNext({
|
|
1798
|
+
runId,
|
|
1799
|
+
step: p.step,
|
|
1800
|
+
resumeData: p.resumeData,
|
|
1801
|
+
runtimeContext: p.runtimeContext
|
|
1802
|
+
});
|
|
1803
|
+
}
|
|
1804
|
+
};
|
|
1862
1805
|
}
|
|
1863
1806
|
/**
|
|
1864
1807
|
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
@@ -1869,7 +1812,7 @@ var Workflow = class extends BaseResource {
|
|
|
1869
1812
|
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1870
1813
|
return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
|
|
1871
1814
|
method: "POST",
|
|
1872
|
-
body: { inputData: params?.inputData, runtimeContext }
|
|
1815
|
+
body: { inputData: params?.inputData, runtimeContext, tracingOptions: params.tracingOptions }
|
|
1873
1816
|
});
|
|
1874
1817
|
}
|
|
1875
1818
|
/**
|
|
@@ -1881,16 +1824,17 @@ var Workflow = class extends BaseResource {
|
|
|
1881
1824
|
step,
|
|
1882
1825
|
runId,
|
|
1883
1826
|
resumeData,
|
|
1827
|
+
tracingOptions,
|
|
1884
1828
|
...rest
|
|
1885
1829
|
}) {
|
|
1886
1830
|
const runtimeContext = parseClientRuntimeContext(rest.runtimeContext);
|
|
1887
1831
|
return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
|
|
1888
1832
|
method: "POST",
|
|
1889
|
-
stream: true,
|
|
1890
1833
|
body: {
|
|
1891
1834
|
step,
|
|
1892
1835
|
resumeData,
|
|
1893
|
-
runtimeContext
|
|
1836
|
+
runtimeContext,
|
|
1837
|
+
tracingOptions
|
|
1894
1838
|
}
|
|
1895
1839
|
});
|
|
1896
1840
|
}
|
|
@@ -1907,7 +1851,7 @@ var Workflow = class extends BaseResource {
|
|
|
1907
1851
|
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1908
1852
|
return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
1909
1853
|
method: "POST",
|
|
1910
|
-
body: { inputData: params.inputData, runtimeContext }
|
|
1854
|
+
body: { inputData: params.inputData, runtimeContext, tracingOptions: params.tracingOptions }
|
|
1911
1855
|
});
|
|
1912
1856
|
}
|
|
1913
1857
|
/**
|
|
@@ -1925,12 +1869,12 @@ var Workflow = class extends BaseResource {
|
|
|
1925
1869
|
`/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
|
|
1926
1870
|
{
|
|
1927
1871
|
method: "POST",
|
|
1928
|
-
body: { inputData: params.inputData, runtimeContext },
|
|
1872
|
+
body: { inputData: params.inputData, runtimeContext, tracingOptions: params.tracingOptions },
|
|
1929
1873
|
stream: true
|
|
1930
1874
|
}
|
|
1931
1875
|
);
|
|
1932
1876
|
if (!response.ok) {
|
|
1933
|
-
throw new Error(`Failed to stream
|
|
1877
|
+
throw new Error(`Failed to stream workflow: ${response.statusText}`);
|
|
1934
1878
|
}
|
|
1935
1879
|
if (!response.body) {
|
|
1936
1880
|
throw new Error("Response body is null");
|
|
@@ -1942,7 +1886,54 @@ var Workflow = class extends BaseResource {
|
|
|
1942
1886
|
async transform(chunk, controller) {
|
|
1943
1887
|
try {
|
|
1944
1888
|
const decoded = new TextDecoder().decode(chunk);
|
|
1945
|
-
const chunks = decoded.split(
|
|
1889
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
1890
|
+
for (const chunk2 of chunks) {
|
|
1891
|
+
if (chunk2) {
|
|
1892
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
1893
|
+
try {
|
|
1894
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
1895
|
+
controller.enqueue(parsedChunk);
|
|
1896
|
+
failedChunk = void 0;
|
|
1897
|
+
} catch {
|
|
1898
|
+
failedChunk = newChunk;
|
|
1899
|
+
}
|
|
1900
|
+
}
|
|
1901
|
+
}
|
|
1902
|
+
} catch {
|
|
1903
|
+
}
|
|
1904
|
+
}
|
|
1905
|
+
});
|
|
1906
|
+
return response.body.pipeThrough(transformStream);
|
|
1907
|
+
}
|
|
1908
|
+
/**
|
|
1909
|
+
* Observes workflow stream for a workflow run
|
|
1910
|
+
* @param params - Object containing the runId
|
|
1911
|
+
* @returns Promise containing the workflow execution results
|
|
1912
|
+
*/
|
|
1913
|
+
async observeStream(params) {
|
|
1914
|
+
const searchParams = new URLSearchParams();
|
|
1915
|
+
searchParams.set("runId", params.runId);
|
|
1916
|
+
const response = await this.request(
|
|
1917
|
+
`/api/workflows/${this.workflowId}/observe-stream?${searchParams.toString()}`,
|
|
1918
|
+
{
|
|
1919
|
+
method: "POST",
|
|
1920
|
+
stream: true
|
|
1921
|
+
}
|
|
1922
|
+
);
|
|
1923
|
+
if (!response.ok) {
|
|
1924
|
+
throw new Error(`Failed to observe workflow stream: ${response.statusText}`);
|
|
1925
|
+
}
|
|
1926
|
+
if (!response.body) {
|
|
1927
|
+
throw new Error("Response body is null");
|
|
1928
|
+
}
|
|
1929
|
+
let failedChunk = void 0;
|
|
1930
|
+
const transformStream = new TransformStream({
|
|
1931
|
+
start() {
|
|
1932
|
+
},
|
|
1933
|
+
async transform(chunk, controller) {
|
|
1934
|
+
try {
|
|
1935
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
1936
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
1946
1937
|
for (const chunk2 of chunks) {
|
|
1947
1938
|
if (chunk2) {
|
|
1948
1939
|
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
@@ -1976,7 +1967,12 @@ var Workflow = class extends BaseResource {
|
|
|
1976
1967
|
`/api/workflows/${this.workflowId}/streamVNext?${searchParams.toString()}`,
|
|
1977
1968
|
{
|
|
1978
1969
|
method: "POST",
|
|
1979
|
-
body: {
|
|
1970
|
+
body: {
|
|
1971
|
+
inputData: params.inputData,
|
|
1972
|
+
runtimeContext,
|
|
1973
|
+
closeOnSuspend: params.closeOnSuspend,
|
|
1974
|
+
tracingOptions: params.tracingOptions
|
|
1975
|
+
},
|
|
1980
1976
|
stream: true
|
|
1981
1977
|
}
|
|
1982
1978
|
);
|
|
@@ -1993,7 +1989,54 @@ var Workflow = class extends BaseResource {
|
|
|
1993
1989
|
async transform(chunk, controller) {
|
|
1994
1990
|
try {
|
|
1995
1991
|
const decoded = new TextDecoder().decode(chunk);
|
|
1996
|
-
const chunks = decoded.split(
|
|
1992
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
1993
|
+
for (const chunk2 of chunks) {
|
|
1994
|
+
if (chunk2) {
|
|
1995
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
1996
|
+
try {
|
|
1997
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
1998
|
+
controller.enqueue(parsedChunk);
|
|
1999
|
+
failedChunk = void 0;
|
|
2000
|
+
} catch {
|
|
2001
|
+
failedChunk = newChunk;
|
|
2002
|
+
}
|
|
2003
|
+
}
|
|
2004
|
+
}
|
|
2005
|
+
} catch {
|
|
2006
|
+
}
|
|
2007
|
+
}
|
|
2008
|
+
});
|
|
2009
|
+
return response.body.pipeThrough(transformStream);
|
|
2010
|
+
}
|
|
2011
|
+
/**
|
|
2012
|
+
* Observes workflow vNext stream for a workflow run
|
|
2013
|
+
* @param params - Object containing the runId
|
|
2014
|
+
* @returns Promise containing the workflow execution results
|
|
2015
|
+
*/
|
|
2016
|
+
async observeStreamVNext(params) {
|
|
2017
|
+
const searchParams = new URLSearchParams();
|
|
2018
|
+
searchParams.set("runId", params.runId);
|
|
2019
|
+
const response = await this.request(
|
|
2020
|
+
`/api/workflows/${this.workflowId}/observe-streamVNext?${searchParams.toString()}`,
|
|
2021
|
+
{
|
|
2022
|
+
method: "POST",
|
|
2023
|
+
stream: true
|
|
2024
|
+
}
|
|
2025
|
+
);
|
|
2026
|
+
if (!response.ok) {
|
|
2027
|
+
throw new Error(`Failed to observe stream vNext workflow: ${response.statusText}`);
|
|
2028
|
+
}
|
|
2029
|
+
if (!response.body) {
|
|
2030
|
+
throw new Error("Response body is null");
|
|
2031
|
+
}
|
|
2032
|
+
let failedChunk = void 0;
|
|
2033
|
+
const transformStream = new TransformStream({
|
|
2034
|
+
start() {
|
|
2035
|
+
},
|
|
2036
|
+
async transform(chunk, controller) {
|
|
2037
|
+
try {
|
|
2038
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
2039
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
1997
2040
|
for (const chunk2 of chunks) {
|
|
1998
2041
|
if (chunk2) {
|
|
1999
2042
|
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
@@ -2024,9 +2067,64 @@ var Workflow = class extends BaseResource {
|
|
|
2024
2067
|
body: {
|
|
2025
2068
|
step: params.step,
|
|
2026
2069
|
resumeData: params.resumeData,
|
|
2027
|
-
runtimeContext
|
|
2070
|
+
runtimeContext,
|
|
2071
|
+
tracingOptions: params.tracingOptions
|
|
2072
|
+
}
|
|
2073
|
+
});
|
|
2074
|
+
}
|
|
2075
|
+
/**
|
|
2076
|
+
* Resumes a suspended workflow step that uses streamVNext asynchronously and returns a promise that resolves when the workflow is complete
|
|
2077
|
+
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
2078
|
+
* @returns Promise containing the workflow resume results
|
|
2079
|
+
*/
|
|
2080
|
+
async resumeStreamVNext(params) {
|
|
2081
|
+
const searchParams = new URLSearchParams();
|
|
2082
|
+
searchParams.set("runId", params.runId);
|
|
2083
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
2084
|
+
const response = await this.request(
|
|
2085
|
+
`/api/workflows/${this.workflowId}/resume-stream?${searchParams.toString()}`,
|
|
2086
|
+
{
|
|
2087
|
+
method: "POST",
|
|
2088
|
+
body: {
|
|
2089
|
+
step: params.step,
|
|
2090
|
+
resumeData: params.resumeData,
|
|
2091
|
+
runtimeContext,
|
|
2092
|
+
tracingOptions: params.tracingOptions
|
|
2093
|
+
},
|
|
2094
|
+
stream: true
|
|
2095
|
+
}
|
|
2096
|
+
);
|
|
2097
|
+
if (!response.ok) {
|
|
2098
|
+
throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
|
|
2099
|
+
}
|
|
2100
|
+
if (!response.body) {
|
|
2101
|
+
throw new Error("Response body is null");
|
|
2102
|
+
}
|
|
2103
|
+
let failedChunk = void 0;
|
|
2104
|
+
const transformStream = new TransformStream({
|
|
2105
|
+
start() {
|
|
2106
|
+
},
|
|
2107
|
+
async transform(chunk, controller) {
|
|
2108
|
+
try {
|
|
2109
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
2110
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
2111
|
+
for (const chunk2 of chunks) {
|
|
2112
|
+
if (chunk2) {
|
|
2113
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
2114
|
+
try {
|
|
2115
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
2116
|
+
controller.enqueue(parsedChunk);
|
|
2117
|
+
failedChunk = void 0;
|
|
2118
|
+
} catch {
|
|
2119
|
+
failedChunk = newChunk;
|
|
2120
|
+
}
|
|
2121
|
+
}
|
|
2122
|
+
}
|
|
2123
|
+
} catch {
|
|
2124
|
+
}
|
|
2028
2125
|
}
|
|
2029
2126
|
});
|
|
2127
|
+
return response.body.pipeThrough(transformStream);
|
|
2030
2128
|
}
|
|
2031
2129
|
/**
|
|
2032
2130
|
* Watches workflow transitions in real-time
|
|
@@ -2064,7 +2162,7 @@ var Workflow = class extends BaseResource {
|
|
|
2064
2162
|
async start(controller) {
|
|
2065
2163
|
try {
|
|
2066
2164
|
for await (const record of records) {
|
|
2067
|
-
const json = JSON.stringify(record) +
|
|
2165
|
+
const json = JSON.stringify(record) + RECORD_SEPARATOR;
|
|
2068
2166
|
controller.enqueue(encoder.encode(json));
|
|
2069
2167
|
}
|
|
2070
2168
|
controller.close();
|
|
@@ -2162,10 +2260,11 @@ var MCPTool = class extends BaseResource {
|
|
|
2162
2260
|
}
|
|
2163
2261
|
/**
|
|
2164
2262
|
* Retrieves details about this specific tool from the MCP server.
|
|
2263
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2165
2264
|
* @returns Promise containing the tool's information (name, description, schema).
|
|
2166
2265
|
*/
|
|
2167
|
-
details() {
|
|
2168
|
-
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}`);
|
|
2266
|
+
details(runtimeContext) {
|
|
2267
|
+
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
|
|
2169
2268
|
}
|
|
2170
2269
|
/**
|
|
2171
2270
|
* Executes this specific tool on the MCP server.
|
|
@@ -2186,7 +2285,7 @@ var MCPTool = class extends BaseResource {
|
|
|
2186
2285
|
};
|
|
2187
2286
|
|
|
2188
2287
|
// src/resources/agent-builder.ts
|
|
2189
|
-
var
|
|
2288
|
+
var RECORD_SEPARATOR2 = "";
|
|
2190
2289
|
var AgentBuilder = class extends BaseResource {
|
|
2191
2290
|
constructor(options, actionId) {
|
|
2192
2291
|
super(options);
|
|
@@ -2221,11 +2320,20 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2221
2320
|
};
|
|
2222
2321
|
}
|
|
2223
2322
|
}
|
|
2323
|
+
/**
|
|
2324
|
+
* @deprecated Use createRunAsync() instead.
|
|
2325
|
+
* @throws {Error} Always throws an error directing users to use createRunAsync()
|
|
2326
|
+
*/
|
|
2327
|
+
async createRun(_params) {
|
|
2328
|
+
throw new Error(
|
|
2329
|
+
"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."
|
|
2330
|
+
);
|
|
2331
|
+
}
|
|
2224
2332
|
/**
|
|
2225
2333
|
* Creates a new agent builder action run and returns the runId.
|
|
2226
2334
|
* This calls `/api/agent-builder/:actionId/create-run`.
|
|
2227
2335
|
*/
|
|
2228
|
-
async
|
|
2336
|
+
async createRunAsync(params) {
|
|
2229
2337
|
const searchParams = new URLSearchParams();
|
|
2230
2338
|
if (!!params?.runId) {
|
|
2231
2339
|
searchParams.set("runId", params.runId);
|
|
@@ -2235,14 +2343,6 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2235
2343
|
method: "POST"
|
|
2236
2344
|
});
|
|
2237
2345
|
}
|
|
2238
|
-
/**
|
|
2239
|
-
* Creates a new workflow run (alias for createRun)
|
|
2240
|
-
* @param params - Optional object containing the optional runId
|
|
2241
|
-
* @returns Promise containing the runId of the created run
|
|
2242
|
-
*/
|
|
2243
|
-
createRunAsync(params) {
|
|
2244
|
-
return this.createRun(params);
|
|
2245
|
-
}
|
|
2246
2346
|
/**
|
|
2247
2347
|
* Starts agent builder action asynchronously and waits for completion.
|
|
2248
2348
|
* This calls `/api/agent-builder/:actionId/start-async`.
|
|
@@ -2325,7 +2425,7 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2325
2425
|
if (done && !value) continue;
|
|
2326
2426
|
try {
|
|
2327
2427
|
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
2328
|
-
const chunks = (buffer + decoded).split(
|
|
2428
|
+
const chunks = (buffer + decoded).split(RECORD_SEPARATOR2);
|
|
2329
2429
|
buffer = chunks.pop() || "";
|
|
2330
2430
|
for (const chunk of chunks) {
|
|
2331
2431
|
if (chunk) {
|
|
@@ -2382,7 +2482,7 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2382
2482
|
async transform(chunk, controller) {
|
|
2383
2483
|
try {
|
|
2384
2484
|
const decoded = new TextDecoder().decode(chunk);
|
|
2385
|
-
const chunks = decoded.split(
|
|
2485
|
+
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
2386
2486
|
for (const chunk2 of chunks) {
|
|
2387
2487
|
if (chunk2) {
|
|
2388
2488
|
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
@@ -2431,7 +2531,7 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2431
2531
|
async transform(chunk, controller) {
|
|
2432
2532
|
try {
|
|
2433
2533
|
const decoded = new TextDecoder().decode(chunk);
|
|
2434
|
-
const chunks = decoded.split(
|
|
2534
|
+
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
2435
2535
|
for (const chunk2 of chunks) {
|
|
2436
2536
|
if (chunk2) {
|
|
2437
2537
|
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
@@ -2602,6 +2702,31 @@ var Observability = class extends BaseResource {
|
|
|
2602
2702
|
const queryString = searchParams.toString();
|
|
2603
2703
|
return this.request(`/api/observability/traces${queryString ? `?${queryString}` : ""}`);
|
|
2604
2704
|
}
|
|
2705
|
+
/**
|
|
2706
|
+
* Retrieves scores by trace ID and span ID
|
|
2707
|
+
* @param params - Parameters containing trace ID, span ID, and pagination options
|
|
2708
|
+
* @returns Promise containing scores and pagination info
|
|
2709
|
+
*/
|
|
2710
|
+
getScoresBySpan(params) {
|
|
2711
|
+
const { traceId, spanId, page, perPage } = params;
|
|
2712
|
+
const searchParams = new URLSearchParams();
|
|
2713
|
+
if (page !== void 0) {
|
|
2714
|
+
searchParams.set("page", String(page));
|
|
2715
|
+
}
|
|
2716
|
+
if (perPage !== void 0) {
|
|
2717
|
+
searchParams.set("perPage", String(perPage));
|
|
2718
|
+
}
|
|
2719
|
+
const queryString = searchParams.toString();
|
|
2720
|
+
return this.request(
|
|
2721
|
+
`/api/observability/traces/${encodeURIComponent(traceId)}/${encodeURIComponent(spanId)}/scores${queryString ? `?${queryString}` : ""}`
|
|
2722
|
+
);
|
|
2723
|
+
}
|
|
2724
|
+
score(params) {
|
|
2725
|
+
return this.request(`/api/observability/traces/score`, {
|
|
2726
|
+
method: "POST",
|
|
2727
|
+
body: { ...params }
|
|
2728
|
+
});
|
|
2729
|
+
}
|
|
2605
2730
|
};
|
|
2606
2731
|
|
|
2607
2732
|
// src/resources/network-memory-thread.ts
|
|
@@ -2667,144 +2792,6 @@ var NetworkMemoryThread = class extends BaseResource {
|
|
|
2667
2792
|
}
|
|
2668
2793
|
};
|
|
2669
2794
|
|
|
2670
|
-
// src/resources/vNextNetwork.ts
|
|
2671
|
-
var RECORD_SEPARATOR4 = "";
|
|
2672
|
-
var VNextNetwork = class extends BaseResource {
|
|
2673
|
-
constructor(options, networkId) {
|
|
2674
|
-
super(options);
|
|
2675
|
-
this.networkId = networkId;
|
|
2676
|
-
}
|
|
2677
|
-
/**
|
|
2678
|
-
* Retrieves details about the network
|
|
2679
|
-
* @returns Promise containing vNext network details
|
|
2680
|
-
*/
|
|
2681
|
-
details() {
|
|
2682
|
-
return this.request(`/api/networks/v-next/${this.networkId}`);
|
|
2683
|
-
}
|
|
2684
|
-
/**
|
|
2685
|
-
* Generates a response from the v-next network
|
|
2686
|
-
* @param params - Generation parameters including message
|
|
2687
|
-
* @returns Promise containing the generated response
|
|
2688
|
-
*/
|
|
2689
|
-
generate(params) {
|
|
2690
|
-
return this.request(`/api/networks/v-next/${this.networkId}/generate`, {
|
|
2691
|
-
method: "POST",
|
|
2692
|
-
body: {
|
|
2693
|
-
...params,
|
|
2694
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
2695
|
-
}
|
|
2696
|
-
});
|
|
2697
|
-
}
|
|
2698
|
-
/**
|
|
2699
|
-
* Generates a response from the v-next network using multiple primitives
|
|
2700
|
-
* @param params - Generation parameters including message
|
|
2701
|
-
* @returns Promise containing the generated response
|
|
2702
|
-
*/
|
|
2703
|
-
loop(params) {
|
|
2704
|
-
return this.request(`/api/networks/v-next/${this.networkId}/loop`, {
|
|
2705
|
-
method: "POST",
|
|
2706
|
-
body: {
|
|
2707
|
-
...params,
|
|
2708
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
2709
|
-
}
|
|
2710
|
-
});
|
|
2711
|
-
}
|
|
2712
|
-
async *streamProcessor(stream) {
|
|
2713
|
-
const reader = stream.getReader();
|
|
2714
|
-
let doneReading = false;
|
|
2715
|
-
let buffer = "";
|
|
2716
|
-
try {
|
|
2717
|
-
while (!doneReading) {
|
|
2718
|
-
const { done, value } = await reader.read();
|
|
2719
|
-
doneReading = done;
|
|
2720
|
-
if (done && !value) continue;
|
|
2721
|
-
try {
|
|
2722
|
-
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
2723
|
-
const chunks = (buffer + decoded).split(RECORD_SEPARATOR4);
|
|
2724
|
-
buffer = chunks.pop() || "";
|
|
2725
|
-
for (const chunk of chunks) {
|
|
2726
|
-
if (chunk) {
|
|
2727
|
-
if (typeof chunk === "string") {
|
|
2728
|
-
try {
|
|
2729
|
-
const parsedChunk = JSON.parse(chunk);
|
|
2730
|
-
yield parsedChunk;
|
|
2731
|
-
} catch {
|
|
2732
|
-
}
|
|
2733
|
-
}
|
|
2734
|
-
}
|
|
2735
|
-
}
|
|
2736
|
-
} catch {
|
|
2737
|
-
}
|
|
2738
|
-
}
|
|
2739
|
-
if (buffer) {
|
|
2740
|
-
try {
|
|
2741
|
-
yield JSON.parse(buffer);
|
|
2742
|
-
} catch {
|
|
2743
|
-
}
|
|
2744
|
-
}
|
|
2745
|
-
} finally {
|
|
2746
|
-
reader.cancel().catch(() => {
|
|
2747
|
-
});
|
|
2748
|
-
}
|
|
2749
|
-
}
|
|
2750
|
-
/**
|
|
2751
|
-
* Streams a response from the v-next network
|
|
2752
|
-
* @param params - Stream parameters including message
|
|
2753
|
-
* @returns Promise containing the results
|
|
2754
|
-
*/
|
|
2755
|
-
async stream(params, onRecord) {
|
|
2756
|
-
const response = await this.request(`/api/networks/v-next/${this.networkId}/stream`, {
|
|
2757
|
-
method: "POST",
|
|
2758
|
-
body: {
|
|
2759
|
-
...params,
|
|
2760
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
2761
|
-
},
|
|
2762
|
-
stream: true
|
|
2763
|
-
});
|
|
2764
|
-
if (!response.ok) {
|
|
2765
|
-
throw new Error(`Failed to stream vNext network: ${response.statusText}`);
|
|
2766
|
-
}
|
|
2767
|
-
if (!response.body) {
|
|
2768
|
-
throw new Error("Response body is null");
|
|
2769
|
-
}
|
|
2770
|
-
for await (const record of this.streamProcessor(response.body)) {
|
|
2771
|
-
if (typeof record === "string") {
|
|
2772
|
-
onRecord(JSON.parse(record));
|
|
2773
|
-
} else {
|
|
2774
|
-
onRecord(record);
|
|
2775
|
-
}
|
|
2776
|
-
}
|
|
2777
|
-
}
|
|
2778
|
-
/**
|
|
2779
|
-
* Streams a response from the v-next network loop
|
|
2780
|
-
* @param params - Stream parameters including message
|
|
2781
|
-
* @returns Promise containing the results
|
|
2782
|
-
*/
|
|
2783
|
-
async loopStream(params, onRecord) {
|
|
2784
|
-
const response = await this.request(`/api/networks/v-next/${this.networkId}/loop-stream`, {
|
|
2785
|
-
method: "POST",
|
|
2786
|
-
body: {
|
|
2787
|
-
...params,
|
|
2788
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
2789
|
-
},
|
|
2790
|
-
stream: true
|
|
2791
|
-
});
|
|
2792
|
-
if (!response.ok) {
|
|
2793
|
-
throw new Error(`Failed to stream vNext network loop: ${response.statusText}`);
|
|
2794
|
-
}
|
|
2795
|
-
if (!response.body) {
|
|
2796
|
-
throw new Error("Response body is null");
|
|
2797
|
-
}
|
|
2798
|
-
for await (const record of this.streamProcessor(response.body)) {
|
|
2799
|
-
if (typeof record === "string") {
|
|
2800
|
-
onRecord(JSON.parse(record));
|
|
2801
|
-
} else {
|
|
2802
|
-
onRecord(record);
|
|
2803
|
-
}
|
|
2804
|
-
}
|
|
2805
|
-
}
|
|
2806
|
-
};
|
|
2807
|
-
|
|
2808
2795
|
// src/client.ts
|
|
2809
2796
|
var MastraClient = class extends BaseResource {
|
|
2810
2797
|
observability;
|
|
@@ -2814,10 +2801,20 @@ var MastraClient = class extends BaseResource {
|
|
|
2814
2801
|
}
|
|
2815
2802
|
/**
|
|
2816
2803
|
* Retrieves all available agents
|
|
2804
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2817
2805
|
* @returns Promise containing map of agent IDs to agent details
|
|
2818
2806
|
*/
|
|
2819
|
-
getAgents() {
|
|
2820
|
-
|
|
2807
|
+
getAgents(runtimeContext) {
|
|
2808
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
2809
|
+
const searchParams = new URLSearchParams();
|
|
2810
|
+
if (runtimeContextParam) {
|
|
2811
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
2812
|
+
}
|
|
2813
|
+
const queryString = searchParams.toString();
|
|
2814
|
+
return this.request(`/api/agents${queryString ? `?${queryString}` : ""}`);
|
|
2815
|
+
}
|
|
2816
|
+
getAgentsModelProviders() {
|
|
2817
|
+
return this.request(`/api/agents/providers`);
|
|
2821
2818
|
}
|
|
2822
2819
|
/**
|
|
2823
2820
|
* Gets an agent instance by ID
|
|
@@ -2835,6 +2832,14 @@ var MastraClient = class extends BaseResource {
|
|
|
2835
2832
|
getMemoryThreads(params) {
|
|
2836
2833
|
return this.request(`/api/memory/threads?resourceid=${params.resourceId}&agentId=${params.agentId}`);
|
|
2837
2834
|
}
|
|
2835
|
+
/**
|
|
2836
|
+
* Retrieves memory config for a resource
|
|
2837
|
+
* @param params - Parameters containing the resource ID
|
|
2838
|
+
* @returns Promise containing array of memory threads
|
|
2839
|
+
*/
|
|
2840
|
+
getMemoryConfig(params) {
|
|
2841
|
+
return this.request(`/api/memory/config?agentId=${params.agentId}`);
|
|
2842
|
+
}
|
|
2838
2843
|
/**
|
|
2839
2844
|
* Creates a new memory thread
|
|
2840
2845
|
* @param params - Parameters for creating the memory thread
|
|
@@ -2851,6 +2856,24 @@ var MastraClient = class extends BaseResource {
|
|
|
2851
2856
|
getMemoryThread(threadId, agentId) {
|
|
2852
2857
|
return new MemoryThread(this.options, threadId, agentId);
|
|
2853
2858
|
}
|
|
2859
|
+
getThreadMessages(threadId, opts = {}) {
|
|
2860
|
+
let url = "";
|
|
2861
|
+
if (opts.agentId) {
|
|
2862
|
+
url = `/api/memory/threads/${threadId}/messages?agentId=${opts.agentId}`;
|
|
2863
|
+
} else if (opts.networkId) {
|
|
2864
|
+
url = `/api/memory/network/threads/${threadId}/messages?networkId=${opts.networkId}`;
|
|
2865
|
+
}
|
|
2866
|
+
return this.request(url);
|
|
2867
|
+
}
|
|
2868
|
+
deleteThread(threadId, opts = {}) {
|
|
2869
|
+
let url = "";
|
|
2870
|
+
if (opts.agentId) {
|
|
2871
|
+
url = `/api/memory/threads/${threadId}?agentId=${opts.agentId}`;
|
|
2872
|
+
} else if (opts.networkId) {
|
|
2873
|
+
url = `/api/memory/network/threads/${threadId}?networkId=${opts.networkId}`;
|
|
2874
|
+
}
|
|
2875
|
+
return this.request(url, { method: "DELETE" });
|
|
2876
|
+
}
|
|
2854
2877
|
/**
|
|
2855
2878
|
* Saves messages to memory
|
|
2856
2879
|
* @param params - Parameters containing messages to save
|
|
@@ -2913,10 +2936,17 @@ var MastraClient = class extends BaseResource {
|
|
|
2913
2936
|
}
|
|
2914
2937
|
/**
|
|
2915
2938
|
* Retrieves all available tools
|
|
2939
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2916
2940
|
* @returns Promise containing map of tool IDs to tool details
|
|
2917
2941
|
*/
|
|
2918
|
-
getTools() {
|
|
2919
|
-
|
|
2942
|
+
getTools(runtimeContext) {
|
|
2943
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
2944
|
+
const searchParams = new URLSearchParams();
|
|
2945
|
+
if (runtimeContextParam) {
|
|
2946
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
2947
|
+
}
|
|
2948
|
+
const queryString = searchParams.toString();
|
|
2949
|
+
return this.request(`/api/tools${queryString ? `?${queryString}` : ""}`);
|
|
2920
2950
|
}
|
|
2921
2951
|
/**
|
|
2922
2952
|
* Gets a tool instance by ID
|
|
@@ -2926,27 +2956,19 @@ var MastraClient = class extends BaseResource {
|
|
|
2926
2956
|
getTool(toolId) {
|
|
2927
2957
|
return new Tool(this.options, toolId);
|
|
2928
2958
|
}
|
|
2929
|
-
/**
|
|
2930
|
-
* Retrieves all available legacy workflows
|
|
2931
|
-
* @returns Promise containing map of legacy workflow IDs to legacy workflow details
|
|
2932
|
-
*/
|
|
2933
|
-
getLegacyWorkflows() {
|
|
2934
|
-
return this.request("/api/workflows/legacy");
|
|
2935
|
-
}
|
|
2936
|
-
/**
|
|
2937
|
-
* Gets a legacy workflow instance by ID
|
|
2938
|
-
* @param workflowId - ID of the legacy workflow to retrieve
|
|
2939
|
-
* @returns Legacy Workflow instance
|
|
2940
|
-
*/
|
|
2941
|
-
getLegacyWorkflow(workflowId) {
|
|
2942
|
-
return new LegacyWorkflow(this.options, workflowId);
|
|
2943
|
-
}
|
|
2944
2959
|
/**
|
|
2945
2960
|
* Retrieves all available workflows
|
|
2961
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2946
2962
|
* @returns Promise containing map of workflow IDs to workflow details
|
|
2947
2963
|
*/
|
|
2948
|
-
getWorkflows() {
|
|
2949
|
-
|
|
2964
|
+
getWorkflows(runtimeContext) {
|
|
2965
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
2966
|
+
const searchParams = new URLSearchParams();
|
|
2967
|
+
if (runtimeContextParam) {
|
|
2968
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
2969
|
+
}
|
|
2970
|
+
const queryString = searchParams.toString();
|
|
2971
|
+
return this.request(`/api/workflows${queryString ? `?${queryString}` : ""}`);
|
|
2950
2972
|
}
|
|
2951
2973
|
/**
|
|
2952
2974
|
* Gets a workflow instance by ID
|
|
@@ -3072,78 +3094,6 @@ var MastraClient = class extends BaseResource {
|
|
|
3072
3094
|
getLogTransports() {
|
|
3073
3095
|
return this.request("/api/logs/transports");
|
|
3074
3096
|
}
|
|
3075
|
-
/**
|
|
3076
|
-
* List of all traces (paged)
|
|
3077
|
-
* @param params - Parameters for filtering traces
|
|
3078
|
-
* @returns Promise containing telemetry data
|
|
3079
|
-
*/
|
|
3080
|
-
getTelemetry(params) {
|
|
3081
|
-
const { name, scope, page, perPage, attribute, fromDate, toDate } = params || {};
|
|
3082
|
-
const _attribute = attribute ? Object.entries(attribute).map(([key, value]) => `${key}:${value}`) : [];
|
|
3083
|
-
const searchParams = new URLSearchParams();
|
|
3084
|
-
if (name) {
|
|
3085
|
-
searchParams.set("name", name);
|
|
3086
|
-
}
|
|
3087
|
-
if (scope) {
|
|
3088
|
-
searchParams.set("scope", scope);
|
|
3089
|
-
}
|
|
3090
|
-
if (page) {
|
|
3091
|
-
searchParams.set("page", String(page));
|
|
3092
|
-
}
|
|
3093
|
-
if (perPage) {
|
|
3094
|
-
searchParams.set("perPage", String(perPage));
|
|
3095
|
-
}
|
|
3096
|
-
if (_attribute) {
|
|
3097
|
-
if (Array.isArray(_attribute)) {
|
|
3098
|
-
for (const attr of _attribute) {
|
|
3099
|
-
searchParams.append("attribute", attr);
|
|
3100
|
-
}
|
|
3101
|
-
} else {
|
|
3102
|
-
searchParams.set("attribute", _attribute);
|
|
3103
|
-
}
|
|
3104
|
-
}
|
|
3105
|
-
if (fromDate) {
|
|
3106
|
-
searchParams.set("fromDate", fromDate.toISOString());
|
|
3107
|
-
}
|
|
3108
|
-
if (toDate) {
|
|
3109
|
-
searchParams.set("toDate", toDate.toISOString());
|
|
3110
|
-
}
|
|
3111
|
-
if (searchParams.size) {
|
|
3112
|
-
return this.request(`/api/telemetry?${searchParams}`);
|
|
3113
|
-
} else {
|
|
3114
|
-
return this.request(`/api/telemetry`);
|
|
3115
|
-
}
|
|
3116
|
-
}
|
|
3117
|
-
/**
|
|
3118
|
-
* Retrieves all available networks
|
|
3119
|
-
* @returns Promise containing map of network IDs to network details
|
|
3120
|
-
*/
|
|
3121
|
-
getNetworks() {
|
|
3122
|
-
return this.request("/api/networks");
|
|
3123
|
-
}
|
|
3124
|
-
/**
|
|
3125
|
-
* Retrieves all available vNext networks
|
|
3126
|
-
* @returns Promise containing map of vNext network IDs to vNext network details
|
|
3127
|
-
*/
|
|
3128
|
-
getVNextNetworks() {
|
|
3129
|
-
return this.request("/api/networks/v-next");
|
|
3130
|
-
}
|
|
3131
|
-
/**
|
|
3132
|
-
* Gets a network instance by ID
|
|
3133
|
-
* @param networkId - ID of the network to retrieve
|
|
3134
|
-
* @returns Network instance
|
|
3135
|
-
*/
|
|
3136
|
-
getNetwork(networkId) {
|
|
3137
|
-
return new Network(this.options, networkId);
|
|
3138
|
-
}
|
|
3139
|
-
/**
|
|
3140
|
-
* Gets a vNext network instance by ID
|
|
3141
|
-
* @param networkId - ID of the vNext network to retrieve
|
|
3142
|
-
* @returns vNext Network instance
|
|
3143
|
-
*/
|
|
3144
|
-
getVNextNetwork(networkId) {
|
|
3145
|
-
return new VNextNetwork(this.options, networkId);
|
|
3146
|
-
}
|
|
3147
3097
|
/**
|
|
3148
3098
|
* Retrieves a list of available MCP servers.
|
|
3149
3099
|
* @param params - Optional parameters for pagination (limit, offset).
|
|
@@ -3214,6 +3164,26 @@ var MastraClient = class extends BaseResource {
|
|
|
3214
3164
|
}) {
|
|
3215
3165
|
return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}`);
|
|
3216
3166
|
}
|
|
3167
|
+
searchMemory({
|
|
3168
|
+
agentId,
|
|
3169
|
+
resourceId,
|
|
3170
|
+
threadId,
|
|
3171
|
+
searchQuery,
|
|
3172
|
+
memoryConfig
|
|
3173
|
+
}) {
|
|
3174
|
+
const params = new URLSearchParams({
|
|
3175
|
+
searchQuery,
|
|
3176
|
+
resourceId,
|
|
3177
|
+
agentId
|
|
3178
|
+
});
|
|
3179
|
+
if (threadId) {
|
|
3180
|
+
params.append("threadId", threadId);
|
|
3181
|
+
}
|
|
3182
|
+
if (memoryConfig) {
|
|
3183
|
+
params.append("memoryConfig", JSON.stringify(memoryConfig));
|
|
3184
|
+
}
|
|
3185
|
+
return this.request(`/api/memory/search?${params}`);
|
|
3186
|
+
}
|
|
3217
3187
|
/**
|
|
3218
3188
|
* Updates the working memory for a specific thread (optionally resource-scoped).
|
|
3219
3189
|
* @param agentId - ID of the agent.
|
|
@@ -3248,7 +3218,7 @@ var MastraClient = class extends BaseResource {
|
|
|
3248
3218
|
* @returns Promise containing the scorer
|
|
3249
3219
|
*/
|
|
3250
3220
|
getScorer(scorerId) {
|
|
3251
|
-
return this.request(`/api/scores/scorers/${scorerId}`);
|
|
3221
|
+
return this.request(`/api/scores/scorers/${encodeURIComponent(scorerId)}`);
|
|
3252
3222
|
}
|
|
3253
3223
|
getScoresByScorerId(params) {
|
|
3254
3224
|
const { page, perPage, scorerId, entityId, entityType } = params;
|
|
@@ -3266,7 +3236,7 @@ var MastraClient = class extends BaseResource {
|
|
|
3266
3236
|
searchParams.set("perPage", String(perPage));
|
|
3267
3237
|
}
|
|
3268
3238
|
const queryString = searchParams.toString();
|
|
3269
|
-
return this.request(`/api/scores/scorer/${scorerId}${queryString ? `?${queryString}` : ""}`);
|
|
3239
|
+
return this.request(`/api/scores/scorer/${encodeURIComponent(scorerId)}${queryString ? `?${queryString}` : ""}`);
|
|
3270
3240
|
}
|
|
3271
3241
|
/**
|
|
3272
3242
|
* Retrieves scores by run ID
|
|
@@ -3283,7 +3253,7 @@ var MastraClient = class extends BaseResource {
|
|
|
3283
3253
|
searchParams.set("perPage", String(perPage));
|
|
3284
3254
|
}
|
|
3285
3255
|
const queryString = searchParams.toString();
|
|
3286
|
-
return this.request(`/api/scores/run/${runId}${queryString ? `?${queryString}` : ""}`);
|
|
3256
|
+
return this.request(`/api/scores/run/${encodeURIComponent(runId)}${queryString ? `?${queryString}` : ""}`);
|
|
3287
3257
|
}
|
|
3288
3258
|
/**
|
|
3289
3259
|
* Retrieves scores by entity ID and type
|
|
@@ -3300,7 +3270,9 @@ var MastraClient = class extends BaseResource {
|
|
|
3300
3270
|
searchParams.set("perPage", String(perPage));
|
|
3301
3271
|
}
|
|
3302
3272
|
const queryString = searchParams.toString();
|
|
3303
|
-
return this.request(
|
|
3273
|
+
return this.request(
|
|
3274
|
+
`/api/scores/entity/${encodeURIComponent(entityType)}/${encodeURIComponent(entityId)}${queryString ? `?${queryString}` : ""}`
|
|
3275
|
+
);
|
|
3304
3276
|
}
|
|
3305
3277
|
/**
|
|
3306
3278
|
* Saves a score
|
|
@@ -3326,8 +3298,35 @@ var MastraClient = class extends BaseResource {
|
|
|
3326
3298
|
getAITraces(params) {
|
|
3327
3299
|
return this.observability.getTraces(params);
|
|
3328
3300
|
}
|
|
3301
|
+
getScoresBySpan(params) {
|
|
3302
|
+
return this.observability.getScoresBySpan(params);
|
|
3303
|
+
}
|
|
3304
|
+
score(params) {
|
|
3305
|
+
return this.observability.score(params);
|
|
3306
|
+
}
|
|
3329
3307
|
};
|
|
3330
3308
|
|
|
3309
|
+
// src/tools.ts
|
|
3310
|
+
var ClientTool = class {
|
|
3311
|
+
id;
|
|
3312
|
+
description;
|
|
3313
|
+
inputSchema;
|
|
3314
|
+
outputSchema;
|
|
3315
|
+
execute;
|
|
3316
|
+
constructor(opts) {
|
|
3317
|
+
this.id = opts.id;
|
|
3318
|
+
this.description = opts.description;
|
|
3319
|
+
this.inputSchema = opts.inputSchema;
|
|
3320
|
+
this.outputSchema = opts.outputSchema;
|
|
3321
|
+
this.execute = opts.execute;
|
|
3322
|
+
}
|
|
3323
|
+
};
|
|
3324
|
+
function createTool(opts) {
|
|
3325
|
+
return new ClientTool(opts);
|
|
3326
|
+
}
|
|
3327
|
+
|
|
3328
|
+
exports.ClientTool = ClientTool;
|
|
3331
3329
|
exports.MastraClient = MastraClient;
|
|
3330
|
+
exports.createTool = createTool;
|
|
3332
3331
|
//# sourceMappingURL=index.cjs.map
|
|
3333
3332
|
//# sourceMappingURL=index.cjs.map
|