@mastra/editor 0.6.3 → 0.7.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 +56 -0
- package/dist/index.cjs +133 -3
- package/dist/index.d.cts +28 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +133 -3
- package/dist/storage/index.cjs +36 -0
- package/dist/storage/index.d.cts +1 -0
- package/dist/storage/index.d.ts +1 -0
- package/dist/storage/index.js +13 -0
- package/package.json +24 -14
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,61 @@
|
|
|
1
1
|
# @mastra/editor
|
|
2
2
|
|
|
3
|
+
## 0.7.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
|
|
28
|
+
- @mastra/memory@1.6.1
|
|
29
|
+
- @mastra/mcp@1.1.0
|
|
30
|
+
|
|
31
|
+
## 0.7.0-alpha.0
|
|
32
|
+
|
|
33
|
+
### Minor Changes
|
|
34
|
+
|
|
35
|
+
- 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))
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
import { FilesystemStore, MastraCompositeStore } from '@mastra/core/storage';
|
|
39
|
+
import { PostgresStore } from '@mastra/pg';
|
|
40
|
+
|
|
41
|
+
export const mastra = new Mastra({
|
|
42
|
+
storage: new MastraCompositeStore({
|
|
43
|
+
id: 'composite',
|
|
44
|
+
default: new PostgresStore({ id: 'pg', connectionString: process.env.DATABASE_URL }),
|
|
45
|
+
editor: new FilesystemStore({ dir: '.mastra-storage' }),
|
|
46
|
+
}),
|
|
47
|
+
});
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
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.
|
|
51
|
+
|
|
52
|
+
### Patch Changes
|
|
53
|
+
|
|
54
|
+
- 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)]:
|
|
55
|
+
- @mastra/core@1.10.0-alpha.0
|
|
56
|
+
- @mastra/memory@1.6.1-alpha.0
|
|
57
|
+
- @mastra/mcp@1.1.0-alpha.0
|
|
58
|
+
|
|
3
59
|
## 0.6.3
|
|
4
60
|
|
|
5
61
|
### 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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/editor",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.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/
|
|
59
|
-
"@mastra/
|
|
68
|
+
"@mastra/memory": "1.6.1",
|
|
69
|
+
"@mastra/schema-compat": "1.1.3"
|
|
60
70
|
},
|
|
61
71
|
"devDependencies": {
|
|
62
|
-
"@hono/node-server": "^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.
|
|
69
|
-
"@internal/ai-
|
|
70
|
-
"@mastra/core": "1.
|
|
71
|
-
"@internal/ai-
|
|
72
|
-
"@mastra/hono": "1.1.
|
|
73
|
-
"@mastra/libsql": "1.6.
|
|
74
|
-
"@mastra/mcp": "1.0
|
|
78
|
+
"@internal/ai-sdk-v4": "0.0.13",
|
|
79
|
+
"@internal/ai-sdk-v5": "0.0.13",
|
|
80
|
+
"@mastra/core": "1.10.0",
|
|
81
|
+
"@internal/ai-v6": "0.0.13",
|
|
82
|
+
"@mastra/hono": "1.1.9",
|
|
83
|
+
"@mastra/libsql": "1.6.4",
|
|
84
|
+
"@mastra/mcp": "1.1.0"
|
|
75
85
|
},
|
|
76
86
|
"peerDependencies": {
|
|
77
|
-
"@mastra/core": ">=1.
|
|
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",
|