@mastra/memory 1.16.0-alpha.3 → 1.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +56 -0
- package/dist/{chunk-3MHY4GB4.cjs → chunk-HAUWGR76.cjs} +5 -3
- package/dist/chunk-HAUWGR76.cjs.map +1 -0
- package/dist/{chunk-25XLVCFF.js → chunk-OOA4C7IX.js} +5 -3
- package/dist/chunk-OOA4C7IX.js.map +1 -0
- package/dist/docs/SKILL.md +2 -1
- package/dist/docs/assets/SOURCE_MAP.json +27 -27
- package/dist/docs/references/docs-memory-storage.md +1 -0
- package/dist/docs/references/reference-storage-redis.md +266 -0
- package/dist/index.cjs +13 -13
- package/dist/index.js +4 -4
- package/dist/{observational-memory-IL63MWVI.js → observational-memory-CIGODMXV.js} +3 -3
- package/dist/{observational-memory-IL63MWVI.js.map → observational-memory-CIGODMXV.js.map} +1 -1
- package/dist/{observational-memory-FPGLTCDV.cjs → observational-memory-EWU3QFIE.cjs} +26 -26
- package/dist/{observational-memory-FPGLTCDV.cjs.map → observational-memory-EWU3QFIE.cjs.map} +1 -1
- package/dist/processors/index.cjs +24 -24
- package/dist/processors/index.js +1 -1
- package/dist/processors/observational-memory/observational-memory.d.ts.map +1 -1
- package/package.json +12 -12
- package/dist/chunk-25XLVCFF.js.map +0 -1
- package/dist/chunk-3MHY4GB4.cjs.map +0 -1
package/dist/docs/SKILL.md
CHANGED
|
@@ -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.16.0
|
|
6
|
+
version: "1.16.0"
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
## When to use
|
|
@@ -43,6 +43,7 @@ Read the individual reference documents for detailed explanations and code examp
|
|
|
43
43
|
- [Reference: libSQL storage](references/reference-storage-libsql.md) - Documentation for the libSQL storage implementation in Mastra.
|
|
44
44
|
- [Reference: MongoDB storage](references/reference-storage-mongodb.md) - Documentation for the MongoDB storage implementation in Mastra.
|
|
45
45
|
- [Reference: PostgreSQL storage](references/reference-storage-postgresql.md) - Documentation for the PostgreSQL storage implementation in Mastra.
|
|
46
|
+
- [Reference: Redis Storage](references/reference-storage-redis.md) - Documentation for the Redis storage implementation in Mastra.
|
|
46
47
|
- [Reference: Upstash storage](references/reference-storage-upstash.md) - Documentation for the Upstash storage implementation in Mastra.
|
|
47
48
|
- [Reference: libSQL vector store](references/reference-vectors-libsql.md) - Documentation for the LibSQLVector class in Mastra, which provides vector search using libSQL with vector extensions.
|
|
48
49
|
- [Reference: MongoDB vector store](references/reference-vectors-mongodb.md) - Documentation for the MongoDBVector class in Mastra, which provides vector search using MongoDB Atlas and Atlas Vector Search.
|
|
@@ -1,119 +1,119 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.16.0
|
|
2
|
+
"version": "1.16.0",
|
|
3
3
|
"package": "@mastra/memory",
|
|
4
4
|
"exports": {
|
|
5
5
|
"ModelByInputTokens": {
|
|
6
6
|
"types": "dist/processors/index.d.ts",
|
|
7
|
-
"implementation": "dist/chunk-
|
|
7
|
+
"implementation": "dist/chunk-OOA4C7IX.js",
|
|
8
8
|
"line": 684
|
|
9
9
|
},
|
|
10
10
|
"OBSERVER_SYSTEM_PROMPT": {
|
|
11
11
|
"types": "dist/processors/index.d.ts",
|
|
12
|
-
"implementation": "dist/chunk-
|
|
12
|
+
"implementation": "dist/chunk-OOA4C7IX.js"
|
|
13
13
|
},
|
|
14
14
|
"ObservationalMemory": {
|
|
15
15
|
"types": "dist/processors/index.d.ts",
|
|
16
|
-
"implementation": "dist/chunk-
|
|
16
|
+
"implementation": "dist/chunk-OOA4C7IX.js",
|
|
17
17
|
"line": 6432
|
|
18
18
|
},
|
|
19
19
|
"ObservationalMemoryProcessor": {
|
|
20
20
|
"types": "dist/processors/index.d.ts",
|
|
21
|
-
"implementation": "dist/chunk-
|
|
22
|
-
"line":
|
|
21
|
+
"implementation": "dist/chunk-OOA4C7IX.js",
|
|
22
|
+
"line": 8870
|
|
23
23
|
},
|
|
24
24
|
"TokenCounter": {
|
|
25
25
|
"types": "dist/processors/index.d.ts",
|
|
26
|
-
"implementation": "dist/chunk-
|
|
26
|
+
"implementation": "dist/chunk-OOA4C7IX.js",
|
|
27
27
|
"line": 5902
|
|
28
28
|
},
|
|
29
29
|
"buildObserverPrompt": {
|
|
30
30
|
"types": "dist/processors/index.d.ts",
|
|
31
|
-
"implementation": "dist/chunk-
|
|
31
|
+
"implementation": "dist/chunk-OOA4C7IX.js",
|
|
32
32
|
"line": 3443
|
|
33
33
|
},
|
|
34
34
|
"buildObserverSystemPrompt": {
|
|
35
35
|
"types": "dist/processors/index.d.ts",
|
|
36
|
-
"implementation": "dist/chunk-
|
|
36
|
+
"implementation": "dist/chunk-OOA4C7IX.js",
|
|
37
37
|
"line": 2842
|
|
38
38
|
},
|
|
39
39
|
"combineObservationGroupRanges": {
|
|
40
40
|
"types": "dist/processors/index.d.ts",
|
|
41
|
-
"implementation": "dist/chunk-
|
|
41
|
+
"implementation": "dist/chunk-OOA4C7IX.js",
|
|
42
42
|
"line": 776
|
|
43
43
|
},
|
|
44
44
|
"deriveObservationGroupProvenance": {
|
|
45
45
|
"types": "dist/processors/index.d.ts",
|
|
46
|
-
"implementation": "dist/chunk-
|
|
46
|
+
"implementation": "dist/chunk-OOA4C7IX.js",
|
|
47
47
|
"line": 810
|
|
48
48
|
},
|
|
49
49
|
"extractCurrentTask": {
|
|
50
50
|
"types": "dist/processors/index.d.ts",
|
|
51
|
-
"implementation": "dist/chunk-
|
|
51
|
+
"implementation": "dist/chunk-OOA4C7IX.js",
|
|
52
52
|
"line": 3557
|
|
53
53
|
},
|
|
54
54
|
"formatMessagesForObserver": {
|
|
55
55
|
"types": "dist/processors/index.d.ts",
|
|
56
|
-
"implementation": "dist/chunk-
|
|
56
|
+
"implementation": "dist/chunk-OOA4C7IX.js",
|
|
57
57
|
"line": 3169
|
|
58
58
|
},
|
|
59
59
|
"getObservationsAsOf": {
|
|
60
60
|
"types": "dist/processors/index.d.ts",
|
|
61
|
-
"implementation": "dist/chunk-
|
|
62
|
-
"line":
|
|
61
|
+
"implementation": "dist/chunk-OOA4C7IX.js",
|
|
62
|
+
"line": 9056
|
|
63
63
|
},
|
|
64
64
|
"hasCurrentTaskSection": {
|
|
65
65
|
"types": "dist/processors/index.d.ts",
|
|
66
|
-
"implementation": "dist/chunk-
|
|
66
|
+
"implementation": "dist/chunk-OOA4C7IX.js",
|
|
67
67
|
"line": 3545
|
|
68
68
|
},
|
|
69
69
|
"injectAnchorIds": {
|
|
70
70
|
"types": "dist/processors/index.d.ts",
|
|
71
|
-
"implementation": "dist/chunk-
|
|
71
|
+
"implementation": "dist/chunk-OOA4C7IX.js",
|
|
72
72
|
"line": 2399
|
|
73
73
|
},
|
|
74
74
|
"optimizeObservationsForContext": {
|
|
75
75
|
"types": "dist/processors/index.d.ts",
|
|
76
|
-
"implementation": "dist/chunk-
|
|
76
|
+
"implementation": "dist/chunk-OOA4C7IX.js",
|
|
77
77
|
"line": 3568
|
|
78
78
|
},
|
|
79
79
|
"parseAnchorId": {
|
|
80
80
|
"types": "dist/processors/index.d.ts",
|
|
81
|
-
"implementation": "dist/chunk-
|
|
81
|
+
"implementation": "dist/chunk-OOA4C7IX.js",
|
|
82
82
|
"line": 2372
|
|
83
83
|
},
|
|
84
84
|
"parseObservationGroups": {
|
|
85
85
|
"types": "dist/processors/index.d.ts",
|
|
86
|
-
"implementation": "dist/chunk-
|
|
86
|
+
"implementation": "dist/chunk-OOA4C7IX.js",
|
|
87
87
|
"line": 745
|
|
88
88
|
},
|
|
89
89
|
"parseObserverOutput": {
|
|
90
90
|
"types": "dist/processors/index.d.ts",
|
|
91
|
-
"implementation": "dist/chunk-
|
|
91
|
+
"implementation": "dist/chunk-OOA4C7IX.js",
|
|
92
92
|
"line": 3453
|
|
93
93
|
},
|
|
94
94
|
"reconcileObservationGroupsFromReflection": {
|
|
95
95
|
"types": "dist/processors/index.d.ts",
|
|
96
|
-
"implementation": "dist/chunk-
|
|
96
|
+
"implementation": "dist/chunk-OOA4C7IX.js",
|
|
97
97
|
"line": 834
|
|
98
98
|
},
|
|
99
99
|
"renderObservationGroupsForReflection": {
|
|
100
100
|
"types": "dist/processors/index.d.ts",
|
|
101
|
-
"implementation": "dist/chunk-
|
|
101
|
+
"implementation": "dist/chunk-OOA4C7IX.js",
|
|
102
102
|
"line": 790
|
|
103
103
|
},
|
|
104
104
|
"stripEphemeralAnchorIds": {
|
|
105
105
|
"types": "dist/processors/index.d.ts",
|
|
106
|
-
"implementation": "dist/chunk-
|
|
106
|
+
"implementation": "dist/chunk-OOA4C7IX.js",
|
|
107
107
|
"line": 2429
|
|
108
108
|
},
|
|
109
109
|
"stripObservationGroups": {
|
|
110
110
|
"types": "dist/processors/index.d.ts",
|
|
111
|
-
"implementation": "dist/chunk-
|
|
111
|
+
"implementation": "dist/chunk-OOA4C7IX.js",
|
|
112
112
|
"line": 767
|
|
113
113
|
},
|
|
114
114
|
"wrapInObservationGroup": {
|
|
115
115
|
"types": "dist/processors/index.d.ts",
|
|
116
|
-
"implementation": "dist/chunk-
|
|
116
|
+
"implementation": "dist/chunk-OOA4C7IX.js",
|
|
117
117
|
"line": 738
|
|
118
118
|
},
|
|
119
119
|
"OBSERVATIONAL_MEMORY_DEFAULTS": {
|
|
@@ -161,7 +161,7 @@
|
|
|
161
161
|
"processors": {
|
|
162
162
|
"index": "dist/processors/index.js",
|
|
163
163
|
"chunks": [
|
|
164
|
-
"chunk-
|
|
164
|
+
"chunk-OOA4C7IX.js",
|
|
165
165
|
"chunk-LSJJAJAF.js"
|
|
166
166
|
]
|
|
167
167
|
}
|
|
@@ -34,6 +34,7 @@ Each provider page includes installation instructions, configuration parameters,
|
|
|
34
34
|
- [PostgreSQL](https://mastra.ai/reference/storage/postgresql)
|
|
35
35
|
- [MongoDB](https://mastra.ai/reference/storage/mongodb)
|
|
36
36
|
- [Upstash](https://mastra.ai/reference/storage/upstash)
|
|
37
|
+
- [Redis](https://mastra.ai/reference/storage/redis)
|
|
37
38
|
- [Cloudflare D1](https://mastra.ai/reference/storage/cloudflare-d1)
|
|
38
39
|
- [Cloudflare KV & Durable Objects](https://mastra.ai/reference/storage/cloudflare)
|
|
39
40
|
- [Convex](https://mastra.ai/reference/storage/convex)
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
# Redis Storage
|
|
2
|
+
|
|
3
|
+
The Redis storage implementation provides a high-performance storage solution using direct Redis connections via [node-redis](https://github.com/redis/node-redis) (the official Redis client for Node.js). It supports standalone Redis, and through custom client configuration, Redis Sentinel and Cluster deployments.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @mastra/redis
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### Using Connection String
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { RedisStore } from '@mastra/redis'
|
|
17
|
+
|
|
18
|
+
const storage = new RedisStore({
|
|
19
|
+
id: 'redis-storage',
|
|
20
|
+
connectionString: 'redis://localhost:6379',
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
await storage.init()
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Using Host/Port Configuration
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import { RedisStore } from '@mastra/redis'
|
|
30
|
+
|
|
31
|
+
const storage = new RedisStore({
|
|
32
|
+
id: 'redis-storage',
|
|
33
|
+
host: 'localhost',
|
|
34
|
+
port: 6379,
|
|
35
|
+
password: 'your-password',
|
|
36
|
+
db: 0,
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
await storage.init()
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Using Pre-configured Client
|
|
43
|
+
|
|
44
|
+
For advanced configurations like Sentinel or Cluster, you can pass a pre-configured redis client:
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
import { RedisStore } from '@mastra/redis'
|
|
48
|
+
import { createClient } from 'redis'
|
|
49
|
+
|
|
50
|
+
const client = createClient({
|
|
51
|
+
url: 'redis://localhost:6379',
|
|
52
|
+
socket: {
|
|
53
|
+
reconnectStrategy: retries => Math.min(retries * 50, 2000),
|
|
54
|
+
},
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
// Connect the client before passing to RedisStore
|
|
58
|
+
await client.connect()
|
|
59
|
+
|
|
60
|
+
const storage = new RedisStore({
|
|
61
|
+
id: 'redis-storage',
|
|
62
|
+
client,
|
|
63
|
+
})
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Parameters
|
|
67
|
+
|
|
68
|
+
**id** (`string`): Unique identifier for the storage instance
|
|
69
|
+
|
|
70
|
+
**connectionString** (`string`): Redis connection URL (e.g., \`redis\://localhost:6379\` or \`redis\://:password\@localhost:6379\`)
|
|
71
|
+
|
|
72
|
+
**host** (`string`): Redis host address
|
|
73
|
+
|
|
74
|
+
**port** (`number`): Redis port number (Default: `6379`)
|
|
75
|
+
|
|
76
|
+
**password** (`string`): Redis password for authentication
|
|
77
|
+
|
|
78
|
+
**db** (`number`): Redis database number (Default: `0`)
|
|
79
|
+
|
|
80
|
+
**client** (`RedisClient`): Pre-configured redis client (from the \`redis\` package) for advanced setups
|
|
81
|
+
|
|
82
|
+
> **Note:** You must provide either `connectionString`, `host`, or `client`. These options are mutually exclusive.
|
|
83
|
+
|
|
84
|
+
## Additional Notes
|
|
85
|
+
|
|
86
|
+
### Key Structure
|
|
87
|
+
|
|
88
|
+
The Redis storage implementation uses the following key patterns:
|
|
89
|
+
|
|
90
|
+
- Threads: `mastra_threads:id:{threadId}`
|
|
91
|
+
- Messages: `mastra_messages:threadId:{threadId}:id:{messageId}`
|
|
92
|
+
- Message index: `msg-idx:{messageId}` (for fast lookups)
|
|
93
|
+
- Thread messages sorted set: `thread:{threadId}:messages`
|
|
94
|
+
- Workflow snapshots: `mastra_workflow_snapshot:namespace:{ns}:workflow_name:{name}:run_id:{id}`
|
|
95
|
+
- Scores: `mastra_scorers:id:{scoreId}`
|
|
96
|
+
- Resources: `mastra_resources:{resourceId}`
|
|
97
|
+
|
|
98
|
+
### Redis Sentinel
|
|
99
|
+
|
|
100
|
+
For high-availability deployments using Redis Sentinel, create a custom client:
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
import { RedisStore } from '@mastra/redis'
|
|
104
|
+
import { createClient } from 'redis'
|
|
105
|
+
|
|
106
|
+
const client = createClient({
|
|
107
|
+
url: 'redis://sentinel-host:26379',
|
|
108
|
+
// Configure sentinel options as needed for your setup
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
await client.connect()
|
|
112
|
+
|
|
113
|
+
const storage = new RedisStore({
|
|
114
|
+
id: 'redis-sentinel-storage',
|
|
115
|
+
client,
|
|
116
|
+
})
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Redis Cluster
|
|
120
|
+
|
|
121
|
+
For Redis Cluster deployments, use the cluster client:
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
import { RedisStore } from '@mastra/redis'
|
|
125
|
+
import { createCluster } from 'redis'
|
|
126
|
+
|
|
127
|
+
const cluster = createCluster({
|
|
128
|
+
rootNodes: [
|
|
129
|
+
{ url: 'redis://node-1:6379' },
|
|
130
|
+
{ url: 'redis://node-2:6379' },
|
|
131
|
+
{ url: 'redis://node-3:6379' },
|
|
132
|
+
],
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
await cluster.connect()
|
|
136
|
+
|
|
137
|
+
const storage = new RedisStore({
|
|
138
|
+
id: 'redis-cluster-storage',
|
|
139
|
+
client: cluster,
|
|
140
|
+
})
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Accessing the Underlying Client
|
|
144
|
+
|
|
145
|
+
You can access the underlying redis client for custom operations:
|
|
146
|
+
|
|
147
|
+
```typescript
|
|
148
|
+
const storage = new RedisStore({
|
|
149
|
+
id: 'redis-storage',
|
|
150
|
+
connectionString: 'redis://localhost:6379',
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
await storage.init()
|
|
154
|
+
|
|
155
|
+
const client = storage.getClient()
|
|
156
|
+
|
|
157
|
+
// Custom Redis operations
|
|
158
|
+
await client.set('custom-key', 'value')
|
|
159
|
+
const value = await client.get('custom-key')
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Closing Connections
|
|
163
|
+
|
|
164
|
+
When shutting down your application, close the Redis connection:
|
|
165
|
+
|
|
166
|
+
```typescript
|
|
167
|
+
await storage.close()
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## Usage Example
|
|
171
|
+
|
|
172
|
+
### Adding memory to an agent
|
|
173
|
+
|
|
174
|
+
```typescript
|
|
175
|
+
import { Memory } from '@mastra/memory'
|
|
176
|
+
import { Agent } from '@mastra/core/agent'
|
|
177
|
+
import { RedisStore } from '@mastra/redis'
|
|
178
|
+
|
|
179
|
+
export const redisAgent = new Agent({
|
|
180
|
+
id: 'redis-agent',
|
|
181
|
+
name: 'Redis Agent',
|
|
182
|
+
instructions:
|
|
183
|
+
'You are an AI agent with the ability to automatically recall memories from previous interactions.',
|
|
184
|
+
model: 'openai/gpt-4o',
|
|
185
|
+
memory: new Memory({
|
|
186
|
+
storage: new RedisStore({
|
|
187
|
+
id: 'redis-agent-storage',
|
|
188
|
+
connectionString: process.env.REDIS_URL!,
|
|
189
|
+
}),
|
|
190
|
+
options: {
|
|
191
|
+
lastMessages: 10,
|
|
192
|
+
},
|
|
193
|
+
}),
|
|
194
|
+
})
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### Using the agent
|
|
198
|
+
|
|
199
|
+
```typescript
|
|
200
|
+
import 'dotenv/config'
|
|
201
|
+
|
|
202
|
+
import { mastra } from './mastra'
|
|
203
|
+
|
|
204
|
+
const threadId = '123'
|
|
205
|
+
const resourceId = 'user-456'
|
|
206
|
+
|
|
207
|
+
const agent = mastra.getAgent('redisAgent')
|
|
208
|
+
|
|
209
|
+
const message = await agent.stream('My name is Mastra', {
|
|
210
|
+
memory: {
|
|
211
|
+
thread: threadId,
|
|
212
|
+
resource: resourceId,
|
|
213
|
+
},
|
|
214
|
+
})
|
|
215
|
+
|
|
216
|
+
await message.textStream.pipeTo(new WritableStream())
|
|
217
|
+
|
|
218
|
+
const stream = await agent.stream("What's my name?", {
|
|
219
|
+
memory: {
|
|
220
|
+
thread: threadId,
|
|
221
|
+
resource: resourceId,
|
|
222
|
+
},
|
|
223
|
+
memoryOptions: {
|
|
224
|
+
lastMessages: 5,
|
|
225
|
+
},
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
for await (const chunk of stream.textStream) {
|
|
229
|
+
process.stdout.write(chunk)
|
|
230
|
+
}
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### Using with Mastra instance
|
|
234
|
+
|
|
235
|
+
```typescript
|
|
236
|
+
import { Mastra } from '@mastra/core'
|
|
237
|
+
import { RedisStore } from '@mastra/redis'
|
|
238
|
+
|
|
239
|
+
const storage = new RedisStore({
|
|
240
|
+
id: 'mastra-storage',
|
|
241
|
+
host: 'localhost',
|
|
242
|
+
port: 6379,
|
|
243
|
+
})
|
|
244
|
+
|
|
245
|
+
const mastra = new Mastra({
|
|
246
|
+
storage, // init() called automatically
|
|
247
|
+
})
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
If using storage directly without Mastra, call `init()` explicitly:
|
|
251
|
+
|
|
252
|
+
```typescript
|
|
253
|
+
import { RedisStore } from '@mastra/redis'
|
|
254
|
+
|
|
255
|
+
const storage = new RedisStore({
|
|
256
|
+
id: 'redis-storage',
|
|
257
|
+
host: 'localhost',
|
|
258
|
+
port: 6379,
|
|
259
|
+
})
|
|
260
|
+
|
|
261
|
+
await storage.init()
|
|
262
|
+
|
|
263
|
+
// Access domain-specific stores via getStore()
|
|
264
|
+
const memoryStore = await storage.getStore('memory')
|
|
265
|
+
const thread = await memoryStore?.getThreadById({ threadId: '...' })
|
|
266
|
+
```
|
package/dist/index.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var chunkCK4U3AYR_cjs = require('./chunk-CK4U3AYR.cjs');
|
|
4
4
|
var chunkIDRQZVB4_cjs = require('./chunk-IDRQZVB4.cjs');
|
|
5
|
-
var
|
|
5
|
+
var chunkHAUWGR76_cjs = require('./chunk-HAUWGR76.cjs');
|
|
6
6
|
var v3 = require('zod/v3');
|
|
7
7
|
var zod = require('zod');
|
|
8
8
|
var z4 = require('zod/v4');
|
|
@@ -15709,7 +15709,7 @@ function formatTimestamp(date) {
|
|
|
15709
15709
|
}
|
|
15710
15710
|
function truncateByTokens(text4, maxTokens, hint) {
|
|
15711
15711
|
if (tokenx.estimateTokenCount(text4) <= maxTokens) return { text: text4, wasTruncated: false };
|
|
15712
|
-
const truncated =
|
|
15712
|
+
const truncated = chunkHAUWGR76_cjs.truncateStringByTokens(text4, maxTokens);
|
|
15713
15713
|
const suffix = hint ? ` [${hint} for more]` : "";
|
|
15714
15714
|
return { text: truncated + suffix, wasTruncated: true };
|
|
15715
15715
|
}
|
|
@@ -15761,11 +15761,11 @@ ${JSON.stringify(inv.args, null, 2)}`;
|
|
|
15761
15761
|
});
|
|
15762
15762
|
}
|
|
15763
15763
|
if (inv.state === "result") {
|
|
15764
|
-
const { value: resultValue } =
|
|
15764
|
+
const { value: resultValue } = chunkHAUWGR76_cjs.resolveToolResultValue(
|
|
15765
15765
|
part,
|
|
15766
15766
|
inv.result
|
|
15767
15767
|
);
|
|
15768
|
-
const resultStr =
|
|
15768
|
+
const resultStr = chunkHAUWGR76_cjs.formatToolResultForObserver(resultValue, { maxTokens: HIGH_DETAIL_TOOL_RESULT_TOKENS });
|
|
15769
15769
|
const fullText = `[Tool Result: ${inv.toolName}]
|
|
15770
15770
|
${resultStr}`;
|
|
15771
15771
|
parts.push(makePart(msg, i, "tool-result", fullText, detail, inv.toolName));
|
|
@@ -15792,7 +15792,7 @@ ${typeof rawArgs === "string" ? rawArgs : JSON.stringify(rawArgs, null, 2)}`;
|
|
|
15792
15792
|
const toolName = part.toolName;
|
|
15793
15793
|
if (toolName) {
|
|
15794
15794
|
const rawResult = part.output ?? part.result;
|
|
15795
|
-
const resultStr =
|
|
15795
|
+
const resultStr = chunkHAUWGR76_cjs.formatToolResultForObserver(rawResult, { maxTokens: HIGH_DETAIL_TOOL_RESULT_TOKENS });
|
|
15796
15796
|
const fullText = `[Tool Result: ${toolName}]
|
|
15797
15797
|
${resultStr}`;
|
|
15798
15798
|
parts.push(makePart(msg, i, "tool-result", fullText, detail, toolName));
|
|
@@ -15871,7 +15871,7 @@ function renderFormattedParts(parts, timestamps, options) {
|
|
|
15871
15871
|
const text4 = buildRenderedText(parts, timestamps);
|
|
15872
15872
|
let totalTokens = tokenx.estimateTokenCount(text4);
|
|
15873
15873
|
if (totalTokens > options.maxTokens) {
|
|
15874
|
-
const truncated =
|
|
15874
|
+
const truncated = chunkHAUWGR76_cjs.truncateStringByTokens(text4, options.maxTokens);
|
|
15875
15875
|
return { text: truncated, truncated: true, tokenOffset: totalTokens - options.maxTokens };
|
|
15876
15876
|
}
|
|
15877
15877
|
const truncatedIndices = parts.map((p, i) => ({ part: p, index: i })).filter(({ part }) => part.text !== part.fullText).sort((a, b) => expandPriority(a.part) - expandPriority(b.part));
|
|
@@ -15904,7 +15904,7 @@ function renderFormattedParts(parts, timestamps, options) {
|
|
|
15904
15904
|
if (expandedTokens <= options.maxTokens) {
|
|
15905
15905
|
return { text: expanded, truncated: false, tokenOffset: 0 };
|
|
15906
15906
|
}
|
|
15907
|
-
const hardTruncated =
|
|
15907
|
+
const hardTruncated = chunkHAUWGR76_cjs.truncateStringByTokens(expanded, options.maxTokens);
|
|
15908
15908
|
return { text: hardTruncated, truncated: true, tokenOffset: expandedTokens - options.maxTokens };
|
|
15909
15909
|
}
|
|
15910
15910
|
async function recallPart({
|
|
@@ -15955,7 +15955,7 @@ async function recallPart({
|
|
|
15955
15955
|
|
|
15956
15956
|
`;
|
|
15957
15957
|
const fallbackText = `${fallbackNote}${firstNextPart.text}`;
|
|
15958
|
-
const truncatedText2 =
|
|
15958
|
+
const truncatedText2 = chunkHAUWGR76_cjs.truncateStringByTokens(fallbackText, maxTokens);
|
|
15959
15959
|
const wasTruncated2 = truncatedText2 !== fallbackText;
|
|
15960
15960
|
return {
|
|
15961
15961
|
text: truncatedText2,
|
|
@@ -15970,7 +15970,7 @@ async function recallPart({
|
|
|
15970
15970
|
}
|
|
15971
15971
|
throw new Error(`Part index ${partIndex} not found in message ${cursor}. Available indices: ${availableIndices}`);
|
|
15972
15972
|
}
|
|
15973
|
-
const truncatedText =
|
|
15973
|
+
const truncatedText = chunkHAUWGR76_cjs.truncateStringByTokens(target.text, maxTokens);
|
|
15974
15974
|
const wasTruncated = truncatedText !== target.text;
|
|
15975
15975
|
return {
|
|
15976
15976
|
text: truncatedText,
|
|
@@ -17601,7 +17601,7 @@ ${workingMemory}`;
|
|
|
17601
17601
|
"Observational memory requires @mastra/core support for request-response-id-rotation. Please bump @mastra/core to a newer version."
|
|
17602
17602
|
);
|
|
17603
17603
|
}
|
|
17604
|
-
const { ObservationalMemory: OMClass } = await import('./observational-memory-
|
|
17604
|
+
const { ObservationalMemory: OMClass } = await import('./observational-memory-EWU3QFIE.cjs');
|
|
17605
17605
|
const onIndexObservations = this.hasRetrievalSearch(omConfig.retrieval) ? async (observation) => {
|
|
17606
17606
|
await this.indexObservation(observation);
|
|
17607
17607
|
} : void 0;
|
|
@@ -18526,18 +18526,18 @@ Notes:
|
|
|
18526
18526
|
if (!effectiveConfig) return null;
|
|
18527
18527
|
const engine = await this.omEngine;
|
|
18528
18528
|
if (!engine) return null;
|
|
18529
|
-
const { ObservationalMemoryProcessor } = await import('./observational-memory-
|
|
18529
|
+
const { ObservationalMemoryProcessor } = await import('./observational-memory-EWU3QFIE.cjs');
|
|
18530
18530
|
return new ObservationalMemoryProcessor(engine, this);
|
|
18531
18531
|
}
|
|
18532
18532
|
};
|
|
18533
18533
|
|
|
18534
18534
|
Object.defineProperty(exports, "ModelByInputTokens", {
|
|
18535
18535
|
enumerable: true,
|
|
18536
|
-
get: function () { return
|
|
18536
|
+
get: function () { return chunkHAUWGR76_cjs.ModelByInputTokens; }
|
|
18537
18537
|
});
|
|
18538
18538
|
Object.defineProperty(exports, "getObservationsAsOf", {
|
|
18539
18539
|
enumerable: true,
|
|
18540
|
-
get: function () { return
|
|
18540
|
+
get: function () { return chunkHAUWGR76_cjs.getObservationsAsOf; }
|
|
18541
18541
|
});
|
|
18542
18542
|
Object.defineProperty(exports, "extractWorkingMemoryContent", {
|
|
18543
18543
|
enumerable: true,
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __commonJS, require_token_error, __toESM } from './chunk-SVPZMV27.js';
|
|
2
2
|
import { __commonJS as __commonJS$1, require_token_error as require_token_error$1, __toESM as __toESM$1 } from './chunk-RC6RZVYE.js';
|
|
3
|
-
import { truncateStringByTokens, resolveToolResultValue, formatToolResultForObserver } from './chunk-
|
|
4
|
-
export { ModelByInputTokens, getObservationsAsOf } from './chunk-
|
|
3
|
+
import { truncateStringByTokens, resolveToolResultValue, formatToolResultForObserver } from './chunk-OOA4C7IX.js';
|
|
4
|
+
export { ModelByInputTokens, getObservationsAsOf } from './chunk-OOA4C7IX.js';
|
|
5
5
|
import { ZodFirstPartyTypeKind } from 'zod/v3';
|
|
6
6
|
import { z } from 'zod';
|
|
7
7
|
import * as z4 from 'zod/v4';
|
|
@@ -17579,7 +17579,7 @@ ${workingMemory}`;
|
|
|
17579
17579
|
"Observational memory requires @mastra/core support for request-response-id-rotation. Please bump @mastra/core to a newer version."
|
|
17580
17580
|
);
|
|
17581
17581
|
}
|
|
17582
|
-
const { ObservationalMemory: OMClass } = await import('./observational-memory-
|
|
17582
|
+
const { ObservationalMemory: OMClass } = await import('./observational-memory-CIGODMXV.js');
|
|
17583
17583
|
const onIndexObservations = this.hasRetrievalSearch(omConfig.retrieval) ? async (observation) => {
|
|
17584
17584
|
await this.indexObservation(observation);
|
|
17585
17585
|
} : void 0;
|
|
@@ -18504,7 +18504,7 @@ Notes:
|
|
|
18504
18504
|
if (!effectiveConfig) return null;
|
|
18505
18505
|
const engine = await this.omEngine;
|
|
18506
18506
|
if (!engine) return null;
|
|
18507
|
-
const { ObservationalMemoryProcessor } = await import('./observational-memory-
|
|
18507
|
+
const { ObservationalMemoryProcessor } = await import('./observational-memory-CIGODMXV.js');
|
|
18508
18508
|
return new ObservationalMemoryProcessor(engine, this);
|
|
18509
18509
|
}
|
|
18510
18510
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { ModelByInputTokens, OBSERVER_SYSTEM_PROMPT, ObservationalMemory, ObservationalMemoryProcessor, TokenCounter, buildObserverPrompt, buildObserverSystemPrompt, combineObservationGroupRanges, deriveObservationGroupProvenance, extractCurrentTask, formatMessagesForObserver, getObservationsAsOf, hasCurrentTaskSection, injectAnchorIds, optimizeObservationsForContext, parseAnchorId, parseObservationGroups, parseObserverOutput, reconcileObservationGroupsFromReflection, renderObservationGroupsForReflection, stripEphemeralAnchorIds, stripObservationGroups, wrapInObservationGroup } from './chunk-
|
|
1
|
+
export { ModelByInputTokens, OBSERVER_SYSTEM_PROMPT, ObservationalMemory, ObservationalMemoryProcessor, TokenCounter, buildObserverPrompt, buildObserverSystemPrompt, combineObservationGroupRanges, deriveObservationGroupProvenance, extractCurrentTask, formatMessagesForObserver, getObservationsAsOf, hasCurrentTaskSection, injectAnchorIds, optimizeObservationsForContext, parseAnchorId, parseObservationGroups, parseObserverOutput, reconcileObservationGroupsFromReflection, renderObservationGroupsForReflection, stripEphemeralAnchorIds, stripObservationGroups, wrapInObservationGroup } from './chunk-OOA4C7IX.js';
|
|
2
2
|
export { OBSERVATIONAL_MEMORY_DEFAULTS, OBSERVATION_CONTEXT_INSTRUCTIONS, OBSERVATION_CONTEXT_PROMPT, OBSERVATION_CONTINUATION_HINT } from './chunk-LSJJAJAF.js';
|
|
3
|
-
//# sourceMappingURL=observational-memory-
|
|
4
|
-
//# sourceMappingURL=observational-memory-
|
|
3
|
+
//# sourceMappingURL=observational-memory-CIGODMXV.js.map
|
|
4
|
+
//# sourceMappingURL=observational-memory-CIGODMXV.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"observational-memory-
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"observational-memory-CIGODMXV.js"}
|