@mastra/editor 0.10.2-alpha.1 → 0.11.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -156,6 +156,7 @@ declare class EditorAgentNamespace extends CrudEditorNamespace<StorageCreateAgen
156
156
  private accumulateObjectVariants;
157
157
  private createAgentFromStoredConfig;
158
158
  private resolveStoredInstructions;
159
+ private applyStoredToolDescriptions;
159
160
  /**
160
161
  * Resolve stored tool IDs to actual tool instances from Mastra's registry.
161
162
  * Applies description overrides from per-tool config when present.
@@ -442,6 +443,8 @@ declare class MastraEditor implements IMastraEditor {
442
443
  __logger?: IMastraLogger;
443
444
  private __toolProviders;
444
445
  private __processorProviders;
446
+ private __source?;
447
+ private __codePath;
445
448
  private readonly __builderConfig?;
446
449
  private __builderInstance?;
447
450
  private __builderResolved;
@@ -521,6 +524,8 @@ declare class MastraEditor implements IMastraEditor {
521
524
  * valid EE license. Dev environments bypass via `isEEEnabled()`.
522
525
  */
523
526
  private assertAgentBuilderLicensed;
527
+ /** Returns the editor's configured source, or undefined if unset. */
528
+ getSource(): 'code' | 'db' | undefined;
524
529
  /** Registered tool providers */
525
530
  getToolProvider(id: string): ToolProvider | undefined;
526
531
  /**
package/dist/index.d.ts CHANGED
@@ -156,6 +156,7 @@ declare class EditorAgentNamespace extends CrudEditorNamespace<StorageCreateAgen
156
156
  private accumulateObjectVariants;
157
157
  private createAgentFromStoredConfig;
158
158
  private resolveStoredInstructions;
159
+ private applyStoredToolDescriptions;
159
160
  /**
160
161
  * Resolve stored tool IDs to actual tool instances from Mastra's registry.
161
162
  * Applies description overrides from per-tool config when present.
@@ -442,6 +443,8 @@ declare class MastraEditor implements IMastraEditor {
442
443
  __logger?: IMastraLogger;
443
444
  private __toolProviders;
444
445
  private __processorProviders;
446
+ private __source?;
447
+ private __codePath;
445
448
  private readonly __builderConfig?;
446
449
  private __builderInstance?;
447
450
  private __builderResolved;
@@ -521,6 +524,8 @@ declare class MastraEditor implements IMastraEditor {
521
524
  * valid EE license. Dev environments bypass via `isEEEnabled()`.
522
525
  */
523
526
  private assertAgentBuilderLicensed;
527
+ /** Returns the editor's configured source, or undefined if unset. */
528
+ getSource(): 'code' | 'db' | undefined;
524
529
  /** Registered tool providers */
525
530
  getToolProvider(id: string): ToolProvider | undefined;
526
531
  /**
package/dist/index.js CHANGED
@@ -1,5 +1,7 @@
1
1
  // src/index.ts
2
2
  import { BUILT_IN_PROCESSOR_PROVIDERS } from "@mastra/core/processor-provider";
3
+ import { FilesystemStore, MastraCompositeStore } from "@mastra/core/storage";
4
+ import { UnknownToolProviderError } from "@mastra/core/tool-provider";
3
5
 
4
6
  // src/namespaces/base.ts
5
7
  var EditorNamespace = class {
@@ -126,6 +128,7 @@ import { Agent } from "@mastra/core/agent";
126
128
  import { CompositeVersionedSkillSource } from "@mastra/core/workspace";
127
129
  import { convertSchemaToZod } from "@mastra/schema-compat";
128
130
  import { RequestContext } from "@mastra/core/request-context";
131
+ import { resolveStoredToolProviders } from "@mastra/core/tool-provider";
129
132
 
130
133
  // src/rule-evaluator.ts
131
134
  function resolvePath(context, path) {
@@ -701,6 +704,14 @@ var EditorAgentNamespace = class extends CrudEditorNamespace {
701
704
  * Returns the (possibly mutated) agent.
702
705
  */
