@mastra/memory 1.2.0-alpha.0 → 1.2.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/CHANGELOG.md +9 -0
- package/dist/{chunk-TYVPTNCP.js → chunk-5YW6JV6Y.js} +68 -3
- package/dist/chunk-5YW6JV6Y.js.map +1 -0
- package/dist/{chunk-AWE2QQPI.cjs → chunk-7SCXX4S7.cjs} +68 -3
- package/dist/chunk-7SCXX4S7.cjs.map +1 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +13 -13
- package/dist/docs/references/docs-memory-observational-memory.md +9 -78
- package/dist/docs/references/reference-memory-observational-memory.md +7 -316
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/{observational-memory-3UO64HYD.cjs → observational-memory-G3HACXHE.cjs} +14 -14
- package/dist/{observational-memory-3UO64HYD.cjs.map → observational-memory-G3HACXHE.cjs.map} +1 -1
- package/dist/{observational-memory-TVHT3HP4.js → observational-memory-LI6QFTRE.js} +3 -3
- package/dist/{observational-memory-TVHT3HP4.js.map → observational-memory-LI6QFTRE.js.map} +1 -1
- package/dist/processors/index.cjs +12 -12
- package/dist/processors/index.js +1 -1
- package/dist/processors/observational-memory/observational-memory.d.ts +16 -0
- package/dist/processors/observational-memory/observational-memory.d.ts.map +1 -1
- package/package.json +4 -4
- package/dist/chunk-AWE2QQPI.cjs.map +0 -1
- package/dist/chunk-TYVPTNCP.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @mastra/memory
|
|
2
2
|
|
|
3
|
+
## 1.2.0-alpha.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Fixed observational memory progress bars resetting to zero after agent responses finish. The messages and observations sidebar bars now retain their values on stream completion, cancellation, and page reload. Also added a buffer-status endpoint so buffering badges resolve with accurate token counts instead of spinning forever when buffering outlives the stream. ([#12934](https://github.com/mastra-ai/mastra/pull/12934))
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`b31c922`](https://github.com/mastra-ai/mastra/commit/b31c922215b513791d98feaea1b98784aa00803a)]:
|
|
10
|
+
- @mastra/core@1.3.0-alpha.2
|
|
11
|
+
|
|
3
12
|
## 1.2.0-alpha.0
|
|
4
13
|
|
|
5
14
|
### Minor Changes
|
|
@@ -1408,6 +1408,30 @@ var ObservationalMemory = class _ObservationalMemory {
|
|
|
1408
1408
|
_ObservationalMemory.reflectionBufferCycleIds.delete(obsBufKey);
|
|
1409
1409
|
}
|
|
1410
1410
|
}
|
|
1411
|
+
/**
|
|
1412
|
+
* Await any in-flight async buffering operations for a given thread/resource.
|
|
1413
|
+
* Returns once all buffering promises have settled (or after timeout).
|
|
1414
|
+
*/
|
|
1415
|
+
static async awaitBuffering(threadId, resourceId, scope, timeoutMs = 3e4) {
|
|
1416
|
+
const lockKey = scope === "resource" && resourceId ? `resource:${resourceId}` : `thread:${threadId ?? "unknown"}`;
|
|
1417
|
+
const obsKey = `obs:${lockKey}`;
|
|
1418
|
+
const reflKey = `refl:${lockKey}`;
|
|
1419
|
+
const promises = [];
|
|
1420
|
+
const obsOp = _ObservationalMemory.asyncBufferingOps.get(obsKey);
|
|
1421
|
+
if (obsOp) promises.push(obsOp);
|
|
1422
|
+
const reflOp = _ObservationalMemory.asyncBufferingOps.get(reflKey);
|
|
1423
|
+
if (reflOp) promises.push(reflOp);
|
|
1424
|
+
if (promises.length === 0) {
|
|
1425
|
+
return;
|
|
1426
|
+
}
|
|
1427
|
+
try {
|
|
1428
|
+
await Promise.race([
|
|
1429
|
+
Promise.all(promises),
|
|
1430
|
+
new Promise((_, reject) => setTimeout(() => reject(new Error("Timeout")), timeoutMs))
|
|
1431
|
+
]);
|
|
1432
|
+
} catch {
|
|
1433
|
+
}
|
|
1434
|
+
}
|
|
1411
1435
|
/**
|
|
1412
1436
|
* Safely get bufferedObservationChunks as an array.
|
|
1413
1437
|
* Handles cases where it might be a JSON string or undefined.
|
|
@@ -1667,6 +1691,13 @@ Async buffering is enabled by default \u2014 this opt-out is only needed when us
|
|
|
1667
1691
|
}
|
|
1668
1692
|
};
|
|
1669
1693
|
}
|
|
1694
|
+
/**
|
|
1695
|
+
* Wait for any in-flight async buffering operations for the given thread/resource.
|
|
1696
|
+
* Used by server endpoints to block until buffering completes so the UI can get final state.
|
|
1697
|
+
*/
|
|
1698
|
+
async waitForBuffering(threadId, resourceId, timeoutMs = 3e4) {
|
|
1699
|
+
return _ObservationalMemory.awaitBuffering(threadId, resourceId, this.scope, timeoutMs);
|
|
1700
|
+
}
|
|
1670
1701
|
/**
|
|
1671
1702
|
* Get the full config including resolved model names.
|
|
1672
1703
|
* This is async because it needs to resolve the model configs.
|
|
@@ -2100,6 +2131,34 @@ Async buffering is enabled by default \u2014 this opt-out is only needed when us
|
|
|
2100
2131
|
}
|
|
2101
2132
|
}
|
|
2102
2133
|
}
|
|
2134
|
+
/**
|
|
2135
|
+
* Persist a marker to the last assistant message in storage.
|
|
2136
|
+
* Unlike persistMarkerToMessage, this fetches messages directly from the DB
|
|
2137
|
+
* so it works even when no MessageList is available (e.g. async buffering ops).
|
|
2138
|
+
*/
|
|
2139
|
+
async persistMarkerToStorage(marker, threadId, resourceId) {
|
|
2140
|
+
try {
|
|
2141
|
+
const result = await this.storage.listMessages({
|
|
2142
|
+
threadId,
|
|
2143
|
+
perPage: 20,
|
|
2144
|
+
orderBy: { field: "createdAt", direction: "DESC" }
|
|
2145
|
+
});
|
|
2146
|
+
const messages = result?.messages ?? [];
|
|
2147
|
+
for (const msg of messages) {
|
|
2148
|
+
if (msg?.role === "assistant" && msg.content?.parts && Array.isArray(msg.content.parts)) {
|
|
2149
|
+
msg.content.parts.push(marker);
|
|
2150
|
+
await this.messageHistory.persistMessages({
|
|
2151
|
+
messages: [msg],
|
|
2152
|
+
threadId,
|
|
2153
|
+
resourceId
|
|
2154
|
+
});
|
|
2155
|
+
return;
|
|
2156
|
+
}
|
|
2157
|
+
}
|
|
2158
|
+
} catch (e) {
|
|
2159
|
+
omDebug(`[OM:persistMarkerToStorage] failed to save marker to DB: ${e}`);
|
|
2160
|
+
}
|
|
2161
|
+
}
|
|
2103
2162
|
/**
|
|
2104
2163
|
* Find the last completed observation boundary in a message's parts.
|
|
2105
2164
|
* A completed observation is a start marker followed by an end marker.
|
|
@@ -3244,6 +3303,8 @@ NOTE: Any messages following this system reminder are newer than your memories.
|
|
|
3244
3303
|
},
|
|
3245
3304
|
currentObservationTokens
|
|
3246
3305
|
);
|
|
3306
|
+
this.storage.setPendingMessageTokens(freshRecord.id, totalPendingTokens).catch(() => {
|
|
3307
|
+
});
|
|
3247
3308
|
}
|
|
3248
3309
|
return messageList;
|
|
3249
3310
|
}
|
|
@@ -3784,6 +3845,7 @@ ${result.observations}` : result.observations;
|
|
|
3784
3845
|
});
|
|
3785
3846
|
void writer.custom(failedMarker).catch(() => {
|
|
3786
3847
|
});
|
|
3848
|
+
await this.persistMarkerToStorage(failedMarker, threadId, freshRecord.resourceId ?? void 0);
|
|
3787
3849
|
}
|
|
3788
3850
|
omError("[OM] Async buffered observation failed", error);
|
|
3789
3851
|
}
|
|
@@ -3846,6 +3908,7 @@ ${result.observations}` : result.observations;
|
|
|
3846
3908
|
});
|
|
3847
3909
|
void writer.custom(endMarker).catch(() => {
|
|
3848
3910
|
});
|
|
3911
|
+
await this.persistMarkerToStorage(endMarker, threadId, record.resourceId ?? void 0);
|
|
3849
3912
|
}
|
|
3850
3913
|
}
|
|
3851
3914
|
/**
|
|
@@ -3972,7 +4035,7 @@ ${bufferedObservations}`;
|
|
|
3972
4035
|
this.storage.setBufferingReflectionFlag(record.id, true).catch((err) => {
|
|
3973
4036
|
omError("[OM] Failed to set buffering reflection flag", err);
|
|
3974
4037
|
});
|
|
3975
|
-
const asyncOp = this.doAsyncBufferedReflection(record, bufferKey, writer).catch((error) => {
|
|
4038
|
+
const asyncOp = this.doAsyncBufferedReflection(record, bufferKey, writer).catch(async (error) => {
|
|
3976
4039
|
if (writer) {
|
|
3977
4040
|
const failedMarker = this.createBufferingFailedMarker({
|
|
3978
4041
|
cycleId: `reflect-buf-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`,
|
|
@@ -3985,6 +4048,7 @@ ${bufferedObservations}`;
|
|
|
3985
4048
|
});
|
|
3986
4049
|
void writer.custom(failedMarker).catch(() => {
|
|
3987
4050
|
});
|
|
4051
|
+
await this.persistMarkerToStorage(failedMarker, record.threadId ?? "", record.resourceId ?? void 0);
|
|
3988
4052
|
}
|
|
3989
4053
|
omError("[OM] Async buffered reflection failed", error);
|
|
3990
4054
|
}).finally(() => {
|
|
@@ -4078,6 +4142,7 @@ ${bufferedObservations}`;
|
|
|
4078
4142
|
});
|
|
4079
4143
|
void writer.custom(endMarker).catch(() => {
|
|
4080
4144
|
});
|
|
4145
|
+
await this.persistMarkerToStorage(endMarker, currentRecord.threadId ?? "", currentRecord.resourceId ?? void 0);
|
|
4081
4146
|
}
|
|
4082
4147
|
}
|
|
4083
4148
|
/**
|
|
@@ -4756,5 +4821,5 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
|
|
|
4756
4821
|
};
|
|
4757
4822
|
|
|
4758
4823
|
export { OBSERVATIONAL_MEMORY_DEFAULTS, OBSERVER_SYSTEM_PROMPT, ObservationalMemory, TokenCounter, buildObserverPrompt, buildObserverSystemPrompt, extractCurrentTask, formatMessagesForObserver, hasCurrentTaskSection, optimizeObservationsForContext, parseObserverOutput };
|
|
4759
|
-
//# sourceMappingURL=chunk-
|
|
4760
|
-
//# sourceMappingURL=chunk-
|
|
4824
|
+
//# sourceMappingURL=chunk-5YW6JV6Y.js.map
|
|
4825
|
+
//# sourceMappingURL=chunk-5YW6JV6Y.js.map
|