@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,240 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
3
+ # Snapshots
4
+
5
+ In Mastra, a snapshot is a serializable representation of a workflow's complete execution state at a specific point in time. Snapshots capture all the information needed to resume a workflow from exactly where it left off, including:
6
+
7
+ - The current state of each step in the workflow
8
+ - The outputs of completed steps
9
+ - The execution path taken through the workflow
10
+ - Any suspended steps and their metadata
11
+ - The remaining retry attempts for each step
12
+ - Additional contextual data needed to resume execution
13
+
14
+ Snapshots are automatically created and managed by Mastra whenever a workflow is suspended, and are persisted to the configured storage system.
15
+
16
+ ## The role of snapshots in suspend and resume
17
+
18
+ Snapshots are the key mechanism enabling Mastra's suspend and resume capabilities. When a workflow step calls `await suspend()`:
19
+
20
+ 1. The workflow execution is paused at that exact point
21
+ 2. The current state of the workflow is captured as a snapshot
22
+ 3. The snapshot is persisted to storage
23
+ 4. The workflow step is marked as "suspended" with a status of `'suspended'`
24
+ 5. Later, when `resume()` is called on the suspended step, the snapshot is retrieved
25
+ 6. The workflow execution resumes from exactly where it left off
26
+
27
+ The mechanism provides a powerful way to implement human-in-the-loop workflows, handle rate limiting, wait for external resources, and implement complex branching workflows that may need to pause for extended periods.
28
+
29
+ ## Snapshot anatomy
30
+
31
+ Each snapshot includes the `runId`, input, step status (`success`, `suspended`, etc.), any suspend and resume payloads, and the final output. As a result, full context is available when resuming execution.
32
+
33
+ ```json
34
+ {
35
+ "runId": "34904c14-e79e-4a12-9804-9655d4616c50",
36
+ "status": "success",
37
+ "value": {},
38
+ "context": {
39
+ "input": {
40
+ "value": 100,
41
+ "user": "Michael",
42
+ "requiredApprovers": ["manager", "finance"]
43
+ },
44
+ "approval-step": {
45
+ "payload": {
46
+ "value": 100,
47
+ "user": "Michael",
48
+ "requiredApprovers": ["manager", "finance"]
49
+ },
50
+ "startedAt": 1758027577955,
51
+ "status": "success",
52
+ "suspendPayload": {
53
+ "message": "Workflow suspended",
54
+ "requestedBy": "Michael",
55
+ "approvers": ["manager", "finance"]
56
+ },
57
+ "suspendedAt": 1758027578065,
58
+ "resumePayload": { "confirm": true, "approver": "manager" },
59
+ "resumedAt": 1758027578517,
60
+ "output": { "value": 100, "approved": true },
61
+ "endedAt": 1758027578634
62
+ }
63
+ },
64
+ "activePaths": [],
65
+ "serializedStepGraph": [
66
+ {
67
+ "type": "step",
68
+ "step": {
69
+ "id": "approval-step",
70
+ "description": "Accepts a value, waits for confirmation"
71
+ }
72
+ }
73
+ ],
74
+ "suspendedPaths": {},
75
+ "waitingPaths": {},
76
+ "result": { "value": 100, "approved": true },
77
+ "requestContext": {},
78
+ "timestamp": 1758027578740
79
+ }
80
+ ```
81
+
82
+ ## How snapshots are saved and retrieved
83
+
84
+ Snapshots are saved to the configured storage system. By default, they use libSQL, but you can configure Upstash or PostgreSQL instead. Each snapshot is saved in the `workflow_snapshots` table and identified by the workflow's `runId`.
85
+
86
+ Read more about:
87
+
88
+ - [libSQL Storage](https://mastra.ai/reference/storage/libsql)
89
+ - [Upstash Storage](https://mastra.ai/reference/storage/upstash)
90
+ - [PostgreSQL Storage](https://mastra.ai/reference/storage/postgresql)
91
+
92
+ ### Saving snapshots
93
+
94
+ When a workflow is suspended, Mastra automatically persists the workflow snapshot with these steps:
95
+
96
+ 1. The `suspend()` function in a step execution triggers the snapshot process
97
+ 2. The `WorkflowInstance.suspend()` method records the suspended machine
98
+ 3. `persistWorkflowSnapshot()` is called to save the current state
99
+ 4. The snapshot is serialized and stored in the configured database in the `workflow_snapshots` table
100
+ 5. The storage record includes the workflow name, run ID, and the serialized snapshot
101
+
102
+ ### Retrieving snapshots
103
+
104
+ When a workflow is resumed, Mastra retrieves the persisted snapshot with these steps:
105
+
106
+ 1. The `resume()` method is called with a specific step ID
107
+ 2. The snapshot is loaded from storage using `loadWorkflowSnapshot()`
108
+ 3. The snapshot is parsed and prepared for resumption
109
+ 4. The workflow execution is recreated with the snapshot state
110
+ 5. The suspended step is resumed, and execution continues
111
+
112
+ ```typescript
113
+ const storage = mastra.getStorage()
114
+ const workflowStore = await storage?.getStore('workflows')
115
+
116
+ const snapshot = await workflowStore?.loadWorkflowSnapshot({
117
+ runId: '<run-id>',
118
+ workflowName: '<workflow-id>',
119
+ })
120
+
121
+ console.log(snapshot)
122
+ ```
123
+
124
+ ## Storage options for snapshots
125
+
126
+ Snapshots are persisted using a `storage` instance configured on the `Mastra` class. This storage layer is shared across all workflows registered to that instance. Mastra supports multiple storage options for flexibility in different environments.
127
+
128
+ ```typescript
129
+ import { Mastra } from '@mastra/core'
130
+ import { LibSQLStore } from '@mastra/libsql'
131
+ import { approvalWorkflow } from './workflows'
132
+
133
+ export const mastra = new Mastra({
134
+ storage: new LibSQLStore({
135
+ id: 'mastra-storage',
136
+ url: ':memory:',
137
+ }),
138
+ workflows: { approvalWorkflow },
139
+ })
140
+ ```
141
+
142
+ - [libSQL Storage](https://mastra.ai/reference/storage/libsql)
143
+ - [PostgreSQL Storage](https://mastra.ai/reference/storage/postgresql)
144
+ - [MongoDB Storage](https://mastra.ai/reference/storage/mongodb)
145
+ - [Upstash Storage](https://mastra.ai/reference/storage/upstash)
146
+ - [Cloudflare D1](https://mastra.ai/reference/storage/cloudflare-d1)
147
+ - [DynamoDB](https://mastra.ai/reference/storage/dynamodb)
148
+ - [More storage providers](https://mastra.ai/docs/storage/overview)
149
+
150
+ ## Best practices
151
+
152
+ 1. **Ensure Serializability**: Any data that needs to be included in the snapshot must be serializable (convertible to JSON).
153
+ 2. **Minimize Snapshot Size**: Avoid storing large data objects directly in the workflow context. Instead, store references to them (like IDs) and retrieve the data when needed.
154
+ 3. **Handle Resume Context Carefully**: When resuming a workflow, carefully consider what context to provide. This will be merged with the existing snapshot data.
155
+ 4. **Set Up Proper Monitoring**: Implement monitoring for suspended workflows and especially long-running ones, plus to ensure they're properly resumed.
156
+ 5. **Consider Storage Scaling**: For applications with many suspended workflows, ensure your storage solution is appropriately scaled.
157
+
158
+ ## Custom snapshot metadata
159
+
160
+ You can attach custom metadata when suspending a workflow by defining a `suspendSchema`. This metadata is stored in the snapshot and made available when the workflow is resumed.
161
+
162
+ ```typescript
163
+ import { createWorkflow, createStep } from '@mastra/core/workflows'
164
+ import { z } from 'zod'
165
+
166
+ const approvalStep = createStep({
167
+ id: 'approval-step',
168
+ description: 'Accepts a value, waits for confirmation',
169
+ inputSchema: z.object({
170
+ value: z.number(),
171
+ user: z.string(),
172
+ requiredApprovers: z.array(z.string()),
173
+ }),
174
+ suspendSchema: z.object({
175
+ message: z.string(),
176
+ requestedBy: z.string(),
177
+ approvers: z.array(z.string()),
178
+ }),
179
+ resumeSchema: z.object({
180
+ confirm: z.boolean(),
181
+ approver: z.string(),
182
+ }),
183
+ outputSchema: z.object({
184
+ value: z.number(),
185
+ approved: z.boolean(),
186
+ }),
187
+ execute: async ({ inputData, resumeData, suspend }) => {
188
+ const { value, user, requiredApprovers } = inputData
189
+ const { confirm } = resumeData ?? {}
190
+
191
+ if (!confirm) {
192
+ return await suspend({
193
+ message: 'Workflow suspended',
194
+ requestedBy: user,
195
+ approvers: [...requiredApprovers],
196
+ })
197
+ }
198
+
199
+ return {
200
+ value,
201
+ approved: confirm,
202
+ }
203
+ },
204
+ })
205
+ ```
206
+
207
+ ### Providing resume data
208
+
209
+ Use `resumeData` to pass structured input when resuming a suspended step. It must match the step’s `resumeSchema`.
210
+
211
+ ```typescript
212
+ const workflow = mastra.getWorkflow('approvalWorkflow')
213
+
214
+ const run = await workflow.createRun()
215
+
216
+ const result = await run.start({
217
+ inputData: {
218
+ value: 100,
219
+ user: 'Michael',
220
+ requiredApprovers: ['manager', 'finance'],
221
+ },
222
+ })
223
+
224
+ if (result.status === 'suspended') {
225
+ const resumedResult = await run.resume({
226
+ step: 'approval-step',
227
+ resumeData: {
228
+ confirm: true,
229
+ approver: 'manager',
230
+ },
231
+ })
232
+ }
233
+ ```
234
+
235
+ ## Related
236
+
237
+ - [Control Flow](https://mastra.ai/docs/workflows/control-flow)
238
+ - [Suspend and Resume](https://mastra.ai/docs/workflows/suspend-and-resume)
239
+ - [Time Travel](https://mastra.ai/docs/workflows/time-travel)
240
+ - [Human-in-the-loop](https://mastra.ai/docs/workflows/human-in-the-loop)
@@ -0,0 +1,142 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
3
+ # AI SDK
4
+
5
+ If you're already using the [Vercel AI SDK](https://sdk.vercel.ai) directly and want to add Mastra capabilities like [processors](https://mastra.ai/docs/agents/processors) or [memory](https://mastra.ai/docs/memory/memory-processors) without switching to the full Mastra agent API, [`withMastra()`](https://mastra.ai/reference/ai-sdk/with-mastra) lets you wrap any AI SDK model with these features. This is useful when you want to keep your existing AI SDK code but add input/output processing, conversation persistence, or content filtering.
6
+
7
+ > **Tip:** If you want to use Mastra together with AI SDK UI (e.g. `useChat()`), visit the [AI SDK UI guide](https://mastra.ai/guides/build-your-ui/ai-sdk-ui).
8
+
9
+ ## Installation
10
+
11
+ Install `@mastra/ai-sdk` to begin using the `withMastra()` function.
12
+
13
+ **npm**:
14
+
15
+ ```bash
16
+ npm install @mastra/ai-sdk@latest
17
+ ```
18
+
19
+ **pnpm**:
20
+
21
+ ```bash
22
+ pnpm add @mastra/ai-sdk@latest
23
+ ```
24
+
25
+ **Yarn**:
26
+
27
+ ```bash
28
+ yarn add @mastra/ai-sdk@latest
29
+ ```
30
+
31
+ **Bun**:
32
+
33
+ ```bash
34
+ bun add @mastra/ai-sdk@latest
35
+ ```
36
+
37
+ ## Examples
38
+
39
+ ### With Processors
40
+
41
+ Processors let you transform messages before they're sent to the model (`processInput`) and after responses are received (`processOutputResult`). This example creates a logging processor that logs message counts at each stage, then wraps an OpenAI model with it.
42
+
43
+ ```typescript
44
+ import { openai } from '@ai-sdk/openai'
45
+ import { generateText } from 'ai'
46
+ import { withMastra } from '@mastra/ai-sdk'
47
+ import type { Processor } from '@mastra/core/processors'
48
+
49
+ const loggingProcessor: Processor<'logger'> = {
50
+ id: 'logger',
51
+ async processInput({ messages }) {
52
+ console.log('Input:', messages.length, 'messages')
53
+ return messages
54
+ },
55
+ async processOutputResult({ messages }) {
56
+ console.log('Output:', messages.length, 'messages')
57
+ return messages
58
+ },
59
+ }
60
+
61
+ const model = withMastra(openai('gpt-5.4'), {
62
+ inputProcessors: [loggingProcessor],
63
+ outputProcessors: [loggingProcessor],
64
+ })
65
+
66
+ const { text } = await generateText({
67
+ model,
68
+ prompt: 'What is 2 + 2?',
69
+ })
70
+ ```
71
+
72
+ ### With Memory
73
+
74
+ Memory automatically loads previous messages from storage before the LLM call and saves new messages after. This example configures a libSQL storage backend to persist conversation history, loading the last 10 messages for context.
75
+
76
+ ```typescript
77
+ import { openai } from '@ai-sdk/openai'
78
+ import { generateText } from 'ai'
79
+ import { withMastra } from '@mastra/ai-sdk'
80
+ import { LibSQLStore } from '@mastra/libsql'
81
+
82
+ const storage = new LibSQLStore({
83
+ id: 'my-app',
84
+ url: 'file:./data.db',
85
+ })
86
+ await storage.init()
87
+
88
+ const memoryStorage = await storage.getStore('memory')
89
+
90
+ const model = withMastra(openai('gpt-5.4'), {
91
+ memory: {
92
+ storage: memoryStorage!,
93
+ threadId: 'user-thread-123',
94
+ resourceId: 'user-123',
95
+ lastMessages: 10,
96
+ },
97
+ })
98
+
99
+ const { text } = await generateText({
100
+ model,
101
+ prompt: 'What did we talk about earlier?',
102
+ })
103
+ ```
104
+
105
+ ### With Processors & Memory
106
+
107
+ You can combine processors and memory together. Input processors run after memory loads historical messages, and output processors run before memory saves the response.
108
+
109
+ ```typescript
110
+ import { openai } from '@ai-sdk/openai'
111
+ import { generateText } from 'ai'
112
+ import { withMastra } from '@mastra/ai-sdk'
113
+ import { LibSQLStore } from '@mastra/libsql'
114
+
115
+ const storage = new LibSQLStore({ id: 'my-app', url: 'file:./data.db' })
116
+ await storage.init()
117
+
118
+ const memoryStorage = await storage.getStore('memory')
119
+
120
+ const model = withMastra(openai('gpt-5.4'), {
121
+ inputProcessors: [myGuardProcessor],
122
+ outputProcessors: [myLoggingProcessor],
123
+ memory: {
124
+ storage: memoryStorage!,
125
+ threadId: 'thread-123',
126
+ resourceId: 'user-123',
127
+ lastMessages: 10,
128
+ },
129
+ })
130
+
131
+ const { text } = await generateText({
132
+ model,
133
+ prompt: 'Hello!',
134
+ })
135
+ ```
136
+
137
+ ## Related
138
+
139
+ - [`withMastra()`](https://mastra.ai/reference/ai-sdk/with-mastra): API reference for `withMastra()`
140
+ - [Processors](https://mastra.ai/docs/agents/processors): Learn about input and output processors
141
+ - [Memory](https://mastra.ai/docs/memory/overview): Overview of Mastra's memory system
142
+ - [AI SDK UI](https://mastra.ai/guides/build-your-ui/ai-sdk-ui): Using AI SDK UI hooks with Mastra agents, workflows, and networks