@axiom-lattice/pg-stores 4.0.0 → 4.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/.turbo/turbo-build.log +8 -8
- package/CHANGELOG.md +15 -0
- package/dist/index.js +59 -23
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +46 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/PGVectorStoreProvider.ts +16 -5
- package/src/__tests__/AgentRunRetention.migrations.test.ts +3 -1
- package/src/createPgStoreConfig.ts +2 -0
- package/src/migrations/model_provider_migrations.ts +38 -0
- package/src/stores/PostgreSQLModelProviderStore.ts +28 -14
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @axiom-lattice/pg-stores@4.0.
|
|
2
|
+
> @axiom-lattice/pg-stores@4.0.2 build /home/runner/work/agentic/agentic/packages/pg-stores
|
|
3
3
|
> tsup src/index.ts --format cjs,esm --dts --sourcemap
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
[34mCLI[39m Target: es2020
|
|
9
9
|
[34mCJS[39m Build start
|
|
10
10
|
[34mESM[39m Build start
|
|
11
|
-
[32mCJS[39m [1mdist/index.js [22m[
|
|
12
|
-
[32mCJS[39m [1mdist/index.js.map [22m[
|
|
13
|
-
[32mCJS[39m ⚡️ Build success in
|
|
14
|
-
[32mESM[39m [1mdist/index.mjs [22m[
|
|
15
|
-
[32mESM[39m [1mdist/index.mjs.map [22m[
|
|
16
|
-
[32mESM[39m ⚡️ Build success in
|
|
11
|
+
[32mCJS[39m [1mdist/index.js [22m[32m529.56 KB[39m
|
|
12
|
+
[32mCJS[39m [1mdist/index.js.map [22m[32m963.70 KB[39m
|
|
13
|
+
[32mCJS[39m ⚡️ Build success in 847ms
|
|
14
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m520.06 KB[39m
|
|
15
|
+
[32mESM[39m [1mdist/index.mjs.map [22m[32m963.41 KB[39m
|
|
16
|
+
[32mESM[39m ⚡️ Build success in 848ms
|
|
17
17
|
[34mDTS[39m Build start
|
|
18
|
-
[32mDTS[39m ⚡️ Build success in
|
|
18
|
+
[32mDTS[39m ⚡️ Build success in 10223ms
|
|
19
19
|
[32mDTS[39m [1mdist/index.d.ts [22m[32m110.68 KB[39m
|
|
20
20
|
[32mDTS[39m [1mdist/index.d.mts [22m[32m110.68 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @axiom-lattice/pg-stores
|
|
2
2
|
|
|
3
|
+
## 4.0.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [a75acf3]
|
|
8
|
+
- @axiom-lattice/protocols@6.1.0
|
|
9
|
+
- @axiom-lattice/core@10.0.2
|
|
10
|
+
|
|
11
|
+
## 4.0.1
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [11f6d6a]
|
|
16
|
+
- @axiom-lattice/core@10.0.1
|
|
17
|
+
|
|
3
18
|
## 4.0.0
|
|
4
19
|
|
|
5
20
|
### Major Changes
|
package/dist/index.js
CHANGED
|
@@ -9692,6 +9692,7 @@ var import_pg25 = require("pg");
|
|
|
9692
9692
|
var import_pgvector = require("@langchain/community/vectorstores/pgvector");
|
|
9693
9693
|
var import_documents = require("@langchain/core/documents");
|
|
9694
9694
|
var import_core7 = require("@axiom-lattice/core");
|
|
9695
|
+
var import_protocols6 = require("@axiom-lattice/protocols");
|
|
9695
9696
|
function safeTableName(name) {
|
|
9696
9697
|
if (!/^[a-z][a-z0-9_-]*$/.test(name)) {
|
|
9697
9698
|
throw new Error(`Invalid table name: ${name}`);
|
|
@@ -9706,16 +9707,20 @@ var PGVectorStoreProvider = class {
|
|
|
9706
9707
|
async create(params) {
|
|
9707
9708
|
const { tableName, embeddingKey } = params;
|
|
9708
9709
|
const tenantId = params.tenantId ?? "default";
|
|
9710
|
+
const requestedKey = embeddingKey || import_protocols6.EMBEDDING_DEFAULT_KEY;
|
|
9709
9711
|
const embeddings = await import_core7.embeddingsLatticeManager.getEmbeddingsClientWithTenant(
|
|
9710
9712
|
tenantId,
|
|
9711
|
-
|
|
9712
|
-
) ?? await import_core7.embeddingsLatticeManager.getEmbeddingsClientWithTenant(
|
|
9713
|
+
requestedKey
|
|
9714
|
+
) ?? (requestedKey === import_protocols6.EMBEDDING_DEFAULT_KEY ? void 0 : await import_core7.embeddingsLatticeManager.getEmbeddingsClientWithTenant(
|
|
9715
|
+
tenantId,
|
|
9716
|
+
import_protocols6.EMBEDDING_DEFAULT_KEY
|
|
9717
|
+
)) ?? await import_core7.embeddingsLatticeManager.getEmbeddingsClientWithTenant(
|
|
9713
9718
|
tenantId,
|
|
9714
9719
|
"default"
|
|
9715
9720
|
);
|
|
9716
9721
|
if (!embeddings) {
|
|
9717
9722
|
throw new Error(
|
|
9718
|
-
`No embedding model "${embeddingKey}" registered for tenant "${tenantId}", and no deployment default. Configure one in the model
|
|
9723
|
+
`No embedding model "${embeddingKey}" registered for tenant "${tenantId}", and no tenant or deployment default. Configure one in the model service panel.`
|
|
9719
9724
|
);
|
|
9720
9725
|
}
|
|
9721
9726
|
return import_pgvector.PGVectorStore.initialize(embeddings, {
|
|
@@ -10884,6 +10889,28 @@ var addModelProviderModelKind = {
|
|
|
10884
10889
|
`);
|
|
10885
10890
|
}
|
|
10886
10891
|
};
|
|
10892
|
+
var addModelProviderKindDefault = {
|
|
10893
|
+
version: 207,
|
|
10894
|
+
name: "add_model_provider_kind_default",
|
|
10895
|
+
up: async (client) => {
|
|
10896
|
+
await client.query(`
|
|
10897
|
+
DROP INDEX IF EXISTS uk_lattice_model_provider_models_tenant_default
|
|
10898
|
+
`);
|
|
10899
|
+
await client.query(`
|
|
10900
|
+
CREATE UNIQUE INDEX IF NOT EXISTS uk_lattice_model_provider_models_tenant_kind_default
|
|
10901
|
+
ON lattice_model_provider_models (tenant_id, kind) WHERE is_default
|
|
10902
|
+
`);
|
|
10903
|
+
},
|
|
10904
|
+
down: async (client) => {
|
|
10905
|
+
await client.query(`
|
|
10906
|
+
DROP INDEX IF EXISTS uk_lattice_model_provider_models_tenant_kind_default
|
|
10907
|
+
`);
|
|
10908
|
+
await client.query(`
|
|
10909
|
+
CREATE UNIQUE INDEX IF NOT EXISTS uk_lattice_model_provider_models_tenant_default
|
|
10910
|
+
ON lattice_model_provider_models (tenant_id) WHERE is_default
|
|
10911
|
+
`);
|
|
10912
|
+
}
|
|
10913
|
+
};
|
|
10887
10914
|
|
|
10888
10915
|
// src/stores/PostgreSQLCapabilityBundleStore.ts
|
|
10889
10916
|
var import_crypto4 = require("crypto");
|
|
@@ -11878,6 +11905,7 @@ var PostgreSQLModelProviderStore = class {
|
|
|
11878
11905
|
this.migrationManager.register(addModelProviderModelExtra);
|
|
11879
11906
|
this.migrationManager.register(addModelProviderModelDefault);
|
|
11880
11907
|
this.migrationManager.register(addModelProviderModelKind);
|
|
11908
|
+
this.migrationManager.register(addModelProviderKindDefault);
|
|
11881
11909
|
if (options.autoMigrate !== false) {
|
|
11882
11910
|
this.initialize().catch((error) => {
|
|
11883
11911
|
console.error("Failed to initialize PostgreSQLModelProviderStore:", error);
|
|
@@ -12216,15 +12244,22 @@ var PostgreSQLModelProviderStore = class {
|
|
|
12216
12244
|
const effectiveKind = rows.map(
|
|
12217
12245
|
(model) => model.kind ?? currentKind.get(model.id) ?? "chat"
|
|
12218
12246
|
);
|
|
12219
|
-
const
|
|
12220
|
-
|
|
12247
|
+
const namedDefaultKinds = /* @__PURE__ */ new Set();
|
|
12248
|
+
rows.forEach((model, index) => {
|
|
12249
|
+
if (model.isDefault === true) {
|
|
12250
|
+
namedDefaultKinds.add(effectiveKind[index]);
|
|
12251
|
+
}
|
|
12252
|
+
});
|
|
12253
|
+
for (const kind of namedDefaultKinds) {
|
|
12221
12254
|
await client.query(
|
|
12222
|
-
`UPDATE lattice_model_provider_models
|
|
12223
|
-
|
|
12255
|
+
`UPDATE lattice_model_provider_models
|
|
12256
|
+
SET is_default = FALSE
|
|
12257
|
+
WHERE tenant_id = $1 AND kind = $2 AND is_default`,
|
|
12258
|
+
[tenantId, kind]
|
|
12224
12259
|
);
|
|
12225
12260
|
}
|
|
12226
12261
|
const effectiveIsDefault = rows.map(
|
|
12227
|
-
(model) => model.isDefault ?? (
|
|
12262
|
+
(model, index) => model.isDefault ?? (namedDefaultKinds.has(effectiveKind[index]) ? false : currentIsDefault.get(model.id)) ?? false
|
|
12228
12263
|
);
|
|
12229
12264
|
await client.query(
|
|
12230
12265
|
`
|
|
@@ -13697,7 +13732,7 @@ function isActiveRunViolation(error) {
|
|
|
13697
13732
|
|
|
13698
13733
|
// src/stores/PostgreSQLChannelReplyJobStore.ts
|
|
13699
13734
|
var import_pg31 = require("pg");
|
|
13700
|
-
var
|
|
13735
|
+
var import_protocols7 = require("@axiom-lattice/protocols");
|
|
13701
13736
|
var DB_CLOCK_MS2 = "FLOOR(EXTRACT(EPOCH FROM clock_timestamp()) * 1000)::bigint";
|
|
13702
13737
|
var COLUMNS = `run_id, tenant_id, assistant_id, thread_id, adapter_channel,
|
|
13703
13738
|
channel_installation_id, reply_target, input_message_id, stream_cursor, status,
|
|
@@ -13788,7 +13823,7 @@ var PostgreSQLChannelReplyJobStore = class {
|
|
|
13788
13823
|
}
|
|
13789
13824
|
/** Creates a pending job with database-clock created/updated timestamps. */
|
|
13790
13825
|
async create(input) {
|
|
13791
|
-
(0,
|
|
13826
|
+
(0, import_protocols7.assertValidCreateChannelReplyJobInput)(input);
|
|
13792
13827
|
const result = await this.pool.query(
|
|
13793
13828
|
`WITH clock AS (SELECT ${DB_CLOCK_MS2} AS now_ms)
|
|
13794
13829
|
INSERT INTO lattice_channel_reply_jobs (
|
|
@@ -13839,7 +13874,7 @@ var PostgreSQLChannelReplyJobStore = class {
|
|
|
13839
13874
|
AND (lease_owner IS NULL OR lease_expires_at IS NULL OR lease_expires_at <= $1)
|
|
13840
13875
|
ORDER BY available_at ASC, created_at ASC, run_id ASC
|
|
13841
13876
|
LIMIT $2`,
|
|
13842
|
-
[now, (0,
|
|
13877
|
+
[now, (0, import_protocols7.normalizeChannelReplyJobListLimit)(limit)]
|
|
13843
13878
|
);
|
|
13844
13879
|
return result.rows.map(mapRow9);
|
|
13845
13880
|
}
|
|
@@ -13965,7 +14000,7 @@ var PostgreSQLChannelReplyJobStore = class {
|
|
|
13965
14000
|
ORDER BY updated_at ASC, run_id ASC
|
|
13966
14001
|
LIMIT $2
|
|
13967
14002
|
)`,
|
|
13968
|
-
[before, (0,
|
|
14003
|
+
[before, (0, import_protocols7.normalizeChannelReplyJobListLimit)(limit)]
|
|
13969
14004
|
);
|
|
13970
14005
|
return result.rowCount ?? 0;
|
|
13971
14006
|
}
|
|
@@ -14419,7 +14454,7 @@ var PostgreSQLCheckpointStorage = class {
|
|
|
14419
14454
|
};
|
|
14420
14455
|
|
|
14421
14456
|
// src/stores/PostgreSQLStore.ts
|
|
14422
|
-
var
|
|
14457
|
+
var import_protocols8 = require("@axiom-lattice/protocols");
|
|
14423
14458
|
function mapRow10(row) {
|
|
14424
14459
|
return {
|
|
14425
14460
|
namespace: row.namespace,
|
|
@@ -14438,9 +14473,9 @@ var PostgreSQLStore = class {
|
|
|
14438
14473
|
this.pool = pool;
|
|
14439
14474
|
}
|
|
14440
14475
|
async put(tenantId, input) {
|
|
14441
|
-
(0,
|
|
14476
|
+
(0, import_protocols8.assertStoreIdentity)(input.namespace, input.key);
|
|
14442
14477
|
const now = /* @__PURE__ */ new Date();
|
|
14443
|
-
const expiresAt = (0,
|
|
14478
|
+
const expiresAt = (0, import_protocols8.storeExpiresAt)(input.ttlMinutes, now) ?? null;
|
|
14444
14479
|
const result = await this.pool.query(
|
|
14445
14480
|
`INSERT INTO lattice_store_items
|
|
14446
14481
|
(tenant_id, namespace, key, value, created_at, updated_at, expires_at)
|
|
@@ -14455,7 +14490,7 @@ var PostgreSQLStore = class {
|
|
|
14455
14490
|
return mapRow10(result.rows[0]);
|
|
14456
14491
|
}
|
|
14457
14492
|
async get(tenantId, namespace, key) {
|
|
14458
|
-
(0,
|
|
14493
|
+
(0, import_protocols8.assertStoreIdentity)(namespace, key);
|
|
14459
14494
|
const result = await this.pool.query(
|
|
14460
14495
|
`SELECT tenant_id, namespace, key, value, created_at, updated_at, expires_at
|
|
14461
14496
|
FROM lattice_store_items
|
|
@@ -14466,7 +14501,7 @@ var PostgreSQLStore = class {
|
|
|
14466
14501
|
return result.rows[0] ? mapRow10(result.rows[0]) : null;
|
|
14467
14502
|
}
|
|
14468
14503
|
async delete(tenantId, namespace, key) {
|
|
14469
|
-
(0,
|
|
14504
|
+
(0, import_protocols8.assertStoreIdentity)(namespace, key);
|
|
14470
14505
|
const result = await this.pool.query(
|
|
14471
14506
|
`DELETE FROM lattice_store_items
|
|
14472
14507
|
WHERE tenant_id = $1 AND namespace = $2 AND key = $3`,
|
|
@@ -14481,7 +14516,7 @@ var PostgreSQLStore = class {
|
|
|
14481
14516
|
];
|
|
14482
14517
|
const params = [tenantId, /* @__PURE__ */ new Date()];
|
|
14483
14518
|
if (input.namespacePrefix) {
|
|
14484
|
-
(0,
|
|
14519
|
+
(0, import_protocols8.assertStoreNamespacePrefix)(input.namespacePrefix);
|
|
14485
14520
|
}
|
|
14486
14521
|
if (input.namespacePrefix && input.namespacePrefix.length > 0) {
|
|
14487
14522
|
params.push(input.namespacePrefix);
|
|
@@ -14495,9 +14530,9 @@ var PostgreSQLStore = class {
|
|
|
14495
14530
|
params.push(input.query.replace(/[\\%_]/g, "\\$&"));
|
|
14496
14531
|
conditions.push(`value::text ILIKE '%' || $${params.length} || '%' ESCAPE '\\'`);
|
|
14497
14532
|
}
|
|
14498
|
-
params.push((0,
|
|
14533
|
+
params.push((0, import_protocols8.storePaginationValue)(input.limit, 10));
|
|
14499
14534
|
const limitParam = params.length;
|
|
14500
|
-
params.push((0,
|
|
14535
|
+
params.push((0, import_protocols8.storePaginationValue)(input.offset, 0));
|
|
14501
14536
|
const offsetParam = params.length;
|
|
14502
14537
|
const result = await this.pool.query(
|
|
14503
14538
|
`SELECT tenant_id, namespace, key, value, created_at, updated_at, expires_at
|
|
@@ -14510,7 +14545,7 @@ var PostgreSQLStore = class {
|
|
|
14510
14545
|
return result.rows.map(mapRow10);
|
|
14511
14546
|
}
|
|
14512
14547
|
async listNamespaces(tenantId, prefix = [], limit = 100) {
|
|
14513
|
-
(0,
|
|
14548
|
+
(0, import_protocols8.assertStoreNamespacePrefix)(prefix);
|
|
14514
14549
|
const conditions = [
|
|
14515
14550
|
"tenant_id = $1",
|
|
14516
14551
|
"(expires_at IS NULL OR expires_at > $2)"
|
|
@@ -14520,7 +14555,7 @@ var PostgreSQLStore = class {
|
|
|
14520
14555
|
params.push(prefix);
|
|
14521
14556
|
conditions.push(`namespace[1:array_length($${params.length}::text[], 1)] = $${params.length}`);
|
|
14522
14557
|
}
|
|
14523
|
-
params.push((0,
|
|
14558
|
+
params.push((0, import_protocols8.storePaginationValue)(limit, 100));
|
|
14524
14559
|
const result = await this.pool.query(
|
|
14525
14560
|
`SELECT DISTINCT namespace
|
|
14526
14561
|
FROM lattice_store_items
|
|
@@ -14532,7 +14567,7 @@ var PostgreSQLStore = class {
|
|
|
14532
14567
|
return result.rows.map((row) => row.namespace);
|
|
14533
14568
|
}
|
|
14534
14569
|
async deleteExpired(now, limit) {
|
|
14535
|
-
const bounded = (0,
|
|
14570
|
+
const bounded = (0, import_protocols8.storePaginationValue)(limit, 0);
|
|
14536
14571
|
const result = await this.pool.query(
|
|
14537
14572
|
`WITH expired AS (
|
|
14538
14573
|
SELECT ctid FROM lattice_store_items
|
|
@@ -14676,6 +14711,7 @@ async function createPgStoreConfig(connectionString) {
|
|
|
14676
14711
|
mm.register(createAgentRunRetentionMigration);
|
|
14677
14712
|
mm.register(createAgentRunProjectTaskMigration);
|
|
14678
14713
|
mm.register(agentRunProjectTaskRunningIndexMigration);
|
|
14714
|
+
mm.register(addModelProviderKindDefault);
|
|
14679
14715
|
await mm.migrate();
|
|
14680
14716
|
const checkpoint = import_langgraph_checkpoint_postgres.PostgresSaver.fromConnString(connectionString);
|
|
14681
14717
|
checkpoint.setup().catch((err) => {
|