@axiom-lattice/pg-stores 1.0.85 → 1.0.87
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/.turbo/turbo-build.log +10 -10
- package/CHANGELOG.md +18 -0
- package/dist/index.d.mts +83 -3
- package/dist/index.d.ts +83 -3
- package/dist/index.js +412 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +399 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -3
- package/src/PGVectorStoreProvider.ts +113 -0
- package/src/createPgStoreConfig.ts +10 -0
- package/src/index.ts +8 -0
- package/src/migrations/collection_migrations.ts +41 -0
- package/src/migrations/connection_config_migrations.ts +50 -0
- package/src/stores/PostgreSQLCollectionStore.ts +165 -0
- package/src/stores/PostgreSQLConnectionStore.ts +128 -0
- package/src/stores/PostgreSQLMcpServerConfigStore.ts +2 -2
package/dist/index.js
CHANGED
|
@@ -34,10 +34,13 @@ __export(index_exports, {
|
|
|
34
34
|
ChannelIdentityMappingStore: () => ChannelIdentityMappingStore,
|
|
35
35
|
MenuStore: () => MenuStore,
|
|
36
36
|
MigrationManager: () => MigrationManager,
|
|
37
|
-
|
|
37
|
+
PGVectorStoreProvider: () => PGVectorStoreProvider,
|
|
38
|
+
Pool: () => import_pg26.Pool,
|
|
38
39
|
PostgreSQLA2AApiKeyStore: () => PostgreSQLA2AApiKeyStore,
|
|
39
40
|
PostgreSQLAssistantStore: () => PostgreSQLAssistantStore,
|
|
40
41
|
PostgreSQLChannelInstallationStore: () => PostgreSQLChannelInstallationStore,
|
|
42
|
+
PostgreSQLCollectionStore: () => PostgreSQLCollectionStore,
|
|
43
|
+
PostgreSQLConnectionStore: () => PostgreSQLConnectionStore,
|
|
41
44
|
PostgreSQLDatabaseConfigStore: () => PostgreSQLDatabaseConfigStore,
|
|
42
45
|
PostgreSQLEvalStore: () => PostgreSQLEvalStore,
|
|
43
46
|
PostgreSQLMcpServerConfigStore: () => PostgreSQLMcpServerConfigStore,
|
|
@@ -69,6 +72,7 @@ __export(index_exports, {
|
|
|
69
72
|
createChannelBindingsTable: () => createChannelBindingsTable,
|
|
70
73
|
createChannelIdentityMappingTables: () => createChannelIdentityMappingTables,
|
|
71
74
|
createChannelInstallationsTable: () => createChannelInstallationsTable,
|
|
75
|
+
createCollectionsTable: () => createCollectionsTable,
|
|
72
76
|
createDatabaseConfigsTable: () => createDatabaseConfigsTable,
|
|
73
77
|
createEvalCasesTable: () => createEvalCasesTable,
|
|
74
78
|
createEvalProjectsTable: () => createEvalProjectsTable,
|
|
@@ -78,6 +82,7 @@ __export(index_exports, {
|
|
|
78
82
|
createMcpServerConfigsTable: () => createMcpServerConfigsTable,
|
|
79
83
|
createMenuItemsTable: () => createMenuItemsTable,
|
|
80
84
|
createMetricsConfigsTable: () => createMetricsConfigsTable,
|
|
85
|
+
createPGVectorStoreProvider: () => createPGVectorStoreProvider,
|
|
81
86
|
createPgStoreConfig: () => createPgStoreConfig,
|
|
82
87
|
createProjectsTable: () => createProjectsTable,
|
|
83
88
|
createScheduledTasksTable: () => createScheduledTasksTable,
|
|
@@ -95,10 +100,10 @@ __export(index_exports, {
|
|
|
95
100
|
safeParse: () => safeParse
|
|
96
101
|
});
|
|
97
102
|
module.exports = __toCommonJS(index_exports);
|
|
98
|
-
var
|
|
103
|
+
var import_pg26 = require("pg");
|
|
99
104
|
|
|
100
105
|
// src/createPgStoreConfig.ts
|
|
101
|
-
var
|
|
106
|
+
var import_pg23 = require("pg");
|
|
102
107
|
|
|
103
108
|
// src/migrations/migration.ts
|
|
104
109
|
var MigrationManager = class {
|
|
@@ -1343,6 +1348,101 @@ var PostgreSQLDatabaseConfigStore = class {
|
|
|
1343
1348
|
}
|
|
1344
1349
|
};
|
|
1345
1350
|
|
|
1351
|
+
// src/stores/PostgreSQLConnectionStore.ts
|
|
1352
|
+
var import_uuid = require("uuid");
|
|
1353
|
+
var TABLE = "lattice_connection_configs";
|
|
1354
|
+
var PostgreSQLConnectionStore = class {
|
|
1355
|
+
constructor(db) {
|
|
1356
|
+
this.db = db;
|
|
1357
|
+
}
|
|
1358
|
+
async listByType(tenantId, type) {
|
|
1359
|
+
const result = await this.db.query(
|
|
1360
|
+
`SELECT * FROM ${TABLE} WHERE tenant_id = $1 AND type = $2 ORDER BY created_at`,
|
|
1361
|
+
[tenantId, type]
|
|
1362
|
+
);
|
|
1363
|
+
return result.rows.map((row) => this.mapRow(row));
|
|
1364
|
+
}
|
|
1365
|
+
async getByKey(tenantId, type, key) {
|
|
1366
|
+
const result = await this.db.query(
|
|
1367
|
+
`SELECT * FROM ${TABLE} WHERE tenant_id = $1 AND type = $2 AND key = $3`,
|
|
1368
|
+
[tenantId, type, key]
|
|
1369
|
+
);
|
|
1370
|
+
if (result.rows.length === 0) return null;
|
|
1371
|
+
return this.mapRow(result.rows[0]);
|
|
1372
|
+
}
|
|
1373
|
+
async create(entry) {
|
|
1374
|
+
const id = (0, import_uuid.v4)();
|
|
1375
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
1376
|
+
await this.db.query(
|
|
1377
|
+
`INSERT INTO ${TABLE} (id, tenant_id, type, key, name, description, config, status, created_at, updated_at)
|
|
1378
|
+
VALUES ($1, $2, $3, $4, $5, $6, $7, 'active', $8::timestamp, $9::timestamp)`,
|
|
1379
|
+
[
|
|
1380
|
+
id,
|
|
1381
|
+
entry.tenantId,
|
|
1382
|
+
entry.type,
|
|
1383
|
+
entry.key,
|
|
1384
|
+
entry.name,
|
|
1385
|
+
entry.description || null,
|
|
1386
|
+
JSON.stringify(entry.config),
|
|
1387
|
+
now,
|
|
1388
|
+
now
|
|
1389
|
+
]
|
|
1390
|
+
);
|
|
1391
|
+
return { id, ...entry, createdAt: now, updatedAt: now };
|
|
1392
|
+
}
|
|
1393
|
+
async update(tenantId, type, key, updates) {
|
|
1394
|
+
const existing = await this.getByKey(tenantId, type, key);
|
|
1395
|
+
if (!existing) return null;
|
|
1396
|
+
const setClauses = [];
|
|
1397
|
+
const values = [];
|
|
1398
|
+
let paramIndex = 1;
|
|
1399
|
+
if (updates.name !== void 0) {
|
|
1400
|
+
setClauses.push(`name = $${paramIndex++}`);
|
|
1401
|
+
values.push(updates.name);
|
|
1402
|
+
}
|
|
1403
|
+
if (updates.description !== void 0) {
|
|
1404
|
+
setClauses.push(`description = $${paramIndex++}`);
|
|
1405
|
+
values.push(updates.description || null);
|
|
1406
|
+
}
|
|
1407
|
+
if (updates.config !== void 0) {
|
|
1408
|
+
setClauses.push(`config = $${paramIndex++}`);
|
|
1409
|
+
values.push(JSON.stringify(updates.config));
|
|
1410
|
+
}
|
|
1411
|
+
if (setClauses.length === 0) return existing;
|
|
1412
|
+
setClauses.push(`updated_at = $${paramIndex++}::timestamp`);
|
|
1413
|
+
values.push((/* @__PURE__ */ new Date()).toISOString());
|
|
1414
|
+
values.push(tenantId, type, key);
|
|
1415
|
+
const whereTenant = paramIndex++;
|
|
1416
|
+
const whereType = paramIndex++;
|
|
1417
|
+
const whereKey = paramIndex;
|
|
1418
|
+
await this.db.query(
|
|
1419
|
+
`UPDATE ${TABLE} SET ${setClauses.join(", ")} WHERE tenant_id = $${whereTenant} AND type = $${whereType} AND key = $${whereKey}`,
|
|
1420
|
+
values
|
|
1421
|
+
);
|
|
1422
|
+
return this.getByKey(tenantId, type, key);
|
|
1423
|
+
}
|
|
1424
|
+
async delete(tenantId, type, key) {
|
|
1425
|
+
const result = await this.db.query(
|
|
1426
|
+
`DELETE FROM ${TABLE} WHERE tenant_id = $1 AND type = $2 AND key = $3`,
|
|
1427
|
+
[tenantId, type, key]
|
|
1428
|
+
);
|
|
1429
|
+
return (result.rowCount ?? 0) > 0;
|
|
1430
|
+
}
|
|
1431
|
+
mapRow(row) {
|
|
1432
|
+
return {
|
|
1433
|
+
id: row.id,
|
|
1434
|
+
tenantId: row.tenant_id,
|
|
1435
|
+
type: row.type,
|
|
1436
|
+
key: row.key,
|
|
1437
|
+
name: row.name,
|
|
1438
|
+
description: row.description || void 0,
|
|
1439
|
+
config: typeof row.config === "string" ? JSON.parse(row.config) : row.config,
|
|
1440
|
+
createdAt: row.created_at instanceof Date ? row.created_at.toISOString() : String(row.created_at),
|
|
1441
|
+
updatedAt: row.updated_at instanceof Date ? row.updated_at.toISOString() : String(row.updated_at)
|
|
1442
|
+
};
|
|
1443
|
+
}
|
|
1444
|
+
};
|
|
1445
|
+
|
|
1346
1446
|
// src/stores/PostgreSQLMetricsServerConfigStore.ts
|
|
1347
1447
|
var import_pg4 = require("pg");
|
|
1348
1448
|
|
|
@@ -1871,7 +1971,7 @@ var PostgreSQLMcpServerConfigStore = class {
|
|
|
1871
1971
|
data.name || null,
|
|
1872
1972
|
data.description || null,
|
|
1873
1973
|
JSON.stringify(configWithEncryptedEnv),
|
|
1874
|
-
data.selectedTools || [],
|
|
1974
|
+
JSON.stringify(data.selectedTools || []),
|
|
1875
1975
|
isEnvEncrypted,
|
|
1876
1976
|
"disconnected",
|
|
1877
1977
|
nowString,
|
|
@@ -1917,7 +2017,7 @@ var PostgreSQLMcpServerConfigStore = class {
|
|
|
1917
2017
|
updateData.is_env_encrypted = isEnvEncrypted;
|
|
1918
2018
|
}
|
|
1919
2019
|
if (updates.selectedTools !== void 0) {
|
|
1920
|
-
updateData.selected_tools = updates.selectedTools;
|
|
2020
|
+
updateData.selected_tools = JSON.stringify(updates.selectedTools);
|
|
1921
2021
|
}
|
|
1922
2022
|
if (updates.status !== void 0) {
|
|
1923
2023
|
updateData.status = updates.status;
|
|
@@ -3819,7 +3919,7 @@ var evalMigrations = [
|
|
|
3819
3919
|
];
|
|
3820
3920
|
|
|
3821
3921
|
// src/stores/PostgreSQLEvalStore.ts
|
|
3822
|
-
var
|
|
3922
|
+
var import_uuid2 = require("uuid");
|
|
3823
3923
|
var PostgreSQLEvalStore = class {
|
|
3824
3924
|
constructor(options) {
|
|
3825
3925
|
this.initialized = false;
|
|
@@ -4015,7 +4115,7 @@ var PostgreSQLEvalStore = class {
|
|
|
4015
4115
|
/** Create a new eval project */
|
|
4016
4116
|
async createProject(tenantId, id, data) {
|
|
4017
4117
|
await this.ensureInitialized();
|
|
4018
|
-
const actualId = id || (0,
|
|
4118
|
+
const actualId = id || (0, import_uuid2.v4)();
|
|
4019
4119
|
const { rows } = await this.pool.query(
|
|
4020
4120
|
`INSERT INTO lattice_eval_projects
|
|
4021
4121
|
(id, tenant_id, name, description, version, judge_model_config, target_server_config, concurrency, report_config)
|
|
@@ -4128,7 +4228,7 @@ var PostgreSQLEvalStore = class {
|
|
|
4128
4228
|
/** Create a new eval suite */
|
|
4129
4229
|
async createSuite(tenantId, projectId, id, data) {
|
|
4130
4230
|
await this.ensureInitialized();
|
|
4131
|
-
const actualId = id || (0,
|
|
4231
|
+
const actualId = id || (0, import_uuid2.v4)();
|
|
4132
4232
|
const { rows } = await this.pool.query(
|
|
4133
4233
|
`INSERT INTO lattice_eval_suites (id, tenant_id, project_id, name)
|
|
4134
4234
|
VALUES ($1, $2, $3, $4)
|
|
@@ -4202,7 +4302,7 @@ var PostgreSQLEvalStore = class {
|
|
|
4202
4302
|
/** Create a new test case */
|
|
4203
4303
|
async createCase(tenantId, suiteId, id, data) {
|
|
4204
4304
|
await this.ensureInitialized();
|
|
4205
|
-
const actualId = id || (0,
|
|
4305
|
+
const actualId = id || (0, import_uuid2.v4)();
|
|
4206
4306
|
const { rows } = await this.pool.query(
|
|
4207
4307
|
`INSERT INTO lattice_eval_cases
|
|
4208
4308
|
(id, tenant_id, suite_id, input_message, input_files, steps, output_type, content_assertion, rubrics)
|
|
@@ -4324,7 +4424,7 @@ var PostgreSQLEvalStore = class {
|
|
|
4324
4424
|
/** Create a new eval run */
|
|
4325
4425
|
async createRun(tenantId, projectId, id, data) {
|
|
4326
4426
|
await this.ensureInitialized();
|
|
4327
|
-
const actualId = id || (0,
|
|
4427
|
+
const actualId = id || (0, import_uuid2.v4)();
|
|
4328
4428
|
const { rows } = await this.pool.query(
|
|
4329
4429
|
`INSERT INTO lattice_eval_runs
|
|
4330
4430
|
(id, project_id, tenant_id, status, concurrency, total_cases, passed_cases, failed_cases, avg_score, started_at)
|
|
@@ -4422,7 +4522,7 @@ var PostgreSQLEvalStore = class {
|
|
|
4422
4522
|
/** Create a result for a case within a run */
|
|
4423
4523
|
async createRunResult(tenantId, runId, id, data) {
|
|
4424
4524
|
await this.ensureInitialized();
|
|
4425
|
-
const actualId = id || (0,
|
|
4525
|
+
const actualId = id || (0, import_uuid2.v4)();
|
|
4426
4526
|
const { rows } = await this.pool.query(
|
|
4427
4527
|
`INSERT INTO lattice_eval_run_results
|
|
4428
4528
|
(id, run_id, suite_name, case_id, pass, score, summary, dimension_results, duration_ms, messages, logs, error)
|
|
@@ -6298,7 +6398,7 @@ var createTasksTable = {
|
|
|
6298
6398
|
};
|
|
6299
6399
|
|
|
6300
6400
|
// src/stores/PostgreSQLTaskStore.ts
|
|
6301
|
-
var
|
|
6401
|
+
var import_uuid3 = require("uuid");
|
|
6302
6402
|
function mapRowToTask(row) {
|
|
6303
6403
|
return {
|
|
6304
6404
|
id: row.id,
|
|
@@ -6364,7 +6464,7 @@ var PostgreSQLTaskStore = class {
|
|
|
6364
6464
|
}
|
|
6365
6465
|
async create(params) {
|
|
6366
6466
|
await this.ensureInitialized();
|
|
6367
|
-
const id = (0,
|
|
6467
|
+
const id = (0, import_uuid3.v4)();
|
|
6368
6468
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
6369
6469
|
await this.pool.query(
|
|
6370
6470
|
`INSERT INTO lattice_tasks (id, tenant_id, owner_type, owner_id, title, description, status, priority, due_date, metadata, parent_id, source_id, context, created_at, updated_at)
|
|
@@ -6983,9 +7083,218 @@ var PostgresSharedResourceStore = class {
|
|
|
6983
7083
|
}
|
|
6984
7084
|
};
|
|
6985
7085
|
|
|
7086
|
+
// src/stores/PostgreSQLCollectionStore.ts
|
|
7087
|
+
var import_pg21 = require("pg");
|
|
7088
|
+
var PostgreSQLCollectionStore = class {
|
|
7089
|
+
constructor(options) {
|
|
7090
|
+
this.initialized = false;
|
|
7091
|
+
this.ownsPool = true;
|
|
7092
|
+
this.initPromise = null;
|
|
7093
|
+
if (options.pool) {
|
|
7094
|
+
this.pool = options.pool;
|
|
7095
|
+
this.ownsPool = false;
|
|
7096
|
+
this.initialized = true;
|
|
7097
|
+
return;
|
|
7098
|
+
}
|
|
7099
|
+
if (typeof options.poolConfig === "string") {
|
|
7100
|
+
this.pool = new import_pg21.Pool({ connectionString: options.poolConfig });
|
|
7101
|
+
} else if (options.poolConfig) {
|
|
7102
|
+
this.pool = new import_pg21.Pool(options.poolConfig);
|
|
7103
|
+
} else {
|
|
7104
|
+
throw new Error("Either pool or poolConfig must be provided");
|
|
7105
|
+
}
|
|
7106
|
+
if (options.autoMigrate !== false) {
|
|
7107
|
+
this.initialize().catch((error) => {
|
|
7108
|
+
console.error("Failed to initialize PostgreSQLCollectionStore:", error);
|
|
7109
|
+
});
|
|
7110
|
+
}
|
|
7111
|
+
}
|
|
7112
|
+
async initialize() {
|
|
7113
|
+
if (this.initialized) return;
|
|
7114
|
+
if (this.initPromise) return this.initPromise;
|
|
7115
|
+
this.initPromise = (async () => {
|
|
7116
|
+
this.initialized = true;
|
|
7117
|
+
})();
|
|
7118
|
+
return this.initPromise;
|
|
7119
|
+
}
|
|
7120
|
+
ensureInit() {
|
|
7121
|
+
if (!this.initialized) {
|
|
7122
|
+
throw new Error("PostgreSQLCollectionStore not initialized");
|
|
7123
|
+
}
|
|
7124
|
+
}
|
|
7125
|
+
async getAllCollections(tenantId) {
|
|
7126
|
+
this.ensureInit();
|
|
7127
|
+
const result = await this.pool.query(
|
|
7128
|
+
`SELECT id, name, tenant_id, label, embedding_key, schema, created_at, updated_at
|
|
7129
|
+
FROM lattice_collections WHERE tenant_id = $1 ORDER BY name`,
|
|
7130
|
+
[tenantId]
|
|
7131
|
+
);
|
|
7132
|
+
return result.rows.map(this.rowToCollection);
|
|
7133
|
+
}
|
|
7134
|
+
async getCollectionByName(tenantId, name) {
|
|
7135
|
+
this.ensureInit();
|
|
7136
|
+
const result = await this.pool.query(
|
|
7137
|
+
`SELECT id, name, tenant_id, label, embedding_key, schema, created_at, updated_at
|
|
7138
|
+
FROM lattice_collections WHERE tenant_id = $1 AND name = $2`,
|
|
7139
|
+
[tenantId, name]
|
|
7140
|
+
);
|
|
7141
|
+
return result.rows.length > 0 ? this.rowToCollection(result.rows[0]) : null;
|
|
7142
|
+
}
|
|
7143
|
+
async createCollection(tenantId, data) {
|
|
7144
|
+
this.ensureInit();
|
|
7145
|
+
const schema = JSON.stringify(data.schema || { fields: [] });
|
|
7146
|
+
const result = await this.pool.query(
|
|
7147
|
+
`INSERT INTO lattice_collections (name, tenant_id, label, embedding_key, schema)
|
|
7148
|
+
VALUES ($1, $2, $3, $4, $5)
|
|
7149
|
+
ON CONFLICT (tenant_id, name) DO NOTHING
|
|
7150
|
+
RETURNING id, name, tenant_id, label, embedding_key, schema, created_at, updated_at`,
|
|
7151
|
+
[data.name, tenantId, data.label, data.embeddingKey, schema]
|
|
7152
|
+
);
|
|
7153
|
+
if (result.rows.length === 0) {
|
|
7154
|
+
throw new Error(`Collection "${data.name}" already exists`);
|
|
7155
|
+
}
|
|
7156
|
+
return this.rowToCollection(result.rows[0]);
|
|
7157
|
+
}
|
|
7158
|
+
async updateCollection(tenantId, name, updates) {
|
|
7159
|
+
this.ensureInit();
|
|
7160
|
+
const setClauses = [];
|
|
7161
|
+
const values = [];
|
|
7162
|
+
let paramIndex = 1;
|
|
7163
|
+
if (updates.label !== void 0) {
|
|
7164
|
+
setClauses.push(`label = $${paramIndex++}`);
|
|
7165
|
+
values.push(updates.label);
|
|
7166
|
+
}
|
|
7167
|
+
if (updates.embeddingKey !== void 0) {
|
|
7168
|
+
setClauses.push(`embedding_key = $${paramIndex++}`);
|
|
7169
|
+
values.push(updates.embeddingKey);
|
|
7170
|
+
}
|
|
7171
|
+
if (updates.schema !== void 0) {
|
|
7172
|
+
setClauses.push(`schema = $${paramIndex++}`);
|
|
7173
|
+
values.push(JSON.stringify(updates.schema));
|
|
7174
|
+
}
|
|
7175
|
+
if (setClauses.length === 0) return this.getCollectionByName(tenantId, name);
|
|
7176
|
+
setClauses.push(`updated_at = NOW()`);
|
|
7177
|
+
values.push(tenantId, name);
|
|
7178
|
+
const result = await this.pool.query(
|
|
7179
|
+
`UPDATE lattice_collections SET ${setClauses.join(", ")}
|
|
7180
|
+
WHERE tenant_id = $${paramIndex++} AND name = $${paramIndex}
|
|
7181
|
+
RETURNING id, name, tenant_id, label, embedding_key, schema, created_at, updated_at`,
|
|
7182
|
+
values
|
|
7183
|
+
);
|
|
7184
|
+
return result.rows.length > 0 ? this.rowToCollection(result.rows[0]) : null;
|
|
7185
|
+
}
|
|
7186
|
+
async deleteCollection(tenantId, name) {
|
|
7187
|
+
this.ensureInit();
|
|
7188
|
+
const result = await this.pool.query(
|
|
7189
|
+
`DELETE FROM lattice_collections WHERE tenant_id = $1 AND name = $2`,
|
|
7190
|
+
[tenantId, name]
|
|
7191
|
+
);
|
|
7192
|
+
return (result.rowCount ?? 0) > 0;
|
|
7193
|
+
}
|
|
7194
|
+
async dispose() {
|
|
7195
|
+
if (this.ownsPool && this.pool) {
|
|
7196
|
+
await this.pool.end();
|
|
7197
|
+
}
|
|
7198
|
+
}
|
|
7199
|
+
rowToCollection(row) {
|
|
7200
|
+
return {
|
|
7201
|
+
id: row.id,
|
|
7202
|
+
name: row.name,
|
|
7203
|
+
tenantId: row.tenant_id,
|
|
7204
|
+
label: row.label,
|
|
7205
|
+
embeddingKey: row.embedding_key,
|
|
7206
|
+
schema: typeof row.schema === "string" ? JSON.parse(row.schema) : row.schema,
|
|
7207
|
+
createdAt: row.created_at,
|
|
7208
|
+
updatedAt: row.updated_at
|
|
7209
|
+
};
|
|
7210
|
+
}
|
|
7211
|
+
};
|
|
7212
|
+
|
|
6986
7213
|
// src/createPgStoreConfig.ts
|
|
6987
7214
|
var import_langgraph_checkpoint_postgres = require("@langchain/langgraph-checkpoint-postgres");
|
|
6988
7215
|
|
|
7216
|
+
// src/PGVectorStoreProvider.ts
|
|
7217
|
+
var import_pg22 = require("pg");
|
|
7218
|
+
var import_pgvector = require("@langchain/community/vectorstores/pgvector");
|
|
7219
|
+
var import_documents = require("@langchain/core/documents");
|
|
7220
|
+
var import_core6 = require("@axiom-lattice/core");
|
|
7221
|
+
function safeTableName(name) {
|
|
7222
|
+
if (!/^[a-z][a-z0-9_-]*$/.test(name)) {
|
|
7223
|
+
throw new Error(`Invalid table name: ${name}`);
|
|
7224
|
+
}
|
|
7225
|
+
return name;
|
|
7226
|
+
}
|
|
7227
|
+
var PGVectorStoreProvider = class {
|
|
7228
|
+
constructor(pool, connectionString) {
|
|
7229
|
+
this.pool = pool;
|
|
7230
|
+
this.connectionString = connectionString;
|
|
7231
|
+
}
|
|
7232
|
+
async create(params) {
|
|
7233
|
+
const { tableName, embeddingKey } = params;
|
|
7234
|
+
let embeddings;
|
|
7235
|
+
try {
|
|
7236
|
+
embeddings = import_core6.embeddingsLatticeManager.getEmbeddingsClient(embeddingKey);
|
|
7237
|
+
} catch {
|
|
7238
|
+
try {
|
|
7239
|
+
embeddings = import_core6.embeddingsLatticeManager.getEmbeddingsClient("default");
|
|
7240
|
+
} catch {
|
|
7241
|
+
throw new Error(
|
|
7242
|
+
`No embedding model registered. Register one first:
|
|
7243
|
+
import { registerEmbeddingsLattice } from "@axiom-lattice/core";
|
|
7244
|
+
registerEmbeddingsLattice("default", new SomeEmbeddings(...));`
|
|
7245
|
+
);
|
|
7246
|
+
}
|
|
7247
|
+
}
|
|
7248
|
+
return import_pgvector.PGVectorStore.initialize(embeddings, {
|
|
7249
|
+
postgresConnectionOptions: { connectionString: this.connectionString },
|
|
7250
|
+
tableName: safeTableName(tableName),
|
|
7251
|
+
columns: {
|
|
7252
|
+
idColumnName: "id",
|
|
7253
|
+
vectorColumnName: "vector",
|
|
7254
|
+
contentColumnName: "content",
|
|
7255
|
+
metadataColumnName: "metadata"
|
|
7256
|
+
},
|
|
7257
|
+
distanceStrategy: "cosine"
|
|
7258
|
+
});
|
|
7259
|
+
}
|
|
7260
|
+
async getEntryCount(tableName) {
|
|
7261
|
+
const name = safeTableName(tableName);
|
|
7262
|
+
try {
|
|
7263
|
+
const result = await this.pool.query(`SELECT COUNT(*) as count FROM "${name}"`);
|
|
7264
|
+
return parseInt(result.rows[0]?.count || "0", 10);
|
|
7265
|
+
} catch {
|
|
7266
|
+
return 0;
|
|
7267
|
+
}
|
|
7268
|
+
}
|
|
7269
|
+
async listEntries(tableName) {
|
|
7270
|
+
const name = safeTableName(tableName);
|
|
7271
|
+
try {
|
|
7272
|
+
const result = await this.pool.query(
|
|
7273
|
+
`SELECT content, metadata FROM "${name}" ORDER BY metadata->>'_created_at' DESC`
|
|
7274
|
+
);
|
|
7275
|
+
return result.rows.map((row) => new import_documents.Document({
|
|
7276
|
+
pageContent: row.content || "",
|
|
7277
|
+
metadata: typeof row.metadata === "string" ? JSON.parse(row.metadata) : row.metadata || {}
|
|
7278
|
+
}));
|
|
7279
|
+
} catch {
|
|
7280
|
+
return [];
|
|
7281
|
+
}
|
|
7282
|
+
}
|
|
7283
|
+
async dropTable(tableName) {
|
|
7284
|
+
const name = safeTableName(tableName);
|
|
7285
|
+
await this.pool.query(`DROP TABLE IF EXISTS "${name}"`);
|
|
7286
|
+
}
|
|
7287
|
+
async dispose(_name) {
|
|
7288
|
+
}
|
|
7289
|
+
};
|
|
7290
|
+
function createPGVectorStoreProvider(connectionString) {
|
|
7291
|
+
const pool = new import_pg22.Pool({ connectionString });
|
|
7292
|
+
return {
|
|
7293
|
+
provider: new PGVectorStoreProvider(pool, connectionString),
|
|
7294
|
+
pool
|
|
7295
|
+
};
|
|
7296
|
+
}
|
|
7297
|
+
|
|
6989
7298
|
// src/migrations/skill_migrations.ts
|
|
6990
7299
|
var createSkillsTable = {
|
|
6991
7300
|
version: 4,
|
|
@@ -7194,9 +7503,83 @@ var createChannelIdentityMappingTables = {
|
|
|
7194
7503
|
}
|
|
7195
7504
|
};
|
|
7196
7505
|
|
|
7506
|
+
// src/migrations/connection_config_migrations.ts
|
|
7507
|
+
var createConnectionConfigsTable = {
|
|
7508
|
+
version: 160,
|
|
7509
|
+
name: "create_connection_configs_table",
|
|
7510
|
+
up: async (client) => {
|
|
7511
|
+
await client.query(`
|
|
7512
|
+
CREATE TABLE IF NOT EXISTS lattice_connection_configs (
|
|
7513
|
+
id VARCHAR(255) NOT NULL,
|
|
7514
|
+
tenant_id VARCHAR(255) NOT NULL,
|
|
7515
|
+
type VARCHAR(255) NOT NULL,
|
|
7516
|
+
key VARCHAR(255) NOT NULL,
|
|
7517
|
+
name VARCHAR(255) NOT NULL,
|
|
7518
|
+
description TEXT,
|
|
7519
|
+
config JSONB NOT NULL DEFAULT '{}',
|
|
7520
|
+
status VARCHAR(32) NOT NULL DEFAULT 'active',
|
|
7521
|
+
last_test_result JSONB,
|
|
7522
|
+
metadata JSONB NOT NULL DEFAULT '{}',
|
|
7523
|
+
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
7524
|
+
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
7525
|
+
|
|
7526
|
+
PRIMARY KEY (tenant_id, id),
|
|
7527
|
+
CONSTRAINT uk_lattice_connection_configs_tenant_type_key UNIQUE (tenant_id, type, key)
|
|
7528
|
+
)
|
|
7529
|
+
`);
|
|
7530
|
+
await client.query(`
|
|
7531
|
+
CREATE INDEX IF NOT EXISTS idx_connection_configs_tenant_id
|
|
7532
|
+
ON lattice_connection_configs(tenant_id)
|
|
7533
|
+
`);
|
|
7534
|
+
await client.query(`
|
|
7535
|
+
CREATE INDEX IF NOT EXISTS idx_connection_configs_tenant_type
|
|
7536
|
+
ON lattice_connection_configs(tenant_id, type)
|
|
7537
|
+
`);
|
|
7538
|
+
},
|
|
7539
|
+
down: async (client) => {
|
|
7540
|
+
await client.query("DROP INDEX IF EXISTS idx_connection_configs_tenant_type");
|
|
7541
|
+
await client.query("DROP INDEX IF EXISTS idx_connection_configs_tenant_id");
|
|
7542
|
+
await client.query("DROP TABLE IF EXISTS lattice_connection_configs");
|
|
7543
|
+
}
|
|
7544
|
+
};
|
|
7545
|
+
|
|
7546
|
+
// src/migrations/collection_migrations.ts
|
|
7547
|
+
var createCollectionsTable = {
|
|
7548
|
+
version: 137,
|
|
7549
|
+
name: "create_collections_table",
|
|
7550
|
+
up: async (client) => {
|
|
7551
|
+
await client.query(`
|
|
7552
|
+
CREATE TABLE IF NOT EXISTS lattice_collections (
|
|
7553
|
+
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
7554
|
+
name VARCHAR(255) NOT NULL,
|
|
7555
|
+
tenant_id VARCHAR(255) NOT NULL DEFAULT 'default',
|
|
7556
|
+
label VARCHAR(255) NOT NULL,
|
|
7557
|
+
embedding_key VARCHAR(255) NOT NULL DEFAULT 'default',
|
|
7558
|
+
schema JSONB DEFAULT '{"fields":[]}',
|
|
7559
|
+
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
7560
|
+
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
7561
|
+
UNIQUE(tenant_id, name)
|
|
7562
|
+
)
|
|
7563
|
+
`);
|
|
7564
|
+
await client.query(`
|
|
7565
|
+
CREATE INDEX IF NOT EXISTS idx_lattice_collections_tenant
|
|
7566
|
+
ON lattice_collections(tenant_id)
|
|
7567
|
+
`);
|
|
7568
|
+
await client.query(`
|
|
7569
|
+
CREATE INDEX IF NOT EXISTS idx_lattice_collections_name
|
|
7570
|
+
ON lattice_collections(name)
|
|
7571
|
+
`);
|
|
7572
|
+
},
|
|
7573
|
+
down: async (client) => {
|
|
7574
|
+
await client.query("DROP INDEX IF EXISTS idx_lattice_collections_name");
|
|
7575
|
+
await client.query("DROP INDEX IF EXISTS idx_lattice_collections_tenant");
|
|
7576
|
+
await client.query("DROP TABLE IF EXISTS lattice_collections");
|
|
7577
|
+
}
|
|
7578
|
+
};
|
|
7579
|
+
|
|
7197
7580
|
// src/createPgStoreConfig.ts
|
|
7198
7581
|
async function createPgStoreConfig(connectionString) {
|
|
7199
|
-
const pool = new
|
|
7582
|
+
const pool = new import_pg23.Pool({ connectionString });
|
|
7200
7583
|
const mm = new MigrationManager(pool);
|
|
7201
7584
|
mm.register(createThreadsTable);
|
|
7202
7585
|
mm.register(createScheduledTasksTable);
|
|
@@ -7240,6 +7623,8 @@ async function createPgStoreConfig(connectionString) {
|
|
|
7240
7623
|
mm.register(createMenuItemsTable);
|
|
7241
7624
|
mm.register(createSharedResourcesTable);
|
|
7242
7625
|
mm.register(addFileContentType);
|
|
7626
|
+
mm.register(createCollectionsTable);
|
|
7627
|
+
mm.register(createConnectionConfigsTable);
|
|
7243
7628
|
await mm.migrate();
|
|
7244
7629
|
const checkpoint = import_langgraph_checkpoint_postgres.PostgresSaver.fromConnString(connectionString);
|
|
7245
7630
|
checkpoint.setup().catch((err) => {
|
|
@@ -7257,6 +7642,7 @@ async function createPgStoreConfig(connectionString) {
|
|
|
7257
7642
|
channelInstallation: new PostgreSQLChannelInstallationStore(opts),
|
|
7258
7643
|
thread: new PostgreSQLThreadStore(opts),
|
|
7259
7644
|
database: new PostgreSQLDatabaseConfigStore(opts),
|
|
7645
|
+
connection: new PostgreSQLConnectionStore(pool),
|
|
7260
7646
|
metrics: new PostgreSQLMetricsServerConfigStore(opts),
|
|
7261
7647
|
mcp: new PostgreSQLMcpServerConfigStore(opts),
|
|
7262
7648
|
assistant: new PostgreSQLAssistantStore(opts),
|
|
@@ -7267,12 +7653,14 @@ async function createPgStoreConfig(connectionString) {
|
|
|
7267
7653
|
schedule: new PostgreSQLScheduleStorage(opts),
|
|
7268
7654
|
menu: new MenuStore(opts),
|
|
7269
7655
|
sharedResource: new PostgresSharedResourceStore(opts),
|
|
7656
|
+
collection: new PostgreSQLCollectionStore(opts),
|
|
7657
|
+
vectorStoreProvider: new PGVectorStoreProvider(pool, connectionString),
|
|
7270
7658
|
checkpoint
|
|
7271
7659
|
};
|
|
7272
7660
|
}
|
|
7273
7661
|
|
|
7274
7662
|
// src/stores/PostgreSQLSkillStore.ts
|
|
7275
|
-
var
|
|
7663
|
+
var import_pg24 = require("pg");
|
|
7276
7664
|
var PostgreSQLSkillStore = class {
|
|
7277
7665
|
constructor(options) {
|
|
7278
7666
|
this.initialized = false;
|
|
@@ -7285,9 +7673,9 @@ var PostgreSQLSkillStore = class {
|
|
|
7285
7673
|
return;
|
|
7286
7674
|
}
|
|
7287
7675
|
if (typeof options.poolConfig === "string") {
|
|
7288
|
-
this.pool = new
|
|
7676
|
+
this.pool = new import_pg24.Pool({ connectionString: options.poolConfig });
|
|
7289
7677
|
} else if (options.poolConfig) {
|
|
7290
|
-
this.pool = new
|
|
7678
|
+
this.pool = new import_pg24.Pool(options.poolConfig);
|
|
7291
7679
|
} else {
|
|
7292
7680
|
throw new Error("Either pool or poolConfig must be provided");
|
|
7293
7681
|
}
|
|
@@ -7588,7 +7976,7 @@ var PostgreSQLSkillStore = class {
|
|
|
7588
7976
|
};
|
|
7589
7977
|
|
|
7590
7978
|
// src/stores/ChannelIdentityMappingStore.ts
|
|
7591
|
-
var
|
|
7979
|
+
var import_pg25 = require("pg");
|
|
7592
7980
|
var ChannelIdentityMappingStore = class {
|
|
7593
7981
|
constructor(options) {
|
|
7594
7982
|
this.initialized = false;
|
|
@@ -7600,7 +7988,7 @@ var ChannelIdentityMappingStore = class {
|
|
|
7600
7988
|
this.initialized = true;
|
|
7601
7989
|
return;
|
|
7602
7990
|
}
|
|
7603
|
-
this.pool = typeof options.poolConfig === "string" ? new
|
|
7991
|
+
this.pool = typeof options.poolConfig === "string" ? new import_pg25.Pool({ connectionString: options.poolConfig }) : options.poolConfig ? new import_pg25.Pool(options.poolConfig) : (() => {
|
|
7604
7992
|
throw new Error("Either pool or poolConfig must be provided");
|
|
7605
7993
|
})();
|
|
7606
7994
|
this.migrationManager = new MigrationManager(this.pool);
|
|
@@ -7824,10 +8212,13 @@ function mapRowToChannelIdentityMapping(row) {
|
|
|
7824
8212
|
ChannelIdentityMappingStore,
|
|
7825
8213
|
MenuStore,
|
|
7826
8214
|
MigrationManager,
|
|
8215
|
+
PGVectorStoreProvider,
|
|
7827
8216
|
Pool,
|
|
7828
8217
|
PostgreSQLA2AApiKeyStore,
|
|
7829
8218
|
PostgreSQLAssistantStore,
|
|
7830
8219
|
PostgreSQLChannelInstallationStore,
|
|
8220
|
+
PostgreSQLCollectionStore,
|
|
8221
|
+
PostgreSQLConnectionStore,
|
|
7831
8222
|
PostgreSQLDatabaseConfigStore,
|
|
7832
8223
|
PostgreSQLEvalStore,
|
|
7833
8224
|
PostgreSQLMcpServerConfigStore,
|
|
@@ -7859,6 +8250,7 @@ function mapRowToChannelIdentityMapping(row) {
|
|
|
7859
8250
|
createChannelBindingsTable,
|
|
7860
8251
|
createChannelIdentityMappingTables,
|
|
7861
8252
|
createChannelInstallationsTable,
|
|
8253
|
+
createCollectionsTable,
|
|
7862
8254
|
createDatabaseConfigsTable,
|
|
7863
8255
|
createEvalCasesTable,
|
|
7864
8256
|
createEvalProjectsTable,
|
|
@@ -7868,6 +8260,7 @@ function mapRowToChannelIdentityMapping(row) {
|
|
|
7868
8260
|
createMcpServerConfigsTable,
|
|
7869
8261
|
createMenuItemsTable,
|
|
7870
8262
|
createMetricsConfigsTable,
|
|
8263
|
+
createPGVectorStoreProvider,
|
|
7871
8264
|
createPgStoreConfig,
|
|
7872
8265
|
createProjectsTable,
|
|
7873
8266
|
createScheduledTasksTable,
|