@axiom-lattice/pg-stores 1.0.91 → 1.0.93

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.mjs CHANGED
@@ -2949,8 +2949,8 @@ var PostgreSQLTenantStore = class {
2949
2949
  updateValues.push(updates.status);
2950
2950
  }
2951
2951
  if (updates.metadata !== void 0) {
2952
- updateFields.push(`metadata = $${paramIndex++}`);
2953
- updateValues.push(updates.metadata);
2952
+ updateFields.push(`metadata = COALESCE(lattice_tenants.metadata, '{}'::jsonb) || $${paramIndex++}::jsonb`);
2953
+ updateValues.push(JSON.stringify(updates.metadata));
2954
2954
  }
2955
2955
  if (updateFields.length === 0) {
2956
2956
  return existing;
@@ -6362,6 +6362,34 @@ var createTasksTable = {
6362
6362
  await client.query("DROP TABLE IF EXISTS lattice_tasks");
6363
6363
  }
6364
6364
  };
6365
+ var addTaskFieldsMigration = {
6366
+ version: 139,
6367
+ name: "add_task_fields_require_review_deps_result_failure",
6368
+ up: async (client) => {
6369
+ await client.query(`
6370
+ ALTER TABLE lattice_tasks
6371
+ ADD COLUMN IF NOT EXISTS require_review BOOLEAN DEFAULT FALSE,
6372
+ ADD COLUMN IF NOT EXISTS dependencies JSONB,
6373
+ ADD COLUMN IF NOT EXISTS result TEXT,
6374
+ ADD COLUMN IF NOT EXISTS failure_reason TEXT
6375
+ `);
6376
+ }
6377
+ };
6378
+ var addTaskProjectFieldsMigration = {
6379
+ version: 140,
6380
+ name: "add_task_project_workspace_fields",
6381
+ up: async (client) => {
6382
+ await client.query(`
6383
+ ALTER TABLE lattice_tasks
6384
+ ADD COLUMN IF NOT EXISTS workspace_id TEXT,
6385
+ ADD COLUMN IF NOT EXISTS project_id TEXT
6386
+ `);
6387
+ await client.query(`
6388
+ CREATE INDEX IF NOT EXISTS idx_tasks_project
6389
+ ON lattice_tasks (tenant_id, project_id)
6390
+ `);
6391
+ }
6392
+ };
6365
6393
 
6366
6394
  // src/stores/PostgreSQLTaskStore.ts
6367
6395
  import { v4 as uuidv42 } from "uuid";
@@ -6380,6 +6408,12 @@ function mapRowToTask(row) {
6380
6408
  parentId: row.parent_id ?? void 0,
6381
6409
  sourceId: row.source_id ?? void 0,
6382
6410
  context: row.context ?? void 0,
6411
+ requireReview: row.require_review ?? void 0,
6412
+ dependencies: row.dependencies ?? void 0,
6413
+ result: row.result ?? void 0,
6414
+ failureReason: row.failure_reason ?? void 0,
6415
+ workspaceId: row.workspace_id ?? void 0,
6416
+ projectId: row.project_id ?? void 0,
6383
6417
  createdAt: new Date(row.created_at),
6384
6418
  updatedAt: new Date(row.updated_at)
6385
6419
  };
@@ -6404,6 +6438,8 @@ var PostgreSQLTaskStore = class {
6404
6438
  }
6405
6439
  this.migrationManager = new MigrationManager(this.pool);
6406
6440
  this.migrationManager.register(createTasksTable);
