@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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @axiom-lattice/pg-stores@4.0.0 build /home/runner/work/agentic/agentic/packages/pg-stores
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
  CLI Building entry: src/index.ts
@@ -8,13 +8,13 @@
8
8
  CLI Target: es2020
9
9
  CJS Build start
10
10
  ESM Build start
11
- CJS dist/index.js 528.09 KB
12
- CJS dist/index.js.map 960.67 KB
13
- CJS ⚡️ Build success in 969ms
14
- ESM dist/index.mjs 518.65 KB
15
- ESM dist/index.mjs.map 960.39 KB
16
- ESM ⚡️ Build success in 1032ms
11
+ CJS dist/index.js 529.56 KB
12
+ CJS dist/index.js.map 963.70 KB
13
+ CJS ⚡️ Build success in 847ms
14
+ ESM dist/index.mjs 520.06 KB
15
+ ESM dist/index.mjs.map 963.41 KB
16
+ ESM ⚡️ Build success in 848ms
17
17
  DTS Build start
18
- DTS ⚡️ Build success in 11614ms
18
+ DTS ⚡️ Build success in 10223ms
19
19
  DTS dist/index.d.ts 110.68 KB
20
20
  DTS dist/index.d.mts 110.68 KB
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
- embeddingKey
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 provider panel.`
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 namesDefault = rows.some((model) => model.isDefault === true);
12220
- if (namesDefault) {
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 SET is_default = FALSE WHERE tenant_id = $1`,
12223
- [tenantId]
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 ?? (namesDefault ? false : currentIsDefault.get(model.id)) ?? false
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 import_protocols6 = require("@axiom-lattice/protocols");
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, import_protocols6.assertValidCreateChannelReplyJobInput)(input);
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, import_protocols6.normalizeChannelReplyJobListLimit)(limit)]
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, import_protocols6.normalizeChannelReplyJobListLimit)(limit)]
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 import_protocols7 = require("@axiom-lattice/protocols");
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, import_protocols7.assertStoreIdentity)(input.namespace, input.key);
14476
+ (0, import_protocols8.assertStoreIdentity)(input.namespace, input.key);
14442
14477
  const now = /* @__PURE__ */ new Date();
14443
- const expiresAt = (0, import_protocols7.storeExpiresAt)(input.ttlMinutes, now) ?? null;
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, import_protocols7.assertStoreIdentity)(namespace, key);
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, import_protocols7.assertStoreIdentity)(namespace, key);
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, import_protocols7.assertStoreNamespacePrefix)(input.namespacePrefix);
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, import_protocols7.storePaginationValue)(input.limit, 10));
14533
+ params.push((0, import_protocols8.storePaginationValue)(input.limit, 10));
14499
14534
  const limitParam = params.length;
14500
- params.push((0, import_protocols7.storePaginationValue)(input.offset, 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, import_protocols7.assertStoreNamespacePrefix)(prefix);
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, import_protocols7.storePaginationValue)(limit, 100));
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, import_protocols7.storePaginationValue)(limit, 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) => {