@mastra/client-js 0.0.0-message-file-url-handling-fix-20250904234524 → 0.0.0-model-router-unknown-provider-20251017212006
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 +541 -3
- package/README.md +6 -10
- package/dist/client.d.ts +37 -39
- package/dist/client.d.ts.map +1 -1
- package/dist/index.cjs +671 -588
- 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 +670 -589
- 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 +71 -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 +128 -13
- package/dist/resources/workflow.d.ts.map +1 -1
- package/dist/tools.d.ts +22 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/types.d.ts +65 -47
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/process-mastra-stream.d.ts +5 -1
- package/dist/utils/process-mastra-stream.d.ts.map +1 -1
- package/package.json +5 -6
- package/dist/resources/legacy-workflow.d.ts +0 -87
- package/dist/resources/legacy-workflow.d.ts.map +0 -1
- package/dist/resources/network.d.ts +0 -30
- package/dist/resources/network.d.ts.map +0 -1
- package/dist/resources/vNextNetwork.d.ts +0 -42
- package/dist/resources/vNextNetwork.d.ts.map +0 -1
package/dist/index.js
CHANGED
|
@@ -15,6 +15,20 @@ function parseClientRuntimeContext(runtimeContext) {
|
|
|
15
15
|
}
|
|
16
16
|
return void 0;
|
|
17
17
|
}
|
|
18
|
+
function base64RuntimeContext(runtimeContext) {
|
|
19
|
+
if (runtimeContext) {
|
|
20
|
+
return btoa(JSON.stringify(runtimeContext));
|
|
21
|
+
}
|
|
22
|
+
return void 0;
|
|
23
|
+
}
|
|
24
|
+
function runtimeContextQueryString(runtimeContext) {
|
|
25
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
26
|
+
if (!runtimeContextParam) return "";
|
|
27
|
+
const searchParams = new URLSearchParams();
|
|
28
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
29
|
+
const queryString = searchParams.toString();
|
|
30
|
+
return queryString ? `?${queryString}` : "";
|
|
31
|
+
}
|
|
18
32
|
function isZodType(value) {
|
|
19
33
|
return typeof value === "object" && value !== null && "_def" in value && "parse" in value && typeof value.parse === "function" && "safeParse" in value && typeof value.safeParse === "function";
|
|
20
34
|
}
|
|
@@ -26,7 +40,7 @@ function zodToJsonSchema(zodSchema) {
|
|
|
26
40
|
const fn = "toJSONSchema";
|
|
27
41
|
return z[fn].call(z, zodSchema);
|
|
28
42
|
}
|
|
29
|
-
return originalZodToJsonSchema(zodSchema, { $refStrategy: "
|
|
43
|
+
return originalZodToJsonSchema(zodSchema, { $refStrategy: "relative" });
|
|
30
44
|
}
|
|
31
45
|
|
|
32
46
|
// src/utils/process-client-tools.ts
|
|
@@ -59,7 +73,7 @@ function processClientTools(clientTools) {
|
|
|
59
73
|
}
|
|
60
74
|
|
|
61
75
|
// src/utils/process-mastra-stream.ts
|
|
62
|
-
async function
|
|
76
|
+
async function sharedProcessMastraStream({
|
|
63
77
|
stream,
|
|
64
78
|
onChunk
|
|
65
79
|
}) {
|
|
@@ -77,7 +91,7 @@ async function processMastraStream({
|
|
|
77
91
|
if (line.startsWith("data: ")) {
|
|
78
92
|
const data = line.slice(6);
|
|
79
93
|
if (data === "[DONE]") {
|
|
80
|
-
console.
|
|
94
|
+
console.info("\u{1F3C1} Stream finished");
|
|
81
95
|
return;
|
|
82
96
|
}
|
|
83
97
|
try {
|
|
@@ -93,6 +107,24 @@ async function processMastraStream({
|
|
|
93
107
|
reader.releaseLock();
|
|
94
108
|
}
|
|
95
109
|
}
|
|
110
|
+
async function processMastraNetworkStream({
|
|
111
|
+
stream,
|
|
112
|
+
onChunk
|
|
113
|
+
}) {
|
|
114
|
+
return sharedProcessMastraStream({
|
|
115
|
+
stream,
|
|
116
|
+
onChunk
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
async function processMastraStream({
|
|
120
|
+
stream,
|
|
121
|
+
onChunk
|
|
122
|
+
}) {
|
|
123
|
+
return sharedProcessMastraStream({
|
|
124
|
+
stream,
|
|
125
|
+
onChunk
|
|
126
|
+
});
|
|
127
|
+
}
|
|
96
128
|
|
|
97
129
|
// src/resources/base.ts
|
|
98
130
|
var BaseResource = class {
|
|
@@ -181,7 +213,9 @@ async function executeToolCallAndRespond({
|
|
|
181
213
|
resourceId,
|
|
182
214
|
threadId,
|
|
183
215
|
runtimeContext,
|
|
184
|
-
tracingContext: { currentSpan: void 0 }
|
|
216
|
+
tracingContext: { currentSpan: void 0 },
|
|
217
|
+
suspend: async () => {
|
|
218
|
+
}
|
|
185
219
|
},
|
|
186
220
|
{
|
|
187
221
|
messages: response.messages,
|
|
@@ -189,11 +223,7 @@ async function executeToolCallAndRespond({
|
|
|
189
223
|
}
|
|
190
224
|
);
|
|
191
225
|
const updatedMessages = [
|
|
192
|
-
|
|
193
|
-
role: "user",
|
|
194
|
-
content: params.messages
|
|
195
|
-
},
|
|
196
|
-
...response.response.messages,
|
|
226
|
+
...response.response.messages || [],
|
|
197
227
|
{
|
|
198
228
|
role: "tool",
|
|
199
229
|
content: [
|
|
@@ -255,17 +285,21 @@ var AgentVoice = class extends BaseResource {
|
|
|
255
285
|
}
|
|
256
286
|
/**
|
|
257
287
|
* Get available speakers for the agent's voice provider
|
|
288
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
289
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
258
290
|
* @returns Promise containing list of available speakers
|
|
259
291
|
*/
|
|
260
|
-
getSpeakers() {
|
|
261
|
-
return this.request(`/api/agents/${this.agentId}/voice/speakers`);
|
|
292
|
+
getSpeakers(runtimeContext) {
|
|
293
|
+
return this.request(`/api/agents/${this.agentId}/voice/speakers${runtimeContextQueryString(runtimeContext)}`);
|
|
262
294
|
}
|
|
263
295
|
/**
|
|
264
296
|
* Get the listener configuration for the agent's voice provider
|
|
297
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
298
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
265
299
|
* @returns Promise containing a check if the agent has listening capabilities
|
|
266
300
|
*/
|
|
267
|
-
getListener() {
|
|
268
|
-
return this.request(`/api/agents/${this.agentId}/voice/listener`);
|
|
301
|
+
getListener(runtimeContext) {
|
|
302
|
+
return this.request(`/api/agents/${this.agentId}/voice/listener${runtimeContextQueryString(runtimeContext)}`);
|
|
269
303
|
}
|
|
270
304
|
};
|
|
271
305
|
var Agent = class extends BaseResource {
|
|
@@ -277,16 +311,11 @@ var Agent = class extends BaseResource {
|
|
|
277
311
|
voice;
|
|
278
312
|
/**
|
|
279
313
|
* Retrieves details about the agent
|
|
314
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
280
315
|
* @returns Promise containing agent details including model and instructions
|
|
281
316
|
*/
|
|
282
|
-
details() {
|
|
283
|
-
return this.request(`/api/agents/${this.agentId}`);
|
|
284
|
-
}
|
|
285
|
-
async generate(params) {
|
|
286
|
-
console.warn(
|
|
287
|
-
"Deprecation NOTICE:Generate method will switch to use generateVNext implementation September 16th. Please use generateLegacy if you don't want to upgrade just yet."
|
|
288
|
-
);
|
|
289
|
-
return this.generateLegacy(params);
|
|
317
|
+
details(runtimeContext) {
|
|
318
|
+
return this.request(`/api/agents/${this.agentId}${runtimeContextQueryString(runtimeContext)}`);
|
|
290
319
|
}
|
|
291
320
|
async generateLegacy(params) {
|
|
292
321
|
const processedParams = {
|
|
@@ -319,7 +348,9 @@ var Agent = class extends BaseResource {
|
|
|
319
348
|
resourceId,
|
|
320
349
|
threadId,
|
|
321
350
|
runtimeContext,
|
|
322
|
-
tracingContext: { currentSpan: void 0 }
|
|
351
|
+
tracingContext: { currentSpan: void 0 },
|
|
352
|
+
suspend: async () => {
|
|
353
|
+
}
|
|
323
354
|
},
|
|
324
355
|
{
|
|
325
356
|
messages: response.messages,
|
|
@@ -327,10 +358,6 @@ var Agent = class extends BaseResource {
|
|
|
327
358
|
}
|
|
328
359
|
);
|
|
329
360
|
const updatedMessages = [
|
|
330
|
-
{
|
|
331
|
-
role: "user",
|
|
332
|
-
content: params.messages
|
|
333
|
-
},
|
|
334
361
|
...response.response.messages,
|
|
335
362
|
{
|
|
336
363
|
role: "tool",
|
|
@@ -353,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;
|
|
@@ -643,17 +683,6 @@ var Agent = class extends BaseResource {
|
|
|
643
683
|
});
|
|
644
684
|
onFinish?.({ message, finishReason, usage });
|
|
645
685
|
}
|
|
646
|
-
/**
|
|
647
|
-
* Streams a response from the agent
|
|
648
|
-
* @param params - Stream parameters including prompt
|
|
649
|
-
* @returns Promise containing the enhanced Response object with processDataStream method
|
|
650
|
-
*/
|
|
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
686
|
/**
|
|
658
687
|
* Streams a response from the agent
|
|
659
688
|
* @param params - Stream parameters including prompt
|
|
@@ -668,7 +697,7 @@ var Agent = class extends BaseResource {
|
|
|
668
697
|
clientTools: processClientTools(params.clientTools)
|
|
669
698
|
};
|
|
670
699
|
const { readable, writable } = new TransformStream();
|
|
671
|
-
const response = await this.
|
|
700
|
+
const response = await this.processStreamResponseLegacy(processedParams, writable);
|
|
672
701
|
const streamResponse = new Response(readable, {
|
|
673
702
|
status: response.status,
|
|
674
703
|
statusText: response.statusText,
|
|
@@ -755,6 +784,14 @@ var Agent = class extends BaseResource {
|
|
|
755
784
|
// but this is completely wrong and this fn is probably broken. Remove ":any" and you'll see a bunch of type errors
|
|
756
785
|
onChunk: async (chunk) => {
|
|
757
786
|
switch (chunk.type) {
|
|
787
|
+
case "tripwire": {
|
|
788
|
+
message.parts.push({
|
|
789
|
+
type: "text",
|
|
790
|
+
text: chunk.payload.tripwireReason
|
|
791
|
+
});
|
|
792
|
+
execUpdate();
|
|
793
|
+
break;
|
|
794
|
+
}
|
|
758
795
|
case "step-start": {
|
|
759
796
|
if (!replaceLastMessage) {
|
|
760
797
|
message.id = chunk.payload.messageId;
|
|
@@ -863,7 +900,7 @@ var Agent = class extends BaseResource {
|
|
|
863
900
|
step,
|
|
864
901
|
toolCallId: chunk.payload.toolCallId,
|
|
865
902
|
toolName: chunk.payload.toolName,
|
|
866
|
-
args:
|
|
903
|
+
args: chunk.payload.args
|
|
867
904
|
};
|
|
868
905
|
message.toolInvocations.push(invocation);
|
|
869
906
|
updateToolInvocationPart(chunk.payload.toolCallId, invocation);
|
|
@@ -917,14 +954,14 @@ var Agent = class extends BaseResource {
|
|
|
917
954
|
}
|
|
918
955
|
case "step-finish": {
|
|
919
956
|
step += 1;
|
|
920
|
-
currentTextPart = chunk.payload.isContinued ? currentTextPart : void 0;
|
|
957
|
+
currentTextPart = chunk.payload.stepResult.isContinued ? currentTextPart : void 0;
|
|
921
958
|
currentReasoningPart = void 0;
|
|
922
959
|
currentReasoningTextDetail = void 0;
|
|
923
960
|
execUpdate();
|
|
924
961
|
break;
|
|
925
962
|
}
|
|
926
963
|
case "finish": {
|
|
927
|
-
finishReason = chunk.payload.
|
|
964
|
+
finishReason = chunk.payload.stepResult.reason;
|
|
928
965
|
if (chunk.payload.usage != null) {
|
|
929
966
|
usage = chunk.payload.usage;
|
|
930
967
|
}
|
|
@@ -935,8 +972,8 @@ var Agent = class extends BaseResource {
|
|
|
935
972
|
});
|
|
936
973
|
onFinish?.({ message, finishReason, usage });
|
|
937
974
|
}
|
|
938
|
-
async
|
|
939
|
-
const response = await this.request(`/api/agents/${this.agentId}/stream
|
|
975
|
+
async processStreamResponse(processedParams, writable) {
|
|
976
|
+
const response = await this.request(`/api/agents/${this.agentId}/stream`, {
|
|
940
977
|
method: "POST",
|
|
941
978
|
body: processedParams,
|
|
942
979
|
stream: true
|
|
@@ -948,9 +985,27 @@ var Agent = class extends BaseResource {
|
|
|
948
985
|
let toolCalls = [];
|
|
949
986
|
let messages = [];
|
|
950
987
|
const [streamForWritable, streamForProcessing] = response.body.tee();
|
|
951
|
-
streamForWritable.pipeTo(
|
|
952
|
-
|
|
953
|
-
|
|
988
|
+
streamForWritable.pipeTo(
|
|
989
|
+
new WritableStream({
|
|
990
|
+
async write(chunk) {
|
|
991
|
+
let writer;
|
|
992
|
+
try {
|
|
993
|
+
writer = writable.getWriter();
|
|
994
|
+
const text = new TextDecoder().decode(chunk);
|
|
995
|
+
const lines = text.split("\n\n");
|
|
996
|
+
const readableLines = lines.filter((line) => line !== "[DONE]").join("\n\n");
|
|
997
|
+
await writer.write(new TextEncoder().encode(readableLines));
|
|
998
|
+
} catch {
|
|
999
|
+
await writer?.write(chunk);
|
|
1000
|
+
} finally {
|
|
1001
|
+
writer?.releaseLock();
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
}),
|
|
1005
|
+
{
|
|
1006
|
+
preventClose: true
|
|
1007
|
+
}
|
|
1008
|
+
).catch((error) => {
|
|
954
1009
|
console.error("Error piping to writable stream:", error);
|
|
955
1010
|
});
|
|
956
1011
|
this.processChatResponse_vNext({
|
|
@@ -969,9 +1024,11 @@ var Agent = class extends BaseResource {
|
|
|
969
1024
|
if (toolCall) {
|
|
970
1025
|
toolCalls.push(toolCall);
|
|
971
1026
|
}
|
|
1027
|
+
let shouldExecuteClientTool = false;
|
|
972
1028
|
for (const toolCall2 of toolCalls) {
|
|
973
1029
|
const clientTool = processedParams.clientTools?.[toolCall2.toolName];
|
|
974
1030
|
if (clientTool && clientTool.execute) {
|
|
1031
|
+
shouldExecuteClientTool = true;
|
|
975
1032
|
const result = await clientTool.execute(
|
|
976
1033
|
{
|
|
977
1034
|
context: toolCall2?.args,
|
|
@@ -980,14 +1037,17 @@ var Agent = class extends BaseResource {
|
|
|
980
1037
|
threadId: processedParams.threadId,
|
|
981
1038
|
runtimeContext: processedParams.runtimeContext,
|
|
982
1039
|
// TODO: Pass proper tracing context when client-js supports tracing
|
|
983
|
-
tracingContext: { currentSpan: void 0 }
|
|
1040
|
+
tracingContext: { currentSpan: void 0 },
|
|
1041
|
+
suspend: async () => {
|
|
1042
|
+
}
|
|
984
1043
|
},
|
|
985
1044
|
{
|
|
986
1045
|
messages: response.messages,
|
|
987
1046
|
toolCallId: toolCall2?.toolCallId
|
|
988
1047
|
}
|
|
989
1048
|
);
|
|
990
|
-
const
|
|
1049
|
+
const lastMessageRaw = messages[messages.length - 1];
|
|
1050
|
+
const lastMessage = lastMessageRaw != null ? JSON.parse(JSON.stringify(lastMessageRaw)) : void 0;
|
|
991
1051
|
const toolInvocationPart = lastMessage?.parts?.find(
|
|
992
1052
|
(part) => part.type === "tool-invocation" && part.toolInvocation?.toolCallId === toolCall2.toolCallId
|
|
993
1053
|
);
|
|
@@ -1005,25 +1065,11 @@ var Agent = class extends BaseResource {
|
|
|
1005
1065
|
toolInvocation.state = "result";
|
|
1006
1066
|
toolInvocation.result = result;
|
|
1007
1067
|
}
|
|
1008
|
-
const
|
|
1009
|
-
|
|
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];
|
|
1023
|
-
this.processStreamResponse_vNext(
|
|
1068
|
+
const updatedMessages = lastMessage != null ? [...messages.filter((m) => m.id !== lastMessage.id), lastMessage] : [...messages];
|
|
1069
|
+
this.processStreamResponse(
|
|
1024
1070
|
{
|
|
1025
1071
|
...processedParams,
|
|
1026
|
-
messages:
|
|
1072
|
+
messages: updatedMessages
|
|
1027
1073
|
},
|
|
1028
1074
|
writable
|
|
1029
1075
|
).catch((error) => {
|
|
@@ -1031,6 +1077,11 @@ var Agent = class extends BaseResource {
|
|
|
1031
1077
|
});
|
|
1032
1078
|
}
|
|
1033
1079
|
}
|
|
1080
|
+
if (!shouldExecuteClientTool) {
|
|
1081
|
+
setTimeout(() => {
|
|
1082
|
+
writable.close();
|
|
1083
|
+
}, 0);
|
|
1084
|
+
}
|
|
1034
1085
|
} else {
|
|
1035
1086
|
setTimeout(() => {
|
|
1036
1087
|
writable.close();
|
|
@@ -1046,15 +1097,52 @@ var Agent = class extends BaseResource {
|
|
|
1046
1097
|
}
|
|
1047
1098
|
return response;
|
|
1048
1099
|
}
|
|
1049
|
-
async
|
|
1100
|
+
async network(params) {
|
|
1101
|
+
const response = await this.request(`/api/agents/${this.agentId}/network`, {
|
|
1102
|
+
method: "POST",
|
|
1103
|
+
body: params,
|
|
1104
|
+
stream: true
|
|
1105
|
+
});
|
|
1106
|
+
if (!response.body) {
|
|
1107
|
+
throw new Error("No response body");
|
|
1108
|
+
}
|
|
1109
|
+
const streamResponse = new Response(response.body, {
|
|
1110
|
+
status: response.status,
|
|
1111
|
+
statusText: response.statusText,
|
|
1112
|
+
headers: response.headers
|
|
1113
|
+
});
|
|
1114
|
+
streamResponse.processDataStream = async ({
|
|
1115
|
+
onChunk
|
|
1116
|
+
}) => {
|
|
1117
|
+
await processMastraNetworkStream({
|
|
1118
|
+
stream: streamResponse.body,
|
|
1119
|
+
onChunk
|
|
1120
|
+
});
|
|
1121
|
+
};
|
|
1122
|
+
return streamResponse;
|
|
1123
|
+
}
|
|
1124
|
+
async stream(messagesOrParams, options) {
|
|
1125
|
+
let params;
|
|
1126
|
+
if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
|
|
1127
|
+
params = messagesOrParams;
|
|
1128
|
+
} else {
|
|
1129
|
+
params = {
|
|
1130
|
+
messages: messagesOrParams,
|
|
1131
|
+
...options
|
|
1132
|
+
};
|
|
1133
|
+
}
|
|
1050
1134
|
const processedParams = {
|
|
1051
1135
|
...params,
|
|
1052
1136
|
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
1053
1137
|
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
1054
|
-
clientTools: processClientTools(params.clientTools)
|
|
1138
|
+
clientTools: processClientTools(params.clientTools),
|
|
1139
|
+
structuredOutput: params.structuredOutput ? {
|
|
1140
|
+
...params.structuredOutput,
|
|
1141
|
+
schema: zodToJsonSchema(params.structuredOutput.schema)
|
|
1142
|
+
} : void 0
|
|
1055
1143
|
};
|
|
1056
1144
|
const { readable, writable } = new TransformStream();
|
|
1057
|
-
const response = await this.
|
|
1145
|
+
const response = await this.processStreamResponse(processedParams, writable);
|
|
1058
1146
|
const streamResponse = new Response(readable, {
|
|
1059
1147
|
status: response.status,
|
|
1060
1148
|
statusText: response.statusText,
|
|
@@ -1073,7 +1161,7 @@ var Agent = class extends BaseResource {
|
|
|
1073
1161
|
/**
|
|
1074
1162
|
* Processes the stream response and handles tool calls
|
|
1075
1163
|
*/
|
|
1076
|
-
async
|
|
1164
|
+
async processStreamResponseLegacy(processedParams, writable) {
|
|
1077
1165
|
const response = await this.request(`/api/agents/${this.agentId}/stream-legacy`, {
|
|
1078
1166
|
method: "POST",
|
|
1079
1167
|
body: processedParams,
|
|
@@ -1118,7 +1206,9 @@ var Agent = class extends BaseResource {
|
|
|
1118
1206
|
threadId: processedParams.threadId,
|
|
1119
1207
|
runtimeContext: processedParams.runtimeContext,
|
|
1120
1208
|
// TODO: Pass proper tracing context when client-js supports tracing
|
|
1121
|
-
tracingContext: { currentSpan: void 0 }
|
|
1209
|
+
tracingContext: { currentSpan: void 0 },
|
|
1210
|
+
suspend: async () => {
|
|
1211
|
+
}
|
|
1122
1212
|
},
|
|
1123
1213
|
{
|
|
1124
1214
|
messages: response.messages,
|
|
@@ -1156,12 +1246,10 @@ var Agent = class extends BaseResource {
|
|
|
1156
1246
|
} finally {
|
|
1157
1247
|
writer.releaseLock();
|
|
1158
1248
|
}
|
|
1159
|
-
|
|
1160
|
-
const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
|
|
1161
|
-
this.processStreamResponse(
|
|
1249
|
+
this.processStreamResponseLegacy(
|
|
1162
1250
|
{
|
|
1163
1251
|
...processedParams,
|
|
1164
|
-
messages: [...
|
|
1252
|
+
messages: [...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
|
|
1165
1253
|
},
|
|
1166
1254
|
writable
|
|
1167
1255
|
).catch((error) => {
|
|
@@ -1187,10 +1275,11 @@ var Agent = class extends BaseResource {
|
|
|
1187
1275
|
/**
|
|
1188
1276
|
* Gets details about a specific tool available to the agent
|
|
1189
1277
|
* @param toolId - ID of the tool to retrieve
|
|
1278
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1190
1279
|
* @returns Promise containing tool details
|
|
1191
1280
|
*/
|
|
1192
|
-
getTool(toolId) {
|
|
1193
|
-
return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
|
|
1281
|
+
getTool(toolId, runtimeContext) {
|
|
1282
|
+
return this.request(`/api/agents/${this.agentId}/tools/${toolId}${runtimeContextQueryString(runtimeContext)}`);
|
|
1194
1283
|
}
|
|
1195
1284
|
/**
|
|
1196
1285
|
* Executes a tool for the agent
|
|
@@ -1201,7 +1290,7 @@ var Agent = class extends BaseResource {
|
|
|
1201
1290
|
executeTool(toolId, params) {
|
|
1202
1291
|
const body = {
|
|
1203
1292
|
data: params.data,
|
|
1204
|
-
runtimeContext:
|
|
1293
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1205
1294
|
};
|
|
1206
1295
|
return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
|
|
1207
1296
|
method: "POST",
|
|
@@ -1210,17 +1299,19 @@ var Agent = class extends BaseResource {
|
|
|
1210
1299
|
}
|
|
1211
1300
|
/**
|
|
1212
1301
|
* Retrieves evaluation results for the agent
|
|
1302
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1213
1303
|
* @returns Promise containing agent evaluations
|
|
1214
1304
|
*/
|
|
1215
|
-
evals() {
|
|
1216
|
-
return this.request(`/api/agents/${this.agentId}/evals/ci`);
|
|
1305
|
+
evals(runtimeContext) {
|
|
1306
|
+
return this.request(`/api/agents/${this.agentId}/evals/ci${runtimeContextQueryString(runtimeContext)}`);
|
|
1217
1307
|
}
|
|
1218
1308
|
/**
|
|
1219
1309
|
* Retrieves live evaluation results for the agent
|
|
1310
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1220
1311
|
* @returns Promise containing live agent evaluations
|
|
1221
1312
|
*/
|
|
1222
|
-
liveEvals() {
|
|
1223
|
-
return this.request(`/api/agents/${this.agentId}/evals/live`);
|
|
1313
|
+
liveEvals(runtimeContext) {
|
|
1314
|
+
return this.request(`/api/agents/${this.agentId}/evals/live${runtimeContextQueryString(runtimeContext)}`);
|
|
1224
1315
|
}
|
|
1225
1316
|
/**
|
|
1226
1317
|
* Updates the model for the agent
|
|
@@ -1233,61 +1324,33 @@ var Agent = class extends BaseResource {
|
|
|
1233
1324
|
body: params
|
|
1234
1325
|
});
|
|
1235
1326
|
}
|
|
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
1327
|
/**
|
|
1250
|
-
*
|
|
1251
|
-
* @param params -
|
|
1252
|
-
* @returns Promise containing the
|
|
1328
|
+
* Updates the model for the agent in the model list
|
|
1329
|
+
* @param params - Parameters for updating the model
|
|
1330
|
+
* @returns Promise containing the updated model
|
|
1253
1331
|
*/
|
|
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`, {
|
|
1332
|
+
updateModelInModelList({ modelConfigId, ...params }) {
|
|
1333
|
+
return this.request(`/api/agents/${this.agentId}/models/${modelConfigId}`, {
|
|
1261
1334
|
method: "POST",
|
|
1262
|
-
body:
|
|
1335
|
+
body: params
|
|
1263
1336
|
});
|
|
1264
1337
|
}
|
|
1265
1338
|
/**
|
|
1266
|
-
*
|
|
1267
|
-
* @param params -
|
|
1268
|
-
* @returns Promise containing the
|
|
1339
|
+
* Reorders the models for the agent
|
|
1340
|
+
* @param params - Parameters for reordering the model list
|
|
1341
|
+
* @returns Promise containing the updated model list
|
|
1269
1342
|
*/
|
|
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`, {
|
|
1343
|
+
reorderModelList(params) {
|
|
1344
|
+
return this.request(`/api/agents/${this.agentId}/models/reorder`, {
|
|
1277
1345
|
method: "POST",
|
|
1278
|
-
body:
|
|
1279
|
-
stream: true
|
|
1346
|
+
body: params
|
|
1280
1347
|
});
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
...options
|
|
1288
|
-
});
|
|
1289
|
-
};
|
|
1290
|
-
return response;
|
|
1348
|
+
}
|
|
1349
|
+
async generateVNext(_messagesOrParams, _options) {
|
|
1350
|
+
throw new Error("generateVNext has been renamed to generate. Please use generate instead.");
|
|
1351
|
+
}
|
|
1352
|
+
async streamVNext(_messagesOrParams, _options) {
|
|
1353
|
+
throw new Error("streamVNext has been renamed to stream. Please use stream instead.");
|
|
1291
1354
|
}
|
|
1292
1355
|
};
|
|
1293
1356
|
|
|
@@ -1378,10 +1441,13 @@ var Vector = class extends BaseResource {
|
|
|
1378
1441
|
/**
|
|
1379
1442
|
* Retrieves details about a specific vector index
|
|
1380
1443
|
* @param indexName - Name of the index to get details for
|
|
1444
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1381
1445
|
* @returns Promise containing vector index details
|
|
1382
1446
|
*/
|
|
1383
|
-
details(indexName) {
|
|
1384
|
-
return this.request(
|
|
1447
|
+
details(indexName, runtimeContext) {
|
|
1448
|
+
return this.request(
|
|
1449
|
+
`/api/vector/${this.vectorName}/indexes/${indexName}${runtimeContextQueryString(runtimeContext)}`
|
|
1450
|
+
);
|
|
1385
1451
|
}
|
|
1386
1452
|
/**
|
|
1387
1453
|
* Deletes a vector index
|
|
@@ -1395,10 +1461,11 @@ var Vector = class extends BaseResource {
|
|
|
1395
1461
|
}
|
|
1396
1462
|
/**
|
|
1397
1463
|
* Retrieves a list of all available indexes
|
|
1464
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1398
1465
|
* @returns Promise containing array of index names
|
|
1399
1466
|
*/
|
|
1400
|
-
getIndexes() {
|
|
1401
|
-
return this.request(`/api/vector/${this.vectorName}/indexes`);
|
|
1467
|
+
getIndexes(runtimeContext) {
|
|
1468
|
+
return this.request(`/api/vector/${this.vectorName}/indexes${runtimeContextQueryString(runtimeContext)}`);
|
|
1402
1469
|
}
|
|
1403
1470
|
/**
|
|
1404
1471
|
* Creates a new vector index
|
|
@@ -1435,123 +1502,50 @@ var Vector = class extends BaseResource {
|
|
|
1435
1502
|
}
|
|
1436
1503
|
};
|
|
1437
1504
|
|
|
1438
|
-
// src/resources/
|
|
1439
|
-
var
|
|
1440
|
-
|
|
1441
|
-
constructor(options, workflowId) {
|
|
1505
|
+
// src/resources/tool.ts
|
|
1506
|
+
var Tool = class extends BaseResource {
|
|
1507
|
+
constructor(options, toolId) {
|
|
1442
1508
|
super(options);
|
|
1443
|
-
this.
|
|
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
|
-
});
|
|
1509
|
+
this.toolId = toolId;
|
|
1503
1510
|
}
|
|
1504
1511
|
/**
|
|
1505
|
-
*
|
|
1506
|
-
* @param
|
|
1507
|
-
* @
|
|
1508
|
-
* @param context - Context to resume the legacy workflow with
|
|
1509
|
-
* @returns Promise containing the legacy workflow resume results
|
|
1512
|
+
* Retrieves details about the tool
|
|
1513
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1514
|
+
* @returns Promise containing tool details including description and schemas
|
|
1510
1515
|
*/
|
|
1511
|
-
|
|
1512
|
-
|
|
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
|
-
});
|
|
1516
|
+
details(runtimeContext) {
|
|
1517
|
+
return this.request(`/api/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
|
|
1523
1518
|
}
|
|
1524
1519
|
/**
|
|
1525
|
-
*
|
|
1526
|
-
* @param params -
|
|
1527
|
-
* @returns Promise containing the
|
|
1520
|
+
* Executes the tool with the provided parameters
|
|
1521
|
+
* @param params - Parameters required for tool execution
|
|
1522
|
+
* @returns Promise containing the tool execution results
|
|
1528
1523
|
*/
|
|
1529
|
-
|
|
1530
|
-
const
|
|
1531
|
-
if (
|
|
1532
|
-
|
|
1524
|
+
execute(params) {
|
|
1525
|
+
const url = new URLSearchParams();
|
|
1526
|
+
if (params.runId) {
|
|
1527
|
+
url.set("runId", params.runId);
|
|
1533
1528
|
}
|
|
1534
|
-
|
|
1529
|
+
const body = {
|
|
1530
|
+
data: params.data,
|
|
1531
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1532
|
+
};
|
|
1533
|
+
return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
|
|
1535
1534
|
method: "POST",
|
|
1536
|
-
body
|
|
1535
|
+
body
|
|
1537
1536
|
});
|
|
1538
1537
|
}
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
body: {
|
|
1548
|
-
stepId: params.stepId,
|
|
1549
|
-
context: params.context
|
|
1550
|
-
}
|
|
1551
|
-
});
|
|
1538
|
+
};
|
|
1539
|
+
|
|
1540
|
+
// src/resources/workflow.ts
|
|
1541
|
+
var RECORD_SEPARATOR = "";
|
|
1542
|
+
var Workflow = class extends BaseResource {
|
|
1543
|
+
constructor(options, workflowId) {
|
|
1544
|
+
super(options);
|
|
1545
|
+
this.workflowId = workflowId;
|
|
1552
1546
|
}
|
|
1553
1547
|
/**
|
|
1554
|
-
* Creates an async generator that processes a readable stream and yields records
|
|
1548
|
+
* Creates an async generator that processes a readable stream and yields workflow records
|
|
1555
1549
|
* separated by the Record Separator character (\x1E)
|
|
1556
1550
|
*
|
|
1557
1551
|
* @param stream - The readable stream to process
|
|
@@ -1596,125 +1590,21 @@ var LegacyWorkflow = class extends BaseResource {
|
|
|
1596
1590
|
}
|
|
1597
1591
|
}
|
|
1598
1592
|
/**
|
|
1599
|
-
*
|
|
1600
|
-
* @param
|
|
1601
|
-
* @returns
|
|
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
|
-
// src/resources/tool.ts
|
|
1620
|
-
var Tool = class extends BaseResource {
|
|
1621
|
-
constructor(options, toolId) {
|
|
1622
|
-
super(options);
|
|
1623
|
-
this.toolId = toolId;
|
|
1624
|
-
}
|
|
1625
|
-
/**
|
|
1626
|
-
* Retrieves details about the tool
|
|
1627
|
-
* @returns Promise containing tool details including description and schemas
|
|
1593
|
+
* Retrieves details about the workflow
|
|
1594
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1595
|
+
* @returns Promise containing workflow details including steps and graphs
|
|
1628
1596
|
*/
|
|
1629
|
-
details() {
|
|
1630
|
-
return this.request(`/api/
|
|
1597
|
+
details(runtimeContext) {
|
|
1598
|
+
return this.request(`/api/workflows/${this.workflowId}${runtimeContextQueryString(runtimeContext)}`);
|
|
1631
1599
|
}
|
|
1632
1600
|
/**
|
|
1633
|
-
*
|
|
1634
|
-
* @param params - Parameters
|
|
1635
|
-
* @
|
|
1601
|
+
* Retrieves all runs for a workflow
|
|
1602
|
+
* @param params - Parameters for filtering runs
|
|
1603
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1604
|
+
* @returns Promise containing workflow runs array
|
|
1636
1605
|
*/
|
|
1637
|
-
|
|
1638
|
-
const
|
|
1639
|
-
if (params.runId) {
|
|
1640
|
-
url.set("runId", params.runId);
|
|
1641
|
-
}
|
|
1642
|
-
const body = {
|
|
1643
|
-
data: params.data,
|
|
1644
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1645
|
-
};
|
|
1646
|
-
return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
|
|
1647
|
-
method: "POST",
|
|
1648
|
-
body
|
|
1649
|
-
});
|
|
1650
|
-
}
|
|
1651
|
-
};
|
|
1652
|
-
|
|
1653
|
-
// src/resources/workflow.ts
|
|
1654
|
-
var RECORD_SEPARATOR2 = "";
|
|
1655
|
-
var Workflow = class extends BaseResource {
|
|
1656
|
-
constructor(options, workflowId) {
|
|
1657
|
-
super(options);
|
|
1658
|
-
this.workflowId = workflowId;
|
|
1659
|
-
}
|
|
1660
|
-
/**
|
|
1661
|
-
* Creates an async generator that processes a readable stream and yields workflow records
|
|
1662
|
-
* separated by the Record Separator character (\x1E)
|
|
1663
|
-
*
|
|
1664
|
-
* @param stream - The readable stream to process
|
|
1665
|
-
* @returns An async generator that yields parsed records
|
|
1666
|
-
*/
|
|
1667
|
-
async *streamProcessor(stream) {
|
|
1668
|
-
const reader = stream.getReader();
|
|
1669
|
-
let doneReading = false;
|
|
1670
|
-
let buffer = "";
|
|
1671
|
-
try {
|
|
1672
|
-
while (!doneReading) {
|
|
1673
|
-
const { done, value } = await reader.read();
|
|
1674
|
-
doneReading = done;
|
|
1675
|
-
if (done && !value) continue;
|
|
1676
|
-
try {
|
|
1677
|
-
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
1678
|
-
const chunks = (buffer + decoded).split(RECORD_SEPARATOR2);
|
|
1679
|
-
buffer = chunks.pop() || "";
|
|
1680
|
-
for (const chunk of chunks) {
|
|
1681
|
-
if (chunk) {
|
|
1682
|
-
if (typeof chunk === "string") {
|
|
1683
|
-
try {
|
|
1684
|
-
const parsedChunk = JSON.parse(chunk);
|
|
1685
|
-
yield parsedChunk;
|
|
1686
|
-
} catch {
|
|
1687
|
-
}
|
|
1688
|
-
}
|
|
1689
|
-
}
|
|
1690
|
-
}
|
|
1691
|
-
} catch {
|
|
1692
|
-
}
|
|
1693
|
-
}
|
|
1694
|
-
if (buffer) {
|
|
1695
|
-
try {
|
|
1696
|
-
yield JSON.parse(buffer);
|
|
1697
|
-
} catch {
|
|
1698
|
-
}
|
|
1699
|
-
}
|
|
1700
|
-
} finally {
|
|
1701
|
-
reader.cancel().catch(() => {
|
|
1702
|
-
});
|
|
1703
|
-
}
|
|
1704
|
-
}
|
|
1705
|
-
/**
|
|
1706
|
-
* Retrieves details about the workflow
|
|
1707
|
-
* @returns Promise containing workflow details including steps and graphs
|
|
1708
|
-
*/
|
|
1709
|
-
details() {
|
|
1710
|
-
return this.request(`/api/workflows/${this.workflowId}`);
|
|
1711
|
-
}
|
|
1712
|
-
/**
|
|
1713
|
-
* Retrieves all runs for a workflow
|
|
1714
|
-
* @param params - Parameters for filtering runs
|
|
1715
|
-
* @returns Promise containing workflow runs array
|
|
1716
|
-
*/
|
|
1717
|
-
runs(params) {
|
|
1606
|
+
runs(params, runtimeContext) {
|
|
1607
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
1718
1608
|
const searchParams = new URLSearchParams();
|
|
1719
1609
|
if (params?.fromDate) {
|
|
1720
1610
|
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
@@ -1731,6 +1621,9 @@ var Workflow = class extends BaseResource {
|
|
|
1731
1621
|
if (params?.resourceId) {
|
|
1732
1622
|
searchParams.set("resourceId", params.resourceId);
|
|
1733
1623
|
}
|
|
1624
|
+
if (runtimeContextParam) {
|
|
1625
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
1626
|
+
}
|
|
1734
1627
|
if (searchParams.size) {
|
|
1735
1628
|
return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
|
|
1736
1629
|
} else {
|
|
@@ -1740,18 +1633,22 @@ var Workflow = class extends BaseResource {
|
|
|
1740
1633
|
/**
|
|
1741
1634
|
* Retrieves a specific workflow run by its ID
|
|
1742
1635
|
* @param runId - The ID of the workflow run to retrieve
|
|
1636
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1743
1637
|
* @returns Promise containing the workflow run details
|
|
1744
1638
|
*/
|
|
1745
|
-
runById(runId) {
|
|
1746
|
-
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}`);
|
|
1639
|
+
runById(runId, runtimeContext) {
|
|
1640
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}${runtimeContextQueryString(runtimeContext)}`);
|
|
1747
1641
|
}
|
|
1748
1642
|
/**
|
|
1749
1643
|
* Retrieves the execution result for a specific workflow run by its ID
|
|
1750
1644
|
* @param runId - The ID of the workflow run to retrieve the execution result for
|
|
1645
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1751
1646
|
* @returns Promise containing the workflow run execution result
|
|
1752
1647
|
*/
|
|
1753
|
-
runExecutionResult(runId) {
|
|
1754
|
-
return this.request(
|
|
1648
|
+
runExecutionResult(runId, runtimeContext) {
|
|
1649
|
+
return this.request(
|
|
1650
|
+
`/api/workflows/${this.workflowId}/runs/${runId}/execution-result${runtimeContextQueryString(runtimeContext)}`
|
|
1651
|
+
);
|
|
1755
1652
|
}
|
|
1756
1653
|
/**
|
|
1757
1654
|
* Cancels a specific workflow run by its ID
|
|
@@ -1774,27 +1671,83 @@ var Workflow = class extends BaseResource {
|
|
|
1774
1671
|
body: { event: params.event, data: params.data }
|
|
1775
1672
|
});
|
|
1776
1673
|
}
|
|
1674
|
+
/**
|
|
1675
|
+
* @deprecated Use createRunAsync() instead.
|
|
1676
|
+
* @throws {Error} Always throws an error directing users to use createRunAsync()
|
|
1677
|
+
*/
|
|
1678
|
+
async createRun(_params) {
|
|
1679
|
+
throw new Error(
|
|
1680
|
+
"createRun() has been deprecated. Please use createRunAsync() instead.\n\nMigration guide:\n Before: const run = workflow.createRun();\n After: const run = await workflow.createRunAsync();\n\nNote: createRunAsync() is an async method, so make sure your calling function is async."
|
|
1681
|
+
);
|
|
1682
|
+
}
|
|
1777
1683
|
/**
|
|
1778
1684
|
* Creates a new workflow run
|
|
1779
1685
|
* @param params - Optional object containing the optional runId
|
|
1780
|
-
* @returns Promise containing the runId of the created run
|
|
1686
|
+
* @returns Promise containing the runId of the created run with methods to control execution
|
|
1781
1687
|
*/
|
|
1782
|
-
|
|
1688
|
+
async createRunAsync(params) {
|
|
1783
1689
|
const searchParams = new URLSearchParams();
|
|
1784
1690
|
if (!!params?.runId) {
|
|
1785
1691
|
searchParams.set("runId", params.runId);
|
|
1786
1692
|
}
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1693
|
+
const res = await this.request(
|
|
1694
|
+
`/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`,
|
|
1695
|
+
{
|
|
1696
|
+
method: "POST"
|
|
1697
|
+
}
|
|
1698
|
+
);
|
|
1699
|
+
const runId = res.runId;
|
|
1700
|
+
return {
|
|
1701
|
+
runId,
|
|
1702
|
+
start: async (p) => {
|
|
1703
|
+
return this.start({
|
|
1704
|
+
runId,
|
|
1705
|
+
inputData: p.inputData,
|
|
1706
|
+
runtimeContext: p.runtimeContext,
|
|
1707
|
+
tracingOptions: p.tracingOptions
|
|
1708
|
+
});
|
|
1709
|
+
},
|
|
1710
|
+
startAsync: async (p) => {
|
|
1711
|
+
return this.startAsync({
|
|
1712
|
+
runId,
|
|
1713
|
+
inputData: p.inputData,
|
|
1714
|
+
runtimeContext: p.runtimeContext,
|
|
1715
|
+
tracingOptions: p.tracingOptions
|
|
1716
|
+
});
|
|
1717
|
+
},
|
|
1718
|
+
watch: async (onRecord) => {
|
|
1719
|
+
return this.watch({ runId }, onRecord);
|
|
1720
|
+
},
|
|
1721
|
+
stream: async (p) => {
|
|
1722
|
+
return this.stream({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
|
|
1723
|
+
},
|
|
1724
|
+
resume: async (p) => {
|
|
1725
|
+
return this.resume({
|
|
1726
|
+
runId,
|
|
1727
|
+
step: p.step,
|
|
1728
|
+
resumeData: p.resumeData,
|
|
1729
|
+
runtimeContext: p.runtimeContext,
|
|
1730
|
+
tracingOptions: p.tracingOptions
|
|
1731
|
+
});
|
|
1732
|
+
},
|
|
1733
|
+
resumeAsync: async (p) => {
|
|
1734
|
+
return this.resumeAsync({
|
|
1735
|
+
runId,
|
|
1736
|
+
step: p.step,
|
|
1737
|
+
resumeData: p.resumeData,
|
|
1738
|
+
runtimeContext: p.runtimeContext,
|
|
1739
|
+
tracingOptions: p.tracingOptions
|
|
1740
|
+
});
|
|
1741
|
+
},
|
|
1742
|
+
resumeStreamVNext: async (p) => {
|
|
1743
|
+
return this.resumeStreamVNext({
|
|
1744
|
+
runId,
|
|
1745
|
+
step: p.step,
|
|
1746
|
+
resumeData: p.resumeData,
|
|
1747
|
+
runtimeContext: p.runtimeContext
|
|
1748
|
+
});
|
|
1749
|
+
}
|
|
1750
|
+
};
|
|
1798
1751
|
}
|
|
1799
1752
|
/**
|
|
1800
1753
|
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
@@ -1805,7 +1758,7 @@ var Workflow = class extends BaseResource {
|
|
|
1805
1758
|
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1806
1759
|
return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
|
|
1807
1760
|
method: "POST",
|
|
1808
|
-
body: { inputData: params?.inputData, runtimeContext }
|
|
1761
|
+
body: { inputData: params?.inputData, runtimeContext, tracingOptions: params.tracingOptions }
|
|
1809
1762
|
});
|
|
1810
1763
|
}
|
|
1811
1764
|
/**
|
|
@@ -1817,16 +1770,17 @@ var Workflow = class extends BaseResource {
|
|
|
1817
1770
|
step,
|
|
1818
1771
|
runId,
|
|
1819
1772
|
resumeData,
|
|
1773
|
+
tracingOptions,
|
|
1820
1774
|
...rest
|
|
1821
1775
|
}) {
|
|
1822
1776
|
const runtimeContext = parseClientRuntimeContext(rest.runtimeContext);
|
|
1823
1777
|
return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
|
|
1824
1778
|
method: "POST",
|
|
1825
|
-
stream: true,
|
|
1826
1779
|
body: {
|
|
1827
1780
|
step,
|
|
1828
1781
|
resumeData,
|
|
1829
|
-
runtimeContext
|
|
1782
|
+
runtimeContext,
|
|
1783
|
+
tracingOptions
|
|
1830
1784
|
}
|
|
1831
1785
|
});
|
|
1832
1786
|
}
|
|
@@ -1843,7 +1797,7 @@ var Workflow = class extends BaseResource {
|
|
|
1843
1797
|
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1844
1798
|
return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
1845
1799
|
method: "POST",
|
|
1846
|
-
body: { inputData: params.inputData, runtimeContext }
|
|
1800
|
+
body: { inputData: params.inputData, runtimeContext, tracingOptions: params.tracingOptions }
|
|
1847
1801
|
});
|
|
1848
1802
|
}
|
|
1849
1803
|
/**
|
|
@@ -1861,7 +1815,110 @@ var Workflow = class extends BaseResource {
|
|
|
1861
1815
|
`/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
|
|
1862
1816
|
{
|
|
1863
1817
|
method: "POST",
|
|
1864
|
-
body: { inputData: params.inputData, runtimeContext },
|
|
1818
|
+
body: { inputData: params.inputData, runtimeContext, tracingOptions: params.tracingOptions },
|
|
1819
|
+
stream: true
|
|
1820
|
+
}
|
|
1821
|
+
);
|
|
1822
|
+
if (!response.ok) {
|
|
1823
|
+
throw new Error(`Failed to stream workflow: ${response.statusText}`);
|
|
1824
|
+
}
|
|
1825
|
+
if (!response.body) {
|
|
1826
|
+
throw new Error("Response body is null");
|
|
1827
|
+
}
|
|
1828
|
+
let failedChunk = void 0;
|
|
1829
|
+
const transformStream = new TransformStream({
|
|
1830
|
+
start() {
|
|
1831
|
+
},
|
|
1832
|
+
async transform(chunk, controller) {
|
|
1833
|
+
try {
|
|
1834
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
1835
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
1836
|
+
for (const chunk2 of chunks) {
|
|
1837
|
+
if (chunk2) {
|
|
1838
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
1839
|
+
try {
|
|
1840
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
1841
|
+
controller.enqueue(parsedChunk);
|
|
1842
|
+
failedChunk = void 0;
|
|
1843
|
+
} catch {
|
|
1844
|
+
failedChunk = newChunk;
|
|
1845
|
+
}
|
|
1846
|
+
}
|
|
1847
|
+
}
|
|
1848
|
+
} catch {
|
|
1849
|
+
}
|
|
1850
|
+
}
|
|
1851
|
+
});
|
|
1852
|
+
return response.body.pipeThrough(transformStream);
|
|
1853
|
+
}
|
|
1854
|
+
/**
|
|
1855
|
+
* Observes workflow stream for a workflow run
|
|
1856
|
+
* @param params - Object containing the runId
|
|
1857
|
+
* @returns Promise containing the workflow execution results
|
|
1858
|
+
*/
|
|
1859
|
+
async observeStream(params) {
|
|
1860
|
+
const searchParams = new URLSearchParams();
|
|
1861
|
+
searchParams.set("runId", params.runId);
|
|
1862
|
+
const response = await this.request(
|
|
1863
|
+
`/api/workflows/${this.workflowId}/observe-stream?${searchParams.toString()}`,
|
|
1864
|
+
{
|
|
1865
|
+
method: "POST",
|
|
1866
|
+
stream: true
|
|
1867
|
+
}
|
|
1868
|
+
);
|
|
1869
|
+
if (!response.ok) {
|
|
1870
|
+
throw new Error(`Failed to observe workflow stream: ${response.statusText}`);
|
|
1871
|
+
}
|
|
1872
|
+
if (!response.body) {
|
|
1873
|
+
throw new Error("Response body is null");
|
|
1874
|
+
}
|
|
1875
|
+
let failedChunk = void 0;
|
|
1876
|
+
const transformStream = new TransformStream({
|
|
1877
|
+
start() {
|
|
1878
|
+
},
|
|
1879
|
+
async transform(chunk, controller) {
|
|
1880
|
+
try {
|
|
1881
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
1882
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
1883
|
+
for (const chunk2 of chunks) {
|
|
1884
|
+
if (chunk2) {
|
|
1885
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
1886
|
+
try {
|
|
1887
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
1888
|
+
controller.enqueue(parsedChunk);
|
|
1889
|
+
failedChunk = void 0;
|
|
1890
|
+
} catch {
|
|
1891
|
+
failedChunk = newChunk;
|
|
1892
|
+
}
|
|
1893
|
+
}
|
|
1894
|
+
}
|
|
1895
|
+
} catch {
|
|
1896
|
+
}
|
|
1897
|
+
}
|
|
1898
|
+
});
|
|
1899
|
+
return response.body.pipeThrough(transformStream);
|
|
1900
|
+
}
|
|
1901
|
+
/**
|
|
1902
|
+
* Starts a workflow run and returns a stream
|
|
1903
|
+
* @param params - Object containing the optional runId, inputData and runtimeContext
|
|
1904
|
+
* @returns Promise containing the workflow execution results
|
|
1905
|
+
*/
|
|
1906
|
+
async streamVNext(params) {
|
|
1907
|
+
const searchParams = new URLSearchParams();
|
|
1908
|
+
if (!!params?.runId) {
|
|
1909
|
+
searchParams.set("runId", params.runId);
|
|
1910
|
+
}
|
|
1911
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1912
|
+
const response = await this.request(
|
|
1913
|
+
`/api/workflows/${this.workflowId}/streamVNext?${searchParams.toString()}`,
|
|
1914
|
+
{
|
|
1915
|
+
method: "POST",
|
|
1916
|
+
body: {
|
|
1917
|
+
inputData: params.inputData,
|
|
1918
|
+
runtimeContext,
|
|
1919
|
+
closeOnSuspend: params.closeOnSuspend,
|
|
1920
|
+
tracingOptions: params.tracingOptions
|
|
1921
|
+
},
|
|
1865
1922
|
stream: true
|
|
1866
1923
|
}
|
|
1867
1924
|
);
|
|
@@ -1878,7 +1935,54 @@ var Workflow = class extends BaseResource {
|
|
|
1878
1935
|
async transform(chunk, controller) {
|
|
1879
1936
|
try {
|
|
1880
1937
|
const decoded = new TextDecoder().decode(chunk);
|
|
1881
|
-
const chunks = decoded.split(
|
|
1938
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
1939
|
+
for (const chunk2 of chunks) {
|
|
1940
|
+
if (chunk2) {
|
|
1941
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
1942
|
+
try {
|
|
1943
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
1944
|
+
controller.enqueue(parsedChunk);
|
|
1945
|
+
failedChunk = void 0;
|
|
1946
|
+
} catch {
|
|
1947
|
+
failedChunk = newChunk;
|
|
1948
|
+
}
|
|
1949
|
+
}
|
|
1950
|
+
}
|
|
1951
|
+
} catch {
|
|
1952
|
+
}
|
|
1953
|
+
}
|
|
1954
|
+
});
|
|
1955
|
+
return response.body.pipeThrough(transformStream);
|
|
1956
|
+
}
|
|
1957
|
+
/**
|
|
1958
|
+
* Observes workflow vNext stream for a workflow run
|
|
1959
|
+
* @param params - Object containing the runId
|
|
1960
|
+
* @returns Promise containing the workflow execution results
|
|
1961
|
+
*/
|
|
1962
|
+
async observeStreamVNext(params) {
|
|
1963
|
+
const searchParams = new URLSearchParams();
|
|
1964
|
+
searchParams.set("runId", params.runId);
|
|
1965
|
+
const response = await this.request(
|
|
1966
|
+
`/api/workflows/${this.workflowId}/observe-streamVNext?${searchParams.toString()}`,
|
|
1967
|
+
{
|
|
1968
|
+
method: "POST",
|
|
1969
|
+
stream: true
|
|
1970
|
+
}
|
|
1971
|
+
);
|
|
1972
|
+
if (!response.ok) {
|
|
1973
|
+
throw new Error(`Failed to observe stream vNext workflow: ${response.statusText}`);
|
|
1974
|
+
}
|
|
1975
|
+
if (!response.body) {
|
|
1976
|
+
throw new Error("Response body is null");
|
|
1977
|
+
}
|
|
1978
|
+
let failedChunk = void 0;
|
|
1979
|
+
const transformStream = new TransformStream({
|
|
1980
|
+
start() {
|
|
1981
|
+
},
|
|
1982
|
+
async transform(chunk, controller) {
|
|
1983
|
+
try {
|
|
1984
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
1985
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
1882
1986
|
for (const chunk2 of chunks) {
|
|
1883
1987
|
if (chunk2) {
|
|
1884
1988
|
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
@@ -1909,10 +2013,65 @@ var Workflow = class extends BaseResource {
|
|
|
1909
2013
|
body: {
|
|
1910
2014
|
step: params.step,
|
|
1911
2015
|
resumeData: params.resumeData,
|
|
1912
|
-
runtimeContext
|
|
2016
|
+
runtimeContext,
|
|
2017
|
+
tracingOptions: params.tracingOptions
|
|
1913
2018
|
}
|
|
1914
2019
|
});
|
|
1915
2020
|
}
|
|
2021
|
+
/**
|
|
2022
|
+
* Resumes a suspended workflow step that uses streamVNext asynchronously and returns a promise that resolves when the workflow is complete
|
|
2023
|
+
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
2024
|
+
* @returns Promise containing the workflow resume results
|
|
2025
|
+
*/
|
|
2026
|
+
async resumeStreamVNext(params) {
|
|
2027
|
+
const searchParams = new URLSearchParams();
|
|
2028
|
+
searchParams.set("runId", params.runId);
|
|
2029
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
2030
|
+
const response = await this.request(
|
|
2031
|
+
`/api/workflows/${this.workflowId}/resume-stream?${searchParams.toString()}`,
|
|
2032
|
+
{
|
|
2033
|
+
method: "POST",
|
|
2034
|
+
body: {
|
|
2035
|
+
step: params.step,
|
|
2036
|
+
resumeData: params.resumeData,
|
|
2037
|
+
runtimeContext,
|
|
2038
|
+
tracingOptions: params.tracingOptions
|
|
2039
|
+
},
|
|
2040
|
+
stream: true
|
|
2041
|
+
}
|
|
2042
|
+
);
|
|
2043
|
+
if (!response.ok) {
|
|
2044
|
+
throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
|
|
2045
|
+
}
|
|
2046
|
+
if (!response.body) {
|
|
2047
|
+
throw new Error("Response body is null");
|
|
2048
|
+
}
|
|
2049
|
+
let failedChunk = void 0;
|
|
2050
|
+
const transformStream = new TransformStream({
|
|
2051
|
+
start() {
|
|
2052
|
+
},
|
|
2053
|
+
async transform(chunk, controller) {
|
|
2054
|
+
try {
|
|
2055
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
2056
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
2057
|
+
for (const chunk2 of chunks) {
|
|
2058
|
+
if (chunk2) {
|
|
2059
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
2060
|
+
try {
|
|
2061
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
2062
|
+
controller.enqueue(parsedChunk);
|
|
2063
|
+
failedChunk = void 0;
|
|
2064
|
+
} catch {
|
|
2065
|
+
failedChunk = newChunk;
|
|
2066
|
+
}
|
|
2067
|
+
}
|
|
2068
|
+
}
|
|
2069
|
+
} catch {
|
|
2070
|
+
}
|
|
2071
|
+
}
|
|
2072
|
+
});
|
|
2073
|
+
return response.body.pipeThrough(transformStream);
|
|
2074
|
+
}
|
|
1916
2075
|
/**
|
|
1917
2076
|
* Watches workflow transitions in real-time
|
|
1918
2077
|
* @param runId - Optional run ID to filter the watch stream
|
|
@@ -1949,7 +2108,7 @@ var Workflow = class extends BaseResource {
|
|
|
1949
2108
|
async start(controller) {
|
|
1950
2109
|
try {
|
|
1951
2110
|
for await (const record of records) {
|
|
1952
|
-
const json = JSON.stringify(record) +
|
|
2111
|
+
const json = JSON.stringify(record) + RECORD_SEPARATOR;
|
|
1953
2112
|
controller.enqueue(encoder.encode(json));
|
|
1954
2113
|
}
|
|
1955
2114
|
controller.close();
|
|
@@ -2047,10 +2206,11 @@ var MCPTool = class extends BaseResource {
|
|
|
2047
2206
|
}
|
|
2048
2207
|
/**
|
|
2049
2208
|
* Retrieves details about this specific tool from the MCP server.
|
|
2209
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2050
2210
|
* @returns Promise containing the tool's information (name, description, schema).
|
|
2051
2211
|
*/
|
|
2052
|
-
details() {
|
|
2053
|
-
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}`);
|
|
2212
|
+
details(runtimeContext) {
|
|
2213
|
+
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
|
|
2054
2214
|
}
|
|
2055
2215
|
/**
|
|
2056
2216
|
* Executes this specific tool on the MCP server.
|
|
@@ -2071,7 +2231,7 @@ var MCPTool = class extends BaseResource {
|
|
|
2071
2231
|
};
|
|
2072
2232
|
|
|
2073
2233
|
// src/resources/agent-builder.ts
|
|
2074
|
-
var
|
|
2234
|
+
var RECORD_SEPARATOR2 = "";
|
|
2075
2235
|
var AgentBuilder = class extends BaseResource {
|
|
2076
2236
|
constructor(options, actionId) {
|
|
2077
2237
|
super(options);
|
|
@@ -2106,11 +2266,20 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2106
2266
|
};
|
|
2107
2267
|
}
|
|
2108
2268
|
}
|
|
2269
|
+
/**
|
|
2270
|
+
* @deprecated Use createRunAsync() instead.
|
|
2271
|
+
* @throws {Error} Always throws an error directing users to use createRunAsync()
|
|
2272
|
+
*/
|
|
2273
|
+
async createRun(_params) {
|
|
2274
|
+
throw new Error(
|
|
2275
|
+
"createRun() has been deprecated. Please use createRunAsync() instead.\n\nMigration guide:\n Before: const run = agentBuilder.createRun();\n After: const run = await agentBuilder.createRunAsync();\n\nNote: createRunAsync() is an async method, so make sure your calling function is async."
|
|
2276
|
+
);
|
|
2277
|
+
}
|
|
2109
2278
|
/**
|
|
2110
2279
|
* Creates a new agent builder action run and returns the runId.
|
|
2111
2280
|
* This calls `/api/agent-builder/:actionId/create-run`.
|
|
2112
2281
|
*/
|
|
2113
|
-
async
|
|
2282
|
+
async createRunAsync(params) {
|
|
2114
2283
|
const searchParams = new URLSearchParams();
|
|
2115
2284
|
if (!!params?.runId) {
|
|
2116
2285
|
searchParams.set("runId", params.runId);
|
|
@@ -2120,14 +2289,6 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2120
2289
|
method: "POST"
|
|
2121
2290
|
});
|
|
2122
2291
|
}
|
|
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
2292
|
/**
|
|
2132
2293
|
* Starts agent builder action asynchronously and waits for completion.
|
|
2133
2294
|
* This calls `/api/agent-builder/:actionId/start-async`.
|
|
@@ -2210,7 +2371,7 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2210
2371
|
if (done && !value) continue;
|
|
2211
2372
|
try {
|
|
2212
2373
|
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
2213
|
-
const chunks = (buffer + decoded).split(
|
|
2374
|
+
const chunks = (buffer + decoded).split(RECORD_SEPARATOR2);
|
|
2214
2375
|
buffer = chunks.pop() || "";
|
|
2215
2376
|
for (const chunk of chunks) {
|
|
2216
2377
|
if (chunk) {
|
|
@@ -2267,7 +2428,7 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2267
2428
|
async transform(chunk, controller) {
|
|
2268
2429
|
try {
|
|
2269
2430
|
const decoded = new TextDecoder().decode(chunk);
|
|
2270
|
-
const chunks = decoded.split(
|
|
2431
|
+
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
2271
2432
|
for (const chunk2 of chunks) {
|
|
2272
2433
|
if (chunk2) {
|
|
2273
2434
|
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
@@ -2316,7 +2477,7 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2316
2477
|
async transform(chunk, controller) {
|
|
2317
2478
|
try {
|
|
2318
2479
|
const decoded = new TextDecoder().decode(chunk);
|
|
2319
|
-
const chunks = decoded.split(
|
|
2480
|
+
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
2320
2481
|
for (const chunk2 of chunks) {
|
|
2321
2482
|
if (chunk2) {
|
|
2322
2483
|
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
@@ -2459,7 +2620,7 @@ var Observability = class extends BaseResource {
|
|
|
2459
2620
|
getTraces(params) {
|
|
2460
2621
|
const { pagination, filters } = params;
|
|
2461
2622
|
const { page, perPage, dateRange } = pagination || {};
|
|
2462
|
-
const { name, spanType } = filters || {};
|
|
2623
|
+
const { name, spanType, entityId, entityType } = filters || {};
|
|
2463
2624
|
const searchParams = new URLSearchParams();
|
|
2464
2625
|
if (page !== void 0) {
|
|
2465
2626
|
searchParams.set("page", String(page));
|
|
@@ -2473,6 +2634,10 @@ var Observability = class extends BaseResource {
|
|
|
2473
2634
|
if (spanType !== void 0) {
|
|
2474
2635
|
searchParams.set("spanType", String(spanType));
|
|
2475
2636
|
}
|
|
2637
|
+
if (entityId && entityType) {
|
|
2638
|
+
searchParams.set("entityId", entityId);
|
|
2639
|
+
searchParams.set("entityType", entityType);
|
|
2640
|
+
}
|
|
2476
2641
|
if (dateRange) {
|
|
2477
2642
|
const dateRangeStr = JSON.stringify({
|
|
2478
2643
|
start: dateRange.start instanceof Date ? dateRange.start.toISOString() : dateRange.start,
|
|
@@ -2483,6 +2648,31 @@ var Observability = class extends BaseResource {
|
|
|
2483
2648
|
const queryString = searchParams.toString();
|
|
2484
2649
|
return this.request(`/api/observability/traces${queryString ? `?${queryString}` : ""}`);
|
|
2485
2650
|
}
|
|
2651
|
+
/**
|
|
2652
|
+
* Retrieves scores by trace ID and span ID
|
|
2653
|
+
* @param params - Parameters containing trace ID, span ID, and pagination options
|
|
2654
|
+
* @returns Promise containing scores and pagination info
|
|
2655
|
+
*/
|
|
2656
|
+
getScoresBySpan(params) {
|
|
2657
|
+
const { traceId, spanId, page, perPage } = params;
|
|
2658
|
+
const searchParams = new URLSearchParams();
|
|
2659
|
+
if (page !== void 0) {
|
|
2660
|
+
searchParams.set("page", String(page));
|
|
2661
|
+
}
|
|
2662
|
+
if (perPage !== void 0) {
|
|
2663
|
+
searchParams.set("perPage", String(perPage));
|
|
2664
|
+
}
|
|
2665
|
+
const queryString = searchParams.toString();
|
|
2666
|
+
return this.request(
|
|
2667
|
+
`/api/observability/traces/${encodeURIComponent(traceId)}/${encodeURIComponent(spanId)}/scores${queryString ? `?${queryString}` : ""}`
|
|
2668
|
+
);
|
|
2669
|
+
}
|
|
2670
|
+
score(params) {
|
|
2671
|
+
return this.request(`/api/observability/traces/score`, {
|
|
2672
|
+
method: "POST",
|
|
2673
|
+
body: { ...params }
|
|
2674
|
+
});
|
|
2675
|
+
}
|
|
2486
2676
|
};
|
|
2487
2677
|
|
|
2488
2678
|
// src/resources/network-memory-thread.ts
|
|
@@ -2548,144 +2738,6 @@ var NetworkMemoryThread = class extends BaseResource {
|
|
|
2548
2738
|
}
|
|
2549
2739
|
};
|
|
2550
2740
|
|
|
2551
|
-
// src/resources/vNextNetwork.ts
|
|
2552
|
-
var RECORD_SEPARATOR4 = "";
|
|
2553
|
-
var VNextNetwork = class extends BaseResource {
|
|
2554
|
-
constructor(options, networkId) {
|
|
2555
|
-
super(options);
|
|
2556
|
-
this.networkId = networkId;
|
|
2557
|
-
}
|
|
2558
|
-
/**
|
|
2559
|
-
* Retrieves details about the network
|
|
2560
|
-
* @returns Promise containing vNext network details
|
|
2561
|
-
*/
|
|
2562
|
-
details() {
|
|
2563
|
-
return this.request(`/api/networks/v-next/${this.networkId}`);
|
|
2564
|
-
}
|
|
2565
|
-
/**
|
|
2566
|
-
* Generates a response from the v-next network
|
|
2567
|
-
* @param params - Generation parameters including message
|
|
2568
|
-
* @returns Promise containing the generated response
|
|
2569
|
-
*/
|
|
2570
|
-
generate(params) {
|
|
2571
|
-
return this.request(`/api/networks/v-next/${this.networkId}/generate`, {
|
|
2572
|
-
method: "POST",
|
|
2573
|
-
body: {
|
|
2574
|
-
...params,
|
|
2575
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
2576
|
-
}
|
|
2577
|
-
});
|
|
2578
|
-
}
|
|
2579
|
-
/**
|
|
2580
|
-
* Generates a response from the v-next network using multiple primitives
|
|
2581
|
-
* @param params - Generation parameters including message
|
|
2582
|
-
* @returns Promise containing the generated response
|
|
2583
|
-
*/
|
|
2584
|
-
loop(params) {
|
|
2585
|
-
return this.request(`/api/networks/v-next/${this.networkId}/loop`, {
|
|
2586
|
-
method: "POST",
|
|
2587
|
-
body: {
|
|
2588
|
-
...params,
|
|
2589
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
2590
|
-
}
|
|
2591
|
-
});
|
|
2592
|
-
}
|
|
2593
|
-
async *streamProcessor(stream) {
|
|
2594
|
-
const reader = stream.getReader();
|
|
2595
|
-
let doneReading = false;
|
|
2596
|
-
let buffer = "";
|
|
2597
|
-
try {
|
|
2598
|
-
while (!doneReading) {
|
|
2599
|
-
const { done, value } = await reader.read();
|
|
2600
|
-
doneReading = done;
|
|
2601
|
-
if (done && !value) continue;
|
|
2602
|
-
try {
|
|
2603
|
-
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
2604
|
-
const chunks = (buffer + decoded).split(RECORD_SEPARATOR4);
|
|
2605
|
-
buffer = chunks.pop() || "";
|
|
2606
|
-
for (const chunk of chunks) {
|
|
2607
|
-
if (chunk) {
|
|
2608
|
-
if (typeof chunk === "string") {
|
|
2609
|
-
try {
|
|
2610
|
-
const parsedChunk = JSON.parse(chunk);
|
|
2611
|
-
yield parsedChunk;
|
|
2612
|
-
} catch {
|
|
2613
|
-
}
|
|
2614
|
-
}
|
|
2615
|
-
}
|
|
2616
|
-
}
|
|
2617
|
-
} catch {
|
|
2618
|
-
}
|
|
2619
|
-
}
|
|
2620
|
-
if (buffer) {
|
|
2621
|
-
try {
|
|
2622
|
-
yield JSON.parse(buffer);
|
|
2623
|
-
} catch {
|
|
2624
|
-
}
|
|
2625
|
-
}
|
|
2626
|
-
} finally {
|
|
2627
|
-
reader.cancel().catch(() => {
|
|
2628
|
-
});
|
|
2629
|
-
}
|
|
2630
|
-
}
|
|
2631
|
-
/**
|
|
2632
|
-
* Streams a response from the v-next network
|
|
2633
|
-
* @param params - Stream parameters including message
|
|
2634
|
-
* @returns Promise containing the results
|
|
2635
|
-
*/
|
|
2636
|
-
async stream(params, onRecord) {
|
|
2637
|
-
const response = await this.request(`/api/networks/v-next/${this.networkId}/stream`, {
|
|
2638
|
-
method: "POST",
|
|
2639
|
-
body: {
|
|
2640
|
-
...params,
|
|
2641
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
2642
|
-
},
|
|
2643
|
-
stream: true
|
|
2644
|
-
});
|
|
2645
|
-
if (!response.ok) {
|
|
2646
|
-
throw new Error(`Failed to stream vNext network: ${response.statusText}`);
|
|
2647
|
-
}
|
|
2648
|
-
if (!response.body) {
|
|
2649
|
-
throw new Error("Response body is null");
|
|
2650
|
-
}
|
|
2651
|
-
for await (const record of this.streamProcessor(response.body)) {
|
|
2652
|
-
if (typeof record === "string") {
|
|
2653
|
-
onRecord(JSON.parse(record));
|
|
2654
|
-
} else {
|
|
2655
|
-
onRecord(record);
|
|
2656
|
-
}
|
|
2657
|
-
}
|
|
2658
|
-
}
|
|
2659
|
-
/**
|
|
2660
|
-
* Streams a response from the v-next network loop
|
|
2661
|
-
* @param params - Stream parameters including message
|
|
2662
|
-
* @returns Promise containing the results
|
|
2663
|
-
*/
|
|
2664
|
-
async loopStream(params, onRecord) {
|
|
2665
|
-
const response = await this.request(`/api/networks/v-next/${this.networkId}/loop-stream`, {
|
|
2666
|
-
method: "POST",
|
|
2667
|
-
body: {
|
|
2668
|
-
...params,
|
|
2669
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
2670
|
-
},
|
|
2671
|
-
stream: true
|
|
2672
|
-
});
|
|
2673
|
-
if (!response.ok) {
|
|
2674
|
-
throw new Error(`Failed to stream vNext network loop: ${response.statusText}`);
|
|
2675
|
-
}
|
|
2676
|
-
if (!response.body) {
|
|
2677
|
-
throw new Error("Response body is null");
|
|
2678
|
-
}
|
|
2679
|
-
for await (const record of this.streamProcessor(response.body)) {
|
|
2680
|
-
if (typeof record === "string") {
|
|
2681
|
-
onRecord(JSON.parse(record));
|
|
2682
|
-
} else {
|
|
2683
|
-
onRecord(record);
|
|
2684
|
-
}
|
|
2685
|
-
}
|
|
2686
|
-
}
|
|
2687
|
-
};
|
|
2688
|
-
|
|
2689
2741
|
// src/client.ts
|
|
2690
2742
|
var MastraClient = class extends BaseResource {
|
|
2691
2743
|
observability;
|
|
@@ -2695,10 +2747,17 @@ var MastraClient = class extends BaseResource {
|
|
|
2695
2747
|
}
|
|
2696
2748
|
/**
|
|
2697
2749
|
* Retrieves all available agents
|
|
2750
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2698
2751
|
* @returns Promise containing map of agent IDs to agent details
|
|
2699
2752
|
*/
|
|
2700
|
-
getAgents() {
|
|
2701
|
-
|
|
2753
|
+
getAgents(runtimeContext) {
|
|
2754
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
2755
|
+
const searchParams = new URLSearchParams();
|
|
2756
|
+
if (runtimeContextParam) {
|
|
2757
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
2758
|
+
}
|
|
2759
|
+
const queryString = searchParams.toString();
|
|
2760
|
+
return this.request(`/api/agents${queryString ? `?${queryString}` : ""}`);
|
|
2702
2761
|
}
|
|
2703
2762
|
/**
|
|
2704
2763
|
* Gets an agent instance by ID
|
|
@@ -2716,6 +2775,14 @@ var MastraClient = class extends BaseResource {
|
|
|
2716
2775
|
getMemoryThreads(params) {
|
|
2717
2776
|
return this.request(`/api/memory/threads?resourceid=${params.resourceId}&agentId=${params.agentId}`);
|
|
2718
2777
|
}
|
|
2778
|
+
/**
|
|
2779
|
+
* Retrieves memory config for a resource
|
|
2780
|
+
* @param params - Parameters containing the resource ID
|
|
2781
|
+
* @returns Promise containing array of memory threads
|
|
2782
|
+
*/
|
|
2783
|
+
getMemoryConfig(params) {
|
|
2784
|
+
return this.request(`/api/memory/config?agentId=${params.agentId}`);
|
|
2785
|
+
}
|
|
2719
2786
|
/**
|
|
2720
2787
|
* Creates a new memory thread
|
|
2721
2788
|
* @param params - Parameters for creating the memory thread
|
|
@@ -2732,6 +2799,24 @@ var MastraClient = class extends BaseResource {
|
|
|
2732
2799
|
getMemoryThread(threadId, agentId) {
|
|
2733
2800
|
return new MemoryThread(this.options, threadId, agentId);
|
|
2734
2801
|
}
|
|
2802
|
+
getThreadMessages(threadId, opts = {}) {
|
|
2803
|
+
let url = "";
|
|
2804
|
+
if (opts.agentId) {
|
|
2805
|
+
url = `/api/memory/threads/${threadId}/messages?agentId=${opts.agentId}`;
|
|
2806
|
+
} else if (opts.networkId) {
|
|
2807
|
+
url = `/api/memory/network/threads/${threadId}/messages?networkId=${opts.networkId}`;
|
|
2808
|
+
}
|
|
2809
|
+
return this.request(url);
|
|
2810
|
+
}
|
|
2811
|
+
deleteThread(threadId, opts = {}) {
|
|
2812
|
+
let url = "";
|
|
2813
|
+
if (opts.agentId) {
|
|
2814
|
+
url = `/api/memory/threads/${threadId}?agentId=${opts.agentId}`;
|
|
2815
|
+
} else if (opts.networkId) {
|
|
2816
|
+
url = `/api/memory/network/threads/${threadId}?networkId=${opts.networkId}`;
|
|
2817
|
+
}
|
|
2818
|
+
return this.request(url, { method: "DELETE" });
|
|
2819
|
+
}
|
|
2735
2820
|
/**
|
|
2736
2821
|
* Saves messages to memory
|
|
2737
2822
|
* @param params - Parameters containing messages to save
|
|
@@ -2794,10 +2879,17 @@ var MastraClient = class extends BaseResource {
|
|
|
2794
2879
|
}
|
|
2795
2880
|
/**
|
|
2796
2881
|
* Retrieves all available tools
|
|
2882
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2797
2883
|
* @returns Promise containing map of tool IDs to tool details
|
|
2798
2884
|
*/
|
|
2799
|
-
getTools() {
|
|
2800
|
-
|
|
2885
|
+
getTools(runtimeContext) {
|
|
2886
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
2887
|
+
const searchParams = new URLSearchParams();
|
|
2888
|
+
if (runtimeContextParam) {
|
|
2889
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
2890
|
+
}
|
|
2891
|
+
const queryString = searchParams.toString();
|
|
2892
|
+
return this.request(`/api/tools${queryString ? `?${queryString}` : ""}`);
|
|
2801
2893
|
}
|
|
2802
2894
|
/**
|
|
2803
2895
|
* Gets a tool instance by ID
|
|
@@ -2807,27 +2899,19 @@ var MastraClient = class extends BaseResource {
|
|
|
2807
2899
|
getTool(toolId) {
|
|
2808
2900
|
return new Tool(this.options, toolId);
|
|
2809
2901
|
}
|
|
2810
|
-
/**
|
|
2811
|
-
* Retrieves all available legacy workflows
|
|
2812
|
-
* @returns Promise containing map of legacy workflow IDs to legacy workflow details
|
|
2813
|
-
*/
|
|
2814
|
-
getLegacyWorkflows() {
|
|
2815
|
-
return this.request("/api/workflows/legacy");
|
|
2816
|
-
}
|
|
2817
|
-
/**
|
|
2818
|
-
* Gets a legacy workflow instance by ID
|
|
2819
|
-
* @param workflowId - ID of the legacy workflow to retrieve
|
|
2820
|
-
* @returns Legacy Workflow instance
|
|
2821
|
-
*/
|
|
2822
|
-
getLegacyWorkflow(workflowId) {
|
|
2823
|
-
return new LegacyWorkflow(this.options, workflowId);
|
|
2824
|
-
}
|
|
2825
2902
|
/**
|
|
2826
2903
|
* Retrieves all available workflows
|
|
2904
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2827
2905
|
* @returns Promise containing map of workflow IDs to workflow details
|
|
2828
2906
|
*/
|
|
2829
|
-
getWorkflows() {
|
|
2830
|
-
|
|
2907
|
+
getWorkflows(runtimeContext) {
|
|
2908
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
2909
|
+
const searchParams = new URLSearchParams();
|
|
2910
|
+
if (runtimeContextParam) {
|
|
2911
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
2912
|
+
}
|
|
2913
|
+
const queryString = searchParams.toString();
|
|
2914
|
+
return this.request(`/api/workflows${queryString ? `?${queryString}` : ""}`);
|
|
2831
2915
|
}
|
|
2832
2916
|
/**
|
|
2833
2917
|
* Gets a workflow instance by ID
|
|
@@ -2995,36 +3079,6 @@ var MastraClient = class extends BaseResource {
|
|
|
2995
3079
|
return this.request(`/api/telemetry`);
|
|
2996
3080
|
}
|
|
2997
3081
|
}
|
|
2998
|
-
/**
|
|
2999
|
-
* Retrieves all available networks
|
|
3000
|
-
* @returns Promise containing map of network IDs to network details
|
|
3001
|
-
*/
|
|
3002
|
-
getNetworks() {
|
|
3003
|
-
return this.request("/api/networks");
|
|
3004
|
-
}
|
|
3005
|
-
/**
|
|
3006
|
-
* Retrieves all available vNext networks
|
|
3007
|
-
* @returns Promise containing map of vNext network IDs to vNext network details
|
|
3008
|
-
*/
|
|
3009
|
-
getVNextNetworks() {
|
|
3010
|
-
return this.request("/api/networks/v-next");
|
|
3011
|
-
}
|
|
3012
|
-
/**
|
|
3013
|
-
* Gets a network instance by ID
|
|
3014
|
-
* @param networkId - ID of the network to retrieve
|
|
3015
|
-
* @returns Network instance
|
|
3016
|
-
*/
|
|
3017
|
-
getNetwork(networkId) {
|
|
3018
|
-
return new Network(this.options, networkId);
|
|
3019
|
-
}
|
|
3020
|
-
/**
|
|
3021
|
-
* Gets a vNext network instance by ID
|
|
3022
|
-
* @param networkId - ID of the vNext network to retrieve
|
|
3023
|
-
* @returns vNext Network instance
|
|
3024
|
-
*/
|
|
3025
|
-
getVNextNetwork(networkId) {
|
|
3026
|
-
return new VNextNetwork(this.options, networkId);
|
|
3027
|
-
}
|
|
3028
3082
|
/**
|
|
3029
3083
|
* Retrieves a list of available MCP servers.
|
|
3030
3084
|
* @param params - Optional parameters for pagination (limit, offset).
|
|
@@ -3129,7 +3183,7 @@ var MastraClient = class extends BaseResource {
|
|
|
3129
3183
|
* @returns Promise containing the scorer
|
|
3130
3184
|
*/
|
|
3131
3185
|
getScorer(scorerId) {
|
|
3132
|
-
return this.request(`/api/scores/scorers/${scorerId}`);
|
|
3186
|
+
return this.request(`/api/scores/scorers/${encodeURIComponent(scorerId)}`);
|
|
3133
3187
|
}
|
|
3134
3188
|
getScoresByScorerId(params) {
|
|
3135
3189
|
const { page, perPage, scorerId, entityId, entityType } = params;
|
|
@@ -3147,7 +3201,7 @@ var MastraClient = class extends BaseResource {
|
|
|
3147
3201
|
searchParams.set("perPage", String(perPage));
|
|
3148
3202
|
}
|
|
3149
3203
|
const queryString = searchParams.toString();
|
|
3150
|
-
return this.request(`/api/scores/scorer/${scorerId}${queryString ? `?${queryString}` : ""}`);
|
|
3204
|
+
return this.request(`/api/scores/scorer/${encodeURIComponent(scorerId)}${queryString ? `?${queryString}` : ""}`);
|
|
3151
3205
|
}
|
|
3152
3206
|
/**
|
|
3153
3207
|
* Retrieves scores by run ID
|
|
@@ -3164,7 +3218,7 @@ var MastraClient = class extends BaseResource {
|
|
|
3164
3218
|
searchParams.set("perPage", String(perPage));
|
|
3165
3219
|
}
|
|
3166
3220
|
const queryString = searchParams.toString();
|
|
3167
|
-
return this.request(`/api/scores/run/${runId}${queryString ? `?${queryString}` : ""}`);
|
|
3221
|
+
return this.request(`/api/scores/run/${encodeURIComponent(runId)}${queryString ? `?${queryString}` : ""}`);
|
|
3168
3222
|
}
|
|
3169
3223
|
/**
|
|
3170
3224
|
* Retrieves scores by entity ID and type
|
|
@@ -3181,7 +3235,9 @@ var MastraClient = class extends BaseResource {
|
|
|
3181
3235
|
searchParams.set("perPage", String(perPage));
|
|
3182
3236
|
}
|
|
3183
3237
|
const queryString = searchParams.toString();
|
|
3184
|
-
return this.request(
|
|
3238
|
+
return this.request(
|
|
3239
|
+
`/api/scores/entity/${encodeURIComponent(entityType)}/${encodeURIComponent(entityId)}${queryString ? `?${queryString}` : ""}`
|
|
3240
|
+
);
|
|
3185
3241
|
}
|
|
3186
3242
|
/**
|
|
3187
3243
|
* Saves a score
|
|
@@ -3207,8 +3263,33 @@ var MastraClient = class extends BaseResource {
|
|
|
3207
3263
|
getAITraces(params) {
|
|
3208
3264
|
return this.observability.getTraces(params);
|
|
3209
3265
|
}
|
|
3266
|
+
getScoresBySpan(params) {
|
|
3267
|
+
return this.observability.getScoresBySpan(params);
|
|
3268
|
+
}
|
|
3269
|
+
score(params) {
|
|
3270
|
+
return this.observability.score(params);
|
|
3271
|
+
}
|
|
3210
3272
|
};
|
|
3211
3273
|
|
|
3212
|
-
|
|
3274
|
+
// src/tools.ts
|
|
3275
|
+
var ClientTool = class {
|
|
3276
|
+
id;
|
|
3277
|
+
description;
|
|
3278
|
+
inputSchema;
|
|
3279
|
+
outputSchema;
|
|
3280
|
+
execute;
|
|
3281
|
+
constructor(opts) {
|
|
3282
|
+
this.id = opts.id;
|
|
3283
|
+
this.description = opts.description;
|
|
3284
|
+
this.inputSchema = opts.inputSchema;
|
|
3285
|
+
this.outputSchema = opts.outputSchema;
|
|
3286
|
+
this.execute = opts.execute;
|
|
3287
|
+
}
|
|
3288
|
+
};
|
|
3289
|
+
function createTool(opts) {
|
|
3290
|
+
return new ClientTool(opts);
|
|
3291
|
+
}
|
|
3292
|
+
|
|
3293
|
+
export { ClientTool, MastraClient, createTool };
|
|
3213
3294
|
//# sourceMappingURL=index.js.map
|
|
3214
3295
|
//# sourceMappingURL=index.js.map
|