@mastra/client-js 0.0.0-message-file-url-handling-fix-20250904234524 → 0.0.0-monorepo-binary-20251013210052
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 +492 -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.cjs
CHANGED
|
@@ -21,6 +21,20 @@ function parseClientRuntimeContext(runtimeContext$1) {
|
|
|
21
21
|
}
|
|
22
22
|
return void 0;
|
|
23
23
|
}
|
|
24
|
+
function base64RuntimeContext(runtimeContext) {
|
|
25
|
+
if (runtimeContext) {
|
|
26
|
+
return btoa(JSON.stringify(runtimeContext));
|
|
27
|
+
}
|
|
28
|
+
return void 0;
|
|
29
|
+
}
|
|
30
|
+
function runtimeContextQueryString(runtimeContext) {
|
|
31
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
32
|
+
if (!runtimeContextParam) return "";
|
|
33
|
+
const searchParams = new URLSearchParams();
|
|
34
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
35
|
+
const queryString = searchParams.toString();
|
|
36
|
+
return queryString ? `?${queryString}` : "";
|
|
37
|
+
}
|
|
24
38
|
function isZodType(value) {
|
|
25
39
|
return typeof value === "object" && value !== null && "_def" in value && "parse" in value && typeof value.parse === "function" && "safeParse" in value && typeof value.safeParse === "function";
|
|
26
40
|
}
|
|
@@ -32,7 +46,7 @@ function zodToJsonSchema(zodSchema) {
|
|
|
32
46
|
const fn = "toJSONSchema";
|
|
33
47
|
return zod.z[fn].call(zod.z, zodSchema);
|
|
34
48
|
}
|
|
35
|
-
return originalZodToJsonSchema__default.default(zodSchema, { $refStrategy: "
|
|
49
|
+
return originalZodToJsonSchema__default.default(zodSchema, { $refStrategy: "relative" });
|
|
36
50
|
}
|
|
37
51
|
|
|
38
52
|
// src/utils/process-client-tools.ts
|
|
@@ -65,7 +79,7 @@ function processClientTools(clientTools) {
|
|
|
65
79
|
}
|
|
66
80
|
|
|
67
81
|
// src/utils/process-mastra-stream.ts
|
|
68
|
-
async function
|
|
82
|
+
async function sharedProcessMastraStream({
|
|
69
83
|
stream,
|
|
70
84
|
onChunk
|
|
71
85
|
}) {
|
|
@@ -83,7 +97,7 @@ async function processMastraStream({
|
|
|
83
97
|
if (line.startsWith("data: ")) {
|
|
84
98
|
const data = line.slice(6);
|
|
85
99
|
if (data === "[DONE]") {
|
|
86
|
-
console.
|
|
100
|
+
console.info("\u{1F3C1} Stream finished");
|
|
87
101
|
return;
|
|
88
102
|
}
|
|
89
103
|
try {
|
|
@@ -99,6 +113,24 @@ async function processMastraStream({
|
|
|
99
113
|
reader.releaseLock();
|
|
100
114
|
}
|
|
101
115
|
}
|
|
116
|
+
async function processMastraNetworkStream({
|
|
117
|
+
stream,
|
|
118
|
+
onChunk
|
|
119
|
+
}) {
|
|
120
|
+
return sharedProcessMastraStream({
|
|
121
|
+
stream,
|
|
122
|
+
onChunk
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
async function processMastraStream({
|
|
126
|
+
stream,
|
|
127
|
+
onChunk
|
|
128
|
+
}) {
|
|
129
|
+
return sharedProcessMastraStream({
|
|
130
|
+
stream,
|
|
131
|
+
onChunk
|
|
132
|
+
});
|
|
133
|
+
}
|
|
102
134
|
|
|
103
135
|
// src/resources/base.ts
|
|
104
136
|
var BaseResource = class {
|
|
@@ -187,7 +219,9 @@ async function executeToolCallAndRespond({
|
|
|
187
219
|
resourceId,
|
|
188
220
|
threadId,
|
|
189
221
|
runtimeContext,
|
|
190
|
-
tracingContext: { currentSpan: void 0 }
|
|
222
|
+
tracingContext: { currentSpan: void 0 },
|
|
223
|
+
suspend: async () => {
|
|
224
|
+
}
|
|
191
225
|
},
|
|
192
226
|
{
|
|
193
227
|
messages: response.messages,
|
|
@@ -195,11 +229,7 @@ async function executeToolCallAndRespond({
|
|
|
195
229
|
}
|
|
196
230
|
);
|
|
197
231
|
const updatedMessages = [
|
|
198
|
-
|
|
199
|
-
role: "user",
|
|
200
|
-
content: params.messages
|
|
201
|
-
},
|
|
202
|
-
...response.response.messages,
|
|
232
|
+
...response.response.messages || [],
|
|
203
233
|
{
|
|
204
234
|
role: "tool",
|
|
205
235
|
content: [
|
|
@@ -261,17 +291,21 @@ var AgentVoice = class extends BaseResource {
|
|
|
261
291
|
}
|
|
262
292
|
/**
|
|
263
293
|
* Get available speakers for the agent's voice provider
|
|
294
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
295
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
264
296
|
* @returns Promise containing list of available speakers
|
|
265
297
|
*/
|
|
266
|
-
getSpeakers() {
|
|
267
|
-
return this.request(`/api/agents/${this.agentId}/voice/speakers`);
|
|
298
|
+
getSpeakers(runtimeContext) {
|
|
299
|
+
return this.request(`/api/agents/${this.agentId}/voice/speakers${runtimeContextQueryString(runtimeContext)}`);
|
|
268
300
|
}
|
|
269
301
|
/**
|
|
270
302
|
* Get the listener configuration for the agent's voice provider
|
|
303
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
304
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
271
305
|
* @returns Promise containing a check if the agent has listening capabilities
|
|
272
306
|
*/
|
|
273
|
-
getListener() {
|
|
274
|
-
return this.request(`/api/agents/${this.agentId}/voice/listener`);
|
|
307
|
+
getListener(runtimeContext) {
|
|
308
|
+
return this.request(`/api/agents/${this.agentId}/voice/listener${runtimeContextQueryString(runtimeContext)}`);
|
|
275
309
|
}
|
|
276
310
|
};
|
|
277
311
|
var Agent = class extends BaseResource {
|
|
@@ -283,16 +317,11 @@ var Agent = class extends BaseResource {
|
|
|
283
317
|
voice;
|
|
284
318
|
/**
|
|
285
319
|
* Retrieves details about the agent
|
|
320
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
286
321
|
* @returns Promise containing agent details including model and instructions
|
|
287
322
|
*/
|
|
288
|
-
details() {
|
|
289
|
-
return this.request(`/api/agents/${this.agentId}`);
|
|
290
|
-
}
|
|
291
|
-
async generate(params) {
|
|
292
|
-
console.warn(
|
|
293
|
-
"Deprecation NOTICE:Generate method will switch to use generateVNext implementation September 16th. Please use generateLegacy if you don't want to upgrade just yet."
|
|
294
|
-
);
|
|
295
|
-
return this.generateLegacy(params);
|
|
323
|
+
details(runtimeContext) {
|
|
324
|
+
return this.request(`/api/agents/${this.agentId}${runtimeContextQueryString(runtimeContext)}`);
|
|
296
325
|
}
|
|
297
326
|
async generateLegacy(params) {
|
|
298
327
|
const processedParams = {
|
|
@@ -325,7 +354,9 @@ var Agent = class extends BaseResource {
|
|
|
325
354
|
resourceId,
|
|
326
355
|
threadId,
|
|
327
356
|
runtimeContext,
|
|
328
|
-
tracingContext: { currentSpan: void 0 }
|
|
357
|
+
tracingContext: { currentSpan: void 0 },
|
|
358
|
+
suspend: async () => {
|
|
359
|
+
}
|
|
329
360
|
},
|
|
330
361
|
{
|
|
331
362
|
messages: response.messages,
|
|
@@ -333,10 +364,6 @@ var Agent = class extends BaseResource {
|
|
|
333
364
|
}
|
|
334
365
|
);
|
|
335
366
|
const updatedMessages = [
|
|
336
|
-
{
|
|
337
|
-
role: "user",
|
|
338
|
-
content: params.messages
|
|
339
|
-
},
|
|
340
367
|
...response.response.messages,
|
|
341
368
|
{
|
|
342
369
|
role: "tool",
|
|
@@ -359,16 +386,29 @@ var Agent = class extends BaseResource {
|
|
|
359
386
|
}
|
|
360
387
|
return response;
|
|
361
388
|
}
|
|
362
|
-
async
|
|
389
|
+
async generate(messagesOrParams, options) {
|
|
390
|
+
let params;
|
|
391
|
+
if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
|
|
392
|
+
params = messagesOrParams;
|
|
393
|
+
} else {
|
|
394
|
+
params = {
|
|
395
|
+
messages: messagesOrParams,
|
|
396
|
+
...options
|
|
397
|
+
};
|
|
398
|
+
}
|
|
363
399
|
const processedParams = {
|
|
364
400
|
...params,
|
|
365
401
|
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
366
402
|
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
367
|
-
clientTools: processClientTools(params.clientTools)
|
|
403
|
+
clientTools: processClientTools(params.clientTools),
|
|
404
|
+
structuredOutput: params.structuredOutput ? {
|
|
405
|
+
...params.structuredOutput,
|
|
406
|
+
schema: zodToJsonSchema(params.structuredOutput.schema)
|
|
407
|
+
} : void 0
|
|
368
408
|
};
|
|
369
409
|
const { runId, resourceId, threadId, runtimeContext } = processedParams;
|
|
370
410
|
const response = await this.request(
|
|
371
|
-
`/api/agents/${this.agentId}/generate
|
|
411
|
+
`/api/agents/${this.agentId}/generate`,
|
|
372
412
|
{
|
|
373
413
|
method: "POST",
|
|
374
414
|
body: processedParams
|
|
@@ -382,7 +422,7 @@ var Agent = class extends BaseResource {
|
|
|
382
422
|
resourceId,
|
|
383
423
|
threadId,
|
|
384
424
|
runtimeContext,
|
|
385
|
-
respondFn: this.
|
|
425
|
+
respondFn: this.generate.bind(this)
|
|
386
426
|
});
|
|
387
427
|
}
|
|
388
428
|
return response;
|
|
@@ -649,17 +689,6 @@ var Agent = class extends BaseResource {
|
|
|
649
689
|
});
|
|
650
690
|
onFinish?.({ message, finishReason, usage });
|
|
651
691
|
}
|
|
652
|
-
/**
|
|
653
|
-
* Streams a response from the agent
|
|
654
|
-
* @param params - Stream parameters including prompt
|
|
655
|
-
* @returns Promise containing the enhanced Response object with processDataStream method
|
|
656
|
-
*/
|
|
657
|
-
async stream(params) {
|
|
658
|
-
console.warn(
|
|
659
|
-
"Deprecation NOTICE:\nStream method will switch to use streamVNext implementation September 16th. Please use streamLegacy if you don't want to upgrade just yet."
|
|
660
|
-
);
|
|
661
|
-
return this.streamLegacy(params);
|
|
662
|
-
}
|
|
663
692
|
/**
|
|
664
693
|
* Streams a response from the agent
|
|
665
694
|
* @param params - Stream parameters including prompt
|
|
@@ -674,7 +703,7 @@ var Agent = class extends BaseResource {
|
|
|
674
703
|
clientTools: processClientTools(params.clientTools)
|
|
675
704
|
};
|
|
676
705
|
const { readable, writable } = new TransformStream();
|
|
677
|
-
const response = await this.
|
|
706
|
+
const response = await this.processStreamResponseLegacy(processedParams, writable);
|
|
678
707
|
const streamResponse = new Response(readable, {
|
|
679
708
|
status: response.status,
|
|
680
709
|
statusText: response.statusText,
|
|
@@ -761,6 +790,14 @@ var Agent = class extends BaseResource {
|
|
|
761
790
|
// but this is completely wrong and this fn is probably broken. Remove ":any" and you'll see a bunch of type errors
|
|
762
791
|
onChunk: async (chunk) => {
|
|
763
792
|
switch (chunk.type) {
|
|
793
|
+
case "tripwire": {
|
|
794
|
+
message.parts.push({
|
|
795
|
+
type: "text",
|
|
796
|
+
text: chunk.payload.tripwireReason
|
|
797
|
+
});
|
|
798
|
+
execUpdate();
|
|
799
|
+
break;
|
|
800
|
+
}
|
|
764
801
|
case "step-start": {
|
|
765
802
|
if (!replaceLastMessage) {
|
|
766
803
|
message.id = chunk.payload.messageId;
|
|
@@ -869,7 +906,7 @@ var Agent = class extends BaseResource {
|
|
|
869
906
|
step,
|
|
870
907
|
toolCallId: chunk.payload.toolCallId,
|
|
871
908
|
toolName: chunk.payload.toolName,
|
|
872
|
-
args:
|
|
909
|
+
args: chunk.payload.args
|
|
873
910
|
};
|
|
874
911
|
message.toolInvocations.push(invocation);
|
|
875
912
|
updateToolInvocationPart(chunk.payload.toolCallId, invocation);
|
|
@@ -923,14 +960,14 @@ var Agent = class extends BaseResource {
|
|
|
923
960
|
}
|
|
924
961
|
case "step-finish": {
|
|
925
962
|
step += 1;
|
|
926
|
-
currentTextPart = chunk.payload.isContinued ? currentTextPart : void 0;
|
|
963
|
+
currentTextPart = chunk.payload.stepResult.isContinued ? currentTextPart : void 0;
|
|
927
964
|
currentReasoningPart = void 0;
|
|
928
965
|
currentReasoningTextDetail = void 0;
|
|
929
966
|
execUpdate();
|
|
930
967
|
break;
|
|
931
968
|
}
|
|
932
969
|
case "finish": {
|
|
933
|
-
finishReason = chunk.payload.
|
|
970
|
+
finishReason = chunk.payload.stepResult.reason;
|
|
934
971
|
if (chunk.payload.usage != null) {
|
|
935
972
|
usage = chunk.payload.usage;
|
|
936
973
|
}
|
|
@@ -941,8 +978,8 @@ var Agent = class extends BaseResource {
|
|
|
941
978
|
});
|
|
942
979
|
onFinish?.({ message, finishReason, usage });
|
|
943
980
|
}
|
|
944
|
-
async
|
|
945
|
-
const response = await this.request(`/api/agents/${this.agentId}/stream
|
|
981
|
+
async processStreamResponse(processedParams, writable) {
|
|
982
|
+
const response = await this.request(`/api/agents/${this.agentId}/stream`, {
|
|
946
983
|
method: "POST",
|
|
947
984
|
body: processedParams,
|
|
948
985
|
stream: true
|
|
@@ -954,9 +991,27 @@ var Agent = class extends BaseResource {
|
|
|
954
991
|
let toolCalls = [];
|
|
955
992
|
let messages = [];
|
|
956
993
|
const [streamForWritable, streamForProcessing] = response.body.tee();
|
|
957
|
-
streamForWritable.pipeTo(
|
|
958
|
-
|
|
959
|
-
|
|
994
|
+
streamForWritable.pipeTo(
|
|
995
|
+
new WritableStream({
|
|
996
|
+
async write(chunk) {
|
|
997
|
+
let writer;
|
|
998
|
+
try {
|
|
999
|
+
writer = writable.getWriter();
|
|
1000
|
+
const text = new TextDecoder().decode(chunk);
|
|
1001
|
+
const lines = text.split("\n\n");
|
|
1002
|
+
const readableLines = lines.filter((line) => line !== "[DONE]").join("\n\n");
|
|
1003
|
+
await writer.write(new TextEncoder().encode(readableLines));
|
|
1004
|
+
} catch {
|
|
1005
|
+
await writer?.write(chunk);
|
|
1006
|
+
} finally {
|
|
1007
|
+
writer?.releaseLock();
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
}),
|
|
1011
|
+
{
|
|
1012
|
+
preventClose: true
|
|
1013
|
+
}
|
|
1014
|
+
).catch((error) => {
|
|
960
1015
|
console.error("Error piping to writable stream:", error);
|
|
961
1016
|
});
|
|
962
1017
|
this.processChatResponse_vNext({
|
|
@@ -975,9 +1030,11 @@ var Agent = class extends BaseResource {
|
|
|
975
1030
|
if (toolCall) {
|
|
976
1031
|
toolCalls.push(toolCall);
|
|
977
1032
|
}
|
|
1033
|
+
let shouldExecuteClientTool = false;
|
|
978
1034
|
for (const toolCall2 of toolCalls) {
|
|
979
1035
|
const clientTool = processedParams.clientTools?.[toolCall2.toolName];
|
|
980
1036
|
if (clientTool && clientTool.execute) {
|
|
1037
|
+
shouldExecuteClientTool = true;
|
|
981
1038
|
const result = await clientTool.execute(
|
|
982
1039
|
{
|
|
983
1040
|
context: toolCall2?.args,
|
|
@@ -986,14 +1043,17 @@ var Agent = class extends BaseResource {
|
|
|
986
1043
|
threadId: processedParams.threadId,
|
|
987
1044
|
runtimeContext: processedParams.runtimeContext,
|
|
988
1045
|
// TODO: Pass proper tracing context when client-js supports tracing
|
|
989
|
-
tracingContext: { currentSpan: void 0 }
|
|
1046
|
+
tracingContext: { currentSpan: void 0 },
|
|
1047
|
+
suspend: async () => {
|
|
1048
|
+
}
|
|
990
1049
|
},
|
|
991
1050
|
{
|
|
992
1051
|
messages: response.messages,
|
|
993
1052
|
toolCallId: toolCall2?.toolCallId
|
|
994
1053
|
}
|
|
995
1054
|
);
|
|
996
|
-
const
|
|
1055
|
+
const lastMessageRaw = messages[messages.length - 1];
|
|
1056
|
+
const lastMessage = lastMessageRaw != null ? JSON.parse(JSON.stringify(lastMessageRaw)) : void 0;
|
|
997
1057
|
const toolInvocationPart = lastMessage?.parts?.find(
|
|
998
1058
|
(part) => part.type === "tool-invocation" && part.toolInvocation?.toolCallId === toolCall2.toolCallId
|
|
999
1059
|
);
|
|
@@ -1011,25 +1071,11 @@ var Agent = class extends BaseResource {
|
|
|
1011
1071
|
toolInvocation.state = "result";
|
|
1012
1072
|
toolInvocation.result = result;
|
|
1013
1073
|
}
|
|
1014
|
-
const
|
|
1015
|
-
|
|
1016
|
-
await writer.write(
|
|
1017
|
-
new TextEncoder().encode(
|
|
1018
|
-
"a:" + JSON.stringify({
|
|
1019
|
-
toolCallId: toolCall2.toolCallId,
|
|
1020
|
-
result
|
|
1021
|
-
}) + "\n"
|
|
1022
|
-
)
|
|
1023
|
-
);
|
|
1024
|
-
} finally {
|
|
1025
|
-
writer.releaseLock();
|
|
1026
|
-
}
|
|
1027
|
-
const originalMessages = processedParams.messages;
|
|
1028
|
-
const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
|
|
1029
|
-
this.processStreamResponse_vNext(
|
|
1074
|
+
const updatedMessages = lastMessage != null ? [...messages.filter((m) => m.id !== lastMessage.id), lastMessage] : [...messages];
|
|
1075
|
+
this.processStreamResponse(
|
|
1030
1076
|
{
|
|
1031
1077
|
...processedParams,
|
|
1032
|
-
messages:
|
|
1078
|
+
messages: updatedMessages
|
|
1033
1079
|
},
|
|
1034
1080
|
writable
|
|
1035
1081
|
).catch((error) => {
|
|
@@ -1037,6 +1083,11 @@ var Agent = class extends BaseResource {
|
|
|
1037
1083
|
});
|
|
1038
1084
|
}
|
|
1039
1085
|
}
|
|
1086
|
+
if (!shouldExecuteClientTool) {
|
|
1087
|
+
setTimeout(() => {
|
|
1088
|
+
writable.close();
|
|
1089
|
+
}, 0);
|
|
1090
|
+
}
|
|
1040
1091
|
} else {
|
|
1041
1092
|
setTimeout(() => {
|
|
1042
1093
|
writable.close();
|
|
@@ -1052,15 +1103,52 @@ var Agent = class extends BaseResource {
|
|
|
1052
1103
|
}
|
|
1053
1104
|
return response;
|
|
1054
1105
|
}
|
|
1055
|
-
async
|
|
1106
|
+
async network(params) {
|
|
1107
|
+
const response = await this.request(`/api/agents/${this.agentId}/network`, {
|
|
1108
|
+
method: "POST",
|
|
1109
|
+
body: params,
|
|
1110
|
+
stream: true
|
|
1111
|
+
});
|
|
1112
|
+
if (!response.body) {
|
|
1113
|
+
throw new Error("No response body");
|
|
1114
|
+
}
|
|
1115
|
+
const streamResponse = new Response(response.body, {
|
|
1116
|
+
status: response.status,
|
|
1117
|
+
statusText: response.statusText,
|
|
1118
|
+
headers: response.headers
|
|
1119
|
+
});
|
|
1120
|
+
streamResponse.processDataStream = async ({
|
|
1121
|
+
onChunk
|
|
1122
|
+
}) => {
|
|
1123
|
+
await processMastraNetworkStream({
|
|
1124
|
+
stream: streamResponse.body,
|
|
1125
|
+
onChunk
|
|
1126
|
+
});
|
|
1127
|
+
};
|
|
1128
|
+
return streamResponse;
|
|
1129
|
+
}
|
|
1130
|
+
async stream(messagesOrParams, options) {
|
|
1131
|
+
let params;
|
|
1132
|
+
if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
|
|
1133
|
+
params = messagesOrParams;
|
|
1134
|
+
} else {
|
|
1135
|
+
params = {
|
|
1136
|
+
messages: messagesOrParams,
|
|
1137
|
+
...options
|
|
1138
|
+
};
|
|
1139
|
+
}
|
|
1056
1140
|
const processedParams = {
|
|
1057
1141
|
...params,
|
|
1058
1142
|
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
1059
1143
|
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
1060
|
-
clientTools: processClientTools(params.clientTools)
|
|
1144
|
+
clientTools: processClientTools(params.clientTools),
|
|
1145
|
+
structuredOutput: params.structuredOutput ? {
|
|
1146
|
+
...params.structuredOutput,
|
|
1147
|
+
schema: zodToJsonSchema(params.structuredOutput.schema)
|
|
1148
|
+
} : void 0
|
|
1061
1149
|
};
|
|
1062
1150
|
const { readable, writable } = new TransformStream();
|
|
1063
|
-
const response = await this.
|
|
1151
|
+
const response = await this.processStreamResponse(processedParams, writable);
|
|
1064
1152
|
const streamResponse = new Response(readable, {
|
|
1065
1153
|
status: response.status,
|
|
1066
1154
|
statusText: response.statusText,
|
|
@@ -1079,7 +1167,7 @@ var Agent = class extends BaseResource {
|
|
|
1079
1167
|
/**
|
|
1080
1168
|
* Processes the stream response and handles tool calls
|
|
1081
1169
|
*/
|
|
1082
|
-
async
|
|
1170
|
+
async processStreamResponseLegacy(processedParams, writable) {
|
|
1083
1171
|
const response = await this.request(`/api/agents/${this.agentId}/stream-legacy`, {
|
|
1084
1172
|
method: "POST",
|
|
1085
1173
|
body: processedParams,
|
|
@@ -1124,7 +1212,9 @@ var Agent = class extends BaseResource {
|
|
|
1124
1212
|
threadId: processedParams.threadId,
|
|
1125
1213
|
runtimeContext: processedParams.runtimeContext,
|
|
1126
1214
|
// TODO: Pass proper tracing context when client-js supports tracing
|
|
1127
|
-
tracingContext: { currentSpan: void 0 }
|
|
1215
|
+
tracingContext: { currentSpan: void 0 },
|
|
1216
|
+
suspend: async () => {
|
|
1217
|
+
}
|
|
1128
1218
|
},
|
|
1129
1219
|
{
|
|
1130
1220
|
messages: response.messages,
|
|
@@ -1162,12 +1252,10 @@ var Agent = class extends BaseResource {
|
|
|
1162
1252
|
} finally {
|
|
1163
1253
|
writer.releaseLock();
|
|
1164
1254
|
}
|
|
1165
|
-
|
|
1166
|
-
const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
|
|
1167
|
-
this.processStreamResponse(
|
|
1255
|
+
this.processStreamResponseLegacy(
|
|
1168
1256
|
{
|
|
1169
1257
|
...processedParams,
|
|
1170
|
-
messages: [...
|
|
1258
|
+
messages: [...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
|
|
1171
1259
|
},
|
|
1172
1260
|
writable
|
|
1173
1261
|
).catch((error) => {
|
|
@@ -1193,10 +1281,11 @@ var Agent = class extends BaseResource {
|
|
|
1193
1281
|
/**
|
|
1194
1282
|
* Gets details about a specific tool available to the agent
|
|
1195
1283
|
* @param toolId - ID of the tool to retrieve
|
|
1284
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1196
1285
|
* @returns Promise containing tool details
|
|
1197
1286
|
*/
|
|
1198
|
-
getTool(toolId) {
|
|
1199
|
-
return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
|
|
1287
|
+
getTool(toolId, runtimeContext) {
|
|
1288
|
+
return this.request(`/api/agents/${this.agentId}/tools/${toolId}${runtimeContextQueryString(runtimeContext)}`);
|
|
1200
1289
|
}
|
|
1201
1290
|
/**
|
|
1202
1291
|
* Executes a tool for the agent
|
|
@@ -1207,7 +1296,7 @@ var Agent = class extends BaseResource {
|
|
|
1207
1296
|
executeTool(toolId, params) {
|
|
1208
1297
|
const body = {
|
|
1209
1298
|
data: params.data,
|
|
1210
|
-
runtimeContext:
|
|
1299
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1211
1300
|
};
|
|
1212
1301
|
return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
|
|
1213
1302
|
method: "POST",
|
|
@@ -1216,17 +1305,19 @@ var Agent = class extends BaseResource {
|
|
|
1216
1305
|
}
|
|
1217
1306
|
/**
|
|
1218
1307
|
* Retrieves evaluation results for the agent
|
|
1308
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1219
1309
|
* @returns Promise containing agent evaluations
|
|
1220
1310
|
*/
|
|
1221
|
-
evals() {
|
|
1222
|
-
return this.request(`/api/agents/${this.agentId}/evals/ci`);
|
|
1311
|
+
evals(runtimeContext) {
|
|
1312
|
+
return this.request(`/api/agents/${this.agentId}/evals/ci${runtimeContextQueryString(runtimeContext)}`);
|
|
1223
1313
|
}
|
|
1224
1314
|
/**
|
|
1225
1315
|
* Retrieves live evaluation results for the agent
|
|
1316
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1226
1317
|
* @returns Promise containing live agent evaluations
|
|
1227
1318
|
*/
|
|
1228
|
-
liveEvals() {
|
|
1229
|
-
return this.request(`/api/agents/${this.agentId}/evals/live`);
|
|
1319
|
+
liveEvals(runtimeContext) {
|
|
1320
|
+
return this.request(`/api/agents/${this.agentId}/evals/live${runtimeContextQueryString(runtimeContext)}`);
|
|
1230
1321
|
}
|
|
1231
1322
|
/**
|
|
1232
1323
|
* Updates the model for the agent
|
|
@@ -1239,61 +1330,33 @@ var Agent = class extends BaseResource {
|
|
|
1239
1330
|
body: params
|
|
1240
1331
|
});
|
|
1241
1332
|
}
|
|
1242
|
-
};
|
|
1243
|
-
var Network = class extends BaseResource {
|
|
1244
|
-
constructor(options, networkId) {
|
|
1245
|
-
super(options);
|
|
1246
|
-
this.networkId = networkId;
|
|
1247
|
-
}
|
|
1248
1333
|
/**
|
|
1249
|
-
*
|
|
1250
|
-
* @
|
|
1251
|
-
|
|
1252
|
-
details() {
|
|
1253
|
-
return this.request(`/api/networks/${this.networkId}`);
|
|
1254
|
-
}
|
|
1255
|
-
/**
|
|
1256
|
-
* Generates a response from the agent
|
|
1257
|
-
* @param params - Generation parameters including prompt
|
|
1258
|
-
* @returns Promise containing the generated response
|
|
1334
|
+
* Updates the model for the agent in the model list
|
|
1335
|
+
* @param params - Parameters for updating the model
|
|
1336
|
+
* @returns Promise containing the updated model
|
|
1259
1337
|
*/
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
...params,
|
|
1263
|
-
output: zodToJsonSchema(params.output),
|
|
1264
|
-
experimental_output: zodToJsonSchema(params.experimental_output)
|
|
1265
|
-
};
|
|
1266
|
-
return this.request(`/api/networks/${this.networkId}/generate`, {
|
|
1338
|
+
updateModelInModelList({ modelConfigId, ...params }) {
|
|
1339
|
+
return this.request(`/api/agents/${this.agentId}/models/${modelConfigId}`, {
|
|
1267
1340
|
method: "POST",
|
|
1268
|
-
body:
|
|
1341
|
+
body: params
|
|
1269
1342
|
});
|
|
1270
1343
|
}
|
|
1271
1344
|
/**
|
|
1272
|
-
*
|
|
1273
|
-
* @param params -
|
|
1274
|
-
* @returns Promise containing the
|
|
1345
|
+
* Reorders the models for the agent
|
|
1346
|
+
* @param params - Parameters for reordering the model list
|
|
1347
|
+
* @returns Promise containing the updated model list
|
|
1275
1348
|
*/
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
...params,
|
|
1279
|
-
output: zodToJsonSchema(params.output),
|
|
1280
|
-
experimental_output: zodToJsonSchema(params.experimental_output)
|
|
1281
|
-
};
|
|
1282
|
-
const response = await this.request(`/api/networks/${this.networkId}/stream`, {
|
|
1349
|
+
reorderModelList(params) {
|
|
1350
|
+
return this.request(`/api/agents/${this.agentId}/models/reorder`, {
|
|
1283
1351
|
method: "POST",
|
|
1284
|
-
body:
|
|
1285
|
-
stream: true
|
|
1352
|
+
body: params
|
|
1286
1353
|
});
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
...options
|
|
1294
|
-
});
|
|
1295
|
-
};
|
|
1296
|
-
return response;
|
|
1354
|
+
}
|
|
1355
|
+
async generateVNext(_messagesOrParams, _options) {
|
|
1356
|
+
throw new Error("generateVNext has been renamed to generate. Please use generate instead.");
|
|
1357
|
+
}
|
|
1358
|
+
async streamVNext(_messagesOrParams, _options) {
|
|
1359
|
+
throw new Error("streamVNext has been renamed to stream. Please use stream instead.");
|
|
1297
1360
|
}
|
|
1298
1361
|
};
|
|
1299
1362
|
|
|
@@ -1384,10 +1447,13 @@ var Vector = class extends BaseResource {
|
|
|
1384
1447
|
/**
|
|
1385
1448
|
* Retrieves details about a specific vector index
|
|
1386
1449
|
* @param indexName - Name of the index to get details for
|
|
1450
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1387
1451
|
* @returns Promise containing vector index details
|
|
1388
1452
|
*/
|
|
1389
|
-
details(indexName) {
|
|
1390
|
-
return this.request(
|
|
1453
|
+
details(indexName, runtimeContext) {
|
|
1454
|
+
return this.request(
|
|
1455
|
+
`/api/vector/${this.vectorName}/indexes/${indexName}${runtimeContextQueryString(runtimeContext)}`
|
|
1456
|
+
);
|
|
1391
1457
|
}
|
|
1392
1458
|
/**
|
|
1393
1459
|
* Deletes a vector index
|
|
@@ -1401,10 +1467,11 @@ var Vector = class extends BaseResource {
|
|
|
1401
1467
|
}
|
|
1402
1468
|
/**
|
|
1403
1469
|
* Retrieves a list of all available indexes
|
|
1470
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1404
1471
|
* @returns Promise containing array of index names
|
|
1405
1472
|
*/
|
|
1406
|
-
getIndexes() {
|
|
1407
|
-
return this.request(`/api/vector/${this.vectorName}/indexes`);
|
|
1473
|
+
getIndexes(runtimeContext) {
|
|
1474
|
+
return this.request(`/api/vector/${this.vectorName}/indexes${runtimeContextQueryString(runtimeContext)}`);
|
|
1408
1475
|
}
|
|
1409
1476
|
/**
|
|
1410
1477
|
* Creates a new vector index
|
|
@@ -1441,123 +1508,50 @@ var Vector = class extends BaseResource {
|
|
|
1441
1508
|
}
|
|
1442
1509
|
};
|
|
1443
1510
|
|
|
1444
|
-
// src/resources/
|
|
1445
|
-
var
|
|
1446
|
-
|
|
1447
|
-
constructor(options, workflowId) {
|
|
1511
|
+
// src/resources/tool.ts
|
|
1512
|
+
var Tool = class extends BaseResource {
|
|
1513
|
+
constructor(options, toolId) {
|
|
1448
1514
|
super(options);
|
|
1449
|
-
this.
|
|
1450
|
-
}
|
|
1451
|
-
/**
|
|
1452
|
-
* Retrieves details about the legacy workflow
|
|
1453
|
-
* @returns Promise containing legacy workflow details including steps and graphs
|
|
1454
|
-
*/
|
|
1455
|
-
details() {
|
|
1456
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}`);
|
|
1457
|
-
}
|
|
1458
|
-
/**
|
|
1459
|
-
* Retrieves all runs for a legacy workflow
|
|
1460
|
-
* @param params - Parameters for filtering runs
|
|
1461
|
-
* @returns Promise containing legacy workflow runs array
|
|
1462
|
-
*/
|
|
1463
|
-
runs(params) {
|
|
1464
|
-
const searchParams = new URLSearchParams();
|
|
1465
|
-
if (params?.fromDate) {
|
|
1466
|
-
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
1467
|
-
}
|
|
1468
|
-
if (params?.toDate) {
|
|
1469
|
-
searchParams.set("toDate", params.toDate.toISOString());
|
|
1470
|
-
}
|
|
1471
|
-
if (params?.limit) {
|
|
1472
|
-
searchParams.set("limit", String(params.limit));
|
|
1473
|
-
}
|
|
1474
|
-
if (params?.offset) {
|
|
1475
|
-
searchParams.set("offset", String(params.offset));
|
|
1476
|
-
}
|
|
1477
|
-
if (params?.resourceId) {
|
|
1478
|
-
searchParams.set("resourceId", params.resourceId);
|
|
1479
|
-
}
|
|
1480
|
-
if (searchParams.size) {
|
|
1481
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/runs?${searchParams}`);
|
|
1482
|
-
} else {
|
|
1483
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/runs`);
|
|
1484
|
-
}
|
|
1485
|
-
}
|
|
1486
|
-
/**
|
|
1487
|
-
* Creates a new legacy workflow run
|
|
1488
|
-
* @returns Promise containing the generated run ID
|
|
1489
|
-
*/
|
|
1490
|
-
createRun(params) {
|
|
1491
|
-
const searchParams = new URLSearchParams();
|
|
1492
|
-
if (!!params?.runId) {
|
|
1493
|
-
searchParams.set("runId", params.runId);
|
|
1494
|
-
}
|
|
1495
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/create-run?${searchParams.toString()}`, {
|
|
1496
|
-
method: "POST"
|
|
1497
|
-
});
|
|
1498
|
-
}
|
|
1499
|
-
/**
|
|
1500
|
-
* Starts a legacy workflow run synchronously without waiting for the workflow to complete
|
|
1501
|
-
* @param params - Object containing the runId and triggerData
|
|
1502
|
-
* @returns Promise containing success message
|
|
1503
|
-
*/
|
|
1504
|
-
start(params) {
|
|
1505
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/start?runId=${params.runId}`, {
|
|
1506
|
-
method: "POST",
|
|
1507
|
-
body: params?.triggerData
|
|
1508
|
-
});
|
|
1515
|
+
this.toolId = toolId;
|
|
1509
1516
|
}
|
|
1510
1517
|
/**
|
|
1511
|
-
*
|
|
1512
|
-
* @param
|
|
1513
|
-
* @
|
|
1514
|
-
* @param context - Context to resume the legacy workflow with
|
|
1515
|
-
* @returns Promise containing the legacy workflow resume results
|
|
1518
|
+
* Retrieves details about the tool
|
|
1519
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1520
|
+
* @returns Promise containing tool details including description and schemas
|
|
1516
1521
|
*/
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
runId,
|
|
1520
|
-
context
|
|
1521
|
-
}) {
|
|
1522
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/resume?runId=${runId}`, {
|
|
1523
|
-
method: "POST",
|
|
1524
|
-
body: {
|
|
1525
|
-
stepId,
|
|
1526
|
-
context
|
|
1527
|
-
}
|
|
1528
|
-
});
|
|
1522
|
+
details(runtimeContext) {
|
|
1523
|
+
return this.request(`/api/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
|
|
1529
1524
|
}
|
|
1530
1525
|
/**
|
|
1531
|
-
*
|
|
1532
|
-
* @param params -
|
|
1533
|
-
* @returns Promise containing the
|
|
1526
|
+
* Executes the tool with the provided parameters
|
|
1527
|
+
* @param params - Parameters required for tool execution
|
|
1528
|
+
* @returns Promise containing the tool execution results
|
|
1534
1529
|
*/
|
|
1535
|
-
|
|
1536
|
-
const
|
|
1537
|
-
if (
|
|
1538
|
-
|
|
1530
|
+
execute(params) {
|
|
1531
|
+
const url = new URLSearchParams();
|
|
1532
|
+
if (params.runId) {
|
|
1533
|
+
url.set("runId", params.runId);
|
|
1539
1534
|
}
|
|
1540
|
-
|
|
1535
|
+
const body = {
|
|
1536
|
+
data: params.data,
|
|
1537
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1538
|
+
};
|
|
1539
|
+
return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
|
|
1541
1540
|
method: "POST",
|
|
1542
|
-
body
|
|
1541
|
+
body
|
|
1543
1542
|
});
|
|
1544
1543
|
}
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
body: {
|
|
1554
|
-
stepId: params.stepId,
|
|
1555
|
-
context: params.context
|
|
1556
|
-
}
|
|
1557
|
-
});
|
|
1544
|
+
};
|
|
1545
|
+
|
|
1546
|
+
// src/resources/workflow.ts
|
|
1547
|
+
var RECORD_SEPARATOR = "";
|
|
1548
|
+
var Workflow = class extends BaseResource {
|
|
1549
|
+
constructor(options, workflowId) {
|
|
1550
|
+
super(options);
|
|
1551
|
+
this.workflowId = workflowId;
|
|
1558
1552
|
}
|
|
1559
1553
|
/**
|
|
1560
|
-
* Creates an async generator that processes a readable stream and yields records
|
|
1554
|
+
* Creates an async generator that processes a readable stream and yields workflow records
|
|
1561
1555
|
* separated by the Record Separator character (\x1E)
|
|
1562
1556
|
*
|
|
1563
1557
|
* @param stream - The readable stream to process
|
|
@@ -1602,125 +1596,21 @@ var LegacyWorkflow = class extends BaseResource {
|
|
|
1602
1596
|
}
|
|
1603
1597
|
}
|
|
1604
1598
|
/**
|
|
1605
|
-
*
|
|
1606
|
-
* @param
|
|
1607
|
-
* @returns
|
|
1608
|
-
*/
|
|
1609
|
-
async watch({ runId }, onRecord) {
|
|
1610
|
-
const response = await this.request(`/api/workflows/legacy/${this.workflowId}/watch?runId=${runId}`, {
|
|
1611
|
-
stream: true
|
|
1612
|
-
});
|
|
1613
|
-
if (!response.ok) {
|
|
1614
|
-
throw new Error(`Failed to watch legacy workflow: ${response.statusText}`);
|
|
1615
|
-
}
|
|
1616
|
-
if (!response.body) {
|
|
1617
|
-
throw new Error("Response body is null");
|
|
1618
|
-
}
|
|
1619
|
-
for await (const record of this.streamProcessor(response.body)) {
|
|
1620
|
-
onRecord(record);
|
|
1621
|
-
}
|
|
1622
|
-
}
|
|
1623
|
-
};
|
|
1624
|
-
|
|
1625
|
-
// src/resources/tool.ts
|
|
1626
|
-
var Tool = class extends BaseResource {
|
|
1627
|
-
constructor(options, toolId) {
|
|
1628
|
-
super(options);
|
|
1629
|
-
this.toolId = toolId;
|
|
1630
|
-
}
|
|
1631
|
-
/**
|
|
1632
|
-
* Retrieves details about the tool
|
|
1633
|
-
* @returns Promise containing tool details including description and schemas
|
|
1599
|
+
* Retrieves details about the workflow
|
|
1600
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1601
|
+
* @returns Promise containing workflow details including steps and graphs
|
|
1634
1602
|
*/
|
|
1635
|
-
details() {
|
|
1636
|
-
return this.request(`/api/
|
|
1603
|
+
details(runtimeContext) {
|
|
1604
|
+
return this.request(`/api/workflows/${this.workflowId}${runtimeContextQueryString(runtimeContext)}`);
|
|
1637
1605
|
}
|
|
1638
1606
|
/**
|
|
1639
|
-
*
|
|
1640
|
-
* @param params - Parameters
|
|
1641
|
-
* @
|
|
1607
|
+
* Retrieves all runs for a workflow
|
|
1608
|
+
* @param params - Parameters for filtering runs
|
|
1609
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1610
|
+
* @returns Promise containing workflow runs array
|
|
1642
1611
|
*/
|
|
1643
|
-
|
|
1644
|
-
const
|
|
1645
|
-
if (params.runId) {
|
|
1646
|
-
url.set("runId", params.runId);
|
|
1647
|
-
}
|
|
1648
|
-
const body = {
|
|
1649
|
-
data: params.data,
|
|
1650
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1651
|
-
};
|
|
1652
|
-
return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
|
|
1653
|
-
method: "POST",
|
|
1654
|
-
body
|
|
1655
|
-
});
|
|
1656
|
-
}
|
|
1657
|
-
};
|
|
1658
|
-
|
|
1659
|
-
// src/resources/workflow.ts
|
|
1660
|
-
var RECORD_SEPARATOR2 = "";
|
|
1661
|
-
var Workflow = class extends BaseResource {
|
|
1662
|
-
constructor(options, workflowId) {
|
|
1663
|
-
super(options);
|
|
1664
|
-
this.workflowId = workflowId;
|
|
1665
|
-
}
|
|
1666
|
-
/**
|
|
1667
|
-
* Creates an async generator that processes a readable stream and yields workflow records
|
|
1668
|
-
* separated by the Record Separator character (\x1E)
|
|
1669
|
-
*
|
|
1670
|
-
* @param stream - The readable stream to process
|
|
1671
|
-
* @returns An async generator that yields parsed records
|
|
1672
|
-
*/
|
|
1673
|
-
async *streamProcessor(stream) {
|
|
1674
|
-
const reader = stream.getReader();
|
|
1675
|
-
let doneReading = false;
|
|
1676
|
-
let buffer = "";
|
|
1677
|
-
try {
|
|
1678
|
-
while (!doneReading) {
|
|
1679
|
-
const { done, value } = await reader.read();
|
|
1680
|
-
doneReading = done;
|
|
1681
|
-
if (done && !value) continue;
|
|
1682
|
-
try {
|
|
1683
|
-
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
1684
|
-
const chunks = (buffer + decoded).split(RECORD_SEPARATOR2);
|
|
1685
|
-
buffer = chunks.pop() || "";
|
|
1686
|
-
for (const chunk of chunks) {
|
|
1687
|
-
if (chunk) {
|
|
1688
|
-
if (typeof chunk === "string") {
|
|
1689
|
-
try {
|
|
1690
|
-
const parsedChunk = JSON.parse(chunk);
|
|
1691
|
-
yield parsedChunk;
|
|
1692
|
-
} catch {
|
|
1693
|
-
}
|
|
1694
|
-
}
|
|
1695
|
-
}
|
|
1696
|
-
}
|
|
1697
|
-
} catch {
|
|
1698
|
-
}
|
|
1699
|
-
}
|
|
1700
|
-
if (buffer) {
|
|
1701
|
-
try {
|
|
1702
|
-
yield JSON.parse(buffer);
|
|
1703
|
-
} catch {
|
|
1704
|
-
}
|
|
1705
|
-
}
|
|
1706
|
-
} finally {
|
|
1707
|
-
reader.cancel().catch(() => {
|
|
1708
|
-
});
|
|
1709
|
-
}
|
|
1710
|
-
}
|
|
1711
|
-
/**
|
|
1712
|
-
* Retrieves details about the workflow
|
|
1713
|
-
* @returns Promise containing workflow details including steps and graphs
|
|
1714
|
-
*/
|
|
1715
|
-
details() {
|
|
1716
|
-
return this.request(`/api/workflows/${this.workflowId}`);
|
|
1717
|
-
}
|
|
1718
|
-
/**
|
|
1719
|
-
* Retrieves all runs for a workflow
|
|
1720
|
-
* @param params - Parameters for filtering runs
|
|
1721
|
-
* @returns Promise containing workflow runs array
|
|
1722
|
-
*/
|
|
1723
|
-
runs(params) {
|
|
1612
|
+
runs(params, runtimeContext) {
|
|
1613
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
1724
1614
|
const searchParams = new URLSearchParams();
|
|
1725
1615
|
if (params?.fromDate) {
|
|
1726
1616
|
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
@@ -1737,6 +1627,9 @@ var Workflow = class extends BaseResource {
|
|
|
1737
1627
|
if (params?.resourceId) {
|
|
1738
1628
|
searchParams.set("resourceId", params.resourceId);
|
|
1739
1629
|
}
|
|
1630
|
+
if (runtimeContextParam) {
|
|
1631
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
1632
|
+
}
|
|
1740
1633
|
if (searchParams.size) {
|
|
1741
1634
|
return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
|
|
1742
1635
|
} else {
|
|
@@ -1746,18 +1639,22 @@ var Workflow = class extends BaseResource {
|
|
|
1746
1639
|
/**
|
|
1747
1640
|
* Retrieves a specific workflow run by its ID
|
|
1748
1641
|
* @param runId - The ID of the workflow run to retrieve
|
|
1642
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1749
1643
|
* @returns Promise containing the workflow run details
|
|
1750
1644
|
*/
|
|
1751
|
-
runById(runId) {
|
|
1752
|
-
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}`);
|
|
1645
|
+
runById(runId, runtimeContext) {
|
|
1646
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}${runtimeContextQueryString(runtimeContext)}`);
|
|
1753
1647
|
}
|
|
1754
1648
|
/**
|
|
1755
1649
|
* Retrieves the execution result for a specific workflow run by its ID
|
|
1756
1650
|
* @param runId - The ID of the workflow run to retrieve the execution result for
|
|
1651
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1757
1652
|
* @returns Promise containing the workflow run execution result
|
|
1758
1653
|
*/
|
|
1759
|
-
runExecutionResult(runId) {
|
|
1760
|
-
return this.request(
|
|
1654
|
+
runExecutionResult(runId, runtimeContext) {
|
|
1655
|
+
return this.request(
|
|
1656
|
+
`/api/workflows/${this.workflowId}/runs/${runId}/execution-result${runtimeContextQueryString(runtimeContext)}`
|
|
1657
|
+
);
|
|
1761
1658
|
}
|
|
1762
1659
|
/**
|
|
1763
1660
|
* Cancels a specific workflow run by its ID
|
|
@@ -1780,27 +1677,83 @@ var Workflow = class extends BaseResource {
|
|
|
1780
1677
|
body: { event: params.event, data: params.data }
|
|
1781
1678
|
});
|
|
1782
1679
|
}
|
|
1680
|
+
/**
|
|
1681
|
+
* @deprecated Use createRunAsync() instead.
|
|
1682
|
+
* @throws {Error} Always throws an error directing users to use createRunAsync()
|
|
1683
|
+
*/
|
|
1684
|
+
async createRun(_params) {
|
|
1685
|
+
throw new Error(
|
|
1686
|
+
"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."
|
|
1687
|
+
);
|
|
1688
|
+
}
|
|
1783
1689
|
/**
|
|
1784
1690
|
* Creates a new workflow run
|
|
1785
1691
|
* @param params - Optional object containing the optional runId
|
|
1786
|
-
* @returns Promise containing the runId of the created run
|
|
1692
|
+
* @returns Promise containing the runId of the created run with methods to control execution
|
|
1787
1693
|
*/
|
|
1788
|
-
|
|
1694
|
+
async createRunAsync(params) {
|
|
1789
1695
|
const searchParams = new URLSearchParams();
|
|
1790
1696
|
if (!!params?.runId) {
|
|
1791
1697
|
searchParams.set("runId", params.runId);
|
|
1792
1698
|
}
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1699
|
+
const res = await this.request(
|
|
1700
|
+
`/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`,
|
|
1701
|
+
{
|
|
1702
|
+
method: "POST"
|
|
1703
|
+
}
|
|
1704
|
+
);
|
|
1705
|
+
const runId = res.runId;
|
|
1706
|
+
return {
|
|
1707
|
+
runId,
|
|
1708
|
+
start: async (p) => {
|
|
1709
|
+
return this.start({
|
|
1710
|
+
runId,
|
|
1711
|
+
inputData: p.inputData,
|
|
1712
|
+
runtimeContext: p.runtimeContext,
|
|
1713
|
+
tracingOptions: p.tracingOptions
|
|
1714
|
+
});
|
|
1715
|
+
},
|
|
1716
|
+
startAsync: async (p) => {
|
|
1717
|
+
return this.startAsync({
|
|
1718
|
+
runId,
|
|
1719
|
+
inputData: p.inputData,
|
|
1720
|
+
runtimeContext: p.runtimeContext,
|
|
1721
|
+
tracingOptions: p.tracingOptions
|
|
1722
|
+
});
|
|
1723
|
+
},
|
|
1724
|
+
watch: async (onRecord) => {
|
|
1725
|
+
return this.watch({ runId }, onRecord);
|
|
1726
|
+
},
|
|
1727
|
+
stream: async (p) => {
|
|
1728
|
+
return this.stream({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
|
|
1729
|
+
},
|
|
1730
|
+
resume: async (p) => {
|
|
1731
|
+
return this.resume({
|
|
1732
|
+
runId,
|
|
1733
|
+
step: p.step,
|
|
1734
|
+
resumeData: p.resumeData,
|
|
1735
|
+
runtimeContext: p.runtimeContext,
|
|
1736
|
+
tracingOptions: p.tracingOptions
|
|
1737
|
+
});
|
|
1738
|
+
},
|
|
1739
|
+
resumeAsync: async (p) => {
|
|
1740
|
+
return this.resumeAsync({
|
|
1741
|
+
runId,
|
|
1742
|
+
step: p.step,
|
|
1743
|
+
resumeData: p.resumeData,
|
|
1744
|
+
runtimeContext: p.runtimeContext,
|
|
1745
|
+
tracingOptions: p.tracingOptions
|
|
1746
|
+
});
|
|
1747
|
+
},
|
|
1748
|
+
resumeStreamVNext: async (p) => {
|
|
1749
|
+
return this.resumeStreamVNext({
|
|
1750
|
+
runId,
|
|
1751
|
+
step: p.step,
|
|
1752
|
+
resumeData: p.resumeData,
|
|
1753
|
+
runtimeContext: p.runtimeContext
|
|
1754
|
+
});
|
|
1755
|
+
}
|
|
1756
|
+
};
|
|
1804
1757
|
}
|
|
1805
1758
|
/**
|
|
1806
1759
|
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
@@ -1811,7 +1764,7 @@ var Workflow = class extends BaseResource {
|
|
|
1811
1764
|
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1812
1765
|
return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
|
|
1813
1766
|
method: "POST",
|
|
1814
|
-
body: { inputData: params?.inputData, runtimeContext }
|
|
1767
|
+
body: { inputData: params?.inputData, runtimeContext, tracingOptions: params.tracingOptions }
|
|
1815
1768
|
});
|
|
1816
1769
|
}
|
|
1817
1770
|
/**
|
|
@@ -1823,16 +1776,17 @@ var Workflow = class extends BaseResource {
|
|
|
1823
1776
|
step,
|
|
1824
1777
|
runId,
|
|
1825
1778
|
resumeData,
|
|
1779
|
+
tracingOptions,
|
|
1826
1780
|
...rest
|
|
1827
1781
|
}) {
|
|
1828
1782
|
const runtimeContext = parseClientRuntimeContext(rest.runtimeContext);
|
|
1829
1783
|
return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
|
|
1830
1784
|
method: "POST",
|
|
1831
|
-
stream: true,
|
|
1832
1785
|
body: {
|
|
1833
1786
|
step,
|
|
1834
1787
|
resumeData,
|
|
1835
|
-
runtimeContext
|
|
1788
|
+
runtimeContext,
|
|
1789
|
+
tracingOptions
|
|
1836
1790
|
}
|
|
1837
1791
|
});
|
|
1838
1792
|
}
|
|
@@ -1849,7 +1803,7 @@ var Workflow = class extends BaseResource {
|
|
|
1849
1803
|
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1850
1804
|
return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
1851
1805
|
method: "POST",
|
|
1852
|
-
body: { inputData: params.inputData, runtimeContext }
|
|
1806
|
+
body: { inputData: params.inputData, runtimeContext, tracingOptions: params.tracingOptions }
|
|
1853
1807
|
});
|
|
1854
1808
|
}
|
|
1855
1809
|
/**
|
|
@@ -1867,7 +1821,110 @@ var Workflow = class extends BaseResource {
|
|
|
1867
1821
|
`/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
|
|
1868
1822
|
{
|
|
1869
1823
|
method: "POST",
|
|
1870
|
-
body: { inputData: params.inputData, runtimeContext },
|
|
1824
|
+
body: { inputData: params.inputData, runtimeContext, tracingOptions: params.tracingOptions },
|
|
1825
|
+
stream: true
|
|
1826
|
+
}
|
|
1827
|
+
);
|
|
1828
|
+
if (!response.ok) {
|
|
1829
|
+
throw new Error(`Failed to stream workflow: ${response.statusText}`);
|
|
1830
|
+
}
|
|
1831
|
+
if (!response.body) {
|
|
1832
|
+
throw new Error("Response body is null");
|
|
1833
|
+
}
|
|
1834
|
+
let failedChunk = void 0;
|
|
1835
|
+
const transformStream = new TransformStream({
|
|
1836
|
+
start() {
|
|
1837
|
+
},
|
|
1838
|
+
async transform(chunk, controller) {
|
|
1839
|
+
try {
|
|
1840
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
1841
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
1842
|
+
for (const chunk2 of chunks) {
|
|
1843
|
+
if (chunk2) {
|
|
1844
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
1845
|
+
try {
|
|
1846
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
1847
|
+
controller.enqueue(parsedChunk);
|
|
1848
|
+
failedChunk = void 0;
|
|
1849
|
+
} catch {
|
|
1850
|
+
failedChunk = newChunk;
|
|
1851
|
+
}
|
|
1852
|
+
}
|
|
1853
|
+
}
|
|
1854
|
+
} catch {
|
|
1855
|
+
}
|
|
1856
|
+
}
|
|
1857
|
+
});
|
|
1858
|
+
return response.body.pipeThrough(transformStream);
|
|
1859
|
+
}
|
|
1860
|
+
/**
|
|
1861
|
+
* Observes workflow stream for a workflow run
|
|
1862
|
+
* @param params - Object containing the runId
|
|
1863
|
+
* @returns Promise containing the workflow execution results
|
|
1864
|
+
*/
|
|
1865
|
+
async observeStream(params) {
|
|
1866
|
+
const searchParams = new URLSearchParams();
|
|
1867
|
+
searchParams.set("runId", params.runId);
|
|
1868
|
+
const response = await this.request(
|
|
1869
|
+
`/api/workflows/${this.workflowId}/observe-stream?${searchParams.toString()}`,
|
|
1870
|
+
{
|
|
1871
|
+
method: "POST",
|
|
1872
|
+
stream: true
|
|
1873
|
+
}
|
|
1874
|
+
);
|
|
1875
|
+
if (!response.ok) {
|
|
1876
|
+
throw new Error(`Failed to observe workflow stream: ${response.statusText}`);
|
|
1877
|
+
}
|
|
1878
|
+
if (!response.body) {
|
|
1879
|
+
throw new Error("Response body is null");
|
|
1880
|
+
}
|
|
1881
|
+
let failedChunk = void 0;
|
|
1882
|
+
const transformStream = new TransformStream({
|
|
1883
|
+
start() {
|
|
1884
|
+
},
|
|
1885
|
+
async transform(chunk, controller) {
|
|
1886
|
+
try {
|
|
1887
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
1888
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
1889
|
+
for (const chunk2 of chunks) {
|
|
1890
|
+
if (chunk2) {
|
|
1891
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
1892
|
+
try {
|
|
1893
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
1894
|
+
controller.enqueue(parsedChunk);
|
|
1895
|
+
failedChunk = void 0;
|
|
1896
|
+
} catch {
|
|
1897
|
+
failedChunk = newChunk;
|
|
1898
|
+
}
|
|
1899
|
+
}
|
|
1900
|
+
}
|
|
1901
|
+
} catch {
|
|
1902
|
+
}
|
|
1903
|
+
}
|
|
1904
|
+
});
|
|
1905
|
+
return response.body.pipeThrough(transformStream);
|
|
1906
|
+
}
|
|
1907
|
+
/**
|
|
1908
|
+
* Starts a workflow run and returns a stream
|
|
1909
|
+
* @param params - Object containing the optional runId, inputData and runtimeContext
|
|
1910
|
+
* @returns Promise containing the workflow execution results
|
|
1911
|
+
*/
|
|
1912
|
+
async streamVNext(params) {
|
|
1913
|
+
const searchParams = new URLSearchParams();
|
|
1914
|
+
if (!!params?.runId) {
|
|
1915
|
+
searchParams.set("runId", params.runId);
|
|
1916
|
+
}
|
|
1917
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1918
|
+
const response = await this.request(
|
|
1919
|
+
`/api/workflows/${this.workflowId}/streamVNext?${searchParams.toString()}`,
|
|
1920
|
+
{
|
|
1921
|
+
method: "POST",
|
|
1922
|
+
body: {
|
|
1923
|
+
inputData: params.inputData,
|
|
1924
|
+
runtimeContext,
|
|
1925
|
+
closeOnSuspend: params.closeOnSuspend,
|
|
1926
|
+
tracingOptions: params.tracingOptions
|
|
1927
|
+
},
|
|
1871
1928
|
stream: true
|
|
1872
1929
|
}
|
|
1873
1930
|
);
|
|
@@ -1884,7 +1941,54 @@ var Workflow = class extends BaseResource {
|
|
|
1884
1941
|
async transform(chunk, controller) {
|
|
1885
1942
|
try {
|
|
1886
1943
|
const decoded = new TextDecoder().decode(chunk);
|
|
1887
|
-
const chunks = decoded.split(
|
|
1944
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
1945
|
+
for (const chunk2 of chunks) {
|
|
1946
|
+
if (chunk2) {
|
|
1947
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
1948
|
+
try {
|
|
1949
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
1950
|
+
controller.enqueue(parsedChunk);
|
|
1951
|
+
failedChunk = void 0;
|
|
1952
|
+
} catch {
|
|
1953
|
+
failedChunk = newChunk;
|
|
1954
|
+
}
|
|
1955
|
+
}
|
|
1956
|
+
}
|
|
1957
|
+
} catch {
|
|
1958
|
+
}
|
|
1959
|
+
}
|
|
1960
|
+
});
|
|
1961
|
+
return response.body.pipeThrough(transformStream);
|
|
1962
|
+
}
|
|
1963
|
+
/**
|
|
1964
|
+
* Observes workflow vNext stream for a workflow run
|
|
1965
|
+
* @param params - Object containing the runId
|
|
1966
|
+
* @returns Promise containing the workflow execution results
|
|
1967
|
+
*/
|
|
1968
|
+
async observeStreamVNext(params) {
|
|
1969
|
+
const searchParams = new URLSearchParams();
|
|
1970
|
+
searchParams.set("runId", params.runId);
|
|
1971
|
+
const response = await this.request(
|
|
1972
|
+
`/api/workflows/${this.workflowId}/observe-streamVNext?${searchParams.toString()}`,
|
|
1973
|
+
{
|
|
1974
|
+
method: "POST",
|
|
1975
|
+
stream: true
|
|
1976
|
+
}
|
|
1977
|
+
);
|
|
1978
|
+
if (!response.ok) {
|
|
1979
|
+
throw new Error(`Failed to observe stream vNext workflow: ${response.statusText}`);
|
|
1980
|
+
}
|
|
1981
|
+
if (!response.body) {
|
|
1982
|
+
throw new Error("Response body is null");
|
|
1983
|
+
}
|
|
1984
|
+
let failedChunk = void 0;
|
|
1985
|
+
const transformStream = new TransformStream({
|
|
1986
|
+
start() {
|
|
1987
|
+
},
|
|
1988
|
+
async transform(chunk, controller) {
|
|
1989
|
+
try {
|
|
1990
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
1991
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
1888
1992
|
for (const chunk2 of chunks) {
|
|
1889
1993
|
if (chunk2) {
|
|
1890
1994
|
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
@@ -1915,10 +2019,65 @@ var Workflow = class extends BaseResource {
|
|
|
1915
2019
|
body: {
|
|
1916
2020
|
step: params.step,
|
|
1917
2021
|
resumeData: params.resumeData,
|
|
1918
|
-
runtimeContext
|
|
2022
|
+
runtimeContext,
|
|
2023
|
+
tracingOptions: params.tracingOptions
|
|
1919
2024
|
}
|
|
1920
2025
|
});
|
|
1921
2026
|
}
|
|
2027
|
+
/**
|
|
2028
|
+
* Resumes a suspended workflow step that uses streamVNext asynchronously and returns a promise that resolves when the workflow is complete
|
|
2029
|
+
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
2030
|
+
* @returns Promise containing the workflow resume results
|
|
2031
|
+
*/
|
|
2032
|
+
async resumeStreamVNext(params) {
|
|
2033
|
+
const searchParams = new URLSearchParams();
|
|
2034
|
+
searchParams.set("runId", params.runId);
|
|
2035
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
2036
|
+
const response = await this.request(
|
|
2037
|
+
`/api/workflows/${this.workflowId}/resume-stream?${searchParams.toString()}`,
|
|
2038
|
+
{
|
|
2039
|
+
method: "POST",
|
|
2040
|
+
body: {
|
|
2041
|
+
step: params.step,
|
|
2042
|
+
resumeData: params.resumeData,
|
|
2043
|
+
runtimeContext,
|
|
2044
|
+
tracingOptions: params.tracingOptions
|
|
2045
|
+
},
|
|
2046
|
+
stream: true
|
|
2047
|
+
}
|
|
2048
|
+
);
|
|
2049
|
+
if (!response.ok) {
|
|
2050
|
+
throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
|
|
2051
|
+
}
|
|
2052
|
+
if (!response.body) {
|
|
2053
|
+
throw new Error("Response body is null");
|
|
2054
|
+
}
|
|
2055
|
+
let failedChunk = void 0;
|
|
2056
|
+
const transformStream = new TransformStream({
|
|
2057
|
+
start() {
|
|
2058
|
+
},
|
|
2059
|
+
async transform(chunk, controller) {
|
|
2060
|
+
try {
|
|
2061
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
2062
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
2063
|
+
for (const chunk2 of chunks) {
|
|
2064
|
+
if (chunk2) {
|
|
2065
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
2066
|
+
try {
|
|
2067
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
2068
|
+
controller.enqueue(parsedChunk);
|
|
2069
|
+
failedChunk = void 0;
|
|
2070
|
+
} catch {
|
|
2071
|
+
failedChunk = newChunk;
|
|
2072
|
+
}
|
|
2073
|
+
}
|
|
2074
|
+
}
|
|
2075
|
+
} catch {
|
|
2076
|
+
}
|
|
2077
|
+
}
|
|
2078
|
+
});
|
|
2079
|
+
return response.body.pipeThrough(transformStream);
|
|
2080
|
+
}
|
|
1922
2081
|
/**
|
|
1923
2082
|
* Watches workflow transitions in real-time
|
|
1924
2083
|
* @param runId - Optional run ID to filter the watch stream
|
|
@@ -1955,7 +2114,7 @@ var Workflow = class extends BaseResource {
|
|
|
1955
2114
|
async start(controller) {
|
|
1956
2115
|
try {
|
|
1957
2116
|
for await (const record of records) {
|
|
1958
|
-
const json = JSON.stringify(record) +
|
|
2117
|
+
const json = JSON.stringify(record) + RECORD_SEPARATOR;
|
|
1959
2118
|
controller.enqueue(encoder.encode(json));
|
|
1960
2119
|
}
|
|
1961
2120
|
controller.close();
|
|
@@ -2053,10 +2212,11 @@ var MCPTool = class extends BaseResource {
|
|
|
2053
2212
|
}
|
|
2054
2213
|
/**
|
|
2055
2214
|
* Retrieves details about this specific tool from the MCP server.
|
|
2215
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2056
2216
|
* @returns Promise containing the tool's information (name, description, schema).
|
|
2057
2217
|
*/
|
|
2058
|
-
details() {
|
|
2059
|
-
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}`);
|
|
2218
|
+
details(runtimeContext) {
|
|
2219
|
+
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
|
|
2060
2220
|
}
|
|
2061
2221
|
/**
|
|
2062
2222
|
* Executes this specific tool on the MCP server.
|
|
@@ -2077,7 +2237,7 @@ var MCPTool = class extends BaseResource {
|
|
|
2077
2237
|
};
|
|
2078
2238
|
|
|
2079
2239
|
// src/resources/agent-builder.ts
|
|
2080
|
-
var
|
|
2240
|
+
var RECORD_SEPARATOR2 = "";
|
|
2081
2241
|
var AgentBuilder = class extends BaseResource {
|
|
2082
2242
|
constructor(options, actionId) {
|
|
2083
2243
|
super(options);
|
|
@@ -2112,11 +2272,20 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2112
2272
|
};
|
|
2113
2273
|
}
|
|
2114
2274
|
}
|
|
2275
|
+
/**
|
|
2276
|
+
* @deprecated Use createRunAsync() instead.
|
|
2277
|
+
* @throws {Error} Always throws an error directing users to use createRunAsync()
|
|
2278
|
+
*/
|
|
2279
|
+
async createRun(_params) {
|
|
2280
|
+
throw new Error(
|
|
2281
|
+
"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."
|
|
2282
|
+
);
|
|
2283
|
+
}
|
|
2115
2284
|
/**
|
|
2116
2285
|
* Creates a new agent builder action run and returns the runId.
|
|
2117
2286
|
* This calls `/api/agent-builder/:actionId/create-run`.
|
|
2118
2287
|
*/
|
|
2119
|
-
async
|
|
2288
|
+
async createRunAsync(params) {
|
|
2120
2289
|
const searchParams = new URLSearchParams();
|
|
2121
2290
|
if (!!params?.runId) {
|
|
2122
2291
|
searchParams.set("runId", params.runId);
|
|
@@ -2126,14 +2295,6 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2126
2295
|
method: "POST"
|
|
2127
2296
|
});
|
|
2128
2297
|
}
|
|
2129
|
-
/**
|
|
2130
|
-
* Creates a new workflow run (alias for createRun)
|
|
2131
|
-
* @param params - Optional object containing the optional runId
|
|
2132
|
-
* @returns Promise containing the runId of the created run
|
|
2133
|
-
*/
|
|
2134
|
-
createRunAsync(params) {
|
|
2135
|
-
return this.createRun(params);
|
|
2136
|
-
}
|
|
2137
2298
|
/**
|
|
2138
2299
|
* Starts agent builder action asynchronously and waits for completion.
|
|
2139
2300
|
* This calls `/api/agent-builder/:actionId/start-async`.
|
|
@@ -2216,7 +2377,7 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2216
2377
|
if (done && !value) continue;
|
|
2217
2378
|
try {
|
|
2218
2379
|
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
2219
|
-
const chunks = (buffer + decoded).split(
|
|
2380
|
+
const chunks = (buffer + decoded).split(RECORD_SEPARATOR2);
|
|
2220
2381
|
buffer = chunks.pop() || "";
|
|
2221
2382
|
for (const chunk of chunks) {
|
|
2222
2383
|
if (chunk) {
|
|
@@ -2273,7 +2434,7 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2273
2434
|
async transform(chunk, controller) {
|
|
2274
2435
|
try {
|
|
2275
2436
|
const decoded = new TextDecoder().decode(chunk);
|
|
2276
|
-
const chunks = decoded.split(
|
|
2437
|
+
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
2277
2438
|
for (const chunk2 of chunks) {
|
|
2278
2439
|
if (chunk2) {
|
|
2279
2440
|
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
@@ -2322,7 +2483,7 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2322
2483
|
async transform(chunk, controller) {
|
|
2323
2484
|
try {
|
|
2324
2485
|
const decoded = new TextDecoder().decode(chunk);
|
|
2325
|
-
const chunks = decoded.split(
|
|
2486
|
+
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
2326
2487
|
for (const chunk2 of chunks) {
|
|
2327
2488
|
if (chunk2) {
|
|
2328
2489
|
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
@@ -2465,7 +2626,7 @@ var Observability = class extends BaseResource {
|
|
|
2465
2626
|
getTraces(params) {
|
|
2466
2627
|
const { pagination, filters } = params;
|
|
2467
2628
|
const { page, perPage, dateRange } = pagination || {};
|
|
2468
|
-
const { name, spanType } = filters || {};
|
|
2629
|
+
const { name, spanType, entityId, entityType } = filters || {};
|
|
2469
2630
|
const searchParams = new URLSearchParams();
|
|
2470
2631
|
if (page !== void 0) {
|
|
2471
2632
|
searchParams.set("page", String(page));
|
|
@@ -2479,6 +2640,10 @@ var Observability = class extends BaseResource {
|
|
|
2479
2640
|
if (spanType !== void 0) {
|
|
2480
2641
|
searchParams.set("spanType", String(spanType));
|
|
2481
2642
|
}
|
|
2643
|
+
if (entityId && entityType) {
|
|
2644
|
+
searchParams.set("entityId", entityId);
|
|
2645
|
+
searchParams.set("entityType", entityType);
|
|
2646
|
+
}
|
|
2482
2647
|
if (dateRange) {
|
|
2483
2648
|
const dateRangeStr = JSON.stringify({
|
|
2484
2649
|
start: dateRange.start instanceof Date ? dateRange.start.toISOString() : dateRange.start,
|
|
@@ -2489,6 +2654,31 @@ var Observability = class extends BaseResource {
|
|
|
2489
2654
|
const queryString = searchParams.toString();
|
|
2490
2655
|
return this.request(`/api/observability/traces${queryString ? `?${queryString}` : ""}`);
|
|
2491
2656
|
}
|
|
2657
|
+
/**
|
|
2658
|
+
* Retrieves scores by trace ID and span ID
|
|
2659
|
+
* @param params - Parameters containing trace ID, span ID, and pagination options
|
|
2660
|
+
* @returns Promise containing scores and pagination info
|
|
2661
|
+
*/
|
|
2662
|
+
getScoresBySpan(params) {
|
|
2663
|
+
const { traceId, spanId, page, perPage } = params;
|
|
2664
|
+
const searchParams = new URLSearchParams();
|
|
2665
|
+
if (page !== void 0) {
|
|
2666
|
+
searchParams.set("page", String(page));
|
|
2667
|
+
}
|
|
2668
|
+
if (perPage !== void 0) {
|
|
2669
|
+
searchParams.set("perPage", String(perPage));
|
|
2670
|
+
}
|
|
2671
|
+
const queryString = searchParams.toString();
|
|
2672
|
+
return this.request(
|
|
2673
|
+
`/api/observability/traces/${encodeURIComponent(traceId)}/${encodeURIComponent(spanId)}/scores${queryString ? `?${queryString}` : ""}`
|
|
2674
|
+
);
|
|
2675
|
+
}
|
|
2676
|
+
score(params) {
|
|
2677
|
+
return this.request(`/api/observability/traces/score`, {
|
|
2678
|
+
method: "POST",
|
|
2679
|
+
body: { ...params }
|
|
2680
|
+
});
|
|
2681
|
+
}
|
|
2492
2682
|
};
|
|
2493
2683
|
|
|
2494
2684
|
// src/resources/network-memory-thread.ts
|
|
@@ -2554,144 +2744,6 @@ var NetworkMemoryThread = class extends BaseResource {
|
|
|
2554
2744
|
}
|
|
2555
2745
|
};
|
|
2556
2746
|
|
|
2557
|
-
// src/resources/vNextNetwork.ts
|
|
2558
|
-
var RECORD_SEPARATOR4 = "";
|
|
2559
|
-
var VNextNetwork = class extends BaseResource {
|
|
2560
|
-
constructor(options, networkId) {
|
|
2561
|
-
super(options);
|
|
2562
|
-
this.networkId = networkId;
|
|
2563
|
-
}
|
|
2564
|
-
/**
|
|
2565
|
-
* Retrieves details about the network
|
|
2566
|
-
* @returns Promise containing vNext network details
|
|
2567
|
-
*/
|
|
2568
|
-
details() {
|
|
2569
|
-
return this.request(`/api/networks/v-next/${this.networkId}`);
|
|
2570
|
-
}
|
|
2571
|
-
/**
|
|
2572
|
-
* Generates a response from the v-next network
|
|
2573
|
-
* @param params - Generation parameters including message
|
|
2574
|
-
* @returns Promise containing the generated response
|
|
2575
|
-
*/
|
|
2576
|
-
generate(params) {
|
|
2577
|
-
return this.request(`/api/networks/v-next/${this.networkId}/generate`, {
|
|
2578
|
-
method: "POST",
|
|
2579
|
-
body: {
|
|
2580
|
-
...params,
|
|
2581
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
2582
|
-
}
|
|
2583
|
-
});
|
|
2584
|
-
}
|
|
2585
|
-
/**
|
|
2586
|
-
* Generates a response from the v-next network using multiple primitives
|
|
2587
|
-
* @param params - Generation parameters including message
|
|
2588
|
-
* @returns Promise containing the generated response
|
|
2589
|
-
*/
|
|
2590
|
-
loop(params) {
|
|
2591
|
-
return this.request(`/api/networks/v-next/${this.networkId}/loop`, {
|
|
2592
|
-
method: "POST",
|
|
2593
|
-
body: {
|
|
2594
|
-
...params,
|
|
2595
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
2596
|
-
}
|
|
2597
|
-
});
|
|
2598
|
-
}
|
|
2599
|
-
async *streamProcessor(stream) {
|
|
2600
|
-
const reader = stream.getReader();
|
|
2601
|
-
let doneReading = false;
|
|
2602
|
-
let buffer = "";
|
|
2603
|
-
try {
|
|
2604
|
-
while (!doneReading) {
|
|
2605
|
-
const { done, value } = await reader.read();
|
|
2606
|
-
doneReading = done;
|
|
2607
|
-
if (done && !value) continue;
|
|
2608
|
-
try {
|
|
2609
|
-
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
2610
|
-
const chunks = (buffer + decoded).split(RECORD_SEPARATOR4);
|
|
2611
|
-
buffer = chunks.pop() || "";
|
|
2612
|
-
for (const chunk of chunks) {
|
|
2613
|
-
if (chunk) {
|
|
2614
|
-
if (typeof chunk === "string") {
|
|
2615
|
-
try {
|
|
2616
|
-
const parsedChunk = JSON.parse(chunk);
|
|
2617
|
-
yield parsedChunk;
|
|
2618
|
-
} catch {
|
|
2619
|
-
}
|
|
2620
|
-
}
|
|
2621
|
-
}
|
|
2622
|
-
}
|
|
2623
|
-
} catch {
|
|
2624
|
-
}
|
|
2625
|
-
}
|
|
2626
|
-
if (buffer) {
|
|
2627
|
-
try {
|
|
2628
|
-
yield JSON.parse(buffer);
|
|
2629
|
-
} catch {
|
|
2630
|
-
}
|
|
2631
|
-
}
|
|
2632
|
-
} finally {
|
|
2633
|
-
reader.cancel().catch(() => {
|
|
2634
|
-
});
|
|
2635
|
-
}
|
|
2636
|
-
}
|
|
2637
|
-
/**
|
|
2638
|
-
* Streams a response from the v-next network
|
|
2639
|
-
* @param params - Stream parameters including message
|
|
2640
|
-
* @returns Promise containing the results
|
|
2641
|
-
*/
|
|
2642
|
-
async stream(params, onRecord) {
|
|
2643
|
-
const response = await this.request(`/api/networks/v-next/${this.networkId}/stream`, {
|
|
2644
|
-
method: "POST",
|
|
2645
|
-
body: {
|
|
2646
|
-
...params,
|
|
2647
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
2648
|
-
},
|
|
2649
|
-
stream: true
|
|
2650
|
-
});
|
|
2651
|
-
if (!response.ok) {
|
|
2652
|
-
throw new Error(`Failed to stream vNext network: ${response.statusText}`);
|
|
2653
|
-
}
|
|
2654
|
-
if (!response.body) {
|
|
2655
|
-
throw new Error("Response body is null");
|
|
2656
|
-
}
|
|
2657
|
-
for await (const record of this.streamProcessor(response.body)) {
|
|
2658
|
-
if (typeof record === "string") {
|
|
2659
|
-
onRecord(JSON.parse(record));
|
|
2660
|
-
} else {
|
|
2661
|
-
onRecord(record);
|
|
2662
|
-
}
|
|
2663
|
-
}
|
|
2664
|
-
}
|
|
2665
|
-
/**
|
|
2666
|
-
* Streams a response from the v-next network loop
|
|
2667
|
-
* @param params - Stream parameters including message
|
|
2668
|
-
* @returns Promise containing the results
|
|
2669
|
-
*/
|
|
2670
|
-
async loopStream(params, onRecord) {
|
|
2671
|
-
const response = await this.request(`/api/networks/v-next/${this.networkId}/loop-stream`, {
|
|
2672
|
-
method: "POST",
|
|
2673
|
-
body: {
|
|
2674
|
-
...params,
|
|
2675
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
2676
|
-
},
|
|
2677
|
-
stream: true
|
|
2678
|
-
});
|
|
2679
|
-
if (!response.ok) {
|
|
2680
|
-
throw new Error(`Failed to stream vNext network loop: ${response.statusText}`);
|
|
2681
|
-
}
|
|
2682
|
-
if (!response.body) {
|
|
2683
|
-
throw new Error("Response body is null");
|
|
2684
|
-
}
|
|
2685
|
-
for await (const record of this.streamProcessor(response.body)) {
|
|
2686
|
-
if (typeof record === "string") {
|
|
2687
|
-
onRecord(JSON.parse(record));
|
|
2688
|
-
} else {
|
|
2689
|
-
onRecord(record);
|
|
2690
|
-
}
|
|
2691
|
-
}
|
|
2692
|
-
}
|
|
2693
|
-
};
|
|
2694
|
-
|
|
2695
2747
|
// src/client.ts
|
|
2696
2748
|
var MastraClient = class extends BaseResource {
|
|
2697
2749
|
observability;
|
|
@@ -2701,10 +2753,17 @@ var MastraClient = class extends BaseResource {
|
|
|
2701
2753
|
}
|
|
2702
2754
|
/**
|
|
2703
2755
|
* Retrieves all available agents
|
|
2756
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2704
2757
|
* @returns Promise containing map of agent IDs to agent details
|
|
2705
2758
|
*/
|
|
2706
|
-
getAgents() {
|
|
2707
|
-
|
|
2759
|
+
getAgents(runtimeContext) {
|
|
2760
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
2761
|
+
const searchParams = new URLSearchParams();
|
|
2762
|
+
if (runtimeContextParam) {
|
|
2763
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
2764
|
+
}
|
|
2765
|
+
const queryString = searchParams.toString();
|
|
2766
|
+
return this.request(`/api/agents${queryString ? `?${queryString}` : ""}`);
|
|
2708
2767
|
}
|
|
2709
2768
|
/**
|
|
2710
2769
|
* Gets an agent instance by ID
|
|
@@ -2722,6 +2781,14 @@ var MastraClient = class extends BaseResource {
|
|
|
2722
2781
|
getMemoryThreads(params) {
|
|
2723
2782
|
return this.request(`/api/memory/threads?resourceid=${params.resourceId}&agentId=${params.agentId}`);
|
|
2724
2783
|
}
|
|
2784
|
+
/**
|
|
2785
|
+
* Retrieves memory config for a resource
|
|
2786
|
+
* @param params - Parameters containing the resource ID
|
|
2787
|
+
* @returns Promise containing array of memory threads
|
|
2788
|
+
*/
|
|
2789
|
+
getMemoryConfig(params) {
|
|
2790
|
+
return this.request(`/api/memory/config?agentId=${params.agentId}`);
|
|
2791
|
+
}
|
|
2725
2792
|
/**
|
|
2726
2793
|
* Creates a new memory thread
|
|
2727
2794
|
* @param params - Parameters for creating the memory thread
|
|
@@ -2738,6 +2805,24 @@ var MastraClient = class extends BaseResource {
|
|
|
2738
2805
|
getMemoryThread(threadId, agentId) {
|
|
2739
2806
|
return new MemoryThread(this.options, threadId, agentId);
|
|
2740
2807
|
}
|
|
2808
|
+
getThreadMessages(threadId, opts = {}) {
|
|
2809
|
+
let url = "";
|
|
2810
|
+
if (opts.agentId) {
|
|
2811
|
+
url = `/api/memory/threads/${threadId}/messages?agentId=${opts.agentId}`;
|
|
2812
|
+
} else if (opts.networkId) {
|
|
2813
|
+
url = `/api/memory/network/threads/${threadId}/messages?networkId=${opts.networkId}`;
|
|
2814
|
+
}
|
|
2815
|
+
return this.request(url);
|
|
2816
|
+
}
|
|
2817
|
+
deleteThread(threadId, opts = {}) {
|
|
2818
|
+
let url = "";
|
|
2819
|
+
if (opts.agentId) {
|
|
2820
|
+
url = `/api/memory/threads/${threadId}?agentId=${opts.agentId}`;
|
|
2821
|
+
} else if (opts.networkId) {
|
|
2822
|
+
url = `/api/memory/network/threads/${threadId}?networkId=${opts.networkId}`;
|
|
2823
|
+
}
|
|
2824
|
+
return this.request(url, { method: "DELETE" });
|
|
2825
|
+
}
|
|
2741
2826
|
/**
|
|
2742
2827
|
* Saves messages to memory
|
|
2743
2828
|
* @param params - Parameters containing messages to save
|
|
@@ -2800,10 +2885,17 @@ var MastraClient = class extends BaseResource {
|
|
|
2800
2885
|
}
|
|
2801
2886
|
/**
|
|
2802
2887
|
* Retrieves all available tools
|
|
2888
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2803
2889
|
* @returns Promise containing map of tool IDs to tool details
|
|
2804
2890
|
*/
|
|
2805
|
-
getTools() {
|
|
2806
|
-
|
|
2891
|
+
getTools(runtimeContext) {
|
|
2892
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
2893
|
+
const searchParams = new URLSearchParams();
|
|
2894
|
+
if (runtimeContextParam) {
|
|
2895
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
2896
|
+
}
|
|
2897
|
+
const queryString = searchParams.toString();
|
|
2898
|
+
return this.request(`/api/tools${queryString ? `?${queryString}` : ""}`);
|
|
2807
2899
|
}
|
|
2808
2900
|
/**
|
|
2809
2901
|
* Gets a tool instance by ID
|
|
@@ -2813,27 +2905,19 @@ var MastraClient = class extends BaseResource {
|
|
|
2813
2905
|
getTool(toolId) {
|
|
2814
2906
|
return new Tool(this.options, toolId);
|
|
2815
2907
|
}
|
|
2816
|
-
/**
|
|
2817
|
-
* Retrieves all available legacy workflows
|
|
2818
|
-
* @returns Promise containing map of legacy workflow IDs to legacy workflow details
|
|
2819
|
-
*/
|
|
2820
|
-
getLegacyWorkflows() {
|
|
2821
|
-
return this.request("/api/workflows/legacy");
|
|
2822
|
-
}
|
|
2823
|
-
/**
|
|
2824
|
-
* Gets a legacy workflow instance by ID
|
|
2825
|
-
* @param workflowId - ID of the legacy workflow to retrieve
|
|
2826
|
-
* @returns Legacy Workflow instance
|
|
2827
|
-
*/
|
|
2828
|
-
getLegacyWorkflow(workflowId) {
|
|
2829
|
-
return new LegacyWorkflow(this.options, workflowId);
|
|
2830
|
-
}
|
|
2831
2908
|
/**
|
|
2832
2909
|
* Retrieves all available workflows
|
|
2910
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2833
2911
|
* @returns Promise containing map of workflow IDs to workflow details
|
|
2834
2912
|
*/
|
|
2835
|
-
getWorkflows() {
|
|
2836
|
-
|
|
2913
|
+
getWorkflows(runtimeContext) {
|
|
2914
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
2915
|
+
const searchParams = new URLSearchParams();
|
|
2916
|
+
if (runtimeContextParam) {
|
|
2917
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
2918
|
+
}
|
|
2919
|
+
const queryString = searchParams.toString();
|
|
2920
|
+
return this.request(`/api/workflows${queryString ? `?${queryString}` : ""}`);
|
|
2837
2921
|
}
|
|
2838
2922
|
/**
|
|
2839
2923
|
* Gets a workflow instance by ID
|
|
@@ -3001,36 +3085,6 @@ var MastraClient = class extends BaseResource {
|
|
|
3001
3085
|
return this.request(`/api/telemetry`);
|
|
3002
3086
|
}
|
|
3003
3087
|
}
|
|
3004
|
-
/**
|
|
3005
|
-
* Retrieves all available networks
|
|
3006
|
-
* @returns Promise containing map of network IDs to network details
|
|
3007
|
-
*/
|
|
3008
|
-
getNetworks() {
|
|
3009
|
-
return this.request("/api/networks");
|
|
3010
|
-
}
|
|
3011
|
-
/**
|
|
3012
|
-
* Retrieves all available vNext networks
|
|
3013
|
-
* @returns Promise containing map of vNext network IDs to vNext network details
|
|
3014
|
-
*/
|
|
3015
|
-
getVNextNetworks() {
|
|
3016
|
-
return this.request("/api/networks/v-next");
|
|
3017
|
-
}
|
|
3018
|
-
/**
|
|
3019
|
-
* Gets a network instance by ID
|
|
3020
|
-
* @param networkId - ID of the network to retrieve
|
|
3021
|
-
* @returns Network instance
|
|
3022
|
-
*/
|
|
3023
|
-
getNetwork(networkId) {
|
|
3024
|
-
return new Network(this.options, networkId);
|
|
3025
|
-
}
|
|
3026
|
-
/**
|
|
3027
|
-
* Gets a vNext network instance by ID
|
|
3028
|
-
* @param networkId - ID of the vNext network to retrieve
|
|
3029
|
-
* @returns vNext Network instance
|
|
3030
|
-
*/
|
|
3031
|
-
getVNextNetwork(networkId) {
|
|
3032
|
-
return new VNextNetwork(this.options, networkId);
|
|
3033
|
-
}
|
|
3034
3088
|
/**
|
|
3035
3089
|
* Retrieves a list of available MCP servers.
|
|
3036
3090
|
* @param params - Optional parameters for pagination (limit, offset).
|
|
@@ -3135,7 +3189,7 @@ var MastraClient = class extends BaseResource {
|
|
|
3135
3189
|
* @returns Promise containing the scorer
|
|
3136
3190
|
*/
|
|
3137
3191
|
getScorer(scorerId) {
|
|
3138
|
-
return this.request(`/api/scores/scorers/${scorerId}`);
|
|
3192
|
+
return this.request(`/api/scores/scorers/${encodeURIComponent(scorerId)}`);
|
|
3139
3193
|
}
|
|
3140
3194
|
getScoresByScorerId(params) {
|
|
3141
3195
|
const { page, perPage, scorerId, entityId, entityType } = params;
|
|
@@ -3153,7 +3207,7 @@ var MastraClient = class extends BaseResource {
|
|
|
3153
3207
|
searchParams.set("perPage", String(perPage));
|
|
3154
3208
|
}
|
|
3155
3209
|
const queryString = searchParams.toString();
|
|
3156
|
-
return this.request(`/api/scores/scorer/${scorerId}${queryString ? `?${queryString}` : ""}`);
|
|
3210
|
+
return this.request(`/api/scores/scorer/${encodeURIComponent(scorerId)}${queryString ? `?${queryString}` : ""}`);
|
|
3157
3211
|
}
|
|
3158
3212
|
/**
|
|
3159
3213
|
* Retrieves scores by run ID
|
|
@@ -3170,7 +3224,7 @@ var MastraClient = class extends BaseResource {
|
|
|
3170
3224
|
searchParams.set("perPage", String(perPage));
|
|
3171
3225
|
}
|
|
3172
3226
|
const queryString = searchParams.toString();
|
|
3173
|
-
return this.request(`/api/scores/run/${runId}${queryString ? `?${queryString}` : ""}`);
|
|
3227
|
+
return this.request(`/api/scores/run/${encodeURIComponent(runId)}${queryString ? `?${queryString}` : ""}`);
|
|
3174
3228
|
}
|
|
3175
3229
|
/**
|
|
3176
3230
|
* Retrieves scores by entity ID and type
|
|
@@ -3187,7 +3241,9 @@ var MastraClient = class extends BaseResource {
|
|
|
3187
3241
|
searchParams.set("perPage", String(perPage));
|
|
3188
3242
|
}
|
|
3189
3243
|
const queryString = searchParams.toString();
|
|
3190
|
-
return this.request(
|
|
3244
|
+
return this.request(
|
|
3245
|
+
`/api/scores/entity/${encodeURIComponent(entityType)}/${encodeURIComponent(entityId)}${queryString ? `?${queryString}` : ""}`
|
|
3246
|
+
);
|
|
3191
3247
|
}
|
|
3192
3248
|
/**
|
|
3193
3249
|
* Saves a score
|
|
@@ -3213,8 +3269,35 @@ var MastraClient = class extends BaseResource {
|
|
|
3213
3269
|
getAITraces(params) {
|
|
3214
3270
|
return this.observability.getTraces(params);
|
|
3215
3271
|
}
|
|
3272
|
+
getScoresBySpan(params) {
|
|
3273
|
+
return this.observability.getScoresBySpan(params);
|
|
3274
|
+
}
|
|
3275
|
+
score(params) {
|
|
3276
|
+
return this.observability.score(params);
|
|
3277
|
+
}
|
|
3216
3278
|
};
|
|
3217
3279
|
|
|
3280
|
+
// src/tools.ts
|
|
3281
|
+
var ClientTool = class {
|
|
3282
|
+
id;
|
|
3283
|
+
description;
|
|
3284
|
+
inputSchema;
|
|
3285
|
+
outputSchema;
|
|
3286
|
+
execute;
|
|
3287
|
+
constructor(opts) {
|
|
3288
|
+
this.id = opts.id;
|
|
3289
|
+
this.description = opts.description;
|
|
3290
|
+
this.inputSchema = opts.inputSchema;
|
|
3291
|
+
this.outputSchema = opts.outputSchema;
|
|
3292
|
+
this.execute = opts.execute;
|
|
3293
|
+
}
|
|
3294
|
+
};
|
|
3295
|
+
function createTool(opts) {
|
|
3296
|
+
return new ClientTool(opts);
|
|
3297
|
+
}
|
|
3298
|
+
|
|
3299
|
+
exports.ClientTool = ClientTool;
|
|
3218
3300
|
exports.MastraClient = MastraClient;
|
|
3301
|
+
exports.createTool = createTool;
|
|
3219
3302
|
//# sourceMappingURL=index.cjs.map
|
|
3220
3303
|
//# sourceMappingURL=index.cjs.map
|