@mastra/client-js 1.48.1-alpha.0 → 1.49.0-alpha.1

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.
@@ -3,7 +3,7 @@ name: mastra-client-js
3
3
  description: Documentation for @mastra/client-js. Use when working with @mastra/client-js APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/client-js"
6
- version: "1.48.1-alpha.0"
6
+ version: "1.49.0-alpha.1"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.48.1-alpha.0",
2
+ "version": "1.49.0-alpha.1",
3
3
  "package": "@mastra/client-js",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -90,6 +90,37 @@ agent.queueMessage('Also check whether the tests need updates.', {
90
90
 
91
91
  When the thread is idle, `queueMessage()` starts a run immediately. When the thread is active, it preserves turn order by starting a new run after the active run completes.
92
92
 
93
+ ### Cancel pending input
94
+
95
+ Use [`cancelQueuedMessages()`](https://mastra.ai/reference/agents/agent) to remove selected pending input without stopping the active run. Cancellation is scoped to the memory thread, including input submitted by other Agents sharing the same runtime and PubSub instance.
96
+
97
+ The thread must still have a pending message to cancel. This example assumes a run is active when you queue the message. An idle thread starts the message immediately instead.
98
+
99
+ ```typescript
100
+ const queued = agent.queueMessage('Also check the tests.', thread)
101
+ await queued.accepted
102
+
103
+ const { cancelledSignalIds } = agent.cancelQueuedMessages({
104
+ ...thread,
105
+ signalIds: [queued.signal.id],
106
+ })
107
+ console.log(cancelledSignalIds)
108
+ ```
109
+
110
+ Only IDs removed locally by this call appear in `cancelledSignalIds`. Mastra still publishes every requested ID through PubSub, even when none are pending locally, so other processes subscribed to the thread can cancel their matching pending input. Because that propagation is asynchronous, the result doesn't confirm remote cancellation, and input that has already been handed to execution is out of reach. Cancellation doesn't delete saved messages, notification records, or state updates, and it never revokes an earlier acceptance acknowledgement.
111
+
112
+ ### Stop the run and clear pending input
113
+
114
+ By default, aborting a thread preserves its queued input. To clear pending signals before stopping the active run, pass `clearPendingSignals: true`:
115
+
116
+ ```typescript
117
+ subscription.abort({ clearPendingSignals: true })
118
+ ```
119
+
120
+ Without a subscription, use `agent.abortThreadStream({ ...thread, clearPendingSignals: true })`. Existing listeners stay subscribed after cancellation, and later messages can still start a new run.
121
+
122
+ With a shared PubSub backend, the runtime receives remote signals, cancellation, and abort requests independently of `subscribeToThread()` observers. Clear-on-abort sends the clear flag to a remote active owner through PubSub, but it doesn't clear every process's local queues. Neither operation cancels continuations created by `continueWithMessages()`.
123
+
93
124
  ## Signal context
94
125
 
95
126
  ### Control low-level signal behavior
@@ -310,6 +310,52 @@ await subscription.processDataStream({
310
310
 
311
311
  **processDataStream().reconnect** (`boolean | { maxRetries?: number; delayMs?: number }`): Reconnects the subscription stream after it closes or a reconnect request fails. true retries indefinitely with a one-second delay.
312
312
 
313
+ The subscription also exposes `abort(options?)` and `unsubscribe()`. `await subscription.abort({ clearPendingSignals: true })` requests an abort and clears pending signals without closing the subscription. Omit the flag to preserve pending input. `unsubscribe()` closes the subscription without aborting the run.
314
+
315
+ ### `abortThread()`
316
+
317
+ Requests cancellation of the thread's active run. Set `clearPendingSignals: true` to clear pending signals before aborting.
318
+
319
+ ```typescript
320
+ const { aborted } = await agent.abortThread({
321
+ resourceId: 'user-123',
322
+ threadId: 'thread-abc',
323
+ clearPendingSignals: true,
324
+ })
325
+ ```
326
+
327
+ **resourceId** (`string`): Resource ID for the memory thread.
328
+
329
+ **threadId** (`string`): Thread to abort.
330
+
331
+ **clearPendingSignals** (`boolean`): Clear pending signals across Agents sharing the thread before aborting. Continuations from continueWithMessages() are excluded. (Default: `false`)
332
+
333
+ Returns `{ aborted: boolean }`. For a remote active owner, `aborted: true` means the request was sent, not acknowledged. Clear-on-abort affects the receiving server's local queues and is forwarded to the active owner. It isn't a global queue clear. Local pending signals are still cleared if no active run is found and `aborted` is `false`.
334
+
335
+ ### `cancelQueuedMessages()`
336
+
337
+ Cancels selected pending signals without stopping the active run. The operation covers pending input across Agents sharing the same memory thread on the server process handling this request. Unlike the core method, the SDK accepts only signal IDs, not `queueOwnerId`.
338
+
339
+ ```typescript
340
+ const { cancelledSignalIds } = await agent.cancelQueuedMessages({
341
+ resourceId: 'user-123',
342
+ threadId: 'thread-abc',
343
+ signalIds: ['signal-123', 'signal-456'],
344
+ })
345
+ ```
346
+
347
+ **resourceId** (`string`): Resource ID for the memory thread.
348
+
349
+ **threadId** (`string`): Thread containing the pending signals.
350
+
351
+ **signalIds** (`string[]`): Between 1 and 1,000 nonempty signal IDs. Duplicate and unknown IDs are ignored.
352
+
353
+ Returns `{ cancelledSignalIds: string[] }` with each ID cancelled on the receiving server process once. The response doesn't include remote acknowledgements. Signals already handed to execution or another owner aren't included. Missing, empty, or oversized ID lists return HTTP 400. Thread ownership restrictions apply to both cancellation routes.
354
+
355
+ The server publishes all requested IDs through its shared PubSub backend, even when none are pending on the receiving process. Other subscribed instances can then remove matching pending input, but this best-effort, asynchronous propagation doesn't confirm remote cancellation. Cancellation doesn't undo saved messages, state updates, notification records, or acceptance acknowledgements. It doesn't cancel continuations from `continueWithMessages()`.
356
+
357
+ The server must use a core version supporting thread-wide cancellation and clear-on-abort. Upgrade `@mastra/core` alongside `@mastra/server`. Unsupported requests return HTTP 501 rather than using older cancellation behavior. With fine-grained authorization enabled, both cancellation routes require `memory:write` permission on the thread in addition to Agent execution permission.
358
+
313
359
  ### `streamUntilIdle()`
314
360
 
315
361
  Stream a response and keep the stream open until every [background task](https://mastra.ai/docs/harness/background-tasks) dispatched during the run completes. The server re-enters the agentic loop on each task completion so the LLM can react to results in the same call. Requires background tasks to be [enabled on the Mastra instance](https://mastra.ai/reference/configuration) and a memory thread; otherwise the call uses a plain `stream()`.
@@ -140,7 +140,7 @@ Returns `Promise<DatasetExperiment>`, the updated experiment record.
140
140
 
141
141
  ## deleteDatasetExperiment()
142
142
 
143
- Deletes an experiment through its dataset. The server deletes the experiment's result records and attempts to delete its observability traces, including their spans and trace-linked signals, but unsupported storage leaves the traces in place and causes the server to log a warning. If trace cleanup fails after an earlier batch succeeds, the promise rejects and preserves the experiment and result records even though some traces may already have been removed.
143
+ Deletes an experiment through its dataset. The server deletes the experiment's observability traces, including their spans and trace-linked signals, and then deletes the experiment and its result records. Unsupported storage leaves the traces in place, and the server logs a warning. If trace deletion fails for any other reason, the promise rejects and Mastra keeps the experiment and its result records, although some traces may already have been removed.
144
144
 
145
145
  ```typescript
146
146
  await client.deleteDatasetExperiment('dataset-id', 'experiment-id', {
@@ -161,7 +161,7 @@ Returns `Promise<{ success: boolean }>`. A missing experiment, an experiment ass
161
161
 
162
162
  ## deleteExperiment()
163
163
 
164
- Deletes an experiment by ID without requiring a dataset reference. Use this method for experiments orphaned by dataset deletion. The server deletes the experiment's result records and attempts to delete its observability traces, but unsupported storage leaves the traces in place and causes the server to log a warning. If trace cleanup fails after an earlier batch succeeds, the promise rejects and preserves the experiment and result records even though some traces may already have been removed.
164
+ Deletes an experiment by ID without requiring a dataset reference. Use this method for experiments orphaned by dataset deletion. The server deletes the experiment's observability traces and then deletes the experiment and its result records. Unsupported storage leaves the traces in place, and the server logs a warning. If trace deletion fails for any other reason, the promise rejects and Mastra keeps the experiment and its result records, although some traces may already have been removed.
165
165
 
166
166
  ```typescript
167
167
  await client.deleteExperiment('experiment-id', {
@@ -189,7 +189,7 @@ await client.purgeDatasetItem('dataset-id', 'item-id', {
189
189
  })
190
190
  ```
191
191
 
192
- The optional third argument scopes the purge to a tenant organization and project. The server returns `404` when the dataset doesn't belong to that scope.
192
+ The optional third argument scopes the purge to a tenant organization and project. The server returns `404` when the dataset doesn't belong to that scope or the item has no history in the dataset.
193
193
 
194
194
  Returns `Promise<{ success: boolean }>`. The operation is idempotent and can't be undone. Purge serializes or conflicts with concurrent dataset item writers without guaranteeing which operation completes first. If a mutating item update loses the race, storage re-reads the purge marker and rejects it with `DATASET_ITEM_PURGED`. Deletes remain idempotent, and any deletion tombstone created during the race stays redacted. MongoDB storage requires a replica set or sharded deployment with transaction support. See [`dataset.purgeItem()`](https://mastra.ai/reference/datasets/purgeItem) for the complete purge behavior.
195
195
 
@@ -229,7 +229,7 @@ const result = await mastraClient.deleteTraces({
229
229
  console.log(result.success)
230
230
  ```
231
231
 
232
- Each request accepts up to 1,000 trace IDs. Signals that aren't linked to a trace are preserved. Deletion also includes traces created by experiments.
232
+ Each request accepts up to 1,000 trace IDs and no tenant scope fields. Signals that aren't linked to a trace are preserved. Traces created by experiments are deleted like any other trace.
233
233
 
234
234
  ## Scoring traces
235
235
 
@@ -217,7 +217,7 @@ Value suggestions are available for these canonical fields:
217
217
 
218
218
  | Scope | Fields |
219
219
  | -------- | ----------------------------------------------------------------------------- |
220
- | Trace | `entityName`, `entityType`, `environment`, `status` |
220
+ | Trace | `entityName`, `entityType`, `environment`, `status`, `tags` |
221
221
  | Spans | `name`, `spanType`, `model`, `provider`, `status`, `entityType`, `entityName` |
222
222
  | Scores | `scorerId`, `scorerVersion`, `scoreSource` |
223
223
  | Feedback | `feedbackType`, `feedbackSource` |
@@ -288,6 +288,7 @@ Hono and Fastify enforce the request-body limit before JSON parsing. Express and
288
288
  | Trace | `traceId`, `threadId`, `resourceId`, `entityName`, `entityType`, `environment`, `status` | `eq`, `ne`, `in`, `notIn`, `exists`, `notExists` |
289
289
  | Trace metadata | `metadata.<key>` | `eq`, `ne`, `in`, `notIn`, `exists`, `notExists` |
290
290
  | Trace | `startedAt`, `endedAt` | `eq`, `ne`, `in`, `notIn`, `lt`, `lte`, `gt`, `gte`, `exists`, `notExists` |
291
+ | Trace | `tags` | `includes`, `notIncludes`, `exists`, `notExists` |
291
292
  | Span | `name`, `spanType`, `model`, `provider`, `status`, `entityType`, `entityId`, `entityName`, `entityVersionId`, `parentEntityVersionId`, `rootEntityVersionId` | `eq`, `ne`, `in`, `notIn`, `exists`, `notExists` |
292
293
  | Span | `startedAt`, `endedAt`, `durationMs` | `eq`, `ne`, `in`, `notIn`, `lt`, `lte`, `gt`, `gte`, `exists`, `notExists` |
293
294
  | Span | `error` | `exists`, `notExists` |
@@ -298,7 +299,7 @@ Hono and Fastify enforce the request-body limit before JSON parsing. Express and
298
299
  | Feedback | `value`, `timestamp` | `eq`, `ne`, `in`, `notIn`, `lt`, `lte`, `gt`, `gte`, `exists`, `notExists` |
299
300
  | Feedback | `comment` | `exists`, `notExists` |
300
301
 
301
- Compose predicates with `{ op: 'and', args: [...] }`, `{ op: 'or', args: [...] }`, and `{ op: 'not', arg: ... }`. Comparison predicates place a field reference on the left and a literal on the right. Membership predicates use a field reference in `value` and a homogeneous literal array in `set`.
302
+ Compose predicates with `{ op: 'and', args: [...] }`, `{ op: 'or', args: [...] }`, and `{ op: 'not', arg: ... }`. Comparison predicates place a field reference on the left and a literal on the right. Membership predicates use a field reference in `value` and a homogeneous literal array in `set`. Tag predicates name the stored tag collection in `path`. `includes` and `notIncludes` also take one tag in `value`, while `exists` and `notExists` take only `op` and `path`. See [Filter by tags](#filter-by-tags).
302
303
 
303
304
  String comparisons are case-sensitive, and literals are never coerced. Canonical string fields compare exact stored values. Metadata string values are trimmed before comparison, as described below. Numeric predicates, including `score` and `durationMs`, require numbers, while timestamp predicates require ISO timestamp strings. A missing value satisfies neither positive nor ordered predicates, although it does satisfy the negative operators `ne` and `notIn`. Combine a negative predicate with `exists` when the field must also be present.
304
305
 
@@ -456,6 +457,32 @@ The key must name one top-level property. Empty keys and nested paths are reject
456
457
 
457
458
  Metadata fields aren't available for grouping. Trace-query discovery returns executable top-level string metadata fields observed in the selected time range.
458
459
 
460
+ ### Filter by tags
461
+
462
+ Tags are a list of strings stored on the current root span, so they use collection operators instead of the scalar `in` and `notIn` operators. This query finds production traces tagged for manual review that don't carry the `archived` tag:
463
+
464
+ ```typescript
465
+ const manualReview = {
466
+ op: 'and',
467
+ args: [
468
+ { op: 'eq', left: { path: 'environment' }, right: { literal: 'production' } },
469
+ { op: 'includes', path: 'tags', value: 'manual-review' },
470
+ { op: 'notIncludes', path: 'tags', value: 'archived' },
471
+ ],
472
+ }
473
+ ```
474
+
475
+ | Operator | Matches when |
476
+ | ------------- | --------------------------------------------------------- |
477
+ | `includes` | The trace has the requested tag |
478
+ | `notIncludes` | The trace has at least one tag, but not the requested tag |
479
+ | `exists` | The trace has at least one tag |
480
+ | `notExists` | The trace has no tags |
481
+
482
+ Tags compare exactly and case-sensitively as whole strings. `value` must be one string with at least one non-whitespace character. Combine several `includes` predicates with `and` or `or` to require or allow multiple tags. A trace with no recorded tags and a trace with an empty tag list behave the same: both satisfy `notExists`, neither satisfies `includes`, `notIncludes`, or `exists`. Use `{ op: 'not', arg: { op: 'includes', ... } }` when untagged traces should also match.
483
+
484
+ `tags` is available in trace predicates only, including those inside `traces.some` or `traces.none`. `in`, `notIn`, and the comparison operators are rejected for `tags`. Value discovery for `tags` returns each observed tag with the number of qualifying traces that carry it.
485
+
459
486
  ### Filter by feedback
460
487
 
461
488
  Every condition inside one `feedback.some` or `feedback.none` clause applies to the same current feedback record. `feedbackType` and `feedbackSource` are exact application-defined strings rather than built-in enums. This query finds traces with a numeric patient rating below zero:
package/dist/index.cjs CHANGED
@@ -1019,9 +1019,10 @@ var Agent = class extends BaseResource {
1019
1019
  const streamResponse = await requestSubscription();
1020
1020
  if (!streamResponse.body) throw new Error("No response body");
1021
1021
  const agent = this;
1022
- streamResponse.abort = async () => (await agent.abortThread({
1022
+ streamResponse.abort = async (options) => (await agent.abortThread({
1023
1023
  resourceId,
1024
- threadId
1024
+ threadId,
1025
+ ...options
1025
1026
  })).aborted;
1026
1027
  let unsubscribed = false;
1027
1028
  let processAbortController;
@@ -1265,16 +1266,29 @@ var Agent = class extends BaseResource {
1265
1266
  * @experimental Agent signals are experimental and may change in a future release.
1266
1267
  */
1267
1268
  async abortThread(params) {
1268
- const { resourceId, threadId, expectedRunId } = params;
1269
+ const { resourceId, threadId, clearPendingSignals, expectedRunId } = params;
1269
1270
  return this.request(`/agents/${this.agentId}/threads/abort`, {
1270
1271
  method: "POST",
1271
1272
  body: {
1272
1273
  resourceId,
1273
1274
  threadId,
1275
+ ...clearPendingSignals === void 0 ? {} : { clearPendingSignals },
1274
1276
  ...expectedRunId === void 0 ? {} : { expectedRunId }
1275
1277
  }
1276
1278
  });
1277
1279
  }
1280
+ /** @experimental Cancels pending thread signals and propagates requested IDs through shared PubSub. */
1281
+ cancelQueuedMessages(params) {
1282
+ const { resourceId, threadId, signalIds } = params;
1283
+ return this.request(`/agents/${this.agentId}/threads/signals/cancel`, {
1284
+ method: "POST",
1285
+ body: {
1286
+ resourceId,
1287
+ threadId,
1288
+ signalIds
1289
+ }
1290
+ });
1291
+ }
1278
1292
  /**
1279
1293
  * Clones this agent to a new stored agent in the database
1280
1294
  * @param params - Clone parameters including optional newId, newName, metadata, authorId, and requestContext