@axiom-lattice/pg-stores 1.0.68 → 1.0.70

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
@@ -33,7 +33,8 @@ __export(index_exports, {
33
33
  ChannelBindingStore: () => ChannelBindingStore,
34
34
  ChannelIdentityMappingStore: () => ChannelIdentityMappingStore,
35
35
  MigrationManager: () => MigrationManager,
36
- Pool: () => import_pg19.Pool,
36
+ Pool: () => import_pg20.Pool,
37
+ PostgreSQLA2AApiKeyStore: () => PostgreSQLA2AApiKeyStore,
37
38
  PostgreSQLAssistantStore: () => PostgreSQLAssistantStore,
38
39
  PostgreSQLChannelInstallationStore: () => PostgreSQLChannelInstallationStore,
39
40
  PostgreSQLDatabaseConfigStore: () => PostgreSQLDatabaseConfigStore,
@@ -51,6 +52,7 @@ __export(index_exports, {
51
52
  PostgreSQLWorkspaceStore: () => PostgreSQLWorkspaceStore,
52
53
  ThreadMessageQueueStore: () => ThreadMessageQueueStore,
53
54
  addAssistantTenantId: () => addAssistantTenantId,
55
+ addProjectConfigColumn: () => addProjectConfigColumn,
54
56
  addScheduleTenantId: () => addScheduleTenantId,
55
57
  addSkillTenantId: () => addSkillTenantId,
56
58
  addThreadTenantId: () => addThreadTenantId,
@@ -58,6 +60,7 @@ __export(index_exports, {
58
60
  changeAssistantPrimaryKey: () => changeAssistantPrimaryKey,
59
61
  changeSkillPrimaryKey: () => changeSkillPrimaryKey,
60
62
  changeThreadPrimaryKey: () => changeThreadPrimaryKey,
63
+ createA2AApiKeysTable: () => createA2AApiKeysTable,
61
64
  createAssistantsTable: () => createAssistantsTable,
62
65
  createChannelBindingsTable: () => createChannelBindingsTable,
63
66
  createChannelIdentityMappingTables: () => createChannelIdentityMappingTables,
@@ -83,7 +86,7 @@ __export(index_exports, {
83
86
  evalMigrations: () => evalMigrations
84
87
  });
85
88
  module.exports = __toCommonJS(index_exports);
86
- var import_pg19 = require("pg");
89
+ var import_pg20 = require("pg");
87
90
 
88
91
  // src/stores/PostgreSQLThreadStore.ts
89
92
  var import_pg = require("pg");
@@ -2149,6 +2152,29 @@ var createProjectsTable = {
2149
2152
  }
2150
2153
  };
2151
2154
 
2155
+ // src/migrations/add_project_config_column.ts
2156
+ var addProjectConfigColumn = {
2157
+ version: 24,
2158
+ name: "add_project_config_column",
2159
+ up: async (client) => {
2160
+ await client.query(`
2161
+ ALTER TABLE lattice_projects
2162
+ ADD COLUMN IF NOT EXISTS config JSONB
2163
+ `);
2164
+ await client.query(`
2165
+ CREATE INDEX IF NOT EXISTS idx_lattice_projects_config
2166
+ ON lattice_projects USING GIN (config)
2167
+ `);
2168
+ },
2169
+ down: async (client) => {
2170
+ await client.query("DROP INDEX IF EXISTS idx_lattice_projects_config");
2171
+ await client.query(`
2172
+ ALTER TABLE lattice_projects
2173
+ DROP COLUMN IF EXISTS config
2174
+ `);
2175
+ }
2176
+ };
2177
+
2152
2178
  // src/stores/PostgreSQLProjectStore.ts
2153
2179
  var PostgreSQLProjectStore = class {
2154
2180
  constructor(options) {
@@ -2161,6 +2187,7 @@ var PostgreSQLProjectStore = class {
2161
2187
  }
2162
2188
  this.migrationManager = new MigrationManager(this.pool);
2163
2189
  this.migrationManager.register(createProjectsTable);
2190
+ this.migrationManager.register(addProjectConfigColumn);
2164
2191
  if (options.autoMigrate !== false) {
2165
2192
  this.initialize().catch((error) => {
2166
2193
  console.error("Failed to initialize PostgreSQLProjectStore:", error);
@@ -2205,6 +2232,7 @@ var PostgreSQLProjectStore = class {
2205
2232
  workspaceId: row.workspace_id,
2206
2233
  name: row.name,
2207
2234
  description: row.description || void 0,
2235
+ config: row.config || void 0,
2208
2236
  createdAt: row.created_at,
2209
2237
  updatedAt: row.updated_at
2210
2238
  };
@@ -2216,7 +2244,7 @@ var PostgreSQLProjectStore = class {
2216
2244
  await this.ensureInitialized();
2217
2245
  const result = await this.pool.query(
2218
2246
  `
2219
- SELECT id, tenant_id, workspace_id, name, description, created_at, updated_at
2247
+ SELECT id, tenant_id, workspace_id, name, description, config, created_at, updated_at
2220
2248
  FROM lattice_projects
2221
2249
  WHERE tenant_id = $1 AND workspace_id = $2
2222
2250
  ORDER BY created_at DESC
@@ -2232,7 +2260,7 @@ var PostgreSQLProjectStore = class {
2232
2260
  await this.ensureInitialized();
2233
2261
  const result = await this.pool.query(
2234
2262
  `
2235
- SELECT id, tenant_id, workspace_id, name, description, created_at, updated_at
2263
+ SELECT id, tenant_id, workspace_id, name, description, config, created_at, updated_at
2236
2264
  FROM lattice_projects
2237
2265
  WHERE id = $1 AND tenant_id = $2
2238
2266
  `,
@@ -2251,15 +2279,16 @@ var PostgreSQLProjectStore = class {
2251
2279
  const now = /* @__PURE__ */ new Date();
2252
2280
  await this.pool.query(
2253
2281
  `
2254
- INSERT INTO lattice_projects (id, tenant_id, workspace_id, name, description, created_at, updated_at)
2255
- VALUES ($1, $2, $3, $4, $5, $6, $7)
2282
+ INSERT INTO lattice_projects (id, tenant_id, workspace_id, name, description, config, created_at, updated_at)
2283
+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
2256
2284
  ON CONFLICT (id, tenant_id) DO UPDATE SET
2257
2285
  workspace_id = EXCLUDED.workspace_id,
2258
2286
  name = EXCLUDED.name,
2259
2287
  description = EXCLUDED.description,
2288
+ config = EXCLUDED.config,
2260
2289
  updated_at = EXCLUDED.updated_at
2261
2290
  `,
2262
- [id, tenantId, workspaceId, data.name, data.description || null, now, now]
2291
+ [id, tenantId, workspaceId, data.name, data.description || null, data.config || null, now, now]
2263
2292
  );
2264
2293
  return {
2265
2294
  id,
@@ -2267,12 +2296,17 @@ var PostgreSQLProjectStore = class {
2267
2296
  workspaceId,
2268
2297
  name: data.name,
2269
2298
  description: data.description,
2299
+ config: data.config,
2270
2300
  createdAt: now,
2271
2301
  updatedAt: now
2272
2302
  };
2273
2303
  }
2274
2304
  /**
2275
2305
  * Update an existing project
2306
+ *
2307
+ * @remarks
2308
+ * - The `config` field uses **replace** semantics: if provided, it completely
2309
+ * overwrites the existing config. To preserve the current config, omit this field.
2276
2310
  */
2277
2311
  async updateProject(tenantId, id, updates) {
2278
2312
  await this.ensureInitialized();
@@ -2291,6 +2325,10 @@ var PostgreSQLProjectStore = class {
2291
2325
  updateFields.push(`description = $${paramIndex++}`);
2292
2326
  updateValues.push(updates.description || null);
2293
2327
  }
2328
+ if (updates.config !== void 0) {
2329
+ updateFields.push(`config = $${paramIndex++}`);
2330
+ updateValues.push(updates.config || null);
2331
+ }
2294
2332
  if (updateFields.length === 0) {
2295
2333
  return existing;
2296
2334
  }
@@ -5064,8 +5102,185 @@ var PostgreSQLChannelInstallationStore = class {
5064
5102
  }
5065
5103
  };
5066
5104
 
5067
- // src/stores/PostgreSQLScheduleStorage.ts
5105
+ // src/stores/PostgreSQLA2AApiKeyStore.ts
5068
5106
  var import_pg16 = require("pg");
5107
+
5108
+ // src/migrations/a2a_api_key_migration.ts
5109
+ var createA2AApiKeysTable = {
5110
+ version: 130,
5111
+ name: "create_a2a_api_keys_table",
5112
+ up: async (client) => {
5113
+ await client.query(`
5114
+ CREATE TABLE IF NOT EXISTS lattice_a2a_api_keys (
5115
+ id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
5116
+ key_value TEXT NOT NULL UNIQUE,
5117
+ tenant_id VARCHAR(255) NOT NULL,
5118
+ project_id VARCHAR(255),
5119
+ workspace_id VARCHAR(255),
5120
+ label VARCHAR(255),
5121
+ enabled BOOLEAN NOT NULL DEFAULT true,
5122
+ created_at TIMESTAMP NOT NULL DEFAULT NOW(),
5123
+ updated_at TIMESTAMP NOT NULL DEFAULT NOW()
5124
+ )
5125
+ `);
5126
+ await client.query(`
5127
+ CREATE INDEX IF NOT EXISTS idx_lattice_a2a_keys_tenant
5128
+ ON lattice_a2a_api_keys(tenant_id)
5129
+ `);
5130
+ await client.query(`
5131
+ CREATE INDEX IF NOT EXISTS idx_lattice_a2a_keys_value
5132
+ ON lattice_a2a_api_keys(key_value)
5133
+ WHERE enabled = true
5134
+ `);
5135
+ },
5136
+ down: async (client) => {
5137
+ await client.query("DROP TABLE IF EXISTS lattice_a2a_api_keys");
5138
+ }
5139
+ };
5140
+
5141
+ // src/stores/PostgreSQLA2AApiKeyStore.ts
5142
+ var import_core5 = require("@axiom-lattice/core");
5143
+ var import_crypto2 = require("crypto");
5144
+ function generateApiKey() {
5145
+ return `a2a_${(0, import_crypto2.randomUUID)().replace(/-/g, "")}`;
5146
+ }
5147
+ function mapRowToRecord(row) {
5148
+ return {
5149
+ id: row.id,
5150
+ key: (0, import_core5.decrypt)(row.key_value),
5151
+ tenantId: row.tenant_id,
5152
+ projectId: row.project_id || void 0,
5153
+ workspaceId: row.workspace_id || void 0,
5154
+ label: row.label || void 0,
5155
+ enabled: row.enabled,
5156
+ createdAt: row.created_at,
5157
+ updatedAt: row.updated_at
5158
+ };
5159
+ }
5160
+ var PostgreSQLA2AApiKeyStore = class {
5161
+ constructor(options) {
5162
+ this.initialized = false;
5163
+ this.initPromise = null;
5164
+ this.pool = typeof options.poolConfig === "string" ? new import_pg16.Pool({ connectionString: options.poolConfig }) : new import_pg16.Pool(options.poolConfig);
5165
+ this.migrationManager = new MigrationManager(this.pool);
5166
+ this.migrationManager.register(createA2AApiKeysTable);
5167
+ if (options.autoMigrate !== false) {
5168
+ this.initialize().catch((error) => {
5169
+ console.error("Failed to initialize PostgreSQLA2AApiKeyStore:", error);
5170
+ throw error;
5171
+ });
5172
+ }
5173
+ }
5174
+ async initialize() {
5175
+ if (this.initialized) return;
5176
+ if (this.initPromise) return this.initPromise;
5177
+ this.initPromise = (async () => {
5178
+ try {
5179
+ await this.migrationManager.migrate();
5180
+ this.initialized = true;
5181
+ } finally {
5182
+ this.initPromise = null;
5183
+ }
5184
+ })();
5185
+ return this.initPromise;
5186
+ }
5187
+ async ensureInitialized() {
5188
+ if (!this.initialized) await this.initialize();
5189
+ }
5190
+ async findByKey(key) {
5191
+ await this.ensureInitialized();
5192
+ const all = await this.pool.query(
5193
+ `SELECT * FROM lattice_a2a_api_keys WHERE enabled = true`
5194
+ );
5195
+ for (const row of all.rows) {
5196
+ if ((0, import_core5.decrypt)(row.key_value) === key) return mapRowToRecord(row);
5197
+ }
5198
+ return null;
5199
+ }
5200
+ async list(params) {
5201
+ await this.ensureInitialized();
5202
+ const limit = params.limit || 100;
5203
+ const offset = params.offset || 0;
5204
+ if (params.tenantId) {
5205
+ const result2 = await this.pool.query(
5206
+ `SELECT * FROM lattice_a2a_api_keys WHERE tenant_id = $1 ORDER BY created_at DESC LIMIT $2 OFFSET $3`,
5207
+ [params.tenantId, limit, offset]
5208
+ );
5209
+ return result2.rows.map(mapRowToRecord);
5210
+ }
5211
+ const result = await this.pool.query(
5212
+ `SELECT * FROM lattice_a2a_api_keys ORDER BY created_at DESC LIMIT $1 OFFSET $2`,
5213
+ [limit, offset]
5214
+ );
5215
+ return result.rows.map(mapRowToRecord);
5216
+ }
5217
+ async create(input) {
5218
+ await this.ensureInitialized();
5219
+ const key = generateApiKey();
5220
+ const result = await this.pool.query(
5221
+ `INSERT INTO lattice_a2a_api_keys (key_value, tenant_id, project_id, workspace_id, label)
5222
+ VALUES ($1, $2, $3, $4, $5) RETURNING *`,
5223
+ [(0, import_core5.encrypt)(key), input.tenantId, input.projectId || null, input.workspaceId || null, input.label || null]
5224
+ );
5225
+ const record = mapRowToRecord(result.rows[0]);
5226
+ record.key = key;
5227
+ return record;
5228
+ }
5229
+ async disable(id) {
5230
+ await this.ensureInitialized();
5231
+ const result = await this.pool.query(
5232
+ `UPDATE lattice_a2a_api_keys SET enabled = false, updated_at = NOW() WHERE id = $1 RETURNING *`,
5233
+ [id]
5234
+ );
5235
+ if (result.rows.length === 0) throw new Error(`A2A API key not found: ${id}`);
5236
+ return mapRowToRecord(result.rows[0]);
5237
+ }
5238
+ async enable(id) {
5239
+ await this.ensureInitialized();
5240
+ const result = await this.pool.query(
5241
+ `UPDATE lattice_a2a_api_keys SET enabled = true, updated_at = NOW() WHERE id = $1 RETURNING *`,
5242
+ [id]
5243
+ );
5244
+ if (result.rows.length === 0) throw new Error(`A2A API key not found: ${id}`);
5245
+ return mapRowToRecord(result.rows[0]);
5246
+ }
5247
+ async rotate(id) {
5248
+ await this.ensureInitialized();
5249
+ const key = generateApiKey();
5250
+ const result = await this.pool.query(
5251
+ `UPDATE lattice_a2a_api_keys SET key_value = $1, updated_at = NOW() WHERE id = $2 RETURNING *`,
5252
+ [(0, import_core5.encrypt)(key), id]
5253
+ );
5254
+ if (result.rows.length === 0) throw new Error(`A2A API key not found: ${id}`);
5255
+ const record = mapRowToRecord(result.rows[0]);
5256
+ record.key = key;
5257
+ return record;
5258
+ }
5259
+ async delete(id) {
5260
+ await this.ensureInitialized();
5261
+ await this.pool.query(`DELETE FROM lattice_a2a_api_keys WHERE id = $1`, [id]);
5262
+ }
5263
+ async loadIntoMap() {
5264
+ await this.ensureInitialized();
5265
+ const result = await this.pool.query(
5266
+ `SELECT * FROM lattice_a2a_api_keys WHERE enabled = true`
5267
+ );
5268
+ const map = /* @__PURE__ */ new Map();
5269
+ for (const row of result.rows) {
5270
+ const key = (0, import_core5.decrypt)(row.key_value);
5271
+ map.set(key, {
5272
+ key,
5273
+ tenantId: row.tenant_id,
5274
+ projectId: row.project_id || void 0,
5275
+ workspaceId: row.workspace_id || void 0
5276
+ });
5277
+ }
5278
+ return map;
5279
+ }
5280
+ };
5281
+
5282
+ // src/stores/PostgreSQLScheduleStorage.ts
5283
+ var import_pg17 = require("pg");
5069
5284
  var import_protocols = require("@axiom-lattice/protocols");
5070
5285
 
5071
5286
  // src/migrations/schedule_migrations.ts
@@ -5233,9 +5448,9 @@ var PostgreSQLScheduleStorage = class {
5233
5448
  constructor(options) {
5234
5449
  this.initialized = false;
5235
5450
  if (typeof options.poolConfig === "string") {
5236
- this.pool = new import_pg16.Pool({ connectionString: options.poolConfig });
5451
+ this.pool = new import_pg17.Pool({ connectionString: options.poolConfig });
5237
5452
  } else {
5238
- this.pool = new import_pg16.Pool(options.poolConfig);
5453
+ this.pool = new import_pg17.Pool(options.poolConfig);
5239
5454
  }
5240
5455
  this.migrationManager = new MigrationManager(this.pool);
5241
5456
  this.migrationManager.register(createScheduledTasksTable);
@@ -5690,12 +5905,13 @@ function createPgStoreConfig(connectionString) {
5690
5905
  assistant: new PostgreSQLAssistantStore(opts),
5691
5906
  workflowTracking: new PostgreSQLWorkflowTrackingStore(optsAuto),
5692
5907
  threadMessageQueue: new ThreadMessageQueueStore(optsAuto),
5908
+ a2aApiKey: new PostgreSQLA2AApiKeyStore(optsAuto),
5693
5909
  schedule: new PostgreSQLScheduleStorage(opts)
5694
5910
  };
5695
5911
  }
5696
5912
 
5697
5913
  // src/stores/PostgreSQLSkillStore.ts
5698
- var import_pg17 = require("pg");
5914
+ var import_pg18 = require("pg");
5699
5915
 
5700
5916
  // src/migrations/skill_migrations.ts
5701
5917
  var createSkillsTable = {
@@ -5857,9 +6073,9 @@ var PostgreSQLSkillStore = class {
5857
6073
  this.ownsPool = true;
5858
6074
  this.initPromise = null;
5859
6075
  if (typeof options.poolConfig === "string") {
5860
- this.pool = new import_pg17.Pool({ connectionString: options.poolConfig });
6076
+ this.pool = new import_pg18.Pool({ connectionString: options.poolConfig });
5861
6077
  } else {
5862
- this.pool = new import_pg17.Pool(options.poolConfig);
6078
+ this.pool = new import_pg18.Pool(options.poolConfig);
5863
6079
  }
5864
6080
  this.migrationManager = new MigrationManager(this.pool);
5865
6081
  this.migrationManager.register(createSkillsTable);
@@ -6213,12 +6429,12 @@ var createChannelIdentityMappingTables = {
6213
6429
  };
6214
6430
 
6215
6431
  // src/stores/ChannelIdentityMappingStore.ts
6216
- var import_pg18 = require("pg");
6432
+ var import_pg19 = require("pg");
6217
6433
  var ChannelIdentityMappingStore = class {
6218
6434
  constructor(options) {
6219
6435
  this.initialized = false;
6220
6436
  this.initPromise = null;
6221
- this.pool = typeof options.poolConfig === "string" ? new import_pg18.Pool({ connectionString: options.poolConfig }) : new import_pg18.Pool(options.poolConfig);
6437
+ this.pool = typeof options.poolConfig === "string" ? new import_pg19.Pool({ connectionString: options.poolConfig }) : new import_pg19.Pool(options.poolConfig);
6222
6438
  this.migrationManager = new MigrationManager(this.pool);
6223
6439
  this.migrationManager.register(createChannelIdentityMappingTables);
6224
6440
  if (options.autoMigrate !== false) {
@@ -6435,6 +6651,7 @@ function mapRowToChannelIdentityMapping(row) {
6435
6651
  ChannelIdentityMappingStore,
6436
6652
  MigrationManager,
6437
6653
  Pool,
6654
+ PostgreSQLA2AApiKeyStore,
6438
6655
  PostgreSQLAssistantStore,
6439
6656
  PostgreSQLChannelInstallationStore,
6440
6657
  PostgreSQLDatabaseConfigStore,
@@ -6452,6 +6669,7 @@ function mapRowToChannelIdentityMapping(row) {
6452
6669
  PostgreSQLWorkspaceStore,
6453
6670
  ThreadMessageQueueStore,
6454
6671
  addAssistantTenantId,
6672
+ addProjectConfigColumn,
6455
6673
  addScheduleTenantId,
6456
6674
  addSkillTenantId,
6457
6675
  addThreadTenantId,
@@ -6459,6 +6677,7 @@ function mapRowToChannelIdentityMapping(row) {
6459
6677
  changeAssistantPrimaryKey,
6460
6678
  changeSkillPrimaryKey,
6461
6679
  changeThreadPrimaryKey,
6680
+ createA2AApiKeysTable,
6462
6681
  createAssistantsTable,
6463
6682
  createChannelBindingsTable,
6464
6683
  createChannelIdentityMappingTables,