@mastra/pg 1.1.0-alpha.0 → 1.1.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 CHANGED
@@ -1,5 +1,30 @@
1
1
  # @mastra/pg
2
2
 
3
+ ## 1.1.0-alpha.1
4
+
5
+ ### Minor Changes
6
+
7
+ - Restructured stored agents to use a thin metadata record with versioned configuration snapshots. ([#12488](https://github.com/mastra-ai/mastra/pull/12488))
8
+
9
+ The agent record now only stores metadata fields (id, status, activeVersionId, authorId, metadata, timestamps). All configuration fields (name, instructions, model, tools, etc.) live exclusively in version snapshot rows, enabling full version history and rollback.
10
+
11
+ **Key changes:**
12
+ - Stored Agent records are now thin metadata-only (StorageAgentType)
13
+ - All config lives in version snapshots (StorageAgentSnapshotType)
14
+ - New resolved type (StorageResolvedAgentType) merges agent record + active version config
15
+ - Renamed `ownerId` to `authorId` for multi-tenant filtering
16
+ - Changed `memory` field type from `string` to `Record<string, unknown>`
17
+ - Added `status` field ('draft' | 'published') to agent records
18
+ - Flattened CreateAgent/UpdateAgent input types (config fields at top level, no nested snapshot)
19
+ - Version config columns are top-level in the agent_versions table (no single snapshot jsonb column)
20
+ - List endpoints return resolved agents (thin record + active version config)
21
+ - Auto-versioning on update with retention limits and race condition handling
22
+
23
+ ### Patch Changes
24
+
25
+ - Updated dependencies [[`b99ceac`](https://github.com/mastra-ai/mastra/commit/b99ceace2c830dbdef47c8692d56a91954aefea2), [`deea43e`](https://github.com/mastra-ai/mastra/commit/deea43eb1366d03a864c5e597d16a48592b9893f), [`ac9ec66`](https://github.com/mastra-ai/mastra/commit/ac9ec6672779b2e6d4344e415481d1a6a7d4911a)]:
26
+ - @mastra/core@1.1.0-alpha.1
27
+
3
28
  ## 1.1.0-alpha.0
4
29
 
5
30
  ### Minor Changes
@@ -33,4 +33,4 @@ docs/
33
33
  ## Version
34
34
 
35
35
  Package: @mastra/pg
36
- Version: 1.1.0-alpha.0
36
+ Version: 1.1.0-alpha.1
@@ -5,7 +5,7 @@ description: Documentation for @mastra/pg. Includes links to type definitions an
5
5
 
6
6
  # @mastra/pg Documentation
7
7
 
8
- > **Version**: 1.1.0-alpha.0
8
+ > **Version**: 1.1.0-alpha.1
9
9
  > **Package**: @mastra/pg
10
10
 
11
11
  ## Quick Navigation
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.1.0-alpha.0",
2
+ "version": "1.1.0-alpha.1",
3
3
  "package": "@mastra/pg",
4
4
  "exports": {},
5
5
  "modules": {}
package/dist/index.cjs CHANGED
@@ -3194,22 +3194,10 @@ var AgentsPG = class _AgentsPG extends storage.AgentsStorage {
3194
3194
  parseRow(row) {
3195
3195
  return {
3196
3196
  id: row.id,
3197
- name: row.name,
3198
- description: row.description,
3199
- instructions: row.instructions,
3200
- model: this.parseJson(row.model, "model"),
3201
- tools: this.parseJson(row.tools, "tools"),
3202
- defaultOptions: this.parseJson(row.defaultOptions, "defaultOptions"),
3203
- workflows: this.parseJson(row.workflows, "workflows"),
3204
- agents: this.parseJson(row.agents, "agents"),
3205
- integrationTools: this.parseJson(row.integrationTools, "integrationTools"),
3206
- inputProcessors: this.parseJson(row.inputProcessors, "inputProcessors"),
3207
- outputProcessors: this.parseJson(row.outputProcessors, "outputProcessors"),
3208
- memory: this.parseJson(row.memory, "memory"),
3209
- scorers: this.parseJson(row.scorers, "scorers"),
3210
- metadata: this.parseJson(row.metadata, "metadata"),
3211
- ownerId: row.ownerId,
3197
+ status: row.status,
3212
3198
  activeVersionId: row.activeVersionId,
3199
+ authorId: row.authorId,
3200
+ metadata: this.parseJson(row.metadata, "metadata"),
3213
3201
  createdAt: row.createdAtZ || row.createdAt,
3214
3202
  updatedAt: row.updatedAtZ || row.updatedAt
3215
3203
  };
@@ -3236,43 +3224,48 @@ var AgentsPG = class _AgentsPG extends storage.AgentsStorage {
3236
3224
  }
3237
3225
  async createAgent({ agent }) {
3238
3226
  try {
3239
- const tableName = getTableName2({ indexName: storage.TABLE_AGENTS, schemaName: getSchemaName2(this.#schema) });
3227
+ const agentsTable = getTableName2({ indexName: storage.TABLE_AGENTS, schemaName: getSchemaName2(this.#schema) });
3240
3228
  const now = /* @__PURE__ */ new Date();
3241
3229
  const nowIso = now.toISOString();
3242
3230
  await this.#db.client.none(
3243
- `INSERT INTO ${tableName} (
3244
- id, name, description, instructions, model, tools,
3245
- "defaultOptions", workflows, agents, "integrationTools",
3246
- "inputProcessors", "outputProcessors", memory, scorers, metadata,
3247
- "ownerId", "activeVersionId",
3231
+ `INSERT INTO ${agentsTable} (
3232
+ id, status, "authorId", metadata,
3233
+ "activeVersionId",
3248
3234
  "createdAt", "createdAtZ", "updatedAt", "updatedAtZ"
3249
- ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21)`,
3235
+ ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)`,
3250
3236
  [
3251
3237
  agent.id,
3252
- agent.name,
3253
- agent.description ?? null,
3254
- agent.instructions,
3255
- JSON.stringify(agent.model),
3256
- agent.tools ? JSON.stringify(agent.tools) : null,
3257
- agent.defaultOptions ? JSON.stringify(agent.defaultOptions) : null,
3258
- agent.workflows ? JSON.stringify(agent.workflows) : null,
3259
- agent.agents ? JSON.stringify(agent.agents) : null,
3260
- agent.integrationTools ? JSON.stringify(agent.integrationTools) : null,
3261
- agent.inputProcessors ? JSON.stringify(agent.inputProcessors) : null,
3262
- agent.outputProcessors ? JSON.stringify(agent.outputProcessors) : null,
3263
- agent.memory ? JSON.stringify(agent.memory) : null,
3264
- agent.scorers ? JSON.stringify(agent.scorers) : null,
3238
+ "draft",
3239
+ agent.authorId ?? null,
3265
3240
  agent.metadata ? JSON.stringify(agent.metadata) : null,
3266
- agent.ownerId ?? null,
3267
- agent.activeVersionId ?? null,
3241
+ null,
3242
+ // activeVersionId starts as null
3268
3243
  nowIso,
3269
3244
  nowIso,
3270
3245
  nowIso,
3271
3246
  nowIso
3272
3247
  ]
3273
3248
  );
3249
+ const { id: _id, authorId: _authorId, metadata: _metadata, ...snapshotConfig } = agent;
3250
+ const versionId = crypto.randomUUID();
3251
+ await this.createVersion({
3252
+ id: versionId,
3253
+ agentId: agent.id,
3254
+ versionNumber: 1,
3255
+ ...snapshotConfig,
3256
+ changedFields: Object.keys(snapshotConfig),
3257
+ changeMessage: "Initial version"
3258
+ });
3259
+ await this.#db.client.none(
3260
+ `UPDATE ${agentsTable} SET "activeVersionId" = $1, status = $2, "updatedAt" = $3, "updatedAtZ" = $4 WHERE id = $5`,
3261
+ [versionId, "published", nowIso, nowIso, agent.id]
3262
+ );
3274
3263
  return {
3275
- ...agent,
3264
+ id: agent.id,
3265
+ status: "published",
3266
+ activeVersionId: versionId,
3267
+ authorId: agent.authorId,
3268
+ metadata: agent.metadata,
3276
3269
  createdAt: now,
3277
3270
  updatedAt: now
3278
3271
  };
@@ -3304,65 +3297,15 @@ var AgentsPG = class _AgentsPG extends storage.AgentsStorage {
3304
3297
  const setClauses = [];
3305
3298
  const values = [];
3306
3299
  let paramIndex = 1;
3307
- if (updates.name !== void 0) {
3308
- setClauses.push(`name = $${paramIndex++}`);
3309
- values.push(updates.name);
3310
- }
3311
- if (updates.description !== void 0) {
3312
- setClauses.push(`description = $${paramIndex++}`);
3313
- values.push(updates.description);
3314
- }
3315
- if (updates.instructions !== void 0) {
3316
- setClauses.push(`instructions = $${paramIndex++}`);
3317
- values.push(updates.instructions);
3318
- }
3319
- if (updates.model !== void 0) {
3320
- setClauses.push(`model = $${paramIndex++}`);
3321
- values.push(JSON.stringify(updates.model));
3322
- }
3323
- if (updates.tools !== void 0) {
3324
- setClauses.push(`tools = $${paramIndex++}`);
3325
- values.push(JSON.stringify(updates.tools));
3326
- }
3327
- if (updates.defaultOptions !== void 0) {
3328
- setClauses.push(`"defaultOptions" = $${paramIndex++}`);
3329
- values.push(JSON.stringify(updates.defaultOptions));
3330
- }
3331
- if (updates.workflows !== void 0) {
3332
- setClauses.push(`workflows = $${paramIndex++}`);
3333
- values.push(JSON.stringify(updates.workflows));
3334
- }
3335
- if (updates.agents !== void 0) {
3336
- setClauses.push(`agents = $${paramIndex++}`);
3337
- values.push(JSON.stringify(updates.agents));
3338
- }
3339
- if (updates.inputProcessors !== void 0) {
3340
- setClauses.push(`"inputProcessors" = $${paramIndex++}`);
3341
- values.push(JSON.stringify(updates.inputProcessors));
3342
- }
3343
- if (updates.outputProcessors !== void 0) {
3344
- setClauses.push(`"outputProcessors" = $${paramIndex++}`);
3345
- values.push(JSON.stringify(updates.outputProcessors));
3346
- }
3347
- if (updates.memory !== void 0) {
3348
- setClauses.push(`memory = $${paramIndex++}`);
3349
- values.push(JSON.stringify(updates.memory));
3350
- }
3351
- if (updates.scorers !== void 0) {
3352
- setClauses.push(`scorers = $${paramIndex++}`);
3353
- values.push(JSON.stringify(updates.scorers));
3354
- }
3355
- if (updates.integrationTools !== void 0) {
3356
- setClauses.push(`"integrationTools" = $${paramIndex++}`);
3357
- values.push(JSON.stringify(updates.integrationTools));
3358
- }
3359
- if (updates.ownerId !== void 0) {
3360
- setClauses.push(`"ownerId" = $${paramIndex++}`);
3361
- values.push(updates.ownerId);
3300
+ if (updates.authorId !== void 0) {
3301
+ setClauses.push(`"authorId" = $${paramIndex++}`);
3302
+ values.push(updates.authorId);
3362
3303
  }
3363
3304
  if (updates.activeVersionId !== void 0) {
3364
3305
  setClauses.push(`"activeVersionId" = $${paramIndex++}`);
3365
3306
  values.push(updates.activeVersionId);
3307
+ setClauses.push(`status = $${paramIndex++}`);
3308
+ values.push("published");
3366
3309
  }
3367
3310
  if (updates.metadata !== void 0) {
3368
3311
  const mergedMetadata = { ...existingAgent.metadata, ...updates.metadata };
@@ -3487,14 +3430,30 @@ var AgentsPG = class _AgentsPG extends storage.AgentsStorage {
3487
3430
  const nowIso = now.toISOString();
3488
3431
  await this.#db.client.none(
3489
3432
  `INSERT INTO ${tableName} (
3490
- id, "agentId", "versionNumber", name, snapshot, "changedFields", "changeMessage", "createdAt", "createdAtZ"
3491
- ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)`,
3433
+ id, "agentId", "versionNumber",
3434
+ name, description, instructions, model, tools,
3435
+ "defaultOptions", workflows, agents, "integrationTools",
3436
+ "inputProcessors", "outputProcessors", memory, scorers,
3437
+ "changedFields", "changeMessage",
3438
+ "createdAt", "createdAtZ"
3439
+ ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20)`,
3492
3440
  [
3493
3441
  input.id,
3494
3442
  input.agentId,
3495
3443
  input.versionNumber,
3496
- input.name ?? null,
3497
- JSON.stringify(input.snapshot),
3444
+ input.name,
3445
+ input.description ?? null,
3446
+ input.instructions,
3447
+ JSON.stringify(input.model),
3448
+ input.tools ? JSON.stringify(input.tools) : null,
3449
+ input.defaultOptions ? JSON.stringify(input.defaultOptions) : null,
3450
+ input.workflows ? JSON.stringify(input.workflows) : null,
3451
+ input.agents ? JSON.stringify(input.agents) : null,
3452
+ input.integrationTools ? JSON.stringify(input.integrationTools) : null,
3453
+ input.inputProcessors ? JSON.stringify(input.inputProcessors) : null,
3454
+ input.outputProcessors ? JSON.stringify(input.outputProcessors) : null,
3455
+ input.memory ? JSON.stringify(input.memory) : null,
3456
+ input.scorers ? JSON.stringify(input.scorers) : null,
3498
3457
  input.changedFields ? JSON.stringify(input.changedFields) : null,
3499
3458
  input.changeMessage ?? null,
3500
3459
  nowIso,
@@ -3699,7 +3658,18 @@ var AgentsPG = class _AgentsPG extends storage.AgentsStorage {
3699
3658
  agentId: row.agentId,
3700
3659
  versionNumber: row.versionNumber,
3701
3660
  name: row.name,
3702
- snapshot: this.parseJson(row.snapshot, "snapshot"),
3661
+ description: row.description,
3662
+ instructions: row.instructions,
3663
+ model: this.parseJson(row.model, "model"),
3664
+ tools: this.parseJson(row.tools, "tools"),
3665
+ defaultOptions: this.parseJson(row.defaultOptions, "defaultOptions"),
3666
+ workflows: this.parseJson(row.workflows, "workflows"),
3667
+ agents: this.parseJson(row.agents, "agents"),
3668
+ integrationTools: this.parseJson(row.integrationTools, "integrationTools"),
3669
+ inputProcessors: this.parseJson(row.inputProcessors, "inputProcessors"),
3670
+ outputProcessors: this.parseJson(row.outputProcessors, "outputProcessors"),
3671
+ memory: this.parseJson(row.memory, "memory"),
3672
+ scorers: this.parseJson(row.scorers, "scorers"),
3703
3673
  changedFields: this.parseJson(row.changedFields, "changedFields"),
3704
3674
  changeMessage: row.changeMessage,
3705
3675
  createdAt: row.createdAtZ || row.createdAt