@mastra/client-js 1.52.0-alpha.1 → 1.52.0-alpha.3

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.52.0-alpha.1"
6
+ version: "1.52.0-alpha.3"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.52.0-alpha.1",
2
+ "version": "1.52.0-alpha.3",
3
3
  "package": "@mastra/client-js",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -351,7 +351,7 @@ Use `createNotificationInboxTool()` to give agents one tool for inbox actions in
351
351
 
352
352
  ## Cross-agent connections in Mastra Code
353
353
 
354
- Cross-agent communication is experimental and off by default. Enable it in Mastra Code with the `/settings` toggle "Experimental cross-agent communication" and restart. Embedded clients can set `crossAgentSignals: true` when calling `createMastraCode()`. The setting enables thread ownership advertisements and peer discovery. It also makes the agent connection tools available. It doesn't affect the pub/sub transport itself.
354
+ Cross-agent communication is experimental and off by default. Enable it in Mastra Code with the `/settings` toggle "Experimental cross-agent communication" and restart. Embedded clients can set `crossAgentSignals: true` when calling `createMastraCode()`. The setting enables thread ownership advertisements and peer discovery. It also makes the agent connection tools available, and lets peer discovery reach instances in other projects on the same machine (see [Discover agents in other projects](#discover-agents-in-other-projects)).
355
355
 
356
356
  ```typescript
357
357
  import { createMastraCode } from 'mastracode'
@@ -388,6 +388,20 @@ Saved connections remain in the sender thread until explicitly disconnected. Eve
388
388
 
389
389
  After a send attempt reaches Core routing, the routing result is authoritative. The result can be `wake`, `deliver`, `persist`, `blocked`, or `discard`, depending on the target thread and notification policy. A send that isn't acknowledged by the advertised thread owner returns an error and doesn't consume its `messageId`, so the sender can retry it.
390
390
 
391
+ ### Discover agents in other projects
392
+
393
+ With cross-agent communication on, `agent_connections_list` lists Mastra Code instances in every project on the same machine, including the current one. An instance can connect to and message an instance in another project, and receive its replies. This needs Unix socket pub/sub. The Mastra Code CLI turns it on by default. Embedded clients pass `unixSocketPubSub: true` alongside `crossAgentSignals: true` to `createMastraCode()`. It doesn't apply in these cases:
394
+
395
+ - On Windows.
396
+ - When you pass your own `pubsub`.
397
+ - When the resource ID, set through `MASTRA_RESOURCE_ID` or `resourceId` in `.mastracode/database.json`, can't be used as a directory name. That covers IDs that are empty, are longer than 128 characters, contain `/`, `\` or control characters, or equal `.`, `..` or `_shared`. Mastra Code logs one warning at startup, and the instance only lists instances that share its resource ID.
398
+
399
+ Mastra Code routes a thread's messages and run leases to the socket directory of the thread's project. Thread-owner lookup and peer discovery, which lists the threads you can connect to, both run in a shared `/tmp/mc/_shared` directory. Instances running versions before this change can't see or be seen by updated instances, so restart every instance after updating.
400
+
401
+ Any local process running as your user can list the threads your instances advertise and message them, so only turn on cross-agent communication on machines and accounts you trust.
402
+
403
+ To isolate an instance or a test from the shared `/tmp/mc` directory, set `MASTRACODE_SIGNALS_SOCKET_ROOT` to another absolute path. Relative paths are ignored. Keep the path short, because macOS limits Unix socket paths to 104 bytes. The root also holds every thread's run and ownership leases. An instance with a different root doesn't coordinate threads with instances that use the default root.
404
+
391
405
  ## Distributed and serverless deployments
392
406
 
393
407
  Signals coordinate runs through a pub/sub backend. When a signal arrives on a backend that implements `LeaseProvider`, Mastra acquires a lease on the target thread so a single process owns the conversation at a time, then either wakes the agent or routes the input into the running loop. Backends without leasing fall back to a no-op that always grants ownership, which is fine in a single process but not across instances.
@@ -10,6 +10,56 @@ Both endpoints use the same authentication as other observability routes and req
10
10
 
11
11
  > **Thread grouping is deprecated:** The `group` option remains supported until the next major release. Use [`queryTraceThreads()`](https://mastra.ai/reference/client-js/observability) to retrieve matching thread identities in new code.
12
12
 
13
+ ## Query individual spans through storage
14
+
15
+ The observability domain in DuckDB and the PostgreSQL and ClickHouse v-next stores supports `querySpans(plan)`. It returns individual completed spans across traces, including matching child spans. Check `storage.getFeatures()?.includes('span-query')` before using this optional storage method. Server routes and client SDK support are separate from this storage API.
16
+
17
+ Build the plan in trusted backend code:
18
+
19
+ ```typescript
20
+ import { planSpanQuery } from '@mastra/core/storage'
21
+
22
+ const storage = await mastra.getStorage()?.getStore('observability')
23
+ if (!storage?.getFeatures()?.includes('span-query')) {
24
+ throw new Error('This store does not support span queries')
25
+ }
26
+
27
+ const plan = planSpanQuery({
28
+ timeRange: {
29
+ from: '2026-10-01T00:00:00.000Z',
30
+ to: '2026-10-02T00:00:00.000Z',
31
+ },
32
+ where: {
33
+ op: 'eq',
34
+ left: { path: 'spanType' },
35
+ right: { literal: 'tool_call' },
36
+ },
37
+ page: { limit: 50 },
38
+ })
39
+
40
+ const { spans, page } = await storage.querySpans(plan)
41
+ ```
42
+
43
+ This example uses local, unscoped storage. For a shared database, pass `{ scope: { organizationId, resourceId } }` as the second argument to `planSpanQuery()`, using identifiers resolved by your backend's authorization. The request body can't supply trusted scope. Apply the same authorization when loading full span details with `getSpan({ traceId, spanId })`.
44
+
45
+ Span queries use the scalar fields and operators available inside `queryTraces()`'s `spans.some` predicate. They don't accept related-record clauses. Nested attributes require support in the shared predicate contract and each store.
46
+
47
+ The `timeRange` applies to each span's `startedAt`, includes `from`, excludes `to`, and can cover at most 31 days. Sort by `startedAt` or `endedAt`, in either direction. The default is `startedAt` descending. A page contains up to 1,000 rows, with a default of 100. Pass `page.next` back as `page.after` with the same filters, time range, scope, and ordering. Cursors use scope and span identifiers to break timestamp ties. They aren't a snapshot across requests. New completions can appear when the view is refreshed.
48
+
49
+ Each row contains span and trace identifiers, display fields, duration, status, and input/output previews of at most 256 Unicode characters. Truncation flags indicate when a preview is incomplete. Stores select the page before loading previews and cost. Full payloads remain available through the existing span detail method.
50
+
51
+ The `cost` field describes only that span's model-token cost:
52
+
53
+ - `available` includes `amount` and `currency`. Zero is a valid amount.
54
+ - `missing` means no matching model metrics were found.
55
+ - `unavailable` means metrics exist but a complete, unambiguous cost can't be established.
56
+
57
+ Directional token totals supply the cost. Overlapping detail metrics aren't added again. A provider-supplied `query_total` cost is counted once. Partial pricing, conflicting currencies, and ambiguous totals produce `unavailable`.
58
+
59
+ Current-record selection runs before mutable filters. PostgreSQL and ClickHouse select the greatest completed `endedAt`. PostgreSQL breaks ties with its ingestion cursor. DuckDB reconstructs the earliest start event and selects the latest ingested completed event, matching its existing span-predicate behavior. Time bounds are checked again after reconstruction. ClickHouse uses its existing completion-only, insert-only model, where equal-version retries must contain identical records. Querying spans doesn't add a table or materialized view.
60
+
61
+ Queries have a 15-second default execution deadline. PostgreSQL and ClickHouse use their existing `traceQuery.timeoutMs` setting. ClickHouse also caps each query at 512 MiB. A page with more than 50,000 matching model metrics fails with a resource-limit error instead of returning partial cost. A small page size limits returned rows, but doesn't limit the number of records the database must examine.
62
+
13
63
  ## Query traces with the client SDK
14
64
 
15
65
  Pass the query to `queryTraces()`: