@mastra/libsql 0.0.0-knowledge-org-scope-20260902233451 → 0.0.0-knowledge-w2-20261007195847
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 +1 -1
- package/dist/docs/references/docs-agents-human-in-the-loop.md +42 -1
- package/dist/docs/references/docs-deployment-workers.md +13 -3
- package/dist/docs/references/docs-memory-memory-processors.md +7 -1
- package/dist/docs/references/docs-memory-message-history.md +68 -4
- package/dist/docs/references/docs-memory-multi-user-threads.md +1 -1
- package/dist/docs/references/docs-memory-overview.md +6 -6
- package/dist/docs/references/docs-memory-semantic-recall.md +35 -1
- package/dist/docs/references/docs-storage.md +2 -0
- package/dist/docs/references/integrations-channels-github.md +6 -2
- package/dist/docs/references/reference-core-mastra-class.md +3 -1
- package/dist/docs/references/reference-file-based-agents-memory.md +0 -2
- package/dist/docs/references/reference-file-based-agents-storage.md +0 -2
- package/dist/docs/references/reference-memory-memory-class.md +7 -2
- package/dist/docs/references/reference-storage-retention.md +64 -10
- package/dist/index.cjs +3131 -1201
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3132 -1202
- package/dist/index.js.map +1 -1
- package/dist/shared/single-connection-client.d.ts +29 -0
- package/dist/shared/single-connection-client.d.ts.map +1 -0
- package/dist/storage/db/index.d.ts +7 -4
- package/dist/storage/db/index.d.ts.map +1 -1
- package/dist/storage/db/write-lock.d.ts.map +1 -1
- package/dist/storage/domains/background-tasks/index.d.ts +2 -4
- package/dist/storage/domains/background-tasks/index.d.ts.map +1 -1
- package/dist/storage/domains/datasets/index.d.ts +2 -1
- package/dist/storage/domains/datasets/index.d.ts.map +1 -1
- package/dist/storage/domains/experiments/index.d.ts.map +1 -1
- package/dist/storage/domains/knowledge/index.d.ts +134 -21
- package/dist/storage/domains/knowledge/index.d.ts.map +1 -1
- package/dist/storage/domains/memory/index.d.ts +15 -2
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/dist/storage/domains/notifications/index.d.ts +6 -1
- package/dist/storage/domains/notifications/index.d.ts.map +1 -1
- package/dist/storage/domains/observability/index.d.ts.map +1 -1
- package/dist/storage/domains/schedules/index.d.ts +2 -2
- package/dist/storage/domains/schedules/index.d.ts.map +1 -1
- package/dist/storage/domains/skills/index.d.ts.map +1 -1
- package/dist/storage/domains/workflows/index.d.ts +1 -1
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/dist/storage/factory-storage.d.ts.map +1 -1
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/retention.d.ts +5 -56
- package/dist/storage/retention.d.ts.map +1 -1
- package/dist/vector/index.d.ts.map +1 -1
- package/dist/vector/write-lock.d.ts +25 -0
- package/dist/vector/write-lock.d.ts.map +1 -1
- package/package.json +13 -11
|
@@ -6,11 +6,37 @@
|
|
|
6
6
|
|
|
7
7
|
Because storage grows without bound by default, Mastra provides an opt-in, age-based retention system. Declare per-table `maxAge` policies in the `retention` config, then call `storage.prune()` to delete rows older than their configured age. Unconfigured data is kept forever, so behavior doesn't change until you opt in.
|
|
8
8
|
|
|
9
|
-
`prune()` deletes rows.
|
|
9
|
+
`prune()` deletes rows in bounded batches. Runs are resumable and cancellable, so you can limit how much work each maintenance window performs. Pruning doesn't reclaim disk space by itself. Use the database-specific maintenance guidance below when you need to return freed space to the operating system.
|
|
10
10
|
|
|
11
11
|
Retention covers **growth tables** only: tables that accumulate rows unbounded as a side effect of normal operation (conversation history, telemetry, job and run records, schedule fire history, event feeds). User-authored artifacts and config (agents, skills, workspaces, prompt blocks, datasets, schedule definitions, channel installations, and so on) grow with user intent and are edited or deleted explicitly, so they're not valid retention keys.
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
Storage adapters use the shared core retention contract for `prune()`, or a database-native mechanism when that better matches the backend.
|
|
14
|
+
|
|
15
|
+
| Adapter | Mechanism | Retention support |
|
|
16
|
+
| -------------------- | ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
17
|
+
| libSQL | `prune()` | All supported growth domains |
|
|
18
|
+
| PostgreSQL | `prune()` | All supported growth domains. vNext observability drops expired partitions or chunks |
|
|
19
|
+
| MongoDB | `prune()` or native TTL | All supported growth domains. Native TTL indexes are also available |
|
|
20
|
+
| DuckDB | `prune()` | Observability spans, metrics, logs, scores, and feedback |
|
|
21
|
+
| MySQL | `prune()` | Observability spans |
|
|
22
|
+
| Microsoft SQL Server | `prune()` | Observability spans |
|
|
23
|
+
| Oracle Database | `prune()` | Observability spans and logs |
|
|
24
|
+
| Amazon Aurora DSQL | `prune()` | Observability spans |
|
|
25
|
+
| Google Cloud Spanner | `prune()` | Observability spans, plus metrics when metrics storage is enabled |
|
|
26
|
+
| ClickHouse | Native TTL | Observability spans, metrics, logs, scores, and feedback. When all five signals have finite retention, deletion-request records expire after the longest signal retention plus 30 days |
|
|
27
|
+
|
|
28
|
+
## Storage-specific maintenance
|
|
29
|
+
|
|
30
|
+
| Adapter | Maintenance guidance |
|
|
31
|
+
| ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
32
|
+
| SQLite and libSQL | Freed pages are reused by future writes, which stops the database file from growing. Reclaiming disk space requires database-level maintenance. |
|
|
33
|
+
| DuckDB | For file-backed stores, run `CHECKPOINT` after pruning to reclaim deleted rows in storage. DuckDB's `VACUUM` doesn't reclaim deleted rows. |
|
|
34
|
+
|
|
35
|
+
## Schedule pruning
|
|
36
|
+
|
|
37
|
+
Run `prune()` from a scheduler or maintenance worker, not from application startup or shutdown hooks. For deployments that share a database, prefer a single active scheduler or worker for pruning.
|
|
38
|
+
|
|
39
|
+
Prefer lower-traffic periods when pruning large tables. Use `maxBatches`, `maxRows`, and `pauseMs` to bound each run, and pass an `AbortSignal` when the maintenance process needs to stop promptly. These recommendations apply to adapters that expose `prune()`. ClickHouse applies its native time to live (TTL) policy within the database.
|
|
14
40
|
|
|
15
41
|
## Usage example
|
|
16
42
|
|
|
@@ -76,10 +102,10 @@ Each domain specifies its age-prunable tables and the timestamp column that anch
|
|
|
76
102
|
| `memory` | `resources` | `createdAt` | Resource age |
|
|
77
103
|
| `threadState` | `threadState` | `updatedAt` | Inactivity: state for still-active threads survives |
|
|
78
104
|
| `observability` | `spans` | `startedAt` | Span age |
|
|
79
|
-
| `observability` | `metrics` | `timestamp` | Metric event age (
|
|
80
|
-
| `observability` | `logs` | `timestamp` | Log event age (
|
|
81
|
-
| `observability` | `scores` | `timestamp` | Score event age (
|
|
82
|
-
| `observability` | `feedback` | `timestamp` | Feedback event age (
|
|
105
|
+
| `observability` | `metrics` | `timestamp` | Metric event age (vNext only) |
|
|
106
|
+
| `observability` | `logs` | `timestamp` | Log event age (vNext only) |
|
|
107
|
+
| `observability` | `scores` | `timestamp` | Score event age (vNext only) |
|
|
108
|
+
| `observability` | `feedback` | `timestamp` | Feedback event age (vNext only) |
|
|
83
109
|
| `scores` | `scorers` | `createdAt` | Score record age |
|
|
84
110
|
| `workflows` | `workflowSnapshot` | `updatedAt` | Inactivity, suspended or long-running workflows survive |
|
|
85
111
|
| `backgroundTasks` | `backgroundTasks` | `completedAt` | Time since completion, in-flight tasks (`NULL`) are never pruned |
|
|
@@ -94,8 +120,9 @@ Each domain specifies its age-prunable tables and the timestamp column that anch
|
|
|
94
120
|
> - Experiments prune as whole units: an aged experiment's result rows are deleted together with it (results cascade with their parent), so a run is never left partially deleted. Retention doesn't have a separate `results` key.
|
|
95
121
|
> - For `schedules`, the growth table is the fire history (`schedule_triggers`, one row per fire): schedule definitions are config and aren't pruned.
|
|
96
122
|
> - On PostgreSQL, timestamp anchors use the timezone-aware mirror columns (for example `createdAtZ`, `completedAtZ`).
|
|
97
|
-
> -
|
|
98
|
-
> -
|
|
123
|
+
> - DuckDB observability stores append-only events for all five signals. Its `spans` policy uses the event `timestamp` column rather than `startedAt`.
|
|
124
|
+
> - LibSQL and PostgreSQL support all domains above except `harness`, which PostgreSQL doesn't implement. MongoDB supports all except `threadState` and `harness`. DuckDB, MySQL, Microsoft SQL Server, Oracle Database, Amazon Aurora DSQL, and Google Cloud Spanner currently support retention only in their `observability` domains, with the signal coverage shown in the support matrix.
|
|
125
|
+
> - The vNext PostgreSQL observability domain stores signal events in day-partitioned tables (`spans`, `metrics`, `logs`, `scores`, `feedback`). For it, `prune()` drops whole day partitions (or TimescaleDB chunks) that are entirely older than the cutoff instead of deleting rows: effective level of detail is one day, and a partition is only dropped once its entire day is past `maxAge`. `PruneResult.deleted` reports the number of rows in the dropped partitions.
|
|
99
126
|
|
|
100
127
|
## Methods
|
|
101
128
|
|
|
@@ -109,7 +136,7 @@ Deletes rows older than their configured `maxAge` across every domain that has a
|
|
|
109
136
|
|
|
110
137
|
Pass `options.retention` to replace the configured policies for that call only: for example to skip a domain (keep chat history) or prune more aggressively than the standing config. The store's configured `retention` is unchanged.
|
|
111
138
|
|
|
112
|
-
|
|
139
|
+
Adapters that use anchor-column indexes create them lazily on the first `prune()` call for each table with a policy (never at `init()`) so deployments that don't configure retention pay no extra index write or disk overhead. The first prune of an existing large table pays a one-time index build. Subsequent prunes reuse the index. DuckDB uses its built-in zone maps instead of creating retention indexes.
|
|
113
140
|
|
|
114
141
|
```typescript
|
|
115
142
|
const results = await storage.prune({
|
|
@@ -175,7 +202,34 @@ async function retentionTick() {
|
|
|
175
202
|
}
|
|
176
203
|
```
|
|
177
204
|
|
|
178
|
-
You can also cancel a long-running prune with an `AbortSignal`: the loop stops between batches and returns partial results with `done: false
|
|
205
|
+
You can also cancel a long-running prune with an `AbortSignal`: the loop stops between batches and returns partial results with `done: false`. The next run resumes cleanly.
|
|
206
|
+
|
|
207
|
+
## ClickHouse native TTL
|
|
208
|
+
|
|
209
|
+
ClickHouse observability storage uses native table TTLs instead of `prune()`. Configure retention as days per signal. `init()` applies the TTLs to new and existing tables and skips `ALTER TABLE` statements when the configured TTL is already present.
|
|
210
|
+
|
|
211
|
+
Omitted signals, and signals set to zero or less, get no TTL. When you remove a signal from `retention`, the next `init()` or `applyRetention()` removes that table's TTL. If Mastra can't read the current TTLs from `system.tables`, it applies the configured TTLs and leaves the others unchanged.
|
|
212
|
+
|
|
213
|
+
For deployments that need to update TTL configuration without running the full initialization path, call `applyRetention()` on the vNext observability store:
|
|
214
|
+
|
|
215
|
+
```typescript
|
|
216
|
+
import { ObservabilityStorageClickhouseVNext } from '@mastra/clickhouse'
|
|
217
|
+
|
|
218
|
+
const observability = new ObservabilityStorageClickhouseVNext({
|
|
219
|
+
client,
|
|
220
|
+
retention: {
|
|
221
|
+
tracing: 30,
|
|
222
|
+
logs: 7,
|
|
223
|
+
metrics: 14,
|
|
224
|
+
scores: 90,
|
|
225
|
+
feedback: 60,
|
|
226
|
+
},
|
|
227
|
+
})
|
|
228
|
+
|
|
229
|
+
await observability.applyRetention()
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
Deletion requests are retained long enough to keep enforcing erasure after signal rows expire. Mastra applies a TTL to `mastra_deletion_requests` only when tracing, logs, metrics, scores, and feedback all have finite retention. The deletion-request TTL is the longest of those periods plus 30 days. For example, if score retention is the longest period at 90 days, deletion requests expire after 120 days. When any signal is unbounded, deletion requests remain unbounded because trace deletion requests cover rows across all five signals.
|
|
179
233
|
|
|
180
234
|
## MongoDB TTL indexes (alternative to prune)
|
|
181
235
|
|