@mastra/client-js 0.0.0-fix-cloud-peer-deps-20250923194656 → 0.0.0-fix-cloud-peer-deps-libsql-20250929202200

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
@@ -223,11 +223,7 @@ async function executeToolCallAndRespond({
223
223
  }
224
224
  );
225
225
  const updatedMessages = [
226
- {
227
- role: "user",
228
- content: params.messages
229
- },
230
- ...response.response.messages,
226
+ ...response.response.messages || [],
231
227
  {
232
228
  role: "tool",
233
229
  content: [
@@ -368,10 +364,6 @@ var Agent = class extends BaseResource {
368
364
  }
369
365
  );
370
366
  const updatedMessages = [
371
- {
372
- role: "user",
373
- content: params.messages
374
- },
375
367
  ...response.response.messages,
376
368
  {
377
369
  role: "tool",
@@ -1081,9 +1073,7 @@ var Agent = class extends BaseResource {
1081
1073
  toolInvocation.state = "result";
1082
1074
  toolInvocation.result = result;
1083
1075
  }
1084
- const originalMessages = processedParams.messages;
1085
- const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
1086
- const updatedMessages = lastMessage != null ? [...messageArray, ...messages.filter((m) => m.id !== lastMessage.id), lastMessage] : [...messageArray, ...messages];
1076
+ const updatedMessages = lastMessage != null ? [...messages.filter((m) => m.id !== lastMessage.id), lastMessage] : [...messages];
1087
1077
  this.processStreamResponse_vNext(
1088
1078
  {
1089
1079
  ...processedParams,
@@ -1259,12 +1249,10 @@ var Agent = class extends BaseResource {
1259
1249
  } finally {
1260
1250
  writer.releaseLock();
1261
1251
  }
1262
- const originalMessages = processedParams.messages;
1263
- const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
1264
1252
  this.processStreamResponse(
1265
1253
  {
1266
1254
  ...processedParams,
1267
- messages: [...messageArray, ...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
1255
+ messages: [...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
1268
1256
  },
1269
1257
  writable
1270
1258
  ).catch((error) => {
@@ -1511,193 +1499,6 @@ var Vector = class extends BaseResource {
1511
1499
  }
1512
1500
  };
1513
1501
 
1514
- // src/resources/legacy-workflow.ts
1515
- var RECORD_SEPARATOR = "";
1516
- var LegacyWorkflow = class extends BaseResource {
1517
- constructor(options, workflowId) {
1518
- super(options);
1519
- this.workflowId = workflowId;
1520
- }
1521
- /**
1522
- * Retrieves details about the legacy workflow
1523
- * @param runtimeContext - Optional runtime context to pass as query parameter
1524
- * @returns Promise containing legacy workflow details including steps and graphs
1525
- */
1526
- details(runtimeContext) {
1527
- return this.request(`/api/workflows/legacy/${this.workflowId}${runtimeContextQueryString(runtimeContext)}`);
1528
- }
1529
- /**
1530
- * Retrieves all runs for a legacy workflow
1531
- * @param params - Parameters for filtering runs
1532
- * @param runtimeContext - Optional runtime context to pass as query parameter
1533
- * @returns Promise containing legacy workflow runs array
1534
- */
1535
- runs(params, runtimeContext) {
1536
- const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
1537
- const searchParams = new URLSearchParams();
1538
- if (params?.fromDate) {
1539
- searchParams.set("fromDate", params.fromDate.toISOString());
1540
- }
1541
- if (params?.toDate) {
1542
- searchParams.set("toDate", params.toDate.toISOString());
1543
- }
1544
- if (params?.limit) {
1545
- searchParams.set("limit", String(params.limit));
1546
- }
1547
- if (params?.offset) {
1548
- searchParams.set("offset", String(params.offset));
1549
- }
1550
- if (params?.resourceId) {
1551
- searchParams.set("resourceId", params.resourceId);
1552
- }
1553
- if (runtimeContextParam) {
1554
- searchParams.set("runtimeContext", runtimeContextParam);
1555
- }
1556
- if (searchParams.size) {
1557
- return this.request(`/api/workflows/legacy/${this.workflowId}/runs?${searchParams}`);
1558
- } else {
1559
- return this.request(`/api/workflows/legacy/${this.workflowId}/runs`);
1560
- }
1561
- }
1562
- /**
1563
- * Creates a new legacy workflow run
1564
- * @returns Promise containing the generated run ID
1565
- */
1566
- createRun(params) {
1567
- const searchParams = new URLSearchParams();
1568
- if (!!params?.runId) {
1569
- searchParams.set("runId", params.runId);
1570
- }
1571
- return this.request(`/api/workflows/legacy/${this.workflowId}/create-run?${searchParams.toString()}`, {
1572
- method: "POST"
1573
- });
1574
- }
1575
- /**
1576
- * Starts a legacy workflow run synchronously without waiting for the workflow to complete
1577
- * @param params - Object containing the runId and triggerData
1578
- * @returns Promise containing success message
1579
- */
1580
- start(params) {
1581
- return this.request(`/api/workflows/legacy/${this.workflowId}/start?runId=${params.runId}`, {
1582
- method: "POST",
1583
- body: params?.triggerData
1584
- });
1585
- }
1586
- /**
1587
- * Resumes a suspended legacy workflow step synchronously without waiting for the workflow to complete
1588
- * @param stepId - ID of the step to resume
1589
- * @param runId - ID of the legacy workflow run
1590
- * @param context - Context to resume the legacy workflow with
1591
- * @returns Promise containing the legacy workflow resume results
1592
- */
1593
- resume({
1594
- stepId,
1595
- runId,
1596
- context
1597
- }) {
1598
- return this.request(`/api/workflows/legacy/${this.workflowId}/resume?runId=${runId}`, {
1599
- method: "POST",
1600
- body: {
1601
- stepId,
1602
- context
1603
- }
1604
- });
1605
- }
1606
- /**
1607
- * Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
1608
- * @param params - Object containing the optional runId and triggerData
1609
- * @returns Promise containing the workflow execution results
1610
- */
1611
- startAsync(params) {
1612
- const searchParams = new URLSearchParams();
1613
- if (!!params?.runId) {
1614
- searchParams.set("runId", params.runId);
1615
- }
1616
- return this.request(`/api/workflows/legacy/${this.workflowId}/start-async?${searchParams.toString()}`, {
1617
- method: "POST",
1618
- body: params?.triggerData
1619
- });
1620
- }
1621
- /**
1622
- * Resumes a suspended legacy workflow step asynchronously and returns a promise that resolves when the workflow is complete
1623
- * @param params - Object containing the runId, stepId, and context
1624
- * @returns Promise containing the workflow resume results
1625
- */
1626
- resumeAsync(params) {
1627
- return this.request(`/api/workflows/legacy/${this.workflowId}/resume-async?runId=${params.runId}`, {
1628
- method: "POST",
1629
- body: {
1630
- stepId: params.stepId,
1631
- context: params.context
1632
- }
1633
- });
1634
- }
1635
- /**
1636
- * Creates an async generator that processes a readable stream and yields records
1637
- * separated by the Record Separator character (\x1E)
1638
- *
1639
- * @param stream - The readable stream to process
1640
- * @returns An async generator that yields parsed records
1641
- */
1642
- async *streamProcessor(stream) {
1643
- const reader = stream.getReader();
1644
- let doneReading = false;
1645
- let buffer = "";
1646
- try {
1647
- while (!doneReading) {
1648
- const { done, value } = await reader.read();
1649
- doneReading = done;
1650
- if (done && !value) continue;
1651
- try {
1652
- const decoded = value ? new TextDecoder().decode(value) : "";
1653
- const chunks = (buffer + decoded).split(RECORD_SEPARATOR);
1654
- buffer = chunks.pop() || "";
1655
- for (const chunk of chunks) {
1656
- if (chunk) {
1657
- if (typeof chunk === "string") {
1658
- try {
1659
- const parsedChunk = JSON.parse(chunk);
1660
- yield parsedChunk;
1661
- } catch {
1662
- }
1663
- }
1664
- }
1665
- }
1666
- } catch {
1667
- }
1668
- }
1669
- if (buffer) {
1670
- try {
1671
- yield JSON.parse(buffer);
1672
- } catch {
1673
- }
1674
- }
1675
- } finally {
1676
- reader.cancel().catch(() => {
1677
- });
1678
- }
1679
- }
1680
- /**
1681
- * Watches legacy workflow transitions in real-time
1682
- * @param runId - Optional run ID to filter the watch stream
1683
- * @returns AsyncGenerator that yields parsed records from the legacy workflow watch stream
1684
- */
1685
- async watch({ runId }, onRecord) {
1686
- const response = await this.request(`/api/workflows/legacy/${this.workflowId}/watch?runId=${runId}`, {
1687
- stream: true
1688
- });
1689
- if (!response.ok) {
1690
- throw new Error(`Failed to watch legacy workflow: ${response.statusText}`);
1691
- }
1692
- if (!response.body) {
1693
- throw new Error("Response body is null");
1694
- }
1695
- for await (const record of this.streamProcessor(response.body)) {
1696
- onRecord(record);
1697
- }
1698
- }
1699
- };
1700
-
1701
1502
  // src/resources/tool.ts
1702
1503
  var Tool = class extends BaseResource {
1703
1504
  constructor(options, toolId) {
@@ -1734,7 +1535,7 @@ var Tool = class extends BaseResource {
1734
1535
  };
1735
1536
 
1736
1537
  // src/resources/workflow.ts
1737
- var RECORD_SEPARATOR2 = "";
1538
+ var RECORD_SEPARATOR = "";
1738
1539
  var Workflow = class extends BaseResource {
1739
1540
  constructor(options, workflowId) {
1740
1541
  super(options);
@@ -1758,7 +1559,7 @@ var Workflow = class extends BaseResource {
1758
1559
  if (done && !value) continue;
1759
1560
  try {
1760
1561
  const decoded = value ? new TextDecoder().decode(value) : "";
1761
- const chunks = (buffer + decoded).split(RECORD_SEPARATOR2);
1562
+ const chunks = (buffer + decoded).split(RECORD_SEPARATOR);
1762
1563
  buffer = chunks.pop() || "";
1763
1564
  for (const chunk of chunks) {
1764
1565
  if (chunk) {
@@ -2004,7 +1805,7 @@ var Workflow = class extends BaseResource {
2004
1805
  async transform(chunk, controller) {
2005
1806
  try {
2006
1807
  const decoded = new TextDecoder().decode(chunk);
2007
- const chunks = decoded.split(RECORD_SEPARATOR2);
1808
+ const chunks = decoded.split(RECORD_SEPARATOR);
2008
1809
  for (const chunk2 of chunks) {
2009
1810
  if (chunk2) {
2010
1811
  const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
@@ -2051,7 +1852,7 @@ var Workflow = class extends BaseResource {
2051
1852
  async transform(chunk, controller) {
2052
1853
  try {
2053
1854
  const decoded = new TextDecoder().decode(chunk);
2054
- const chunks = decoded.split(RECORD_SEPARATOR2);
1855
+ const chunks = decoded.split(RECORD_SEPARATOR);
2055
1856
  for (const chunk2 of chunks) {
2056
1857
  if (chunk2) {
2057
1858
  const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
@@ -2102,7 +1903,7 @@ var Workflow = class extends BaseResource {
2102
1903
  async transform(chunk, controller) {
2103
1904
  try {
2104
1905
  const decoded = new TextDecoder().decode(chunk);
2105
- const chunks = decoded.split(RECORD_SEPARATOR2);
1906
+ const chunks = decoded.split(RECORD_SEPARATOR);
2106
1907
  for (const chunk2 of chunks) {
2107
1908
  if (chunk2) {
2108
1909
  const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
@@ -2189,7 +1990,7 @@ var Workflow = class extends BaseResource {
2189
1990
  async start(controller) {
2190
1991
  try {
2191
1992
  for await (const record of records) {
2192
- const json = JSON.stringify(record) + RECORD_SEPARATOR2;
1993
+ const json = JSON.stringify(record) + RECORD_SEPARATOR;
2193
1994
  controller.enqueue(encoder.encode(json));
2194
1995
  }
2195
1996
  controller.close();
@@ -2312,7 +2113,7 @@ var MCPTool = class extends BaseResource {
2312
2113
  };
2313
2114
 
2314
2115
  // src/resources/agent-builder.ts
2315
- var RECORD_SEPARATOR3 = "";
2116
+ var RECORD_SEPARATOR2 = "";
2316
2117
  var AgentBuilder = class extends BaseResource {
2317
2118
  constructor(options, actionId) {
2318
2119
  super(options);
@@ -2452,7 +2253,7 @@ var AgentBuilder = class extends BaseResource {
2452
2253
  if (done && !value) continue;
2453
2254
  try {
2454
2255
  const decoded = value ? new TextDecoder().decode(value) : "";
2455
- const chunks = (buffer + decoded).split(RECORD_SEPARATOR3);
2256
+ const chunks = (buffer + decoded).split(RECORD_SEPARATOR2);
2456
2257
  buffer = chunks.pop() || "";
2457
2258
  for (const chunk of chunks) {
2458
2259
  if (chunk) {
@@ -2509,7 +2310,7 @@ var AgentBuilder = class extends BaseResource {
2509
2310
  async transform(chunk, controller) {
2510
2311
  try {
2511
2312
  const decoded = new TextDecoder().decode(chunk);
2512
- const chunks = decoded.split(RECORD_SEPARATOR3);
2313
+ const chunks = decoded.split(RECORD_SEPARATOR2);
2513
2314
  for (const chunk2 of chunks) {
2514
2315
  if (chunk2) {
2515
2316
  const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
@@ -2558,7 +2359,7 @@ var AgentBuilder = class extends BaseResource {
2558
2359
  async transform(chunk, controller) {
2559
2360
  try {
2560
2361
  const decoded = new TextDecoder().decode(chunk);
2561
- const chunks = decoded.split(RECORD_SEPARATOR3);
2362
+ const chunks = decoded.split(RECORD_SEPARATOR2);
2562
2363
  for (const chunk2 of chunks) {
2563
2364
  if (chunk2) {
2564
2365
  const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
@@ -2729,6 +2530,25 @@ var Observability = class extends BaseResource {
2729
2530
  const queryString = searchParams.toString();
2730
2531
  return this.request(`/api/observability/traces${queryString ? `?${queryString}` : ""}`);
2731
2532
  }
2533
+ /**
2534
+ * Retrieves scores by trace ID and span ID
2535
+ * @param params - Parameters containing trace ID, span ID, and pagination options
2536
+ * @returns Promise containing scores and pagination info
2537
+ */
2538
+ getScoresBySpan(params) {
2539
+ const { traceId, spanId, page, perPage } = params;
2540
+ const searchParams = new URLSearchParams();
2541
+ if (page !== void 0) {
2542
+ searchParams.set("page", String(page));
2543
+ }
2544
+ if (perPage !== void 0) {
2545
+ searchParams.set("perPage", String(perPage));
2546
+ }
2547
+ const queryString = searchParams.toString();
2548
+ return this.request(
2549
+ `/api/observability/traces/${encodeURIComponent(traceId)}/${encodeURIComponent(spanId)}/scores${queryString ? `?${queryString}` : ""}`
2550
+ );
2551
+ }
2732
2552
  score(params) {
2733
2553
  return this.request(`/api/observability/traces/score`, {
2734
2554
  method: "POST",
@@ -2801,7 +2621,7 @@ var NetworkMemoryThread = class extends BaseResource {
2801
2621
  };
2802
2622
 
2803
2623
  // src/resources/vNextNetwork.ts
2804
- var RECORD_SEPARATOR4 = "";
2624
+ var RECORD_SEPARATOR3 = "";
2805
2625
  var VNextNetwork = class extends BaseResource {
2806
2626
  constructor(options, networkId) {
2807
2627
  super(options);
@@ -2854,7 +2674,7 @@ var VNextNetwork = class extends BaseResource {
2854
2674
  if (done && !value) continue;
2855
2675
  try {
2856
2676
  const decoded = value ? new TextDecoder().decode(value) : "";
2857
- const chunks = (buffer + decoded).split(RECORD_SEPARATOR4);
2677
+ const chunks = (buffer + decoded).split(RECORD_SEPARATOR3);
2858
2678
  buffer = chunks.pop() || "";
2859
2679
  for (const chunk of chunks) {
2860
2680
  if (chunk) {
@@ -3100,21 +2920,6 @@ var MastraClient = class extends BaseResource {
3100
2920
  getTool(toolId) {
3101
2921
  return new Tool(this.options, toolId);
3102
2922
  }
3103
- /**
3104
- * Retrieves all available legacy workflows
3105
- * @returns Promise containing map of legacy workflow IDs to legacy workflow details
3106
- */
3107
- getLegacyWorkflows() {
3108
- return this.request("/api/workflows/legacy");
3109
- }
3110
- /**
3111
- * Gets a legacy workflow instance by ID
3112
- * @param workflowId - ID of the legacy workflow to retrieve
3113
- * @returns Legacy Workflow instance
3114
- */
3115
- getLegacyWorkflow(workflowId) {
3116
- return new LegacyWorkflow(this.options, workflowId);
3117
- }
3118
2923
  /**
3119
2924
  * Retrieves all available workflows
3120
2925
  * @param runtimeContext - Optional runtime context to pass as query parameter
@@ -3414,7 +3219,7 @@ var MastraClient = class extends BaseResource {
3414
3219
  * @returns Promise containing the scorer
3415
3220
  */
3416
3221
  getScorer(scorerId) {
3417
- return this.request(`/api/scores/scorers/${scorerId}`);
3222
+ return this.request(`/api/scores/scorers/${encodeURIComponent(scorerId)}`);
3418
3223
  }
3419
3224
  getScoresByScorerId(params) {
3420
3225
  const { page, perPage, scorerId, entityId, entityType } = params;
@@ -3432,7 +3237,7 @@ var MastraClient = class extends BaseResource {
3432
3237
  searchParams.set("perPage", String(perPage));
3433
3238
  }
3434
3239
  const queryString = searchParams.toString();
3435
- return this.request(`/api/scores/scorer/${scorerId}${queryString ? `?${queryString}` : ""}`);
3240
+ return this.request(`/api/scores/scorer/${encodeURIComponent(scorerId)}${queryString ? `?${queryString}` : ""}`);
3436
3241
  }
3437
3242
  /**
3438
3243
  * Retrieves scores by run ID
@@ -3449,7 +3254,7 @@ var MastraClient = class extends BaseResource {
3449
3254
  searchParams.set("perPage", String(perPage));
3450
3255
  }
3451
3256
  const queryString = searchParams.toString();
3452
- return this.request(`/api/scores/run/${runId}${queryString ? `?${queryString}` : ""}`);
3257
+ return this.request(`/api/scores/run/${encodeURIComponent(runId)}${queryString ? `?${queryString}` : ""}`);
3453
3258
  }
3454
3259
  /**
3455
3260
  * Retrieves scores by entity ID and type
@@ -3466,7 +3271,9 @@ var MastraClient = class extends BaseResource {
3466
3271
  searchParams.set("perPage", String(perPage));
3467
3272
  }
3468
3273
  const queryString = searchParams.toString();
3469
- return this.request(`/api/scores/entity/${entityType}/${entityId}${queryString ? `?${queryString}` : ""}`);
3274
+ return this.request(
3275
+ `/api/scores/entity/${encodeURIComponent(entityType)}/${encodeURIComponent(entityId)}${queryString ? `?${queryString}` : ""}`
3276
+ );
3470
3277
  }
3471
3278
  /**
3472
3279
  * Saves a score
@@ -3492,6 +3299,9 @@ var MastraClient = class extends BaseResource {
3492
3299
  getAITraces(params) {
3493
3300
  return this.observability.getTraces(params);
3494
3301
  }
3302
+ getScoresBySpan(params) {
3303
+ return this.observability.getScoresBySpan(params);
3304
+ }
3495
3305
  score(params) {
3496
3306
  return this.observability.score(params);
3497
3307
  }