@mastra/memory 1.15.1-alpha.1 → 1.16.0-alpha.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 +28 -0
- package/dist/{chunk-OUMWCVQI.cjs → chunk-3NECGYWZ.cjs} +121 -16
- package/dist/chunk-3NECGYWZ.cjs.map +1 -0
- package/dist/{chunk-HAEQMUD4.js → chunk-HB6AYAFD.js} +121 -16
- package/dist/chunk-HB6AYAFD.js.map +1 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +47 -47
- package/dist/docs/references/docs-memory-message-history.md +6 -0
- package/dist/docs/references/docs-memory-observational-memory.md +29 -7
- package/dist/docs/references/reference-memory-observational-memory.md +2 -0
- package/dist/index.cjs +15 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -5
- package/dist/index.js.map +1 -1
- package/dist/{observational-memory-H74M5SB6.js → observational-memory-WWAB2MMI.js} +3 -3
- package/dist/{observational-memory-H74M5SB6.js.map → observational-memory-WWAB2MMI.js.map} +1 -1
- package/dist/{observational-memory-TKXRH2LD.cjs → observational-memory-X4N2R4CA.cjs} +26 -26
- package/dist/{observational-memory-TKXRH2LD.cjs.map → observational-memory-X4N2R4CA.cjs.map} +1 -1
- package/dist/processors/index.cjs +24 -24
- package/dist/processors/index.js +1 -1
- package/dist/processors/observational-memory/markers.d.ts +3 -0
- package/dist/processors/observational-memory/markers.d.ts.map +1 -1
- package/dist/processors/observational-memory/observation-turn/step.d.ts.map +1 -1
- package/dist/processors/observational-memory/observational-memory.d.ts +6 -0
- package/dist/processors/observational-memory/observational-memory.d.ts.map +1 -1
- package/dist/processors/observational-memory/processor.d.ts.map +1 -1
- package/dist/processors/observational-memory/reflector-runner.d.ts +1 -0
- package/dist/processors/observational-memory/reflector-runner.d.ts.map +1 -1
- package/dist/processors/observational-memory/types.d.ts +19 -0
- package/dist/processors/observational-memory/types.d.ts.map +1 -1
- package/package.json +8 -8
- package/dist/chunk-HAEQMUD4.js.map +0 -1
- package/dist/chunk-OUMWCVQI.cjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# @mastra/memory
|
|
2
2
|
|
|
3
|
+
## 1.16.0-alpha.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Added activateAfterIdle setting for observational memory so buffered observations can activate after idle time before the next prompt. ([#15365](https://github.com/mastra-ai/mastra/pull/15365))
|
|
8
|
+
|
|
9
|
+
**Example**
|
|
10
|
+
|
|
11
|
+
Set `activateAfterIdle: 300_000` (or `"5m"`) on the `observationalMemory` config to activate buffered context after 5 minutes of inactivity.
|
|
12
|
+
|
|
13
|
+
This helps long-running threads reuse compressed context after prompt cache TTLs expire instead of sending a larger raw message window on the next request.
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Updated dependencies [[`3d83d06`](https://github.com/mastra-ai/mastra/commit/3d83d06f776f00fb5f4163dddd32a030c5c20844), [`7e0e63e`](https://github.com/mastra-ai/mastra/commit/7e0e63e2e485e84442351f4c7a79a424c83539dc), [`9467ea8`](https://github.com/mastra-ai/mastra/commit/9467ea87695749a53dfc041576410ebf9ee7bb67), [`7338d94`](https://github.com/mastra-ai/mastra/commit/7338d949380cf68b095342e8e42610dc51d557c1), [`c65aec3`](https://github.com/mastra-ai/mastra/commit/c65aec356cc037ee7c4b30ccea946807d4c4f443)]:
|
|
18
|
+
- @mastra/core@1.26.0-alpha.2
|
|
19
|
+
- @mastra/schema-compat@1.2.9-alpha.0
|
|
20
|
+
|
|
21
|
+
## 1.15.1
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- Fixed gateway model detection to use duck typing instead of instanceof check, preventing potential failures from cross-package module resolution issues. Propagates `gatewayId` through the AISDKV5LanguageModel wrapper so duck-type detection works even when models are re-wrapped. ([#15168](https://github.com/mastra-ai/mastra/pull/15168))
|
|
26
|
+
|
|
27
|
+
- Updated dependencies [[`87df955`](https://github.com/mastra-ai/mastra/commit/87df955c028660c075873fd5d74af28233ce32eb), [`8fad147`](https://github.com/mastra-ai/mastra/commit/8fad14759804179c8e080ce4d9dec6ef1a808b31), [`582644c`](https://github.com/mastra-ai/mastra/commit/582644c4a87f83b4f245a84d72b9e8590585012e), [`cbdf3e1`](https://github.com/mastra-ai/mastra/commit/cbdf3e12b3d0c30a6e5347be658e2009648c130a), [`8fe46d3`](https://github.com/mastra-ai/mastra/commit/8fe46d354027f3f0f0846e64219772348de106dd), [`18c67db`](https://github.com/mastra-ai/mastra/commit/18c67dbb9c9ebc26f26f65f7d3ff836e5691ef46), [`4ba3bb1`](https://github.com/mastra-ai/mastra/commit/4ba3bb1e465ad2ddaba3bbf2bc47e0faec32985e), [`5d84914`](https://github.com/mastra-ai/mastra/commit/5d84914e0e520c642a40329b210b413fcd139898), [`8dcc77e`](https://github.com/mastra-ai/mastra/commit/8dcc77e78a5340f5848f74b9e9f1b3da3513c1f5), [`aa67fc5`](https://github.com/mastra-ai/mastra/commit/aa67fc59ee8a5eeff1f23eb05970b8d7a536c8ff), [`fd2f314`](https://github.com/mastra-ai/mastra/commit/fd2f31473d3449b6b97e837ef8641264377f41a7), [`fa8140b`](https://github.com/mastra-ai/mastra/commit/fa8140bcd4251d2e3ac85fdc5547dfc4f372b5be), [`190f452`](https://github.com/mastra-ai/mastra/commit/190f45258b0640e2adfc8219fa3258cdc5b8f071), [`e80fead`](https://github.com/mastra-ai/mastra/commit/e80fead1412cc0d1b2f7d6a1ce5017d9e0098ff7), [`0287b64`](https://github.com/mastra-ai/mastra/commit/0287b644a5c3272755cf3112e71338106664103b), [`7e7bf60`](https://github.com/mastra-ai/mastra/commit/7e7bf606886bf374a6f9d4ca9b09dd83d0533372), [`184907d`](https://github.com/mastra-ai/mastra/commit/184907d775d8609c03c26e78ccaf37315f3aa287), [`075e91a`](https://github.com/mastra-ai/mastra/commit/075e91a4549baf46ad7a42a6a8ac8dfa78cc09e6), [`2a69802`](https://github.com/mastra-ai/mastra/commit/2a69802a0fc6d8a25a77fa6a42276e9d59a83914), [`0c4cd13`](https://github.com/mastra-ai/mastra/commit/0c4cd131931c04ac5405373c932a242dbe88edd6), [`b16a753`](https://github.com/mastra-ai/mastra/commit/b16a753d5748440248d7df82e29bb987a9c8386c)]:
|
|
28
|
+
- @mastra/core@1.25.0
|
|
29
|
+
- @mastra/schema-compat@1.2.8
|
|
30
|
+
|
|
3
31
|
## 1.15.1-alpha.1
|
|
4
32
|
|
|
5
33
|
### Patch Changes
|
|
@@ -491,7 +491,10 @@ function createActivationMarker(params) {
|
|
|
491
491
|
threadId: params.threadId,
|
|
492
492
|
generationCount: params.generationCount,
|
|
493
493
|
config: params.config,
|
|
494
|
-
observations: params.observations
|
|
494
|
+
observations: params.observations,
|
|
495
|
+
triggeredBy: params.triggeredBy,
|
|
496
|
+
lastActivityAt: params.lastActivityAt,
|
|
497
|
+
ttlExpiredMs: params.ttlExpiredMs
|
|
495
498
|
}
|
|
496
499
|
};
|
|
497
500
|
}
|
|
@@ -941,6 +944,8 @@ var ObservationStrategy = class _ObservationStrategy {
|
|
|
941
944
|
this.scope = deps.scope;
|
|
942
945
|
this.retrieval = deps.retrieval;
|
|
943
946
|
}
|
|
947
|
+
deps;
|
|
948
|
+
opts;
|
|
944
949
|
storage;
|
|
945
950
|
messageHistory;
|
|
946
951
|
tokenCounter;
|
|
@@ -1947,6 +1952,8 @@ var ObservationStep = class {
|
|
|
1947
1952
|
this.turn = turn;
|
|
1948
1953
|
this.stepNumber = stepNumber;
|
|
1949
1954
|
}
|
|
1955
|
+
turn;
|
|
1956
|
+
stepNumber;
|
|
1950
1957
|
_prepared = false;
|
|
1951
1958
|
_context;
|
|
1952
1959
|
/** Whether this step has been prepared. */
|
|
@@ -2006,7 +2013,8 @@ var ObservationStep = class {
|
|
|
2006
2013
|
threadId,
|
|
2007
2014
|
writer: this.turn.writer,
|
|
2008
2015
|
requestContext: this.turn.requestContext,
|
|
2009
|
-
observabilityContext: this.turn.observabilityContext
|
|
2016
|
+
observabilityContext: this.turn.observabilityContext,
|
|
2017
|
+
lastActivityAt: getLastActivityFromMessages(messageList.get.all.db())
|
|
2010
2018
|
});
|
|
2011
2019
|
await this.turn.refreshRecord();
|
|
2012
2020
|
if (this.turn.record.generationCount > preReflectGeneration) {
|
|
@@ -2182,7 +2190,8 @@ var ObservationStep = class {
|
|
|
2182
2190
|
writer: this.turn.writer,
|
|
2183
2191
|
messageList,
|
|
2184
2192
|
requestContext: this.turn.requestContext,
|
|
2185
|
-
observabilityContext: this.turn.observabilityContext
|
|
2193
|
+
observabilityContext: this.turn.observabilityContext,
|
|
2194
|
+
lastActivityAt: getLastActivityFromMessages(messageList.get.all.db())
|
|
2186
2195
|
});
|
|
2187
2196
|
return {
|
|
2188
2197
|
succeeded: true,
|
|
@@ -4137,7 +4146,8 @@ var ReflectorRunner = class {
|
|
|
4137
4146
|
observationTokens: getMaxThreshold(
|
|
4138
4147
|
record ? this.getEffectiveReflectionTokens(record) : this.reflectionConfig.observationTokens
|
|
4139
4148
|
),
|
|
4140
|
-
scope: this.scope
|
|
4149
|
+
scope: this.scope,
|
|
4150
|
+
activateAfterIdle: this.reflectionConfig.activateAfterIdle
|
|
4141
4151
|
};
|
|
4142
4152
|
}
|
|
4143
4153
|
/**
|
|
@@ -4423,7 +4433,7 @@ var ReflectorRunner = class {
|
|
|
4423
4433
|
* Try to activate buffered reflection when threshold is reached.
|
|
4424
4434
|
* Returns true if activation succeeded.
|
|
4425
4435
|
*/
|
|
4426
|
-
async tryActivateBufferedReflection(record, lockKey, writer, messageList) {
|
|
4436
|
+
async tryActivateBufferedReflection(record, lockKey, writer, messageList, activationMetadata) {
|
|
4427
4437
|
const bufferKey = this.buffering.getReflectionBufferKey(lockKey);
|
|
4428
4438
|
const asyncOp = BufferingCoordinator.asyncBufferingOps.get(bufferKey);
|
|
4429
4439
|
if (asyncOp) {
|
|
@@ -4483,6 +4493,9 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
|
|
|
4483
4493
|
threadId: freshRecord.threadId ?? "",
|
|
4484
4494
|
generationCount: afterRecord?.generationCount ?? freshRecord.generationCount ?? 0,
|
|
4485
4495
|
observations: afterRecord?.activeObservations,
|
|
4496
|
+
triggeredBy: activationMetadata?.triggeredBy,
|
|
4497
|
+
lastActivityAt: activationMetadata?.lastActivityAt,
|
|
4498
|
+
ttlExpiredMs: activationMetadata?.ttlExpiredMs,
|
|
4486
4499
|
config: this.getObservationMarkerConfig(freshRecord)
|
|
4487
4500
|
});
|
|
4488
4501
|
void writer.custom(activationMarker).catch(() => {
|
|
@@ -4511,7 +4524,9 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
|
|
|
4511
4524
|
messageList,
|
|
4512
4525
|
reflectionHooks,
|
|
4513
4526
|
requestContext,
|
|
4514
|
-
observabilityContext
|
|
4527
|
+
observabilityContext,
|
|
4528
|
+
lastActivityAt,
|
|
4529
|
+
threadId: requestedThreadId
|
|
4515
4530
|
} = opts;
|
|
4516
4531
|
const lockKey = this.buffering.getLockKey(record.threadId, record.resourceId);
|
|
4517
4532
|
const reflectThreshold = getMaxThreshold(this.getEffectiveReflectionTokens(record));
|
|
@@ -4543,9 +4558,17 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
|
|
|
4543
4558
|
);
|
|
4544
4559
|
}
|
|
4545
4560
|
}
|
|
4546
|
-
|
|
4561
|
+
const activateAfterIdle = this.reflectionConfig.activateAfterIdle;
|
|
4562
|
+
const ttlExpiredMs = activateAfterIdle !== void 0 && lastActivityAt !== void 0 ? Date.now() - lastActivityAt : void 0;
|
|
4563
|
+
const ttlExpired = ttlExpiredMs !== void 0 && activateAfterIdle !== void 0 && ttlExpiredMs >= activateAfterIdle;
|
|
4564
|
+
if (observationTokens < reflectThreshold && !ttlExpired) {
|
|
4547
4565
|
return;
|
|
4548
4566
|
}
|
|
4567
|
+
const activationMetadata = {
|
|
4568
|
+
triggeredBy: ttlExpired ? "ttl" : "threshold",
|
|
4569
|
+
lastActivityAt: ttlExpired ? lastActivityAt : void 0,
|
|
4570
|
+
ttlExpiredMs: ttlExpired ? ttlExpiredMs : void 0
|
|
4571
|
+
};
|
|
4549
4572
|
if (record.isReflecting) {
|
|
4550
4573
|
if (isOpActiveInProcess(record.id, "reflecting")) {
|
|
4551
4574
|
omDebug(`[OM:reflect] isReflecting=true and active in this process, skipping`);
|
|
@@ -4555,7 +4578,13 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
|
|
|
4555
4578
|
await this.storage.setReflectingFlag(record.id, false);
|
|
4556
4579
|
}
|
|
4557
4580
|
if (this.buffering.isAsyncReflectionEnabled()) {
|
|
4558
|
-
const activationSuccess = await this.tryActivateBufferedReflection(
|
|
4581
|
+
const activationSuccess = await this.tryActivateBufferedReflection(
|
|
4582
|
+
record,
|
|
4583
|
+
lockKey,
|
|
4584
|
+
writer,
|
|
4585
|
+
messageList,
|
|
4586
|
+
activationMetadata
|
|
4587
|
+
);
|
|
4559
4588
|
if (activationSuccess) {
|
|
4560
4589
|
return;
|
|
4561
4590
|
}
|
|
@@ -4584,7 +4613,7 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
|
|
|
4584
4613
|
registerOp(record.id, "reflecting");
|
|
4585
4614
|
const cycleId = crypto.randomUUID();
|
|
4586
4615
|
const startedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
4587
|
-
const threadId =
|
|
4616
|
+
const threadId = requestedThreadId ?? "unknown";
|
|
4588
4617
|
if (writer) {
|
|
4589
4618
|
const startMarker = createObservationStartMarker({
|
|
4590
4619
|
cycleId,
|
|
@@ -6234,6 +6263,58 @@ function buildMessageRange(messages) {
|
|
|
6234
6263
|
const last = [...messages].reverse().find(messageHasVisibleContent) ?? messages[messages.length - 1];
|
|
6235
6264
|
return `${first.id}:${last.id}`;
|
|
6236
6265
|
}
|
|
6266
|
+
function getLastActivityFromMessages(messages) {
|
|
6267
|
+
if (!messages) return void 0;
|
|
6268
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
6269
|
+
const message = messages[i];
|
|
6270
|
+
if (!message || message.role !== "assistant") {
|
|
6271
|
+
continue;
|
|
6272
|
+
}
|
|
6273
|
+
if (!message.content || typeof message.content === "string") {
|
|
6274
|
+
return message.createdAt ? new Date(message.createdAt).getTime() : void 0;
|
|
6275
|
+
}
|
|
6276
|
+
for (let j = message.content.parts.length - 1; j >= 0; j--) {
|
|
6277
|
+
const part = message.content.parts[j];
|
|
6278
|
+
if (!part || part.type?.startsWith("data-")) {
|
|
6279
|
+
continue;
|
|
6280
|
+
}
|
|
6281
|
+
if (part.createdAt !== void 0) {
|
|
6282
|
+
return part.createdAt;
|
|
6283
|
+
}
|
|
6284
|
+
}
|
|
6285
|
+
return message.createdAt ? new Date(message.createdAt).getTime() : void 0;
|
|
6286
|
+
}
|
|
6287
|
+
return void 0;
|
|
6288
|
+
}
|
|
6289
|
+
function parseActivationTTL(value, fieldPath) {
|
|
6290
|
+
if (value === void 0) {
|
|
6291
|
+
return void 0;
|
|
6292
|
+
}
|
|
6293
|
+
if (typeof value === "number") {
|
|
6294
|
+
if (!Number.isFinite(value) || value < 0) {
|
|
6295
|
+
throw new Error(`${fieldPath} must be a non-negative number of milliseconds or a duration string like "5m".`);
|
|
6296
|
+
}
|
|
6297
|
+
return value;
|
|
6298
|
+
}
|
|
6299
|
+
const trimmed = value.trim();
|
|
6300
|
+
const match = trimmed.match(
|
|
6301
|
+
/^(\d+(?:\.\d+)?)\s*(ms|msec|msecs|millisecond|milliseconds|s|sec|secs|second|seconds|m|min|mins|minute|minutes|h|hr|hrs|hour|hours)$/i
|
|
6302
|
+
);
|
|
6303
|
+
if (!match) {
|
|
6304
|
+
throw new Error(
|
|
6305
|
+
`${fieldPath} must be a non-negative number of milliseconds or a duration string like "5m" or "1hr".`
|
|
6306
|
+
);
|
|
6307
|
+
}
|
|
6308
|
+
const rawAmount = match[1];
|
|
6309
|
+
const rawUnit = match[2];
|
|
6310
|
+
const amount = Number(rawAmount);
|
|
6311
|
+
const unit = rawUnit.toLowerCase();
|
|
6312
|
+
if (!Number.isFinite(amount) || amount < 0) {
|
|
6313
|
+
throw new Error(`${fieldPath} must be a non-negative number of milliseconds or a duration string like "5m".`);
|
|
6314
|
+
}
|
|
6315
|
+
const multiplier = unit === "ms" || unit === "msec" || unit === "msecs" || unit === "millisecond" || unit === "milliseconds" ? 1 : unit === "s" || unit === "sec" || unit === "secs" || unit === "second" || unit === "seconds" ? 1e3 : unit === "m" || unit === "min" || unit === "mins" || unit === "minute" || unit === "minutes" ? 6e4 : 36e5;
|
|
6316
|
+
return amount * multiplier;
|
|
6317
|
+
}
|
|
6237
6318
|
var ObservationalMemory = class _ObservationalMemory {
|
|
6238
6319
|
storage;
|
|
6239
6320
|
tokenCounter;
|
|
@@ -6380,6 +6461,7 @@ Async buffering is enabled by default \u2014 this opt-out is only needed when us
|
|
|
6380
6461
|
config.observation?.messageTokens ?? chunkD4J4XPGM_cjs.OBSERVATIONAL_MEMORY_DEFAULTS.observation.messageTokens
|
|
6381
6462
|
),
|
|
6382
6463
|
bufferActivation: asyncBufferingDisabled ? void 0 : config.observation?.bufferActivation ?? chunkD4J4XPGM_cjs.OBSERVATIONAL_MEMORY_DEFAULTS.observation.bufferActivation,
|
|
6464
|
+
activateAfterIdle: parseActivationTTL(config.activateAfterIdle, "activateAfterIdle"),
|
|
6383
6465
|
blockAfter: asyncBufferingDisabled ? void 0 : resolveBlockAfter(
|
|
6384
6466
|
config.observation?.blockAfter ?? (config.observation?.bufferTokens ?? chunkD4J4XPGM_cjs.OBSERVATIONAL_MEMORY_DEFAULTS.observation.bufferTokens ? 1.2 : void 0),
|
|
6385
6467
|
config.observation?.messageTokens ?? chunkD4J4XPGM_cjs.OBSERVATIONAL_MEMORY_DEFAULTS.observation.messageTokens
|
|
@@ -6398,6 +6480,7 @@ Async buffering is enabled by default \u2014 this opt-out is only needed when us
|
|
|
6398
6480
|
},
|
|
6399
6481
|
providerOptions: config.reflection?.providerOptions ?? chunkD4J4XPGM_cjs.OBSERVATIONAL_MEMORY_DEFAULTS.reflection.providerOptions,
|
|
6400
6482
|
bufferActivation: asyncBufferingDisabled ? void 0 : config?.reflection?.bufferActivation ?? chunkD4J4XPGM_cjs.OBSERVATIONAL_MEMORY_DEFAULTS.reflection.bufferActivation,
|
|
6483
|
+
activateAfterIdle: parseActivationTTL(config.activateAfterIdle, "activateAfterIdle"),
|
|
6401
6484
|
blockAfter: asyncBufferingDisabled ? void 0 : resolveBlockAfter(
|
|
6402
6485
|
config.reflection?.blockAfter ?? (config.reflection?.bufferActivation ?? chunkD4J4XPGM_cjs.OBSERVATIONAL_MEMORY_DEFAULTS.reflection.bufferActivation ? 1.2 : void 0),
|
|
6403
6486
|
config.reflection?.observationTokens ?? chunkD4J4XPGM_cjs.OBSERVATIONAL_MEMORY_DEFAULTS.reflection.observationTokens
|
|
@@ -6792,7 +6875,8 @@ Async buffering is enabled by default \u2014 this opt-out is only needed when us
|
|
|
6792
6875
|
return {
|
|
6793
6876
|
messageTokens: getMaxThreshold(this.observationConfig.messageTokens),
|
|
6794
6877
|
observationTokens: getMaxThreshold(this.reflectionConfig.observationTokens),
|
|
6795
|
-
scope: this.scope
|
|
6878
|
+
scope: this.scope,
|
|
6879
|
+
activateAfterIdle: this.observationConfig.activateAfterIdle
|
|
6796
6880
|
};
|
|
6797
6881
|
}
|
|
6798
6882
|
/**
|
|
@@ -8030,7 +8114,7 @@ ${grouped}` : grouped;
|
|
|
8030
8114
|
await BufferingCoordinator.awaitBuffering(threadId, resourceId ?? null, this.scope);
|
|
8031
8115
|
const preStatus = await this.getStatus({ threadId, resourceId, messages });
|
|
8032
8116
|
if (preStatus.canActivate) {
|
|
8033
|
-
const actResult = await this.activate({ threadId, resourceId });
|
|
8117
|
+
const actResult = await this.activate({ threadId, resourceId, messages });
|
|
8034
8118
|
activated = actResult.activated;
|
|
8035
8119
|
}
|
|
8036
8120
|
const postStatus = await this.getStatus({ threadId, resourceId, messages });
|
|
@@ -8290,10 +8374,28 @@ ${grouped}` : grouped;
|
|
|
8290
8374
|
if (!chunks.length) {
|
|
8291
8375
|
return { activated: false, record };
|
|
8292
8376
|
}
|
|
8377
|
+
let activationTriggeredBy = "threshold";
|
|
8378
|
+
let activationLastActivityAt;
|
|
8379
|
+
let activateAfterIdleExpiredMs;
|
|
8293
8380
|
if (opts.checkThreshold) {
|
|
8294
|
-
const
|
|
8295
|
-
|
|
8296
|
-
|
|
8381
|
+
const thresholdMessages = opts.messages ?? await this.loadMessagesFromStorage(
|
|
8382
|
+
threadId,
|
|
8383
|
+
resourceId,
|
|
8384
|
+
record.lastObservedAt ? new Date(record.lastObservedAt) : void 0
|
|
8385
|
+
);
|
|
8386
|
+
const activateAfterIdle = this.observationConfig.activateAfterIdle;
|
|
8387
|
+
const lastActivityAt = getLastActivityFromMessages(thresholdMessages);
|
|
8388
|
+
const ttlExpiredMs = activateAfterIdle !== void 0 && lastActivityAt !== void 0 ? Date.now() - lastActivityAt : void 0;
|
|
8389
|
+
const ttlExpired = ttlExpiredMs !== void 0 && activateAfterIdle !== void 0 && ttlExpiredMs >= activateAfterIdle;
|
|
8390
|
+
if (ttlExpired) {
|
|
8391
|
+
activationTriggeredBy = "ttl";
|
|
8392
|
+
activationLastActivityAt = lastActivityAt;
|
|
8393
|
+
activateAfterIdleExpiredMs = ttlExpiredMs;
|
|
8394
|
+
} else {
|
|
8395
|
+
const status = await this.getStatus({ threadId, resourceId, messages: thresholdMessages });
|
|
8396
|
+
if (status.pendingTokens < status.threshold) {
|
|
8397
|
+
return { activated: false, record };
|
|
8398
|
+
}
|
|
8297
8399
|
}
|
|
8298
8400
|
}
|
|
8299
8401
|
if (record.isBufferingObservation) {
|
|
@@ -8351,6 +8453,9 @@ ${grouped}` : grouped;
|
|
|
8351
8453
|
threadId: postSwapRecord.threadId ?? record.threadId ?? "",
|
|
8352
8454
|
generationCount: postSwapRecord.generationCount ?? 0,
|
|
8353
8455
|
observations: chunkData?.observations ?? activationResult.observations,
|
|
8456
|
+
triggeredBy: activationTriggeredBy,
|
|
8457
|
+
lastActivityAt: activationLastActivityAt,
|
|
8458
|
+
ttlExpiredMs: activateAfterIdleExpiredMs,
|
|
8354
8459
|
config: this.getObservationMarkerConfig()
|
|
8355
8460
|
});
|
|
8356
8461
|
void opts.writer.custom(activationMarker).catch(() => {
|
|
@@ -8866,5 +8971,5 @@ exports.stripEphemeralAnchorIds = stripEphemeralAnchorIds;
|
|
|
8866
8971
|
exports.stripObservationGroups = stripObservationGroups;
|
|
8867
8972
|
exports.truncateStringByTokens = truncateStringByTokens;
|
|
8868
8973
|
exports.wrapInObservationGroup = wrapInObservationGroup;
|
|
8869
|
-
//# sourceMappingURL=chunk-
|
|
8870
|
-
//# sourceMappingURL=chunk-
|
|
8974
|
+
//# sourceMappingURL=chunk-3NECGYWZ.cjs.map
|
|
8975
|
+
//# sourceMappingURL=chunk-3NECGYWZ.cjs.map
|