@mastra/memory 1.11.1-alpha.0 → 1.12.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/CHANGELOG.md +32 -0
- package/README.md +1 -1
- package/dist/{chunk-2NZR2XHO.js → chunk-DDQHE4NV.js} +38 -20
- package/dist/chunk-DDQHE4NV.js.map +1 -0
- package/dist/{chunk-W2RTLXNQ.cjs → chunk-HLGFIN4J.cjs} +38 -20
- package/dist/chunk-HLGFIN4J.cjs.map +1 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +39 -39
- package/dist/docs/references/docs-memory-message-history.md +6 -4
- package/dist/docs/references/docs-memory-observational-memory.md +20 -11
- package/dist/docs/references/docs-memory-overview.md +4 -4
- package/dist/docs/references/docs-memory-semantic-recall.md +28 -19
- package/dist/docs/references/docs-memory-storage.md +4 -4
- package/dist/docs/references/reference-memory-observational-memory.md +1 -1
- package/dist/docs/references/reference-storage-dynamodb.md +1 -1
- package/dist/docs/references/reference-storage-upstash.md +1 -1
- package/dist/index.cjs +137 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +130 -15
- package/dist/index.js.map +1 -1
- package/dist/{observational-memory-JCPPBSVG.cjs → observational-memory-34W4S4I5.cjs} +26 -26
- package/dist/{observational-memory-JCPPBSVG.cjs.map → observational-memory-34W4S4I5.cjs.map} +1 -1
- package/dist/{observational-memory-SASGM6OW.js → observational-memory-B25SASRW.js} +3 -3
- package/dist/{observational-memory-SASGM6OW.js.map → observational-memory-B25SASRW.js.map} +1 -1
- package/dist/processors/index.cjs +24 -24
- package/dist/processors/index.js +1 -1
- package/dist/processors/observational-memory/observation-strategies/async-buffer.d.ts +1 -0
- package/dist/processors/observational-memory/observation-strategies/async-buffer.d.ts.map +1 -1
- package/dist/processors/observational-memory/observation-strategies/base.d.ts +7 -2
- package/dist/processors/observational-memory/observation-strategies/base.d.ts.map +1 -1
- package/dist/processors/observational-memory/observation-strategies/resource-scoped.d.ts +1 -0
- package/dist/processors/observational-memory/observation-strategies/resource-scoped.d.ts.map +1 -1
- package/dist/processors/observational-memory/observation-strategies/sync.d.ts +1 -0
- package/dist/processors/observational-memory/observation-strategies/sync.d.ts.map +1 -1
- package/dist/processors/observational-memory/observational-memory.d.ts.map +1 -1
- package/dist/tools/om-tools.d.ts.map +1 -1
- package/package.json +7 -7
- package/dist/chunk-2NZR2XHO.js.map +0 -1
- package/dist/chunk-W2RTLXNQ.cjs.map +0 -1
|
@@ -950,7 +950,11 @@ var ObservationStrategy = class _ObservationStrategy {
|
|
|
950
950
|
retrieval;
|
|
951
951
|
/** Select the right strategy based on scope and mode. Wired up by index.ts. */
|
|
952
952
|
static create;
|
|
953
|
-
/**
|
|
953
|
+
/**
|
|
954
|
+
* Run the full observation lifecycle.
|
|
955
|
+
* @returns `true` if a full observation cycle completed; `false` if skipped (stale lock) or async-buffer failure was swallowed.
|
|
956
|
+
* @throws On sync/resource-scoped observer failure after failed markers (same as pre–Option-A contract).
|
|
957
|
+
*/
|
|
954
958
|
async run() {
|
|
955
959
|
const { record, threadId, abortSignal, writer, reflectionHooks, requestContext } = this.opts;
|
|
956
960
|
const cycleId = this.generateCycleId();
|
|
@@ -958,7 +962,7 @@ var ObservationStrategy = class _ObservationStrategy {
|
|
|
958
962
|
if (this.needsLock) {
|
|
959
963
|
const fresh = await this.storage.getObservationalMemory(record.threadId, record.resourceId);
|
|
960
964
|
if (fresh?.lastObservedAt && record.lastObservedAt && fresh.lastObservedAt > record.lastObservedAt) {
|
|
961
|
-
return;
|
|
965
|
+
return false;
|
|
962
966
|
}
|
|
963
967
|
}
|
|
964
968
|
const { messages, existingObservations } = await this.prepare();
|
|
@@ -979,23 +983,29 @@ var ObservationStrategy = class _ObservationStrategy {
|
|
|
979
983
|
observabilityContext: this.opts.observabilityContext
|
|
980
984
|
});
|
|
981
985
|
}
|
|
986
|
+
return true;
|
|
982
987
|
} catch (error) {
|
|
983
988
|
await this.emitFailedMarkers(cycleId, error);
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
989
|
+
if (!this.rethrowOnFailure) {
|
|
990
|
+
const failedMarkerForStorage = {
|
|
991
|
+
type: "data-om-observation-failed",
|
|
992
|
+
data: {
|
|
993
|
+
cycleId,
|
|
994
|
+
operationType: "observation",
|
|
995
|
+
startedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
996
|
+
error: error instanceof Error ? error.message : String(error),
|
|
997
|
+
recordId: record.id,
|
|
998
|
+
threadId
|
|
999
|
+
}
|
|
1000
|
+
};
|
|
1001
|
+
await this.persistMarkerToStorage(failedMarkerForStorage, threadId, this.opts.resourceId).catch(() => {
|
|
1002
|
+
});
|
|
1003
|
+
if (abortSignal?.aborted) throw error;
|
|
1004
|
+
omError("[OM] Observation failed", error);
|
|
1005
|
+
return false;
|
|
1006
|
+
}
|
|
998
1007
|
omError("[OM] Observation failed", error);
|
|
1008
|
+
throw error;
|
|
999
1009
|
}
|
|
1000
1010
|
}
|
|
1001
1011
|
// ── Shared helpers ──────────────────────────────────────────
|
|
@@ -1216,6 +1226,9 @@ var SyncObservationStrategy = class extends ObservationStrategy {
|
|
|
1216
1226
|
get needsReflection() {
|
|
1217
1227
|
return true;
|
|
1218
1228
|
}
|
|
1229
|
+
get rethrowOnFailure() {
|
|
1230
|
+
return true;
|
|
1231
|
+
}
|
|
1219
1232
|
async prepare() {
|
|
1220
1233
|
const { record, threadId, messages } = this.opts;
|
|
1221
1234
|
this.deps.emitDebugEvent({
|
|
@@ -1409,6 +1422,9 @@ var AsyncBufferObservationStrategy = class extends ObservationStrategy {
|
|
|
1409
1422
|
get needsReflection() {
|
|
1410
1423
|
return false;
|
|
1411
1424
|
}
|
|
1425
|
+
get rethrowOnFailure() {
|
|
1426
|
+
return false;
|
|
1427
|
+
}
|
|
1412
1428
|
generateCycleId() {
|
|
1413
1429
|
return this.cycleId;
|
|
1414
1430
|
}
|
|
@@ -1545,6 +1561,9 @@ var ResourceScopedObservationStrategy = class extends ObservationStrategy {
|
|
|
1545
1561
|
get needsReflection() {
|
|
1546
1562
|
return true;
|
|
1547
1563
|
}
|
|
1564
|
+
get rethrowOnFailure() {
|
|
1565
|
+
return true;
|
|
1566
|
+
}
|
|
1548
1567
|
async prepare() {
|
|
1549
1568
|
const { record, threadId: currentThreadId, messages: currentThreadMessages } = this.opts;
|
|
1550
1569
|
const { threads: allThreads } = await this.storage.listThreads({ filter: { resourceId: this.resourceId } });
|
|
@@ -7813,7 +7832,7 @@ ${grouped}` : grouped;
|
|
|
7813
7832
|
}
|
|
7814
7833
|
hooks?.onObservationStart?.();
|
|
7815
7834
|
try {
|
|
7816
|
-
await ObservationStrategy.create(this, {
|
|
7835
|
+
observed = await ObservationStrategy.create(this, {
|
|
7817
7836
|
record: freshRecord,
|
|
7818
7837
|
threadId,
|
|
7819
7838
|
resourceId,
|
|
@@ -7823,7 +7842,6 @@ ${grouped}` : grouped;
|
|
|
7823
7842
|
writer: opts.writer,
|
|
7824
7843
|
observabilityContext: opts.observabilityContext
|
|
7825
7844
|
}).run();
|
|
7826
|
-
observed = true;
|
|
7827
7845
|
} finally {
|
|
7828
7846
|
hooks?.onObservationEnd?.();
|
|
7829
7847
|
}
|
|
@@ -8457,5 +8475,5 @@ exports.stripEphemeralAnchorIds = stripEphemeralAnchorIds;
|
|
|
8457
8475
|
exports.stripObservationGroups = stripObservationGroups;
|
|
8458
8476
|
exports.truncateStringByTokens = truncateStringByTokens;
|
|
8459
8477
|
exports.wrapInObservationGroup = wrapInObservationGroup;
|
|
8460
|
-
//# sourceMappingURL=chunk-
|
|
8461
|
-
//# sourceMappingURL=chunk-
|
|
8478
|
+
//# sourceMappingURL=chunk-HLGFIN4J.cjs.map
|
|
8479
|
+
//# sourceMappingURL=chunk-HLGFIN4J.cjs.map
|