@mastra/client-js 0.16.8 → 0.16.9-alpha.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/dist/index.js CHANGED
@@ -22,13 +22,13 @@ function base64RuntimeContext(runtimeContext) {
22
22
  }
23
23
  return void 0;
24
24
  }
25
- function runtimeContextQueryString(runtimeContext) {
25
+ function runtimeContextQueryString(runtimeContext, delimiter = "?") {
26
26
  const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
27
27
  if (!runtimeContextParam) return "";
28
28
  const searchParams = new URLSearchParams();
29
29
  searchParams.set("runtimeContext", runtimeContextParam);
30
30
  const queryString = searchParams.toString();
31
- return queryString ? `?${queryString}` : "";
31
+ return queryString ? `${delimiter}${queryString}` : "";
32
32
  }
33
33
  function isZodType(value) {
34
34
  return typeof value === "object" && value !== null && "_def" in value && "parse" in value && typeof value.parse === "function" && "safeParse" in value && typeof value.safeParse === "function";
@@ -1368,6 +1368,15 @@ var Agent = class extends BaseResource {
1368
1368
  body: params
1369
1369
  });
1370
1370
  }
1371
+ /**
1372
+ * Resets the agent's model to the original model that was set during construction
1373
+ * @returns Promise containing a success message
1374
+ */
1375
+ resetModel() {
1376
+ return this.request(`/api/agents/${this.agentId}/model/reset`, {
1377
+ method: "POST"
1378
+ });
1379
+ }
1371
1380
  /**
1372
1381
  * Updates the model for the agent in the model list
1373
1382
  * @param params - Parameters for updating the model
@@ -1407,34 +1416,44 @@ var MemoryThread = class extends BaseResource {
1407
1416
  }
1408
1417
  /**
1409
1418
  * Retrieves the memory thread details
1419
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1410
1420
  * @returns Promise containing thread details including title and metadata
1411
1421
  */
