@axiom-lattice/pg-stores 1.0.89 → 1.0.90
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/.turbo/turbo-build.log +10 -10
- package/CHANGELOG.md +9 -0
- package/dist/index.d.mts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +50 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +49 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -3
- package/src/__tests__/PostgreSQLWorkflowTrackingStore.test.ts +71 -1
- package/src/createPgStoreConfig.ts +2 -1
- package/src/migrations/workflow_tracking_migrations.ts +18 -0
- package/src/stores/PostgreSQLWorkflowTrackingStore.ts +39 -1
package/dist/index.mjs
CHANGED
|
@@ -3302,6 +3302,21 @@ var addStepThreadId = {
|
|
|
3302
3302
|
`);
|
|
3303
3303
|
}
|
|
3304
3304
|
};
|
|
3305
|
+
var addWorkflowRunsTenantStatusUpdatedIndex = {
|
|
3306
|
+
name: "add_workflow_runs_tenant_status_updated_index",
|
|
3307
|
+
version: 161,
|
|
3308
|
+
up: async (client) => {
|
|
3309
|
+
await client.query(`
|
|
3310
|
+
CREATE INDEX IF NOT EXISTS idx_workflow_runs_tenant_status
|
|
3311
|
+
ON lattice_workflow_runs (tenant_id, status, updated_at DESC);
|
|
3312
|
+
`);
|
|
3313
|
+
},
|
|
3314
|
+
down: async (client) => {
|
|
3315
|
+
await client.query(`
|
|
3316
|
+
DROP INDEX IF EXISTS idx_workflow_runs_tenant_status;
|
|
3317
|
+
`);
|
|
3318
|
+
}
|
|
3319
|
+
};
|
|
3305
3320
|
|
|
3306
3321
|
// src/stores/PostgreSQLWorkflowTrackingStore.ts
|
|
3307
3322
|
var PostgreSQLWorkflowTrackingStore = class {
|
|
@@ -3325,6 +3340,7 @@ var PostgreSQLWorkflowTrackingStore = class {
|
|
|
3325
3340
|
this.migrationManager = new MigrationManager(this.pool);
|
|
3326
3341
|
this.migrationManager.register(createWorkflowTrackingTables);
|
|
3327
3342
|
this.migrationManager.register(addStepThreadId);
|
|
3343
|
+
this.migrationManager.register(addWorkflowRunsTenantStatusUpdatedIndex);
|
|
3328
3344
|
if (options.autoMigrate !== false) {
|
|
3329
3345
|
this.initialize().catch((error) => {
|
|
3330
3346
|
console.error("Failed to initialize PostgreSQLWorkflowTrackingStore:", error);
|
|
@@ -3454,6 +3470,37 @@ var PostgreSQLWorkflowTrackingStore = class {
|
|
|
3454
3470
|
);
|
|
3455
3471
|
return result.rows.map(mapRowToWorkflowRun);
|
|
3456
3472
|
}
|
|
3473
|
+
async queryWorkflowRuns(tenantId, options = {}) {
|
|
3474
|
+
await this.ensureInitialized();
|
|
3475
|
+
const conditions = ["tenant_id = $1"];
|
|
3476
|
+
const whereParams = [tenantId];
|
|
3477
|
+
if (options.status) {
|
|
3478
|
+
whereParams.push(options.status);
|
|
3479
|
+
conditions.push(`status = $${whereParams.length}`);
|
|
3480
|
+
}
|
|
3481
|
+
if (options.assistantId) {
|
|
3482
|
+
whereParams.push(options.assistantId);
|
|
3483
|
+
conditions.push(`assistant_id = $${whereParams.length}`);
|
|
3484
|
+
}
|
|
3485
|
+
const where = conditions.join(" AND ");
|
|
3486
|
+
const countResult = await this.pool.query(
|
|
3487
|
+
`SELECT COUNT(*) AS count FROM lattice_workflow_runs WHERE ${where}`,
|
|
3488
|
+
whereParams
|
|
3489
|
+
);
|
|
3490
|
+
const total = parseInt(countResult.rows[0].count, 10);
|
|
3491
|
+
const selectParams = [...whereParams];
|
|
3492
|
+
let sql = `SELECT * FROM lattice_workflow_runs WHERE ${where} ORDER BY updated_at DESC, id DESC`;
|
|
3493
|
+
if (options.limit !== void 0) {
|
|
3494
|
+
selectParams.push(options.limit);
|
|
3495
|
+
sql += ` LIMIT $${selectParams.length}`;
|
|
3496
|
+
}
|
|
3497
|
+
if (options.offset !== void 0) {
|
|
3498
|
+
selectParams.push(options.offset);
|
|
3499
|
+
sql += ` OFFSET $${selectParams.length}`;
|
|
3500
|
+
}
|
|
3501
|
+
const result = await this.pool.query(sql, selectParams);
|
|
3502
|
+
return { records: result.rows.map(mapRowToWorkflowRun), total };
|
|
3503
|
+
}
|
|
3457
3504
|
async createRunStep(request) {
|
|
3458
3505
|
await this.ensureInitialized();
|
|
3459
3506
|
const now = /* @__PURE__ */ new Date();
|
|
@@ -7526,6 +7573,7 @@ async function createPgStoreConfig(connectionString) {
|
|
|
7526
7573
|
mm.register(addFileContentType);
|
|
7527
7574
|
mm.register(createCollectionsTable);
|
|
7528
7575
|
mm.register(createConnectionConfigsTable);
|
|
7576
|
+
mm.register(addWorkflowRunsTenantStatusUpdatedIndex);
|
|
7529
7577
|
await mm.migrate();
|
|
7530
7578
|
const checkpoint = PostgresSaver.fromConnString(connectionString);
|
|
7531
7579
|
checkpoint.setup().catch((err) => {
|
|
@@ -8141,6 +8189,7 @@ export {
|
|
|
8141
8189
|
addSkillTenantId,
|
|
8142
8190
|
addStepThreadId,
|
|
8143
8191
|
addThreadTenantId,
|
|
8192
|
+
addWorkflowRunsTenantStatusUpdatedIndex,
|
|
8144
8193
|
alterChannelInstallationsTable,
|
|
8145
8194
|
changeAssistantPrimaryKey,
|
|
8146
8195
|
changeSkillPrimaryKey,
|