@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/dist/index.js CHANGED
@@ -3170,22 +3170,10 @@ var AgentsPG = class _AgentsPG extends AgentsStorage {
3170
3170
  parseRow(row) {
3171
3171
  return {
3172
3172
  id: row.id,
3173
- name: row.name,
3174
- description: row.description,
3175
- instructions: row.instructions,
3176
- model: this.parseJson(row.model, "model"),
3177
- tools: this.parseJson(row.tools, "tools"),
3178
- defaultOptions: this.parseJson(row.defaultOptions, "defaultOptions"),
3179
- workflows: this.parseJson(row.workflows, "workflows"),
3180
- agents: this.parseJson(row.agents, "agents"),
3181
- integrationTools: this.parseJson(row.integrationTools, "integrationTools"),
3182
- inputProcessors: this.parseJson(row.inputProcessors, "inputProcessors"),
3183
- outputProcessors: this.parseJson(row.outputProcessors, "outputProcessors"),
3184
- memory: this.parseJson(row.memory, "memory"),
3185
- scorers: this.parseJson(row.scorers, "scorers"),
3186
- metadata: this.parseJson(row.metadata, "metadata"),
3187
- ownerId: row.ownerId,
3173
+ status: row.status,
3188
3174
  activeVersionId: row.activeVersionId,
3175
+ authorId: row.authorId,
3176
+ metadata: this.parseJson(row.metadata, "metadata"),
3189
3177
  createdAt: row.createdAtZ || row.createdAt,
3190
3178
  updatedAt: row.updatedAtZ || row.updatedAt
3191
3179
  };
@@ -3212,43 +3200,48 @@ var AgentsPG = class _AgentsPG extends AgentsStorage {
3212
3200
  }
3213
3201
  async createAgent({ agent }) {
3214
3202
  try {
3215
- const tableName = getTableName2({ indexName: TABLE_AGENTS, schemaName: getSchemaName2(this.#schema) });
3203
+ const agentsTable = getTableName2({ indexName: TABLE_AGENTS, schemaName: getSchemaName2(this.#schema) });
3216
3204
  const now = /* @__PURE__ */ new Date();
3217
3205
  const nowIso = now.toISOString();
3218
3206
  await this.#db.client.none(
3219
- `INSERT INTO ${tableName} (
3220
- id, name, description, instructions, model, tools,
3221
- "defaultOptions", workflows, agents, "integrationTools",
3222
- "inputProcessors", "outputProcessors", memory, scorers, metadata,
3223
- "ownerId", "activeVersionId",
3207
+ `INSERT INTO ${agentsTable} (
3208
+ id, status, "authorId", metadata,
3209
+ "activeVersionId",
3224
3210
  "createdAt", "createdAtZ", "updatedAt", "updatedAtZ"
3225
- ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21)`,
3211
+ ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)`,
3226
3212
  [
3227
3213
  agent.id,
3228
- agent.name,
3229
- agent.description ?? null,
3230
- agent.instructions,
3231
- JSON.stringify(agent.model),
3232
- agent.tools ? JSON.stringify(agent.tools) : null,
3233
- agent.defaultOptions ? JSON.stringify(agent.defaultOptions) : null,
3234
- agent.workflows ? JSON.stringify(agent.workflows) : null,
3235
- agent.agents ? JSON.stringify(agent.agents) : null,
3236
- agent.integrationTools ? JSON.stringify(agent.integrationTools) : null,
3237
- agent.inputProcessors ? JSON.stringify(agent.inputProcessors) : null,
3238
- agent.outputProcessors ? JSON.stringify(agent.outputProcessors) : null,
3239
- agent.memory ? JSON.stringify(agent.memory) : null,
3240
- agent.scorers ? JSON.stringify(agent.scorers) : null,
3214
+ "draft",
3215
+ agent.authorId ?? null,
3241
3216
  agent.metadata ? JSON.stringify(agent.metadata) : null,
3242
- agent.ownerId ?? null,
3243
- agent.activeVersionId ?? null,
3217
+ null,
3218
+ // activeVersionId starts as null
3244
3219
  nowIso,
3245
3220
  nowIso,
3246
3221
  nowIso,
3247
3222
  nowIso
3248
3223
  ]
3249
3224
  );
3225
+ const { id: _id, authorId: _authorId, metadata: _metadata, ...snapshotConfig } = agent;
3226
+ const versionId = crypto.randomUUID();
3227
+ await this.createVersion({
3228
+ id: versionId,
3229
+ agentId: agent.id,
3230
+ versionNumber: 1,
3231
+ ...snapshotConfig,
3232
+ changedFields: Object.keys(snapshotConfig),
3233
+ changeMessage: "Initial version"
3234
+ });
3235
+ await this.#db.client.none(
3236
+ `UPDATE ${agentsTable} SET "activeVersionId" = $1, status = $2, "updatedAt" = $3, "updatedAtZ" = $4 WHERE id = $5`,
3237
+ [versionId, "published", nowIso, nowIso, agent.id]
3238
+ );
3250
3239
  return {
3251
- ...agent,
3240
+ id: agent.id,
3241
+ status: "published",
3242
+ activeVersionId: versionId,
3243
+ authorId: agent.authorId,
3244
+ metadata: agent.metadata,
3252
3245
  createdAt: now,
3253
3246
  updatedAt: now
3254
3247
  };
@@ -3280,65 +3273,15 @@ var AgentsPG = class _AgentsPG extends AgentsStorage {
3280
3273
  const setClauses = [];
3281
3274
  const values = [];
3282
3275
  let paramIndex = 1;
3283
- if (updates.name !== void 0) {
3284
- setClauses.push(`name = $${paramIndex++}`);
3285
- values.push(updates.name);
3286
- }
3287
- if (updates.description !== void 0) {
3288
- setClauses.push(`description = $${paramIndex++}`);
3289
- values.push(updates.description);
3290
- }
3291
- if (updates.instructions !== void 0) {
3292
- setClauses.push(`instructions = $${paramIndex++}`);
3293
- values.push(updates.instructions);
3294
- }
3295
- if (updates.model !== void 0) {
3296
- setClauses.push(`model = $${paramIndex++}`);
3297
- values.push(JSON.stringify(updates.model));
3298
- }
3299
- if (updates.tools !== void 0) {
3300
- setClauses.push(`tools = $${paramIndex++}`);
3301
- values.push(JSON.stringify(updates.tools));
3302
- }
3303
- if (updates.defaultOptions !== void 0) {
3304
- setClauses.push(`"defaultOptions" = $${paramIndex++}`);
3305
- values.push(JSON.stringify(updates.defaultOptions));
3306
- }
3307
- if (updates.workflows !== void 0) {
3308
- setClauses.push(`workflows = $${paramIndex++}`);
3309
- values.push(JSON.stringify(updates.workflows));
3310
- }
3311
- if (updates.agents !== void 0) {
3312
- setClauses.push(`agents = $${paramIndex++}`);
3313
- values.push(JSON.stringify(updates.agents));
3314
- }
3315
- if (updates.inputProcessors !== void 0) {
3316
- setClauses.push(`"inputProcessors" = $${paramIndex++}`);
3317
- values.push(JSON.stringify(updates.inputProcessors));
3318
- }
3319
- if (updates.outputProcessors !== void 0) {
3320
- setClauses.push(`"outputProcessors" = $${paramIndex++}`);
3321
- values.push(JSON.stringify(updates.outputProcessors));
3322
- }
3323
- if (updates.memory !== void 0) {
3324
- setClauses.push(`memory = $${paramIndex++}`);
3325
- values.push(JSON.stringify(updates.memory));
3326
- }
3327
- if (updates.scorers !== void 0) {
3328
- setClauses.push(`scorers = $${paramIndex++}`);
3329
- values.push(JSON.stringify(updates.scorers));
3330
- }
3331
- if (updates.integrationTools !== void 0) {
3332
- setClauses.push(`"integrationTools" = $${paramIndex++}`);
3333
- values.push(JSON.stringify(updates.integrationTools));
3334
- }
3335
- if (updates.ownerId !== void 0) {
3336
- setClauses.push(`"ownerId" = $${paramIndex++}`);
3337
- values.push(updates.ownerId);
3276
+ if (updates.authorId !== void 0) {
3277
+ setClauses.push(`"authorId" = $${paramIndex++}`);
3278
+ values.push(updates.authorId);
3338
3279
  }
3339
3280
  if (updates.activeVersionId !== void 0) {
3340
3281
  setClauses.push(`"activeVersionId" = $${paramIndex++}`);
3341
3282
  values.push(updates.activeVersionId);
3283
+ setClauses.push(`status = $${paramIndex++}`);
3284
+ values.push("published");
3342
3285
  }
3343
3286
  if (updates.metadata !== void 0) {
3344
3287
  const mergedMetadata = { ...existingAgent.metadata, ...updates.metadata };
@@ -3463,14 +3406,30 @@ var AgentsPG = class _AgentsPG extends AgentsStorage {
3463
3406
  const nowIso = now.toISOString();
3464
3407
  await this.#db.client.none(
3465
3408
  `INSERT INTO ${tableName} (
3466
- id, "agentId", "versionNumber", name, snapshot, "changedFields", "changeMessage", "createdAt", "createdAtZ"
3467
- ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)`,
3409
+ id, "agentId", "versionNumber",
3410
+ name, description, instructions, model, tools,
3411
+ "defaultOptions", workflows, agents, "integrationTools",
3412
+ "inputProcessors", "outputProcessors", memory, scorers,
3413
+ "changedFields", "changeMessage",
3414
+ "createdAt", "createdAtZ"
3415
+ ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20)`,
3468
3416
  [
3469
3417
  input.id,
3470
3418
  input.agentId,
3471
3419
  input.versionNumber,
3472
- input.name ?? null,
3473
- JSON.stringify(input.snapshot),
3420
+ input.name,
3421
+ input.description ?? null,
3422
+ input.instructions,
3423
+ JSON.stringify(input.model),
3424
+ input.tools ? JSON.stringify(input.tools) : null,
3425
+ input.defaultOptions ? JSON.stringify(input.defaultOptions) : null,
3426
+ input.workflows ? JSON.stringify(input.workflows) : null,
3427
+ input.agents ? JSON.stringify(input.agents) : null,
3428
+ input.integrationTools ? JSON.stringify(input.integrationTools) : null,
3429
+ input.inputProcessors ? JSON.stringify(input.inputProcessors) : null,
3430
+ input.outputProcessors ? JSON.stringify(input.outputProcessors) : null,
3431
+ input.memory ? JSON.stringify(input.memory) : null,
3432
+ input.scorers ? JSON.stringify(input.scorers) : null,
3474
3433
  input.changedFields ? JSON.stringify(input.changedFields) : null,
3475
3434
  input.changeMessage ?? null,
3476
3435
  nowIso,
@@ -3675,7 +3634,18 @@ var AgentsPG = class _AgentsPG extends AgentsStorage {
3675
3634
  agentId: row.agentId,
3676
3635
  versionNumber: row.versionNumber,
3677
3636
  name: row.name,
3678
- snapshot: this.parseJson(row.snapshot, "snapshot"),
3637
+ description: row.description,
3638
+ instructions: row.instructions,
3639
+ model: this.parseJson(row.model, "model"),
3640
+ tools: this.parseJson(row.tools, "tools"),
3641
+ defaultOptions: this.parseJson(row.defaultOptions, "defaultOptions"),
3642
+ workflows: this.parseJson(row.workflows, "workflows"),
3643
+ agents: this.parseJson(row.agents, "agents"),
3644
+ integrationTools: this.parseJson(row.integrationTools, "integrationTools"),
3645
+ inputProcessors: this.parseJson(row.inputProcessors, "inputProcessors"),
3646
+ outputProcessors: this.parseJson(row.outputProcessors, "outputProcessors"),
3647
+ memory: this.parseJson(row.memory, "memory"),
3648
+ scorers: this.parseJson(row.scorers, "scorers"),
3679
3649
  changedFields: this.parseJson(row.changedFields, "changedFields"),
3680
3650
  changeMessage: row.changeMessage,
3681
3651
  createdAt: row.createdAtZ || row.createdAt