@axiom-lattice/pg-stores 3.0.0 → 3.0.2

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
@@ -1,8 +1,8 @@
1
1
  // src/index.ts
2
- import { Pool as Pool26 } from "pg";
2
+ import { Pool as Pool27 } from "pg";
3
3
 
4
4
  // src/createPgStoreConfig.ts
5
- import { Pool as Pool23 } from "pg";
5
+ import { Pool as Pool24 } from "pg";
6
6
 
7
7
  // src/migrations/migration.ts
8
8
  var MigrationManager = class {
@@ -5960,8 +5960,232 @@ var PostgreSQLA2AApiKeyStore = class {
5960
5960
  }
5961
5961
  };
5962
5962
 
5963
- // src/stores/PostgreSQLScheduleStorage.ts
5963
+ // src/stores/PostgreSQLAgentWebAppStore.ts
5964
+ import { randomUUID as randomUUID2 } from "crypto";
5964
5965
  import { Pool as Pool17 } from "pg";
5966
+
5967
+ // src/migrations/agent_web_apps_migration.ts
5968
+ var createAgentWebAppsTable = {
5969
+ version: 169,
5970
+ name: "create_agent_web_apps_table",
5971
+ up: async (client) => {
5972
+ await client.query(`
5973
+ CREATE TABLE IF NOT EXISTS lattice_agent_web_apps (
5974
+ id VARCHAR(255) PRIMARY KEY,
5975
+ tenant_id VARCHAR(255) NOT NULL,
5976
+ assistant_id VARCHAR(255) NOT NULL,
5977
+ name VARCHAR(255) NOT NULL,
5978
+ description TEXT,
5979
+ status VARCHAR(32) NOT NULL DEFAULT 'draft'
5980
+ CONSTRAINT chk_lattice_agent_web_apps_status CHECK (status IN ('draft', 'active', 'disabled')),
5981
+ integration JSONB NOT NULL,
5982
+ scope JSONB NOT NULL,
5983
+ features JSONB NOT NULL,
5984
+ appearance JSONB NOT NULL DEFAULT '{}'::jsonb,
5985
+ created_at TIMESTAMPTZ NOT NULL DEFAULT date_trunc('milliseconds', NOW()),
5986
+ updated_at TIMESTAMPTZ NOT NULL DEFAULT date_trunc('milliseconds', NOW())
5987
+ )
5988
+ `);
5989
+ await client.query(`
5990
+ CREATE INDEX IF NOT EXISTS idx_lattice_agent_web_apps_tenant_assistant
5991
+ ON lattice_agent_web_apps(tenant_id, assistant_id)
5992
+ `);
5993
+ },
5994
+ down: async (client) => {
5995
+ await client.query(
5996
+ "DROP INDEX IF EXISTS idx_lattice_agent_web_apps_tenant_assistant"
5997
+ );
5998
+ await client.query("DROP TABLE IF EXISTS lattice_agent_web_apps");
5999
+ }
6000
+ };
6001
+
6002
+ // src/stores/PostgreSQLAgentWebAppStore.ts
6003
+ function isRecord(value) {
6004
+ return typeof value === "object" && value !== null && !Array.isArray(value);
6005
+ }
6006
+ function isStringArray(value) {
6007
+ return Array.isArray(value) && value.every((item) => typeof item === "string");
6008
+ }
6009
+ function isIntegration(value) {
6010
+ return isRecord(value) && value.type === "react_sdk";
6011
+ }
6012
+ function isScope(value) {
6013
+ return isRecord(value) && typeof value.defaultProjectId === "string" && isStringArray(value.allowedProjectIds) && (value.defaultModelKey === void 0 || typeof value.defaultModelKey === "string") && (value.allowedModelKeys === void 0 || isStringArray(value.allowedModelKeys));
6014
+ }
6015
+ function isFeatures(value) {
6016
+ return isRecord(value) && typeof value.projectSelector === "boolean" && typeof value.modelSelector === "boolean" && typeof value.threadManagement === "boolean" && typeof value.attachments === "boolean" && typeof value.hitl === "boolean" && typeof value.genUI === "boolean";
6017
+ }
6018
+ function isAppearance(value) {
6019
+ return isRecord(value) && (value.title === void 0 || typeof value.title === "string") && (value.welcomeMessage === void 0 || typeof value.welcomeMessage === "string") && (value.primaryColor === void 0 || typeof value.primaryColor === "string");
6020
+ }
6021
+ function isStatus(value) {
6022
+ return value === "draft" || value === "active" || value === "disabled";
6023
+ }
6024
+ function mapRow(row) {
6025
+ if (!isStatus(row.status) || !isIntegration(row.integration) || !isScope(row.scope) || !isFeatures(row.features) || !isAppearance(row.appearance)) {
6026
+ throw new Error(`Invalid agent web app row: ${row.id}`);
6027
+ }
6028
+ return {
6029
+ id: row.id,
6030
+ tenantId: row.tenant_id,
6031
+ assistantId: row.assistant_id,
6032
+ name: row.name,
6033
+ description: row.description ?? void 0,
6034
+ status: row.status,
6035
+ integration: row.integration,
6036
+ scope: row.scope,
6037
+ features: row.features,
6038
+ appearance: row.appearance,
6039
+ createdAt: row.created_at,
6040
+ updatedAt: row.updated_at
6041
+ };
6042
+ }
6043
+ var PostgreSQLAgentWebAppStore = class {
6044
+ constructor(options) {
6045
+ this.initialized = false;
6046
+ this.ownsPool = true;
6047
+ this.initPromise = null;
6048
+ if (options.pool) {
6049
+ this.pool = options.pool;
6050
+ this.ownsPool = false;
6051
+ this.initialized = true;
6052
+ return;
6053
+ }
6054
+ this.pool = typeof options.poolConfig === "string" ? new Pool17({ connectionString: options.poolConfig }) : options.poolConfig ? new Pool17(options.poolConfig) : (() => {
6055
+ throw new Error("Either pool or poolConfig must be provided");
6056
+ })();
6057
+ this.migrationManager = new MigrationManager(this.pool);
6058
+ this.migrationManager.register(createAgentWebAppsTable);
6059
+ if (options.autoMigrate !== false) {
6060
+ this.startInitialization();
6061
+ }
6062
+ }
6063
+ async initialize() {
6064
+ if (this.initialized) return;
6065
+ if (this.initPromise) return this.initPromise;
6066
+ return this.startInitialization();
6067
+ }
6068
+ startInitialization() {
6069
+ this.initPromise = this.migrationManager.migrate().then(() => {
6070
+ this.initialized = true;
6071
+ });
6072
+ void this.initPromise.catch(() => void 0);
6073
+ return this.initPromise;
6074
+ }
6075
+ async dispose() {
6076
+ if (this.ownsPool) await this.pool.end();
6077
+ }
6078
+ async ensureInitialized() {
6079
+ if (!this.initialized) await this.initialize();
6080
+ }
6081
+ async list(tenantId, assistantId) {
6082
+ await this.ensureInitialized();
6083
+ const result = assistantId === void 0 ? await this.pool.query(
6084
+ `SELECT * FROM lattice_agent_web_apps
6085
+ WHERE tenant_id = $1
6086
+ ORDER BY created_at DESC, id DESC`,
6087
+ [tenantId]
6088
+ ) : await this.pool.query(
6089
+ `SELECT * FROM lattice_agent_web_apps
6090
+ WHERE tenant_id = $1 AND assistant_id = $2
6091
+ ORDER BY created_at DESC, id DESC`,
6092
+ [tenantId, assistantId]
6093
+ );
6094
+ return result.rows.map(mapRow);
6095
+ }
6096
+ async getById(tenantId, webAppId) {
6097
+ await this.ensureInitialized();
6098
+ const result = await this.pool.query(
6099
+ `SELECT * FROM lattice_agent_web_apps
6100
+ WHERE tenant_id = $1 AND id = $2`,
6101
+ [tenantId, webAppId]
6102
+ );
6103
+ return result.rows[0] ? mapRow(result.rows[0]) : null;
6104
+ }
6105
+ async findById(webAppId) {
6106
+ await this.ensureInitialized();
6107
+ const result = await this.pool.query(
6108
+ `SELECT * FROM lattice_agent_web_apps
6109
+ WHERE id = $1`,
6110
+ [webAppId]
6111
+ );
6112
+ return result.rows[0] ? mapRow(result.rows[0]) : null;
6113
+ }
6114
+ async create(tenantId, input) {
6115
+ await this.ensureInitialized();
6116
+ const id = `webapp_${randomUUID2().replace(/-/g, "")}`;
6117
+ const result = await this.pool.query(
6118
+ `INSERT INTO lattice_agent_web_apps
6119
+ (id, tenant_id, assistant_id, name, description, status, integration, scope, features, appearance)
6120
+ VALUES ($1, $2, $3, $4, $5, $6, $7::jsonb, $8::jsonb, $9::jsonb, $10::jsonb)
6121
+ RETURNING *`,
6122
+ [
6123
+ id,
6124
+ tenantId,
6125
+ input.assistantId,
6126
+ input.name,
6127
+ input.description ?? null,
6128
+ "draft",
6129
+ JSON.stringify(input.integration),
6130
+ JSON.stringify(input.scope),
6131
+ JSON.stringify(input.features),
6132
+ JSON.stringify(input.appearance)
6133
+ ]
6134
+ );
6135
+ return mapRow(result.rows[0]);
6136
+ }
6137
+ async update(tenantId, webAppId, patch, options) {
6138
+ await this.ensureInitialized();
6139
+ const assignments = [];
6140
+ const values = [];
6141
+ const add = (column, value) => {
6142
+ values.push(value);
6143
+ assignments.push(`${column} = $${values.length}`);
6144
+ };
6145
+ if (patch.name !== void 0) add("name", patch.name);
6146
+ if (Object.prototype.hasOwnProperty.call(patch, "description")) {
6147
+ add("description", patch.description ?? null);
6148
+ }
6149
+ if (patch.scope !== void 0) {
6150
+ add("scope", JSON.stringify(patch.scope));
6151
+ }
6152
+ if (patch.features !== void 0) {
6153
+ add("features", JSON.stringify(patch.features));
6154
+ }
6155
+ if (patch.appearance !== void 0) {
6156
+ add("appearance", JSON.stringify(patch.appearance));
6157
+ }
6158
+ if (patch.status !== void 0) add("status", patch.status);
6159
+ if (assignments.length === 0) return this.getById(tenantId, webAppId);
6160
+ values.push(tenantId, webAppId);
6161
+ const tenantParam = values.length - 1;
6162
+ const idParam = values.length;
6163
+ const expectedUpdatedAtClause = options?.expectedUpdatedAt ? ` AND date_trunc('milliseconds', updated_at) = $${values.push(options.expectedUpdatedAt)}` : "";
6164
+ const result = await this.pool.query(
6165
+ `UPDATE lattice_agent_web_apps
6166
+ SET ${assignments.join(", ")}, updated_at = GREATEST(
6167
+ date_trunc('milliseconds', clock_timestamp()),
6168
+ updated_at + interval '1 millisecond'
6169
+ )
6170
+ WHERE tenant_id = $${tenantParam} AND id = $${idParam}${expectedUpdatedAtClause}
6171
+ RETURNING *`,
6172
+ values
6173
+ );
6174
+ return result.rows[0] ? mapRow(result.rows[0]) : null;
6175
+ }
6176
+ async delete(tenantId, webAppId) {
6177
+ await this.ensureInitialized();
6178
+ const result = await this.pool.query(
6179
+ `DELETE FROM lattice_agent_web_apps
6180
+ WHERE tenant_id = $1 AND id = $2`,
6181
+ [tenantId, webAppId]
6182
+ );
6183
+ return result.rowCount === 1;
6184
+ }
6185
+ };
6186
+
6187
+ // src/stores/PostgreSQLScheduleStorage.ts
6188
+ import { Pool as Pool18 } from "pg";
5965
6189
  import {
5966
6190
  ScheduledTaskStatus
5967
6191
  } from "@axiom-lattice/protocols";
