@mastra/client-js 0.0.0-break-rename-vnext-legacy-20251002212351 → 0.0.0-bundle-recursion-20251030002519
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 +242 -4
- package/dist/client.d.ts +24 -15
- package/dist/client.d.ts.map +1 -1
- package/dist/index.cjs +304 -161
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +304 -161
- package/dist/index.js.map +1 -1
- package/dist/resources/agent-builder.d.ts +50 -2
- package/dist/resources/agent-builder.d.ts.map +1 -1
- package/dist/resources/agent.d.ts +28 -8
- package/dist/resources/agent.d.ts.map +1 -1
- package/dist/resources/memory-thread.d.ts +16 -8
- package/dist/resources/memory-thread.d.ts.map +1 -1
- package/dist/resources/workflow.d.ts +6 -6
- package/dist/resources/workflow.d.ts.map +1 -1
- package/dist/types.d.ts +55 -64
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/index.d.ts +7 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/process-mastra-stream.d.ts.map +1 -1
- package/package.json +6 -5
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { processDataStream, parsePartialJson } from '@ai-sdk/ui-utils';
|
|
2
2
|
import { v4 } from '@lukeed/uuid';
|
|
3
|
+
import { getErrorFromUnknown } from '@mastra/core/error';
|
|
3
4
|
import { RuntimeContext } from '@mastra/core/runtime-context';
|
|
4
5
|
import { isVercelTool } from '@mastra/core/tools/is-vercel-tool';
|
|
5
6
|
import { z } from 'zod';
|
|
@@ -21,13 +22,13 @@ function base64RuntimeContext(runtimeContext) {
|
|
|
21
22
|
}
|
|
22
23
|
return void 0;
|
|
23
24
|
}
|
|
24
|
-
function runtimeContextQueryString(runtimeContext) {
|
|
25
|
+
function runtimeContextQueryString(runtimeContext, delimiter = "?") {
|
|
25
26
|
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
26
27
|
if (!runtimeContextParam) return "";
|
|
27
28
|
const searchParams = new URLSearchParams();
|
|
28
29
|
searchParams.set("runtimeContext", runtimeContextParam);
|
|
29
30
|
const queryString = searchParams.toString();
|
|
30
|
-
return queryString ?
|
|
31
|
+
return queryString ? `${delimiter}${queryString}` : "";
|
|
31
32
|
}
|
|
32
33
|
function isZodType(value) {
|
|
33
34
|
return typeof value === "object" && value !== null && "_def" in value && "parse" in value && typeof value.parse === "function" && "safeParse" in value && typeof value.safeParse === "function";
|
|
@@ -94,11 +95,15 @@ async function sharedProcessMastraStream({
|
|
|
94
95
|
console.info("\u{1F3C1} Stream finished");
|
|
95
96
|
return;
|
|
96
97
|
}
|
|
98
|
+
let json;
|
|
97
99
|
try {
|
|
98
|
-
|
|
99
|
-
await onChunk(json);
|
|
100
|
+
json = JSON.parse(data);
|
|
100
101
|
} catch (error) {
|
|
101
102
|
console.error("\u274C JSON parse error:", error, "Data:", data);
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
if (json) {
|
|
106
|
+
await onChunk(json);
|
|
102
107
|
}
|
|
103
108
|
}
|
|
104
109
|
}
|
|
@@ -317,6 +322,12 @@ var Agent = class extends BaseResource {
|
|
|
317
322
|
details(runtimeContext) {
|
|
318
323
|
return this.request(`/api/agents/${this.agentId}${runtimeContextQueryString(runtimeContext)}`);
|
|
319
324
|
}
|
|
325
|
+
enhanceInstructions(instructions, comment) {
|
|
326
|
+
return this.request(`/api/agents/${this.agentId}/instructions/enhance`, {
|
|
327
|
+
method: "POST",
|
|
328
|
+
body: { instructions, comment }
|
|
329
|
+
});
|
|
330
|
+
}
|
|
320
331
|
async generateLegacy(params) {
|
|
321
332
|
const processedParams = {
|
|
322
333
|
...params,
|
|
@@ -392,7 +403,6 @@ var Agent = class extends BaseResource {
|
|
|
392
403
|
}
|
|
393
404
|
const processedParams = {
|
|
394
405
|
...params,
|
|
395
|
-
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
396
406
|
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
397
407
|
clientTools: processClientTools(params.clientTools),
|
|
398
408
|
structuredOutput: params.structuredOutput ? {
|
|
@@ -697,7 +707,7 @@ var Agent = class extends BaseResource {
|
|
|
697
707
|
clientTools: processClientTools(params.clientTools)
|
|
698
708
|
};
|
|
699
709
|
const { readable, writable } = new TransformStream();
|
|
700
|
-
const response = await this.
|
|
710
|
+
const response = await this.processStreamResponseLegacy(processedParams, writable);
|
|
701
711
|
const streamResponse = new Response(readable, {
|
|
702
712
|
status: response.status,
|
|
703
713
|
statusText: response.statusText,
|
|
@@ -784,6 +794,14 @@ var Agent = class extends BaseResource {
|
|
|
784
794
|
// but this is completely wrong and this fn is probably broken. Remove ":any" and you'll see a bunch of type errors
|
|
785
795
|
onChunk: async (chunk) => {
|
|
786
796
|
switch (chunk.type) {
|
|
797
|
+
case "tripwire": {
|
|
798
|
+
message.parts.push({
|
|
799
|
+
type: "text",
|
|
800
|
+
text: chunk.payload.tripwireReason
|
|
801
|
+
});
|
|
802
|
+
execUpdate();
|
|
803
|
+
break;
|
|
804
|
+
}
|
|
787
805
|
case "step-start": {
|
|
788
806
|
if (!replaceLastMessage) {
|
|
789
807
|
message.id = chunk.payload.messageId;
|
|
@@ -937,7 +955,10 @@ var Agent = class extends BaseResource {
|
|
|
937
955
|
break;
|
|
938
956
|
}
|
|
939
957
|
case "error": {
|
|
940
|
-
throw
|
|
958
|
+
throw getErrorFromUnknown(chunk.payload.error, {
|
|
959
|
+
fallbackMessage: "Unknown error in stream",
|
|
960
|
+
supportSerialization: false
|
|
961
|
+
});
|
|
941
962
|
}
|
|
942
963
|
case "data": {
|
|
943
964
|
data.push(...chunk.payload.data);
|
|
@@ -964,8 +985,8 @@ var Agent = class extends BaseResource {
|
|
|
964
985
|
});
|
|
965
986
|
onFinish?.({ message, finishReason, usage });
|
|
966
987
|
}
|
|
967
|
-
async
|
|
968
|
-
const response = await this.request(`/api/agents/${this.agentId}
|
|
988
|
+
async processStreamResponse(processedParams, writable, route = "stream") {
|
|
989
|
+
const response = await this.request(`/api/agents/${this.agentId}/${route}`, {
|
|
969
990
|
method: "POST",
|
|
970
991
|
body: processedParams,
|
|
971
992
|
stream: true
|
|
@@ -980,18 +1001,17 @@ var Agent = class extends BaseResource {
|
|
|
980
1001
|
streamForWritable.pipeTo(
|
|
981
1002
|
new WritableStream({
|
|
982
1003
|
async write(chunk) {
|
|
1004
|
+
let writer;
|
|
983
1005
|
try {
|
|
1006
|
+
writer = writable.getWriter();
|
|
984
1007
|
const text = new TextDecoder().decode(chunk);
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
1008
|
+
const lines = text.split("\n\n");
|
|
1009
|
+
const readableLines = lines.filter((line) => line !== "[DONE]").join("\n\n");
|
|
1010
|
+
await writer.write(new TextEncoder().encode(readableLines));
|
|
988
1011
|
} catch {
|
|
989
|
-
|
|
990
|
-
const writer = writable.getWriter();
|
|
991
|
-
try {
|
|
992
|
-
await writer.write(chunk);
|
|
1012
|
+
await writer?.write(chunk);
|
|
993
1013
|
} finally {
|
|
994
|
-
writer
|
|
1014
|
+
writer?.releaseLock();
|
|
995
1015
|
}
|
|
996
1016
|
}
|
|
997
1017
|
}),
|
|
@@ -1059,7 +1079,7 @@ var Agent = class extends BaseResource {
|
|
|
1059
1079
|
toolInvocation.result = result;
|
|
1060
1080
|
}
|
|
1061
1081
|
const updatedMessages = lastMessage != null ? [...messages.filter((m) => m.id !== lastMessage.id), lastMessage] : [...messages];
|
|
1062
|
-
this.
|
|
1082
|
+
this.processStreamResponse(
|
|
1063
1083
|
{
|
|
1064
1084
|
...processedParams,
|
|
1065
1085
|
messages: updatedMessages
|
|
@@ -1126,7 +1146,6 @@ var Agent = class extends BaseResource {
|
|
|
1126
1146
|
}
|
|
1127
1147
|
const processedParams = {
|
|
1128
1148
|
...params,
|
|
1129
|
-
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
1130
1149
|
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
1131
1150
|
clientTools: processClientTools(params.clientTools),
|
|
1132
1151
|
structuredOutput: params.structuredOutput ? {
|
|
@@ -1135,7 +1154,43 @@ var Agent = class extends BaseResource {
|
|
|
1135
1154
|
} : void 0
|
|
1136
1155
|
};
|
|
1137
1156
|
const { readable, writable } = new TransformStream();
|
|
1138
|
-
const response = await this.
|
|
1157
|
+
const response = await this.processStreamResponse(processedParams, writable);
|
|
1158
|
+
const streamResponse = new Response(readable, {
|
|
1159
|
+
status: response.status,
|
|
1160
|
+
statusText: response.statusText,
|
|
1161
|
+
headers: response.headers
|
|
1162
|
+
});
|
|
1163
|
+
streamResponse.processDataStream = async ({
|
|
1164
|
+
onChunk
|
|
1165
|
+
}) => {
|
|
1166
|
+
await processMastraStream({
|
|
1167
|
+
stream: streamResponse.body,
|
|
1168
|
+
onChunk
|
|
1169
|
+
});
|
|
1170
|
+
};
|
|
1171
|
+
return streamResponse;
|
|
1172
|
+
}
|
|
1173
|
+
async approveToolCall(params) {
|
|
1174
|
+
const { readable, writable } = new TransformStream();
|
|
1175
|
+
const response = await this.processStreamResponse(params, writable, "approve-tool-call");
|
|
1176
|
+
const streamResponse = new Response(readable, {
|
|
1177
|
+
status: response.status,
|
|
1178
|
+
statusText: response.statusText,
|
|
1179
|
+
headers: response.headers
|
|
1180
|
+
});
|
|
1181
|
+
streamResponse.processDataStream = async ({
|
|
1182
|
+
onChunk
|
|
1183
|
+
}) => {
|
|
1184
|
+
await processMastraStream({
|
|
1185
|
+
stream: streamResponse.body,
|
|
1186
|
+
onChunk
|
|
1187
|
+
});
|
|
1188
|
+
};
|
|
1189
|
+
return streamResponse;
|
|
1190
|
+
}
|
|
1191
|
+
async declineToolCall(params) {
|
|
1192
|
+
const { readable, writable } = new TransformStream();
|
|
1193
|
+
const response = await this.processStreamResponse(params, writable, "decline-tool-call");
|
|
1139
1194
|
const streamResponse = new Response(readable, {
|
|
1140
1195
|
status: response.status,
|
|
1141
1196
|
statusText: response.statusText,
|
|
@@ -1154,7 +1209,7 @@ var Agent = class extends BaseResource {
|
|
|
1154
1209
|
/**
|
|
1155
1210
|
* Processes the stream response and handles tool calls
|
|
1156
1211
|
*/
|
|
1157
|
-
async
|
|
1212
|
+
async processStreamResponseLegacy(processedParams, writable) {
|
|
1158
1213
|
const response = await this.request(`/api/agents/${this.agentId}/stream-legacy`, {
|
|
1159
1214
|
method: "POST",
|
|
1160
1215
|
body: processedParams,
|
|
@@ -1239,7 +1294,7 @@ var Agent = class extends BaseResource {
|
|
|
1239
1294
|
} finally {
|
|
1240
1295
|
writer.releaseLock();
|
|
1241
1296
|
}
|
|
1242
|
-
this.
|
|
1297
|
+
this.processStreamResponseLegacy(
|
|
1243
1298
|
{
|
|
1244
1299
|
...processedParams,
|
|
1245
1300
|
messages: [...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
|
|
@@ -1356,34 +1411,44 @@ var MemoryThread = class extends BaseResource {
|
|
|
1356
1411
|
}
|
|
1357
1412
|
/**
|
|
1358
1413
|
* Retrieves the memory thread details
|
|
1414
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1359
1415
|
* @returns Promise containing thread details including title and metadata
|
|
1360
1416
|
*/
|
|
1361
|
-
get() {
|
|
1362
|
-
return this.request(
|
|
1417
|
+
get(runtimeContext) {
|
|
1418
|
+
return this.request(
|
|
1419
|
+
`/api/memory/threads/${this.threadId}?agentId=${this.agentId}${runtimeContextQueryString(runtimeContext, "&")}`
|
|
1420
|
+
);
|
|
1363
1421
|
}
|
|
1364
1422
|
/**
|
|
1365
1423
|
* Updates the memory thread properties
|
|
1366
|
-
* @param params - Update parameters including title and
|
|
1424
|
+
* @param params - Update parameters including title, metadata, and optional runtime context
|
|
1367
1425
|
* @returns Promise containing updated thread details
|
|
1368
1426
|
*/
|
|
1369
1427
|
update(params) {
|
|
1370
|
-
return this.request(
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1428
|
+
return this.request(
|
|
1429
|
+
`/api/memory/threads/${this.threadId}?agentId=${this.agentId}${runtimeContextQueryString(params.runtimeContext, "&")}`,
|
|
1430
|
+
{
|
|
1431
|
+
method: "PATCH",
|
|
1432
|
+
body: params
|
|
1433
|
+
}
|
|
1434
|
+
);
|
|
1374
1435
|
}
|
|
1375
1436
|
/**
|
|
1376
1437
|
* Deletes the memory thread
|
|
1438
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1377
1439
|
* @returns Promise containing deletion result
|
|
1378
1440
|
*/
|
|
1379
|
-
delete() {
|
|
1380
|
-
return this.request(
|
|
1381
|
-
|
|
1382
|
-
|
|
1441
|
+
delete(runtimeContext) {
|
|
1442
|
+
return this.request(
|
|
1443
|
+
`/api/memory/threads/${this.threadId}?agentId=${this.agentId}${runtimeContextQueryString(runtimeContext, "&")}`,
|
|
1444
|
+
{
|
|
1445
|
+
method: "DELETE"
|
|
1446
|
+
}
|
|
1447
|
+
);
|
|
1383
1448
|
}
|
|
1384
1449
|
/**
|
|
1385
1450
|
* Retrieves messages associated with the thread
|
|
1386
|
-
* @param params - Optional parameters including limit for number of messages to retrieve
|
|
1451
|
+
* @param params - Optional parameters including limit for number of messages to retrieve and runtime context
|
|
1387
1452
|
* @returns Promise containing thread messages and UI messages
|
|
1388
1453
|
*/
|
|
1389
1454
|
getMessages(params) {
|
|
@@ -1391,37 +1456,46 @@ var MemoryThread = class extends BaseResource {
|
|
|
1391
1456
|
agentId: this.agentId,
|
|
1392
1457
|
...params?.limit ? { limit: params.limit.toString() } : {}
|
|
1393
1458
|
});
|
|
1394
|
-
return this.request(
|
|
1459
|
+
return this.request(
|
|
1460
|
+
`/api/memory/threads/${this.threadId}/messages?${query.toString()}${runtimeContextQueryString(params?.runtimeContext, "&")}`
|
|
1461
|
+
);
|
|
1395
1462
|
}
|
|
1396
1463
|
/**
|
|
1397
1464
|
* Retrieves paginated messages associated with the thread with advanced filtering and selection options
|
|
1398
|
-
* @param params - Pagination parameters including selectBy criteria, page, perPage, date ranges,
|
|
1465
|
+
* @param params - Pagination parameters including selectBy criteria, page, perPage, date ranges, message inclusion options, and runtime context
|
|
1399
1466
|
* @returns Promise containing paginated thread messages with pagination metadata (total, page, perPage, hasMore)
|
|
1400
1467
|
*/
|
|
1401
1468
|
getMessagesPaginated({
|
|
1402
1469
|
selectBy,
|
|
1470
|
+
runtimeContext,
|
|
1403
1471
|
...rest
|
|
1404
1472
|
}) {
|
|
1405
1473
|
const query = new URLSearchParams({
|
|
1406
1474
|
...rest,
|
|
1407
1475
|
...selectBy ? { selectBy: JSON.stringify(selectBy) } : {}
|
|
1408
1476
|
});
|
|
1409
|
-
return this.request(
|
|
1477
|
+
return this.request(
|
|
1478
|
+
`/api/memory/threads/${this.threadId}/messages/paginated?${query.toString()}${runtimeContextQueryString(runtimeContext, "&")}`
|
|
1479
|
+
);
|
|
1410
1480
|
}
|
|
1411
1481
|
/**
|
|
1412
1482
|
* Deletes one or more messages from the thread
|
|
1413
1483
|
* @param messageIds - Can be a single message ID (string), array of message IDs,
|
|
1414
1484
|
* message object with id property, or array of message objects
|
|
1485
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1415
1486
|
* @returns Promise containing deletion result
|
|
1416
1487
|
*/
|
|
1417
|
-
deleteMessages(messageIds) {
|
|
1488
|
+
deleteMessages(messageIds, runtimeContext) {
|
|
1418
1489
|
const query = new URLSearchParams({
|
|
1419
1490
|
agentId: this.agentId
|
|
1420
1491
|
});
|
|
1421
|
-
return this.request(
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1492
|
+
return this.request(
|
|
1493
|
+
`/api/memory/messages/delete?${query.toString()}${runtimeContextQueryString(runtimeContext, "&")}`,
|
|
1494
|
+
{
|
|
1495
|
+
method: "POST",
|
|
1496
|
+
body: { messageIds }
|
|
1497
|
+
}
|
|
1498
|
+
);
|
|
1425
1499
|
}
|
|
1426
1500
|
};
|
|
1427
1501
|
|
|
@@ -2259,6 +2333,35 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2259
2333
|
};
|
|
2260
2334
|
}
|
|
2261
2335
|
}
|
|
2336
|
+
/**
|
|
2337
|
+
* Creates a transform stream that parses binary chunks into JSON records.
|
|
2338
|
+
*/
|
|
2339
|
+
createRecordParserTransform() {
|
|
2340
|
+
let failedChunk = void 0;
|
|
2341
|
+
return new TransformStream({
|
|
2342
|
+
start() {
|
|
2343
|
+
},
|
|
2344
|
+
async transform(chunk, controller) {
|
|
2345
|
+
try {
|
|
2346
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
2347
|
+
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
2348
|
+
for (const chunk2 of chunks) {
|
|
2349
|
+
if (chunk2) {
|
|
2350
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
2351
|
+
try {
|
|
2352
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
2353
|
+
controller.enqueue(parsedChunk);
|
|
2354
|
+
failedChunk = void 0;
|
|
2355
|
+
} catch {
|
|
2356
|
+
failedChunk = newChunk;
|
|
2357
|
+
}
|
|
2358
|
+
}
|
|
2359
|
+
}
|
|
2360
|
+
} catch {
|
|
2361
|
+
}
|
|
2362
|
+
}
|
|
2363
|
+
});
|
|
2364
|
+
}
|
|
2262
2365
|
/**
|
|
2263
2366
|
* @deprecated Use createRunAsync() instead.
|
|
2264
2367
|
* @throws {Error} Always throws an error directing users to use createRunAsync()
|
|
@@ -2414,31 +2517,7 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2414
2517
|
if (!response.body) {
|
|
2415
2518
|
throw new Error("Response body is null");
|
|
2416
2519
|
}
|
|
2417
|
-
|
|
2418
|
-
const transformStream = new TransformStream({
|
|
2419
|
-
start() {
|
|
2420
|
-
},
|
|
2421
|
-
async transform(chunk, controller) {
|
|
2422
|
-
try {
|
|
2423
|
-
const decoded = new TextDecoder().decode(chunk);
|
|
2424
|
-
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
2425
|
-
for (const chunk2 of chunks) {
|
|
2426
|
-
if (chunk2) {
|
|
2427
|
-
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
2428
|
-
try {
|
|
2429
|
-
const parsedChunk = JSON.parse(newChunk);
|
|
2430
|
-
controller.enqueue(parsedChunk);
|
|
2431
|
-
failedChunk = void 0;
|
|
2432
|
-
} catch {
|
|
2433
|
-
failedChunk = newChunk;
|
|
2434
|
-
}
|
|
2435
|
-
}
|
|
2436
|
-
}
|
|
2437
|
-
} catch {
|
|
2438
|
-
}
|
|
2439
|
-
}
|
|
2440
|
-
});
|
|
2441
|
-
return response.body.pipeThrough(transformStream);
|
|
2520
|
+
return response.body.pipeThrough(this.createRecordParserTransform());
|
|
2442
2521
|
}
|
|
2443
2522
|
/**
|
|
2444
2523
|
* Streams agent builder action progress in real-time using VNext streaming.
|
|
@@ -2463,31 +2542,7 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2463
2542
|
if (!response.body) {
|
|
2464
2543
|
throw new Error("Response body is null");
|
|
2465
2544
|
}
|
|
2466
|
-
|
|
2467
|
-
const transformStream = new TransformStream({
|
|
2468
|
-
start() {
|
|
2469
|
-
},
|
|
2470
|
-
async transform(chunk, controller) {
|
|
2471
|
-
try {
|
|
2472
|
-
const decoded = new TextDecoder().decode(chunk);
|
|
2473
|
-
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
2474
|
-
for (const chunk2 of chunks) {
|
|
2475
|
-
if (chunk2) {
|
|
2476
|
-
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
2477
|
-
try {
|
|
2478
|
-
const parsedChunk = JSON.parse(newChunk);
|
|
2479
|
-
controller.enqueue(parsedChunk);
|
|
2480
|
-
failedChunk = void 0;
|
|
2481
|
-
} catch {
|
|
2482
|
-
failedChunk = newChunk;
|
|
2483
|
-
}
|
|
2484
|
-
}
|
|
2485
|
-
}
|
|
2486
|
-
} catch {
|
|
2487
|
-
}
|
|
2488
|
-
}
|
|
2489
|
-
});
|
|
2490
|
-
return response.body.pipeThrough(transformStream);
|
|
2545
|
+
return response.body.pipeThrough(this.createRecordParserTransform());
|
|
2491
2546
|
}
|
|
2492
2547
|
/**
|
|
2493
2548
|
* Watches an existing agent builder action run by runId.
|
|
@@ -2515,6 +2570,93 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2515
2570
|
}
|
|
2516
2571
|
}
|
|
2517
2572
|
}
|
|
2573
|
+
/**
|
|
2574
|
+
* Observes an existing agent builder action run stream.
|
|
2575
|
+
* Replays cached execution from the beginning, then continues with live stream.
|
|
2576
|
+
* This is the recommended method for recovery after page refresh/hot reload.
|
|
2577
|
+
* This calls `/api/agent-builder/:actionId/observe` (which delegates to observeStreamVNext).
|
|
2578
|
+
*/
|
|
2579
|
+
async observeStream(params) {
|
|
2580
|
+
const searchParams = new URLSearchParams();
|
|
2581
|
+
searchParams.set("runId", params.runId);
|
|
2582
|
+
const url = `/api/agent-builder/${this.actionId}/observe?${searchParams.toString()}`;
|
|
2583
|
+
const response = await this.request(url, {
|
|
2584
|
+
method: "POST",
|
|
2585
|
+
stream: true
|
|
2586
|
+
});
|
|
2587
|
+
if (!response.ok) {
|
|
2588
|
+
throw new Error(`Failed to observe agent builder action stream: ${response.statusText}`);
|
|
2589
|
+
}
|
|
2590
|
+
if (!response.body) {
|
|
2591
|
+
throw new Error("Response body is null");
|
|
2592
|
+
}
|
|
2593
|
+
return response.body.pipeThrough(this.createRecordParserTransform());
|
|
2594
|
+
}
|
|
2595
|
+
/**
|
|
2596
|
+
* Observes an existing agent builder action run stream using VNext streaming API.
|
|
2597
|
+
* Replays cached execution from the beginning, then continues with live stream.
|
|
2598
|
+
* This calls `/api/agent-builder/:actionId/observe-streamVNext`.
|
|
2599
|
+
*/
|
|
2600
|
+
async observeStreamVNext(params) {
|
|
2601
|
+
const searchParams = new URLSearchParams();
|
|
2602
|
+
searchParams.set("runId", params.runId);
|
|
2603
|
+
const url = `/api/agent-builder/${this.actionId}/observe-streamVNext?${searchParams.toString()}`;
|
|
2604
|
+
const response = await this.request(url, {
|
|
2605
|
+
method: "POST",
|
|
2606
|
+
stream: true
|
|
2607
|
+
});
|
|
2608
|
+
if (!response.ok) {
|
|
2609
|
+
throw new Error(`Failed to observe agent builder action stream VNext: ${response.statusText}`);
|
|
2610
|
+
}
|
|
2611
|
+
if (!response.body) {
|
|
2612
|
+
throw new Error("Response body is null");
|
|
2613
|
+
}
|
|
2614
|
+
return response.body.pipeThrough(this.createRecordParserTransform());
|
|
2615
|
+
}
|
|
2616
|
+
/**
|
|
2617
|
+
* Observes an existing agent builder action run stream using legacy streaming API.
|
|
2618
|
+
* Replays cached execution from the beginning, then continues with live stream.
|
|
2619
|
+
* This calls `/api/agent-builder/:actionId/observe-stream-legacy`.
|
|
2620
|
+
*/
|
|
2621
|
+
async observeStreamLegacy(params) {
|
|
2622
|
+
const searchParams = new URLSearchParams();
|
|
2623
|
+
searchParams.set("runId", params.runId);
|
|
2624
|
+
const url = `/api/agent-builder/${this.actionId}/observe-stream-legacy?${searchParams.toString()}`;
|
|
2625
|
+
const response = await this.request(url, {
|
|
2626
|
+
method: "POST",
|
|
2627
|
+
stream: true
|
|
2628
|
+
});
|
|
2629
|
+
if (!response.ok) {
|
|
2630
|
+
throw new Error(`Failed to observe agent builder action stream legacy: ${response.statusText}`);
|
|
2631
|
+
}
|
|
2632
|
+
if (!response.body) {
|
|
2633
|
+
throw new Error("Response body is null");
|
|
2634
|
+
}
|
|
2635
|
+
return response.body.pipeThrough(this.createRecordParserTransform());
|
|
2636
|
+
}
|
|
2637
|
+
/**
|
|
2638
|
+
* Resumes a suspended agent builder action and streams the results.
|
|
2639
|
+
* This calls `/api/agent-builder/:actionId/resume-stream`.
|
|
2640
|
+
*/
|
|
2641
|
+
async resumeStream(params) {
|
|
2642
|
+
const searchParams = new URLSearchParams();
|
|
2643
|
+
searchParams.set("runId", params.runId);
|
|
2644
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
2645
|
+
const { runId: _, runtimeContext: __, ...resumeParams } = params;
|
|
2646
|
+
const url = `/api/agent-builder/${this.actionId}/resume-stream?${searchParams.toString()}`;
|
|
2647
|
+
const response = await this.request(url, {
|
|
2648
|
+
method: "POST",
|
|
2649
|
+
body: { ...resumeParams, runtimeContext },
|
|
2650
|
+
stream: true
|
|
2651
|
+
});
|
|
2652
|
+
if (!response.ok) {
|
|
2653
|
+
throw new Error(`Failed to resume agent builder action stream: ${response.statusText}`);
|
|
2654
|
+
}
|
|
2655
|
+
if (!response.body) {
|
|
2656
|
+
throw new Error("Response body is null");
|
|
2657
|
+
}
|
|
2658
|
+
return response.body.pipeThrough(this.createRecordParserTransform());
|
|
2659
|
+
}
|
|
2518
2660
|
/**
|
|
2519
2661
|
* Gets a specific action run by its ID.
|
|
2520
2662
|
* This calls `/api/agent-builder/:actionId/runs/:runId`.
|
|
@@ -2752,6 +2894,9 @@ var MastraClient = class extends BaseResource {
|
|
|
2752
2894
|
const queryString = searchParams.toString();
|
|
2753
2895
|
return this.request(`/api/agents${queryString ? `?${queryString}` : ""}`);
|
|
2754
2896
|
}
|
|
2897
|
+
getAgentsModelProviders() {
|
|
2898
|
+
return this.request(`/api/agents/providers`);
|
|
2899
|
+
}
|
|
2755
2900
|
/**
|
|
2756
2901
|
* Gets an agent instance by ID
|
|
2757
2902
|
* @param agentId - ID of the agent to retrieve
|
|
@@ -2762,27 +2907,34 @@ var MastraClient = class extends BaseResource {
|
|
|
2762
2907
|
}
|
|
2763
2908
|
/**
|
|
2764
2909
|
* Retrieves memory threads for a resource
|
|
2765
|
-
* @param params - Parameters containing the resource ID
|
|
2910
|
+
* @param params - Parameters containing the resource ID and optional runtime context
|
|
2766
2911
|
* @returns Promise containing array of memory threads
|
|
2767
2912
|
*/
|
|
2768
2913
|
getMemoryThreads(params) {
|
|
2769
|
-
return this.request(
|
|
2914
|
+
return this.request(
|
|
2915
|
+
`/api/memory/threads?resourceid=${params.resourceId}&agentId=${params.agentId}${runtimeContextQueryString(params.runtimeContext, "&")}`
|
|
2916
|
+
);
|
|
2770
2917
|
}
|
|
2771
2918
|
/**
|
|
2772
2919
|
* Retrieves memory config for a resource
|
|
2773
|
-
* @param params - Parameters containing the resource ID
|
|
2774
|
-
* @returns Promise containing
|
|
2920
|
+
* @param params - Parameters containing the resource ID and optional runtime context
|
|
2921
|
+
* @returns Promise containing memory configuration
|
|
2775
2922
|
*/
|
|
2776
2923
|
getMemoryConfig(params) {
|
|
2777
|
-
return this.request(
|
|
2924
|
+
return this.request(
|
|
2925
|
+
`/api/memory/config?agentId=${params.agentId}${runtimeContextQueryString(params.runtimeContext, "&")}`
|
|
2926
|
+
);
|
|
2778
2927
|
}
|
|
2779
2928
|
/**
|
|
2780
2929
|
* Creates a new memory thread
|
|
2781
|
-
* @param params - Parameters for creating the memory thread
|
|
2930
|
+
* @param params - Parameters for creating the memory thread including optional runtime context
|
|
2782
2931
|
* @returns Promise containing the created memory thread
|
|
2783
2932
|
*/
|
|
2784
2933
|
createMemoryThread(params) {
|
|
2785
|
-
return this.request(
|
|
2934
|
+
return this.request(
|
|
2935
|
+
`/api/memory/threads?agentId=${params.agentId}${runtimeContextQueryString(params.runtimeContext, "&")}`,
|
|
2936
|
+
{ method: "POST", body: params }
|
|
2937
|
+
);
|
|
2786
2938
|
}
|
|
2787
2939
|
/**
|
|
2788
2940
|
* Gets a memory thread instance by ID
|
|
@@ -2795,38 +2947,43 @@ var MastraClient = class extends BaseResource {
|
|
|
2795
2947
|
getThreadMessages(threadId, opts = {}) {
|
|
2796
2948
|
let url = "";
|
|
2797
2949
|
if (opts.agentId) {
|
|
2798
|
-
url = `/api/memory/threads/${threadId}/messages?agentId=${opts.agentId}`;
|
|
2950
|
+
url = `/api/memory/threads/${threadId}/messages?agentId=${opts.agentId}${runtimeContextQueryString(opts.runtimeContext, "&")}`;
|
|
2799
2951
|
} else if (opts.networkId) {
|
|
2800
|
-
url = `/api/memory/network/threads/${threadId}/messages?networkId=${opts.networkId}`;
|
|
2952
|
+
url = `/api/memory/network/threads/${threadId}/messages?networkId=${opts.networkId}${runtimeContextQueryString(opts.runtimeContext, "&")}`;
|
|
2801
2953
|
}
|
|
2802
2954
|
return this.request(url);
|
|
2803
2955
|
}
|
|
2804
2956
|
deleteThread(threadId, opts = {}) {
|
|
2805
2957
|
let url = "";
|
|
2806
2958
|
if (opts.agentId) {
|
|
2807
|
-
url = `/api/memory/threads/${threadId}?agentId=${opts.agentId}`;
|
|
2959
|
+
url = `/api/memory/threads/${threadId}?agentId=${opts.agentId}${runtimeContextQueryString(opts.runtimeContext, "&")}`;
|
|
2808
2960
|
} else if (opts.networkId) {
|
|
2809
|
-
url = `/api/memory/network/threads/${threadId}?networkId=${opts.networkId}`;
|
|
2961
|
+
url = `/api/memory/network/threads/${threadId}?networkId=${opts.networkId}${runtimeContextQueryString(opts.runtimeContext, "&")}`;
|
|
2810
2962
|
}
|
|
2811
2963
|
return this.request(url, { method: "DELETE" });
|
|
2812
2964
|
}
|
|
2813
2965
|
/**
|
|
2814
2966
|
* Saves messages to memory
|
|
2815
|
-
* @param params - Parameters containing messages to save
|
|
2967
|
+
* @param params - Parameters containing messages to save and optional runtime context
|
|
2816
2968
|
* @returns Promise containing the saved messages
|
|
2817
2969
|
*/
|
|
2818
2970
|
saveMessageToMemory(params) {
|
|
2819
|
-
return this.request(
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2971
|
+
return this.request(
|
|
2972
|
+
`/api/memory/save-messages?agentId=${params.agentId}${runtimeContextQueryString(params.runtimeContext, "&")}`,
|
|
2973
|
+
{
|
|
2974
|
+
method: "POST",
|
|
2975
|
+
body: params
|
|
2976
|
+
}
|
|
2977
|
+
);
|
|
2823
2978
|
}
|
|
2824
2979
|
/**
|
|
2825
2980
|
* Gets the status of the memory system
|
|
2981
|
+
* @param agentId - The agent ID
|
|
2982
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2826
2983
|
* @returns Promise containing memory system status
|
|
2827
2984
|
*/
|
|
2828
|
-
getMemoryStatus(agentId) {
|
|
2829
|
-
return this.request(`/api/memory/status?agentId=${agentId}`);
|
|
2985
|
+
getMemoryStatus(agentId, runtimeContext) {
|
|
2986
|
+
return this.request(`/api/memory/status?agentId=${agentId}${runtimeContextQueryString(runtimeContext, "&")}`);
|
|
2830
2987
|
}
|
|
2831
2988
|
/**
|
|
2832
2989
|
* Retrieves memory threads for a resource
|
|
@@ -3030,48 +3187,6 @@ var MastraClient = class extends BaseResource {
|
|
|
3030
3187
|
getLogTransports() {
|
|
3031
3188
|
return this.request("/api/logs/transports");
|
|
3032
3189
|
}
|
|
3033
|
-
/**
|
|
3034
|
-
* List of all traces (paged)
|
|
3035
|
-
* @param params - Parameters for filtering traces
|
|
3036
|
-
* @returns Promise containing telemetry data
|
|
3037
|
-
*/
|
|
3038
|
-
getTelemetry(params) {
|
|
3039
|
-
const { name, scope, page, perPage, attribute, fromDate, toDate } = params || {};
|
|
3040
|
-
const _attribute = attribute ? Object.entries(attribute).map(([key, value]) => `${key}:${value}`) : [];
|
|
3041
|
-
const searchParams = new URLSearchParams();
|
|
3042
|
-
if (name) {
|
|
3043
|
-
searchParams.set("name", name);
|
|
3044
|
-
}
|
|
3045
|
-
if (scope) {
|
|
3046
|
-
searchParams.set("scope", scope);
|
|
3047
|
-
}
|
|
3048
|
-
if (page) {
|
|
3049
|
-
searchParams.set("page", String(page));
|
|
3050
|
-
}
|
|
3051
|
-
if (perPage) {
|
|
3052
|
-
searchParams.set("perPage", String(perPage));
|
|
3053
|
-
}
|
|
3054
|
-
if (_attribute) {
|
|
3055
|
-
if (Array.isArray(_attribute)) {
|
|
3056
|
-
for (const attr of _attribute) {
|
|
3057
|
-
searchParams.append("attribute", attr);
|
|
3058
|
-
}
|
|
3059
|
-
} else {
|
|
3060
|
-
searchParams.set("attribute", _attribute);
|
|
3061
|
-
}
|
|
3062
|
-
}
|
|
3063
|
-
if (fromDate) {
|
|
3064
|
-
searchParams.set("fromDate", fromDate.toISOString());
|
|
3065
|
-
}
|
|
3066
|
-
if (toDate) {
|
|
3067
|
-
searchParams.set("toDate", toDate.toISOString());
|
|
3068
|
-
}
|
|
3069
|
-
if (searchParams.size) {
|
|
3070
|
-
return this.request(`/api/telemetry?${searchParams}`);
|
|
3071
|
-
} else {
|
|
3072
|
-
return this.request(`/api/telemetry`);
|
|
3073
|
-
}
|
|
3074
|
-
}
|
|
3075
3190
|
/**
|
|
3076
3191
|
* Retrieves a list of available MCP servers.
|
|
3077
3192
|
* @param params - Optional parameters for pagination (limit, offset).
|
|
@@ -3138,9 +3253,33 @@ var MastraClient = class extends BaseResource {
|
|
|
3138
3253
|
getWorkingMemory({
|
|
3139
3254
|
agentId,
|
|
3140
3255
|
threadId,
|
|
3141
|
-
resourceId
|
|
3256
|
+
resourceId,
|
|
3257
|
+
runtimeContext
|
|
3142
3258
|
}) {
|
|
3143
|
-
return this.request(
|
|
3259
|
+
return this.request(
|
|
3260
|
+
`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}${runtimeContextQueryString(runtimeContext, "&")}`
|
|
3261
|
+
);
|
|
3262
|
+
}
|
|
3263
|
+
searchMemory({
|
|
3264
|
+
agentId,
|
|
3265
|
+
resourceId,
|
|
3266
|
+
threadId,
|
|
3267
|
+
searchQuery,
|
|
3268
|
+
memoryConfig,
|
|
3269
|
+
runtimeContext
|
|
3270
|
+
}) {
|
|
3271
|
+
const params = new URLSearchParams({
|
|
3272
|
+
searchQuery,
|
|
3273
|
+
resourceId,
|
|
3274
|
+
agentId
|
|
3275
|
+
});
|
|
3276
|
+
if (threadId) {
|
|
3277
|
+
params.append("threadId", threadId);
|
|
3278
|
+
}
|
|
3279
|
+
if (memoryConfig) {
|
|
3280
|
+
params.append("memoryConfig", JSON.stringify(memoryConfig));
|
|
3281
|
+
}
|
|
3282
|
+
return this.request(`/api/memory/search?${params}${runtimeContextQueryString(runtimeContext, "&")}`);
|
|
3144
3283
|
}
|
|
3145
3284
|
/**
|
|
3146
3285
|
* Updates the working memory for a specific thread (optionally resource-scoped).
|
|
@@ -3153,15 +3292,19 @@ var MastraClient = class extends BaseResource {
|
|
|
3153
3292
|
agentId,
|
|
3154
3293
|
threadId,
|
|
3155
3294
|
workingMemory,
|
|
3156
|
-
resourceId
|
|
3295
|
+
resourceId,
|
|
3296
|
+
runtimeContext
|
|
3157
3297
|
}) {
|
|
3158
|
-
return this.request(
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3298
|
+
return this.request(
|
|
3299
|
+
`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}${runtimeContextQueryString(runtimeContext, "&")}`,
|
|
3300
|
+
{
|
|
3301
|
+
method: "POST",
|
|
3302
|
+
body: {
|
|
3303
|
+
workingMemory,
|
|
3304
|
+
resourceId
|
|
3305
|
+
}
|
|
3163
3306
|
}
|
|
3164
|
-
|
|
3307
|
+
);
|
|
3165
3308
|
}
|
|
3166
3309
|
/**
|
|
3167
3310
|
* Retrieves all available scorers
|