@mastra/client-js 0.16.9 → 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 +273 -55
- 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.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
|
}
|
|
@@ -197,10 +197,9 @@ var BaseResource = class {
|
|
|
197
197
|
async function executeToolCallAndRespond({
|
|
198
198
|
response,
|
|
199
199
|
params,
|
|
200
|
-
runId,
|
|
201
200
|
resourceId,
|
|
202
201
|
threadId,
|
|
203
|
-
|
|
202
|
+
requestContext,
|
|
204
203
|
respondFn
|
|
205
204
|
}) {
|
|
206
205
|
if (response.finishReason === "tool-calls") {
|
|
@@ -211,22 +210,18 @@ async function executeToolCallAndRespond({
|
|
|
211
210
|
for (const toolCall of toolCalls) {
|
|
212
211
|
const clientTool = params.clientTools?.[toolCall.toolName];
|
|
213
212
|
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
|
-
{
|
|
213
|
+
const result = await clientTool.execute(toolCall?.args, {
|
|
214
|
+
requestContext,
|
|
215
|
+
tracingContext: { currentSpan: void 0 },
|
|
216
|
+
agent: {
|
|
226
217
|
messages: response.messages,
|
|
227
|
-
toolCallId: toolCall?.toolCallId
|
|
218
|
+
toolCallId: toolCall?.toolCallId,
|
|
219
|
+
suspend: async () => {
|
|
220
|
+
},
|
|
221
|
+
threadId,
|
|
222
|
+
resourceId
|
|
228
223
|
}
|
|
229
|
-
);
|
|
224
|
+
});
|
|
230
225
|
const updatedMessages = [
|
|
231
226
|
...response.response.messages || [],
|
|
232
227
|
{
|
|
@@ -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();
|
|
@@ -1037,23 +1032,19 @@ var Agent = class extends BaseResource {
|
|
|
1037
1032
|
const clientTool = processedParams.clientTools?.[toolCall2.toolName];
|
|
1038
1033
|
if (clientTool && clientTool.execute) {
|
|
1039
1034
|
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
|
-
{
|
|
1035
|
+
const result = await clientTool.execute(toolCall2?.args, {
|
|
1036
|
+
requestContext: processedParams.requestContext,
|
|
1037
|
+
// TODO: Pass proper tracing context when client-js supports tracing
|
|
1038
|
+
tracingContext: { currentSpan: void 0 },
|
|
1039
|
+
agent: {
|
|
1053
1040
|
messages: response.messages,
|
|
1054
|
-
toolCallId: toolCall2?.toolCallId
|
|
1041
|
+
toolCallId: toolCall2?.toolCallId,
|
|
1042
|
+
suspend: async () => {
|
|
1043
|
+
},
|
|
1044
|
+
threadId: processedParams.threadId,
|
|
1045
|
+
resourceId: processedParams.resourceId
|
|
1055
1046
|
}
|
|
1056
|
-
);
|
|
1047
|
+
});
|
|
1057
1048
|
const lastMessageRaw = messages[messages.length - 1];
|
|
1058
1049
|
const lastMessage = lastMessageRaw != null ? JSON.parse(JSON.stringify(lastMessageRaw)) : void 0;
|
|
1059
1050
|
const toolInvocationPart = lastMessage?.parts?.find(
|
|
@@ -1141,8 +1132,7 @@ var Agent = class extends BaseResource {
|
|
|
1141
1132
|
}
|
|
1142
1133
|
const processedParams = {
|
|
1143
1134
|
...params,
|
|
1144
|
-
|
|
1145
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
1135
|
+
requestContext: parseClientRequestContext(params.requestContext),
|
|
1146
1136
|
clientTools: processClientTools(params.clientTools),
|
|
1147
1137
|
structuredOutput: params.structuredOutput ? {
|
|
1148
1138
|
...params.structuredOutput,
|
|
@@ -1242,23 +1232,19 @@ var Agent = class extends BaseResource {
|
|
|
1242
1232
|
for (const toolCall2 of toolCalls) {
|
|
1243
1233
|
const clientTool = processedParams.clientTools?.[toolCall2.toolName];
|
|
1244
1234
|
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
|
-
{
|
|
1235
|
+
const result = await clientTool.execute(toolCall2?.args, {
|
|
1236
|
+
requestContext: processedParams.requestContext,
|
|
1237
|
+
// TODO: Pass proper tracing context when client-js supports tracing
|
|
1238
|
+
tracingContext: { currentSpan: void 0 },
|
|
1239
|
+
agent: {
|
|
1258
1240
|
messages: response.messages,
|
|
1259
|
-
toolCallId: toolCall2?.toolCallId
|
|
1241
|
+
toolCallId: toolCall2?.toolCallId,
|
|
1242
|
+
suspend: async () => {
|
|
1243
|
+
},
|
|
1244
|
+
threadId: processedParams.threadId,
|
|
1245
|
+
resourceId: processedParams.resourceId
|
|
1260
1246
|
}
|
|
1261
|
-
);
|
|
1247
|
+
});
|
|
1262
1248
|
const lastMessage = JSON.parse(JSON.stringify(messages[messages.length - 1]));
|
|
1263
1249
|
const toolInvocationPart = lastMessage?.parts?.find(
|
|
1264
1250
|
(part) => part.type === "tool-invocation" && part.toolInvocation?.toolCallId === toolCall2.toolCallId
|
|
@@ -1319,11 +1305,11 @@ var Agent = class extends BaseResource {
|
|
|
1319
1305
|
/**
|
|
1320
1306
|
* Gets details about a specific tool available to the agent
|
|
1321
1307
|
* @param toolId - ID of the tool to retrieve
|
|
1322
|
-
* @param
|
|
1308
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1323
1309
|
* @returns Promise containing tool details
|
|
1324
1310
|
*/
|
|
1325
|
-
getTool(toolId,
|
|
1326
|
-
return this.request(`/api/agents/${this.agentId}/tools/${toolId}${
|
|
1311
|
+
getTool(toolId, requestContext) {
|
|
1312
|
+
return this.request(`/api/agents/${this.agentId}/tools/${toolId}${requestContextQueryString(requestContext)}`);
|
|
1327
1313
|
}
|
|
1328
1314
|
/**
|
|
1329
1315
|
* Executes a tool for the agent
|
|
@@ -1334,29 +1320,13 @@ var Agent = class extends BaseResource {
|
|
|
1334
1320
|
executeTool(toolId, params) {
|
|
1335
1321
|
const body = {
|
|
1336
1322
|
data: params.data,
|
|
1337
|
-
|
|
1323
|
+
requestContext: parseClientRequestContext(params.requestContext)
|
|
1338
1324
|
};
|
|
1339
1325
|
return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
|
|
1340
1326
|
method: "POST",
|
|
1341
1327
|
body
|
|
1342
1328
|
});
|
|
1343
1329
|
}
|
|
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
1330
|
/**
|
|
1361
1331
|
* Updates the model for the agent
|
|
1362
1332
|
* @param params - Parameters for updating the model
|
|
@@ -1399,12 +1369,6 @@ var Agent = class extends BaseResource {
|
|
|
1399
1369
|
body: params
|
|
1400
1370
|
});
|
|
1401
1371
|
}
|
|
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
1372
|
};
|
|
1409
1373
|
|
|
1410
1374
|
// src/resources/memory-thread.ts
|
|
@@ -1416,22 +1380,22 @@ var MemoryThread = class extends BaseResource {
|
|
|
1416
1380
|
}
|
|
1417
1381
|
/**
|
|
1418
1382
|
* Retrieves the memory thread details
|
|
1419
|
-
* @param
|
|
1383
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1420
1384
|
* @returns Promise containing thread details including title and metadata
|
|
1421
1385
|
*/
|
|
1422
|
-
get(
|
|
1386
|
+
get(requestContext) {
|
|
1423
1387
|
return this.request(
|
|
1424
|
-
`/api/memory/threads/${this.threadId}?agentId=${this.agentId}${
|
|
1388
|
+
`/api/memory/threads/${this.threadId}?agentId=${this.agentId}${requestContextQueryString(requestContext, "&")}`
|
|
1425
1389
|
);
|
|
1426
1390
|
}
|
|
1427
1391
|
/**
|
|
1428
1392
|
* Updates the memory thread properties
|
|
1429
|
-
* @param params - Update parameters including title, metadata, and optional
|
|
1393
|
+
* @param params - Update parameters including title, metadata, and optional request context
|
|
1430
1394
|
* @returns Promise containing updated thread details
|
|
1431
1395
|
*/
|
|
1432
1396
|
update(params) {
|
|
1433
1397
|
return this.request(
|
|
1434
|
-
`/api/memory/threads/${this.threadId}?agentId=${this.agentId}${
|
|
1398
|
+
`/api/memory/threads/${this.threadId}?agentId=${this.agentId}${requestContextQueryString(params.requestContext, "&")}`,
|
|
1435
1399
|
{
|
|
1436
1400
|
method: "PATCH",
|
|
1437
1401
|
body: params
|
|
@@ -1440,62 +1404,49 @@ var MemoryThread = class extends BaseResource {
|
|
|
1440
1404
|
}
|
|
1441
1405
|
/**
|
|
1442
1406
|
* Deletes the memory thread
|
|
1443
|
-
* @param
|
|
1407
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1444
1408
|
* @returns Promise containing deletion result
|
|
1445
1409
|
*/
|
|
1446
|
-
delete(
|
|
1410
|
+
delete(requestContext) {
|
|
1447
1411
|
return this.request(
|
|
1448
|
-
`/api/memory/threads/${this.threadId}?agentId=${this.agentId}${
|
|
1412
|
+
`/api/memory/threads/${this.threadId}?agentId=${this.agentId}${requestContextQueryString(requestContext, "&")}`,
|
|
1449
1413
|
{
|
|
1450
1414
|
method: "DELETE"
|
|
1451
1415
|
}
|
|
1452
1416
|
);
|
|
1453
1417
|
}
|
|
1454
1418
|
/**
|
|
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
|
|
1419
|
+
* Retrieves paginated messages associated with the thread with filtering and ordering options
|
|
1420
|
+
* @param params - Pagination parameters including page, perPage, orderBy, filter, include options, and request context
|
|
1471
1421
|
* @returns Promise containing paginated thread messages with pagination metadata (total, page, perPage, hasMore)
|
|
1472
1422
|
*/
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
)
|
|
1423
|
+
listMessages(params = {}) {
|
|
1424
|
+
const { page, perPage, orderBy, filter, include, resourceId, requestContext } = params;
|
|
1425
|
+
const queryParams = {};
|
|
1426
|
+
if (resourceId) queryParams.resourceId = resourceId;
|
|
1427
|
+
if (page !== void 0) queryParams.page = String(page);
|
|
1428
|
+
if (perPage !== void 0) queryParams.perPage = String(perPage);
|
|
1429
|
+
if (orderBy) queryParams.orderBy = JSON.stringify(orderBy);
|
|
1430
|
+
if (filter) queryParams.filter = JSON.stringify(filter);
|
|
1431
|
+
if (include) queryParams.include = JSON.stringify(include);
|
|
1432
|
+
const query = new URLSearchParams(queryParams);
|
|
1433
|
+
const queryString = query.toString();
|
|
1434
|
+
const url = `/api/memory/threads/${this.threadId}/messages${queryString ? `?${queryString}` : ""}${requestContextQueryString(requestContext, queryString ? "&" : "?")}`;
|
|
1435
|
+
return this.request(url);
|
|
1485
1436
|
}
|
|
1486
1437
|
/**
|
|
1487
1438
|
* Deletes one or more messages from the thread
|
|
1488
1439
|
* @param messageIds - Can be a single message ID (string), array of message IDs,
|
|
1489
1440
|
* message object with id property, or array of message objects
|
|
1490
|
-
* @param
|
|
1441
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1491
1442
|
* @returns Promise containing deletion result
|
|
1492
1443
|
*/
|
|
1493
|
-
deleteMessages(messageIds,
|
|
1444
|
+
deleteMessages(messageIds, requestContext) {
|
|
1494
1445
|
const query = new URLSearchParams({
|
|
1495
1446
|
agentId: this.agentId
|
|
1496
1447
|
});
|
|
1497
1448
|
return this.request(
|
|
1498
|
-
`/api/memory/messages/delete?${query.toString()}${
|
|
1449
|
+
`/api/memory/messages/delete?${query.toString()}${requestContextQueryString(requestContext, "&")}`,
|
|
1499
1450
|
{
|
|
1500
1451
|
method: "POST",
|
|
1501
1452
|
body: { messageIds }
|
|
@@ -1513,12 +1464,12 @@ var Vector = class extends BaseResource {
|
|
|
1513
1464
|
/**
|
|
1514
1465
|
* Retrieves details about a specific vector index
|
|
1515
1466
|
* @param indexName - Name of the index to get details for
|
|
1516
|
-
* @param
|
|
1467
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1517
1468
|
* @returns Promise containing vector index details
|
|
1518
1469
|
*/
|
|
1519
|
-
details(indexName,
|
|
1470
|
+
details(indexName, requestContext) {
|
|
1520
1471
|
return this.request(
|
|
1521
|
-
`/api/vector/${this.vectorName}/indexes/${indexName}${
|
|
1472
|
+
`/api/vector/${this.vectorName}/indexes/${indexName}${requestContextQueryString(requestContext)}`
|
|
1522
1473
|
);
|
|
1523
1474
|
}
|
|
1524
1475
|
/**
|
|
@@ -1533,11 +1484,11 @@ var Vector = class extends BaseResource {
|
|
|
1533
1484
|
}
|
|
1534
1485
|
/**
|
|
1535
1486
|
* Retrieves a list of all available indexes
|
|
1536
|
-
* @param
|
|
1487
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1537
1488
|
* @returns Promise containing array of index names
|
|
1538
1489
|
*/
|
|
1539
|
-
getIndexes(
|
|
1540
|
-
return this.request(`/api/vector/${this.vectorName}/indexes${
|
|
1490
|
+
getIndexes(requestContext) {
|
|
1491
|
+
return this.request(`/api/vector/${this.vectorName}/indexes${requestContextQueryString(requestContext)}`);
|
|
1541
1492
|
}
|
|
1542
1493
|
/**
|
|
1543
1494
|
* Creates a new vector index
|
|
@@ -1582,11 +1533,11 @@ var Tool = class extends BaseResource {
|
|
|
1582
1533
|
}
|
|
1583
1534
|
/**
|
|
1584
1535
|
* Retrieves details about the tool
|
|
1585
|
-
* @param
|
|
1536
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1586
1537
|
* @returns Promise containing tool details including description and schemas
|
|
1587
1538
|
*/
|
|
1588
|
-
details(
|
|
1589
|
-
return this.request(`/api/tools/${this.toolId}${
|
|
1539
|
+
details(requestContext) {
|
|
1540
|
+
return this.request(`/api/tools/${this.toolId}${requestContextQueryString(requestContext)}`);
|
|
1590
1541
|
}
|
|
1591
1542
|
/**
|
|
1592
1543
|
* Executes the tool with the provided parameters
|
|
@@ -1600,7 +1551,7 @@ var Tool = class extends BaseResource {
|
|
|
1600
1551
|
}
|
|
1601
1552
|
const body = {
|
|
1602
1553
|
data: params.data,
|
|
1603
|
-
|
|
1554
|
+
requestContext: parseClientRequestContext(params.requestContext)
|
|
1604
1555
|
};
|
|
1605
1556
|
return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
|
|
1606
1557
|
method: "POST",
|
|
@@ -1616,67 +1567,22 @@ var Workflow = class extends BaseResource {
|
|
|
1616
1567
|
super(options);
|
|
1617
1568
|
this.workflowId = workflowId;
|
|
1618
1569
|
}
|
|
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
1570
|
/**
|
|
1665
1571
|
* Retrieves details about the workflow
|
|
1666
|
-
* @param
|
|
1572
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1667
1573
|
* @returns Promise containing workflow details including steps and graphs
|
|
1668
1574
|
*/
|
|
1669
|
-
details(
|
|
1670
|
-
return this.request(`/api/workflows/${this.workflowId}${
|
|
1575
|
+
details(requestContext) {
|
|
1576
|
+
return this.request(`/api/workflows/${this.workflowId}${requestContextQueryString(requestContext)}`);
|
|
1671
1577
|
}
|
|
1672
1578
|
/**
|
|
1673
1579
|
* Retrieves all runs for a workflow
|
|
1674
1580
|
* @param params - Parameters for filtering runs
|
|
1675
|
-
* @param
|
|
1581
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1676
1582
|
* @returns Promise containing workflow runs array
|
|
1677
1583
|
*/
|
|
1678
|
-
runs(params,
|
|
1679
|
-
const
|
|
1584
|
+
runs(params, requestContext) {
|
|
1585
|
+
const requestContextParam = base64RequestContext(parseClientRequestContext(requestContext));
|
|
1680
1586
|
const searchParams = new URLSearchParams();
|
|
1681
1587
|
if (params?.fromDate) {
|
|
1682
1588
|
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
@@ -1684,17 +1590,21 @@ var Workflow = class extends BaseResource {
|
|
|
1684
1590
|
if (params?.toDate) {
|
|
1685
1591
|
searchParams.set("toDate", params.toDate.toISOString());
|
|
1686
1592
|
}
|
|
1687
|
-
if (params?.
|
|
1688
|
-
|
|
1593
|
+
if (params?.perPage !== null && params?.perPage !== void 0) {
|
|
1594
|
+
if (params.perPage === false) {
|
|
1595
|
+
searchParams.set("perPage", "false");
|
|
1596
|
+
} else if (typeof params.perPage === "number" && params.perPage > 0 && Number.isInteger(params.perPage)) {
|
|
1597
|
+
searchParams.set("perPage", String(params.perPage));
|
|
1598
|
+
}
|
|
1689
1599
|
}
|
|
1690
|
-
if (params?.
|
|
1691
|
-
searchParams.set("
|
|
1600
|
+
if (params?.page !== null && params?.page !== void 0 && !isNaN(Number(params?.page))) {
|
|
1601
|
+
searchParams.set("page", String(params.page));
|
|
1692
1602
|
}
|
|
1693
1603
|
if (params?.resourceId) {
|
|
1694
1604
|
searchParams.set("resourceId", params.resourceId);
|
|
1695
1605
|
}
|
|
1696
|
-
if (
|
|
1697
|
-
searchParams.set("
|
|
1606
|
+
if (requestContextParam) {
|
|
1607
|
+
searchParams.set("requestContext", requestContextParam);
|
|
1698
1608
|
}
|
|
1699
1609
|
if (searchParams.size) {
|
|
1700
1610
|
return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
|
|
@@ -1705,21 +1615,21 @@ var Workflow = class extends BaseResource {
|
|
|
1705
1615
|
/**
|
|
1706
1616
|
* Retrieves a specific workflow run by its ID
|
|
1707
1617
|
* @param runId - The ID of the workflow run to retrieve
|
|
1708
|
-
* @param
|
|
1618
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1709
1619
|
* @returns Promise containing the workflow run details
|
|
1710
1620
|
*/
|
|
1711
|
-
runById(runId,
|
|
1712
|
-
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}${
|
|
1621
|
+
runById(runId, requestContext) {
|
|
1622
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}${requestContextQueryString(requestContext)}`);
|
|
1713
1623
|
}
|
|
1714
1624
|
/**
|
|
1715
1625
|
* Retrieves the execution result for a specific workflow run by its ID
|
|
1716
1626
|
* @param runId - The ID of the workflow run to retrieve the execution result for
|
|
1717
|
-
* @param
|
|
1627
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1718
1628
|
* @returns Promise containing the workflow run execution result
|
|
1719
1629
|
*/
|
|
1720
|
-
runExecutionResult(runId,
|
|
1630
|
+
runExecutionResult(runId, requestContext) {
|
|
1721
1631
|
return this.request(
|
|
1722
|
-
`/api/workflows/${this.workflowId}/runs/${runId}/execution-result${
|
|
1632
|
+
`/api/workflows/${this.workflowId}/runs/${runId}/execution-result${requestContextQueryString(requestContext)}`
|
|
1723
1633
|
);
|
|
1724
1634
|
}
|
|
1725
1635
|
/**
|
|
@@ -1732,32 +1642,12 @@ var Workflow = class extends BaseResource {
|
|
|
1732
1642
|
method: "POST"
|
|
1733
1643
|
});
|
|
1734
1644
|
}
|
|
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
1645
|
/**
|
|
1756
1646
|
* Creates a new workflow run
|
|
1757
1647
|
* @param params - Optional object containing the optional runId
|
|
1758
1648
|
* @returns Promise containing the runId of the created run with methods to control execution
|
|
1759
1649
|
*/
|
|
1760
|
-
async
|
|
1650
|
+
async createRun(params) {
|
|
1761
1651
|
const searchParams = new URLSearchParams();
|
|
1762
1652
|
if (!!params?.runId) {
|
|
1763
1653
|
searchParams.set("runId", params.runId);
|
|
@@ -1775,7 +1665,7 @@ var Workflow = class extends BaseResource {
|
|
|
1775
1665
|
return this.start({
|
|
1776
1666
|
runId,
|
|
1777
1667
|
inputData: p.inputData,
|
|
1778
|
-
|
|
1668
|
+
requestContext: p.requestContext,
|
|
1779
1669
|
tracingOptions: p.tracingOptions
|
|
1780
1670
|
});
|
|
1781
1671
|
},
|
|
@@ -1783,22 +1673,19 @@ var Workflow = class extends BaseResource {
|
|
|
1783
1673
|
return this.startAsync({
|
|
1784
1674
|
runId,
|
|
1785
1675
|
inputData: p.inputData,
|
|
1786
|
-
|
|
1676
|
+
requestContext: p.requestContext,
|
|
1787
1677
|
tracingOptions: p.tracingOptions
|
|
1788
1678
|
});
|
|
1789
1679
|
},
|
|
1790
|
-
watch: async (onRecord) => {
|
|
1791
|
-
return this.watch({ runId }, onRecord);
|
|
1792
|
-
},
|
|
1793
1680
|
stream: async (p) => {
|
|
1794
|
-
return this.stream({ runId, inputData: p.inputData,
|
|
1681
|
+
return this.stream({ runId, inputData: p.inputData, requestContext: p.requestContext });
|
|
1795
1682
|
},
|
|
1796
1683
|
resume: async (p) => {
|
|
1797
1684
|
return this.resume({
|
|
1798
1685
|
runId,
|
|
1799
1686
|
step: p.step,
|
|
1800
1687
|
resumeData: p.resumeData,
|
|
1801
|
-
|
|
1688
|
+
requestContext: p.requestContext,
|
|
1802
1689
|
tracingOptions: p.tracingOptions
|
|
1803
1690
|
});
|
|
1804
1691
|
},
|
|
@@ -1807,7 +1694,7 @@ var Workflow = class extends BaseResource {
|
|
|
1807
1694
|
runId,
|
|
1808
1695
|
step: p.step,
|
|
1809
1696
|
resumeData: p.resumeData,
|
|
1810
|
-
|
|
1697
|
+
requestContext: p.requestContext,
|
|
1811
1698
|
tracingOptions: p.tracingOptions
|
|
1812
1699
|
});
|
|
1813
1700
|
},
|
|
@@ -1816,26 +1703,26 @@ var Workflow = class extends BaseResource {
|
|
|
1816
1703
|
runId,
|
|
1817
1704
|
step: p.step,
|
|
1818
1705
|
resumeData: p.resumeData,
|
|
1819
|
-
|
|
1706
|
+
requestContext: p.requestContext
|
|
1820
1707
|
});
|
|
1821
1708
|
}
|
|
1822
1709
|
};
|
|
1823
1710
|
}
|
|
1824
1711
|
/**
|
|
1825
1712
|
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
1826
|
-
* @param params - Object containing the runId, inputData and
|
|
1713
|
+
* @param params - Object containing the runId, inputData and requestContext
|
|
1827
1714
|
* @returns Promise containing success message
|
|
1828
1715
|
*/
|
|
1829
1716
|
start(params) {
|
|
1830
|
-
const
|
|
1717
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
1831
1718
|
return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
|
|
1832
1719
|
method: "POST",
|
|
1833
|
-
body: { inputData: params?.inputData,
|
|
1720
|
+
body: { inputData: params?.inputData, requestContext, tracingOptions: params.tracingOptions }
|
|
1834
1721
|
});
|
|
1835
1722
|
}
|
|
1836
1723
|
/**
|
|
1837
1724
|
* Resumes a suspended workflow step synchronously without waiting for the workflow to complete
|
|
1838
|
-
* @param params - Object containing the runId, step, resumeData and
|
|
1725
|
+
* @param params - Object containing the runId, step, resumeData and requestContext
|
|
1839
1726
|
* @returns Promise containing success message
|
|
1840
1727
|
*/
|
|
1841
1728
|
resume({
|
|
@@ -1845,20 +1732,20 @@ var Workflow = class extends BaseResource {
|
|
|
1845
1732
|
tracingOptions,
|
|
1846
1733
|
...rest
|
|
1847
1734
|
}) {
|
|
1848
|
-
const
|
|
1735
|
+
const requestContext = parseClientRequestContext(rest.requestContext);
|
|
1849
1736
|
return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
|
|
1850
1737
|
method: "POST",
|
|
1851
1738
|
body: {
|
|
1852
1739
|
step,
|
|
1853
1740
|
resumeData,
|
|
1854
|
-
|
|
1741
|
+
requestContext,
|
|
1855
1742
|
tracingOptions
|
|
1856
1743
|
}
|
|
1857
1744
|
});
|
|
1858
1745
|
}
|
|
1859
1746
|
/**
|
|
1860
1747
|
* 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
|
|
1748
|
+
* @param params - Object containing the optional runId, inputData and requestContext
|
|
1862
1749
|
* @returns Promise containing the workflow execution results
|
|
1863
1750
|
*/
|
|
1864
1751
|
startAsync(params) {
|
|
@@ -1866,15 +1753,15 @@ var Workflow = class extends BaseResource {
|
|
|
1866
1753
|
if (!!params?.runId) {
|
|
1867
1754
|
searchParams.set("runId", params.runId);
|
|
1868
1755
|
}
|
|
1869
|
-
const
|
|
1756
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
1870
1757
|
return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
1871
1758
|
method: "POST",
|
|
1872
|
-
body: { inputData: params.inputData,
|
|
1759
|
+
body: { inputData: params.inputData, requestContext, tracingOptions: params.tracingOptions }
|
|
1873
1760
|
});
|
|
1874
1761
|
}
|
|
1875
1762
|
/**
|
|
1876
1763
|
* Starts a workflow run and returns a stream
|
|
1877
|
-
* @param params - Object containing the optional runId, inputData and
|
|
1764
|
+
* @param params - Object containing the optional runId, inputData and requestContext
|
|
1878
1765
|
* @returns Promise containing the workflow execution results
|
|
1879
1766
|
*/
|
|
1880
1767
|
async stream(params) {
|
|
@@ -1882,12 +1769,12 @@ var Workflow = class extends BaseResource {
|
|
|
1882
1769
|
if (!!params?.runId) {
|
|
1883
1770
|
searchParams.set("runId", params.runId);
|
|
1884
1771
|
}
|
|
1885
|
-
const
|
|
1772
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
1886
1773
|
const response = await this.request(
|
|
1887
1774
|
`/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
|
|
1888
1775
|
{
|
|
1889
1776
|
method: "POST",
|
|
1890
|
-
body: { inputData: params.inputData,
|
|
1777
|
+
body: { inputData: params.inputData, requestContext, tracingOptions: params.tracingOptions },
|
|
1891
1778
|
stream: true
|
|
1892
1779
|
}
|
|
1893
1780
|
);
|
|
@@ -1972,7 +1859,7 @@ var Workflow = class extends BaseResource {
|
|
|
1972
1859
|
}
|
|
1973
1860
|
/**
|
|
1974
1861
|
* Starts a workflow run and returns a stream
|
|
1975
|
-
* @param params - Object containing the optional runId, inputData and
|
|
1862
|
+
* @param params - Object containing the optional runId, inputData and requestContext
|
|
1976
1863
|
* @returns Promise containing the workflow execution results
|
|
1977
1864
|
*/
|
|
1978
1865
|
async streamVNext(params) {
|
|
@@ -1980,14 +1867,14 @@ var Workflow = class extends BaseResource {
|
|
|
1980
1867
|
if (!!params?.runId) {
|
|
1981
1868
|
searchParams.set("runId", params.runId);
|
|
1982
1869
|
}
|
|
1983
|
-
const
|
|
1870
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
1984
1871
|
const response = await this.request(
|
|
1985
1872
|
`/api/workflows/${this.workflowId}/streamVNext?${searchParams.toString()}`,
|
|
1986
1873
|
{
|
|
1987
1874
|
method: "POST",
|
|
1988
1875
|
body: {
|
|
1989
1876
|
inputData: params.inputData,
|
|
1990
|
-
|
|
1877
|
+
requestContext,
|
|
1991
1878
|
closeOnSuspend: params.closeOnSuspend,
|
|
1992
1879
|
tracingOptions: params.tracingOptions
|
|
1993
1880
|
},
|
|
@@ -2075,30 +1962,30 @@ var Workflow = class extends BaseResource {
|
|
|
2075
1962
|
}
|
|
2076
1963
|
/**
|
|
2077
1964
|
* 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
|
|
1965
|
+
* @param params - Object containing the runId, step, resumeData and requestContext
|
|
2079
1966
|
* @returns Promise containing the workflow resume results
|
|
2080
1967
|
*/
|
|
2081
1968
|
resumeAsync(params) {
|
|
2082
|
-
const
|
|
1969
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2083
1970
|
return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
2084
1971
|
method: "POST",
|
|
2085
1972
|
body: {
|
|
2086
1973
|
step: params.step,
|
|
2087
1974
|
resumeData: params.resumeData,
|
|
2088
|
-
|
|
1975
|
+
requestContext,
|
|
2089
1976
|
tracingOptions: params.tracingOptions
|
|
2090
1977
|
}
|
|
2091
1978
|
});
|
|
2092
1979
|
}
|
|
2093
1980
|
/**
|
|
2094
1981
|
* 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
|
|
1982
|
+
* @param params - Object containing the runId, step, resumeData and requestContext
|
|
2096
1983
|
* @returns Promise containing the workflow resume results
|
|
2097
1984
|
*/
|
|
2098
1985
|
async resumeStreamVNext(params) {
|
|
2099
1986
|
const searchParams = new URLSearchParams();
|
|
2100
1987
|
searchParams.set("runId", params.runId);
|
|
2101
|
-
const
|
|
1988
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2102
1989
|
const response = await this.request(
|
|
2103
1990
|
`/api/workflows/${this.workflowId}/resume-stream?${searchParams.toString()}`,
|
|
2104
1991
|
{
|
|
@@ -2106,7 +1993,7 @@ var Workflow = class extends BaseResource {
|
|
|
2106
1993
|
body: {
|
|
2107
1994
|
step: params.step,
|
|
2108
1995
|
resumeData: params.resumeData,
|
|
2109
|
-
|
|
1996
|
+
requestContext,
|
|
2110
1997
|
tracingOptions: params.tracingOptions
|
|
2111
1998
|
},
|
|
2112
1999
|
stream: true
|
|
@@ -2144,29 +2031,6 @@ var Workflow = class extends BaseResource {
|
|
|
2144
2031
|
});
|
|
2145
2032
|
return response.body.pipeThrough(transformStream);
|
|
2146
2033
|
}
|
|
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
2034
|
/**
|
|
2171
2035
|
* Creates a new ReadableStream from an iterable or async iterable of objects,
|
|
2172
2036
|
* serializing each as JSON and separating them with the record separator (\x1E).
|
|
@@ -2278,22 +2142,22 @@ var MCPTool = class extends BaseResource {
|
|
|
2278
2142
|
}
|
|
2279
2143
|
/**
|
|
2280
2144
|
* Retrieves details about this specific tool from the MCP server.
|
|
2281
|
-
* @param
|
|
2145
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
2282
2146
|
* @returns Promise containing the tool's information (name, description, schema).
|
|
2283
2147
|
*/
|
|
2284
|
-
details(
|
|
2285
|
-
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}${
|
|
2148
|
+
details(requestContext) {
|
|
2149
|
+
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}${requestContextQueryString(requestContext)}`);
|
|
2286
2150
|
}
|
|
2287
2151
|
/**
|
|
2288
2152
|
* Executes this specific tool on the MCP server.
|
|
2289
|
-
* @param params - Parameters for tool execution, including data/args and optional
|
|
2153
|
+
* @param params - Parameters for tool execution, including data/args and optional requestContext.
|
|
2290
2154
|
* @returns Promise containing the result of the tool execution.
|
|
2291
2155
|
*/
|
|
2292
2156
|
execute(params) {
|
|
2293
2157
|
const body = {};
|
|
2294
2158
|
if (params.data !== void 0) body.data = params.data;
|
|
2295
|
-
if (params.
|
|
2296
|
-
body.
|
|
2159
|
+
if (params.requestContext !== void 0) {
|
|
2160
|
+
body.requestContext = params.requestContext;
|
|
2297
2161
|
}
|
|
2298
2162
|
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}/execute`, {
|
|
2299
2163
|
method: "POST",
|
|
@@ -2339,19 +2203,39 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2339
2203
|
}
|
|
2340
2204
|
}
|
|
2341
2205
|
/**
|
|
2342
|
-
*
|
|
2343
|
-
* @throws {Error} Always throws an error directing users to use createRunAsync()
|
|
2206
|
+
* Creates a transform stream that parses binary chunks into JSON records.
|
|
2344
2207
|
*/
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2208
|
+
createRecordParserTransform() {
|
|
2209
|
+
let failedChunk = void 0;
|
|
2210
|
+
return new TransformStream({
|
|
2211
|
+
start() {
|
|
2212
|
+
},
|
|
2213
|
+
async transform(chunk, controller) {
|
|
2214
|
+
try {
|
|
2215
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
2216
|
+
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
2217
|
+
for (const chunk2 of chunks) {
|
|
2218
|
+
if (chunk2) {
|
|
2219
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
2220
|
+
try {
|
|
2221
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
2222
|
+
controller.enqueue(parsedChunk);
|
|
2223
|
+
failedChunk = void 0;
|
|
2224
|
+
} catch {
|
|
2225
|
+
failedChunk = newChunk;
|
|
2226
|
+
}
|
|
2227
|
+
}
|
|
2228
|
+
}
|
|
2229
|
+
} catch {
|
|
2230
|
+
}
|
|
2231
|
+
}
|
|
2232
|
+
});
|
|
2349
2233
|
}
|
|
2350
2234
|
/**
|
|
2351
2235
|
* Creates a new agent builder action run and returns the runId.
|
|
2352
2236
|
* This calls `/api/agent-builder/:actionId/create-run`.
|
|
2353
2237
|
*/
|
|
2354
|
-
async
|
|
2238
|
+
async createRun(params) {
|
|
2355
2239
|
const searchParams = new URLSearchParams();
|
|
2356
2240
|
if (!!params?.runId) {
|
|
2357
2241
|
searchParams.set("runId", params.runId);
|
|
@@ -2370,12 +2254,12 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2370
2254
|
if (runId) {
|
|
2371
2255
|
searchParams.set("runId", runId);
|
|
2372
2256
|
}
|
|
2373
|
-
const
|
|
2374
|
-
const {
|
|
2257
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2258
|
+
const { requestContext: _, ...actionParams } = params;
|
|
2375
2259
|
const url = `/api/agent-builder/${this.actionId}/start-async${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
|
|
2376
2260
|
const result = await this.request(url, {
|
|
2377
2261
|
method: "POST",
|
|
2378
|
-
body: { ...actionParams,
|
|
2262
|
+
body: { ...actionParams, requestContext }
|
|
2379
2263
|
});
|
|
2380
2264
|
return this.transformWorkflowResult(result);
|
|
2381
2265
|
}
|
|
@@ -2386,12 +2270,12 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2386
2270
|
async startActionRun(params, runId) {
|
|
2387
2271
|
const searchParams = new URLSearchParams();
|
|
2388
2272
|
searchParams.set("runId", runId);
|
|
2389
|
-
const
|
|
2390
|
-
const {
|
|
2273
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2274
|
+
const { requestContext: _, ...actionParams } = params;
|
|
2391
2275
|
const url = `/api/agent-builder/${this.actionId}/start?${searchParams.toString()}`;
|
|
2392
2276
|
return this.request(url, {
|
|
2393
2277
|
method: "POST",
|
|
2394
|
-
body: { ...actionParams,
|
|
2278
|
+
body: { ...actionParams, requestContext }
|
|
2395
2279
|
});
|
|
2396
2280
|
}
|
|
2397
2281
|
/**
|
|
@@ -2401,12 +2285,12 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2401
2285
|
async resume(params, runId) {
|
|
2402
2286
|
const searchParams = new URLSearchParams();
|
|
2403
2287
|
searchParams.set("runId", runId);
|
|
2404
|
-
const
|
|
2405
|
-
const {
|
|
2288
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2289
|
+
const { requestContext: _, ...resumeParams } = params;
|
|
2406
2290
|
const url = `/api/agent-builder/${this.actionId}/resume?${searchParams.toString()}`;
|
|
2407
2291
|
return this.request(url, {
|
|
2408
2292
|
method: "POST",
|
|
2409
|
-
body: { ...resumeParams,
|
|
2293
|
+
body: { ...resumeParams, requestContext }
|
|
2410
2294
|
});
|
|
2411
2295
|
}
|
|
2412
2296
|
/**
|
|
@@ -2416,12 +2300,12 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2416
2300
|
async resumeAsync(params, runId) {
|
|
2417
2301
|
const searchParams = new URLSearchParams();
|
|
2418
2302
|
searchParams.set("runId", runId);
|
|
2419
|
-
const
|
|
2420
|
-
const {
|
|
2303
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2304
|
+
const { requestContext: _, ...resumeParams } = params;
|
|
2421
2305
|
const url = `/api/agent-builder/${this.actionId}/resume-async?${searchParams.toString()}`;
|
|
2422
2306
|
const result = await this.request(url, {
|
|
2423
2307
|
method: "POST",
|
|
2424
|
-
body: { ...resumeParams,
|
|
2308
|
+
body: { ...resumeParams, requestContext }
|
|
2425
2309
|
});
|
|
2426
2310
|
return this.transformWorkflowResult(result);
|
|
2427
2311
|
}
|
|
@@ -2479,12 +2363,12 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2479
2363
|
if (runId) {
|
|
2480
2364
|
searchParams.set("runId", runId);
|
|
2481
2365
|
}
|
|
2482
|
-
const
|
|
2483
|
-
const {
|
|
2366
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2367
|
+
const { requestContext: _, ...actionParams } = params;
|
|
2484
2368
|
const url = `/api/agent-builder/${this.actionId}/stream${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
|
|
2485
2369
|
const response = await this.request(url, {
|
|
2486
2370
|
method: "POST",
|
|
2487
|
-
body: { ...actionParams,
|
|
2371
|
+
body: { ...actionParams, requestContext },
|
|
2488
2372
|
stream: true
|
|
2489
2373
|
});
|
|
2490
2374
|
if (!response.ok) {
|
|
@@ -2493,31 +2377,7 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2493
2377
|
if (!response.body) {
|
|
2494
2378
|
throw new Error("Response body is null");
|
|
2495
2379
|
}
|
|
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);
|
|
2380
|
+
return response.body.pipeThrough(this.createRecordParserTransform());
|
|
2521
2381
|
}
|
|
2522
2382
|
/**
|
|
2523
2383
|
* Streams agent builder action progress in real-time using VNext streaming.
|
|
@@ -2528,12 +2388,12 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2528
2388
|
if (runId) {
|
|
2529
2389
|
searchParams.set("runId", runId);
|
|
2530
2390
|
}
|
|
2531
|
-
const
|
|
2532
|
-
const {
|
|
2391
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2392
|
+
const { requestContext: _, ...actionParams } = params;
|
|
2533
2393
|
const url = `/api/agent-builder/${this.actionId}/streamVNext${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
|
|
2534
2394
|
const response = await this.request(url, {
|
|
2535
2395
|
method: "POST",
|
|
2536
|
-
body: { ...actionParams,
|
|
2396
|
+
body: { ...actionParams, requestContext },
|
|
2537
2397
|
stream: true
|
|
2538
2398
|
});
|
|
2539
2399
|
if (!response.ok) {
|
|
@@ -2542,57 +2402,94 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2542
2402
|
if (!response.body) {
|
|
2543
2403
|
throw new Error("Response body is null");
|
|
2544
2404
|
}
|
|
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
|
-
}
|
|
2405
|
+
return response.body.pipeThrough(this.createRecordParserTransform());
|
|
2406
|
+
}
|
|
2407
|
+
/**
|
|
2408
|
+
* Observes an existing agent builder action run stream.
|
|
2409
|
+
* Replays cached execution from the beginning, then continues with live stream.
|
|
2410
|
+
* This is the recommended method for recovery after page refresh/hot reload.
|
|
2411
|
+
* This calls `/api/agent-builder/:actionId/observe` (which delegates to observeStreamVNext).
|
|
2412
|
+
*/
|
|
2413
|
+
async observeStream(params) {
|
|
2414
|
+
const searchParams = new URLSearchParams();
|
|
2415
|
+
searchParams.set("runId", params.runId);
|
|
2416
|
+
const url = `/api/agent-builder/${this.actionId}/observe?${searchParams.toString()}`;
|
|
2417
|
+
const response = await this.request(url, {
|
|
2418
|
+
method: "POST",
|
|
2419
|
+
stream: true
|
|
2568
2420
|
});
|
|
2569
|
-
|
|
2421
|
+
if (!response.ok) {
|
|
2422
|
+
throw new Error(`Failed to observe agent builder action stream: ${response.statusText}`);
|
|
2423
|
+
}
|
|
2424
|
+
if (!response.body) {
|
|
2425
|
+
throw new Error("Response body is null");
|
|
2426
|
+
}
|
|
2427
|
+
return response.body.pipeThrough(this.createRecordParserTransform());
|
|
2570
2428
|
}
|
|
2571
2429
|
/**
|
|
2572
|
-
*
|
|
2573
|
-
*
|
|
2574
|
-
*
|
|
2575
|
-
* This calls `/api/agent-builder/:actionId/watch`.
|
|
2430
|
+
* Observes an existing agent builder action run stream using VNext streaming API.
|
|
2431
|
+
* Replays cached execution from the beginning, then continues with live stream.
|
|
2432
|
+
* This calls `/api/agent-builder/:actionId/observe-streamVNext`.
|
|
2576
2433
|
*/
|
|
2577
|
-
async
|
|
2578
|
-
const
|
|
2434
|
+
async observeStreamVNext(params) {
|
|
2435
|
+
const searchParams = new URLSearchParams();
|
|
2436
|
+
searchParams.set("runId", params.runId);
|
|
2437
|
+
const url = `/api/agent-builder/${this.actionId}/observe-streamVNext?${searchParams.toString()}`;
|
|
2579
2438
|
const response = await this.request(url, {
|
|
2580
|
-
method: "
|
|
2439
|
+
method: "POST",
|
|
2581
2440
|
stream: true
|
|
2582
2441
|
});
|
|
2583
2442
|
if (!response.ok) {
|
|
2584
|
-
throw new Error(`Failed to
|
|
2443
|
+
throw new Error(`Failed to observe agent builder action stream VNext: ${response.statusText}`);
|
|
2585
2444
|
}
|
|
2586
2445
|
if (!response.body) {
|
|
2587
2446
|
throw new Error("Response body is null");
|
|
2588
2447
|
}
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2448
|
+
return response.body.pipeThrough(this.createRecordParserTransform());
|
|
2449
|
+
}
|
|
2450
|
+
/**
|
|
2451
|
+
* Observes an existing agent builder action run stream using legacy streaming API.
|
|
2452
|
+
* Replays cached execution from the beginning, then continues with live stream.
|
|
2453
|
+
* This calls `/api/agent-builder/:actionId/observe-stream-legacy`.
|
|
2454
|
+
*/
|
|
2455
|
+
async observeStreamLegacy(params) {
|
|
2456
|
+
const searchParams = new URLSearchParams();
|
|
2457
|
+
searchParams.set("runId", params.runId);
|
|
2458
|
+
const url = `/api/agent-builder/${this.actionId}/observe-stream-legacy?${searchParams.toString()}`;
|
|
2459
|
+
const response = await this.request(url, {
|
|
2460
|
+
method: "POST",
|
|
2461
|
+
stream: true
|
|
2462
|
+
});
|
|
2463
|
+
if (!response.ok) {
|
|
2464
|
+
throw new Error(`Failed to observe agent builder action stream legacy: ${response.statusText}`);
|
|
2465
|
+
}
|
|
2466
|
+
if (!response.body) {
|
|
2467
|
+
throw new Error("Response body is null");
|
|
2595
2468
|
}
|
|
2469
|
+
return response.body.pipeThrough(this.createRecordParserTransform());
|
|
2470
|
+
}
|
|
2471
|
+
/**
|
|
2472
|
+
* Resumes a suspended agent builder action and streams the results.
|
|
2473
|
+
* This calls `/api/agent-builder/:actionId/resume-stream`.
|
|
2474
|
+
*/
|
|
2475
|
+
async resumeStream(params) {
|
|
2476
|
+
const searchParams = new URLSearchParams();
|
|
2477
|
+
searchParams.set("runId", params.runId);
|
|
2478
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2479
|
+
const { runId: _, requestContext: __, ...resumeParams } = params;
|
|
2480
|
+
const url = `/api/agent-builder/${this.actionId}/resume-stream?${searchParams.toString()}`;
|
|
2481
|
+
const response = await this.request(url, {
|
|
2482
|
+
method: "POST",
|
|
2483
|
+
body: { ...resumeParams, requestContext },
|
|
2484
|
+
stream: true
|
|
2485
|
+
});
|
|
2486
|
+
if (!response.ok) {
|
|
2487
|
+
throw new Error(`Failed to resume agent builder action stream: ${response.statusText}`);
|
|
2488
|
+
}
|
|
2489
|
+
if (!response.body) {
|
|
2490
|
+
throw new Error("Response body is null");
|
|
2491
|
+
}
|
|
2492
|
+
return response.body.pipeThrough(this.createRecordParserTransform());
|
|
2596
2493
|
}
|
|
2597
2494
|
/**
|
|
2598
2495
|
* Gets a specific action run by its ID.
|
|
@@ -2624,11 +2521,11 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2624
2521
|
if (params?.toDate) {
|
|
2625
2522
|
searchParams.set("toDate", params.toDate.toISOString());
|
|
2626
2523
|
}
|
|
2627
|
-
if (params?.
|
|
2628
|
-
searchParams.set("
|
|
2524
|
+
if (params?.perPage !== void 0) {
|
|
2525
|
+
searchParams.set("perPage", String(params.perPage));
|
|
2629
2526
|
}
|
|
2630
|
-
if (params?.
|
|
2631
|
-
searchParams.set("
|
|
2527
|
+
if (params?.page !== void 0) {
|
|
2528
|
+
searchParams.set("page", String(params.page));
|
|
2632
2529
|
}
|
|
2633
2530
|
if (params?.resourceId) {
|
|
2634
2531
|
searchParams.set("resourceId", params.resourceId);
|
|
@@ -2658,17 +2555,6 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2658
2555
|
method: "POST"
|
|
2659
2556
|
});
|
|
2660
2557
|
}
|
|
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
2558
|
};
|
|
2673
2559
|
|
|
2674
2560
|
// src/resources/observability.ts
|
|
@@ -2677,15 +2563,15 @@ var Observability = class extends BaseResource {
|
|
|
2677
2563
|
super(options);
|
|
2678
2564
|
}
|
|
2679
2565
|
/**
|
|
2680
|
-
* Retrieves a specific
|
|
2566
|
+
* Retrieves a specific trace by ID
|
|
2681
2567
|
* @param traceId - ID of the trace to retrieve
|
|
2682
|
-
* @returns Promise containing the
|
|
2568
|
+
* @returns Promise containing the trace with all its spans
|
|
2683
2569
|
*/
|
|
2684
2570
|
getTrace(traceId) {
|
|
2685
2571
|
return this.request(`/api/observability/traces/${traceId}`);
|
|
2686
2572
|
}
|
|
2687
2573
|
/**
|
|
2688
|
-
* Retrieves paginated list of
|
|
2574
|
+
* Retrieves paginated list of traces with optional filtering
|
|
2689
2575
|
* @param params - Parameters for pagination and filtering
|
|
2690
2576
|
* @returns Promise containing paginated traces and pagination info
|
|
2691
2577
|
*/
|
|
@@ -2725,7 +2611,7 @@ var Observability = class extends BaseResource {
|
|
|
2725
2611
|
* @param params - Parameters containing trace ID, span ID, and pagination options
|
|
2726
2612
|
* @returns Promise containing scores and pagination info
|
|
2727
2613
|
*/
|
|
2728
|
-
|
|
2614
|
+
listScoresBySpan(params) {
|
|
2729
2615
|
const { traceId, spanId, page, perPage } = params;
|
|
2730
2616
|
const searchParams = new URLSearchParams();
|
|
2731
2617
|
if (page !== void 0) {
|
|
@@ -2747,69 +2633,6 @@ var Observability = class extends BaseResource {
|
|
|
2747
2633
|
}
|
|
2748
2634
|
};
|
|
2749
2635
|
|
|
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
2636
|
// src/client.ts
|
|
2814
2637
|
var MastraClient = class extends BaseResource {
|
|
2815
2638
|
observability;
|
|
@@ -2819,18 +2642,21 @@ var MastraClient = class extends BaseResource {
|
|
|
2819
2642
|
}
|
|
2820
2643
|
/**
|
|
2821
2644
|
* Retrieves all available agents
|
|
2822
|
-
* @param
|
|
2645
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
2823
2646
|
* @returns Promise containing map of agent IDs to agent details
|
|
2824
2647
|
*/
|
|
2825
|
-
|
|
2826
|
-
const
|
|
2648
|
+
listAgents(requestContext) {
|
|
2649
|
+
const requestContextParam = base64RequestContext(parseClientRequestContext(requestContext));
|
|
2827
2650
|
const searchParams = new URLSearchParams();
|
|
2828
|
-
if (
|
|
2829
|
-
searchParams.set("
|
|
2651
|
+
if (requestContextParam) {
|
|
2652
|
+
searchParams.set("requestContext", requestContextParam);
|
|
2830
2653
|
}
|
|
2831
2654
|
const queryString = searchParams.toString();
|
|
2832
2655
|
return this.request(`/api/agents${queryString ? `?${queryString}` : ""}`);
|
|
2833
2656
|
}
|
|
2657
|
+
listAgentsModelProviders() {
|
|
2658
|
+
return this.request(`/api/agents/providers`);
|
|
2659
|
+
}
|
|
2834
2660
|
/**
|
|
2835
2661
|
* Gets an agent instance by ID
|
|
2836
2662
|
* @param agentId - ID of the agent to retrieve
|
|
@@ -2840,33 +2666,50 @@ var MastraClient = class extends BaseResource {
|
|
|
2840
2666
|
return new Agent(this.options, agentId);
|
|
2841
2667
|
}
|
|
2842
2668
|
/**
|
|
2843
|
-
*
|
|
2844
|
-
* @param params - Parameters containing
|
|
2845
|
-
* @returns Promise containing array of memory threads
|
|
2669
|
+
* Lists memory threads for a resource with pagination support
|
|
2670
|
+
* @param params - Parameters containing resource ID, pagination options, and optional request context
|
|
2671
|
+
* @returns Promise containing paginated array of memory threads with metadata
|
|
2846
2672
|
*/
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2673
|
+
async listMemoryThreads(params) {
|
|
2674
|
+
const queryParams = new URLSearchParams({
|
|
2675
|
+
resourceId: params.resourceId,
|
|
2676
|
+
resourceid: params.resourceId,
|
|
2677
|
+
agentId: params.agentId,
|
|
2678
|
+
...params.page !== void 0 && { page: params.page.toString() },
|
|
2679
|
+
...params.perPage !== void 0 && { perPage: params.perPage.toString() },
|
|
2680
|
+
...params.orderBy && { orderBy: params.orderBy },
|
|
2681
|
+
...params.sortDirection && { sortDirection: params.sortDirection }
|
|
2682
|
+
});
|
|
2683
|
+
const response = await this.request(
|
|
2684
|
+
`/api/memory/threads?${queryParams.toString()}${requestContextQueryString(params.requestContext, "&")}`
|
|
2850
2685
|
);
|
|
2686
|
+
const actualResponse = "threads" in response ? response : {
|
|
2687
|
+
threads: response,
|
|
2688
|
+
total: response.length,
|
|
2689
|
+
page: params.page ?? 0,
|
|
2690
|
+
perPage: params.perPage ?? 100,
|
|
2691
|
+
hasMore: false
|
|
2692
|
+
};
|
|
2693
|
+
return actualResponse;
|
|
2851
2694
|
}
|
|
2852
2695
|
/**
|
|
2853
2696
|
* Retrieves memory config for a resource
|
|
2854
|
-
* @param params - Parameters containing the resource ID and optional
|
|
2697
|
+
* @param params - Parameters containing the resource ID and optional request context
|
|
2855
2698
|
* @returns Promise containing memory configuration
|
|
2856
2699
|
*/
|
|
2857
2700
|
getMemoryConfig(params) {
|
|
2858
2701
|
return this.request(
|
|
2859
|
-
`/api/memory/config?agentId=${params.agentId}${
|
|
2702
|
+
`/api/memory/config?agentId=${params.agentId}${requestContextQueryString(params.requestContext, "&")}`
|
|
2860
2703
|
);
|
|
2861
2704
|
}
|
|
2862
2705
|
/**
|
|
2863
2706
|
* Creates a new memory thread
|
|
2864
|
-
* @param params - Parameters for creating the memory thread including optional
|
|
2707
|
+
* @param params - Parameters for creating the memory thread including optional request context
|
|
2865
2708
|
* @returns Promise containing the created memory thread
|
|
2866
2709
|
*/
|
|
2867
2710
|
createMemoryThread(params) {
|
|
2868
2711
|
return this.request(
|
|
2869
|
-
`/api/memory/threads?agentId=${params.agentId}${
|
|
2712
|
+
`/api/memory/threads?agentId=${params.agentId}${requestContextQueryString(params.requestContext, "&")}`,
|
|
2870
2713
|
{ method: "POST", body: params }
|
|
2871
2714
|
);
|
|
2872
2715
|
}
|
|
@@ -2875,35 +2718,38 @@ var MastraClient = class extends BaseResource {
|
|
|
2875
2718
|
* @param threadId - ID of the memory thread to retrieve
|
|
2876
2719
|
* @returns MemoryThread instance
|
|
2877
2720
|
*/
|
|
2878
|
-
getMemoryThread(threadId, agentId) {
|
|
2721
|
+
getMemoryThread({ threadId, agentId }) {
|
|
2879
2722
|
return new MemoryThread(this.options, threadId, agentId);
|
|
2880
2723
|
}
|
|
2881
|
-
|
|
2724
|
+
listThreadMessages(threadId, opts = {}) {
|
|
2725
|
+
if (!opts.agentId && !opts.networkId) {
|
|
2726
|
+
throw new Error("Either agentId or networkId must be provided");
|
|
2727
|
+
}
|
|
2882
2728
|
let url = "";
|
|
2883
2729
|
if (opts.agentId) {
|
|
2884
|
-
url = `/api/memory/threads/${threadId}/messages?agentId=${opts.agentId}${
|
|
2730
|
+
url = `/api/memory/threads/${threadId}/messages?agentId=${opts.agentId}${requestContextQueryString(opts.requestContext, "&")}`;
|
|
2885
2731
|
} else if (opts.networkId) {
|
|
2886
|
-
url = `/api/memory/network/threads/${threadId}/messages?networkId=${opts.networkId}${
|
|
2732
|
+
url = `/api/memory/network/threads/${threadId}/messages?networkId=${opts.networkId}${requestContextQueryString(opts.requestContext, "&")}`;
|
|
2887
2733
|
}
|
|
2888
2734
|
return this.request(url);
|
|
2889
2735
|
}
|
|
2890
2736
|
deleteThread(threadId, opts = {}) {
|
|
2891
2737
|
let url = "";
|
|
2892
2738
|
if (opts.agentId) {
|
|
2893
|
-
url = `/api/memory/threads/${threadId}?agentId=${opts.agentId}${
|
|
2739
|
+
url = `/api/memory/threads/${threadId}?agentId=${opts.agentId}${requestContextQueryString(opts.requestContext, "&")}`;
|
|
2894
2740
|
} else if (opts.networkId) {
|
|
2895
|
-
url = `/api/memory/network/threads/${threadId}?networkId=${opts.networkId}${
|
|
2741
|
+
url = `/api/memory/network/threads/${threadId}?networkId=${opts.networkId}${requestContextQueryString(opts.requestContext, "&")}`;
|
|
2896
2742
|
}
|
|
2897
2743
|
return this.request(url, { method: "DELETE" });
|
|
2898
2744
|
}
|
|
2899
2745
|
/**
|
|
2900
2746
|
* Saves messages to memory
|
|
2901
|
-
* @param params - Parameters containing messages to save and optional
|
|
2747
|
+
* @param params - Parameters containing messages to save and optional request context
|
|
2902
2748
|
* @returns Promise containing the saved messages
|
|
2903
2749
|
*/
|
|
2904
2750
|
saveMessageToMemory(params) {
|
|
2905
2751
|
return this.request(
|
|
2906
|
-
`/api/memory/save-messages?agentId=${params.agentId}${
|
|
2752
|
+
`/api/memory/save-messages?agentId=${params.agentId}${requestContextQueryString(params.requestContext, "&")}`,
|
|
2907
2753
|
{
|
|
2908
2754
|
method: "POST",
|
|
2909
2755
|
body: params
|
|
@@ -2913,64 +2759,22 @@ var MastraClient = class extends BaseResource {
|
|
|
2913
2759
|
/**
|
|
2914
2760
|
* Gets the status of the memory system
|
|
2915
2761
|
* @param agentId - The agent ID
|
|
2916
|
-
* @param
|
|
2917
|
-
* @returns Promise containing memory system status
|
|
2918
|
-
*/
|
|
2919
|
-
getMemoryStatus(agentId, runtimeContext) {
|
|
2920
|
-
return this.request(`/api/memory/status?agentId=${agentId}${runtimeContextQueryString(runtimeContext, "&")}`);
|
|
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
|
|
2762
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
2959
2763
|
* @returns Promise containing memory system status
|
|
2960
2764
|
*/
|
|
2961
|
-
|
|
2962
|
-
return this.request(`/api/memory/
|
|
2765
|
+
getMemoryStatus(agentId, requestContext) {
|
|
2766
|
+
return this.request(`/api/memory/status?agentId=${agentId}${requestContextQueryString(requestContext, "&")}`);
|
|
2963
2767
|
}
|
|
2964
2768
|
/**
|
|
2965
2769
|
* Retrieves all available tools
|
|
2966
|
-
* @param
|
|
2770
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
2967
2771
|
* @returns Promise containing map of tool IDs to tool details
|
|
2968
2772
|
*/
|
|
2969
|
-
|
|
2970
|
-
const
|
|
2773
|
+
listTools(requestContext) {
|
|
2774
|
+
const requestContextParam = base64RequestContext(parseClientRequestContext(requestContext));
|
|
2971
2775
|
const searchParams = new URLSearchParams();
|
|
2972
|
-
if (
|
|
2973
|
-
searchParams.set("
|
|
2776
|
+
if (requestContextParam) {
|
|
2777
|
+
searchParams.set("requestContext", requestContextParam);
|
|
2974
2778
|
}
|
|
2975
2779
|
const queryString = searchParams.toString();
|
|
2976
2780
|
return this.request(`/api/tools${queryString ? `?${queryString}` : ""}`);
|
|
@@ -2985,14 +2789,14 @@ var MastraClient = class extends BaseResource {
|
|
|
2985
2789
|
}
|
|
2986
2790
|
/**
|
|
2987
2791
|
* Retrieves all available workflows
|
|
2988
|
-
* @param
|
|
2792
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
2989
2793
|
* @returns Promise containing map of workflow IDs to workflow details
|
|
2990
2794
|
*/
|
|
2991
|
-
|
|
2992
|
-
const
|
|
2795
|
+
listWorkflows(requestContext) {
|
|
2796
|
+
const requestContextParam = base64RequestContext(parseClientRequestContext(requestContext));
|
|
2993
2797
|
const searchParams = new URLSearchParams();
|
|
2994
|
-
if (
|
|
2995
|
-
searchParams.set("
|
|
2798
|
+
if (requestContextParam) {
|
|
2799
|
+
searchParams.set("requestContext", requestContextParam);
|
|
2996
2800
|
}
|
|
2997
2801
|
const queryString = searchParams.toString();
|
|
2998
2802
|
return this.request(`/api/workflows${queryString ? `?${queryString}` : ""}`);
|
|
@@ -3032,7 +2836,7 @@ var MastraClient = class extends BaseResource {
|
|
|
3032
2836
|
* @param params - Parameters for filtering logs
|
|
3033
2837
|
* @returns Promise containing array of log messages
|
|
3034
2838
|
*/
|
|
3035
|
-
|
|
2839
|
+
listLogs(params) {
|
|
3036
2840
|
const { transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
|
|
3037
2841
|
const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
|
|
3038
2842
|
const searchParams = new URLSearchParams();
|
|
@@ -3118,63 +2922,21 @@ var MastraClient = class extends BaseResource {
|
|
|
3118
2922
|
* List of all log transports
|
|
3119
2923
|
* @returns Promise containing list of log transports
|
|
3120
2924
|
*/
|
|
3121
|
-
|
|
2925
|
+
listLogTransports() {
|
|
3122
2926
|
return this.request("/api/logs/transports");
|
|
3123
2927
|
}
|
|
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
2928
|
/**
|
|
3167
2929
|
* Retrieves a list of available MCP servers.
|
|
3168
|
-
* @param params - Optional parameters for pagination (
|
|
2930
|
+
* @param params - Optional parameters for pagination (perPage, page).
|
|
3169
2931
|
* @returns Promise containing the list of MCP servers and pagination info.
|
|
3170
2932
|
*/
|
|
3171
2933
|
getMcpServers(params) {
|
|
3172
2934
|
const searchParams = new URLSearchParams();
|
|
3173
|
-
if (params?.
|
|
3174
|
-
searchParams.set("
|
|
2935
|
+
if (params?.perPage !== void 0) {
|
|
2936
|
+
searchParams.set("perPage", String(params.perPage));
|
|
3175
2937
|
}
|
|
3176
|
-
if (params?.
|
|
3177
|
-
searchParams.set("
|
|
2938
|
+
if (params?.page !== void 0) {
|
|
2939
|
+
searchParams.set("page", String(params.page));
|
|
3178
2940
|
}
|
|
3179
2941
|
const queryString = searchParams.toString();
|
|
3180
2942
|
return this.request(`/api/mcp/v0/servers${queryString ? `?${queryString}` : ""}`);
|
|
@@ -3230,12 +2992,33 @@ var MastraClient = class extends BaseResource {
|
|
|
3230
2992
|
agentId,
|
|
3231
2993
|
threadId,
|
|
3232
2994
|
resourceId,
|
|
3233
|
-
|
|
2995
|
+
requestContext
|
|
3234
2996
|
}) {
|
|
3235
2997
|
return this.request(
|
|
3236
|
-
`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}${
|
|
2998
|
+
`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}${requestContextQueryString(requestContext, "&")}`
|
|
3237
2999
|
);
|
|
3238
3000
|
}
|
|
3001
|
+
searchMemory({
|
|
3002
|
+
agentId,
|
|
3003
|
+
resourceId,
|
|
3004
|
+
threadId,
|
|
3005
|
+
searchQuery,
|
|
3006
|
+
memoryConfig,
|
|
3007
|
+
requestContext
|
|
3008
|
+
}) {
|
|
3009
|
+
const params = new URLSearchParams({
|
|
3010
|
+
searchQuery,
|
|
3011
|
+
resourceId,
|
|
3012
|
+
agentId
|
|
3013
|
+
});
|
|
3014
|
+
if (threadId) {
|
|
3015
|
+
params.append("threadId", threadId);
|
|
3016
|
+
}
|
|
3017
|
+
if (memoryConfig) {
|
|
3018
|
+
params.append("memoryConfig", JSON.stringify(memoryConfig));
|
|
3019
|
+
}
|
|
3020
|
+
return this.request(`/api/memory/search?${params}${requestContextQueryString(requestContext, "&")}`);
|
|
3021
|
+
}
|
|
3239
3022
|
/**
|
|
3240
3023
|
* Updates the working memory for a specific thread (optionally resource-scoped).
|
|
3241
3024
|
* @param agentId - ID of the agent.
|
|
@@ -3248,10 +3031,10 @@ var MastraClient = class extends BaseResource {
|
|
|
3248
3031
|
threadId,
|
|
3249
3032
|
workingMemory,
|
|
3250
3033
|
resourceId,
|
|
3251
|
-
|
|
3034
|
+
requestContext
|
|
3252
3035
|
}) {
|
|
3253
3036
|
return this.request(
|
|
3254
|
-
`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}${
|
|
3037
|
+
`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}${requestContextQueryString(requestContext, "&")}`,
|
|
3255
3038
|
{
|
|
3256
3039
|
method: "POST",
|
|
3257
3040
|
body: {
|
|
@@ -3265,7 +3048,7 @@ var MastraClient = class extends BaseResource {
|
|
|
3265
3048
|
* Retrieves all available scorers
|
|
3266
3049
|
* @returns Promise containing list of available scorers
|
|
3267
3050
|
*/
|
|
3268
|
-
|
|
3051
|
+
listScorers() {
|
|
3269
3052
|
return this.request("/api/scores/scorers");
|
|
3270
3053
|
}
|
|
3271
3054
|
/**
|
|
@@ -3276,7 +3059,7 @@ var MastraClient = class extends BaseResource {
|
|
|
3276
3059
|
getScorer(scorerId) {
|
|
3277
3060
|
return this.request(`/api/scores/scorers/${encodeURIComponent(scorerId)}`);
|
|
3278
3061
|
}
|
|
3279
|
-
|
|
3062
|
+
listScoresByScorerId(params) {
|
|
3280
3063
|
const { page, perPage, scorerId, entityId, entityType } = params;
|
|
3281
3064
|
const searchParams = new URLSearchParams();
|
|
3282
3065
|
if (entityId) {
|
|
@@ -3299,7 +3082,7 @@ var MastraClient = class extends BaseResource {
|
|
|
3299
3082
|
* @param params - Parameters containing run ID and pagination options
|
|
3300
3083
|
* @returns Promise containing scores and pagination info
|
|
3301
3084
|
*/
|
|
3302
|
-
|
|
3085
|
+
listScoresByRunId(params) {
|
|
3303
3086
|
const { runId, page, perPage } = params;
|
|
3304
3087
|
const searchParams = new URLSearchParams();
|
|
3305
3088
|
if (page !== void 0) {
|
|
@@ -3316,7 +3099,7 @@ var MastraClient = class extends BaseResource {
|
|
|
3316
3099
|
* @param params - Parameters containing entity ID, type, and pagination options
|
|
3317
3100
|
* @returns Promise containing scores and pagination info
|
|
3318
3101
|
*/
|
|
3319
|
-
|
|
3102
|
+
listScoresByEntityId(params) {
|
|
3320
3103
|
const { entityId, entityType, page, perPage } = params;
|
|
3321
3104
|
const searchParams = new URLSearchParams();
|
|
3322
3105
|
if (page !== void 0) {
|
|
@@ -3341,14 +3124,14 @@ var MastraClient = class extends BaseResource {
|
|
|
3341
3124
|
body: params
|
|
3342
3125
|
});
|
|
3343
3126
|
}
|
|
3344
|
-
|
|
3127
|
+
getTrace(traceId) {
|
|
3345
3128
|
return this.observability.getTrace(traceId);
|
|
3346
3129
|
}
|
|
3347
|
-
|
|
3130
|
+
getTraces(params) {
|
|
3348
3131
|
return this.observability.getTraces(params);
|
|
3349
3132
|
}
|
|
3350
|
-
|
|
3351
|
-
return this.observability.
|
|
3133
|
+
listScoresBySpan(params) {
|
|
3134
|
+
return this.observability.listScoresBySpan(params);
|
|
3352
3135
|
}
|
|
3353
3136
|
score(params) {
|
|
3354
3137
|
return this.observability.score(params);
|