@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.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import { Pool as
|
|
2
|
+
import { Pool as Pool26 } from "pg";
|
|
3
3
|
|
|
4
4
|
// src/createPgStoreConfig.ts
|
|
5
|
-
import { Pool as
|
|
5
|
+
import { Pool as Pool23 } from "pg";
|
|
6
6
|
|
|
7
7
|
// src/migrations/migration.ts
|
|
8
8
|
var MigrationManager = class {
|
|
@@ -1247,6 +1247,101 @@ var PostgreSQLDatabaseConfigStore = class {
|
|
|
1247
1247
|
}
|
|
1248
1248
|
};
|
|
1249
1249
|
|
|
1250
|
+
// src/stores/PostgreSQLConnectionStore.ts
|
|
1251
|
+
import { v4 as uuid } from "uuid";
|
|
1252
|
+
var TABLE = "lattice_connection_configs";
|
|
1253
|
+
var PostgreSQLConnectionStore = class {
|
|
1254
|
+
constructor(db) {
|
|
1255
|
+
this.db = db;
|
|
1256
|
+
}
|
|
1257
|
+
async listByType(tenantId, type) {
|
|
1258
|
+
const result = await this.db.query(
|
|
1259
|
+
`SELECT * FROM ${TABLE} WHERE tenant_id = $1 AND type = $2 ORDER BY created_at`,
|
|
1260
|
+
[tenantId, type]
|
|
1261
|
+
);
|
|
1262
|
+
return result.rows.map((row) => this.mapRow(row));
|
|
1263
|
+
}
|
|
1264
|
+
async getByKey(tenantId, type, key) {
|
|
1265
|
+
const result = await this.db.query(
|
|
1266
|
+
`SELECT * FROM ${TABLE} WHERE tenant_id = $1 AND type = $2 AND key = $3`,
|
|
1267
|
+
[tenantId, type, key]
|
|
1268
|
+
);
|
|
1269
|
+
if (result.rows.length === 0) return null;
|
|
1270
|
+
return this.mapRow(result.rows[0]);
|
|
1271
|
+
}
|
|
1272
|
+
async create(entry) {
|
|
1273
|
+
const id = uuid();
|
|
1274
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
1275
|
+
await this.db.query(
|
|
1276
|
+
`INSERT INTO ${TABLE} (id, tenant_id, type, key, name, description, config, status, created_at, updated_at)
|
|
1277
|
+
VALUES ($1, $2, $3, $4, $5, $6, $7, 'active', $8::timestamp, $9::timestamp)`,
|
|
1278
|
+
[
|
|
1279
|
+
id,
|
|
1280
|
+
entry.tenantId,
|
|
1281
|
+
entry.type,
|
|
1282
|
+
entry.key,
|
|
1283
|
+
entry.name,
|
|
1284
|
+
entry.description || null,
|
|
1285
|
+
JSON.stringify(entry.config),
|
|
1286
|
+
now,
|
|
1287
|
+
now
|
|
1288
|
+
]
|
|
1289
|
+
);
|
|
1290
|
+
return { id, ...entry, createdAt: now, updatedAt: now };
|
|
1291
|
+
}
|
|
1292
|
+
async update(tenantId, type, key, updates) {
|
|
1293
|
+
const existing = await this.getByKey(tenantId, type, key);
|
|
1294
|
+
if (!existing) return null;
|
|
1295
|
+
const setClauses = [];
|
|
1296
|
+
const values = [];
|
|
1297
|
+
let paramIndex = 1;
|
|
1298
|
+
if (updates.name !== void 0) {
|
|
1299
|
+
setClauses.push(`name = $${paramIndex++}`);
|
|
1300
|
+
values.push(updates.name);
|
|
1301
|
+
}
|
|
1302
|
+
if (updates.description !== void 0) {
|
|
1303
|
+
setClauses.push(`description = $${paramIndex++}`);
|
|
1304
|
+
values.push(updates.description || null);
|
|
1305
|
+
}
|
|
1306
|
+
if (updates.config !== void 0) {
|
|
1307
|
+
setClauses.push(`config = $${paramIndex++}`);
|
|
1308
|
+
values.push(JSON.stringify(updates.config));
|
|
1309
|
+
}
|
|
1310
|
+
if (setClauses.length === 0) return existing;
|
|
1311
|
+
setClauses.push(`updated_at = $${paramIndex++}::timestamp`);
|
|
1312
|
+
values.push((/* @__PURE__ */ new Date()).toISOString());
|
|
1313
|
+
values.push(tenantId, type, key);
|
|
1314
|
+
const whereTenant = paramIndex++;
|
|
1315
|
+
const whereType = paramIndex++;
|
|
1316
|
+
const whereKey = paramIndex;
|
|
1317
|
+
await this.db.query(
|
|
1318
|
+
`UPDATE ${TABLE} SET ${setClauses.join(", ")} WHERE tenant_id = $${whereTenant} AND type = $${whereType} AND key = $${whereKey}`,
|
|
1319
|
+
values
|
|
1320
|
+
);
|
|
1321
|
+
return this.getByKey(tenantId, type, key);
|
|
1322
|
+
}
|
|
1323
|
+
async delete(tenantId, type, key) {
|
|
1324
|
+
const result = await this.db.query(
|
|
1325
|
+
`DELETE FROM ${TABLE} WHERE tenant_id = $1 AND type = $2 AND key = $3`,
|
|
1326
|
+
[tenantId, type, key]
|
|
1327
|
+
);
|
|
1328
|
+
return (result.rowCount ?? 0) > 0;
|
|
1329
|
+
}
|
|
1330
|
+
mapRow(row) {
|
|
1331
|
+
return {
|
|
1332
|
+
id: row.id,
|
|
1333
|
+
tenantId: row.tenant_id,
|
|
1334
|
+
type: row.type,
|
|
1335
|
+
key: row.key,
|
|
1336
|
+
name: row.name,
|
|
1337
|
+
description: row.description || void 0,
|
|
1338
|
+
config: typeof row.config === "string" ? JSON.parse(row.config) : row.config,
|
|
1339
|
+
createdAt: row.created_at instanceof Date ? row.created_at.toISOString() : String(row.created_at),
|
|
1340
|
+
updatedAt: row.updated_at instanceof Date ? row.updated_at.toISOString() : String(row.updated_at)
|
|
1341
|
+
};
|
|
1342
|
+
}
|
|
1343
|
+
};
|
|
1344
|
+
|
|
1250
1345
|
// src/stores/PostgreSQLMetricsServerConfigStore.ts
|
|
1251
1346
|
import { Pool as Pool4 } from "pg";
|
|
1252
1347
|
|
|
@@ -1775,7 +1870,7 @@ var PostgreSQLMcpServerConfigStore = class {
|
|
|
1775
1870
|
data.name || null,
|
|
1776
1871
|
data.description || null,
|
|
1777
1872
|
JSON.stringify(configWithEncryptedEnv),
|
|
1778
|
-
data.selectedTools || [],
|
|
1873
|
+
JSON.stringify(data.selectedTools || []),
|
|
1779
1874
|
isEnvEncrypted,
|
|
1780
1875
|
"disconnected",
|
|
1781
1876
|
nowString,
|
|
@@ -1821,7 +1916,7 @@ var PostgreSQLMcpServerConfigStore = class {
|
|
|
1821
1916
|
updateData.is_env_encrypted = isEnvEncrypted;
|
|
1822
1917
|
}
|
|
1823
1918
|
if (updates.selectedTools !== void 0) {
|
|
1824
|
-
updateData.selected_tools = updates.selectedTools;
|
|
1919
|
+
updateData.selected_tools = JSON.stringify(updates.selectedTools);
|
|
1825
1920
|
}
|
|
1826
1921
|
if (updates.status !== void 0) {
|
|
1827
1922
|
updateData.status = updates.status;
|
|
@@ -6889,9 +6984,218 @@ var PostgresSharedResourceStore = class {
|
|
|
6889
6984
|
}
|
|
6890
6985
|
};
|
|
6891
6986
|
|
|
6987
|
+
// src/stores/PostgreSQLCollectionStore.ts
|
|
6988
|
+
import { Pool as Pool21 } from "pg";
|
|
6989
|
+
var PostgreSQLCollectionStore = class {
|
|
6990
|
+
constructor(options) {
|
|
6991
|
+
this.initialized = false;
|
|
6992
|
+
this.ownsPool = true;
|
|
6993
|
+
this.initPromise = null;
|
|
6994
|
+
if (options.pool) {
|
|
6995
|
+
this.pool = options.pool;
|
|
6996
|
+
this.ownsPool = false;
|
|
6997
|
+
this.initialized = true;
|
|
6998
|
+
return;
|
|
6999
|
+
}
|
|
7000
|
+
if (typeof options.poolConfig === "string") {
|
|
7001
|
+
this.pool = new Pool21({ connectionString: options.poolConfig });
|
|
7002
|
+
} else if (options.poolConfig) {
|
|
7003
|
+
this.pool = new Pool21(options.poolConfig);
|
|
7004
|
+
} else {
|
|
7005
|
+
throw new Error("Either pool or poolConfig must be provided");
|
|
7006
|
+
}
|
|
7007
|
+
if (options.autoMigrate !== false) {
|
|
7008
|
+
this.initialize().catch((error) => {
|
|
7009
|
+
console.error("Failed to initialize PostgreSQLCollectionStore:", error);
|
|
7010
|
+
});
|
|
7011
|
+
}
|
|
7012
|
+
}
|
|
7013
|
+
async initialize() {
|
|
7014
|
+
if (this.initialized) return;
|
|
7015
|
+
if (this.initPromise) return this.initPromise;
|
|
7016
|
+
this.initPromise = (async () => {
|
|
7017
|
+
this.initialized = true;
|
|
7018
|
+
})();
|
|
7019
|
+
return this.initPromise;
|
|
7020
|
+
}
|
|
7021
|
+
ensureInit() {
|
|
7022
|
+
if (!this.initialized) {
|
|
7023
|
+
throw new Error("PostgreSQLCollectionStore not initialized");
|
|
7024
|
+
}
|
|
7025
|
+
}
|
|
7026
|
+
async getAllCollections(tenantId) {
|
|
7027
|
+
this.ensureInit();
|
|
7028
|
+
const result = await this.pool.query(
|
|
7029
|
+
`SELECT id, name, tenant_id, label, embedding_key, schema, created_at, updated_at
|
|
7030
|
+
FROM lattice_collections WHERE tenant_id = $1 ORDER BY name`,
|
|
7031
|
+
[tenantId]
|
|
7032
|
+
);
|
|
7033
|
+
return result.rows.map(this.rowToCollection);
|
|
7034
|
+
}
|
|
7035
|
+
async getCollectionByName(tenantId, name) {
|
|
7036
|
+
this.ensureInit();
|
|
7037
|
+
const result = await this.pool.query(
|
|
7038
|
+
`SELECT id, name, tenant_id, label, embedding_key, schema, created_at, updated_at
|
|
7039
|
+
FROM lattice_collections WHERE tenant_id = $1 AND name = $2`,
|
|
7040
|
+
[tenantId, name]
|
|
7041
|
+
);
|
|
7042
|
+
return result.rows.length > 0 ? this.rowToCollection(result.rows[0]) : null;
|
|
7043
|
+
}
|
|
7044
|
+
async createCollection(tenantId, data) {
|
|
7045
|
+
this.ensureInit();
|
|
7046
|
+
const schema = JSON.stringify(data.schema || { fields: [] });
|
|
7047
|
+
const result = await this.pool.query(
|
|
7048
|
+
`INSERT INTO lattice_collections (name, tenant_id, label, embedding_key, schema)
|
|
7049
|
+
VALUES ($1, $2, $3, $4, $5)
|
|
7050
|
+
ON CONFLICT (tenant_id, name) DO NOTHING
|
|
7051
|
+
RETURNING id, name, tenant_id, label, embedding_key, schema, created_at, updated_at`,
|
|
7052
|
+
[data.name, tenantId, data.label, data.embeddingKey, schema]
|
|
7053
|
+
);
|
|
7054
|
+
if (result.rows.length === 0) {
|
|
7055
|
+
throw new Error(`Collection "${data.name}" already exists`);
|
|
7056
|
+
}
|
|
7057
|
+
return this.rowToCollection(result.rows[0]);
|
|
7058
|
+
}
|
|
7059
|
+
async updateCollection(tenantId, name, updates) {
|
|
7060
|
+
this.ensureInit();
|
|
7061
|
+
const setClauses = [];
|
|
7062
|
+
const values = [];
|
|
7063
|
+
let paramIndex = 1;
|
|
7064
|
+
if (updates.label !== void 0) {
|
|
7065
|
+
setClauses.push(`label = $${paramIndex++}`);
|
|
7066
|
+
values.push(updates.label);
|
|
7067
|
+
}
|
|
7068
|
+
if (updates.embeddingKey !== void 0) {
|
|
7069
|
+
setClauses.push(`embedding_key = $${paramIndex++}`);
|
|
7070
|
+
values.push(updates.embeddingKey);
|
|
7071
|
+
}
|
|
7072
|
+
if (updates.schema !== void 0) {
|
|
7073
|
+
setClauses.push(`schema = $${paramIndex++}`);
|
|
7074
|
+
values.push(JSON.stringify(updates.schema));
|
|
7075
|
+
}
|
|
7076
|
+
if (setClauses.length === 0) return this.getCollectionByName(tenantId, name);
|
|
7077
|
+
setClauses.push(`updated_at = NOW()`);
|
|
7078
|
+
values.push(tenantId, name);
|
|
7079
|
+
const result = await this.pool.query(
|
|
7080
|
+
`UPDATE lattice_collections SET ${setClauses.join(", ")}
|
|
7081
|
+
WHERE tenant_id = $${paramIndex++} AND name = $${paramIndex}
|
|
7082
|
+
RETURNING id, name, tenant_id, label, embedding_key, schema, created_at, updated_at`,
|
|
7083
|
+
values
|
|
7084
|
+
);
|
|
7085
|
+
return result.rows.length > 0 ? this.rowToCollection(result.rows[0]) : null;
|
|
7086
|
+
}
|
|
7087
|
+
async deleteCollection(tenantId, name) {
|
|
7088
|
+
this.ensureInit();
|
|
7089
|
+
const result = await this.pool.query(
|
|
7090
|
+
`DELETE FROM lattice_collections WHERE tenant_id = $1 AND name = $2`,
|
|
7091
|
+
[tenantId, name]
|
|
7092
|
+
);
|
|
7093
|
+
return (result.rowCount ?? 0) > 0;
|
|
7094
|
+
}
|
|
7095
|
+
async dispose() {
|
|
7096
|
+
if (this.ownsPool && this.pool) {
|
|
7097
|
+
await this.pool.end();
|
|
7098
|
+
}
|
|
7099
|
+
}
|
|
7100
|
+
rowToCollection(row) {
|
|
7101
|
+
return {
|
|
7102
|
+
id: row.id,
|
|
7103
|
+
name: row.name,
|
|
7104
|
+
tenantId: row.tenant_id,
|
|
7105
|
+
label: row.label,
|
|
7106
|
+
embeddingKey: row.embedding_key,
|
|
7107
|
+
schema: typeof row.schema === "string" ? JSON.parse(row.schema) : row.schema,
|
|
7108
|
+
createdAt: row.created_at,
|
|
7109
|
+
updatedAt: row.updated_at
|
|
7110
|
+
};
|
|
7111
|
+
}
|
|
7112
|
+
};
|
|
7113
|
+
|
|
6892
7114
|
// src/createPgStoreConfig.ts
|
|
6893
7115
|
import { PostgresSaver } from "@langchain/langgraph-checkpoint-postgres";
|
|
6894
7116
|
|
|
7117
|
+
// src/PGVectorStoreProvider.ts
|
|
7118
|
+
import { Pool as Pool22 } from "pg";
|
|
7119
|
+
import { PGVectorStore } from "@langchain/community/vectorstores/pgvector";
|
|
7120
|
+
import { Document } from "@langchain/core/documents";
|
|
7121
|
+
import { embeddingsLatticeManager } from "@axiom-lattice/core";
|
|
7122
|
+
function safeTableName(name) {
|
|
7123
|
+
if (!/^[a-z][a-z0-9_-]*$/.test(name)) {
|
|
7124
|
+
throw new Error(`Invalid table name: ${name}`);
|
|
7125
|
+
}
|
|
7126
|
+
return name;
|
|
7127
|
+
}
|
|
7128
|
+
var PGVectorStoreProvider = class {
|
|
7129
|
+
constructor(pool, connectionString) {
|
|
7130
|
+
this.pool = pool;
|
|
7131
|
+
this.connectionString = connectionString;
|
|
7132
|
+
}
|
|
7133
|
+
async create(params) {
|
|
7134
|
+
const { tableName, embeddingKey } = params;
|
|
7135
|
+
let embeddings;
|
|
7136
|
+
try {
|
|
7137
|
+
embeddings = embeddingsLatticeManager.getEmbeddingsClient(embeddingKey);
|
|
7138
|
+
} catch {
|
|
7139
|
+
try {
|
|
7140
|
+
embeddings = embeddingsLatticeManager.getEmbeddingsClient("default");
|
|
7141
|
+
} catch {
|
|
7142
|
+
throw new Error(
|
|
7143
|
+
`No embedding model registered. Register one first:
|
|
7144
|
+
import { registerEmbeddingsLattice } from "@axiom-lattice/core";
|
|
7145
|
+
registerEmbeddingsLattice("default", new SomeEmbeddings(...));`
|
|
7146
|
+
);
|
|
7147
|
+
}
|
|
7148
|
+
}
|
|
7149
|
+
return PGVectorStore.initialize(embeddings, {
|
|
7150
|
+
postgresConnectionOptions: { connectionString: this.connectionString },
|
|
7151
|
+
tableName: safeTableName(tableName),
|
|
7152
|
+
columns: {
|
|
7153
|
+
idColumnName: "id",
|
|
7154
|
+
vectorColumnName: "vector",
|
|
7155
|
+
contentColumnName: "content",
|
|
7156
|
+
metadataColumnName: "metadata"
|
|
7157
|
+
},
|
|
7158
|
+
distanceStrategy: "cosine"
|
|
7159
|
+
});
|
|
7160
|
+
}
|
|
7161
|
+
async getEntryCount(tableName) {
|
|
7162
|
+
const name = safeTableName(tableName);
|
|
7163
|
+
try {
|
|
7164
|
+
const result = await this.pool.query(`SELECT COUNT(*) as count FROM "${name}"`);
|
|
7165
|
+
return parseInt(result.rows[0]?.count || "0", 10);
|
|
7166
|
+
} catch {
|
|
7167
|
+
return 0;
|
|
7168
|
+
}
|
|
7169
|
+
}
|
|
7170
|
+
async listEntries(tableName) {
|
|
7171
|
+
const name = safeTableName(tableName);
|
|
7172
|
+
try {
|
|
7173
|
+
const result = await this.pool.query(
|
|
7174
|
+
`SELECT content, metadata FROM "${name}" ORDER BY metadata->>'_created_at' DESC`
|
|
7175
|
+
);
|
|
7176
|
+
return result.rows.map((row) => new Document({
|
|
7177
|
+
pageContent: row.content || "",
|
|
7178
|
+
metadata: typeof row.metadata === "string" ? JSON.parse(row.metadata) : row.metadata || {}
|
|
7179
|
+
}));
|
|
7180
|
+
} catch {
|
|
7181
|
+
return [];
|
|
7182
|
+
}
|
|
7183
|
+
}
|
|
7184
|
+
async dropTable(tableName) {
|
|
7185
|
+
const name = safeTableName(tableName);
|
|
7186
|
+
await this.pool.query(`DROP TABLE IF EXISTS "${name}"`);
|
|
7187
|
+
}
|
|
7188
|
+
async dispose(_name) {
|
|
7189
|
+
}
|
|
7190
|
+
};
|
|
7191
|
+
function createPGVectorStoreProvider(connectionString) {
|
|
7192
|
+
const pool = new Pool22({ connectionString });
|
|
7193
|
+
return {
|
|
7194
|
+
provider: new PGVectorStoreProvider(pool, connectionString),
|
|
7195
|
+
pool
|
|
7196
|
+
};
|
|
7197
|
+
}
|
|
7198
|
+
|
|
6895
7199
|
// src/migrations/skill_migrations.ts
|
|
6896
7200
|
var createSkillsTable = {
|
|
6897
7201
|
version: 4,
|
|
@@ -7100,9 +7404,83 @@ var createChannelIdentityMappingTables = {
|
|
|
7100
7404
|
}
|
|
7101
7405
|
};
|
|
7102
7406
|
|
|
7407
|
+
// src/migrations/connection_config_migrations.ts
|
|
7408
|
+
var createConnectionConfigsTable = {
|
|
7409
|
+
version: 160,
|
|
7410
|
+
name: "create_connection_configs_table",
|
|
7411
|
+
up: async (client) => {
|
|
7412
|
+
await client.query(`
|
|
7413
|
+
CREATE TABLE IF NOT EXISTS lattice_connection_configs (
|
|
7414
|
+
id VARCHAR(255) NOT NULL,
|
|
7415
|
+
tenant_id VARCHAR(255) NOT NULL,
|
|
7416
|
+
type VARCHAR(255) NOT NULL,
|
|
7417
|
+
key VARCHAR(255) NOT NULL,
|
|
7418
|
+
name VARCHAR(255) NOT NULL,
|
|
7419
|
+
description TEXT,
|
|
7420
|
+
config JSONB NOT NULL DEFAULT '{}',
|
|
7421
|
+
status VARCHAR(32) NOT NULL DEFAULT 'active',
|
|
7422
|
+
last_test_result JSONB,
|
|
7423
|
+
metadata JSONB NOT NULL DEFAULT '{}',
|
|
7424
|
+
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
7425
|
+
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
7426
|
+
|
|
7427
|
+
PRIMARY KEY (tenant_id, id),
|
|
7428
|
+
CONSTRAINT uk_lattice_connection_configs_tenant_type_key UNIQUE (tenant_id, type, key)
|
|
7429
|
+
)
|
|
7430
|
+
`);
|
|
7431
|
+
await client.query(`
|
|
7432
|
+
CREATE INDEX IF NOT EXISTS idx_connection_configs_tenant_id
|
|
7433
|
+
ON lattice_connection_configs(tenant_id)
|
|
7434
|
+
`);
|
|
7435
|
+
await client.query(`
|
|
7436
|
+
CREATE INDEX IF NOT EXISTS idx_connection_configs_tenant_type
|
|
7437
|
+
ON lattice_connection_configs(tenant_id, type)
|
|
7438
|
+
`);
|
|
7439
|
+
},
|
|
7440
|
+
down: async (client) => {
|
|
7441
|
+
await client.query("DROP INDEX IF EXISTS idx_connection_configs_tenant_type");
|
|
7442
|
+
await client.query("DROP INDEX IF EXISTS idx_connection_configs_tenant_id");
|
|
7443
|
+
await client.query("DROP TABLE IF EXISTS lattice_connection_configs");
|
|
7444
|
+
}
|
|
7445
|
+
};
|
|
7446
|
+
|
|
7447
|
+
// src/migrations/collection_migrations.ts
|
|
7448
|
+
var createCollectionsTable = {
|
|
7449
|
+
version: 137,
|
|
7450
|
+
name: "create_collections_table",
|
|
7451
|
+
up: async (client) => {
|
|
7452
|
+
await client.query(`
|
|
7453
|
+
CREATE TABLE IF NOT EXISTS lattice_collections (
|
|
7454
|
+
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
7455
|
+
name VARCHAR(255) NOT NULL,
|
|
7456
|
+
tenant_id VARCHAR(255) NOT NULL DEFAULT 'default',
|
|
7457
|
+
label VARCHAR(255) NOT NULL,
|
|
7458
|
+
embedding_key VARCHAR(255) NOT NULL DEFAULT 'default',
|
|
7459
|
+
schema JSONB DEFAULT '{"fields":[]}',
|
|
7460
|
+
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
7461
|
+
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
7462
|
+
UNIQUE(tenant_id, name)
|
|
7463
|
+
)
|
|
7464
|
+
`);
|
|
7465
|
+
await client.query(`
|
|
7466
|
+
CREATE INDEX IF NOT EXISTS idx_lattice_collections_tenant
|
|
7467
|
+
ON lattice_collections(tenant_id)
|
|
7468
|
+
`);
|
|
7469
|
+
await client.query(`
|
|
7470
|
+
CREATE INDEX IF NOT EXISTS idx_lattice_collections_name
|
|
7471
|
+
ON lattice_collections(name)
|
|
7472
|
+
`);
|
|
7473
|
+
},
|
|
7474
|
+
down: async (client) => {
|
|
7475
|
+
await client.query("DROP INDEX IF EXISTS idx_lattice_collections_name");
|
|
7476
|
+
await client.query("DROP INDEX IF EXISTS idx_lattice_collections_tenant");
|
|
7477
|
+
await client.query("DROP TABLE IF EXISTS lattice_collections");
|
|
7478
|
+
}
|
|
7479
|
+
};
|
|
7480
|
+
|
|
7103
7481
|
// src/createPgStoreConfig.ts
|
|
7104
7482
|
async function createPgStoreConfig(connectionString) {
|
|
7105
|
-
const pool = new
|
|
7483
|
+
const pool = new Pool23({ connectionString });
|
|
7106
7484
|
const mm = new MigrationManager(pool);
|
|
7107
7485
|
mm.register(createThreadsTable);
|
|
7108
7486
|
mm.register(createScheduledTasksTable);
|
|
@@ -7146,6 +7524,8 @@ async function createPgStoreConfig(connectionString) {
|
|
|
7146
7524
|
mm.register(createMenuItemsTable);
|
|
7147
7525
|
mm.register(createSharedResourcesTable);
|
|
7148
7526
|
mm.register(addFileContentType);
|
|
7527
|
+
mm.register(createCollectionsTable);
|
|
7528
|
+
mm.register(createConnectionConfigsTable);
|
|
7149
7529
|
await mm.migrate();
|
|
7150
7530
|
const checkpoint = PostgresSaver.fromConnString(connectionString);
|
|
7151
7531
|
checkpoint.setup().catch((err) => {
|
|
@@ -7163,6 +7543,7 @@ async function createPgStoreConfig(connectionString) {
|
|
|
7163
7543
|
channelInstallation: new PostgreSQLChannelInstallationStore(opts),
|
|
7164
7544
|
thread: new PostgreSQLThreadStore(opts),
|
|
7165
7545
|
database: new PostgreSQLDatabaseConfigStore(opts),
|
|
7546
|
+
connection: new PostgreSQLConnectionStore(pool),
|
|
7166
7547
|
metrics: new PostgreSQLMetricsServerConfigStore(opts),
|
|
7167
7548
|
mcp: new PostgreSQLMcpServerConfigStore(opts),
|
|
7168
7549
|
assistant: new PostgreSQLAssistantStore(opts),
|
|
@@ -7173,12 +7554,14 @@ async function createPgStoreConfig(connectionString) {
|
|
|
7173
7554
|
schedule: new PostgreSQLScheduleStorage(opts),
|
|
7174
7555
|
menu: new MenuStore(opts),
|
|
7175
7556
|
sharedResource: new PostgresSharedResourceStore(opts),
|
|
7557
|
+
collection: new PostgreSQLCollectionStore(opts),
|
|
7558
|
+
vectorStoreProvider: new PGVectorStoreProvider(pool, connectionString),
|
|
7176
7559
|
checkpoint
|
|
7177
7560
|
};
|
|
7178
7561
|
}
|
|
7179
7562
|
|
|
7180
7563
|
// src/stores/PostgreSQLSkillStore.ts
|
|
7181
|
-
import { Pool as
|
|
7564
|
+
import { Pool as Pool24 } from "pg";
|
|
7182
7565
|
var PostgreSQLSkillStore = class {
|
|
7183
7566
|
constructor(options) {
|
|
7184
7567
|
this.initialized = false;
|
|
@@ -7191,9 +7574,9 @@ var PostgreSQLSkillStore = class {
|
|
|
7191
7574
|
return;
|
|
7192
7575
|
}
|
|
7193
7576
|
if (typeof options.poolConfig === "string") {
|
|
7194
|
-
this.pool = new
|
|
7577
|
+
this.pool = new Pool24({ connectionString: options.poolConfig });
|
|
7195
7578
|
} else if (options.poolConfig) {
|
|
7196
|
-
this.pool = new
|
|
7579
|
+
this.pool = new Pool24(options.poolConfig);
|
|
7197
7580
|
} else {
|
|
7198
7581
|
throw new Error("Either pool or poolConfig must be provided");
|
|
7199
7582
|
}
|
|
@@ -7494,7 +7877,7 @@ var PostgreSQLSkillStore = class {
|
|
|
7494
7877
|
};
|
|
7495
7878
|
|
|
7496
7879
|
// src/stores/ChannelIdentityMappingStore.ts
|
|
7497
|
-
import { Pool as
|
|
7880
|
+
import { Pool as Pool25 } from "pg";
|
|
7498
7881
|
var ChannelIdentityMappingStore = class {
|
|
7499
7882
|
constructor(options) {
|
|
7500
7883
|
this.initialized = false;
|
|
@@ -7506,7 +7889,7 @@ var ChannelIdentityMappingStore = class {
|
|
|
7506
7889
|
this.initialized = true;
|
|
7507
7890
|
return;
|
|
7508
7891
|
}
|
|
7509
|
-
this.pool = typeof options.poolConfig === "string" ? new
|
|
7892
|
+
this.pool = typeof options.poolConfig === "string" ? new Pool25({ connectionString: options.poolConfig }) : options.poolConfig ? new Pool25(options.poolConfig) : (() => {
|
|
7510
7893
|
throw new Error("Either pool or poolConfig must be provided");
|
|
7511
7894
|
})();
|
|
7512
7895
|
this.migrationManager = new MigrationManager(this.pool);
|
|
@@ -7729,10 +8112,13 @@ export {
|
|
|
7729
8112
|
ChannelIdentityMappingStore,
|
|
7730
8113
|
MenuStore,
|
|
7731
8114
|
MigrationManager,
|
|
7732
|
-
|
|
8115
|
+
PGVectorStoreProvider,
|
|
8116
|
+
Pool26 as Pool,
|
|
7733
8117
|
PostgreSQLA2AApiKeyStore,
|
|
7734
8118
|
PostgreSQLAssistantStore,
|
|
7735
8119
|
PostgreSQLChannelInstallationStore,
|
|
8120
|
+
PostgreSQLCollectionStore,
|
|
8121
|
+
PostgreSQLConnectionStore,
|
|
7736
8122
|
PostgreSQLDatabaseConfigStore,
|
|
7737
8123
|
PostgreSQLEvalStore,
|
|
7738
8124
|
PostgreSQLMcpServerConfigStore,
|
|
@@ -7764,6 +8150,7 @@ export {
|
|
|
7764
8150
|
createChannelBindingsTable,
|
|
7765
8151
|
createChannelIdentityMappingTables,
|
|
7766
8152
|
createChannelInstallationsTable,
|
|
8153
|
+
createCollectionsTable,
|
|
7767
8154
|
createDatabaseConfigsTable,
|
|
7768
8155
|
createEvalCasesTable,
|
|
7769
8156
|
createEvalProjectsTable,
|
|
@@ -7773,6 +8160,7 @@ export {
|
|
|
7773
8160
|
createMcpServerConfigsTable,
|
|
7774
8161
|
createMenuItemsTable,
|
|
7775
8162
|
createMetricsConfigsTable,
|
|
8163
|
+
createPGVectorStoreProvider,
|
|
7776
8164
|
createPgStoreConfig,
|
|
7777
8165
|
createProjectsTable,
|
|
7778
8166
|
createScheduledTasksTable,
|