@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/dist/index.cjs CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  var uiUtils = require('@ai-sdk/ui-utils');
4
4
  var uuid = require('@lukeed/uuid');
5
+ var error = require('@mastra/core/error');
5
6
  var runtimeContext = require('@mastra/core/runtime-context');
6
7
  var isVercelTool = require('@mastra/core/tools/is-vercel-tool');
7
8
  var zod = require('zod');
@@ -27,13 +28,13 @@ function base64RuntimeContext(runtimeContext) {
27
28
  }
28
29
  return void 0;
29
30
  }
30
- function runtimeContextQueryString(runtimeContext) {
31
+ function runtimeContextQueryString(runtimeContext, delimiter = "?") {
31
32
  const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
32
33
  if (!runtimeContextParam) return "";
33
34
  const searchParams = new URLSearchParams();
34
35
  searchParams.set("runtimeContext", runtimeContextParam);
35
36
  const queryString = searchParams.toString();
36
- return queryString ? `?${queryString}` : "";
37
+ return queryString ? `${delimiter}${queryString}` : "";
37
38
  }
38
39
  function isZodType(value) {
39
40
  return typeof value === "object" && value !== null && "_def" in value && "parse" in value && typeof value.parse === "function" && "safeParse" in value && typeof value.safeParse === "function";
@@ -100,11 +101,15 @@ async function sharedProcessMastraStream({
100
101
  console.info("\u{1F3C1} Stream finished");
101
102
  return;
102
103
  }
104
+ let json;
103
105
  try {
104
- const json = JSON.parse(data);
105
- await onChunk(json);
106
+ json = JSON.parse(data);
106
107
  } catch (error) {
107
108
  console.error("\u274C JSON parse error:", error, "Data:", data);
109
+ continue;
110
+ }
111
+ if (json) {
112
+ await onChunk(json);
108
113
  }
109
114
  }
110
115
  }
@@ -323,6 +328,12 @@ var Agent = class extends BaseResource {
323
328
  details(runtimeContext) {
324
329
  return this.request(`/api/agents/${this.agentId}${runtimeContextQueryString(runtimeContext)}`);
325
330
  }
331
+ enhanceInstructions(instructions, comment) {
332
+ return this.request(`/api/agents/${this.agentId}/instructions/enhance`, {
333
+ method: "POST",
334
+ body: { instructions, comment }
335
+ });
336
+ }
326
337
  async generateLegacy(params) {
327
338
  const processedParams = {
328
339
  ...params,
@@ -398,7 +409,6 @@ var Agent = class extends BaseResource {
398
409
  }
399
410
  const processedParams = {
400
411
  ...params,
401
- output: params.output ? zodToJsonSchema(params.output) : void 0,
402
412
  runtimeContext: parseClientRuntimeContext(params.runtimeContext),
403
413
  clientTools: processClientTools(params.clientTools),
404
414
  structuredOutput: params.structuredOutput ? {
@@ -703,7 +713,7 @@ var Agent = class extends BaseResource {
703
713
  clientTools: processClientTools(params.clientTools)
704
714
  };
705
715
  const { readable, writable } = new TransformStream();
706
- const response = await this.processStreamResponse(processedParams, writable);
716
+ const response = await this.processStreamResponseLegacy(processedParams, writable);
707
717
  const streamResponse = new Response(readable, {
708
718
  status: response.status,
709
719
  statusText: response.statusText,
@@ -790,6 +800,14 @@ var Agent = class extends BaseResource {
790
800
  // but this is completely wrong and this fn is probably broken. Remove ":any" and you'll see a bunch of type errors
791
801
  onChunk: async (chunk) => {
792
802
  switch (chunk.type) {
803
+ case "tripwire": {
804
+ message.parts.push({
805
+ type: "text",
806
+ text: chunk.payload.tripwireReason
807
+ });
808
+ execUpdate();
809
+ break;
810
+ }
793
811
  case "step-start": {
794
812
  if (!replaceLastMessage) {
795
813
  message.id = chunk.payload.messageId;
@@ -943,7 +961,10 @@ var Agent = class extends BaseResource {
943
961
  break;
944
962
  }
945
963
  case "error": {
946
- throw new Error(chunk.payload.error);
964
+ throw error.getErrorFromUnknown(chunk.payload.error, {
965
+ fallbackMessage: "Unknown error in stream",
966
+ supportSerialization: false
967
+ });
947
968
  }
948
969
  case "data": {
949
970
  data.push(...chunk.payload.data);
@@ -970,8 +991,8 @@ var Agent = class extends BaseResource {
970
991
  });
971
992
  onFinish?.({ message, finishReason, usage });
972
993
  }
973
- async processStreamResponse_vNext(processedParams, writable) {
974
- const response = await this.request(`/api/agents/${this.agentId}/stream`, {
994
+ async processStreamResponse(processedParams, writable, route = "stream") {
995
+ const response = await this.request(`/api/agents/${this.agentId}/${route}`, {
975
996
  method: "POST",
976
997
  body: processedParams,
977
998
  stream: true
@@ -986,18 +1007,17 @@ var Agent = class extends BaseResource {
986
1007
  streamForWritable.pipeTo(
987
1008
  new WritableStream({
988
1009
  async write(chunk) {
1010
+ let writer;
989
1011
  try {
1012
+ writer = writable.getWriter();
990
1013
  const text = new TextDecoder().decode(chunk);
991
- if (text.includes("[DONE]")) {
992
- return;
993
- }
1014
+ const lines = text.split("\n\n");
1015
+ const readableLines = lines.filter((line) => line !== "[DONE]").join("\n\n");
1016
+ await writer.write(new TextEncoder().encode(readableLines));
994
1017
  } catch {
995
- }
996
- const writer = writable.getWriter();
997
- try {
998
- await writer.write(chunk);
1018
+ await writer?.write(chunk);
999
1019
  } finally {
1000
- writer.releaseLock();
1020
+ writer?.releaseLock();
1001
1021
  }
1002
1022
  }
1003
1023
  }),
@@ -1065,7 +1085,7 @@ var Agent = class extends BaseResource {
1065
1085
  toolInvocation.result = result;
1066
1086
  }
1067
1087
  const updatedMessages = lastMessage != null ? [...messages.filter((m) => m.id !== lastMessage.id), lastMessage] : [...messages];
1068
- this.processStreamResponse_vNext(
1088
+ this.processStreamResponse(
1069
1089
  {
1070
1090
  ...processedParams,
1071
1091
  messages: updatedMessages
@@ -1132,7 +1152,6 @@ var Agent = class extends BaseResource {
1132
1152
  }
1133
1153
  const processedParams = {
1134
1154
  ...params,
1135
- output: params.output ? zodToJsonSchema(params.output) : void 0,
1136
1155
  runtimeContext: parseClientRuntimeContext(params.runtimeContext),
1137
1156
  clientTools: processClientTools(params.clientTools),
1138
1157
  structuredOutput: params.structuredOutput ? {
@@ -1141,7 +1160,43 @@ var Agent = class extends BaseResource {
1141
1160
  } : void 0
1142
1161
  };
1143
1162
  const { readable, writable } = new TransformStream();
1144
- const response = await this.processStreamResponse_vNext(processedParams, writable);
1163
+ const response = await this.processStreamResponse(processedParams, writable);
1164
+ const streamResponse = new Response(readable, {
1165
+ status: response.status,
1166
+ statusText: response.statusText,
1167
+ headers: response.headers
1168
+ });
1169
+ streamResponse.processDataStream = async ({
1170
+ onChunk
1171
+ }) => {
1172
+ await processMastraStream({
1173
+ stream: streamResponse.body,
1174
+ onChunk
1175
+ });
1176
+ };
1177
+ return streamResponse;
1178
+ }
1179
+ async approveToolCall(params) {
1180
+ const { readable, writable } = new TransformStream();
1181
+ const response = await this.processStreamResponse(params, writable, "approve-tool-call");
1182
+ const streamResponse = new Response(readable, {
1183
+ status: response.status,
1184
+ statusText: response.statusText,
1185
+ headers: response.headers
1186
+ });
1187
+ streamResponse.processDataStream = async ({
1188
+ onChunk
1189
+ }) => {
1190
+ await processMastraStream({
1191
+ stream: streamResponse.body,
1192
+ onChunk
1193
+ });
1194
+ };
1195
+ return streamResponse;
1196
+ }
1197
+ async declineToolCall(params) {
1198
+ const { readable, writable } = new TransformStream();
1199
+ const response = await this.processStreamResponse(params, writable, "decline-tool-call");
1145
1200
  const streamResponse = new Response(readable, {
1146
1201
  status: response.status,
1147
1202
  statusText: response.statusText,
@@ -1160,7 +1215,7 @@ var Agent = class extends BaseResource {
1160
1215
  /**
1161
1216
  * Processes the stream response and handles tool calls
1162
1217
  */
1163
- async processStreamResponse(processedParams, writable) {
1218
+ async processStreamResponseLegacy(processedParams, writable) {
1164
1219
  const response = await this.request(`/api/agents/${this.agentId}/stream-legacy`, {
1165
1220
  method: "POST",
1166
1221
  body: processedParams,
@@ -1245,7 +1300,7 @@ var Agent = class extends BaseResource {
1245
1300
  } finally {
1246
1301
  writer.releaseLock();
1247
1302
  }
1248
- this.processStreamResponse(
1303
+ this.processStreamResponseLegacy(
1249
1304
  {
1250
1305
  ...processedParams,
1251
1306
  messages: [...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
@@ -1362,34 +1417,44 @@ var MemoryThread = class extends BaseResource {
1362
1417
  }
1363
1418
  /**
1364
1419
  * Retrieves the memory thread details
1420
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1365
1421
  * @returns Promise containing thread details including title and metadata
1366
1422
  */
1367
- get() {
1368
- return this.request(`/api/memory/threads/${this.threadId}?agentId=${this.agentId}`);
1423
+ get(runtimeContext) {
1424
+ return this.request(
1425
+ `/api/memory/threads/${this.threadId}?agentId=${this.agentId}${runtimeContextQueryString(runtimeContext, "&")}`
1426
+ );
1369
1427
  }
1370
1428
  /**
1371
1429
  * Updates the memory thread properties
1372
- * @param params - Update parameters including title and metadata
1430
+ * @param params - Update parameters including title, metadata, and optional runtime context
1373
1431
  * @returns Promise containing updated thread details
1374
1432
  */
1375
1433
  update(params) {
1376
- return this.request(`/api/memory/threads/${this.threadId}?agentId=${this.agentId}`, {
1377
- method: "PATCH",
1378
- body: params
1379
- });
1434
+ return this.request(
1435
+ `/api/memory/threads/${this.threadId}?agentId=${this.agentId}${runtimeContextQueryString(params.runtimeContext, "&")}`,
1436
+ {
1437
+ method: "PATCH",
1438
+ body: params
1439
+ }
1440
+ );
1380
1441
  }
1381
1442
  /**
1382
1443
  * Deletes the memory thread
1444
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1383
1445
  * @returns Promise containing deletion result
1384
1446
  */
1385
- delete() {
1386
- return this.request(`/api/memory/threads/${this.threadId}?agentId=${this.agentId}`, {
1387
- method: "DELETE"
1388
- });
1447
+ delete(runtimeContext) {
1448
+ return this.request(
1449
+ `/api/memory/threads/${this.threadId}?agentId=${this.agentId}${runtimeContextQueryString(runtimeContext, "&")}`,
1450
+ {
1451
+ method: "DELETE"
1452
+ }
1453
+ );
1389
1454
  }
1390
1455
  /**
1391
1456
  * Retrieves messages associated with the thread
1392
- * @param params - Optional parameters including limit for number of messages to retrieve
1457
+ * @param params - Optional parameters including limit for number of messages to retrieve and runtime context
1393
1458
  * @returns Promise containing thread messages and UI messages
1394
1459
  */
1395
1460
  getMessages(params) {
@@ -1397,37 +1462,46 @@ var MemoryThread = class extends BaseResource {
1397
1462
  agentId: this.agentId,
1398
1463
  ...params?.limit ? { limit: params.limit.toString() } : {}
1399
1464
  });
1400
- return this.request(`/api/memory/threads/${this.threadId}/messages?${query.toString()}`);
1465
+ return this.request(
1466
+ `/api/memory/threads/${this.threadId}/messages?${query.toString()}${runtimeContextQueryString(params?.runtimeContext, "&")}`
1467
+ );
1401
1468
  }
1402
1469
  /**
1403
1470
  * Retrieves paginated messages associated with the thread with advanced filtering and selection options
1404
- * @param params - Pagination parameters including selectBy criteria, page, perPage, date ranges, and message inclusion options
1471
+ * @param params - Pagination parameters including selectBy criteria, page, perPage, date ranges, message inclusion options, and runtime context
1405
1472
  * @returns Promise containing paginated thread messages with pagination metadata (total, page, perPage, hasMore)
1406
1473
  */
1407
1474
  getMessagesPaginated({
1408
1475
  selectBy,
1476
+ runtimeContext,
1409
1477
  ...rest
1410
1478
  }) {
1411
1479
  const query = new URLSearchParams({
1412
1480
  ...rest,
1413
1481
  ...selectBy ? { selectBy: JSON.stringify(selectBy) } : {}
1414
1482
  });
1415
- return this.request(`/api/memory/threads/${this.threadId}/messages/paginated?${query.toString()}`);
1483
+ return this.request(
1484
+ `/api/memory/threads/${this.threadId}/messages/paginated?${query.toString()}${runtimeContextQueryString(runtimeContext, "&")}`
1485
+ );
1416
1486
  }
1417
1487
  /**
1418
1488
  * Deletes one or more messages from the thread
1419
1489
  * @param messageIds - Can be a single message ID (string), array of message IDs,
1420
1490
  * message object with id property, or array of message objects
1491
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1421
1492
  * @returns Promise containing deletion result
1422
1493
  */
1423
- deleteMessages(messageIds) {
1494
+ deleteMessages(messageIds, runtimeContext) {
1424
1495
  const query = new URLSearchParams({
1425
1496
  agentId: this.agentId
1426
1497
  });
1427
- return this.request(`/api/memory/messages/delete?${query.toString()}`, {
1428
- method: "POST",
1429
- body: { messageIds }
1430
- });
1498
+ return this.request(
1499
+ `/api/memory/messages/delete?${query.toString()}${runtimeContextQueryString(runtimeContext, "&")}`,
1500
+ {
1501
+ method: "POST",
1502
+ body: { messageIds }
1503
+ }
1504
+ );
1431
1505
  }
1432
1506
  };
1433
1507
 
@@ -2265,6 +2339,35 @@ var AgentBuilder = class extends BaseResource {
2265
2339
  };
2266
2340
  }
2267
2341
  }
2342
+ /**
2343
+ * Creates a transform stream that parses binary chunks into JSON records.
2344
+ */
2345
+ createRecordParserTransform() {
2346
+ let failedChunk = void 0;
2347
+ return new TransformStream({
2348
+ start() {
2349
+ },
2350
+ async transform(chunk, controller) {
2351
+ try {
2352
+ const decoded = new TextDecoder().decode(chunk);
2353
+ const chunks = decoded.split(RECORD_SEPARATOR2);
2354
+ for (const chunk2 of chunks) {
2355
+ if (chunk2) {
2356
+ const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
2357
+ try {
2358
+ const parsedChunk = JSON.parse(newChunk);
2359
+ controller.enqueue(parsedChunk);
2360
+ failedChunk = void 0;
2361
+ } catch {
2362
+ failedChunk = newChunk;
2363
+ }
2364
+ }
2365
+ }
2366
+ } catch {
2367
+ }
2368
+ }
2369
+ });
2370
+ }
2268
2371
  /**
2269
2372
  * @deprecated Use createRunAsync() instead.
2270
2373
  * @throws {Error} Always throws an error directing users to use createRunAsync()
@@ -2420,31 +2523,7 @@ var AgentBuilder = class extends BaseResource {
2420
2523
  if (!response.body) {
2421
2524
  throw new Error("Response body is null");
2422
2525
  }
2423
- let failedChunk = void 0;
2424
- const transformStream = new TransformStream({
2425
- start() {
2426
- },
2427
- async transform(chunk, controller) {
2428
- try {
2429
- const decoded = new TextDecoder().decode(chunk);
2430
- const chunks = decoded.split(RECORD_SEPARATOR2);
2431
- for (const chunk2 of chunks) {
2432
- if (chunk2) {
2433
- const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
2434
- try {
2435
- const parsedChunk = JSON.parse(newChunk);
2436
- controller.enqueue(parsedChunk);
2437
- failedChunk = void 0;
2438
- } catch {
2439
- failedChunk = newChunk;
2440
- }
2441
- }
2442
- }
2443
- } catch {
2444
- }
2445
- }
2446
- });
2447
- return response.body.pipeThrough(transformStream);
2526
+ return response.body.pipeThrough(this.createRecordParserTransform());
2448
2527
  }
2449
2528
  /**
2450
2529
  * Streams agent builder action progress in real-time using VNext streaming.
@@ -2469,31 +2548,7 @@ var AgentBuilder = class extends BaseResource {
2469
2548
  if (!response.body) {
2470
2549
  throw new Error("Response body is null");
2471
2550
  }
2472
- let failedChunk = void 0;
2473
- const transformStream = new TransformStream({
2474
- start() {
2475
- },
2476
- async transform(chunk, controller) {
2477
- try {
2478
- const decoded = new TextDecoder().decode(chunk);
2479
- const chunks = decoded.split(RECORD_SEPARATOR2);
2480
- for (const chunk2 of chunks) {
2481
- if (chunk2) {
2482
- const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
2483
- try {
2484
- const parsedChunk = JSON.parse(newChunk);
2485
- controller.enqueue(parsedChunk);
2486
- failedChunk = void 0;
2487
- } catch {
2488
- failedChunk = newChunk;
2489
- }
2490
- }
2491
- }
2492
- } catch {
2493
- }
2494
- }
2495
- });
2496
- return response.body.pipeThrough(transformStream);
2551
+ return response.body.pipeThrough(this.createRecordParserTransform());
2497
2552
  }
2498
2553
  /**
2499
2554
  * Watches an existing agent builder action run by runId.
@@ -2521,6 +2576,93 @@ var AgentBuilder = class extends BaseResource {
2521
2576
  }
2522
2577
  }
2523
2578
  }
2579
+ /**
2580
+ * Observes an existing agent builder action run stream.
2581
+ * Replays cached execution from the beginning, then continues with live stream.
2582
+ * This is the recommended method for recovery after page refresh/hot reload.
2583
+ * This calls `/api/agent-builder/:actionId/observe` (which delegates to observeStreamVNext).
2584
+ */
2585
+ async observeStream(params) {
2586
+ const searchParams = new URLSearchParams();
2587
+ searchParams.set("runId", params.runId);
2588
+ const url = `/api/agent-builder/${this.actionId}/observe?${searchParams.toString()}`;
2589
+ const response = await this.request(url, {
2590
+ method: "POST",
2591
+ stream: true
2592
+ });
2593
+ if (!response.ok) {
2594
+ throw new Error(`Failed to observe agent builder action stream: ${response.statusText}`);
2595
+ }
2596
+ if (!response.body) {
2597
+ throw new Error("Response body is null");
2598
+ }
2599
+ return response.body.pipeThrough(this.createRecordParserTransform());
2600
+ }
2601
+ /**
2602
+ * Observes an existing agent builder action run stream using VNext streaming API.
2603
+ * Replays cached execution from the beginning, then continues with live stream.
2604
+ * This calls `/api/agent-builder/:actionId/observe-streamVNext`.
2605
+ */
2606
+ async observeStreamVNext(params) {
2607
+ const searchParams = new URLSearchParams();
2608
+ searchParams.set("runId", params.runId);
2609
+ const url = `/api/agent-builder/${this.actionId}/observe-streamVNext?${searchParams.toString()}`;
2610
+ const response = await this.request(url, {
2611
+ method: "POST",
2612
+ stream: true
2613
+ });
2614
+ if (!response.ok) {
2615
+ throw new Error(`Failed to observe agent builder action stream VNext: ${response.statusText}`);
2616
+ }
2617
+ if (!response.body) {
2618
+ throw new Error("Response body is null");
2619
+ }
2620
+ return response.body.pipeThrough(this.createRecordParserTransform());
2621
+ }
2622
+ /**
2623
+ * Observes an existing agent builder action run stream using legacy streaming API.
2624
+ * Replays cached execution from the beginning, then continues with live stream.
2625
+ * This calls `/api/agent-builder/:actionId/observe-stream-legacy`.
2626
+ */
2627
+ async observeStreamLegacy(params) {
2628
+ const searchParams = new URLSearchParams();
2629
+ searchParams.set("runId", params.runId);
2630
+ const url = `/api/agent-builder/${this.actionId}/observe-stream-legacy?${searchParams.toString()}`;
2631
+ const response = await this.request(url, {
2632
+ method: "POST",
2633
+ stream: true
2634
+ });
2635
+ if (!response.ok) {
2636
+ throw new Error(`Failed to observe agent builder action stream legacy: ${response.statusText}`);
2637
+ }
2638
+ if (!response.body) {
2639
+ throw new Error("Response body is null");
2640
+ }
2641
+ return response.body.pipeThrough(this.createRecordParserTransform());
2642
+ }
2643
+ /**
2644
+ * Resumes a suspended agent builder action and streams the results.
2645
+ * This calls `/api/agent-builder/:actionId/resume-stream`.
2646
+ */
2647
+ async resumeStream(params) {
2648
+ const searchParams = new URLSearchParams();
2649
+ searchParams.set("runId", params.runId);
2650
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2651
+ const { runId: _, runtimeContext: __, ...resumeParams } = params;
2652
+ const url = `/api/agent-builder/${this.actionId}/resume-stream?${searchParams.toString()}`;
2653
+ const response = await this.request(url, {
2654
+ method: "POST",
2655
+ body: { ...resumeParams, runtimeContext },
2656
+ stream: true
2657
+ });
2658
+ if (!response.ok) {
2659
+ throw new Error(`Failed to resume agent builder action stream: ${response.statusText}`);
2660
+ }
2661
+ if (!response.body) {
2662
+ throw new Error("Response body is null");
2663
+ }
2664
+ return response.body.pipeThrough(this.createRecordParserTransform());
2665
+ }
2524
2666
  /**
2525
2667
  * Gets a specific action run by its ID.
2526
2668
  * This calls `/api/agent-builder/:actionId/runs/:runId`.
@@ -2758,6 +2900,9 @@ var MastraClient = class extends BaseResource {
2758
2900
  const queryString = searchParams.toString();
2759
2901
  return this.request(`/api/agents${queryString ? `?${queryString}` : ""}`);
2760
2902
  }
2903
+ getAgentsModelProviders() {
2904
+ return this.request(`/api/agents/providers`);
2905
+ }
2761
2906
  /**
2762
2907
  * Gets an agent instance by ID
2763
2908
  * @param agentId - ID of the agent to retrieve
@@ -2768,27 +2913,34 @@ var MastraClient = class extends BaseResource {
2768
2913
  }
2769
2914
  /**
2770
2915
  * Retrieves memory threads for a resource
2771
- * @param params - Parameters containing the resource ID
2916
+ * @param params - Parameters containing the resource ID and optional runtime context
2772
2917
  * @returns Promise containing array of memory threads
2773
2918
  */
2774
2919
  getMemoryThreads(params) {
2775
- return this.request(`/api/memory/threads?resourceid=${params.resourceId}&agentId=${params.agentId}`);
2920
+ return this.request(
2921
+ `/api/memory/threads?resourceid=${params.resourceId}&agentId=${params.agentId}${runtimeContextQueryString(params.runtimeContext, "&")}`
2922
+ );
2776
2923
  }
2777
2924
  /**
2778
2925
  * Retrieves memory config for a resource
2779
- * @param params - Parameters containing the resource ID
2780
- * @returns Promise containing array of memory threads
2926
+ * @param params - Parameters containing the resource ID and optional runtime context
2927
+ * @returns Promise containing memory configuration
2781
2928
  */
2782
2929
  getMemoryConfig(params) {
2783
- return this.request(`/api/memory/config?agentId=${params.agentId}`);
2930
+ return this.request(
2931
+ `/api/memory/config?agentId=${params.agentId}${runtimeContextQueryString(params.runtimeContext, "&")}`
2932
+ );
2784
2933
  }
2785
2934
  /**
2786
2935
  * Creates a new memory thread
2787
- * @param params - Parameters for creating the memory thread
2936
+ * @param params - Parameters for creating the memory thread including optional runtime context
2788
2937
  * @returns Promise containing the created memory thread
2789
2938
  */
2790
2939
  createMemoryThread(params) {
2791
- return this.request(`/api/memory/threads?agentId=${params.agentId}`, { method: "POST", body: params });
2940
+ return this.request(
2941
+ `/api/memory/threads?agentId=${params.agentId}${runtimeContextQueryString(params.runtimeContext, "&")}`,
2942
+ { method: "POST", body: params }
2943
+ );
2792
2944
  }
2793
2945
  /**
2794
2946
  * Gets a memory thread instance by ID
@@ -2801,38 +2953,43 @@ var MastraClient = class extends BaseResource {
2801
2953
  getThreadMessages(threadId, opts = {}) {
2802
2954
  let url = "";
2803
2955
  if (opts.agentId) {
2804
- url = `/api/memory/threads/${threadId}/messages?agentId=${opts.agentId}`;
2956
+ url = `/api/memory/threads/${threadId}/messages?agentId=${opts.agentId}${runtimeContextQueryString(opts.runtimeContext, "&")}`;
2805
2957
  } else if (opts.networkId) {
2806
- url = `/api/memory/network/threads/${threadId}/messages?networkId=${opts.networkId}`;
2958
+ url = `/api/memory/network/threads/${threadId}/messages?networkId=${opts.networkId}${runtimeContextQueryString(opts.runtimeContext, "&")}`;
2807
2959
  }
2808
2960
  return this.request(url);
2809
2961
  }
2810
2962
  deleteThread(threadId, opts = {}) {
2811
2963
  let url = "";
2812
2964
  if (opts.agentId) {
2813
- url = `/api/memory/threads/${threadId}?agentId=${opts.agentId}`;
2965
+ url = `/api/memory/threads/${threadId}?agentId=${opts.agentId}${runtimeContextQueryString(opts.runtimeContext, "&")}`;
2814
2966
  } else if (opts.networkId) {
2815
- url = `/api/memory/network/threads/${threadId}?networkId=${opts.networkId}`;
2967
+ url = `/api/memory/network/threads/${threadId}?networkId=${opts.networkId}${runtimeContextQueryString(opts.runtimeContext, "&")}`;
2816
2968
  }
2817
2969
  return this.request(url, { method: "DELETE" });
2818
2970
  }
2819
2971
  /**
2820
2972
  * Saves messages to memory
2821
- * @param params - Parameters containing messages to save
2973
+ * @param params - Parameters containing messages to save and optional runtime context
2822
2974
  * @returns Promise containing the saved messages
2823
2975
  */
2824
2976
  saveMessageToMemory(params) {
2825
- return this.request(`/api/memory/save-messages?agentId=${params.agentId}`, {
2826
- method: "POST",
2827
- body: params
2828
- });
2977
+ return this.request(
2978
+ `/api/memory/save-messages?agentId=${params.agentId}${runtimeContextQueryString(params.runtimeContext, "&")}`,
2979
+ {
2980
+ method: "POST",
2981
+ body: params
2982
+ }
2983
+ );
2829
2984
  }
2830
2985
  /**
2831
2986
  * Gets the status of the memory system
2987
+ * @param agentId - The agent ID
2988
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2832
2989
  * @returns Promise containing memory system status
2833
2990
  */
2834
- getMemoryStatus(agentId) {
2835
- return this.request(`/api/memory/status?agentId=${agentId}`);
2991
+ getMemoryStatus(agentId, runtimeContext) {
2992
+ return this.request(`/api/memory/status?agentId=${agentId}${runtimeContextQueryString(runtimeContext, "&")}`);
2836
2993
  }
2837
2994
  /**
2838
2995
  * Retrieves memory threads for a resource
@@ -3036,48 +3193,6 @@ var MastraClient = class extends BaseResource {
3036
3193
  getLogTransports() {
3037
3194
  return this.request("/api/logs/transports");
3038
3195
  }
3039
- /**
3040
- * List of all traces (paged)
3041
- * @param params - Parameters for filtering traces
3042
- * @returns Promise containing telemetry data
3043
- */
3044
- getTelemetry(params) {
3045
- const { name, scope, page, perPage, attribute, fromDate, toDate } = params || {};
3046
- const _attribute = attribute ? Object.entries(attribute).map(([key, value]) => `${key}:${value}`) : [];
3047
- const searchParams = new URLSearchParams();
3048
- if (name) {
3049
- searchParams.set("name", name);
3050
- }
3051
- if (scope) {
3052
- searchParams.set("scope", scope);
3053
- }
3054
- if (page) {
3055
- searchParams.set("page", String(page));
3056
- }
3057
- if (perPage) {
3058
- searchParams.set("perPage", String(perPage));
3059
- }
3060
- if (_attribute) {
3061
- if (Array.isArray(_attribute)) {
3062
- for (const attr of _attribute) {
3063
- searchParams.append("attribute", attr);
3064
- }
3065
- } else {
3066
- searchParams.set("attribute", _attribute);
3067
- }
3068
- }
3069
- if (fromDate) {
3070
- searchParams.set("fromDate", fromDate.toISOString());
3071
- }
3072
- if (toDate) {
3073
- searchParams.set("toDate", toDate.toISOString());
3074
- }
3075
- if (searchParams.size) {
3076
- return this.request(`/api/telemetry?${searchParams}`);
3077
- } else {
3078
- return this.request(`/api/telemetry`);
3079
- }
3080
- }
3081
3196
  /**
3082
3197
  * Retrieves a list of available MCP servers.
3083
3198
  * @param params - Optional parameters for pagination (limit, offset).
@@ -3144,9 +3259,33 @@ var MastraClient = class extends BaseResource {
3144
3259
  getWorkingMemory({
3145
3260
  agentId,
3146
3261
  threadId,
3147
- resourceId
3262
+ resourceId,
3263
+ runtimeContext
3148
3264
  }) {
3149
- return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}`);
3265
+ return this.request(
3266
+ `/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}${runtimeContextQueryString(runtimeContext, "&")}`
3267
+ );
3268
+ }
3269
+ searchMemory({
3270
+ agentId,
3271
+ resourceId,
3272
+ threadId,
3273
+ searchQuery,
3274
+ memoryConfig,
3275
+ runtimeContext
3276
+ }) {
3277
+ const params = new URLSearchParams({
3278
+ searchQuery,
3279
+ resourceId,
3280
+ agentId
3281
+ });
3282
+ if (threadId) {
3283
+ params.append("threadId", threadId);
3284
+ }
3285
+ if (memoryConfig) {
3286
+ params.append("memoryConfig", JSON.stringify(memoryConfig));
3287
+ }
3288
+ return this.request(`/api/memory/search?${params}${runtimeContextQueryString(runtimeContext, "&")}`);
3150
3289
  }
3151
3290
  /**
3152
3291
  * Updates the working memory for a specific thread (optionally resource-scoped).
@@ -3159,15 +3298,19 @@ var MastraClient = class extends BaseResource {
3159
3298
  agentId,
3160
3299
  threadId,
3161
3300
  workingMemory,
3162
- resourceId
3301
+ resourceId,
3302
+ runtimeContext
3163
3303
  }) {
3164
- return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}`, {
3165
- method: "POST",
3166
- body: {
3167
- workingMemory,
3168
- resourceId
3304
+ return this.request(
3305
+ `/api/memory/threads/${threadId}/working-memory?agentId=${agentId}${runtimeContextQueryString(runtimeContext, "&")}`,
3306
+ {
3307
+ method: "POST",
3308
+ body: {
3309
+ workingMemory,
3310
+ resourceId
3311
+ }
3169
3312
  }
3170
- });
3313
+ );
3171
3314
  }
3172
3315
  /**
3173
3316
  * Retrieves all available scorers