@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.js CHANGED
@@ -35,8 +35,9 @@ __export(index_exports, {
35
35
  MenuStore: () => MenuStore,
36
36
  MigrationManager: () => MigrationManager,
37
37
  PGVectorStoreProvider: () => PGVectorStoreProvider,
38
- Pool: () => import_pg26.Pool,
38
+ Pool: () => import_pg27.Pool,
39
39
  PostgreSQLA2AApiKeyStore: () => PostgreSQLA2AApiKeyStore,
40
+ PostgreSQLAgentWebAppStore: () => PostgreSQLAgentWebAppStore,
40
41
  PostgreSQLAssistantStore: () => PostgreSQLAssistantStore,
41
42
  PostgreSQLChannelInstallationStore: () => PostgreSQLChannelInstallationStore,
42
43
  PostgreSQLCollectionStore: () => PostgreSQLCollectionStore,
@@ -74,6 +75,7 @@ __export(index_exports, {
74
75
  changeSkillPrimaryKey: () => changeSkillPrimaryKey,
75
76
  changeThreadPrimaryKey: () => changeThreadPrimaryKey,
76
77
  createA2AApiKeysTable: () => createA2AApiKeysTable,
78
+ createAgentWebAppsTable: () => createAgentWebAppsTable,
77
79
  createAssistantsTable: () => createAssistantsTable,
78
80
  createChannelBindingsTable: () => createChannelBindingsTable,
79
81
  createChannelIdentityMappingTables: () => createChannelIdentityMappingTables,
@@ -107,10 +109,10 @@ __export(index_exports, {
107
109
  safeParse: () => safeParse
108
110
  });
109
111
  module.exports = __toCommonJS(index_exports);
110
- var import_pg26 = require("pg");
112
+ var import_pg27 = require("pg");
111
113
 
112
114
  // src/createPgStoreConfig.ts
113
- var import_pg23 = require("pg");
115
+ var import_pg24 = require("pg");
114
116
 
115
117
  // src/migrations/migration.ts
116
118
  var MigrationManager = class {
@@ -6068,8 +6070,232 @@ var PostgreSQLA2AApiKeyStore = class {
6068
6070
  }
6069
6071
  };
6070
6072
 
6071
- // src/stores/PostgreSQLScheduleStorage.ts
6073
+ // src/stores/PostgreSQLAgentWebAppStore.ts
6074
+ var import_crypto3 = require("crypto");
6072
6075
  var import_pg17 = require("pg");
6076
+
6077
+ // src/migrations/agent_web_apps_migration.ts
6078
+ var createAgentWebAppsTable = {
6079
+ version: 169,
6080
+ name: "create_agent_web_apps_table",
6081
+ up: async (client) => {
6082
+ await client.query(`
6083
+ CREATE TABLE IF NOT EXISTS lattice_agent_web_apps (
6084
+ id VARCHAR(255) PRIMARY KEY,
6085
+ tenant_id VARCHAR(255) NOT NULL,
6086
+ assistant_id VARCHAR(255) NOT NULL,
6087
+ name VARCHAR(255) NOT NULL,
6088
+ description TEXT,
6089
+ status VARCHAR(32) NOT NULL DEFAULT 'draft'
6090
+ CONSTRAINT chk_lattice_agent_web_apps_status CHECK (status IN ('draft', 'active', 'disabled')),
6091
+ integration JSONB NOT NULL,
6092
+ scope JSONB NOT NULL,
6093
+ features JSONB NOT NULL,
6094
+ appearance JSONB NOT NULL DEFAULT '{}'::jsonb,
6095
+ created_at TIMESTAMPTZ NOT NULL DEFAULT date_trunc('milliseconds', NOW()),
6096
+ updated_at TIMESTAMPTZ NOT NULL DEFAULT date_trunc('milliseconds', NOW())
6097
+ )
6098
+ `);
6099
+ await client.query(`
6100
+ CREATE INDEX IF NOT EXISTS idx_lattice_agent_web_apps_tenant_assistant
6101
+ ON lattice_agent_web_apps(tenant_id, assistant_id)
6102
+ `);
6103
+ },
6104
+ down: async (client) => {
6105
+ await client.query(
6106
+ "DROP INDEX IF EXISTS idx_lattice_agent_web_apps_tenant_assistant"
6107
+ );
6108
+ await client.query("DROP TABLE IF EXISTS lattice_agent_web_apps");
6109
+ }
6110
+ };
6111
+
6112
+ // src/stores/PostgreSQLAgentWebAppStore.ts
6113
+ function isRecord(value) {
6114
+ return typeof value === "object" && value !== null && !Array.isArray(value);
6115
+ }
6116
+ function isStringArray(value) {
6117
+ return Array.isArray(value) && value.every((item) => typeof item === "string");
6118
+ }
6119
+ function isIntegration(value) {
6120
+ return isRecord(value) && value.type === "react_sdk";
6121
+ }
6122
+ function isScope(value) {
6123
+ 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));
6124
+ }
6125
+ function isFeatures(value) {
6126
+ 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";
6127
+ }
6128
+ function isAppearance(value) {
6129
+ 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");
6130
+ }
6131
+ function isStatus(value) {
6132
+ return value === "draft" || value === "active" || value === "disabled";
6133
+ }
6134
+ function mapRow(row) {
6135
+ if (!isStatus(row.status) || !isIntegration(row.integration) || !isScope(row.scope) || !isFeatures(row.features) || !isAppearance(row.appearance)) {
6136
+ throw new Error(`Invalid agent web app row: ${row.id}`);
6137
+ }
6138
+ return {
6139
+ id: row.id,
6140
+ tenantId: row.tenant_id,
6141
+ assistantId: row.assistant_id,
6142
+ name: row.name,
6143
+ description: row.description ?? void 0,
6144
+ status: row.status,
6145
+ integration: row.integration,
6146
+ scope: row.scope,
6147
+ features: row.features,
6148
+ appearance: row.appearance,
6149
+ createdAt: row.created_at,
6150
+ updatedAt: row.updated_at
6151
+ };
6152
+ }
6153
+ var PostgreSQLAgentWebAppStore = class {
6154
+ constructor(options) {
6155
+ this.initialized = false;
6156
+ this.ownsPool = true;
6157
+ this.initPromise = null;
6158
+ if (options.pool) {
6159
+ this.pool = options.pool;
6160
+ this.ownsPool = false;
6161
+ this.initialized = true;
6162
+ return;
6163
+ }
6164
+ this.pool = typeof options.poolConfig === "string" ? new import_pg17.Pool({ connectionString: options.poolConfig }) : options.poolConfig ? new import_pg17.Pool(options.poolConfig) : (() => {
6165
+ throw new Error("Either pool or poolConfig must be provided");
6166
+ })();
6167
+ this.migrationManager = new MigrationManager(this.pool);
6168
+ this.migrationManager.register(createAgentWebAppsTable);
6169
+ if (options.autoMigrate !== false) {
6170
+ this.startInitialization();
6171
+ }
6172
+ }
6173
+ async initialize() {
6174
+ if (this.initialized) return;
6175
+ if (this.initPromise) return this.initPromise;
6176
+ return this.startInitialization();
6177
+ }
6178
+ startInitialization() {
6179
+ this.initPromise = this.migrationManager.migrate().then(() => {
6180
+ this.initialized = true;
6181
+ });
6182
+ void this.initPromise.catch(() => void 0);
6183
+ return this.initPromise;
6184
+ }
6185
+ async dispose() {
6186
+ if (this.ownsPool) await this.pool.end();
6187
+ }
6188
+ async ensureInitialized() {
6189
+ if (!this.initialized) await this.initialize();
6190
+ }
6191
+ async list(tenantId, assistantId) {
6192
+ await this.ensureInitialized();
6193
+ const result = assistantId === void 0 ? await this.pool.query(
6194
+ `SELECT * FROM lattice_agent_web_apps
6195
+ WHERE tenant_id = $1
6196
+ ORDER BY created_at DESC, id DESC`,
6197
+ [tenantId]
6198
+ ) : await this.pool.query(
6199
+ `SELECT * FROM lattice_agent_web_apps
6200
+ WHERE tenant_id = $1 AND assistant_id = $2
6201
+ ORDER BY created_at DESC, id DESC`,
6202
+ [tenantId, assistantId]
6203
+ );
6204
+ return result.rows.map(mapRow);
6205
+ }
6206
+ async getById(tenantId, webAppId) {
6207
+ await this.ensureInitialized();
6208
+ const result = await this.pool.query(
6209
+ `SELECT * FROM lattice_agent_web_apps
6210
+ WHERE tenant_id = $1 AND id = $2`,
6211
+ [tenantId, webAppId]
6212
+ );
6213
+ return result.rows[0] ? mapRow(result.rows[0]) : null;
6214
+ }
6215
+ async findById(webAppId) {
6216
+ await this.ensureInitialized();
6217
+ const result = await this.pool.query(
6218
+ `SELECT * FROM lattice_agent_web_apps
6219
+ WHERE id = $1`,
6220
+ [webAppId]
6221
+ );
6222
+ return result.rows[0] ? mapRow(result.rows[0]) : null;
6223
+ }
6224
+ async create(tenantId, input) {
6225
+ await this.ensureInitialized();
6226
+ const id = `webapp_${(0, import_crypto3.randomUUID)().replace(/-/g, "")}`;
6227
+ const result = await this.pool.query(
6228
+ `INSERT INTO lattice_agent_web_apps
6229
+ (id, tenant_id, assistant_id, name, description, status, integration, scope, features, appearance)
6230
+ VALUES ($1, $2, $3, $4, $5, $6, $7::jsonb, $8::jsonb, $9::jsonb, $10::jsonb)
6231
+ RETURNING *`,
6232
+ [
6233
+ id,
6234
+ tenantId,
6235
+ input.assistantId,
6236
+ input.name,
6237
+ input.description ?? null,
6238
+ "draft",
6239
+ JSON.stringify(input.integration),
6240
+ JSON.stringify(input.scope),
6241
+ JSON.stringify(input.features),
6242
+ JSON.stringify(input.appearance)
6243
+ ]
6244
+ );
6245
+ return mapRow(result.rows[0]);
6246
+ }
6247
+ async update(tenantId, webAppId, patch, options) {
6248
+ await this.ensureInitialized();
6249
+ const assignments = [];
6250
+ const values = [];
6251
+ const add = (column, value) => {
6252
+ values.push(value);
6253
+ assignments.push(`${column} = $${values.length}`);
6254
+ };
6255
+ if (patch.name !== void 0) add("name", patch.name);
6256
+ if (Object.prototype.hasOwnProperty.call(patch, "description")) {
6257
+ add("description", patch.description ?? null);
6258
+ }
6259
+ if (patch.scope !== void 0) {
6260
+ add("scope", JSON.stringify(patch.scope));
6261
+ }
6262
+ if (patch.features !== void 0) {
6263
+ add("features", JSON.stringify(patch.features));
6264
+ }
6265
+ if (patch.appearance !== void 0) {
6266
+ add("appearance", JSON.stringify(patch.appearance));
6267
+ }
6268
+ if (patch.status !== void 0) add("status", patch.status);
6269
+ if (assignments.length === 0) return this.getById(tenantId, webAppId);
6270
+ values.push(tenantId, webAppId);
6271
+ const tenantParam = values.length - 1;
6272
+ const idParam = values.length;
6273
+ const expectedUpdatedAtClause = options?.expectedUpdatedAt ? ` AND date_trunc('milliseconds', updated_at) = $${values.push(options.expectedUpdatedAt)}` : "";
6274
+ const result = await this.pool.query(
6275
+ `UPDATE lattice_agent_web_apps
6276
+ SET ${assignments.join(", ")}, updated_at = GREATEST(
6277
+ date_trunc('milliseconds', clock_timestamp()),
6278
+ updated_at + interval '1 millisecond'
6279
+ )
6280
+ WHERE tenant_id = $${tenantParam} AND id = $${idParam}${expectedUpdatedAtClause}
6281
+ RETURNING *`,
6282
+ values
6283
+ );
6284
+ return result.rows[0] ? mapRow(result.rows[0]) : null;
6285
+ }
6286
+ async delete(tenantId, webAppId) {
6287
+ await this.ensureInitialized();
6288
+ const result = await this.pool.query(
6289
+ `DELETE FROM lattice_agent_web_apps
6290
+ WHERE tenant_id = $1 AND id = $2`,
6291
+ [tenantId, webAppId]
6292
+ );
6293
+ return result.rowCount === 1;
6294
+ }
6295
+ };
6296
+
6297
+ // src/stores/PostgreSQLScheduleStorage.ts
6298
+ var import_pg18 = require("pg");
6073
6299
  var import_protocols = require("@axiom-lattice/protocols");
6074
6300
 
6075
6301
  // src/migrations/schedule_migrations.ts
@@ -6244,9 +6470,9 @@ var PostgreSQLScheduleStorage = class {
6244
6470
  return;
6245
6471
  }
6246
6472
  if (typeof options.poolConfig === "string") {
6247
- this.pool = new import_pg17.Pool({ connectionString: options.poolConfig });
6473
+ this.pool = new import_pg18.Pool({ connectionString: options.poolConfig });
6248
6474
  } else if (options.poolConfig) {
6249
- this.pool = new import_pg17.Pool(options.poolConfig);
6475
+ this.pool = new import_pg18.Pool(options.poolConfig);
6250
6476
  } else {
6251
6477
  throw new Error("Either pool or poolConfig must be provided");
6252
6478
  }
@@ -6684,7 +6910,7 @@ var PostgreSQLScheduleStorage = class {
6684
6910
  };
6685
6911
 
6686
6912
  // src/stores/PostgreSQLTaskStore.ts
6687
- var import_pg18 = require("pg");
6913
+ var import_pg19 = require("pg");
6688
6914
 
6689
6915
  // src/migrations/task_migration.ts
6690
6916
  var createTasksTable = {
@@ -6874,9 +7100,9 @@ var PostgreSQLTaskStore = class {
6874
7100
  return;
6875
7101
  }
6876
7102
  if (typeof options.poolConfig === "string") {
6877
- this.pool = new import_pg18.Pool({ connectionString: options.poolConfig });
7103
+ this.pool = new import_pg19.Pool({ connectionString: options.poolConfig });
6878
7104
  } else if (options.poolConfig) {
6879
- this.pool = new import_pg18.Pool(options.poolConfig);
7105
+ this.pool = new import_pg19.Pool(options.poolConfig);
6880
7106
  } else {
6881
7107
  throw new Error("Either pool or poolConfig must be provided");
6882
7108
  }
@@ -7622,7 +7848,7 @@ var PostgreSQLTaskWorkItemStore = class {
7622
7848
  };
7623
7849
 
7624
7850
  // src/stores/MenuStore.ts
7625
- var import_pg19 = require("pg");
7851
+ var import_pg20 = require("pg");
7626
7852
 
7627
7853
  // src/migrations/menu_items_migration.ts
7628
7854
  var createMenuItemsTable = {
@@ -7699,7 +7925,7 @@ var MenuStore = class {
7699
7925
  this.initialized = true;
7700
7926
  return;
7701
7927
  }
7702
- this.pool = typeof options.poolConfig === "string" ? new import_pg19.Pool({ connectionString: options.poolConfig }) : options.poolConfig ? new import_pg19.Pool(options.poolConfig) : (() => {
7928
+ this.pool = typeof options.poolConfig === "string" ? new import_pg20.Pool({ connectionString: options.poolConfig }) : options.poolConfig ? new import_pg20.Pool(options.poolConfig) : (() => {
7703
7929
  throw new Error("Either pool or poolConfig must be provided");
7704
7930
  })();
7705
7931
  this.migrationManager = new MigrationManager(this.pool);
@@ -7854,7 +8080,7 @@ var MenuStore = class {
7854
8080
  };
7855
8081
 
7856
8082
  // src/stores/PostgresSharedResourceStore.ts
7857
- var import_pg20 = require("pg");
8083
+ var import_pg21 = require("pg");
7858
8084
 
7859
8085
  // src/migrations/shared_resources_migration.ts
7860
8086
  var createSharedResourcesTable = {
@@ -7908,7 +8134,7 @@ var PostgresSharedResourceStore = class {
7908
8134
  this.initialized = true;
7909
8135
  return;
7910
8136
  }
7911
- this.pool = typeof options.poolConfig === "string" ? new import_pg20.Pool({ connectionString: options.poolConfig }) : options.poolConfig ? new import_pg20.Pool(options.poolConfig) : (() => {
8137
+ this.pool = typeof options.poolConfig === "string" ? new import_pg21.Pool({ connectionString: options.poolConfig }) : options.poolConfig ? new import_pg21.Pool(options.poolConfig) : (() => {
7912
8138
  throw new Error("Either pool or poolConfig must be provided");
7913
8139
  })();
7914
8140
  this.migrationManager = new MigrationManager(this.pool);
@@ -8077,7 +8303,7 @@ var PostgresSharedResourceStore = class {
8077
8303
  };
8078
8304
 
8079
8305
  // src/stores/PostgreSQLCollectionStore.ts
8080
- var import_pg21 = require("pg");
8306
+ var import_pg22 = require("pg");
8081
8307
  var PostgreSQLCollectionStore = class {
8082
8308
  constructor(options) {
8083
8309
  this.initialized = false;
@@ -8090,9 +8316,9 @@ var PostgreSQLCollectionStore = class {
8090
8316
  return;
8091
8317
  }
8092
8318
  if (typeof options.poolConfig === "string") {
8093
- this.pool = new import_pg21.Pool({ connectionString: options.poolConfig });
8319
+ this.pool = new import_pg22.Pool({ connectionString: options.poolConfig });
8094
8320
  } else if (options.poolConfig) {
8095
- this.pool = new import_pg21.Pool(options.poolConfig);
8321
+ this.pool = new import_pg22.Pool(options.poolConfig);
8096
8322
  } else {
8097
8323
  throw new Error("Either pool or poolConfig must be provided");
8098
8324
  }
@@ -8207,7 +8433,7 @@ var PostgreSQLCollectionStore = class {
8207
8433
  var import_langgraph_checkpoint_postgres = require("@langchain/langgraph-checkpoint-postgres");
8208
8434
 
8209
8435
  // src/PGVectorStoreProvider.ts
8210
- var import_pg22 = require("pg");
8436
+ var import_pg23 = require("pg");
8211
8437
  var import_pgvector = require("@langchain/community/vectorstores/pgvector");
8212
8438
  var import_documents = require("@langchain/core/documents");
8213
8439
  var import_core6 = require("@axiom-lattice/core");
@@ -8281,7 +8507,7 @@ var PGVectorStoreProvider = class {
8281
8507
  }
8282
8508
  };
8283
8509
  function createPGVectorStoreProvider(connectionString) {
8284
- const pool = new import_pg22.Pool({ connectionString });
8510
+ const pool = new import_pg23.Pool({ connectionString });
8285
8511
  return {
8286
8512
  provider: new PGVectorStoreProvider(pool, connectionString),
8287
8513
  pool
@@ -8632,7 +8858,7 @@ var addTaskWorkItemEventKeyMigration = {
8632
8858
 
8633
8859
  // src/createPgStoreConfig.ts
8634
8860
  async function createPgStoreConfig(connectionString) {
8635
- const pool = new import_pg23.Pool({ connectionString });
8861
+ const pool = new import_pg24.Pool({ connectionString });
8636
8862
  const mm = new MigrationManager(pool);
8637
8863
  mm.register(createThreadsTable);
8638
8864
  mm.register(createScheduledTasksTable);
@@ -8686,6 +8912,7 @@ async function createPgStoreConfig(connectionString) {
8686
8912
  mm.register(addProjectKindColumn);
8687
8913
  mm.register(addA2AKeyAssistantIds);
8688
8914
  mm.register(addTaskWorkItemEventKeyMigration);
8915
+ mm.register(createAgentWebAppsTable);
8689
8916
  await mm.migrate();
8690
8917
  const checkpoint = import_langgraph_checkpoint_postgres.PostgresSaver.fromConnString(connectionString);
8691
8918
  checkpoint.setup().catch((err) => {
@@ -8713,6 +8940,7 @@ async function createPgStoreConfig(connectionString) {
8713
8940
  task: new PostgreSQLTaskStore(opts),
8714
8941
  taskWorkItem: taskWorkItemStore,
8715
8942
  a2aApiKey: new PostgreSQLA2AApiKeyStore(opts),
8943
+ agentWebApp: new PostgreSQLAgentWebAppStore(opts),
8716
8944
  schedule: new PostgreSQLScheduleStorage(opts),
8717
8945
  menu: new MenuStore(opts),
8718
8946
  sharedResource: new PostgresSharedResourceStore(opts),
@@ -8723,7 +8951,7 @@ async function createPgStoreConfig(connectionString) {
8723
8951
  }
8724
8952
 
8725
8953
  // src/stores/PostgreSQLSkillStore.ts
8726
- var import_pg24 = require("pg");
8954
+ var import_pg25 = require("pg");
8727
8955
  var PostgreSQLSkillStore = class {
8728
8956
  constructor(options) {
8729
8957
  this.initialized = false;
@@ -8736,9 +8964,9 @@ var PostgreSQLSkillStore = class {
8736
8964
  return;
8737
8965
  }
8738
8966
  if (typeof options.poolConfig === "string") {
8739
- this.pool = new import_pg24.Pool({ connectionString: options.poolConfig });
8967
+ this.pool = new import_pg25.Pool({ connectionString: options.poolConfig });
8740
8968
  } else if (options.poolConfig) {
8741
- this.pool = new import_pg24.Pool(options.poolConfig);
8969
+ this.pool = new import_pg25.Pool(options.poolConfig);
8742
8970
  } else {
8743
8971
  throw new Error("Either pool or poolConfig must be provided");
8744
8972
  }
@@ -9039,7 +9267,7 @@ var PostgreSQLSkillStore = class {
9039
9267
  };
9040
9268
 
9041
9269
  // src/stores/ChannelIdentityMappingStore.ts
9042
- var import_pg25 = require("pg");
9270
+ var import_pg26 = require("pg");
9043
9271
  var ChannelIdentityMappingStore = class {
9044
9272
  constructor(options) {
9045
9273
  this.initialized = false;
@@ -9051,7 +9279,7 @@ var ChannelIdentityMappingStore = class {
9051
9279
  this.initialized = true;
9052
9280
  return;
9053
9281
  }
9054
- this.pool = typeof options.poolConfig === "string" ? new import_pg25.Pool({ connectionString: options.poolConfig }) : options.poolConfig ? new import_pg25.Pool(options.poolConfig) : (() => {
9282
+ this.pool = typeof options.poolConfig === "string" ? new import_pg26.Pool({ connectionString: options.poolConfig }) : options.poolConfig ? new import_pg26.Pool(options.poolConfig) : (() => {
9055
9283
  throw new Error("Either pool or poolConfig must be provided");
9056
9284
  })();
9057
9285
  this.migrationManager = new MigrationManager(this.pool);
@@ -9278,6 +9506,7 @@ function mapRowToChannelIdentityMapping(row) {
9278
9506
  PGVectorStoreProvider,
9279
9507
  Pool,
9280
9508
  PostgreSQLA2AApiKeyStore,
9509
+ PostgreSQLAgentWebAppStore,
9281
9510
  PostgreSQLAssistantStore,
9282
9511
  PostgreSQLChannelInstallationStore,
9283
9512
  PostgreSQLCollectionStore,
@@ -9315,6 +9544,7 @@ function mapRowToChannelIdentityMapping(row) {
9315
9544
  changeSkillPrimaryKey,
9316
9545
  changeThreadPrimaryKey,
9317
9546
  createA2AApiKeysTable,
9547
+ createAgentWebAppsTable,
9318
9548
  createAssistantsTable,
9319
9549
  createChannelBindingsTable,
9320
9550
  createChannelIdentityMappingTables,