703
706
  async applyStoredOverrides(agent, options, requestContext) {
707
+ const editorConfig = agent.__getEditorConfig?.();
708
+ if (editorConfig === false) {
709
+ return agent;
710
+ }
711
+ const instructionsEditable = editorConfig === void 0 ? true : editorConfig.instructions === true;
712
+ const toolsConfig = editorConfig === void 0 ? true : editorConfig.tools;
713
+ const toolsEditable = toolsConfig === true;
714
+ const toolDescriptionsEditable = typeof toolsConfig === "object" && toolsConfig !== null && toolsConfig.description === true;
704
715
  let storedConfig = null;
705
716
  try {
706
717
  this.ensureRegistered();
@@ -722,7 +733,7 @@ var EditorAgentNamespace = class extends CrudEditorNamespace {
722
733
  }
723
734
  const fork = agent.__fork();
724
735
  this.logger?.debug(`[applyStoredOverrides] Applying stored overrides to code agent "${agent.id}"`);
725
- if (storedConfig.instructions !== void 0 && storedConfig.instructions !== null) {
736
+ if (instructionsEditable && storedConfig.instructions !== void 0 && storedConfig.instructions !== null) {
726
737
  const resolved = this.resolveStoredInstructions(storedConfig.instructions);
727
738
  if (resolved !== void 0) {
728
739
  fork.__updateInstructions(resolved);
@@ -731,11 +742,13 @@ var EditorAgentNamespace = class extends CrudEditorNamespace {
731
742
  const hasStoredTools = storedConfig.tools != null;
732
743
  const hasStoredMCPClients = storedConfig.mcpClients != null;
733
744
  const hasStoredIntegrationTools = storedConfig.integrationTools != null;
734
- if (hasStoredTools || hasStoredMCPClients || hasStoredIntegrationTools) {
745
+ const hasStoredToolProviders = storedConfig.toolProviders != null && Object.keys(storedConfig.toolProviders).length > 0;
746
+ if (toolsEditable && (hasStoredTools || hasStoredMCPClients || hasStoredIntegrationTools || hasStoredToolProviders)) {
735
747
  const hasConditionalTools = this.isConditionalVariants(storedConfig.tools);
736
748
  const hasConditionalMCPClients = storedConfig.mcpClients != null && this.isConditionalVariants(storedConfig.mcpClients);
737
749
  const hasConditionalIntegrationTools = storedConfig.integrationTools != null && this.isConditionalVariants(storedConfig.integrationTools);
738
- const isDynamicTools = hasConditionalTools || hasConditionalMCPClients || hasConditionalIntegrationTools || hasStoredIntegrationTools;
750
+ const hasConditionalToolProviders = storedConfig.toolProviders != null && this.isConditionalVariants(storedConfig.toolProviders);
751
+ const isDynamicTools = hasConditionalTools || hasConditionalMCPClients || hasConditionalIntegrationTools || hasStoredIntegrationTools || hasConditionalToolProviders || hasStoredToolProviders;
739
752
  if (isDynamicTools) {
740
753
  const originalTools = agent.listTools.bind(agent);
741
754
  const toolsFn = async ({ requestContext: requestContext2 }) => {
@@ -759,7 +772,20 @@ var EditorAgentNamespace = class extends CrudEditorNamespace {
759
772
  resolvedIntegrationToolsConfig,
760
773
  requestContext2
761
774
  );
762
- return { ...codeTools, ...registryTools, ...mcpTools, ...integrationTools };
775
+ const resolvedToolProvidersConfig = hasConditionalToolProviders ? this.accumulateObjectVariants(
776
+ storedConfig.toolProviders,
777
+ ctx
778
+ ) : storedConfig.toolProviders;
779
+ const providerTools = await resolveStoredToolProviders(
780
+ resolvedToolProvidersConfig,
781
+ (providerId) => this.editor.getToolProviderOrThrow(providerId),
782
+ {
783
+ requestContext: ctx,
784
+ authorId: storedConfig.authorId,
785
+ logger: this.logger
786
+ }
787
+ );
788
+ return { ...codeTools, ...registryTools, ...mcpTools, ...integrationTools, ...providerTools };
763
789
  };
764
790
  fork.__setTools(toolsFn);
765
791
  } else {
@@ -776,6 +802,28 @@ var EditorAgentNamespace = class extends CrudEditorNamespace {
776
802
  );
777
803
  fork.__setTools({ ...codeTools, ...registryTools, ...mcpTools, ...integrationTools });
778
804
  }
805
+ } else if (toolDescriptionsEditable && hasStoredTools) {
806
+ const hasConditionalTools = this.isConditionalVariants(storedConfig.tools);
807
+ if (hasConditionalTools) {
808
+ const originalTools = agent.listTools.bind(agent);
809
+ const toolsFn = async ({ requestContext: requestContext2 }) => {
810
+ const codeTools = await originalTools({ requestContext: requestContext2 });
811
+ const resolvedToolsConfig = this.accumulateObjectVariants(
812
+ storedConfig.tools,
813
+ requestContext2.toJSON()
814
+ );
815
+ return this.applyStoredToolDescriptions(codeTools, resolvedToolsConfig);
816
+ };
817
+ fork.__setTools(toolsFn);
818
+ } else {
819
+ const codeTools = await fork.listTools();
820
+ fork.__setTools(
821
+ this.applyStoredToolDescriptions(
822
+ codeTools,
823
+ storedConfig.tools
824
+ )
825
+ );
826
+ }
779
827
  }
780
828
  if (storedConfig.resolvedVersionId) {
781
829
  const existing = fork.toRawConfig() ?? {};
@@ -831,6 +879,8 @@ var EditorAgentNamespace = class extends CrudEditorNamespace {
831
879
  const hasConditionalTools = storedAgent.tools != null && this.isConditionalVariants(storedAgent.tools);
832
880
  const hasConditionalMCPClients = storedAgent.mcpClients != null && this.isConditionalVariants(storedAgent.mcpClients);
833
881
  const hasConditionalIntegrationTools = storedAgent.integrationTools != null && this.isConditionalVariants(storedAgent.integrationTools);
882
+ const hasToolProviders = storedAgent.toolProviders != null && Object.keys(storedAgent.toolProviders).length > 0;
883
+ const hasConditionalToolProviders = storedAgent.toolProviders != null && this.isConditionalVariants(storedAgent.toolProviders);
834
884
  const hasConditionalWorkflows = storedAgent.workflows != null && this.isConditionalVariants(storedAgent.workflows);
835
885
  const hasConditionalAgents = storedAgent.agents != null && this.isConditionalVariants(storedAgent.agents);
836
886
  const hasConditionalMemory = storedAgent.memory != null && this.isConditionalVariants(storedAgent.memory);
@@ -842,7 +892,7 @@ var EditorAgentNamespace = class extends CrudEditorNamespace {
842
892
  const hasConditionalWorkspace = storedAgent.workspace != null && this.isConditionalVariants(storedAgent.workspace);
843
893
  const hasConditionalBrowser = storedAgent.browser != null && this.isConditionalVariants(storedAgent.browser);
844
894
  const hasIntegrationTools = storedAgent.integrationTools != null;
845
- const isDynamicTools = hasConditionalTools || hasConditionalMCPClients || hasConditionalIntegrationTools || hasIntegrationTools;
895
+ const isDynamicTools = hasConditionalTools || hasConditionalMCPClients || hasConditionalIntegrationTools || hasIntegrationTools || hasConditionalToolProviders || hasToolProviders;
846
896
  let tools;
847
897
  if (isDynamicTools) {
848
898
  tools = async ({ requestContext }) => {
@@ -865,7 +915,17 @@ var EditorAgentNamespace = class extends CrudEditorNamespace {
865
915
  resolvedIntegrationToolsConfig,
866
916
  requestContext
867
917
  );
868
- return { ...registryTools, ...mcpTools, ...integrationTools };
918
+ const resolvedToolProvidersConfig = hasConditionalToolProviders ? this.accumulateObjectVariants(storedAgent.toolProviders, ctx) : storedAgent.toolProviders;
919
+ const providerTools = await resolveStoredToolProviders(
920
+ resolvedToolProvidersConfig,
921
+ (providerId) => this.editor.getToolProviderOrThrow(providerId),
922
+ {
923
+ requestContext: ctx,
924
+ authorId: storedAgent.authorId,
925
+ logger: this.logger
926
+ }
927
+ );
928
+ return { ...registryTools, ...mcpTools, ...integrationTools, ...providerTools };
869
929
  };
870
930
  } else {
871
931
  const registryTools = this.resolveStoredTools(storedAgent.tools);
@@ -1064,6 +1124,20 @@ var EditorAgentNamespace = class extends CrudEditorNamespace {
1064
1124
  return resolveInstructionBlocks(blocks, context, { promptBlocksStorage: promptBlocksStore });
1065
1125
  };
1066
1126
  }
1127
+ applyStoredToolDescriptions(codeTools, storedTools) {
1128
+ if (!storedTools || Array.isArray(storedTools)) {
1129
+ return codeTools;
1130
+ }
1131
+ let nextTools;
1132
+ for (const [toolKey, toolConfig] of Object.entries(storedTools)) {
1133
+ if (!toolConfig.description || !(toolKey in codeTools)) {
1134
+ continue;
1135
+ }
1136
+ nextTools ?? (nextTools = { ...codeTools });
1137
+ nextTools[toolKey] = { ...codeTools[toolKey], description: toolConfig.description };
1138
+ }
1139
+ return nextTools ?? codeTools;
1140
+ }
1067
1141
  /**
1068
1142
  * Resolve stored tool IDs to actual tool instances from Mastra's registry.
1069
1143
  * Applies description overrides from per-tool config when present.
@@ -2178,6 +2252,8 @@ var MastraEditor = class {
2178
2252
  this.__logger = config?.logger;
2179
2253
  this.__toolProviders = config?.toolProviders ?? {};
2180
2254
  this.__processorProviders = { ...BUILT_IN_PROCESSOR_PROVIDERS, ...config?.processorProviders };
2255
+ this.__source = config?.source;
2256
+ this.__codePath = config?.codePath ?? "./mastra/editor";
2181
2257
  this.__filesystems = /* @__PURE__ */ new Map();
2182
2258
  this.__filesystems.set(localFilesystemProvider.id, localFilesystemProvider);
2183
2259
  for (const [id, provider] of Object.entries(config?.filesystems ?? {})) {
@@ -2215,6 +2291,21 @@ var MastraEditor = class {
2215
2291
  if (!this.__logger) {
2216
2292
  this.__logger = mastra.getLogger();
2217
2293
  }
2294
+ if (this.__source === "code") {
2295
+ const filesystemStore = new FilesystemStore({ dir: this.__codePath });
2296
+ const existingStorage = mastra.getStorage();
2297
+ if (existingStorage) {
2298
+ mastra.setStorage(
2299
+ new MastraCompositeStore({
2300
+ id: `${existingStorage.id}-with-editor-filesystem`,
2301
+ default: existingStorage,
2302
+ editor: filesystemStore
2303
+ })
2304
+ );
2305
+ } else {
2306
+ mastra.setStorage(filesystemStore);
2307
+ }
2308
+ }
2218
2309
  this.ensureBuilderWorkspaces().then(() => this.reconcileBuilderWorkspaces()).catch((err) => {
2219
2310
  this.__logger?.warn("[MastraEditor] Failed to persist/reconcile builder workspaces on startup", {
2220
2311
  error: err
@@ -2363,6 +2454,10 @@ var MastraEditor = class {
2363
2454
  );
2364
2455
  }
2365
2456
  }
2457
+ /** Returns the editor's configured source, or undefined if unset. */
2458
+ getSource() {
2459
+ return this.__source;
2460
+ }
2366
2461
  /** Registered tool providers */
2367
2462
  getToolProvider(id) {
2368
2463
  return this.__toolProviders[id];
@@ -2374,9 +2469,7 @@ var MastraEditor = class {
2374
2469
  getToolProviderOrThrow(id) {
2375
2470
  const provider = this.__toolProviders[id];
2376
2471
  if (!provider) {
2377
- throw new Error(
2378
- `Unknown tool provider "${id}". Available: ${Object.keys(this.__toolProviders).join(", ") || "(none)"}`
2379
- );
2472
+ throw new UnknownToolProviderError(id, Object.keys(this.__toolProviders));
2380
2473
  }
2381
2474
  return provider;
2382
2475
  }