1412
- get() {
1413
- return this.request(`/api/memory/threads/${this.threadId}?agentId=${this.agentId}`);
1422
+ get(runtimeContext) {
1423
+ return this.request(
1424
+ `/api/memory/threads/${this.threadId}?agentId=${this.agentId}${runtimeContextQueryString(runtimeContext, "&")}`
1425
+ );
1414
1426
  }
1415
1427
  /**
1416
1428
  * Updates the memory thread properties
1417
- * @param params - Update parameters including title and metadata
1429
+ * @param params - Update parameters including title, metadata, and optional runtime context
1418
1430
  * @returns Promise containing updated thread details
1419
1431
  */
1420
1432
  update(params) {
1421
- return this.request(`/api/memory/threads/${this.threadId}?agentId=${this.agentId}`, {
1422
- method: "PATCH",
1423
- body: params
1424
- });
1433
+ return this.request(
1434
+ `/api/memory/threads/${this.threadId}?agentId=${this.agentId}${runtimeContextQueryString(params.runtimeContext, "&")}`,
1435
+ {
1436
+ method: "PATCH",
1437
+ body: params
1438
+ }
1439
+ );
1425
1440
  }
1426
1441
  /**
1427
1442
  * Deletes the memory thread
1443
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1428
1444
  * @returns Promise containing deletion result
1429
1445
  */
1430
- delete() {
1431
- return this.request(`/api/memory/threads/${this.threadId}?agentId=${this.agentId}`, {
1432
- method: "DELETE"
1433
- });
1446
+ delete(runtimeContext) {
1447
+ return this.request(
1448
+ `/api/memory/threads/${this.threadId}?agentId=${this.agentId}${runtimeContextQueryString(runtimeContext, "&")}`,
1449
+ {
1450
+ method: "DELETE"
1451
+ }
1452
+ );
1434
1453
  }
1435
1454
  /**
1436
1455
  * Retrieves messages associated with the thread
1437
- * @param params - Optional parameters including limit for number of messages to retrieve
1456
+ * @param params - Optional parameters including limit for number of messages to retrieve and runtime context
1438
1457
  * @returns Promise containing thread messages and UI messages
1439
1458
  */
1440
1459
  getMessages(params) {
@@ -1442,37 +1461,46 @@ var MemoryThread = class extends BaseResource {
1442
1461
  agentId: this.agentId,
1443
1462
  ...params?.limit ? { limit: params.limit.toString() } : {}
1444
1463
  });
1445
- return this.request(`/api/memory/threads/${this.threadId}/messages?${query.toString()}`);
1464
+ return this.request(
1465
+ `/api/memory/threads/${this.threadId}/messages?${query.toString()}${runtimeContextQueryString(params?.runtimeContext, "&")}`
1466
+ );
1446
1467
  }
1447
1468
  /**
1448
1469
  * Retrieves paginated messages associated with the thread with advanced filtering and selection options
1449
- * @param params - Pagination parameters including selectBy criteria, page, perPage, date ranges, and message inclusion options
1470
+ * @param params - Pagination parameters including selectBy criteria, page, perPage, date ranges, message inclusion options, and runtime context
1450
1471
  * @returns Promise containing paginated thread messages with pagination metadata (total, page, perPage, hasMore)
1451
1472
  */
1452
1473
  getMessagesPaginated({
1453
1474
  selectBy,
1475
+ runtimeContext,
1454
1476
  ...rest
1455
1477
  }) {
1456
1478
  const query = new URLSearchParams({
1457
1479
  ...rest,
1458
1480
  ...selectBy ? { selectBy: JSON.stringify(selectBy) } : {}
1459
1481
  });
1460
- return this.request(`/api/memory/threads/${this.threadId}/messages/paginated?${query.toString()}`);
1482
+ return this.request(
1483
+ `/api/memory/threads/${this.threadId}/messages/paginated?${query.toString()}${runtimeContextQueryString(runtimeContext, "&")}`
1484
+ );
1461
1485
  }
1462
1486
  /**
1463
1487
  * Deletes one or more messages from the thread
1464
1488
  * @param messageIds - Can be a single message ID (string), array of message IDs,
1465
1489
  * message object with id property, or array of message objects
1490
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1466
1491
  * @returns Promise containing deletion result
1467
1492
  */
1468
- deleteMessages(messageIds) {
1493
+ deleteMessages(messageIds, runtimeContext) {
1469
1494
  const query = new URLSearchParams({
1470
1495
  agentId: this.agentId
1471
1496
  });
1472
- return this.request(`/api/memory/messages/delete?${query.toString()}`, {
1473
- method: "POST",
1474
- body: { messageIds }
1475
- });
1497
+ return this.request(
1498
+ `/api/memory/messages/delete?${query.toString()}${runtimeContextQueryString(runtimeContext, "&")}`,
1499
+ {
1500
+ method: "POST",
1501
+ body: { messageIds }
1502
+ }
1503
+ );
1476
1504
  }
1477
1505
  };
1478
1506
 
@@ -2813,27 +2841,34 @@ var MastraClient = class extends BaseResource {
2813
2841
  }
2814
2842
  /**
2815
2843
  * Retrieves memory threads for a resource
2816
- * @param params - Parameters containing the resource ID
2844
+ * @param params - Parameters containing the resource ID and optional runtime context
2817
2845
  * @returns Promise containing array of memory threads
2818
2846
  */
2819
2847
  getMemoryThreads(params) {
2820
- return this.request(`/api/memory/threads?resourceid=${params.resourceId}&agentId=${params.agentId}`);
2848
+ return this.request(
2849
+ `/api/memory/threads?resourceid=${params.resourceId}&agentId=${params.agentId}${runtimeContextQueryString(params.runtimeContext, "&")}`
2850
+ );
2821
2851
  }
2822
2852
  /**
2823
2853
  * Retrieves memory config for a resource
2824
- * @param params - Parameters containing the resource ID
2825
- * @returns Promise containing array of memory threads
2854
+ * @param params - Parameters containing the resource ID and optional runtime context
2855
+ * @returns Promise containing memory configuration
2826
2856
  */
2827
2857
  getMemoryConfig(params) {
2828
- return this.request(`/api/memory/config?agentId=${params.agentId}`);
2858
+ return this.request(
2859
+ `/api/memory/config?agentId=${params.agentId}${runtimeContextQueryString(params.runtimeContext, "&")}`
2860
+ );
2829
2861
  }
2830
2862
  /**
2831
2863
  * Creates a new memory thread
2832
- * @param params - Parameters for creating the memory thread
2864
+ * @param params - Parameters for creating the memory thread including optional runtime context
2833
2865
  * @returns Promise containing the created memory thread
2834
2866
  */
2835
2867
  createMemoryThread(params) {
2836
- return this.request(`/api/memory/threads?agentId=${params.agentId}`, { method: "POST", body: params });
2868
+ return this.request(
2869
+ `/api/memory/threads?agentId=${params.agentId}${runtimeContextQueryString(params.runtimeContext, "&")}`,
2870
+ { method: "POST", body: params }
2871
+ );
2837
2872
  }
2838
2873
  /**
2839
2874
  * Gets a memory thread instance by ID
@@ -2846,38 +2881,43 @@ var MastraClient = class extends BaseResource {
2846
2881
  getThreadMessages(threadId, opts = {}) {
2847
2882
  let url = "";
2848
2883
  if (opts.agentId) {
2849
- url = `/api/memory/threads/${threadId}/messages?agentId=${opts.agentId}`;
2884
+ url = `/api/memory/threads/${threadId}/messages?agentId=${opts.agentId}${runtimeContextQueryString(opts.runtimeContext, "&")}`;
2850
2885
  } else if (opts.networkId) {
2851
- url = `/api/memory/network/threads/${threadId}/messages?networkId=${opts.networkId}`;
2886
+ url = `/api/memory/network/threads/${threadId}/messages?networkId=${opts.networkId}${runtimeContextQueryString(opts.runtimeContext, "&")}`;
2852
2887
  }
2853
2888
  return this.request(url);
2854
2889
  }
2855
2890
  deleteThread(threadId, opts = {}) {
2856
2891
  let url = "";
2857
2892
  if (opts.agentId) {
2858
- url = `/api/memory/threads/${threadId}?agentId=${opts.agentId}`;
2893
+ url = `/api/memory/threads/${threadId}?agentId=${opts.agentId}${runtimeContextQueryString(opts.runtimeContext, "&")}`;
2859
2894
  } else if (opts.networkId) {
2860
- url = `/api/memory/network/threads/${threadId}?networkId=${opts.networkId}`;
2895
+ url = `/api/memory/network/threads/${threadId}?networkId=${opts.networkId}${runtimeContextQueryString(opts.runtimeContext, "&")}`;
2861
2896
  }
2862
2897
  return this.request(url, { method: "DELETE" });
2863
2898
  }
2864
2899
  /**
2865
2900
  * Saves messages to memory
2866
- * @param params - Parameters containing messages to save
2901
+ * @param params - Parameters containing messages to save and optional runtime context
2867
2902
  * @returns Promise containing the saved messages
2868
2903
  */
2869
2904
  saveMessageToMemory(params) {
2870
- return this.request(`/api/memory/save-messages?agentId=${params.agentId}`, {
2871
- method: "POST",
2872
- body: params
2873
- });
2905
+ return this.request(
2906
+ `/api/memory/save-messages?agentId=${params.agentId}${runtimeContextQueryString(params.runtimeContext, "&")}`,
2907
+ {
2908
+ method: "POST",
2909
+ body: params
2910
+ }
2911
+ );
2874
2912
  }
2875
2913
  /**
2876
2914
  * Gets the status of the memory system
2915
+ * @param agentId - The agent ID
2916
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2877
2917
  * @returns Promise containing memory system status
2878
2918
  */
2879
- getMemoryStatus(agentId) {
2880
- return this.request(`/api/memory/status?agentId=${agentId}`);
2919
+ getMemoryStatus(agentId, runtimeContext) {
2920
+ return this.request(`/api/memory/status?agentId=${agentId}${runtimeContextQueryString(runtimeContext, "&")}`);
2881
2921
  }
2882
2922
  /**
2883
2923
  * Retrieves memory threads for a resource
@@ -3189,9 +3229,12 @@ var MastraClient = class extends BaseResource {
3189
3229
  getWorkingMemory({
3190
3230
  agentId,
3191
3231
  threadId,
3192
- resourceId
3232
+ resourceId,
3233
+ runtimeContext
3193
3234
  }) {
3194
- return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}`);
3235
+ return this.request(
3236
+ `/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}${runtimeContextQueryString(runtimeContext, "&")}`
3237
+ );
3195
3238
  }
3196
3239
  /**
3197
3240
  * Updates the working memory for a specific thread (optionally resource-scoped).
@@ -3204,15 +3247,19 @@ var MastraClient = class extends BaseResource {
3204
3247
  agentId,
3205
3248
  threadId,
3206
3249
  workingMemory,
3207
- resourceId
3250
+ resourceId,
3251
+ runtimeContext
3208
3252
  }) {
3209
- return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}`, {
3210
- method: "POST",
3211
- body: {
3212
- workingMemory,
3213
- resourceId
3253
+ return this.request(
3254
+ `/api/memory/threads/${threadId}/working-memory?agentId=${agentId}${runtimeContextQueryString(runtimeContext, "&")}`,
3255
+ {
3256
+ method: "POST",
3257
+ body: {
3258
+ workingMemory,
3259
+ resourceId
3260
+ }
3214
3261
  }
3215
- });
3262
+ );
3216
3263
  }
3217
3264
  /**
3218
3265
  * Retrieves all available scorers
@@ -3294,13 +3341,6 @@ var MastraClient = class extends BaseResource {
3294
3341
  body: params
3295
3342
  });
3296
3343
  }
3297
- /**
3298
- * Retrieves model providers with available keys
3299
- * @returns Promise containing model providers with available keys
3300
- */
3301
- getModelProviders() {
3302
- return this.request(`/api/model-providers`);
3303
- }
3304
3344
  getAITrace(traceId) {
3305
3345
  return this.observability.getTrace(traceId);
3306
3346
  }