@mastra/server 1.71.0-alpha.0 → 1.71.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/dist/{agent-versions-D3PJ6_ax.js → agent-versions-BA8ug-Iy.js} +3 -3
- package/dist/{agent-versions-D3PJ6_ax.js.map → agent-versions-BA8ug-Iy.js.map} +1 -1
- package/dist/{agent-versions-DzIbaLyi.cjs → agent-versions-BNqDvnn0.cjs} +3 -3
- package/dist/{agent-versions-DzIbaLyi.cjs.map → agent-versions-BNqDvnn0.cjs.map} +1 -1
- package/dist/{agents-DBtumkdm.cjs → agents-CqEbqSrC.cjs} +2 -2
- package/dist/{agents-DBtumkdm.cjs.map → agents-CqEbqSrC.cjs.map} +1 -1
- package/dist/{agents-BmJNsjp6.js → agents-Dstk6Isf.js} +2 -2
- package/dist/{agents-BmJNsjp6.js.map → agents-Dstk6Isf.js.map} +1 -1
- package/dist/{api-schema-manifest-CE2lXPKH.cjs → api-schema-manifest-CHTg1Kb-.cjs} +2 -2
- package/dist/{api-schema-manifest-CE2lXPKH.cjs.map → api-schema-manifest-CHTg1Kb-.cjs.map} +1 -1
- package/dist/{api-schema-manifest-D0_Q8UhK.js → api-schema-manifest-wibRCXX8.js} +2 -2
- package/dist/{api-schema-manifest-D0_Q8UhK.js.map → api-schema-manifest-wibRCXX8.js.map} +1 -1
- package/dist/{default-options-C9HZGjYi.cjs → default-options-C7tykjLq.cjs} +3 -1
- package/dist/default-options-C7tykjLq.cjs.map +1 -0
- package/dist/{default-options-C9JVjlto.js → default-options-oSlrqpuP.js} +3 -1
- package/dist/{default-options-C9JVjlto.js.map → default-options-oSlrqpuP.js.map} +1 -1
- package/dist/{dist-B3wkDytS.js → dist-D19QgTH4.js} +289 -259
- package/dist/dist-D19QgTH4.js.map +1 -0
- package/dist/{dist-pojdOe9l.cjs → dist-unhwBKm6.cjs} +289 -259
- package/dist/dist-unhwBKm6.cjs.map +1 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/{editor-builder-hB7crH1A.js → editor-builder-BaIipd1y.js} +2 -2
- package/dist/{editor-builder-hB7crH1A.js.map → editor-builder-BaIipd1y.js.map} +1 -1
- package/dist/{editor-builder-BLW-4Sbg.cjs → editor-builder-BbdoWaL_.cjs} +2 -2
- package/dist/{editor-builder-BLW-4Sbg.cjs.map → editor-builder-BbdoWaL_.cjs.map} +1 -1
- package/dist/{editor-builder-DVuvlXR2.cjs → editor-builder-ByrOB5f8.cjs} +2 -2
- package/dist/{editor-builder-DVuvlXR2.cjs.map → editor-builder-ByrOB5f8.cjs.map} +1 -1
- package/dist/{editor-builder-D46tZA82.js → editor-builder-DRn7G0Mr.js} +2 -2
- package/dist/{editor-builder-D46tZA82.js.map → editor-builder-DRn7G0Mr.js.map} +1 -1
- package/dist/{observability-new-endpoints-DJYL-Y5A.cjs → observability-new-endpoints-Ct0CSLE4.cjs} +48 -12
- package/dist/observability-new-endpoints-Ct0CSLE4.cjs.map +1 -0
- package/dist/{observability-new-endpoints-DQHOnzNX.js → observability-new-endpoints-DqS6dcR5.js} +44 -14
- package/dist/observability-new-endpoints-DqS6dcR5.js.map +1 -0
- package/dist/{routes-CeJQfjk5.js → routes-BRIkKqTl.js} +6 -5
- package/dist/routes-BRIkKqTl.js.map +1 -0
- package/dist/{routes-l-SxuNkD.cjs → routes-CLtivVqs.cjs} +6 -5
- package/dist/routes-CLtivVqs.cjs.map +1 -0
- package/dist/{scorer-versions-8-YMrgNx.js → scorer-versions-CscApWzu.js} +2 -2
- package/dist/{scorer-versions-8-YMrgNx.js.map → scorer-versions-CscApWzu.js.map} +1 -1
- package/dist/{scorer-versions-K5H3xinO.cjs → scorer-versions-nip3xSwF.cjs} +2 -2
- package/dist/{scorer-versions-K5H3xinO.cjs.map → scorer-versions-nip3xSwF.cjs.map} +1 -1
- package/dist/server/handlers/agent-builder.cjs +2 -2
- package/dist/server/handlers/agent-builder.js +2 -2
- package/dist/server/handlers/agent-versions.cjs +1 -1
- package/dist/server/handlers/agent-versions.d.ts +16 -0
- package/dist/server/handlers/agent-versions.d.ts.map +1 -1
- package/dist/server/handlers/agent-versions.js +1 -1
- package/dist/server/handlers/agents.cjs +2 -2
- package/dist/server/handlers/agents.d.ts +8 -0
- package/dist/server/handlers/agents.d.ts.map +1 -1
- package/dist/server/handlers/agents.js +2 -2
- package/dist/server/handlers/datasets.cjs +2 -1
- package/dist/server/handlers/datasets.cjs.map +1 -1
- package/dist/server/handlers/datasets.d.ts.map +1 -1
- package/dist/server/handlers/datasets.js +2 -1
- package/dist/server/handlers/datasets.js.map +1 -1
- package/dist/server/handlers/editor-builder.cjs +1 -1
- package/dist/server/handlers/editor-builder.js +1 -1
- package/dist/server/handlers/error.cjs +15 -0
- package/dist/server/handlers/error.cjs.map +1 -1
- package/dist/server/handlers/error.d.ts.map +1 -1
- package/dist/server/handlers/error.js +15 -0
- package/dist/server/handlers/error.js.map +1 -1
- package/dist/server/handlers/favorites-enrichment.cjs +1 -1
- package/dist/server/handlers/favorites-enrichment.js +1 -1
- package/dist/server/handlers/observability-new-endpoints.cjs +2 -1
- package/dist/server/handlers/observability-new-endpoints.d.ts +126 -0
- package/dist/server/handlers/observability-new-endpoints.d.ts.map +1 -1
- package/dist/server/handlers/observability-new-endpoints.js +2 -2
- package/dist/server/handlers/observability-shared.cjs +127 -0
- package/dist/server/handlers/observability-shared.cjs.map +1 -1
- package/dist/server/handlers/observability-shared.d.ts +49 -0
- package/dist/server/handlers/observability-shared.d.ts.map +1 -1
- package/dist/server/handlers/observability-shared.js +125 -1
- package/dist/server/handlers/observability-shared.js.map +1 -1
- package/dist/server/handlers/observability.cjs +3 -1
- package/dist/server/handlers/observability.cjs.map +1 -1
- package/dist/server/handlers/observability.js +3 -2
- package/dist/server/handlers/observability.js.map +1 -1
- package/dist/server/handlers/plans.cjs +1 -1
- package/dist/server/handlers/plans.js +1 -1
- package/dist/server/handlers/responses.d.ts +11 -11
- package/dist/server/handlers/scorer-versions.cjs +1 -1
- package/dist/server/handlers/scorer-versions.js +1 -1
- package/dist/server/handlers/stored-agent-favorites.cjs +2 -2
- package/dist/server/handlers/stored-agent-favorites.js +2 -2
- package/dist/server/handlers/stored-agents.cjs +2 -2
- package/dist/server/handlers/stored-agents.d.ts +16 -0
- package/dist/server/handlers/stored-agents.d.ts.map +1 -1
- package/dist/server/handlers/stored-agents.js +2 -2
- package/dist/server/handlers/stored-scorers.cjs +1 -1
- package/dist/server/handlers/stored-scorers.js +1 -1
- package/dist/server/handlers/stored-skill-favorites.cjs +1 -1
- package/dist/server/handlers/stored-skill-favorites.js +1 -1
- package/dist/server/handlers/stored-skills.cjs +1 -1
- package/dist/server/handlers/stored-skills.js +1 -1
- package/dist/server/handlers/system.cjs +3 -8
- package/dist/server/handlers/system.cjs.map +1 -1
- package/dist/server/handlers/system.d.ts +28 -0
- package/dist/server/handlers/system.d.ts.map +1 -1
- package/dist/server/handlers/system.js +4 -9
- package/dist/server/handlers/system.js.map +1 -1
- package/dist/server/handlers/tools.cjs +1 -1
- package/dist/server/handlers/tools.js +1 -1
- package/dist/server/handlers/workflow-builder.cjs +1 -1
- package/dist/server/handlers/workflow-builder.js +1 -1
- package/dist/server/handlers/workflows.cjs +1 -1
- package/dist/server/handlers/workflows.js +1 -1
- package/dist/server/schemas/agent-versions.d.ts +10 -0
- package/dist/server/schemas/agent-versions.d.ts.map +1 -1
- package/dist/server/schemas/agents.d.ts +3 -0
- package/dist/server/schemas/agents.d.ts.map +1 -1
- package/dist/server/schemas/default-options.d.ts +1 -0
- package/dist/server/schemas/default-options.d.ts.map +1 -1
- package/dist/server/schemas/index.cjs +9 -8
- package/dist/server/schemas/index.js +9 -9
- package/dist/server/schemas/stored-agents.d.ts +20 -0
- package/dist/server/schemas/stored-agents.d.ts.map +1 -1
- package/dist/server/schemas/system.d.ts +40 -0
- package/dist/server/schemas/system.d.ts.map +1 -1
- package/dist/server/server-adapter/index.cjs +1 -1
- package/dist/server/server-adapter/index.js +1 -1
- package/dist/server/server-adapter/routes/conversations.d.ts +3 -3
- package/dist/server/server-adapter/routes/observability.d.ts +62 -0
- package/dist/server/server-adapter/routes/observability.d.ts.map +1 -1
- package/dist/server/server-adapter/routes/system.d.ts +28 -0
- package/dist/server/server-adapter/routes/system.d.ts.map +1 -1
- package/dist/{stored-agents-50BO-sci.js → stored-agents-CIdYOdK0.js} +2 -2
- package/dist/{stored-agents-50BO-sci.js.map → stored-agents-CIdYOdK0.js.map} +1 -1
- package/dist/{stored-agents-BFT40viq.cjs → stored-agents-DTgigNRY.cjs} +2 -2
- package/dist/{stored-agents-BFT40viq.cjs.map → stored-agents-DTgigNRY.cjs.map} +1 -1
- package/dist/{stored-scorers-DBor7on7.cjs → stored-scorers-CziNmnC8.cjs} +2 -2
- package/dist/{stored-scorers-DBor7on7.cjs.map → stored-scorers-CziNmnC8.cjs.map} +1 -1
- package/dist/{stored-scorers-DLYUKdcQ.js → stored-scorers-DrkDvsU8.js} +2 -2
- package/dist/{stored-scorers-DLYUKdcQ.js.map → stored-scorers-DrkDvsU8.js.map} +1 -1
- package/dist/{system-DMAG21IT.js → system-BE5tDMHq.js} +24 -5
- package/dist/system-BE5tDMHq.js.map +1 -0
- package/dist/{system-D85p7-oz.cjs → system-BlGYb2fu.cjs} +29 -4
- package/dist/system-BlGYb2fu.cjs.map +1 -0
- package/dist/{workflow-builder-d_5P8lL1.cjs → workflow-builder-Cp9M5q2y.cjs} +3 -3
- package/dist/{workflow-builder-d_5P8lL1.cjs.map → workflow-builder-Cp9M5q2y.cjs.map} +1 -1
- package/dist/{workflow-builder-CO7uURIo.js → workflow-builder-JDAg-Yz7.js} +3 -3
- package/dist/{workflow-builder-CO7uURIo.js.map → workflow-builder-JDAg-Yz7.js.map} +1 -1
- package/package.json +9 -9
- package/dist/default-options-C9HZGjYi.cjs.map +0 -1
- package/dist/dist-B3wkDytS.js.map +0 -1
- package/dist/dist-pojdOe9l.cjs.map +0 -1
- package/dist/observability-new-endpoints-DJYL-Y5A.cjs.map +0 -1
- package/dist/observability-new-endpoints-DQHOnzNX.js.map +0 -1
- package/dist/routes-CeJQfjk5.js.map +0 -1
- package/dist/routes-l-SxuNkD.cjs.map +0 -1
- package/dist/system-D85p7-oz.cjs.map +0 -1
- package/dist/system-DMAG21IT.js.map +0 -1
|
@@ -4638,7 +4638,7 @@ function splitLines(text) {
|
|
|
4638
4638
|
return result;
|
|
4639
4639
|
}
|
|
4640
4640
|
//#endregion
|
|
4641
|
-
//#region ../memory/dist/src-
|
|
4641
|
+
//#region ../memory/dist/src-DsewkOlu.js
|
|
4642
4642
|
var __defProp$3 = Object.defineProperty;
|
|
4643
4643
|
var __exportAll = (all, no_symbols) => {
|
|
4644
4644
|
let target = {};
|
|
@@ -27649,6 +27649,285 @@ async function summarizeConversation(opts) {
|
|
|
27649
27649
|
usage: result.usage
|
|
27650
27650
|
};
|
|
27651
27651
|
}
|
|
27652
|
+
const UPDATE_WORKING_MEMORY_TOOL_NAME = "updateWorkingMemory";
|
|
27653
|
+
const SET_WORKING_MEMORY_TOOL_NAME = "setWorkingMemory";
|
|
27654
|
+
/**
|
|
27655
|
+
* Deep merges two objects, with special handling for null values (delete) and arrays (replace).
|
|
27656
|
+
* - Object properties are recursively merged
|
|
27657
|
+
* - null values in the update will delete the corresponding property, even when the property
|
|
27658
|
+
* or its parent object does not exist yet (so padded nulls never get stored literally)
|
|
27659
|
+
* - Arrays are replaced entirely (not merged element-by-element)
|
|
27660
|
+
* - Primitive values are overwritten
|
|
27661
|
+
* - The returned object is always newly constructed and never aliases `update`
|
|
27662
|
+
*/
|
|
27663
|
+
function deepMergeWorkingMemory(existing, update) {
|
|
27664
|
+
if (!update || typeof update !== "object" || Object.keys(update).length === 0) return existing && typeof existing === "object" ? { ...existing } : {};
|
|
27665
|
+
const result = { ...existing && typeof existing === "object" && !Array.isArray(existing) ? existing : {} };
|
|
27666
|
+
for (const key of Object.keys(update)) {
|
|
27667
|
+
const updateValue = update[key];
|
|
27668
|
+
const existingValue = result[key];
|
|
27669
|
+
if (updateValue === void 0) continue;
|
|
27670
|
+
if (updateValue === null) delete result[key];
|
|
27671
|
+
else if (Array.isArray(updateValue)) result[key] = updateValue;
|
|
27672
|
+
else if (typeof updateValue === "object") result[key] = deepMergeWorkingMemory(existingValue && typeof existingValue === "object" && !Array.isArray(existingValue) ? existingValue : void 0, updateValue);
|
|
27673
|
+
else result[key] = updateValue;
|
|
27674
|
+
}
|
|
27675
|
+
return result;
|
|
27676
|
+
}
|
|
27677
|
+
/** `.nullable()` wraps a schema as `anyOf: [schema, { type: 'null' }]`; unwrap it so its declared fields are visible. */
|
|
27678
|
+
function resolveNullableBranch(value, schema) {
|
|
27679
|
+
const branches = schema.anyOf ?? schema.oneOf;
|
|
27680
|
+
if (!Array.isArray(branches)) return schema;
|
|
27681
|
+
const kind = Array.isArray(value) ? "array" : "object";
|
|
27682
|
+
const matching = branches.filter((branch) => branch.type === kind);
|
|
27683
|
+
return matching.length === 1 ? matching[0] : schema;
|
|
27684
|
+
}
|
|
27685
|
+
function stripNullsFromOptional(value, rawSchema) {
|
|
27686
|
+
const schema = resolveNullableBranch(value, rawSchema);
|
|
27687
|
+
if (Array.isArray(value)) {
|
|
27688
|
+
const itemSchema = schema.items ?? {};
|
|
27689
|
+
return value.map((item) => stripNullsFromOptional(item, itemSchema));
|
|
27690
|
+
}
|
|
27691
|
+
if (typeof value === "object" && value !== null) {
|
|
27692
|
+
const properties = schema.properties ?? {};
|
|
27693
|
+
const required = schema.required ?? [];
|
|
27694
|
+
const result = {};
|
|
27695
|
+
for (const [key, propertyValue] of Object.entries(value)) {
|
|
27696
|
+
if (propertyValue === null && Object.hasOwn(properties, key) && !required.includes(key)) continue;
|
|
27697
|
+
result[key] = stripNullsFromOptional(propertyValue, properties[key] ?? {});
|
|
27698
|
+
}
|
|
27699
|
+
return result;
|
|
27700
|
+
}
|
|
27701
|
+
return value;
|
|
27702
|
+
}
|
|
27703
|
+
const updateWorkingMemoryTool = (memoryConfig) => {
|
|
27704
|
+
const schema = memoryConfig?.workingMemory?.schema;
|
|
27705
|
+
let inputSchema = {
|
|
27706
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
27707
|
+
type: "object",
|
|
27708
|
+
properties: { memory: {
|
|
27709
|
+
type: "string",
|
|
27710
|
+
description: `The Markdown formatted working memory content to store. This MUST be a string. Never pass an object.`
|
|
27711
|
+
} },
|
|
27712
|
+
required: ["memory"]
|
|
27713
|
+
};
|
|
27714
|
+
if (schema) {
|
|
27715
|
+
const standardSchema = (0, _mastra_core_schema.isStandardSchemaWithJSON)(schema) ? schema : (0, _mastra_core_schema.toStandardSchema)(schema);
|
|
27716
|
+
const jsonSchema = require_schema_e0VHpMt0.standardSchemaToJSONSchema(standardSchema, { io: "input" });
|
|
27717
|
+
delete jsonSchema.$schema;
|
|
27718
|
+
const wrappedJsonSchema = {
|
|
27719
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
27720
|
+
type: "object",
|
|
27721
|
+
description: "The JSON formatted working memory content to store.",
|
|
27722
|
+
properties: { memory: jsonSchema },
|
|
27723
|
+
required: ["memory"]
|
|
27724
|
+
};
|
|
27725
|
+
const validateMemory = (memoryValue) => standardSchema["~standard"].validate(memoryValue);
|
|
27726
|
+
const toWrappedResult = (result) => "issues" in result && result.issues ? result : { value: { memory: result.value } };
|
|
27727
|
+
inputSchema = { "~standard": {
|
|
27728
|
+
version: 1,
|
|
27729
|
+
vendor: "mastra",
|
|
27730
|
+
validate: (value) => {
|
|
27731
|
+
const memoryValue = stripNullsFromOptional(!!value && typeof value === "object" && !Array.isArray(value) && "memory" in value ? value.memory : value, jsonSchema);
|
|
27732
|
+
const result = validateMemory(memoryValue);
|
|
27733
|
+
return result instanceof Promise ? result.then(toWrappedResult) : toWrappedResult(result);
|
|
27734
|
+
},
|
|
27735
|
+
jsonSchema: {
|
|
27736
|
+
input: () => wrappedJsonSchema,
|
|
27737
|
+
output: () => wrappedJsonSchema
|
|
27738
|
+
}
|
|
27739
|
+
} };
|
|
27740
|
+
}
|
|
27741
|
+
const usesMergeSemantics = Boolean(schema);
|
|
27742
|
+
const useStateSignals = memoryConfig?.workingMemory?.useStateSignals === true;
|
|
27743
|
+
const stateSignalsPreamble = `The current working memory state is delivered to you each turn by the system inside a <working-memory>...</working-memory> block. That block is system-emitted state, NOT something the user typed — never describe it as the user sharing it. Read from it directly when answering. Only call this tool when the user provides genuinely NEW or CHANGED facts that should be persisted; do NOT call it to re-save unchanged data.`;
|
|
27744
|
+
return (0, _mastra_core_tools.createTool)({
|
|
27745
|
+
id: "update-working-memory",
|
|
27746
|
+
description: schema ? useStateSignals ? `${stateSignalsPreamble} Data is merged with existing memory — only include fields you want to add or update.` : `Update the working memory with new information. Data is merged with existing memory - only include fields you want to add or update. To preserve existing data, omit the field entirely. Arrays are replaced entirely when provided, so pass the complete array or omit it to keep the existing values.` : useStateSignals ? `${stateSignalsPreamble} Pass the full updated Markdown blob as a string in the memory field.` : `Update the working memory with new information. Any data not included will be overwritten. Always pass data as string to the memory field. Never pass an object.`,
|
|
27747
|
+
inputSchema,
|
|
27748
|
+
...usesMergeSemantics ? { strict: false } : {},
|
|
27749
|
+
execute: async (inputData, context) => {
|
|
27750
|
+
const workingMemoryInput = inputData;
|
|
27751
|
+
const threadId = context?.agent?.threadId;
|
|
27752
|
+
const resourceId = context?.agent?.resourceId;
|
|
27753
|
+
const memory = context?.memory;
|
|
27754
|
+
if (!memory) throw new Error("Memory instance is required for working memory updates");
|
|
27755
|
+
const scope = memoryConfig?.workingMemory?.scope || "resource";
|
|
27756
|
+
if (scope === "thread" && !threadId) throw new Error("Thread ID is required for thread-scoped working memory updates");
|
|
27757
|
+
if (scope === "resource" && !resourceId) throw new Error("Resource ID is required for resource-scoped working memory updates");
|
|
27758
|
+
if (threadId) {
|
|
27759
|
+
let thread = await memory.getThreadById({ threadId });
|
|
27760
|
+
if (!thread) thread = await memory.createThread({
|
|
27761
|
+
threadId,
|
|
27762
|
+
resourceId,
|
|
27763
|
+
memoryConfig
|
|
27764
|
+
});
|
|
27765
|
+
if (thread.resourceId && resourceId && thread.resourceId !== resourceId) throw new Error(`Thread with id ${threadId} resourceId does not match the current resourceId ${resourceId}`);
|
|
27766
|
+
}
|
|
27767
|
+
let workingMemory;
|
|
27768
|
+
if (usesMergeSemantics) {
|
|
27769
|
+
const existingRaw = await memory.getWorkingMemory({
|
|
27770
|
+
threadId,
|
|
27771
|
+
resourceId,
|
|
27772
|
+
memoryConfig
|
|
27773
|
+
});
|
|
27774
|
+
let existingData = null;
|
|
27775
|
+
if (existingRaw) try {
|
|
27776
|
+
existingData = typeof existingRaw === "string" ? JSON.parse(existingRaw) : existingRaw;
|
|
27777
|
+
} catch {
|
|
27778
|
+
existingData = null;
|
|
27779
|
+
}
|
|
27780
|
+
const memoryInput = workingMemoryInput.memory;
|
|
27781
|
+
if (memoryInput === void 0 || memoryInput === null) return {
|
|
27782
|
+
success: true,
|
|
27783
|
+
message: "No memory data provided, existing memory unchanged."
|
|
27784
|
+
};
|
|
27785
|
+
let newData;
|
|
27786
|
+
if (typeof memoryInput === "string") try {
|
|
27787
|
+
newData = JSON.parse(memoryInput);
|
|
27788
|
+
} catch (parseError) {
|
|
27789
|
+
const errorMessage = parseError instanceof Error ? parseError.message : String(parseError);
|
|
27790
|
+
throw new Error(`Failed to parse working memory input as JSON: ${errorMessage}. Raw input: ${memoryInput.length > 500 ? memoryInput.slice(0, 500) + "..." : memoryInput}`);
|
|
27791
|
+
}
|
|
27792
|
+
else newData = memoryInput;
|
|
27793
|
+
const mergedData = deepMergeWorkingMemory(existingData, newData);
|
|
27794
|
+
workingMemory = JSON.stringify(mergedData);
|
|
27795
|
+
} else {
|
|
27796
|
+
const memoryInput = workingMemoryInput.memory;
|
|
27797
|
+
workingMemory = typeof memoryInput === "string" ? memoryInput : JSON.stringify(memoryInput);
|
|
27798
|
+
const existingRaw = await memory.getWorkingMemory({
|
|
27799
|
+
threadId,
|
|
27800
|
+
resourceId,
|
|
27801
|
+
memoryConfig
|
|
27802
|
+
});
|
|
27803
|
+
if (existingRaw) {
|
|
27804
|
+
const template = await memory.getWorkingMemoryTemplate({ memoryConfig });
|
|
27805
|
+
if (template?.content) {
|
|
27806
|
+
const normalizedNew = workingMemory.replace(/\s+/g, " ").trim();
|
|
27807
|
+
const normalizedTemplate = template.content.replace(/\s+/g, " ").trim();
|
|
27808
|
+
const normalizedExisting = existingRaw.replace(/\s+/g, " ").trim();
|
|
27809
|
+
if (normalizedNew === normalizedTemplate && normalizedExisting !== normalizedTemplate) return {
|
|
27810
|
+
success: false,
|
|
27811
|
+
message: "Attempted to replace existing working memory with empty template. Update skipped to prevent data loss."
|
|
27812
|
+
};
|
|
27813
|
+
}
|
|
27814
|
+
}
|
|
27815
|
+
}
|
|
27816
|
+
await memory.updateWorkingMemory({
|
|
27817
|
+
threadId,
|
|
27818
|
+
resourceId,
|
|
27819
|
+
workingMemory,
|
|
27820
|
+
memoryConfig
|
|
27821
|
+
});
|
|
27822
|
+
return { success: true };
|
|
27823
|
+
}
|
|
27824
|
+
});
|
|
27825
|
+
};
|
|
27826
|
+
const __experimental_updateWorkingMemoryToolVNext = (config) => {
|
|
27827
|
+
return (0, _mastra_core_tools.createTool)({
|
|
27828
|
+
id: "update-working-memory",
|
|
27829
|
+
description: "Update the working memory with new information.",
|
|
27830
|
+
inputSchema: {
|
|
27831
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
27832
|
+
type: "object",
|
|
27833
|
+
properties: {
|
|
27834
|
+
newMemory: {
|
|
27835
|
+
type: "string",
|
|
27836
|
+
description: `The ${config.workingMemory?.schema ? "JSON" : "Markdown"} formatted working memory content to store`
|
|
27837
|
+
},
|
|
27838
|
+
searchString: {
|
|
27839
|
+
type: "string",
|
|
27840
|
+
description: "The working memory string to find. Will be replaced with the newMemory string. If this is omitted or doesn't exist, the newMemory string will be appended to the end of your working memory. Replacing single lines at a time is encouraged for greater accuracy. If updateReason is not 'append-new-memory', this search string must be provided or the tool call will be rejected."
|
|
27841
|
+
},
|
|
27842
|
+
updateReason: {
|
|
27843
|
+
type: "string",
|
|
27844
|
+
enum: [
|
|
27845
|
+
"append-new-memory",
|
|
27846
|
+
"clarify-existing-memory",
|
|
27847
|
+
"replace-irrelevant-memory"
|
|
27848
|
+
],
|
|
27849
|
+
description: "The reason you're updating working memory. Passing any value other than 'append-new-memory' requires a searchString to be provided. Defaults to append-new-memory"
|
|
27850
|
+
}
|
|
27851
|
+
}
|
|
27852
|
+
},
|
|
27853
|
+
execute: async (inputData, context) => {
|
|
27854
|
+
const workingMemoryInput = inputData;
|
|
27855
|
+
const threadId = context?.agent?.threadId;
|
|
27856
|
+
const resourceId = context?.agent?.resourceId;
|
|
27857
|
+
const memory = context?.memory;
|
|
27858
|
+
if (!memory) throw new Error("Memory instance is required for working memory updates");
|
|
27859
|
+
const scope = config.workingMemory?.scope || "resource";
|
|
27860
|
+
if (scope === "thread" && !threadId) throw new Error("Thread ID is required for thread-scoped working memory updates");
|
|
27861
|
+
if (scope === "resource" && !resourceId) throw new Error("Resource ID is required for resource-scoped working memory updates");
|
|
27862
|
+
if (threadId) {
|
|
27863
|
+
let thread = await memory.getThreadById({ threadId });
|
|
27864
|
+
if (!thread) thread = await memory.createThread({
|
|
27865
|
+
threadId,
|
|
27866
|
+
resourceId,
|
|
27867
|
+
memoryConfig: config
|
|
27868
|
+
});
|
|
27869
|
+
if (thread.resourceId && resourceId && thread.resourceId !== resourceId) throw new Error(`Thread with id ${threadId} resourceId does not match the current resourceId ${resourceId}`);
|
|
27870
|
+
}
|
|
27871
|
+
const workingMemory = workingMemoryInput.newMemory || "";
|
|
27872
|
+
if (!workingMemoryInput.updateReason) workingMemoryInput.updateReason = `append-new-memory`;
|
|
27873
|
+
if (workingMemoryInput.searchString && config.workingMemory?.scope === `resource` && workingMemoryInput.updateReason === `replace-irrelevant-memory`) workingMemoryInput.searchString = void 0;
|
|
27874
|
+
if (workingMemoryInput.updateReason === `append-new-memory` && workingMemoryInput.searchString) workingMemoryInput.searchString = void 0;
|
|
27875
|
+
if (workingMemoryInput.updateReason !== `append-new-memory` && !workingMemoryInput.searchString) return {
|
|
27876
|
+
success: false,
|
|
27877
|
+
reason: `updateReason was ${workingMemoryInput.updateReason} but no searchString was provided. Unable to replace undefined with "${workingMemoryInput.newMemory}"`
|
|
27878
|
+
};
|
|
27879
|
+
const result = await memory.__experimental_updateWorkingMemoryVNext({
|
|
27880
|
+
threadId,
|
|
27881
|
+
resourceId,
|
|
27882
|
+
workingMemory,
|
|
27883
|
+
searchString: workingMemoryInput.searchString,
|
|
27884
|
+
memoryConfig: config
|
|
27885
|
+
});
|
|
27886
|
+
if (result) return result;
|
|
27887
|
+
return { success: true };
|
|
27888
|
+
}
|
|
27889
|
+
});
|
|
27890
|
+
};
|
|
27891
|
+
/**
|
|
27892
|
+
* Returns the working-memory tool plus the wire name it should be registered under.
|
|
27893
|
+
*
|
|
27894
|
+
* - Default delivery (`useStateSignals: false`): wire name `updateWorkingMemory`,
|
|
27895
|
+
* identical shape to today.
|
|
27896
|
+
* - State-signals delivery (`useStateSignals: true`): wire name `setWorkingMemory`.
|
|
27897
|
+
* The rename keeps legacy strip filters (which match the literal `updateWorkingMemory`)
|
|
27898
|
+
* from removing tool-call parts so they persist as a normal audit trail. Any
|
|
27899
|
+
* future state-signal-specific tweaks to the tool (e.g. delta-aware results,
|
|
27900
|
+
* scoped descriptions) belong here.
|
|
27901
|
+
*
|
|
27902
|
+
* The VNext vs default tool body decision is left to the caller because Memory
|
|
27903
|
+
* owns the `isVNextWorkingMemoryConfig` check; pass `vNext: true` to use the
|
|
27904
|
+
* search-and-replace shape.
|
|
27905
|
+
*/
|
|
27906
|
+
function createWorkingMemoryTool(config, options = {}) {
|
|
27907
|
+
const useStateSignals = config.workingMemory?.useStateSignals === true;
|
|
27908
|
+
const tool = options.vNext ? __experimental_updateWorkingMemoryToolVNext(config) : updateWorkingMemoryTool(config);
|
|
27909
|
+
return {
|
|
27910
|
+
name: useStateSignals ? SET_WORKING_MEMORY_TOOL_NAME : UPDATE_WORKING_MEMORY_TOOL_NAME,
|
|
27911
|
+
tool
|
|
27912
|
+
};
|
|
27913
|
+
}
|
|
27914
|
+
/**
|
|
27915
|
+
* The structured-output schema for this extractor stays generic because every structured extractor shares one
|
|
27916
|
+
* response object: a strict working-memory schema there would make one invalid document fail every sibling
|
|
27917
|
+
* extractor. The configured schema is enforced here instead, with its own validator, before anything is stored.
|
|
27918
|
+
* Like the working memory tool, nulls in optional fields are treated as "not provided" rather than as invalid.
|
|
27919
|
+
*/
|
|
27920
|
+
async function validateAgainstConfiguredSchema(schema, value) {
|
|
27921
|
+
const standardSchema = (0, _mastra_core_schema.toStandardSchema)(schema);
|
|
27922
|
+
const jsonSchema = require_schema_e0VHpMt0.standardSchemaToJSONSchema(standardSchema, { io: "input" });
|
|
27923
|
+
const result = await standardSchema["~standard"].validate(stripNullsFromOptional(value, jsonSchema));
|
|
27924
|
+
if (!result.issues) return result.value;
|
|
27925
|
+
const details = result.issues.map((issue) => {
|
|
27926
|
+
const path$7 = issue.path?.map((segment) => String(typeof segment === "object" ? segment.key : segment)).join(".");
|
|
27927
|
+
return path$7 ? `${path$7}: ${issue.message}` : issue.message;
|
|
27928
|
+
}).join("; ");
|
|
27929
|
+
throw new Error(`Working memory update does not match the configured schema, so it was not saved: ${details}`);
|
|
27930
|
+
}
|
|
27652
27931
|
async function getWorkingMemoryDetails(context) {
|
|
27653
27932
|
const memory = context.memory;
|
|
27654
27933
|
const memoryConfig = (0, _mastra_core_memory.parseMemoryRequestContext)(context.requestContext)?.memoryConfig;
|
|
@@ -27693,9 +27972,13 @@ var WorkingMemoryExtractor = class extends Extractor {
|
|
|
27693
27972
|
},
|
|
27694
27973
|
onExtracted: async ({ current, memory, threadId, resourceId, requestContext }) => {
|
|
27695
27974
|
const memoryConfig = (0, _mastra_core_memory.parseMemoryRequestContext)(requestContext)?.memoryConfig;
|
|
27696
|
-
const
|
|
27697
|
-
|
|
27698
|
-
|
|
27975
|
+
const configuredSchema = memory.getMergedThreadConfig(memoryConfig ?? {}).workingMemory?.schema;
|
|
27976
|
+
let document = current;
|
|
27977
|
+
if (configuredSchema) {
|
|
27978
|
+
if (current === null) return;
|
|
27979
|
+
document = await validateAgainstConfiguredSchema(configuredSchema, current);
|
|
27980
|
+
}
|
|
27981
|
+
const workingMemory = typeof document === "string" ? document : JSON.stringify(document) ?? "";
|
|
27699
27982
|
if (!workingMemory.trim()) return;
|
|
27700
27983
|
await memory.updateWorkingMemory({
|
|
27701
27984
|
threadId,
|
|
@@ -27703,7 +27986,7 @@ var WorkingMemoryExtractor = class extends Extractor {
|
|
|
27703
27986
|
workingMemory,
|
|
27704
27987
|
memoryConfig
|
|
27705
27988
|
});
|
|
27706
|
-
return
|
|
27989
|
+
return document;
|
|
27707
27990
|
}
|
|
27708
27991
|
});
|
|
27709
27992
|
}
|
|
@@ -28651,259 +28934,6 @@ const recallTool = (_memoryConfig, options) => {
|
|
|
28651
28934
|
}
|
|
28652
28935
|
});
|
|
28653
28936
|
};
|
|
28654
|
-
const UPDATE_WORKING_MEMORY_TOOL_NAME = "updateWorkingMemory";
|
|
28655
|
-
const SET_WORKING_MEMORY_TOOL_NAME = "setWorkingMemory";
|
|
28656
|
-
/**
|
|
28657
|
-
* Deep merges two objects, with special handling for null values (delete) and arrays (replace).
|
|
28658
|
-
* - Object properties are recursively merged
|
|
28659
|
-
* - null values in the update will delete the corresponding property, even when the property
|
|
28660
|
-
* or its parent object does not exist yet (so padded nulls never get stored literally)
|
|
28661
|
-
* - Arrays are replaced entirely (not merged element-by-element)
|
|
28662
|
-
* - Primitive values are overwritten
|
|
28663
|
-
* - The returned object is always newly constructed and never aliases `update`
|
|
28664
|
-
*/
|
|
28665
|
-
function deepMergeWorkingMemory(existing, update) {
|
|
28666
|
-
if (!update || typeof update !== "object" || Object.keys(update).length === 0) return existing && typeof existing === "object" ? { ...existing } : {};
|
|
28667
|
-
const result = { ...existing && typeof existing === "object" && !Array.isArray(existing) ? existing : {} };
|
|
28668
|
-
for (const key of Object.keys(update)) {
|
|
28669
|
-
const updateValue = update[key];
|
|
28670
|
-
const existingValue = result[key];
|
|
28671
|
-
if (updateValue === void 0) continue;
|
|
28672
|
-
if (updateValue === null) delete result[key];
|
|
28673
|
-
else if (Array.isArray(updateValue)) result[key] = updateValue;
|
|
28674
|
-
else if (typeof updateValue === "object") result[key] = deepMergeWorkingMemory(existingValue && typeof existingValue === "object" && !Array.isArray(existingValue) ? existingValue : void 0, updateValue);
|
|
28675
|
-
else result[key] = updateValue;
|
|
28676
|
-
}
|
|
28677
|
-
return result;
|
|
28678
|
-
}
|
|
28679
|
-
function stripNullsFromOptional(value, schema) {
|
|
28680
|
-
if (Array.isArray(value)) {
|
|
28681
|
-
const itemSchema = schema.items ?? {};
|
|
28682
|
-
return value.map((item) => stripNullsFromOptional(item, itemSchema));
|
|
28683
|
-
}
|
|
28684
|
-
if (typeof value === "object" && value !== null) {
|
|
28685
|
-
const properties = schema.properties ?? {};
|
|
28686
|
-
const required = schema.required ?? [];
|
|
28687
|
-
const result = {};
|
|
28688
|
-
for (const [key, propertyValue] of Object.entries(value)) {
|
|
28689
|
-
if (propertyValue === null && !required.includes(key)) continue;
|
|
28690
|
-
result[key] = stripNullsFromOptional(propertyValue, properties[key] ?? {});
|
|
28691
|
-
}
|
|
28692
|
-
return result;
|
|
28693
|
-
}
|
|
28694
|
-
return value;
|
|
28695
|
-
}
|
|
28696
|
-
const updateWorkingMemoryTool = (memoryConfig) => {
|
|
28697
|
-
const schema = memoryConfig?.workingMemory?.schema;
|
|
28698
|
-
let inputSchema = {
|
|
28699
|
-
$schema: "http://json-schema.org/draft-07/schema#",
|
|
28700
|
-
type: "object",
|
|
28701
|
-
properties: { memory: {
|
|
28702
|
-
type: "string",
|
|
28703
|
-
description: `The Markdown formatted working memory content to store. This MUST be a string. Never pass an object.`
|
|
28704
|
-
} },
|
|
28705
|
-
required: ["memory"]
|
|
28706
|
-
};
|
|
28707
|
-
if (schema) {
|
|
28708
|
-
const standardSchema = (0, _mastra_core_schema.isStandardSchemaWithJSON)(schema) ? schema : (0, _mastra_core_schema.toStandardSchema)(schema);
|
|
28709
|
-
const jsonSchema = require_schema_e0VHpMt0.standardSchemaToJSONSchema(standardSchema, { io: "input" });
|
|
28710
|
-
delete jsonSchema.$schema;
|
|
28711
|
-
const wrappedJsonSchema = {
|
|
28712
|
-
$schema: "http://json-schema.org/draft-07/schema#",
|
|
28713
|
-
type: "object",
|
|
28714
|
-
description: "The JSON formatted working memory content to store.",
|
|
28715
|
-
properties: { memory: jsonSchema },
|
|
28716
|
-
required: ["memory"]
|
|
28717
|
-
};
|
|
28718
|
-
const validateMemory = (memoryValue) => standardSchema["~standard"].validate(memoryValue);
|
|
28719
|
-
const toWrappedResult = (result) => "issues" in result && result.issues ? result : { value: { memory: result.value } };
|
|
28720
|
-
inputSchema = { "~standard": {
|
|
28721
|
-
version: 1,
|
|
28722
|
-
vendor: "mastra",
|
|
28723
|
-
validate: (value) => {
|
|
28724
|
-
const memoryValue = stripNullsFromOptional(!!value && typeof value === "object" && !Array.isArray(value) && "memory" in value ? value.memory : value, jsonSchema);
|
|
28725
|
-
const result = validateMemory(memoryValue);
|
|
28726
|
-
return result instanceof Promise ? result.then(toWrappedResult) : toWrappedResult(result);
|
|
28727
|
-
},
|
|
28728
|
-
jsonSchema: {
|
|
28729
|
-
input: () => wrappedJsonSchema,
|
|
28730
|
-
output: () => wrappedJsonSchema
|
|
28731
|
-
}
|
|
28732
|
-
} };
|
|
28733
|
-
}
|
|
28734
|
-
const usesMergeSemantics = Boolean(schema);
|
|
28735
|
-
const useStateSignals = memoryConfig?.workingMemory?.useStateSignals === true;
|
|
28736
|
-
const stateSignalsPreamble = `The current working memory state is delivered to you each turn by the system inside a <working-memory>...</working-memory> block. That block is system-emitted state, NOT something the user typed — never describe it as the user sharing it. Read from it directly when answering. Only call this tool when the user provides genuinely NEW or CHANGED facts that should be persisted; do NOT call it to re-save unchanged data.`;
|
|
28737
|
-
return (0, _mastra_core_tools.createTool)({
|
|
28738
|
-
id: "update-working-memory",
|
|
28739
|
-
description: schema ? useStateSignals ? `${stateSignalsPreamble} Data is merged with existing memory — only include fields you want to add or update.` : `Update the working memory with new information. Data is merged with existing memory - only include fields you want to add or update. To preserve existing data, omit the field entirely. Arrays are replaced entirely when provided, so pass the complete array or omit it to keep the existing values.` : useStateSignals ? `${stateSignalsPreamble} Pass the full updated Markdown blob as a string in the memory field.` : `Update the working memory with new information. Any data not included will be overwritten. Always pass data as string to the memory field. Never pass an object.`,
|
|
28740
|
-
inputSchema,
|
|
28741
|
-
...usesMergeSemantics ? { strict: false } : {},
|
|
28742
|
-
execute: async (inputData, context) => {
|
|
28743
|
-
const workingMemoryInput = inputData;
|
|
28744
|
-
const threadId = context?.agent?.threadId;
|
|
28745
|
-
const resourceId = context?.agent?.resourceId;
|
|
28746
|
-
const memory = context?.memory;
|
|
28747
|
-
if (!memory) throw new Error("Memory instance is required for working memory updates");
|
|
28748
|
-
const scope = memoryConfig?.workingMemory?.scope || "resource";
|
|
28749
|
-
if (scope === "thread" && !threadId) throw new Error("Thread ID is required for thread-scoped working memory updates");
|
|
28750
|
-
if (scope === "resource" && !resourceId) throw new Error("Resource ID is required for resource-scoped working memory updates");
|
|
28751
|
-
if (threadId) {
|
|
28752
|
-
let thread = await memory.getThreadById({ threadId });
|
|
28753
|
-
if (!thread) thread = await memory.createThread({
|
|
28754
|
-
threadId,
|
|
28755
|
-
resourceId,
|
|
28756
|
-
memoryConfig
|
|
28757
|
-
});
|
|
28758
|
-
if (thread.resourceId && resourceId && thread.resourceId !== resourceId) throw new Error(`Thread with id ${threadId} resourceId does not match the current resourceId ${resourceId}`);
|
|
28759
|
-
}
|
|
28760
|
-
let workingMemory;
|
|
28761
|
-
if (usesMergeSemantics) {
|
|
28762
|
-
const existingRaw = await memory.getWorkingMemory({
|
|
28763
|
-
threadId,
|
|
28764
|
-
resourceId,
|
|
28765
|
-
memoryConfig
|
|
28766
|
-
});
|
|
28767
|
-
let existingData = null;
|
|
28768
|
-
if (existingRaw) try {
|
|
28769
|
-
existingData = typeof existingRaw === "string" ? JSON.parse(existingRaw) : existingRaw;
|
|
28770
|
-
} catch {
|
|
28771
|
-
existingData = null;
|
|
28772
|
-
}
|
|
28773
|
-
const memoryInput = workingMemoryInput.memory;
|
|
28774
|
-
if (memoryInput === void 0 || memoryInput === null) return {
|
|
28775
|
-
success: true,
|
|
28776
|
-
message: "No memory data provided, existing memory unchanged."
|
|
28777
|
-
};
|
|
28778
|
-
let newData;
|
|
28779
|
-
if (typeof memoryInput === "string") try {
|
|
28780
|
-
newData = JSON.parse(memoryInput);
|
|
28781
|
-
} catch (parseError) {
|
|
28782
|
-
const errorMessage = parseError instanceof Error ? parseError.message : String(parseError);
|
|
28783
|
-
throw new Error(`Failed to parse working memory input as JSON: ${errorMessage}. Raw input: ${memoryInput.length > 500 ? memoryInput.slice(0, 500) + "..." : memoryInput}`);
|
|
28784
|
-
}
|
|
28785
|
-
else newData = memoryInput;
|
|
28786
|
-
const mergedData = deepMergeWorkingMemory(existingData, newData);
|
|
28787
|
-
workingMemory = JSON.stringify(mergedData);
|
|
28788
|
-
} else {
|
|
28789
|
-
const memoryInput = workingMemoryInput.memory;
|
|
28790
|
-
workingMemory = typeof memoryInput === "string" ? memoryInput : JSON.stringify(memoryInput);
|
|
28791
|
-
const existingRaw = await memory.getWorkingMemory({
|
|
28792
|
-
threadId,
|
|
28793
|
-
resourceId,
|
|
28794
|
-
memoryConfig
|
|
28795
|
-
});
|
|
28796
|
-
if (existingRaw) {
|
|
28797
|
-
const template = await memory.getWorkingMemoryTemplate({ memoryConfig });
|
|
28798
|
-
if (template?.content) {
|
|
28799
|
-
const normalizedNew = workingMemory.replace(/\s+/g, " ").trim();
|
|
28800
|
-
const normalizedTemplate = template.content.replace(/\s+/g, " ").trim();
|
|
28801
|
-
const normalizedExisting = existingRaw.replace(/\s+/g, " ").trim();
|
|
28802
|
-
if (normalizedNew === normalizedTemplate && normalizedExisting !== normalizedTemplate) return {
|
|
28803
|
-
success: false,
|
|
28804
|
-
message: "Attempted to replace existing working memory with empty template. Update skipped to prevent data loss."
|
|
28805
|
-
};
|
|
28806
|
-
}
|
|
28807
|
-
}
|
|
28808
|
-
}
|
|
28809
|
-
await memory.updateWorkingMemory({
|
|
28810
|
-
threadId,
|
|
28811
|
-
resourceId,
|
|
28812
|
-
workingMemory,
|
|
28813
|
-
memoryConfig
|
|
28814
|
-
});
|
|
28815
|
-
return { success: true };
|
|
28816
|
-
}
|
|
28817
|
-
});
|
|
28818
|
-
};
|
|
28819
|
-
const __experimental_updateWorkingMemoryToolVNext = (config) => {
|
|
28820
|
-
return (0, _mastra_core_tools.createTool)({
|
|
28821
|
-
id: "update-working-memory",
|
|
28822
|
-
description: "Update the working memory with new information.",
|
|
28823
|
-
inputSchema: {
|
|
28824
|
-
$schema: "http://json-schema.org/draft-07/schema#",
|
|
28825
|
-
type: "object",
|
|
28826
|
-
properties: {
|
|
28827
|
-
newMemory: {
|
|
28828
|
-
type: "string",
|
|
28829
|
-
description: `The ${config.workingMemory?.schema ? "JSON" : "Markdown"} formatted working memory content to store`
|
|
28830
|
-
},
|
|
28831
|
-
searchString: {
|
|
28832
|
-
type: "string",
|
|
28833
|
-
description: "The working memory string to find. Will be replaced with the newMemory string. If this is omitted or doesn't exist, the newMemory string will be appended to the end of your working memory. Replacing single lines at a time is encouraged for greater accuracy. If updateReason is not 'append-new-memory', this search string must be provided or the tool call will be rejected."
|
|
28834
|
-
},
|
|
28835
|
-
updateReason: {
|
|
28836
|
-
type: "string",
|
|
28837
|
-
enum: [
|
|
28838
|
-
"append-new-memory",
|
|
28839
|
-
"clarify-existing-memory",
|
|
28840
|
-
"replace-irrelevant-memory"
|
|
28841
|
-
],
|
|
28842
|
-
description: "The reason you're updating working memory. Passing any value other than 'append-new-memory' requires a searchString to be provided. Defaults to append-new-memory"
|
|
28843
|
-
}
|
|
28844
|
-
}
|
|
28845
|
-
},
|
|
28846
|
-
execute: async (inputData, context) => {
|
|
28847
|
-
const workingMemoryInput = inputData;
|
|
28848
|
-
const threadId = context?.agent?.threadId;
|
|
28849
|
-
const resourceId = context?.agent?.resourceId;
|
|
28850
|
-
const memory = context?.memory;
|
|
28851
|
-
if (!memory) throw new Error("Memory instance is required for working memory updates");
|
|
28852
|
-
const scope = config.workingMemory?.scope || "resource";
|
|
28853
|
-
if (scope === "thread" && !threadId) throw new Error("Thread ID is required for thread-scoped working memory updates");
|
|
28854
|
-
if (scope === "resource" && !resourceId) throw new Error("Resource ID is required for resource-scoped working memory updates");
|
|
28855
|
-
if (threadId) {
|
|
28856
|
-
let thread = await memory.getThreadById({ threadId });
|
|
28857
|
-
if (!thread) thread = await memory.createThread({
|
|
28858
|
-
threadId,
|
|
28859
|
-
resourceId,
|
|
28860
|
-
memoryConfig: config
|
|
28861
|
-
});
|
|
28862
|
-
if (thread.resourceId && resourceId && thread.resourceId !== resourceId) throw new Error(`Thread with id ${threadId} resourceId does not match the current resourceId ${resourceId}`);
|
|
28863
|
-
}
|
|
28864
|
-
const workingMemory = workingMemoryInput.newMemory || "";
|
|
28865
|
-
if (!workingMemoryInput.updateReason) workingMemoryInput.updateReason = `append-new-memory`;
|
|
28866
|
-
if (workingMemoryInput.searchString && config.workingMemory?.scope === `resource` && workingMemoryInput.updateReason === `replace-irrelevant-memory`) workingMemoryInput.searchString = void 0;
|
|
28867
|
-
if (workingMemoryInput.updateReason === `append-new-memory` && workingMemoryInput.searchString) workingMemoryInput.searchString = void 0;
|
|
28868
|
-
if (workingMemoryInput.updateReason !== `append-new-memory` && !workingMemoryInput.searchString) return {
|
|
28869
|
-
success: false,
|
|
28870
|
-
reason: `updateReason was ${workingMemoryInput.updateReason} but no searchString was provided. Unable to replace undefined with "${workingMemoryInput.newMemory}"`
|
|
28871
|
-
};
|
|
28872
|
-
const result = await memory.__experimental_updateWorkingMemoryVNext({
|
|
28873
|
-
threadId,
|
|
28874
|
-
resourceId,
|
|
28875
|
-
workingMemory,
|
|
28876
|
-
searchString: workingMemoryInput.searchString,
|
|
28877
|
-
memoryConfig: config
|
|
28878
|
-
});
|
|
28879
|
-
if (result) return result;
|
|
28880
|
-
return { success: true };
|
|
28881
|
-
}
|
|
28882
|
-
});
|
|
28883
|
-
};
|
|
28884
|
-
/**
|
|
28885
|
-
* Returns the working-memory tool plus the wire name it should be registered under.
|
|
28886
|
-
*
|
|
28887
|
-
* - Default delivery (`useStateSignals: false`): wire name `updateWorkingMemory`,
|
|
28888
|
-
* identical shape to today.
|
|
28889
|
-
* - State-signals delivery (`useStateSignals: true`): wire name `setWorkingMemory`.
|
|
28890
|
-
* The rename keeps legacy strip filters (which match the literal `updateWorkingMemory`)
|
|
28891
|
-
* from removing tool-call parts so they persist as a normal audit trail. Any
|
|
28892
|
-
* future state-signal-specific tweaks to the tool (e.g. delta-aware results,
|
|
28893
|
-
* scoped descriptions) belong here.
|
|
28894
|
-
*
|
|
28895
|
-
* The VNext vs default tool body decision is left to the caller because Memory
|
|
28896
|
-
* owns the `isVNextWorkingMemoryConfig` check; pass `vNext: true` to use the
|
|
28897
|
-
* search-and-replace shape.
|
|
28898
|
-
*/
|
|
28899
|
-
function createWorkingMemoryTool(config, options = {}) {
|
|
28900
|
-
const useStateSignals = config.workingMemory?.useStateSignals === true;
|
|
28901
|
-
const tool = options.vNext ? __experimental_updateWorkingMemoryToolVNext(config) : updateWorkingMemoryTool(config);
|
|
28902
|
-
return {
|
|
28903
|
-
name: useStateSignals ? SET_WORKING_MEMORY_TOOL_NAME : UPDATE_WORKING_MEMORY_TOOL_NAME,
|
|
28904
|
-
tool
|
|
28905
|
-
};
|
|
28906
|
-
}
|
|
28907
28937
|
/**
|
|
28908
28938
|
* WorkingMemoryStateProcessor
|
|
28909
28939
|
*
|
|
@@ -49207,4 +49237,4 @@ const agentBuilderWorkflows = {
|
|
|
49207
49237
|
//#endregion
|
|
49208
49238
|
exports.agentBuilderWorkflows = agentBuilderWorkflows;
|
|
49209
49239
|
|
|
49210
|
-
//# sourceMappingURL=dist-
|
|
49240
|
+
//# sourceMappingURL=dist-unhwBKm6.cjs.map
|