@mastra/pg 1.17.0-alpha.4 → 1.17.1-alpha.0
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 +73 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/reference-memory-memory-class.md +1 -1
- package/dist/index.cjs +23 -37
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +25 -38
- package/dist/index.js.map +1 -1
- package/dist/shared/config.d.ts.map +1 -1
- package/dist/storage/factory-storage.d.ts +5 -16
- package/dist/storage/factory-storage.d.ts.map +1 -1
- package/dist/storage/index.d.ts +1 -1
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +7 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,78 @@
|
|
|
1
1
|
# @mastra/pg
|
|
2
2
|
|
|
3
|
+
## 1.17.1-alpha.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Improved Factory work-item concurrency by replacing distributed advisory locks with atomic claims, idempotent replay, and serializable relationship transactions. ([#20135](https://github.com/mastra-ai/mastra/pull/20135))
|
|
8
|
+
|
|
9
|
+
- Hardened distributed lock cleanup so clients are destroyed when transaction rollback fails. ([#20135](https://github.com/mastra-ai/mastra/pull/20135))
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [[`73839cb`](https://github.com/mastra-ai/mastra/commit/73839cb58322679c170627d1015669ede5f619aa), [`8e4dc79`](https://github.com/mastra-ai/mastra/commit/8e4dc793dcf035ea506f9ce79f56d2d501a4be14), [`2db93cc`](https://github.com/mastra-ai/mastra/commit/2db93ccd0b872e4de7853a93383efe0647901df8), [`094ab61`](https://github.com/mastra-ai/mastra/commit/094ab6129a1a3ecf6eeb86decac17d5faea4e02a), [`fe80944`](https://github.com/mastra-ai/mastra/commit/fe80944f3ef6681fea6eae8200fce387b7bb3c2f), [`e51e166`](https://github.com/mastra-ai/mastra/commit/e51e166c52e220abc9b64554ce37359dca8544b1)]:
|
|
12
|
+
- @mastra/core@1.53.0-alpha.4
|
|
13
|
+
|
|
14
|
+
## 1.17.0
|
|
15
|
+
|
|
16
|
+
### Minor Changes
|
|
17
|
+
|
|
18
|
+
- Added PgFactoryStorage for persisting Mastra agent state and lifecycle-managed application domains through one PostgreSQL pool. ([#19681](https://github.com/mastra-ai/mastra/pull/19681))
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { PgFactoryStorage } from '@mastra/pg';
|
|
22
|
+
|
|
23
|
+
const storage = new PgFactoryStorage({ connectionString: process.env.DATABASE_URL! });
|
|
24
|
+
await storage.init();
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Patch Changes
|
|
28
|
+
|
|
29
|
+
- Fixed a missing semicolon in the SQL generated by exportSchemas(). The CREATE INDEX statement for the favorites table ran into the next CREATE TABLE statement, so applying the exported schema as a single query (for example with pg's client.query() or a Supabase migration) failed with a Postgres syntax error. Fixes https://github.com/mastra-ai/mastra/issues/19942 ([#19944](https://github.com/mastra-ai/mastra/pull/19944))
|
|
30
|
+
|
|
31
|
+
- Replaced GitHub-specific Mastra Code session state with Factory project and linked-repository identities. This lets SDK consumers represent sessions independently of a source-control provider and select a repository explicitly when sandbox execution is required. ([#19849](https://github.com/mastra-ai/mastra/pull/19849))
|
|
32
|
+
|
|
33
|
+
Updated Mastra Code onboarding to be Factory-first: create a Factory by name, then link repositories from your connected source-control installations in a separate step. A Factory is valid with zero linked repositories, and the Board, Metrics, and Audit pages stay available for any server-backed Factory. Factory pages keep project-scoped data separate from repository-scoped intake and provide a repository selector when a Factory has multiple linked repositories. Creating a Factory from a local folder remains available as a secondary option.
|
|
34
|
+
|
|
35
|
+
**Before**
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
const state = { githubProjectId: 'project-1', sandboxId, sandboxWorkdir };
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
**After**
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
const state = {
|
|
45
|
+
factoryProjectId: 'factory-project-1',
|
|
46
|
+
projectRepositoryId: 'project-repository-1',
|
|
47
|
+
sandboxId,
|
|
48
|
+
sandboxWorkdir,
|
|
49
|
+
};
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
- Fixed an issue where the process could crash when Postgres drops an idle database connection (e.g., due to a backend restart, failover, or network failure). ([#19469](https://github.com/mastra-ai/mastra/pull/19469))
|
|
53
|
+
|
|
54
|
+
Previously, a dropped idle connection caused an uncaught exception that terminated the process. Now the connection drop is caught and logged as a warning, and the store automatically reconnects on the next database operation.
|
|
55
|
+
|
|
56
|
+
User-provided connection pools are unaffected and keep their existing error handling.
|
|
57
|
+
|
|
58
|
+
- Fix factory storage error classification and schema drift handling. ([#20002](https://github.com/mastra-ai/mastra/pull/20002))
|
|
59
|
+
|
|
60
|
+
- `isUniqueViolation` in the LibSQL factory storage now only matches real unique-index violations (`SQLITE_CONSTRAINT_UNIQUE` / `SQLITE_CONSTRAINT_PRIMARYKEY`). Previously any `SQLITE_CONSTRAINT` failure — including NOT NULL violations — was reported as a "Unique constraint violation", which masked the real error (seen as `Unique constraint violation on collection 'factory_rule_evaluations'` when polled ingestion inserted nullable columns into a stale table).
|
|
61
|
+
- `ensureCollections` in both the LibSQL and Postgres factory storage adapters now relaxes stale NOT NULL constraints when a column becomes nullable in the schema. Postgres uses `ALTER COLUMN ... DROP NOT NULL`; LibSQL rebuilds the table in place since SQLite cannot drop NOT NULL directly. Existing rows and unique indexes are preserved.
|
|
62
|
+
|
|
63
|
+
- Added stable metrics and logs capability reporting for observability storage. The system packages response now includes `observabilityStorageCapabilities` with `metrics` and `logs` flags, enabling capability-based detection that is resilient to bundler-generated constructor name changes. ([#19305](https://github.com/mastra-ai/mastra/pull/19305))
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
const packages = await client.getSystemPackages();
|
|
67
|
+
console.log(packages.observabilityStorageCapabilities?.metrics); // true
|
|
68
|
+
console.log(packages.observabilityStorageCapabilities?.logs); // true
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Studio now uses the capability response instead of relying on constructor names, with a fallback for older servers.
|
|
72
|
+
|
|
73
|
+
- Updated dependencies [[`ec857fc`](https://github.com/mastra-ai/mastra/commit/ec857fc79c264b53b38e16478c789b7177f2ad59), [`d7385ad`](https://github.com/mastra-ai/mastra/commit/d7385ad9e88f9e4f33d15c0ec0bfebedde0cbc2e), [`41a5392`](https://github.com/mastra-ai/mastra/commit/41a5392d9f6c5e18d6b227f0fc0ddf49c50774e9), [`3d6e539`](https://github.com/mastra-ai/mastra/commit/3d6e539272eb2ea0407034605ee1906b3be06b39), [`1426af2`](https://github.com/mastra-ai/mastra/commit/1426af24975879c000d13ac75673f630fcc970c1), [`a40adeb`](https://github.com/mastra-ai/mastra/commit/a40adeb222b961a56a58af56a106106525721b74), [`8a0d145`](https://github.com/mastra-ai/mastra/commit/8a0d145aadbdf7278665aceaaec364b35dd9bd94), [`bd2f1d2`](https://github.com/mastra-ai/mastra/commit/bd2f1d274d05e60e2366f005ea0d94d5cea0d5ff), [`e1f2fae`](https://github.com/mastra-ai/mastra/commit/e1f2faebaf048c3d4c2e2c01d293767c195d5794), [`63aa799`](https://github.com/mastra-ai/mastra/commit/63aa799c6b44eacc7806cda6846b7c5bbee06b37), [`b7e79c3`](https://github.com/mastra-ai/mastra/commit/b7e79c3c02ac5cd415db34ba0975ceafc1464333), [`675fbff`](https://github.com/mastra-ai/mastra/commit/675fbff84d3274391b33e852f76083c38a5514e5), [`da009e1`](https://github.com/mastra-ai/mastra/commit/da009e1aacd89ed94b8d1b2af09c9d4fe7c4db49), [`3b77e77`](https://github.com/mastra-ai/mastra/commit/3b77e7704936522e4769d29de1b5ea6901f302bd), [`c7d30cd`](https://github.com/mastra-ai/mastra/commit/c7d30cd86009c407df91105591f03cd6e3d2854d), [`21a0eb8`](https://github.com/mastra-ai/mastra/commit/21a0eb86746ba0b703acea360d4f84c6a5a493f2), [`8b20926`](https://github.com/mastra-ai/mastra/commit/8b20926cd59e2ba3d66458e062fa0e6e2ada3e68), [`975295d`](https://github.com/mastra-ai/mastra/commit/975295d418552f0d46a59edfef4c3ee555f9930a), [`73db8db`](https://github.com/mastra-ai/mastra/commit/73db8db90d69ab6153c7942749f624db0d96952d), [`6b1bf3b`](https://github.com/mastra-ai/mastra/commit/6b1bf3b9494bd51aa8f654c68c9355d6046fa2a1), [`35c2181`](https://github.com/mastra-ai/mastra/commit/35c2181e6a50e47c90ba36260db7c9723d54696f), [`0a2c22c`](https://github.com/mastra-ai/mastra/commit/0a2c22c902604439ec490319e14c17f331e0c84c), [`4cfdd64`](https://github.com/mastra-ai/mastra/commit/4cfdd645794feaea0c4ea711e70ecdfbef0c5b8e), [`b75d749`](https://github.com/mastra-ai/mastra/commit/b75d749621ff5d17e86bcb4ee809d301fb4f7cf3), [`821648b`](https://github.com/mastra-ai/mastra/commit/821648bf2871ef840100c7bacbecf676010bd12a), [`de86fd7`](https://github.com/mastra-ai/mastra/commit/de86fd7119f0438381d1a642e3d258143c0b9c29), [`2745031`](https://github.com/mastra-ai/mastra/commit/2745031d1d4a4978f037092da371428c32e2842a), [`b4b7ea8`](https://github.com/mastra-ai/mastra/commit/b4b7ea8733f033fc441ea47ed03f6afb17ec2248), [`3a8024c`](https://github.com/mastra-ai/mastra/commit/3a8024ce615f8aa89479c0d71fe61d10bb0040be), [`35865a5`](https://github.com/mastra-ai/mastra/commit/35865a53e194aa9634d6a70a97010e7a6b9d58b1), [`74faf8b`](https://github.com/mastra-ai/mastra/commit/74faf8bd9c1018f2492653c06b1e25fc8300e9e6), [`ef03fbc`](https://github.com/mastra-ai/mastra/commit/ef03fbcc556bcbc04c9b3d06fab88771ecaa043c), [`675fbff`](https://github.com/mastra-ai/mastra/commit/675fbff84d3274391b33e852f76083c38a5514e5), [`70687f7`](https://github.com/mastra-ai/mastra/commit/70687f7e495a322a02070b4a67cb0c77a5ca91ec), [`1fadac4`](https://github.com/mastra-ai/mastra/commit/1fadac44537caeefe81f9f775ae2f2f3d94e9069), [`73db8db`](https://github.com/mastra-ai/mastra/commit/73db8db90d69ab6153c7942749f624db0d96952d), [`76b7181`](https://github.com/mastra-ai/mastra/commit/76b71810366e6d90b9d3973149d1c7ba3659ffb9), [`792ec9a`](https://github.com/mastra-ai/mastra/commit/792ec9a0869bab8274cf5e0ed2840738737a1607), [`712b864`](https://github.com/mastra-ai/mastra/commit/712b864aa1ed12b14c54390ec17b69de163c37f7), [`85e4fb5`](https://github.com/mastra-ai/mastra/commit/85e4fb50087a81c74df3a762f53b56373db0b912), [`0c0e8d7`](https://github.com/mastra-ai/mastra/commit/0c0e8d7becd4d1445c656b78d5d845f606c1ff9d), [`a7bbe77`](https://github.com/mastra-ai/mastra/commit/a7bbe773577f60bc4761b534ef7ec6b476332dad), [`72e437c`](https://github.com/mastra-ai/mastra/commit/72e437c515942c80b9def5b026e0bdee61b469d9), [`8f7a5de`](https://github.com/mastra-ai/mastra/commit/8f7a5dedc246cdc938bb65516703cf9b27b03756), [`a7bbe77`](https://github.com/mastra-ai/mastra/commit/a7bbe773577f60bc4761b534ef7ec6b476332dad), [`11f6cd9`](https://github.com/mastra-ai/mastra/commit/11f6cd96fe42582403416608beb212cc1a2cc79e), [`ef03c0c`](https://github.com/mastra-ai/mastra/commit/ef03c0cfc62367a458e4cc56462e2148b35681c5), [`4fb4d88`](https://github.com/mastra-ai/mastra/commit/4fb4d881bc107acee13890ad4d78661016c510ed), [`4e68363`](https://github.com/mastra-ai/mastra/commit/4e683634f94ebd062d26a3bb6093a8dfc7263d37), [`c328769`](https://github.com/mastra-ai/mastra/commit/c3287698ff8ef98dba86d415faa566fa3e5f4d56), [`9f7c67a`](https://github.com/mastra-ai/mastra/commit/9f7c67abeeb52c41c51a9b5edee60b62afe7cd8d), [`3b65e68`](https://github.com/mastra-ai/mastra/commit/3b65e68d7f1c771c7a70eea42d83fefdd28cad88), [`4eba27a`](https://github.com/mastra-ai/mastra/commit/4eba27adcf60f991df0e62f94b3e75b4e67f3b4b), [`c701be3`](https://github.com/mastra-ai/mastra/commit/c701be32d7d9aa94a66da8c6cc38dcac6856f464), [`db650ce`](https://github.com/mastra-ai/mastra/commit/db650ce490348914e85b93651d83acdf8f2a4c31), [`232fcbc`](https://github.com/mastra-ai/mastra/commit/232fcbc14fce625dd672ba043329c0b732c62be2), [`6354eeb`](https://github.com/mastra-ai/mastra/commit/6354eeb32efa9f5f68f51dda394e90e2ee76f1fb), [`a8799bb`](https://github.com/mastra-ai/mastra/commit/a8799bb8e44f4a60d01e4e2acd3448ff80bf14f8), [`3d6e539`](https://github.com/mastra-ai/mastra/commit/3d6e539272eb2ea0407034605ee1906b3be06b39), [`e3868e2`](https://github.com/mastra-ai/mastra/commit/e3868e22babfffd0133771669ca724501c2dd58e), [`9251370`](https://github.com/mastra-ai/mastra/commit/9251370ad413af464aa22d7566338bec5613e8de), [`3491666`](https://github.com/mastra-ai/mastra/commit/34916663c4fdd43b48c21f4ab2d5fb6dcccc94f9), [`c0bec73`](https://github.com/mastra-ai/mastra/commit/c0bec732c93d1a22ae5e51ed66cf8cacca8bd6a6)]:
|
|
74
|
+
- @mastra/core@1.52.0
|
|
75
|
+
|
|
3
76
|
## 1.17.0-alpha.4
|
|
4
77
|
|
|
5
78
|
### Patch Changes
|
package/dist/docs/SKILL.md
CHANGED
|
@@ -47,7 +47,7 @@ export const agent = new Agent({
|
|
|
47
47
|
|
|
48
48
|
**options.observationalMemory** (`boolean | ObservationalMemoryOptions`): Enable Observational Memory for long-context agentic memory. Set to true for defaults, or pass a config object to customize token budgets, models, and scope. See Observational Memory reference for configuration details.
|
|
49
49
|
|
|
50
|
-
**options.generateTitle** (`boolean | { model: DynamicArgument<MastraLanguageModel>; instructions?: DynamicArgument<string> }`): Controls automatic thread title generation from the
|
|
50
|
+
**options.generateTitle** (`boolean | { model: DynamicArgument<MastraLanguageModel>; instructions?: DynamicArgument<string> }`): Controls automatic thread title generation from the conversation transcript. Can be a boolean or an object with custom model and instructions.
|
|
51
51
|
|
|
52
52
|
## Returns
|
|
53
53
|
|
package/dist/index.cjs
CHANGED
|
@@ -20250,10 +20250,6 @@ function serializeDefault(value) {
|
|
|
20250
20250
|
if (typeof value === "string") return `'${value.replace(/'/g, "''")}'`;
|
|
20251
20251
|
return String(value);
|
|
20252
20252
|
}
|
|
20253
|
-
function hashAdvisoryLockKey(key) {
|
|
20254
|
-
const digest = crypto$1.createHash("sha256").update(key).digest();
|
|
20255
|
-
return [digest.readInt32BE(0), digest.readInt32BE(4)];
|
|
20256
|
-
}
|
|
20257
20253
|
var PgFactoryStorageOps = class {
|
|
20258
20254
|
#queryable;
|
|
20259
20255
|
#transactionClient;
|
|
@@ -20548,21 +20544,36 @@ var PgFactoryStorage = class extends storage.FactoryStorage {
|
|
|
20548
20544
|
async initStorage() {
|
|
20549
20545
|
await this.#pool.query("SELECT 1");
|
|
20550
20546
|
}
|
|
20551
|
-
async withTransaction(fn) {
|
|
20552
|
-
const
|
|
20553
|
-
|
|
20554
|
-
await
|
|
20547
|
+
async withTransaction(fn, options) {
|
|
20548
|
+
const maxAttempts = options?.isolationLevel === "serializable" ? 3 : 1;
|
|
20549
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
20550
|
+
const client = await this.#pool.connect();
|
|
20551
|
+
let transactionOpen = false;
|
|
20552
|
+
let releaseError;
|
|
20555
20553
|
try {
|
|
20554
|
+
await client.query(options?.isolationLevel === "serializable" ? "BEGIN ISOLATION LEVEL SERIALIZABLE" : "BEGIN");
|
|
20555
|
+
transactionOpen = true;
|
|
20556
20556
|
const result = await fn(new PgFactoryStorageOps(client, this.#schemas, client));
|
|
20557
20557
|
await client.query("COMMIT");
|
|
20558
|
+
transactionOpen = false;
|
|
20558
20559
|
return result;
|
|
20559
20560
|
} catch (error) {
|
|
20560
|
-
|
|
20561
|
-
|
|
20561
|
+
if (transactionOpen) {
|
|
20562
|
+
try {
|
|
20563
|
+
await client.query("ROLLBACK");
|
|
20564
|
+
transactionOpen = false;
|
|
20565
|
+
} catch (rollbackError) {
|
|
20566
|
+
releaseError = rollbackError instanceof Error ? rollbackError : new Error(String(rollbackError));
|
|
20567
|
+
throw new AggregateError([error, rollbackError], "Factory transaction and rollback both failed");
|
|
20568
|
+
}
|
|
20569
|
+
}
|
|
20570
|
+
const serializationFailure = typeof error === "object" && error !== null && error.code === "40001";
|
|
20571
|
+
if (!serializationFailure || attempt === maxAttempts) throw error;
|
|
20572
|
+
} finally {
|
|
20573
|
+
client.release(releaseError);
|
|
20562
20574
|
}
|
|
20563
|
-
} finally {
|
|
20564
|
-
client.release();
|
|
20565
20575
|
}
|
|
20576
|
+
throw new Error("PgFactoryStorage: serializable transaction retry limit exceeded");
|
|
20566
20577
|
}
|
|
20567
20578
|
async ensureCollections(schemas) {
|
|
20568
20579
|
for (const schema of schemas) {
|
|
@@ -20580,30 +20591,6 @@ var PgFactoryStorage = class extends storage.FactoryStorage {
|
|
|
20580
20591
|
authDatabase() {
|
|
20581
20592
|
return { dialect: "postgres", pool: this.#pool };
|
|
20582
20593
|
}
|
|
20583
|
-
/**
|
|
20584
|
-
* Run `fn` while holding a Postgres transaction-scoped advisory lock for
|
|
20585
|
-
* `key`, serializing callers across replicas. The lock releases when the
|
|
20586
|
-
* transaction ends (commit, rollback, or connection loss), so a crashed
|
|
20587
|
-
* replica can never hold it forever.
|
|
20588
|
-
*/
|
|
20589
|
-
async withDistributedLock(key, fn) {
|
|
20590
|
-
const [k1, k2] = hashAdvisoryLockKey(key);
|
|
20591
|
-
const client = await this.#pool.connect();
|
|
20592
|
-
try {
|
|
20593
|
-
await client.query("BEGIN");
|
|
20594
|
-
await client.query("SELECT pg_advisory_xact_lock($1, $2)", [k1, k2]);
|
|
20595
|
-
try {
|
|
20596
|
-
const result = await fn();
|
|
20597
|
-
await client.query("COMMIT");
|
|
20598
|
-
return result;
|
|
20599
|
-
} catch (error) {
|
|
20600
|
-
await client.query("ROLLBACK");
|
|
20601
|
-
throw error;
|
|
20602
|
-
}
|
|
20603
|
-
} finally {
|
|
20604
|
-
client.release();
|
|
20605
|
-
}
|
|
20606
|
-
}
|
|
20607
20594
|
#columnDdl(name, spec) {
|
|
20608
20595
|
assertIdentifier("column", name);
|
|
20609
20596
|
let ddl = `"${name}" ${COLUMN_DDL[spec.type]}`;
|
|
@@ -21067,6 +21054,5 @@ exports.ToolProviderConnectionsPG = ToolProviderConnectionsPG;
|
|
|
21067
21054
|
exports.WorkflowsPG = WorkflowsPG;
|
|
21068
21055
|
exports.WorkspacesPG = WorkspacesPG;
|
|
21069
21056
|
exports.exportSchemas = exportSchemas;
|
|
21070
|
-
exports.hashAdvisoryLockKey = hashAdvisoryLockKey;
|
|
21071
21057
|
//# sourceMappingURL=index.cjs.map
|
|
21072
21058
|
//# sourceMappingURL=index.cjs.map
|