6441
+ this.migrationManager.register(addTaskFieldsMigration);
6442
+ this.migrationManager.register(addTaskProjectFieldsMigration);
6407
6443
  if (options.autoMigrate !== false) {
6408
6444
  this.initialize().catch((error) => {
6409
6445
  console.error("Failed to initialize PostgreSQLTaskStore:", error);
@@ -6433,8 +6469,8 @@ var PostgreSQLTaskStore = class {
6433
6469
  const id = uuidv42();
6434
6470
  const now = (/* @__PURE__ */ new Date()).toISOString();
6435
6471
  await this.pool.query(
6436
- `INSERT INTO lattice_tasks (id, tenant_id, owner_type, owner_id, title, description, status, priority, due_date, metadata, parent_id, source_id, context, created_at, updated_at)
6437
- VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15)`,
6472
+ `INSERT INTO lattice_tasks (id, tenant_id, owner_type, owner_id, title, description, status, priority, due_date, metadata, parent_id, source_id, context, require_review, dependencies, result, failure_reason, workspace_id, project_id, created_at, updated_at)
6473
+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21)`,
6438
6474
  [
6439
6475
  id,
6440
6476
  params.tenantId,
@@ -6449,6 +6485,12 @@ var PostgreSQLTaskStore = class {
6449
6485
  params.parentId || null,
6450
6486
  params.sourceId || null,
6451
6487
  params.context ? JSON.stringify(params.context) : null,
6488
+ params.requireReview ?? null,
6489
+ params.dependencies ? JSON.stringify(params.dependencies) : null,
6490
+ params.result ?? null,
6491
+ params.failureReason ?? null,
6492
+ params.workspaceId || null,
6493
+ params.projectId || null,
6452
6494
  now,
6453
6495
  now
6454
6496
  ]
@@ -6478,13 +6520,24 @@ var PostgreSQLTaskStore = class {
6478
6520
  params.push(filter.ownerId);
6479
6521
  }
6480
6522
  if (filter.status) {
6481
- conditions.push(`status = $${paramIndex++}`);
6482
- params.push(filter.status);
6523
+ const statuses = filter.status.split(",").map((s) => s.trim()).filter(Boolean);
6524
+ const placeholders = statuses.map((_, i) => `$${paramIndex + i}`).join(", ");
6525
+ conditions.push(`status IN (${placeholders})`);
6526
+ params.push(...statuses);
6527
+ paramIndex += statuses.length;
6483
6528
  }
6484
6529
  if (filter.priority) {
6485
6530
  conditions.push(`priority = $${paramIndex++}`);
6486
6531
  params.push(filter.priority);
6487
6532
  }
6533
+ if (filter.workspaceId) {
6534
+ conditions.push(`workspace_id = $${paramIndex++}`);
6535
+ params.push(filter.workspaceId);
6536
+ }
6537
+ if (filter.projectId) {
6538
+ conditions.push(`project_id = $${paramIndex++}`);
6539
+ params.push(filter.projectId);
6540
+ }
6488
6541
  if (filter.parentId) {
6489
6542
  conditions.push(`parent_id = $${paramIndex++}`);
6490
6543
  params.push(filter.parentId);
@@ -6562,6 +6615,30 @@ var PostgreSQLTaskStore = class {
6562
6615
  setClauses.push(`owner_id = $${paramIndex++}`);
6563
6616
  params.push(updates.ownerId);
6564
6617
  }
6618
+ if (updates.requireReview !== void 0) {
6619
+ setClauses.push(`require_review = $${paramIndex++}`);
6620
+ params.push(updates.requireReview);
6621
+ }
6622
+ if (updates.dependencies !== void 0) {
6623
+ setClauses.push(`dependencies = $${paramIndex++}`);
6624
+ params.push(JSON.stringify(updates.dependencies));
6625
+ }
6626
+ if (updates.result !== void 0) {
6627
+ setClauses.push(`result = $${paramIndex++}`);
6628
+ params.push(updates.result);
6629
+ }
6630
+ if (updates.failureReason !== void 0) {
6631
+ setClauses.push(`failure_reason = $${paramIndex++}`);
6632
+ params.push(updates.failureReason);
6633
+ }
6634
+ if (updates.workspaceId !== void 0) {
6635
+ setClauses.push(`workspace_id = $${paramIndex++}`);
6636
+ params.push(updates.workspaceId);
6637
+ }
6638
+ if (updates.projectId !== void 0) {
6639
+ setClauses.push(`project_id = $${paramIndex++}`);
6640
+ params.push(updates.projectId);
6641
+ }
6565
6642
  if (setClauses.length === 0) {
6566
6643
  return existing;
6567
6644
  }
@@ -6594,6 +6671,72 @@ var PostgreSQLTaskStore = class {
6594
6671
  }
6595
6672
  };
6596
6673
 
6674
+ // src/stores/PostgreSQLTaskWorkItemStore.ts
6675
+ import { v4 } from "uuid";
6676
+ var PostgreSQLTaskWorkItemStore = class {
6677
+ constructor(pool) {
6678
+ this.pool = pool;
6679
+ }
6680
+ async create(params) {
6681
+ const id = v4();
6682
+ const result = await this.pool.query(
6683
+ `INSERT INTO lattice_task_work_items
6684
+ (id, tenant_id, task_id, action, actor, thread_id, summary, detail, attempt, workspace_id, project_id)
6685
+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)
6686
+ RETURNING *`,
6687
+ [
6688
+ id,
6689
+ params.tenantId,
6690
+ params.taskId,
6691
+ params.action,
6692
+ params.actor,
6693
+ params.threadId || null,
6694
+ params.summary || null,
6695
+ params.detail ? JSON.stringify(params.detail) : null,
6696
+ params.attempt || null,
6697
+ params.workspaceId || null,
6698
+ params.projectId || null
6699
+ ]
6700
+ );
6701
+ return this.rowToItem(result.rows[0]);
6702
+ }
6703
+ async list(filter) {
6704
+ let query = `SELECT * FROM lattice_task_work_items WHERE tenant_id = $1 AND task_id = $2`;
6705
+ const params = [filter.tenantId, filter.taskId];
6706
+ if (filter.action) {
6707
+ query += ` AND action = $${params.length + 1}`;
6708
+ params.push(filter.action);
6709
+ }
6710
+ query += ` ORDER BY created_at ASC`;
6711
+ if (filter.limit) {
6712
+ query += ` LIMIT $${params.length + 1}`;
6713
+ params.push(filter.limit);
6714
+ }
6715
+ if (filter.offset) {
6716
+ query += ` OFFSET $${params.length + 1}`;
6717
+ params.push(filter.offset);
6718
+ }
6719
+ const result = await this.pool.query(query, params);
6720
+ return result.rows.map((row) => this.rowToItem(row));
6721
+ }
6722
+ rowToItem(row) {
6723
+ return {
6724
+ id: row.id,
6725
+ taskId: row.task_id,
6726
+ tenantId: row.tenant_id,
6727
+ action: row.action,
6728
+ actor: row.actor,
6729
+ threadId: row.thread_id,
6730
+ summary: row.summary,
6731
+ detail: row.detail,
6732
+ attempt: row.attempt,
6733
+ workspaceId: row.workspace_id,
6734
+ projectId: row.project_id,
6735
+ createdAt: new Date(row.created_at)
6736
+ };
6737
+ }
6738
+ };
6739
+
6597
6740
  // src/stores/MenuStore.ts
6598
6741
  import { Pool as Pool19 } from "pg";
6599
6742
 
@@ -7543,6 +7686,52 @@ var createCollectionsTable = {
7543
7686
  }
7544
7687
  };
7545
7688
 
7689
+ // src/migrations/task_work_items_migration.ts
7690
+ var createTaskWorkItemsMigration = {
7691
+ version: 138,
7692
+ name: "create_task_work_items_table",
7693
+ up: async (client) => {
7694
+ await client.query(`
7695
+ CREATE TABLE IF NOT EXISTS lattice_task_work_items (
7696
+ id TEXT NOT NULL,
7697
+ tenant_id TEXT NOT NULL,
7698
+ task_id TEXT NOT NULL,
7699
+ action TEXT NOT NULL,
7700
+ actor TEXT NOT NULL,
7701
+ thread_id TEXT,
7702
+ summary TEXT,
7703
+ detail JSONB,
7704
+ attempt INTEGER,
7705
+ created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
7706
+ PRIMARY KEY (tenant_id, id)
7707
+ )
7708
+ `);
7709
+ await client.query(`
7710
+ CREATE INDEX IF NOT EXISTS idx_task_work_items_task_id
7711
+ ON lattice_task_work_items (tenant_id, task_id)
7712
+ `);
7713
+ await client.query(`
7714
+ CREATE INDEX IF NOT EXISTS idx_task_work_items_action
7715
+ ON lattice_task_work_items (tenant_id, task_id, action)
7716
+ `);
7717
+ }
7718
+ };
7719
+ var addWorkItemProjectFieldsMigration = {
7720
+ version: 140,
7721
+ name: "add_task_work_item_project_fields",
7722
+ up: async (client) => {
7723
+ await client.query(`
7724
+ ALTER TABLE lattice_task_work_items
7725
+ ADD COLUMN IF NOT EXISTS workspace_id TEXT,
7726
+ ADD COLUMN IF NOT EXISTS project_id TEXT
7727
+ `);
7728
+ await client.query(`
7729
+ CREATE INDEX IF NOT EXISTS idx_task_work_items_project
7730
+ ON lattice_task_work_items (tenant_id, project_id)
7731
+ `);
7732
+ }
7733
+ };
7734
+
7546
7735
  // src/createPgStoreConfig.ts
7547
7736
  async function createPgStoreConfig(connectionString) {
7548
7737
  const pool = new Pool23({ connectionString });
@@ -7590,6 +7779,10 @@ async function createPgStoreConfig(connectionString) {
7590
7779
  mm.register(createSharedResourcesTable);
7591
7780
  mm.register(addFileContentType);
7592
7781
  mm.register(createCollectionsTable);
7782
+ mm.register(addTaskFieldsMigration);
7783
+ mm.register(createTaskWorkItemsMigration);
7784
+ mm.register(addTaskProjectFieldsMigration);
7785
+ mm.register(addWorkItemProjectFieldsMigration);
7593
7786
  mm.register(createConnectionConfigsTable);
7594
7787
  mm.register(addWorkflowRunsTenantStatusUpdatedIndex);
7595
7788
  await mm.migrate();
@@ -7598,6 +7791,7 @@ async function createPgStoreConfig(connectionString) {
7598
7791
  console.error("[pg-stores] Failed to setup checkpoint table:", err.message || err);
7599
7792
  });
7600
7793
  const opts = { pool };
7794
+ const taskWorkItemStore = new PostgreSQLTaskWorkItemStore(pool);
7601
7795
  return {
7602
7796
  workspace: new PostgreSQLWorkspaceStore(opts),
7603
7797
  project: new PostgreSQLProjectStore(opts),
@@ -7616,6 +7810,7 @@ async function createPgStoreConfig(connectionString) {
7616
7810
  workflowTracking: new PostgreSQLWorkflowTrackingStore(opts),
7617
7811
  threadMessageQueue: new ThreadMessageQueueStore(opts),
7618
7812
  task: new PostgreSQLTaskStore(opts),
7813
+ taskWorkItem: taskWorkItemStore,
7619
7814
  a2aApiKey: new PostgreSQLA2AApiKeyStore(opts),
7620
7815
  schedule: new PostgreSQLScheduleStorage(opts),
7621
7816
  menu: new MenuStore(opts),