@mastra/editor 0.16.7-alpha.1 → 0.17.0-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/dist/index.cjs CHANGED
@@ -638,6 +638,7 @@ const AGENT_SNAPSHOT_CONFIG_FIELDS = [
638
638
  "description",
639
639
  "instructions",
640
640
  "model",
641
+ "modelList",
641
642
  "tools",
642
643
  "defaultOptions",
643
644
  "workflows",
@@ -935,16 +936,18 @@ var EditorAgentNamespace = class extends CrudEditorNamespace {
935
936
  * from the stored config override the code agent's values (if explicitly set):
936
937
  * - `instructions` — system prompt
937
938
  * - `tools` — tool selection with description overrides (merged on top of code tools)
939
+ * - `modelList` — ordered serializable fallback settings matched to code entries by ID
938
940
  *
939
941
  * Fields that are absent or undefined in the stored config are left untouched.
940
- * Model, workspace, memory, and other code-defined fields are never overridden —
941
- * they may contain SDK instances or dynamic functions that cannot be safely serialized.
942
+ * Workspace, memory, and other code-defined fields are never overridden because they
943
+ * may contain SDK instances or dynamic functions that cannot be safely serialized.
942
944
  * Returns the (possibly mutated) agent.
943
945
  */
944
946
  async applyStoredOverrides(agent, options, requestContext) {
945
947
  const editorConfig = agent.__getEditorConfig?.();
946
948
  if (editorConfig === false) return agent;
947
949
  const instructionsEditable = editorConfig === void 0 ? true : editorConfig.instructions === true;
950
+ const modelEditable = editorConfig !== void 0 && editorConfig.model === true;
948
951
  const toolsConfig = editorConfig === void 0 ? true : editorConfig.tools;
949
952
  const toolsEditable = toolsConfig === true;
950
953
  const toolDescriptionsEditable = typeof toolsConfig === "object" && toolsConfig !== null && toolsConfig.description === true;
@@ -979,6 +982,38 @@ var EditorAgentNamespace = class extends CrudEditorNamespace {
979
982
  const resolved = this.resolveStoredInstructions(storedConfig.instructions);
980
983
  if (resolved !== void 0) fork.__updateInstructions(this.mergeInstructionEnvelope(agent, resolved));
981
984
  }
985
+ if (modelEditable && storedConfig.modelList) {
986
+ const codeModel = fork.__getOverridableFields().model;
987
+ if (!Array.isArray(codeModel)) throw new Error(`Agent "${agent.id}" delegates its model list to the editor but its code-defined model is not a static fallback list.`);
988
+ const codeModelsById = new Map(codeModel.map((model) => [model.id, model]));
989
+ const appliedModelIds = /* @__PURE__ */ new Set();
990
+ const modelList = storedConfig.modelList.flatMap((storedModel) => {
991
+ const codeModelEntry = codeModelsById.get(storedModel.id);
992
+ if (!codeModelEntry) {
993
+ this.logger?.warn(`[applyStoredOverrides] Ignoring stale stored model-list entry "${storedModel.id}" for agent "${agent.id}"`);
994
+ return [];
995
+ }
996
+ appliedModelIds.add(storedModel.id);
997
+ const codeModelRef = typeof codeModelEntry.model === "string" ? codeModelEntry.model : "id" in codeModelEntry.model && typeof codeModelEntry.model.id === "string" ? codeModelEntry.model.id : "provider" in codeModelEntry.model && "modelId" in codeModelEntry.model && typeof codeModelEntry.model.provider === "string" && typeof codeModelEntry.model.modelId === "string" ? `${codeModelEntry.model.provider}/${codeModelEntry.model.modelId}` : void 0;
998
+ const storedModelRef = `${storedModel.provider}/${storedModel.modelId}`;
999
+ return [{
1000
+ ...codeModelEntry,
1001
+ id: storedModel.id,
1002
+ model: codeModelRef === storedModelRef ? codeModelEntry.model : storedModelRef,
1003
+ enabled: storedModel.enabled,
1004
+ maxRetries: storedModel.maxRetries,
1005
+ maxRetriesConfigured: true
1006
+ }];
1007
+ });
1008
+ modelList.push(...codeModel.flatMap((model) => model.id && !appliedModelIds.has(model.id) ? [{
1009
+ ...model,
1010
+ id: model.id,
1011
+ enabled: model.enabled ?? true,
1012
+ maxRetries: model.maxRetries ?? 0,
1013
+ maxRetriesConfigured: "maxRetriesConfigured" in model ? model.maxRetriesConfigured ?? false : false
1014
+ }] : []));
1015
+ fork.__updateModel({ model: modelList });
1016
+ }
982
1017
  const hasStoredTools = storedConfig.tools != null;
983
1018
  const hasStoredMCPClients = storedConfig.mcpClients != null;
984
1019
  const hasStoredIntegrationTools = storedConfig.integrationTools != null;