@mastra/memory 1.41.4-alpha.1 → 1.42.0-alpha.3

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.
@@ -3,7 +3,7 @@ name: mastra-memory
3
3
  description: Documentation for @mastra/memory. Use when working with @mastra/memory APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/memory"
6
- version: "1.41.4-alpha.1"
6
+ version: "1.42.0-alpha.3"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,243 +1,243 @@
1
1
  {
2
- "version": "1.41.4-alpha.1",
2
+ "version": "1.42.0-alpha.3",
3
3
  "package": "@mastra/memory",
4
4
  "exports": {
5
5
  "AUTO_MODEL_BY_PROVIDER": {
6
6
  "types": "dist/processors/observational-memory/auto-model.d.ts",
7
- "implementation": "dist/src-SlK5VIXE.js",
8
- "line": 32945
7
+ "implementation": "dist/src-CHDmfrJu.js",
8
+ "line": 32963
9
9
  },
10
10
  "Extractor": {
11
11
  "types": "dist/processors/observational-memory/extractor.d.ts",
12
- "implementation": "dist/src-SlK5VIXE.js",
12
+ "implementation": "dist/src-CHDmfrJu.js",
13
13
  "line": 24432
14
14
  },
15
15
  "ModelByInputTokens": {
16
16
  "types": "dist/processors/observational-memory/model-by-input-tokens.d.ts",
17
- "implementation": "dist/src-SlK5VIXE.js",
18
- "line": 32728
17
+ "implementation": "dist/src-CHDmfrJu.js",
18
+ "line": 32746
19
19
  },
20
20
  "OBSERVATIONAL_MEMORY_DEFAULTS": {
21
21
  "types": "dist/processors/observational-memory/constants.d.ts",
22
- "implementation": "dist/src-SlK5VIXE.js",
22
+ "implementation": "dist/src-CHDmfrJu.js",
23
23
  "line": 24168
24
24
  },
25
25
  "OBSERVATION_CONTEXT_INSTRUCTIONS": {
26
26
  "types": "dist/processors/observational-memory/constants.d.ts",
27
- "implementation": "dist/src-SlK5VIXE.js",
27
+ "implementation": "dist/src-CHDmfrJu.js",
28
28
  "line": 24229
29
29
  },
30
30
  "OBSERVATION_CONTEXT_PROMPT": {
31
31
  "types": "dist/processors/observational-memory/constants.d.ts",
32
- "implementation": "dist/src-SlK5VIXE.js",
32
+ "implementation": "dist/src-CHDmfrJu.js",
33
33
  "line": 24211
34
34
  },
35
35
  "OBSERVATION_CONTEXT_PROMPT_THREAD": {
36
36
  "types": "dist/processors/observational-memory/constants.d.ts",
37
- "implementation": "dist/src-SlK5VIXE.js",
37
+ "implementation": "dist/src-CHDmfrJu.js",
38
38
  "line": 24216
39
39
  },
40
40
  "OBSERVATION_CONTINUATION_HINT": {
41
41
  "types": "dist/processors/observational-memory/constants.d.ts",
42
- "implementation": "dist/src-SlK5VIXE.js",
42
+ "implementation": "dist/src-CHDmfrJu.js",
43
43
  "line": 24198
44
44
  },
45
45
  "OBSERVER_SYSTEM_PROMPT": {
46
46
  "types": "dist/processors/observational-memory/observer-agent.d.ts",
47
- "implementation": "dist/src-SlK5VIXE.js",
48
- "line": 26880
47
+ "implementation": "dist/src-CHDmfrJu.js",
48
+ "line": 26898
49
49
  },
50
50
  "ObservationalMemory": {
51
51
  "types": "dist/processors/observational-memory/observational-memory.d.ts",
52
- "implementation": "dist/src-SlK5VIXE.js",
53
- "line": 38063
52
+ "implementation": "dist/src-CHDmfrJu.js",
53
+ "line": 38081
54
54
  },
55
55
  "ObservationalMemoryProcessor": {
56
56
  "types": "dist/processors/observational-memory/processor.d.ts",
57
- "implementation": "dist/src-SlK5VIXE.js",
58
- "line": 40898
57
+ "implementation": "dist/src-CHDmfrJu.js",
58
+ "line": 40920
59
59
  },
60
60
  "TokenCounter": {
61
61
  "types": "dist/processors/observational-memory/token-counter.d.ts",
62
- "implementation": "dist/src-SlK5VIXE.js",
63
- "line": 29410
62
+ "implementation": "dist/src-CHDmfrJu.js",
63
+ "line": 29428
64
64
  },
65
65
  "WorkingMemoryExtractor": {
66
66
  "types": "dist/processors/observational-memory/working-memory-extractor.d.ts",
67
- "implementation": "dist/src-SlK5VIXE.js",
68
- "line": 30466
67
+ "implementation": "dist/src-CHDmfrJu.js",
68
+ "line": 30484
69
69
  },
70
70
  "buildObserverPrompt": {
71
71
  "types": "dist/processors/observational-memory/observer-agent.d.ts",
72
- "implementation": "dist/src-SlK5VIXE.js",
73
- "line": 27562
72
+ "implementation": "dist/src-CHDmfrJu.js",
73
+ "line": 27580
74
74
  },
75
75
  "buildObserverSystemPrompt": {
76
76
  "types": "dist/processors/observational-memory/observer-agent.d.ts",
77
- "implementation": "dist/src-SlK5VIXE.js",
78
- "line": 26774
77
+ "implementation": "dist/src-CHDmfrJu.js",
78
+ "line": 26792
79
79
  },
80
80
  "combineObservationGroupRanges": {
81
81
  "types": "dist/processors/observational-memory/observation-groups.d.ts",
82
- "implementation": "dist/src-SlK5VIXE.js",
83
- "line": 31048
82
+ "implementation": "dist/src-CHDmfrJu.js",
83
+ "line": 31066
84
84
  },
85
85
  "deriveObservationGroupProvenance": {
86
86
  "types": "dist/processors/observational-memory/observation-groups.d.ts",
87
- "implementation": "dist/src-SlK5VIXE.js",
88
- "line": 31092
87
+ "implementation": "dist/src-CHDmfrJu.js",
88
+ "line": 31110
89
89
  },
90
90
  "extractCurrentTask": {
91
91
  "types": "dist/processors/observational-memory/observer-agent.d.ts",
92
- "implementation": "dist/src-SlK5VIXE.js",
93
- "line": 27875
92
+ "implementation": "dist/src-CHDmfrJu.js",
93
+ "line": 27893
94
94
  },
95
95
  "formatMessagesForObserver": {
96
96
  "types": "dist/processors/observational-memory/observer-agent.d.ts",
97
- "implementation": "dist/src-SlK5VIXE.js",
98
- "line": 27313
97
+ "implementation": "dist/src-CHDmfrJu.js",
98
+ "line": 27331
99
99
  },
100
100
  "getObservationContextPrompt": {
101
101
  "types": "dist/processors/observational-memory/constants.d.ts",
102
- "implementation": "dist/src-SlK5VIXE.js",
102
+ "implementation": "dist/src-CHDmfrJu.js",
103
103
  "line": 24222
104
104
  },
105
105
  "getObservationsAsOf": {
106
106
  "types": "dist/processors/observational-memory/observation-utils.d.ts",
107
- "implementation": "dist/src-SlK5VIXE.js",
108
- "line": 41244
107
+ "implementation": "dist/src-CHDmfrJu.js",
108
+ "line": 41266
109
109
  },
110
110
  "hasCurrentTaskSection": {
111
111
  "types": "dist/processors/observational-memory/observer-agent.d.ts",
112
- "implementation": "dist/src-SlK5VIXE.js",
113
- "line": 27863
112
+ "implementation": "dist/src-CHDmfrJu.js",
113
+ "line": 27881
114
114
  },
115
115
  "injectAnchorIds": {
116
116
  "types": "dist/processors/observational-memory/anchor-ids.d.ts",
117
- "implementation": "dist/src-SlK5VIXE.js",
117
+ "implementation": "dist/src-CHDmfrJu.js",
118
118
  "line": 25432
119
119
  },
120
120
  "optimizeObservationsForContext": {
121
121
  "types": "dist/processors/observational-memory/observer-agent.d.ts",
122
- "implementation": "dist/src-SlK5VIXE.js",
123
- "line": 27896
122
+ "implementation": "dist/src-CHDmfrJu.js",
123
+ "line": 27914
124
124
  },
125
125
  "parseAnchorId": {
126
126
  "types": "dist/processors/observational-memory/anchor-ids.d.ts",
127
- "implementation": "dist/src-SlK5VIXE.js",
127
+ "implementation": "dist/src-CHDmfrJu.js",
128
128
  "line": 25416
129
129
  },
130
130
  "parseObservationGroups": {
131
131
  "types": "dist/processors/observational-memory/observation-groups.d.ts",
132
- "implementation": "dist/src-SlK5VIXE.js",
133
- "line": 31003
132
+ "implementation": "dist/src-CHDmfrJu.js",
133
+ "line": 31021
134
134
  },
135
135
  "parseObserverOutput": {
136
136
  "types": "dist/processors/observational-memory/observer-agent.d.ts",
137
- "implementation": "dist/src-SlK5VIXE.js",
138
- "line": 27573
137
+ "implementation": "dist/src-CHDmfrJu.js",
138
+ "line": 27591
139
139
  },
140
140
  "reconcileObservationGroupsFromReflection": {
141
141
  "types": "dist/processors/observational-memory/observation-groups.d.ts",
142
- "implementation": "dist/src-SlK5VIXE.js",
143
- "line": 31111
142
+ "implementation": "dist/src-CHDmfrJu.js",
143
+ "line": 31129
144
144
  },
145
145
  "renderObservationGroupsForReflection": {
146
146
  "types": "dist/processors/observational-memory/observation-groups.d.ts",
147
- "implementation": "dist/src-SlK5VIXE.js",
148
- "line": 31077
147
+ "implementation": "dist/src-CHDmfrJu.js",
148
+ "line": 31095
149
149
  },
150
150
  "resolveAutoModelId": {
151
151
  "types": "dist/processors/observational-memory/auto-model.d.ts",
152
- "implementation": "dist/src-SlK5VIXE.js",
153
- "line": 32965
152
+ "implementation": "dist/src-CHDmfrJu.js",
153
+ "line": 32983
154
154
  },
155
155
  "stripEphemeralAnchorIds": {
156
156
  "types": "dist/processors/observational-memory/anchor-ids.d.ts",
157
- "implementation": "dist/src-SlK5VIXE.js",
157
+ "implementation": "dist/src-CHDmfrJu.js",
158
158
  "line": 25455
159
159
  },
160
160
  "stripObservationGroups": {
161
161
  "types": "dist/processors/observational-memory/observation-groups.d.ts",
162
- "implementation": "dist/src-SlK5VIXE.js",
163
- "line": 31020
162
+ "implementation": "dist/src-CHDmfrJu.js",
163
+ "line": 31038
164
164
  },
165
165
  "summarizeConversation": {
166
166
  "types": "dist/processors/observational-memory/summarize.d.ts",
167
- "implementation": "dist/src-SlK5VIXE.js",
168
- "line": 30078
167
+ "implementation": "dist/src-CHDmfrJu.js",
168
+ "line": 30096
169
169
  },
170
170
  "wrapInObservationGroup": {
171
171
  "types": "dist/processors/observational-memory/observation-groups.d.ts",
172
- "implementation": "dist/src-SlK5VIXE.js",
173
- "line": 30974
172
+ "implementation": "dist/src-CHDmfrJu.js",
173
+ "line": 30992
174
174
  },
175
175
  "KnowledgeSemanticIndexCoordinator": {
176
176
  "types": "dist/removed-subconscious.d.ts",
177
- "implementation": "dist/src-SlK5VIXE.js",
178
- "line": 30572
177
+ "implementation": "dist/src-CHDmfrJu.js",
178
+ "line": 30590
179
179
  },
180
180
  "Memory": {
181
181
  "types": "dist/index.d.ts",
182
- "implementation": "dist/src-SlK5VIXE.js",
183
- "line": 41496
182
+ "implementation": "dist/src-CHDmfrJu.js",
183
+ "line": 41518
184
184
  },
185
185
  "SUMMARIZE_THREAD_DEFAULTS": {
186
186
  "types": "dist/processors/observational-memory/summarize.d.ts",
187
- "implementation": "dist/src-SlK5VIXE.js",
188
- "line": 30034
187
+ "implementation": "dist/src-CHDmfrJu.js",
188
+ "line": 30052
189
189
  },
190
190
  "StaleKnowledgeSemanticIndexError": {
191
191
  "types": "dist/removed-subconscious.d.ts",
192
- "implementation": "dist/src-SlK5VIXE.js",
193
- "line": 30578
192
+ "implementation": "dist/src-CHDmfrJu.js",
193
+ "line": 30596
194
194
  },
195
195
  "Subconscious": {
196
196
  "types": "dist/removed-subconscious.d.ts",
197
- "implementation": "dist/src-SlK5VIXE.js",
198
- "line": 30566
197
+ "implementation": "dist/src-CHDmfrJu.js",
198
+ "line": 30584
199
199
  },
200
200
  "WORKING_MEMORY_STATE_ID": {
201
201
  "types": "dist/processors/working-memory-state/processor.d.ts",
202
- "implementation": "dist/src-SlK5VIXE.js",
203
- "line": 32774
202
+ "implementation": "dist/src-CHDmfrJu.js",
203
+ "line": 32792
204
204
  },
205
205
  "WORKING_MEMORY_STATE_PROCESSOR_ID": {
206
206
  "types": "dist/processors/working-memory-state/processor.d.ts",
207
- "implementation": "dist/src-SlK5VIXE.js",
208
- "line": 32775
207
+ "implementation": "dist/src-CHDmfrJu.js",
208
+ "line": 32793
209
209
  },
210
210
  "WorkingMemoryStateProcessor": {
211
211
  "types": "dist/processors/working-memory-state/processor.d.ts",
212
- "implementation": "dist/src-SlK5VIXE.js",
213
- "line": 32776
212
+ "implementation": "dist/src-CHDmfrJu.js",
213
+ "line": 32794
214
214
  },
215
215
  "deepMergeWorkingMemory": {
216
216
  "types": "dist/tools/working-memory.d.ts",
217
- "implementation": "dist/src-SlK5VIXE.js",
218
- "line": 30157
217
+ "implementation": "dist/src-CHDmfrJu.js",
218
+ "line": 30175
219
219
  },
220
220
  "extractWorkingMemoryContent": {
221
221
  "types": "dist/index.d.ts",
222
- "implementation": "dist/src-SlK5VIXE.js",
223
- "line": 41309
222
+ "implementation": "dist/src-CHDmfrJu.js",
223
+ "line": 41331
224
224
  },
225
225
  "extractWorkingMemoryTags": {
226
226
  "types": "dist/index.d.ts",
227
- "implementation": "dist/src-SlK5VIXE.js",
228
- "line": 41277
227
+ "implementation": "dist/src-CHDmfrJu.js",
228
+ "line": 41299
229
229
  },
230
230
  "removeWorkingMemoryTags": {
231
231
  "types": "dist/index.d.ts",
232
- "implementation": "dist/src-SlK5VIXE.js",
233
- "line": 41290
232
+ "implementation": "dist/src-CHDmfrJu.js",
233
+ "line": 41312
234
234
  }
235
235
  },
236
236
  "modules": {
237
237
  "processors": {
238
238
  "index": "dist/processors/index.js",
239
239
  "chunks": [
240
- "src-SlK5VIXE.js"
240
+ "src-CHDmfrJu.js"
241
241
  ]
242
242
  }
243
243
  }
@@ -41,6 +41,8 @@ const { thread, clonedMessages } = await memory.cloneThread({
41
41
 
42
42
  **options.messageLimit** (`number`): Maximum number of messages to clone. When set, clones the most recent N messages.
43
43
 
44
+ **options.contextWindowOnly** (`boolean`): Clone only the messages still in the context window. With Observational Memory configured and a source thread it has observed, that is the messages after lastObservedAt. Can't be combined with messageLimit or messageFilter.
45
+
44
46
  **options.messageFilter** (`MessageFilter`): Filter criteria for selecting which messages to clone.
45
47
 
46
48
  **options.messageFilter.startDate** (`Date`): Only clone messages created on or after this date.
@@ -174,4 +176,19 @@ When [Observational Memory](https://mastra.ai/docs/memory/observational-memory)
174
176
  - **Resource-scoped OM (deprecated, same `resourceId`)**: The OM record is shared between the source and cloned threads since they belong to the same resource. No duplication occurs.
175
177
  - **Resource-scoped OM (deprecated, different `resourceId`)**: The OM record is cloned to the new resource. Message IDs are remapped and any thread-identifying tags within observations are updated to reference the cloned thread.
176
178
 
177
- Only the current (most recent) OM generation is cloned. Older history generations aren't copied. Transient processing state (observation/reflection in-progress flags) is reset on the cloned record.
179
+ Only the current (most recent) OM generation is cloned. Older history generations aren't copied. Transient processing state (observation/reflection in-progress flags) is reset on the cloned record.
180
+
181
+ ### Copying only the context window
182
+
183
+ By default `cloneThread()` copies every message. Pass `contextWindowOnly: true` to copy only the messages in the context window. When OM is configured on the `Memory` instance and the source thread has observations, those are the messages created after `lastObservedAt` on the OM record the configured scope reads. The observations already carry the earlier messages. The source thread keeps all of its messages. When records exist for both scopes, the clone carries the one the configured scope reads.
184
+
185
+ With thread-scoped OM, the clone starts with the same context as the source: the same observations and the same unobserved messages. With resource-scoped OM cloned within the same resource, the clone shares the source's OM record, and the copied messages sit beside the originals in the resource. The resource's context can then hold both copies of each unobserved message. A resource-scoped clone into another resource doesn't carry the unobserved messages of the source resource's other threads.
186
+
187
+ The clone's stored message history holds only the copied messages, and thread-scoped semantic recall searches only those. Semantic recall with resource scope, the default, searches every thread of the resource. In a clone within the same resource it can still return the source's earlier messages. Without OM configured, or when OM hasn't observed anything yet, every message is still copied.
188
+
189
+ ```typescript
190
+ const { thread } = await memory.cloneThread({
191
+ sourceThreadId: 'thread-123',
192
+ options: { contextWindowOnly: true },
193
+ })
194
+ ```
@@ -41,6 +41,8 @@ const { thread, messageIdMap } = await memory.copyThread({
41
41
 
42
42
  **options.messageLimit** (`number`): Maximum number of messages to copy. When set, copies the most recent N messages.
43
43
 
44
+ **options.contextWindowOnly** (`boolean`): Copy only the messages still in the context window. With Observational Memory configured and a source thread it has observed, that is the messages after lastObservedAt. Can't be combined with messageLimit or messageFilter.
45
+
44
46
  **options.messageFilter** (`MessageFilter`): Filter criteria for selecting which messages to copy, by date range or message IDs.
45
47
 
46
48
  ## Returns
@@ -35,8 +35,12 @@ Observer input is multimodal-aware. OM keeps text placeholders like `[Image #1:
35
35
 
36
36
  OM performs thresholding with fast local token estimation. Text uses `tokenx`, and image-like inputs use provider-aware heuristics plus deterministic fallbacks when metadata is incomplete.
37
37
 
38
+ By default, live date hints follow the observation block rather than changing its absolute-date prefix. The complete hint suffix is limited to 8,000 characters and 64 date cues, including its tags, current-day explanation, and any omission notice. Set `observationalMemory: { liveDateHints: false }` to omit the suffix. Unchanged observations then produce the same OM context across days. Other context sections or messages can still change.
39
+
38
40
  **enabled** (`boolean`): Enable or disable Observational Memory. When omitted from a config object, defaults to true. Only enabled: false explicitly disables it. (Default: `true`)
39
41
 
42
+ **liveDateHints** (`boolean`): Append current-day and relative-date cues after the observations, using their recorded time zone. Set to false to keep date hints out of the Actor context. Absolute dates and static date gaps remain unchanged. (Default: `true`)
43
+
40
44
  **model** (`'auto' | string | LanguageModel | DynamicModel | ModelByInputTokens | ModelWithRetries[]`): Model for both the Observer and Reflector agents. Cannot be used together with observation.model or reflection.model. When all model fields are omitted, each role defaults to "auto". Automatic selection prefers google/gemini-2.5-flash when GOOGLE_GENERATIVE_AI_API_KEY is configured, then a low-cost model for the active provider, then the active main model. Use "default" for the legacy fixed default. (Default: `'auto'`)
41
45
 
42
46
  **autoModels** (`Record<string, string>`): Overrides the model automatic selection picks for a provider, keyed by provider ID. For example, { openai: "\_\_GATEWAY_OPENAI_MODEL_LUNA\_\_" }. Providers not listed use the built-in pick.
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_src = require("./src-Cr_776no.cjs");
2
+ const require_src = require("./src-DiUUpFI9.cjs");
3
3
  let _mastra_core_processors = require("@mastra/core/processors");
4
4
  let _mastra_core_memory = require("@mastra/core/memory");
5
5
  exports.AUTO_MODEL_BY_PROVIDER = require_src.AUTO_MODEL_BY_PROVIDER;
package/dist/index.d.ts CHANGED
@@ -29,6 +29,8 @@ export type { SummarizeConversationOptions, SummarizeConversationResult, Summari
29
29
  * Inlined here to avoid importing runtime exports that don't exist on older @mastra/core versions.
30
30
  */
31
31
  type MemoryObservationalMemoryOptions = Omit<ObservationalMemoryOptions, 'model' | 'observation' | 'reflection'> & {
32
+ /** Append live relative-date cues after observations. Defaults to true. */
33
+ liveDateHints?: ObservationalMemoryConfig['liveDateHints'];
32
34
  model?: ObservationalMemoryConfig['model'];
33
35
  observation?: ObservationalMemoryConfig['observation'];
34
36
  reflection?: ObservationalMemoryConfig['reflection'];
@@ -528,9 +530,13 @@ export declare class Memory extends MastraMemory {
528
530
  * @param args.resourceId - Resource ID for the new thread (defaults to source thread's resourceId)
529
531
  * @param args.title - Title for the new cloned thread
530
532
  * @param args.metadata - Additional metadata to merge with clone metadata
531
- * @param args.options - Options for filtering which messages to include
533
+ * @param args.options - Options for filtering which messages to include. Without a filter or
534
+ * limit, every message is copied.
532
535
  * @param args.options.messageLimit - Maximum number of messages to copy (from most recent)
533
536
  * @param args.options.messageFilter - Filter messages by date range or specific IDs
537
+ * @param args.options.contextWindowOnly - With observational memory, copy only the messages after
538
+ * `lastObservedAt`, the ones still in the context window. Can't be combined with `messageFilter`
539
+ * or `messageLimit`.
534
540
  * @param memoryConfig - Optional memory configuration override
535
541
  * @returns The newly created thread and the cloned messages
536
542
  *
@@ -606,6 +612,14 @@ export declare class Memory extends MastraMemory {
606
612
  * merged, because filter-based updates replace the whole metadata object on some stores.
607
613
  */
608
614
  private moveObservationVectors;
615
+ /**
616
+ * With observational memory, the context window is the observations plus the messages created
617
+ * after `lastObservedAt`, read from the record the configured engine reads (`contextOM`), as
618
+ * `getContext` does. When the caller asks for `contextWindowOnly`, copy only those messages: the
619
+ * observations carry the rest. Otherwise copy what the caller's filter or limit selects, or every
620
+ * message. `contextWindowOnly` is `Memory`'s own option and never reaches the storage copy.
621
+ */
622
+ private withContextWindowFilter;
609
623
  /**
610
624
  * Clone observational memory records when cloning a thread.
611
625
  * Thread-scoped: always cloned to the new thread.
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export { m as AUTO_MODEL_BY_PROVIDER, K as Extractor, D as KnowledgeSemanticIndexCoordinator, t as Memory, n as MessageHistory, y as ModelByInputTokens, M as SUMMARIZE_THREAD_DEFAULTS, r as SemanticRecall, O as StaleKnowledgeSemanticIndexError, k as Subconscious, g as WORKING_MEMORY_STATE_ID, _ as WORKING_MEMORY_STATE_PROCESSOR_ID, i as WorkingMemory, A as WorkingMemoryExtractor, v as WorkingMemoryStateProcessor, a as asUserTurn, j as deepMergeWorkingMemory, o as escapeTurnMarkup, s as extractWorkingMemoryContent, c as extractWorkingMemoryTags, d as getObservationsAsOf, l as removeWorkingMemoryTags, h as resolveAutoModelId, u as sealTurnMarkup, N as summarizeConversation } from "./src-SlK5VIXE.js";
1
+ export { m as AUTO_MODEL_BY_PROVIDER, K as Extractor, D as KnowledgeSemanticIndexCoordinator, t as Memory, n as MessageHistory, y as ModelByInputTokens, M as SUMMARIZE_THREAD_DEFAULTS, r as SemanticRecall, O as StaleKnowledgeSemanticIndexError, k as Subconscious, g as WORKING_MEMORY_STATE_ID, _ as WORKING_MEMORY_STATE_PROCESSOR_ID, i as WorkingMemory, A as WorkingMemoryExtractor, v as WorkingMemoryStateProcessor, a as asUserTurn, j as deepMergeWorkingMemory, o as escapeTurnMarkup, s as extractWorkingMemoryContent, c as extractWorkingMemoryTags, d as getObservationsAsOf, l as removeWorkingMemoryTags, h as resolveAutoModelId, u as sealTurnMarkup, N as summarizeConversation } from "./src-CHDmfrJu.js";
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_src = require("../src-Cr_776no.cjs");
2
+ const require_src = require("../src-DiUUpFI9.cjs");
3
3
  exports.AUTO_MODEL_BY_PROVIDER = require_src.AUTO_MODEL_BY_PROVIDER;
4
4
  exports.Extractor = require_src.Extractor;
5
5
  exports.ModelByInputTokens = require_src.ModelByInputTokens;
@@ -1 +1 @@
1
- export { m as AUTO_MODEL_BY_PROVIDER, K as Extractor, y as ModelByInputTokens, q as OBSERVATIONAL_MEMORY_DEFAULTS, J as OBSERVATION_CONTEXT_INSTRUCTIONS, Y as OBSERVATION_CONTEXT_PROMPT, X as OBSERVATION_CONTEXT_PROMPT_THREAD, Z as OBSERVATION_CONTINUATION_HINT, F as OBSERVER_SYSTEM_PROMPT, p as ObservationalMemory, f as ObservationalMemoryProcessor, P as TokenCounter, A as WorkingMemoryExtractor, I as buildObserverPrompt, L as buildObserverSystemPrompt, b as combineObservationGroupRanges, x as deriveObservationGroupProvenance, R as extractCurrentTask, z as formatMessagesForObserver, Q as getObservationContextPrompt, d as getObservationsAsOf, B as hasCurrentTaskSection, U as injectAnchorIds, V as optimizeObservationsForContext, W as parseAnchorId, S as parseObservationGroups, H as parseObserverOutput, C as reconcileObservationGroupsFromReflection, w as renderObservationGroupsForReflection, h as resolveAutoModelId, G as stripEphemeralAnchorIds, T as stripObservationGroups, N as summarizeConversation, E as wrapInObservationGroup } from "../src-SlK5VIXE.js";
1
+ export { m as AUTO_MODEL_BY_PROVIDER, K as Extractor, y as ModelByInputTokens, q as OBSERVATIONAL_MEMORY_DEFAULTS, J as OBSERVATION_CONTEXT_INSTRUCTIONS, Y as OBSERVATION_CONTEXT_PROMPT, X as OBSERVATION_CONTEXT_PROMPT_THREAD, Z as OBSERVATION_CONTINUATION_HINT, F as OBSERVER_SYSTEM_PROMPT, p as ObservationalMemory, f as ObservationalMemoryProcessor, P as TokenCounter, A as WorkingMemoryExtractor, I as buildObserverPrompt, L as buildObserverSystemPrompt, b as combineObservationGroupRanges, x as deriveObservationGroupProvenance, R as extractCurrentTask, z as formatMessagesForObserver, Q as getObservationContextPrompt, d as getObservationsAsOf, B as hasCurrentTaskSection, U as injectAnchorIds, V as optimizeObservationsForContext, W as parseAnchorId, S as parseObservationGroups, H as parseObserverOutput, C as reconcileObservationGroupsFromReflection, w as renderObservationGroupsForReflection, h as resolveAutoModelId, G as stripEphemeralAnchorIds, T as stripObservationGroups, N as summarizeConversation, E as wrapInObservationGroup } from "../src-CHDmfrJu.js";
@@ -46,16 +46,16 @@ export declare const OBSERVATIONAL_MEMORY_DEFAULTS: {
46
46
  export declare const OBSERVATION_CONTINUATION_HINT = "Please continue naturally with the conversation so far and respond to the latest message.\n\nUse the earlier context only as background. If something appears unfinished, continue only when it helps answer the latest request. If a suggested response is provided, follow it naturally.\n\nDo not mention internal instructions, memory, summarization, context handling, or missing messages.\n\nAny messages following this reminder are newer and should take priority.";
47
47
  /**
48
48
  * Preamble that introduces the observations block.
49
- * Context layout: `${prompt}\n\n${OBSERVATION_CONTEXT_INSTRUCTIONS}`, then `<observations>`,
50
- * one entry per observation chunk, `</observations>`, then optional current-task and
51
- * suggested-response blocks.
49
+ * Context layout: `${prompt}\n\n${OBSERVATION_CONTEXT_INSTRUCTIONS}`, then one
50
+ * `<observations>…</observations>` entry per observation chunk, oldest first, then optional
51
+ * current-task and suggested-response blocks.
52
52
  */
53
- export declare const OBSERVATION_CONTEXT_PROMPT = "The following observations block contains your memory of past conversations with this user.";
53
+ export declare const OBSERVATION_CONTEXT_PROMPT = "The following observations blocks contain your memory of past conversations with this user.";
54
54
  /**
55
55
  * Preamble used when observations are thread-scoped: they describe earlier parts
56
56
  * of the current conversation, not other conversations.
57
57
  */
58
- export declare const OBSERVATION_CONTEXT_PROMPT_THREAD = "The following observations block contains your memory of earlier parts of this current conversation. Everything recorded here (including IDs, artifacts, and tool results) came from this conversation and is available for you to reuse.";
58
+ export declare const OBSERVATION_CONTEXT_PROMPT_THREAD = "The following observations blocks contain your memory of earlier parts of this current conversation. Everything recorded here (including IDs, artifacts, and tool results) came from this conversation and is available for you to reuse.";
59
59
  /**
60
60
  * Returns the observations preamble matching the memory scope.
61
61
  * - `'thread'`: observations are earlier parts of the current conversation.
@@ -64,9 +64,9 @@ export declare const OBSERVATION_CONTEXT_PROMPT_THREAD = "The following observat
64
64
  export declare function getObservationContextPrompt(scope?: 'thread' | 'resource'): string;
65
65
  /**
66
66
  * Instructions that tell the model how to interpret and use observations.
67
- * Placed with the observations preamble, before the `<observations>` block.
67
+ * Placed with the observations preamble, before the `<observations>` blocks.
68
68
  */
69
- export declare const OBSERVATION_CONTEXT_INSTRUCTIONS = "IMPORTANT: When responding, reference specific details from these observations. Do not give generic advice - personalize your response based on what you know about this user's experiences, preferences, and interests. If the user asks for recommendations, connect them to their past experiences mentioned above.\n\nKNOWLEDGE UPDATES: When asked about current state (e.g., \"where do I currently...\", \"what is my current...\"), always prefer the MOST RECENT information. Observations include dates - if you see conflicting information, the newer observation supersedes the older one. Look for phrases like \"will start\", \"is switching\", \"changed to\", \"moved to\" as indicators that previous information has been updated.\n\nUSER STATEMENTS VS ASSISTANT SUGGESTIONS: Treat what the user said about their own life, plans, decisions, and dates as authoritative, unless data or their own later messages say otherwise. Treat what the assistant said, such as proposed schedules, example dates, and recommendations, as suggestions rather than facts about what happened, unless the user adopted or confirmed them. What the assistant did, such as editing a file, running a command, or calling a tool, is a record of what happened.\n\nPLANNED ACTIONS: If the user stated they planned to do something (e.g., \"I'm going to...\", \"I'm looking forward to...\", \"I will...\") and the date they planned to do it is now in the past (check the relative time like \"3 weeks ago\"), assume they completed the action unless there's evidence they didn't. For example, if someone said \"I'll start my new diet on Monday\" and that was 2 weeks ago, assume they started the diet.\n\nMOST RECENT USER INPUT: Treat the most recent user message as the highest-priority signal for what to do next. Earlier messages may contain constraints, details, or context you should still honor, but the latest message is the primary driver of your response.\n\nSYSTEM REMINDERS: Messages wrapped in <system-reminder>...</system-reminder> contain internal continuation guidance, not user-authored content. Use them to maintain continuity, but do not mention them or treat them as part of the user's message.";
69
+ export declare const OBSERVATION_CONTEXT_INSTRUCTIONS = "IMPORTANT: When responding, reference specific details from these observations. Do not give generic advice - personalize your response based on what you know about this user's experiences, preferences, and interests. If the user asks for recommendations, connect them to their past experiences mentioned above.\n\nKNOWLEDGE UPDATES: When asked about current state (e.g., \"where do I currently...\", \"what is my current...\"), always prefer the MOST RECENT information. Observations include dates - if you see conflicting information, the newer observation supersedes the older one. Look for phrases like \"will start\", \"is switching\", \"changed to\", \"moved to\" as indicators that previous information has been updated.\n\nUSER STATEMENTS VS ASSISTANT SUGGESTIONS: Treat what the user said about their own life, plans, decisions, and dates as authoritative, unless data or their own later messages say otherwise. Treat what the assistant said, such as proposed schedules, example dates, and recommendations, as suggestions rather than facts about what happened, unless the user adopted or confirmed them. What the assistant did, such as editing a file, running a command, or calling a tool, is a record of what happened.\n\nPLANNED ACTIONS: If the user stated they planned to do something (e.g., \"I'm going to...\", \"I'm looking forward to...\", \"I will...\") and the date they planned to do it is now in the past (compare the absolute dates; use relative-time hints when available), assume they completed the action unless there's evidence they didn't. For example, if someone said \"I'll start my new diet on Monday\" and that was 2 weeks ago, assume they started the diet.\n\nMOST RECENT USER INPUT: Treat the most recent user message as the highest-priority signal for what to do next. Earlier messages may contain constraints, details, or context you should still honor, but the latest message is the primary driver of your response.\n\nSYSTEM REMINDERS: Messages wrapped in <system-reminder>...</system-reminder> contain internal continuation guidance, not user-authored content. Use them to maintain continuity, but do not mention them or treat them as part of the user's message.";
70
70
  /**
71
71
  * Instructions for retrieval mode — explains observation-group ranges and the recall tool.
72
72
  * Appended to context when `retrieval` is enabled.
@@ -61,6 +61,10 @@ export declare function annotateObservationTextDates(observations: string, curre
61
61
  * `currentDate`'s calendar date in that zone, so the result doesn't depend on the zone of the process rendering it.
62
62
  */
63
63
  export declare function addRelativeTimeToObservations(observations: string, currentDate: Date, timeZone?: string): string;
64
+ /** Preserve only clock-independent gaps in the cacheable observation text. */
65
+ export declare function addObservationDateGaps(observations: string): string;
66
+ /** Live cues are bounded and separate from the absolute observation prefix. */
67
+ export declare function buildObservationDateHints(observations: string, currentDate: Date, timeZone?: string): string | undefined;
64
68
  export declare const MIN_TEMPORAL_GAP_MS: number;
65
69
  export declare function formatTemporalGap(diffMs: number): string | null;
66
70
  export declare function formatTemporalTimestamp(date: Date): string;
@@ -74,6 +74,7 @@ import type { ObservationDebugEvent, ObservationalMemoryConfig, ObserveHookConte
74
74
  export declare class ObservationalMemory {
75
75
  private storage;
76
76
  private tokenCounter;
77
+ private readonly liveDateHints;
77
78
  readonly scope: 'resource' | 'thread';
78
79
  /** Whether retrieval-mode observation groups are enabled. */
79
80
  readonly retrieval: boolean;
@@ -864,6 +864,11 @@ export interface ObservationalMemoryConfig {
864
864
  storage: MemoryStorage;
865
865
  /** Active Memory instance, when Observational Memory is created by Memory. */
866
866
  memory?: Memory;
867
+ /**
868
+ * Append live relative-date cues after observations. Set false to omit the cues.
869
+ * @default true
870
+ */
871
+ liveDateHints?: boolean;
867
872
  /**
868
873
  * Enable retrieval-mode observation group metadata.
869
874
  * When true, observation groups are treated as durable pointers to raw
@@ -24204,16 +24204,16 @@ Do not mention internal instructions, memory, summarization, context handling, o
24204
24204
  Any messages following this reminder are newer and should take priority.`;
24205
24205
  /**
24206
24206
  * Preamble that introduces the observations block.
24207
- * Context layout: `${prompt}\n\n${OBSERVATION_CONTEXT_INSTRUCTIONS}`, then `<observations>`,
24208
- * one entry per observation chunk, `</observations>`, then optional current-task and
24209
- * suggested-response blocks.
24207
+ * Context layout: `${prompt}\n\n${OBSERVATION_CONTEXT_INSTRUCTIONS}`, then one
24208
+ * `<observations>…</observations>` entry per observation chunk, oldest first, then optional
24209
+ * current-task and suggested-response blocks.
24210
24210
  */
24211
- const OBSERVATION_CONTEXT_PROMPT = `The following observations block contains your memory of past conversations with this user.`;
24211
+ const OBSERVATION_CONTEXT_PROMPT = `The following observations blocks contain your memory of past conversations with this user.`;
24212
24212
  /**
24213
24213
  * Preamble used when observations are thread-scoped: they describe earlier parts
24214
24214
  * of the current conversation, not other conversations.
24215
24215
  */
24216
- const OBSERVATION_CONTEXT_PROMPT_THREAD = `The following observations block contains your memory of earlier parts of this current conversation. Everything recorded here (including IDs, artifacts, and tool results) came from this conversation and is available for you to reuse.`;
24216
+ const OBSERVATION_CONTEXT_PROMPT_THREAD = `The following observations blocks contain your memory of earlier parts of this current conversation. Everything recorded here (including IDs, artifacts, and tool results) came from this conversation and is available for you to reuse.`;
24217
24217
  /**
24218
24218
  * Returns the observations preamble matching the memory scope.
24219
24219
  * - `'thread'`: observations are earlier parts of the current conversation.
@@ -24224,7 +24224,7 @@ function getObservationContextPrompt(scope = "thread") {
24224
24224
  }
24225
24225
  /**
24226
24226
  * Instructions that tell the model how to interpret and use observations.
24227
- * Placed with the observations preamble, before the `<observations>` block.
24227
+ * Placed with the observations preamble, before the `<observations>` blocks.
24228
24228
  */
24229
24229
  const OBSERVATION_CONTEXT_INSTRUCTIONS = `IMPORTANT: When responding, reference specific details from these observations. Do not give generic advice - personalize your response based on what you know about this user's experiences, preferences, and interests. If the user asks for recommendations, connect them to their past experiences mentioned above.
24230
24230
 
@@ -24232,7 +24232,7 @@ KNOWLEDGE UPDATES: When asked about current state (e.g., "where do I currently..
24232
24232
 
24233
24233
  USER STATEMENTS VS ASSISTANT SUGGESTIONS: Treat what the user said about their own life, plans, decisions, and dates as authoritative, unless data or their own later messages say otherwise. Treat what the assistant said, such as proposed schedules, example dates, and recommendations, as suggestions rather than facts about what happened, unless the user adopted or confirmed them. What the assistant did, such as editing a file, running a command, or calling a tool, is a record of what happened.
24234
24234
 
24235
- PLANNED ACTIONS: If the user stated they planned to do something (e.g., "I'm going to...", "I'm looking forward to...", "I will...") and the date they planned to do it is now in the past (check the relative time like "3 weeks ago"), assume they completed the action unless there's evidence they didn't. For example, if someone said "I'll start my new diet on Monday" and that was 2 weeks ago, assume they started the diet.
24235
+ PLANNED ACTIONS: If the user stated they planned to do something (e.g., "I'm going to...", "I'm looking forward to...", "I will...") and the date they planned to do it is now in the past (compare the absolute dates; use relative-time hints when available), assume they completed the action unless there's evidence they didn't. For example, if someone said "I'll start my new diet on Monday" and that was 2 weeks ago, assume they started the diet.
24236
24236
 
24237
24237
  MOST RECENT USER INPUT: Treat the most recent user message as the highest-priority signal for what to do next. Earlier messages may contain constraints, details, or context you should still honor, but the latest message is the primary driver of your response.
24238
24238
 
@@ -25718,15 +25718,8 @@ function isFutureIntentObservation(line) {
25718
25718
  /\babout\s+to\b/i
25719
25719
  ].some((pattern) => pattern.test(line));
25720
25720
  }
25721
- /**
25722
- * Expand inline estimated dates with relative time.
25723
- * Matches patterns like "(estimated May 27-28, 2023)" or "(meaning May 30, 2023 at 3:00 PM)"
25724
- * and expands them to "(meaning May 30, 2023 - 3 weeks ago)". Notes without a year are left alone.
25725
- */
25726
- function expandInlineEstimatedDates(observations, currentDate, timeZone) {
25727
- const inlineDateRegex = /\((estimated|meaning)\s([^()]*)\)/gi;
25728
- const today = calendarDayIn(currentDate, timeZone);
25729
- return observations.replace(inlineDateRegex, (match, prefix, noteText, offset) => {
25721
+ function expandInlineEstimatedDatesForDay(observations, today) {
25722
+ return observations.replace(/\((estimated|meaning)\s([^()]*)\)/gi, (match, prefix, noteText, offset) => {
25730
25723
  const dateContent = noteText.trimStart();
25731
25724
  const span = findDateSpan(dateContent);
25732
25725
  if (!span) return match;
@@ -25737,14 +25730,8 @@ function expandInlineEstimatedDates(observations, currentDate, timeZone) {
25737
25730
  return `(${prefix} ${dateContent} - ${relative})`;
25738
25731
  });
25739
25732
  }
25740
- /**
25741
- * Annotates dates written into observation text, e.g. "exam on January 10, 2024" becomes
25742
- * "exam on January 10, 2024 (5 months ago)". Only dates that state their year are annotated;
25743
- * "Date:" headers and "(meaning/estimated …)" notes are handled separately and skipped here.
25744
- */
25745
- function annotateObservationTextDates(observations, currentDate, timeZone) {
25733
+ function annotateObservationTextDatesForDay(observations, today) {
25746
25734
  const regex = new RegExp(String.raw`^Date:.*$|\((?:[Ee]stimated|[Mm]eaning)\b[^()]*\)|${FREE_TEXT_DATE.source}`, "gm");
25747
- const today = calendarDayIn(currentDate, timeZone);
25748
25735
  return observations.replace(regex, (match, offset) => {
25749
25736
  if (match.startsWith("Date:") || match.startsWith("(")) return match;
25750
25737
  const span = parseDateSpan(match);
@@ -25762,8 +25749,16 @@ function annotateObservationTextDates(observations, currentDate, timeZone) {
25762
25749
  * `currentDate`'s calendar date in that zone, so the result doesn't depend on the zone of the process rendering it.
25763
25750
  */
25764
25751
  function addRelativeTimeToObservations(observations, currentDate, timeZone) {
25765
- const today = calendarDayIn(currentDate, timeZone);
25766
- const withInlineDates = annotateObservationTextDates(expandInlineEstimatedDates(observations, currentDate, timeZone), currentDate, timeZone);
25752
+ return addRelativeTimeForDay(observations, calendarDayIn(currentDate, timeZone));
25753
+ }
25754
+ function addRelativeTimeForDay(observations, today) {
25755
+ return formatObservationDateHeaders(annotateObservationTextDatesForDay(expandInlineEstimatedDatesForDay(observations, today), today), today);
25756
+ }
25757
+ /** Preserve only clock-independent gaps in the cacheable observation text. */
25758
+ function addObservationDateGaps(observations) {
25759
+ return formatObservationDateHeaders(observations);
25760
+ }
25761
+ function formatObservationDateHeaders(withInlineDates, today) {
25767
25762
  const dateHeaderRegex = /^(Date:[ \t]*)(.*)$/gm;
25768
25763
  const dates = [];
25769
25764
  let regexMatch;
@@ -25789,12 +25784,35 @@ function addRelativeTimeToObservations(observations, currentDate, timeZone) {
25789
25784
  const gap = formatGapBetweenDates(prev.span.end, curr.span.start);
25790
25785
  if (gap) result += `\n${gap}\n\n`;
25791
25786
  }
25792
- result += `${curr.prefix}${curr.dateStr} (${relativeSpan(curr.span, today)})`;
25787
+ result += today === void 0 ? curr.match : `${curr.prefix}${curr.dateStr} (${relativeSpan(curr.span, today)})`;
25793
25788
  lastIndex = curr.index + curr.match.length;
25794
25789
  }
25795
25790
  result += withInlineDates.slice(lastIndex);
25796
25791
  return result;
25797
25792
  }
25793
+ /** Live cues are bounded and separate from the absolute observation prefix. */
25794
+ function buildObservationDateHints(observations, currentDate, timeZone) {
25795
+ const today = calendarDayIn(currentDate, timeZone);
25796
+ const opening = `<observation-date-hints>\nToday is ${(/* @__PURE__ */ new Date(today * DAY_MS)).toISOString().slice(0, 10)} in the observation time zone (${resolveTimeZone(timeZone) ?? "process local"}). These live annotations refer to the absolute observations above; they are not additional observations.`;
25797
+ const closing = "\n</observation-date-hints>";
25798
+ const omission = "\nAdditional date cues omitted. Interpret remaining absolute dates against today; past planned actions likely already happened.";
25799
+ const lines = [];
25800
+ let remaining = 8e3 - opening.length - 26 - 126;
25801
+ let omitted = false;
25802
+ for (const line of observations.split("\n")) {
25803
+ if (!/\d{4}/.test(line)) continue;
25804
+ const annotated = addRelativeTimeForDay(line, today);
25805
+ if (annotated === line) continue;
25806
+ if (lines.length >= 64 || annotated.length + 1 > remaining) {
25807
+ omitted = true;
25808
+ break;
25809
+ }
25810
+ lines.push(annotated);
25811
+ remaining -= annotated.length + 1;
25812
+ }
25813
+ if (!lines.length && !omitted) return void 0;
25814
+ return `${opening}${lines.map((line) => `\n${line}`).join("")}${omitted ? omission : ""}${closing}`;
25815
+ }
25798
25816
  function formatTemporalGap(diffMs) {
25799
25817
  if (diffMs < 6e5) return null;
25800
25818
  const minute = 6e4;
@@ -38063,6 +38081,7 @@ let hasWarnedResourceScopeDeprecation = false;
38063
38081
  var ObservationalMemory = class ObservationalMemory {
38064
38082
  storage;
38065
38083
  tokenCounter;
38084
+ liveDateHints;
38066
38085
  scope;
38067
38086
  /** Whether retrieval-mode observation groups are enabled. */
38068
38087
  retrieval;
@@ -38195,6 +38214,7 @@ var ObservationalMemory = class ObservationalMemory {
38195
38214
  if (config.model && config.reflection?.model) throw new Error("Cannot set both `model` and `reflection.model`. Use `model` to set both agents, or set each individually.");
38196
38215
  this.shouldObscureThreadIds = config.obscureThreadIds || false;
38197
38216
  this.storage = config.storage;
38217
+ this.liveDateHints = config.liveDateHints ?? true;
38198
38218
  this.scope = config.scope ?? "thread";
38199
38219
  this.retrieval = Boolean(config.retrieval);
38200
38220
  this.retrievalScope = typeof config.retrieval === "object" ? config.retrieval.scope ?? "resource" : "resource";
@@ -38983,12 +39003,14 @@ var ObservationalMemory = class ObservationalMemory {
38983
39003
  * the message for the current thread.
38984
39004
  */
38985
39005
  formatObservationsForContext(observations, currentTask, suggestedResponse, extractedValues, unobservedContextBlocks, currentDate, retrieval = false, timeZone) {
38986
- let optimized = retrieval ? renderObservationGroupsForReflection(observations, { includeReflectionKind: true }) ?? optimizeObservationsForContext(observations) : optimizeObservationsForContext(observations);
38987
- if (currentDate) optimized = addRelativeTimeToObservations(optimized, currentDate, timeZone);
39006
+ const optimized = retrieval ? renderObservationGroupsForReflection(observations, { includeReflectionKind: true }) ?? optimizeObservationsForContext(observations) : optimizeObservationsForContext(observations);
39007
+ const dateHints = this.liveDateHints && currentDate ? buildObservationDateHints(optimized, currentDate, timeZone) : void 0;
39008
+ const stableObservations = currentDate ? addObservationDateGaps(optimized) : optimized;
38988
39009
  const messages = [`${getObservationContextPrompt(this.scope)}\n\n${OBSERVATION_CONTEXT_INSTRUCTIONS}${retrieval ? `\n\n${getRetrievalInstructions(this.retrievalScope, this.retrievalInstructions, this.retrievalSearch, this.storage.supportsObservationalMemoryHistorySearch === true)}` : ""}`];
38989
39010
  if (unobservedContextBlocks) messages.push(`The following content is from OTHER conversations different from the current conversation, they're here for reference, but they're not necessarily your focus:\nSTART_OTHER_CONVERSATIONS_BLOCK\n${unobservedContextBlocks}\nEND_OTHER_CONVERSATIONS_BLOCK`);
38990
- const observationChunks = this.splitObservationContextChunks(optimized);
38991
- if (observationChunks.length > 0) messages.push("<observations>", ...observationChunks, "</observations>");
39011
+ const observationChunks = this.splitObservationContextChunks(stableObservations);
39012
+ for (const chunk of observationChunks) messages.push(`<observations>\n${chunk}\n</observations>`);
39013
+ if (observationChunks.length > 0 && dateHints) messages.push(dateHints);
38992
39014
  if (currentTask) messages.push(`<current-task>\n${currentTask}\n</current-task>`);
38993
39015
  if (suggestedResponse) messages.push(`<suggested-response>\n${suggestedResponse}\n</suggested-response>`);
38994
39016
  messages.push(...buildExtractedValueContextSections([...this.observationConfig.extractors, ...this.reflectionConfig.extractors], extractedValues));
@@ -42633,6 +42655,7 @@ ${workingMemory}`;
42633
42655
  return new OMClass({
42634
42656
  storage: memoryStore,
42635
42657
  memory: this,
42658
+ liveDateHints: omConfig.liveDateHints,
42636
42659
  scope: omConfig.scope,
42637
42660
  retrieval: omConfig.retrieval,
42638
42661
  activateAfterIdle: omConfig.activateAfterIdle,
@@ -43269,9 +43292,13 @@ Notes:
43269
43292
  * @param args.resourceId - Resource ID for the new thread (defaults to source thread's resourceId)
43270
43293
  * @param args.title - Title for the new cloned thread
43271
43294
  * @param args.metadata - Additional metadata to merge with clone metadata
43272
- * @param args.options - Options for filtering which messages to include
43295
+ * @param args.options - Options for filtering which messages to include. Without a filter or
43296
+ * limit, every message is copied.
43273
43297
  * @param args.options.messageLimit - Maximum number of messages to copy (from most recent)
43274
43298
  * @param args.options.messageFilter - Filter messages by date range or specific IDs
43299
+ * @param args.options.contextWindowOnly - With observational memory, copy only the messages after
43300
+ * `lastObservedAt`, the ones still in the context window. Can't be combined with `messageFilter`
43301
+ * or `messageLimit`.
43275
43302
  * @param memoryConfig - Optional memory configuration override
43276
43303
  * @returns The newly created thread and the cloned messages
43277
43304
  *
@@ -43341,8 +43368,11 @@ Notes:
43341
43368
  async copyThread(args, memoryConfig) {
43342
43369
  const memoryStore = await this.getMemoryStore();
43343
43370
  const config = this.getMergedThreadConfig(memoryConfig);
43344
- const result = await memoryStore.copyThread(args);
43345
43371
  const sourceResourceId = (await this.getThreadById({ threadId: args.sourceThreadId }))?.resourceId;
43372
+ const omEngine = await this.omEngine;
43373
+ const liveContextOM = omEngine && sourceResourceId ? await omEngine.getRecord(args.sourceThreadId, sourceResourceId) : null;
43374
+ const contextOM = liveContextOM ? structuredClone(liveContextOM) : null;
43375
+ const result = await memoryStore.copyThread(this.withContextWindowFilter(args, contextOM));
43346
43376
  let priorDestinationResourceWm;
43347
43377
  if (config.workingMemory?.enabled) {
43348
43378
  const scope = config.workingMemory.scope || "resource";
@@ -43364,7 +43394,7 @@ Notes:
43364
43394
  }
43365
43395
  }
43366
43396
  if (memoryStore.supportsObservationalMemory && sourceResourceId) try {
43367
- await this.cloneObservationalMemory(memoryStore, args.sourceThreadId, sourceResourceId, result);
43397
+ await this.cloneObservationalMemory(memoryStore, args.sourceThreadId, sourceResourceId, result, contextOM);
43368
43398
  } catch (error) {
43369
43399
  await this.rollbackCopiedThread(memoryStore, result.thread, "OM clone", false, priorDestinationResourceWm);
43370
43400
  throw error;
@@ -43557,13 +43587,38 @@ Notes:
43557
43587
  }
43558
43588
  }
43559
43589
  /**
43590
+ * With observational memory, the context window is the observations plus the messages created
43591
+ * after `lastObservedAt`, read from the record the configured engine reads (`contextOM`), as
43592
+ * `getContext` does. When the caller asks for `contextWindowOnly`, copy only those messages: the
43593
+ * observations carry the rest. Otherwise copy what the caller's filter or limit selects, or every
43594
+ * message. `contextWindowOnly` is `Memory`'s own option and never reaches the storage copy.
43595
+ */
43596
+ withContextWindowFilter(args, contextOM) {
43597
+ const { contextWindowOnly, ...options } = args.options ?? {};
43598
+ if (contextWindowOnly && (options.messageFilter !== void 0 || options.messageLimit !== void 0)) throw new Error("cloneThread: contextWindowOnly copies only the messages in the context window and cannot be combined with messageFilter or messageLimit");
43599
+ const storageArgs = args.options ? {
43600
+ ...args,
43601
+ options
43602
+ } : args;
43603
+ if (!contextWindowOnly || !contextOM?.lastObservedAt) return storageArgs;
43604
+ const startDate = new Date(new Date(contextOM.lastObservedAt).getTime() + 1);
43605
+ return {
43606
+ ...storageArgs,
43607
+ options: {
43608
+ ...options,
43609
+ messageFilter: { startDate }
43610
+ }
43611
+ };
43612
+ }
43613
+ /**
43560
43614
  * Clone observational memory records when cloning a thread.
43561
43615
  * Thread-scoped: always cloned to the new thread.
43562
43616
  * Resource-scoped: cloned only when the resourceId changes (same resourceId shares OM naturally).
43563
43617
  * All stored message/thread IDs are remapped to the cloned IDs.
43564
43618
  */
43565
- async cloneObservationalMemory(memoryStore, sourceThreadId, sourceResourceId, result) {
43566
- let sourceOM = await memoryStore.getObservationalMemory(sourceThreadId, sourceResourceId);
43619
+ async cloneObservationalMemory(memoryStore, sourceThreadId, sourceResourceId, result, contextOM) {
43620
+ let sourceOM = contextOM;
43621
+ if (!sourceOM) sourceOM = await memoryStore.getObservationalMemory(sourceThreadId, sourceResourceId);
43567
43622
  if (!sourceOM) sourceOM = await memoryStore.getObservationalMemory(null, sourceResourceId);
43568
43623
  if (!sourceOM) return;
43569
43624
  const clonedThreadId = result.thread.id;
@@ -24226,16 +24226,16 @@ Do not mention internal instructions, memory, summarization, context handling, o
24226
24226
  Any messages following this reminder are newer and should take priority.`;
24227
24227
  /**
24228
24228
  * Preamble that introduces the observations block.
24229
- * Context layout: `${prompt}\n\n${OBSERVATION_CONTEXT_INSTRUCTIONS}`, then `<observations>`,
24230
- * one entry per observation chunk, `</observations>`, then optional current-task and
24231
- * suggested-response blocks.
24229
+ * Context layout: `${prompt}\n\n${OBSERVATION_CONTEXT_INSTRUCTIONS}`, then one
24230
+ * `<observations>…</observations>` entry per observation chunk, oldest first, then optional
24231
+ * current-task and suggested-response blocks.
24232
24232
  */
24233
- const OBSERVATION_CONTEXT_PROMPT = `The following observations block contains your memory of past conversations with this user.`;
24233
+ const OBSERVATION_CONTEXT_PROMPT = `The following observations blocks contain your memory of past conversations with this user.`;
24234
24234
  /**
24235
24235
  * Preamble used when observations are thread-scoped: they describe earlier parts
24236
24236
  * of the current conversation, not other conversations.
24237
24237
  */
24238
- const OBSERVATION_CONTEXT_PROMPT_THREAD = `The following observations block contains your memory of earlier parts of this current conversation. Everything recorded here (including IDs, artifacts, and tool results) came from this conversation and is available for you to reuse.`;
24238
+ const OBSERVATION_CONTEXT_PROMPT_THREAD = `The following observations blocks contain your memory of earlier parts of this current conversation. Everything recorded here (including IDs, artifacts, and tool results) came from this conversation and is available for you to reuse.`;
24239
24239
  /**
24240
24240
  * Returns the observations preamble matching the memory scope.
24241
24241
  * - `'thread'`: observations are earlier parts of the current conversation.
@@ -24246,7 +24246,7 @@ function getObservationContextPrompt(scope = "thread") {
24246
24246
  }
24247
24247
  /**
24248
24248
  * Instructions that tell the model how to interpret and use observations.
24249
- * Placed with the observations preamble, before the `<observations>` block.
24249
+ * Placed with the observations preamble, before the `<observations>` blocks.
24250
24250
  */
24251
24251
  const OBSERVATION_CONTEXT_INSTRUCTIONS = `IMPORTANT: When responding, reference specific details from these observations. Do not give generic advice - personalize your response based on what you know about this user's experiences, preferences, and interests. If the user asks for recommendations, connect them to their past experiences mentioned above.
24252
24252
 
@@ -24254,7 +24254,7 @@ KNOWLEDGE UPDATES: When asked about current state (e.g., "where do I currently..
24254
24254
 
24255
24255
  USER STATEMENTS VS ASSISTANT SUGGESTIONS: Treat what the user said about their own life, plans, decisions, and dates as authoritative, unless data or their own later messages say otherwise. Treat what the assistant said, such as proposed schedules, example dates, and recommendations, as suggestions rather than facts about what happened, unless the user adopted or confirmed them. What the assistant did, such as editing a file, running a command, or calling a tool, is a record of what happened.
24256
24256
 
24257
- PLANNED ACTIONS: If the user stated they planned to do something (e.g., "I'm going to...", "I'm looking forward to...", "I will...") and the date they planned to do it is now in the past (check the relative time like "3 weeks ago"), assume they completed the action unless there's evidence they didn't. For example, if someone said "I'll start my new diet on Monday" and that was 2 weeks ago, assume they started the diet.
24257
+ PLANNED ACTIONS: If the user stated they planned to do something (e.g., "I'm going to...", "I'm looking forward to...", "I will...") and the date they planned to do it is now in the past (compare the absolute dates; use relative-time hints when available), assume they completed the action unless there's evidence they didn't. For example, if someone said "I'll start my new diet on Monday" and that was 2 weeks ago, assume they started the diet.
24258
24258
 
24259
24259
  MOST RECENT USER INPUT: Treat the most recent user message as the highest-priority signal for what to do next. Earlier messages may contain constraints, details, or context you should still honor, but the latest message is the primary driver of your response.
24260
24260
 
@@ -25740,15 +25740,8 @@ function isFutureIntentObservation(line) {
25740
25740
  /\babout\s+to\b/i
25741
25741
  ].some((pattern) => pattern.test(line));
25742
25742
  }
25743
- /**
25744
- * Expand inline estimated dates with relative time.
25745
- * Matches patterns like "(estimated May 27-28, 2023)" or "(meaning May 30, 2023 at 3:00 PM)"
25746
- * and expands them to "(meaning May 30, 2023 - 3 weeks ago)". Notes without a year are left alone.
25747
- */
25748
- function expandInlineEstimatedDates(observations, currentDate, timeZone) {
25749
- const inlineDateRegex = /\((estimated|meaning)\s([^()]*)\)/gi;
25750
- const today = calendarDayIn(currentDate, timeZone);
25751
- return observations.replace(inlineDateRegex, (match, prefix, noteText, offset) => {
25743
+ function expandInlineEstimatedDatesForDay(observations, today) {
25744
+ return observations.replace(/\((estimated|meaning)\s([^()]*)\)/gi, (match, prefix, noteText, offset) => {
25752
25745
  const dateContent = noteText.trimStart();
25753
25746
  const span = findDateSpan(dateContent);
25754
25747
  if (!span) return match;
@@ -25759,14 +25752,8 @@ function expandInlineEstimatedDates(observations, currentDate, timeZone) {
25759
25752
  return `(${prefix} ${dateContent} - ${relative})`;
25760
25753
  });
25761
25754
  }
25762
- /**
25763
- * Annotates dates written into observation text, e.g. "exam on January 10, 2024" becomes
25764
- * "exam on January 10, 2024 (5 months ago)". Only dates that state their year are annotated;
25765
- * "Date:" headers and "(meaning/estimated …)" notes are handled separately and skipped here.
25766
- */
25767
- function annotateObservationTextDates(observations, currentDate, timeZone) {
25755
+ function annotateObservationTextDatesForDay(observations, today) {
25768
25756
  const regex = new RegExp(String.raw`^Date:.*$|\((?:[Ee]stimated|[Mm]eaning)\b[^()]*\)|${FREE_TEXT_DATE.source}`, "gm");
25769
- const today = calendarDayIn(currentDate, timeZone);
25770
25757
  return observations.replace(regex, (match, offset) => {
25771
25758
  if (match.startsWith("Date:") || match.startsWith("(")) return match;
25772
25759
  const span = parseDateSpan(match);
@@ -25784,8 +25771,16 @@ function annotateObservationTextDates(observations, currentDate, timeZone) {
25784
25771
  * `currentDate`'s calendar date in that zone, so the result doesn't depend on the zone of the process rendering it.
25785
25772
  */
25786
25773
  function addRelativeTimeToObservations(observations, currentDate, timeZone) {
25787
- const today = calendarDayIn(currentDate, timeZone);
25788
- const withInlineDates = annotateObservationTextDates(expandInlineEstimatedDates(observations, currentDate, timeZone), currentDate, timeZone);
25774
+ return addRelativeTimeForDay(observations, calendarDayIn(currentDate, timeZone));
25775
+ }
25776
+ function addRelativeTimeForDay(observations, today) {
25777
+ return formatObservationDateHeaders(annotateObservationTextDatesForDay(expandInlineEstimatedDatesForDay(observations, today), today), today);
25778
+ }
25779
+ /** Preserve only clock-independent gaps in the cacheable observation text. */
25780
+ function addObservationDateGaps(observations) {
25781
+ return formatObservationDateHeaders(observations);
25782
+ }
25783
+ function formatObservationDateHeaders(withInlineDates, today) {
25789
25784
  const dateHeaderRegex = /^(Date:[ \t]*)(.*)$/gm;
25790
25785
  const dates = [];
25791
25786
  let regexMatch;
@@ -25811,12 +25806,35 @@ function addRelativeTimeToObservations(observations, currentDate, timeZone) {
25811
25806
  const gap = formatGapBetweenDates(prev.span.end, curr.span.start);
25812
25807
  if (gap) result += `\n${gap}\n\n`;
25813
25808
  }
25814
- result += `${curr.prefix}${curr.dateStr} (${relativeSpan(curr.span, today)})`;
25809
+ result += today === void 0 ? curr.match : `${curr.prefix}${curr.dateStr} (${relativeSpan(curr.span, today)})`;
25815
25810
  lastIndex = curr.index + curr.match.length;
25816
25811
  }
25817
25812
  result += withInlineDates.slice(lastIndex);
25818
25813
  return result;
25819
25814
  }
25815
+ /** Live cues are bounded and separate from the absolute observation prefix. */
25816
+ function buildObservationDateHints(observations, currentDate, timeZone) {
25817
+ const today = calendarDayIn(currentDate, timeZone);
25818
+ const opening = `<observation-date-hints>\nToday is ${(/* @__PURE__ */ new Date(today * DAY_MS)).toISOString().slice(0, 10)} in the observation time zone (${resolveTimeZone(timeZone) ?? "process local"}). These live annotations refer to the absolute observations above; they are not additional observations.`;
25819
+ const closing = "\n</observation-date-hints>";
25820
+ const omission = "\nAdditional date cues omitted. Interpret remaining absolute dates against today; past planned actions likely already happened.";
25821
+ const lines = [];
25822
+ let remaining = 8e3 - opening.length - 26 - 126;
25823
+ let omitted = false;
25824
+ for (const line of observations.split("\n")) {
25825
+ if (!/\d{4}/.test(line)) continue;
25826
+ const annotated = addRelativeTimeForDay(line, today);
25827
+ if (annotated === line) continue;
25828
+ if (lines.length >= 64 || annotated.length + 1 > remaining) {
25829
+ omitted = true;
25830
+ break;
25831
+ }
25832
+ lines.push(annotated);
25833
+ remaining -= annotated.length + 1;
25834
+ }
25835
+ if (!lines.length && !omitted) return void 0;
25836
+ return `${opening}${lines.map((line) => `\n${line}`).join("")}${omitted ? omission : ""}${closing}`;
25837
+ }
25820
25838
  function formatTemporalGap(diffMs) {
25821
25839
  if (diffMs < 6e5) return null;
25822
25840
  const minute = 6e4;
@@ -38085,6 +38103,7 @@ let hasWarnedResourceScopeDeprecation = false;
38085
38103
  var ObservationalMemory = class ObservationalMemory {
38086
38104
  storage;
38087
38105
  tokenCounter;
38106
+ liveDateHints;
38088
38107
  scope;
38089
38108
  /** Whether retrieval-mode observation groups are enabled. */
38090
38109
  retrieval;
@@ -38217,6 +38236,7 @@ var ObservationalMemory = class ObservationalMemory {
38217
38236
  if (config.model && config.reflection?.model) throw new Error("Cannot set both `model` and `reflection.model`. Use `model` to set both agents, or set each individually.");
38218
38237
  this.shouldObscureThreadIds = config.obscureThreadIds || false;
38219
38238
  this.storage = config.storage;
38239
+ this.liveDateHints = config.liveDateHints ?? true;
38220
38240
  this.scope = config.scope ?? "thread";
38221
38241
  this.retrieval = Boolean(config.retrieval);
38222
38242
  this.retrievalScope = typeof config.retrieval === "object" ? config.retrieval.scope ?? "resource" : "resource";
@@ -39005,12 +39025,14 @@ var ObservationalMemory = class ObservationalMemory {
39005
39025
  * the message for the current thread.
39006
39026
  */
39007
39027
  formatObservationsForContext(observations, currentTask, suggestedResponse, extractedValues, unobservedContextBlocks, currentDate, retrieval = false, timeZone) {
39008
- let optimized = retrieval ? renderObservationGroupsForReflection(observations, { includeReflectionKind: true }) ?? optimizeObservationsForContext(observations) : optimizeObservationsForContext(observations);
39009
- if (currentDate) optimized = addRelativeTimeToObservations(optimized, currentDate, timeZone);
39028
+ const optimized = retrieval ? renderObservationGroupsForReflection(observations, { includeReflectionKind: true }) ?? optimizeObservationsForContext(observations) : optimizeObservationsForContext(observations);
39029
+ const dateHints = this.liveDateHints && currentDate ? buildObservationDateHints(optimized, currentDate, timeZone) : void 0;
39030
+ const stableObservations = currentDate ? addObservationDateGaps(optimized) : optimized;
39010
39031
  const messages = [`${getObservationContextPrompt(this.scope)}\n\n${OBSERVATION_CONTEXT_INSTRUCTIONS}${retrieval ? `\n\n${getRetrievalInstructions(this.retrievalScope, this.retrievalInstructions, this.retrievalSearch, this.storage.supportsObservationalMemoryHistorySearch === true)}` : ""}`];
39011
39032
  if (unobservedContextBlocks) messages.push(`The following content is from OTHER conversations different from the current conversation, they're here for reference, but they're not necessarily your focus:\nSTART_OTHER_CONVERSATIONS_BLOCK\n${unobservedContextBlocks}\nEND_OTHER_CONVERSATIONS_BLOCK`);
39012
- const observationChunks = this.splitObservationContextChunks(optimized);
39013
- if (observationChunks.length > 0) messages.push("<observations>", ...observationChunks, "</observations>");
39033
+ const observationChunks = this.splitObservationContextChunks(stableObservations);
39034
+ for (const chunk of observationChunks) messages.push(`<observations>\n${chunk}\n</observations>`);
39035
+ if (observationChunks.length > 0 && dateHints) messages.push(dateHints);
39014
39036
  if (currentTask) messages.push(`<current-task>\n${currentTask}\n</current-task>`);
39015
39037
  if (suggestedResponse) messages.push(`<suggested-response>\n${suggestedResponse}\n</suggested-response>`);
39016
39038
  messages.push(...buildExtractedValueContextSections([...this.observationConfig.extractors, ...this.reflectionConfig.extractors], extractedValues));
@@ -42655,6 +42677,7 @@ ${workingMemory}`;
42655
42677
  return new OMClass({
42656
42678
  storage: memoryStore,
42657
42679
  memory: this,
42680
+ liveDateHints: omConfig.liveDateHints,
42658
42681
  scope: omConfig.scope,
42659
42682
  retrieval: omConfig.retrieval,
42660
42683
  activateAfterIdle: omConfig.activateAfterIdle,
@@ -43291,9 +43314,13 @@ Notes:
43291
43314
  * @param args.resourceId - Resource ID for the new thread (defaults to source thread's resourceId)
43292
43315
  * @param args.title - Title for the new cloned thread
43293
43316
  * @param args.metadata - Additional metadata to merge with clone metadata
43294
- * @param args.options - Options for filtering which messages to include
43317
+ * @param args.options - Options for filtering which messages to include. Without a filter or
43318
+ * limit, every message is copied.
43295
43319
  * @param args.options.messageLimit - Maximum number of messages to copy (from most recent)
43296
43320
  * @param args.options.messageFilter - Filter messages by date range or specific IDs
43321
+ * @param args.options.contextWindowOnly - With observational memory, copy only the messages after
43322
+ * `lastObservedAt`, the ones still in the context window. Can't be combined with `messageFilter`
43323
+ * or `messageLimit`.
43297
43324
  * @param memoryConfig - Optional memory configuration override
43298
43325
  * @returns The newly created thread and the cloned messages
43299
43326
  *
@@ -43363,8 +43390,11 @@ Notes:
43363
43390
  async copyThread(args, memoryConfig) {
43364
43391
  const memoryStore = await this.getMemoryStore();
43365
43392
  const config = this.getMergedThreadConfig(memoryConfig);
43366
- const result = await memoryStore.copyThread(args);
43367
43393
  const sourceResourceId = (await this.getThreadById({ threadId: args.sourceThreadId }))?.resourceId;
43394
+ const omEngine = await this.omEngine;
43395
+ const liveContextOM = omEngine && sourceResourceId ? await omEngine.getRecord(args.sourceThreadId, sourceResourceId) : null;
43396
+ const contextOM = liveContextOM ? structuredClone(liveContextOM) : null;
43397
+ const result = await memoryStore.copyThread(this.withContextWindowFilter(args, contextOM));
43368
43398
  let priorDestinationResourceWm;
43369
43399
  if (config.workingMemory?.enabled) {
43370
43400
  const scope = config.workingMemory.scope || "resource";
@@ -43386,7 +43416,7 @@ Notes:
43386
43416
  }
43387
43417
  }
43388
43418
  if (memoryStore.supportsObservationalMemory && sourceResourceId) try {
43389
- await this.cloneObservationalMemory(memoryStore, args.sourceThreadId, sourceResourceId, result);
43419
+ await this.cloneObservationalMemory(memoryStore, args.sourceThreadId, sourceResourceId, result, contextOM);
43390
43420
  } catch (error) {
43391
43421
  await this.rollbackCopiedThread(memoryStore, result.thread, "OM clone", false, priorDestinationResourceWm);
43392
43422
  throw error;
@@ -43579,13 +43609,38 @@ Notes:
43579
43609
  }
43580
43610
  }
43581
43611
  /**
43612
+ * With observational memory, the context window is the observations plus the messages created
43613
+ * after `lastObservedAt`, read from the record the configured engine reads (`contextOM`), as
43614
+ * `getContext` does. When the caller asks for `contextWindowOnly`, copy only those messages: the
43615
+ * observations carry the rest. Otherwise copy what the caller's filter or limit selects, or every
43616
+ * message. `contextWindowOnly` is `Memory`'s own option and never reaches the storage copy.
43617
+ */
43618
+ withContextWindowFilter(args, contextOM) {
43619
+ const { contextWindowOnly, ...options } = args.options ?? {};
43620
+ if (contextWindowOnly && (options.messageFilter !== void 0 || options.messageLimit !== void 0)) throw new Error("cloneThread: contextWindowOnly copies only the messages in the context window and cannot be combined with messageFilter or messageLimit");
43621
+ const storageArgs = args.options ? {
43622
+ ...args,
43623
+ options
43624
+ } : args;
43625
+ if (!contextWindowOnly || !contextOM?.lastObservedAt) return storageArgs;
43626
+ const startDate = new Date(new Date(contextOM.lastObservedAt).getTime() + 1);
43627
+ return {
43628
+ ...storageArgs,
43629
+ options: {
43630
+ ...options,
43631
+ messageFilter: { startDate }
43632
+ }
43633
+ };
43634
+ }
43635
+ /**
43582
43636
  * Clone observational memory records when cloning a thread.
43583
43637
  * Thread-scoped: always cloned to the new thread.
43584
43638
  * Resource-scoped: cloned only when the resourceId changes (same resourceId shares OM naturally).
43585
43639
  * All stored message/thread IDs are remapped to the cloned IDs.
43586
43640
  */
43587
- async cloneObservationalMemory(memoryStore, sourceThreadId, sourceResourceId, result) {
43588
- let sourceOM = await memoryStore.getObservationalMemory(sourceThreadId, sourceResourceId);
43641
+ async cloneObservationalMemory(memoryStore, sourceThreadId, sourceResourceId, result, contextOM) {
43642
+ let sourceOM = contextOM;
43643
+ if (!sourceOM) sourceOM = await memoryStore.getObservationalMemory(sourceThreadId, sourceResourceId);
43589
43644
  if (!sourceOM) sourceOM = await memoryStore.getObservationalMemory(null, sourceResourceId);
43590
43645
  if (!sourceOM) return;
43591
43646
  const clonedThreadId = result.thread.id;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/memory",
3
- "version": "1.41.4-alpha.1",
3
+ "version": "1.42.0-alpha.3",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -73,7 +73,7 @@
73
73
  "@internal/ai-v7": "0.0.99",
74
74
  "@internal/lint": "0.0.152",
75
75
  "@internal/types-builder": "0.0.127",
76
- "@mastra/core": "1.87.0-alpha.8"
76
+ "@mastra/core": "1.87.0-alpha.12"
77
77
  },
78
78
  "peerDependencies": {
79
79
  "@mastra/core": ">=1.85.1-0 <2.0.0-0"