@mastra/memory 1.41.4-alpha.1 → 1.42.0-alpha.2
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/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +54 -54
- package/dist/docs/references/reference-memory-cloneThread.md +18 -1
- package/dist/docs/references/reference-memory-copyThread.md +2 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +13 -1
- package/dist/index.js +1 -1
- package/dist/processors/index.cjs +1 -1
- package/dist/processors/index.js +1 -1
- package/dist/processors/observational-memory/constants.d.ts +6 -6
- package/dist/{src-SlK5VIXE.js → src-Bv05c6Nj.js} +44 -13
- package/dist/{src-Cr_776no.cjs → src-D2dL-xVG.cjs} +44 -13
- package/package.json +2 -2
package/dist/docs/SKILL.md
CHANGED
|
@@ -1,243 +1,243 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.
|
|
2
|
+
"version": "1.42.0-alpha.2",
|
|
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-
|
|
7
|
+
"implementation": "dist/src-Bv05c6Nj.js",
|
|
8
8
|
"line": 32945
|
|
9
9
|
},
|
|
10
10
|
"Extractor": {
|
|
11
11
|
"types": "dist/processors/observational-memory/extractor.d.ts",
|
|
12
|
-
"implementation": "dist/src-
|
|
12
|
+
"implementation": "dist/src-Bv05c6Nj.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-
|
|
17
|
+
"implementation": "dist/src-Bv05c6Nj.js",
|
|
18
18
|
"line": 32728
|
|
19
19
|
},
|
|
20
20
|
"OBSERVATIONAL_MEMORY_DEFAULTS": {
|
|
21
21
|
"types": "dist/processors/observational-memory/constants.d.ts",
|
|
22
|
-
"implementation": "dist/src-
|
|
22
|
+
"implementation": "dist/src-Bv05c6Nj.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-
|
|
27
|
+
"implementation": "dist/src-Bv05c6Nj.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-
|
|
32
|
+
"implementation": "dist/src-Bv05c6Nj.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-
|
|
37
|
+
"implementation": "dist/src-Bv05c6Nj.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-
|
|
42
|
+
"implementation": "dist/src-Bv05c6Nj.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-
|
|
47
|
+
"implementation": "dist/src-Bv05c6Nj.js",
|
|
48
48
|
"line": 26880
|
|
49
49
|
},
|
|
50
50
|
"ObservationalMemory": {
|
|
51
51
|
"types": "dist/processors/observational-memory/observational-memory.d.ts",
|
|
52
|
-
"implementation": "dist/src-
|
|
52
|
+
"implementation": "dist/src-Bv05c6Nj.js",
|
|
53
53
|
"line": 38063
|
|
54
54
|
},
|
|
55
55
|
"ObservationalMemoryProcessor": {
|
|
56
56
|
"types": "dist/processors/observational-memory/processor.d.ts",
|
|
57
|
-
"implementation": "dist/src-
|
|
58
|
-
"line":
|
|
57
|
+
"implementation": "dist/src-Bv05c6Nj.js",
|
|
58
|
+
"line": 40897
|
|
59
59
|
},
|
|
60
60
|
"TokenCounter": {
|
|
61
61
|
"types": "dist/processors/observational-memory/token-counter.d.ts",
|
|
62
|
-
"implementation": "dist/src-
|
|
62
|
+
"implementation": "dist/src-Bv05c6Nj.js",
|
|
63
63
|
"line": 29410
|
|
64
64
|
},
|
|
65
65
|
"WorkingMemoryExtractor": {
|
|
66
66
|
"types": "dist/processors/observational-memory/working-memory-extractor.d.ts",
|
|
67
|
-
"implementation": "dist/src-
|
|
67
|
+
"implementation": "dist/src-Bv05c6Nj.js",
|
|
68
68
|
"line": 30466
|
|
69
69
|
},
|
|
70
70
|
"buildObserverPrompt": {
|
|
71
71
|
"types": "dist/processors/observational-memory/observer-agent.d.ts",
|
|
72
|
-
"implementation": "dist/src-
|
|
72
|
+
"implementation": "dist/src-Bv05c6Nj.js",
|
|
73
73
|
"line": 27562
|
|
74
74
|
},
|
|
75
75
|
"buildObserverSystemPrompt": {
|
|
76
76
|
"types": "dist/processors/observational-memory/observer-agent.d.ts",
|
|
77
|
-
"implementation": "dist/src-
|
|
77
|
+
"implementation": "dist/src-Bv05c6Nj.js",
|
|
78
78
|
"line": 26774
|
|
79
79
|
},
|
|
80
80
|
"combineObservationGroupRanges": {
|
|
81
81
|
"types": "dist/processors/observational-memory/observation-groups.d.ts",
|
|
82
|
-
"implementation": "dist/src-
|
|
82
|
+
"implementation": "dist/src-Bv05c6Nj.js",
|
|
83
83
|
"line": 31048
|
|
84
84
|
},
|
|
85
85
|
"deriveObservationGroupProvenance": {
|
|
86
86
|
"types": "dist/processors/observational-memory/observation-groups.d.ts",
|
|
87
|
-
"implementation": "dist/src-
|
|
87
|
+
"implementation": "dist/src-Bv05c6Nj.js",
|
|
88
88
|
"line": 31092
|
|
89
89
|
},
|
|
90
90
|
"extractCurrentTask": {
|
|
91
91
|
"types": "dist/processors/observational-memory/observer-agent.d.ts",
|
|
92
|
-
"implementation": "dist/src-
|
|
92
|
+
"implementation": "dist/src-Bv05c6Nj.js",
|
|
93
93
|
"line": 27875
|
|
94
94
|
},
|
|
95
95
|
"formatMessagesForObserver": {
|
|
96
96
|
"types": "dist/processors/observational-memory/observer-agent.d.ts",
|
|
97
|
-
"implementation": "dist/src-
|
|
97
|
+
"implementation": "dist/src-Bv05c6Nj.js",
|
|
98
98
|
"line": 27313
|
|
99
99
|
},
|
|
100
100
|
"getObservationContextPrompt": {
|
|
101
101
|
"types": "dist/processors/observational-memory/constants.d.ts",
|
|
102
|
-
"implementation": "dist/src-
|
|
102
|
+
"implementation": "dist/src-Bv05c6Nj.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-
|
|
108
|
-
"line":
|
|
107
|
+
"implementation": "dist/src-Bv05c6Nj.js",
|
|
108
|
+
"line": 41243
|
|
109
109
|
},
|
|
110
110
|
"hasCurrentTaskSection": {
|
|
111
111
|
"types": "dist/processors/observational-memory/observer-agent.d.ts",
|
|
112
|
-
"implementation": "dist/src-
|
|
112
|
+
"implementation": "dist/src-Bv05c6Nj.js",
|
|
113
113
|
"line": 27863
|
|
114
114
|
},
|
|
115
115
|
"injectAnchorIds": {
|
|
116
116
|
"types": "dist/processors/observational-memory/anchor-ids.d.ts",
|
|
117
|
-
"implementation": "dist/src-
|
|
117
|
+
"implementation": "dist/src-Bv05c6Nj.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-
|
|
122
|
+
"implementation": "dist/src-Bv05c6Nj.js",
|
|
123
123
|
"line": 27896
|
|
124
124
|
},
|
|
125
125
|
"parseAnchorId": {
|
|
126
126
|
"types": "dist/processors/observational-memory/anchor-ids.d.ts",
|
|
127
|
-
"implementation": "dist/src-
|
|
127
|
+
"implementation": "dist/src-Bv05c6Nj.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-
|
|
132
|
+
"implementation": "dist/src-Bv05c6Nj.js",
|
|
133
133
|
"line": 31003
|
|
134
134
|
},
|
|
135
135
|
"parseObserverOutput": {
|
|
136
136
|
"types": "dist/processors/observational-memory/observer-agent.d.ts",
|
|
137
|
-
"implementation": "dist/src-
|
|
137
|
+
"implementation": "dist/src-Bv05c6Nj.js",
|
|
138
138
|
"line": 27573
|
|
139
139
|
},
|
|
140
140
|
"reconcileObservationGroupsFromReflection": {
|
|
141
141
|
"types": "dist/processors/observational-memory/observation-groups.d.ts",
|
|
142
|
-
"implementation": "dist/src-
|
|
142
|
+
"implementation": "dist/src-Bv05c6Nj.js",
|
|
143
143
|
"line": 31111
|
|
144
144
|
},
|
|
145
145
|
"renderObservationGroupsForReflection": {
|
|
146
146
|
"types": "dist/processors/observational-memory/observation-groups.d.ts",
|
|
147
|
-
"implementation": "dist/src-
|
|
147
|
+
"implementation": "dist/src-Bv05c6Nj.js",
|
|
148
148
|
"line": 31077
|
|
149
149
|
},
|
|
150
150
|
"resolveAutoModelId": {
|
|
151
151
|
"types": "dist/processors/observational-memory/auto-model.d.ts",
|
|
152
|
-
"implementation": "dist/src-
|
|
152
|
+
"implementation": "dist/src-Bv05c6Nj.js",
|
|
153
153
|
"line": 32965
|
|
154
154
|
},
|
|
155
155
|
"stripEphemeralAnchorIds": {
|
|
156
156
|
"types": "dist/processors/observational-memory/anchor-ids.d.ts",
|
|
157
|
-
"implementation": "dist/src-
|
|
157
|
+
"implementation": "dist/src-Bv05c6Nj.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-
|
|
162
|
+
"implementation": "dist/src-Bv05c6Nj.js",
|
|
163
163
|
"line": 31020
|
|
164
164
|
},
|
|
165
165
|
"summarizeConversation": {
|
|
166
166
|
"types": "dist/processors/observational-memory/summarize.d.ts",
|
|
167
|
-
"implementation": "dist/src-
|
|
167
|
+
"implementation": "dist/src-Bv05c6Nj.js",
|
|
168
168
|
"line": 30078
|
|
169
169
|
},
|
|
170
170
|
"wrapInObservationGroup": {
|
|
171
171
|
"types": "dist/processors/observational-memory/observation-groups.d.ts",
|
|
172
|
-
"implementation": "dist/src-
|
|
172
|
+
"implementation": "dist/src-Bv05c6Nj.js",
|
|
173
173
|
"line": 30974
|
|
174
174
|
},
|
|
175
175
|
"KnowledgeSemanticIndexCoordinator": {
|
|
176
176
|
"types": "dist/removed-subconscious.d.ts",
|
|
177
|
-
"implementation": "dist/src-
|
|
177
|
+
"implementation": "dist/src-Bv05c6Nj.js",
|
|
178
178
|
"line": 30572
|
|
179
179
|
},
|
|
180
180
|
"Memory": {
|
|
181
181
|
"types": "dist/index.d.ts",
|
|
182
|
-
"implementation": "dist/src-
|
|
183
|
-
"line":
|
|
182
|
+
"implementation": "dist/src-Bv05c6Nj.js",
|
|
183
|
+
"line": 41495
|
|
184
184
|
},
|
|
185
185
|
"SUMMARIZE_THREAD_DEFAULTS": {
|
|
186
186
|
"types": "dist/processors/observational-memory/summarize.d.ts",
|
|
187
|
-
"implementation": "dist/src-
|
|
187
|
+
"implementation": "dist/src-Bv05c6Nj.js",
|
|
188
188
|
"line": 30034
|
|
189
189
|
},
|
|
190
190
|
"StaleKnowledgeSemanticIndexError": {
|
|
191
191
|
"types": "dist/removed-subconscious.d.ts",
|
|
192
|
-
"implementation": "dist/src-
|
|
192
|
+
"implementation": "dist/src-Bv05c6Nj.js",
|
|
193
193
|
"line": 30578
|
|
194
194
|
},
|
|
195
195
|
"Subconscious": {
|
|
196
196
|
"types": "dist/removed-subconscious.d.ts",
|
|
197
|
-
"implementation": "dist/src-
|
|
197
|
+
"implementation": "dist/src-Bv05c6Nj.js",
|
|
198
198
|
"line": 30566
|
|
199
199
|
},
|
|
200
200
|
"WORKING_MEMORY_STATE_ID": {
|
|
201
201
|
"types": "dist/processors/working-memory-state/processor.d.ts",
|
|
202
|
-
"implementation": "dist/src-
|
|
202
|
+
"implementation": "dist/src-Bv05c6Nj.js",
|
|
203
203
|
"line": 32774
|
|
204
204
|
},
|
|
205
205
|
"WORKING_MEMORY_STATE_PROCESSOR_ID": {
|
|
206
206
|
"types": "dist/processors/working-memory-state/processor.d.ts",
|
|
207
|
-
"implementation": "dist/src-
|
|
207
|
+
"implementation": "dist/src-Bv05c6Nj.js",
|
|
208
208
|
"line": 32775
|
|
209
209
|
},
|
|
210
210
|
"WorkingMemoryStateProcessor": {
|
|
211
211
|
"types": "dist/processors/working-memory-state/processor.d.ts",
|
|
212
|
-
"implementation": "dist/src-
|
|
212
|
+
"implementation": "dist/src-Bv05c6Nj.js",
|
|
213
213
|
"line": 32776
|
|
214
214
|
},
|
|
215
215
|
"deepMergeWorkingMemory": {
|
|
216
216
|
"types": "dist/tools/working-memory.d.ts",
|
|
217
|
-
"implementation": "dist/src-
|
|
217
|
+
"implementation": "dist/src-Bv05c6Nj.js",
|
|
218
218
|
"line": 30157
|
|
219
219
|
},
|
|
220
220
|
"extractWorkingMemoryContent": {
|
|
221
221
|
"types": "dist/index.d.ts",
|
|
222
|
-
"implementation": "dist/src-
|
|
223
|
-
"line":
|
|
222
|
+
"implementation": "dist/src-Bv05c6Nj.js",
|
|
223
|
+
"line": 41308
|
|
224
224
|
},
|
|
225
225
|
"extractWorkingMemoryTags": {
|
|
226
226
|
"types": "dist/index.d.ts",
|
|
227
|
-
"implementation": "dist/src-
|
|
228
|
-
"line":
|
|
227
|
+
"implementation": "dist/src-Bv05c6Nj.js",
|
|
228
|
+
"line": 41276
|
|
229
229
|
},
|
|
230
230
|
"removeWorkingMemoryTags": {
|
|
231
231
|
"types": "dist/index.d.ts",
|
|
232
|
-
"implementation": "dist/src-
|
|
233
|
-
"line":
|
|
232
|
+
"implementation": "dist/src-Bv05c6Nj.js",
|
|
233
|
+
"line": 41289
|
|
234
234
|
}
|
|
235
235
|
},
|
|
236
236
|
"modules": {
|
|
237
237
|
"processors": {
|
|
238
238
|
"index": "dist/processors/index.js",
|
|
239
239
|
"chunks": [
|
|
240
|
-
"src-
|
|
240
|
+
"src-Bv05c6Nj.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
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_src = require("./src-
|
|
2
|
+
const require_src = require("./src-D2dL-xVG.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
|
@@ -528,9 +528,13 @@ export declare class Memory extends MastraMemory {
|
|
|
528
528
|
* @param args.resourceId - Resource ID for the new thread (defaults to source thread's resourceId)
|
|
529
529
|
* @param args.title - Title for the new cloned thread
|
|
530
530
|
* @param args.metadata - Additional metadata to merge with clone metadata
|
|
531
|
-
* @param args.options - Options for filtering which messages to include
|
|
531
|
+
* @param args.options - Options for filtering which messages to include. Without a filter or
|
|
532
|
+
* limit, every message is copied.
|
|
532
533
|
* @param args.options.messageLimit - Maximum number of messages to copy (from most recent)
|
|
533
534
|
* @param args.options.messageFilter - Filter messages by date range or specific IDs
|
|
535
|
+
* @param args.options.contextWindowOnly - With observational memory, copy only the messages after
|
|
536
|
+
* `lastObservedAt`, the ones still in the context window. Can't be combined with `messageFilter`
|
|
537
|
+
* or `messageLimit`.
|
|
534
538
|
* @param memoryConfig - Optional memory configuration override
|
|
535
539
|
* @returns The newly created thread and the cloned messages
|
|
536
540
|
*
|
|
@@ -606,6 +610,14 @@ export declare class Memory extends MastraMemory {
|
|
|
606
610
|
* merged, because filter-based updates replace the whole metadata object on some stores.
|
|
607
611
|
*/
|
|
608
612
|
private moveObservationVectors;
|
|
613
|
+
/**
|
|
614
|
+
* With observational memory, the context window is the observations plus the messages created
|
|
615
|
+
* after `lastObservedAt`, read from the record the configured engine reads (`contextOM`), as
|
|
616
|
+
* `getContext` does. When the caller asks for `contextWindowOnly`, copy only those messages: the
|
|
617
|
+
* observations carry the rest. Otherwise copy what the caller's filter or limit selects, or every
|
|
618
|
+
* message. `contextWindowOnly` is `Memory`'s own option and never reaches the storage copy.
|
|
619
|
+
*/
|
|
620
|
+
private withContextWindowFilter;
|
|
609
621
|
/**
|
|
610
622
|
* Clone observational memory records when cloning a thread.
|
|
611
623
|
* 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-
|
|
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-Bv05c6Nj.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_src = require("../src-
|
|
2
|
+
const require_src = require("../src-D2dL-xVG.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;
|
package/dist/processors/index.js
CHANGED
|
@@ -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-
|
|
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-Bv05c6Nj.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
|
|
50
|
-
*
|
|
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
|
|
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
|
|
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,7 +64,7 @@ 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>`
|
|
67
|
+
* Placed with the observations preamble, before the `<observations>` blocks.
|
|
68
68
|
*/
|
|
69
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.";
|
|
70
70
|
/**
|
|
@@ -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
|
|
24208
|
-
*
|
|
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
|
|
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
|
|
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>`
|
|
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
|
|
|
@@ -38987,8 +38987,7 @@ var ObservationalMemory = class ObservationalMemory {
|
|
|
38987
38987
|
if (currentDate) optimized = addRelativeTimeToObservations(optimized, currentDate, timeZone);
|
|
38988
38988
|
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
38989
|
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
|
|
38991
|
-
if (observationChunks.length > 0) messages.push("<observations>", ...observationChunks, "</observations>");
|
|
38990
|
+
for (const chunk of this.splitObservationContextChunks(optimized)) messages.push(`<observations>\n${chunk}\n</observations>`);
|
|
38992
38991
|
if (currentTask) messages.push(`<current-task>\n${currentTask}\n</current-task>`);
|
|
38993
38992
|
if (suggestedResponse) messages.push(`<suggested-response>\n${suggestedResponse}\n</suggested-response>`);
|
|
38994
38993
|
messages.push(...buildExtractedValueContextSections([...this.observationConfig.extractors, ...this.reflectionConfig.extractors], extractedValues));
|
|
@@ -43269,9 +43268,13 @@ Notes:
|
|
|
43269
43268
|
* @param args.resourceId - Resource ID for the new thread (defaults to source thread's resourceId)
|
|
43270
43269
|
* @param args.title - Title for the new cloned thread
|
|
43271
43270
|
* @param args.metadata - Additional metadata to merge with clone metadata
|
|
43272
|
-
* @param args.options - Options for filtering which messages to include
|
|
43271
|
+
* @param args.options - Options for filtering which messages to include. Without a filter or
|
|
43272
|
+
* limit, every message is copied.
|
|
43273
43273
|
* @param args.options.messageLimit - Maximum number of messages to copy (from most recent)
|
|
43274
43274
|
* @param args.options.messageFilter - Filter messages by date range or specific IDs
|
|
43275
|
+
* @param args.options.contextWindowOnly - With observational memory, copy only the messages after
|
|
43276
|
+
* `lastObservedAt`, the ones still in the context window. Can't be combined with `messageFilter`
|
|
43277
|
+
* or `messageLimit`.
|
|
43275
43278
|
* @param memoryConfig - Optional memory configuration override
|
|
43276
43279
|
* @returns The newly created thread and the cloned messages
|
|
43277
43280
|
*
|
|
@@ -43341,8 +43344,11 @@ Notes:
|
|
|
43341
43344
|
async copyThread(args, memoryConfig) {
|
|
43342
43345
|
const memoryStore = await this.getMemoryStore();
|
|
43343
43346
|
const config = this.getMergedThreadConfig(memoryConfig);
|
|
43344
|
-
const result = await memoryStore.copyThread(args);
|
|
43345
43347
|
const sourceResourceId = (await this.getThreadById({ threadId: args.sourceThreadId }))?.resourceId;
|
|
43348
|
+
const omEngine = await this.omEngine;
|
|
43349
|
+
const liveContextOM = omEngine && sourceResourceId ? await omEngine.getRecord(args.sourceThreadId, sourceResourceId) : null;
|
|
43350
|
+
const contextOM = liveContextOM ? structuredClone(liveContextOM) : null;
|
|
43351
|
+
const result = await memoryStore.copyThread(this.withContextWindowFilter(args, contextOM));
|
|
43346
43352
|
let priorDestinationResourceWm;
|
|
43347
43353
|
if (config.workingMemory?.enabled) {
|
|
43348
43354
|
const scope = config.workingMemory.scope || "resource";
|
|
@@ -43364,7 +43370,7 @@ Notes:
|
|
|
43364
43370
|
}
|
|
43365
43371
|
}
|
|
43366
43372
|
if (memoryStore.supportsObservationalMemory && sourceResourceId) try {
|
|
43367
|
-
await this.cloneObservationalMemory(memoryStore, args.sourceThreadId, sourceResourceId, result);
|
|
43373
|
+
await this.cloneObservationalMemory(memoryStore, args.sourceThreadId, sourceResourceId, result, contextOM);
|
|
43368
43374
|
} catch (error) {
|
|
43369
43375
|
await this.rollbackCopiedThread(memoryStore, result.thread, "OM clone", false, priorDestinationResourceWm);
|
|
43370
43376
|
throw error;
|
|
@@ -43557,13 +43563,38 @@ Notes:
|
|
|
43557
43563
|
}
|
|
43558
43564
|
}
|
|
43559
43565
|
/**
|
|
43566
|
+
* With observational memory, the context window is the observations plus the messages created
|
|
43567
|
+
* after `lastObservedAt`, read from the record the configured engine reads (`contextOM`), as
|
|
43568
|
+
* `getContext` does. When the caller asks for `contextWindowOnly`, copy only those messages: the
|
|
43569
|
+
* observations carry the rest. Otherwise copy what the caller's filter or limit selects, or every
|
|
43570
|
+
* message. `contextWindowOnly` is `Memory`'s own option and never reaches the storage copy.
|
|
43571
|
+
*/
|
|
43572
|
+
withContextWindowFilter(args, contextOM) {
|
|
43573
|
+
const { contextWindowOnly, ...options } = args.options ?? {};
|
|
43574
|
+
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");
|
|
43575
|
+
const storageArgs = args.options ? {
|
|
43576
|
+
...args,
|
|
43577
|
+
options
|
|
43578
|
+
} : args;
|
|
43579
|
+
if (!contextWindowOnly || !contextOM?.lastObservedAt) return storageArgs;
|
|
43580
|
+
const startDate = new Date(new Date(contextOM.lastObservedAt).getTime() + 1);
|
|
43581
|
+
return {
|
|
43582
|
+
...storageArgs,
|
|
43583
|
+
options: {
|
|
43584
|
+
...options,
|
|
43585
|
+
messageFilter: { startDate }
|
|
43586
|
+
}
|
|
43587
|
+
};
|
|
43588
|
+
}
|
|
43589
|
+
/**
|
|
43560
43590
|
* Clone observational memory records when cloning a thread.
|
|
43561
43591
|
* Thread-scoped: always cloned to the new thread.
|
|
43562
43592
|
* Resource-scoped: cloned only when the resourceId changes (same resourceId shares OM naturally).
|
|
43563
43593
|
* All stored message/thread IDs are remapped to the cloned IDs.
|
|
43564
43594
|
*/
|
|
43565
|
-
async cloneObservationalMemory(memoryStore, sourceThreadId, sourceResourceId, result) {
|
|
43566
|
-
let sourceOM =
|
|
43595
|
+
async cloneObservationalMemory(memoryStore, sourceThreadId, sourceResourceId, result, contextOM) {
|
|
43596
|
+
let sourceOM = contextOM;
|
|
43597
|
+
if (!sourceOM) sourceOM = await memoryStore.getObservationalMemory(sourceThreadId, sourceResourceId);
|
|
43567
43598
|
if (!sourceOM) sourceOM = await memoryStore.getObservationalMemory(null, sourceResourceId);
|
|
43568
43599
|
if (!sourceOM) return;
|
|
43569
43600
|
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
|
|
24230
|
-
*
|
|
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
|
|
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
|
|
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>`
|
|
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
|
|
|
@@ -39009,8 +39009,7 @@ var ObservationalMemory = class ObservationalMemory {
|
|
|
39009
39009
|
if (currentDate) optimized = addRelativeTimeToObservations(optimized, currentDate, timeZone);
|
|
39010
39010
|
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
39011
|
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
|
|
39013
|
-
if (observationChunks.length > 0) messages.push("<observations>", ...observationChunks, "</observations>");
|
|
39012
|
+
for (const chunk of this.splitObservationContextChunks(optimized)) messages.push(`<observations>\n${chunk}\n</observations>`);
|
|
39014
39013
|
if (currentTask) messages.push(`<current-task>\n${currentTask}\n</current-task>`);
|
|
39015
39014
|
if (suggestedResponse) messages.push(`<suggested-response>\n${suggestedResponse}\n</suggested-response>`);
|
|
39016
39015
|
messages.push(...buildExtractedValueContextSections([...this.observationConfig.extractors, ...this.reflectionConfig.extractors], extractedValues));
|
|
@@ -43291,9 +43290,13 @@ Notes:
|
|
|
43291
43290
|
* @param args.resourceId - Resource ID for the new thread (defaults to source thread's resourceId)
|
|
43292
43291
|
* @param args.title - Title for the new cloned thread
|
|
43293
43292
|
* @param args.metadata - Additional metadata to merge with clone metadata
|
|
43294
|
-
* @param args.options - Options for filtering which messages to include
|
|
43293
|
+
* @param args.options - Options for filtering which messages to include. Without a filter or
|
|
43294
|
+
* limit, every message is copied.
|
|
43295
43295
|
* @param args.options.messageLimit - Maximum number of messages to copy (from most recent)
|
|
43296
43296
|
* @param args.options.messageFilter - Filter messages by date range or specific IDs
|
|
43297
|
+
* @param args.options.contextWindowOnly - With observational memory, copy only the messages after
|
|
43298
|
+
* `lastObservedAt`, the ones still in the context window. Can't be combined with `messageFilter`
|
|
43299
|
+
* or `messageLimit`.
|
|
43297
43300
|
* @param memoryConfig - Optional memory configuration override
|
|
43298
43301
|
* @returns The newly created thread and the cloned messages
|
|
43299
43302
|
*
|
|
@@ -43363,8 +43366,11 @@ Notes:
|
|
|
43363
43366
|
async copyThread(args, memoryConfig) {
|
|
43364
43367
|
const memoryStore = await this.getMemoryStore();
|
|
43365
43368
|
const config = this.getMergedThreadConfig(memoryConfig);
|
|
43366
|
-
const result = await memoryStore.copyThread(args);
|
|
43367
43369
|
const sourceResourceId = (await this.getThreadById({ threadId: args.sourceThreadId }))?.resourceId;
|
|
43370
|
+
const omEngine = await this.omEngine;
|
|
43371
|
+
const liveContextOM = omEngine && sourceResourceId ? await omEngine.getRecord(args.sourceThreadId, sourceResourceId) : null;
|
|
43372
|
+
const contextOM = liveContextOM ? structuredClone(liveContextOM) : null;
|
|
43373
|
+
const result = await memoryStore.copyThread(this.withContextWindowFilter(args, contextOM));
|
|
43368
43374
|
let priorDestinationResourceWm;
|
|
43369
43375
|
if (config.workingMemory?.enabled) {
|
|
43370
43376
|
const scope = config.workingMemory.scope || "resource";
|
|
@@ -43386,7 +43392,7 @@ Notes:
|
|
|
43386
43392
|
}
|
|
43387
43393
|
}
|
|
43388
43394
|
if (memoryStore.supportsObservationalMemory && sourceResourceId) try {
|
|
43389
|
-
await this.cloneObservationalMemory(memoryStore, args.sourceThreadId, sourceResourceId, result);
|
|
43395
|
+
await this.cloneObservationalMemory(memoryStore, args.sourceThreadId, sourceResourceId, result, contextOM);
|
|
43390
43396
|
} catch (error) {
|
|
43391
43397
|
await this.rollbackCopiedThread(memoryStore, result.thread, "OM clone", false, priorDestinationResourceWm);
|
|
43392
43398
|
throw error;
|
|
@@ -43579,13 +43585,38 @@ Notes:
|
|
|
43579
43585
|
}
|
|
43580
43586
|
}
|
|
43581
43587
|
/**
|
|
43588
|
+
* With observational memory, the context window is the observations plus the messages created
|
|
43589
|
+
* after `lastObservedAt`, read from the record the configured engine reads (`contextOM`), as
|
|
43590
|
+
* `getContext` does. When the caller asks for `contextWindowOnly`, copy only those messages: the
|
|
43591
|
+
* observations carry the rest. Otherwise copy what the caller's filter or limit selects, or every
|
|
43592
|
+
* message. `contextWindowOnly` is `Memory`'s own option and never reaches the storage copy.
|
|
43593
|
+
*/
|
|
43594
|
+
withContextWindowFilter(args, contextOM) {
|
|
43595
|
+
const { contextWindowOnly, ...options } = args.options ?? {};
|
|
43596
|
+
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");
|
|
43597
|
+
const storageArgs = args.options ? {
|
|
43598
|
+
...args,
|
|
43599
|
+
options
|
|
43600
|
+
} : args;
|
|
43601
|
+
if (!contextWindowOnly || !contextOM?.lastObservedAt) return storageArgs;
|
|
43602
|
+
const startDate = new Date(new Date(contextOM.lastObservedAt).getTime() + 1);
|
|
43603
|
+
return {
|
|
43604
|
+
...storageArgs,
|
|
43605
|
+
options: {
|
|
43606
|
+
...options,
|
|
43607
|
+
messageFilter: { startDate }
|
|
43608
|
+
}
|
|
43609
|
+
};
|
|
43610
|
+
}
|
|
43611
|
+
/**
|
|
43582
43612
|
* Clone observational memory records when cloning a thread.
|
|
43583
43613
|
* Thread-scoped: always cloned to the new thread.
|
|
43584
43614
|
* Resource-scoped: cloned only when the resourceId changes (same resourceId shares OM naturally).
|
|
43585
43615
|
* All stored message/thread IDs are remapped to the cloned IDs.
|
|
43586
43616
|
*/
|
|
43587
|
-
async cloneObservationalMemory(memoryStore, sourceThreadId, sourceResourceId, result) {
|
|
43588
|
-
let sourceOM =
|
|
43617
|
+
async cloneObservationalMemory(memoryStore, sourceThreadId, sourceResourceId, result, contextOM) {
|
|
43618
|
+
let sourceOM = contextOM;
|
|
43619
|
+
if (!sourceOM) sourceOM = await memoryStore.getObservationalMemory(sourceThreadId, sourceResourceId);
|
|
43589
43620
|
if (!sourceOM) sourceOM = await memoryStore.getObservationalMemory(null, sourceResourceId);
|
|
43590
43621
|
if (!sourceOM) return;
|
|
43591
43622
|
const clonedThreadId = result.thread.id;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/memory",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.42.0-alpha.2",
|
|
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.
|
|
76
|
+
"@mastra/core": "1.87.0-alpha.11"
|
|
77
77
|
},
|
|
78
78
|
"peerDependencies": {
|
|
79
79
|
"@mastra/core": ">=1.85.1-0 <2.0.0-0"
|