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