@mastra/libsql 0.0.0-error-handler-fix-20251020202607 → 0.0.0-esbuild-bundle-worker-20260807182016

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.
Files changed (104) hide show
  1. package/CHANGELOG.md +4789 -3
  2. package/LICENSE.md +15 -0
  3. package/README.md +30 -20
  4. package/dist/docs/SKILL.md +52 -0
  5. package/dist/docs/assets/SOURCE_MAP.json +6 -0
  6. package/dist/docs/references/docs-agents-agent-approval.md +664 -0
  7. package/dist/docs/references/docs-agents-networks.md +184 -0
  8. package/dist/docs/references/docs-deployment-workers.md +137 -0
  9. package/dist/docs/references/docs-editor-overview.md +349 -0
  10. package/dist/docs/references/docs-memory-memory-processors.md +385 -0
  11. package/dist/docs/references/docs-memory-message-history.md +348 -0
  12. package/dist/docs/references/docs-memory-multi-user-threads.md +208 -0
  13. package/dist/docs/references/docs-memory-overview.md +266 -0
  14. package/dist/docs/references/docs-memory-semantic-recall.md +401 -0
  15. package/dist/docs/references/docs-memory-working-memory.md +431 -0
  16. package/dist/docs/references/docs-storage-overview.md +214 -0
  17. package/dist/docs/references/docs-workflows-snapshots.md +240 -0
  18. package/dist/docs/references/guides-agent-frameworks-ai-sdk.md +142 -0
  19. package/dist/docs/references/guides-rag-retrieval.md +520 -0
  20. package/dist/docs/references/reference-core-getMemory.md +51 -0
  21. package/dist/docs/references/reference-core-listMemory.md +57 -0
  22. package/dist/docs/references/reference-core-mastra-class.md +153 -0
  23. package/dist/docs/references/reference-file-based-agents-memory.md +58 -0
  24. package/dist/docs/references/reference-file-based-agents-storage.md +30 -0
  25. package/dist/docs/references/reference-memory-memory-class.md +148 -0
  26. package/dist/docs/references/reference-storage-composite.md +397 -0
  27. package/dist/docs/references/reference-storage-dynamodb.md +284 -0
  28. package/dist/docs/references/reference-storage-libsql.md +143 -0
  29. package/dist/docs/references/reference-storage-retention.md +248 -0
  30. package/dist/docs/references/reference-vectors-libsql.md +307 -0
  31. package/dist/index.cjs +13164 -3390
  32. package/dist/index.cjs.map +1 -1
  33. package/dist/index.js +13134 -3383
  34. package/dist/index.js.map +1 -1
  35. package/dist/storage/db/index.d.ts +389 -0
  36. package/dist/storage/db/index.d.ts.map +1 -0
  37. package/dist/storage/db/utils.d.ts +84 -0
  38. package/dist/storage/db/utils.d.ts.map +1 -0
  39. package/dist/storage/db/write-lock.d.ts +8 -0
  40. package/dist/storage/db/write-lock.d.ts.map +1 -0
  41. package/dist/storage/domains/agents/index.d.ts +30 -0
  42. package/dist/storage/domains/agents/index.d.ts.map +1 -0
  43. package/dist/storage/domains/background-tasks/index.d.ts +27 -0
  44. package/dist/storage/domains/background-tasks/index.d.ts.map +1 -0
  45. package/dist/storage/domains/blobs/index.d.ts +17 -0
  46. package/dist/storage/domains/blobs/index.d.ts.map +1 -0
  47. package/dist/storage/domains/channels/index.d.ts +20 -0
  48. package/dist/storage/domains/channels/index.d.ts.map +1 -0
  49. package/dist/storage/domains/datasets/index.d.ts +43 -0
  50. package/dist/storage/domains/datasets/index.d.ts.map +1 -0
  51. package/dist/storage/domains/experiments/index.d.ts +54 -0
  52. package/dist/storage/domains/experiments/index.d.ts.map +1 -0
  53. package/dist/storage/domains/favorites/index.d.ts +17 -0
  54. package/dist/storage/domains/favorites/index.d.ts.map +1 -0
  55. package/dist/storage/domains/harness/index.d.ts +17 -0
  56. package/dist/storage/domains/harness/index.d.ts.map +1 -0
  57. package/dist/storage/domains/mcp-clients/index.d.ts +26 -0
  58. package/dist/storage/domains/mcp-clients/index.d.ts.map +1 -0
  59. package/dist/storage/domains/mcp-servers/index.d.ts +26 -0
  60. package/dist/storage/domains/mcp-servers/index.d.ts.map +1 -0
  61. package/dist/storage/domains/memory/index.d.ts +58 -54
  62. package/dist/storage/domains/memory/index.d.ts.map +1 -1
  63. package/dist/storage/domains/notifications/index.d.ts +23 -0
  64. package/dist/storage/domains/notifications/index.d.ts.map +1 -0
  65. package/dist/storage/domains/observability/index.d.ts +49 -29
  66. package/dist/storage/domains/observability/index.d.ts.map +1 -1
  67. package/dist/storage/domains/prompt-blocks/index.d.ts +25 -0
  68. package/dist/storage/domains/prompt-blocks/index.d.ts.map +1 -0
  69. package/dist/storage/domains/schedules/index.d.ts +27 -0
  70. package/dist/storage/domains/schedules/index.d.ts.map +1 -0
  71. package/dist/storage/domains/scorer-definitions/index.d.ts +26 -0
  72. package/dist/storage/domains/scorer-definitions/index.d.ts.map +1 -0
  73. package/dist/storage/domains/scores/index.d.ts +29 -31
  74. package/dist/storage/domains/scores/index.d.ts.map +1 -1
  75. package/dist/storage/domains/skills/index.d.ts +26 -0
  76. package/dist/storage/domains/skills/index.d.ts.map +1 -0
  77. package/dist/storage/domains/thread-state/index.d.ts +38 -0
  78. package/dist/storage/domains/thread-state/index.d.ts.map +1 -0
  79. package/dist/storage/domains/tool-provider-connections/index.d.ts +14 -0
  80. package/dist/storage/domains/tool-provider-connections/index.d.ts.map +1 -0
  81. package/dist/storage/domains/utils.d.ts +28 -54
  82. package/dist/storage/domains/utils.d.ts.map +1 -1
  83. package/dist/storage/domains/workflow-definitions/index.d.ts +14 -0
  84. package/dist/storage/domains/workflow-definitions/index.d.ts.map +1 -0
  85. package/dist/storage/domains/workflows/index.d.ts +27 -32
  86. package/dist/storage/domains/workflows/index.d.ts.map +1 -1
  87. package/dist/storage/domains/workspaces/index.d.ts +26 -0
  88. package/dist/storage/domains/workspaces/index.d.ts.map +1 -0
  89. package/dist/storage/factory-storage.d.ts +28 -0
  90. package/dist/storage/factory-storage.d.ts.map +1 -0
  91. package/dist/storage/index.d.ts +128 -255
  92. package/dist/storage/index.d.ts.map +1 -1
  93. package/dist/storage/retention.d.ts +77 -0
  94. package/dist/storage/retention.d.ts.map +1 -0
  95. package/dist/vector/index.d.ts +31 -4
  96. package/dist/vector/index.d.ts.map +1 -1
  97. package/dist/vector/sql-builder.d.ts.map +1 -1
  98. package/package.json +22 -16
  99. package/dist/storage/domains/legacy-evals/index.d.ts +0 -18
  100. package/dist/storage/domains/legacy-evals/index.d.ts.map +0 -1
  101. package/dist/storage/domains/operations/index.d.ts +0 -110
  102. package/dist/storage/domains/operations/index.d.ts.map +0 -1
  103. package/dist/storage/domains/traces/index.d.ts +0 -21
  104. package/dist/storage/domains/traces/index.d.ts.map +0 -1
