@axiom-lattice/pg-stores 1.0.67 → 1.0.69

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,5 +1,5 @@
1
1
  // src/index.ts
2
- import { Pool as Pool19 } from "pg";
2
+ import { Pool as Pool20 } from "pg";
3
3
 
4
4
  // src/stores/PostgreSQLThreadStore.ts
5
5
  import { Pool } from "pg";
@@ -2065,6 +2065,29 @@ var createProjectsTable = {
2065
2065
  }
2066
2066
  };
2067
2067
 
2068
+ // src/migrations/add_project_config_column.ts
2069
+ var addProjectConfigColumn = {
2070
+ version: 24,
2071
+ name: "add_project_config_column",
2072
+ up: async (client) => {
2073
+ await client.query(`
2074
+ ALTER TABLE lattice_projects
2075
+ ADD COLUMN IF NOT EXISTS config JSONB
2076
+ `);
2077
+ await client.query(`
2078
+ CREATE INDEX IF NOT EXISTS idx_lattice_projects_config
2079
+ ON lattice_projects USING GIN (config)
2080
+ `);
2081
+ },
2082
+ down: async (client) => {
2083
+ await client.query("DROP INDEX IF EXISTS idx_lattice_projects_config");
2084
+ await client.query(`
2085
+ ALTER TABLE lattice_projects
2086
+ DROP COLUMN IF EXISTS config
2087
+ `);
2088
+ }
2089
+ };
2090
+
2068
2091
  // src/stores/PostgreSQLProjectStore.ts