@@ -6138,9 +6362,9 @@ var PostgreSQLScheduleStorage = class {
6138
6362
  return;
6139
6363
  }
6140
6364
  if (typeof options.poolConfig === "string") {
6141
- this.pool = new Pool17({ connectionString: options.poolConfig });
6365
+ this.pool = new Pool18({ connectionString: options.poolConfig });
6142
6366
  } else if (options.poolConfig) {
6143
- this.pool = new Pool17(options.poolConfig);
6367
+ this.pool = new Pool18(options.poolConfig);
6144
6368
  } else {
6145
6369
  throw new Error("Either pool or poolConfig must be provided");
6146
6370
  }
@@ -6578,7 +6802,7 @@ var PostgreSQLScheduleStorage = class {
6578
6802
  };
6579
6803
 
6580
6804
  // src/stores/PostgreSQLTaskStore.ts
6581
- import { Pool as Pool18 } from "pg";
6805
+ import { Pool as Pool19 } from "pg";
6582
6806
 
6583
6807
  // src/migrations/task_migration.ts
6584
6808
  var createTasksTable = {
@@ -6768,9 +6992,9 @@ var PostgreSQLTaskStore = class {
6768
6992
  return;
6769
6993
  }
6770
6994
  if (typeof options.poolConfig === "string") {
6771
- this.pool = new Pool18({ connectionString: options.poolConfig });
6995
+ this.pool = new Pool19({ connectionString: options.poolConfig });
6772
6996
  } else if (options.poolConfig) {
6773
- this.pool = new Pool18(options.poolConfig);
6997
+ this.pool = new Pool19(options.poolConfig);
6774
6998
  } else {
6775
6999
  throw new Error("Either pool or poolConfig must be provided");
6776
7000
  }
@@ -7516,7 +7740,7 @@ var PostgreSQLTaskWorkItemStore = class {
7516
7740
  };
7517
7741
 
7518
7742
  // src/stores/MenuStore.ts
7519
- import { Pool as Pool19 } from "pg";
7743
+ import { Pool as Pool20 } from "pg";
7520
7744
 
7521
7745
  // src/migrations/menu_items_migration.ts
7522
7746
  var createMenuItemsTable = {
@@ -7593,7 +7817,7 @@ var MenuStore = class {
7593
7817
  this.initialized = true;
7594
7818
  return;
7595
7819
  }
7596
- this.pool = typeof options.poolConfig === "string" ? new Pool19({ connectionString: options.poolConfig }) : options.poolConfig ? new Pool19(options.poolConfig) : (() => {
7820
+ this.pool = typeof options.poolConfig === "string" ? new Pool20({ connectionString: options.poolConfig }) : options.poolConfig ? new Pool20(options.poolConfig) : (() => {
7597
7821
  throw new Error("Either pool or poolConfig must be provided");
7598
7822
  })();
7599
7823
  this.migrationManager = new MigrationManager(this.pool);
@@ -7748,7 +7972,7 @@ var MenuStore = class {
7748
7972
  };
7749
7973
 
7750
7974
  // src/stores/PostgresSharedResourceStore.ts
7751
- import { Pool as Pool20 } from "pg";
7975
+ import { Pool as Pool21 } from "pg";
7752
7976
 
7753
7977
  // src/migrations/shared_resources_migration.ts
7754
7978
  var createSharedResourcesTable = {
@@ -7802,7 +8026,7 @@ var PostgresSharedResourceStore = class {
7802
8026
  this.initialized = true;
7803
8027
  return;
7804
8028
  }
7805
- this.pool = typeof options.poolConfig === "string" ? new Pool20({ connectionString: options.poolConfig }) : options.poolConfig ? new Pool20(options.poolConfig) : (() => {
8029
+ this.pool = typeof options.poolConfig === "string" ? new Pool21({ connectionString: options.poolConfig }) : options.poolConfig ? new Pool21(options.poolConfig) : (() => {
7806
8030
  throw new Error("Either pool or poolConfig must be provided");
7807
8031
  })();
7808
8032
  this.migrationManager = new MigrationManager(this.pool);
@@ -7971,7 +8195,7 @@ var PostgresSharedResourceStore = class {
7971
8195
  };
7972
8196
 
7973
8197
  // src/stores/PostgreSQLCollectionStore.ts
7974
- import { Pool as Pool21 } from "pg";
8198
+ import { Pool as Pool22 } from "pg";
7975
8199
  var PostgreSQLCollectionStore = class {
7976
8200
  constructor(options) {
7977
8201
  this.initialized = false;
@@ -7984,9 +8208,9 @@ var PostgreSQLCollectionStore = class {
7984
8208
  return;
7985
8209
  }
7986
8210
  if (typeof options.poolConfig === "string") {
7987
- this.pool = new Pool21({ connectionString: options.poolConfig });
8211
+ this.pool = new Pool22({ connectionString: options.poolConfig });
7988
8212
  } else if (options.poolConfig) {
7989
- this.pool = new Pool21(options.poolConfig);
8213
+ this.pool = new Pool22(options.poolConfig);
7990
8214
  } else {
7991
8215
  throw new Error("Either pool or poolConfig must be provided");
7992
8216
  }
@@ -8101,7 +8325,7 @@ var PostgreSQLCollectionStore = class {
8101
8325
  import { PostgresSaver } from "@langchain/langgraph-checkpoint-postgres";
8102
8326
 
8103
8327
  // src/PGVectorStoreProvider.ts
8104
- import { Pool as Pool22 } from "pg";
8328
+ import { Pool as Pool23 } from "pg";
8105
8329
  import { PGVectorStore } from "@langchain/community/vectorstores/pgvector";
8106
8330
  import { Document } from "@langchain/core/documents";
8107
8331
  import { embeddingsLatticeManager } from "@axiom-lattice/core";
@@ -8175,7 +8399,7 @@ var PGVectorStoreProvider = class {
8175
8399
  }
8176
8400
  };
8177
8401
  function createPGVectorStoreProvider(connectionString) {
8178
- const pool = new Pool22({ connectionString });
8402
+ const pool = new Pool23({ connectionString });
8179
8403
  return {
8180
8404
  provider: new PGVectorStoreProvider(pool, connectionString),
8181
8405
  pool
@@ -8526,7 +8750,7 @@ var addTaskWorkItemEventKeyMigration = {
8526
8750
 
8527
8751
  // src/createPgStoreConfig.ts
8528
8752
  async function createPgStoreConfig(connectionString) {
8529
- const pool = new Pool23({ connectionString });
8753
+ const pool = new Pool24({ connectionString });
8530
8754
  const mm = new MigrationManager(pool);
8531
8755
  mm.register(createThreadsTable);
8532
8756
  mm.register(createScheduledTasksTable);
@@ -8580,6 +8804,7 @@ async function createPgStoreConfig(connectionString) {
8580
8804
  mm.register(addProjectKindColumn);
8581
8805
  mm.register(addA2AKeyAssistantIds);
8582
8806
  mm.register(addTaskWorkItemEventKeyMigration);
8807
+ mm.register(createAgentWebAppsTable);
8583
8808
  await mm.migrate();
8584
8809
  const checkpoint = PostgresSaver.fromConnString(connectionString);
8585
8810
  checkpoint.setup().catch((err) => {
@@ -8607,6 +8832,7 @@ async function createPgStoreConfig(connectionString) {
8607
8832
  task: new PostgreSQLTaskStore(opts),
8608
8833
  taskWorkItem: taskWorkItemStore,
8609
8834
  a2aApiKey: new PostgreSQLA2AApiKeyStore(opts),
8835
+ agentWebApp: new PostgreSQLAgentWebAppStore(opts),
8610
8836
  schedule: new PostgreSQLScheduleStorage(opts),
8611
8837
  menu: new MenuStore(opts),
8612
8838
  sharedResource: new PostgresSharedResourceStore(opts),
@@ -8617,7 +8843,7 @@ async function createPgStoreConfig(connectionString) {
8617
8843
  }
8618
8844
 
8619
8845
  // src/stores/PostgreSQLSkillStore.ts
8620
- import { Pool as Pool24 } from "pg";
8846
+ import { Pool as Pool25 } from "pg";
8621
8847
  var PostgreSQLSkillStore = class {
8622
8848
  constructor(options) {
8623
8849
  this.initialized = false;
@@ -8630,9 +8856,9 @@ var PostgreSQLSkillStore = class {
8630
8856
  return;
8631
8857
  }
8632
8858
  if (typeof options.poolConfig === "string") {
8633
- this.pool = new Pool24({ connectionString: options.poolConfig });
8859
+ this.pool = new Pool25({ connectionString: options.poolConfig });
8634
8860
  } else if (options.poolConfig) {
8635
- this.pool = new Pool24(options.poolConfig);
8861
+ this.pool = new Pool25(options.poolConfig);
8636
8862
  } else {
8637
8863
  throw new Error("Either pool or poolConfig must be provided");
8638
8864
  }
@@ -8933,7 +9159,7 @@ var PostgreSQLSkillStore = class {
8933
9159
  };
8934
9160
 
8935
9161
  // src/stores/ChannelIdentityMappingStore.ts
8936
- import { Pool as Pool25 } from "pg";
9162
+ import { Pool as Pool26 } from "pg";
8937
9163
  var ChannelIdentityMappingStore = class {
8938
9164
  constructor(options) {
8939
9165
  this.initialized = false;
@@ -8945,7 +9171,7 @@ var ChannelIdentityMappingStore = class {
8945
9171
  this.initialized = true;
8946
9172
  return;
8947
9173
  }
8948
- this.pool = typeof options.poolConfig === "string" ? new Pool25({ connectionString: options.poolConfig }) : options.poolConfig ? new Pool25(options.poolConfig) : (() => {
9174
+ this.pool = typeof options.poolConfig === "string" ? new Pool26({ connectionString: options.poolConfig }) : options.poolConfig ? new Pool26(options.poolConfig) : (() => {
8949
9175
  throw new Error("Either pool or poolConfig must be provided");
8950
9176
  })();
8951
9177
  this.migrationManager = new MigrationManager(this.pool);
@@ -9169,8 +9395,9 @@ export {
9169
9395
  MenuStore,
9170
9396
  MigrationManager,
9171
9397
  PGVectorStoreProvider,
9172
- Pool26 as Pool,
9398
+ Pool27 as Pool,
9173
9399
  PostgreSQLA2AApiKeyStore,
9400
+ PostgreSQLAgentWebAppStore,
9174
9401
  PostgreSQLAssistantStore,
9175
9402
  PostgreSQLChannelInstallationStore,
9176
9403
  PostgreSQLCollectionStore,
@@ -9208,6 +9435,7 @@ export {
9208
9435
  changeSkillPrimaryKey,
9209
9436
  changeThreadPrimaryKey,
9210
9437
  createA2AApiKeysTable,
9438
+ createAgentWebAppsTable,
9211
9439
  createAssistantsTable,
9212
9440
  createChannelBindingsTable,
9213
9441
  createChannelIdentityMappingTables,