@mastra/editor 0.6.3-alpha.0 → 0.7.0-alpha.0

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,42 @@
1
1
  # @mastra/editor
2
2
 
3
+ ## 0.7.0-alpha.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Added `FilesystemStore`, a file-based storage adapter for editor domains. Stores agent configurations, prompt blocks, scorer definitions, MCP clients, MCP servers, workspaces, and skills as JSON files in a local directory (default: `.mastra-storage/`). Only published snapshots are written to disk — version history is kept in memory. Use with `MastraCompositeStore`'s `editor` shorthand to enable Git-friendly editor configurations. ([#13727](https://github.com/mastra-ai/mastra/pull/13727))
8
+
9
+ ```typescript
10
+ import { FilesystemStore, MastraCompositeStore } from '@mastra/core/storage';
11
+ import { PostgresStore } from '@mastra/pg';
12
+
13
+ export const mastra = new Mastra({
14
+ storage: new MastraCompositeStore({
15
+ id: 'composite',
16
+ default: new PostgresStore({ id: 'pg', connectionString: process.env.DATABASE_URL }),
17
+ editor: new FilesystemStore({ dir: '.mastra-storage' }),
18
+ }),
19
+ });
20
+ ```
21
+
22
+ Added `applyStoredOverrides` to the editor agent namespace. When a stored configuration exists for a code-defined agent, the editor merges the stored **instructions** and **tools** on top of the code agent's values at runtime. Model, memory, workspace, and other code-defined fields are never overridden — they may contain SDK instances or dynamic functions that cannot be safely serialized. Original code-defined values are preserved via a WeakMap and restored if the stored override is deleted.
23
+
24
+ ### Patch Changes
25
+
26
+ - Updated dependencies [[`41e48c1`](https://github.com/mastra-ai/mastra/commit/41e48c198eee846478e60c02ec432c19d322a517), [`82469d3`](https://github.com/mastra-ai/mastra/commit/82469d3135d5a49dd8dc8feec0ff398b4e0225a0), [`33e2fd5`](https://github.com/mastra-ai/mastra/commit/33e2fd5088f83666df17401e2da68c943dbc0448), [`7ef6e2c`](https://github.com/mastra-ai/mastra/commit/7ef6e2c61be5a42e26f55d15b5902866fc76634f), [`08072ec`](https://github.com/mastra-ai/mastra/commit/08072ec54b5dfe810ed66c0d583ae9d1a9103c11), [`ef9d0f0`](https://github.com/mastra-ai/mastra/commit/ef9d0f0fa98ff225b17afe071f5b84a9258dc142), [`b12d2a5`](https://github.com/mastra-ai/mastra/commit/b12d2a59a48be0477cabae66eb6cf0fc94a7d40d), [`9e21667`](https://github.com/mastra-ai/mastra/commit/9e2166746df81da8f1f933a918741fc52f922c70), [`fa37d39`](https://github.com/mastra-ai/mastra/commit/fa37d39910421feaf8847716292e3d65dd4f30c2), [`b12d2a5`](https://github.com/mastra-ai/mastra/commit/b12d2a59a48be0477cabae66eb6cf0fc94a7d40d), [`1391f22`](https://github.com/mastra-ai/mastra/commit/1391f227ff197080de185ac1073c1d1568c0631f), [`71c38bf`](https://github.com/mastra-ai/mastra/commit/71c38bf905905148ecd0e75c07c1f9825d299b76), [`f993c38`](https://github.com/mastra-ai/mastra/commit/f993c3848c97479b813231be872443bedeced6ab), [`f51849a`](https://github.com/mastra-ai/mastra/commit/f51849a568935122b5100b7ee69704e6d680cf7b), [`3ceb231`](https://github.com/mastra-ai/mastra/commit/3ceb2317aad7da36df5053e7c84f9381eeb68d11), [`9bf3a0d`](https://github.com/mastra-ai/mastra/commit/9bf3a0dac602787925f1762f1f0387d7b4a59620), [`cafa045`](https://github.com/mastra-ai/mastra/commit/cafa0453c9de141ad50c09a13894622dffdd9978), [`1fd9ddb`](https://github.com/mastra-ai/mastra/commit/1fd9ddbb3fe83b281b12bd2e27e426ae86288266), [`1391f22`](https://github.com/mastra-ai/mastra/commit/1391f227ff197080de185ac1073c1d1568c0631f), [`ef888d2`](https://github.com/mastra-ai/mastra/commit/ef888d23c77f85f4c202228b63f8fd9b6d9361af), [`e7a567c`](https://github.com/mastra-ai/mastra/commit/e7a567cfb3e65c955a07d0167cb1b4141f5bda01), [`3626623`](https://github.com/mastra-ai/mastra/commit/36266238eb7db78fce2ac34187194613f6f53733), [`6135ef4`](https://github.com/mastra-ai/mastra/commit/6135ef4f5288652bf45f616ec590607e4c95f443), [`d9d228c`](https://github.com/mastra-ai/mastra/commit/d9d228c0c6ae82ae6ce3b540a3a56b2b1c2b8d98), [`5576507`](https://github.com/mastra-ai/mastra/commit/55765071e360fb97e443aa0a91ccf7e1cd8d92aa), [`79d69c9`](https://github.com/mastra-ai/mastra/commit/79d69c9d5f842ff1c31352fb6026f04c1f6190f3), [`94f44b8`](https://github.com/mastra-ai/mastra/commit/94f44b827ce57b179e50f4916a84c0fa6e7f3b8c), [`13187db`](https://github.com/mastra-ai/mastra/commit/13187dbac880174232dedc5a501ff6c5d0fe59bc), [`2ae5311`](https://github.com/mastra-ai/mastra/commit/2ae531185fff66a80fa165c0999e3d801900e89d), [`6135ef4`](https://github.com/mastra-ai/mastra/commit/6135ef4f5288652bf45f616ec590607e4c95f443)]:
27
+ - @mastra/core@1.10.0-alpha.0
28
+ - @mastra/memory@1.6.1-alpha.0
29
+ - @mastra/mcp@1.1.0-alpha.0
30
+
31
+ ## 0.6.3
32
+
33
+ ### Patch Changes
34
+
35
+ - Updated dependencies [[`504fc8b`](https://github.com/mastra-ai/mastra/commit/504fc8b9d0ddab717577ad3bf9c95ea4bd5377bd), [`f9c150b`](https://github.com/mastra-ai/mastra/commit/f9c150b7595ad05ad9cc9a11098e2944361e8c22), [`88de7e8`](https://github.com/mastra-ai/mastra/commit/88de7e8dfe4b7e1951a9e441bb33136e705ce24e), [`edee4b3`](https://github.com/mastra-ai/mastra/commit/edee4b37dff0af515fc7cc0e8d71ee39e6a762f0), [`9311c17`](https://github.com/mastra-ai/mastra/commit/9311c17d7a0640d9c4da2e71b814dc67c57c6369), [`3790c75`](https://github.com/mastra-ai/mastra/commit/3790c7578cc6a47d854eb12d89e6b1912867fe29), [`e7a235b`](https://github.com/mastra-ai/mastra/commit/e7a235be6472e0c870ed6c791ddb17c492dc188b), [`d51d298`](https://github.com/mastra-ai/mastra/commit/d51d298953967aab1f58ec965b644d109214f085), [`6dbeeb9`](https://github.com/mastra-ai/mastra/commit/6dbeeb94a8b1eebb727300d1a98961f882180794), [`d5f0d8d`](https://github.com/mastra-ai/mastra/commit/d5f0d8d6a03e515ddaa9b5da19b7e44b8357b07b), [`09c3b18`](https://github.com/mastra-ai/mastra/commit/09c3b1802ff14e243a8a8baea327440bc8cc2e32), [`b896379`](https://github.com/mastra-ai/mastra/commit/b8963791c6afa79484645fcec596a201f936b9a2), [`b896379`](https://github.com/mastra-ai/mastra/commit/b8963791c6afa79484645fcec596a201f936b9a2), [`85c84eb`](https://github.com/mastra-ai/mastra/commit/85c84ebb78aebfcba9d209c8e152b16d7a00cb71), [`a89272a`](https://github.com/mastra-ai/mastra/commit/a89272a5d71939b9fcd284e6a6dc1dd091a6bdcf), [`ee9c8df`](https://github.com/mastra-ai/mastra/commit/ee9c8df644f19d055af5f496bf4942705f5a47b7), [`77b4a25`](https://github.com/mastra-ai/mastra/commit/77b4a254e51907f8ff3a3ba95596a18e93ae4b35), [`276246e`](https://github.com/mastra-ai/mastra/commit/276246e0b9066a1ea48bbc70df84dbe528daaf99), [`08ecfdb`](https://github.com/mastra-ai/mastra/commit/08ecfdbdad6fb8285deef86a034bdf4a6047cfca), [`d5f628c`](https://github.com/mastra-ai/mastra/commit/d5f628ca86c6f6f3ff1035d52f635df32dd81cab), [`24f7204`](https://github.com/mastra-ai/mastra/commit/24f72046eb35b47c75d36193af4fb817b588720d), [`359d687`](https://github.com/mastra-ai/mastra/commit/359d687527ab95a79e0ec0487dcecec8d9c7c7dc), [`524c0f3`](https://github.com/mastra-ai/mastra/commit/524c0f3c434c3d9d18f66338dcef383d6161b59c), [`c18a0e9`](https://github.com/mastra-ai/mastra/commit/c18a0e9cef1e4ca004b2963d35e4cfc031971eac), [`4bd21ea`](https://github.com/mastra-ai/mastra/commit/4bd21ea43d44d0a0427414fc047577f9f0aa3bec), [`115a7a4`](https://github.com/mastra-ai/mastra/commit/115a7a47db5e9896fec12ae6507501adb9ec89bf), [`22a48ae`](https://github.com/mastra-ai/mastra/commit/22a48ae2513eb54d8d79dad361fddbca97a155e8), [`3c6ef79`](https://github.com/mastra-ai/mastra/commit/3c6ef798481e00d6d22563be2de98818fd4dd5e0), [`9e77e8f`](https://github.com/mastra-ai/mastra/commit/9e77e8f0e823ef58cb448dd1f390fce987a101f3), [`9311c17`](https://github.com/mastra-ai/mastra/commit/9311c17d7a0640d9c4da2e71b814dc67c57c6369), [`7edf78f`](https://github.com/mastra-ai/mastra/commit/7edf78f80422c43e84585f08ba11df0d4d0b73c5), [`1c4221c`](https://github.com/mastra-ai/mastra/commit/1c4221cf6032ec98d0e094d4ee11da3e48490d96), [`d25b9ea`](https://github.com/mastra-ai/mastra/commit/d25b9eabd400167255a97b690ffbc4ee4097ded5), [`fe1ce5c`](https://github.com/mastra-ai/mastra/commit/fe1ce5c9211c03d561606fda95cbfe7df1d9a9b5), [`b03c0e0`](https://github.com/mastra-ai/mastra/commit/b03c0e0389a799523929a458b0509c9e4244d562), [`0a8366b`](https://github.com/mastra-ai/mastra/commit/0a8366b0a692fcdde56c4d526e4cf03c502ae4ac), [`56f2018`](https://github.com/mastra-ai/mastra/commit/56f2018cb38969c11933e815a5f70cf631d3964a), [`85664e9`](https://github.com/mastra-ai/mastra/commit/85664e9fd857320fbc245e301f764f45f66f32a3), [`bc79650`](https://github.com/mastra-ai/mastra/commit/bc796500c6e0334faa158a96077e3fb332274869), [`9257d01`](https://github.com/mastra-ai/mastra/commit/9257d01d1366d81f84c582fe02b5e200cf9621f4), [`9311c17`](https://github.com/mastra-ai/mastra/commit/9311c17d7a0640d9c4da2e71b814dc67c57c6369), [`3a3a59e`](https://github.com/mastra-ai/mastra/commit/3a3a59e8ffaa6a985fe3d9a126a3f5ade11a6724), [`3108d4e`](https://github.com/mastra-ai/mastra/commit/3108d4e649c9fddbf03253a6feeb388a5fa9fa5a), [`0c33b2c`](https://github.com/mastra-ai/mastra/commit/0c33b2c9db537f815e1c59e2c898ffce2e395a79), [`191e5bd`](https://github.com/mastra-ai/mastra/commit/191e5bd29b82f5bda35243945790da7bc7b695c2), [`fde104d`](https://github.com/mastra-ai/mastra/commit/fde104da80935d6e0dd24327e86a51011fcb3173), [`f77cd94`](https://github.com/mastra-ai/mastra/commit/f77cd94c44eabed490384e7d19232a865e13214c), [`e8135c7`](https://github.com/mastra-ai/mastra/commit/e8135c7e300dac5040670eec7eab896ac6092e30), [`daca48f`](https://github.com/mastra-ai/mastra/commit/daca48f0fb17b7ae0b62a2ac40cf0e491b2fd0b7), [`257d14f`](https://github.com/mastra-ai/mastra/commit/257d14faca5931f2e4186fc165b6f0b1f915deee), [`352f25d`](https://github.com/mastra-ai/mastra/commit/352f25da316b24cdd5b410fd8dddf6a8b763da2a), [`93477d0`](https://github.com/mastra-ai/mastra/commit/93477d0769b8a13ea5ed73d508d967fb23eaeed9), [`31c78b3`](https://github.com/mastra-ai/mastra/commit/31c78b3eb28f58a8017f1dcc795c33214d87feac), [`0bc0720`](https://github.com/mastra-ai/mastra/commit/0bc07201095791858087cc56f353fcd65e87ab54), [`36516ac`](https://github.com/mastra-ai/mastra/commit/36516aca1021cbeb42e74751b46a2614101f37c8), [`e947652`](https://github.com/mastra-ai/mastra/commit/e9476527fdecb4449e54570e80dfaf8466901254), [`23b43dd`](https://github.com/mastra-ai/mastra/commit/23b43ddd0e3db05dee828c2733faa2496b7b0319), [`3c6ef79`](https://github.com/mastra-ai/mastra/commit/3c6ef798481e00d6d22563be2de98818fd4dd5e0), [`9257d01`](https://github.com/mastra-ai/mastra/commit/9257d01d1366d81f84c582fe02b5e200cf9621f4), [`ec248f6`](https://github.com/mastra-ai/mastra/commit/ec248f6b56e8a037c066c49b2178e2507471d988)]:
36
+ - @mastra/core@1.9.0
37
+ - @mastra/memory@1.6.0
38
+ - @mastra/mcp@1.0.3
39
+
3
40
  ## 0.6.3-alpha.0
4
41
 
5
42
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -154,8 +154,11 @@ var CrudEditorNamespace = class extends EditorNamespace {
154
154
  */
155
155
  clearCache(id) {
156
156
  if (id) {
157
+ const wasCached = this._cache.has(id);
157
158
  this._cache.delete(id);
158
- this.onCacheEvict(id);
159
+ if (wasCached) {
160
+ this.onCacheEvict(id);
161
+ }
159
162
  this.logger?.debug(`[clearCache] Cleared cache for "${id}"`);
160
163
  } else {
161
164
  for (const cachedId of Array.from(this._cache.keys())) {
@@ -559,6 +562,7 @@ var EditorMCPNamespace = class _EditorMCPNamespace extends CrudEditorNamespace {
559
562
  };
560
563
 
561
564
  // src/namespaces/agent.ts
565
+ var codeDefaults = /* @__PURE__ */ new WeakMap();
562
566
  var EditorAgentNamespace = class extends CrudEditorNamespace {
563
567
  async getStorageAdapter() {
564
568
  const storage = this.mastra?.getStorage();
@@ -599,7 +603,13 @@ var EditorAgentNamespace = class extends CrudEditorNamespace {
599
603
  return this.createAgentFromStoredConfig(storedAgent);
600
604
  }
601
605
  onCacheEvict(id) {
602
- this.mastra?.removeAgent(id);
606
+ try {
607
+ const existing = this.mastra?.getAgentById(id);
608
+ if (existing?.source === "stored") {
609
+ this.mastra?.removeAgent(id);
610
+ }
611
+ } catch {
612
+ }
603
613
  }
604
614
  /**
605
615
  * Evict all cached agents that reference a given skill ID.
@@ -628,6 +638,117 @@ var EditorAgentNamespace = class extends CrudEditorNamespace {
628
638
  }
629
639
  }
630
640
  }
641
+ /**
642
+ * Apply stored configuration overrides to a code-defined agent.
643
+ *
644
+ * When a stored config exists for the given agent's ID, the following fields
645
+ * from the stored config override the code agent's values (if explicitly set):
646
+ * - `instructions` — system prompt
647
+ * - `tools` — tool selection with description overrides (merged on top of code tools)
648
+ *
649
+ * Fields that are absent or undefined in the stored config are left untouched.
650
+ * Model, workspace, memory, and other code-defined fields are never overridden —
651
+ * they may contain SDK instances or dynamic functions that cannot be safely serialized.
652
+ * Returns the (possibly mutated) agent.
653
+ */
654
+ async applyStoredOverrides(agent) {
655
+ let storedConfig = null;
656
+ try {
657
+ this.ensureRegistered();
658
+ const adapter = await this.getStorageAdapter();
659
+ storedConfig = await adapter.getByIdResolved(agent.id, { status: "draft" });
660
+ } catch {
661
+ this.restoreCodeDefaults(agent);
662
+ return agent;
663
+ }
664
+ if (!storedConfig) {
665
+ this.restoreCodeDefaults(agent);
666
+ return agent;
667
+ }
668
+ this.saveCodeDefaults(agent);
669
+ this.restoreCodeDefaults(agent);
670
+ this.saveCodeDefaults(agent);
671
+ this.logger?.debug(`[applyStoredOverrides] Applying stored overrides to code agent "${agent.id}"`);
672
+ if (storedConfig.instructions !== void 0 && storedConfig.instructions !== null) {
673
+ const resolved = this.resolveStoredInstructions(storedConfig.instructions);
674
+ if (resolved !== void 0) {
675
+ agent.__updateInstructions(resolved);
676
+ }
677
+ }
678
+ const hasStoredTools = storedConfig.tools != null;
679
+ const hasStoredMCPClients = storedConfig.mcpClients != null;
680
+ const hasStoredIntegrationTools = storedConfig.integrationTools != null;
681
+ if (hasStoredTools || hasStoredMCPClients || hasStoredIntegrationTools) {
682
+ const hasConditionalTools = this.isConditionalVariants(storedConfig.tools);
683
+ const hasConditionalMCPClients = storedConfig.mcpClients != null && this.isConditionalVariants(storedConfig.mcpClients);
684
+ const hasConditionalIntegrationTools = storedConfig.integrationTools != null && this.isConditionalVariants(storedConfig.integrationTools);
685
+ const isDynamicTools = hasConditionalTools || hasConditionalMCPClients || hasConditionalIntegrationTools;
686
+ if (isDynamicTools) {
687
+ const originalTools = agent.listTools.bind(agent);
688
+ const toolsFn = async ({ requestContext }) => {
689
+ const codeTools = await originalTools({ requestContext });
690
+ const ctx = requestContext.toJSON();
691
+ const resolvedToolsConfig = hasConditionalTools ? this.accumulateObjectVariants(
692
+ storedConfig.tools,
693
+ ctx
694
+ ) : storedConfig.tools;
695
+ const registryTools = this.resolveStoredTools(resolvedToolsConfig);
696
+ const resolvedMCPClientsConfig = hasConditionalMCPClients ? this.accumulateObjectVariants(
697
+ storedConfig.mcpClients,
698
+ ctx
699
+ ) : storedConfig.mcpClients;
700
+ const mcpTools = await this.resolveStoredMCPTools(resolvedMCPClientsConfig);
701
+ const resolvedIntegrationToolsConfig = hasConditionalIntegrationTools ? this.accumulateObjectVariants(
702
+ storedConfig.integrationTools,
703
+ ctx
704
+ ) : storedConfig.integrationTools;
705
+ const integrationTools = await this.resolveStoredIntegrationTools(resolvedIntegrationToolsConfig, ctx);
706
+ return { ...codeTools, ...registryTools, ...mcpTools, ...integrationTools };
707
+ };
708
+ agent.__setTools(toolsFn);
709
+ } else {
710
+ const codeTools = await agent.listTools();
711
+ const registryTools = this.resolveStoredTools(
712
+ storedConfig.tools
713
+ );
714
+ const mcpTools = await this.resolveStoredMCPTools(
715
+ storedConfig.mcpClients
716
+ );
717
+ const integrationTools = await this.resolveStoredIntegrationTools(
718
+ storedConfig.integrationTools
719
+ );
720
+ agent.__setTools({ ...codeTools, ...registryTools, ...mcpTools, ...integrationTools });
721
+ }
722
+ }
723
+ return agent;
724
+ }
725
+ /**
726
+ * Save the agent's current field values to the module-level WeakMap
727
+ * so they can be restored if the stored config is later removed.
728
+ * Only saves on the first call (guards against overwriting originals with overridden values).
729
+ *
730
+ * Only instructions and tools are saved — these are the only fields
731
+ * that `applyStoredOverrides` mutates.
732
+ */
733
+ saveCodeDefaults(agent) {
734
+ if (codeDefaults.has(agent)) return;
735
+ const fields = agent.__getOverridableFields();
736
+ codeDefaults.set(agent, {
737
+ instructions: fields.instructions,
738
+ tools: fields.tools
739
+ });
740
+ }
741
+ /**
742
+ * Restore the agent's original code-defined field values from the WeakMap.
743
+ * Clears the saved snapshot afterward.
744
+ */
745
+ restoreCodeDefaults(agent) {
746
+ const saved = codeDefaults.get(agent);
747
+ if (!saved) return;
748
+ agent.__updateInstructions(saved.instructions);
749
+ agent.__setTools(saved.tools);
750
+ codeDefaults.delete(agent);
751
+ }
631
752
  // ============================================================================
632
753
  // Private helpers
633
754
  // ============================================================================
@@ -868,7 +989,16 @@ var EditorAgentNamespace = class extends CrudEditorNamespace {
868
989
  workspace,
869
990
  ...skillsFormat && { skillsFormat }
870
991
  });
871
- this.mastra?.addAgent(agent, storedAgent.id, { source: "stored" });
992
+ const existingCodeAgent = (() => {
993
+ try {
994
+ return this.mastra?.getAgentById(storedAgent.id);
995
+ } catch {
996
+ return void 0;
997
+ }
998
+ })();
999
+ if (!existingCodeAgent || existingCodeAgent.source !== "code") {
1000
+ this.mastra?.addAgent(agent, storedAgent.id, { source: "stored" });
1001
+ }
872
1002
  this.logger?.debug(`[createAgentFromStoredConfig] Successfully created agent "${storedAgent.id}"`);
873
1003
  return agent;
874
1004
  }
package/dist/index.d.cts CHANGED
@@ -102,6 +102,34 @@ declare class EditorAgentNamespace extends CrudEditorNamespace<StorageCreateAgen
102
102
  * subsequent agent.getById() calls re-hydrate with the updated skill version.
103
103
  */
104
104
  invalidateAgentsReferencingSkill(skillId: string): void;
105
+ /**
106
+ * Apply stored configuration overrides to a code-defined agent.
107
+ *
108
+ * When a stored config exists for the given agent's ID, the following fields
109
+ * from the stored config override the code agent's values (if explicitly set):
110
+ * - `instructions` — system prompt
111
+ * - `tools` — tool selection with description overrides (merged on top of code tools)
112
+ *
113
+ * Fields that are absent or undefined in the stored config are left untouched.
114
+ * Model, workspace, memory, and other code-defined fields are never overridden —
115
+ * they may contain SDK instances or dynamic functions that cannot be safely serialized.
116
+ * Returns the (possibly mutated) agent.
117
+ */
118
+ applyStoredOverrides(agent: Agent): Promise<Agent>;
119
+ /**
120
+ * Save the agent's current field values to the module-level WeakMap
121
+ * so they can be restored if the stored config is later removed.
122
+ * Only saves on the first call (guards against overwriting originals with overridden values).
123
+ *
124
+ * Only instructions and tools are saved — these are the only fields
125
+ * that `applyStoredOverrides` mutates.
126
+ */
127
+ private saveCodeDefaults;
128
+ /**
129
+ * Restore the agent's original code-defined field values from the WeakMap.
130
+ * Clears the saved snapshot afterward.
131
+ */
132
+ private restoreCodeDefaults;
105
133
  /**
106
134
  * Detect whether a StorageConditionalField value is a conditional variant array
107
135
  * (as opposed to the plain static value T).
package/dist/index.d.ts CHANGED
@@ -102,6 +102,34 @@ declare class EditorAgentNamespace extends CrudEditorNamespace<StorageCreateAgen
102
102
  * subsequent agent.getById() calls re-hydrate with the updated skill version.
103
103
  */
104
104
  invalidateAgentsReferencingSkill(skillId: string): void;
105
+ /**
106
+ * Apply stored configuration overrides to a code-defined agent.
107
+ *
108
+ * When a stored config exists for the given agent's ID, the following fields
109
+ * from the stored config override the code agent's values (if explicitly set):
110
+ * - `instructions` — system prompt
111
+ * - `tools` — tool selection with description overrides (merged on top of code tools)
112
+ *
113
+ * Fields that are absent or undefined in the stored config are left untouched.
114
+ * Model, workspace, memory, and other code-defined fields are never overridden —
115
+ * they may contain SDK instances or dynamic functions that cannot be safely serialized.
116
+ * Returns the (possibly mutated) agent.
117
+ */
118
+ applyStoredOverrides(agent: Agent): Promise<Agent>;
119
+ /**
120
+ * Save the agent's current field values to the module-level WeakMap
121
+ * so they can be restored if the stored config is later removed.
122
+ * Only saves on the first call (guards against overwriting originals with overridden values).
123
+ *
124
+ * Only instructions and tools are saved — these are the only fields
125
+ * that `applyStoredOverrides` mutates.
126
+ */
127
+ private saveCodeDefaults;
128
+ /**
129
+ * Restore the agent's original code-defined field values from the WeakMap.
130
+ * Clears the saved snapshot afterward.
131
+ */
132
+ private restoreCodeDefaults;
105
133
  /**
106
134
  * Detect whether a StorageConditionalField value is a conditional variant array
107
135
  * (as opposed to the plain static value T).
package/dist/index.js CHANGED
@@ -106,8 +106,11 @@ var CrudEditorNamespace = class extends EditorNamespace {
106
106
  */
107
107
  clearCache(id) {
108
108
  if (id) {
109
+ const wasCached = this._cache.has(id);
109
110
  this._cache.delete(id);
110
- this.onCacheEvict(id);
111
+ if (wasCached) {
112
+ this.onCacheEvict(id);
113
+ }
111
114
  this.logger?.debug(`[clearCache] Cleared cache for "${id}"`);
112
115
  } else {
113
116
  for (const cachedId of Array.from(this._cache.keys())) {
@@ -511,6 +514,7 @@ var EditorMCPNamespace = class _EditorMCPNamespace extends CrudEditorNamespace {
511
514
  };
512
515
 
513
516
  // src/namespaces/agent.ts
517
+ var codeDefaults = /* @__PURE__ */ new WeakMap();
514
518
  var EditorAgentNamespace = class extends CrudEditorNamespace {
515
519
  async getStorageAdapter() {
516
520
  const storage = this.mastra?.getStorage();
@@ -551,7 +555,13 @@ var EditorAgentNamespace = class extends CrudEditorNamespace {
551
555
  return this.createAgentFromStoredConfig(storedAgent);
552
556
  }
553
557
  onCacheEvict(id) {
554
- this.mastra?.removeAgent(id);
558
+ try {
559
+ const existing = this.mastra?.getAgentById(id);
560
+ if (existing?.source === "stored") {
561
+ this.mastra?.removeAgent(id);
562
+ }
563
+ } catch {
564
+ }
555
565
  }
556
566
  /**
557
567
  * Evict all cached agents that reference a given skill ID.
@@ -580,6 +590,117 @@ var EditorAgentNamespace = class extends CrudEditorNamespace {
580
590
  }
581
591
  }
582
592
  }
593
+ /**
594
+ * Apply stored configuration overrides to a code-defined agent.
595
+ *
596
+ * When a stored config exists for the given agent's ID, the following fields
597
+ * from the stored config override the code agent's values (if explicitly set):
598
+ * - `instructions` — system prompt
599
+ * - `tools` — tool selection with description overrides (merged on top of code tools)
600
+ *
601
+ * Fields that are absent or undefined in the stored config are left untouched.
602
+ * Model, workspace, memory, and other code-defined fields are never overridden —
603
+ * they may contain SDK instances or dynamic functions that cannot be safely serialized.
604
+ * Returns the (possibly mutated) agent.
605
+ */
606
+ async applyStoredOverrides(agent) {
607
+ let storedConfig = null;
608
+ try {
609
+ this.ensureRegistered();
610
+ const adapter = await this.getStorageAdapter();
611
+ storedConfig = await adapter.getByIdResolved(agent.id, { status: "draft" });
612
+ } catch {
613
+ this.restoreCodeDefaults(agent);
614
+ return agent;
615
+ }
616
+ if (!storedConfig) {
617
+ this.restoreCodeDefaults(agent);
618
+ return agent;
619
+ }
620
+ this.saveCodeDefaults(agent);
621
+ this.restoreCodeDefaults(agent);
622
+ this.saveCodeDefaults(agent);
623
+ this.logger?.debug(`[applyStoredOverrides] Applying stored overrides to code agent "${agent.id}"`);
624
+ if (storedConfig.instructions !== void 0 && storedConfig.instructions !== null) {
625
+ const resolved = this.resolveStoredInstructions(storedConfig.instructions);
626
+ if (resolved !== void 0) {
627
+ agent.__updateInstructions(resolved);
628
+ }
629
+ }
630
+ const hasStoredTools = storedConfig.tools != null;
631
+ const hasStoredMCPClients = storedConfig.mcpClients != null;
632
+ const hasStoredIntegrationTools = storedConfig.integrationTools != null;
633
+ if (hasStoredTools || hasStoredMCPClients || hasStoredIntegrationTools) {
634
+ const hasConditionalTools = this.isConditionalVariants(storedConfig.tools);
635
+ const hasConditionalMCPClients = storedConfig.mcpClients != null && this.isConditionalVariants(storedConfig.mcpClients);
636
+ const hasConditionalIntegrationTools = storedConfig.integrationTools != null && this.isConditionalVariants(storedConfig.integrationTools);
637
+ const isDynamicTools = hasConditionalTools || hasConditionalMCPClients || hasConditionalIntegrationTools;
638
+ if (isDynamicTools) {
639
+ const originalTools = agent.listTools.bind(agent);
640
+ const toolsFn = async ({ requestContext }) => {
641
+ const codeTools = await originalTools({ requestContext });
642
+ const ctx = requestContext.toJSON();
643
+ const resolvedToolsConfig = hasConditionalTools ? this.accumulateObjectVariants(
644
+ storedConfig.tools,
645
+ ctx
646
+ ) : storedConfig.tools;
647
+ const registryTools = this.resolveStoredTools(resolvedToolsConfig);
648
+ const resolvedMCPClientsConfig = hasConditionalMCPClients ? this.accumulateObjectVariants(
649
+ storedConfig.mcpClients,
650
+ ctx
651
+ ) : storedConfig.mcpClients;
652
+ const mcpTools = await this.resolveStoredMCPTools(resolvedMCPClientsConfig);
653
+ const resolvedIntegrationToolsConfig = hasConditionalIntegrationTools ? this.accumulateObjectVariants(
654
+ storedConfig.integrationTools,
655
+ ctx
656
+ ) : storedConfig.integrationTools;
657
+ const integrationTools = await this.resolveStoredIntegrationTools(resolvedIntegrationToolsConfig, ctx);
658
+ return { ...codeTools, ...registryTools, ...mcpTools, ...integrationTools };
659
+ };
660
+ agent.__setTools(toolsFn);
661
+ } else {
662
+ const codeTools = await agent.listTools();
663
+ const registryTools = this.resolveStoredTools(
664
+ storedConfig.tools
665
+ );
666
+ const mcpTools = await this.resolveStoredMCPTools(
667
+ storedConfig.mcpClients
668
+ );
669
+ const integrationTools = await this.resolveStoredIntegrationTools(
670
+ storedConfig.integrationTools
671
+ );
672
+ agent.__setTools({ ...codeTools, ...registryTools, ...mcpTools, ...integrationTools });
673
+ }
674
+ }
675
+ return agent;
676
+ }
677
+ /**
678
+ * Save the agent's current field values to the module-level WeakMap
679
+ * so they can be restored if the stored config is later removed.
680
+ * Only saves on the first call (guards against overwriting originals with overridden values).
681
+ *
682
+ * Only instructions and tools are saved — these are the only fields
683
+ * that `applyStoredOverrides` mutates.
684
+ */
685
+ saveCodeDefaults(agent) {
686
+ if (codeDefaults.has(agent)) return;
687
+ const fields = agent.__getOverridableFields();
688
+ codeDefaults.set(agent, {
689
+ instructions: fields.instructions,
690
+ tools: fields.tools
691
+ });
692
+ }
693
+ /**
694
+ * Restore the agent's original code-defined field values from the WeakMap.
695
+ * Clears the saved snapshot afterward.
696
+ */
697
+ restoreCodeDefaults(agent) {
698
+ const saved = codeDefaults.get(agent);
699
+ if (!saved) return;
700
+ agent.__updateInstructions(saved.instructions);
701
+ agent.__setTools(saved.tools);
702
+ codeDefaults.delete(agent);
703
+ }
583
704
  // ============================================================================
584
705
  // Private helpers
585
706
  // ============================================================================
@@ -820,7 +941,16 @@ var EditorAgentNamespace = class extends CrudEditorNamespace {
820
941
  workspace,
821
942
  ...skillsFormat && { skillsFormat }
822
943
  });
823
- this.mastra?.addAgent(agent, storedAgent.id, { source: "stored" });
944
+ const existingCodeAgent = (() => {
945
+ try {
946
+ return this.mastra?.getAgentById(storedAgent.id);
947
+ } catch {
948
+ return void 0;
949
+ }
950
+ })();
951
+ if (!existingCodeAgent || existingCodeAgent.source !== "code") {
952
+ this.mastra?.addAgent(agent, storedAgent.id, { source: "stored" });
953
+ }
824
954
  this.logger?.debug(`[createAgentFromStoredConfig] Successfully created agent "${storedAgent.id}"`);
825
955
  return agent;
826
956
  }
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/storage/index.ts
21
+ var storage_exports = {};
22
+ __export(storage_exports, {
23
+ FilesystemDB: () => import_storage.FilesystemDB,
24
+ FilesystemStore: () => import_storage.FilesystemStore,
25
+ FilesystemVersionedHelpers: () => import_storage.FilesystemVersionedHelpers,
26
+ GitHistory: () => import_storage.GitHistory
27
+ });
28
+ module.exports = __toCommonJS(storage_exports);
29
+ var import_storage = require("@mastra/core/storage");
30
+ // Annotate the CommonJS export names for ESM import in node:
31
+ 0 && (module.exports = {
32
+ FilesystemDB,
33
+ FilesystemStore,
34
+ FilesystemVersionedHelpers,
35
+ GitHistory
36
+ });
@@ -0,0 +1 @@
1
+ export { FilesystemDB, FilesystemStore, FilesystemStoreConfig, FilesystemVersionedHelpers, GitHistory } from '@mastra/core/storage';
@@ -0,0 +1 @@
1
+ export { FilesystemDB, FilesystemStore, FilesystemStoreConfig, FilesystemVersionedHelpers, GitHistory } from '@mastra/core/storage';
@@ -0,0 +1,13 @@
1
+ // src/storage/index.ts
2
+ import {
3
+ FilesystemStore,
4
+ FilesystemDB,
5
+ FilesystemVersionedHelpers,
6
+ GitHistory
7
+ } from "@mastra/core/storage";
8
+ export {
9
+ FilesystemDB,
10
+ FilesystemStore,
11
+ FilesystemVersionedHelpers,
12
+ GitHistory
13
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/editor",
3
- "version": "0.6.3-alpha.0",
3
+ "version": "0.7.0-alpha.0",
4
4
  "description": "Mastra Editor for agent management and instantiation",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",
@@ -36,6 +36,16 @@
36
36
  "types": "./dist/arcade.d.ts",
37
37
  "default": "./dist/arcade.cjs"
38
38
  }
39
+ },
40
+ "./storage": {
41
+ "import": {
42
+ "types": "./dist/storage/index.d.ts",
43
+ "default": "./dist/storage/index.js"
44
+ },
45
+ "require": {
46
+ "types": "./dist/storage/index.d.ts",
47
+ "default": "./dist/storage/index.cjs"
48
+ }
39
49
  }
40
50
  },
41
51
  "files": [
@@ -55,26 +65,26 @@
55
65
  "@arcadeai/arcadejs": "^2.2.0",
56
66
  "@composio/core": "^0.6.3",
57
67
  "@composio/mastra": "^0.6.3",
58
- "@mastra/memory": "1.6.0-alpha.0",
68
+ "@mastra/memory": "1.6.1-alpha.0",
59
69
  "@mastra/schema-compat": "1.1.3"
60
70
  },
61
71
  "devDependencies": {
62
- "@hono/node-server": "^1.14.1",
72
+ "@hono/node-server": "^1.19.9",
63
73
  "hono": "^4.7.10",
64
74
  "tsup": "^8.0.2",
65
75
  "typescript": "^5.9.3",
66
76
  "vitest": "4.0.18",
67
77
  "zod": "^3.25.76",
68
- "@internal/ai-sdk-v4": "0.0.10",
69
- "@mastra/core": "1.9.0-alpha.0",
70
- "@internal/ai-sdk-v5": "0.0.10",
71
- "@mastra/hono": "1.1.8-alpha.0",
72
- "@internal/ai-v6": "0.0.10",
73
- "@mastra/libsql": "1.6.3-alpha.0",
74
- "@mastra/mcp": "1.0.3-alpha.0"
78
+ "@internal/ai-sdk-v4": "0.0.12",
79
+ "@internal/ai-sdk-v5": "0.0.12",
80
+ "@internal/ai-v6": "0.0.12",
81
+ "@mastra/core": "1.10.0-alpha.0",
82
+ "@mastra/hono": "1.1.9-alpha.0",
83
+ "@mastra/libsql": "1.6.4-alpha.0",
84
+ "@mastra/mcp": "1.1.0-alpha.0"
75
85
  },
76
86
  "peerDependencies": {
77
- "@mastra/core": ">=1.0.0-0 <2.0.0-0",
87
+ "@mastra/core": ">=1.7.1-0 <2.0.0-0",
78
88
  "@mastra/mcp": ">=1.0.0-0 <2.0.0-0",
79
89
  "zod": "^3.25.0 || ^4.0.0"
80
90
  },
@@ -87,8 +97,8 @@
87
97
  "node": ">=22.13.0"
88
98
  },
89
99
  "scripts": {
90
- "build": "tsup src/index.ts src/composio.ts src/arcade.ts --format cjs,esm --dts",
91
- "dev": "tsup src/index.ts src/composio.ts src/arcade.ts --format cjs,esm --dts --watch",
100
+ "build": "tsup src/index.ts src/composio.ts src/arcade.ts src/storage/index.ts --format cjs,esm --dts",
101
+ "dev": "tsup src/index.ts src/composio.ts src/arcade.ts src/storage/index.ts --format cjs,esm --dts --watch",
92
102
  "clean": "rm -rf dist",
93
103
  "typecheck": "tsc --noEmit",
94
104
  "test": "vitest run",