@mastra/client-js 1.41.0-alpha.10 → 1.41.0-alpha.11

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/CHANGELOG.md CHANGED
@@ -1,5 +1,46 @@
1
1
  # @mastra/client-js
2
2
 
3
+ ## 1.41.0-alpha.11
4
+
5
+ ### Minor Changes
6
+
7
+ - Added a `durable` option to stored agents so agents created through the Agents API can run with durable execution — no code deployment required. ([#21715](https://github.com/mastra-ai/mastra/pull/21715))
8
+
9
+ ```typescript
10
+ await mastraClient.createStoredAgent({
11
+ id: 'helper',
12
+ name: 'Helper',
13
+ instructions: 'You are a helpful assistant.',
14
+ model: { provider: 'openai', name: 'gpt-5' },
15
+ durable: true,
16
+ });
17
+ ```
18
+
19
+ Pass `true` for defaults, or `{ maxSteps, cleanupTimeoutMs }` to tune the durable loop. Cache and pubsub are inherited from the server's Mastra instance, so configure distributed backends there for durability across replicas. Automatic recovery is still configured in code via `recovery.durableAgents`.
20
+
21
+ - Fixed the agent controller event types, which described payloads the server never sends. ([#21739](https://github.com/mastra-ai/mastra/pull/21739))
22
+
23
+ `KnownAgentControllerEvent` was written by hand and had drifted from the controller. Narrowing on `om_activation` gave you an `enabled` boolean that does not exist, `om_status` a `status` string instead of the token windows, `om_thread_title_updated` a `title` instead of `newTitle`, and `subagent_end` only a `toolCallId` — its `agentType`, `result`, `isError` and `durationMs` were missing. `usage_update` typed its payload as `unknown`, so every consumer cast it. Seven events the controller emits (`state_changed`, `command_exit`, `tool_suspension_cancelled`, and the four remaining `subagent_*` events) were not typed at all and fell through `isKnownAgentControllerEvent`.
24
+
25
+ `isKnownAgentControllerEvent` now returns `true` for those seven events as well. If you route unrecognised events to a fallback branch, they no longer reach it — give them a case in your `switch` or they are silently dropped.
26
+
27
+ `thread_created` now delivers `thread.createdAt` and `thread.updatedAt` as `Date`s, the way the `message_*` events already did — the stream carries them as ISO strings.
28
+
29
+ Payload drift is now a compile error instead of a wrong field at runtime, so handlers reading the old fields need updating.
30
+
31
+ ```ts
32
+ // Before: compiled, but `enabled` is always undefined
33
+ if (event.type === 'om_activation' && event.enabled) { ... }
34
+
35
+ // After: tsc rejects it; the event carries cycleId, tokensActivated, generationCount, …
36
+ if (event.type === 'om_activation') { console.log(event.tokensActivated) }
37
+ ```
38
+
39
+ ### Patch Changes
40
+
41
+ - Updated dependencies [[`6223446`](https://github.com/mastra-ai/mastra/commit/6223446ddce6166e96e0ba5e00d628b615dee8ca), [`583e235`](https://github.com/mastra-ai/mastra/commit/583e23519c13af16c1746f9c49722d011216611b), [`a77f8d4`](https://github.com/mastra-ai/mastra/commit/a77f8d4740d2178a74c41e4bf678b4fcd8fa0bb2), [`40d358e`](https://github.com/mastra-ai/mastra/commit/40d358e29d55543803e64b49241122f598ffabc7), [`e80cd7e`](https://github.com/mastra-ai/mastra/commit/e80cd7e7683e7d732e1cc6784bcac1d2640d2ce3), [`20504b2`](https://github.com/mastra-ai/mastra/commit/20504b2ecebd0e077acda3d457ab57480a98ed3e)]:
42
+ - @mastra/core@1.60.0-alpha.11
43
+
3
44
  ## 1.41.0-alpha.10
4
45
 
5
46
  ### Patch Changes
@@ -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.41.0-alpha.10"
6
+ version: "1.41.0-alpha.11"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.41.0-alpha.10",
2
+ "version": "1.41.0-alpha.11",
3
3
  "package": "@mastra/client-js",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -778,9 +778,29 @@ const agent = await mastraClient.createStoredAgent({
778
778
  version: '1.0',
779
779
  team: 'engineering',
780
780
  },
781
+ durable: true,
781
782
  })
782
783
  ```
783
784
 
785
+ #### Durable stored agents
786
+
787
+ Set `durable` to run the agent as a [durable agent](https://mastra.ai/docs/harness/durable-agents) once the server hydrates it. Pass `true` to accept the defaults, or an object to tune the durable loop:
788
+
789
+ ```typescript
790
+ const agent = await mastraClient.createStoredAgent({
791
+ id: 'durable-agent',
792
+ name: 'Durable Agent',
793
+ instructions: 'You are a helpful assistant.',
794
+ model: {
795
+ provider: 'openai',
796
+ name: 'gpt-5.4',
797
+ },
798
+ durable: { maxSteps: 50, cleanupTimeoutMs: 0 },
799
+ })
800
+ ```
801
+
802
+ Only serializable options are accepted. The durable cache and pubsub are inherited from the server's `Mastra` instance. If it has no distributed cache or pubsub configured, durability is process-local. Automatic recovery is still configured in code through `recovery.durableAgents`.
803
+
784
804
  ### `getStoredAgent()`
785
805
 
786
806
  Get an instance of a specific stored agent:
package/dist/index.cjs CHANGED
@@ -5672,22 +5672,29 @@ const KNOWN_AGENT_CONTROLLER_EVENT_TYPES = new Set(Object.keys({
5672
5672
  message_start: true,
5673
5673
  message_update: true,
5674
5674
  message_end: true,
5675
+ state_changed: true,
5675
5676
  tool_input_start: true,
5676
5677
  tool_input_delta: true,
5677
5678
  tool_input_end: true,
5678
5679
  tool_start: true,
5679
5680
  tool_update: true,
5680
5681
  shell_output: true,
5682
+ command_exit: true,
5681
5683
  tool_end: true,
5682
5684
  tool_approval_required: true,
5683
5685
  tool_suspended: true,
5686
+ tool_suspension_cancelled: true,
5684
5687
  mode_changed: true,
5685
5688
  model_changed: true,
5686
5689
  thread_changed: true,
5687
5690
  thread_created: true,
5688
5691
  thread_deleted: true,
5689
5692
  subagent_start: true,
5693
+ subagent_text_delta: true,
5694
+ subagent_tool_start: true,
5695
+ subagent_tool_end: true,
5690
5696
  subagent_end: true,
5697
+ subagent_model_changed: true,
5691
5698
  task_updated: true,
5692
5699
  notification: true,
5693
5700
  notification_summary: true,
@@ -5718,19 +5725,37 @@ const KNOWN_AGENT_CONTROLLER_EVENT_TYPES = new Set(Object.keys({
5718
5725
  function isKnownAgentControllerEvent(event) {
5719
5726
  return KNOWN_AGENT_CONTROLLER_EVENT_TYPES.has(event.type);
5720
5727
  }
5728
+ const toDate = (value) => value instanceof Date ? value : new Date(value);
5721
5729
  function hydrateMessage(message) {
5722
5730
  return {
5723
5731
  ...message,
5724
- createdAt: message.createdAt instanceof Date ? message.createdAt : new Date(message.createdAt)
5732
+ createdAt: toDate(message.createdAt)
5725
5733
  };
5726
5734
  }
5727
- function hydrateEventMessage(event) {
5728
- if (event.type !== "message_start" && event.type !== "message_update" && event.type !== "message_end") return event;
5735
+ function hydrateThread(thread) {
5729
5736
  return {
5730
- ...event,
5731
- message: hydrateMessage(event.message)
5737
+ ...thread,
5738
+ createdAt: toDate(thread.createdAt),
5739
+ updatedAt: toDate(thread.updatedAt)
5732
5740
  };
5733
5741
  }
5742
+ /** The stream carries every timestamp as an ISO string; give consumers back the `Date`s the type promises. */
5743
+ function hydrateEventTimestamps(event) {
5744
+ if (!isKnownAgentControllerEvent(event)) return event;
5745
+ switch (event.type) {
5746
+ case "message_start":
5747
+ case "message_update":
5748
+ case "message_end": return {
5749
+ ...event,
5750
+ message: hydrateMessage(event.message)
5751
+ };
5752
+ case "thread_created": return {
5753
+ ...event,
5754
+ thread: hydrateThread(event.thread)
5755
+ };
5756
+ default: return event;
5757
+ }
5758
+ }
5734
5759
  /**
5735
5760
  * A session bound to a `resourceId` within one agent controller. Sessions are
5736
5761
  * get-or-create on the server, so re-creating the same resourceId (and scope)
@@ -5862,7 +5887,7 @@ var AgentControllerSession = class extends BaseResource {
5862
5887
  if (!data) continue;
5863
5888
  let event;
5864
5889
  try {
5865
- event = hydrateEventMessage(JSON.parse(data));
5890
+ event = hydrateEventTimestamps(JSON.parse(data));
5866
5891
  } catch {
5867
5892
  continue;
5868
5893
  }