@mastra/client-js 1.46.1-alpha.0 → 1.47.0-alpha.10

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.
Files changed (60) hide show
  1. package/dist/_types/@ai-sdk_provider/package.json +1 -0
  2. package/dist/_types/@ai-sdk_provider-utils/dist/index.d.ts +1 -1
  3. package/dist/_types/@ai-sdk_provider-utils/package.json +1 -0
  4. package/dist/_types/@ai-sdk_ui-utils/dist/index.d.ts +3 -3
  5. package/dist/_types/@ai-sdk_ui-utils/package.json +1 -0
  6. package/dist/client.d.ts +57 -208
  7. package/dist/client.d.ts.map +1 -1
  8. package/dist/docs/SKILL.md +2 -2
  9. package/dist/docs/assets/SOURCE_MAP.json +1 -1
  10. package/dist/docs/references/docs-connections-a2a.md +4 -3
  11. package/dist/docs/references/docs-harness-agent-controller.md +4 -2
  12. package/dist/docs/references/reference-client-js-agent-controller.md +77 -16
  13. package/dist/docs/references/reference-client-js-agents.md +25 -0
  14. package/dist/docs/references/reference-client-js-mastra-client.md +1 -1
  15. package/dist/docs/references/reference-client-js-observability.md +104 -5
  16. package/dist/docs/references/reference-observability-tracing-trace-query.md +219 -46
  17. package/dist/index.cjs +353 -165
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.ts +3 -1
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +354 -166
  22. package/dist/index.js.map +1 -1
  23. package/dist/resources/a2a.d.ts +5 -1
  24. package/dist/resources/a2a.d.ts.map +1 -1
  25. package/dist/resources/agent-builder.d.ts +25 -40
  26. package/dist/resources/agent-builder.d.ts.map +1 -1
  27. package/dist/resources/agent-controller.d.ts +5 -4
  28. package/dist/resources/agent-controller.d.ts.map +1 -1
  29. package/dist/resources/agent.d.ts +46 -74
  30. package/dist/resources/agent.d.ts.map +1 -1
  31. package/dist/resources/base.d.ts.map +1 -1
  32. package/dist/resources/channels.d.ts +13 -31
  33. package/dist/resources/channels.d.ts.map +1 -1
  34. package/dist/resources/conversations.d.ts +6 -3
  35. package/dist/resources/conversations.d.ts.map +1 -1
  36. package/dist/resources/mcp-tool.d.ts +9 -6
  37. package/dist/resources/mcp-tool.d.ts.map +1 -1
  38. package/dist/resources/memory-thread.d.ts +11 -11
  39. package/dist/resources/memory-thread.d.ts.map +1 -1
  40. package/dist/resources/observability-route-types.d.ts +101 -0
  41. package/dist/resources/observability-route-types.d.ts.map +1 -0
  42. package/dist/resources/observability.d.ts +35 -8
  43. package/dist/resources/observability.d.ts.map +1 -1
  44. package/dist/resources/responses.d.ts +5 -2
  45. package/dist/resources/responses.d.ts.map +1 -1
  46. package/dist/resources/run.d.ts +21 -57
  47. package/dist/resources/run.d.ts.map +1 -1
  48. package/dist/resources/tool.d.ts +6 -4
  49. package/dist/resources/tool.d.ts.map +1 -1
  50. package/dist/resources/vector.d.ts +5 -10
  51. package/dist/resources/vector.d.ts.map +1 -1
  52. package/dist/resources/workflow.d.ts +8 -10
  53. package/dist/resources/workflow.d.ts.map +1 -1
  54. package/dist/route-types.generated.d.ts +3010 -2190
  55. package/dist/route-types.generated.d.ts.map +1 -1
  56. package/dist/types.d.ts +252 -1593
  57. package/dist/types.d.ts.map +1 -1
  58. package/dist/utils/index.d.ts +7 -0
  59. package/dist/utils/index.d.ts.map +1 -1
  60. package/package.json +10 -10
@@ -4,9 +4,9 @@
4
4
 
5
5
  # Advanced trace queries
