@axiom-lattice/pg-stores 3.3.3 → 3.3.5

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
@@ -7845,11 +7845,11 @@ var PostgreSQLTaskStore = class {
7845
7845
  params.push(filter.ownerId);
7846
7846
  }
7847
7847
  if (filter.status) {
7848
- const statuses = filter.status.split(",").map((s) => s.trim()).filter(Boolean);
7849
- const placeholders = statuses.map((_, i) => `$${paramIndex + i}`).join(", ");
7848
+ const statuses2 = filter.status.split(",").map((s) => s.trim()).filter(Boolean);
7849
+ const placeholders = statuses2.map((_, i) => `$${paramIndex + i}`).join(", ");
7850
7850
  conditions.push(`status IN (${placeholders})`);
7851
- params.push(...statuses);
7852
- paramIndex += statuses.length;
7851
+ params.push(...statuses2);
7852
+ paramIndex += statuses2.length;
7853
7853
  }
7854
7854
  if (filter.priority) {
7855
7855
  conditions.push(`priority = $${paramIndex++}`);
@@ -10152,6 +10152,60 @@ var createOutboxTable = {
10152
10152
  }
10153
10153
  };
10154
10154
 
10155
+ // src/migrations/plugin_deployment_migration.ts
10156
+ var createPluginDeployments = {
10157
+ version: 189,
10158
+ name: "create_plugin_deployments",
10159
+ up: async (client) => {
10160
+ await client.query(`
10161
+ CREATE TABLE IF NOT EXISTS lattice_plugin_deployments (
10162
+ id VARCHAR(255) PRIMARY KEY,
10163
+ tenant_id VARCHAR(255) NOT NULL,
10164
+ plugin_type VARCHAR(255) NOT NULL,
10165
+ plugin_version VARCHAR(255) NOT NULL,
10166
+ mode VARCHAR(16) NOT NULL,
10167
+ status VARCHAR(32) NOT NULL,
10168
+ provider VARCHAR(64) NOT NULL,
10169
+ sandbox_name VARCHAR(255) NOT NULL,
10170
+ port INTEGER NOT NULL,
10171
+ endpoint TEXT,
10172
+ image_ref TEXT,
10173
+ auth_token TEXT NOT NULL,
10174
+ idle_timeout_ms INTEGER NOT NULL,
10175
+ last_health_at TIMESTAMPTZ,
10176
+ last_error TEXT,
10177
+ created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
10178
+ updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
10179
+ UNIQUE (tenant_id, plugin_type)
10180
+ )
10181
+ `);
10182
+ await client.query(`
10183
+ CREATE INDEX IF NOT EXISTS idx_lattice_plugin_deployments_tenant
10184
+ ON lattice_plugin_deployments (tenant_id)
10185
+ `);
10186
+ },
10187
+ down: async (client) => {
10188
+ await client.query("DROP INDEX IF EXISTS idx_lattice_plugin_deployments_tenant");
10189
+ await client.query("DROP TABLE IF EXISTS lattice_plugin_deployments");
10190
+ }
10191
+ };
10192
+ var dropPluginDeploymentAuthToken = {
10193
+ version: 190,
10194
+ name: "drop_plugin_deployment_auth_token",
10195
+ up: async (client) => {
10196
+ await client.query(`
10197
+ ALTER TABLE lattice_plugin_deployments
10198
+ DROP COLUMN IF EXISTS auth_token
10199
+ `);
10200
+ },
10201
+ down: async (client) => {
10202
+ await client.query(`
10203
+ ALTER TABLE lattice_plugin_deployments
10204
+ ADD COLUMN IF NOT EXISTS auth_token TEXT NOT NULL DEFAULT ''
10205
+ `);
10206
+ }
10207
+ };
10208
+
10155
10209
  // src/migrations/model_provider_migrations.ts
10156
10210
  var createModelProvidersTable = {
10157
10211
  version: 181,
@@ -11935,6 +11989,145 @@ var PostgreSQLOutboxStore = class {
11935
11989
  }
11936
11990
  };
11937
11991
 
