@axiom-lattice/pg-stores 1.0.89 → 1.0.91

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
@@ -1254,6 +1254,13 @@ var PostgreSQLConnectionStore = class {
1254
1254
  constructor(db) {
1255
1255
  this.db = db;
1256
1256
  }
1257
+ async listByTenant(tenantId) {
1258
+ const result = await this.db.query(
1259
+ `SELECT * FROM ${TABLE} WHERE tenant_id = $1 ORDER BY created_at`,
1260
+ [tenantId]
1261
+ );
1262
+ return result.rows.map((row) => this.mapRow(row));
1263
+ }
1257
1264
  async listByType(tenantId, type) {
1258
1265
  const result = await this.db.query(
1259
1266
  `SELECT * FROM ${TABLE} WHERE tenant_id = $1 AND type = $2 ORDER BY created_at`,
@@ -3302,6 +3309,21 @@ var addStepThreadId = {
3302
3309
  `);
3303
3310
  }
3304
3311
  };
3312
+ var addWorkflowRunsTenantStatusUpdatedIndex = {
3313
+ name: "add_workflow_runs_tenant_status_updated_index",
3314
+ version: 161,
3315
+ up: async (client) => {
3316
+ await client.query(`
3317
+ CREATE INDEX IF NOT EXISTS idx_workflow_runs_tenant_status
3318
+ ON lattice_workflow_runs (tenant_id, status, updated_at DESC);
3319
+ `);
3320
+ },
3321
+ down: async (client) => {
3322
+ await client.query(`
3323
+ DROP INDEX IF EXISTS idx_workflow_runs_tenant_status;
3324
+ `);
3325
+ }
3326
+ };
3305
3327
 
3306
3328
  // src/stores/PostgreSQLWorkflowTrackingStore.ts
3307
3329
  var PostgreSQLWorkflowTrackingStore = class {
@@ -3325,6 +3347,7 @@ var PostgreSQLWorkflowTrackingStore = class {
3325
3347
  this.migrationManager = new MigrationManager(this.pool);
3326
3348
  this.migrationManager.register(createWorkflowTrackingTables);
3327
3349
  this.migrationManager.register(addStepThreadId);
3350
+ this.migrationManager.register(addWorkflowRunsTenantStatusUpdatedIndex);
3328
3351
  if (options.autoMigrate !== false) {
3329
3352
  this.initialize().catch((error) => {
3330
3353
  console.error("Failed to initialize PostgreSQLWorkflowTrackingStore:", error);
@@ -3454,6 +3477,37 @@ var PostgreSQLWorkflowTrackingStore = class {
3454
3477
  );
3455
3478
  return result.rows.map(mapRowToWorkflowRun);
3456
3479
  }
3480
+ async queryWorkflowRuns(tenantId, options = {}) {
3481
+ await this.ensureInitialized();
3482
+ const conditions = ["tenant_id = $1"];
3483
+ const whereParams = [tenantId];
3484
+ if (options.status) {
3485
+ whereParams.push(options.status);
3486
+ conditions.push(`status = $${whereParams.length}`);
3487
+ }
3488
+ if (options.assistantId) {
3489
+ whereParams.push(options.assistantId);
3490
+ conditions.push(`assistant_id = $${whereParams.length}`);
3491
+ }
3492
+ const where = conditions.join(" AND ");
3493
+ const countResult = await this.pool.query(
3494
+ `SELECT COUNT(*) AS count FROM lattice_workflow_runs WHERE ${where}`,
3495
+ whereParams
3496
+ );
3497
+ const total = parseInt(countResult.rows[0].count, 10);
3498
+ const selectParams = [...whereParams];
3499
+ let sql = `SELECT * FROM lattice_workflow_runs WHERE ${where} ORDER BY updated_at DESC, id DESC`;
3500
+ if (options.limit !== void 0) {
3501
+ selectParams.push(options.limit);
3502
+ sql += ` LIMIT $${selectParams.length}`;
3503
+ }
3504
+ if (options.offset !== void 0) {
3505
+ selectParams.push(options.offset);
3506
+ sql += ` OFFSET $${selectParams.length}`;
3507
+ }
3508
+ const result = await this.pool.query(sql, selectParams);
3509
+ return { records: result.rows.map(mapRowToWorkflowRun), total };
3510
+ }
3457
3511
  async createRunStep(request) {
3458
3512
  await this.ensureInitialized();
3459
3513
  const now = /* @__PURE__ */ new Date();
@@ -3613,7 +3667,7 @@ function mapRowToRunStep(row) {
3613
3667
  edgeTo: row.edge_to,
3614
3668
  edgePurpose: row.edge_purpose,
3615
3669
  input: safeParse(row.input, void 0),
3616
- output: safeParse(row.output, void 0),
3670
+ output: typeof row.output === "string" ? safeParse(row.output, row.output) : row.output ?? void 0,
3617
3671
  status: row.status,
3618
3672
  errorMessage: row.error_message,
3619
3673
  startedAt: row.started_at,
@@ -4508,6 +4562,17 @@ var PostgreSQLEvalStore = class {
4508
4562
  );
4509
4563
  return rows.length ? this.mapRowToRunResult(rows[0]) : null;
4510
4564
  }
4565
+ /** Delete a run result by ID */
4566
+ async deleteRunResult(tenantId, id) {
4567
+ await this.ensureInitialized();
4568
+ const result = await this.pool.query(
4569
+ `DELETE FROM lattice_eval_run_results
4570
+ WHERE id = $1
4571
+ AND run_id IN (SELECT id FROM lattice_eval_runs WHERE tenant_id = $2)`,
4572
+ [id, tenantId]
4573
+ );
4574
+ return (result.rowCount ?? 0) > 0;
4575
+ }
4511
4576
  /** Get a single run result by ID with tenant isolation */
4512
4577
  async getRunResultById(tenantId, id) {
4513
4578
  await this.ensureInitialized();
@@ -7526,6 +7591,7 @@ async function createPgStoreConfig(connectionString) {
7526
7591
  mm.register(addFileContentType);
7527
7592
  mm.register(createCollectionsTable);
7528
7593
  mm.register(createConnectionConfigsTable);
7594
+ mm.register(addWorkflowRunsTenantStatusUpdatedIndex);
7529
7595
  await mm.migrate();
7530
7596
  const checkpoint = PostgresSaver.fromConnString(connectionString);
7531
7597
  checkpoint.setup().catch((err) => {
@@ -8141,6 +8207,7 @@ export {
8141
8207
  addSkillTenantId,
8142
8208
  addStepThreadId,
8143
8209
  addThreadTenantId,
8210
+ addWorkflowRunsTenantStatusUpdatedIndex,
8144
8211
  alterChannelInstallationsTable,
8145
8212
  changeAssistantPrimaryKey,
8146
8213
  changeSkillPrimaryKey,