@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.js
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
import { processDataStream, parsePartialJson } from '@ai-sdk/ui-utils';
|
|
2
2
|
import { v4 } from '@lukeed/uuid';
|
|
3
3
|
import { getErrorFromUnknown } from '@mastra/core/error';
|
|
4
|
-
import {
|
|
4
|
+
import { RequestContext } from '@mastra/core/request-context';
|
|
5
5
|
import { isVercelTool } from '@mastra/core/tools/is-vercel-tool';
|
|
6
6
|
import { z } from 'zod';
|
|
7
7
|
import originalZodToJsonSchema from 'zod-to-json-schema';
|
|
8
8
|
|
|
9
9
|
// src/resources/agent.ts
|
|
10
|
-
function
|
|
11
|
-
if (
|
|
12
|
-
if (
|
|
13
|
-
return Object.fromEntries(
|
|
10
|
+
function parseClientRequestContext(requestContext) {
|
|
11
|
+
if (requestContext) {
|
|
12
|
+
if (requestContext instanceof RequestContext) {
|
|
13
|
+
return Object.fromEntries(requestContext.entries());
|
|
14
14
|
}
|
|
15
|
-
return
|
|
15
|
+
return requestContext;
|
|
16
16
|
}
|
|
17
17
|
return void 0;
|
|
18
18
|
}
|
|
19
|
-
function
|
|
20
|
-
if (
|
|
21
|
-
return btoa(JSON.stringify(
|
|
19
|
+
function base64RequestContext(requestContext) {
|
|
20
|
+
if (requestContext) {
|
|
21
|
+
return btoa(JSON.stringify(requestContext));
|
|
22
22
|
}
|
|
23
23
|
return void 0;
|
|
24
24
|
}
|
|
25
|
-
function
|
|
26
|
-
const
|
|
27
|
-
if (!
|
|
25
|
+
function requestContextQueryString(requestContext, delimiter = "?") {
|
|
26
|
+
const requestContextParam = base64RequestContext(parseClientRequestContext(requestContext));
|
|
27
|
+
if (!requestContextParam) return "";
|
|
28
28
|
const searchParams = new URLSearchParams();
|
|
29
|
-
searchParams.set("
|
|
29
|
+
searchParams.set("requestContext", requestContextParam);
|
|
30
30
|
const queryString = searchParams.toString();
|
|
31
31
|
return queryString ? `${delimiter}${queryString}` : "";
|
|
32
32
|
}
|
|
@@ -92,7 +92,6 @@ async function sharedProcessMastraStream({
|
|
|
92
92
|
if (line.startsWith("data: ")) {
|
|
93
93
|
const data = line.slice(6);
|
|
94
94
|
if (data === "[DONE]") {
|
|
95
|
-
console.info("\u{1F3C1} Stream finished");
|
|
96
95
|
return;
|
|
97
96
|
}
|
|
98
97
|
let json;
|
|
@@ -197,10 +196,9 @@ var BaseResource = class {
|
|
|
197
196
|
async function executeToolCallAndRespond({
|
|
198
197
|
response,
|
|
199
198
|
params,
|
|
200
|
-
runId,
|
|
201
199
|
resourceId,
|
|
202
200
|
threadId,
|
|
203
|
-
|
|
201
|
+
requestContext,
|
|
204
202
|
respondFn
|
|
205
203
|
}) {
|
|
206
204
|
if (response.finishReason === "tool-calls") {
|
|
@@ -209,24 +207,20 @@ async function executeToolCallAndRespond({
|
|
|
209
207
|
return response;
|
|
210
208
|
}
|
|
211
209
|
for (const toolCall of toolCalls) {
|
|
212
|
-
const clientTool = params.clientTools?.[toolCall.toolName];
|
|
210
|
+
const clientTool = params.clientTools?.[toolCall.payload.toolName];
|
|
213
211
|
if (clientTool && clientTool.execute) {
|
|
214
|
-
const result = await clientTool.execute(
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
resourceId,
|
|
219
|
-
threadId,
|
|
220
|
-
runtimeContext,
|
|
221
|
-
tracingContext: { currentSpan: void 0 },
|
|
222
|
-
suspend: async () => {
|
|
223
|
-
}
|
|
224
|
-
},
|
|
225
|
-
{
|
|
212
|
+
const result = await clientTool.execute(toolCall?.payload.args, {
|
|
213
|
+
requestContext,
|
|
214
|
+
tracingContext: { currentSpan: void 0 },
|
|
215
|
+
agent: {
|
|
226
216
|
messages: response.messages,
|
|
227
|
-
toolCallId: toolCall?.toolCallId
|
|
217
|
+
toolCallId: toolCall?.payload.toolCallId,
|
|
218
|
+
suspend: async () => {
|
|
219
|
+
},
|
|
220
|
+
threadId,
|
|
221
|
+
resourceId
|
|
228
222
|
}
|
|
229
|
-
);
|
|
223
|
+
});
|
|
230
224
|
const updatedMessages = [
|
|
231
225
|
...response.response.messages || [],
|
|
232
226
|
{
|
|
@@ -234,8 +228,8 @@ async function executeToolCallAndRespond({
|
|
|
234
228
|
content: [
|
|
235
229
|
{
|
|
236
230
|
type: "tool-result",
|
|
237
|
-
toolCallId: toolCall.toolCallId,
|
|
238
|
-
toolName: toolCall.toolName,
|
|
231
|
+
toolCallId: toolCall.payload.toolCallId,
|
|
232
|
+
toolName: toolCall.payload.toolName,
|
|
239
233
|
result
|
|
240
234
|
}
|
|
241
235
|
]
|
|
@@ -248,6 +242,7 @@ async function executeToolCallAndRespond({
|
|
|
248
242
|
}
|
|
249
243
|
}
|
|
250
244
|
}
|
|
245
|
+
return response;
|
|
251
246
|
}
|
|
252
247
|
var AgentVoice = class extends BaseResource {
|
|
253
248
|
constructor(options, agentId) {
|
|
@@ -290,21 +285,21 @@ var AgentVoice = class extends BaseResource {
|
|
|
290
285
|
}
|
|
291
286
|
/**
|
|
292
287
|
* Get available speakers for the agent's voice provider
|
|
293
|
-
* @param
|
|
294
|
-
* @param
|
|
288
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
289
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
295
290
|
* @returns Promise containing list of available speakers
|
|
296
291
|
*/
|
|
297
|
-
getSpeakers(
|
|
298
|
-
return this.request(`/api/agents/${this.agentId}/voice/speakers${
|
|
292
|
+
getSpeakers(requestContext) {
|
|
293
|
+
return this.request(`/api/agents/${this.agentId}/voice/speakers${requestContextQueryString(requestContext)}`);
|
|
299
294
|
}
|
|
300
295
|
/**
|
|
301
296
|
* Get the listener configuration for the agent's voice provider
|
|
302
|
-
* @param
|
|
303
|
-
* @param
|
|
297
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
298
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
304
299
|
* @returns Promise containing a check if the agent has listening capabilities
|
|
305
300
|
*/
|
|
306
|
-
getListener(
|
|
307
|
-
return this.request(`/api/agents/${this.agentId}/voice/listener${
|
|
301
|
+
getListener(requestContext) {
|
|
302
|
+
return this.request(`/api/agents/${this.agentId}/voice/listener${requestContextQueryString(requestContext)}`);
|
|
308
303
|
}
|
|
309
304
|
};
|
|
310
305
|
var Agent = class extends BaseResource {
|
|
@@ -316,21 +311,27 @@ var Agent = class extends BaseResource {
|
|
|
316
311
|
voice;
|
|
317
312
|
/**
|
|
318
313
|
* Retrieves details about the agent
|
|
319
|
-
* @param
|
|
314
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
320
315
|
* @returns Promise containing agent details including model and instructions
|
|
321
316
|
*/
|
|
322
|
-
details(
|
|
323
|
-
return this.request(`/api/agents/${this.agentId}${
|
|
317
|
+
details(requestContext) {
|
|
318
|
+
return this.request(`/api/agents/${this.agentId}${requestContextQueryString(requestContext)}`);
|
|
319
|
+
}
|
|
320
|
+
enhanceInstructions(instructions, comment) {
|
|
321
|
+
return this.request(`/api/agents/${this.agentId}/instructions/enhance`, {
|
|
322
|
+
method: "POST",
|
|
323
|
+
body: { instructions, comment }
|
|
324
|
+
});
|
|
324
325
|
}
|
|
325
326
|
async generateLegacy(params) {
|
|
326
327
|
const processedParams = {
|
|
327
328
|
...params,
|
|
328
329
|
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
329
330
|
experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
|
|
330
|
-
|
|
331
|
+
requestContext: parseClientRequestContext(params.requestContext),
|
|
331
332
|
clientTools: processClientTools(params.clientTools)
|
|
332
333
|
};
|
|
333
|
-
const {
|
|
334
|
+
const { resourceId, threadId, requestContext } = processedParams;
|
|
334
335
|
const response = await this.request(
|
|
335
336
|
`/api/agents/${this.agentId}/generate-legacy`,
|
|
336
337
|
{
|
|
@@ -346,22 +347,18 @@ var Agent = class extends BaseResource {
|
|
|
346
347
|
for (const toolCall of toolCalls) {
|
|
347
348
|
const clientTool = params.clientTools?.[toolCall.toolName];
|
|
348
349
|
if (clientTool && clientTool.execute) {
|
|
349
|
-
const result = await clientTool.execute(
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
resourceId,
|
|
354
|
-
threadId,
|
|
355
|
-
runtimeContext,
|
|
356
|
-
tracingContext: { currentSpan: void 0 },
|
|
357
|
-
suspend: async () => {
|
|
358
|
-
}
|
|
359
|
-
},
|
|
360
|
-
{
|
|
350
|
+
const result = await clientTool.execute(toolCall?.args, {
|
|
351
|
+
requestContext,
|
|
352
|
+
tracingContext: { currentSpan: void 0 },
|
|
353
|
+
agent: {
|
|
361
354
|
messages: response.messages,
|
|
362
|
-
toolCallId: toolCall?.toolCallId
|
|
355
|
+
toolCallId: toolCall?.toolCallId,
|
|
356
|
+
suspend: async () => {
|
|
357
|
+
},
|
|
358
|
+
threadId,
|
|
359
|
+
resourceId
|
|
363
360
|
}
|
|
364
|
-
);
|
|
361
|
+
});
|
|
365
362
|
const updatedMessages = [
|
|
366
363
|
...response.response.messages,
|
|
367
364
|
{
|
|
@@ -397,15 +394,14 @@ var Agent = class extends BaseResource {
|
|
|
397
394
|
}
|
|
398
395
|
const processedParams = {
|
|
399
396
|
...params,
|
|
400
|
-
|
|
401
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
397
|
+
requestContext: parseClientRequestContext(params.requestContext),
|
|
402
398
|
clientTools: processClientTools(params.clientTools),
|
|
403
399
|
structuredOutput: params.structuredOutput ? {
|
|
404
400
|
...params.structuredOutput,
|
|
405
401
|
schema: zodToJsonSchema(params.structuredOutput.schema)
|
|
406
402
|
} : void 0
|
|
407
403
|
};
|
|
408
|
-
const {
|
|
404
|
+
const { resourceId, threadId, requestContext } = processedParams;
|
|
409
405
|
const response = await this.request(
|
|
410
406
|
`/api/agents/${this.agentId}/generate`,
|
|
411
407
|
{
|
|
@@ -417,10 +413,9 @@ var Agent = class extends BaseResource {
|
|
|
417
413
|
return executeToolCallAndRespond({
|
|
418
414
|
response,
|
|
419
415
|
params,
|
|
420
|
-
runId,
|
|
421
416
|
resourceId,
|
|
422
417
|
threadId,
|
|
423
|
-
|
|
418
|
+
requestContext,
|
|
424
419
|
respondFn: this.generate.bind(this)
|
|
425
420
|
});
|
|
426
421
|
}
|
|
@@ -698,7 +693,7 @@ var Agent = class extends BaseResource {
|
|
|
698
693
|
...params,
|
|
699
694
|
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
700
695
|
experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
|
|
701
|
-
|
|
696
|
+
requestContext: parseClientRequestContext(params.requestContext),
|
|
702
697
|
clientTools: processClientTools(params.clientTools)
|
|
703
698
|
};
|
|
704
699
|
const { readable, writable } = new TransformStream();
|
|
@@ -980,7 +975,7 @@ var Agent = class extends BaseResource {
|
|
|
980
975
|
});
|
|
981
976
|
onFinish?.({ message, finishReason, usage });
|
|
982
977
|
}
|
|
983
|
-
async processStreamResponse(processedParams,
|
|
978
|
+
async processStreamResponse(processedParams, controller, route = "stream") {
|
|
984
979
|
const response = await this.request(`/api/agents/${this.agentId}/${route}`, {
|
|
985
980
|
method: "POST",
|
|
986
981
|
body: processedParams,
|
|
@@ -992,29 +987,30 @@ var Agent = class extends BaseResource {
|
|
|
992
987
|
try {
|
|
993
988
|
let toolCalls = [];
|
|
994
989
|
let messages = [];
|
|
995
|
-
const [
|
|
996
|
-
|
|
990
|
+
const [streamForController, streamForProcessing] = response.body.tee();
|
|
991
|
+
const pipePromise = streamForController.pipeTo(
|
|
997
992
|
new WritableStream({
|
|
998
993
|
async write(chunk) {
|
|
999
|
-
let writer;
|
|
1000
994
|
try {
|
|
1001
|
-
writer = writable.getWriter();
|
|
1002
995
|
const text = new TextDecoder().decode(chunk);
|
|
1003
996
|
const lines = text.split("\n\n");
|
|
1004
|
-
const readableLines = lines.filter((line) => line !== "[DONE]").join("\n\n");
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
997
|
+
const readableLines = lines.filter((line) => line.trim() !== "[DONE]" && line.trim() !== "data: [DONE]").join("\n\n");
|
|
998
|
+
if (readableLines) {
|
|
999
|
+
const encoded = new TextEncoder().encode(readableLines);
|
|
1000
|
+
controller.enqueue(encoded);
|
|
1001
|
+
}
|
|
1002
|
+
} catch (error) {
|
|
1003
|
+
console.error("Error enqueueing to controller:", error);
|
|
1004
|
+
controller.enqueue(chunk);
|
|
1010
1005
|
}
|
|
1011
1006
|
}
|
|
1012
|
-
})
|
|
1013
|
-
{
|
|
1014
|
-
preventClose: true
|
|
1015
|
-
}
|
|
1007
|
+
})
|
|
1016
1008
|
).catch((error) => {
|
|
1017
|
-
console.error("Error piping to
|
|
1009
|
+
console.error("Error piping to controller:", error);
|
|
1010
|
+
try {
|
|
1011
|
+
controller.close();
|
|
1012
|
+
} catch {
|
|
1013
|
+
}
|
|
1018
1014
|
});
|
|
1019
1015
|
this.processChatResponse_vNext({
|
|
1020
1016
|
stream: streamForProcessing,
|
|
@@ -1037,23 +1033,19 @@ var Agent = class extends BaseResource {
|
|
|
1037
1033
|
const clientTool = processedParams.clientTools?.[toolCall2.toolName];
|
|
1038
1034
|
if (clientTool && clientTool.execute) {
|
|
1039
1035
|
shouldExecuteClientTool = true;
|
|
1040
|
-
const result = await clientTool.execute(
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
threadId: processedParams.threadId,
|
|
1046
|
-
runtimeContext: processedParams.runtimeContext,
|
|
1047
|
-
// TODO: Pass proper tracing context when client-js supports tracing
|
|
1048
|
-
tracingContext: { currentSpan: void 0 },
|
|
1049
|
-
suspend: async () => {
|
|
1050
|
-
}
|
|
1051
|
-
},
|
|
1052
|
-
{
|
|
1036
|
+
const result = await clientTool.execute(toolCall2?.args, {
|
|
1037
|
+
requestContext: processedParams.requestContext,
|
|
1038
|
+
// TODO: Pass proper tracing context when client-js supports tracing
|
|
1039
|
+
tracingContext: { currentSpan: void 0 },
|
|
1040
|
+
agent: {
|
|
1053
1041
|
messages: response.messages,
|
|
1054
|
-
toolCallId: toolCall2?.toolCallId
|
|
1042
|
+
toolCallId: toolCall2?.toolCallId,
|
|
1043
|
+
suspend: async () => {
|
|
1044
|
+
},
|
|
1045
|
+
threadId: processedParams.threadId,
|
|
1046
|
+
resourceId: processedParams.resourceId
|
|
1055
1047
|
}
|
|
1056
|
-
);
|
|
1048
|
+
});
|
|
1057
1049
|
const lastMessageRaw = messages[messages.length - 1];
|
|
1058
1050
|
const lastMessage = lastMessageRaw != null ? JSON.parse(JSON.stringify(lastMessageRaw)) : void 0;
|
|
1059
1051
|
const toolInvocationPart = lastMessage?.parts?.find(
|
|
@@ -1074,31 +1066,36 @@ var Agent = class extends BaseResource {
|
|
|
1074
1066
|
toolInvocation.result = result;
|
|
1075
1067
|
}
|
|
1076
1068
|
const updatedMessages = lastMessage != null ? [...messages.filter((m) => m.id !== lastMessage.id), lastMessage] : [...messages];
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
})
|
|
1069
|
+
try {
|
|
1070
|
+
await this.processStreamResponse(
|
|
1071
|
+
{
|
|
1072
|
+
...processedParams,
|
|
1073
|
+
messages: updatedMessages
|
|
1074
|
+
},
|
|
1075
|
+
controller
|
|
1076
|
+
);
|
|
1077
|
+
} catch (error) {
|
|
1078
|
+
console.error("Error processing recursive stream response:", error);
|
|
1079
|
+
}
|
|
1086
1080
|
}
|
|
1087
1081
|
}
|
|
1088
1082
|
if (!shouldExecuteClientTool) {
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
}, 0);
|
|
1083
|
+
await pipePromise;
|
|
1084
|
+
controller.close();
|
|
1092
1085
|
}
|
|
1093
1086
|
} else {
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
}, 0);
|
|
1087
|
+
await pipePromise;
|
|
1088
|
+
controller.close();
|
|
1097
1089
|
}
|
|
1098
1090
|
},
|
|
1099
1091
|
lastMessage: void 0
|
|
1100
|
-
}).catch((error) => {
|
|
1092
|
+
}).catch(async (error) => {
|
|
1101
1093
|
console.error("Error processing stream response:", error);
|
|
1094
|
+
try {
|
|
1095
|
+
await pipePromise;
|
|
1096
|
+
controller.close();
|
|
1097
|
+
} catch {
|
|
1098
|
+
}
|
|
1102
1099
|
});
|
|
1103
1100
|
} catch (error) {
|
|
1104
1101
|
console.error("Error processing stream response:", error);
|
|
@@ -1141,16 +1138,20 @@ var Agent = class extends BaseResource {
|
|
|
1141
1138
|
}
|
|
1142
1139
|
const processedParams = {
|
|
1143
1140
|
...params,
|
|
1144
|
-
|
|
1145
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
1141
|
+
requestContext: parseClientRequestContext(params.requestContext),
|
|
1146
1142
|
clientTools: processClientTools(params.clientTools),
|
|
1147
1143
|
structuredOutput: params.structuredOutput ? {
|
|
1148
1144
|
...params.structuredOutput,
|
|
1149
1145
|
schema: zodToJsonSchema(params.structuredOutput.schema)
|
|
1150
1146
|
} : void 0
|
|
1151
1147
|
};
|
|
1152
|
-
|
|
1153
|
-
const
|
|
1148
|
+
let readableController;
|
|
1149
|
+
const readable = new ReadableStream({
|
|
1150
|
+
start(controller) {
|
|
1151
|
+
readableController = controller;
|
|
1152
|
+
}
|
|
1153
|
+
});
|
|
1154
|
+
const response = await this.processStreamResponse(processedParams, readableController);
|
|
1154
1155
|
const streamResponse = new Response(readable, {
|
|
1155
1156
|
status: response.status,
|
|
1156
1157
|
statusText: response.statusText,
|
|
@@ -1167,8 +1168,13 @@ var Agent = class extends BaseResource {
|
|
|
1167
1168
|
return streamResponse;
|
|
1168
1169
|
}
|
|
1169
1170
|
async approveToolCall(params) {
|
|
1170
|
-
|
|
1171
|
-
const
|
|
1171
|
+
let readableController;
|
|
1172
|
+
const readable = new ReadableStream({
|
|
1173
|
+
start(controller) {
|
|
1174
|
+
readableController = controller;
|
|
1175
|
+
}
|
|
1176
|
+
});
|
|
1177
|
+
const response = await this.processStreamResponse(params, readableController, "approve-tool-call");
|
|
1172
1178
|
const streamResponse = new Response(readable, {
|
|
1173
1179
|
status: response.status,
|
|
1174
1180
|
statusText: response.statusText,
|
|
@@ -1185,8 +1191,13 @@ var Agent = class extends BaseResource {
|
|
|
1185
1191
|
return streamResponse;
|
|
1186
1192
|
}
|
|
1187
1193
|
async declineToolCall(params) {
|
|
1188
|
-
|
|
1189
|
-
const
|
|
1194
|
+
let readableController;
|
|
1195
|
+
const readable = new ReadableStream({
|
|
1196
|
+
start(controller) {
|
|
1197
|
+
readableController = controller;
|
|
1198
|
+
}
|
|
1199
|
+
});
|
|
1200
|
+
const response = await this.processStreamResponse(params, readableController, "decline-tool-call");
|
|
1190
1201
|
const streamResponse = new Response(readable, {
|
|
1191
1202
|
status: response.status,
|
|
1192
1203
|
statusText: response.statusText,
|
|
@@ -1242,23 +1253,19 @@ var Agent = class extends BaseResource {
|
|
|
1242
1253
|
for (const toolCall2 of toolCalls) {
|
|
1243
1254
|
const clientTool = processedParams.clientTools?.[toolCall2.toolName];
|
|
1244
1255
|
if (clientTool && clientTool.execute) {
|
|
1245
|
-
const result = await clientTool.execute(
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
threadId: processedParams.threadId,
|
|
1251
|
-
runtimeContext: processedParams.runtimeContext,
|
|
1252
|
-
// TODO: Pass proper tracing context when client-js supports tracing
|
|
1253
|
-
tracingContext: { currentSpan: void 0 },
|
|
1254
|
-
suspend: async () => {
|
|
1255
|
-
}
|
|
1256
|
-
},
|
|
1257
|
-
{
|
|
1256
|
+
const result = await clientTool.execute(toolCall2?.args, {
|
|
1257
|
+
requestContext: processedParams.requestContext,
|
|
1258
|
+
// TODO: Pass proper tracing context when client-js supports tracing
|
|
1259
|
+
tracingContext: { currentSpan: void 0 },
|
|
1260
|
+
agent: {
|
|
1258
1261
|
messages: response.messages,
|
|
1259
|
-
toolCallId: toolCall2?.toolCallId
|
|
1262
|
+
toolCallId: toolCall2?.toolCallId,
|
|
1263
|
+
suspend: async () => {
|
|
1264
|
+
},
|
|
1265
|
+
threadId: processedParams.threadId,
|
|
1266
|
+
resourceId: processedParams.resourceId
|
|
1260
1267
|
}
|
|
1261
|
-
);
|
|
1268
|
+
});
|
|
1262
1269
|
const lastMessage = JSON.parse(JSON.stringify(messages[messages.length - 1]));
|
|
1263
1270
|
const toolInvocationPart = lastMessage?.parts?.find(
|
|
1264
1271
|
(part) => part.type === "tool-invocation" && part.toolInvocation?.toolCallId === toolCall2.toolCallId
|
|
@@ -1319,11 +1326,11 @@ var Agent = class extends BaseResource {
|
|
|
1319
1326
|
/**
|
|
1320
1327
|
* Gets details about a specific tool available to the agent
|
|
1321
1328
|
* @param toolId - ID of the tool to retrieve
|
|
1322
|
-
* @param
|
|
1329
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1323
1330
|
* @returns Promise containing tool details
|
|
1324
1331
|
*/
|
|
1325
|
-
getTool(toolId,
|
|
1326
|
-
return this.request(`/api/agents/${this.agentId}/tools/${toolId}${
|
|
1332
|
+
getTool(toolId, requestContext) {
|
|
1333
|
+
return this.request(`/api/agents/${this.agentId}/tools/${toolId}${requestContextQueryString(requestContext)}`);
|
|
1327
1334
|
}
|
|
1328
1335
|
/**
|
|
1329
1336
|
* Executes a tool for the agent
|
|
@@ -1334,29 +1341,13 @@ var Agent = class extends BaseResource {
|
|
|
1334
1341
|
executeTool(toolId, params) {
|
|
1335
1342
|
const body = {
|
|
1336
1343
|
data: params.data,
|
|
1337
|
-
|
|
1344
|
+
requestContext: parseClientRequestContext(params.requestContext)
|
|
1338
1345
|
};
|
|
1339
1346
|
return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
|
|
1340
1347
|
method: "POST",
|
|
1341
1348
|
body
|
|
1342
1349
|
});
|
|
1343
1350
|
}
|
|
1344
|
-
/**
|
|
1345
|
-
* Retrieves evaluation results for the agent
|
|
1346
|
-
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1347
|
-
* @returns Promise containing agent evaluations
|
|
1348
|
-
*/
|
|
1349
|
-
evals(runtimeContext) {
|
|
1350
|
-
return this.request(`/api/agents/${this.agentId}/evals/ci${runtimeContextQueryString(runtimeContext)}`);
|
|
1351
|
-
}
|
|
1352
|
-
/**
|
|
1353
|
-
* Retrieves live evaluation results for the agent
|
|
1354
|
-
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1355
|
-
* @returns Promise containing live agent evaluations
|
|
1356
|
-
*/
|
|
1357
|
-
liveEvals(runtimeContext) {
|
|
1358
|
-
return this.request(`/api/agents/${this.agentId}/evals/live${runtimeContextQueryString(runtimeContext)}`);
|
|
1359
|
-
}
|
|
1360
1351
|
/**
|
|
1361
1352
|
* Updates the model for the agent
|
|
1362
1353
|
* @param params - Parameters for updating the model
|
|
@@ -1399,12 +1390,6 @@ var Agent = class extends BaseResource {
|
|
|
1399
1390
|
body: params
|
|
1400
1391
|
});
|
|
1401
1392
|
}
|
|
1402
|
-
async generateVNext(_messagesOrParams, _options) {
|
|
1403
|
-
throw new Error("generateVNext has been renamed to generate. Please use generate instead.");
|
|
1404
|
-
}
|
|
1405
|
-
async streamVNext(_messagesOrParams, _options) {
|
|
1406
|
-
throw new Error("streamVNext has been renamed to stream. Please use stream instead.");
|
|
1407
|
-
}
|
|
1408
1393
|
};
|
|
1409
1394
|
|
|
1410
1395
|
// src/resources/memory-thread.ts
|
|
@@ -1416,22 +1401,22 @@ var MemoryThread = class extends BaseResource {
|
|
|
1416
1401
|
}
|
|
1417
1402
|
/**
|
|
1418
1403
|
* Retrieves the memory thread details
|
|
1419
|
-
* @param
|
|
1404
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1420
1405
|
* @returns Promise containing thread details including title and metadata
|
|
1421
1406
|
*/
|
|
1422
|
-
get(
|
|
1407
|
+
get(requestContext) {
|
|
1423
1408
|
return this.request(
|
|
1424
|
-
`/api/memory/threads/${this.threadId}?agentId=${this.agentId}${
|
|
1409
|
+
`/api/memory/threads/${this.threadId}?agentId=${this.agentId}${requestContextQueryString(requestContext, "&")}`
|
|
1425
1410
|
);
|
|
1426
1411
|
}
|
|
1427
1412
|
/**
|
|
1428
1413
|
* Updates the memory thread properties
|
|
1429
|
-
* @param params - Update parameters including title, metadata, and optional
|
|
1414
|
+
* @param params - Update parameters including title, metadata, and optional request context
|
|
1430
1415
|
* @returns Promise containing updated thread details
|
|
1431
1416
|
*/
|
|
1432
1417
|
update(params) {
|
|
1433
1418
|
return this.request(
|
|
1434
|
-
`/api/memory/threads/${this.threadId}?agentId=${this.agentId}${
|
|
1419
|
+
`/api/memory/threads/${this.threadId}?agentId=${this.agentId}${requestContextQueryString(params.requestContext, "&")}`,
|
|
1435
1420
|
{
|
|
1436
1421
|
method: "PATCH",
|
|
1437
1422
|
body: params
|
|
@@ -1440,62 +1425,49 @@ var MemoryThread = class extends BaseResource {
|
|
|
1440
1425
|
}
|
|
1441
1426
|
/**
|
|
1442
1427
|
* Deletes the memory thread
|
|
1443
|
-
* @param
|
|
1428
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1444
1429
|
* @returns Promise containing deletion result
|
|
1445
1430
|
*/
|
|
1446
|
-
delete(
|
|
1431
|
+
delete(requestContext) {
|
|
1447
1432
|
return this.request(
|
|
1448
|
-
`/api/memory/threads/${this.threadId}?agentId=${this.agentId}${
|
|
1433
|
+
`/api/memory/threads/${this.threadId}?agentId=${this.agentId}${requestContextQueryString(requestContext, "&")}`,
|
|
1449
1434
|
{
|
|
1450
1435
|
method: "DELETE"
|
|
1451
1436
|
}
|
|
1452
1437
|
);
|
|
1453
1438
|
}
|
|
1454
1439
|
/**
|
|
1455
|
-
* Retrieves messages associated with the thread
|
|
1456
|
-
* @param params -
|
|
1457
|
-
* @returns Promise containing thread messages and UI messages
|
|
1458
|
-
*/
|
|
1459
|
-
getMessages(params) {
|
|
1460
|
-
const query = new URLSearchParams({
|
|
1461
|
-
agentId: this.agentId,
|
|
1462
|
-
...params?.limit ? { limit: params.limit.toString() } : {}
|
|
1463
|
-
});
|
|
1464
|
-
return this.request(
|
|
1465
|
-
`/api/memory/threads/${this.threadId}/messages?${query.toString()}${runtimeContextQueryString(params?.runtimeContext, "&")}`
|
|
1466
|
-
);
|
|
1467
|
-
}
|
|
1468
|
-
/**
|
|
1469
|
-
* Retrieves paginated messages associated with the thread with advanced filtering and selection options
|
|
1470
|
-
* @param params - Pagination parameters including selectBy criteria, page, perPage, date ranges, message inclusion options, and runtime context
|
|
1440
|
+
* Retrieves paginated messages associated with the thread with filtering and ordering options
|
|
1441
|
+
* @param params - Pagination parameters including page, perPage, orderBy, filter, include options, and request context
|
|
1471
1442
|
* @returns Promise containing paginated thread messages with pagination metadata (total, page, perPage, hasMore)
|
|
1472
1443
|
*/
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
)
|
|
1444
|
+
listMessages(params = {}) {
|
|
1445
|
+
const { page, perPage, orderBy, filter, include, resourceId, requestContext } = params;
|
|
1446
|
+
const queryParams = {};
|
|
1447
|
+
if (resourceId) queryParams.resourceId = resourceId;
|
|
1448
|
+
if (page !== void 0) queryParams.page = String(page);
|
|
1449
|
+
if (perPage !== void 0) queryParams.perPage = String(perPage);
|
|
1450
|
+
if (orderBy) queryParams.orderBy = JSON.stringify(orderBy);
|
|
1451
|
+
if (filter) queryParams.filter = JSON.stringify(filter);
|
|
1452
|
+
if (include) queryParams.include = JSON.stringify(include);
|
|
1453
|
+
const query = new URLSearchParams(queryParams);
|
|
1454
|
+
const queryString = query.toString();
|
|
1455
|
+
const url = `/api/memory/threads/${this.threadId}/messages${queryString ? `?${queryString}` : ""}${requestContextQueryString(requestContext, queryString ? "&" : "?")}`;
|
|
1456
|
+
return this.request(url);
|
|
1485
1457
|
}
|
|
1486
1458
|
/**
|
|
1487
1459
|
* Deletes one or more messages from the thread
|
|
1488
1460
|
* @param messageIds - Can be a single message ID (string), array of message IDs,
|
|
1489
1461
|
* message object with id property, or array of message objects
|
|
1490
|
-
* @param
|
|
1462
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1491
1463
|
* @returns Promise containing deletion result
|
|
1492
1464
|
*/
|
|
1493
|
-
deleteMessages(messageIds,
|
|
1465
|
+
deleteMessages(messageIds, requestContext) {
|
|
1494
1466
|
const query = new URLSearchParams({
|
|
1495
1467
|
agentId: this.agentId
|
|
1496
1468
|
});
|
|
1497
1469
|
return this.request(
|
|
1498
|
-
`/api/memory/messages/delete?${query.toString()}${
|
|
1470
|
+
`/api/memory/messages/delete?${query.toString()}${requestContextQueryString(requestContext, "&")}`,
|
|
1499
1471
|
{
|
|
1500
1472
|
method: "POST",
|
|
1501
1473
|
body: { messageIds }
|
|
@@ -1513,12 +1485,12 @@ var Vector = class extends BaseResource {
|
|
|
1513
1485
|
/**
|
|
1514
1486
|
* Retrieves details about a specific vector index
|
|
1515
1487
|
* @param indexName - Name of the index to get details for
|
|
1516
|
-
* @param
|
|
1488
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1517
1489
|
* @returns Promise containing vector index details
|
|
1518
1490
|
*/
|
|
1519
|
-
details(indexName,
|
|
1491
|
+
details(indexName, requestContext) {
|
|
1520
1492
|
return this.request(
|
|
1521
|
-
`/api/vector/${this.vectorName}/indexes/${indexName}${
|
|
1493
|
+
`/api/vector/${this.vectorName}/indexes/${indexName}${requestContextQueryString(requestContext)}`
|
|
1522
1494
|
);
|
|
1523
1495
|
}
|
|
1524
1496
|
/**
|
|
@@ -1533,11 +1505,11 @@ var Vector = class extends BaseResource {
|
|
|
1533
1505
|
}
|
|
1534
1506
|
/**
|
|
1535
1507
|
* Retrieves a list of all available indexes
|
|
1536
|
-
* @param
|
|
1508
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1537
1509
|
* @returns Promise containing array of index names
|
|
1538
1510
|
*/
|
|
1539
|
-
getIndexes(
|
|
1540
|
-
return this.request(`/api/vector/${this.vectorName}/indexes${
|
|
1511
|
+
getIndexes(requestContext) {
|
|
1512
|
+
return this.request(`/api/vector/${this.vectorName}/indexes${requestContextQueryString(requestContext)}`);
|
|
1541
1513
|
}
|
|
1542
1514
|
/**
|
|
1543
1515
|
* Creates a new vector index
|
|
@@ -1582,11 +1554,11 @@ var Tool = class extends BaseResource {
|
|
|
1582
1554
|
}
|
|
1583
1555
|
/**
|
|
1584
1556
|
* Retrieves details about the tool
|
|
1585
|
-
* @param
|
|
1557
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1586
1558
|
* @returns Promise containing tool details including description and schemas
|
|
1587
1559
|
*/
|
|
1588
|
-
details(
|
|
1589
|
-
return this.request(`/api/tools/${this.toolId}${
|
|
1560
|
+
details(requestContext) {
|
|
1561
|
+
return this.request(`/api/tools/${this.toolId}${requestContextQueryString(requestContext)}`);
|
|
1590
1562
|
}
|
|
1591
1563
|
/**
|
|
1592
1564
|
* Executes the tool with the provided parameters
|
|
@@ -1600,7 +1572,7 @@ var Tool = class extends BaseResource {
|
|
|
1600
1572
|
}
|
|
1601
1573
|
const body = {
|
|
1602
1574
|
data: params.data,
|
|
1603
|
-
|
|
1575
|
+
requestContext: parseClientRequestContext(params.requestContext)
|
|
1604
1576
|
};
|
|
1605
1577
|
return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
|
|
1606
1578
|
method: "POST",
|
|
@@ -1616,67 +1588,22 @@ var Workflow = class extends BaseResource {
|
|
|
1616
1588
|
super(options);
|
|
1617
1589
|
this.workflowId = workflowId;
|
|
1618
1590
|
}
|
|
1619
|
-
/**
|
|
1620
|
-
* Creates an async generator that processes a readable stream and yields workflow records
|
|
1621
|
-
* separated by the Record Separator character (\x1E)
|
|
1622
|
-
*
|
|
1623
|
-
* @param stream - The readable stream to process
|
|
1624
|
-
* @returns An async generator that yields parsed records
|
|
1625
|
-
*/
|
|
1626
|
-
async *streamProcessor(stream) {
|
|
1627
|
-
const reader = stream.getReader();
|
|
1628
|
-
let doneReading = false;
|
|
1629
|
-
let buffer = "";
|
|
1630
|
-
try {
|
|
1631
|
-
while (!doneReading) {
|
|
1632
|
-
const { done, value } = await reader.read();
|
|
1633
|
-
doneReading = done;
|
|
1634
|
-
if (done && !value) continue;
|
|
1635
|
-
try {
|
|
1636
|
-
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
1637
|
-
const chunks = (buffer + decoded).split(RECORD_SEPARATOR);
|
|
1638
|
-
buffer = chunks.pop() || "";
|
|
1639
|
-
for (const chunk of chunks) {
|
|
1640
|
-
if (chunk) {
|
|
1641
|
-
if (typeof chunk === "string") {
|
|
1642
|
-
try {
|
|
1643
|
-
const parsedChunk = JSON.parse(chunk);
|
|
1644
|
-
yield parsedChunk;
|
|
1645
|
-
} catch {
|
|
1646
|
-
}
|
|
1647
|
-
}
|
|
1648
|
-
}
|
|
1649
|
-
}
|
|
1650
|
-
} catch {
|
|
1651
|
-
}
|
|
1652
|
-
}
|
|
1653
|
-
if (buffer) {
|
|
1654
|
-
try {
|
|
1655
|
-
yield JSON.parse(buffer);
|
|
1656
|
-
} catch {
|
|
1657
|
-
}
|
|
1658
|
-
}
|
|
1659
|
-
} finally {
|
|
1660
|
-
reader.cancel().catch(() => {
|
|
1661
|
-
});
|
|
1662
|
-
}
|
|
1663
|
-
}
|
|
1664
1591
|
/**
|
|
1665
1592
|
* Retrieves details about the workflow
|
|
1666
|
-
* @param
|
|
1593
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1667
1594
|
* @returns Promise containing workflow details including steps and graphs
|
|
1668
1595
|
*/
|
|
1669
|
-
details(
|
|
1670
|
-
return this.request(`/api/workflows/${this.workflowId}${
|
|
1596
|
+
details(requestContext) {
|
|
1597
|
+
return this.request(`/api/workflows/${this.workflowId}${requestContextQueryString(requestContext)}`);
|
|
1671
1598
|
}
|
|
1672
1599
|
/**
|
|
1673
1600
|
* Retrieves all runs for a workflow
|
|
1674
1601
|
* @param params - Parameters for filtering runs
|
|
1675
|
-
* @param
|
|
1602
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1676
1603
|
* @returns Promise containing workflow runs array
|
|
1677
1604
|
*/
|
|
1678
|
-
runs(params,
|
|
1679
|
-
const
|
|
1605
|
+
runs(params, requestContext) {
|
|
1606
|
+
const requestContextParam = base64RequestContext(parseClientRequestContext(requestContext));
|
|
1680
1607
|
const searchParams = new URLSearchParams();
|
|
1681
1608
|
if (params?.fromDate) {
|
|
1682
1609
|
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
@@ -1684,17 +1611,21 @@ var Workflow = class extends BaseResource {
|
|
|
1684
1611
|
if (params?.toDate) {
|
|
1685
1612
|
searchParams.set("toDate", params.toDate.toISOString());
|
|
1686
1613
|
}
|
|
1687
|
-
if (params?.
|
|
1688
|
-
|
|
1614
|
+
if (params?.perPage !== null && params?.perPage !== void 0) {
|
|
1615
|
+
if (params.perPage === false) {
|
|
1616
|
+
searchParams.set("perPage", "false");
|
|
1617
|
+
} else if (typeof params.perPage === "number" && params.perPage > 0 && Number.isInteger(params.perPage)) {
|
|
1618
|
+
searchParams.set("perPage", String(params.perPage));
|
|
1619
|
+
}
|
|
1689
1620
|
}
|
|
1690
|
-
if (params?.
|
|
1691
|
-
searchParams.set("
|
|
1621
|
+
if (params?.page !== null && params?.page !== void 0 && !isNaN(Number(params?.page))) {
|
|
1622
|
+
searchParams.set("page", String(params.page));
|
|
1692
1623
|
}
|
|
1693
1624
|
if (params?.resourceId) {
|
|
1694
1625
|
searchParams.set("resourceId", params.resourceId);
|
|
1695
1626
|
}
|
|
1696
|
-
if (
|
|
1697
|
-
searchParams.set("
|
|
1627
|
+
if (requestContextParam) {
|
|
1628
|
+
searchParams.set("requestContext", requestContextParam);
|
|
1698
1629
|
}
|
|
1699
1630
|
if (searchParams.size) {
|
|
1700
1631
|
return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
|
|
@@ -1705,21 +1636,21 @@ var Workflow = class extends BaseResource {
|
|
|
1705
1636
|
/**
|
|
1706
1637
|
* Retrieves a specific workflow run by its ID
|
|
1707
1638
|
* @param runId - The ID of the workflow run to retrieve
|
|
1708
|
-
* @param
|
|
1639
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1709
1640
|
* @returns Promise containing the workflow run details
|
|
1710
1641
|
*/
|
|
1711
|
-
runById(runId,
|
|
1712
|
-
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}${
|
|
1642
|
+
runById(runId, requestContext) {
|
|
1643
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}${requestContextQueryString(requestContext)}`);
|
|
1713
1644
|
}
|
|
1714
1645
|
/**
|
|
1715
1646
|
* Retrieves the execution result for a specific workflow run by its ID
|
|
1716
1647
|
* @param runId - The ID of the workflow run to retrieve the execution result for
|
|
1717
|
-
* @param
|
|
1648
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1718
1649
|
* @returns Promise containing the workflow run execution result
|
|
1719
1650
|
*/
|
|
1720
|
-
runExecutionResult(runId,
|
|
1651
|
+
runExecutionResult(runId, requestContext) {
|
|
1721
1652
|
return this.request(
|
|
1722
|
-
`/api/workflows/${this.workflowId}/runs/${runId}/execution-result${
|
|
1653
|
+
`/api/workflows/${this.workflowId}/runs/${runId}/execution-result${requestContextQueryString(requestContext)}`
|
|
1723
1654
|
);
|
|
1724
1655
|
}
|
|
1725
1656
|
/**
|
|
@@ -1732,32 +1663,12 @@ var Workflow = class extends BaseResource {
|
|
|
1732
1663
|
method: "POST"
|
|
1733
1664
|
});
|
|
1734
1665
|
}
|
|
1735
|
-
/**
|
|
1736
|
-
* Sends an event to a specific workflow run by its ID
|
|
1737
|
-
* @param params - Object containing the runId, event and data
|
|
1738
|
-
* @returns Promise containing a success message
|
|
1739
|
-
*/
|
|
1740
|
-
sendRunEvent(params) {
|
|
1741
|
-
return this.request(`/api/workflows/${this.workflowId}/runs/${params.runId}/send-event`, {
|
|
1742
|
-
method: "POST",
|
|
1743
|
-
body: { event: params.event, data: params.data }
|
|
1744
|
-
});
|
|
1745
|
-
}
|
|
1746
|
-
/**
|
|
1747
|
-
* @deprecated Use createRunAsync() instead.
|
|
1748
|
-
* @throws {Error} Always throws an error directing users to use createRunAsync()
|
|
1749
|
-
*/
|
|
1750
|
-
async createRun(_params) {
|
|
1751
|
-
throw new Error(
|
|
1752
|
-
"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."
|
|
1753
|
-
);
|
|
1754
|
-
}
|
|
1755
1666
|
/**
|
|
1756
1667
|
* Creates a new workflow run
|
|
1757
1668
|
* @param params - Optional object containing the optional runId
|
|
1758
1669
|
* @returns Promise containing the runId of the created run with methods to control execution
|
|
1759
1670
|
*/
|
|
1760
|
-
async
|
|
1671
|
+
async createRun(params) {
|
|
1761
1672
|
const searchParams = new URLSearchParams();
|
|
1762
1673
|
if (!!params?.runId) {
|
|
1763
1674
|
searchParams.set("runId", params.runId);
|
|
@@ -1775,7 +1686,7 @@ var Workflow = class extends BaseResource {
|
|
|
1775
1686
|
return this.start({
|
|
1776
1687
|
runId,
|
|
1777
1688
|
inputData: p.inputData,
|
|
1778
|
-
|
|
1689
|
+
requestContext: p.requestContext,
|
|
1779
1690
|
tracingOptions: p.tracingOptions
|
|
1780
1691
|
});
|
|
1781
1692
|
},
|
|
@@ -1783,22 +1694,19 @@ var Workflow = class extends BaseResource {
|
|
|
1783
1694
|
return this.startAsync({
|
|
1784
1695
|
runId,
|
|
1785
1696
|
inputData: p.inputData,
|
|
1786
|
-
|
|
1697
|
+
requestContext: p.requestContext,
|
|
1787
1698
|
tracingOptions: p.tracingOptions
|
|
1788
1699
|
});
|
|
1789
1700
|
},
|
|
1790
|
-
watch: async (onRecord) => {
|
|
1791
|
-
return this.watch({ runId }, onRecord);
|
|
1792
|
-
},
|
|
1793
1701
|
stream: async (p) => {
|
|
1794
|
-
return this.stream({ runId, inputData: p.inputData,
|
|
1702
|
+
return this.stream({ runId, inputData: p.inputData, requestContext: p.requestContext });
|
|
1795
1703
|
},
|
|
1796
1704
|
resume: async (p) => {
|
|
1797
1705
|
return this.resume({
|
|
1798
1706
|
runId,
|
|
1799
1707
|
step: p.step,
|
|
1800
1708
|
resumeData: p.resumeData,
|
|
1801
|
-
|
|
1709
|
+
requestContext: p.requestContext,
|
|
1802
1710
|
tracingOptions: p.tracingOptions
|
|
1803
1711
|
});
|
|
1804
1712
|
},
|
|
@@ -1807,7 +1715,7 @@ var Workflow = class extends BaseResource {
|
|
|
1807
1715
|
runId,
|
|
1808
1716
|
step: p.step,
|
|
1809
1717
|
resumeData: p.resumeData,
|
|
1810
|
-
|
|
1718
|
+
requestContext: p.requestContext,
|
|
1811
1719
|
tracingOptions: p.tracingOptions
|
|
1812
1720
|
});
|
|
1813
1721
|
},
|
|
@@ -1816,26 +1724,26 @@ var Workflow = class extends BaseResource {
|
|
|
1816
1724
|
runId,
|
|
1817
1725
|
step: p.step,
|
|
1818
1726
|
resumeData: p.resumeData,
|
|
1819
|
-
|
|
1727
|
+
requestContext: p.requestContext
|
|
1820
1728
|
});
|
|
1821
1729
|
}
|
|
1822
1730
|
};
|
|
1823
1731
|
}
|
|
1824
1732
|
/**
|
|
1825
1733
|
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
1826
|
-
* @param params - Object containing the runId, inputData and
|
|
1734
|
+
* @param params - Object containing the runId, inputData and requestContext
|
|
1827
1735
|
* @returns Promise containing success message
|
|
1828
1736
|
*/
|
|
1829
1737
|
start(params) {
|
|
1830
|
-
const
|
|
1738
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
1831
1739
|
return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
|
|
1832
1740
|
method: "POST",
|
|
1833
|
-
body: { inputData: params?.inputData,
|
|
1741
|
+
body: { inputData: params?.inputData, requestContext, tracingOptions: params.tracingOptions }
|
|
1834
1742
|
});
|
|
1835
1743
|
}
|
|
1836
1744
|
/**
|
|
1837
1745
|
* Resumes a suspended workflow step synchronously without waiting for the workflow to complete
|
|
1838
|
-
* @param params - Object containing the runId, step, resumeData and
|
|
1746
|
+
* @param params - Object containing the runId, step, resumeData and requestContext
|
|
1839
1747
|
* @returns Promise containing success message
|
|
1840
1748
|
*/
|
|
1841
1749
|
resume({
|
|
@@ -1845,20 +1753,20 @@ var Workflow = class extends BaseResource {
|
|
|
1845
1753
|
tracingOptions,
|
|
1846
1754
|
...rest
|
|
1847
1755
|
}) {
|
|
1848
|
-
const
|
|
1756
|
+
const requestContext = parseClientRequestContext(rest.requestContext);
|
|
1849
1757
|
return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
|
|
1850
1758
|
method: "POST",
|
|
1851
1759
|
body: {
|
|
1852
1760
|
step,
|
|
1853
1761
|
resumeData,
|
|
1854
|
-
|
|
1762
|
+
requestContext,
|
|
1855
1763
|
tracingOptions
|
|
1856
1764
|
}
|
|
1857
1765
|
});
|
|
1858
1766
|
}
|
|
1859
1767
|
/**
|
|
1860
1768
|
* Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
|
|
1861
|
-
* @param params - Object containing the optional runId, inputData and
|
|
1769
|
+
* @param params - Object containing the optional runId, inputData and requestContext
|
|
1862
1770
|
* @returns Promise containing the workflow execution results
|
|
1863
1771
|
*/
|
|
1864
1772
|
startAsync(params) {
|
|
@@ -1866,15 +1774,15 @@ var Workflow = class extends BaseResource {
|
|
|
1866
1774
|
if (!!params?.runId) {
|
|
1867
1775
|
searchParams.set("runId", params.runId);
|
|
1868
1776
|
}
|
|
1869
|
-
const
|
|
1777
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
1870
1778
|
return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
1871
1779
|
method: "POST",
|
|
1872
|
-
body: { inputData: params.inputData,
|
|
1780
|
+
body: { inputData: params.inputData, requestContext, tracingOptions: params.tracingOptions }
|
|
1873
1781
|
});
|
|
1874
1782
|
}
|
|
1875
1783
|
/**
|
|
1876
1784
|
* Starts a workflow run and returns a stream
|
|
1877
|
-
* @param params - Object containing the optional runId, inputData and
|
|
1785
|
+
* @param params - Object containing the optional runId, inputData and requestContext
|
|
1878
1786
|
* @returns Promise containing the workflow execution results
|
|
1879
1787
|
*/
|
|
1880
1788
|
async stream(params) {
|
|
@@ -1882,12 +1790,12 @@ var Workflow = class extends BaseResource {
|
|
|
1882
1790
|
if (!!params?.runId) {
|
|
1883
1791
|
searchParams.set("runId", params.runId);
|
|
1884
1792
|
}
|
|
1885
|
-
const
|
|
1793
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
1886
1794
|
const response = await this.request(
|
|
1887
1795
|
`/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
|
|
1888
1796
|
{
|
|
1889
1797
|
method: "POST",
|
|
1890
|
-
body: { inputData: params.inputData,
|
|
1798
|
+
body: { inputData: params.inputData, requestContext, tracingOptions: params.tracingOptions },
|
|
1891
1799
|
stream: true
|
|
1892
1800
|
}
|
|
1893
1801
|
);
|
|
@@ -1972,7 +1880,7 @@ var Workflow = class extends BaseResource {
|
|
|
1972
1880
|
}
|
|
1973
1881
|
/**
|
|
1974
1882
|
* Starts a workflow run and returns a stream
|
|
1975
|
-
* @param params - Object containing the optional runId, inputData and
|
|
1883
|
+
* @param params - Object containing the optional runId, inputData and requestContext
|
|
1976
1884
|
* @returns Promise containing the workflow execution results
|
|
1977
1885
|
*/
|
|
1978
1886
|
async streamVNext(params) {
|
|
@@ -1980,14 +1888,14 @@ var Workflow = class extends BaseResource {
|
|
|
1980
1888
|
if (!!params?.runId) {
|
|
1981
1889
|
searchParams.set("runId", params.runId);
|
|
1982
1890
|
}
|
|
1983
|
-
const
|
|
1891
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
1984
1892
|
const response = await this.request(
|
|
1985
1893
|
`/api/workflows/${this.workflowId}/streamVNext?${searchParams.toString()}`,
|
|
1986
1894
|
{
|
|
1987
1895
|
method: "POST",
|
|
1988
1896
|
body: {
|
|
1989
1897
|
inputData: params.inputData,
|
|
1990
|
-
|
|
1898
|
+
requestContext,
|
|
1991
1899
|
closeOnSuspend: params.closeOnSuspend,
|
|
1992
1900
|
tracingOptions: params.tracingOptions
|
|
1993
1901
|
},
|
|
@@ -2075,30 +1983,30 @@ var Workflow = class extends BaseResource {
|
|
|
2075
1983
|
}
|
|
2076
1984
|
/**
|
|
2077
1985
|
* Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
2078
|
-
* @param params - Object containing the runId, step, resumeData and
|
|
1986
|
+
* @param params - Object containing the runId, step, resumeData and requestContext
|
|
2079
1987
|
* @returns Promise containing the workflow resume results
|
|
2080
1988
|
*/
|
|
2081
1989
|
resumeAsync(params) {
|
|
2082
|
-
const
|
|
1990
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2083
1991
|
return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
2084
1992
|
method: "POST",
|
|
2085
1993
|
body: {
|
|
2086
1994
|
step: params.step,
|
|
2087
1995
|
resumeData: params.resumeData,
|
|
2088
|
-
|
|
1996
|
+
requestContext,
|
|
2089
1997
|
tracingOptions: params.tracingOptions
|
|
2090
1998
|
}
|
|
2091
1999
|
});
|
|
2092
2000
|
}
|
|
2093
2001
|
/**
|
|
2094
2002
|
* Resumes a suspended workflow step that uses streamVNext asynchronously and returns a promise that resolves when the workflow is complete
|
|
2095
|
-
* @param params - Object containing the runId, step, resumeData and
|
|
2003
|
+
* @param params - Object containing the runId, step, resumeData and requestContext
|
|
2096
2004
|
* @returns Promise containing the workflow resume results
|
|
2097
2005
|
*/
|
|
2098
2006
|
async resumeStreamVNext(params) {
|
|
2099
2007
|
const searchParams = new URLSearchParams();
|
|
2100
2008
|
searchParams.set("runId", params.runId);
|
|
2101
|
-
const
|
|
2009
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2102
2010
|
const response = await this.request(
|
|
2103
2011
|
`/api/workflows/${this.workflowId}/resume-stream?${searchParams.toString()}`,
|
|
2104
2012
|
{
|
|
@@ -2106,7 +2014,7 @@ var Workflow = class extends BaseResource {
|
|
|
2106
2014
|
body: {
|
|
2107
2015
|
step: params.step,
|
|
2108
2016
|
resumeData: params.resumeData,
|
|
2109
|
-
|
|
2017
|
+
requestContext,
|
|
2110
2018
|
tracingOptions: params.tracingOptions
|
|
2111
2019
|
},
|
|
2112
2020
|
stream: true
|
|
@@ -2144,29 +2052,6 @@ var Workflow = class extends BaseResource {
|
|
|
2144
2052
|
});
|
|
2145
2053
|
return response.body.pipeThrough(transformStream);
|
|
2146
2054
|
}
|
|
2147
|
-
/**
|
|
2148
|
-
* Watches workflow transitions in real-time
|
|
2149
|
-
* @param runId - Optional run ID to filter the watch stream
|
|
2150
|
-
* @returns AsyncGenerator that yields parsed records from the workflow watch stream
|
|
2151
|
-
*/
|
|
2152
|
-
async watch({ runId }, onRecord) {
|
|
2153
|
-
const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
|
|
2154
|
-
stream: true
|
|
2155
|
-
});
|
|
2156
|
-
if (!response.ok) {
|
|
2157
|
-
throw new Error(`Failed to watch workflow: ${response.statusText}`);
|
|
2158
|
-
}
|
|
2159
|
-
if (!response.body) {
|
|
2160
|
-
throw new Error("Response body is null");
|
|
2161
|
-
}
|
|
2162
|
-
for await (const record of this.streamProcessor(response.body)) {
|
|
2163
|
-
if (typeof record === "string") {
|
|
2164
|
-
onRecord(JSON.parse(record));
|
|
2165
|
-
} else {
|
|
2166
|
-
onRecord(record);
|
|
2167
|
-
}
|
|
2168
|
-
}
|
|
2169
|
-
}
|
|
2170
2055
|
/**
|
|
2171
2056
|
* Creates a new ReadableStream from an iterable or async iterable of objects,
|
|
2172
2057
|
* serializing each as JSON and separating them with the record separator (\x1E).
|
|
@@ -2278,22 +2163,22 @@ var MCPTool = class extends BaseResource {
|
|
|
2278
2163
|
}
|
|
2279
2164
|
/**
|
|
2280
2165
|
* Retrieves details about this specific tool from the MCP server.
|
|
2281
|
-
* @param
|
|
2166
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
2282
2167
|
* @returns Promise containing the tool's information (name, description, schema).
|
|
2283
2168
|
*/
|
|
2284
|
-
details(
|
|
2285
|
-
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}${
|
|
2169
|
+
details(requestContext) {
|
|
2170
|
+
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}${requestContextQueryString(requestContext)}`);
|
|
2286
2171
|
}
|
|
2287
2172
|
/**
|
|
2288
2173
|
* Executes this specific tool on the MCP server.
|
|
2289
|
-
* @param params - Parameters for tool execution, including data/args and optional
|
|
2174
|
+
* @param params - Parameters for tool execution, including data/args and optional requestContext.
|
|
2290
2175
|
* @returns Promise containing the result of the tool execution.
|
|
2291
2176
|
*/
|
|
2292
2177
|
execute(params) {
|
|
2293
2178
|
const body = {};
|
|
2294
2179
|
if (params.data !== void 0) body.data = params.data;
|
|
2295
|
-
if (params.
|
|
2296
|
-
body.
|
|
2180
|
+
if (params.requestContext !== void 0) {
|
|
2181
|
+
body.requestContext = params.requestContext;
|
|
2297
2182
|
}
|
|
2298
2183
|
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}/execute`, {
|
|
2299
2184
|
method: "POST",
|
|
@@ -2339,19 +2224,39 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2339
2224
|
}
|
|
2340
2225
|
}
|
|
2341
2226
|
/**
|
|
2342
|
-
*
|
|
2343
|
-
* @throws {Error} Always throws an error directing users to use createRunAsync()
|
|
2227
|
+
* Creates a transform stream that parses binary chunks into JSON records.
|
|
2344
2228
|
*/
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2229
|
+
createRecordParserTransform() {
|
|
2230
|
+
let failedChunk = void 0;
|
|
2231
|
+
return new TransformStream({
|
|
2232
|
+
start() {
|
|
2233
|
+
},
|
|
2234
|
+
async transform(chunk, controller) {
|
|
2235
|
+
try {
|
|
2236
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
2237
|
+
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
2238
|
+
for (const chunk2 of chunks) {
|
|
2239
|
+
if (chunk2) {
|
|
2240
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
2241
|
+
try {
|
|
2242
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
2243
|
+
controller.enqueue(parsedChunk);
|
|
2244
|
+
failedChunk = void 0;
|
|
2245
|
+
} catch {
|
|
2246
|
+
failedChunk = newChunk;
|
|
2247
|
+
}
|
|
2248
|
+
}
|
|
2249
|
+
}
|
|
2250
|
+
} catch {
|
|
2251
|
+
}
|
|
2252
|
+
}
|
|
2253
|
+
});
|
|
2349
2254
|
}
|
|
2350
2255
|
/**
|
|
2351
2256
|
* Creates a new agent builder action run and returns the runId.
|
|
2352
2257
|
* This calls `/api/agent-builder/:actionId/create-run`.
|
|
2353
2258
|
*/
|
|
2354
|
-
async
|
|
2259
|
+
async createRun(params) {
|
|
2355
2260
|
const searchParams = new URLSearchParams();
|
|
2356
2261
|
if (!!params?.runId) {
|
|
2357
2262
|
searchParams.set("runId", params.runId);
|
|
@@ -2370,12 +2275,12 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2370
2275
|
if (runId) {
|
|
2371
2276
|
searchParams.set("runId", runId);
|
|
2372
2277
|
}
|
|
2373
|
-
const
|
|
2374
|
-
const {
|
|
2278
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2279
|
+
const { requestContext: _, ...actionParams } = params;
|
|
2375
2280
|
const url = `/api/agent-builder/${this.actionId}/start-async${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
|
|
2376
2281
|
const result = await this.request(url, {
|
|
2377
2282
|
method: "POST",
|
|
2378
|
-
body: { ...actionParams,
|
|
2283
|
+
body: { ...actionParams, requestContext }
|
|
2379
2284
|
});
|
|
2380
2285
|
return this.transformWorkflowResult(result);
|
|
2381
2286
|
}
|
|
@@ -2386,12 +2291,12 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2386
2291
|
async startActionRun(params, runId) {
|
|
2387
2292
|
const searchParams = new URLSearchParams();
|
|
2388
2293
|
searchParams.set("runId", runId);
|
|
2389
|
-
const
|
|
2390
|
-
const {
|
|
2294
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2295
|
+
const { requestContext: _, ...actionParams } = params;
|
|
2391
2296
|
const url = `/api/agent-builder/${this.actionId}/start?${searchParams.toString()}`;
|
|
2392
2297
|
return this.request(url, {
|
|
2393
2298
|
method: "POST",
|
|
2394
|
-
body: { ...actionParams,
|
|
2299
|
+
body: { ...actionParams, requestContext }
|
|
2395
2300
|
});
|
|
2396
2301
|
}
|
|
2397
2302
|
/**
|
|
@@ -2401,12 +2306,12 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2401
2306
|
async resume(params, runId) {
|
|
2402
2307
|
const searchParams = new URLSearchParams();
|
|
2403
2308
|
searchParams.set("runId", runId);
|
|
2404
|
-
const
|
|
2405
|
-
const {
|
|
2309
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2310
|
+
const { requestContext: _, ...resumeParams } = params;
|
|
2406
2311
|
const url = `/api/agent-builder/${this.actionId}/resume?${searchParams.toString()}`;
|
|
2407
2312
|
return this.request(url, {
|
|
2408
2313
|
method: "POST",
|
|
2409
|
-
body: { ...resumeParams,
|
|
2314
|
+
body: { ...resumeParams, requestContext }
|
|
2410
2315
|
});
|
|
2411
2316
|
}
|
|
2412
2317
|
/**
|
|
@@ -2416,12 +2321,12 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2416
2321
|
async resumeAsync(params, runId) {
|
|
2417
2322
|
const searchParams = new URLSearchParams();
|
|
2418
2323
|
searchParams.set("runId", runId);
|
|
2419
|
-
const
|
|
2420
|
-
const {
|
|
2324
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2325
|
+
const { requestContext: _, ...resumeParams } = params;
|
|
2421
2326
|
const url = `/api/agent-builder/${this.actionId}/resume-async?${searchParams.toString()}`;
|
|
2422
2327
|
const result = await this.request(url, {
|
|
2423
2328
|
method: "POST",
|
|
2424
|
-
body: { ...resumeParams,
|
|
2329
|
+
body: { ...resumeParams, requestContext }
|
|
2425
2330
|
});
|
|
2426
2331
|
return this.transformWorkflowResult(result);
|
|
2427
2332
|
}
|
|
@@ -2479,12 +2384,12 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2479
2384
|
if (runId) {
|
|
2480
2385
|
searchParams.set("runId", runId);
|
|
2481
2386
|
}
|
|
2482
|
-
const
|
|
2483
|
-
const {
|
|
2387
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2388
|
+
const { requestContext: _, ...actionParams } = params;
|
|
2484
2389
|
const url = `/api/agent-builder/${this.actionId}/stream${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
|
|
2485
2390
|
const response = await this.request(url, {
|
|
2486
2391
|
method: "POST",
|
|
2487
|
-
body: { ...actionParams,
|
|
2392
|
+
body: { ...actionParams, requestContext },
|
|
2488
2393
|
stream: true
|
|
2489
2394
|
});
|
|
2490
2395
|
if (!response.ok) {
|
|
@@ -2493,31 +2398,7 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2493
2398
|
if (!response.body) {
|
|
2494
2399
|
throw new Error("Response body is null");
|
|
2495
2400
|
}
|
|
2496
|
-
|
|
2497
|
-
const transformStream = new TransformStream({
|
|
2498
|
-
start() {
|
|
2499
|
-
},
|
|
2500
|
-
async transform(chunk, controller) {
|
|
2501
|
-
try {
|
|
2502
|
-
const decoded = new TextDecoder().decode(chunk);
|
|
2503
|
-
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
2504
|
-
for (const chunk2 of chunks) {
|
|
2505
|
-
if (chunk2) {
|
|
2506
|
-
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
2507
|
-
try {
|
|
2508
|
-
const parsedChunk = JSON.parse(newChunk);
|
|
2509
|
-
controller.enqueue(parsedChunk);
|
|
2510
|
-
failedChunk = void 0;
|
|
2511
|
-
} catch {
|
|
2512
|
-
failedChunk = newChunk;
|
|
2513
|
-
}
|
|
2514
|
-
}
|
|
2515
|
-
}
|
|
2516
|
-
} catch {
|
|
2517
|
-
}
|
|
2518
|
-
}
|
|
2519
|
-
});
|
|
2520
|
-
return response.body.pipeThrough(transformStream);
|
|
2401
|
+
return response.body.pipeThrough(this.createRecordParserTransform());
|
|
2521
2402
|
}
|
|
2522
2403
|
/**
|
|
2523
2404
|
* Streams agent builder action progress in real-time using VNext streaming.
|
|
@@ -2528,12 +2409,12 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2528
2409
|
if (runId) {
|
|
2529
2410
|
searchParams.set("runId", runId);
|
|
2530
2411
|
}
|
|
2531
|
-
const
|
|
2532
|
-
const {
|
|
2412
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2413
|
+
const { requestContext: _, ...actionParams } = params;
|
|
2533
2414
|
const url = `/api/agent-builder/${this.actionId}/streamVNext${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
|
|
2534
2415
|
const response = await this.request(url, {
|
|
2535
2416
|
method: "POST",
|
|
2536
|
-
body: { ...actionParams,
|
|
2417
|
+
body: { ...actionParams, requestContext },
|
|
2537
2418
|
stream: true
|
|
2538
2419
|
});
|
|
2539
2420
|
if (!response.ok) {
|
|
@@ -2542,57 +2423,94 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2542
2423
|
if (!response.body) {
|
|
2543
2424
|
throw new Error("Response body is null");
|
|
2544
2425
|
}
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
} catch {
|
|
2561
|
-
failedChunk = newChunk;
|
|
2562
|
-
}
|
|
2563
|
-
}
|
|
2564
|
-
}
|
|
2565
|
-
} catch {
|
|
2566
|
-
}
|
|
2567
|
-
}
|
|
2426
|
+
return response.body.pipeThrough(this.createRecordParserTransform());
|
|
2427
|
+
}
|
|
2428
|
+
/**
|
|
2429
|
+
* Observes an existing agent builder action run stream.
|
|
2430
|
+
* Replays cached execution from the beginning, then continues with live stream.
|
|
2431
|
+
* This is the recommended method for recovery after page refresh/hot reload.
|
|
2432
|
+
* This calls `/api/agent-builder/:actionId/observe` (which delegates to observeStreamVNext).
|
|
2433
|
+
*/
|
|
2434
|
+
async observeStream(params) {
|
|
2435
|
+
const searchParams = new URLSearchParams();
|
|
2436
|
+
searchParams.set("runId", params.runId);
|
|
2437
|
+
const url = `/api/agent-builder/${this.actionId}/observe?${searchParams.toString()}`;
|
|
2438
|
+
const response = await this.request(url, {
|
|
2439
|
+
method: "POST",
|
|
2440
|
+
stream: true
|
|
2568
2441
|
});
|
|
2569
|
-
|
|
2442
|
+
if (!response.ok) {
|
|
2443
|
+
throw new Error(`Failed to observe agent builder action stream: ${response.statusText}`);
|
|
2444
|
+
}
|
|
2445
|
+
if (!response.body) {
|
|
2446
|
+
throw new Error("Response body is null");
|
|
2447
|
+
}
|
|
2448
|
+
return response.body.pipeThrough(this.createRecordParserTransform());
|
|
2570
2449
|
}
|
|
2571
2450
|
/**
|
|
2572
|
-
*
|
|
2573
|
-
*
|
|
2574
|
-
*
|
|
2575
|
-
* This calls `/api/agent-builder/:actionId/watch`.
|
|
2451
|
+
* Observes an existing agent builder action run stream using VNext streaming API.
|
|
2452
|
+
* Replays cached execution from the beginning, then continues with live stream.
|
|
2453
|
+
* This calls `/api/agent-builder/:actionId/observe-streamVNext`.
|
|
2576
2454
|
*/
|
|
2577
|
-
async
|
|
2578
|
-
const
|
|
2455
|
+
async observeStreamVNext(params) {
|
|
2456
|
+
const searchParams = new URLSearchParams();
|
|
2457
|
+
searchParams.set("runId", params.runId);
|
|
2458
|
+
const url = `/api/agent-builder/${this.actionId}/observe-streamVNext?${searchParams.toString()}`;
|
|
2579
2459
|
const response = await this.request(url, {
|
|
2580
|
-
method: "
|
|
2460
|
+
method: "POST",
|
|
2581
2461
|
stream: true
|
|
2582
2462
|
});
|
|
2583
2463
|
if (!response.ok) {
|
|
2584
|
-
throw new Error(`Failed to
|
|
2464
|
+
throw new Error(`Failed to observe agent builder action stream VNext: ${response.statusText}`);
|
|
2585
2465
|
}
|
|
2586
2466
|
if (!response.body) {
|
|
2587
2467
|
throw new Error("Response body is null");
|
|
2588
2468
|
}
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2469
|
+
return response.body.pipeThrough(this.createRecordParserTransform());
|
|
2470
|
+
}
|
|
2471
|
+
/**
|
|
2472
|
+
* Observes an existing agent builder action run stream using legacy streaming API.
|
|
2473
|
+
* Replays cached execution from the beginning, then continues with live stream.
|
|
2474
|
+
* This calls `/api/agent-builder/:actionId/observe-stream-legacy`.
|
|
2475
|
+
*/
|
|
2476
|
+
async observeStreamLegacy(params) {
|
|
2477
|
+
const searchParams = new URLSearchParams();
|
|
2478
|
+
searchParams.set("runId", params.runId);
|
|
2479
|
+
const url = `/api/agent-builder/${this.actionId}/observe-stream-legacy?${searchParams.toString()}`;
|
|
2480
|
+
const response = await this.request(url, {
|
|
2481
|
+
method: "POST",
|
|
2482
|
+
stream: true
|
|
2483
|
+
});
|
|
2484
|
+
if (!response.ok) {
|
|
2485
|
+
throw new Error(`Failed to observe agent builder action stream legacy: ${response.statusText}`);
|
|
2595
2486
|
}
|
|
2487
|
+
if (!response.body) {
|
|
2488
|
+
throw new Error("Response body is null");
|
|
2489
|
+
}
|
|
2490
|
+
return response.body.pipeThrough(this.createRecordParserTransform());
|
|
2491
|
+
}
|
|
2492
|
+
/**
|
|
2493
|
+
* Resumes a suspended agent builder action and streams the results.
|
|
2494
|
+
* This calls `/api/agent-builder/:actionId/resume-stream`.
|
|
2495
|
+
*/
|
|
2496
|
+
async resumeStream(params) {
|
|
2497
|
+
const searchParams = new URLSearchParams();
|
|
2498
|
+
searchParams.set("runId", params.runId);
|
|
2499
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2500
|
+
const { runId: _, requestContext: __, ...resumeParams } = params;
|
|
2501
|
+
const url = `/api/agent-builder/${this.actionId}/resume-stream?${searchParams.toString()}`;
|
|
2502
|
+
const response = await this.request(url, {
|
|
2503
|
+
method: "POST",
|
|
2504
|
+
body: { ...resumeParams, requestContext },
|
|
2505
|
+
stream: true
|
|
2506
|
+
});
|
|
2507
|
+
if (!response.ok) {
|
|
2508
|
+
throw new Error(`Failed to resume agent builder action stream: ${response.statusText}`);
|
|
2509
|
+
}
|
|
2510
|
+
if (!response.body) {
|
|
2511
|
+
throw new Error("Response body is null");
|
|
2512
|
+
}
|
|
2513
|
+
return response.body.pipeThrough(this.createRecordParserTransform());
|
|
2596
2514
|
}
|
|
2597
2515
|
/**
|
|
2598
2516
|
* Gets a specific action run by its ID.
|
|
@@ -2624,11 +2542,11 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2624
2542
|
if (params?.toDate) {
|
|
2625
2543
|
searchParams.set("toDate", params.toDate.toISOString());
|
|
2626
2544
|
}
|
|
2627
|
-
if (params?.
|
|
2628
|
-
searchParams.set("
|
|
2545
|
+
if (params?.perPage !== void 0) {
|
|
2546
|
+
searchParams.set("perPage", String(params.perPage));
|
|
2629
2547
|
}
|
|
2630
|
-
if (params?.
|
|
2631
|
-
searchParams.set("
|
|
2548
|
+
if (params?.page !== void 0) {
|
|
2549
|
+
searchParams.set("page", String(params.page));
|
|
2632
2550
|
}
|
|
2633
2551
|
if (params?.resourceId) {
|
|
2634
2552
|
searchParams.set("resourceId", params.resourceId);
|
|
@@ -2658,17 +2576,6 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2658
2576
|
method: "POST"
|
|
2659
2577
|
});
|
|
2660
2578
|
}
|
|
2661
|
-
/**
|
|
2662
|
-
* Sends an event to an agent builder action run.
|
|
2663
|
-
* This calls `/api/agent-builder/:actionId/runs/:runId/send-event`.
|
|
2664
|
-
*/
|
|
2665
|
-
async sendRunEvent(params) {
|
|
2666
|
-
const url = `/api/agent-builder/${this.actionId}/runs/${params.runId}/send-event`;
|
|
2667
|
-
return this.request(url, {
|
|
2668
|
-
method: "POST",
|
|
2669
|
-
body: { event: params.event, data: params.data }
|
|
2670
|
-
});
|
|
2671
|
-
}
|
|
2672
2579
|
};
|
|
2673
2580
|
|
|
2674
2581
|
// src/resources/observability.ts
|
|
@@ -2677,15 +2584,15 @@ var Observability = class extends BaseResource {
|
|
|
2677
2584
|
super(options);
|
|
2678
2585
|
}
|
|
2679
2586
|
/**
|
|
2680
|
-
* Retrieves a specific
|
|
2587
|
+
* Retrieves a specific trace by ID
|
|
2681
2588
|
* @param traceId - ID of the trace to retrieve
|
|
2682
|
-
* @returns Promise containing the
|
|
2589
|
+
* @returns Promise containing the trace with all its spans
|
|
2683
2590
|
*/
|
|
2684
2591
|
getTrace(traceId) {
|
|
2685
2592
|
return this.request(`/api/observability/traces/${traceId}`);
|
|
2686
2593
|
}
|
|
2687
2594
|
/**
|
|
2688
|
-
* Retrieves paginated list of
|
|
2595
|
+
* Retrieves paginated list of traces with optional filtering
|
|
2689
2596
|
* @param params - Parameters for pagination and filtering
|
|
2690
2597
|
* @returns Promise containing paginated traces and pagination info
|
|
2691
2598
|
*/
|
|
@@ -2725,7 +2632,7 @@ var Observability = class extends BaseResource {
|
|
|
2725
2632
|
* @param params - Parameters containing trace ID, span ID, and pagination options
|
|
2726
2633
|
* @returns Promise containing scores and pagination info
|
|
2727
2634
|
*/
|
|
2728
|
-
|
|
2635
|
+
listScoresBySpan(params) {
|
|
2729
2636
|
const { traceId, spanId, page, perPage } = params;
|
|
2730
2637
|
const searchParams = new URLSearchParams();
|
|
2731
2638
|
if (page !== void 0) {
|
|
@@ -2747,69 +2654,6 @@ var Observability = class extends BaseResource {
|
|
|
2747
2654
|
}
|
|
2748
2655
|
};
|
|
2749
2656
|
|
|
2750
|
-
// src/resources/network-memory-thread.ts
|
|
2751
|
-
var NetworkMemoryThread = class extends BaseResource {
|
|
2752
|
-
constructor(options, threadId, networkId) {
|
|
2753
|
-
super(options);
|
|
2754
|
-
this.threadId = threadId;
|
|
2755
|
-
this.networkId = networkId;
|
|
2756
|
-
}
|
|
2757
|
-
/**
|
|
2758
|
-
* Retrieves the memory thread details
|
|
2759
|
-
* @returns Promise containing thread details including title and metadata
|
|
2760
|
-
*/
|
|
2761
|
-
get() {
|
|
2762
|
-
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`);
|
|
2763
|
-
}
|
|
2764
|
-
/**
|
|
2765
|
-
* Updates the memory thread properties
|
|
2766
|
-
* @param params - Update parameters including title and metadata
|
|
2767
|
-
* @returns Promise containing updated thread details
|
|
2768
|
-
*/
|
|
2769
|
-
update(params) {
|
|
2770
|
-
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
|
|
2771
|
-
method: "PATCH",
|
|
2772
|
-
body: params
|
|
2773
|
-
});
|
|
2774
|
-
}
|
|
2775
|
-
/**
|
|
2776
|
-
* Deletes the memory thread
|
|
2777
|
-
* @returns Promise containing deletion result
|
|
2778
|
-
*/
|
|
2779
|
-
delete() {
|
|
2780
|
-
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
|
|
2781
|
-
method: "DELETE"
|
|
2782
|
-
});
|
|
2783
|
-
}
|
|
2784
|
-
/**
|
|
2785
|
-
* Retrieves messages associated with the thread
|
|
2786
|
-
* @param params - Optional parameters including limit for number of messages to retrieve
|
|
2787
|
-
* @returns Promise containing thread messages and UI messages
|
|
2788
|
-
*/
|
|
2789
|
-
getMessages(params) {
|
|
2790
|
-
const query = new URLSearchParams({
|
|
2791
|
-
networkId: this.networkId,
|
|
2792
|
-
...params?.limit ? { limit: params.limit.toString() } : {}
|
|
2793
|
-
});
|
|
2794
|
-
return this.request(`/api/memory/network/threads/${this.threadId}/messages?${query.toString()}`);
|
|
2795
|
-
}
|
|
2796
|
-
/**
|
|
2797
|
-
* Deletes one or more messages from the thread
|
|
2798
|
-
* @param messageIds - Can be a single message ID (string), array of message IDs,
|
|
2799
|
-
* message object with id property, or array of message objects
|
|
2800
|
-
* @returns Promise containing deletion result
|
|
2801
|
-
*/
|
|
2802
|
-
deleteMessages(messageIds) {
|
|
2803
|
-
const query = new URLSearchParams({
|
|
2804
|
-
networkId: this.networkId
|
|
2805
|
-
});
|
|
2806
|
-
return this.request(`/api/memory/network/messages/delete?${query.toString()}`, {
|
|
2807
|
-
method: "POST",
|
|
2808
|
-
body: { messageIds }
|
|
2809
|
-
});
|
|
2810
|
-
}
|
|
2811
|
-
};
|
|
2812
|
-
|
|
2813
2657
|
// src/client.ts
|
|
2814
2658
|
var MastraClient = class extends BaseResource {
|
|
2815
2659
|
observability;
|
|
@@ -2819,18 +2663,21 @@ var MastraClient = class extends BaseResource {
|
|
|
2819
2663
|
}
|
|
2820
2664
|
/**
|
|
2821
2665
|
* Retrieves all available agents
|
|
2822
|
-
* @param
|
|
2666
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
2823
2667
|
* @returns Promise containing map of agent IDs to agent details
|
|
2824
2668
|
*/
|
|
2825
|
-
|
|
2826
|
-
const
|
|
2669
|
+
listAgents(requestContext) {
|
|
2670
|
+
const requestContextParam = base64RequestContext(parseClientRequestContext(requestContext));
|
|
2827
2671
|
const searchParams = new URLSearchParams();
|
|
2828
|
-
if (
|
|
2829
|
-
searchParams.set("
|
|
2672
|
+
if (requestContextParam) {
|
|
2673
|
+
searchParams.set("requestContext", requestContextParam);
|
|
2830
2674
|
}
|
|
2831
2675
|
const queryString = searchParams.toString();
|
|
2832
2676
|
return this.request(`/api/agents${queryString ? `?${queryString}` : ""}`);
|
|
2833
2677
|
}
|
|
2678
|
+
listAgentsModelProviders() {
|
|
2679
|
+
return this.request(`/api/agents/providers`);
|
|
2680
|
+
}
|
|
2834
2681
|
/**
|
|
2835
2682
|
* Gets an agent instance by ID
|
|
2836
2683
|
* @param agentId - ID of the agent to retrieve
|
|
@@ -2840,33 +2687,50 @@ var MastraClient = class extends BaseResource {
|
|
|
2840
2687
|
return new Agent(this.options, agentId);
|
|
2841
2688
|
}
|
|
2842
2689
|
/**
|
|
2843
|
-
*
|
|
2844
|
-
* @param params - Parameters containing
|
|
2845
|
-
* @returns Promise containing array of memory threads
|
|
2690
|
+
* Lists memory threads for a resource with pagination support
|
|
2691
|
+
* @param params - Parameters containing resource ID, pagination options, and optional request context
|
|
2692
|
+
* @returns Promise containing paginated array of memory threads with metadata
|
|
2846
2693
|
*/
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2694
|
+
async listMemoryThreads(params) {
|
|
2695
|
+
const queryParams = new URLSearchParams({
|
|
2696
|
+
resourceId: params.resourceId,
|
|
2697
|
+
resourceid: params.resourceId,
|
|
2698
|
+
agentId: params.agentId,
|
|
2699
|
+
...params.page !== void 0 && { page: params.page.toString() },
|
|
2700
|
+
...params.perPage !== void 0 && { perPage: params.perPage.toString() },
|
|
2701
|
+
...params.orderBy && { orderBy: params.orderBy },
|
|
2702
|
+
...params.sortDirection && { sortDirection: params.sortDirection }
|
|
2703
|
+
});
|
|
2704
|
+
const response = await this.request(
|
|
2705
|
+
`/api/memory/threads?${queryParams.toString()}${requestContextQueryString(params.requestContext, "&")}`
|
|
2850
2706
|
);
|
|
2707
|
+
const actualResponse = "threads" in response ? response : {
|
|
2708
|
+
threads: response,
|
|
2709
|
+
total: response.length,
|
|
2710
|
+
page: params.page ?? 0,
|
|
2711
|
+
perPage: params.perPage ?? 100,
|
|
2712
|
+
hasMore: false
|
|
2713
|
+
};
|
|
2714
|
+
return actualResponse;
|
|
2851
2715
|
}
|
|
2852
2716
|
/**
|
|
2853
2717
|
* Retrieves memory config for a resource
|
|
2854
|
-
* @param params - Parameters containing the resource ID and optional
|
|
2718
|
+
* @param params - Parameters containing the resource ID and optional request context
|
|
2855
2719
|
* @returns Promise containing memory configuration
|
|
2856
2720
|
*/
|
|
2857
2721
|
getMemoryConfig(params) {
|
|
2858
2722
|
return this.request(
|
|
2859
|
-
`/api/memory/config?agentId=${params.agentId}${
|
|
2723
|
+
`/api/memory/config?agentId=${params.agentId}${requestContextQueryString(params.requestContext, "&")}`
|
|
2860
2724
|
);
|
|
2861
2725
|
}
|
|
2862
2726
|
/**
|
|
2863
2727
|
* Creates a new memory thread
|
|
2864
|
-
* @param params - Parameters for creating the memory thread including optional
|
|
2728
|
+
* @param params - Parameters for creating the memory thread including optional request context
|
|
2865
2729
|
* @returns Promise containing the created memory thread
|
|
2866
2730
|
*/
|
|
2867
2731
|
createMemoryThread(params) {
|
|
2868
2732
|
return this.request(
|
|
2869
|
-
`/api/memory/threads?agentId=${params.agentId}${
|
|
2733
|
+
`/api/memory/threads?agentId=${params.agentId}${requestContextQueryString(params.requestContext, "&")}`,
|
|
2870
2734
|
{ method: "POST", body: params }
|
|
2871
2735
|
);
|
|
2872
2736
|
}
|
|
@@ -2875,35 +2739,38 @@ var MastraClient = class extends BaseResource {
|
|
|
2875
2739
|
* @param threadId - ID of the memory thread to retrieve
|
|
2876
2740
|
* @returns MemoryThread instance
|
|
2877
2741
|
*/
|
|
2878
|
-
getMemoryThread(threadId, agentId) {
|
|
2742
|
+
getMemoryThread({ threadId, agentId }) {
|
|
2879
2743
|
return new MemoryThread(this.options, threadId, agentId);
|
|
2880
2744
|
}
|
|
2881
|
-
|
|
2745
|
+
listThreadMessages(threadId, opts = {}) {
|
|
2746
|
+
if (!opts.agentId && !opts.networkId) {
|
|
2747
|
+
throw new Error("Either agentId or networkId must be provided");
|
|
2748
|
+
}
|
|
2882
2749
|
let url = "";
|
|
2883
2750
|
if (opts.agentId) {
|
|
2884
|
-
url = `/api/memory/threads/${threadId}/messages?agentId=${opts.agentId}${
|
|
2751
|
+
url = `/api/memory/threads/${threadId}/messages?agentId=${opts.agentId}${requestContextQueryString(opts.requestContext, "&")}`;
|
|
2885
2752
|
} else if (opts.networkId) {
|
|
2886
|
-
url = `/api/memory/network/threads/${threadId}/messages?networkId=${opts.networkId}${
|
|
2753
|
+
url = `/api/memory/network/threads/${threadId}/messages?networkId=${opts.networkId}${requestContextQueryString(opts.requestContext, "&")}`;
|
|
2887
2754
|
}
|
|
2888
2755
|
return this.request(url);
|
|
2889
2756
|
}
|
|
2890
2757
|
deleteThread(threadId, opts = {}) {
|
|
2891
2758
|
let url = "";
|
|
2892
2759
|
if (opts.agentId) {
|
|
2893
|
-
url = `/api/memory/threads/${threadId}?agentId=${opts.agentId}${
|
|
2760
|
+
url = `/api/memory/threads/${threadId}?agentId=${opts.agentId}${requestContextQueryString(opts.requestContext, "&")}`;
|
|
2894
2761
|
} else if (opts.networkId) {
|
|
2895
|
-
url = `/api/memory/network/threads/${threadId}?networkId=${opts.networkId}${
|
|
2762
|
+
url = `/api/memory/network/threads/${threadId}?networkId=${opts.networkId}${requestContextQueryString(opts.requestContext, "&")}`;
|
|
2896
2763
|
}
|
|
2897
2764
|
return this.request(url, { method: "DELETE" });
|
|
2898
2765
|
}
|
|
2899
2766
|
/**
|
|
2900
2767
|
* Saves messages to memory
|
|
2901
|
-
* @param params - Parameters containing messages to save and optional
|
|
2768
|
+
* @param params - Parameters containing messages to save and optional request context
|
|
2902
2769
|
* @returns Promise containing the saved messages
|
|
2903
2770
|
*/
|
|
2904
2771
|
saveMessageToMemory(params) {
|
|
2905
2772
|
return this.request(
|
|
2906
|
-
`/api/memory/save-messages?agentId=${params.agentId}${
|
|
2773
|
+
`/api/memory/save-messages?agentId=${params.agentId}${requestContextQueryString(params.requestContext, "&")}`,
|
|
2907
2774
|
{
|
|
2908
2775
|
method: "POST",
|
|
2909
2776
|
body: params
|
|
@@ -2913,64 +2780,22 @@ var MastraClient = class extends BaseResource {
|
|
|
2913
2780
|
/**
|
|
2914
2781
|
* Gets the status of the memory system
|
|
2915
2782
|
* @param agentId - The agent ID
|
|
2916
|
-
* @param
|
|
2783
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
2917
2784
|
* @returns Promise containing memory system status
|
|
2918
2785
|
*/
|
|
2919
|
-
getMemoryStatus(agentId,
|
|
2920
|
-
return this.request(`/api/memory/status?agentId=${agentId}${
|
|
2921
|
-
}
|
|
2922
|
-
/**
|
|
2923
|
-
* Retrieves memory threads for a resource
|
|
2924
|
-
* @param params - Parameters containing the resource ID
|
|
2925
|
-
* @returns Promise containing array of memory threads
|
|
2926
|
-
*/
|
|
2927
|
-
getNetworkMemoryThreads(params) {
|
|
2928
|
-
return this.request(`/api/memory/network/threads?resourceid=${params.resourceId}&networkId=${params.networkId}`);
|
|
2929
|
-
}
|
|
2930
|
-
/**
|
|
2931
|
-
* Creates a new memory thread
|
|
2932
|
-
* @param params - Parameters for creating the memory thread
|
|
2933
|
-
* @returns Promise containing the created memory thread
|
|
2934
|
-
*/
|
|
2935
|
-
createNetworkMemoryThread(params) {
|
|
2936
|
-
return this.request(`/api/memory/network/threads?networkId=${params.networkId}`, { method: "POST", body: params });
|
|
2937
|
-
}
|
|
2938
|
-
/**
|
|
2939
|
-
* Gets a memory thread instance by ID
|
|
2940
|
-
* @param threadId - ID of the memory thread to retrieve
|
|
2941
|
-
* @returns MemoryThread instance
|
|
2942
|
-
*/
|
|
2943
|
-
getNetworkMemoryThread(threadId, networkId) {
|
|
2944
|
-
return new NetworkMemoryThread(this.options, threadId, networkId);
|
|
2945
|
-
}
|
|
2946
|
-
/**
|
|
2947
|
-
* Saves messages to memory
|
|
2948
|
-
* @param params - Parameters containing messages to save
|
|
2949
|
-
* @returns Promise containing the saved messages
|
|
2950
|
-
*/
|
|
2951
|
-
saveNetworkMessageToMemory(params) {
|
|
2952
|
-
return this.request(`/api/memory/network/save-messages?networkId=${params.networkId}`, {
|
|
2953
|
-
method: "POST",
|
|
2954
|
-
body: params
|
|
2955
|
-
});
|
|
2956
|
-
}
|
|
2957
|
-
/**
|
|
2958
|
-
* Gets the status of the memory system
|
|
2959
|
-
* @returns Promise containing memory system status
|
|
2960
|
-
*/
|
|
2961
|
-
getNetworkMemoryStatus(networkId) {
|
|
2962
|
-
return this.request(`/api/memory/network/status?networkId=${networkId}`);
|
|
2786
|
+
getMemoryStatus(agentId, requestContext) {
|
|
2787
|
+
return this.request(`/api/memory/status?agentId=${agentId}${requestContextQueryString(requestContext, "&")}`);
|
|
2963
2788
|
}
|
|
2964
2789
|
/**
|
|
2965
2790
|
* Retrieves all available tools
|
|
2966
|
-
* @param
|
|
2791
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
2967
2792
|
* @returns Promise containing map of tool IDs to tool details
|
|
2968
2793
|
*/
|
|
2969
|
-
|
|
2970
|
-
const
|
|
2794
|
+
listTools(requestContext) {
|
|
2795
|
+
const requestContextParam = base64RequestContext(parseClientRequestContext(requestContext));
|
|
2971
2796
|
const searchParams = new URLSearchParams();
|
|
2972
|
-
if (
|
|
2973
|
-
searchParams.set("
|
|
2797
|
+
if (requestContextParam) {
|
|
2798
|
+
searchParams.set("requestContext", requestContextParam);
|
|
2974
2799
|
}
|
|
2975
2800
|
const queryString = searchParams.toString();
|
|
2976
2801
|
return this.request(`/api/tools${queryString ? `?${queryString}` : ""}`);
|
|
@@ -2985,14 +2810,14 @@ var MastraClient = class extends BaseResource {
|
|
|
2985
2810
|
}
|
|
2986
2811
|
/**
|
|
2987
2812
|
* Retrieves all available workflows
|
|
2988
|
-
* @param
|
|
2813
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
2989
2814
|
* @returns Promise containing map of workflow IDs to workflow details
|
|
2990
2815
|
*/
|
|
2991
|
-
|
|
2992
|
-
const
|
|
2816
|
+
listWorkflows(requestContext) {
|
|
2817
|
+
const requestContextParam = base64RequestContext(parseClientRequestContext(requestContext));
|
|
2993
2818
|
const searchParams = new URLSearchParams();
|
|
2994
|
-
if (
|
|
2995
|
-
searchParams.set("
|
|
2819
|
+
if (requestContextParam) {
|
|
2820
|
+
searchParams.set("requestContext", requestContextParam);
|
|
2996
2821
|
}
|
|
2997
2822
|
const queryString = searchParams.toString();
|
|
2998
2823
|
return this.request(`/api/workflows${queryString ? `?${queryString}` : ""}`);
|
|
@@ -3032,7 +2857,7 @@ var MastraClient = class extends BaseResource {
|
|
|
3032
2857
|
* @param params - Parameters for filtering logs
|
|
3033
2858
|
* @returns Promise containing array of log messages
|
|
3034
2859
|
*/
|
|
3035
|
-
|
|
2860
|
+
listLogs(params) {
|
|
3036
2861
|
const { transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
|
|
3037
2862
|
const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
|
|
3038
2863
|
const searchParams = new URLSearchParams();
|
|
@@ -3118,63 +2943,21 @@ var MastraClient = class extends BaseResource {
|
|
|
3118
2943
|
* List of all log transports
|
|
3119
2944
|
* @returns Promise containing list of log transports
|
|
3120
2945
|
*/
|
|
3121
|
-
|
|
2946
|
+
listLogTransports() {
|
|
3122
2947
|
return this.request("/api/logs/transports");
|
|
3123
2948
|
}
|
|
3124
|
-
/**
|
|
3125
|
-
* List of all traces (paged)
|
|
3126
|
-
* @param params - Parameters for filtering traces
|
|
3127
|
-
* @returns Promise containing telemetry data
|
|
3128
|
-
*/
|
|
3129
|
-
getTelemetry(params) {
|
|
3130
|
-
const { name, scope, page, perPage, attribute, fromDate, toDate } = params || {};
|
|
3131
|
-
const _attribute = attribute ? Object.entries(attribute).map(([key, value]) => `${key}:${value}`) : [];
|
|
3132
|
-
const searchParams = new URLSearchParams();
|
|
3133
|
-
if (name) {
|
|
3134
|
-
searchParams.set("name", name);
|
|
3135
|
-
}
|
|
3136
|
-
if (scope) {
|
|
3137
|
-
searchParams.set("scope", scope);
|
|
3138
|
-
}
|
|
3139
|
-
if (page) {
|
|
3140
|
-
searchParams.set("page", String(page));
|
|
3141
|
-
}
|
|
3142
|
-
if (perPage) {
|
|
3143
|
-
searchParams.set("perPage", String(perPage));
|
|
3144
|
-
}
|
|
3145
|
-
if (_attribute) {
|
|
3146
|
-
if (Array.isArray(_attribute)) {
|
|
3147
|
-
for (const attr of _attribute) {
|
|
3148
|
-
searchParams.append("attribute", attr);
|
|
3149
|
-
}
|
|
3150
|
-
} else {
|
|
3151
|
-
searchParams.set("attribute", _attribute);
|
|
3152
|
-
}
|
|
3153
|
-
}
|
|
3154
|
-
if (fromDate) {
|
|
3155
|
-
searchParams.set("fromDate", fromDate.toISOString());
|
|
3156
|
-
}
|
|
3157
|
-
if (toDate) {
|
|
3158
|
-
searchParams.set("toDate", toDate.toISOString());
|
|
3159
|
-
}
|
|
3160
|
-
if (searchParams.size) {
|
|
3161
|
-
return this.request(`/api/telemetry?${searchParams}`);
|
|
3162
|
-
} else {
|
|
3163
|
-
return this.request(`/api/telemetry`);
|
|
3164
|
-
}
|
|
3165
|
-
}
|
|
3166
2949
|
/**
|
|
3167
2950
|
* Retrieves a list of available MCP servers.
|
|
3168
|
-
* @param params - Optional parameters for pagination (
|
|
2951
|
+
* @param params - Optional parameters for pagination (perPage, page).
|
|
3169
2952
|
* @returns Promise containing the list of MCP servers and pagination info.
|
|
3170
2953
|
*/
|
|
3171
2954
|
getMcpServers(params) {
|
|
3172
2955
|
const searchParams = new URLSearchParams();
|
|
3173
|
-
if (params?.
|
|
3174
|
-
searchParams.set("
|
|
2956
|
+
if (params?.perPage !== void 0) {
|
|
2957
|
+
searchParams.set("perPage", String(params.perPage));
|
|
3175
2958
|
}
|
|
3176
|
-
if (params?.
|
|
3177
|
-
searchParams.set("
|
|
2959
|
+
if (params?.page !== void 0) {
|
|
2960
|
+
searchParams.set("page", String(params.page));
|
|
3178
2961
|
}
|
|
3179
2962
|
const queryString = searchParams.toString();
|
|
3180
2963
|
return this.request(`/api/mcp/v0/servers${queryString ? `?${queryString}` : ""}`);
|
|
@@ -3230,12 +3013,33 @@ var MastraClient = class extends BaseResource {
|
|
|
3230
3013
|
agentId,
|
|
3231
3014
|
threadId,
|
|
3232
3015
|
resourceId,
|
|
3233
|
-
|
|
3016
|
+
requestContext
|
|
3234
3017
|
}) {
|
|
3235
3018
|
return this.request(
|
|
3236
|
-
`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}${
|
|
3019
|
+
`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}${requestContextQueryString(requestContext, "&")}`
|
|
3237
3020
|
);
|
|
3238
3021
|
}
|
|
3022
|
+
searchMemory({
|
|
3023
|
+
agentId,
|
|
3024
|
+
resourceId,
|
|
3025
|
+
threadId,
|
|
3026
|
+
searchQuery,
|
|
3027
|
+
memoryConfig,
|
|
3028
|
+
requestContext
|
|
3029
|
+
}) {
|
|
3030
|
+
const params = new URLSearchParams({
|
|
3031
|
+
searchQuery,
|
|
3032
|
+
resourceId,
|
|
3033
|
+
agentId
|
|
3034
|
+
});
|
|
3035
|
+
if (threadId) {
|
|
3036
|
+
params.append("threadId", threadId);
|
|
3037
|
+
}
|
|
3038
|
+
if (memoryConfig) {
|
|
3039
|
+
params.append("memoryConfig", JSON.stringify(memoryConfig));
|
|
3040
|
+
}
|
|
3041
|
+
return this.request(`/api/memory/search?${params}${requestContextQueryString(requestContext, "&")}`);
|
|
3042
|
+
}
|
|
3239
3043
|
/**
|
|
3240
3044
|
* Updates the working memory for a specific thread (optionally resource-scoped).
|
|
3241
3045
|
* @param agentId - ID of the agent.
|
|
@@ -3248,10 +3052,10 @@ var MastraClient = class extends BaseResource {
|
|
|
3248
3052
|
threadId,
|
|
3249
3053
|
workingMemory,
|
|
3250
3054
|
resourceId,
|
|
3251
|
-
|
|
3055
|
+
requestContext
|
|
3252
3056
|
}) {
|
|
3253
3057
|
return this.request(
|
|
3254
|
-
`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}${
|
|
3058
|
+
`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}${requestContextQueryString(requestContext, "&")}`,
|
|
3255
3059
|
{
|
|
3256
3060
|
method: "POST",
|
|
3257
3061
|
body: {
|
|
@@ -3265,7 +3069,7 @@ var MastraClient = class extends BaseResource {
|
|
|
3265
3069
|
* Retrieves all available scorers
|
|
3266
3070
|
* @returns Promise containing list of available scorers
|
|
3267
3071
|
*/
|
|
3268
|
-
|
|
3072
|
+
listScorers() {
|
|
3269
3073
|
return this.request("/api/scores/scorers");
|
|
3270
3074
|
}
|
|
3271
3075
|
/**
|
|
@@ -3276,7 +3080,7 @@ var MastraClient = class extends BaseResource {
|
|
|
3276
3080
|
getScorer(scorerId) {
|
|
3277
3081
|
return this.request(`/api/scores/scorers/${encodeURIComponent(scorerId)}`);
|
|
3278
3082
|
}
|
|
3279
|
-
|
|
3083
|
+
listScoresByScorerId(params) {
|
|
3280
3084
|
const { page, perPage, scorerId, entityId, entityType } = params;
|
|
3281
3085
|
const searchParams = new URLSearchParams();
|
|
3282
3086
|
if (entityId) {
|
|
@@ -3299,7 +3103,7 @@ var MastraClient = class extends BaseResource {
|
|
|
3299
3103
|
* @param params - Parameters containing run ID and pagination options
|
|
3300
3104
|
* @returns Promise containing scores and pagination info
|
|
3301
3105
|
*/
|
|
3302
|
-
|
|
3106
|
+
listScoresByRunId(params) {
|
|
3303
3107
|
const { runId, page, perPage } = params;
|
|
3304
3108
|
const searchParams = new URLSearchParams();
|
|
3305
3109
|
if (page !== void 0) {
|
|
@@ -3316,7 +3120,7 @@ var MastraClient = class extends BaseResource {
|
|
|
3316
3120
|
* @param params - Parameters containing entity ID, type, and pagination options
|
|
3317
3121
|
* @returns Promise containing scores and pagination info
|
|
3318
3122
|
*/
|
|
3319
|
-
|
|
3123
|
+
listScoresByEntityId(params) {
|
|
3320
3124
|
const { entityId, entityType, page, perPage } = params;
|
|
3321
3125
|
const searchParams = new URLSearchParams();
|
|
3322
3126
|
if (page !== void 0) {
|
|
@@ -3341,14 +3145,14 @@ var MastraClient = class extends BaseResource {
|
|
|
3341
3145
|
body: params
|
|
3342
3146
|
});
|
|
3343
3147
|
}
|
|
3344
|
-
|
|
3148
|
+
getTrace(traceId) {
|
|
3345
3149
|
return this.observability.getTrace(traceId);
|
|
3346
3150
|
}
|
|
3347
|
-
|
|
3151
|
+
getTraces(params) {
|
|
3348
3152
|
return this.observability.getTraces(params);
|
|
3349
3153
|
}
|
|
3350
|
-
|
|
3351
|
-
return this.observability.
|
|
3154
|
+
listScoresBySpan(params) {
|
|
3155
|
+
return this.observability.listScoresBySpan(params);
|
|
3352
3156
|
}
|
|
3353
3157
|
score(params) {
|
|
3354
3158
|
return this.observability.score(params);
|