11992
+ // src/stores/PostgreSQLPluginDeploymentStore.ts
11993
+ var columns5 = "id, tenant_id, plugin_type, plugin_version, mode, status, provider, sandbox_name, port, endpoint, image_ref, idle_timeout_ms, last_health_at, last_error, created_at, updated_at";
11994
+ var statuses = [
11995
+ "requested",
11996
+ "provisioning",
11997
+ "running",
11998
+ "paused",
11999
+ "stopping",
12000
+ "stopped",
12001
+ "failed"
12002
+ ];
12003
+ function isStatus4(value) {
12004
+ return typeof value === "string" && statuses.includes(value);
12005
+ }
12006
+ function mapRow8(row) {
12007
+ if (typeof row.id !== "string" || typeof row.tenant_id !== "string" || typeof row.plugin_type !== "string" || typeof row.plugin_version !== "string" || row.mode !== "onDemand" && row.mode !== "alwaysOn" || !isStatus4(row.status) || typeof row.provider !== "string" || typeof row.sandbox_name !== "string" || typeof row.port !== "number" || typeof row.idle_timeout_ms !== "number" || !(row.created_at instanceof Date) || Number.isNaN(row.created_at.getTime()) || !(row.updated_at instanceof Date) || Number.isNaN(row.updated_at.getTime())) {
12008
+ throw new Error("Invalid plugin deployment row");
12009
+ }
12010
+ return {
12011
+ id: row.id,
12012
+ tenantId: row.tenant_id,
12013
+ pluginType: row.plugin_type,
12014
+ pluginVersion: row.plugin_version,
12015
+ mode: row.mode,
12016
+ status: row.status,
12017
+ provider: row.provider,
12018
+ sandboxName: row.sandbox_name,
12019
+ port: row.port,
12020
+ ...typeof row.endpoint === "string" ? { endpoint: row.endpoint } : {},
12021
+ ...typeof row.image_ref === "string" ? { imageRef: row.image_ref } : {},
12022
+ idleTimeoutMs: row.idle_timeout_ms,
12023
+ ...row.last_health_at instanceof Date && !Number.isNaN(row.last_health_at.getTime()) ? { lastHealthAt: row.last_health_at.toISOString() } : {},
12024
+ ...typeof row.last_error === "string" ? { lastError: row.last_error } : {},
12025
+ createdAt: row.created_at.toISOString(),
12026
+ updatedAt: row.updated_at.toISOString()
12027
+ };
12028
+ }
12029
+ var PostgreSQLPluginDeploymentStore = class {
12030
+ /** Creates a store using an externally managed shared pool. */
12031
+ constructor(options) {
12032
+ this.pool = options.pool;
12033
+ }
12034
+ /** Lists every deployment for a tenant, ordered by plugin type. */
12035
+ async listByTenant(tenantId) {
12036
+ const result = await this.pool.query(
12037
+ `SELECT ${columns5} FROM lattice_plugin_deployments WHERE tenant_id = $1 ORDER BY plugin_type`,
12038
+ [tenantId]
12039
+ );
12040
+ return result.rows.map(mapRow8);
12041
+ }
12042
+ /** Returns the deployment for a tenant + plugin type, or undefined. */
12043
+ async get(tenantId, pluginType) {
12044
+ const result = await this.pool.query(
12045
+ `SELECT ${columns5} FROM lattice_plugin_deployments WHERE tenant_id = $1 AND plugin_type = $2`,
12046
+ [tenantId, pluginType]
12047
+ );
12048
+ return result.rows[0] ? mapRow8(result.rows[0]) : void 0;
12049
+ }
12050
+ /** Upserts a deployment keyed by tenant + plugin type, preserving the original id and createdAt. */
12051
+ async upsert(deployment) {
12052
+ const result = await this.pool.query(
12053
+ `INSERT INTO lattice_plugin_deployments (${columns5})
12054
+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16)
12055
+ ON CONFLICT (tenant_id, plugin_type) DO UPDATE SET
12056
+ plugin_version = EXCLUDED.plugin_version,
12057
+ mode = EXCLUDED.mode,
12058
+ status = EXCLUDED.status,
12059
+ provider = EXCLUDED.provider,
12060
+ sandbox_name = EXCLUDED.sandbox_name,
12061
+ port = EXCLUDED.port,
12062
+ endpoint = EXCLUDED.endpoint,
12063
+ image_ref = EXCLUDED.image_ref,
12064
+ idle_timeout_ms = EXCLUDED.idle_timeout_ms,
12065
+ last_health_at = EXCLUDED.last_health_at,
12066
+ last_error = EXCLUDED.last_error,
12067
+ updated_at = NOW()
12068
+ RETURNING ${columns5}`,
12069
+ [
12070
+ deployment.id,
12071
+ deployment.tenantId,
12072
+ deployment.pluginType,
12073
+ deployment.pluginVersion,
12074
+ deployment.mode,
12075
+ deployment.status,
12076
+ deployment.provider,
12077
+ deployment.sandboxName,
12078
+ deployment.port,
12079
+ deployment.endpoint ?? null,
12080
+ deployment.imageRef ?? null,
12081
+ deployment.idleTimeoutMs,
12082
+ deployment.lastHealthAt ? new Date(deployment.lastHealthAt) : null,
12083
+ deployment.lastError ?? null,
12084
+ new Date(deployment.createdAt),
12085
+ new Date(deployment.updatedAt)
12086
+ ]
12087
+ );
12088
+ return mapRow8(result.rows[0]);
12089
+ }
12090
+ /** Applies a partial update to mutable columns; returns undefined when no row exists. */
12091
+ async updateStatus(tenantId, pluginType, patch) {
12092
+ const assignments = [];
12093
+ const params = [];
12094
+ const assign = (column, value) => {
12095
+ params.push(value);
12096
+ assignments.push(`${column} = $${params.length}`);
12097
+ };
12098
+ if (patch.status !== void 0) assign("status", patch.status);
12099
+ if (patch.mode !== void 0) assign("mode", patch.mode);
12100
+ if (patch.endpoint !== void 0) assign("endpoint", patch.endpoint);
12101
+ if (patch.imageRef !== void 0) assign("image_ref", patch.imageRef);
12102
+ if (patch.idleTimeoutMs !== void 0) assign("idle_timeout_ms", patch.idleTimeoutMs);
12103
+ if (patch.lastHealthAt !== void 0) assign("last_health_at", new Date(patch.lastHealthAt));
12104
+ if (patch.lastError !== void 0) assign("last_error", patch.lastError);
12105
+ if (patch.pluginVersion !== void 0) assign("plugin_version", patch.pluginVersion);
12106
+ if (patch.provider !== void 0) assign("provider", patch.provider);
12107
+ if (patch.sandboxName !== void 0) assign("sandbox_name", patch.sandboxName);
12108
+ if (patch.port !== void 0) assign("port", patch.port);
12109
+ assignments.push("updated_at = NOW()");
12110
+ params.push(tenantId, pluginType);
12111
+ const tenantParam = params.length - 1;
12112
+ const pluginParam = params.length;
12113
+ const result = await this.pool.query(
12114
+ `UPDATE lattice_plugin_deployments SET ${assignments.join(", ")}
12115
+ WHERE tenant_id = $${tenantParam} AND plugin_type = $${pluginParam}
12116
+ RETURNING ${columns5}`,
12117
+ params
12118
+ );
12119
+ return result.rows[0] ? mapRow8(result.rows[0]) : void 0;
12120
+ }
12121
+ /** Deletes a deployment by tenant + plugin type; returns whether a row was removed. */
12122
+ async delete(tenantId, pluginType) {
12123
+ const result = await this.pool.query(
12124
+ `DELETE FROM lattice_plugin_deployments WHERE tenant_id = $1 AND plugin_type = $2`,
12125
+ [tenantId, pluginType]
12126
+ );
12127
+ return (result.rowCount ?? 0) > 0;
12128
+ }
12129
+ };
12130
+
11938
12131
  // src/createPgStoreConfig.ts
