@mastra/client-js 0.16.9 → 1.0.0-beta.1
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 +281 -54
- package/README.md +8 -10
- package/dist/client.d.ts +52 -77
- package/dist/client.d.ts.map +1 -1
- package/dist/index.cjs +467 -663
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +467 -663
- package/dist/index.js.map +1 -1
- package/dist/resources/agent-builder.d.ts +49 -34
- package/dist/resources/agent-builder.d.ts.map +1 -1
- package/dist/resources/agent.d.ts +18 -44
- package/dist/resources/agent.d.ts.map +1 -1
- package/dist/resources/mcp-tool.d.ts +5 -5
- package/dist/resources/memory-thread.d.ts +14 -22
- package/dist/resources/memory-thread.d.ts.map +1 -1
- package/dist/resources/observability.d.ts +8 -8
- package/dist/resources/observability.d.ts.map +1 -1
- package/dist/resources/tool.d.ts +4 -4
- package/dist/resources/vector.d.ts +5 -5
- package/dist/resources/workflow.d.ts +32 -97
- package/dist/resources/workflow.d.ts.map +1 -1
- package/dist/types.d.ts +92 -125
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/index.d.ts +6 -6
- package/dist/utils/process-mastra-stream.d.ts.map +1 -1
- package/package.json +8 -12
- package/dist/resources/network-memory-thread.d.ts +0 -47
- package/dist/resources/network-memory-thread.d.ts.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var uiUtils = require('@ai-sdk/ui-utils');
|
|
4
4
|
var uuid = require('@lukeed/uuid');
|
|
5
5
|
var error = require('@mastra/core/error');
|
|
6
|
-
var
|
|
6
|
+
var requestContext = require('@mastra/core/request-context');
|
|
7
7
|
var isVercelTool = require('@mastra/core/tools/is-vercel-tool');
|
|
8
8
|
var zod = require('zod');
|
|
9
9
|
var originalZodToJsonSchema = require('zod-to-json-schema');
|
|
@@ -13,26 +13,26 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
|
13
13
|
var originalZodToJsonSchema__default = /*#__PURE__*/_interopDefault(originalZodToJsonSchema);
|
|
14
14
|
|
|
15
15
|
// src/resources/agent.ts
|
|
16
|
-
function
|
|
17
|
-
if (
|
|
18
|
-
if (
|
|
19
|
-
return Object.fromEntries(
|
|
16
|
+
function parseClientRequestContext(requestContext$1) {
|
|
17
|
+
if (requestContext$1) {
|
|
18
|
+
if (requestContext$1 instanceof requestContext.RequestContext) {
|
|
19
|
+
return Object.fromEntries(requestContext$1.entries());
|
|
20
20
|
}
|
|
21
|
-
return
|
|
21
|
+
return requestContext$1;
|
|
22
22
|
}
|
|
23
23
|
return void 0;
|
|
24
24
|
}
|
|
25
|
-
function
|
|
26
|
-
if (
|
|
27
|
-
return btoa(JSON.stringify(
|
|
25
|
+
function base64RequestContext(requestContext) {
|
|
26
|
+
if (requestContext) {
|
|
27
|
+
return btoa(JSON.stringify(requestContext));
|
|
28
28
|
}
|
|
29
29
|
return void 0;
|
|
30
30
|
}
|
|
31
|
-
function
|
|
32
|
-
const
|
|
33
|
-
if (!
|
|
31
|
+
function requestContextQueryString(requestContext, delimiter = "?") {
|
|
32
|
+
const requestContextParam = base64RequestContext(parseClientRequestContext(requestContext));
|
|
33
|
+
if (!requestContextParam) return "";
|
|
34
34
|
const searchParams = new URLSearchParams();
|
|
35
|
-
searchParams.set("
|
|
35
|
+
searchParams.set("requestContext", requestContextParam);
|
|
36
36
|
const queryString = searchParams.toString();
|
|
37
37
|
return queryString ? `${delimiter}${queryString}` : "";
|
|
38
38
|
}
|
|
@@ -98,7 +98,6 @@ async function sharedProcessMastraStream({
|
|
|
98
98
|
if (line.startsWith("data: ")) {
|
|
99
99
|
const data = line.slice(6);
|
|
100
100
|
if (data === "[DONE]") {
|
|
101
|
-
console.info("\u{1F3C1} Stream finished");
|
|
102
101
|
return;
|
|
103
102
|
}
|
|
104
103
|
let json;
|
|
@@ -203,10 +202,9 @@ var BaseResource = class {
|
|
|
203
202
|
async function executeToolCallAndRespond({
|
|
204
203
|
response,
|
|
205
204
|
params,
|
|
206
|
-
runId,
|
|
207
205
|
resourceId,
|
|
208
206
|
threadId,
|
|
209
|
-
|
|
207
|
+
requestContext,
|
|
210
208
|
respondFn
|
|
211
209
|
}) {
|
|
212
210
|
if (response.finishReason === "tool-calls") {
|
|
@@ -215,24 +213,20 @@ async function executeToolCallAndRespond({
|
|
|
215
213
|
return response;
|
|
216
214
|
}
|
|
217
215
|
for (const toolCall of toolCalls) {
|
|
218
|
-
const clientTool = params.clientTools?.[toolCall.toolName];
|
|
216
|
+
const clientTool = params.clientTools?.[toolCall.payload.toolName];
|
|
219
217
|
if (clientTool && clientTool.execute) {
|
|
220
|
-
const result = await clientTool.execute(
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
resourceId,
|
|
225
|
-
threadId,
|
|
226
|
-
runtimeContext,
|
|
227
|
-
tracingContext: { currentSpan: void 0 },
|
|
228
|
-
suspend: async () => {
|
|
229
|
-
}
|
|
230
|
-
},
|
|
231
|
-
{
|
|
218
|
+
const result = await clientTool.execute(toolCall?.payload.args, {
|
|
219
|
+
requestContext,
|
|
220
|
+
tracingContext: { currentSpan: void 0 },
|
|
221
|
+
agent: {
|
|
232
222
|
messages: response.messages,
|
|
233
|
-
toolCallId: toolCall?.toolCallId
|
|
223
|
+
toolCallId: toolCall?.payload.toolCallId,
|
|
224
|
+
suspend: async () => {
|
|
225
|
+
},
|
|
226
|
+
threadId,
|
|
227
|
+
resourceId
|
|
234
228
|
}
|
|
235
|
-
);
|
|
229
|
+
});
|
|
236
230
|
const updatedMessages = [
|
|
237
231
|
...response.response.messages || [],
|
|
238
232
|
{
|
|
@@ -240,8 +234,8 @@ async function executeToolCallAndRespond({
|
|
|
240
234
|
content: [
|
|
241
235
|
{
|
|
242
236
|
type: "tool-result",
|
|
243
|
-
toolCallId: toolCall.toolCallId,
|
|
244
|
-
toolName: toolCall.toolName,
|
|
237
|
+
toolCallId: toolCall.payload.toolCallId,
|
|
238
|
+
toolName: toolCall.payload.toolName,
|
|
245
239
|
result
|
|
246
240
|
}
|
|
247
241
|
]
|
|
@@ -254,6 +248,7 @@ async function executeToolCallAndRespond({
|
|
|
254
248
|
}
|
|
255
249
|
}
|
|
256
250
|
}
|
|
251
|
+
return response;
|
|
257
252
|
}
|
|
258
253
|
var AgentVoice = class extends BaseResource {
|
|
259
254
|
constructor(options, agentId) {
|
|
@@ -296,21 +291,21 @@ var AgentVoice = class extends BaseResource {
|
|
|
296
291
|
}
|
|
297
292
|
/**
|
|
298
293
|
* Get available speakers for the agent's voice provider
|
|
299
|
-
* @param
|
|
300
|
-
* @param
|
|
294
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
295
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
301
296
|
* @returns Promise containing list of available speakers
|
|
302
297
|
*/
|
|
303
|
-
getSpeakers(
|
|
304
|
-
return this.request(`/api/agents/${this.agentId}/voice/speakers${
|
|
298
|
+
getSpeakers(requestContext) {
|
|
299
|
+
return this.request(`/api/agents/${this.agentId}/voice/speakers${requestContextQueryString(requestContext)}`);
|
|
305
300
|
}
|
|
306
301
|
/**
|
|
307
302
|
* Get the listener configuration for the agent's voice provider
|
|
308
|
-
* @param
|
|
309
|
-
* @param
|
|
303
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
304
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
310
305
|
* @returns Promise containing a check if the agent has listening capabilities
|
|
311
306
|
*/
|
|
312
|
-
getListener(
|
|
313
|
-
return this.request(`/api/agents/${this.agentId}/voice/listener${
|
|
307
|
+
getListener(requestContext) {
|
|
308
|
+
return this.request(`/api/agents/${this.agentId}/voice/listener${requestContextQueryString(requestContext)}`);
|
|
314
309
|
}
|
|
315
310
|
};
|
|
316
311
|
var Agent = class extends BaseResource {
|
|
@@ -322,21 +317,27 @@ var Agent = class extends BaseResource {
|
|
|
322
317
|
voice;
|
|
323
318
|
/**
|
|
324
319
|
* Retrieves details about the agent
|
|
325
|
-
* @param
|
|
320
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
326
321
|
* @returns Promise containing agent details including model and instructions
|
|
327
322
|
*/
|
|
328
|
-
details(
|
|
329
|
-
return this.request(`/api/agents/${this.agentId}${
|
|
323
|
+
details(requestContext) {
|
|
324
|
+
return this.request(`/api/agents/${this.agentId}${requestContextQueryString(requestContext)}`);
|
|
325
|
+
}
|
|
326
|
+
enhanceInstructions(instructions, comment) {
|
|
327
|
+
return this.request(`/api/agents/${this.agentId}/instructions/enhance`, {
|
|
328
|
+
method: "POST",
|
|
329
|
+
body: { instructions, comment }
|
|
330
|
+
});
|
|
330
331
|
}
|
|
331
332
|
async generateLegacy(params) {
|
|
332
333
|
const processedParams = {
|
|
333
334
|
...params,
|
|
334
335
|
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
335
336
|
experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
|
|
336
|
-
|
|
337
|
+
requestContext: parseClientRequestContext(params.requestContext),
|
|
337
338
|
clientTools: processClientTools(params.clientTools)
|
|
338
339
|
};
|
|
339
|
-
const {
|
|
340
|
+
const { resourceId, threadId, requestContext } = processedParams;
|
|
340
341
|
const response = await this.request(
|
|
341
342
|
`/api/agents/${this.agentId}/generate-legacy`,
|
|
342
343
|
{
|
|
@@ -352,22 +353,18 @@ var Agent = class extends BaseResource {
|
|
|
352
353
|
for (const toolCall of toolCalls) {
|
|
353
354
|
const clientTool = params.clientTools?.[toolCall.toolName];
|
|
354
355
|
if (clientTool && clientTool.execute) {
|
|
355
|
-
const result = await clientTool.execute(
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
resourceId,
|
|
360
|
-
threadId,
|
|
361
|
-
runtimeContext,
|
|
362
|
-
tracingContext: { currentSpan: void 0 },
|
|
363
|
-
suspend: async () => {
|
|
364
|
-
}
|
|
365
|
-
},
|
|
366
|
-
{
|
|
356
|
+
const result = await clientTool.execute(toolCall?.args, {
|
|
357
|
+
requestContext,
|
|
358
|
+
tracingContext: { currentSpan: void 0 },
|
|
359
|
+
agent: {
|
|
367
360
|
messages: response.messages,
|
|
368
|
-
toolCallId: toolCall?.toolCallId
|
|
361
|
+
toolCallId: toolCall?.toolCallId,
|
|
362
|
+
suspend: async () => {
|
|
363
|
+
},
|
|
364
|
+
threadId,
|
|
365
|
+
resourceId
|
|
369
366
|
}
|
|
370
|
-
);
|
|
367
|
+
});
|
|
371
368
|
const updatedMessages = [
|
|
372
369
|
...response.response.messages,
|
|
373
370
|
{
|
|
@@ -403,15 +400,14 @@ var Agent = class extends BaseResource {
|
|
|
403
400
|
}
|
|
404
401
|
const processedParams = {
|
|
405
402
|
...params,
|
|
406
|
-
|
|
407
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
403
|
+
requestContext: parseClientRequestContext(params.requestContext),
|
|
408
404
|
clientTools: processClientTools(params.clientTools),
|
|
409
405
|
structuredOutput: params.structuredOutput ? {
|
|
410
406
|
...params.structuredOutput,
|
|
411
407
|
schema: zodToJsonSchema(params.structuredOutput.schema)
|
|
412
408
|
} : void 0
|
|
413
409
|
};
|
|
414
|
-
const {
|
|
410
|
+
const { resourceId, threadId, requestContext } = processedParams;
|
|
415
411
|
const response = await this.request(
|
|
416
412
|
`/api/agents/${this.agentId}/generate`,
|
|
417
413
|
{
|
|
@@ -423,10 +419,9 @@ var Agent = class extends BaseResource {
|
|
|
423
419
|
return executeToolCallAndRespond({
|
|
424
420
|
response,
|
|
425
421
|
params,
|
|
426
|
-
runId,
|
|
427
422
|
resourceId,
|
|
428
423
|
threadId,
|
|
429
|
-
|
|
424
|
+
requestContext,
|
|
430
425
|
respondFn: this.generate.bind(this)
|
|
431
426
|
});
|
|
432
427
|
}
|
|
@@ -704,7 +699,7 @@ var Agent = class extends BaseResource {
|
|
|
704
699
|
...params,
|
|
705
700
|
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
706
701
|
experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
|
|
707
|
-
|
|
702
|
+
requestContext: parseClientRequestContext(params.requestContext),
|
|
708
703
|
clientTools: processClientTools(params.clientTools)
|
|
709
704
|
};
|
|
710
705
|
const { readable, writable } = new TransformStream();
|
|
@@ -986,7 +981,7 @@ var Agent = class extends BaseResource {
|
|
|
986
981
|
});
|
|
987
982
|
onFinish?.({ message, finishReason, usage });
|
|
988
983
|
}
|
|
989
|
-
async processStreamResponse(processedParams,
|
|
984
|
+
async processStreamResponse(processedParams, controller, route = "stream") {
|
|
990
985
|
const response = await this.request(`/api/agents/${this.agentId}/${route}`, {
|
|
991
986
|
method: "POST",
|
|
992
987
|
body: processedParams,
|
|
@@ -998,29 +993,30 @@ var Agent = class extends BaseResource {
|
|
|
998
993
|
try {
|
|
999
994
|
let toolCalls = [];
|
|
1000
995
|
let messages = [];
|
|
1001
|
-
const [
|
|
1002
|
-
|
|
996
|
+
const [streamForController, streamForProcessing] = response.body.tee();
|
|
997
|
+
const pipePromise = streamForController.pipeTo(
|
|
1003
998
|
new WritableStream({
|
|
1004
999
|
async write(chunk) {
|
|
1005
|
-
let writer;
|
|
1006
1000
|
try {
|
|
1007
|
-
writer = writable.getWriter();
|
|
1008
1001
|
const text = new TextDecoder().decode(chunk);
|
|
1009
1002
|
const lines = text.split("\n\n");
|
|
1010
|
-
const readableLines = lines.filter((line) => line !== "[DONE]").join("\n\n");
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1003
|
+
const readableLines = lines.filter((line) => line.trim() !== "[DONE]" && line.trim() !== "data: [DONE]").join("\n\n");
|
|
1004
|
+
if (readableLines) {
|
|
1005
|
+
const encoded = new TextEncoder().encode(readableLines);
|
|
1006
|
+
controller.enqueue(encoded);
|
|
1007
|
+
}
|
|
1008
|
+
} catch (error) {
|
|
1009
|
+
console.error("Error enqueueing to controller:", error);
|
|
1010
|
+
controller.enqueue(chunk);
|
|
1016
1011
|
}
|
|
1017
1012
|
}
|
|
1018
|
-
})
|
|
1019
|
-
{
|
|
1020
|
-
preventClose: true
|
|
1021
|
-
}
|
|
1013
|
+
})
|
|
1022
1014
|
).catch((error) => {
|
|
1023
|
-
console.error("Error piping to
|
|
1015
|
+
console.error("Error piping to controller:", error);
|
|
1016
|
+
try {
|
|
1017
|
+
controller.close();
|
|
1018
|
+
} catch {
|
|
1019
|
+
}
|
|
1024
1020
|
});
|
|
1025
1021
|
this.processChatResponse_vNext({
|
|
1026
1022
|
stream: streamForProcessing,
|
|
@@ -1043,23 +1039,19 @@ var Agent = class extends BaseResource {
|
|
|
1043
1039
|
const clientTool = processedParams.clientTools?.[toolCall2.toolName];
|
|
1044
1040
|
if (clientTool && clientTool.execute) {
|
|
1045
1041
|
shouldExecuteClientTool = true;
|
|
1046
|
-
const result = await clientTool.execute(
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
threadId: processedParams.threadId,
|
|
1052
|
-
runtimeContext: processedParams.runtimeContext,
|
|
1053
|
-
// TODO: Pass proper tracing context when client-js supports tracing
|
|
1054
|
-
tracingContext: { currentSpan: void 0 },
|
|
1055
|
-
suspend: async () => {
|
|
1056
|
-
}
|
|
1057
|
-
},
|
|
1058
|
-
{
|
|
1042
|
+
const result = await clientTool.execute(toolCall2?.args, {
|
|
1043
|
+
requestContext: processedParams.requestContext,
|
|
1044
|
+
// TODO: Pass proper tracing context when client-js supports tracing
|
|
1045
|
+
tracingContext: { currentSpan: void 0 },
|
|
1046
|
+
agent: {
|
|
1059
1047
|
messages: response.messages,
|
|
1060
|
-
toolCallId: toolCall2?.toolCallId
|
|
1048
|
+
toolCallId: toolCall2?.toolCallId,
|
|
1049
|
+
suspend: async () => {
|
|
1050
|
+
},
|
|
1051
|
+
threadId: processedParams.threadId,
|
|
1052
|
+
resourceId: processedParams.resourceId
|
|
1061
1053
|
}
|
|
1062
|
-
);
|
|
1054
|
+
});
|
|
1063
1055
|
const lastMessageRaw = messages[messages.length - 1];
|
|
1064
1056
|
const lastMessage = lastMessageRaw != null ? JSON.parse(JSON.stringify(lastMessageRaw)) : void 0;
|
|
1065
1057
|
const toolInvocationPart = lastMessage?.parts?.find(
|
|
@@ -1080,31 +1072,36 @@ var Agent = class extends BaseResource {
|
|
|
1080
1072
|
toolInvocation.result = result;
|
|
1081
1073
|
}
|
|
1082
1074
|
const updatedMessages = lastMessage != null ? [...messages.filter((m) => m.id !== lastMessage.id), lastMessage] : [...messages];
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
})
|
|
1075
|
+
try {
|
|
1076
|
+
await this.processStreamResponse(
|
|
1077
|
+
{
|
|
1078
|
+
...processedParams,
|
|
1079
|
+
messages: updatedMessages
|
|
1080
|
+
},
|
|
1081
|
+
controller
|
|
1082
|
+
);
|
|
1083
|
+
} catch (error) {
|
|
1084
|
+
console.error("Error processing recursive stream response:", error);
|
|
1085
|
+
}
|
|
1092
1086
|
}
|
|
1093
1087
|
}
|
|
1094
1088
|
if (!shouldExecuteClientTool) {
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
}, 0);
|
|
1089
|
+
await pipePromise;
|
|
1090
|
+
controller.close();
|
|
1098
1091
|
}
|
|
1099
1092
|
} else {
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
}, 0);
|
|
1093
|
+
await pipePromise;
|
|
1094
|
+
controller.close();
|
|
1103
1095
|
}
|
|
1104
1096
|
},
|
|
1105
1097
|
lastMessage: void 0
|
|
1106
|
-
}).catch((error) => {
|
|
1098
|
+
}).catch(async (error) => {
|
|
1107
1099
|
console.error("Error processing stream response:", error);
|
|
1100
|
+
try {
|
|
1101
|
+
await pipePromise;
|
|
1102
|
+
controller.close();
|
|
1103
|
+
} catch {
|
|
1104
|
+
}
|
|
1108
1105
|
});
|
|
1109
1106
|
} catch (error) {
|
|
1110
1107
|
console.error("Error processing stream response:", error);
|
|
@@ -1147,16 +1144,20 @@ var Agent = class extends BaseResource {
|
|
|
1147
1144
|
}
|
|
1148
1145
|
const processedParams = {
|
|
1149
1146
|
...params,
|
|
1150
|
-
|
|
1151
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
1147
|
+
requestContext: parseClientRequestContext(params.requestContext),
|
|
1152
1148
|
clientTools: processClientTools(params.clientTools),
|
|
1153
1149
|
structuredOutput: params.structuredOutput ? {
|
|
1154
1150
|
...params.structuredOutput,
|
|
1155
1151
|
schema: zodToJsonSchema(params.structuredOutput.schema)
|
|
1156
1152
|
} : void 0
|
|
1157
1153
|
};
|
|
1158
|
-
|
|
1159
|
-
const
|
|
1154
|
+
let readableController;
|
|
1155
|
+
const readable = new ReadableStream({
|
|
1156
|
+
start(controller) {
|
|
1157
|
+
readableController = controller;
|
|
1158
|
+
}
|
|
1159
|
+
});
|
|
1160
|
+
const response = await this.processStreamResponse(processedParams, readableController);
|
|
1160
1161
|
const streamResponse = new Response(readable, {
|
|
1161
1162
|
status: response.status,
|
|
1162
1163
|
statusText: response.statusText,
|
|
@@ -1173,8 +1174,13 @@ var Agent = class extends BaseResource {
|
|
|
1173
1174
|
return streamResponse;
|
|
1174
1175
|
}
|
|
1175
1176
|
async approveToolCall(params) {
|
|
1176
|
-
|
|
1177
|
-
const
|
|
1177
|
+
let readableController;
|
|
1178
|
+
const readable = new ReadableStream({
|
|
1179
|
+
start(controller) {
|
|
1180
|
+
readableController = controller;
|
|
1181
|
+
}
|
|
1182
|
+
});
|
|
1183
|
+
const response = await this.processStreamResponse(params, readableController, "approve-tool-call");
|
|
1178
1184
|
const streamResponse = new Response(readable, {
|
|
1179
1185
|
status: response.status,
|
|
1180
1186
|
statusText: response.statusText,
|
|
@@ -1191,8 +1197,13 @@ var Agent = class extends BaseResource {
|
|
|
1191
1197
|
return streamResponse;
|
|
1192
1198
|
}
|
|
1193
1199
|
async declineToolCall(params) {
|
|
1194
|
-
|
|
1195
|
-
const
|
|
1200
|
+
let readableController;
|
|
1201
|
+
const readable = new ReadableStream({
|
|
1202
|
+
start(controller) {
|
|
1203
|
+
readableController = controller;
|
|
1204
|
+
}
|
|
1205
|
+
});
|
|
1206
|
+
const response = await this.processStreamResponse(params, readableController, "decline-tool-call");
|
|
1196
1207
|
const streamResponse = new Response(readable, {
|
|
1197
1208
|
status: response.status,
|
|
1198
1209
|
statusText: response.statusText,
|
|
@@ -1248,23 +1259,19 @@ var Agent = class extends BaseResource {
|
|
|
1248
1259
|
for (const toolCall2 of toolCalls) {
|
|
1249
1260
|
const clientTool = processedParams.clientTools?.[toolCall2.toolName];
|
|
1250
1261
|
if (clientTool && clientTool.execute) {
|
|
1251
|
-
const result = await clientTool.execute(
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
threadId: processedParams.threadId,
|
|
1257
|
-
runtimeContext: processedParams.runtimeContext,
|
|
1258
|
-
// TODO: Pass proper tracing context when client-js supports tracing
|
|
1259
|
-
tracingContext: { currentSpan: void 0 },
|
|
1260
|
-
suspend: async () => {
|
|
1261
|
-
}
|
|
1262
|
-
},
|
|
1263
|
-
{
|
|
1262
|
+
const result = await clientTool.execute(toolCall2?.args, {
|
|
1263
|
+
requestContext: processedParams.requestContext,
|
|
1264
|
+
// TODO: Pass proper tracing context when client-js supports tracing
|
|
1265
|
+
tracingContext: { currentSpan: void 0 },
|
|
1266
|
+
agent: {
|
|
1264
1267
|
messages: response.messages,
|
|
1265
|
-
toolCallId: toolCall2?.toolCallId
|
|
1268
|
+
toolCallId: toolCall2?.toolCallId,
|
|
1269
|
+
suspend: async () => {
|
|
1270
|
+
},
|
|
1271
|
+
threadId: processedParams.threadId,
|
|
1272
|
+
resourceId: processedParams.resourceId
|
|
1266
1273
|
}
|
|
1267
|
-
);
|
|
1274
|
+
});
|
|
1268
1275
|
const lastMessage = JSON.parse(JSON.stringify(messages[messages.length - 1]));
|
|
1269
1276
|
const toolInvocationPart = lastMessage?.parts?.find(
|
|
1270
1277
|
(part) => part.type === "tool-invocation" && part.toolInvocation?.toolCallId === toolCall2.toolCallId
|
|
@@ -1325,11 +1332,11 @@ var Agent = class extends BaseResource {
|
|
|
1325
1332
|
/**
|
|
1326
1333
|
* Gets details about a specific tool available to the agent
|
|
1327
1334
|
* @param toolId - ID of the tool to retrieve
|
|
1328
|
-
* @param
|
|
1335
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1329
1336
|
* @returns Promise containing tool details
|
|
1330
1337
|
*/
|
|
1331
|
-
getTool(toolId,
|
|
1332
|
-
return this.request(`/api/agents/${this.agentId}/tools/${toolId}${
|
|
1338
|
+
getTool(toolId, requestContext) {
|
|
1339
|
+
return this.request(`/api/agents/${this.agentId}/tools/${toolId}${requestContextQueryString(requestContext)}`);
|
|
1333
1340
|
}
|
|
1334
1341
|
/**
|
|
1335
1342
|
* Executes a tool for the agent
|
|
@@ -1340,29 +1347,13 @@ var Agent = class extends BaseResource {
|
|
|
1340
1347
|
executeTool(toolId, params) {
|
|
1341
1348
|
const body = {
|
|
1342
1349
|
data: params.data,
|
|
1343
|
-
|
|
1350
|
+
requestContext: parseClientRequestContext(params.requestContext)
|
|
1344
1351
|
};
|
|
1345
1352
|
return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
|
|
1346
1353
|
method: "POST",
|
|
1347
1354
|
body
|
|
1348
1355
|
});
|
|
1349
1356
|
}
|
|
1350
|
-
/**
|
|
1351
|
-
* Retrieves evaluation results for the agent
|
|
1352
|
-
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1353
|
-
* @returns Promise containing agent evaluations
|
|
1354
|
-
*/
|
|
1355
|
-
evals(runtimeContext) {
|
|
1356
|
-
return this.request(`/api/agents/${this.agentId}/evals/ci${runtimeContextQueryString(runtimeContext)}`);
|
|
1357
|
-
}
|
|
1358
|
-
/**
|
|
1359
|
-
* Retrieves live evaluation results for the agent
|
|
1360
|
-
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1361
|
-
* @returns Promise containing live agent evaluations
|
|
1362
|
-
*/
|
|
1363
|
-
liveEvals(runtimeContext) {
|
|
1364
|
-
return this.request(`/api/agents/${this.agentId}/evals/live${runtimeContextQueryString(runtimeContext)}`);
|
|
1365
|
-
}
|
|
1366
1357
|
/**
|
|
1367
1358
|
* Updates the model for the agent
|
|
1368
1359
|
* @param params - Parameters for updating the model
|
|
@@ -1405,12 +1396,6 @@ var Agent = class extends BaseResource {
|
|
|
1405
1396
|
body: params
|
|
1406
1397
|
});
|
|
1407
1398
|
}
|
|
1408
|
-
async generateVNext(_messagesOrParams, _options) {
|
|
1409
|
-
throw new Error("generateVNext has been renamed to generate. Please use generate instead.");
|
|
1410
|
-
}
|
|
1411
|
-
async streamVNext(_messagesOrParams, _options) {
|
|
1412
|
-
throw new Error("streamVNext has been renamed to stream. Please use stream instead.");
|
|
1413
|
-
}
|
|
1414
1399
|
};
|
|
1415
1400
|
|
|
1416
1401
|
// src/resources/memory-thread.ts
|
|
@@ -1422,22 +1407,22 @@ var MemoryThread = class extends BaseResource {
|
|
|
1422
1407
|
}
|
|
1423
1408
|
/**
|
|
1424
1409
|
* Retrieves the memory thread details
|
|
1425
|
-
* @param
|
|
1410
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1426
1411
|
* @returns Promise containing thread details including title and metadata
|
|
1427
1412
|
*/
|
|
1428
|
-
get(
|
|
1413
|
+
get(requestContext) {
|
|
1429
1414
|
return this.request(
|
|
1430
|
-
`/api/memory/threads/${this.threadId}?agentId=${this.agentId}${
|
|
1415
|
+
`/api/memory/threads/${this.threadId}?agentId=${this.agentId}${requestContextQueryString(requestContext, "&")}`
|
|
1431
1416
|
);
|
|
1432
1417
|
}
|
|
1433
1418
|
/**
|
|
1434
1419
|
* Updates the memory thread properties
|
|
1435
|
-
* @param params - Update parameters including title, metadata, and optional
|
|
1420
|
+
* @param params - Update parameters including title, metadata, and optional request context
|
|
1436
1421
|
* @returns Promise containing updated thread details
|
|
1437
1422
|
*/
|
|
1438
1423
|
update(params) {
|
|
1439
1424
|
return this.request(
|
|
1440
|
-
`/api/memory/threads/${this.threadId}?agentId=${this.agentId}${
|
|
1425
|
+
`/api/memory/threads/${this.threadId}?agentId=${this.agentId}${requestContextQueryString(params.requestContext, "&")}`,
|
|
1441
1426
|
{
|
|
1442
1427
|
method: "PATCH",
|
|
1443
1428
|
body: params
|
|
@@ -1446,62 +1431,49 @@ var MemoryThread = class extends BaseResource {
|
|
|
1446
1431
|
}
|
|
1447
1432
|
/**
|
|
1448
1433
|
* Deletes the memory thread
|
|
1449
|
-
* @param
|
|
1434
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1450
1435
|
* @returns Promise containing deletion result
|
|
1451
1436
|
*/
|
|
1452
|
-
delete(
|
|
1437
|
+
delete(requestContext) {
|
|
1453
1438
|
return this.request(
|
|
1454
|
-
`/api/memory/threads/${this.threadId}?agentId=${this.agentId}${
|
|
1439
|
+
`/api/memory/threads/${this.threadId}?agentId=${this.agentId}${requestContextQueryString(requestContext, "&")}`,
|
|
1455
1440
|
{
|
|
1456
1441
|
method: "DELETE"
|
|
1457
1442
|
}
|
|
1458
1443
|
);
|
|
1459
1444
|
}
|
|
1460
1445
|
/**
|
|
1461
|
-
* Retrieves messages associated with the thread
|
|
1462
|
-
* @param params -
|
|
1463
|
-
* @returns Promise containing thread messages and UI messages
|
|
1464
|
-
*/
|
|
1465
|
-
getMessages(params) {
|
|
1466
|
-
const query = new URLSearchParams({
|
|
1467
|
-
agentId: this.agentId,
|
|
1468
|
-
...params?.limit ? { limit: params.limit.toString() } : {}
|
|
1469
|
-
});
|
|
1470
|
-
return this.request(
|
|
1471
|
-
`/api/memory/threads/${this.threadId}/messages?${query.toString()}${runtimeContextQueryString(params?.runtimeContext, "&")}`
|
|
1472
|
-
);
|
|
1473
|
-
}
|
|
1474
|
-
/**
|
|
1475
|
-
* Retrieves paginated messages associated with the thread with advanced filtering and selection options
|
|
1476
|
-
* @param params - Pagination parameters including selectBy criteria, page, perPage, date ranges, message inclusion options, and runtime context
|
|
1446
|
+
* Retrieves paginated messages associated with the thread with filtering and ordering options
|
|
1447
|
+
* @param params - Pagination parameters including page, perPage, orderBy, filter, include options, and request context
|
|
1477
1448
|
* @returns Promise containing paginated thread messages with pagination metadata (total, page, perPage, hasMore)
|
|
1478
1449
|
*/
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
)
|
|
1450
|
+
listMessages(params = {}) {
|
|
1451
|
+
const { page, perPage, orderBy, filter, include, resourceId, requestContext } = params;
|
|
1452
|
+
const queryParams = {};
|
|
1453
|
+
if (resourceId) queryParams.resourceId = resourceId;
|
|
1454
|
+
if (page !== void 0) queryParams.page = String(page);
|
|
1455
|
+
if (perPage !== void 0) queryParams.perPage = String(perPage);
|
|
1456
|
+
if (orderBy) queryParams.orderBy = JSON.stringify(orderBy);
|
|
1457
|
+
if (filter) queryParams.filter = JSON.stringify(filter);
|
|
1458
|
+
if (include) queryParams.include = JSON.stringify(include);
|
|
1459
|
+
const query = new URLSearchParams(queryParams);
|
|
1460
|
+
const queryString = query.toString();
|
|
1461
|
+
const url = `/api/memory/threads/${this.threadId}/messages${queryString ? `?${queryString}` : ""}${requestContextQueryString(requestContext, queryString ? "&" : "?")}`;
|
|
1462
|
+
return this.request(url);
|
|
1491
1463
|
}
|
|
1492
1464
|
/**
|
|
1493
1465
|
* Deletes one or more messages from the thread
|
|
1494
1466
|
* @param messageIds - Can be a single message ID (string), array of message IDs,
|
|
1495
1467
|
* message object with id property, or array of message objects
|
|
1496
|
-
* @param
|
|
1468
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1497
1469
|
* @returns Promise containing deletion result
|
|
1498
1470
|
*/
|
|
1499
|
-
deleteMessages(messageIds,
|
|
1471
|
+
deleteMessages(messageIds, requestContext) {
|
|
1500
1472
|
const query = new URLSearchParams({
|
|
1501
1473
|
agentId: this.agentId
|
|
1502
1474
|
});
|
|
1503
1475
|
return this.request(
|
|
1504
|
-
`/api/memory/messages/delete?${query.toString()}${
|
|
1476
|
+
`/api/memory/messages/delete?${query.toString()}${requestContextQueryString(requestContext, "&")}`,
|
|
1505
1477
|
{
|
|
1506
1478
|
method: "POST",
|
|
1507
1479
|
body: { messageIds }
|
|
@@ -1519,12 +1491,12 @@ var Vector = class extends BaseResource {
|
|
|
1519
1491
|
/**
|
|
1520
1492
|
* Retrieves details about a specific vector index
|
|
1521
1493
|
* @param indexName - Name of the index to get details for
|
|
1522
|
-
* @param
|
|
1494
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1523
1495
|
* @returns Promise containing vector index details
|
|
1524
1496
|
*/
|
|
1525
|
-
details(indexName,
|
|
1497
|
+
details(indexName, requestContext) {
|
|
1526
1498
|
return this.request(
|
|
1527
|
-
`/api/vector/${this.vectorName}/indexes/${indexName}${
|
|
1499
|
+
`/api/vector/${this.vectorName}/indexes/${indexName}${requestContextQueryString(requestContext)}`
|
|
1528
1500
|
);
|
|
1529
1501
|
}
|
|
1530
1502
|
/**
|
|
@@ -1539,11 +1511,11 @@ var Vector = class extends BaseResource {
|
|
|
1539
1511
|
}
|
|
1540
1512
|
/**
|
|
1541
1513
|
* Retrieves a list of all available indexes
|
|
1542
|
-
* @param
|
|
1514
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1543
1515
|
* @returns Promise containing array of index names
|
|
1544
1516
|
*/
|
|
1545
|
-
getIndexes(
|
|
1546
|
-
return this.request(`/api/vector/${this.vectorName}/indexes${
|
|
1517
|
+
getIndexes(requestContext) {
|
|
1518
|
+
return this.request(`/api/vector/${this.vectorName}/indexes${requestContextQueryString(requestContext)}`);
|
|
1547
1519
|
}
|
|
1548
1520
|
/**
|
|
1549
1521
|
* Creates a new vector index
|
|
@@ -1588,11 +1560,11 @@ var Tool = class extends BaseResource {
|
|
|
1588
1560
|
}
|
|
1589
1561
|
/**
|
|
1590
1562
|
* Retrieves details about the tool
|
|
1591
|
-
* @param
|
|
1563
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1592
1564
|
* @returns Promise containing tool details including description and schemas
|
|
1593
1565
|
*/
|
|
1594
|
-
details(
|
|
1595
|
-
return this.request(`/api/tools/${this.toolId}${
|
|
1566
|
+
details(requestContext) {
|
|
1567
|
+
return this.request(`/api/tools/${this.toolId}${requestContextQueryString(requestContext)}`);
|
|
1596
1568
|
}
|
|
1597
1569
|
/**
|
|
1598
1570
|
* Executes the tool with the provided parameters
|
|
@@ -1606,7 +1578,7 @@ var Tool = class extends BaseResource {
|
|
|
1606
1578
|
}
|
|
1607
1579
|
const body = {
|
|
1608
1580
|
data: params.data,
|
|
1609
|
-
|
|
1581
|
+
requestContext: parseClientRequestContext(params.requestContext)
|
|
1610
1582
|
};
|
|
1611
1583
|
return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
|
|
1612
1584
|
method: "POST",
|
|
@@ -1622,67 +1594,22 @@ var Workflow = class extends BaseResource {
|
|
|
1622
1594
|
super(options);
|
|
1623
1595
|
this.workflowId = workflowId;
|
|
1624
1596
|
}
|
|
1625
|
-
/**
|
|
1626
|
-
* Creates an async generator that processes a readable stream and yields workflow records
|
|
1627
|
-
* separated by the Record Separator character (\x1E)
|
|
1628
|
-
*
|
|
1629
|
-
* @param stream - The readable stream to process
|
|
1630
|
-
* @returns An async generator that yields parsed records
|
|
1631
|
-
*/
|
|
1632
|
-
async *streamProcessor(stream) {
|
|
1633
|
-
const reader = stream.getReader();
|
|
1634
|
-
let doneReading = false;
|
|
1635
|
-
let buffer = "";
|
|
1636
|
-
try {
|
|
1637
|
-
while (!doneReading) {
|
|
1638
|
-
const { done, value } = await reader.read();
|
|
1639
|
-
doneReading = done;
|
|
1640
|
-
if (done && !value) continue;
|
|
1641
|
-
try {
|
|
1642
|
-
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
1643
|
-
const chunks = (buffer + decoded).split(RECORD_SEPARATOR);
|
|
1644
|
-
buffer = chunks.pop() || "";
|
|
1645
|
-
for (const chunk of chunks) {
|
|
1646
|
-
if (chunk) {
|
|
1647
|
-
if (typeof chunk === "string") {
|
|
1648
|
-
try {
|
|
1649
|
-
const parsedChunk = JSON.parse(chunk);
|
|
1650
|
-
yield parsedChunk;
|
|
1651
|
-
} catch {
|
|
1652
|
-
}
|
|
1653
|
-
}
|
|
1654
|
-
}
|
|
1655
|
-
}
|
|
1656
|
-
} catch {
|
|
1657
|
-
}
|
|
1658
|
-
}
|
|
1659
|
-
if (buffer) {
|
|
1660
|
-
try {
|
|
1661
|
-
yield JSON.parse(buffer);
|
|
1662
|
-
} catch {
|
|
1663
|
-
}
|
|
1664
|
-
}
|
|
1665
|
-
} finally {
|
|
1666
|
-
reader.cancel().catch(() => {
|
|
1667
|
-
});
|
|
1668
|
-
}
|
|
1669
|
-
}
|
|
1670
1597
|
/**
|
|
1671
1598
|
* Retrieves details about the workflow
|
|
1672
|
-
* @param
|
|
1599
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1673
1600
|
* @returns Promise containing workflow details including steps and graphs
|
|
1674
1601
|
*/
|
|
1675
|
-
details(
|
|
1676
|
-
return this.request(`/api/workflows/${this.workflowId}${
|
|
1602
|
+
details(requestContext) {
|
|
1603
|
+
return this.request(`/api/workflows/${this.workflowId}${requestContextQueryString(requestContext)}`);
|
|
1677
1604
|
}
|
|
1678
1605
|
/**
|
|
1679
1606
|
* Retrieves all runs for a workflow
|
|
1680
1607
|
* @param params - Parameters for filtering runs
|
|
1681
|
-
* @param
|
|
1608
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1682
1609
|
* @returns Promise containing workflow runs array
|
|
1683
1610
|
*/
|
|
1684
|
-
runs(params,
|
|
1685
|
-
const
|
|
1611
|
+
runs(params, requestContext) {
|
|
1612
|
+
const requestContextParam = base64RequestContext(parseClientRequestContext(requestContext));
|
|
1686
1613
|
const searchParams = new URLSearchParams();
|
|
1687
1614
|
if (params?.fromDate) {
|
|
1688
1615
|
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
@@ -1690,17 +1617,21 @@ var Workflow = class extends BaseResource {
|
|
|
1690
1617
|
if (params?.toDate) {
|
|
1691
1618
|
searchParams.set("toDate", params.toDate.toISOString());
|
|
1692
1619
|
}
|
|
1693
|
-
if (params?.
|
|
1694
|
-
|
|
1620
|
+
if (params?.perPage !== null && params?.perPage !== void 0) {
|
|
1621
|
+
if (params.perPage === false) {
|
|
1622
|
+
searchParams.set("perPage", "false");
|
|
1623
|
+
} else if (typeof params.perPage === "number" && params.perPage > 0 && Number.isInteger(params.perPage)) {
|
|
1624
|
+
searchParams.set("perPage", String(params.perPage));
|
|
1625
|
+
}
|
|
1695
1626
|
}
|
|
1696
|
-
if (params?.
|
|
1697
|
-
searchParams.set("
|
|
1627
|
+
if (params?.page !== null && params?.page !== void 0 && !isNaN(Number(params?.page))) {
|
|
1628
|
+
searchParams.set("page", String(params.page));
|
|
1698
1629
|
}
|
|
1699
1630
|
if (params?.resourceId) {
|
|
1700
1631
|
searchParams.set("resourceId", params.resourceId);
|
|
1701
1632
|
}
|
|
1702
|
-
if (
|
|
1703
|
-
searchParams.set("
|
|
1633
|
+
if (requestContextParam) {
|
|
1634
|
+
searchParams.set("requestContext", requestContextParam);
|
|
1704
1635
|
}
|
|
1705
1636
|
if (searchParams.size) {
|
|
1706
1637
|
return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
|
|
@@ -1711,21 +1642,21 @@ var Workflow = class extends BaseResource {
|
|
|
1711
1642
|
/**
|
|
1712
1643
|
* Retrieves a specific workflow run by its ID
|
|
1713
1644
|
* @param runId - The ID of the workflow run to retrieve
|
|
1714
|
-
* @param
|
|
1645
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1715
1646
|
* @returns Promise containing the workflow run details
|
|
1716
1647
|
*/
|
|
1717
|
-
runById(runId,
|
|
1718
|
-
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}${
|
|
1648
|
+
runById(runId, requestContext) {
|
|
1649
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}${requestContextQueryString(requestContext)}`);
|
|
1719
1650
|
}
|
|
1720
1651
|
/**
|
|
1721
1652
|
* Retrieves the execution result for a specific workflow run by its ID
|
|
1722
1653
|
* @param runId - The ID of the workflow run to retrieve the execution result for
|
|
1723
|
-
* @param
|
|
1654
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1724
1655
|
* @returns Promise containing the workflow run execution result
|
|
1725
1656
|
*/
|
|
1726
|
-
runExecutionResult(runId,
|
|
1657
|
+
runExecutionResult(runId, requestContext) {
|
|
1727
1658
|
return this.request(
|
|
1728
|
-
`/api/workflows/${this.workflowId}/runs/${runId}/execution-result${
|
|
1659
|
+
`/api/workflows/${this.workflowId}/runs/${runId}/execution-result${requestContextQueryString(requestContext)}`
|
|
1729
1660
|
);
|
|
1730
1661
|
}
|
|
1731
1662
|
/**
|
|
@@ -1738,32 +1669,12 @@ var Workflow = class extends BaseResource {
|
|
|
1738
1669
|
method: "POST"
|
|
1739
1670
|
});
|
|
1740
1671
|
}
|
|
1741
|
-
/**
|
|
1742
|
-
* Sends an event to a specific workflow run by its ID
|
|
1743
|
-
* @param params - Object containing the runId, event and data
|
|
1744
|
-
* @returns Promise containing a success message
|
|
1745
|
-
*/
|
|
1746
|
-
sendRunEvent(params) {
|
|
1747
|
-
return this.request(`/api/workflows/${this.workflowId}/runs/${params.runId}/send-event`, {
|
|
1748
|
-
method: "POST",
|
|
1749
|
-
body: { event: params.event, data: params.data }
|
|
1750
|
-
});
|
|
1751
|
-
}
|
|
1752
|
-
/**
|
|
1753
|
-
* @deprecated Use createRunAsync() instead.
|
|
1754
|
-
* @throws {Error} Always throws an error directing users to use createRunAsync()
|
|
1755
|
-
*/
|
|
1756
|
-
async createRun(_params) {
|
|
1757
|
-
throw new Error(
|
|
1758
|
-
"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."
|
|
1759
|
-
);
|
|
1760
|
-
}
|
|
1761
1672
|
/**
|
|
1762
1673
|
* Creates a new workflow run
|
|
1763
1674
|
* @param params - Optional object containing the optional runId
|
|
1764
1675
|
* @returns Promise containing the runId of the created run with methods to control execution
|
|
1765
1676
|
*/
|
|
1766
|
-
async
|
|
1677
|
+
async createRun(params) {
|
|
1767
1678
|
const searchParams = new URLSearchParams();
|
|
1768
1679
|
if (!!params?.runId) {
|
|
1769
1680
|
searchParams.set("runId", params.runId);
|
|
@@ -1781,7 +1692,7 @@ var Workflow = class extends BaseResource {
|
|
|
1781
1692
|
return this.start({
|
|
1782
1693
|
runId,
|
|
1783
1694
|
inputData: p.inputData,
|
|
1784
|
-
|
|
1695
|
+
requestContext: p.requestContext,
|
|
1785
1696
|
tracingOptions: p.tracingOptions
|
|
1786
1697
|
});
|
|
1787
1698
|
},
|
|
@@ -1789,22 +1700,19 @@ var Workflow = class extends BaseResource {
|
|
|
1789
1700
|
return this.startAsync({
|
|
1790
1701
|
runId,
|
|
1791
1702
|
inputData: p.inputData,
|
|
1792
|
-
|
|
1703
|
+
requestContext: p.requestContext,
|
|
1793
1704
|
tracingOptions: p.tracingOptions
|
|
1794
1705
|
});
|
|
1795
1706
|
},
|
|
1796
|
-
watch: async (onRecord) => {
|
|
1797
|
-
return this.watch({ runId }, onRecord);
|
|
1798
|
-
},
|
|
1799
1707
|
stream: async (p) => {
|
|
1800
|
-
return this.stream({ runId, inputData: p.inputData,
|
|
1708
|
+
return this.stream({ runId, inputData: p.inputData, requestContext: p.requestContext });
|
|
1801
1709
|
},
|
|
1802
1710
|
resume: async (p) => {
|
|
1803
1711
|
return this.resume({
|
|
1804
1712
|
runId,
|
|
1805
1713
|
step: p.step,
|
|
1806
1714
|
resumeData: p.resumeData,
|
|
1807
|
-
|
|
1715
|
+
requestContext: p.requestContext,
|
|
1808
1716
|
tracingOptions: p.tracingOptions
|
|
1809
1717
|
});
|
|
1810
1718
|
},
|
|
@@ -1813,7 +1721,7 @@ var Workflow = class extends BaseResource {
|
|
|
1813
1721
|
runId,
|
|
1814
1722
|
step: p.step,
|
|
1815
1723
|
resumeData: p.resumeData,
|
|
1816
|
-
|
|
1724
|
+
requestContext: p.requestContext,
|
|
1817
1725
|
tracingOptions: p.tracingOptions
|
|
1818
1726
|
});
|
|
1819
1727
|
},
|
|
@@ -1822,26 +1730,26 @@ var Workflow = class extends BaseResource {
|
|
|
1822
1730
|
runId,
|
|
1823
1731
|
step: p.step,
|
|
1824
1732
|
resumeData: p.resumeData,
|
|
1825
|
-
|
|
1733
|
+
requestContext: p.requestContext
|
|
1826
1734
|
});
|
|
1827
1735
|
}
|
|
1828
1736
|
};
|
|
1829
1737
|
}
|
|
1830
1738
|
/**
|
|
1831
1739
|
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
1832
|
-
* @param params - Object containing the runId, inputData and
|
|
1740
|
+
* @param params - Object containing the runId, inputData and requestContext
|
|
1833
1741
|
* @returns Promise containing success message
|
|
1834
1742
|
*/
|
|
1835
1743
|
start(params) {
|
|
1836
|
-
const
|
|
1744
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
1837
1745
|
return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
|
|
1838
1746
|
method: "POST",
|
|
1839
|
-
body: { inputData: params?.inputData,
|
|
1747
|
+
body: { inputData: params?.inputData, requestContext, tracingOptions: params.tracingOptions }
|
|
1840
1748
|
});
|
|
1841
1749
|
}
|
|
1842
1750
|
/**
|
|
1843
1751
|
* Resumes a suspended workflow step synchronously without waiting for the workflow to complete
|
|
1844
|
-
* @param params - Object containing the runId, step, resumeData and
|
|
1752
|
+
* @param params - Object containing the runId, step, resumeData and requestContext
|
|
1845
1753
|
* @returns Promise containing success message
|
|
1846
1754
|
*/
|
|
1847
1755
|
resume({
|
|
@@ -1851,20 +1759,20 @@ var Workflow = class extends BaseResource {
|
|
|
1851
1759
|
tracingOptions,
|
|
1852
1760
|
...rest
|
|
1853
1761
|
}) {
|
|
1854
|
-
const
|
|
1762
|
+
const requestContext = parseClientRequestContext(rest.requestContext);
|
|
1855
1763
|
return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
|
|
1856
1764
|
method: "POST",
|
|
1857
1765
|
body: {
|
|
1858
1766
|
step,
|
|
1859
1767
|
resumeData,
|
|
1860
|
-
|
|
1768
|
+
requestContext,
|
|
1861
1769
|
tracingOptions
|
|
1862
1770
|
}
|
|
1863
1771
|
});
|
|
1864
1772
|
}
|
|
1865
1773
|
/**
|
|
1866
1774
|
* Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
|
|
1867
|
-
* @param params - Object containing the optional runId, inputData and
|
|
1775
|
+
* @param params - Object containing the optional runId, inputData and requestContext
|
|
1868
1776
|
* @returns Promise containing the workflow execution results
|
|
1869
1777
|
*/
|
|
1870
1778
|
startAsync(params) {
|
|
@@ -1872,15 +1780,15 @@ var Workflow = class extends BaseResource {
|
|
|
1872
1780
|
if (!!params?.runId) {
|
|
1873
1781
|
searchParams.set("runId", params.runId);
|
|
1874
1782
|
}
|
|
1875
|
-
const
|
|
1783
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
1876
1784
|
return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
1877
1785
|
method: "POST",
|
|
1878
|
-
body: { inputData: params.inputData,
|
|
1786
|
+
body: { inputData: params.inputData, requestContext, tracingOptions: params.tracingOptions }
|
|
1879
1787
|
});
|
|
1880
1788
|
}
|
|
1881
1789
|
/**
|
|
1882
1790
|
* Starts a workflow run and returns a stream
|
|
1883
|
-
* @param params - Object containing the optional runId, inputData and
|
|
1791
|
+
* @param params - Object containing the optional runId, inputData and requestContext
|
|
1884
1792
|
* @returns Promise containing the workflow execution results
|
|
1885
1793
|
*/
|
|
1886
1794
|
async stream(params) {
|
|
@@ -1888,12 +1796,12 @@ var Workflow = class extends BaseResource {
|
|
|
1888
1796
|
if (!!params?.runId) {
|
|
1889
1797
|
searchParams.set("runId", params.runId);
|
|
1890
1798
|
}
|
|
1891
|
-
const
|
|
1799
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
1892
1800
|
const response = await this.request(
|
|
1893
1801
|
`/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
|
|
1894
1802
|
{
|
|
1895
1803
|
method: "POST",
|
|
1896
|
-
body: { inputData: params.inputData,
|
|
1804
|
+
body: { inputData: params.inputData, requestContext, tracingOptions: params.tracingOptions },
|
|
1897
1805
|
stream: true
|
|
1898
1806
|
}
|
|
1899
1807
|
);
|
|
@@ -1978,7 +1886,7 @@ var Workflow = class extends BaseResource {
|
|
|
1978
1886
|
}
|
|
1979
1887
|
/**
|
|
1980
1888
|
* Starts a workflow run and returns a stream
|
|
1981
|
-
* @param params - Object containing the optional runId, inputData and
|
|
1889
|
+
* @param params - Object containing the optional runId, inputData and requestContext
|
|
1982
1890
|
* @returns Promise containing the workflow execution results
|
|
1983
1891
|
*/
|
|
1984
1892
|
async streamVNext(params) {
|
|
@@ -1986,14 +1894,14 @@ var Workflow = class extends BaseResource {
|
|
|
1986
1894
|
if (!!params?.runId) {
|
|
1987
1895
|
searchParams.set("runId", params.runId);
|
|
1988
1896
|
}
|
|
1989
|
-
const
|
|
1897
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
1990
1898
|
const response = await this.request(
|
|
1991
1899
|
`/api/workflows/${this.workflowId}/streamVNext?${searchParams.toString()}`,
|
|
1992
1900
|
{
|
|
1993
1901
|
method: "POST",
|
|
1994
1902
|
body: {
|
|
1995
1903
|
inputData: params.inputData,
|
|
1996
|
-
|
|
1904
|
+
requestContext,
|
|
1997
1905
|
closeOnSuspend: params.closeOnSuspend,
|
|
1998
1906
|
tracingOptions: params.tracingOptions
|
|
1999
1907
|
},
|
|
@@ -2081,30 +1989,30 @@ var Workflow = class extends BaseResource {
|
|
|
2081
1989
|
}
|
|
2082
1990
|
/**
|
|
2083
1991
|
* Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
2084
|
-
* @param params - Object containing the runId, step, resumeData and
|
|
1992
|
+
* @param params - Object containing the runId, step, resumeData and requestContext
|
|
2085
1993
|
* @returns Promise containing the workflow resume results
|
|
2086
1994
|
*/
|
|
2087
1995
|
resumeAsync(params) {
|
|
2088
|
-
const
|
|
1996
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2089
1997
|
return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
2090
1998
|
method: "POST",
|
|
2091
1999
|
body: {
|
|
2092
2000
|
step: params.step,
|
|
2093
2001
|
resumeData: params.resumeData,
|
|
2094
|
-
|
|
2002
|
+
requestContext,
|
|
2095
2003
|
tracingOptions: params.tracingOptions
|
|
2096
2004
|
}
|
|
2097
2005
|
});
|
|
2098
2006
|
}
|
|
2099
2007
|
/**
|
|
2100
2008
|
* Resumes a suspended workflow step that uses streamVNext asynchronously and returns a promise that resolves when the workflow is complete
|
|
2101
|
-
* @param params - Object containing the runId, step, resumeData and
|
|
2009
|
+
* @param params - Object containing the runId, step, resumeData and requestContext
|
|
2102
2010
|
* @returns Promise containing the workflow resume results
|
|
2103
2011
|
*/
|
|
2104
2012
|
async resumeStreamVNext(params) {
|
|
2105
2013
|
const searchParams = new URLSearchParams();
|
|
2106
2014
|
searchParams.set("runId", params.runId);
|
|
2107
|
-
const
|
|
2015
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2108
2016
|
const response = await this.request(
|
|
2109
2017
|
`/api/workflows/${this.workflowId}/resume-stream?${searchParams.toString()}`,
|
|
2110
2018
|
{
|
|
@@ -2112,7 +2020,7 @@ var Workflow = class extends BaseResource {
|
|
|
2112
2020
|
body: {
|
|
2113
2021
|
step: params.step,
|
|
2114
2022
|
resumeData: params.resumeData,
|
|
2115
|
-
|
|
2023
|
+
requestContext,
|
|
2116
2024
|
tracingOptions: params.tracingOptions
|
|
2117
2025
|
},
|
|
2118
2026
|
stream: true
|
|
@@ -2150,29 +2058,6 @@ var Workflow = class extends BaseResource {
|
|
|
2150
2058
|
});
|
|
2151
2059
|
return response.body.pipeThrough(transformStream);
|
|
2152
2060
|
}
|
|
2153
|
-
/**
|
|
2154
|
-
* Watches workflow transitions in real-time
|
|
2155
|
-
* @param runId - Optional run ID to filter the watch stream
|
|
2156
|
-
* @returns AsyncGenerator that yields parsed records from the workflow watch stream
|
|
2157
|
-
*/
|
|
2158
|
-
async watch({ runId }, onRecord) {
|
|
2159
|
-
const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
|
|
2160
|
-
stream: true
|
|
2161
|
-
});
|
|
2162
|
-
if (!response.ok) {
|
|
2163
|
-
throw new Error(`Failed to watch workflow: ${response.statusText}`);
|
|
2164
|
-
}
|
|
2165
|
-
if (!response.body) {
|
|
2166
|
-
throw new Error("Response body is null");
|
|
2167
|
-
}
|
|
2168
|
-
for await (const record of this.streamProcessor(response.body)) {
|
|
2169
|
-
if (typeof record === "string") {
|
|
2170
|
-
onRecord(JSON.parse(record));
|
|
2171
|
-
} else {
|
|
2172
|
-
onRecord(record);
|
|
2173
|
-
}
|
|
2174
|
-
}
|
|
2175
|
-
}
|
|
2176
2061
|
/**
|
|
2177
2062
|
* Creates a new ReadableStream from an iterable or async iterable of objects,
|
|
2178
2063
|
* serializing each as JSON and separating them with the record separator (\x1E).
|
|
@@ -2284,22 +2169,22 @@ var MCPTool = class extends BaseResource {
|
|
|
2284
2169
|
}
|
|
2285
2170
|
/**
|
|
2286
2171
|
* Retrieves details about this specific tool from the MCP server.
|
|
2287
|
-
* @param
|
|
2172
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
2288
2173
|
* @returns Promise containing the tool's information (name, description, schema).
|
|
2289
2174
|
*/
|
|
2290
|
-
details(
|
|
2291
|
-
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}${
|
|
2175
|
+
details(requestContext) {
|
|
2176
|
+
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}${requestContextQueryString(requestContext)}`);
|
|
2292
2177
|
}
|
|
2293
2178
|
/**
|
|
2294
2179
|
* Executes this specific tool on the MCP server.
|
|
2295
|
-
* @param params - Parameters for tool execution, including data/args and optional
|
|
2180
|
+
* @param params - Parameters for tool execution, including data/args and optional requestContext.
|
|
2296
2181
|
* @returns Promise containing the result of the tool execution.
|
|
2297
2182
|
*/
|
|
2298
2183
|
execute(params) {
|
|
2299
2184
|
const body = {};
|
|
2300
2185
|
if (params.data !== void 0) body.data = params.data;
|
|
2301
|
-
if (params.
|
|
2302
|
-
body.
|
|
2186
|
+
if (params.requestContext !== void 0) {
|
|
2187
|
+
body.requestContext = params.requestContext;
|
|
2303
2188
|
}
|
|
2304
2189
|
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}/execute`, {
|
|
2305
2190
|
method: "POST",
|
|
@@ -2345,19 +2230,39 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2345
2230
|
}
|
|
2346
2231
|
}
|
|
2347
2232
|
/**
|
|
2348
|
-
*
|
|
2349
|
-
* @throws {Error} Always throws an error directing users to use createRunAsync()
|
|
2233
|
+
* Creates a transform stream that parses binary chunks into JSON records.
|
|
2350
2234
|
*/
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2235
|
+
createRecordParserTransform() {
|
|
2236
|
+
let failedChunk = void 0;
|
|
2237
|
+
return new TransformStream({
|
|
2238
|
+
start() {
|
|
2239
|
+
},
|
|
2240
|
+
async transform(chunk, controller) {
|
|
2241
|
+
try {
|
|
2242
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
2243
|
+
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
2244
|
+
for (const chunk2 of chunks) {
|
|
2245
|
+
if (chunk2) {
|
|
2246
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
2247
|
+
try {
|
|
2248
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
2249
|
+
controller.enqueue(parsedChunk);
|
|
2250
|
+
failedChunk = void 0;
|
|
2251
|
+
} catch {
|
|
2252
|
+
failedChunk = newChunk;
|
|
2253
|
+
}
|
|
2254
|
+
}
|
|
2255
|
+
}
|
|
2256
|
+
} catch {
|
|
2257
|
+
}
|
|
2258
|
+
}
|
|
2259
|
+
});
|
|
2355
2260
|
}
|
|
2356
2261
|
/**
|
|
2357
2262
|
* Creates a new agent builder action run and returns the runId.
|
|
2358
2263
|
* This calls `/api/agent-builder/:actionId/create-run`.
|
|
2359
2264
|
*/
|
|
2360
|
-
async
|
|
2265
|
+
async createRun(params) {
|
|
2361
2266
|
const searchParams = new URLSearchParams();
|
|
2362
2267
|
if (!!params?.runId) {
|
|
2363
2268
|
searchParams.set("runId", params.runId);
|
|
@@ -2376,12 +2281,12 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2376
2281
|
if (runId) {
|
|
2377
2282
|
searchParams.set("runId", runId);
|
|
2378
2283
|
}
|
|
2379
|
-
const
|
|
2380
|
-
const {
|
|
2284
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2285
|
+
const { requestContext: _, ...actionParams } = params;
|
|
2381
2286
|
const url = `/api/agent-builder/${this.actionId}/start-async${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
|
|
2382
2287
|
const result = await this.request(url, {
|
|
2383
2288
|
method: "POST",
|
|
2384
|
-
body: { ...actionParams,
|
|
2289
|
+
body: { ...actionParams, requestContext }
|
|
2385
2290
|
});
|
|
2386
2291
|
return this.transformWorkflowResult(result);
|
|
2387
2292
|
}
|
|
@@ -2392,12 +2297,12 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2392
2297
|
async startActionRun(params, runId) {
|
|
2393
2298
|
const searchParams = new URLSearchParams();
|
|
2394
2299
|
searchParams.set("runId", runId);
|
|
2395
|
-
const
|
|
2396
|
-
const {
|
|
2300
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2301
|
+
const { requestContext: _, ...actionParams } = params;
|
|
2397
2302
|
const url = `/api/agent-builder/${this.actionId}/start?${searchParams.toString()}`;
|
|
2398
2303
|
return this.request(url, {
|
|
2399
2304
|
method: "POST",
|
|
2400
|
-
body: { ...actionParams,
|
|
2305
|
+
body: { ...actionParams, requestContext }
|
|
2401
2306
|
});
|
|
2402
2307
|
}
|
|
2403
2308
|
/**
|
|
@@ -2407,12 +2312,12 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2407
2312
|
async resume(params, runId) {
|
|
2408
2313
|
const searchParams = new URLSearchParams();
|
|
2409
2314
|
searchParams.set("runId", runId);
|
|
2410
|
-
const
|
|
2411
|
-
const {
|
|
2315
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2316
|
+
const { requestContext: _, ...resumeParams } = params;
|
|
2412
2317
|
const url = `/api/agent-builder/${this.actionId}/resume?${searchParams.toString()}`;
|
|
2413
2318
|
return this.request(url, {
|
|
2414
2319
|
method: "POST",
|
|
2415
|
-
body: { ...resumeParams,
|
|
2320
|
+
body: { ...resumeParams, requestContext }
|
|
2416
2321
|
});
|
|
2417
2322
|
}
|
|
2418
2323
|
/**
|
|
@@ -2422,12 +2327,12 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2422
2327
|
async resumeAsync(params, runId) {
|
|
2423
2328
|
const searchParams = new URLSearchParams();
|
|
2424
2329
|
searchParams.set("runId", runId);
|
|
2425
|
-
const
|
|
2426
|
-
const {
|
|
2330
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2331
|
+
const { requestContext: _, ...resumeParams } = params;
|
|
2427
2332
|
const url = `/api/agent-builder/${this.actionId}/resume-async?${searchParams.toString()}`;
|
|
2428
2333
|
const result = await this.request(url, {
|
|
2429
2334
|
method: "POST",
|
|
2430
|
-
body: { ...resumeParams,
|
|
2335
|
+
body: { ...resumeParams, requestContext }
|
|
2431
2336
|
});
|
|
2432
2337
|
return this.transformWorkflowResult(result);
|
|
2433
2338
|
}
|
|
@@ -2485,12 +2390,12 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2485
2390
|
if (runId) {
|
|
2486
2391
|
searchParams.set("runId", runId);
|
|
2487
2392
|
}
|
|
2488
|
-
const
|
|
2489
|
-
const {
|
|
2393
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2394
|
+
const { requestContext: _, ...actionParams } = params;
|
|
2490
2395
|
const url = `/api/agent-builder/${this.actionId}/stream${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
|
|
2491
2396
|
const response = await this.request(url, {
|
|
2492
2397
|
method: "POST",
|
|
2493
|
-
body: { ...actionParams,
|
|
2398
|
+
body: { ...actionParams, requestContext },
|
|
2494
2399
|
stream: true
|
|
2495
2400
|
});
|
|
2496
2401
|
if (!response.ok) {
|
|
@@ -2499,31 +2404,7 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2499
2404
|
if (!response.body) {
|
|
2500
2405
|
throw new Error("Response body is null");
|
|
2501
2406
|
}
|
|
2502
|
-
|
|
2503
|
-
const transformStream = new TransformStream({
|
|
2504
|
-
start() {
|
|
2505
|
-
},
|
|
2506
|
-
async transform(chunk, controller) {
|
|
2507
|
-
try {
|
|
2508
|
-
const decoded = new TextDecoder().decode(chunk);
|
|
2509
|
-
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
2510
|
-
for (const chunk2 of chunks) {
|
|
2511
|
-
if (chunk2) {
|
|
2512
|
-
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
2513
|
-
try {
|
|
2514
|
-
const parsedChunk = JSON.parse(newChunk);
|
|
2515
|
-
controller.enqueue(parsedChunk);
|
|
2516
|
-
failedChunk = void 0;
|
|
2517
|
-
} catch {
|
|
2518
|
-
failedChunk = newChunk;
|
|
2519
|
-
}
|
|
2520
|
-
}
|
|
2521
|
-
}
|
|
2522
|
-
} catch {
|
|
2523
|
-
}
|
|
2524
|
-
}
|
|
2525
|
-
});
|
|
2526
|
-
return response.body.pipeThrough(transformStream);
|
|
2407
|
+
return response.body.pipeThrough(this.createRecordParserTransform());
|
|
2527
2408
|
}
|
|
2528
2409
|
/**
|
|
2529
2410
|
* Streams agent builder action progress in real-time using VNext streaming.
|
|
@@ -2534,12 +2415,12 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2534
2415
|
if (runId) {
|
|
2535
2416
|
searchParams.set("runId", runId);
|
|
2536
2417
|
}
|
|
2537
|
-
const
|
|
2538
|
-
const {
|
|
2418
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2419
|
+
const { requestContext: _, ...actionParams } = params;
|
|
2539
2420
|
const url = `/api/agent-builder/${this.actionId}/streamVNext${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
|
|
2540
2421
|
const response = await this.request(url, {
|
|
2541
2422
|
method: "POST",
|
|
2542
|
-
body: { ...actionParams,
|
|
2423
|
+
body: { ...actionParams, requestContext },
|
|
2543
2424
|
stream: true
|
|
2544
2425
|
});
|
|
2545
2426
|
if (!response.ok) {
|
|
@@ -2548,57 +2429,94 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2548
2429
|
if (!response.body) {
|
|
2549
2430
|
throw new Error("Response body is null");
|
|
2550
2431
|
}
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
} catch {
|
|
2567
|
-
failedChunk = newChunk;
|
|
2568
|
-
}
|
|
2569
|
-
}
|
|
2570
|
-
}
|
|
2571
|
-
} catch {
|
|
2572
|
-
}
|
|
2573
|
-
}
|
|
2432
|
+
return response.body.pipeThrough(this.createRecordParserTransform());
|
|
2433
|
+
}
|
|
2434
|
+
/**
|
|
2435
|
+
* Observes an existing agent builder action run stream.
|
|
2436
|
+
* Replays cached execution from the beginning, then continues with live stream.
|
|
2437
|
+
* This is the recommended method for recovery after page refresh/hot reload.
|
|
2438
|
+
* This calls `/api/agent-builder/:actionId/observe` (which delegates to observeStreamVNext).
|
|
2439
|
+
*/
|
|
2440
|
+
async observeStream(params) {
|
|
2441
|
+
const searchParams = new URLSearchParams();
|
|
2442
|
+
searchParams.set("runId", params.runId);
|
|
2443
|
+
const url = `/api/agent-builder/${this.actionId}/observe?${searchParams.toString()}`;
|
|
2444
|
+
const response = await this.request(url, {
|
|
2445
|
+
method: "POST",
|
|
2446
|
+
stream: true
|
|
2574
2447
|
});
|
|
2575
|
-
|
|
2448
|
+
if (!response.ok) {
|
|
2449
|
+
throw new Error(`Failed to observe agent builder action stream: ${response.statusText}`);
|
|
2450
|
+
}
|
|
2451
|
+
if (!response.body) {
|
|
2452
|
+
throw new Error("Response body is null");
|
|
2453
|
+
}
|
|
2454
|
+
return response.body.pipeThrough(this.createRecordParserTransform());
|
|
2576
2455
|
}
|
|
2577
2456
|
/**
|
|
2578
|
-
*
|
|
2579
|
-
*
|
|
2580
|
-
*
|
|
2581
|
-
* This calls `/api/agent-builder/:actionId/watch`.
|
|
2457
|
+
* Observes an existing agent builder action run stream using VNext streaming API.
|
|
2458
|
+
* Replays cached execution from the beginning, then continues with live stream.
|
|
2459
|
+
* This calls `/api/agent-builder/:actionId/observe-streamVNext`.
|
|
2582
2460
|
*/
|
|
2583
|
-
async
|
|
2584
|
-
const
|
|
2461
|
+
async observeStreamVNext(params) {
|
|
2462
|
+
const searchParams = new URLSearchParams();
|
|
2463
|
+
searchParams.set("runId", params.runId);
|
|
2464
|
+
const url = `/api/agent-builder/${this.actionId}/observe-streamVNext?${searchParams.toString()}`;
|
|
2585
2465
|
const response = await this.request(url, {
|
|
2586
|
-
method: "
|
|
2466
|
+
method: "POST",
|
|
2587
2467
|
stream: true
|
|
2588
2468
|
});
|
|
2589
2469
|
if (!response.ok) {
|
|
2590
|
-
throw new Error(`Failed to
|
|
2470
|
+
throw new Error(`Failed to observe agent builder action stream VNext: ${response.statusText}`);
|
|
2591
2471
|
}
|
|
2592
2472
|
if (!response.body) {
|
|
2593
2473
|
throw new Error("Response body is null");
|
|
2594
2474
|
}
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2475
|
+
return response.body.pipeThrough(this.createRecordParserTransform());
|
|
2476
|
+
}
|
|
2477
|
+
/**
|
|
2478
|
+
* Observes an existing agent builder action run stream using legacy streaming API.
|
|
2479
|
+
* Replays cached execution from the beginning, then continues with live stream.
|
|
2480
|
+
* This calls `/api/agent-builder/:actionId/observe-stream-legacy`.
|
|
2481
|
+
*/
|
|
2482
|
+
async observeStreamLegacy(params) {
|
|
2483
|
+
const searchParams = new URLSearchParams();
|
|
2484
|
+
searchParams.set("runId", params.runId);
|
|
2485
|
+
const url = `/api/agent-builder/${this.actionId}/observe-stream-legacy?${searchParams.toString()}`;
|
|
2486
|
+
const response = await this.request(url, {
|
|
2487
|
+
method: "POST",
|
|
2488
|
+
stream: true
|
|
2489
|
+
});
|
|
2490
|
+
if (!response.ok) {
|
|
2491
|
+
throw new Error(`Failed to observe agent builder action stream legacy: ${response.statusText}`);
|
|
2601
2492
|
}
|
|
2493
|
+
if (!response.body) {
|
|
2494
|
+
throw new Error("Response body is null");
|
|
2495
|
+
}
|
|
2496
|
+
return response.body.pipeThrough(this.createRecordParserTransform());
|
|
2497
|
+
}
|
|
2498
|
+
/**
|
|
2499
|
+
* Resumes a suspended agent builder action and streams the results.
|
|
2500
|
+
* This calls `/api/agent-builder/:actionId/resume-stream`.
|
|
2501
|
+
*/
|
|
2502
|
+
async resumeStream(params) {
|
|
2503
|
+
const searchParams = new URLSearchParams();
|
|
2504
|
+
searchParams.set("runId", params.runId);
|
|
2505
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2506
|
+
const { runId: _, requestContext: __, ...resumeParams } = params;
|
|
2507
|
+
const url = `/api/agent-builder/${this.actionId}/resume-stream?${searchParams.toString()}`;
|
|
2508
|
+
const response = await this.request(url, {
|
|
2509
|
+
method: "POST",
|
|
2510
|
+
body: { ...resumeParams, requestContext },
|
|
2511
|
+
stream: true
|
|
2512
|
+
});
|
|
2513
|
+
if (!response.ok) {
|
|
2514
|
+
throw new Error(`Failed to resume agent builder action stream: ${response.statusText}`);
|
|
2515
|
+
}
|
|
2516
|
+
if (!response.body) {
|
|
2517
|
+
throw new Error("Response body is null");
|
|
2518
|
+
}
|
|
2519
|
+
return response.body.pipeThrough(this.createRecordParserTransform());
|
|
2602
2520
|
}
|
|
2603
2521
|
/**
|
|
2604
2522
|
* Gets a specific action run by its ID.
|
|
@@ -2630,11 +2548,11 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2630
2548
|
if (params?.toDate) {
|
|
2631
2549
|
searchParams.set("toDate", params.toDate.toISOString());
|
|
2632
2550
|
}
|
|
2633
|
-
if (params?.
|
|
2634
|
-
searchParams.set("
|
|
2551
|
+
if (params?.perPage !== void 0) {
|
|
2552
|
+
searchParams.set("perPage", String(params.perPage));
|
|
2635
2553
|
}
|
|
2636
|
-
if (params?.
|
|
2637
|
-
searchParams.set("
|
|
2554
|
+
if (params?.page !== void 0) {
|
|
2555
|
+
searchParams.set("page", String(params.page));
|
|
2638
2556
|
}
|
|
2639
2557
|
if (params?.resourceId) {
|
|
2640
2558
|
searchParams.set("resourceId", params.resourceId);
|
|
@@ -2664,17 +2582,6 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2664
2582
|
method: "POST"
|
|
2665
2583
|
});
|
|
2666
2584
|
}
|
|
2667
|
-
/**
|
|
2668
|
-
* Sends an event to an agent builder action run.
|
|
2669
|
-
* This calls `/api/agent-builder/:actionId/runs/:runId/send-event`.
|
|
2670
|
-
*/
|
|
2671
|
-
async sendRunEvent(params) {
|
|
2672
|
-
const url = `/api/agent-builder/${this.actionId}/runs/${params.runId}/send-event`;
|
|
2673
|
-
return this.request(url, {
|
|
2674
|
-
method: "POST",
|
|
2675
|
-
body: { event: params.event, data: params.data }
|
|
2676
|
-
});
|
|
2677
|
-
}
|
|
2678
2585
|
};
|
|
2679
2586
|
|
|
2680
2587
|
// src/resources/observability.ts
|
|
@@ -2683,15 +2590,15 @@ var Observability = class extends BaseResource {
|
|
|
2683
2590
|
super(options);
|
|
2684
2591
|
}
|
|
2685
2592
|
/**
|
|
2686
|
-
* Retrieves a specific
|
|
2593
|
+
* Retrieves a specific trace by ID
|
|
2687
2594
|
* @param traceId - ID of the trace to retrieve
|
|
2688
|
-
* @returns Promise containing the
|
|
2595
|
+
* @returns Promise containing the trace with all its spans
|
|
2689
2596
|
*/
|
|
2690
2597
|
getTrace(traceId) {
|
|
2691
2598
|
return this.request(`/api/observability/traces/${traceId}`);
|
|
2692
2599
|
}
|
|
2693
2600
|
/**
|
|
2694
|
-
* Retrieves paginated list of
|
|
2601
|
+
* Retrieves paginated list of traces with optional filtering
|
|
2695
2602
|
* @param params - Parameters for pagination and filtering
|
|
2696
2603
|
* @returns Promise containing paginated traces and pagination info
|
|
2697
2604
|
*/
|
|
@@ -2731,7 +2638,7 @@ var Observability = class extends BaseResource {
|
|
|
2731
2638
|
* @param params - Parameters containing trace ID, span ID, and pagination options
|
|
2732
2639
|
* @returns Promise containing scores and pagination info
|
|
2733
2640
|
*/
|
|
2734
|
-
|
|
2641
|
+
listScoresBySpan(params) {
|
|
2735
2642
|
const { traceId, spanId, page, perPage } = params;
|
|
2736
2643
|
const searchParams = new URLSearchParams();
|
|
2737
2644
|
if (page !== void 0) {
|
|
@@ -2753,69 +2660,6 @@ var Observability = class extends BaseResource {
|
|
|
2753
2660
|
}
|
|
2754
2661
|
};
|
|
2755
2662
|
|
|
2756
|
-
// src/resources/network-memory-thread.ts
|
|
2757
|
-
var NetworkMemoryThread = class extends BaseResource {
|
|
2758
|
-
constructor(options, threadId, networkId) {
|
|
2759
|
-
super(options);
|
|
2760
|
-
this.threadId = threadId;
|
|
2761
|
-
this.networkId = networkId;
|
|
2762
|
-
}
|
|
2763
|
-
/**
|
|
2764
|
-
* Retrieves the memory thread details
|
|
2765
|
-
* @returns Promise containing thread details including title and metadata
|
|
2766
|
-
*/
|
|
2767
|
-
get() {
|
|
2768
|
-
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`);
|
|
2769
|
-
}
|
|
2770
|
-
/**
|
|
2771
|
-
* Updates the memory thread properties
|
|
2772
|
-
* @param params - Update parameters including title and metadata
|
|
2773
|
-
* @returns Promise containing updated thread details
|
|
2774
|
-
*/
|
|
2775
|
-
update(params) {
|
|
2776
|
-
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
|
|
2777
|
-
method: "PATCH",
|
|
2778
|
-
body: params
|
|
2779
|
-
});
|
|
2780
|
-
}
|
|
2781
|
-
/**
|
|
2782
|
-
* Deletes the memory thread
|
|
2783
|
-
* @returns Promise containing deletion result
|
|
2784
|
-
*/
|
|
2785
|
-
delete() {
|
|
2786
|
-
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
|
|
2787
|
-
method: "DELETE"
|
|
2788
|
-
});
|
|
2789
|
-
}
|
|
2790
|
-
/**
|
|
2791
|
-
* Retrieves messages associated with the thread
|
|
2792
|
-
* @param params - Optional parameters including limit for number of messages to retrieve
|
|
2793
|
-
* @returns Promise containing thread messages and UI messages
|
|
2794
|
-
*/
|
|
2795
|
-
getMessages(params) {
|
|
2796
|
-
const query = new URLSearchParams({
|
|
2797
|
-
networkId: this.networkId,
|
|
2798
|
-
...params?.limit ? { limit: params.limit.toString() } : {}
|
|
2799
|
-
});
|
|
2800
|
-
return this.request(`/api/memory/network/threads/${this.threadId}/messages?${query.toString()}`);
|
|
2801
|
-
}
|
|
2802
|
-
/**
|
|
2803
|
-
* Deletes one or more messages from the thread
|
|
2804
|
-
* @param messageIds - Can be a single message ID (string), array of message IDs,
|
|
2805
|
-
* message object with id property, or array of message objects
|
|
2806
|
-
* @returns Promise containing deletion result
|
|
2807
|
-
*/
|
|
2808
|
-
deleteMessages(messageIds) {
|
|
2809
|
-
const query = new URLSearchParams({
|
|
2810
|
-
networkId: this.networkId
|
|
2811
|
-
});
|
|
2812
|
-
return this.request(`/api/memory/network/messages/delete?${query.toString()}`, {
|
|
2813
|
-
method: "POST",
|
|
2814
|
-
body: { messageIds }
|
|
2815
|
-
});
|
|
2816
|
-
}
|
|
2817
|
-
};
|
|
2818
|
-
|
|
2819
2663
|
// src/client.ts
|
|
2820
2664
|
var MastraClient = class extends BaseResource {
|
|
2821
2665
|
observability;
|
|
@@ -2825,18 +2669,21 @@ var MastraClient = class extends BaseResource {
|
|
|
2825
2669
|
}
|
|
2826
2670
|
/**
|
|
2827
2671
|
* Retrieves all available agents
|
|
2828
|
-
* @param
|
|
2672
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
2829
2673
|
* @returns Promise containing map of agent IDs to agent details
|
|
2830
2674
|
*/
|
|
2831
|
-
|
|
2832
|
-
const
|
|
2675
|
+
listAgents(requestContext) {
|
|
2676
|
+
const requestContextParam = base64RequestContext(parseClientRequestContext(requestContext));
|
|
2833
2677
|
const searchParams = new URLSearchParams();
|
|
2834
|
-
if (
|
|
2835
|
-
searchParams.set("
|
|
2678
|
+
if (requestContextParam) {
|
|
2679
|
+
searchParams.set("requestContext", requestContextParam);
|
|
2836
2680
|
}
|
|
2837
2681
|
const queryString = searchParams.toString();
|
|
2838
2682
|
return this.request(`/api/agents${queryString ? `?${queryString}` : ""}`);
|
|
2839
2683
|
}
|
|
2684
|
+
listAgentsModelProviders() {
|
|
2685
|
+
return this.request(`/api/agents/providers`);
|
|
2686
|
+
}
|
|
2840
2687
|
/**
|
|
2841
2688
|
* Gets an agent instance by ID
|
|
2842
2689
|
* @param agentId - ID of the agent to retrieve
|
|
@@ -2846,33 +2693,50 @@ var MastraClient = class extends BaseResource {
|
|
|
2846
2693
|
return new Agent(this.options, agentId);
|
|
2847
2694
|
}
|
|
2848
2695
|
/**
|
|
2849
|
-
*
|
|
2850
|
-
* @param params - Parameters containing
|
|
2851
|
-
* @returns Promise containing array of memory threads
|
|
2696
|
+
* Lists memory threads for a resource with pagination support
|
|
2697
|
+
* @param params - Parameters containing resource ID, pagination options, and optional request context
|
|
2698
|
+
* @returns Promise containing paginated array of memory threads with metadata
|
|
2852
2699
|
*/
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2700
|
+
async listMemoryThreads(params) {
|
|
2701
|
+
const queryParams = new URLSearchParams({
|
|
2702
|
+
resourceId: params.resourceId,
|
|
2703
|
+
resourceid: params.resourceId,
|
|
2704
|
+
agentId: params.agentId,
|
|
2705
|
+
...params.page !== void 0 && { page: params.page.toString() },
|
|
2706
|
+
...params.perPage !== void 0 && { perPage: params.perPage.toString() },
|
|
2707
|
+
...params.orderBy && { orderBy: params.orderBy },
|
|
2708
|
+
...params.sortDirection && { sortDirection: params.sortDirection }
|
|
2709
|
+
});
|
|
2710
|
+
const response = await this.request(
|
|
2711
|
+
`/api/memory/threads?${queryParams.toString()}${requestContextQueryString(params.requestContext, "&")}`
|
|
2856
2712
|
);
|
|
2713
|
+
const actualResponse = "threads" in response ? response : {
|
|
2714
|
+
threads: response,
|
|
2715
|
+
total: response.length,
|
|
2716
|
+
page: params.page ?? 0,
|
|
2717
|
+
perPage: params.perPage ?? 100,
|
|
2718
|
+
hasMore: false
|
|
2719
|
+
};
|
|
2720
|
+
return actualResponse;
|
|
2857
2721
|
}
|
|
2858
2722
|
/**
|
|
2859
2723
|
* Retrieves memory config for a resource
|
|
2860
|
-
* @param params - Parameters containing the resource ID and optional
|
|
2724
|
+
* @param params - Parameters containing the resource ID and optional request context
|
|
2861
2725
|
* @returns Promise containing memory configuration
|
|
2862
2726
|
*/
|
|
2863
2727
|
getMemoryConfig(params) {
|
|
2864
2728
|
return this.request(
|
|
2865
|
-
`/api/memory/config?agentId=${params.agentId}${
|
|
2729
|
+
`/api/memory/config?agentId=${params.agentId}${requestContextQueryString(params.requestContext, "&")}`
|
|
2866
2730
|
);
|
|
2867
2731
|
}
|
|
2868
2732
|
/**
|
|
2869
2733
|
* Creates a new memory thread
|
|
2870
|
-
* @param params - Parameters for creating the memory thread including optional
|
|
2734
|
+
* @param params - Parameters for creating the memory thread including optional request context
|
|
2871
2735
|
* @returns Promise containing the created memory thread
|
|
2872
2736
|
*/
|
|
2873
2737
|
createMemoryThread(params) {
|
|
2874
2738
|
return this.request(
|
|
2875
|
-
`/api/memory/threads?agentId=${params.agentId}${
|
|
2739
|
+
`/api/memory/threads?agentId=${params.agentId}${requestContextQueryString(params.requestContext, "&")}`,
|
|
2876
2740
|
{ method: "POST", body: params }
|
|
2877
2741
|
);
|
|
2878
2742
|
}
|
|
@@ -2881,35 +2745,38 @@ var MastraClient = class extends BaseResource {
|
|
|
2881
2745
|
* @param threadId - ID of the memory thread to retrieve
|
|
2882
2746
|
* @returns MemoryThread instance
|
|
2883
2747
|
*/
|
|
2884
|
-
getMemoryThread(threadId, agentId) {
|
|
2748
|
+
getMemoryThread({ threadId, agentId }) {
|
|
2885
2749
|
return new MemoryThread(this.options, threadId, agentId);
|
|
2886
2750
|
}
|
|
2887
|
-
|
|
2751
|
+
listThreadMessages(threadId, opts = {}) {
|
|
2752
|
+
if (!opts.agentId && !opts.networkId) {
|
|
2753
|
+
throw new Error("Either agentId or networkId must be provided");
|
|
2754
|
+
}
|
|
2888
2755
|
let url = "";
|
|
2889
2756
|
if (opts.agentId) {
|
|
2890
|
-
url = `/api/memory/threads/${threadId}/messages?agentId=${opts.agentId}${
|
|
2757
|
+
url = `/api/memory/threads/${threadId}/messages?agentId=${opts.agentId}${requestContextQueryString(opts.requestContext, "&")}`;
|
|
2891
2758
|
} else if (opts.networkId) {
|
|
2892
|
-
url = `/api/memory/network/threads/${threadId}/messages?networkId=${opts.networkId}${
|
|
2759
|
+
url = `/api/memory/network/threads/${threadId}/messages?networkId=${opts.networkId}${requestContextQueryString(opts.requestContext, "&")}`;
|
|
2893
2760
|
}
|
|
2894
2761
|
return this.request(url);
|
|
2895
2762
|
}
|
|
2896
2763
|
deleteThread(threadId, opts = {}) {
|
|
2897
2764
|
let url = "";
|
|
2898
2765
|
if (opts.agentId) {
|
|
2899
|
-
url = `/api/memory/threads/${threadId}?agentId=${opts.agentId}${
|
|
2766
|
+
url = `/api/memory/threads/${threadId}?agentId=${opts.agentId}${requestContextQueryString(opts.requestContext, "&")}`;
|
|
2900
2767
|
} else if (opts.networkId) {
|
|
2901
|
-
url = `/api/memory/network/threads/${threadId}?networkId=${opts.networkId}${
|
|
2768
|
+
url = `/api/memory/network/threads/${threadId}?networkId=${opts.networkId}${requestContextQueryString(opts.requestContext, "&")}`;
|
|
2902
2769
|
}
|
|
2903
2770
|
return this.request(url, { method: "DELETE" });
|
|
2904
2771
|
}
|
|
2905
2772
|
/**
|
|
2906
2773
|
* Saves messages to memory
|
|
2907
|
-
* @param params - Parameters containing messages to save and optional
|
|
2774
|
+
* @param params - Parameters containing messages to save and optional request context
|
|
2908
2775
|
* @returns Promise containing the saved messages
|
|
2909
2776
|
*/
|
|
2910
2777
|
saveMessageToMemory(params) {
|
|
2911
2778
|
return this.request(
|
|
2912
|
-
`/api/memory/save-messages?agentId=${params.agentId}${
|
|
2779
|
+
`/api/memory/save-messages?agentId=${params.agentId}${requestContextQueryString(params.requestContext, "&")}`,
|
|
2913
2780
|
{
|
|
2914
2781
|
method: "POST",
|
|
2915
2782
|
body: params
|
|
@@ -2919,64 +2786,22 @@ var MastraClient = class extends BaseResource {
|
|
|
2919
2786
|
/**
|
|
2920
2787
|
* Gets the status of the memory system
|
|
2921
2788
|
* @param agentId - The agent ID
|
|
2922
|
-
* @param
|
|
2789
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
2923
2790
|
* @returns Promise containing memory system status
|
|
2924
2791
|
*/
|
|
2925
|
-
getMemoryStatus(agentId,
|
|
2926
|
-
return this.request(`/api/memory/status?agentId=${agentId}${
|
|
2927
|
-
}
|
|
2928
|
-
/**
|
|
2929
|
-
* Retrieves memory threads for a resource
|
|
2930
|
-
* @param params - Parameters containing the resource ID
|
|
2931
|
-
* @returns Promise containing array of memory threads
|
|
2932
|
-
*/
|
|
2933
|
-
getNetworkMemoryThreads(params) {
|
|
2934
|
-
return this.request(`/api/memory/network/threads?resourceid=${params.resourceId}&networkId=${params.networkId}`);
|
|
2935
|
-
}
|
|
2936
|
-
/**
|
|
2937
|
-
* Creates a new memory thread
|
|
2938
|
-
* @param params - Parameters for creating the memory thread
|
|
2939
|
-
* @returns Promise containing the created memory thread
|
|
2940
|
-
*/
|
|
2941
|
-
createNetworkMemoryThread(params) {
|
|
2942
|
-
return this.request(`/api/memory/network/threads?networkId=${params.networkId}`, { method: "POST", body: params });
|
|
2943
|
-
}
|
|
2944
|
-
/**
|
|
2945
|
-
* Gets a memory thread instance by ID
|
|
2946
|
-
* @param threadId - ID of the memory thread to retrieve
|
|
2947
|
-
* @returns MemoryThread instance
|
|
2948
|
-
*/
|
|
2949
|
-
getNetworkMemoryThread(threadId, networkId) {
|
|
2950
|
-
return new NetworkMemoryThread(this.options, threadId, networkId);
|
|
2951
|
-
}
|
|
2952
|
-
/**
|
|
2953
|
-
* Saves messages to memory
|
|
2954
|
-
* @param params - Parameters containing messages to save
|
|
2955
|
-
* @returns Promise containing the saved messages
|
|
2956
|
-
*/
|
|
2957
|
-
saveNetworkMessageToMemory(params) {
|
|
2958
|
-
return this.request(`/api/memory/network/save-messages?networkId=${params.networkId}`, {
|
|
2959
|
-
method: "POST",
|
|
2960
|
-
body: params
|
|
2961
|
-
});
|
|
2962
|
-
}
|
|
2963
|
-
/**
|
|
2964
|
-
* Gets the status of the memory system
|
|
2965
|
-
* @returns Promise containing memory system status
|
|
2966
|
-
*/
|
|
2967
|
-
getNetworkMemoryStatus(networkId) {
|
|
2968
|
-
return this.request(`/api/memory/network/status?networkId=${networkId}`);
|
|
2792
|
+
getMemoryStatus(agentId, requestContext) {
|
|
2793
|
+
return this.request(`/api/memory/status?agentId=${agentId}${requestContextQueryString(requestContext, "&")}`);
|
|
2969
2794
|
}
|
|
2970
2795
|
/**
|
|
2971
2796
|
* Retrieves all available tools
|
|
2972
|
-
* @param
|
|
2797
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
2973
2798
|
* @returns Promise containing map of tool IDs to tool details
|
|
2974
2799
|
*/
|
|
2975
|
-
|
|
2976
|
-
const
|
|
2800
|
+
listTools(requestContext) {
|
|
2801
|
+
const requestContextParam = base64RequestContext(parseClientRequestContext(requestContext));
|
|
2977
2802
|
const searchParams = new URLSearchParams();
|
|
2978
|
-
if (
|
|
2979
|
-
searchParams.set("
|
|
2803
|
+
if (requestContextParam) {
|
|
2804
|
+
searchParams.set("requestContext", requestContextParam);
|
|
2980
2805
|
}
|
|
2981
2806
|
const queryString = searchParams.toString();
|
|
2982
2807
|
return this.request(`/api/tools${queryString ? `?${queryString}` : ""}`);
|
|
@@ -2991,14 +2816,14 @@ var MastraClient = class extends BaseResource {
|
|
|
2991
2816
|
}
|
|
2992
2817
|
/**
|
|
2993
2818
|
* Retrieves all available workflows
|
|
2994
|
-
* @param
|
|
2819
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
2995
2820
|
* @returns Promise containing map of workflow IDs to workflow details
|
|
2996
2821
|
*/
|
|
2997
|
-
|
|
2998
|
-
const
|
|
2822
|
+
listWorkflows(requestContext) {
|
|
2823
|
+
const requestContextParam = base64RequestContext(parseClientRequestContext(requestContext));
|
|
2999
2824
|
const searchParams = new URLSearchParams();
|
|
3000
|
-
if (
|
|
3001
|
-
searchParams.set("
|
|
2825
|
+
if (requestContextParam) {
|
|
2826
|
+
searchParams.set("requestContext", requestContextParam);
|
|
3002
2827
|
}
|
|
3003
2828
|
const queryString = searchParams.toString();
|
|
3004
2829
|
return this.request(`/api/workflows${queryString ? `?${queryString}` : ""}`);
|
|
@@ -3038,7 +2863,7 @@ var MastraClient = class extends BaseResource {
|
|
|
3038
2863
|
* @param params - Parameters for filtering logs
|
|
3039
2864
|
* @returns Promise containing array of log messages
|
|
3040
2865
|
*/
|
|
3041
|
-
|
|
2866
|
+
listLogs(params) {
|
|
3042
2867
|
const { transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
|
|
3043
2868
|
const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
|
|
3044
2869
|
const searchParams = new URLSearchParams();
|
|
@@ -3124,63 +2949,21 @@ var MastraClient = class extends BaseResource {
|
|
|
3124
2949
|
* List of all log transports
|
|
3125
2950
|
* @returns Promise containing list of log transports
|
|
3126
2951
|
*/
|
|
3127
|
-
|
|
2952
|
+
listLogTransports() {
|
|
3128
2953
|
return this.request("/api/logs/transports");
|
|
3129
2954
|
}
|
|
3130
|
-
/**
|
|
3131
|
-
* List of all traces (paged)
|
|
3132
|
-
* @param params - Parameters for filtering traces
|
|
3133
|
-
* @returns Promise containing telemetry data
|
|
3134
|
-
*/
|
|
3135
|
-
getTelemetry(params) {
|
|
3136
|
-
const { name, scope, page, perPage, attribute, fromDate, toDate } = params || {};
|
|
3137
|
-
const _attribute = attribute ? Object.entries(attribute).map(([key, value]) => `${key}:${value}`) : [];
|
|
3138
|
-
const searchParams = new URLSearchParams();
|
|
3139
|
-
if (name) {
|
|
3140
|
-
searchParams.set("name", name);
|
|
3141
|
-
}
|
|
3142
|
-
if (scope) {
|
|
3143
|
-
searchParams.set("scope", scope);
|
|
3144
|
-
}
|
|
3145
|
-
if (page) {
|
|
3146
|
-
searchParams.set("page", String(page));
|
|
3147
|
-
}
|
|
3148
|
-
if (perPage) {
|
|
3149
|
-
searchParams.set("perPage", String(perPage));
|
|
3150
|
-
}
|
|
3151
|
-
if (_attribute) {
|
|
3152
|
-
if (Array.isArray(_attribute)) {
|
|
3153
|
-
for (const attr of _attribute) {
|
|
3154
|
-
searchParams.append("attribute", attr);
|
|
3155
|
-
}
|
|
3156
|
-
} else {
|
|
3157
|
-
searchParams.set("attribute", _attribute);
|
|
3158
|
-
}
|
|
3159
|
-
}
|
|
3160
|
-
if (fromDate) {
|
|
3161
|
-
searchParams.set("fromDate", fromDate.toISOString());
|
|
3162
|
-
}
|
|
3163
|
-
if (toDate) {
|
|
3164
|
-
searchParams.set("toDate", toDate.toISOString());
|
|
3165
|
-
}
|
|
3166
|
-
if (searchParams.size) {
|
|
3167
|
-
return this.request(`/api/telemetry?${searchParams}`);
|
|
3168
|
-
} else {
|
|
3169
|
-
return this.request(`/api/telemetry`);
|
|
3170
|
-
}
|
|
3171
|
-
}
|
|
3172
2955
|
/**
|
|
3173
2956
|
* Retrieves a list of available MCP servers.
|
|
3174
|
-
* @param params - Optional parameters for pagination (
|
|
2957
|
+
* @param params - Optional parameters for pagination (perPage, page).
|
|
3175
2958
|
* @returns Promise containing the list of MCP servers and pagination info.
|
|
3176
2959
|
*/
|
|
3177
2960
|
getMcpServers(params) {
|
|
3178
2961
|
const searchParams = new URLSearchParams();
|
|
3179
|
-
if (params?.
|
|
3180
|
-
searchParams.set("
|
|
2962
|
+
if (params?.perPage !== void 0) {
|
|
2963
|
+
searchParams.set("perPage", String(params.perPage));
|
|
3181
2964
|
}
|
|
3182
|
-
if (params?.
|
|
3183
|
-
searchParams.set("
|
|
2965
|
+
if (params?.page !== void 0) {
|
|
2966
|
+
searchParams.set("page", String(params.page));
|
|
3184
2967
|
}
|
|
3185
2968
|
const queryString = searchParams.toString();
|
|
3186
2969
|
return this.request(`/api/mcp/v0/servers${queryString ? `?${queryString}` : ""}`);
|
|
@@ -3236,12 +3019,33 @@ var MastraClient = class extends BaseResource {
|
|
|
3236
3019
|
agentId,
|
|
3237
3020
|
threadId,
|
|
3238
3021
|
resourceId,
|
|
3239
|
-
|
|
3022
|
+
requestContext
|
|
3240
3023
|
}) {
|
|
3241
3024
|
return this.request(
|
|
3242
|
-
`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}${
|
|
3025
|
+
`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}${requestContextQueryString(requestContext, "&")}`
|
|
3243
3026
|
);
|
|
3244
3027
|
}
|
|
3028
|
+
searchMemory({
|
|
3029
|
+
agentId,
|
|
3030
|
+
resourceId,
|
|
3031
|
+
threadId,
|
|
3032
|
+
searchQuery,
|
|
3033
|
+
memoryConfig,
|
|
3034
|
+
requestContext
|
|
3035
|
+
}) {
|
|
3036
|
+
const params = new URLSearchParams({
|
|
3037
|
+
searchQuery,
|
|
3038
|
+
resourceId,
|
|
3039
|
+
agentId
|
|
3040
|
+
});
|
|
3041
|
+
if (threadId) {
|
|
3042
|
+
params.append("threadId", threadId);
|
|
3043
|
+
}
|
|
3044
|
+
if (memoryConfig) {
|
|
3045
|
+
params.append("memoryConfig", JSON.stringify(memoryConfig));
|
|
3046
|
+
}
|
|
3047
|
+
return this.request(`/api/memory/search?${params}${requestContextQueryString(requestContext, "&")}`);
|
|
3048
|
+
}
|
|
3245
3049
|
/**
|
|
3246
3050
|
* Updates the working memory for a specific thread (optionally resource-scoped).
|
|
3247
3051
|
* @param agentId - ID of the agent.
|
|
@@ -3254,10 +3058,10 @@ var MastraClient = class extends BaseResource {
|
|
|
3254
3058
|
threadId,
|
|
3255
3059
|
workingMemory,
|
|
3256
3060
|
resourceId,
|
|
3257
|
-
|
|
3061
|
+
requestContext
|
|
3258
3062
|
}) {
|
|
3259
3063
|
return this.request(
|
|
3260
|
-
`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}${
|
|
3064
|
+
`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}${requestContextQueryString(requestContext, "&")}`,
|
|
3261
3065
|
{
|
|
3262
3066
|
method: "POST",
|
|
3263
3067
|
body: {
|
|
@@ -3271,7 +3075,7 @@ var MastraClient = class extends BaseResource {
|
|
|
3271
3075
|
* Retrieves all available scorers
|
|
3272
3076
|
* @returns Promise containing list of available scorers
|
|
3273
3077
|
*/
|
|
3274
|
-
|
|
3078
|
+
listScorers() {
|
|
3275
3079
|
return this.request("/api/scores/scorers");
|
|
3276
3080
|
}
|
|
3277
3081
|
/**
|
|
@@ -3282,7 +3086,7 @@ var MastraClient = class extends BaseResource {
|
|
|
3282
3086
|
getScorer(scorerId) {
|
|
3283
3087
|
return this.request(`/api/scores/scorers/${encodeURIComponent(scorerId)}`);
|
|
3284
3088
|
}
|
|
3285
|
-
|
|
3089
|
+
listScoresByScorerId(params) {
|
|
3286
3090
|
const { page, perPage, scorerId, entityId, entityType } = params;
|
|
3287
3091
|
const searchParams = new URLSearchParams();
|
|
3288
3092
|
if (entityId) {
|
|
@@ -3305,7 +3109,7 @@ var MastraClient = class extends BaseResource {
|
|
|
3305
3109
|
* @param params - Parameters containing run ID and pagination options
|
|
3306
3110
|
* @returns Promise containing scores and pagination info
|
|
3307
3111
|
*/
|
|
3308
|
-
|
|
3112
|
+
listScoresByRunId(params) {
|
|
3309
3113
|
const { runId, page, perPage } = params;
|
|
3310
3114
|
const searchParams = new URLSearchParams();
|
|
3311
3115
|
if (page !== void 0) {
|
|
@@ -3322,7 +3126,7 @@ var MastraClient = class extends BaseResource {
|
|
|
3322
3126
|
* @param params - Parameters containing entity ID, type, and pagination options
|
|
3323
3127
|
* @returns Promise containing scores and pagination info
|
|
3324
3128
|
*/
|
|
3325
|
-
|
|
3129
|
+
listScoresByEntityId(params) {
|
|
3326
3130
|
const { entityId, entityType, page, perPage } = params;
|
|
3327
3131
|
const searchParams = new URLSearchParams();
|
|
3328
3132
|
if (page !== void 0) {
|
|
@@ -3347,14 +3151,14 @@ var MastraClient = class extends BaseResource {
|
|
|
3347
3151
|
body: params
|
|
3348
3152
|
});
|
|
3349
3153
|
}
|
|
3350
|
-
|
|
3154
|
+
getTrace(traceId) {
|
|
3351
3155
|
return this.observability.getTrace(traceId);
|
|
3352
3156
|
}
|
|
3353
|
-
|
|
3157
|
+
getTraces(params) {
|
|
3354
3158
|
return this.observability.getTraces(params);
|
|
3355
3159
|
}
|
|
3356
|
-
|
|
3357
|
-
return this.observability.
|
|
3160
|
+
listScoresBySpan(params) {
|
|
3161
|
+
return this.observability.listScoresBySpan(params);
|
|
3358
3162
|
}
|
|
3359
3163
|
score(params) {
|
|
3360
3164
|
return this.observability.score(params);
|