@mastra/editor 0.15.7-alpha.1 → 0.16.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 +67 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -0
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +67 -8
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -733,6 +733,13 @@ function getProvidedAgentRecordFields(input) {
|
|
|
733
733
|
if (status !== void 0) recordFields.status = status;
|
|
734
734
|
return Object.keys(recordFields).length > 1 ? recordFields : null;
|
|
735
735
|
}
|
|
736
|
+
function isMemoryIdRef(ref) {
|
|
737
|
+
return !!ref && "type" in ref && ref.type === "id";
|
|
738
|
+
}
|
|
739
|
+
/** Tagged inline refs and legacy untagged configs both resolve to the serialized config. */
|
|
740
|
+
function unwrapInlineMemory(ref) {
|
|
741
|
+
return "type" in ref && ref.type === "inline" ? ref.config : ref;
|
|
742
|
+
}
|
|
736
743
|
var EditorAgentNamespace = class extends CrudEditorNamespace {
|
|
737
744
|
constructor(..._args) {
|
|
738
745
|
super(..._args);
|
|
@@ -1074,6 +1081,41 @@ var EditorAgentNamespace = class extends CrudEditorNamespace {
|
|
|
1074
1081
|
} : { ...variant.value };
|
|
1075
1082
|
return result;
|
|
1076
1083
|
}
|
|
1084
|
+
/**
|
|
1085
|
+
* Accumulate matching memory variants. Inline configs shallow-merge like
|
|
1086
|
+
* other object fields, but a registered-memory reference replaces whatever
|
|
1087
|
+
* has accumulated (and a later inline variant replaces a reference), so the
|
|
1088
|
+
* result is never a hybrid of a reference and inline config.
|
|
1089
|
+
*/
|
|
1090
|
+
accumulateMemoryVariants(variants, context) {
|
|
1091
|
+
let result;
|
|
1092
|
+
for (const variant of variants) {
|
|
1093
|
+
if (variant.rules && !evaluateRuleGroup(variant.rules, context)) continue;
|
|
1094
|
+
if (isMemoryIdRef(variant.value)) {
|
|
1095
|
+
result = variant.value;
|
|
1096
|
+
continue;
|
|
1097
|
+
}
|
|
1098
|
+
const inline = unwrapInlineMemory(variant.value);
|
|
1099
|
+
result = result && !isMemoryIdRef(result) ? {
|
|
1100
|
+
...unwrapInlineMemory(result),
|
|
1101
|
+
...inline
|
|
1102
|
+
} : { ...inline };
|
|
1103
|
+
}
|
|
1104
|
+
return result;
|
|
1105
|
+
}
|
|
1106
|
+
resolveConditionalMemory(variants) {
|
|
1107
|
+
const registeredMemory = /* @__PURE__ */ new Map();
|
|
1108
|
+
const usableVariants = variants.filter((variant) => {
|
|
1109
|
+
if (!isMemoryIdRef(variant.value)) return true;
|
|
1110
|
+
const registered = this.resolveRegisteredMemory(variant.value.memoryId);
|
|
1111
|
+
if (registered) registeredMemory.set(variant.value.memoryId, registered);
|
|
1112
|
+
return Boolean(registered);
|
|
1113
|
+
});
|
|
1114
|
+
return ({ requestContext }) => {
|
|
1115
|
+
const resolved = this.accumulateMemoryVariants(usableVariants, requestContext.toJSON());
|
|
1116
|
+
return isMemoryIdRef(resolved) ? registeredMemory.get(resolved.memoryId) : this.resolveStoredMemory(resolved);
|
|
1117
|
+
};
|
|
1118
|
+
}
|
|
1077
1119
|
async createAgentFromStoredConfig(storedAgent) {
|
|
1078
1120
|
if (!this.mastra) throw new Error("MastraEditor is not registered with a Mastra instance");
|
|
1079
1121
|
this.logger?.debug(`[createAgentFromStoredConfig] Creating agent from stored config "${storedAgent.id}"`);
|
|
@@ -1138,11 +1180,7 @@ var EditorAgentNamespace = class extends CrudEditorNamespace {
|
|
|
1138
1180
|
const resolved = Array.isArray(variants[0]?.value) ? this.accumulateArrayVariants(variants, ctx) : this.accumulateObjectVariants(variants, ctx);
|
|
1139
1181
|
return this.resolveStoredAgents(resolved);
|
|
1140
1182
|
} : this.resolveStoredAgents(storedAgent.agents);
|
|
1141
|
-
const memory = hasConditionalMemory ? (
|
|
1142
|
-
const ctx = requestContext.toJSON();
|
|
1143
|
-
const resolved = this.accumulateObjectVariants(storedAgent.memory, ctx);
|
|
1144
|
-
return this.resolveStoredMemory(resolved);
|
|
1145
|
-
} : this.resolveStoredMemory(storedAgent.memory);
|
|
1183
|
+
const memory = hasConditionalMemory ? this.resolveConditionalMemory(storedAgent.memory) : this.resolveStoredMemory(storedAgent.memory);
|
|
1146
1184
|
const scorers = hasConditionalScorers ? async ({ requestContext }) => {
|
|
1147
1185
|
const ctx = requestContext.toJSON();
|
|
1148
1186
|
const resolved = this.accumulateObjectVariants(storedAgent.scorers, ctx);
|
|
@@ -1485,8 +1523,8 @@ var EditorAgentNamespace = class extends CrudEditorNamespace {
|
|
|
1485
1523
|
}
|
|
1486
1524
|
return resolvedAgents;
|
|
1487
1525
|
}
|
|
1488
|
-
resolveStoredMemory(
|
|
1489
|
-
if (!
|
|
1526
|
+
resolveStoredMemory(memoryRef) {
|
|
1527
|
+
if (!memoryRef) {
|
|
1490
1528
|
this.logger?.debug(`[resolveStoredMemory] No memory config provided`);
|
|
1491
1529
|
return;
|
|
1492
1530
|
}
|
|
@@ -1494,6 +1532,22 @@ var EditorAgentNamespace = class extends CrudEditorNamespace {
|
|
|
1494
1532
|
this.logger?.warn("MastraEditor not registered with Mastra instance. Cannot instantiate memory.");
|
|
1495
1533
|
return;
|
|
1496
1534
|
}
|
|
1535
|
+
if (isMemoryIdRef(memoryRef)) return this.resolveRegisteredMemory(memoryRef.memoryId);
|
|
1536
|
+
return this.buildInlineMemory(unwrapInlineMemory(memoryRef));
|
|
1537
|
+
}
|
|
1538
|
+
/**
|
|
1539
|
+
* Look up a Memory instance registered on Mastra, by registry key first and
|
|
1540
|
+
* then by the instance's own id. A missing reference is not fatal: the agent
|
|
1541
|
+
* runs without memory and stored threads/messages are left untouched.
|
|
1542
|
+
*/
|
|
1543
|
+
resolveRegisteredMemory(memoryId) {
|
|
1544
|
+
const registry = this.mastra?.listMemory() ?? {};
|
|
1545
|
+
const memory = registry[memoryId] ?? Object.values(registry).find((m) => m.id === memoryId);
|
|
1546
|
+
if (!memory) this.logger?.warn(`Memory "${memoryId}" referenced in stored agent but not registered in Mastra. The agent will run without memory.`);
|
|
1547
|
+
return memory;
|
|
1548
|
+
}
|
|
1549
|
+
buildInlineMemory(memoryConfig) {
|
|
1550
|
+
if (!this.mastra) return void 0;
|
|
1497
1551
|
try {
|
|
1498
1552
|
let vector;
|
|
1499
1553
|
if (memoryConfig.vector) {
|
|
@@ -1604,7 +1658,12 @@ var EditorAgentNamespace = class extends CrudEditorNamespace {
|
|
|
1604
1658
|
const workflowKeys = Object.keys(workflows || {});
|
|
1605
1659
|
const agentsResolved = await agent.listAgents({ requestContext });
|
|
1606
1660
|
const agentKeys = Object.keys(agentsResolved || {});
|
|
1607
|
-
const
|
|
1661
|
+
const memory = await agent.getMemory({ requestContext });
|
|
1662
|
+
const registeredMemoryKey = memory ? Object.entries(this.mastra?.listMemory() ?? {}).find(([, registered]) => registered === memory)?.[0] : void 0;
|
|
1663
|
+
const memoryConfig = registeredMemoryKey ? {
|
|
1664
|
+
type: "id",
|
|
1665
|
+
memoryId: registeredMemoryKey
|
|
1666
|
+
} : memory?.getConfig();
|
|
1608
1667
|
let storedScorers;
|
|
1609
1668
|
const resolvedScorers = await agent.listScorers({ requestContext });
|
|
1610
1669
|
if (resolvedScorers && Object.keys(resolvedScorers).length > 0) {
|