11939
12132
  async function createPgStoreConfig(connectionString) {
11940
12133
  const pool = new Pool30({ connectionString });
@@ -12007,6 +12200,8 @@ async function createPgStoreConfig(connectionString) {
12007
12200
  mm.register(createDistributedLeases);
12008
12201
  mm.register(createOutboxTable);
12009
12202
  mm.register(addConnectionSecretFields);
12203
+ mm.register(createPluginDeployments);
12204
+ mm.register(dropPluginDeploymentAuthToken);
12010
12205
  await mm.migrate();
12011
12206
  const checkpoint = PostgresSaver.fromConnString(connectionString);
12012
12207
  checkpoint.setup().catch((err) => {
@@ -12050,6 +12245,7 @@ async function createPgStoreConfig(connectionString) {
12050
12245
  userPushSubscription: new PostgreSQLUserPushSubscriptionStore(opts),
12051
12246
  lease: new PostgreSQLLeaseStore(opts),
12052
12247
  outbox: new PostgreSQLOutboxStore(opts),
12248
+ pluginDeployment: new PostgreSQLPluginDeploymentStore(opts),
12053
12249
  vectorStoreProvider: new PGVectorStoreProvider(pool, connectionString),
12054
12250
  checkpoint
12055
12251
  };
@@ -12624,6 +12820,7 @@ export {
12624
12820
  PostgreSQLMetricsServerConfigStore,
12625
12821
  PostgreSQLModelProviderStore,
12626
12822
  PostgreSQLOpenAuditStore,
12823
+ PostgreSQLPluginDeploymentStore,
12627
12824
  PostgreSQLProjectBotMembershipStore,
12628
12825
  PostgreSQLProjectMembershipStore,
12629
12826
  PostgreSQLProjectRoomMessageStore,
@@ -12681,6 +12878,7 @@ export {
12681
12878
  createMetricsConfigsTable,
12682
12879
  createPGVectorStoreProvider,
12683
12880
  createPgStoreConfig,
12881
+ createPluginDeployments,
12684
12882
  createProjectRoomReadStates,
12685
12883
  createProjectRoomTables,
12686
12884
  createProjectsTable,
@@ -12693,6 +12891,7 @@ export {
12693
12891
  createUsersTable,
12694
12892
  createWorkflowTrackingTables,
12695
12893
  createWorkspacesTable,
12894
+ dropPluginDeploymentAuthToken,
12696
12895
  enforceUniqueEvalProjectName,
12697
12896
  evalMigrations,
12698
12897
  mapRowToRunStep,