@mastra/client-js 0.16.9-alpha.0 → 1.0.0-beta.0
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 +280 -47
- package/README.md +8 -10
- package/dist/client.d.ts +52 -77
- package/dist/client.d.ts.map +1 -1
- package/dist/index.cjs +404 -621
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +404 -621
- 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 +17 -43
- 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/package.json +6 -10
- 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
|
}
|
|
@@ -203,10 +203,9 @@ var BaseResource = class {
|
|
|
203
203
|
async function executeToolCallAndRespond({
|
|
204
204
|
response,
|
|
205
205
|
params,
|
|
206
|
-
runId,
|
|
207
206
|
resourceId,
|
|
208
207
|
threadId,
|
|
209
|
-
|
|
208
|
+
requestContext,
|
|
210
209
|
respondFn
|
|
211
210
|
}) {
|
|
212
211
|
if (response.finishReason === "tool-calls") {
|
|
@@ -217,22 +216,18 @@ async function executeToolCallAndRespond({
|
|
|
217
216
|
for (const toolCall of toolCalls) {
|
|
218
217
|
const clientTool = params.clientTools?.[toolCall.toolName];
|
|
219
218
|
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
|
-
{
|
|
219
|
+
const result = await clientTool.execute(toolCall?.args, {
|
|
220
|
+
requestContext,
|
|
221
|
+
tracingContext: { currentSpan: void 0 },
|
|
222
|
+
agent: {
|
|
232
223
|
messages: response.messages,
|
|
233
|
-
toolCallId: toolCall?.toolCallId
|
|
224
|
+
toolCallId: toolCall?.toolCallId,
|
|
225
|
+
suspend: async () => {
|
|
226
|
+
},
|
|
227
|
+
threadId,
|
|
228
|
+
resourceId
|
|
234
229
|
}
|
|
235
|
-
);
|
|
230
|
+
});
|
|
236
231
|
const updatedMessages = [
|
|
237
232
|
...response.response.messages || [],
|
|
238
233
|
{
|
|
@@ -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();
|
|
@@ -1043,23 +1038,19 @@ var Agent = class extends BaseResource {
|
|
|
1043
1038
|
const clientTool = processedParams.clientTools?.[toolCall2.toolName];
|
|
1044
1039
|
if (clientTool && clientTool.execute) {
|
|
1045
1040
|
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
|
-
{
|
|
1041
|
+
const result = await clientTool.execute(toolCall2?.args, {
|
|
1042
|
+
requestContext: processedParams.requestContext,
|
|
1043
|
+
// TODO: Pass proper tracing context when client-js supports tracing
|
|
1044
|
+
tracingContext: { currentSpan: void 0 },
|
|
1045
|
+
agent: {
|
|
1059
1046
|
messages: response.messages,
|
|
1060
|
-
toolCallId: toolCall2?.toolCallId
|
|
1047
|
+
toolCallId: toolCall2?.toolCallId,
|
|
1048
|
+
suspend: async () => {
|
|
1049
|
+
},
|
|
1050
|
+
threadId: processedParams.threadId,
|
|
1051
|
+
resourceId: processedParams.resourceId
|
|
1061
1052
|
}
|
|
1062
|
-
);
|
|
1053
|
+
});
|
|
1063
1054
|
const lastMessageRaw = messages[messages.length - 1];
|
|
1064
1055
|
const lastMessage = lastMessageRaw != null ? JSON.parse(JSON.stringify(lastMessageRaw)) : void 0;
|
|
1065
1056
|
const toolInvocationPart = lastMessage?.parts?.find(
|
|
@@ -1147,8 +1138,7 @@ var Agent = class extends BaseResource {
|
|
|
1147
1138
|
}
|
|
1148
1139
|
const processedParams = {
|
|
1149
1140
|
...params,
|
|
1150
|
-
|
|
1151
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
1141
|
+
requestContext: parseClientRequestContext(params.requestContext),
|
|
1152
1142
|
clientTools: processClientTools(params.clientTools),
|
|
1153
1143
|
structuredOutput: params.structuredOutput ? {
|
|
1154
1144
|
...params.structuredOutput,
|
|
@@ -1248,23 +1238,19 @@ var Agent = class extends BaseResource {
|
|
|
1248
1238
|
for (const toolCall2 of toolCalls) {
|
|
1249
1239
|
const clientTool = processedParams.clientTools?.[toolCall2.toolName];
|
|
1250
1240
|
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
|
-
{
|
|
1241
|
+
const result = await clientTool.execute(toolCall2?.args, {
|
|
1242
|
+
requestContext: processedParams.requestContext,
|
|
1243
|
+
// TODO: Pass proper tracing context when client-js supports tracing
|
|
1244
|
+
tracingContext: { currentSpan: void 0 },
|
|
1245
|
+
agent: {
|
|
1264
1246
|
messages: response.messages,
|
|
1265
|
-
toolCallId: toolCall2?.toolCallId
|
|
1247
|
+
toolCallId: toolCall2?.toolCallId,
|
|
1248
|
+
suspend: async () => {
|
|
1249
|
+
},
|
|
1250
|
+
threadId: processedParams.threadId,
|
|
1251
|
+
resourceId: processedParams.resourceId
|
|
1266
1252
|
}
|
|
1267
|
-
);
|
|
1253
|
+
});
|
|
1268
1254
|
const lastMessage = JSON.parse(JSON.stringify(messages[messages.length - 1]));
|
|
1269
1255
|
const toolInvocationPart = lastMessage?.parts?.find(
|
|
1270
1256
|
(part) => part.type === "tool-invocation" && part.toolInvocation?.toolCallId === toolCall2.toolCallId
|
|
@@ -1325,11 +1311,11 @@ var Agent = class extends BaseResource {
|
|
|
1325
1311
|
/**
|
|
1326
1312
|
* Gets details about a specific tool available to the agent
|
|
1327
1313
|
* @param toolId - ID of the tool to retrieve
|
|
1328
|
-
* @param
|
|
1314
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1329
1315
|
* @returns Promise containing tool details
|
|
1330
1316
|
*/
|
|
1331
|
-
getTool(toolId,
|
|
1332
|
-
return this.request(`/api/agents/${this.agentId}/tools/${toolId}${
|
|
1317
|
+
getTool(toolId, requestContext) {
|
|
1318
|
+
return this.request(`/api/agents/${this.agentId}/tools/${toolId}${requestContextQueryString(requestContext)}`);
|
|
1333
1319
|
}
|
|
1334
1320
|
/**
|
|
1335
1321
|
* Executes a tool for the agent
|
|
@@ -1340,29 +1326,13 @@ var Agent = class extends BaseResource {
|
|
|
1340
1326
|
executeTool(toolId, params) {
|
|
1341
1327
|
const body = {
|
|
1342
1328
|
data: params.data,
|
|
1343
|
-
|
|
1329
|
+
requestContext: parseClientRequestContext(params.requestContext)
|
|
1344
1330
|
};
|
|
1345
1331
|
return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
|
|
1346
1332
|
method: "POST",
|
|
1347
1333
|
body
|
|
1348
1334
|
});
|
|
1349
1335
|
}
|
|
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
1336
|
/**
|
|
1367
1337
|
* Updates the model for the agent
|
|
1368
1338
|
* @param params - Parameters for updating the model
|
|
@@ -1405,12 +1375,6 @@ var Agent = class extends BaseResource {
|
|
|
1405
1375
|
body: params
|
|
1406
1376
|
});
|
|
1407
1377
|
}
|
|
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
1378
|
};
|
|
1415
1379
|
|
|
1416
1380
|
// src/resources/memory-thread.ts
|
|
@@ -1422,22 +1386,22 @@ var MemoryThread = class extends BaseResource {
|
|
|
1422
1386
|
}
|
|
1423
1387
|
/**
|
|
1424
1388
|
* Retrieves the memory thread details
|
|
1425
|
-
* @param
|
|
1389
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1426
1390
|
* @returns Promise containing thread details including title and metadata
|
|
1427
1391
|
*/
|
|
1428
|
-
get(
|
|
1392
|
+
get(requestContext) {
|
|
1429
1393
|
return this.request(
|
|
1430
|
-
`/api/memory/threads/${this.threadId}?agentId=${this.agentId}${
|
|
1394
|
+
`/api/memory/threads/${this.threadId}?agentId=${this.agentId}${requestContextQueryString(requestContext, "&")}`
|
|
1431
1395
|
);
|
|
1432
1396
|
}
|
|
1433
1397
|
/**
|
|
1434
1398
|
* Updates the memory thread properties
|
|
1435
|
-
* @param params - Update parameters including title, metadata, and optional
|
|
1399
|
+
* @param params - Update parameters including title, metadata, and optional request context
|
|
1436
1400
|
* @returns Promise containing updated thread details
|
|
1437
1401
|
*/
|
|
1438
1402
|
update(params) {
|
|
1439
1403
|
return this.request(
|
|
1440
|
-
`/api/memory/threads/${this.threadId}?agentId=${this.agentId}${
|
|
1404
|
+
`/api/memory/threads/${this.threadId}?agentId=${this.agentId}${requestContextQueryString(params.requestContext, "&")}`,
|
|
1441
1405
|
{
|
|
1442
1406
|
method: "PATCH",
|
|
1443
1407
|
body: params
|
|
@@ -1446,62 +1410,49 @@ var MemoryThread = class extends BaseResource {
|
|
|
1446
1410
|
}
|
|
1447
1411
|
/**
|
|
1448
1412
|
* Deletes the memory thread
|
|
1449
|
-
* @param
|
|
1413
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1450
1414
|
* @returns Promise containing deletion result
|
|
1451
1415
|
*/
|
|
1452
|
-
delete(
|
|
1416
|
+
delete(requestContext) {
|
|
1453
1417
|
return this.request(
|
|
1454
|
-
`/api/memory/threads/${this.threadId}?agentId=${this.agentId}${
|
|
1418
|
+
`/api/memory/threads/${this.threadId}?agentId=${this.agentId}${requestContextQueryString(requestContext, "&")}`,
|
|
1455
1419
|
{
|
|
1456
1420
|
method: "DELETE"
|
|
1457
1421
|
}
|
|
1458
1422
|
);
|
|
1459
1423
|
}
|
|
1460
1424
|
/**
|
|
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
|
|
1425
|
+
* Retrieves paginated messages associated with the thread with filtering and ordering options
|
|
1426
|
+
* @param params - Pagination parameters including page, perPage, orderBy, filter, include options, and request context
|
|
1477
1427
|
* @returns Promise containing paginated thread messages with pagination metadata (total, page, perPage, hasMore)
|
|
1478
1428
|
*/
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
)
|
|
1429
|
+
listMessages(params = {}) {
|
|
1430
|
+
const { page, perPage, orderBy, filter, include, resourceId, requestContext } = params;
|
|
1431
|
+
const queryParams = {};
|
|
1432
|
+
if (resourceId) queryParams.resourceId = resourceId;
|
|
1433
|
+
if (page !== void 0) queryParams.page = String(page);
|
|
1434
|
+
if (perPage !== void 0) queryParams.perPage = String(perPage);
|
|
1435
|
+
if (orderBy) queryParams.orderBy = JSON.stringify(orderBy);
|
|
1436
|
+
if (filter) queryParams.filter = JSON.stringify(filter);
|
|
1437
|
+
if (include) queryParams.include = JSON.stringify(include);
|
|
1438
|
+
const query = new URLSearchParams(queryParams);
|
|
1439
|
+
const queryString = query.toString();
|
|
1440
|
+
const url = `/api/memory/threads/${this.threadId}/messages${queryString ? `?${queryString}` : ""}${requestContextQueryString(requestContext, queryString ? "&" : "?")}`;
|
|
1441
|
+
return this.request(url);
|
|
1491
1442
|
}
|
|
1492
1443
|
/**
|
|
1493
1444
|
* Deletes one or more messages from the thread
|
|
1494
1445
|
* @param messageIds - Can be a single message ID (string), array of message IDs,
|
|
1495
1446
|
* message object with id property, or array of message objects
|
|
1496
|
-
* @param
|
|
1447
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1497
1448
|
* @returns Promise containing deletion result
|
|
1498
1449
|
*/
|
|
1499
|
-
deleteMessages(messageIds,
|
|
1450
|
+
deleteMessages(messageIds, requestContext) {
|
|
1500
1451
|
const query = new URLSearchParams({
|
|
1501
1452
|
agentId: this.agentId
|
|
1502
1453
|
});
|
|
1503
1454
|
return this.request(
|
|
1504
|
-
`/api/memory/messages/delete?${query.toString()}${
|
|
1455
|
+
`/api/memory/messages/delete?${query.toString()}${requestContextQueryString(requestContext, "&")}`,
|
|
1505
1456
|
{
|
|
1506
1457
|
method: "POST",
|
|
1507
1458
|
body: { messageIds }
|
|
@@ -1519,12 +1470,12 @@ var Vector = class extends BaseResource {
|
|
|
1519
1470
|
/**
|
|
1520
1471
|
* Retrieves details about a specific vector index
|
|
1521
1472
|
* @param indexName - Name of the index to get details for
|
|
1522
|
-
* @param
|
|
1473
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1523
1474
|
* @returns Promise containing vector index details
|
|
1524
1475
|
*/
|
|
1525
|
-
details(indexName,
|
|
1476
|
+
details(indexName, requestContext) {
|
|
1526
1477
|
return this.request(
|
|
1527
|
-
`/api/vector/${this.vectorName}/indexes/${indexName}${
|
|
1478
|
+
`/api/vector/${this.vectorName}/indexes/${indexName}${requestContextQueryString(requestContext)}`
|
|
1528
1479
|
);
|
|
1529
1480
|
}
|
|
1530
1481
|
/**
|
|
@@ -1539,11 +1490,11 @@ var Vector = class extends BaseResource {
|
|
|
1539
1490
|
}
|
|
1540
1491
|
/**
|
|
1541
1492
|
* Retrieves a list of all available indexes
|
|
1542
|
-
* @param
|
|
1493
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1543
1494
|
* @returns Promise containing array of index names
|
|
1544
1495
|
*/
|
|
1545
|
-
getIndexes(
|
|
1546
|
-
return this.request(`/api/vector/${this.vectorName}/indexes${
|
|
1496
|
+
getIndexes(requestContext) {
|
|
1497
|
+
return this.request(`/api/vector/${this.vectorName}/indexes${requestContextQueryString(requestContext)}`);
|
|
1547
1498
|
}
|
|
1548
1499
|
/**
|
|
1549
1500
|
* Creates a new vector index
|
|
@@ -1588,11 +1539,11 @@ var Tool = class extends BaseResource {
|
|
|
1588
1539
|
}
|
|
1589
1540
|
/**
|
|
1590
1541
|
* Retrieves details about the tool
|
|
1591
|
-
* @param
|
|
1542
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1592
1543
|
* @returns Promise containing tool details including description and schemas
|
|
1593
1544
|
*/
|
|
1594
|
-
details(
|
|
1595
|
-
return this.request(`/api/tools/${this.toolId}${
|
|
1545
|
+
details(requestContext) {
|
|
1546
|
+
return this.request(`/api/tools/${this.toolId}${requestContextQueryString(requestContext)}`);
|
|
1596
1547
|
}
|
|
1597
1548
|
/**
|
|
1598
1549
|
* Executes the tool with the provided parameters
|
|
@@ -1606,7 +1557,7 @@ var Tool = class extends BaseResource {
|
|
|
1606
1557
|
}
|
|
1607
1558
|
const body = {
|
|
1608
1559
|
data: params.data,
|
|
1609
|
-
|
|
1560
|
+
requestContext: parseClientRequestContext(params.requestContext)
|
|
1610
1561
|
};
|
|
1611
1562
|
return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
|
|
1612
1563
|
method: "POST",
|
|
@@ -1622,67 +1573,22 @@ var Workflow = class extends BaseResource {
|
|
|
1622
1573
|
super(options);
|
|
1623
1574
|
this.workflowId = workflowId;
|
|
1624
1575
|
}
|
|
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
1576
|
/**
|
|
1671
1577
|
* Retrieves details about the workflow
|
|
1672
|
-
* @param
|
|
1578
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1673
1579
|
* @returns Promise containing workflow details including steps and graphs
|
|
1674
1580
|
*/
|
|
1675
|
-
details(
|
|
1676
|
-
return this.request(`/api/workflows/${this.workflowId}${
|
|
1581
|
+
details(requestContext) {
|
|
1582
|
+
return this.request(`/api/workflows/${this.workflowId}${requestContextQueryString(requestContext)}`);
|
|
1677
1583
|
}
|
|
1678
1584
|
/**
|
|
1679
1585
|
* Retrieves all runs for a workflow
|
|
1680
1586
|
* @param params - Parameters for filtering runs
|
|
1681
|
-
* @param
|
|
1587
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1682
1588
|
* @returns Promise containing workflow runs array
|
|
1683
1589
|
*/
|
|
1684
|
-
runs(params,
|
|
1685
|
-
const
|
|
1590
|
+
runs(params, requestContext) {
|
|
1591
|
+
const requestContextParam = base64RequestContext(parseClientRequestContext(requestContext));
|
|
1686
1592
|
const searchParams = new URLSearchParams();
|
|
1687
1593
|
if (params?.fromDate) {
|
|
1688
1594
|
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
@@ -1690,17 +1596,21 @@ var Workflow = class extends BaseResource {
|
|
|
1690
1596
|
if (params?.toDate) {
|
|
1691
1597
|
searchParams.set("toDate", params.toDate.toISOString());
|
|
1692
1598
|
}
|
|
1693
|
-
if (params?.
|
|
1694
|
-
|
|
1599
|
+
if (params?.perPage !== null && params?.perPage !== void 0) {
|
|
1600
|
+
if (params.perPage === false) {
|
|
1601
|
+
searchParams.set("perPage", "false");
|
|
1602
|
+
} else if (typeof params.perPage === "number" && params.perPage > 0 && Number.isInteger(params.perPage)) {
|
|
1603
|
+
searchParams.set("perPage", String(params.perPage));
|
|
1604
|
+
}
|
|
1695
1605
|
}
|
|
1696
|
-
if (params?.
|
|
1697
|
-
searchParams.set("
|
|
1606
|
+
if (params?.page !== null && params?.page !== void 0 && !isNaN(Number(params?.page))) {
|
|
1607
|
+
searchParams.set("page", String(params.page));
|
|
1698
1608
|
}
|
|
1699
1609
|
if (params?.resourceId) {
|
|
1700
1610
|
searchParams.set("resourceId", params.resourceId);
|
|
1701
1611
|
}
|
|
1702
|
-
if (
|
|
1703
|
-
searchParams.set("
|
|
1612
|
+
if (requestContextParam) {
|
|
1613
|
+
searchParams.set("requestContext", requestContextParam);
|
|
1704
1614
|
}
|
|
1705
1615
|
if (searchParams.size) {
|
|
1706
1616
|
return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
|
|
@@ -1711,21 +1621,21 @@ var Workflow = class extends BaseResource {
|
|
|
1711
1621
|
/**
|
|
1712
1622
|
* Retrieves a specific workflow run by its ID
|
|
1713
1623
|
* @param runId - The ID of the workflow run to retrieve
|
|
1714
|
-
* @param
|
|
1624
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1715
1625
|
* @returns Promise containing the workflow run details
|
|
1716
1626
|
*/
|
|
1717
|
-
runById(runId,
|
|
1718
|
-
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}${
|
|
1627
|
+
runById(runId, requestContext) {
|
|
1628
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}${requestContextQueryString(requestContext)}`);
|
|
1719
1629
|
}
|
|
1720
1630
|
/**
|
|
1721
1631
|
* Retrieves the execution result for a specific workflow run by its ID
|
|
1722
1632
|
* @param runId - The ID of the workflow run to retrieve the execution result for
|
|
1723
|
-
* @param
|
|
1633
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1724
1634
|
* @returns Promise containing the workflow run execution result
|
|
1725
1635
|
*/
|
|
1726
|
-
runExecutionResult(runId,
|
|
1636
|
+
runExecutionResult(runId, requestContext) {
|
|
1727
1637
|
return this.request(
|
|
1728
|
-
`/api/workflows/${this.workflowId}/runs/${runId}/execution-result${
|
|
1638
|
+
`/api/workflows/${this.workflowId}/runs/${runId}/execution-result${requestContextQueryString(requestContext)}`
|
|
1729
1639
|
);
|
|
1730
1640
|
}
|
|
1731
1641
|
/**
|
|
@@ -1738,32 +1648,12 @@ var Workflow = class extends BaseResource {
|
|
|
1738
1648
|
method: "POST"
|
|
1739
1649
|
});
|
|
1740
1650
|
}
|
|
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
1651
|
/**
|
|
1762
1652
|
* Creates a new workflow run
|
|
1763
1653
|
* @param params - Optional object containing the optional runId
|
|
1764
1654
|
* @returns Promise containing the runId of the created run with methods to control execution
|
|
1765
1655
|
*/
|
|
1766
|
-
async
|
|
1656
|
+
async createRun(params) {
|
|
1767
1657
|
const searchParams = new URLSearchParams();
|
|
1768
1658
|
if (!!params?.runId) {
|
|
1769
1659
|
searchParams.set("runId", params.runId);
|
|
@@ -1781,7 +1671,7 @@ var Workflow = class extends BaseResource {
|
|
|
1781
1671
|
return this.start({
|
|
1782
1672
|
runId,
|
|
1783
1673
|
inputData: p.inputData,
|
|
1784
|
-
|
|
1674
|
+
requestContext: p.requestContext,
|
|
1785
1675
|
tracingOptions: p.tracingOptions
|
|
1786
1676
|
});
|
|
1787
1677
|
},
|
|
@@ -1789,22 +1679,19 @@ var Workflow = class extends BaseResource {
|
|
|
1789
1679
|
return this.startAsync({
|
|
1790
1680
|
runId,
|
|
1791
1681
|
inputData: p.inputData,
|
|
1792
|
-
|
|
1682
|
+
requestContext: p.requestContext,
|
|
1793
1683
|
tracingOptions: p.tracingOptions
|
|
1794
1684
|
});
|
|
1795
1685
|
},
|
|
1796
|
-
watch: async (onRecord) => {
|
|
1797
|
-
return this.watch({ runId }, onRecord);
|
|
1798
|
-
},
|
|
1799
1686
|
stream: async (p) => {
|
|
1800
|
-
return this.stream({ runId, inputData: p.inputData,
|
|
1687
|
+
return this.stream({ runId, inputData: p.inputData, requestContext: p.requestContext });
|
|
1801
1688
|
},
|
|
1802
1689
|
resume: async (p) => {
|
|
1803
1690
|
return this.resume({
|
|
1804
1691
|
runId,
|
|
1805
1692
|
step: p.step,
|
|
1806
1693
|
resumeData: p.resumeData,
|
|
1807
|
-
|
|
1694
|
+
requestContext: p.requestContext,
|
|
1808
1695
|
tracingOptions: p.tracingOptions
|
|
1809
1696
|
});
|
|
1810
1697
|
},
|
|
@@ -1813,7 +1700,7 @@ var Workflow = class extends BaseResource {
|
|
|
1813
1700
|
runId,
|
|
1814
1701
|
step: p.step,
|
|
1815
1702
|
resumeData: p.resumeData,
|
|
1816
|
-
|
|
1703
|
+
requestContext: p.requestContext,
|
|
1817
1704
|
tracingOptions: p.tracingOptions
|
|
1818
1705
|
});
|
|
1819
1706
|
},
|
|
@@ -1822,26 +1709,26 @@ var Workflow = class extends BaseResource {
|
|
|
1822
1709
|
runId,
|
|
1823
1710
|
step: p.step,
|
|
1824
1711
|
resumeData: p.resumeData,
|
|
1825
|
-
|
|
1712
|
+
requestContext: p.requestContext
|
|
1826
1713
|
});
|
|
1827
1714
|
}
|
|
1828
1715
|
};
|
|
1829
1716
|
}
|
|
1830
1717
|
/**
|
|
1831
1718
|
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
1832
|
-
* @param params - Object containing the runId, inputData and
|
|
1719
|
+
* @param params - Object containing the runId, inputData and requestContext
|
|
1833
1720
|
* @returns Promise containing success message
|
|
1834
1721
|
*/
|
|
1835
1722
|
start(params) {
|
|
1836
|
-
const
|
|
1723
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
1837
1724
|
return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
|
|
1838
1725
|
method: "POST",
|
|
1839
|
-
body: { inputData: params?.inputData,
|
|
1726
|
+
body: { inputData: params?.inputData, requestContext, tracingOptions: params.tracingOptions }
|
|
1840
1727
|
});
|
|
1841
1728
|
}
|
|
1842
1729
|
/**
|
|
1843
1730
|
* Resumes a suspended workflow step synchronously without waiting for the workflow to complete
|
|
1844
|
-
* @param params - Object containing the runId, step, resumeData and
|
|
1731
|
+
* @param params - Object containing the runId, step, resumeData and requestContext
|
|
1845
1732
|
* @returns Promise containing success message
|
|
1846
1733
|
*/
|
|
1847
1734
|
resume({
|
|
@@ -1851,20 +1738,20 @@ var Workflow = class extends BaseResource {
|
|
|
1851
1738
|
tracingOptions,
|
|
1852
1739
|
...rest
|
|
1853
1740
|
}) {
|
|
1854
|
-
const
|
|
1741
|
+
const requestContext = parseClientRequestContext(rest.requestContext);
|
|
1855
1742
|
return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
|
|
1856
1743
|
method: "POST",
|
|
1857
1744
|
body: {
|
|
1858
1745
|
step,
|
|
1859
1746
|
resumeData,
|
|
1860
|
-
|
|
1747
|
+
requestContext,
|
|
1861
1748
|
tracingOptions
|
|
1862
1749
|
}
|
|
1863
1750
|
});
|
|
1864
1751
|
}
|
|
1865
1752
|
/**
|
|
1866
1753
|
* 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
|
|
1754
|
+
* @param params - Object containing the optional runId, inputData and requestContext
|
|
1868
1755
|
* @returns Promise containing the workflow execution results
|
|
1869
1756
|
*/
|
|
1870
1757
|
startAsync(params) {
|
|
@@ -1872,15 +1759,15 @@ var Workflow = class extends BaseResource {
|
|
|
1872
1759
|
if (!!params?.runId) {
|
|
1873
1760
|
searchParams.set("runId", params.runId);
|
|
1874
1761
|
}
|
|
1875
|
-
const
|
|
1762
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
1876
1763
|
return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
1877
1764
|
method: "POST",
|
|
1878
|
-
body: { inputData: params.inputData,
|
|
1765
|
+
body: { inputData: params.inputData, requestContext, tracingOptions: params.tracingOptions }
|
|
1879
1766
|
});
|
|
1880
1767
|
}
|
|
1881
1768
|
/**
|
|
1882
1769
|
* Starts a workflow run and returns a stream
|
|
1883
|
-
* @param params - Object containing the optional runId, inputData and
|
|
1770
|
+
* @param params - Object containing the optional runId, inputData and requestContext
|
|
1884
1771
|
* @returns Promise containing the workflow execution results
|
|
1885
1772
|
*/
|
|
1886
1773
|
async stream(params) {
|
|
@@ -1888,12 +1775,12 @@ var Workflow = class extends BaseResource {
|
|
|
1888
1775
|
if (!!params?.runId) {
|
|
1889
1776
|
searchParams.set("runId", params.runId);
|
|
1890
1777
|
}
|
|
1891
|
-
const
|
|
1778
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
1892
1779
|
const response = await this.request(
|
|
1893
1780
|
`/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
|
|
1894
1781
|
{
|
|
1895
1782
|
method: "POST",
|
|
1896
|
-
body: { inputData: params.inputData,
|
|
1783
|
+
body: { inputData: params.inputData, requestContext, tracingOptions: params.tracingOptions },
|
|
1897
1784
|
stream: true
|
|
1898
1785
|
}
|
|
1899
1786
|
);
|
|
@@ -1978,7 +1865,7 @@ var Workflow = class extends BaseResource {
|
|
|
1978
1865
|
}
|
|
1979
1866
|
/**
|
|
1980
1867
|
* Starts a workflow run and returns a stream
|
|
1981
|
-
* @param params - Object containing the optional runId, inputData and
|
|
1868
|
+
* @param params - Object containing the optional runId, inputData and requestContext
|
|
1982
1869
|
* @returns Promise containing the workflow execution results
|
|
1983
1870
|
*/
|
|
1984
1871
|
async streamVNext(params) {
|
|
@@ -1986,14 +1873,14 @@ var Workflow = class extends BaseResource {
|
|
|
1986
1873
|
if (!!params?.runId) {
|
|
1987
1874
|
searchParams.set("runId", params.runId);
|
|
1988
1875
|
}
|
|
1989
|
-
const
|
|
1876
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
1990
1877
|
const response = await this.request(
|
|
1991
1878
|
`/api/workflows/${this.workflowId}/streamVNext?${searchParams.toString()}`,
|
|
1992
1879
|
{
|
|
1993
1880
|
method: "POST",
|
|
1994
1881
|
body: {
|
|
1995
1882
|
inputData: params.inputData,
|
|
1996
|
-
|
|
1883
|
+
requestContext,
|
|
1997
1884
|
closeOnSuspend: params.closeOnSuspend,
|
|
1998
1885
|
tracingOptions: params.tracingOptions
|
|
1999
1886
|
},
|
|
@@ -2081,30 +1968,30 @@ var Workflow = class extends BaseResource {
|
|
|
2081
1968
|
}
|
|
2082
1969
|
/**
|
|
2083
1970
|
* 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
|
|
1971
|
+
* @param params - Object containing the runId, step, resumeData and requestContext
|
|
2085
1972
|
* @returns Promise containing the workflow resume results
|
|
2086
1973
|
*/
|
|
2087
1974
|
resumeAsync(params) {
|
|
2088
|
-
const
|
|
1975
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2089
1976
|
return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
2090
1977
|
method: "POST",
|
|
2091
1978
|
body: {
|
|
2092
1979
|
step: params.step,
|
|
2093
1980
|
resumeData: params.resumeData,
|
|
2094
|
-
|
|
1981
|
+
requestContext,
|
|
2095
1982
|
tracingOptions: params.tracingOptions
|
|
2096
1983
|
}
|
|
2097
1984
|
});
|
|
2098
1985
|
}
|
|
2099
1986
|
/**
|
|
2100
1987
|
* 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
|
|
1988
|
+
* @param params - Object containing the runId, step, resumeData and requestContext
|
|
2102
1989
|
* @returns Promise containing the workflow resume results
|
|
2103
1990
|
*/
|
|
2104
1991
|
async resumeStreamVNext(params) {
|
|
2105
1992
|
const searchParams = new URLSearchParams();
|
|
2106
1993
|
searchParams.set("runId", params.runId);
|
|
2107
|
-
const
|
|
1994
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2108
1995
|
const response = await this.request(
|
|
2109
1996
|
`/api/workflows/${this.workflowId}/resume-stream?${searchParams.toString()}`,
|
|
2110
1997
|
{
|
|
@@ -2112,7 +1999,7 @@ var Workflow = class extends BaseResource {
|
|
|
2112
1999
|
body: {
|
|
2113
2000
|
step: params.step,
|
|
2114
2001
|
resumeData: params.resumeData,
|
|
2115
|
-
|
|
2002
|
+
requestContext,
|
|
2116
2003
|
tracingOptions: params.tracingOptions
|
|
2117
2004
|
},
|
|
2118
2005
|
stream: true
|
|
@@ -2150,29 +2037,6 @@ var Workflow = class extends BaseResource {
|
|
|
2150
2037
|
});
|
|
2151
2038
|
return response.body.pipeThrough(transformStream);
|
|
2152
2039
|
}
|
|
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
2040
|
/**
|
|
2177
2041
|
* Creates a new ReadableStream from an iterable or async iterable of objects,
|
|
2178
2042
|
* serializing each as JSON and separating them with the record separator (\x1E).
|
|
@@ -2284,22 +2148,22 @@ var MCPTool = class extends BaseResource {
|
|
|
2284
2148
|
}
|
|
2285
2149
|
/**
|
|
2286
2150
|
* Retrieves details about this specific tool from the MCP server.
|
|
2287
|
-
* @param
|
|
2151
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
2288
2152
|
* @returns Promise containing the tool's information (name, description, schema).
|
|
2289
2153
|
*/
|
|
2290
|
-
details(
|
|
2291
|
-
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}${
|
|
2154
|
+
details(requestContext) {
|
|
2155
|
+
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}${requestContextQueryString(requestContext)}`);
|
|
2292
2156
|
}
|
|
2293
2157
|
/**
|
|
2294
2158
|
* Executes this specific tool on the MCP server.
|
|
2295
|
-
* @param params - Parameters for tool execution, including data/args and optional
|
|
2159
|
+
* @param params - Parameters for tool execution, including data/args and optional requestContext.
|
|
2296
2160
|
* @returns Promise containing the result of the tool execution.
|
|
2297
2161
|
*/
|
|
2298
2162
|
execute(params) {
|
|
2299
2163
|
const body = {};
|
|
2300
2164
|
if (params.data !== void 0) body.data = params.data;
|
|
2301
|
-
if (params.
|
|
2302
|
-
body.
|
|
2165
|
+
if (params.requestContext !== void 0) {
|
|
2166
|
+
body.requestContext = params.requestContext;
|
|
2303
2167
|
}
|
|
2304
2168
|
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}/execute`, {
|
|
2305
2169
|
method: "POST",
|
|
@@ -2345,19 +2209,39 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2345
2209
|
}
|
|
2346
2210
|
}
|
|
2347
2211
|
/**
|
|
2348
|
-
*
|
|
2349
|
-
* @throws {Error} Always throws an error directing users to use createRunAsync()
|
|
2212
|
+
* Creates a transform stream that parses binary chunks into JSON records.
|
|
2350
2213
|
*/
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2214
|
+
createRecordParserTransform() {
|
|
2215
|
+
let failedChunk = void 0;
|
|
2216
|
+
return new TransformStream({
|
|
2217
|
+
start() {
|
|
2218
|
+
},
|
|
2219
|
+
async transform(chunk, controller) {
|
|
2220
|
+
try {
|
|
2221
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
2222
|
+
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
2223
|
+
for (const chunk2 of chunks) {
|
|
2224
|
+
if (chunk2) {
|
|
2225
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
2226
|
+
try {
|
|
2227
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
2228
|
+
controller.enqueue(parsedChunk);
|
|
2229
|
+
failedChunk = void 0;
|
|
2230
|
+
} catch {
|
|
2231
|
+
failedChunk = newChunk;
|
|
2232
|
+
}
|
|
2233
|
+
}
|
|
2234
|
+
}
|
|
2235
|
+
} catch {
|
|
2236
|
+
}
|
|
2237
|
+
}
|
|
2238
|
+
});
|
|
2355
2239
|
}
|
|
2356
2240
|
/**
|
|
2357
2241
|
* Creates a new agent builder action run and returns the runId.
|
|
2358
2242
|
* This calls `/api/agent-builder/:actionId/create-run`.
|
|
2359
2243
|
*/
|
|
2360
|
-
async
|
|
2244
|
+
async createRun(params) {
|
|
2361
2245
|
const searchParams = new URLSearchParams();
|
|
2362
2246
|
if (!!params?.runId) {
|
|
2363
2247
|
searchParams.set("runId", params.runId);
|
|
@@ -2376,12 +2260,12 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2376
2260
|
if (runId) {
|
|
2377
2261
|
searchParams.set("runId", runId);
|
|
2378
2262
|
}
|
|
2379
|
-
const
|
|
2380
|
-
const {
|
|
2263
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2264
|
+
const { requestContext: _, ...actionParams } = params;
|
|
2381
2265
|
const url = `/api/agent-builder/${this.actionId}/start-async${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
|
|
2382
2266
|
const result = await this.request(url, {
|
|
2383
2267
|
method: "POST",
|
|
2384
|
-
body: { ...actionParams,
|
|
2268
|
+
body: { ...actionParams, requestContext }
|
|
2385
2269
|
});
|
|
2386
2270
|
return this.transformWorkflowResult(result);
|
|
2387
2271
|
}
|
|
@@ -2392,12 +2276,12 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2392
2276
|
async startActionRun(params, runId) {
|
|
2393
2277
|
const searchParams = new URLSearchParams();
|
|
2394
2278
|
searchParams.set("runId", runId);
|
|
2395
|
-
const
|
|
2396
|
-
const {
|
|
2279
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2280
|
+
const { requestContext: _, ...actionParams } = params;
|
|
2397
2281
|
const url = `/api/agent-builder/${this.actionId}/start?${searchParams.toString()}`;
|
|
2398
2282
|
return this.request(url, {
|
|
2399
2283
|
method: "POST",
|
|
2400
|
-
body: { ...actionParams,
|
|
2284
|
+
body: { ...actionParams, requestContext }
|
|
2401
2285
|
});
|
|
2402
2286
|
}
|
|
2403
2287
|
/**
|
|
@@ -2407,12 +2291,12 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2407
2291
|
async resume(params, runId) {
|
|
2408
2292
|
const searchParams = new URLSearchParams();
|
|
2409
2293
|
searchParams.set("runId", runId);
|
|
2410
|
-
const
|
|
2411
|
-
const {
|
|
2294
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2295
|
+
const { requestContext: _, ...resumeParams } = params;
|
|
2412
2296
|
const url = `/api/agent-builder/${this.actionId}/resume?${searchParams.toString()}`;
|
|
2413
2297
|
return this.request(url, {
|
|
2414
2298
|
method: "POST",
|
|
2415
|
-
body: { ...resumeParams,
|
|
2299
|
+
body: { ...resumeParams, requestContext }
|
|
2416
2300
|
});
|
|
2417
2301
|
}
|
|
2418
2302
|
/**
|
|
@@ -2422,12 +2306,12 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2422
2306
|
async resumeAsync(params, runId) {
|
|
2423
2307
|
const searchParams = new URLSearchParams();
|
|
2424
2308
|
searchParams.set("runId", runId);
|
|
2425
|
-
const
|
|
2426
|
-
const {
|
|
2309
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2310
|
+
const { requestContext: _, ...resumeParams } = params;
|
|
2427
2311
|
const url = `/api/agent-builder/${this.actionId}/resume-async?${searchParams.toString()}`;
|
|
2428
2312
|
const result = await this.request(url, {
|
|
2429
2313
|
method: "POST",
|
|
2430
|
-
body: { ...resumeParams,
|
|
2314
|
+
body: { ...resumeParams, requestContext }
|
|
2431
2315
|
});
|
|
2432
2316
|
return this.transformWorkflowResult(result);
|
|
2433
2317
|
}
|
|
@@ -2485,12 +2369,12 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2485
2369
|
if (runId) {
|
|
2486
2370
|
searchParams.set("runId", runId);
|
|
2487
2371
|
}
|
|
2488
|
-
const
|
|
2489
|
-
const {
|
|
2372
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2373
|
+
const { requestContext: _, ...actionParams } = params;
|
|
2490
2374
|
const url = `/api/agent-builder/${this.actionId}/stream${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
|
|
2491
2375
|
const response = await this.request(url, {
|
|
2492
2376
|
method: "POST",
|
|
2493
|
-
body: { ...actionParams,
|
|
2377
|
+
body: { ...actionParams, requestContext },
|
|
2494
2378
|
stream: true
|
|
2495
2379
|
});
|
|
2496
2380
|
if (!response.ok) {
|
|
@@ -2499,31 +2383,7 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2499
2383
|
if (!response.body) {
|
|
2500
2384
|
throw new Error("Response body is null");
|
|
2501
2385
|
}
|
|
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);
|
|
2386
|
+
return response.body.pipeThrough(this.createRecordParserTransform());
|
|
2527
2387
|
}
|
|
2528
2388
|
/**
|
|
2529
2389
|
* Streams agent builder action progress in real-time using VNext streaming.
|
|
@@ -2534,12 +2394,12 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2534
2394
|
if (runId) {
|
|
2535
2395
|
searchParams.set("runId", runId);
|
|
2536
2396
|
}
|
|
2537
|
-
const
|
|
2538
|
-
const {
|
|
2397
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2398
|
+
const { requestContext: _, ...actionParams } = params;
|
|
2539
2399
|
const url = `/api/agent-builder/${this.actionId}/streamVNext${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
|
|
2540
2400
|
const response = await this.request(url, {
|
|
2541
2401
|
method: "POST",
|
|
2542
|
-
body: { ...actionParams,
|
|
2402
|
+
body: { ...actionParams, requestContext },
|
|
2543
2403
|
stream: true
|
|
2544
2404
|
});
|
|
2545
2405
|
if (!response.ok) {
|
|
@@ -2548,57 +2408,94 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2548
2408
|
if (!response.body) {
|
|
2549
2409
|
throw new Error("Response body is null");
|
|
2550
2410
|
}
|
|
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
|
-
}
|
|
2411
|
+
return response.body.pipeThrough(this.createRecordParserTransform());
|
|
2412
|
+
}
|
|
2413
|
+
/**
|
|
2414
|
+
* Observes an existing agent builder action run stream.
|
|
2415
|
+
* Replays cached execution from the beginning, then continues with live stream.
|
|
2416
|
+
* This is the recommended method for recovery after page refresh/hot reload.
|
|
2417
|
+
* This calls `/api/agent-builder/:actionId/observe` (which delegates to observeStreamVNext).
|
|
2418
|
+
*/
|
|
2419
|
+
async observeStream(params) {
|
|
2420
|
+
const searchParams = new URLSearchParams();
|
|
2421
|
+
searchParams.set("runId", params.runId);
|
|
2422
|
+
const url = `/api/agent-builder/${this.actionId}/observe?${searchParams.toString()}`;
|
|
2423
|
+
const response = await this.request(url, {
|
|
2424
|
+
method: "POST",
|
|
2425
|
+
stream: true
|
|
2574
2426
|
});
|
|
2575
|
-
|
|
2427
|
+
if (!response.ok) {
|
|
2428
|
+
throw new Error(`Failed to observe agent builder action stream: ${response.statusText}`);
|
|
2429
|
+
}
|
|
2430
|
+
if (!response.body) {
|
|
2431
|
+
throw new Error("Response body is null");
|
|
2432
|
+
}
|
|
2433
|
+
return response.body.pipeThrough(this.createRecordParserTransform());
|
|
2576
2434
|
}
|
|
2577
2435
|
/**
|
|
2578
|
-
*
|
|
2579
|
-
*
|
|
2580
|
-
*
|
|
2581
|
-
* This calls `/api/agent-builder/:actionId/watch`.
|
|
2436
|
+
* Observes an existing agent builder action run stream using VNext streaming API.
|
|
2437
|
+
* Replays cached execution from the beginning, then continues with live stream.
|
|
2438
|
+
* This calls `/api/agent-builder/:actionId/observe-streamVNext`.
|
|
2582
2439
|
*/
|
|
2583
|
-
async
|
|
2584
|
-
const
|
|
2440
|
+
async observeStreamVNext(params) {
|
|
2441
|
+
const searchParams = new URLSearchParams();
|
|
2442
|
+
searchParams.set("runId", params.runId);
|
|
2443
|
+
const url = `/api/agent-builder/${this.actionId}/observe-streamVNext?${searchParams.toString()}`;
|
|
2585
2444
|
const response = await this.request(url, {
|
|
2586
|
-
method: "
|
|
2445
|
+
method: "POST",
|
|
2587
2446
|
stream: true
|
|
2588
2447
|
});
|
|
2589
2448
|
if (!response.ok) {
|
|
2590
|
-
throw new Error(`Failed to
|
|
2449
|
+
throw new Error(`Failed to observe agent builder action stream VNext: ${response.statusText}`);
|
|
2591
2450
|
}
|
|
2592
2451
|
if (!response.body) {
|
|
2593
2452
|
throw new Error("Response body is null");
|
|
2594
2453
|
}
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2454
|
+
return response.body.pipeThrough(this.createRecordParserTransform());
|
|
2455
|
+
}
|
|
2456
|
+
/**
|
|
2457
|
+
* Observes an existing agent builder action run stream using legacy streaming API.
|
|
2458
|
+
* Replays cached execution from the beginning, then continues with live stream.
|
|
2459
|
+
* This calls `/api/agent-builder/:actionId/observe-stream-legacy`.
|
|
2460
|
+
*/
|
|
2461
|
+
async observeStreamLegacy(params) {
|
|
2462
|
+
const searchParams = new URLSearchParams();
|
|
2463
|
+
searchParams.set("runId", params.runId);
|
|
2464
|
+
const url = `/api/agent-builder/${this.actionId}/observe-stream-legacy?${searchParams.toString()}`;
|
|
2465
|
+
const response = await this.request(url, {
|
|
2466
|
+
method: "POST",
|
|
2467
|
+
stream: true
|
|
2468
|
+
});
|
|
2469
|
+
if (!response.ok) {
|
|
2470
|
+
throw new Error(`Failed to observe agent builder action stream legacy: ${response.statusText}`);
|
|
2471
|
+
}
|
|
2472
|
+
if (!response.body) {
|
|
2473
|
+
throw new Error("Response body is null");
|
|
2601
2474
|
}
|
|
2475
|
+
return response.body.pipeThrough(this.createRecordParserTransform());
|
|
2476
|
+
}
|
|
2477
|
+
/**
|
|
2478
|
+
* Resumes a suspended agent builder action and streams the results.
|
|
2479
|
+
* This calls `/api/agent-builder/:actionId/resume-stream`.
|
|
2480
|
+
*/
|
|
2481
|
+
async resumeStream(params) {
|
|
2482
|
+
const searchParams = new URLSearchParams();
|
|
2483
|
+
searchParams.set("runId", params.runId);
|
|
2484
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2485
|
+
const { runId: _, requestContext: __, ...resumeParams } = params;
|
|
2486
|
+
const url = `/api/agent-builder/${this.actionId}/resume-stream?${searchParams.toString()}`;
|
|
2487
|
+
const response = await this.request(url, {
|
|
2488
|
+
method: "POST",
|
|
2489
|
+
body: { ...resumeParams, requestContext },
|
|
2490
|
+
stream: true
|
|
2491
|
+
});
|
|
2492
|
+
if (!response.ok) {
|
|
2493
|
+
throw new Error(`Failed to resume agent builder action stream: ${response.statusText}`);
|
|
2494
|
+
}
|
|
2495
|
+
if (!response.body) {
|
|
2496
|
+
throw new Error("Response body is null");
|
|
2497
|
+
}
|
|
2498
|
+
return response.body.pipeThrough(this.createRecordParserTransform());
|
|
2602
2499
|
}
|
|
2603
2500
|
/**
|
|
2604
2501
|
* Gets a specific action run by its ID.
|
|
@@ -2630,11 +2527,11 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2630
2527
|
if (params?.toDate) {
|
|
2631
2528
|
searchParams.set("toDate", params.toDate.toISOString());
|
|
2632
2529
|
}
|
|
2633
|
-
if (params?.
|
|
2634
|
-
searchParams.set("
|
|
2530
|
+
if (params?.perPage !== void 0) {
|
|
2531
|
+
searchParams.set("perPage", String(params.perPage));
|
|
2635
2532
|
}
|
|
2636
|
-
if (params?.
|
|
2637
|
-
searchParams.set("
|
|
2533
|
+
if (params?.page !== void 0) {
|
|
2534
|
+
searchParams.set("page", String(params.page));
|
|
2638
2535
|
}
|
|
2639
2536
|
if (params?.resourceId) {
|
|
2640
2537
|
searchParams.set("resourceId", params.resourceId);
|
|
@@ -2664,17 +2561,6 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2664
2561
|
method: "POST"
|
|
2665
2562
|
});
|
|
2666
2563
|
}
|
|
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
2564
|
};
|
|
2679
2565
|
|
|
2680
2566
|
// src/resources/observability.ts
|
|
@@ -2683,15 +2569,15 @@ var Observability = class extends BaseResource {
|
|
|
2683
2569
|
super(options);
|
|
2684
2570
|
}
|
|
2685
2571
|
/**
|
|
2686
|
-
* Retrieves a specific
|
|
2572
|
+
* Retrieves a specific trace by ID
|
|
2687
2573
|
* @param traceId - ID of the trace to retrieve
|
|
2688
|
-
* @returns Promise containing the
|
|
2574
|
+
* @returns Promise containing the trace with all its spans
|
|
2689
2575
|
*/
|
|
2690
2576
|
getTrace(traceId) {
|
|
2691
2577
|
return this.request(`/api/observability/traces/${traceId}`);
|
|
2692
2578
|
}
|
|
2693
2579
|
/**
|
|
2694
|
-
* Retrieves paginated list of
|
|
2580
|
+
* Retrieves paginated list of traces with optional filtering
|
|
2695
2581
|
* @param params - Parameters for pagination and filtering
|
|
2696
2582
|
* @returns Promise containing paginated traces and pagination info
|
|
2697
2583
|
*/
|
|
@@ -2731,7 +2617,7 @@ var Observability = class extends BaseResource {
|
|
|
2731
2617
|
* @param params - Parameters containing trace ID, span ID, and pagination options
|
|
2732
2618
|
* @returns Promise containing scores and pagination info
|
|
2733
2619
|
*/
|
|
2734
|
-
|
|
2620
|
+
listScoresBySpan(params) {
|
|
2735
2621
|
const { traceId, spanId, page, perPage } = params;
|
|
2736
2622
|
const searchParams = new URLSearchParams();
|
|
2737
2623
|
if (page !== void 0) {
|
|
@@ -2753,69 +2639,6 @@ var Observability = class extends BaseResource {
|
|
|
2753
2639
|
}
|
|
2754
2640
|
};
|
|
2755
2641
|
|
|
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
2642
|
// src/client.ts
|
|
2820
2643
|
var MastraClient = class extends BaseResource {
|
|
2821
2644
|
observability;
|
|
@@ -2825,18 +2648,21 @@ var MastraClient = class extends BaseResource {
|
|
|
2825
2648
|
}
|
|
2826
2649
|
/**
|
|
2827
2650
|
* Retrieves all available agents
|
|
2828
|
-
* @param
|
|
2651
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
2829
2652
|
* @returns Promise containing map of agent IDs to agent details
|
|
2830
2653
|
*/
|
|
2831
|
-
|
|
2832
|
-
const
|
|
2654
|
+
listAgents(requestContext) {
|
|
2655
|
+
const requestContextParam = base64RequestContext(parseClientRequestContext(requestContext));
|
|
2833
2656
|
const searchParams = new URLSearchParams();
|
|
2834
|
-
if (
|
|
2835
|
-
searchParams.set("
|
|
2657
|
+
if (requestContextParam) {
|
|
2658
|
+
searchParams.set("requestContext", requestContextParam);
|
|
2836
2659
|
}
|
|
2837
2660
|
const queryString = searchParams.toString();
|
|
2838
2661
|
return this.request(`/api/agents${queryString ? `?${queryString}` : ""}`);
|
|
2839
2662
|
}
|
|
2663
|
+
listAgentsModelProviders() {
|
|
2664
|
+
return this.request(`/api/agents/providers`);
|
|
2665
|
+
}
|
|
2840
2666
|
/**
|
|
2841
2667
|
* Gets an agent instance by ID
|
|
2842
2668
|
* @param agentId - ID of the agent to retrieve
|
|
@@ -2846,33 +2672,50 @@ var MastraClient = class extends BaseResource {
|
|
|
2846
2672
|
return new Agent(this.options, agentId);
|
|
2847
2673
|
}
|
|
2848
2674
|
/**
|
|
2849
|
-
*
|
|
2850
|
-
* @param params - Parameters containing
|
|
2851
|
-
* @returns Promise containing array of memory threads
|
|
2675
|
+
* Lists memory threads for a resource with pagination support
|
|
2676
|
+
* @param params - Parameters containing resource ID, pagination options, and optional request context
|
|
2677
|
+
* @returns Promise containing paginated array of memory threads with metadata
|
|
2852
2678
|
*/
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2679
|
+
async listMemoryThreads(params) {
|
|
2680
|
+
const queryParams = new URLSearchParams({
|
|
2681
|
+
resourceId: params.resourceId,
|
|
2682
|
+
resourceid: params.resourceId,
|
|
2683
|
+
agentId: params.agentId,
|
|
2684
|
+
...params.page !== void 0 && { page: params.page.toString() },
|
|
2685
|
+
...params.perPage !== void 0 && { perPage: params.perPage.toString() },
|
|
2686
|
+
...params.orderBy && { orderBy: params.orderBy },
|
|
2687
|
+
...params.sortDirection && { sortDirection: params.sortDirection }
|
|
2688
|
+
});
|
|
2689
|
+
const response = await this.request(
|
|
2690
|
+
`/api/memory/threads?${queryParams.toString()}${requestContextQueryString(params.requestContext, "&")}`
|
|
2856
2691
|
);
|
|
2692
|
+
const actualResponse = "threads" in response ? response : {
|
|
2693
|
+
threads: response,
|
|
2694
|
+
total: response.length,
|
|
2695
|
+
page: params.page ?? 0,
|
|
2696
|
+
perPage: params.perPage ?? 100,
|
|
2697
|
+
hasMore: false
|
|
2698
|
+
};
|
|
2699
|
+
return actualResponse;
|
|
2857
2700
|
}
|
|
2858
2701
|
/**
|
|
2859
2702
|
* Retrieves memory config for a resource
|
|
2860
|
-
* @param params - Parameters containing the resource ID and optional
|
|
2703
|
+
* @param params - Parameters containing the resource ID and optional request context
|
|
2861
2704
|
* @returns Promise containing memory configuration
|
|
2862
2705
|
*/
|
|
2863
2706
|
getMemoryConfig(params) {
|
|
2864
2707
|
return this.request(
|
|
2865
|
-
`/api/memory/config?agentId=${params.agentId}${
|
|
2708
|
+
`/api/memory/config?agentId=${params.agentId}${requestContextQueryString(params.requestContext, "&")}`
|
|
2866
2709
|
);
|
|
2867
2710
|
}
|
|
2868
2711
|
/**
|
|
2869
2712
|
* Creates a new memory thread
|
|
2870
|
-
* @param params - Parameters for creating the memory thread including optional
|
|
2713
|
+
* @param params - Parameters for creating the memory thread including optional request context
|
|
2871
2714
|
* @returns Promise containing the created memory thread
|
|
2872
2715
|
*/
|
|
2873
2716
|
createMemoryThread(params) {
|
|
2874
2717
|
return this.request(
|
|
2875
|
-
`/api/memory/threads?agentId=${params.agentId}${
|
|
2718
|
+
`/api/memory/threads?agentId=${params.agentId}${requestContextQueryString(params.requestContext, "&")}`,
|
|
2876
2719
|
{ method: "POST", body: params }
|
|
2877
2720
|
);
|
|
2878
2721
|
}
|
|
@@ -2881,35 +2724,38 @@ var MastraClient = class extends BaseResource {
|
|
|
2881
2724
|
* @param threadId - ID of the memory thread to retrieve
|
|
2882
2725
|
* @returns MemoryThread instance
|
|
2883
2726
|
*/
|
|
2884
|
-
getMemoryThread(threadId, agentId) {
|
|
2727
|
+
getMemoryThread({ threadId, agentId }) {
|
|
2885
2728
|
return new MemoryThread(this.options, threadId, agentId);
|
|
2886
2729
|
}
|
|
2887
|
-
|
|
2730
|
+
listThreadMessages(threadId, opts = {}) {
|
|
2731
|
+
if (!opts.agentId && !opts.networkId) {
|
|
2732
|
+
throw new Error("Either agentId or networkId must be provided");
|
|
2733
|
+
}
|
|
2888
2734
|
let url = "";
|
|
2889
2735
|
if (opts.agentId) {
|
|
2890
|
-
url = `/api/memory/threads/${threadId}/messages?agentId=${opts.agentId}${
|
|
2736
|
+
url = `/api/memory/threads/${threadId}/messages?agentId=${opts.agentId}${requestContextQueryString(opts.requestContext, "&")}`;
|
|
2891
2737
|
} else if (opts.networkId) {
|
|
2892
|
-
url = `/api/memory/network/threads/${threadId}/messages?networkId=${opts.networkId}${
|
|
2738
|
+
url = `/api/memory/network/threads/${threadId}/messages?networkId=${opts.networkId}${requestContextQueryString(opts.requestContext, "&")}`;
|
|
2893
2739
|
}
|
|
2894
2740
|
return this.request(url);
|
|
2895
2741
|
}
|
|
2896
2742
|
deleteThread(threadId, opts = {}) {
|
|
2897
2743
|
let url = "";
|
|
2898
2744
|
if (opts.agentId) {
|
|
2899
|
-
url = `/api/memory/threads/${threadId}?agentId=${opts.agentId}${
|
|
2745
|
+
url = `/api/memory/threads/${threadId}?agentId=${opts.agentId}${requestContextQueryString(opts.requestContext, "&")}`;
|
|
2900
2746
|
} else if (opts.networkId) {
|
|
2901
|
-
url = `/api/memory/network/threads/${threadId}?networkId=${opts.networkId}${
|
|
2747
|
+
url = `/api/memory/network/threads/${threadId}?networkId=${opts.networkId}${requestContextQueryString(opts.requestContext, "&")}`;
|
|
2902
2748
|
}
|
|
2903
2749
|
return this.request(url, { method: "DELETE" });
|
|
2904
2750
|
}
|
|
2905
2751
|
/**
|
|
2906
2752
|
* Saves messages to memory
|
|
2907
|
-
* @param params - Parameters containing messages to save and optional
|
|
2753
|
+
* @param params - Parameters containing messages to save and optional request context
|
|
2908
2754
|
* @returns Promise containing the saved messages
|
|
2909
2755
|
*/
|
|
2910
2756
|
saveMessageToMemory(params) {
|
|
2911
2757
|
return this.request(
|
|
2912
|
-
`/api/memory/save-messages?agentId=${params.agentId}${
|
|
2758
|
+
`/api/memory/save-messages?agentId=${params.agentId}${requestContextQueryString(params.requestContext, "&")}`,
|
|
2913
2759
|
{
|
|
2914
2760
|
method: "POST",
|
|
2915
2761
|
body: params
|
|
@@ -2919,64 +2765,22 @@ var MastraClient = class extends BaseResource {
|
|
|
2919
2765
|
/**
|
|
2920
2766
|
* Gets the status of the memory system
|
|
2921
2767
|
* @param agentId - The agent ID
|
|
2922
|
-
* @param
|
|
2923
|
-
* @returns Promise containing memory system status
|
|
2924
|
-
*/
|
|
2925
|
-
getMemoryStatus(agentId, runtimeContext) {
|
|
2926
|
-
return this.request(`/api/memory/status?agentId=${agentId}${runtimeContextQueryString(runtimeContext, "&")}`);
|
|
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
|
|
2768
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
2965
2769
|
* @returns Promise containing memory system status
|
|
2966
2770
|
*/
|
|
2967
|
-
|
|
2968
|
-
return this.request(`/api/memory/
|
|
2771
|
+
getMemoryStatus(agentId, requestContext) {
|
|
2772
|
+
return this.request(`/api/memory/status?agentId=${agentId}${requestContextQueryString(requestContext, "&")}`);
|
|
2969
2773
|
}
|
|
2970
2774
|
/**
|
|
2971
2775
|
* Retrieves all available tools
|
|
2972
|
-
* @param
|
|
2776
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
2973
2777
|
* @returns Promise containing map of tool IDs to tool details
|
|
2974
2778
|
*/
|
|
2975
|
-
|
|
2976
|
-
const
|
|
2779
|
+
listTools(requestContext) {
|
|
2780
|
+
const requestContextParam = base64RequestContext(parseClientRequestContext(requestContext));
|
|
2977
2781
|
const searchParams = new URLSearchParams();
|
|
2978
|
-
if (
|
|
2979
|
-
searchParams.set("
|
|
2782
|
+
if (requestContextParam) {
|
|
2783
|
+
searchParams.set("requestContext", requestContextParam);
|
|
2980
2784
|
}
|
|
2981
2785
|
const queryString = searchParams.toString();
|
|
2982
2786
|
return this.request(`/api/tools${queryString ? `?${queryString}` : ""}`);
|
|
@@ -2991,14 +2795,14 @@ var MastraClient = class extends BaseResource {
|
|
|
2991
2795
|
}
|
|
2992
2796
|
/**
|
|
2993
2797
|
* Retrieves all available workflows
|
|
2994
|
-
* @param
|
|
2798
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
2995
2799
|
* @returns Promise containing map of workflow IDs to workflow details
|
|
2996
2800
|
*/
|
|
2997
|
-
|
|
2998
|
-
const
|
|
2801
|
+
listWorkflows(requestContext) {
|
|
2802
|
+
const requestContextParam = base64RequestContext(parseClientRequestContext(requestContext));
|
|
2999
2803
|
const searchParams = new URLSearchParams();
|
|
3000
|
-
if (
|
|
3001
|
-
searchParams.set("
|
|
2804
|
+
if (requestContextParam) {
|
|
2805
|
+
searchParams.set("requestContext", requestContextParam);
|
|
3002
2806
|
}
|
|
3003
2807
|
const queryString = searchParams.toString();
|
|
3004
2808
|
return this.request(`/api/workflows${queryString ? `?${queryString}` : ""}`);
|
|
@@ -3038,7 +2842,7 @@ var MastraClient = class extends BaseResource {
|
|
|
3038
2842
|
* @param params - Parameters for filtering logs
|
|
3039
2843
|
* @returns Promise containing array of log messages
|
|
3040
2844
|
*/
|
|
3041
|
-
|
|
2845
|
+
listLogs(params) {
|
|
3042
2846
|
const { transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
|
|
3043
2847
|
const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
|
|
3044
2848
|
const searchParams = new URLSearchParams();
|
|
@@ -3124,63 +2928,21 @@ var MastraClient = class extends BaseResource {
|
|
|
3124
2928
|
* List of all log transports
|
|
3125
2929
|
* @returns Promise containing list of log transports
|
|
3126
2930
|
*/
|
|
3127
|
-
|
|
2931
|
+
listLogTransports() {
|
|
3128
2932
|
return this.request("/api/logs/transports");
|
|
3129
2933
|
}
|
|
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
2934
|
/**
|
|
3173
2935
|
* Retrieves a list of available MCP servers.
|
|
3174
|
-
* @param params - Optional parameters for pagination (
|
|
2936
|
+
* @param params - Optional parameters for pagination (perPage, page).
|
|
3175
2937
|
* @returns Promise containing the list of MCP servers and pagination info.
|
|
3176
2938
|
*/
|
|
3177
2939
|
getMcpServers(params) {
|
|
3178
2940
|
const searchParams = new URLSearchParams();
|
|
3179
|
-
if (params?.
|
|
3180
|
-
searchParams.set("
|
|
2941
|
+
if (params?.perPage !== void 0) {
|
|
2942
|
+
searchParams.set("perPage", String(params.perPage));
|
|
3181
2943
|
}
|
|
3182
|
-
if (params?.
|
|
3183
|
-
searchParams.set("
|
|
2944
|
+
if (params?.page !== void 0) {
|
|
2945
|
+
searchParams.set("page", String(params.page));
|
|
3184
2946
|
}
|
|
3185
2947
|
const queryString = searchParams.toString();
|
|
3186
2948
|
return this.request(`/api/mcp/v0/servers${queryString ? `?${queryString}` : ""}`);
|
|
@@ -3236,12 +2998,33 @@ var MastraClient = class extends BaseResource {
|
|
|
3236
2998
|
agentId,
|
|
3237
2999
|
threadId,
|
|
3238
3000
|
resourceId,
|
|
3239
|
-
|
|
3001
|
+
requestContext
|
|
3240
3002
|
}) {
|
|
3241
3003
|
return this.request(
|
|
3242
|
-
`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}${
|
|
3004
|
+
`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}${requestContextQueryString(requestContext, "&")}`
|
|
3243
3005
|
);
|
|
3244
3006
|
}
|
|
3007
|
+
searchMemory({
|
|
3008
|
+
agentId,
|
|
3009
|
+
resourceId,
|
|
3010
|
+
threadId,
|
|
3011
|
+
searchQuery,
|
|
3012
|
+
memoryConfig,
|
|
3013
|
+
requestContext
|
|
3014
|
+
}) {
|
|
3015
|
+
const params = new URLSearchParams({
|
|
3016
|
+
searchQuery,
|
|
3017
|
+
resourceId,
|
|
3018
|
+
agentId
|
|
3019
|
+
});
|
|
3020
|
+
if (threadId) {
|
|
3021
|
+
params.append("threadId", threadId);
|
|
3022
|
+
}
|
|
3023
|
+
if (memoryConfig) {
|
|
3024
|
+
params.append("memoryConfig", JSON.stringify(memoryConfig));
|
|
3025
|
+
}
|
|
3026
|
+
return this.request(`/api/memory/search?${params}${requestContextQueryString(requestContext, "&")}`);
|
|
3027
|
+
}
|
|
3245
3028
|
/**
|
|
3246
3029
|
* Updates the working memory for a specific thread (optionally resource-scoped).
|
|
3247
3030
|
* @param agentId - ID of the agent.
|
|
@@ -3254,10 +3037,10 @@ var MastraClient = class extends BaseResource {
|
|
|
3254
3037
|
threadId,
|
|
3255
3038
|
workingMemory,
|
|
3256
3039
|
resourceId,
|
|
3257
|
-
|
|
3040
|
+
requestContext
|
|
3258
3041
|
}) {
|
|
3259
3042
|
return this.request(
|
|
3260
|
-
`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}${
|
|
3043
|
+
`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}${requestContextQueryString(requestContext, "&")}`,
|
|
3261
3044
|
{
|
|
3262
3045
|
method: "POST",
|
|
3263
3046
|
body: {
|
|
@@ -3271,7 +3054,7 @@ var MastraClient = class extends BaseResource {
|
|
|
3271
3054
|
* Retrieves all available scorers
|
|
3272
3055
|
* @returns Promise containing list of available scorers
|
|
3273
3056
|
*/
|
|
3274
|
-
|
|
3057
|
+
listScorers() {
|
|
3275
3058
|
return this.request("/api/scores/scorers");
|
|
3276
3059
|
}
|
|
3277
3060
|
/**
|
|
@@ -3282,7 +3065,7 @@ var MastraClient = class extends BaseResource {
|
|
|
3282
3065
|
getScorer(scorerId) {
|
|
3283
3066
|
return this.request(`/api/scores/scorers/${encodeURIComponent(scorerId)}`);
|
|
3284
3067
|
}
|
|
3285
|
-
|
|
3068
|
+
listScoresByScorerId(params) {
|
|
3286
3069
|
const { page, perPage, scorerId, entityId, entityType } = params;
|
|
3287
3070
|
const searchParams = new URLSearchParams();
|
|
3288
3071
|
if (entityId) {
|
|
@@ -3305,7 +3088,7 @@ var MastraClient = class extends BaseResource {
|
|
|
3305
3088
|
* @param params - Parameters containing run ID and pagination options
|
|
3306
3089
|
* @returns Promise containing scores and pagination info
|
|
3307
3090
|
*/
|
|
3308
|
-
|
|
3091
|
+
listScoresByRunId(params) {
|
|
3309
3092
|
const { runId, page, perPage } = params;
|
|
3310
3093
|
const searchParams = new URLSearchParams();
|
|
3311
3094
|
if (page !== void 0) {
|
|
@@ -3322,7 +3105,7 @@ var MastraClient = class extends BaseResource {
|
|
|
3322
3105
|
* @param params - Parameters containing entity ID, type, and pagination options
|
|
3323
3106
|
* @returns Promise containing scores and pagination info
|
|
3324
3107
|
*/
|
|
3325
|
-
|
|
3108
|
+
listScoresByEntityId(params) {
|
|
3326
3109
|
const { entityId, entityType, page, perPage } = params;
|
|
3327
3110
|
const searchParams = new URLSearchParams();
|
|
3328
3111
|
if (page !== void 0) {
|
|
@@ -3347,14 +3130,14 @@ var MastraClient = class extends BaseResource {
|
|
|
3347
3130
|
body: params
|
|
3348
3131
|
});
|
|
3349
3132
|
}
|
|
3350
|
-
|
|
3133
|
+
getTrace(traceId) {
|
|
3351
3134
|
return this.observability.getTrace(traceId);
|
|
3352
3135
|
}
|
|
3353
|
-
|
|
3136
|
+
getTraces(params) {
|
|
3354
3137
|
return this.observability.getTraces(params);
|
|
3355
3138
|
}
|
|
3356
|
-
|
|
3357
|
-
return this.observability.
|
|
3139
|
+
listScoresBySpan(params) {
|
|
3140
|
+
return this.observability.listScoresBySpan(params);
|
|
3358
3141
|
}
|
|
3359
3142
|
score(params) {
|
|
3360
3143
|
return this.observability.score(params);
|