6
6
 
7
- Use `POST /api/observability/traces/query` to find completed logical traces that match trace fields and related span or score records. The endpoint returns a fixed lightweight trace projection, or distinct thread IDs when you group by `threadId`.
7
+ Use `queryTraces()` or `POST /api/observability/traces/query` to find completed logical traces that match trace fields and related span, score, or feedback records. Use `queryTraceThreads()` or `POST /api/observability/threads/query` to find thread identities that qualify across multiple eligible traces.
8
8
 
9
- The endpoint uses the same authentication as other observability routes and requires the `observability:read` permission. The configured observability store must support advanced trace queries.
9
+ Both endpoints use the same authentication as other observability routes and require the `observability:read` permission. The configured observability store must support the requested trace-query or thread-query operation.
10
10
 
11
11
  ## Query traces with the client SDK
12
12
 
@@ -37,7 +37,74 @@ const result = await mastraClient.queryTraces({
37
37
 
38
38
  A `some` clause matches when one related record satisfies its complete nested predicate. In this example, `scorerId`, `scorerVersion`, and `score` must match on the same score record. A `none` clause uses anti-existence semantics: it matches when no related record satisfies its complete nested predicate. A trace with no related scores therefore matches `scores.none`.
39
39
 
40
- Span clauses examine the current root span and current child spans. The root `timeRange` applies only to the selected current root's `startedAt`. Related spans and scores can participate even when their own timestamps are outside that range. Related records correlate only through a matching non-null `traceId`.
40
+ Span clauses examine the current root span and current child spans. The root `timeRange` applies only to the selected current root's `startedAt`. Related spans, scores, and feedback can participate even when their own timestamps are outside that range. Related records correlate only through a matching non-null `traceId`.
41
+
42
+ ## Query threads across traces
43
+
44
+ Pass an eligible trace selection and an optional thread predicate to `queryTraceThreads()`:
45
+
46
+ ```typescript
47
+ const result = await mastraClient.queryTraceThreads({
48
+ traces: {
49
+ timeRange: {
50
+ from: '2026-08-01T00:00:00.000Z',
51
+ to: '2026-08-08T00:00:00.000Z',
52
+ },
53
+ where: {
54
+ op: 'eq',
55
+ left: { path: 'environment' },
56
+ right: { literal: 'production' },
57
+ },
58
+ },
59
+ where: {
60
+ op: 'and',
61
+ args: [
62
+ {
63
+ traces: {
64
+ some: {
65
+ scores: {
66
+ some: {
67
+ op: 'lt',
68
+ left: { path: 'score' },
69
+ right: { literal: 0.6 },
70
+ },
71
+ },
72
+ },
73
+ },
74
+ },
75
+ {
76
+ traces: {
77
+ some: {
78
+ feedback: {
79
+ some: {
80
+ op: 'eq',
81
+ left: { path: 'feedbackType' },
82
+ right: { literal: 'clinician-correction' },
83
+ },
84
+ },
85
+ },
86
+ },
87
+ },
88
+ ],
89
+ },
90
+ page: { limit: 25 },
91
+ })
92
+ ```
93
+
94
+ The server applies `traces.timeRange` and `traces.where` first. This produces the complete eligible trace population. It then derives distinct non-null `threadId` values and evaluates the top-level `where` predicate against eligible traces in each thread.
95
+
96
+ One `traces.some` clause requires one eligible trace to satisfy its complete nested trace predicate. Separate `traces.some` clauses are independent, so different traces in the same thread can satisfy them. Nested `spans.some`, `scores.some`, and `feedback.some` clauses still require one related record to satisfy every condition inside that clause.
97
+
98
+ `traces.none: P` uses anti-existence semantics: it matches only when no eligible trace in the thread satisfies `P`. This differs from `traces.some: { feedback: { none: P } }`, which requires at least one eligible trace with no matching feedback record.
99
+
100
+ The response contains identities only:
101
+
102
+ ```json
103
+ {
104
+ "threads": [{ "threadId": "thread-123" }],
105
+ "page": { "next": null }
106
+ }
107
+ ```
41
108
 
42
109
  ## Send an HTTP request
43
110
 
@@ -65,34 +132,143 @@ curl --request POST \
65
132
  }'
66
133
  ```
67
134
 
135
+ ## Discover fields and values
136
+
137
+ Use trace-query discovery to build field and value autocomplete without scanning trace payloads or copying the query grammar into your client. The configured observability store must support `trace-query-discovery`.
138
+
139
+ Call `getTraceQueryFields()` for one predicate scope:
140
+
141
+ ```typescript
142
+ const timeRange = {
143
+ from: '2026-08-01T00:00:00.000Z',
144
+ to: '2026-08-08T00:00:00.000Z',
145
+ }
146
+
147
+ const fields = await mastraClient.getTraceQueryFields({
148
+ timeRange,
149
+ predicateScope: 'trace',
150
+ search: 'region',
151
+ limit: 25,
152
+ })
153
+ ```
154
+
155
+ The response separates canonical fields from observed metadata fields:
156
+
157
+ ```json
158
+ {
159
+ "canonicalFields": [],
160
+ "observedFields": [
161
+ {
162
+ "path": "metadata.region",
163
+ "valueKind": "string",
164
+ "operators": ["eq", "ne", "in", "notIn", "exists", "notExists"],
165
+ "valueSuggestions": true,
166
+ "occurrences": 125
167
+ }
168
+ ],
169
+ "observedFieldsTruncated": false
170
+ }
171
+ ```
172
+
173
+ Canonical fields come from the same registry used to validate trace queries. They don't consume `limit`. The canonical order follows that registry. `observedFields` contains top-level string `metadata.<key>` paths found on qualifying current root spans. These fields are ordered by `occurrences` descending, then by path. Nested metadata, keys containing `.`, empty keys, non-string values, and oversized paths are omitted.
174
+
175
+ `predicateScope` selects the local predicate grammar. It isn't an authorization scope:
176
+
177
+ | `predicateScope` | Example returned path | Query usage |
178
+ | ---------------- | ---------------------------------- | ----------------------------------------- |
179
+ | `trace` | `environment` or `metadata.region` | Root `where` predicate |
180
+ | `spans` | `model` | Inside `spans.some` or `spans.none` |
181
+ | `scores` | `scorerId` | Inside `scores.some` or `scores.none` |
182
+ | `feedback` | `feedbackType` | Inside `feedback.some` or `feedback.none` |
183
+
184
+ A global field picker can request all four scopes in parallel and qualify display labels locally. Every returned path is directly accepted by `queryTraces()` in its matching scope. `metadata` by itself isn't a field. A user interface can offer manual metadata-key entry separately.
185
+
186
+ After a user selects one field with `valueSuggestions: true`, call `getTraceQueryValues()`:
187
+
188
+ ```typescript
189
+ const abortController = new AbortController()
190
+ const suggestions = await mastraClient.getTraceQueryValues(
191
+ {
192
+ timeRange,
193
+ predicateScope: 'trace',
194
+ path: 'metadata.region',
195
+ search: 'west',
196
+ limit: 25,
197
+ },
198
+ { signal: abortController.signal },
199
+ )
200
+ ```
201
+
202
+ ```json
203
+ {
204
+ "values": [
205
+ { "value": "eu-west-1", "count": 82 },
206
+ { "value": "us-west-2", "count": 43 }
207
+ ],
208
+ "valuesTruncated": false
209
+ }
210
+ ```
211
+
212
+ Discovery returns string values only. Missing values, empty strings, and strings larger than 4,096 UTF-8 bytes are omitted. Values are ordered by `count` descending, then by value. Suggestions are advisory: `queryTraces()` continues to accept valid manual literals that discovery doesn't return.
213
+
214
+ Value suggestions are available for these canonical fields:
215
+
216
+ | Scope | Fields |
217
+ | -------- | ----------------------------------------------------------------------------- |
218
+ | Trace | `entityName`, `entityType`, `environment`, `status` |
219
+ | Spans | `name`, `spanType`, `model`, `provider`, `status`, `entityType`, `entityName` |
220
+ | Scores | `scorerId`, `scorerVersion`, `scoreSource` |
221
+ | Feedback | `feedbackType`, `feedbackSource` |
222
+
223
+ Each executable top-level string `metadata.<key>` field also supports value suggestions in the `trace` scope. Identifiers, timestamps, durations, numeric score or feedback values, comments, errors, and version IDs don't. The fields response still includes canonical fields with `valueSuggestions: false`. The values endpoint rejects those paths with `422 TRACE_QUERY_INVALID`.
224
+
225
+ Both discovery requests require a half-open time range of at most 31 days. They use the same current-record semantics as `queryTraces()`: qualifying completed roots satisfy `from <= startedAt < to`, and related values come only from current records joined to those roots by `traceId`. Discovery doesn't accept or apply a draft `where` predicate.
226
+
227
+ `search` defaults to the empty string, is trimmed, and matches case-insensitive literal substrings. Characters such as `%` and `_` have no wildcard meaning. An empty search returns the most frequent results. `limit` defaults to 25 and has a maximum of 100. Both endpoints fetch one extra result to set their truncation flag, but don't provide a cursor. When a flag is `true`, refine `search`. It doesn't imply that a next page is available. No matches return an empty array and `false` truncation.
228
+
229
+ If discovery exceeds its execution timeout, the route returns `504 TRACE_QUERY_EXECUTION_TIMEOUT`. If the backend exceeds a memory or resource budget, it returns `503 TRACE_QUERY_RESOURCE_LIMIT`. Neither failure returns partial suggestions or sets a truncation flag. Truncation only means a complete ranking was cut to the requested response limit.
230
+
231
+ ClickHouse discovery requests default to a 5-second timeout and a 256 MiB per-query memory limit. Configure these with `observability.traceQuery.discovery.timeoutMs` and `observability.traceQuery.discovery.memoryLimitBytes` on `ClickhouseStoreVNext`. Discovery falls back to `observability.traceQuery.timeoutMs` when its timeout isn't configured, without changing ordinary `queryTraces()` execution limits.
232
+
233
+ Both routes require `observability:read` and use the configured observability storage boundary. Don't send organization or project authorization fields in the request. Treat discovered paths, values, and counts as observability data.
234
+
68
235
  ## Request fields
69
236
 
70
- | Field | Required | Description |
71
- | ----------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
72
- | `timeRange` | Yes | Trace start-time boundary. `from` is inclusive, `to` is exclusive, and the range can span at most 31 days. Both values must be ISO timestamps. |
73
- | `where` | No | Recursive trace predicate. Supports scalar conditions and `spans.some`, `spans.none`, `scores.some`, and `scores.none`. |
74
- | `group` | No | Set to `{ by: ['threadId'] }` to return distinct non-null thread IDs. |
75
- | `orderBy` | No | One item ordering ungrouped results by `startedAt` or `endedAt`, in `asc` or `desc` order. Defaults to `startedAt desc`. Not accepted with `group`. |
76
- | `page` | No | `{ limit, after }`. `limit` defaults to 100 and has a maximum of 1000. Pass the opaque `page.next` value as `after`. |
237
+ ### Trace queries
238
+
239
+ | Field | Required | Description |
240
+ | ----------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
241
+ | `timeRange` | Yes | Trace start-time boundary. `from` is inclusive and `to` is exclusive. Both values must be ISO timestamps, `from` must be earlier than `to`, and the range can't exceed 31 days. |
242
+ | `where` | No | Recursive trace predicate. Supports scalar conditions and `spans`, `scores`, and `feedback` `some` or `none` clauses. |
243
+ | `orderBy` | No | One item ordering results by `startedAt` or `endedAt`, in `asc` or `desc` order. Defaults to `startedAt desc`. |
244
+ | `page` | No | `{ limit, after }`. `limit` defaults to 100 and has a maximum of 1000. Pass the opaque `page.next` value as `after`. |
245
+
246
+ ### Thread queries
77
247
 
78
- Unknown fields are rejected. The request can't select a projection, declare joins, or control authorization. Request bodies are limited to 256 KiB.
248
+ | Field | Required | Description |
249
+ | -------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
250
+ | `traces` | Yes | Eligible trace selection containing `timeRange` and an optional trace `where` predicate. |
251
+ | `where` | No | Recursive thread predicate composed with boolean operators and `traces.some` or `traces.none`. Each quantifier contains a complete trace predicate. |
252
+ | `page` | No | `{ limit, after }`. Thread identities always use fixed ordinal `threadId` ascending order. Pass the opaque `page.next` value as `after`. |
253
+
254
+ Unknown fields are rejected. Requests can't select a projection, declare joins, request counts or measures, or control authorization. Request bodies are limited to 256 KiB.
79
255
 
80
256
  ## Query limits
81
257
 
82
258
  The planner rejects a query before storage execution when it exceeds any of these limits:
83
259
 
84
- | Input | Maximum |
85
- | ----------------------------------------- | ----------------- |
86
- | Root `timeRange` | 31 days |
87
- | Predicate nesting depth | 12 levels |
88
- | Predicate nodes | 100 |
89
- | Related `spans` and `scores` clauses | 8 total |
90
- | Values in one `in` or `notIn` set | 100 |
91
- | Comparison literals and membership values | 1,000 total |
92
- | String literal | 4,096 UTF-8 bytes |
93
- | Raw predicate path | 128 UTF-8 bytes |
94
- | `page.limit` | 1,000 |
95
- | HTTP request body | 256 KiB |
260
+ | Input | Maximum |
261
+ | ----------------------------------------------------------- | ----------------- |
262
+ | Trace selection `timeRange` | 31 days |
263
+ | Predicate nesting depth | 12 levels |
264
+ | Predicate nodes | 100 |
265
+ | Related `traces`, `spans`, `scores`, and `feedback` clauses | 8 total |
266
+ | Values in one `in` or `notIn` set | 100 |
267
+ | Comparison literals and membership values | 1,000 total |
268
+ | String literal | 4,096 UTF-8 bytes |
269
+ | Raw predicate path | 128 UTF-8 bytes |
270
+ | `page.limit` | 1,000 |
271
+ | HTTP request body | 256 KiB |
96
272
 
97
273
  Each comparison literal counts as one literal. Each member of an `in` or `notIn` set also counts as one literal, even when the set is within its per-set limit.
98
274
 
@@ -271,7 +447,7 @@ const messageTrace = {
271
447
 
272
448
  The key must name one top-level property. Empty keys and nested paths are rejected. Metadata keys aren't trimmed, so leading and trailing whitespace remains part of the exact key identity. When metadata duplicates a canonical trace field, such as `resourceId`, `threadId`, or `environment`, prefer the canonical field because it uses the dedicated storage column. The `metadata.<key>` form remains available when you specifically need the value from the metadata object. Metadata and canonical values may differ.
273
449
 
274
- Metadata fields aren't available for grouping or field discovery.
450
+ Metadata fields aren't available for grouping. Trace-query discovery returns executable top-level string metadata fields observed in the selected time range.
275
451
 
276
452
  ### Filter by feedback
277
453
 
@@ -336,43 +512,40 @@ An ungrouped query returns only lightweight completed traces:
336
512
  }
337
513
  ```
338
514
 
339
- A grouped query returns distinct non-null thread IDs in ascending order:
515
+ A thread query returns distinct non-null thread IDs in ordinal ascending order:
340
516
 
341
- ```typescript
342
- const result = await mastraClient.queryTraces({
343
- timeRange: {
344
- from: '2026-08-01T00:00:00.000Z',
345
- to: '2026-08-08T00:00:00.000Z',
346
- },
347
- group: { by: ['threadId'] },
348
- })
349
- // { groups: [{ threadId: 'thread-123' }], page: { next: null } }
517
+ ```json
518
+ {
519
+ "threads": [{ "threadId": "thread-123" }],
520
+ "page": { "next": null }
521
+ }
350
522
  ```
351
523
 
352
524
  Related evidence isn't embedded in either response. Use the trace-detail and branch APIs to load spans after selecting a result.
353
525
 
354
526
  ## Pagination and errors
355
527
 
356
- Ordering is deterministic. Ungrouped ordering appends `traceId` ascending as a tie-breaker. Grouped queries always order by `threadId` ascending.
528
+ Ordering is deterministic. Trace ordering appends `traceId` ascending as a tie-breaker. Thread queries always use raw ordinal `threadId` ascending order. Callers can't override it.
357
529
 
358
- Cursors are bound to the accepted normalized query shape and ordering. Reusing a cursor after changing the time range, predicates, grouping, or ordering returns `409`. A malformed cursor returns `400`.
530
+ Cursors are bound to the operation, accepted normalized query, authorization state, and ordering. Reusing a cursor after changing the trace selection, predicates, or ordering returns `409`. Trace and thread cursors aren't interchangeable. A malformed cursor returns `400`.
359
531
 
360
532
  Cursor pagination is deterministic, but it isn't a database snapshot. Traces or replacement signals written between page requests can change later pages.
361
533
 
362
- PostgreSQL and ClickHouse stop an advanced trace query after 15 seconds by default and return `504` when the database timeout is exceeded. Set `traceQueryTimeoutMs` in the store's vNext observability configuration to an integer from 1 through 300,000 milliseconds to change the timeout. DuckDB doesn't currently provide query-scoped timeout or cancellation through its driver wrapper, so this `504` guarantee doesn't apply to DuckDB.
534
+ PostgreSQL and ClickHouse stop advanced trace and thread queries after 15 seconds by default and return `504` when the database timeout is exceeded. Set `traceQueryTimeoutMs` in the store's vNext observability configuration to an integer from 1 through 300,000 milliseconds to change the timeout. DuckDB doesn't currently provide query-scoped timeout or cancellation through its driver wrapper, so this `504` guarantee doesn't apply to DuckDB.
363
535
 
364
- | Status | Meaning |
365
- | ------ | ------------------------------------------------------------------------------------------------------------------------------------- |
366
- | `400` | Malformed JSON or malformed cursor. |
367
- | `409` | The cursor doesn't match the query. |
368
- | `413` | The request body exceeds 256 KiB. |
369
- | `422` | The JSON is well formed, but the request is structurally or semantically invalid. The response includes stable issue codes and paths. |
370
- | `501` | The configured observability store doesn't support advanced trace queries. |
371
- | `504` | A PostgreSQL or ClickHouse query exceeded its configured database execution timeout. |
536
+ | Status | Meaning |
537
+ | ------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
538
+ | `400` | Malformed JSON or malformed cursor. |
539
+ | `409` | The cursor doesn't match the query. |
540
+ | `413` | The request body exceeds 256 KiB. |
541
+ | `422` | The JSON is well formed, but the request is structurally or semantically invalid. The response includes stable issue codes and paths. Discovery validation uses `TRACE_QUERY_INVALID`. |
542
+ | `501` | The installed Core or configured observability store doesn't support the requested operation. Discovery returns `TRACE_QUERY_DISCOVERY_UNSUPPORTED` unless Core provides the discovery contract and the store implements both field and value discovery. |
543
+ | `503` | Discovery exceeded a backend memory or resource budget and returned `TRACE_QUERY_RESOURCE_LIMIT`. |
544
+ | `504` | A PostgreSQL or ClickHouse query exceeded its configured database execution timeout. Discovery returns `TRACE_QUERY_EXECUTION_TIMEOUT`. |
372
545
 
373
546
  ## Limitations
374
547
 
375
- The endpoint returns completed traces only. It doesn't support running traces, custom projections, embedded evidence, summaries, aggregations, grouping by fields other than `threadId`, or conditions over an entire group.
548
+ Both operations consider completed traces only. They don't support running traces, custom projections, embedded evidence, summaries, aggregations, counts, measures, or custom grouping.
376
549
 
377
550
  ## Related
378
551