@mastra/libsql 1.18.0 → 1.19.0-alpha.1
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 +62 -0
- package/dist/docs/SKILL.md +4 -3
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-agent-builder-deploying.md +2 -2
- package/dist/docs/references/docs-agent-builder-overview.md +1 -1
- package/dist/docs/references/docs-agents-agent-approval.md +85 -11
- package/dist/docs/references/docs-agents-networks.md +2 -2
- package/dist/docs/references/docs-deployment-workers.md +137 -0
- package/dist/docs/references/docs-memory-memory-processors.md +10 -10
- package/dist/docs/references/docs-memory-message-history.md +11 -5
- package/dist/docs/references/docs-memory-multi-user-threads.md +6 -6
- package/dist/docs/references/docs-memory-overview.md +24 -10
- package/dist/docs/references/docs-memory-semantic-recall.md +3 -3
- package/dist/docs/references/docs-memory-working-memory.md +8 -8
- package/dist/docs/references/docs-rag-retrieval.md +18 -18
- package/dist/docs/references/docs-storage-overview.md +2 -2
- package/dist/docs/references/docs-workflows-snapshots.md +3 -3
- package/dist/docs/references/reference-core-mastra-class.md +48 -1
- package/dist/docs/references/reference-file-based-agents-storage.md +1 -1
- package/dist/docs/references/reference-memory-memory-class.md +4 -4
- package/dist/docs/references/reference-storage-dynamodb.md +7 -7
- package/dist/docs/references/reference-storage-retention.md +33 -33
- package/dist/docs/references/reference-vectors-libsql.md +2 -2
- package/dist/index.cjs +193 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +194 -21
- package/dist/index.js.map +1 -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/workflow-definitions/index.d.ts +14 -0
- package/dist/storage/domains/workflow-definitions/index.d.ts.map +1 -0
- package/dist/storage/index.d.ts +2 -1
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +5 -5
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
Storage grows without bound by default. Retention is an opt-in, age-based cleanup system: you declare per-table `maxAge` policies in the `retention` config, then call `storage.prune()` to delete rows older than their configured age. Anything you don't configure is kept forever, so there is no behavior change until you opt in.
|
|
6
6
|
|
|
7
|
-
`prune()` deletes rows. It caps growth and is safe to run against large tables (batched, bounded, resumable, cancellable). It never reclaims disk
|
|
7
|
+
`prune()` deletes rows. It caps growth and is safe to run against large tables (batched, bounded, resumable, cancellable). It never reclaims disk: on SQLite/libSQL the freed pages are reused by future writes so the file stops growing, but handing disk back to the OS (for example a `VACUUM`) is left to the underlying database and the operator to manage.
|
|
8
8
|
|
|
9
|
-
Retention covers **growth tables** only
|
|
9
|
+
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.
|
|
10
10
|
|
|
11
11
|
The reference implementations are [libSQL](https://mastra.ai/reference/storage/libsql), [PostgreSQL](https://mastra.ai/reference/storage/postgresql), and [MongoDB](https://mastra.ai/reference/storage/mongodb). Other adapters keep rows forever until they implement retention.
|
|
12
12
|
|
|
@@ -31,7 +31,7 @@ const storage = new LibSQLStore({
|
|
|
31
31
|
},
|
|
32
32
|
})
|
|
33
33
|
|
|
34
|
-
// Wire this to your own cron/scheduler
|
|
34
|
+
// Wire this to your own cron/scheduler: Mastra never runs it for you.
|
|
35
35
|
const results = await storage.prune()
|
|
36
36
|
```
|
|
37
37
|
|
|
@@ -65,35 +65,35 @@ Set the `retention` field on the store config.
|
|
|
65
65
|
|
|
66
66
|
### Retention-eligible tables
|
|
67
67
|
|
|
68
|
-
Each domain declares which of its tables can be age-pruned and which timestamp column anchors the comparison. The anchor is chosen so `maxAge` means what you'd expect for that data
|
|
69
|
-
|
|
70
|
-
| Domain | Table key | Anchor column | `maxAge` measures
|
|
71
|
-
| ----------------- | ------------------ | ---------------- |
|
|
72
|
-
| `memory` | `threads` | `createdAt` | Thread age
|
|
73
|
-
| `memory` | `messages` | `createdAt` | Message age
|
|
74
|
-
| `memory` | `resources` | `createdAt` | Resource age
|
|
75
|
-
| `threadState` | `threadState` | `updatedAt` | Inactivity
|
|
76
|
-
| `observability` | `spans` | `startedAt` | Span age
|
|
77
|
-
| `observability` | `metrics` | `timestamp` | Metric event age (v-next only)
|
|
78
|
-
| `observability` | `logs` | `timestamp` | Log event age (v-next only)
|
|
79
|
-
| `observability` | `scores` | `timestamp` | Score event age (v-next only)
|
|
80
|
-
| `observability` | `feedback` | `timestamp` | Feedback event age (v-next only)
|
|
81
|
-
| `scores` | `scorers` | `createdAt` | Score record age
|
|
82
|
-
| `workflows` | `workflowSnapshot` | `updatedAt` | Inactivity
|
|
83
|
-
| `backgroundTasks` | `backgroundTasks` | `completedAt` | Time since completion
|
|
84
|
-
| `experiments` | `experiments` | `completedAt` | Time since completion
|
|
85
|
-
| `notifications` | `notifications` | `createdAt` | Notification age
|
|
86
|
-
| `harness` | `sessions` | `createdAt` | Session record age
|
|
87
|
-
| `schedules` | `triggers` | `actual_fire_at` | Fire-history age (epoch-ms column)
|
|
68
|
+
Each domain declares which of its tables can be age-pruned and which timestamp column anchors the comparison. The anchor is chosen so `maxAge` means what you'd expect for that data. Append-only logs use creation time, and live state uses last activity. Jobs and runs use completion time, so in-flight work is never pruned.
|
|
69
|
+
|
|
70
|
+
| Domain | Table key | Anchor column | `maxAge` measures |
|
|
71
|
+
| ----------------- | ------------------ | ---------------- | ---------------------------------------------------------------- |
|
|
72
|
+
| `memory` | `threads` | `createdAt` | Thread age |
|
|
73
|
+
| `memory` | `messages` | `createdAt` | Message age |
|
|
74
|
+
| `memory` | `resources` | `createdAt` | Resource age |
|
|
75
|
+
| `threadState` | `threadState` | `updatedAt` | Inactivity: state for still-active threads survives |
|
|
76
|
+
| `observability` | `spans` | `startedAt` | Span age |
|
|
77
|
+
| `observability` | `metrics` | `timestamp` | Metric event age (v-next only) |
|
|
78
|
+
| `observability` | `logs` | `timestamp` | Log event age (v-next only) |
|
|
79
|
+
| `observability` | `scores` | `timestamp` | Score event age (v-next only) |
|
|
80
|
+
| `observability` | `feedback` | `timestamp` | Feedback event age (v-next only) |
|
|
81
|
+
| `scores` | `scorers` | `createdAt` | Score record age |
|
|
82
|
+
| `workflows` | `workflowSnapshot` | `updatedAt` | Inactivity, suspended or long-running workflows survive |
|
|
83
|
+
| `backgroundTasks` | `backgroundTasks` | `completedAt` | Time since completion, in-flight tasks (`NULL`) are never pruned |
|
|
84
|
+
| `experiments` | `experiments` | `completedAt` | Time since completion, running experiments are never pruned |
|
|
85
|
+
| `notifications` | `notifications` | `createdAt` | Notification age |
|
|
86
|
+
| `harness` | `sessions` | `createdAt` | Session record age |
|
|
87
|
+
| `schedules` | `triggers` | `actual_fire_at` | Fire-history age (epoch-ms column) |
|
|
88
88
|
|
|
89
89
|
> **Note:**
|
|
90
90
|
>
|
|
91
91
|
> - The memory `observational_memory` table has no timestamp anchor, so it can't be age-pruned and isn't a valid retention key.
|
|
92
92
|
> - 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.
|
|
93
|
-
> - For `schedules`, the growth table is the fire history (`schedule_triggers`, one row per fire)
|
|
93
|
+
> - For `schedules`, the growth table is the fire history (`schedule_triggers`, one row per fire): schedule definitions are config and aren't pruned.
|
|
94
94
|
> - On PostgreSQL, timestamp anchors use the timezone-aware mirror columns (for example `createdAtZ`, `completedAtZ`).
|
|
95
95
|
> - LibSQL supports all domains above; PostgreSQL and MongoDB support all except `threadState` and `harness`, which they don't implement.
|
|
96
|
-
> - The v-next 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
|
|
96
|
+
> - The v-next 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.
|
|
97
97
|
|
|
98
98
|
## Methods
|
|
99
99
|
|
|
@@ -103,11 +103,11 @@ Each domain declares which of its tables can be age-pruned and which timestamp c
|
|
|
103
103
|
|
|
104
104
|
Deletes rows older than their configured `maxAge` across every domain that has a policy in `retention`. Returns one `PruneResult` per table touched. With no `retention` configured it's a no-op returning `[]`.
|
|
105
105
|
|
|
106
|
-
`prune()` is designed to be safe on tables with millions of rows. It deletes in bounded, batched chunks
|
|
106
|
+
`prune()` is designed to be safe on tables with millions of rows. It deletes in bounded, batched chunks (each batch is its own transaction) so it never takes a long lock or bloats the transaction log. It never runs a `VACUUM`.
|
|
107
107
|
|
|
108
|
-
Pass `options.retention` to replace the configured policies for that call only
|
|
108
|
+
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.
|
|
109
109
|
|
|
110
|
-
Anchor-column indexes are created lazily on the first `prune()` call for each table with a policy
|
|
110
|
+
Anchor-column indexes are created 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.
|
|
111
111
|
|
|
112
112
|
```typescript
|
|
113
113
|
const results = await storage.prune({
|
|
@@ -156,7 +156,7 @@ interface PruneResult {
|
|
|
156
156
|
|
|
157
157
|
## Running prune on a schedule
|
|
158
158
|
|
|
159
|
-
`prune()` has no built-in scheduler
|
|
159
|
+
`prune()` has no built-in scheduler: you decide when it runs. Because it's bounded, a single call may not delete everything. When any result has `done: false`, eligible rows remain and you call again on the next tick. This keeps each invocation short and lets a large backlog drain over several runs.
|
|
160
160
|
|
|
161
161
|
```typescript
|
|
162
162
|
// Runs on your own cron (node-cron, a workflow schedule, an external job, etc.).
|
|
@@ -173,7 +173,7 @@ async function retentionTick() {
|
|
|
173
173
|
}
|
|
174
174
|
```
|
|
175
175
|
|
|
176
|
-
You can also cancel a long-running prune with an `AbortSignal
|
|
176
|
+
You can also cancel a long-running prune with an `AbortSignal`: the loop stops between batches and returns partial results with `done: false`, so the next run resumes cleanly.
|
|
177
177
|
|
|
178
178
|
## MongoDB TTL indexes (alternative to prune)
|
|
179
179
|
|
|
@@ -192,7 +192,7 @@ MongoDB offers native [TTL (Time-To-Live) indexes](https://www.mongodb.com/docs/
|
|
|
192
192
|
> - You need resumable, cancellable cleanup operations
|
|
193
193
|
> - You're using composite storage with multiple databases
|
|
194
194
|
>
|
|
195
|
-
> Both approaches are valid. TTL is simpler
|
|
195
|
+
> Both approaches are valid. TTL is simpler. `prune()` gives more control.
|
|
196
196
|
|
|
197
197
|
### Setting up TTL indexes on MongoDB
|
|
198
198
|
|
|
@@ -232,9 +232,9 @@ const storage = new MongoDBStore({
|
|
|
232
232
|
|
|
233
233
|
## Reclaiming disk
|
|
234
234
|
|
|
235
|
-
`prune()` deletes rows but doesn't shrink the database file. On SQLite/libSQL the freed pages go on a freelist and are reused by future writes, so the file stops growing
|
|
235
|
+
`prune()` deletes rows but doesn't shrink the database file. On SQLite/libSQL the freed pages go on a freelist and are reused by future writes, so the file stops growing: for most users this alone solves the unbounded-growth problem.
|
|
236
236
|
|
|
237
|
-
Handing that free space back to the OS is a separate concern that Mastra doesn't manage. If you specifically need to shrink the file, run the underlying database's compaction (for example `VACUUM` on self-hosted libSQL) yourself
|
|
237
|
+
Handing that free space back to the OS is a separate concern that Mastra doesn't manage. If you specifically need to shrink the file, run the underlying database's compaction (for example `VACUUM` on self-hosted libSQL) yourself in a maintenance window. A full `VACUUM` locks the file and needs roughly twice the file size in free disk. On PostgreSQL, autovacuum reclaims dead tuples for reuse automatically; a manual `VACUUM FULL` is only needed if you must return disk to the OS.
|
|
238
238
|
|
|
239
239
|
For MongoDB, deleted documents are reused by future insertions. To reclaim disk space, run [`db.runCommand({ compact: "collection_name" })`](https://www.mongodb.com/docs/manual/reference/command/compact/) during a maintenance window.
|
|
240
240
|
|
|
@@ -85,7 +85,7 @@ const results = await store.query({
|
|
|
85
85
|
|
|
86
86
|
### `createIndex()`
|
|
87
87
|
|
|
88
|
-
Creates a new vector collection. The index name must start with a letter or underscore and can only contain letters, numbers, and
|
|
88
|
+
Creates a new vector collection. The index name must start with a letter or underscore and can only contain letters, numbers, and underscore characters. The dimension must be a positive integer.
|
|
89
89
|
|
|
90
90
|
**indexName** (`string`): Name of the index to create
|
|
91
91
|
|
|
@@ -279,7 +279,7 @@ export const libsqlAgent = new Agent({
|
|
|
279
279
|
name: 'libSQL Agent',
|
|
280
280
|
instructions:
|
|
281
281
|
'You are an AI agent with the ability to automatically recall memories from previous interactions.',
|
|
282
|
-
model: 'openai/gpt-5.
|
|
282
|
+
model: 'openai/gpt-5.6-sol',
|
|
283
283
|
memory: new Memory({
|
|
284
284
|
storage: new LibSQLStore({
|
|
285
285
|
id: 'libsql-agent-storage',
|
package/dist/index.cjs
CHANGED
|
@@ -2854,7 +2854,7 @@ function serializeJson(v) {
|
|
|
2854
2854
|
if (typeof v === "object" && v != null) return JSON.stringify(v);
|
|
2855
2855
|
return v ?? null;
|
|
2856
2856
|
}
|
|
2857
|
-
function parseJson$
|
|
2857
|
+
function parseJson$3(val) {
|
|
2858
2858
|
if (val == null) return void 0;
|
|
2859
2859
|
if (typeof val === "string") try {
|
|
2860
2860
|
return JSON.parse(val);
|
|
@@ -2869,14 +2869,14 @@ function rowToTask(row) {
|
|
|
2869
2869
|
status: String(row.status),
|
|
2870
2870
|
toolName: String(row.tool_name),
|
|
2871
2871
|
toolCallId: String(row.tool_call_id),
|
|
2872
|
-
args: parseJson$
|
|
2872
|
+
args: parseJson$3(row.args) ?? {},
|
|
2873
2873
|
agentId: String(row.agent_id),
|
|
2874
2874
|
threadId: row.thread_id != null ? String(row.thread_id) : void 0,
|
|
2875
2875
|
resourceId: row.resource_id != null ? String(row.resource_id) : void 0,
|
|
2876
2876
|
runId: String(row.run_id),
|
|
2877
|
-
result: parseJson$
|
|
2878
|
-
error: parseJson$
|
|
2879
|
-
suspendPayload: parseJson$
|
|
2877
|
+
result: parseJson$3(row.result),
|
|
2878
|
+
error: parseJson$3(row.error),
|
|
2879
|
+
suspendPayload: parseJson$3(row.suspend_payload),
|
|
2880
2880
|
retryCount: Number(row.retry_count),
|
|
2881
2881
|
maxRetries: Number(row.max_retries),
|
|
2882
2882
|
timeoutMs: Number(row.timeout_ms),
|
|
@@ -3468,6 +3468,7 @@ var DatasetsLibSQL = class extends _mastra_core_storage.DatasetsStorage {
|
|
|
3468
3468
|
await this.#addColumnIfNotExists(_mastra_core_storage.TABLE_DATASET_ITEMS, "organizationId", "TEXT");
|
|
3469
3469
|
await this.#addColumnIfNotExists(_mastra_core_storage.TABLE_DATASET_ITEMS, "projectId", "TEXT");
|
|
3470
3470
|
await this.#addColumnIfNotExists(_mastra_core_storage.TABLE_DATASET_ITEMS, "toolMocks", "TEXT");
|
|
3471
|
+
await this.#addColumnIfNotExists(_mastra_core_storage.TABLE_DATASET_ITEMS, "unmockedToolPolicy", "TEXT");
|
|
3471
3472
|
await this.#addColumnIfNotExists(_mastra_core_storage.TABLE_DATASET_ITEMS, "externalId", "TEXT");
|
|
3472
3473
|
await this.#client.batch([
|
|
3473
3474
|
{
|
|
@@ -3564,6 +3565,7 @@ var DatasetsLibSQL = class extends _mastra_core_storage.DatasetsStorage {
|
|
|
3564
3565
|
groundTruth: row.groundTruth ? (0, _mastra_core_storage.safelyParseJSON)(row.groundTruth) : void 0,
|
|
3565
3566
|
expectedTrajectory: row.expectedTrajectory ? (0, _mastra_core_storage.safelyParseJSON)(row.expectedTrajectory) : void 0,
|
|
3566
3567
|
toolMocks: row.toolMocks ? (0, _mastra_core_storage.safelyParseJSON)(row.toolMocks) : void 0,
|
|
3568
|
+
unmockedToolPolicy: row.unmockedToolPolicy ?? void 0,
|
|
3567
3569
|
requestContext: row.requestContext ? (0, _mastra_core_storage.safelyParseJSON)(row.requestContext) : void 0,
|
|
3568
3570
|
metadata: row.metadata ? (0, _mastra_core_storage.safelyParseJSON)(row.metadata) : void 0,
|
|
3569
3571
|
source: row.source ? (0, _mastra_core_storage.safelyParseJSON)(row.source) : void 0,
|
|
@@ -3585,6 +3587,7 @@ var DatasetsLibSQL = class extends _mastra_core_storage.DatasetsStorage {
|
|
|
3585
3587
|
groundTruth: row.groundTruth ? (0, _mastra_core_storage.safelyParseJSON)(row.groundTruth) : void 0,
|
|
3586
3588
|
expectedTrajectory: row.expectedTrajectory ? (0, _mastra_core_storage.safelyParseJSON)(row.expectedTrajectory) : void 0,
|
|
3587
3589
|
toolMocks: row.toolMocks ? (0, _mastra_core_storage.safelyParseJSON)(row.toolMocks) : void 0,
|
|
3590
|
+
unmockedToolPolicy: row.unmockedToolPolicy ?? void 0,
|
|
3588
3591
|
requestContext: row.requestContext ? (0, _mastra_core_storage.safelyParseJSON)(row.requestContext) : void 0,
|
|
3589
3592
|
metadata: row.metadata ? (0, _mastra_core_storage.safelyParseJSON)(row.metadata) : void 0,
|
|
3590
3593
|
source: row.source ? (0, _mastra_core_storage.safelyParseJSON)(row.source) : void 0,
|
|
@@ -3898,7 +3901,7 @@ var DatasetsLibSQL = class extends _mastra_core_storage.DatasetsStorage {
|
|
|
3898
3901
|
args: [args.datasetId]
|
|
3899
3902
|
},
|
|
3900
3903
|
{
|
|
3901
|
-
sql: `INSERT INTO ${_mastra_core_storage.TABLE_DATASET_ITEMS} (id, datasetId, datasetVersion, externalId, organizationId, projectId, validTo, isDeleted, input, groundTruth, expectedTrajectory, toolMocks, requestContext, metadata, source, createdAt, updatedAt) VALUES (?, ?, (SELECT version FROM ${_mastra_core_storage.TABLE_DATASETS} WHERE id = ?), ?, (SELECT organizationId FROM ${_mastra_core_storage.TABLE_DATASETS} WHERE id = ?), (SELECT projectId FROM ${_mastra_core_storage.TABLE_DATASETS} WHERE id = ?), NULL, 0, jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), ?, ?)`,
|
|
3904
|
+
sql: `INSERT INTO ${_mastra_core_storage.TABLE_DATASET_ITEMS} (id, datasetId, datasetVersion, externalId, organizationId, projectId, validTo, isDeleted, input, groundTruth, expectedTrajectory, toolMocks, unmockedToolPolicy, requestContext, metadata, source, createdAt, updatedAt) VALUES (?, ?, (SELECT version FROM ${_mastra_core_storage.TABLE_DATASETS} WHERE id = ?), ?, (SELECT organizationId FROM ${_mastra_core_storage.TABLE_DATASETS} WHERE id = ?), (SELECT projectId FROM ${_mastra_core_storage.TABLE_DATASETS} WHERE id = ?), NULL, 0, jsonb(?), jsonb(?), jsonb(?), jsonb(?), ?, jsonb(?), jsonb(?), jsonb(?), ?, ?)`,
|
|
3902
3905
|
args: [
|
|
3903
3906
|
id,
|
|
3904
3907
|
args.datasetId,
|
|
@@ -3910,6 +3913,7 @@ var DatasetsLibSQL = class extends _mastra_core_storage.DatasetsStorage {
|
|
|
3910
3913
|
jsonbArg(args.groundTruth),
|
|
3911
3914
|
jsonbArg(args.expectedTrajectory),
|
|
3912
3915
|
jsonbArg(args.toolMocks),
|
|
3916
|
+
args.unmockedToolPolicy ?? null,
|
|
3913
3917
|
jsonbArg(args.requestContext),
|
|
3914
3918
|
jsonbArg(args.metadata),
|
|
3915
3919
|
jsonbArg(args.source),
|
|
@@ -3939,6 +3943,7 @@ var DatasetsLibSQL = class extends _mastra_core_storage.DatasetsStorage {
|
|
|
3939
3943
|
groundTruth: args.groundTruth,
|
|
3940
3944
|
expectedTrajectory: args.expectedTrajectory,
|
|
3941
3945
|
toolMocks: args.toolMocks,
|
|
3946
|
+
unmockedToolPolicy: args.unmockedToolPolicy,
|
|
3942
3947
|
requestContext: args.requestContext,
|
|
3943
3948
|
metadata: args.metadata,
|
|
3944
3949
|
source: args.source,
|
|
@@ -3981,6 +3986,7 @@ var DatasetsLibSQL = class extends _mastra_core_storage.DatasetsStorage {
|
|
|
3981
3986
|
const mergedGroundTruth = args.groundTruth !== void 0 ? args.groundTruth : existing.groundTruth;
|
|
3982
3987
|
const mergedExpectedTrajectory = args.expectedTrajectory !== void 0 ? args.expectedTrajectory : existing.expectedTrajectory;
|
|
3983
3988
|
const mergedToolMocks = args.toolMocks !== void 0 ? args.toolMocks : existing.toolMocks;
|
|
3989
|
+
const mergedUnmockedToolPolicy = args.unmockedToolPolicy !== void 0 ? args.unmockedToolPolicy : existing.unmockedToolPolicy;
|
|
3984
3990
|
const mergedRequestContext = args.requestContext !== void 0 ? args.requestContext : existing.requestContext;
|
|
3985
3991
|
const mergedMetadata = args.metadata !== void 0 ? args.metadata : existing.metadata;
|
|
3986
3992
|
const mergedSource = args.source !== void 0 ? args.source : existing.source;
|
|
@@ -3994,7 +4000,7 @@ var DatasetsLibSQL = class extends _mastra_core_storage.DatasetsStorage {
|
|
|
3994
4000
|
args: [args.datasetId, args.id]
|
|
3995
4001
|
},
|
|
3996
4002
|
{
|
|
3997
|
-
sql: `INSERT INTO ${_mastra_core_storage.TABLE_DATASET_ITEMS} (id, datasetId, datasetVersion, externalId, organizationId, projectId, validTo, isDeleted, input, groundTruth, expectedTrajectory, toolMocks, requestContext, metadata, source, createdAt, updatedAt) VALUES (?, ?, (SELECT version FROM ${_mastra_core_storage.TABLE_DATASETS} WHERE id = ?), ?, (SELECT organizationId FROM ${_mastra_core_storage.TABLE_DATASETS} WHERE id = ?), (SELECT projectId FROM ${_mastra_core_storage.TABLE_DATASETS} WHERE id = ?), NULL, 0, jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), ?, ?)`,
|
|
4003
|
+
sql: `INSERT INTO ${_mastra_core_storage.TABLE_DATASET_ITEMS} (id, datasetId, datasetVersion, externalId, organizationId, projectId, validTo, isDeleted, input, groundTruth, expectedTrajectory, toolMocks, unmockedToolPolicy, requestContext, metadata, source, createdAt, updatedAt) VALUES (?, ?, (SELECT version FROM ${_mastra_core_storage.TABLE_DATASETS} WHERE id = ?), ?, (SELECT organizationId FROM ${_mastra_core_storage.TABLE_DATASETS} WHERE id = ?), (SELECT projectId FROM ${_mastra_core_storage.TABLE_DATASETS} WHERE id = ?), NULL, 0, jsonb(?), jsonb(?), jsonb(?), jsonb(?), ?, jsonb(?), jsonb(?), jsonb(?), ?, ?)`,
|
|
3998
4004
|
args: [
|
|
3999
4005
|
args.id,
|
|
4000
4006
|
args.datasetId,
|
|
@@ -4006,6 +4012,7 @@ var DatasetsLibSQL = class extends _mastra_core_storage.DatasetsStorage {
|
|
|
4006
4012
|
jsonbArg(mergedGroundTruth),
|
|
4007
4013
|
jsonbArg(mergedExpectedTrajectory),
|
|
4008
4014
|
jsonbArg(mergedToolMocks),
|
|
4015
|
+
mergedUnmockedToolPolicy ?? null,
|
|
4009
4016
|
jsonbArg(mergedRequestContext),
|
|
4010
4017
|
jsonbArg(mergedMetadata),
|
|
4011
4018
|
jsonbArg(mergedSource),
|
|
@@ -4033,6 +4040,7 @@ var DatasetsLibSQL = class extends _mastra_core_storage.DatasetsStorage {
|
|
|
4033
4040
|
groundTruth: mergedGroundTruth,
|
|
4034
4041
|
expectedTrajectory: mergedExpectedTrajectory,
|
|
4035
4042
|
toolMocks: mergedToolMocks,
|
|
4043
|
+
unmockedToolPolicy: mergedUnmockedToolPolicy,
|
|
4036
4044
|
requestContext: mergedRequestContext,
|
|
4037
4045
|
metadata: mergedMetadata,
|
|
4038
4046
|
source: mergedSource,
|
|
@@ -4073,7 +4081,7 @@ var DatasetsLibSQL = class extends _mastra_core_storage.DatasetsStorage {
|
|
|
4073
4081
|
args: [datasetId, id]
|
|
4074
4082
|
},
|
|
4075
4083
|
{
|
|
4076
|
-
sql: `INSERT INTO ${_mastra_core_storage.TABLE_DATASET_ITEMS} (id, datasetId, datasetVersion, externalId, organizationId, projectId, validTo, isDeleted, input, groundTruth, expectedTrajectory, toolMocks, requestContext, metadata, source, createdAt, updatedAt) VALUES (?, ?, (SELECT version FROM ${_mastra_core_storage.TABLE_DATASETS} WHERE id = ?), ?, (SELECT organizationId FROM ${_mastra_core_storage.TABLE_DATASETS} WHERE id = ?), (SELECT projectId FROM ${_mastra_core_storage.TABLE_DATASETS} WHERE id = ?), NULL, 1, jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), ?, ?)`,
|
|
4084
|
+
sql: `INSERT INTO ${_mastra_core_storage.TABLE_DATASET_ITEMS} (id, datasetId, datasetVersion, externalId, organizationId, projectId, validTo, isDeleted, input, groundTruth, expectedTrajectory, toolMocks, unmockedToolPolicy, requestContext, metadata, source, createdAt, updatedAt) VALUES (?, ?, (SELECT version FROM ${_mastra_core_storage.TABLE_DATASETS} WHERE id = ?), ?, (SELECT organizationId FROM ${_mastra_core_storage.TABLE_DATASETS} WHERE id = ?), (SELECT projectId FROM ${_mastra_core_storage.TABLE_DATASETS} WHERE id = ?), NULL, 1, jsonb(?), jsonb(?), jsonb(?), jsonb(?), ?, jsonb(?), jsonb(?), jsonb(?), ?, ?)`,
|
|
4077
4085
|
args: [
|
|
4078
4086
|
id,
|
|
4079
4087
|
datasetId,
|
|
@@ -4085,6 +4093,7 @@ var DatasetsLibSQL = class extends _mastra_core_storage.DatasetsStorage {
|
|
|
4085
4093
|
jsonbArg(existing.groundTruth),
|
|
4086
4094
|
jsonbArg(existing.expectedTrajectory),
|
|
4087
4095
|
jsonbArg(existing.toolMocks),
|
|
4096
|
+
existing.unmockedToolPolicy ?? null,
|
|
4088
4097
|
jsonbArg(existing.requestContext),
|
|
4089
4098
|
jsonbArg(existing.metadata),
|
|
4090
4099
|
jsonbArg(existing.source),
|
|
@@ -4380,7 +4389,7 @@ var DatasetsLibSQL = class extends _mastra_core_storage.DatasetsStorage {
|
|
|
4380
4389
|
});
|
|
4381
4390
|
const externalIds = [...new Set(input.items.flatMap((item) => item.externalId ? [item.externalId] : []))];
|
|
4382
4391
|
const historyResult = externalIds.length ? await tx.execute({
|
|
4383
|
-
sql: `SELECT id, datasetId, datasetVersion, externalId, organizationId, projectId, validTo, isDeleted, json(input) AS input, json(groundTruth) AS groundTruth, json(expectedTrajectory) AS expectedTrajectory, json(toolMocks) AS toolMocks, json(requestContext) AS requestContext, json(metadata) AS metadata, json(source) AS source, createdAt, updatedAt FROM ${_mastra_core_storage.TABLE_DATASET_ITEMS} WHERE datasetId = ? AND externalId IN (${externalIds.map(() => "?").join(",")}) ORDER BY datasetVersion`,
|
|
4392
|
+
sql: `SELECT id, datasetId, datasetVersion, externalId, organizationId, projectId, validTo, isDeleted, json(input) AS input, json(groundTruth) AS groundTruth, json(expectedTrajectory) AS expectedTrajectory, json(toolMocks) AS toolMocks, unmockedToolPolicy, json(requestContext) AS requestContext, json(metadata) AS metadata, json(source) AS source, createdAt, updatedAt FROM ${_mastra_core_storage.TABLE_DATASET_ITEMS} WHERE datasetId = ? AND externalId IN (${externalIds.map(() => "?").join(",")}) ORDER BY datasetVersion`,
|
|
4384
4393
|
args: [input.datasetId, ...externalIds]
|
|
4385
4394
|
}) : { rows: [] };
|
|
4386
4395
|
const plan = this.planDatasetItemBatch(input.items, historyResult.rows.map((row) => this.transformItemRowFull(row)), () => crypto.randomUUID());
|
|
@@ -4395,7 +4404,7 @@ var DatasetsLibSQL = class extends _mastra_core_storage.DatasetsStorage {
|
|
|
4395
4404
|
});
|
|
4396
4405
|
for (const { id, item } of plan.inserts) {
|
|
4397
4406
|
await tx.execute({
|
|
4398
|
-
sql: `INSERT INTO ${_mastra_core_storage.TABLE_DATASET_ITEMS} (id, datasetId, datasetVersion, externalId, organizationId, projectId, validTo, isDeleted, input, groundTruth, expectedTrajectory, toolMocks, requestContext, metadata, source, createdAt, updatedAt) VALUES (?, ?, ?, ?, ?, ?, NULL, 0, jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), ?, ?)`,
|
|
4407
|
+
sql: `INSERT INTO ${_mastra_core_storage.TABLE_DATASET_ITEMS} (id, datasetId, datasetVersion, externalId, organizationId, projectId, validTo, isDeleted, input, groundTruth, expectedTrajectory, toolMocks, unmockedToolPolicy, requestContext, metadata, source, createdAt, updatedAt) VALUES (?, ?, ?, ?, ?, ?, NULL, 0, jsonb(?), jsonb(?), jsonb(?), jsonb(?), ?, jsonb(?), jsonb(?), jsonb(?), ?, ?)`,
|
|
4399
4408
|
args: [
|
|
4400
4409
|
id,
|
|
4401
4410
|
input.datasetId,
|
|
@@ -4407,6 +4416,7 @@ var DatasetsLibSQL = class extends _mastra_core_storage.DatasetsStorage {
|
|
|
4407
4416
|
jsonbArg(item.groundTruth),
|
|
4408
4417
|
jsonbArg(item.expectedTrajectory),
|
|
4409
4418
|
jsonbArg(item.toolMocks),
|
|
4419
|
+
item.unmockedToolPolicy ?? null,
|
|
4410
4420
|
jsonbArg(item.requestContext),
|
|
4411
4421
|
jsonbArg(item.metadata),
|
|
4412
4422
|
jsonbArg(item.source),
|
|
@@ -4425,6 +4435,7 @@ var DatasetsLibSQL = class extends _mastra_core_storage.DatasetsStorage {
|
|
|
4425
4435
|
groundTruth: item.groundTruth,
|
|
4426
4436
|
expectedTrajectory: item.expectedTrajectory,
|
|
4427
4437
|
toolMocks: item.toolMocks,
|
|
4438
|
+
unmockedToolPolicy: item.unmockedToolPolicy,
|
|
4428
4439
|
requestContext: item.requestContext,
|
|
4429
4440
|
metadata: item.metadata,
|
|
4430
4441
|
source: item.source,
|
|
@@ -4485,7 +4496,7 @@ var DatasetsLibSQL = class extends _mastra_core_storage.DatasetsStorage {
|
|
|
4485
4496
|
args: [input.datasetId, item.id]
|
|
4486
4497
|
});
|
|
4487
4498
|
statements.push({
|
|
4488
|
-
sql: `INSERT INTO ${_mastra_core_storage.TABLE_DATASET_ITEMS} (id, datasetId, datasetVersion, externalId, organizationId, projectId, validTo, isDeleted, input, groundTruth, expectedTrajectory, toolMocks, requestContext, metadata, source, createdAt, updatedAt) VALUES (?, ?, (SELECT version FROM ${_mastra_core_storage.TABLE_DATASETS} WHERE id = ?), ?, ?, ?, NULL, 1, jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), ?, ?)`,
|
|
4499
|
+
sql: `INSERT INTO ${_mastra_core_storage.TABLE_DATASET_ITEMS} (id, datasetId, datasetVersion, externalId, organizationId, projectId, validTo, isDeleted, input, groundTruth, expectedTrajectory, toolMocks, unmockedToolPolicy, requestContext, metadata, source, createdAt, updatedAt) VALUES (?, ?, (SELECT version FROM ${_mastra_core_storage.TABLE_DATASETS} WHERE id = ?), ?, ?, ?, NULL, 1, jsonb(?), jsonb(?), jsonb(?), jsonb(?), ?, jsonb(?), jsonb(?), jsonb(?), ?, ?)`,
|
|
4489
4500
|
args: [
|
|
4490
4501
|
item.id,
|
|
4491
4502
|
input.datasetId,
|
|
@@ -4497,6 +4508,7 @@ var DatasetsLibSQL = class extends _mastra_core_storage.DatasetsStorage {
|
|
|
4497
4508
|
jsonbArg(item.groundTruth),
|
|
4498
4509
|
jsonbArg(item.expectedTrajectory),
|
|
4499
4510
|
jsonbArg(item.toolMocks),
|
|
4511
|
+
item.unmockedToolPolicy ?? null,
|
|
4500
4512
|
jsonbArg(item.requestContext),
|
|
4501
4513
|
jsonbArg(item.metadata),
|
|
4502
4514
|
jsonbArg(item.source),
|
|
@@ -4577,6 +4589,7 @@ var ExperimentsLibSQL = class extends _mastra_core_storage.ExperimentsStorage {
|
|
|
4577
4589
|
ifNotExists: [
|
|
4578
4590
|
"status",
|
|
4579
4591
|
"tags",
|
|
4592
|
+
"comment",
|
|
4580
4593
|
"toolMockReport",
|
|
4581
4594
|
"organizationId",
|
|
4582
4595
|
"projectId"
|
|
@@ -4715,6 +4728,7 @@ var ExperimentsLibSQL = class extends _mastra_core_storage.ExperimentsStorage {
|
|
|
4715
4728
|
traceId: row.traceId ?? null,
|
|
4716
4729
|
status: row.status ?? null,
|
|
4717
4730
|
tags: row.tags ? (0, _mastra_core_storage.safelyParseJSON)(row.tags) : null,
|
|
4731
|
+
comment: row.comment ?? null,
|
|
4718
4732
|
toolMockReport: row.toolMockReport ? (0, _mastra_core_storage.safelyParseJSON)(row.toolMockReport) : null,
|
|
4719
4733
|
createdAt: (0, _mastra_core_storage.ensureDate)(row.createdAt)
|
|
4720
4734
|
};
|
|
@@ -5029,6 +5043,10 @@ var ExperimentsLibSQL = class extends _mastra_core_storage.ExperimentsStorage {
|
|
|
5029
5043
|
setClauses.push(`"tags" = ?`);
|
|
5030
5044
|
values.push(JSON.stringify(input.tags));
|
|
5031
5045
|
}
|
|
5046
|
+
if (input.comment !== void 0) {
|
|
5047
|
+
setClauses.push(`"comment" = ?`);
|
|
5048
|
+
values.push(input.comment);
|
|
5049
|
+
}
|
|
5032
5050
|
if (setClauses.length === 0) {
|
|
5033
5051
|
const existing = await this.getExperimentResultById({ id: input.id });
|
|
5034
5052
|
if (!existing) throw new _mastra_core_error.MastraError({
|
|
@@ -8512,7 +8530,7 @@ const statusTimestamp = (status, now) => {
|
|
|
8512
8530
|
if (status === "discarded") return { discardedAt: now };
|
|
8513
8531
|
return {};
|
|
8514
8532
|
};
|
|
8515
|
-
function parseJson$
|
|
8533
|
+
function parseJson$2(value) {
|
|
8516
8534
|
if (value == null) return void 0;
|
|
8517
8535
|
if (typeof value === "string") try {
|
|
8518
8536
|
return JSON.parse(value);
|
|
@@ -8534,14 +8552,14 @@ function rowToNotification(row) {
|
|
|
8534
8552
|
priority: String(row.priority),
|
|
8535
8553
|
status: String(row.status),
|
|
8536
8554
|
summary: String(row.summary),
|
|
8537
|
-
payload: parseJson$
|
|
8555
|
+
payload: parseJson$2(row.payload),
|
|
8538
8556
|
resourceId: row.resourceId == null ? void 0 : String(row.resourceId),
|
|
8539
8557
|
agentId: row.agentId == null ? void 0 : String(row.agentId),
|
|
8540
8558
|
sourceId: row.sourceId == null ? void 0 : String(row.sourceId),
|
|
8541
8559
|
dedupeKey: row.dedupeKey == null ? void 0 : String(row.dedupeKey),
|
|
8542
8560
|
coalesceKey: row.coalesceKey == null ? void 0 : String(row.coalesceKey),
|
|
8543
8561
|
coalescedCount: Number(row.coalescedCount ?? 1),
|
|
8544
|
-
attributes: parseJson$
|
|
8562
|
+
attributes: parseJson$2(row.attributes),
|
|
8545
8563
|
createdAt: new Date(String(row.createdAt)),
|
|
8546
8564
|
updatedAt: new Date(String(row.updatedAt)),
|
|
8547
8565
|
deliveredAt: parseDate(row.deliveredAt),
|
|
@@ -8557,7 +8575,7 @@ function rowToNotification(row) {
|
|
|
8557
8575
|
lastDeliveryError: row.lastDeliveryError == null ? void 0 : String(row.lastDeliveryError),
|
|
8558
8576
|
deliveredSignalId: row.deliveredSignalId == null ? void 0 : String(row.deliveredSignalId),
|
|
8559
8577
|
summarySignalId: row.summarySignalId == null ? void 0 : String(row.summarySignalId),
|
|
8560
|
-
metadata: parseJson$
|
|
8578
|
+
metadata: parseJson$2(row.metadata)
|
|
8561
8579
|
};
|
|
8562
8580
|
}
|
|
8563
8581
|
function addArrayFilter(conditions, args, column, value) {
|
|
@@ -9748,7 +9766,7 @@ var PromptBlocksLibSQL = class extends _mastra_core_storage.PromptBlocksStorage
|
|
|
9748
9766
|
};
|
|
9749
9767
|
//#endregion
|
|
9750
9768
|
//#region src/storage/domains/schedules/index.ts
|
|
9751
|
-
function parseJson(val) {
|
|
9769
|
+
function parseJson$1(val) {
|
|
9752
9770
|
if (val == null) return void 0;
|
|
9753
9771
|
if (typeof val === "string") try {
|
|
9754
9772
|
return JSON.parse(val);
|
|
@@ -9762,7 +9780,7 @@ function toNumber(val) {
|
|
|
9762
9780
|
return Number(val);
|
|
9763
9781
|
}
|
|
9764
9782
|
function rowToSchedule(row) {
|
|
9765
|
-
const target = parseJson(row.target);
|
|
9783
|
+
const target = parseJson$1(row.target);
|
|
9766
9784
|
if (!target) throw new Error(`Schedule row ${row.id} has invalid target`);
|
|
9767
9785
|
const schedule = {
|
|
9768
9786
|
id: String(row.id),
|
|
@@ -9776,7 +9794,7 @@ function rowToSchedule(row) {
|
|
|
9776
9794
|
if (row.timezone != null) schedule.timezone = String(row.timezone);
|
|
9777
9795
|
if (row.last_fire_at != null) schedule.lastFireAt = toNumber(row.last_fire_at);
|
|
9778
9796
|
if (row.last_run_id != null) schedule.lastRunId = String(row.last_run_id);
|
|
9779
|
-
const metadata = parseJson(row.metadata);
|
|
9797
|
+
const metadata = parseJson$1(row.metadata);
|
|
9780
9798
|
if (metadata !== void 0) schedule.metadata = metadata;
|
|
9781
9799
|
if (row.owner_type != null) schedule.ownerType = String(row.owner_type);
|
|
9782
9800
|
if (row.owner_id != null) schedule.ownerId = String(row.owner_id);
|
|
@@ -9794,7 +9812,7 @@ function rowToTrigger(row) {
|
|
|
9794
9812
|
};
|
|
9795
9813
|
if (row.error != null) trigger.error = String(row.error);
|
|
9796
9814
|
if (row.parent_trigger_id != null) trigger.parentTriggerId = String(row.parent_trigger_id);
|
|
9797
|
-
const metadata = parseJson(row.metadata);
|
|
9815
|
+
const metadata = parseJson$1(row.metadata);
|
|
9798
9816
|
if (metadata !== void 0) trigger.metadata = metadata;
|
|
9799
9817
|
return trigger;
|
|
9800
9818
|
}
|
|
@@ -11675,6 +11693,159 @@ var ToolProviderConnectionsLibSQL = class extends _mastra_core_storage.ToolProvi
|
|
|
11675
11693
|
}
|
|
11676
11694
|
};
|
|
11677
11695
|
//#endregion
|
|
11696
|
+
//#region src/storage/domains/workflow-definitions/index.ts
|
|
11697
|
+
function parseJson(val, column, rowId) {
|
|
11698
|
+
if (val == null) return void 0;
|
|
11699
|
+
if (typeof val === "string") try {
|
|
11700
|
+
return JSON.parse(val);
|
|
11701
|
+
} catch {
|
|
11702
|
+
throw new Error(`Workflow definition row "${String(rowId)}" has malformed JSON in column "${column}".`);
|
|
11703
|
+
}
|
|
11704
|
+
return val;
|
|
11705
|
+
}
|
|
11706
|
+
function rowToDefinition(row) {
|
|
11707
|
+
const inputSchema = parseJson(row.inputSchema, "inputSchema", row.id);
|
|
11708
|
+
const outputSchema = parseJson(row.outputSchema, "outputSchema", row.id);
|
|
11709
|
+
const graph = parseJson(row.graph, "graph", row.id);
|
|
11710
|
+
if (inputSchema === void 0 || outputSchema === void 0 || graph === void 0) throw new Error(`Workflow definition row "${row.id}" is missing required JSON columns.`);
|
|
11711
|
+
const def = {
|
|
11712
|
+
id: String(row.id),
|
|
11713
|
+
inputSchema,
|
|
11714
|
+
outputSchema,
|
|
11715
|
+
graph,
|
|
11716
|
+
status: row.status,
|
|
11717
|
+
source: row.source,
|
|
11718
|
+
createdAt: new Date(row.createdAt),
|
|
11719
|
+
updatedAt: new Date(row.updatedAt)
|
|
11720
|
+
};
|
|
11721
|
+
if (row.description != null) def.description = String(row.description);
|
|
11722
|
+
const metadata = parseJson(row.metadata, "metadata", row.id);
|
|
11723
|
+
if (metadata !== void 0) def.metadata = metadata;
|
|
11724
|
+
const stateSchema = parseJson(row.stateSchema, "stateSchema", row.id);
|
|
11725
|
+
if (stateSchema !== void 0) def.stateSchema = stateSchema;
|
|
11726
|
+
const requestContextSchema = parseJson(row.requestContextSchema, "requestContextSchema", row.id);
|
|
11727
|
+
if (requestContextSchema !== void 0) def.requestContextSchema = requestContextSchema;
|
|
11728
|
+
if (row.authorId != null) def.authorId = String(row.authorId);
|
|
11729
|
+
return def;
|
|
11730
|
+
}
|
|
11731
|
+
var WorkflowDefinitionsLibSQL = class extends _mastra_core_storage.WorkflowDefinitionsStorage {
|
|
11732
|
+
#db;
|
|
11733
|
+
#client;
|
|
11734
|
+
constructor(config) {
|
|
11735
|
+
super();
|
|
11736
|
+
const client = resolveClient(config);
|
|
11737
|
+
this.#client = client;
|
|
11738
|
+
this.#db = new LibSQLDB({
|
|
11739
|
+
client,
|
|
11740
|
+
maxRetries: config.maxRetries,
|
|
11741
|
+
initialBackoffMs: config.initialBackoffMs
|
|
11742
|
+
});
|
|
11743
|
+
}
|
|
11744
|
+
async init() {
|
|
11745
|
+
await this.#db.createTable({
|
|
11746
|
+
tableName: _mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS,
|
|
11747
|
+
schema: _mastra_core_storage.TABLE_SCHEMAS[_mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS]
|
|
11748
|
+
});
|
|
11749
|
+
await this.#client.execute({
|
|
11750
|
+
sql: `CREATE INDEX IF NOT EXISTS idx_workflow_definitions_status ON "${_mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS}" ("status")`,
|
|
11751
|
+
args: []
|
|
11752
|
+
});
|
|
11753
|
+
}
|
|
11754
|
+
async dangerouslyClearAll() {
|
|
11755
|
+
await this.#db.deleteData({ tableName: _mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS });
|
|
11756
|
+
}
|
|
11757
|
+
async upsert(input) {
|
|
11758
|
+
const now = /* @__PURE__ */ new Date();
|
|
11759
|
+
if (!await this.get(input.id)) {
|
|
11760
|
+
if (!("inputSchema" in input) || !input.inputSchema) throw new Error(`Cannot create workflow definition "${input.id}": inputSchema is required.`);
|
|
11761
|
+
if (!("outputSchema" in input) || !input.outputSchema) throw new Error(`Cannot create workflow definition "${input.id}": outputSchema is required.`);
|
|
11762
|
+
if (!("graph" in input) || !input.graph) throw new Error(`Cannot create workflow definition "${input.id}": graph is required.`);
|
|
11763
|
+
const record = {
|
|
11764
|
+
id: input.id,
|
|
11765
|
+
description: input.description ?? null,
|
|
11766
|
+
metadata: input.metadata ?? null,
|
|
11767
|
+
inputSchema: input.inputSchema,
|
|
11768
|
+
outputSchema: input.outputSchema,
|
|
11769
|
+
stateSchema: input.stateSchema ?? null,
|
|
11770
|
+
requestContextSchema: input.requestContextSchema ?? null,
|
|
11771
|
+
graph: input.graph,
|
|
11772
|
+
status: "active",
|
|
11773
|
+
source: "storage",
|
|
11774
|
+
authorId: "authorId" in input ? input.authorId ?? null : null,
|
|
11775
|
+
createdAt: now,
|
|
11776
|
+
updatedAt: now
|
|
11777
|
+
};
|
|
11778
|
+
try {
|
|
11779
|
+
await this.#db.insertOnly({
|
|
11780
|
+
tableName: _mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS,
|
|
11781
|
+
record
|
|
11782
|
+
});
|
|
11783
|
+
} catch (error) {
|
|
11784
|
+
if (!await this.get(input.id)) throw error;
|
|
11785
|
+
return this.#applyUpdate(input, now);
|
|
11786
|
+
}
|
|
11787
|
+
const created = await this.get(input.id);
|
|
11788
|
+
if (!created) throw new Error(`Failed to persist workflow definition "${input.id}".`);
|
|
11789
|
+
return created;
|
|
11790
|
+
}
|
|
11791
|
+
return this.#applyUpdate(input, now);
|
|
11792
|
+
}
|
|
11793
|
+
async #applyUpdate(input, now) {
|
|
11794
|
+
const data = { updatedAt: now };
|
|
11795
|
+
if ("description" in input && input.description !== void 0) data.description = input.description;
|
|
11796
|
+
if ("metadata" in input && input.metadata !== void 0) data.metadata = input.metadata;
|
|
11797
|
+
if ("inputSchema" in input && input.inputSchema !== void 0) data.inputSchema = input.inputSchema;
|
|
11798
|
+
if ("outputSchema" in input && input.outputSchema !== void 0) data.outputSchema = input.outputSchema;
|
|
11799
|
+
if ("stateSchema" in input && input.stateSchema !== void 0) data.stateSchema = input.stateSchema;
|
|
11800
|
+
if ("requestContextSchema" in input && input.requestContextSchema !== void 0) data.requestContextSchema = input.requestContextSchema;
|
|
11801
|
+
if ("graph" in input && input.graph !== void 0) data.graph = input.graph;
|
|
11802
|
+
if ("status" in input && input.status !== void 0) data.status = input.status;
|
|
11803
|
+
if ("authorId" in input && input.authorId !== void 0) data.authorId = input.authorId;
|
|
11804
|
+
await this.#db.update({
|
|
11805
|
+
tableName: _mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS,
|
|
11806
|
+
keys: { id: input.id },
|
|
11807
|
+
data
|
|
11808
|
+
});
|
|
11809
|
+
const updated = await this.get(input.id);
|
|
11810
|
+
if (!updated) throw new Error(`Failed to update workflow definition "${input.id}".`);
|
|
11811
|
+
return updated;
|
|
11812
|
+
}
|
|
11813
|
+
async get(id) {
|
|
11814
|
+
const row = (await this.#client.execute({
|
|
11815
|
+
sql: `SELECT ${buildSelectColumns(_mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS)} FROM "${_mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS}" WHERE id = ?`,
|
|
11816
|
+
args: [id]
|
|
11817
|
+
})).rows[0];
|
|
11818
|
+
return row ? rowToDefinition(row) : null;
|
|
11819
|
+
}
|
|
11820
|
+
async list(args) {
|
|
11821
|
+
const conditions = [];
|
|
11822
|
+
const params = [];
|
|
11823
|
+
if (args?.status) {
|
|
11824
|
+
conditions.push("status = ?");
|
|
11825
|
+
params.push(args.status);
|
|
11826
|
+
}
|
|
11827
|
+
if (args?.authorId !== void 0) {
|
|
11828
|
+
conditions.push("authorId = ?");
|
|
11829
|
+
params.push(args.authorId);
|
|
11830
|
+
}
|
|
11831
|
+
const where = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
11832
|
+
const definitions = (await this.#client.execute({
|
|
11833
|
+
sql: `SELECT ${buildSelectColumns(_mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS)} FROM "${_mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS}" ${where} ORDER BY updatedAt DESC`,
|
|
11834
|
+
args: params
|
|
11835
|
+
})).rows.map((row) => rowToDefinition(row));
|
|
11836
|
+
return {
|
|
11837
|
+
definitions,
|
|
11838
|
+
total: definitions.length
|
|
11839
|
+
};
|
|
11840
|
+
}
|
|
11841
|
+
async delete(id) {
|
|
11842
|
+
await this.#client.execute({
|
|
11843
|
+
sql: `DELETE FROM "${_mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS}" WHERE id = ?`,
|
|
11844
|
+
args: [id]
|
|
11845
|
+
});
|
|
11846
|
+
}
|
|
11847
|
+
};
|
|
11848
|
+
//#endregion
|
|
11678
11849
|
//#region src/storage/domains/workflows/index.ts
|
|
11679
11850
|
var WorkflowsLibSQL = class WorkflowsLibSQL extends _mastra_core_storage.WorkflowsStorage {
|
|
11680
11851
|
/**
|
|
@@ -12969,6 +13140,7 @@ var LibSQLStore = class extends _mastra_core_storage.MastraCompositeStore {
|
|
|
12969
13140
|
};
|
|
12970
13141
|
const scores = new ScoresLibSQL(domainConfig);
|
|
12971
13142
|
const workflows = new WorkflowsLibSQL(domainConfig);
|
|
13143
|
+
const workflowDefinitions = new WorkflowDefinitionsLibSQL(domainConfig);
|
|
12972
13144
|
const memory = new MemoryLibSQL(domainConfig);
|
|
12973
13145
|
const observability = new ObservabilityLibSQL(domainConfig);
|
|
12974
13146
|
const agents = new AgentsLibSQL(domainConfig);
|
|
@@ -12992,6 +13164,7 @@ var LibSQLStore = class extends _mastra_core_storage.MastraCompositeStore {
|
|
|
12992
13164
|
this.stores = {
|
|
12993
13165
|
scores,
|
|
12994
13166
|
workflows,
|
|
13167
|
+
workflowDefinitions,
|
|
12995
13168
|
memory,
|
|
12996
13169
|
observability,
|
|
12997
13170
|
agents,
|
|
@@ -13205,6 +13378,7 @@ exports.ScoresLibSQL = ScoresLibSQL;
|
|
|
13205
13378
|
exports.SkillsLibSQL = SkillsLibSQL;
|
|
13206
13379
|
exports.ThreadStateLibSQL = ThreadStateLibSQL;
|
|
13207
13380
|
exports.ToolProviderConnectionsLibSQL = ToolProviderConnectionsLibSQL;
|
|
13381
|
+
exports.WorkflowDefinitionsLibSQL = WorkflowDefinitionsLibSQL;
|
|
13208
13382
|
exports.WorkflowsLibSQL = WorkflowsLibSQL;
|
|
13209
13383
|
exports.WorkspacesLibSQL = WorkspacesLibSQL;
|
|
13210
13384
|
|