@mastra/editor 0.7.16-alpha.0 → 0.7.16-alpha.2

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,25 @@
1
1
  # @mastra/editor
2
2
 
3
+ ## 0.7.16-alpha.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Resolving stored agent versions no longer mutates the shared singleton agent instance. Instruction and tool overrides are now applied to an isolated clone, making concurrent version resolution safe and preventing overrides from leaking onto the global agent. ([#15314](https://github.com/mastra-ai/mastra/pull/15314))
8
+
9
+ - Updated dependencies [[`cbdf3e1`](https://github.com/mastra-ai/mastra/commit/cbdf3e12b3d0c30a6e5347be658e2009648c130a), [`8fe46d3`](https://github.com/mastra-ai/mastra/commit/8fe46d354027f3f0f0846e64219772348de106dd), [`18c67db`](https://github.com/mastra-ai/mastra/commit/18c67dbb9c9ebc26f26f65f7d3ff836e5691ef46), [`8dcc77e`](https://github.com/mastra-ai/mastra/commit/8dcc77e78a5340f5848f74b9e9f1b3da3513c1f5), [`aa67fc5`](https://github.com/mastra-ai/mastra/commit/aa67fc59ee8a5eeff1f23eb05970b8d7a536c8ff), [`fa8140b`](https://github.com/mastra-ai/mastra/commit/fa8140bcd4251d2e3ac85fdc5547dfc4f372b5be), [`190f452`](https://github.com/mastra-ai/mastra/commit/190f45258b0640e2adfc8219fa3258cdc5b8f071), [`7e7bf60`](https://github.com/mastra-ai/mastra/commit/7e7bf606886bf374a6f9d4ca9b09dd83d0533372), [`184907d`](https://github.com/mastra-ai/mastra/commit/184907d775d8609c03c26e78ccaf37315f3aa287), [`5f3d4dd`](https://github.com/mastra-ai/mastra/commit/5f3d4ddf237241f4b238ac062ac61eadabed0770), [`0c4cd13`](https://github.com/mastra-ai/mastra/commit/0c4cd131931c04ac5405373c932a242dbe88edd6), [`b16a753`](https://github.com/mastra-ai/mastra/commit/b16a753d5748440248d7df82e29bb987a9c8386c)]:
10
+ - @mastra/core@1.25.0-alpha.3
11
+ - @mastra/mcp@1.5.0-alpha.0
12
+
13
+ ## 0.7.16-alpha.1
14
+
15
+ ### Patch Changes
16
+
17
+ - Updated dependencies [[`4ba3bb1`](https://github.com/mastra-ai/mastra/commit/4ba3bb1e465ad2ddaba3bbf2bc47e0faec32985e), [`2a69802`](https://github.com/mastra-ai/mastra/commit/2a69802a0fc6d8a25a77fa6a42276e9d59a83914)]:
18
+ - @mastra/core@1.25.0-alpha.2
19
+ - @mastra/schema-compat@1.2.8-alpha.0
20
+ - @mastra/mcp@1.4.2
21
+ - @mastra/memory@1.15.1-alpha.1
22
+
3
23
  ## 0.7.16-alpha.0
4
24
 
5
25
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -565,7 +565,6 @@ var EditorMCPNamespace = class _EditorMCPNamespace extends CrudEditorNamespace {
565
565
  };
566
566
 
567
567
  // src/namespaces/agent.ts
568
- var codeDefaults = /* @__PURE__ */ new WeakMap();
569
568
  var EditorAgentNamespace = class extends CrudEditorNamespace {
570
569
  async getStorageAdapter() {
571
570
  const storage = this.mastra?.getStorage();
@@ -657,12 +656,6 @@ var EditorAgentNamespace = class extends CrudEditorNamespace {
657
656
  * they may contain SDK instances or dynamic functions that cannot be safely serialized.
658
657
  * Returns the (possibly mutated) agent.
659
658
  */
660
- clearResolvedVersionId(agent) {
661
- const raw = agent.toRawConfig();
662
- if (!raw || !("resolvedVersionId" in raw)) return;
663
- const { resolvedVersionId: _removed, ...rest } = raw;
664
- agent.__setRawConfig(rest);
665
- }
666
659
  async applyStoredOverrides(agent, options) {
667
660
  let storedConfig = null;
668
661
  try {
@@ -674,29 +667,21 @@ var EditorAgentNamespace = class extends CrudEditorNamespace {
674
667
  if (options && "versionId" in options) {
675
668
  throw error;
676
669
  }
677
- this.restoreCodeDefaults(agent);
678
- this.clearResolvedVersionId(agent);
679
670
  return agent;
680
671
  }
681
672
  if (!storedConfig) {
682
- this.restoreCodeDefaults(agent);
683
- this.clearResolvedVersionId(agent);
684
673
  return agent;
685
674
  }
686
675
  const requestedPublished = options && !("versionId" in options) && options.status === "published";
687
676
  if (requestedPublished && !storedConfig.activeVersionId) {
688
- this.restoreCodeDefaults(agent);
689
- this.clearResolvedVersionId(agent);
690
677
  return agent;
691
678
  }
692
- this.saveCodeDefaults(agent);
693
- this.restoreCodeDefaults(agent);
694
- this.saveCodeDefaults(agent);
679
+ const fork = agent.__fork();
695
680
  this.logger?.debug(`[applyStoredOverrides] Applying stored overrides to code agent "${agent.id}"`);
696
681
  if (storedConfig.instructions !== void 0 && storedConfig.instructions !== null) {
697
682
  const resolved = this.resolveStoredInstructions(storedConfig.instructions);
698
683
  if (resolved !== void 0) {
699
- agent.__updateInstructions(resolved);
684
+ fork.__updateInstructions(resolved);
700
685
  }
701
686
  }
702
687
  const hasStoredTools = storedConfig.tools != null;
@@ -708,7 +693,7 @@ var EditorAgentNamespace = class extends CrudEditorNamespace {
708
693
  const hasConditionalIntegrationTools = storedConfig.integrationTools != null && this.isConditionalVariants(storedConfig.integrationTools);
709
694
  const isDynamicTools = hasConditionalTools || hasConditionalMCPClients || hasConditionalIntegrationTools;
710
695
  if (isDynamicTools) {
711
- const originalTools = agent.listTools.bind(agent);
696
+ const originalTools = fork.listTools.bind(fork);
712
697
  const toolsFn = async ({ requestContext }) => {
713
698
  const codeTools = await originalTools({ requestContext });
714
699
  const ctx = requestContext.toJSON();
@@ -729,9 +714,9 @@ var EditorAgentNamespace = class extends CrudEditorNamespace {
729
714
  const integrationTools = await this.resolveStoredIntegrationTools(resolvedIntegrationToolsConfig, ctx);
730
715
  return { ...codeTools, ...registryTools, ...mcpTools, ...integrationTools };
731
716
  };
732
- agent.__setTools(toolsFn);
717
+ fork.__setTools(toolsFn);
733
718
  } else {
734
- const codeTools = await agent.listTools();
719
+ const codeTools = await fork.listTools();
735
720
  const registryTools = this.resolveStoredTools(
736
721
  storedConfig.tools
737
722
  );
@@ -741,43 +726,14 @@ var EditorAgentNamespace = class extends CrudEditorNamespace {
741
726
  const integrationTools = await this.resolveStoredIntegrationTools(
742
727
  storedConfig.integrationTools
743
728
  );
744
- agent.__setTools({ ...codeTools, ...registryTools, ...mcpTools, ...integrationTools });
729
+ fork.__setTools({ ...codeTools, ...registryTools, ...mcpTools, ...integrationTools });
745
730
  }
746
731
  }
747
732
  if (storedConfig.resolvedVersionId) {
748
- const existing = agent.toRawConfig() ?? {};
749
- agent.__setRawConfig({ ...existing, resolvedVersionId: storedConfig.resolvedVersionId });
750
- } else {
751
- this.clearResolvedVersionId(agent);
733
+ const existing = fork.toRawConfig() ?? {};
734
+ fork.__setRawConfig({ ...existing, resolvedVersionId: storedConfig.resolvedVersionId });
752
735
  }
753
- return agent;
754
- }
755
- /**
756
- * Save the agent's current field values to the module-level WeakMap
757
- * so they can be restored if the stored config is later removed.
758
- * Only saves on the first call (guards against overwriting originals with overridden values).
759
- *
760
- * Only instructions and tools are saved — these are the only fields
761
- * that `applyStoredOverrides` mutates.
762
- */
763
- saveCodeDefaults(agent) {
764
- if (codeDefaults.has(agent)) return;
765
- const fields = agent.__getOverridableFields();
766
- codeDefaults.set(agent, {
767
- instructions: fields.instructions,
768
- tools: fields.tools
769
- });
770
- }
771
- /**
772
- * Restore the agent's original code-defined field values from the WeakMap.
773
- * Clears the saved snapshot afterward.
774
- */
775
- restoreCodeDefaults(agent) {
776
- const saved = codeDefaults.get(agent);
777
- if (!saved) return;
778
- agent.__updateInstructions(saved.instructions);
779
- agent.__setTools(saved.tools);
780
- codeDefaults.delete(agent);
736
+ return fork;
781
737
  }
782
738
  // ============================================================================
783
739
  // Private helpers
package/dist/index.d.cts CHANGED
@@ -115,26 +115,11 @@ declare class EditorAgentNamespace extends CrudEditorNamespace<StorageCreateAgen
115
115
  * they may contain SDK instances or dynamic functions that cannot be safely serialized.
116
116
  * Returns the (possibly mutated) agent.
117
117
  */
118
- private clearResolvedVersionId;
119
118
  applyStoredOverrides(agent: Agent, options?: {
120
119
  status?: 'draft' | 'published';
121
120
  } | {
122
121
  versionId: string;
123
122
  }): Promise<Agent>;
124
- /**
125
- * Save the agent's current field values to the module-level WeakMap
126
- * so they can be restored if the stored config is later removed.
127
- * Only saves on the first call (guards against overwriting originals with overridden values).
128
- *
129
- * Only instructions and tools are saved — these are the only fields
130
- * that `applyStoredOverrides` mutates.
131
- */
132
- private saveCodeDefaults;
133
- /**
134
- * Restore the agent's original code-defined field values from the WeakMap.
135
- * Clears the saved snapshot afterward.
136
- */
137
- private restoreCodeDefaults;
138
123
  /**
139
124
  * Detect whether a StorageConditionalField value is a conditional variant array
140
125
  * (as opposed to the plain static value T).
package/dist/index.d.ts CHANGED
@@ -115,26 +115,11 @@ declare class EditorAgentNamespace extends CrudEditorNamespace<StorageCreateAgen
115
115
  * they may contain SDK instances or dynamic functions that cannot be safely serialized.
116
116
  * Returns the (possibly mutated) agent.
117
117
  */
118
- private clearResolvedVersionId;
119
118
  applyStoredOverrides(agent: Agent, options?: {
120
119
  status?: 'draft' | 'published';
121
120
  } | {
122
121
  versionId: string;
123
122
  }): Promise<Agent>;
124
- /**
125
- * Save the agent's current field values to the module-level WeakMap
126
- * so they can be restored if the stored config is later removed.
127
- * Only saves on the first call (guards against overwriting originals with overridden values).
128
- *
129
- * Only instructions and tools are saved — these are the only fields
130
- * that `applyStoredOverrides` mutates.
131
- */
132
- private saveCodeDefaults;
133
- /**
134
- * Restore the agent's original code-defined field values from the WeakMap.
135
- * Clears the saved snapshot afterward.
136
- */
137
- private restoreCodeDefaults;
138
123
  /**
139
124
  * Detect whether a StorageConditionalField value is a conditional variant array
140
125
  * (as opposed to the plain static value T).
package/dist/index.js CHANGED
@@ -517,7 +517,6 @@ var EditorMCPNamespace = class _EditorMCPNamespace extends CrudEditorNamespace {
517
517
  };
518
518
 
519
519
  // src/namespaces/agent.ts
520
- var codeDefaults = /* @__PURE__ */ new WeakMap();
521
520
  var EditorAgentNamespace = class extends CrudEditorNamespace {
522
521
  async getStorageAdapter() {
523
522
  const storage = this.mastra?.getStorage();
@@ -609,12 +608,6 @@ var EditorAgentNamespace = class extends CrudEditorNamespace {
609
608
  * they may contain SDK instances or dynamic functions that cannot be safely serialized.
610
609
  * Returns the (possibly mutated) agent.
611
610
  */
612
- clearResolvedVersionId(agent) {
613
- const raw = agent.toRawConfig();
614
- if (!raw || !("resolvedVersionId" in raw)) return;
615
- const { resolvedVersionId: _removed, ...rest } = raw;
616
- agent.__setRawConfig(rest);
617
- }
618
611
  async applyStoredOverrides(agent, options) {
619
612
  let storedConfig = null;
620
613
  try {
@@ -626,29 +619,21 @@ var EditorAgentNamespace = class extends CrudEditorNamespace {
626
619
  if (options && "versionId" in options) {
627
620
  throw error;
628
621
  }
629
- this.restoreCodeDefaults(agent);
630
- this.clearResolvedVersionId(agent);
631
622
  return agent;
632
623
  }
633
624
  if (!storedConfig) {
634
- this.restoreCodeDefaults(agent);
635
- this.clearResolvedVersionId(agent);
636
625
  return agent;
637
626
  }
638
627
  const requestedPublished = options && !("versionId" in options) && options.status === "published";
639
628
  if (requestedPublished && !storedConfig.activeVersionId) {
640
- this.restoreCodeDefaults(agent);
641
- this.clearResolvedVersionId(agent);
642
629
  return agent;
643
630
  }
644
- this.saveCodeDefaults(agent);
645
- this.restoreCodeDefaults(agent);
646
- this.saveCodeDefaults(agent);
631
+ const fork = agent.__fork();
647
632
  this.logger?.debug(`[applyStoredOverrides] Applying stored overrides to code agent "${agent.id}"`);
648
633
  if (storedConfig.instructions !== void 0 && storedConfig.instructions !== null) {
649
634
  const resolved = this.resolveStoredInstructions(storedConfig.instructions);
650
635
  if (resolved !== void 0) {
651
- agent.__updateInstructions(resolved);
636
+ fork.__updateInstructions(resolved);
652
637
  }
653
638
  }
654
639
  const hasStoredTools = storedConfig.tools != null;
@@ -660,7 +645,7 @@ var EditorAgentNamespace = class extends CrudEditorNamespace {
660
645
  const hasConditionalIntegrationTools = storedConfig.integrationTools != null && this.isConditionalVariants(storedConfig.integrationTools);
661
646
  const isDynamicTools = hasConditionalTools || hasConditionalMCPClients || hasConditionalIntegrationTools;
662
647
  if (isDynamicTools) {
663
- const originalTools = agent.listTools.bind(agent);
648
+ const originalTools = fork.listTools.bind(fork);
664
649
  const toolsFn = async ({ requestContext }) => {
665
650
  const codeTools = await originalTools({ requestContext });
666
651
  const ctx = requestContext.toJSON();
@@ -681,9 +666,9 @@ var EditorAgentNamespace = class extends CrudEditorNamespace {
681
666
  const integrationTools = await this.resolveStoredIntegrationTools(resolvedIntegrationToolsConfig, ctx);
682
667
  return { ...codeTools, ...registryTools, ...mcpTools, ...integrationTools };
683
668
  };
684
- agent.__setTools(toolsFn);
669
+ fork.__setTools(toolsFn);
685
670
  } else {
686
- const codeTools = await agent.listTools();
671
+ const codeTools = await fork.listTools();
687
672
  const registryTools = this.resolveStoredTools(
688
673
  storedConfig.tools
689
674
  );
@@ -693,43 +678,14 @@ var EditorAgentNamespace = class extends CrudEditorNamespace {
693
678
  const integrationTools = await this.resolveStoredIntegrationTools(
694
679
  storedConfig.integrationTools
695
680
  );
696
- agent.__setTools({ ...codeTools, ...registryTools, ...mcpTools, ...integrationTools });
681
+ fork.__setTools({ ...codeTools, ...registryTools, ...mcpTools, ...integrationTools });
697
682
  }
698
683
  }
699
684
  if (storedConfig.resolvedVersionId) {
700
- const existing = agent.toRawConfig() ?? {};
701
- agent.__setRawConfig({ ...existing, resolvedVersionId: storedConfig.resolvedVersionId });
702
- } else {
703
- this.clearResolvedVersionId(agent);
685
+ const existing = fork.toRawConfig() ?? {};
686
+ fork.__setRawConfig({ ...existing, resolvedVersionId: storedConfig.resolvedVersionId });
704
687
  }
705
- return agent;
706
- }
707
- /**
708
- * Save the agent's current field values to the module-level WeakMap
709
- * so they can be restored if the stored config is later removed.
710
- * Only saves on the first call (guards against overwriting originals with overridden values).
711
- *
712
- * Only instructions and tools are saved — these are the only fields
713
- * that `applyStoredOverrides` mutates.
714
- */
715
- saveCodeDefaults(agent) {
716
- if (codeDefaults.has(agent)) return;
717
- const fields = agent.__getOverridableFields();
718
- codeDefaults.set(agent, {
719
- instructions: fields.instructions,
720
- tools: fields.tools
721
- });
722
- }
723
- /**
724
- * Restore the agent's original code-defined field values from the WeakMap.
725
- * Clears the saved snapshot afterward.
726
- */
727
- restoreCodeDefaults(agent) {
728
- const saved = codeDefaults.get(agent);
729
- if (!saved) return;
730
- agent.__updateInstructions(saved.instructions);
731
- agent.__setTools(saved.tools);
732
- codeDefaults.delete(agent);
688
+ return fork;
733
689
  }
734
690
  // ============================================================================
735
691
  // Private helpers
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/editor",
3
- "version": "0.7.16-alpha.0",
3
+ "version": "0.7.16-alpha.2",
4
4
  "description": "Mastra Editor for agent management and instantiation",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",
@@ -65,8 +65,8 @@
65
65
  "@arcadeai/arcadejs": "^2.3.0",
66
66
  "@composio/core": "^0.6.5",
67
67
  "@composio/mastra": "^0.6.5",
68
- "@mastra/memory": "1.15.1-alpha.0",
69
- "@mastra/schema-compat": "1.2.7"
68
+ "@mastra/memory": "1.15.1-alpha.1",
69
+ "@mastra/schema-compat": "1.2.8-alpha.0"
70
70
  },
71
71
  "devDependencies": {
72
72
  "@hono/node-server": "^1.19.11",
@@ -76,12 +76,12 @@
76
76
  "vitest": "4.0.18",
77
77
  "zod": "^3.25.76",
78
78
  "@internal/ai-sdk-v4": "0.0.29",
79
+ "@internal/ai-sdk-v5": "0.0.29",
79
80
  "@internal/ai-v6": "0.0.29",
80
- "@mastra/hono": "1.4.4-alpha.0",
81
- "@mastra/core": "1.24.2-alpha.0",
82
- "@mastra/libsql": "1.8.0",
83
- "@mastra/mcp": "1.4.2",
84
- "@internal/ai-sdk-v5": "0.0.29"
81
+ "@mastra/hono": "1.4.4-alpha.3",
82
+ "@mastra/libsql": "1.8.1-alpha.1",
83
+ "@mastra/core": "1.25.0-alpha.3",
84
+ "@mastra/mcp": "1.5.0-alpha.0"
85
85
  },
86
86
  "peerDependencies": {
87
87
  "@mastra/core": ">=1.7.1-0 <2.0.0-0",