@mastra/libsql 1.19.0 → 1.20.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 +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-agents-agent-approval.md +1 -1
- package/dist/docs/references/docs-agents-networks.md +2 -2
- package/dist/docs/references/docs-memory-overview.md +2 -2
- package/dist/docs/references/docs-storage-overview.md +2 -2
- package/dist/docs/references/reference-file-based-agents-storage.md +1 -1
- package/dist/docs/references/reference-storage-composite.md +58 -0
- package/dist/docs/references/reference-storage-retention.md +1 -1
- package/dist/index.cjs +87 -36
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +87 -36
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/experiments/index.d.ts.map +1 -1
- package/dist/storage/domains/memory/index.d.ts +6 -0
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,67 @@
|
|
|
1
1
|
# @mastra/libsql
|
|
2
2
|
|
|
3
|
+
## 1.20.0-alpha.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Fixed `include` in `listMessages` and `listMessagesByResourceId` so it can no longer return a message that belongs to a different resource. When you pass a `resourceId`, the target message and its surrounding context messages now stay inside that resource. Includes that cross threads inside the same resource keep working, so semantic recall with `scope: 'resource'` is unchanged. ([#20984](https://github.com/mastra-ai/mastra/pull/20984))
|
|
8
|
+
|
|
9
|
+
**Behaviour change in the in-memory store**
|
|
10
|
+
|
|
11
|
+
The in-memory store read the context window from the thread you queried. It now reads the window from the thread that owns the target message, which is what the SQL stores already did. This only changes the result when an `include` entry names a message from another thread.
|
|
12
|
+
|
|
13
|
+
The in-memory store also ignored `include` in `listMessagesByResourceId`. It now returns the included messages, like `@mastra/libsql` and `@mastra/pg` do.
|
|
14
|
+
|
|
15
|
+
Fixes #20604.
|
|
16
|
+
|
|
17
|
+
- Updated dependencies [[`6445eba`](https://github.com/mastra-ai/mastra/commit/6445eba6020abac681aba1cc9289f446cb400cbe), [`df31eb0`](https://github.com/mastra-ai/mastra/commit/df31eb0c7087d782a0d9346e467f9a4af4b0eef6), [`fcd0667`](https://github.com/mastra-ai/mastra/commit/fcd0667a4e378be35c9a1b1eb19cce78fbfd7282), [`bab06b1`](https://github.com/mastra-ai/mastra/commit/bab06b18923873a584bdfc71a6b4ec7fb4727fb7)]:
|
|
18
|
+
- @mastra/core@1.58.0-alpha.5
|
|
19
|
+
|
|
20
|
+
## 1.20.0-alpha.0
|
|
21
|
+
|
|
22
|
+
### Minor Changes
|
|
23
|
+
|
|
24
|
+
- Added experiment provenance and grouping support to the LibSQL, MongoDB, MySQL, PostgreSQL, and Spanner storage adapters. These fields remain available for later grouping and filtering. ([#20645](https://github.com/mastra-ai/mastra/pull/20645))
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import { PostgresStore } from '@mastra/pg';
|
|
28
|
+
|
|
29
|
+
const storage = new PostgresStore({
|
|
30
|
+
id: 'postgres-storage',
|
|
31
|
+
connectionString: process.env.DATABASE_URL!,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
await dataset.startExperiment({
|
|
35
|
+
task,
|
|
36
|
+
scorers,
|
|
37
|
+
provenance: { source: 'github', sourceVersion: 'abc123' },
|
|
38
|
+
grouping: { experimentSetId: 'benchmark-1', variantId: 'candidate', trialIndex: 0 },
|
|
39
|
+
});
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
- Memory list reads now surface database errors instead of silently returning empty results. ([#17910](https://github.com/mastra-ai/mastra/pull/17910))
|
|
43
|
+
|
|
44
|
+
Previously, the paginated memory reads (`listThreads`, `listMessages`, `listMessagesByResourceId`, and `listMessagesById`) caught backend failures, logged them, and returned an empty payload like `{ threads: [], total: 0, hasMore: false }`. A transient outage (locked table, dropped connection) was therefore indistinguishable from a genuinely empty result, so an agent reading conversation history during a brief failure would treat it as "no history" and could overwrite real state. These methods now re-throw the failure as a `MastraError`. Validation (USER) errors and genuinely empty results are unchanged.
|
|
45
|
+
|
|
46
|
+
**Behavior change**
|
|
47
|
+
|
|
48
|
+
Callers that previously received an empty result on a backend failure will now receive a thrown `MastraError`. If you call these read methods directly (rather than through an agent, which already surfaces errors), wrap them so a transient outage doesn't crash the caller:
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
try {
|
|
52
|
+
const { threads } = await storage.listThreads({ resourceId });
|
|
53
|
+
// ...use threads
|
|
54
|
+
} catch (error) {
|
|
55
|
+
// a real backend failure. Decide whether to retry, surface, or degrade.
|
|
56
|
+
// An empty thread list no longer hides here; it only means "no threads".
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Patch Changes
|
|
61
|
+
|
|
62
|
+
- Updated dependencies [[`e7109ee`](https://github.com/mastra-ai/mastra/commit/e7109ee6f731bacc79c885906f3c7dca8d8f013a), [`772c0c8`](https://github.com/mastra-ai/mastra/commit/772c0c897cec383258de2e6178147f8014767c7b), [`578bf2e`](https://github.com/mastra-ai/mastra/commit/578bf2e6a88e9d5b8bf502204e15a95dfbb679ae), [`06b2d87`](https://github.com/mastra-ai/mastra/commit/06b2d87e63bcdd0ed59215c6789692b9b12de376), [`ac01d63`](https://github.com/mastra-ai/mastra/commit/ac01d6355974aec73fdb8781449ed12bac582094), [`a810a05`](https://github.com/mastra-ai/mastra/commit/a810a058f62ad407cfc1701e0be36ae91145d7cf), [`f8da216`](https://github.com/mastra-ai/mastra/commit/f8da21633e7eb0e31c9ce0fc30567870d19416d3), [`6104347`](https://github.com/mastra-ai/mastra/commit/61043473ba6bfd0a25156824e853e13165562e6c), [`45bfb88`](https://github.com/mastra-ai/mastra/commit/45bfb88fd52f1dd3be20e2a38905777c96499c90), [`e3b9307`](https://github.com/mastra-ai/mastra/commit/e3b9307098daefbfae2a52ae2ef51bc9fc701190), [`d6834c5`](https://github.com/mastra-ai/mastra/commit/d6834c5a7866b16734d23900163c2414ed70d791), [`c52d346`](https://github.com/mastra-ai/mastra/commit/c52d3462ec831a5d95926ecd3d3373f5928ad2e5), [`0023e79`](https://github.com/mastra-ai/mastra/commit/0023e7919431078280abd11c89d1edeae35fcc69), [`c2ad51e`](https://github.com/mastra-ai/mastra/commit/c2ad51e2467f901eecba8c9f4a45e22a50bd7c18), [`3dc97ea`](https://github.com/mastra-ai/mastra/commit/3dc97ea415fad353b48a13095fad1835933cc12a), [`3d01cd3`](https://github.com/mastra-ai/mastra/commit/3d01cd387321b6f9c5cac31d487c84bf51b19c78), [`7bf3086`](https://github.com/mastra-ai/mastra/commit/7bf308663f0115ca74ad20554ade740f06640859), [`a8dd139`](https://github.com/mastra-ai/mastra/commit/a8dd1391a9fe9a6632c25809ef236980afa9a020), [`e5786be`](https://github.com/mastra-ai/mastra/commit/e5786be02bb903073082bd9d6da880ebaacc343f), [`2093fbd`](https://github.com/mastra-ai/mastra/commit/2093fbd53bb744bae19ec89f6d73db9a66fbe8a7), [`e7a5da4`](https://github.com/mastra-ai/mastra/commit/e7a5da4ef8e4dd452d2f232961b4e682a85ffe43), [`7b4393d`](https://github.com/mastra-ai/mastra/commit/7b4393d557411fdcf07b0e30e5acaf7cc85154ae)]:
|
|
63
|
+
- @mastra/core@1.58.0-alpha.1
|
|
64
|
+
|
|
3
65
|
## 1.19.0
|
|
4
66
|
|
|
5
67
|
### Minor Changes
|
package/dist/docs/SKILL.md
CHANGED
|
@@ -498,7 +498,7 @@ The same discovery is available over HTTP as `GET /agents/:agentId/suspended-run
|
|
|
498
498
|
|
|
499
499
|
## Tool approval: Supervisor agents
|
|
500
500
|
|
|
501
|
-
A [supervisor agent](https://mastra.ai/docs/
|
|
501
|
+
A [supervisor agent](https://mastra.ai/docs/capabilities/subagents) coordinates multiple subagents using `.stream()` or `.generate()`. When a subagent calls a tool that requires approval, the request propagates up through the delegation chain and surfaces at the supervisor level:
|
|
502
502
|
|
|
503
503
|
1. The supervisor delegates a task to a subagent.
|
|
504
504
|
2. The subagent calls a tool that has `requireApproval: true` or uses `suspend()`.
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# Agent networks
|
|
4
4
|
|
|
5
|
-
> **Deprecated:** Agent networks are deprecated and will be removed in a future major release. [Supervisor agents](https://mastra.ai/docs/
|
|
5
|
+
> **Deprecated:** Agent networks are deprecated and will be removed in a future major release. [Supervisor agents](https://mastra.ai/docs/capabilities/subagents) using `agent.stream()` or `agent.generate()` are now the recommended approach. It provides the same multi-agent coordination with better control, a simpler API, and easier debugging.
|
|
6
6
|
>
|
|
7
7
|
> See the [migration guide](https://mastra.ai/guides/migrations/network-to-supervisor) to upgrade.
|
|
8
8
|
|
|
@@ -180,5 +180,5 @@ Requirements for automatic resumption:
|
|
|
180
180
|
|
|
181
181
|
## Related
|
|
182
182
|
|
|
183
|
-
- [Supervisor agents](https://mastra.ai/docs/
|
|
183
|
+
- [Supervisor agents](https://mastra.ai/docs/capabilities/subagents)
|
|
184
184
|
- [Migration: `.network()` to supervisor agents](https://mastra.ai/guides/migrations/network-to-supervisor)
|
|
@@ -188,7 +188,7 @@ Conversation messages are ordered by timestamp and deduplicated by message ID, s
|
|
|
188
188
|
|
|
189
189
|
## Memory in multi-agent systems
|
|
190
190
|
|
|
191
|
-
When a [supervisor agent](https://mastra.ai/docs/
|
|
191
|
+
When a [supervisor agent](https://mastra.ai/docs/capabilities/subagents) delegates to a subagent, Mastra isolates subagent memory automatically. No flag enables this as it happens on every delegation. Understanding how this scoping works lets you decide what stays private and what to share intentionally.
|
|
192
192
|
|
|
193
193
|
### How delegation scopes memory
|
|
194
194
|
|
|
@@ -200,7 +200,7 @@ Each delegation creates a fresh `threadId` and a deterministic `resourceId` for
|
|
|
200
200
|
|
|
201
201
|
> **Note:** Title generation (`generateTitle`) is a top-level thread concern and **isn't** applied to inherited subagent threads. Because each delegation creates an ephemeral thread that no one sees, running title generation for it would waste an LLM call per delegation. To generate titles for a subagent's own threads, give that subagent its own memory configuration.
|
|
202
202
|
|
|
203
|
-
The supervisor forwards its conversation context to the subagent so it has enough background to complete the task. Only the delegation prompt and the subagent's response are saved, the full parent conversation isn't stored. You can control which messages reach the subagent with the [`messageFilter`](https://mastra.ai/docs/
|
|
203
|
+
The supervisor forwards its conversation context to the subagent so it has enough background to complete the task. Only the delegation prompt and the subagent's response are saved, the full parent conversation isn't stored. You can control which messages reach the subagent with the [`messageFilter`](https://mastra.ai/docs/capabilities/subagents) callback.
|
|
204
204
|
|
|
205
205
|
> **Note:** Subagent resource IDs are always suffixed with the agent name (`{parentResourceId}-{agentName}`). Different subagents under the same supervisor never share a resource ID through delegation.
|
|
206
206
|
|
|
@@ -184,7 +184,7 @@ export const mastra = new Mastra({
|
|
|
184
184
|
})
|
|
185
185
|
```
|
|
186
186
|
|
|
187
|
-
You can also route `observability` to a dedicated analytics backend. See [observability
|
|
187
|
+
You can also route `observability` to a dedicated analytics backend. See the [observability quickstart](https://mastra.ai/docs/observability/overview) for an observability-specific example.
|
|
188
188
|
|
|
189
189
|
## Supported providers
|
|
190
190
|
|
|
@@ -211,4 +211,4 @@ Each provider page includes installation instructions, configuration parameters,
|
|
|
211
211
|
- [Storage retention](https://mastra.ai/reference/storage/retention)
|
|
212
212
|
- [Storage schemas](https://mastra.ai/reference/storage/overview)
|
|
213
213
|
- [Memory](https://mastra.ai/docs/memory/overview)
|
|
214
|
-
- [Observability storage](https://mastra.ai/docs/observability/
|
|
214
|
+
- [Observability storage](https://mastra.ai/docs/observability/overview)
|
|
@@ -23,7 +23,7 @@ Mastra registers the store before file-based agents and workflows, so storage-de
|
|
|
23
23
|
|
|
24
24
|
## Production backends
|
|
25
25
|
|
|
26
|
-
`storage.ts` can export any Mastra storage adapter, such as LibSQL, PostgreSQL, or MongoDB. For setup patterns, provider support, and schema details, see [storage overview](https://mastra.ai/docs/storage/overview), [observability
|
|
26
|
+
`storage.ts` can export any Mastra storage adapter, such as LibSQL, PostgreSQL, or MongoDB. For setup patterns, provider support, and schema details, see [storage overview](https://mastra.ai/docs/storage/overview), [observability signal support](https://mastra.ai/docs/observability/overview), and the [storage reference](https://mastra.ai/reference/storage/overview).
|
|
27
27
|
|
|
28
28
|
## Precedence with code
|
|
29
29
|
|
|
@@ -251,6 +251,64 @@ const memoryStore = await storage.getStore('memory')
|
|
|
251
251
|
const thread = await memoryStore?.getThreadById({ threadId: '...' })
|
|
252
252
|
```
|
|
253
253
|
|
|
254
|
+
## Closing connections
|
|
255
|
+
|
|
256
|
+
`close()` releases the connections of the stores a composite was built from: the `default` and `editor` stores, plus any domain that owns its own client. Each store is closed once, even when it backs several domains. When passed to the Mastra class, `close()` is called by `shutdown()`:
|
|
257
|
+
|
|
258
|
+
```typescript
|
|
259
|
+
import { MastraCompositeStore } from '@mastra/core/storage'
|
|
260
|
+
import { PostgresStore } from '@mastra/pg'
|
|
261
|
+
import { Mastra } from '@mastra/core'
|
|
262
|
+
|
|
263
|
+
const pgStore = new PostgresStore({
|
|
264
|
+
id: 'pg-storage',
|
|
265
|
+
connectionString: process.env.DATABASE_URL,
|
|
266
|
+
})
|
|
267
|
+
|
|
268
|
+
export const mastra = new Mastra({
|
|
269
|
+
storage: new MastraCompositeStore({ id: 'composite', default: pgStore }),
|
|
270
|
+
})
|
|
271
|
+
|
|
272
|
+
process.on('SIGTERM', async () => {
|
|
273
|
+
// Releases the Postgres pool, so the process can exit
|
|
274
|
+
await mastra.shutdown()
|
|
275
|
+
})
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
A store you construct only to supply a domain isn't reachable through the composite. Keep a reference to it and close it yourself:
|
|
279
|
+
|
|
280
|
+
```typescript
|
|
281
|
+
import { MastraCompositeStore } from '@mastra/core/storage'
|
|
282
|
+
import { ClickhouseStore } from '@mastra/clickhouse'
|
|
283
|
+
import { PostgresStore } from '@mastra/pg'
|
|
284
|
+
import { Mastra } from '@mastra/core'
|
|
285
|
+
|
|
286
|
+
const pgStore = new PostgresStore({
|
|
287
|
+
id: 'pg-storage',
|
|
288
|
+
connectionString: process.env.DATABASE_URL,
|
|
289
|
+
})
|
|
290
|
+
|
|
291
|
+
const clickhouseStore = new ClickhouseStore({
|
|
292
|
+
id: 'clickhouse-storage',
|
|
293
|
+
url: process.env.CLICKHOUSE_URL,
|
|
294
|
+
username: process.env.CLICKHOUSE_USERNAME,
|
|
295
|
+
password: process.env.CLICKHOUSE_PASSWORD,
|
|
296
|
+
})
|
|
297
|
+
|
|
298
|
+
export const mastra = new Mastra({
|
|
299
|
+
storage: new MastraCompositeStore({
|
|
300
|
+
id: 'composite',
|
|
301
|
+
default: pgStore,
|
|
302
|
+
domains: { observability: clickhouseStore.stores?.observability },
|
|
303
|
+
}),
|
|
304
|
+
})
|
|
305
|
+
|
|
306
|
+
process.on('SIGTERM', async () => {
|
|
307
|
+
await mastra.shutdown()
|
|
308
|
+
await clickhouseStore.close()
|
|
309
|
+
})
|
|
310
|
+
```
|
|
311
|
+
|
|
254
312
|
## Use cases
|
|
255
313
|
|
|
256
314
|
### Separate databases for different workloads
|
|
@@ -92,7 +92,7 @@ Each domain declares which of its tables can be age-pruned and which timestamp c
|
|
|
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
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
|
-
> - LibSQL
|
|
95
|
+
> - LibSQL and PostgreSQL support all domains above except `harness`, which PostgreSQL doesn't implement. MongoDB supports all except `threadState` and `harness`.
|
|
96
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
|
package/dist/index.cjs
CHANGED
|
@@ -4592,7 +4592,13 @@ var ExperimentsLibSQL = class extends _mastra_core_storage.ExperimentsStorage {
|
|
|
4592
4592
|
ifNotExists: [
|
|
4593
4593
|
"agentVersion",
|
|
4594
4594
|
"organizationId",
|
|
4595
|
-
"projectId"
|
|
4595
|
+
"projectId",
|
|
4596
|
+
"provenance",
|
|
4597
|
+
"runnerAttestation",
|
|
4598
|
+
"experimentSetId",
|
|
4599
|
+
"comparisonId",
|
|
4600
|
+
"variantId",
|
|
4601
|
+
"trialIndex"
|
|
4596
4602
|
]
|
|
4597
4603
|
});
|
|
4598
4604
|
await this.#db.alterTable({
|
|
@@ -4612,6 +4618,10 @@ var ExperimentsLibSQL = class extends _mastra_core_storage.ExperimentsStorage {
|
|
|
4612
4618
|
sql: `CREATE INDEX IF NOT EXISTS idx_experiments_datasetid ON "${_mastra_core_storage.TABLE_EXPERIMENTS}" ("datasetId")`,
|
|
4613
4619
|
args: []
|
|
4614
4620
|
},
|
|
4621
|
+
{
|
|
4622
|
+
sql: `CREATE INDEX IF NOT EXISTS idx_experiments_grouping ON "${_mastra_core_storage.TABLE_EXPERIMENTS}" ("experimentSetId", "comparisonId", "variantId", "trialIndex")`,
|
|
4623
|
+
args: []
|
|
4624
|
+
},
|
|
4615
4625
|
{
|
|
4616
4626
|
sql: `CREATE INDEX IF NOT EXISTS idx_experiment_results_experimentid ON "${_mastra_core_storage.TABLE_EXPERIMENT_RESULTS}" ("experimentId")`,
|
|
4617
4627
|
args: []
|
|
@@ -4711,6 +4721,12 @@ var ExperimentsLibSQL = class extends _mastra_core_storage.ExperimentsStorage {
|
|
|
4711
4721
|
name: row.name ?? void 0,
|
|
4712
4722
|
description: row.description ?? void 0,
|
|
4713
4723
|
metadata: row.metadata ? (0, _mastra_core_storage.safelyParseJSON)(row.metadata) : void 0,
|
|
4724
|
+
provenance: row.provenance ? (0, _mastra_core_storage.safelyParseJSON)(row.provenance) : null,
|
|
4725
|
+
runnerAttestation: row.runnerAttestation ? (0, _mastra_core_storage.safelyParseJSON)(row.runnerAttestation) : null,
|
|
4726
|
+
experimentSetId: row.experimentSetId ?? null,
|
|
4727
|
+
comparisonId: row.comparisonId ?? null,
|
|
4728
|
+
variantId: row.variantId ?? null,
|
|
4729
|
+
trialIndex: row.trialIndex != null ? row.trialIndex : null,
|
|
4714
4730
|
status: row.status,
|
|
4715
4731
|
totalItems: row.totalItems,
|
|
4716
4732
|
succeededCount: row.succeededCount,
|
|
@@ -4764,6 +4780,12 @@ var ExperimentsLibSQL = class extends _mastra_core_storage.ExperimentsStorage {
|
|
|
4764
4780
|
name: input.name ?? null,
|
|
4765
4781
|
description: input.description ?? null,
|
|
4766
4782
|
metadata: input.metadata ?? null,
|
|
4783
|
+
provenance: input.provenance ?? null,
|
|
4784
|
+
runnerAttestation: input.runnerAttestation ?? null,
|
|
4785
|
+
experimentSetId: input.experimentSetId ?? null,
|
|
4786
|
+
comparisonId: input.comparisonId ?? null,
|
|
4787
|
+
variantId: input.variantId ?? null,
|
|
4788
|
+
trialIndex: input.trialIndex ?? null,
|
|
4767
4789
|
status: "pending",
|
|
4768
4790
|
totalItems: input.totalItems,
|
|
4769
4791
|
succeededCount: 0,
|
|
@@ -4787,6 +4809,12 @@ var ExperimentsLibSQL = class extends _mastra_core_storage.ExperimentsStorage {
|
|
|
4787
4809
|
name: input.name,
|
|
4788
4810
|
description: input.description,
|
|
4789
4811
|
metadata: input.metadata,
|
|
4812
|
+
provenance: input.provenance ?? null,
|
|
4813
|
+
runnerAttestation: input.runnerAttestation ?? null,
|
|
4814
|
+
experimentSetId: input.experimentSetId ?? null,
|
|
4815
|
+
comparisonId: input.comparisonId ?? null,
|
|
4816
|
+
variantId: input.variantId ?? null,
|
|
4817
|
+
trialIndex: input.trialIndex ?? null,
|
|
4790
4818
|
status: "pending",
|
|
4791
4819
|
totalItems: input.totalItems,
|
|
4792
4820
|
succeededCount: 0,
|
|
@@ -4912,6 +4940,22 @@ var ExperimentsLibSQL = class extends _mastra_core_storage.ExperimentsStorage {
|
|
|
4912
4940
|
conditions.push("status = ?");
|
|
4913
4941
|
queryParams.push(args.status);
|
|
4914
4942
|
}
|
|
4943
|
+
if (args.experimentSetId !== void 0) {
|
|
4944
|
+
conditions.push("experimentSetId = ?");
|
|
4945
|
+
queryParams.push(args.experimentSetId);
|
|
4946
|
+
}
|
|
4947
|
+
if (args.comparisonId !== void 0) {
|
|
4948
|
+
conditions.push("comparisonId = ?");
|
|
4949
|
+
queryParams.push(args.comparisonId);
|
|
4950
|
+
}
|
|
4951
|
+
if (args.variantId !== void 0) {
|
|
4952
|
+
conditions.push("variantId = ?");
|
|
4953
|
+
queryParams.push(args.variantId);
|
|
4954
|
+
}
|
|
4955
|
+
if (args.trialIndex !== void 0) {
|
|
4956
|
+
conditions.push("trialIndex = ?");
|
|
4957
|
+
queryParams.push(args.trialIndex);
|
|
4958
|
+
}
|
|
4915
4959
|
if (args.filters) {
|
|
4916
4960
|
const { organizationId, projectId } = args.filters;
|
|
4917
4961
|
if (organizationId !== void 0) {
|
|
@@ -6678,14 +6722,21 @@ var MemoryLibSQL = class MemoryLibSQL extends _mastra_core_storage.MemoryStorage
|
|
|
6678
6722
|
return direction === "ASC" ? String(aValue).localeCompare(String(bValue)) : String(bValue).localeCompare(String(aValue));
|
|
6679
6723
|
});
|
|
6680
6724
|
}
|
|
6681
|
-
|
|
6725
|
+
/**
|
|
6726
|
+
* Fetches included messages by ID, discovering their thread automatically.
|
|
6727
|
+
* This handles cross-thread includes where the include item doesn't specify a threadId.
|
|
6728
|
+
* When a resourceId is given, both the target lookup and the surrounding window stay
|
|
6729
|
+
* inside that resource, so an include never leaks another resource's messages.
|
|
6730
|
+
*/
|
|
6731
|
+
async _getIncludedMessages({ include, resourceId }) {
|
|
6682
6732
|
if (!include || include.length === 0) return null;
|
|
6683
6733
|
const targetIds = include.map((inc) => inc.id).filter(Boolean);
|
|
6684
6734
|
if (targetIds.length === 0) return null;
|
|
6735
|
+
const resourceCondition = resourceId ? ` AND "resourceId" = ?` : "";
|
|
6685
6736
|
const idPlaceholders = targetIds.map(() => "?").join(", ");
|
|
6686
6737
|
const targetResult = await this.#client.execute({
|
|
6687
|
-
sql: `SELECT id, thread_id, "createdAt" FROM "${_mastra_core_storage.TABLE_MESSAGES}" WHERE id IN (${idPlaceholders})`,
|
|
6688
|
-
args: targetIds
|
|
6738
|
+
sql: `SELECT id, thread_id, "createdAt" FROM "${_mastra_core_storage.TABLE_MESSAGES}" WHERE id IN (${idPlaceholders})${resourceCondition}`,
|
|
6739
|
+
args: resourceId ? [...targetIds, resourceId] : targetIds
|
|
6689
6740
|
});
|
|
6690
6741
|
if (!targetResult.rows || targetResult.rows.length === 0) return null;
|
|
6691
6742
|
const targetMap = new Map(targetResult.rows.map((r) => [r.id, {
|
|
@@ -6702,21 +6753,25 @@ var MemoryLibSQL = class MemoryLibSQL extends _mastra_core_storage.MemoryStorage
|
|
|
6702
6753
|
SELECT id, content, role, type, "createdAt", thread_id, "resourceId"
|
|
6703
6754
|
FROM "${_mastra_core_storage.TABLE_MESSAGES}"
|
|
6704
6755
|
WHERE thread_id = ?
|
|
6705
|
-
AND "createdAt" <=
|
|
6756
|
+
AND "createdAt" <= ?${resourceCondition}
|
|
6706
6757
|
ORDER BY "createdAt" DESC, id DESC
|
|
6707
6758
|
LIMIT ?
|
|
6708
6759
|
)`);
|
|
6709
|
-
params.push(target.threadId, target.createdAt
|
|
6760
|
+
params.push(target.threadId, target.createdAt);
|
|
6761
|
+
if (resourceId) params.push(resourceId);
|
|
6762
|
+
params.push(withPreviousMessages + 1);
|
|
6710
6763
|
if (withNextMessages > 0) {
|
|
6711
6764
|
unionQueries.push(`SELECT * FROM (
|
|
6712
6765
|
SELECT id, content, role, type, "createdAt", thread_id, "resourceId"
|
|
6713
6766
|
FROM "${_mastra_core_storage.TABLE_MESSAGES}"
|
|
6714
6767
|
WHERE thread_id = ?
|
|
6715
|
-
AND "createdAt" >
|
|
6768
|
+
AND "createdAt" > ?${resourceCondition}
|
|
6716
6769
|
ORDER BY "createdAt" ASC, id ASC
|
|
6717
6770
|
LIMIT ?
|
|
6718
6771
|
)`);
|
|
6719
|
-
params.push(target.threadId, target.createdAt
|
|
6772
|
+
params.push(target.threadId, target.createdAt);
|
|
6773
|
+
if (resourceId) params.push(resourceId);
|
|
6774
|
+
params.push(withNextMessages);
|
|
6720
6775
|
}
|
|
6721
6776
|
}
|
|
6722
6777
|
if (unionQueries.length === 0) return null;
|
|
@@ -6812,7 +6867,10 @@ var MemoryLibSQL = class MemoryLibSQL extends _mastra_core_storage.MemoryStorage
|
|
|
6812
6867
|
hasMore: false
|
|
6813
6868
|
};
|
|
6814
6869
|
if (perPage === 0 && include && include.length > 0) {
|
|
6815
|
-
const includeMessages = await this._getIncludedMessages({
|
|
6870
|
+
const includeMessages = await this._getIncludedMessages({
|
|
6871
|
+
include,
|
|
6872
|
+
resourceId
|
|
6873
|
+
});
|
|
6816
6874
|
if (!includeMessages || includeMessages.length === 0) return {
|
|
6817
6875
|
messages: [],
|
|
6818
6876
|
total: 0,
|
|
@@ -6853,7 +6911,10 @@ var MemoryLibSQL = class MemoryLibSQL extends _mastra_core_storage.MemoryStorage
|
|
|
6853
6911
|
};
|
|
6854
6912
|
const messageIds = new Set(messages.map((m) => m.id));
|
|
6855
6913
|
if (include && include.length > 0) {
|
|
6856
|
-
const includeMessages = await this._getIncludedMessages({
|
|
6914
|
+
const includeMessages = await this._getIncludedMessages({
|
|
6915
|
+
include,
|
|
6916
|
+
resourceId
|
|
6917
|
+
});
|
|
6857
6918
|
if (includeMessages) {
|
|
6858
6919
|
for (const includeMsg of includeMessages) if (!messageIds.has(includeMsg.id)) {
|
|
6859
6920
|
messages.push(includeMsg);
|
|
@@ -6873,6 +6934,7 @@ var MemoryLibSQL = class MemoryLibSQL extends _mastra_core_storage.MemoryStorage
|
|
|
6873
6934
|
hasMore: metadataFilter ? perPageInput !== false && offset + paginatedCount < total : perPageInput !== false && !allThreadMessagesReturned && offset + perPage < total
|
|
6874
6935
|
};
|
|
6875
6936
|
} catch (error) {
|
|
6937
|
+
if (error instanceof _mastra_core_error.MastraError && error.category === _mastra_core_error.ErrorCategory.USER) throw error;
|
|
6876
6938
|
const mastraError = new _mastra_core_error.MastraError({
|
|
6877
6939
|
id: (0, _mastra_core_storage.createStorageErrorId)("LIBSQL", "LIST_MESSAGES", "FAILED"),
|
|
6878
6940
|
domain: _mastra_core_error.ErrorDomain.STORAGE,
|
|
@@ -6884,25 +6946,19 @@ var MemoryLibSQL = class MemoryLibSQL extends _mastra_core_storage.MemoryStorage
|
|
|
6884
6946
|
}, error);
|
|
6885
6947
|
this.logger?.error?.(mastraError.toString());
|
|
6886
6948
|
this.logger?.trackException?.(mastraError);
|
|
6887
|
-
|
|
6888
|
-
messages: [],
|
|
6889
|
-
total: 0,
|
|
6890
|
-
page,
|
|
6891
|
-
perPage: perPageForResponse,
|
|
6892
|
-
hasMore: false
|
|
6893
|
-
};
|
|
6949
|
+
throw mastraError;
|
|
6894
6950
|
}
|
|
6895
6951
|
}
|
|
6896
6952
|
async listMessagesByResourceId(args) {
|
|
6897
6953
|
const { resourceId, include, filter, perPage: perPageInput, page = 0, orderBy } = args;
|
|
6898
6954
|
if (!resourceId || typeof resourceId !== "string" || resourceId.trim().length === 0) throw new _mastra_core_error.MastraError({
|
|
6899
|
-
id: (0, _mastra_core_storage.createStorageErrorId)("LIBSQL", "
|
|
6955
|
+
id: (0, _mastra_core_storage.createStorageErrorId)("LIBSQL", "LIST_MESSAGES_BY_RESOURCE_ID", "INVALID_QUERY"),
|
|
6900
6956
|
domain: _mastra_core_error.ErrorDomain.STORAGE,
|
|
6901
6957
|
category: _mastra_core_error.ErrorCategory.USER,
|
|
6902
6958
|
details: { resourceId: resourceId ?? "" }
|
|
6903
6959
|
}, /* @__PURE__ */ new Error("resourceId is required"));
|
|
6904
6960
|
if (page < 0) throw new _mastra_core_error.MastraError({
|
|
6905
|
-
id: (0, _mastra_core_storage.createStorageErrorId)("LIBSQL", "
|
|
6961
|
+
id: (0, _mastra_core_storage.createStorageErrorId)("LIBSQL", "LIST_MESSAGES_BY_RESOURCE_ID", "INVALID_PAGE"),
|
|
6906
6962
|
domain: _mastra_core_error.ErrorDomain.STORAGE,
|
|
6907
6963
|
category: _mastra_core_error.ErrorCategory.USER,
|
|
6908
6964
|
details: { page }
|
|
@@ -6937,7 +6993,10 @@ var MemoryLibSQL = class MemoryLibSQL extends _mastra_core_storage.MemoryStorage
|
|
|
6937
6993
|
hasMore: false
|
|
6938
6994
|
};
|
|
6939
6995
|
if (perPage === 0 && include && include.length > 0) {
|
|
6940
|
-
const includeMessages = await this._getIncludedMessages({
|
|
6996
|
+
const includeMessages = await this._getIncludedMessages({
|
|
6997
|
+
include,
|
|
6998
|
+
resourceId
|
|
6999
|
+
});
|
|
6941
7000
|
if (!includeMessages || includeMessages.length === 0) return {
|
|
6942
7001
|
messages: [],
|
|
6943
7002
|
total: 0,
|
|
@@ -6977,7 +7036,10 @@ var MemoryLibSQL = class MemoryLibSQL extends _mastra_core_storage.MemoryStorage
|
|
|
6977
7036
|
};
|
|
6978
7037
|
const messageIds = new Set(messages.map((m) => m.id));
|
|
6979
7038
|
if (include && include.length > 0) {
|
|
6980
|
-
const includeMessages = await this._getIncludedMessages({
|
|
7039
|
+
const includeMessages = await this._getIncludedMessages({
|
|
7040
|
+
include,
|
|
7041
|
+
resourceId
|
|
7042
|
+
});
|
|
6981
7043
|
if (includeMessages) {
|
|
6982
7044
|
for (const includeMsg of includeMessages) if (!messageIds.has(includeMsg.id)) {
|
|
6983
7045
|
messages.push(includeMsg);
|
|
@@ -6994,21 +7056,16 @@ var MemoryLibSQL = class MemoryLibSQL extends _mastra_core_storage.MemoryStorage
|
|
|
6994
7056
|
hasMore: perPageInput !== false && offset + perPage < total
|
|
6995
7057
|
};
|
|
6996
7058
|
} catch (error) {
|
|
7059
|
+
if (error instanceof _mastra_core_error.MastraError && error.category === _mastra_core_error.ErrorCategory.USER) throw error;
|
|
6997
7060
|
const mastraError = new _mastra_core_error.MastraError({
|
|
6998
|
-
id: (0, _mastra_core_storage.createStorageErrorId)("LIBSQL", "
|
|
7061
|
+
id: (0, _mastra_core_storage.createStorageErrorId)("LIBSQL", "LIST_MESSAGES_BY_RESOURCE_ID", "FAILED"),
|
|
6999
7062
|
domain: _mastra_core_error.ErrorDomain.STORAGE,
|
|
7000
7063
|
category: _mastra_core_error.ErrorCategory.THIRD_PARTY,
|
|
7001
7064
|
details: { resourceId }
|
|
7002
7065
|
}, error);
|
|
7003
7066
|
this.logger?.error?.(mastraError.toString());
|
|
7004
7067
|
this.logger?.trackException?.(mastraError);
|
|
7005
|
-
|
|
7006
|
-
messages: [],
|
|
7007
|
-
total: 0,
|
|
7008
|
-
page,
|
|
7009
|
-
perPage: perPageForResponse,
|
|
7010
|
-
hasMore: false
|
|
7011
|
-
};
|
|
7068
|
+
throw mastraError;
|
|
7012
7069
|
}
|
|
7013
7070
|
}
|
|
7014
7071
|
async saveMessages({ messages }) {
|
|
@@ -7356,13 +7413,7 @@ var MemoryLibSQL = class MemoryLibSQL extends _mastra_core_storage.MemoryStorage
|
|
|
7356
7413
|
}, error);
|
|
7357
7414
|
this.logger?.trackException?.(mastraError);
|
|
7358
7415
|
this.logger?.error?.(mastraError.toString());
|
|
7359
|
-
|
|
7360
|
-
threads: [],
|
|
7361
|
-
total: 0,
|
|
7362
|
-
page,
|
|
7363
|
-
perPage: perPageForResponse,
|
|
7364
|
-
hasMore: false
|
|
7365
|
-
};
|
|
7416
|
+
throw mastraError;
|
|
7366
7417
|
}
|
|
7367
7418
|
}
|
|
7368
7419
|
async saveThread({ thread }) {
|