@@ -0,0 +1,385 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
3
+ # Memory processors
4
+
5
+ Memory processors transform and filter messages as they pass through an agent with memory enabled. They manage context window limits and remove unnecessary content, plus optimize the information sent to the language model.
6
+
7
+ When memory is enabled on an agent, Mastra adds memory processors to the agent's processor pipeline. These processors retrieve message history and working memory, plus semantically relevant messages, then persist new messages after the model responds.
8
+
9
+ Memory processors are [processors](https://mastra.ai/docs/agents/processors) that operate specifically on memory-related messages and state.
10
+
11
+ ## Built-in memory processors
12
+
13
+ Mastra automatically adds these processors when memory is enabled:
14
+
15
+ ### `MessageHistory`
16
+
17
+ Retrieves message history and persists new messages.
18
+
19
+ **When you configure:**
20
+
21
+ ```typescript
22
+ memory: new Memory({
23
+ lastMessages: 10,
24
+ })
25
+ ```
26
+
27
+ **Mastra internally:**
28
+
29
+ 1. Creates a `MessageHistory` processor with `limit: 10`
30
+ 2. Adds it to the agent's input processors (runs before the LLM)
31
+ 3. Adds it to the agent's output processors (runs after the LLM)
32
+
33
+ **What it does:**
34
+
35
+ - **Input**: Fetches the last 10 messages from storage and prepends them to the conversation
36
+ - **Output**: Persists new messages to storage after the model responds
37
+
38
+ **Example:**
39
+
40
+ ```typescript
41
+ import { Agent } from '@mastra/core/agent'
42
+ import { Memory } from '@mastra/memory'
43
+ import { LibSQLStore } from '@mastra/libsql'
44
+ import { openai } from '@ai-sdk/openai'
45
+
46
+ const agent = new Agent({
47
+ id: 'test-agent',
48
+ name: 'Test Agent',
49
+ instructions: 'You are a helpful assistant',
50
+ model: 'openai/gpt-5.6-sol',
51
+ memory: new Memory({
52
+ storage: new LibSQLStore({
53
+ id: 'memory-store',
54
+ url: 'file:memory.db',
55
+ }),
56
+ lastMessages: 10, // MessageHistory processor automatically added
57
+ }),
58
+ })
59
+ ```
60
+
61
+ ### `SemanticRecall`
62
+
63
+ Retrieves semantically relevant messages based on the current input and creates embeddings for new messages.
64
+
65
+ **When you configure:**
66
+
67
+ ```typescript
68
+ memory: new Memory({
69
+ semanticRecall: { enabled: true },
70
+ vector: myVectorStore,
71
+ embedder: myEmbedder,
72
+ })
73
+ ```
74
+
75
+ **Mastra internally:**
76
+
77
+ 1. Creates a `SemanticRecall` processor
78
+ 2. Adds it to the agent's input processors (runs before the LLM)
79
+ 3. Adds it to the agent's output processors (runs after the LLM)
80
+ 4. Requires both a vector store and embedder to be configured
81
+
82
+ **What it does:**
83
+
84
+ - **Input**: Performs vector similarity search to find relevant past messages and prepends them to the conversation
85
+ - **Output**: Creates embeddings for new messages and stores them in the vector store for future retrieval
86
+
87
+ **Example:**
88
+
89
+ ```typescript
90
+ import { Agent } from '@mastra/core/agent'
91
+ import { Memory } from '@mastra/memory'
92
+ import { LibSQLStore } from '@mastra/libsql'
93
+ import { PineconeVector } from '@mastra/pinecone'
94
+ import { OpenAIEmbedder } from '@mastra/openai'
95
+ import { openai } from '@ai-sdk/openai'
96
+
97
+ const agent = new Agent({
98
+ name: 'semantic-agent',
99
+ instructions: 'You are a helpful assistant with semantic memory',
100
+ model: 'openai/gpt-5.6-sol',
101
+ memory: new Memory({
102
+ storage: new LibSQLStore({
103
+ id: 'memory-store',
104
+ url: 'file:memory.db',
105
+ }),
106
+ vector: new PineconeVector({
107
+ id: 'memory-vector',
108
+ apiKey: process.env.PINECONE_API_KEY!,
109
+ }),
110
+ embedder: new OpenAIEmbedder({
111
+ model: 'text-embedding-3-small',
112
+ apiKey: process.env.OPENAI_API_KEY!,
113
+ }),
114
+ semanticRecall: { enabled: true }, // SemanticRecall processor automatically added
115
+ }),
116
+ })
117
+ ```
118
+
119
+ ### `WorkingMemory`
120
+
121
+ Manages working memory state across conversations.
122
+
123
+ **When you configure:**
124
+
125
+ ```typescript
126
+ memory: new Memory({
127
+ workingMemory: { enabled: true },
128
+ })
129
+ ```
130
+
131
+ **Mastra internally:**
132
+
133
+ 1. Creates a `WorkingMemory` processor
134
+ 2. Adds it to the agent's input processors (runs before the LLM)
135
+ 3. Requires a storage adapter to be configured
136
+
137
+ **What it does:**
138
+
139
+ - **Input**: Retrieves working memory state for the current thread and prepends it to the conversation
140
+ - **Output**: No output processing
141
+
142
+ **Example:**
143
+
144
+ ```typescript
145
+ import { Agent } from '@mastra/core/agent'
146
+ import { Memory } from '@mastra/memory'
147
+ import { LibSQLStore } from '@mastra/libsql'
148
+ import { openai } from '@ai-sdk/openai'
149
+
150
+ const agent = new Agent({
151
+ name: 'working-memory-agent',
152
+ instructions: 'You are an assistant with working memory',
153
+ model: 'openai/gpt-5.6-sol',
154
+ memory: new Memory({
155
+ storage: new LibSQLStore({
156
+ id: 'memory-store',
157
+ url: 'file:memory.db',
158
+ }),
159
+ workingMemory: { enabled: true }, // WorkingMemory processor automatically added
160
+ }),
161
+ })
162
+ ```
163
+
164
+ ## Manual control and deduplication
165
+
166
+ If you manually add a memory processor to `inputProcessors` or `outputProcessors`, Mastra **won't** automatically add it. This gives you full control over processor ordering:
167
+
168
+ ```typescript
169
+ import { Agent } from '@mastra/core/agent'
170
+ import { Memory } from '@mastra/memory'
171
+ import { MessageHistory } from '@mastra/core/processors'
172
+ import { TokenLimiter } from '@mastra/core/processors'
173
+ import { LibSQLStore } from '@mastra/libsql'
174
+ import { openai } from '@ai-sdk/openai'
175
+
176
+ // Custom MessageHistory with different configuration
177
+ const customMessageHistory = new MessageHistory({
178
+ storage: new LibSQLStore({ id: 'memory-store', url: 'file:memory.db' }),
179
+ lastMessages: 20,
180
+ })
181
+
182
+ const agent = new Agent({
183
+ name: 'custom-memory-agent',
184
+ instructions: 'You are a helpful assistant',
185
+ model: 'openai/gpt-5.6-sol',
186
+ memory: new Memory({
187
+ storage: new LibSQLStore({ id: 'memory-store', url: 'file:memory.db' }),
188
+ lastMessages: 10, // This would normally add MessageHistory(10)
189
+ }),
190
+ inputProcessors: [
191
+ customMessageHistory, // Your custom one is used instead
192
+ new TokenLimiter({ limit: 4000 }), // Runs after your custom MessageHistory
193
+ ],
194
+ })
195
+ ```
196
+
197
+ ## Processor execution order
198
+
199
+ Understanding the execution order is important when combining guardrails with memory:
200
+
201
+ ### Input Processors
202
+
203
+ ```text
204
+ [Memory Processors] → [Your inputProcessors]
205
+ ```
206
+
207
+ 1. **Memory processors run FIRST**: `WorkingMemory`, `MessageHistory`, `SemanticRecall`
208
+ 2. **Your input processors run AFTER**: guardrails, filters, validators
209
+
210
+ As a result, memory loads message history before your processors can validate or filter the input.
211
+
212
+ ### Output Processors
213
+
214
+ ```text
215
+ [Your outputProcessors] → [Memory Processors]
216
+ ```
217
+
218
+ 1. **Your output processors run FIRST**: guardrails, filters, validators
219
+ 2. **Memory processors run AFTER**: `SemanticRecall` (embeddings), `MessageHistory` (persistence)
220
+
221
+ This ordering is designed to be **safe by default**: if your output guardrail calls `abort()`, the memory processors never run and **no messages are saved**.
222
+
223
+ ## Guardrails and memory
224
+
225
+ The default execution order provides safe guardrail behavior:
226
+
227
+ ### Output guardrails (recommended)
228
+
229
+ Output guardrails run **before** memory processors save messages. If a guardrail aborts:
230
+
231
+ - The tripwire is triggered
232
+ - Memory processors are skipped
233
+ - **No messages are persisted to storage**
234
+
235
+ ```typescript
236
+ import { Agent } from '@mastra/core/agent'
237
+ import { Memory } from '@mastra/memory'
238
+ import { openai } from '@ai-sdk/openai'
239
+
240
+ // Output guardrail that blocks inappropriate content
241
+ const contentBlocker = {
242
+ id: 'content-blocker',
243
+ processOutputResult: async ({ messages, abort }) => {
244
+ const hasInappropriateContent = messages.some(msg => containsBadContent(msg))
245
+ if (hasInappropriateContent) {
246
+ abort('Content blocked by guardrail')
247
+ }
248
+ return messages
249
+ },
250
+ }
251
+
252
+ const agent = new Agent({
253
+ id: 'safe-agent',
254
+ name: 'safe-agent',
255
+ instructions: 'You are a helpful assistant',
256
+ model: 'openai/gpt-5.6-sol',
257
+ memory: new Memory({ lastMessages: 10 }),
258
+ // Your guardrail runs BEFORE memory saves
259
+ outputProcessors: [contentBlocker],
260
+ })
261
+
262
+ // If the guardrail aborts, nothing is saved to memory
263
+ const result = await agent.generate('Hello')
264
+ if (result.tripwire) {
265
+ console.log('Blocked:', result.tripwire.reason)
266
+ // Memory is empty - no messages were persisted
267
+ }
268
+ ```
269
+
270
+ ### Input guardrails
271
+
272
+ Input guardrails run **after** memory processors load history. If a guardrail aborts:
273
+
274
+ - The tripwire is triggered
275
+ - The LLM is never called
276
+ - Output processors (including memory persistence) are skipped
277
+ - **No messages are persisted to storage**
278
+
279
+ ```typescript
280
+ // Input guardrail that validates user input
281
+ const inputValidator = {
282
+ id: 'input-validator',
283
+ processInput: async ({ messages, abort }) => {
284
+ const lastUserMessage = messages.findLast(m => m.role === 'user')
285
+ if (isInvalidInput(lastUserMessage)) {
286
+ abort('Invalid input detected')
287
+ }
288
+ return messages
289
+ },
290
+ }
291
+
292
+ const agent = new Agent({
293
+ id: 'validated-agent',
294
+ name: 'validated-agent',
295
+ instructions: 'You are a helpful assistant',
296
+ model: 'openai/gpt-5.6-sol',
297
+ memory: new Memory({ lastMessages: 10 }),
298
+ // Your guardrail runs AFTER memory loads history
299
+ inputProcessors: [inputValidator],
300
+ })
301
+ ```
302
+
303
+ ### Summary
304
+
305
+ | Guardrail Type | When it runs | If it aborts |
306
+ | -------------- | -------------------------- | ----------------------------- |
307
+ | Input | After memory loads history | LLM not called, nothing saved |
308
+ | Output | Before memory saves | Nothing saved to storage |
309
+
310
+ Both scenarios are safe - guardrails prevent inappropriate content from being persisted to memory
311
+
312
+ ## Handling large attachments
313
+
314
+ Some storage providers enforce record size limits that base64-encoded file attachments can exceed:
315
+
316
+ | Provider | Record size limit |
317
+ | ------------------------------------------------------------------ | ----------------- |
318
+ | [DynamoDB](https://mastra.ai/reference/storage/dynamodb) | 400 KB |
319
+ | [Convex](https://mastra.ai/reference/storage/convex) | 1 MiB |
320
+ | [Cloudflare D1](https://mastra.ai/reference/storage/cloudflare-d1) | 1 MiB |
321
+
322
+ PostgreSQL, MongoDB, and libSQL have higher limits and are usually unaffected.
323
+
324
+ Use an input processor to upload attachments to external storage, then replace them with URL references before messages are persisted.
325
+
326
+ ```typescript
327
+ import type { Processor } from '@mastra/core/processors'
328
+ import type { MastraDBMessage } from '@mastra/core/memory'
329
+
330
+ export class AttachmentUploader implements Processor {
331
+ id = 'attachment-uploader'
332
+
333
+ async processInput({ messages }: { messages: MastraDBMessage[] }) {
334
+ return Promise.all(messages.map(message => this.processMessage(message)))
335
+ }
336
+
337
+ async processMessage(message: MastraDBMessage) {
338
+ const attachments = message.content.experimental_attachments
339
+ if (!attachments?.length) return message
340
+
341
+ const uploaded = await Promise.all(
342
+ attachments.map(async attachment => {
343
+ if (!attachment.url?.startsWith('data:')) return attachment
344
+
345
+ const url = await this.upload(attachment.url, attachment.contentType)
346
+ return { ...attachment, url }
347
+ }),
348
+ )
349
+
350
+ return { ...message, content: { ...message.content, experimental_attachments: uploaded } }
351
+ }
352
+
353
+ async upload(dataUri: string, contentType?: string): Promise<string> {
354
+ const base64 = dataUri.split(',')[1]
355
+ const buffer = Buffer.from(base64, 'base64')
356
+
357
+ throw new Error('Implement upload() with your storage provider')
358
+ }
359
+ }
360
+ ```
361
+
362
+ Use the processor with your agent:
363
+
364
+ ```typescript
365
+ import { Agent } from '@mastra/core/agent'
366
+ import { Memory } from '@mastra/memory'
367
+ import { AttachmentUploader } from '../processors/attachment-uploader'
368
+
369
+ export const supportAgent = new Agent({
370
+ id: 'support-agent',
371
+ name: 'Support agent',
372
+ instructions: 'Answer customer support questions.',
373
+ model: 'openai/gpt-5.6-sol',
374
+ memory: new Memory({ lastMessages: 10 }),
375
+ inputProcessors: [new AttachmentUploader()],
376
+ })
377
+ ```
378
+
379
+ ## Related documentation
380
+
381
+ - [Processors](https://mastra.ai/docs/agents/processors): General processor concepts and custom processor creation
382
+ - [Guardrails](https://mastra.ai/docs/agents/guardrails): Security and validation processors
383
+ - [Memory Overview](https://mastra.ai/docs/memory/overview): Memory types and configuration
384
+
385
+ When creating custom processors avoid mutating the input `messages` array or its objects directly.