2069
2092
  var PostgreSQLProjectStore = class {
2070
2093
  constructor(options) {
@@ -2077,6 +2100,7 @@ var PostgreSQLProjectStore = class {
2077
2100
  }
2078
2101
  this.migrationManager = new MigrationManager(this.pool);
2079
2102
  this.migrationManager.register(createProjectsTable);
2103
+ this.migrationManager.register(addProjectConfigColumn);
2080
2104
  if (options.autoMigrate !== false) {
2081
2105
  this.initialize().catch((error) => {
2082
2106
  console.error("Failed to initialize PostgreSQLProjectStore:", error);
@@ -2121,6 +2145,7 @@ var PostgreSQLProjectStore = class {
2121
2145
  workspaceId: row.workspace_id,
2122
2146
  name: row.name,
2123
2147
  description: row.description || void 0,
2148
+ config: row.config || void 0,
2124
2149
  createdAt: row.created_at,
2125
2150
  updatedAt: row.updated_at
2126
2151
  };
@@ -2132,7 +2157,7 @@ var PostgreSQLProjectStore = class {
2132
2157
  await this.ensureInitialized();
2133
2158
  const result = await this.pool.query(
2134
2159
  `
2135
- SELECT id, tenant_id, workspace_id, name, description, created_at, updated_at
2160
+ SELECT id, tenant_id, workspace_id, name, description, config, created_at, updated_at
2136
2161
  FROM lattice_projects
2137
2162
  WHERE tenant_id = $1 AND workspace_id = $2
2138
2163
  ORDER BY created_at DESC
@@ -2148,7 +2173,7 @@ var PostgreSQLProjectStore = class {
2148
2173
  await this.ensureInitialized();
2149
2174
  const result = await this.pool.query(
2150
2175
  `
2151
- SELECT id, tenant_id, workspace_id, name, description, created_at, updated_at
2176
+ SELECT id, tenant_id, workspace_id, name, description, config, created_at, updated_at
2152
2177
  FROM lattice_projects
2153
2178
  WHERE id = $1 AND tenant_id = $2
2154
2179
  `,
@@ -2167,15 +2192,16 @@ var PostgreSQLProjectStore = class {
2167
2192
  const now = /* @__PURE__ */ new Date();
2168
2193
  await this.pool.query(
2169
2194
  `
2170
- INSERT INTO lattice_projects (id, tenant_id, workspace_id, name, description, created_at, updated_at)
2171
- VALUES ($1, $2, $3, $4, $5, $6, $7)
2195
+ INSERT INTO lattice_projects (id, tenant_id, workspace_id, name, description, config, created_at, updated_at)
2196
+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
2172
2197
  ON CONFLICT (id, tenant_id) DO UPDATE SET
2173
2198
  workspace_id = EXCLUDED.workspace_id,
2174
2199
  name = EXCLUDED.name,
2175
2200
  description = EXCLUDED.description,
2201
+ config = EXCLUDED.config,
2176
2202
  updated_at = EXCLUDED.updated_at
2177
2203
  `,
2178
- [id, tenantId, workspaceId, data.name, data.description || null, now, now]
2204
+ [id, tenantId, workspaceId, data.name, data.description || null, data.config || null, now, now]
2179
2205
  );
2180
2206
  return {
2181
2207
  id,
@@ -2183,12 +2209,17 @@ var PostgreSQLProjectStore = class {
2183
2209
  workspaceId,
2184
2210
  name: data.name,
2185
2211
  description: data.description,
2212
+ config: data.config,
2186
2213
  createdAt: now,
2187
2214
  updatedAt: now
2188
2215
  };
2189
2216
  }
2190
2217
  /**
2191
2218
  * Update an existing project
2219
+ *
2220
+ * @remarks
2221
+ * - The `config` field uses **replace** semantics: if provided, it completely
2222
+ * overwrites the existing config. To preserve the current config, omit this field.
2192
2223
  */
2193
2224
  async updateProject(tenantId, id, updates) {
2194
2225
  await this.ensureInitialized();
@@ -2207,6 +2238,10 @@ var PostgreSQLProjectStore = class {
2207
2238
  updateFields.push(`description = $${paramIndex++}`);
2208
2239
  updateValues.push(updates.description || null);
2209
2240
  }
2241
+ if (updates.config !== void 0) {
2242
+ updateFields.push(`config = $${paramIndex++}`);
2243
+ updateValues.push(updates.config || null);
2244
+ }
2210
2245
  if (updateFields.length === 0) {
2211
2246
  return existing;
2212
2247
  }
@@ -4980,8 +5015,185 @@ var PostgreSQLChannelInstallationStore = class {
4980
5015
  }
4981
5016
  };
4982
5017
 
4983
- // src/stores/PostgreSQLScheduleStorage.ts
5018
+ // src/stores/PostgreSQLA2AApiKeyStore.ts
4984
5019
  import { Pool as Pool16 } from "pg";
5020
+
5021
+ // src/migrations/a2a_api_key_migration.ts
5022
+ var createA2AApiKeysTable = {
5023
+ version: 130,
5024
+ name: "create_a2a_api_keys_table",
5025
+ up: async (client) => {
5026
+ await client.query(`
5027
+ CREATE TABLE IF NOT EXISTS lattice_a2a_api_keys (
5028
+ id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
5029
+ key_value TEXT NOT NULL UNIQUE,
5030
+ tenant_id VARCHAR(255) NOT NULL,
5031
+ project_id VARCHAR(255),
5032
+ workspace_id VARCHAR(255),
5033
+ label VARCHAR(255),
5034
+ enabled BOOLEAN NOT NULL DEFAULT true,
5035
+ created_at TIMESTAMP NOT NULL DEFAULT NOW(),
5036
+ updated_at TIMESTAMP NOT NULL DEFAULT NOW()
5037
+ )
5038
+ `);
5039
+ await client.query(`
5040
+ CREATE INDEX IF NOT EXISTS idx_lattice_a2a_keys_tenant
5041
+ ON lattice_a2a_api_keys(tenant_id)
5042
+ `);
5043
+ await client.query(`
5044
+ CREATE INDEX IF NOT EXISTS idx_lattice_a2a_keys_value
5045
+ ON lattice_a2a_api_keys(key_value)
5046
+ WHERE enabled = true
5047
+ `);
5048
+ },
5049
+ down: async (client) => {
5050
+ await client.query("DROP TABLE IF EXISTS lattice_a2a_api_keys");
5051
+ }
5052
+ };
5053
+
5054
+ // src/stores/PostgreSQLA2AApiKeyStore.ts
5055
+ import { encrypt as encrypt5, decrypt as decrypt5 } from "@axiom-lattice/core";
5056
+ import { randomUUID } from "crypto";
5057
+ function generateApiKey() {
5058
+ return `a2a_${randomUUID().replace(/-/g, "")}`;
5059
+ }
5060
+ function mapRowToRecord(row) {
5061
+ return {
5062
+ id: row.id,
5063
+ key: decrypt5(row.key_value),
5064
+ tenantId: row.tenant_id,
5065
+ projectId: row.project_id || void 0,
5066
+ workspaceId: row.workspace_id || void 0,
5067
+ label: row.label || void 0,
5068
+ enabled: row.enabled,
5069
+ createdAt: row.created_at,
5070
+ updatedAt: row.updated_at
5071
+ };
5072
+ }
5073
+ var PostgreSQLA2AApiKeyStore = class {
5074
+ constructor(options) {
5075
+ this.initialized = false;
5076
+ this.initPromise = null;
5077
+ this.pool = typeof options.poolConfig === "string" ? new Pool16({ connectionString: options.poolConfig }) : new Pool16(options.poolConfig);
5078
+ this.migrationManager = new MigrationManager(this.pool);
5079
+ this.migrationManager.register(createA2AApiKeysTable);
5080
+ if (options.autoMigrate !== false) {
5081
+ this.initialize().catch((error) => {
5082
+ console.error("Failed to initialize PostgreSQLA2AApiKeyStore:", error);
5083
+ throw error;
5084
+ });
5085
+ }
5086
+ }
5087
+ async initialize() {
5088
+ if (this.initialized) return;
5089
+ if (this.initPromise) return this.initPromise;
5090
+ this.initPromise = (async () => {
5091
+ try {
5092
+ await this.migrationManager.migrate();
5093
+ this.initialized = true;
5094
+ } finally {
5095
+ this.initPromise = null;
5096
+ }
5097
+ })();
5098
+ return this.initPromise;
5099
+ }
5100
+ async ensureInitialized() {
5101
+ if (!this.initialized) await this.initialize();
5102
+ }
5103
+ async findByKey(key) {
5104
+ await this.ensureInitialized();
5105
+ const all = await this.pool.query(
5106
+ `SELECT * FROM lattice_a2a_api_keys WHERE enabled = true`
5107
+ );
5108
+ for (const row of all.rows) {
5109
+ if (decrypt5(row.key_value) === key) return mapRowToRecord(row);
5110
+ }
5111
+ return null;
5112
+ }
5113
+ async list(params) {
5114
+ await this.ensureInitialized();
5115
+ const limit = params.limit || 100;
5116
+ const offset = params.offset || 0;
5117
+ if (params.tenantId) {
5118
+ const result2 = await this.pool.query(
5119
+ `SELECT * FROM lattice_a2a_api_keys WHERE tenant_id = $1 ORDER BY created_at DESC LIMIT $2 OFFSET $3`,
5120
+ [params.tenantId, limit, offset]
5121
+ );
5122
+ return result2.rows.map(mapRowToRecord);
5123
+ }
5124
+ const result = await this.pool.query(
5125
+ `SELECT * FROM lattice_a2a_api_keys ORDER BY created_at DESC LIMIT $1 OFFSET $2`,
5126
+ [limit, offset]
5127
+ );
5128
+ return result.rows.map(mapRowToRecord);
5129
+ }
5130
+ async create(input) {
5131
+ await this.ensureInitialized();
5132
+ const key = generateApiKey();
5133
+ const result = await this.pool.query(
5134
+ `INSERT INTO lattice_a2a_api_keys (key_value, tenant_id, project_id, workspace_id, label)
5135
+ VALUES ($1, $2, $3, $4, $5) RETURNING *`,
5136
+ [encrypt5(key), input.tenantId, input.projectId || null, input.workspaceId || null, input.label || null]
5137
+ );
5138
+ const record = mapRowToRecord(result.rows[0]);
5139
+ record.key = key;
5140
+ return record;
5141
+ }
5142
+ async disable(id) {
5143
+ await this.ensureInitialized();
5144
+ const result = await this.pool.query(
5145
+ `UPDATE lattice_a2a_api_keys SET enabled = false, updated_at = NOW() WHERE id = $1 RETURNING *`,
5146
+ [id]
5147
+ );
5148
+ if (result.rows.length === 0) throw new Error(`A2A API key not found: ${id}`);
5149
+ return mapRowToRecord(result.rows[0]);
5150
+ }
5151
+ async enable(id) {
5152
+ await this.ensureInitialized();
5153
+ const result = await this.pool.query(
5154
+ `UPDATE lattice_a2a_api_keys SET enabled = true, updated_at = NOW() WHERE id = $1 RETURNING *`,
5155
+ [id]
5156
+ );
5157
+ if (result.rows.length === 0) throw new Error(`A2A API key not found: ${id}`);
5158
+ return mapRowToRecord(result.rows[0]);
5159
+ }
5160
+ async rotate(id) {
5161
+ await this.ensureInitialized();
5162
+ const key = generateApiKey();
5163
+ const result = await this.pool.query(
5164
+ `UPDATE lattice_a2a_api_keys SET key_value = $1, updated_at = NOW() WHERE id = $2 RETURNING *`,
5165
+ [encrypt5(key), id]
5166
+ );
5167
+ if (result.rows.length === 0) throw new Error(`A2A API key not found: ${id}`);
5168
+ const record = mapRowToRecord(result.rows[0]);
5169
+ record.key = key;
5170
+ return record;
5171
+ }
5172
+ async delete(id) {
5173
+ await this.ensureInitialized();
5174
+ await this.pool.query(`DELETE FROM lattice_a2a_api_keys WHERE id = $1`, [id]);
5175
+ }
5176
+ async loadIntoMap() {
5177
+ await this.ensureInitialized();
5178
+ const result = await this.pool.query(
5179
+ `SELECT * FROM lattice_a2a_api_keys WHERE enabled = true`
5180
+ );
5181
+ const map = /* @__PURE__ */ new Map();
5182
+ for (const row of result.rows) {
5183
+ const key = decrypt5(row.key_value);
5184
+ map.set(key, {
5185
+ key,
5186
+ tenantId: row.tenant_id,
5187
+ projectId: row.project_id || void 0,
5188
+ workspaceId: row.workspace_id || void 0
5189
+ });
5190
+ }
5191
+ return map;
5192
+ }
5193
+ };
5194
+
5195
+ // src/stores/PostgreSQLScheduleStorage.ts
5196
+ import { Pool as Pool17 } from "pg";
4985
5197
  import {
4986
5198
  ScheduledTaskStatus
4987
5199
  } from "@axiom-lattice/protocols";
@@ -5151,9 +5363,9 @@ var PostgreSQLScheduleStorage = class {
5151
5363
  constructor(options) {
5152
5364
  this.initialized = false;
5153
5365
  if (typeof options.poolConfig === "string") {
5154
- this.pool = new Pool16({ connectionString: options.poolConfig });
5366
+ this.pool = new Pool17({ connectionString: options.poolConfig });
5155
5367
  } else {
5156
- this.pool = new Pool16(options.poolConfig);
5368
+ this.pool = new Pool17(options.poolConfig);
5157
5369
  }
5158
5370
  this.migrationManager = new MigrationManager(this.pool);
5159
5371
  this.migrationManager.register(createScheduledTasksTable);
@@ -5608,12 +5820,13 @@ function createPgStoreConfig(connectionString) {
5608
5820
  assistant: new PostgreSQLAssistantStore(opts),
5609
5821
  workflowTracking: new PostgreSQLWorkflowTrackingStore(optsAuto),
5610
5822
  threadMessageQueue: new ThreadMessageQueueStore(optsAuto),
5823
+ a2aApiKey: new PostgreSQLA2AApiKeyStore(optsAuto),
5611
5824
  schedule: new PostgreSQLScheduleStorage(opts)
5612
5825
  };
5613
5826
  }
5614
5827
 
5615
5828
  // src/stores/PostgreSQLSkillStore.ts
5616
- import { Pool as Pool17 } from "pg";
5829
+ import { Pool as Pool18 } from "pg";
5617
5830
 
5618
5831
  // src/migrations/skill_migrations.ts
5619
5832
  var createSkillsTable = {
@@ -5775,9 +5988,9 @@ var PostgreSQLSkillStore = class {
5775
5988
  this.ownsPool = true;
5776
5989
  this.initPromise = null;
5777
5990
  if (typeof options.poolConfig === "string") {
5778
- this.pool = new Pool17({ connectionString: options.poolConfig });
5991
+ this.pool = new Pool18({ connectionString: options.poolConfig });
5779
5992
  } else {
5780
- this.pool = new Pool17(options.poolConfig);
5993
+ this.pool = new Pool18(options.poolConfig);
5781
5994
  }
5782
5995
  this.migrationManager = new MigrationManager(this.pool);
5783
5996
  this.migrationManager.register(createSkillsTable);
@@ -6131,12 +6344,12 @@ var createChannelIdentityMappingTables = {
6131
6344
  };
6132
6345
 
6133
6346
  // src/stores/ChannelIdentityMappingStore.ts
6134
- import { Pool as Pool18 } from "pg";
6347
+ import { Pool as Pool19 } from "pg";
6135
6348
  var ChannelIdentityMappingStore = class {
6136
6349
  constructor(options) {
6137
6350
  this.initialized = false;
6138
6351
  this.initPromise = null;
6139
- this.pool = typeof options.poolConfig === "string" ? new Pool18({ connectionString: options.poolConfig }) : new Pool18(options.poolConfig);
6352
+ this.pool = typeof options.poolConfig === "string" ? new Pool19({ connectionString: options.poolConfig }) : new Pool19(options.poolConfig);
6140
6353
  this.migrationManager = new MigrationManager(this.pool);
6141
6354
  this.migrationManager.register(createChannelIdentityMappingTables);
6142
6355
  if (options.autoMigrate !== false) {
@@ -6351,7 +6564,8 @@ export {
6351
6564
  ChannelBindingStore,
6352
6565
  ChannelIdentityMappingStore,
6353
6566
  MigrationManager,
6354
- Pool19 as Pool,
6567
+ Pool20 as Pool,
6568
+ PostgreSQLA2AApiKeyStore,
6355
6569
  PostgreSQLAssistantStore,
6356
6570
  PostgreSQLChannelInstallationStore,
6357
6571
  PostgreSQLDatabaseConfigStore,
@@ -6369,6 +6583,7 @@ export {
6369
6583
  PostgreSQLWorkspaceStore,
6370
6584
  ThreadMessageQueueStore,
6371
6585
  addAssistantTenantId,
6586
+ addProjectConfigColumn,
6372
6587
  addScheduleTenantId,
6373
6588
  addSkillTenantId,
6374
6589
  addThreadTenantId,
@@ -6376,6 +6591,7 @@ export {
6376
6591
  changeAssistantPrimaryKey,
6377
6592
  changeSkillPrimaryKey,
6378
6593
  changeThreadPrimaryKey,
6594
+ createA2AApiKeysTable,
6379
6595
  createAssistantsTable,
6380
6596
  createChannelBindingsTable,
6381
6597
  createChannelIdentityMappingTables,