@mastra/client-js 0.0.0-fix-persist-session-cache-option-mcp-server-20251031182703 → 0.0.0-fix-9244-clickhouse-metadata-20251104213434

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
@@ -197,7 +197,6 @@ 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,
@@ -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
- context: toolCall?.args,
217
- runId,
218
- resourceId,
219
- threadId,
220
- requestContext,
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
  {
@@ -336,7 +331,7 @@ var Agent = class extends BaseResource {
336
331
  requestContext: parseClientRequestContext(params.requestContext),
337
332
  clientTools: processClientTools(params.clientTools)
338
333
  };
339
- const { runId, resourceId, threadId, requestContext } = processedParams;
334
+ const { resourceId, threadId, requestContext } = processedParams;
340
335
  const response = await this.request(
341
336
  `/api/agents/${this.agentId}/generate-legacy`,
342
337
  {
@@ -352,22 +347,18 @@ var Agent = class extends BaseResource {
352
347
  for (const toolCall of toolCalls) {
353
348
  const clientTool = params.clientTools?.[toolCall.toolName];
354
349
  if (clientTool && clientTool.execute) {
355
- const result = await clientTool.execute(
356
- {
357
- context: toolCall?.args,
358
- runId,
359
- resourceId,
360
- threadId,
361
- requestContext,
362
- tracingContext: { currentSpan: void 0 },
363
- suspend: async () => {
364
- }
365
- },
366
- {
350
+ const result = await clientTool.execute(toolCall?.args, {
351
+ requestContext,
352
+ tracingContext: { currentSpan: void 0 },
353
+ agent: {
367
354
  messages: response.messages,
368
- toolCallId: toolCall?.toolCallId
355
+ toolCallId: toolCall?.toolCallId,
356
+ suspend: async () => {
357
+ },
358
+ threadId,
359
+ resourceId
369
360
  }
370
- );
361
+ });
371
362
  const updatedMessages = [
372
363
  ...response.response.messages,
373
364
  {
@@ -410,7 +401,7 @@ var Agent = class extends BaseResource {
410
401
  schema: zodToJsonSchema(params.structuredOutput.schema)
411
402
  } : void 0
412
403
  };
413
- const { runId, resourceId, threadId, requestContext } = processedParams;
404
+ const { resourceId, threadId, requestContext } = processedParams;
414
405
  const response = await this.request(
415
406
  `/api/agents/${this.agentId}/generate`,
416
407
  {
@@ -422,7 +413,6 @@ var Agent = class extends BaseResource {
422
413
  return executeToolCallAndRespond({
423
414
  response,
424
415
  params,
425
- runId,
426
416
  resourceId,
427
417
  threadId,
428
418
  requestContext,
@@ -1042,23 +1032,19 @@ var Agent = class extends BaseResource {
1042
1032
  const clientTool = processedParams.clientTools?.[toolCall2.toolName];
1043
1033
  if (clientTool && clientTool.execute) {
1044
1034
  shouldExecuteClientTool = true;
1045
- const result = await clientTool.execute(
1046
- {
1047
- context: toolCall2?.args,
1048
- runId: processedParams.runId,
1049
- resourceId: processedParams.resourceId,
1050
- threadId: processedParams.threadId,
1051
- requestContext: processedParams.requestContext,
1052
- // TODO: Pass proper tracing context when client-js supports tracing
1053
- tracingContext: { currentSpan: void 0 },
1054
- suspend: async () => {
1055
- }
1056
- },
1057
- {
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: {
1058
1040
  messages: response.messages,
1059
- toolCallId: toolCall2?.toolCallId
1041
+ toolCallId: toolCall2?.toolCallId,
1042
+ suspend: async () => {
1043
+ },
1044
+ threadId: processedParams.threadId,
1045
+ resourceId: processedParams.resourceId
1060
1046
  }
1061
- );
1047
+ });
1062
1048
  const lastMessageRaw = messages[messages.length - 1];
1063
1049
  const lastMessage = lastMessageRaw != null ? JSON.parse(JSON.stringify(lastMessageRaw)) : void 0;
1064
1050
  const toolInvocationPart = lastMessage?.parts?.find(
@@ -1246,23 +1232,19 @@ var Agent = class extends BaseResource {
1246
1232
  for (const toolCall2 of toolCalls) {
1247
1233
  const clientTool = processedParams.clientTools?.[toolCall2.toolName];
1248
1234
  if (clientTool && clientTool.execute) {
1249
- const result = await clientTool.execute(
1250
- {
1251
- context: toolCall2?.args,
1252
- runId: processedParams.runId,
1253
- resourceId: processedParams.resourceId,
1254
- threadId: processedParams.threadId,
1255
- requestContext: processedParams.requestContext,
1256
- // TODO: Pass proper tracing context when client-js supports tracing
1257
- tracingContext: { currentSpan: void 0 },
1258
- suspend: async () => {
1259
- }
1260
- },
1261
- {
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: {
1262
1240
  messages: response.messages,
1263
- toolCallId: toolCall2?.toolCallId
1241
+ toolCallId: toolCall2?.toolCallId,
1242
+ suspend: async () => {
1243
+ },
1244
+ threadId: processedParams.threadId,
1245
+ resourceId: processedParams.resourceId
1264
1246
  }
1265
- );
1247
+ });
1266
1248
  const lastMessage = JSON.parse(JSON.stringify(messages[messages.length - 1]));
1267
1249
  const toolInvocationPart = lastMessage?.parts?.find(
1268
1250
  (part) => part.type === "tool-invocation" && part.toolInvocation?.toolCallId === toolCall2.toolCallId
@@ -1387,12 +1369,6 @@ var Agent = class extends BaseResource {
1387
1369
  body: params
1388
1370
  });
1389
1371
  }
1390
- async generateVNext(_messagesOrParams, _options) {
1391
- throw new Error("generateVNext has been renamed to generate. Please use generate instead.");
1392
- }
1393
- async streamVNext(_messagesOrParams, _options) {
1394
- throw new Error("streamVNext has been renamed to stream. Please use stream instead.");
1395
- }
1396
1372
  };
1397
1373
 
1398
1374
  // src/resources/memory-thread.ts
@@ -1440,9 +1416,9 @@ var MemoryThread = class extends BaseResource {
1440
1416
  );
1441
1417
  }
1442
1418
  /**
1443
- * Retrieves messages associated with the thread
1419
+ * Retrieves messages associated with the thread (always returns mastra-db format)
1444
1420
  * @param params - Optional parameters including limit for number of messages to retrieve and request context
1445
- * @returns Promise containing thread messages and UI messages
1421
+ * @returns Promise containing thread messages in mastra-db format
1446
1422
  */
1447
1423
  getMessages(params) {
1448
1424
  const query = new URLSearchParams({
@@ -1454,19 +1430,20 @@ var MemoryThread = class extends BaseResource {
1454
1430
  );
1455
1431
  }
1456
1432
  /**
1457
- * Retrieves paginated messages associated with the thread with advanced filtering and selection options
1458
- * @param params - Pagination parameters including selectBy criteria, page, perPage, date ranges, message inclusion options, and request context
1433
+ * Retrieves paginated messages associated with the thread with filtering and ordering options
1434
+ * @param params - Pagination parameters including page, perPage, orderBy, filter, include options, and request context
1459
1435
  * @returns Promise containing paginated thread messages with pagination metadata (total, page, perPage, hasMore)
1460
1436
  */
1461
- getMessagesPaginated({
1462
- selectBy,
1463
- requestContext,
1464
- ...rest
1465
- }) {
1466
- const query = new URLSearchParams({
1467
- ...rest,
1468
- ...selectBy ? { selectBy: JSON.stringify(selectBy) } : {}
1469
- });
1437
+ listMessages(params = {}) {
1438
+ const { page, perPage, orderBy, filter, include, resourceId, requestContext } = params;
1439
+ const queryParams = {};
1440
+ if (resourceId) queryParams.resourceId = resourceId;
1441
+ if (page !== void 0) queryParams.page = String(page);
1442
+ if (perPage !== void 0) queryParams.perPage = String(perPage);
1443
+ if (orderBy) queryParams.orderBy = JSON.stringify(orderBy);
1444
+ if (filter) queryParams.filter = JSON.stringify(filter);
1445
+ if (include) queryParams.include = JSON.stringify(include);
1446
+ const query = new URLSearchParams(queryParams);
1470
1447
  return this.request(
1471
1448
  `/api/memory/threads/${this.threadId}/messages/paginated?${query.toString()}${requestContextQueryString(requestContext, "&")}`
1472
1449
  );
@@ -1604,51 +1581,6 @@ var Workflow = class extends BaseResource {
1604
1581
  super(options);
1605
1582
  this.workflowId = workflowId;
1606
1583
  }
1607
- /**
1608
- * Creates an async generator that processes a readable stream and yields workflow records
1609
- * separated by the Record Separator character (\x1E)
1610
- *
1611
- * @param stream - The readable stream to process
1612
- * @returns An async generator that yields parsed records
1613
- */
1614
- async *streamProcessor(stream) {
1615
- const reader = stream.getReader();
1616
- let doneReading = false;
1617
- let buffer = "";
1618
- try {
1619
- while (!doneReading) {
1620
- const { done, value } = await reader.read();
1621
- doneReading = done;
1622
- if (done && !value) continue;
1623
- try {
1624
- const decoded = value ? new TextDecoder().decode(value) : "";
1625
- const chunks = (buffer + decoded).split(RECORD_SEPARATOR);
1626
- buffer = chunks.pop() || "";
1627
- for (const chunk of chunks) {
1628
- if (chunk) {
1629
- if (typeof chunk === "string") {
1630
- try {
1631
- const parsedChunk = JSON.parse(chunk);
1632
- yield parsedChunk;
1633
- } catch {
1634
- }
1635
- }
1636
- }
1637
- }
1638
- } catch {
1639
- }
1640
- }
1641
- if (buffer) {
1642
- try {
1643
- yield JSON.parse(buffer);
1644
- } catch {
1645
- }
1646
- }
1647
- } finally {
1648
- reader.cancel().catch(() => {
1649
- });
1650
- }
1651
- }
1652
1584
  /**
1653
1585
  * Retrieves details about the workflow
1654
1586
  * @param requestContext - Optional request context to pass as query parameter
@@ -1672,11 +1604,15 @@ var Workflow = class extends BaseResource {
1672
1604
  if (params?.toDate) {
1673
1605
  searchParams.set("toDate", params.toDate.toISOString());
1674
1606
  }
1675
- if (params?.limit !== null && params?.limit !== void 0 && !isNaN(Number(params?.limit))) {
1676
- searchParams.set("limit", String(params.limit));
1607
+ if (params?.perPage !== null && params?.perPage !== void 0) {
1608
+ if (params.perPage === false) {
1609
+ searchParams.set("perPage", "false");
1610
+ } else if (typeof params.perPage === "number" && params.perPage > 0 && Number.isInteger(params.perPage)) {
1611
+ searchParams.set("perPage", String(params.perPage));
1612
+ }
1677
1613
  }
1678
- if (params?.offset !== null && params?.offset !== void 0 && !isNaN(Number(params?.offset))) {
1679
- searchParams.set("offset", String(params.offset));
1614
+ if (params?.page !== null && params?.page !== void 0 && !isNaN(Number(params?.page))) {
1615
+ searchParams.set("page", String(params.page));
1680
1616
  }
1681
1617
  if (params?.resourceId) {
1682
1618
  searchParams.set("resourceId", params.resourceId);
@@ -1731,21 +1667,12 @@ var Workflow = class extends BaseResource {
1731
1667
  body: { event: params.event, data: params.data }
1732
1668
  });
1733
1669
  }
1734
- /**
1735
- * @deprecated Use createRunAsync() instead.
1736
- * @throws {Error} Always throws an error directing users to use createRunAsync()
1737
- */
1738
- async createRun(_params) {
1739
- throw new Error(
1740
- "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."
1741
- );
1742
- }
1743
1670
  /**
1744
1671
  * Creates a new workflow run
1745
1672
  * @param params - Optional object containing the optional runId
1746
1673
  * @returns Promise containing the runId of the created run with methods to control execution
1747
1674
  */
1748
- async createRunAsync(params) {
1675
+ async createRun(params) {
1749
1676
  const searchParams = new URLSearchParams();
1750
1677
  if (!!params?.runId) {
1751
1678
  searchParams.set("runId", params.runId);
@@ -1775,9 +1702,6 @@ var Workflow = class extends BaseResource {
1775
1702
  tracingOptions: p.tracingOptions
1776
1703
  });
1777
1704
  },
1778
- watch: async (onRecord) => {
1779
- return this.watch({ runId }, onRecord);
1780
- },
1781
1705
  stream: async (p) => {
1782
1706
  return this.stream({ runId, inputData: p.inputData, requestContext: p.requestContext });
1783
1707
  },
@@ -2132,29 +2056,6 @@ var Workflow = class extends BaseResource {
2132
2056
  });
2133
2057
  return response.body.pipeThrough(transformStream);
2134
2058
  }
2135
- /**
2136
- * Watches workflow transitions in real-time
2137
- * @param runId - Optional run ID to filter the watch stream
2138
- * @returns AsyncGenerator that yields parsed records from the workflow watch stream
2139
- */
2140
- async watch({ runId }, onRecord) {
2141
- const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
2142
- stream: true
2143
- });
2144
- if (!response.ok) {
2145
- throw new Error(`Failed to watch workflow: ${response.statusText}`);
2146
- }
2147
- if (!response.body) {
2148
- throw new Error("Response body is null");
2149
- }
2150
- for await (const record of this.streamProcessor(response.body)) {
2151
- if (typeof record === "string") {
2152
- onRecord(JSON.parse(record));
2153
- } else {
2154
- onRecord(record);
2155
- }
2156
- }
2157
- }
2158
2059
  /**
2159
2060
  * Creates a new ReadableStream from an iterable or async iterable of objects,
2160
2061
  * serializing each as JSON and separating them with the record separator (\x1E).
@@ -2355,20 +2256,11 @@ var AgentBuilder = class extends BaseResource {
2355
2256
  }
2356
2257
  });
2357
2258
  }
2358
- /**
2359
- * @deprecated Use createRunAsync() instead.
2360
- * @throws {Error} Always throws an error directing users to use createRunAsync()
2361
- */
2362
- async createRun(_params) {
2363
- throw new Error(
2364
- "createRun() has been deprecated. Please use createRunAsync() instead.\n\nMigration guide:\n Before: const run = agentBuilder.createRun();\n After: const run = await agentBuilder.createRunAsync();\n\nNote: createRunAsync() is an async method, so make sure your calling function is async."
2365
- );
2366
- }
2367
2259
  /**
2368
2260
  * Creates a new agent builder action run and returns the runId.
2369
2261
  * This calls `/api/agent-builder/:actionId/create-run`.
2370
2262
  */
2371
- async createRunAsync(params) {
2263
+ async createRun(params) {
2372
2264
  const searchParams = new URLSearchParams();
2373
2265
  if (!!params?.runId) {
2374
2266
  searchParams.set("runId", params.runId);
@@ -2537,32 +2429,6 @@ var AgentBuilder = class extends BaseResource {
2537
2429
  }
2538
2430
  return response.body.pipeThrough(this.createRecordParserTransform());
2539
2431
  }
2540
- /**
2541
- * Watches an existing agent builder action run by runId.
2542
- * This is used for hot reload recovery - it loads the existing run state
2543
- * and streams any remaining progress.
2544
- * This calls `/api/agent-builder/:actionId/watch`.
2545
- */
2546
- async watch({ runId, eventType }, onRecord) {
2547
- const url = `/api/agent-builder/${this.actionId}/watch?runId=${runId}${eventType ? `&eventType=${eventType}` : ""}`;
2548
- const response = await this.request(url, {
2549
- method: "GET",
2550
- stream: true
2551
- });
2552
- if (!response.ok) {
2553
- throw new Error(`Failed to watch agent builder action: ${response.statusText}`);
2554
- }
2555
- if (!response.body) {
2556
- throw new Error("Response body is null");
2557
- }
2558
- for await (const record of this.streamProcessor(response.body)) {
2559
- if (typeof record === "string") {
2560
- onRecord(JSON.parse(record));
2561
- } else {
2562
- onRecord(record);
2563
- }
2564
- }
2565
- }
2566
2432
  /**
2567
2433
  * Observes an existing agent builder action run stream.
2568
2434
  * Replays cached execution from the beginning, then continues with live stream.
@@ -2680,11 +2546,11 @@ var AgentBuilder = class extends BaseResource {
2680
2546
  if (params?.toDate) {
2681
2547
  searchParams.set("toDate", params.toDate.toISOString());
2682
2548
  }
2683
- if (params?.limit !== void 0) {
2684
- searchParams.set("limit", String(params.limit));
2549
+ if (params?.perPage !== void 0) {
2550
+ searchParams.set("perPage", String(params.perPage));
2685
2551
  }
2686
- if (params?.offset !== void 0) {
2687
- searchParams.set("offset", String(params.offset));
2552
+ if (params?.page !== void 0) {
2553
+ searchParams.set("page", String(params.page));
2688
2554
  }
2689
2555
  if (params?.resourceId) {
2690
2556
  searchParams.set("resourceId", params.resourceId);
@@ -2781,7 +2647,7 @@ var Observability = class extends BaseResource {
2781
2647
  * @param params - Parameters containing trace ID, span ID, and pagination options
2782
2648
  * @returns Promise containing scores and pagination info
2783
2649
  */
2784
- getScoresBySpan(params) {
2650
+ listScoresBySpan(params) {
2785
2651
  const { traceId, spanId, page, perPage } = params;
2786
2652
  const searchParams = new URLSearchParams();
2787
2653
  if (page !== void 0) {
@@ -2844,8 +2710,8 @@ var MastraClient = class extends BaseResource {
2844
2710
  const queryParams = new URLSearchParams({
2845
2711
  resourceId: params.resourceId,
2846
2712
  agentId: params.agentId,
2847
- ...params.offset !== void 0 && { offset: params.offset.toString() },
2848
- ...params.limit !== void 0 && { limit: params.limit.toString() },
2713
+ ...params.page !== void 0 && { page: params.page.toString() },
2714
+ ...params.perPage !== void 0 && { perPage: params.perPage.toString() },
2849
2715
  ...params.orderBy && { orderBy: params.orderBy },
2850
2716
  ...params.sortDirection && { sortDirection: params.sortDirection }
2851
2717
  });
@@ -3085,16 +2951,16 @@ var MastraClient = class extends BaseResource {
3085
2951
  }
3086
2952
  /**
3087
2953
  * Retrieves a list of available MCP servers.
3088
- * @param params - Optional parameters for pagination (limit, offset).
2954
+ * @param params - Optional parameters for pagination (perPage, page).
3089
2955
  * @returns Promise containing the list of MCP servers and pagination info.
3090
2956
  */
3091
2957
  getMcpServers(params) {
3092
2958
  const searchParams = new URLSearchParams();
3093
- if (params?.limit !== void 0) {
3094
- searchParams.set("limit", String(params.limit));
2959
+ if (params?.perPage !== void 0) {
2960
+ searchParams.set("perPage", String(params.perPage));
3095
2961
  }
3096
- if (params?.offset !== void 0) {
3097
- searchParams.set("offset", String(params.offset));
2962
+ if (params?.page !== void 0) {
2963
+ searchParams.set("page", String(params.page));
3098
2964
  }
3099
2965
  const queryString = searchParams.toString();
3100
2966
  return this.request(`/api/mcp/v0/servers${queryString ? `?${queryString}` : ""}`);
@@ -3217,7 +3083,7 @@ var MastraClient = class extends BaseResource {
3217
3083
  getScorer(scorerId) {
3218
3084
  return this.request(`/api/scores/scorers/${encodeURIComponent(scorerId)}`);
3219
3085
  }
3220
- getScoresByScorerId(params) {
3086
+ listScoresByScorerId(params) {
3221
3087
  const { page, perPage, scorerId, entityId, entityType } = params;
3222
3088
  const searchParams = new URLSearchParams();
3223
3089
  if (entityId) {
@@ -3240,7 +3106,7 @@ var MastraClient = class extends BaseResource {
3240
3106
  * @param params - Parameters containing run ID and pagination options
3241
3107
  * @returns Promise containing scores and pagination info
3242
3108
  */
3243
- getScoresByRunId(params) {
3109
+ listScoresByRunId(params) {
3244
3110
  const { runId, page, perPage } = params;
3245
3111
  const searchParams = new URLSearchParams();
3246
3112
  if (page !== void 0) {
@@ -3257,7 +3123,7 @@ var MastraClient = class extends BaseResource {
3257
3123
  * @param params - Parameters containing entity ID, type, and pagination options
3258
3124
  * @returns Promise containing scores and pagination info
3259
3125
  */
3260
- getScoresByEntityId(params) {
3126
+ listScoresByEntityId(params) {
3261
3127
  const { entityId, entityType, page, perPage } = params;
3262
3128
  const searchParams = new URLSearchParams();
3263
3129
  if (page !== void 0) {
@@ -3282,21 +3148,14 @@ var MastraClient = class extends BaseResource {
3282
3148
  body: params
3283
3149
  });
3284
3150
  }
3285
- /**
3286
- * Retrieves model providers with available keys
3287
- * @returns Promise containing model providers with available keys
3288
- */
3289
- getModelProviders() {
3290
- return this.request(`/api/model-providers`);
3291
- }
3292
3151
  getAITrace(traceId) {
3293
3152
  return this.observability.getTrace(traceId);
3294
3153
  }
3295
3154
  getAITraces(params) {
3296
3155
  return this.observability.getTraces(params);
3297
3156
  }
3298
- getScoresBySpan(params) {
3299
- return this.observability.getScoresBySpan(params);
3157
+ listScoresBySpan(params) {
3158
+ return this.observability.listScoresBySpan(params);
3300
3159
  }
3301
3160
  score(params) {
3302
3161
  return this.observability.score(params);