@mastra/memory 1.5.2 → 1.6.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 +27 -0
- package/LICENSE.md +15 -0
- package/dist/{chunk-PVFLHAZX.cjs → chunk-5UYAHJVJ.cjs} +77 -73
- package/dist/chunk-5UYAHJVJ.cjs.map +1 -0
- package/dist/{chunk-HNPAIFCZ.js → chunk-A62BQK35.js} +77 -73
- package/dist/chunk-A62BQK35.js.map +1 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +16 -16
- package/dist/docs/references/docs-memory-observational-memory.md +3 -5
- package/dist/docs/references/reference-memory-cloneThread.md +13 -1
- package/dist/docs/references/reference-memory-observational-memory.md +4 -2
- package/dist/index.cjs +106 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +106 -7
- package/dist/index.js.map +1 -1
- package/dist/{observational-memory-Q47HN5YL.cjs → observational-memory-MXI54VC7.cjs} +17 -17
- package/dist/{observational-memory-Q47HN5YL.cjs.map → observational-memory-MXI54VC7.cjs.map} +1 -1
- package/dist/{observational-memory-KAFD4QZK.js → observational-memory-SR6G4HN5.js} +3 -3
- package/dist/{observational-memory-KAFD4QZK.js.map → observational-memory-SR6G4HN5.js.map} +1 -1
- package/dist/processors/index.cjs +15 -15
- package/dist/processors/index.js +1 -1
- package/dist/processors/observational-memory/observational-memory.d.ts +3 -4
- package/dist/processors/observational-memory/observational-memory.d.ts.map +1 -1
- package/dist/processors/observational-memory/types.d.ts +8 -2
- package/dist/processors/observational-memory/types.d.ts.map +1 -1
- package/package.json +6 -6
- package/dist/chunk-HNPAIFCZ.js.map +0 -1
- package/dist/chunk-PVFLHAZX.cjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# @mastra/memory
|
|
2
2
|
|
|
3
|
+
## 1.6.0-alpha.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Added Observational Memory cloning when forking threads. Thread-scoped OM is cloned with remapped message IDs. Resource-scoped OM is shared when the resourceId stays the same, and cloned with remapped thread tags when the resourceId changes. Only the current OM generation is cloned (older history generations are not copied). If OM cloning fails, the already-persisted thread clone is rolled back. ([#13569](https://github.com/mastra-ai/mastra/pull/13569))
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Stop auto-applying `maxOutputTokens: 100_000` to observer and reflector models when users supply their own model. ([#13563](https://github.com/mastra-ai/mastra/pull/13563))
|
|
12
|
+
|
|
13
|
+
Previously, the 100k default was always injected regardless of model choice. Now it is only applied when using the built-in default model (`google/gemini-2.5-flash`). If you set a custom `observation.model` or `reflection.model`, no `maxOutputTokens` default is added — pass it explicitly in `modelSettings` if your model needs it.
|
|
14
|
+
|
|
15
|
+
- Fixed duplicate user messages when observational memory async buffering is active. Sealed-for-buffering messages without observation markers are now skipped in per-step save instead of being re-saved with new IDs. ([#13130](https://github.com/mastra-ai/mastra/pull/13130))
|
|
16
|
+
|
|
17
|
+
- Fixed stale continuation hints in observational memory. ([#13606](https://github.com/mastra-ai/mastra/pull/13606))
|
|
18
|
+
|
|
19
|
+
When newer outputs omit continuation hints, old hints are now cleared. This prevents outdated task and response guidance from appearing in later turns.
|
|
20
|
+
|
|
21
|
+
- Fixed a bug where async buffered observations generated stale continuation hints (suggested response and current task) that would be injected into the agent's context on the next turn, causing the agent to reply to old messages or work on already-completed tasks. ([#13678](https://github.com/mastra-ai/mastra/pull/13678))
|
|
22
|
+
|
|
23
|
+
- Fixed observational memory compatibility with Codex and other stream-only providers. Observer and reflector calls now use the streaming API internally, so providers that require `stream: true` in requests work correctly out of the box. ([#13563](https://github.com/mastra-ai/mastra/pull/13563))
|
|
24
|
+
|
|
25
|
+
- Fixed Memory.recall() to include pagination metadata (total, page, perPage, hasMore) in its response, ensuring consistent pagination regardless of whether agentId is provided. Fixes #13277 ([#13278](https://github.com/mastra-ai/mastra/pull/13278))
|
|
26
|
+
|
|
27
|
+
- Updated dependencies [[`504fc8b`](https://github.com/mastra-ai/mastra/commit/504fc8b9d0ddab717577ad3bf9c95ea4bd5377bd), [`f9c150b`](https://github.com/mastra-ai/mastra/commit/f9c150b7595ad05ad9cc9a11098e2944361e8c22), [`88de7e8`](https://github.com/mastra-ai/mastra/commit/88de7e8dfe4b7e1951a9e441bb33136e705ce24e), [`edee4b3`](https://github.com/mastra-ai/mastra/commit/edee4b37dff0af515fc7cc0e8d71ee39e6a762f0), [`3790c75`](https://github.com/mastra-ai/mastra/commit/3790c7578cc6a47d854eb12d89e6b1912867fe29), [`e7a235b`](https://github.com/mastra-ai/mastra/commit/e7a235be6472e0c870ed6c791ddb17c492dc188b), [`d51d298`](https://github.com/mastra-ai/mastra/commit/d51d298953967aab1f58ec965b644d109214f085), [`6dbeeb9`](https://github.com/mastra-ai/mastra/commit/6dbeeb94a8b1eebb727300d1a98961f882180794), [`d5f0d8d`](https://github.com/mastra-ai/mastra/commit/d5f0d8d6a03e515ddaa9b5da19b7e44b8357b07b), [`09c3b18`](https://github.com/mastra-ai/mastra/commit/09c3b1802ff14e243a8a8baea327440bc8cc2e32), [`b896379`](https://github.com/mastra-ai/mastra/commit/b8963791c6afa79484645fcec596a201f936b9a2), [`85c84eb`](https://github.com/mastra-ai/mastra/commit/85c84ebb78aebfcba9d209c8e152b16d7a00cb71), [`a89272a`](https://github.com/mastra-ai/mastra/commit/a89272a5d71939b9fcd284e6a6dc1dd091a6bdcf), [`ee9c8df`](https://github.com/mastra-ai/mastra/commit/ee9c8df644f19d055af5f496bf4942705f5a47b7), [`77b4a25`](https://github.com/mastra-ai/mastra/commit/77b4a254e51907f8ff3a3ba95596a18e93ae4b35), [`276246e`](https://github.com/mastra-ai/mastra/commit/276246e0b9066a1ea48bbc70df84dbe528daaf99), [`08ecfdb`](https://github.com/mastra-ai/mastra/commit/08ecfdbdad6fb8285deef86a034bdf4a6047cfca), [`d5f628c`](https://github.com/mastra-ai/mastra/commit/d5f628ca86c6f6f3ff1035d52f635df32dd81cab), [`524c0f3`](https://github.com/mastra-ai/mastra/commit/524c0f3c434c3d9d18f66338dcef383d6161b59c), [`c18a0e9`](https://github.com/mastra-ai/mastra/commit/c18a0e9cef1e4ca004b2963d35e4cfc031971eac), [`4bd21ea`](https://github.com/mastra-ai/mastra/commit/4bd21ea43d44d0a0427414fc047577f9f0aa3bec), [`115a7a4`](https://github.com/mastra-ai/mastra/commit/115a7a47db5e9896fec12ae6507501adb9ec89bf), [`22a48ae`](https://github.com/mastra-ai/mastra/commit/22a48ae2513eb54d8d79dad361fddbca97a155e8), [`3c6ef79`](https://github.com/mastra-ai/mastra/commit/3c6ef798481e00d6d22563be2de98818fd4dd5e0), [`9311c17`](https://github.com/mastra-ai/mastra/commit/9311c17d7a0640d9c4da2e71b814dc67c57c6369), [`7edf78f`](https://github.com/mastra-ai/mastra/commit/7edf78f80422c43e84585f08ba11df0d4d0b73c5), [`1c4221c`](https://github.com/mastra-ai/mastra/commit/1c4221cf6032ec98d0e094d4ee11da3e48490d96), [`d25b9ea`](https://github.com/mastra-ai/mastra/commit/d25b9eabd400167255a97b690ffbc4ee4097ded5), [`fe1ce5c`](https://github.com/mastra-ai/mastra/commit/fe1ce5c9211c03d561606fda95cbfe7df1d9a9b5), [`b03c0e0`](https://github.com/mastra-ai/mastra/commit/b03c0e0389a799523929a458b0509c9e4244d562), [`0a8366b`](https://github.com/mastra-ai/mastra/commit/0a8366b0a692fcdde56c4d526e4cf03c502ae4ac), [`85664e9`](https://github.com/mastra-ai/mastra/commit/85664e9fd857320fbc245e301f764f45f66f32a3), [`bc79650`](https://github.com/mastra-ai/mastra/commit/bc796500c6e0334faa158a96077e3fb332274869), [`9257d01`](https://github.com/mastra-ai/mastra/commit/9257d01d1366d81f84c582fe02b5e200cf9621f4), [`3a3a59e`](https://github.com/mastra-ai/mastra/commit/3a3a59e8ffaa6a985fe3d9a126a3f5ade11a6724), [`3108d4e`](https://github.com/mastra-ai/mastra/commit/3108d4e649c9fddbf03253a6feeb388a5fa9fa5a), [`0c33b2c`](https://github.com/mastra-ai/mastra/commit/0c33b2c9db537f815e1c59e2c898ffce2e395a79), [`191e5bd`](https://github.com/mastra-ai/mastra/commit/191e5bd29b82f5bda35243945790da7bc7b695c2), [`f77cd94`](https://github.com/mastra-ai/mastra/commit/f77cd94c44eabed490384e7d19232a865e13214c), [`e8135c7`](https://github.com/mastra-ai/mastra/commit/e8135c7e300dac5040670eec7eab896ac6092e30), [`daca48f`](https://github.com/mastra-ai/mastra/commit/daca48f0fb17b7ae0b62a2ac40cf0e491b2fd0b7), [`257d14f`](https://github.com/mastra-ai/mastra/commit/257d14faca5931f2e4186fc165b6f0b1f915deee), [`352f25d`](https://github.com/mastra-ai/mastra/commit/352f25da316b24cdd5b410fd8dddf6a8b763da2a), [`93477d0`](https://github.com/mastra-ai/mastra/commit/93477d0769b8a13ea5ed73d508d967fb23eaeed9), [`31c78b3`](https://github.com/mastra-ai/mastra/commit/31c78b3eb28f58a8017f1dcc795c33214d87feac), [`0bc0720`](https://github.com/mastra-ai/mastra/commit/0bc07201095791858087cc56f353fcd65e87ab54), [`36516ac`](https://github.com/mastra-ai/mastra/commit/36516aca1021cbeb42e74751b46a2614101f37c8), [`e947652`](https://github.com/mastra-ai/mastra/commit/e9476527fdecb4449e54570e80dfaf8466901254), [`3c6ef79`](https://github.com/mastra-ai/mastra/commit/3c6ef798481e00d6d22563be2de98818fd4dd5e0), [`9257d01`](https://github.com/mastra-ai/mastra/commit/9257d01d1366d81f84c582fe02b5e200cf9621f4), [`ec248f6`](https://github.com/mastra-ai/mastra/commit/ec248f6b56e8a037c066c49b2178e2507471d988)]:
|
|
28
|
+
- @mastra/core@1.9.0-alpha.0
|
|
29
|
+
|
|
3
30
|
## 1.5.2
|
|
4
31
|
|
|
5
32
|
### Patch Changes
|
package/LICENSE.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
Portions of this software are licensed as follows:
|
|
2
|
+
|
|
3
|
+
- All content that resides under any directory named "ee/" within this
|
|
4
|
+
repository, including but not limited to:
|
|
5
|
+
- `packages/core/src/auth/ee/`
|
|
6
|
+
- `packages/server/src/server/auth/ee/`
|
|
7
|
+
is licensed under the license defined in `ee/LICENSE`.
|
|
8
|
+
|
|
9
|
+
- All third-party components incorporated into the Mastra Software are
|
|
10
|
+
licensed under the original license provided by the owner of the
|
|
11
|
+
applicable component.
|
|
12
|
+
|
|
13
|
+
- Content outside of the above-mentioned directories or restrictions is
|
|
14
|
+
available under the "Apache License 2.0" as defined below.
|
|
15
|
+
|
|
1
16
|
# Apache License 2.0
|
|
2
17
|
|
|
3
18
|
Copyright (c) 2025 Kepler Software, Inc.
|
|
@@ -1622,6 +1622,11 @@ See https://mastra.ai/docs/memory/observational-memory#models for model recommen
|
|
|
1622
1622
|
const messageTokens = config.observation?.messageTokens ?? OBSERVATIONAL_MEMORY_DEFAULTS.observation.messageTokens;
|
|
1623
1623
|
const observationTokens = config.reflection?.observationTokens ?? OBSERVATIONAL_MEMORY_DEFAULTS.reflection.observationTokens;
|
|
1624
1624
|
const isSharedBudget = config.shareTokenBudget ?? false;
|
|
1625
|
+
const isDefaultModelSelection = (model) => model === void 0 || model === "default";
|
|
1626
|
+
const observationSelectedModel = config.model ?? config.observation?.model ?? config.reflection?.model;
|
|
1627
|
+
const reflectionSelectedModel = config.model ?? config.reflection?.model ?? config.observation?.model;
|
|
1628
|
+
const observationDefaultMaxOutputTokens = config.observation?.modelSettings?.maxOutputTokens ?? (isDefaultModelSelection(observationSelectedModel) ? OBSERVATIONAL_MEMORY_DEFAULTS.observation.modelSettings.maxOutputTokens : void 0);
|
|
1629
|
+
const reflectionDefaultMaxOutputTokens = config.reflection?.modelSettings?.maxOutputTokens ?? (isDefaultModelSelection(reflectionSelectedModel) ? OBSERVATIONAL_MEMORY_DEFAULTS.reflection.modelSettings.maxOutputTokens : void 0);
|
|
1625
1630
|
const totalBudget = messageTokens + observationTokens;
|
|
1626
1631
|
const userExplicitlyConfiguredAsync = config.observation?.bufferTokens !== void 0 || config.observation?.bufferActivation !== void 0 || config.reflection?.bufferActivation !== void 0;
|
|
1627
1632
|
const asyncBufferingDisabled = config.observation?.bufferTokens === false || config.scope === "resource" && !userExplicitlyConfiguredAsync;
|
|
@@ -1653,7 +1658,7 @@ Async buffering is enabled by default \u2014 this opt-out is only needed when us
|
|
|
1653
1658
|
shareTokenBudget: isSharedBudget,
|
|
1654
1659
|
modelSettings: {
|
|
1655
1660
|
temperature: config.observation?.modelSettings?.temperature ?? OBSERVATIONAL_MEMORY_DEFAULTS.observation.modelSettings.temperature,
|
|
1656
|
-
maxOutputTokens:
|
|
1661
|
+
...observationDefaultMaxOutputTokens !== void 0 ? { maxOutputTokens: observationDefaultMaxOutputTokens } : {}
|
|
1657
1662
|
},
|
|
1658
1663
|
providerOptions: config.observation?.providerOptions ?? OBSERVATIONAL_MEMORY_DEFAULTS.observation.providerOptions,
|
|
1659
1664
|
maxTokensPerBatch: config.observation?.maxTokensPerBatch ?? OBSERVATIONAL_MEMORY_DEFAULTS.observation.maxTokensPerBatch,
|
|
@@ -1674,7 +1679,7 @@ Async buffering is enabled by default \u2014 this opt-out is only needed when us
|
|
|
1674
1679
|
shareTokenBudget: isSharedBudget,
|
|
1675
1680
|
modelSettings: {
|
|
1676
1681
|
temperature: config.reflection?.modelSettings?.temperature ?? OBSERVATIONAL_MEMORY_DEFAULTS.reflection.modelSettings.temperature,
|
|
1677
|
-
maxOutputTokens:
|
|
1682
|
+
...reflectionDefaultMaxOutputTokens !== void 0 ? { maxOutputTokens: reflectionDefaultMaxOutputTokens } : {}
|
|
1678
1683
|
},
|
|
1679
1684
|
providerOptions: config.reflection?.providerOptions ?? OBSERVATIONAL_MEMORY_DEFAULTS.reflection.providerOptions,
|
|
1680
1685
|
bufferActivation: asyncBufferingDisabled ? void 0 : config?.reflection?.bufferActivation ?? OBSERVATIONAL_MEMORY_DEFAULTS.reflection.bufferActivation,
|
|
@@ -2416,18 +2421,17 @@ Async buffering is enabled by default \u2014 this opt-out is only needed when us
|
|
|
2416
2421
|
const agent = this.getObserverAgent();
|
|
2417
2422
|
const prompt = buildObserverPrompt(existingObservations, messagesToObserve, options);
|
|
2418
2423
|
const doGenerate = async () => {
|
|
2419
|
-
|
|
2420
|
-
|
|
2424
|
+
return this.withAbortCheck(async () => {
|
|
2425
|
+
const streamResult = await agent.stream(prompt, {
|
|
2421
2426
|
modelSettings: {
|
|
2422
2427
|
...this.observationConfig.modelSettings
|
|
2423
2428
|
},
|
|
2424
2429
|
providerOptions: this.observationConfig.providerOptions,
|
|
2425
2430
|
...abortSignal ? { abortSignal } : {},
|
|
2426
2431
|
...options?.requestContext ? { requestContext: options.requestContext } : {}
|
|
2427
|
-
})
|
|
2428
|
-
|
|
2429
|
-
);
|
|
2430
|
-
return result2;
|
|
2432
|
+
});
|
|
2433
|
+
return streamResult.getFullOutput();
|
|
2434
|
+
}, abortSignal);
|
|
2431
2435
|
};
|
|
2432
2436
|
let result = await doGenerate();
|
|
2433
2437
|
let parsed = parseObserverOutput(result.text);
|
|
@@ -2474,17 +2478,17 @@ Async buffering is enabled by default \u2014 this opt-out is only needed when us
|
|
|
2474
2478
|
this.observedMessageIds.add(msg.id);
|
|
2475
2479
|
}
|
|
2476
2480
|
const doGenerate = async () => {
|
|
2477
|
-
return this.withAbortCheck(
|
|
2478
|
-
|
|
2481
|
+
return this.withAbortCheck(async () => {
|
|
2482
|
+
const streamResult = await agent$1.stream(prompt, {
|
|
2479
2483
|
modelSettings: {
|
|
2480
2484
|
...this.observationConfig.modelSettings
|
|
2481
2485
|
},
|
|
2482
2486
|
providerOptions: this.observationConfig.providerOptions,
|
|
2483
2487
|
...abortSignal ? { abortSignal } : {},
|
|
2484
2488
|
...requestContext ? { requestContext } : {}
|
|
2485
|
-
})
|
|
2486
|
-
|
|
2487
|
-
);
|
|
2489
|
+
});
|
|
2490
|
+
return streamResult.getFullOutput();
|
|
2491
|
+
}, abortSignal);
|
|
2488
2492
|
};
|
|
2489
2493
|
let result = await doGenerate();
|
|
2490
2494
|
let parsed = parseMultiThreadObserverOutput(result.text);
|
|
@@ -2542,8 +2546,8 @@ Async buffering is enabled by default \u2014 this opt-out is only needed when us
|
|
|
2542
2546
|
`[OM:callReflector] ${isRetry ? `retry #${attemptNumber - 1}` : "first attempt"}: level=${currentLevel}, originalTokens=${originalTokens}, targetThreshold=${targetThreshold}, promptLen=${prompt.length}, skipContinuationHints=${skipContinuationHints}`
|
|
2543
2547
|
);
|
|
2544
2548
|
let chunkCount = 0;
|
|
2545
|
-
const result = await this.withAbortCheck(
|
|
2546
|
-
|
|
2549
|
+
const result = await this.withAbortCheck(async () => {
|
|
2550
|
+
const streamResult = await agent.stream(prompt, {
|
|
2547
2551
|
modelSettings: {
|
|
2548
2552
|
...this.reflectionConfig.modelSettings
|
|
2549
2553
|
},
|
|
@@ -2570,9 +2574,9 @@ Async buffering is enabled by default \u2014 this opt-out is only needed when us
|
|
|
2570
2574
|
omError(`[OM:callReflector] onError after ${chunkCount} chunks`, error);
|
|
2571
2575
|
}
|
|
2572
2576
|
} : {}
|
|
2573
|
-
})
|
|
2574
|
-
|
|
2575
|
-
);
|
|
2577
|
+
});
|
|
2578
|
+
return streamResult.getFullOutput();
|
|
2579
|
+
}, abortSignal);
|
|
2576
2580
|
omDebug(
|
|
2577
2581
|
`[OM:callReflector] attempt #${attemptNumber} returned: textLen=${result.text?.length}, textPreview="${result.text?.slice(0, 120)}...", inputTokens=${result.usage?.inputTokens ?? result.totalUsage?.inputTokens}, outputTokens=${result.usage?.outputTokens ?? result.totalUsage?.outputTokens}`
|
|
2578
2582
|
);
|
|
@@ -2911,19 +2915,17 @@ ${suggestedResponse}
|
|
|
2911
2915
|
omDebug(
|
|
2912
2916
|
`[OM:threshold] activation succeeded, obsTokens=${updatedRecord.observationTokenCount}, activeObsLen=${updatedRecord.activeObservations?.length}`
|
|
2913
2917
|
);
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
});
|
|
2926
|
-
}
|
|
2918
|
+
const thread = await this.storage.getThreadById({ threadId });
|
|
2919
|
+
if (thread) {
|
|
2920
|
+
const newMetadata = memory.setThreadOMMetadata(thread.metadata, {
|
|
2921
|
+
suggestedResponse: activationResult.suggestedContinuation,
|
|
2922
|
+
currentTask: activationResult.currentTask
|
|
2923
|
+
});
|
|
2924
|
+
await this.storage.updateThread({
|
|
2925
|
+
id: threadId,
|
|
2926
|
+
title: thread.title ?? "",
|
|
2927
|
+
metadata: newMetadata
|
|
2928
|
+
});
|
|
2927
2929
|
}
|
|
2928
2930
|
await this.maybeAsyncReflect(
|
|
2929
2931
|
updatedRecord,
|
|
@@ -3279,19 +3281,17 @@ ${suggestedResponse}
|
|
|
3279
3281
|
_ObservationalMemory.lastBufferedBoundary.set(bufKey, 0);
|
|
3280
3282
|
this.storage.setBufferingObservationFlag(record.id, false, 0).catch(() => {
|
|
3281
3283
|
});
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
});
|
|
3294
|
-
}
|
|
3284
|
+
const thread = await this.storage.getThreadById({ threadId });
|
|
3285
|
+
if (thread) {
|
|
3286
|
+
const newMetadata = memory.setThreadOMMetadata(thread.metadata, {
|
|
3287
|
+
suggestedResponse: activationResult.suggestedContinuation,
|
|
3288
|
+
currentTask: activationResult.currentTask
|
|
3289
|
+
});
|
|
3290
|
+
await this.storage.updateThread({
|
|
3291
|
+
id: threadId,
|
|
3292
|
+
title: thread.title ?? "",
|
|
3293
|
+
metadata: newMetadata
|
|
3294
|
+
});
|
|
3295
3295
|
}
|
|
3296
3296
|
await this.maybeReflect({
|
|
3297
3297
|
record,
|
|
@@ -3510,24 +3510,30 @@ ${suggestedResponse}
|
|
|
3510
3510
|
return messageList;
|
|
3511
3511
|
}
|
|
3512
3512
|
/**
|
|
3513
|
-
* Save messages to storage
|
|
3514
|
-
* previously saved with observation markers (sealed).
|
|
3513
|
+
* Save messages to storage while preventing duplicate inserts for sealed messages.
|
|
3515
3514
|
*
|
|
3516
|
-
*
|
|
3517
|
-
*
|
|
3515
|
+
* Sealed messages that do not yet contain a completed observation boundary are
|
|
3516
|
+
* skipped because async buffering already persisted them.
|
|
3518
3517
|
*/
|
|
3519
3518
|
async saveMessagesWithSealedIdTracking(messagesToSave, sealedIds, threadId, resourceId, state) {
|
|
3519
|
+
const filteredMessages = [];
|
|
3520
3520
|
for (const msg of messagesToSave) {
|
|
3521
3521
|
if (sealedIds.has(msg.id)) {
|
|
3522
|
-
|
|
3522
|
+
if (this.findLastCompletedObservationBoundary(msg) !== -1) {
|
|
3523
|
+
filteredMessages.push(msg);
|
|
3524
|
+
}
|
|
3525
|
+
} else {
|
|
3526
|
+
filteredMessages.push(msg);
|
|
3523
3527
|
}
|
|
3524
3528
|
}
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3529
|
+
if (filteredMessages.length > 0) {
|
|
3530
|
+
await this.messageHistory.persistMessages({
|
|
3531
|
+
messages: filteredMessages,
|
|
3532
|
+
threadId,
|
|
3533
|
+
resourceId
|
|
3534
|
+
});
|
|
3535
|
+
}
|
|
3536
|
+
for (const msg of filteredMessages) {
|
|
3531
3537
|
if (this.findLastCompletedObservationBoundary(msg) !== -1) {
|
|
3532
3538
|
sealedIds.add(msg.id);
|
|
3533
3539
|
}
|
|
@@ -3810,19 +3816,17 @@ ${result.observations}` : result.observations;
|
|
|
3810
3816
|
const newMessageIds = messagesToObserve.map((m) => m.id);
|
|
3811
3817
|
const existingIds = freshRecord?.observedMessageIds ?? record.observedMessageIds ?? [];
|
|
3812
3818
|
const allObservedIds = [.../* @__PURE__ */ new Set([...Array.isArray(existingIds) ? existingIds : [], ...newMessageIds])];
|
|
3813
|
-
|
|
3814
|
-
|
|
3815
|
-
|
|
3816
|
-
|
|
3817
|
-
|
|
3818
|
-
|
|
3819
|
-
|
|
3820
|
-
|
|
3821
|
-
|
|
3822
|
-
|
|
3823
|
-
|
|
3824
|
-
});
|
|
3825
|
-
}
|
|
3819
|
+
const thread = await this.storage.getThreadById({ threadId });
|
|
3820
|
+
if (thread) {
|
|
3821
|
+
const newMetadata = memory.setThreadOMMetadata(thread.metadata, {
|
|
3822
|
+
suggestedResponse: result.suggestedContinuation,
|
|
3823
|
+
currentTask: result.currentTask
|
|
3824
|
+
});
|
|
3825
|
+
await this.storage.updateThread({
|
|
3826
|
+
id: threadId,
|
|
3827
|
+
title: thread.title ?? "",
|
|
3828
|
+
metadata: newMetadata
|
|
3829
|
+
});
|
|
3826
3830
|
}
|
|
3827
3831
|
await this.storage.updateActiveObservations({
|
|
3828
3832
|
id: record.id,
|
|
@@ -4058,7 +4062,7 @@ ${result.observations}` : result.observations;
|
|
|
4058
4062
|
messagesToBuffer,
|
|
4059
4063
|
void 0,
|
|
4060
4064
|
// No abort signal for background ops
|
|
4061
|
-
{ requestContext }
|
|
4065
|
+
{ skipContinuationHints: true, requestContext }
|
|
4062
4066
|
);
|
|
4063
4067
|
if (!result.observations) {
|
|
4064
4068
|
omDebug(`[OM:doAsyncBufferedObservation] empty observations returned, skipping buffer storage`);
|
|
@@ -4676,8 +4680,8 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
|
|
|
4676
4680
|
if (thread) {
|
|
4677
4681
|
const newMetadata = memory.setThreadOMMetadata(thread.metadata, {
|
|
4678
4682
|
lastObservedAt: threadLastObservedAt.toISOString(),
|
|
4679
|
-
|
|
4680
|
-
|
|
4683
|
+
suggestedResponse: result.suggestedContinuation,
|
|
4684
|
+
currentTask: result.currentTask
|
|
4681
4685
|
});
|
|
4682
4686
|
await this.storage.updateThread({
|
|
4683
4687
|
id: threadId,
|
|
@@ -5128,5 +5132,5 @@ exports.formatMessagesForObserver = formatMessagesForObserver;
|
|
|
5128
5132
|
exports.hasCurrentTaskSection = hasCurrentTaskSection;
|
|
5129
5133
|
exports.optimizeObservationsForContext = optimizeObservationsForContext;
|
|
5130
5134
|
exports.parseObserverOutput = parseObserverOutput;
|
|
5131
|
-
//# sourceMappingURL=chunk-
|
|
5132
|
-
//# sourceMappingURL=chunk-
|
|
5135
|
+
//# sourceMappingURL=chunk-5UYAHJVJ.cjs.map
|
|
5136
|
+
//# sourceMappingURL=chunk-5UYAHJVJ.cjs.map
|