@axiom-lattice/local-stores 5.2.4 → 5.4.0

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.js CHANGED
@@ -60,6 +60,7 @@ __export(index_exports, {
60
60
  LocalProjectRoomStore: () => LocalProjectRoomStore,
61
61
  LocalProjectStore: () => LocalProjectStore,
62
62
  LocalScheduleStorage: () => LocalScheduleStorage,
63
+ LocalSessionStore: () => LocalSessionStore,
63
64
  LocalSkillStore: () => LocalSkillStore,
64
65
  LocalStore: () => LocalStore,
65
66
  LocalTaskStore: () => LocalTaskStore,
@@ -359,6 +360,7 @@ var MigrationManager = class {
359
360
  var import_langgraph_checkpoint_sqlite = require("@langchain/langgraph-checkpoint-sqlite");
360
361
 
361
362
  // src/stores/LocalThreadStore.ts
363
+ var import_protocols = require("@axiom-lattice/protocols");
362
364
  var STORE_NAME = "lt_threads";
363
365
  var DDL = `
364
366
  CREATE TABLE IF NOT EXISTS lt_threads (
@@ -408,6 +410,30 @@ var LocalThreadStore = class {
408
410
  }
409
411
  return threads;
410
412
  }
413
+ async listThreadsByTenant(tenantId, query = {}) {
414
+ const limit = Math.min(200, Math.max(1, Math.floor(query.limit ?? 50)));
415
+ const offset = Math.max(0, Math.floor(query.offset ?? 0));
416
+ const createdAfter = query.createdAfter ? Date.parse(query.createdAfter) : void 0;
417
+ const rows2 = this.db.prepare(
418
+ `SELECT * FROM lt_threads WHERE tenant_id = ? ORDER BY created_at DESC, id DESC`
419
+ ).all(tenantId);
420
+ const filtered = rows2.map(mapRowToThread).filter((thread) => {
421
+ if (query.assistantId && thread.assistantId !== query.assistantId) {
422
+ return false;
423
+ }
424
+ if (createdAfter !== void 0 && Number.isFinite(createdAfter) && thread.createdAt.getTime() < createdAfter) {
425
+ return false;
426
+ }
427
+ if (query.kind && (0, import_protocols.classifyThreadMetadata)(thread.metadata) !== query.kind) {
428
+ return false;
429
+ }
430
+ return true;
431
+ });
432
+ return {
433
+ records: filtered.slice(offset, offset + limit).map(import_protocols.toThreadMonitorRecord),
434
+ total: filtered.length
435
+ };
436
+ }
411
437
  async getThreadById(tenantId, threadId) {
412
438
  const row = this.db.prepare(
413
439
  `SELECT * FROM lt_threads WHERE tenant_id = ? AND id = ?`
@@ -490,9 +516,9 @@ function mapRowToThread(row) {
490
516
  }
491
517
 
492
518
  // src/stores/LocalStore.ts
493
- var import_protocols = require("@axiom-lattice/protocols");
519
+ var import_protocols2 = require("@axiom-lattice/protocols");
494
520
  var STORE_NAME2 = "lt_store_items";
495
- var NAMESPACE_SEPARATOR = import_protocols.STORE_IDENTITY_SEPARATOR;
521
+ var NAMESPACE_SEPARATOR = import_protocols2.STORE_IDENTITY_SEPARATOR;
496
522
  var DDL2 = `
497
523
  CREATE TABLE IF NOT EXISTS lt_store_items (
498
524
  tenant_id TEXT NOT NULL,
@@ -555,13 +581,13 @@ var LocalStore = class {
555
581
  mm.migrate();
556
582
  }
557
583
  async put(tenantId, input) {
558
- (0, import_protocols.assertStoreIdentity)(input.namespace, input.key);
584
+ (0, import_protocols2.assertStoreIdentity)(input.namespace, input.key);
559
585
  const now = nowISO();
560
586
  const path2 = namespacePath(input.namespace);
561
587
  const existing = this.db.prepare(
562
588
  `SELECT created_at FROM lt_store_items WHERE tenant_id = ? AND namespace_path = ? AND key = ?`
563
589
  ).get(tenantId, path2, input.key);
564
- const expiresAt = (0, import_protocols.storeExpiresAt)(input.ttlMinutes)?.toISOString() ?? null;
590
+ const expiresAt = (0, import_protocols2.storeExpiresAt)(input.ttlMinutes)?.toISOString() ?? null;
565
591
  this.db.prepare(
566
592
  `INSERT INTO lt_store_items
567
593
  (tenant_id, namespace_path, key, value, created_at, updated_at, expires_at)
@@ -589,7 +615,7 @@ var LocalStore = class {
589
615
  };
590
616
  }
591
617
  async get(tenantId, namespace, key) {
592
- (0, import_protocols.assertStoreIdentity)(namespace, key);
618
+ (0, import_protocols2.assertStoreIdentity)(namespace, key);
593
619
  const now = nowISO();
594
620
  const row = this.db.prepare(
595
621
  `SELECT * FROM lt_store_items
@@ -599,7 +625,7 @@ var LocalStore = class {
599
625
  return row ? mapRow(row) : null;
600
626
  }
601
627
  async delete(tenantId, namespace, key) {
602
- (0, import_protocols.assertStoreIdentity)(namespace, key);
628
+ (0, import_protocols2.assertStoreIdentity)(namespace, key);
603
629
  const result = this.db.prepare(
604
630
  `DELETE FROM lt_store_items WHERE tenant_id = ? AND namespace_path = ? AND key = ?`
605
631
  ).run(tenantId, namespacePath(namespace), key);
@@ -608,10 +634,10 @@ var LocalStore = class {
608
634
  async search(tenantId, input) {
609
635
  const now = nowISO();
610
636
  const prefix = input.namespacePrefix ?? [];
611
- (0, import_protocols.assertStoreNamespacePrefix)(prefix);
637
+ (0, import_protocols2.assertStoreNamespacePrefix)(prefix);
612
638
  const query = input.query?.toLowerCase();
613
- const limit = (0, import_protocols.storePaginationValue)(input.limit, 10);
614
- const offset = (0, import_protocols.storePaginationValue)(input.offset, 0);
639
+ const limit = (0, import_protocols2.storePaginationValue)(input.limit, 10);
640
+ const offset = (0, import_protocols2.storePaginationValue)(input.offset, 0);
615
641
  const rows2 = this.db.prepare(
616
642
  `SELECT * FROM lt_store_items
617
643
  WHERE tenant_id = ? AND (expires_at IS NULL OR expires_at > ?)`
@@ -619,7 +645,7 @@ var LocalStore = class {
619
645
  return rows2.map(mapRow).filter((item) => hasPrefix(item.namespace, prefix)).filter((item) => input.filter === void 0 || matchesFilter(item.value, input.filter)).filter((item) => query === void 0 || JSON.stringify(item.value).toLowerCase().includes(query)).sort((left, right) => right.updatedAt.getTime() - left.updatedAt.getTime() || namespacePath(left.namespace).localeCompare(namespacePath(right.namespace)) || left.key.localeCompare(right.key)).slice(offset, offset + limit);
620
646
  }
621
647
  async listNamespaces(tenantId, prefix = [], limit = 100) {
622
- (0, import_protocols.assertStoreNamespacePrefix)(prefix);
648
+ (0, import_protocols2.assertStoreNamespacePrefix)(prefix);
623
649
  const rows2 = this.db.prepare(
624
650
  `SELECT DISTINCT namespace_path FROM lt_store_items
625
651
  WHERE tenant_id = ? AND (expires_at IS NULL OR expires_at > ?)`
@@ -629,14 +655,14 @@ var LocalStore = class {
629
655
  const namespace = row.namespace_path.split(NAMESPACE_SEPARATOR);
630
656
  if (hasPrefix(namespace, prefix)) namespaces.set(row.namespace_path, namespace);
631
657
  }
632
- return Array.from(namespaces.entries()).sort(([left], [right]) => left.localeCompare(right)).slice(0, (0, import_protocols.storePaginationValue)(limit, 100)).map(([, namespace]) => namespace);
658
+ return Array.from(namespaces.entries()).sort(([left], [right]) => left.localeCompare(right)).slice(0, (0, import_protocols2.storePaginationValue)(limit, 100)).map(([, namespace]) => namespace);
633
659
  }
634
660
  async deleteExpired(now, limit) {
635
661
  const rows2 = this.db.prepare(
636
662
  `SELECT tenant_id, namespace_path, key FROM lt_store_items
637
663
  WHERE expires_at IS NOT NULL AND expires_at <= ?
638
664
  LIMIT ?`
639
- ).all(now.toISOString(), (0, import_protocols.storePaginationValue)(limit, 0));
665
+ ).all(now.toISOString(), (0, import_protocols2.storePaginationValue)(limit, 0));
640
666
  const statement = this.db.prepare(
641
667
  `DELETE FROM lt_store_items WHERE tenant_id = ? AND namespace_path = ? AND key = ?`
642
668
  );
@@ -747,7 +773,7 @@ var LocalAssistantStore = class {
747
773
  }
748
774
  async getByOwner(tenantId, userId) {
749
775
  const row = this.db.prepare(
750
- `SELECT * FROM lt_assistants WHERE tenant_id = ? AND owner_user_id = ? LIMIT 1`
776
+ `SELECT * FROM lt_assistants WHERE tenant_id = ? AND owner_user_id = ? ORDER BY created_at ASC LIMIT 1`
751
777
  ).get(tenantId, userId);
752
778
  return row ? mapRowToAssistant(row) : null;
753
779
  }
@@ -863,7 +889,7 @@ function mapRowToWorkspace(row) {
863
889
  }
864
890
 
865
891
  // src/stores/LocalProjectStore.ts
866
- var import_protocols2 = require("@axiom-lattice/protocols");
892
+ var import_protocols3 = require("@axiom-lattice/protocols");
867
893
  var DDL5 = `
868
894
  CREATE TABLE IF NOT EXISTS lt_projects (
869
895
  id TEXT NOT NULL,
@@ -904,7 +930,7 @@ var LocalProjectStore = class {
904
930
  return row ? mapRowToProject(row) : null;
905
931
  }
906
932
  async createProject(tenantId, workspaceId, id, data) {
907
- (0, import_protocols2.assertGenericProjectConfig)(data.config);
933
+ (0, import_protocols3.assertGenericProjectConfig)(data.config);
908
934
  const now = nowISO();
909
935
  const kind = data.kind || "business";
910
936
  this.db.prepare(
@@ -925,7 +951,7 @@ var LocalProjectStore = class {
925
951
  return await this.getProjectById(tenantId, id);
926
952
  }
927
953
  async updateProject(tenantId, id, updates) {
928
- (0, import_protocols2.assertGenericProjectConfig)(updates.config);
954
+ (0, import_protocols3.assertGenericProjectConfig)(updates.config);
929
955
  const existing = await this.getProjectById(tenantId, id);
930
956
  if (!existing) return null;
931
957
  const setClauses = [];
@@ -1824,6 +1850,7 @@ CREATE TABLE IF NOT EXISTS lt_users (
1824
1850
  email TEXT NOT NULL,
1825
1851
  name TEXT NOT NULL,
1826
1852
  status TEXT NOT NULL DEFAULT 'pending',
1853
+ auth_epoch TEXT,
1827
1854
  metadata TEXT DEFAULT '{}',
1828
1855
  created_at TEXT NOT NULL,
1829
1856
  updated_at TEXT NOT NULL
@@ -1835,6 +1862,10 @@ var LocalUserStore = class {
1835
1862
  constructor(db) {
1836
1863
  this.db = db;
1837
1864
  ensureTable(db, DDL6);
1865
+ const columns6 = db.prepare(`PRAGMA table_info(lt_users)`).all();
1866
+ if (!columns6.some((column) => column.name === "auth_epoch")) {
1867
+ db.exec(`ALTER TABLE lt_users ADD COLUMN auth_epoch TEXT`);
1868
+ }
1838
1869
  }
1839
1870
  async getAllUsers() {
1840
1871
  const rows2 = this.db.prepare(
@@ -1895,6 +1926,10 @@ var LocalUserStore = class {
1895
1926
  setClauses.push("status = ?");
1896
1927
  values.push(updates.status);
1897
1928
  }
1929
+ if (updates.authEpoch !== void 0) {
1930
+ setClauses.push("auth_epoch = ?");
1931
+ values.push(updates.authEpoch);
1932
+ }
1898
1933
  if (updates.metadata !== void 0) {
1899
1934
  setClauses.push("metadata = ?");
1900
1935
  values.push(JSON.stringify(updates.metadata));
@@ -1920,6 +1955,7 @@ function mapRowToUser(row) {
1920
1955
  email: row.email,
1921
1956
  name: row.name,
1922
1957
  status: row.status,
1958
+ ...row.auth_epoch ? { authEpoch: row.auth_epoch } : {},
1923
1959
  metadata: JSON.parse(row.metadata || "{}"),
1924
1960
  createdAt: parseISO(row.created_at),
1925
1961
  updatedAt: parseISO(row.updated_at)
@@ -2028,7 +2064,7 @@ function mapRowToTenant(row) {
2028
2064
  }
2029
2065
 
2030
2066
  // src/stores/LocalUserTenantLinkStore.ts
2031
- var import_protocols3 = require("@axiom-lattice/protocols");
2067
+ var import_protocols4 = require("@axiom-lattice/protocols");
2032
2068
  var DDL8 = `
2033
2069
  CREATE TABLE IF NOT EXISTS lt_user_tenant_links (
2034
2070
  user_id TEXT NOT NULL,
@@ -2065,7 +2101,7 @@ var LocalUserTenantLinkStore = class {
2065
2101
  return row ? mapRowToLink(row) : null;
2066
2102
  }
2067
2103
  async createLink(data) {
2068
- (0, import_protocols3.assertNotPlatformTenant)(data.tenantId);
2104
+ (0, import_protocols4.assertNotPlatformTenant)(data.tenantId);
2069
2105
  const now = nowISO();
2070
2106
  const role2 = data.role || "member";
2071
2107
  const metadata = JSON.stringify(data.metadata || {});
@@ -2128,7 +2164,7 @@ function mapRowToLink(row) {
2128
2164
  }
2129
2165
 
2130
2166
  // src/stores/LocalUserExternalIdentityStore.ts
2131
- var import_protocols4 = require("@axiom-lattice/protocols");
2167
+ var import_protocols5 = require("@axiom-lattice/protocols");
2132
2168
  var DDL9 = `
2133
2169
  CREATE TABLE IF NOT EXISTS lt_user_identities (
2134
2170
  user_id TEXT NOT NULL,
@@ -2187,14 +2223,14 @@ var LocalUserExternalIdentityStore = class {
2187
2223
  identity.subject
2188
2224
  );
2189
2225
  if (!existing) {
2190
- throw new import_protocols4.ExternalIdentityPersistError(
2226
+ throw new import_protocols5.ExternalIdentityPersistError(
2191
2227
  identity.providerId,
2192
2228
  identity.issuer,
2193
2229
  identity.subject
2194
2230
  );
2195
2231
  }
2196
2232
  if (existing.userId !== identity.userId) {
2197
- throw new import_protocols4.ExternalIdentityConflictError(
2233
+ throw new import_protocols5.ExternalIdentityConflictError(
2198
2234
  identity.providerId,
2199
2235
  identity.issuer,
2200
2236
  identity.subject
@@ -2217,7 +2253,7 @@ var LocalUserExternalIdentityStore = class {
2217
2253
 
2218
2254
  // src/stores/LocalOidcProviderConfigStore.ts
2219
2255
  var import_core = require("@axiom-lattice/core");
2220
- var import_protocols5 = require("@axiom-lattice/protocols");
2256
+ var import_protocols6 = require("@axiom-lattice/protocols");
2221
2257
  var DDL10 = `
2222
2258
  CREATE TABLE IF NOT EXISTS lattice_oidc_provider_configs (
2223
2259
  id TEXT NOT NULL PRIMARY KEY,
@@ -2303,7 +2339,7 @@ var LocalOidcProviderConfigStore = class {
2303
2339
  }
2304
2340
  async create(id, input) {
2305
2341
  if (this.db.prepare(`SELECT 1 FROM lattice_oidc_provider_configs WHERE id = ?`).get(id)) {
2306
- throw new import_protocols5.OidcProviderConfigConflictError(id);
2342
+ throw new import_protocols6.OidcProviderConfigConflictError(id);
2307
2343
  }
2308
2344
  const now = nowISO();
2309
2345
  const tenantId = normalizeTenantId(input.defaultTenantId);
@@ -2331,7 +2367,7 @@ var LocalOidcProviderConfigStore = class {
2331
2367
  );
2332
2368
  } catch (error) {
2333
2369
  if (error instanceof Error && /UNIQUE constraint failed/.test(error.message)) {
2334
- throw new import_protocols5.OidcProviderConfigConflictError(id);
2370
+ throw new import_protocols6.OidcProviderConfigConflictError(id);
2335
2371
  }
2336
2372
  throw error;
2337
2373
  }
@@ -2474,7 +2510,7 @@ var LocalPlatformMemberStore = class {
2474
2510
  };
2475
2511
 
2476
2512
  // src/stores/LocalPlatformInvitationStore.ts
2477
- var import_protocols6 = require("@axiom-lattice/protocols");
2513
+ var import_protocols7 = require("@axiom-lattice/protocols");
2478
2514
  var DDL12 = `
2479
2515
  CREATE TABLE IF NOT EXISTS lattice_platform_invitations (
2480
2516
  email TEXT NOT NULL PRIMARY KEY,
@@ -2507,7 +2543,7 @@ var LocalPlatformInvitationStore = class {
2507
2543
  }
2508
2544
  /** Returns the invitation for an email, or null. */
2509
2545
  async get(email) {
2510
- const row = this.db.prepare(`SELECT * FROM lattice_platform_invitations WHERE email = ?`).get((0, import_protocols6.normalizePlatformInvitationEmail)(email));
2546
+ const row = this.db.prepare(`SELECT * FROM lattice_platform_invitations WHERE email = ?`).get((0, import_protocols7.normalizePlatformInvitationEmail)(email));
2511
2547
  return row ? mapRow10(row) : null;
2512
2548
  }
2513
2549
  /**
@@ -2517,7 +2553,7 @@ var LocalPlatformInvitationStore = class {
2517
2553
  * including `expiresAt` and `consumedAt`.
2518
2554
  */
2519
2555
  async upsert(invitation) {
2520
- const email = (0, import_protocols6.normalizePlatformInvitationEmail)(invitation.email);
2556
+ const email = (0, import_protocols7.normalizePlatformInvitationEmail)(invitation.email);
2521
2557
  this.db.prepare(
2522
2558
  `INSERT INTO lattice_platform_invitations
2523
2559
  (email, role, invited_by, created_at, expires_at, consumed_at)
@@ -2544,7 +2580,7 @@ var LocalPlatformInvitationStore = class {
2544
2580
  }
2545
2581
  /** Deletes an invitation. Returns whether a row was removed. */
2546
2582
  async delete(email) {
2547
- const result = this.db.prepare(`DELETE FROM lattice_platform_invitations WHERE email = ?`).run((0, import_protocols6.normalizePlatformInvitationEmail)(email));
2583
+ const result = this.db.prepare(`DELETE FROM lattice_platform_invitations WHERE email = ?`).run((0, import_protocols7.normalizePlatformInvitationEmail)(email));
2548
2584
  return result.changes > 0;
2549
2585
  }
2550
2586
  /**
@@ -2554,7 +2590,7 @@ var LocalPlatformInvitationStore = class {
2554
2590
  * consumed, or expired.
2555
2591
  */
2556
2592
  async consume(email, at) {
2557
- const normalized = (0, import_protocols6.normalizePlatformInvitationEmail)(email);
2593
+ const normalized = (0, import_protocols7.normalizePlatformInvitationEmail)(email);
2558
2594
  const timestamp2 = at.toISOString();
2559
2595
  const result = this.db.prepare(
2560
2596
  `UPDATE lattice_platform_invitations
@@ -2569,7 +2605,7 @@ var LocalPlatformInvitationStore = class {
2569
2605
  };
2570
2606
 
2571
2607
  // src/stores/LocalOidcIdentityClaimStore.ts
2572
- var import_protocols7 = require("@axiom-lattice/protocols");
2608
+ var import_protocols8 = require("@axiom-lattice/protocols");
2573
2609
  var DDL13 = `
2574
2610
  CREATE TABLE IF NOT EXISTS lattice_oidc_identity_claims (
2575
2611
  id TEXT NOT NULL PRIMARY KEY,
@@ -2669,7 +2705,7 @@ var LocalOidcIdentityClaimStore = class {
2669
2705
  ).get(input.providerId, input.issuer, input.subject);
2670
2706
  if (existing) {
2671
2707
  if (parseISO(existing.expires_at).getTime() > now.getTime()) {
2672
- throw new import_protocols7.OidcIdentityClaimConflictError(
2708
+ throw new import_protocols8.OidcIdentityClaimConflictError(
2673
2709
  input.providerId,
2674
2710
  input.issuer,
2675
2711
  input.subject
@@ -2696,7 +2732,7 @@ var LocalOidcIdentityClaimStore = class {
2696
2732
  input.providerId,
2697
2733
  input.issuer,
2698
2734
  input.subject,
2699
- (0, import_protocols7.normalizeOidcIdentityEmail)(input.email),
2735
+ (0, import_protocols8.normalizeOidcIdentityEmail)(input.email),
2700
2736
  input.name ?? null,
2701
2737
  input.picture ?? null,
2702
2738
  timestamp2,
@@ -2712,7 +2748,7 @@ var LocalOidcIdentityClaimStore = class {
2712
2748
  } catch (error) {
2713
2749
  const message = error instanceof Error ? error.message : String(error);
2714
2750
  if (message.toLowerCase().includes("unique")) {
2715
- throw new import_protocols7.OidcIdentityClaimConflictError(
2751
+ throw new import_protocols8.OidcIdentityClaimConflictError(
2716
2752
  input.providerId,
2717
2753
  input.issuer,
2718
2754
  input.subject
@@ -2729,7 +2765,7 @@ var LocalOidcIdentityClaimStore = class {
2729
2765
  const params = [];
2730
2766
  if (updates.email !== void 0) {
2731
2767
  sets.push("email = ?");
2732
- params.push((0, import_protocols7.normalizeOidcIdentityEmail)(updates.email));
2768
+ params.push((0, import_protocols8.normalizeOidcIdentityEmail)(updates.email));
2733
2769
  }
2734
2770
  if (updates.name !== void 0) {
2735
2771
  sets.push("name = ?");
@@ -2779,7 +2815,7 @@ var LocalOidcIdentityClaimStore = class {
2779
2815
 
2780
2816
  // src/stores/LocalInviteLinkStore.ts
2781
2817
  var import_core2 = require("@axiom-lattice/core");
2782
- var import_protocols8 = require("@axiom-lattice/protocols");
2818
+ var import_protocols9 = require("@axiom-lattice/protocols");
2783
2819
  var DDL14 = `
2784
2820
  CREATE TABLE IF NOT EXISTS lattice_invite_links (
2785
2821
  id TEXT NOT NULL PRIMARY KEY,
@@ -2856,7 +2892,7 @@ var LocalInviteLinkStore = class {
2856
2892
  input.scope,
2857
2893
  input.tokenHash,
2858
2894
  (0, import_core2.encrypt)(input.token),
2859
- input.email ? (0, import_protocols8.normalizeInviteLinkEmail)(input.email) : null,
2895
+ input.email ? (0, import_protocols9.normalizeInviteLinkEmail)(input.email) : null,
2860
2896
  input.platformRole ?? null,
2861
2897
  input.tenantId ?? null,
2862
2898
  input.tenantRole ?? null,
@@ -2892,7 +2928,7 @@ var LocalInviteLinkStore = class {
2892
2928
  };
2893
2929
 
2894
2930
  // src/stores/LocalPlatformSettingsStore.ts
2895
- var import_protocols9 = require("@axiom-lattice/protocols");
2931
+ var import_protocols10 = require("@axiom-lattice/protocols");
2896
2932
  var SETTINGS_ID = "default";
2897
2933
  var COLUMNS = "id, document, version, updated_by, updated_at";
2898
2934
  function normalizeUpdatedBy(updatedBy) {
@@ -2956,7 +2992,7 @@ var LocalPlatformSettingsStore = class {
2956
2992
  );
2957
2993
  if (result.changes === 0) {
2958
2994
  const actual = this.db.prepare(`SELECT version FROM lattice_platform_settings WHERE id = ?`).get(SETTINGS_ID);
2959
- throw new import_protocols9.PlatformSettingsVersionConflictError(
2995
+ throw new import_protocols10.PlatformSettingsVersionConflictError(
2960
2996
  expectedVersion,
2961
2997
  actual ? Number(actual.version) : 0
2962
2998
  );
@@ -5319,11 +5355,11 @@ var LocalEvalStore = class {
5319
5355
  };
5320
5356
 
5321
5357
  // src/stores/LocalChannelBindingStore.ts
5322
- var import_protocols11 = require("@axiom-lattice/protocols");
5358
+ var import_protocols12 = require("@axiom-lattice/protocols");
5323
5359
  var import_crypto2 = require("crypto");
5324
5360
 
5325
5361
  // src/stores/room-channel-binding-index.ts
5326
- var import_protocols10 = require("@axiom-lattice/protocols");
5362
+ var import_protocols11 = require("@axiom-lattice/protocols");
5327
5363
  var UNIQUE_INDEX_SQL = `CREATE UNIQUE INDEX IF NOT EXISTS idx_lt_cb_subject_unique
5328
5364
  ON lt_channel_bindings(channel, channel_installation_id, tenant_id, sender_id)`;
5329
5365
  var LOOKUP_INDEX_SQL = `CREATE INDEX IF NOT EXISTS idx_lt_cb_resolve
@@ -5337,7 +5373,7 @@ function ensureChannelBindingSubjectIndex(db) {
5337
5373
  HAVING COUNT(*) > 1
5338
5374
  ORDER BY tenant_id, channel, channel_installation_id, sender_id`).all();
5339
5375
  if (conflicts.length > 0) {
5340
- throw new import_protocols10.ChannelBindingMigrationConflictError(conflicts.map(mapConflict));
5376
+ throw new import_protocols11.ChannelBindingMigrationConflictError(conflicts.map(mapConflict));
5341
5377
  }
5342
5378
  db.exec("DROP INDEX IF EXISTS idx_lt_cb_room_subject");
5343
5379
  db.exec(UNIQUE_INDEX_SQL);
@@ -5435,7 +5471,7 @@ var LocalChannelBindingStore = class {
5435
5471
  );
5436
5472
  } catch (error) {
5437
5473
  if (error instanceof Error && /UNIQUE constraint failed/.test(error.message)) {
5438
- throw new import_protocols11.DuplicateChannelBindingSubjectError();
5474
+ throw new import_protocols12.DuplicateChannelBindingSubjectError();
5439
5475
  }
5440
5476
  throw error;
5441
5477
  }
@@ -5949,6 +5985,24 @@ var LocalOpenAuditStore = class {
5949
5985
  this.db = db;
5950
5986
  ensureTable(db, DDL27);
5951
5987
  }
5988
+ async get(tenantId, id) {
5989
+ const row = this.db.prepare("SELECT * FROM lt_open_audit WHERE tenant_id = ? AND id = ?").get(tenantId, id);
5990
+ if (!row) return null;
5991
+ return {
5992
+ id: row.id,
5993
+ tenantId: row.tenant_id,
5994
+ credentialId: row.credential_id,
5995
+ credentialKind: row.credential_kind,
5996
+ projectId: row.project_id,
5997
+ domain: row.domain,
5998
+ action: row.action,
5999
+ args: row.args ? JSON.parse(row.args) : void 0,
6000
+ status: row.status,
6001
+ errorCode: row.error_code ?? void 0,
6002
+ durationMs: row.duration_ms,
6003
+ createdAt: parseISO(row.created_at)
6004
+ };
6005
+ }
5952
6006
  async query(params) {
5953
6007
  const clauses = ["tenant_id = ?"];
5954
6008
  const values = [params.tenantId];
@@ -5956,10 +6010,18 @@ var LocalOpenAuditStore = class {
5956
6010
  clauses.push("credential_id = ?");
5957
6011
  values.push(params.credentialId);
5958
6012
  }
6013
+ if (params.projectId) {
6014
+ clauses.push("project_id = ?");
6015
+ values.push(params.projectId);
6016
+ }
5959
6017
  if (params.domain) {
5960
6018
  clauses.push("domain = ?");
5961
6019
  values.push(params.domain);
5962
6020
  }
6021
+ if (params.action) {
6022
+ clauses.push("action = ?");
6023
+ values.push(params.action);
6024
+ }
5963
6025
  if (params.status) {
5964
6026
  clauses.push("status = ?");
5965
6027
  values.push(params.status);
@@ -6017,7 +6079,7 @@ var LocalOpenAuditStore = class {
6017
6079
  };
6018
6080
 
6019
6081
  // src/stores/LocalThreadMessageQueueStore.ts
6020
- var import_protocols12 = require("@axiom-lattice/protocols");
6082
+ var import_protocols13 = require("@axiom-lattice/protocols");
6021
6083
  var import_crypto5 = require("crypto");
6022
6084
  var DDL28 = `
6023
6085
  CREATE TABLE IF NOT EXISTS lt_thread_message_queue (
@@ -6229,15 +6291,16 @@ var LocalThreadMessageQueueStore = class {
6229
6291
  ).get(threadId, ...filter.params);
6230
6292
  return row.count;
6231
6293
  }
6232
- async getThreadsWithPendingMessages() {
6294
+ async getThreadsWithPendingMessages(tenantId) {
6233
6295
  const rows2 = this.db.prepare(
6234
6296
  `SELECT tenant_id, assistant_id, thread_id, workspace_id, project_id,
6235
6297
  MAX(status = 'pending') AS has_pending
6236
6298
  FROM lt_thread_message_queue
6237
6299
  WHERE status IN ('pending', 'processing')
6300
+ ${tenantId ? "AND tenant_id = ?" : ""}
6238
6301
  GROUP BY tenant_id, assistant_id, thread_id, workspace_id, project_id
6239
6302
  ORDER BY thread_id`
6240
- ).all();
6303
+ ).all(...tenantId ? [tenantId] : []);
6241
6304
  return rows2.map((r) => ({
6242
6305
  tenantId: r.tenant_id,
6243
6306
  assistantId: r.assistant_id,
@@ -6280,8 +6343,8 @@ var LocalThreadMessageQueueStore = class {
6280
6343
  };
6281
6344
  function validateQueueTrust(params) {
6282
6345
  return {
6283
- trustedRunContext: params.trusted_run_context === void 0 ? void 0 : (0, import_protocols12.parseTrustedRunContext)(params.trusted_run_context),
6284
- executionMode: params.execution_mode === void 0 ? void 0 : (0, import_protocols12.parseQueuedExecutionMode)(params.execution_mode)
6346
+ trustedRunContext: params.trusted_run_context === void 0 ? void 0 : (0, import_protocols13.parseTrustedRunContext)(params.trusted_run_context),
6347
+ executionMode: params.execution_mode === void 0 ? void 0 : (0, import_protocols13.parseQueuedExecutionMode)(params.execution_mode)
6285
6348
  };
6286
6349
  }
6287
6350
  function scopeClause(scope) {
@@ -6302,8 +6365,8 @@ function rowToMessage(row) {
6302
6365
  priority: row.priority || 0,
6303
6366
  command: row.command ? JSON.parse(row.command) : void 0,
6304
6367
  custom_run_config: row.custom_run_config ? JSON.parse(row.custom_run_config) : void 0,
6305
- trusted_run_context: row.trusted_run_context ? (0, import_protocols12.parseTrustedRunContext)(JSON.parse(row.trusted_run_context)) : void 0,
6306
- execution_mode: row.execution_mode == null ? void 0 : (0, import_protocols12.parseQueuedExecutionMode)(row.execution_mode)
6368
+ trusted_run_context: row.trusted_run_context ? (0, import_protocols13.parseTrustedRunContext)(JSON.parse(row.trusted_run_context)) : void 0,
6369
+ execution_mode: row.execution_mode == null ? void 0 : (0, import_protocols13.parseQueuedExecutionMode)(row.execution_mode)
6307
6370
  };
6308
6371
  }
6309
6372
 
@@ -6827,7 +6890,7 @@ function mapRowToTask(row) {
6827
6890
  }
6828
6891
 
6829
6892
  // src/stores/LocalTaskStore.ts
6830
- var import_protocols13 = require("@axiom-lattice/protocols");
6893
+ var import_protocols14 = require("@axiom-lattice/protocols");
6831
6894
  var import_crypto6 = require("crypto");
6832
6895
  var MAX_CANONICAL_TASK_TIME = "9999-12-31T23:59:59.999Z";
6833
6896
  var TASK_STATUSES = /* @__PURE__ */ new Set([
@@ -7016,7 +7079,7 @@ var LocalTaskStore = class {
7016
7079
  if (filter.metadata) {
7017
7080
  for (const [key, value] of Object.entries(filter.metadata)) {
7018
7081
  const safeKey = key.replace(/[^a-zA-Z0-9_]/g, "");
7019
- const expected = (0, import_protocols13.normalizeTaskMetadataScalar)(value);
7082
+ const expected = (0, import_protocols14.normalizeTaskMetadataScalar)(value);
7020
7083
  if (!safeKey || expected === void 0) continue;
7021
7084
  if (expected === "true" || expected === "false") {
7022
7085
  conditions.push(
@@ -7591,7 +7654,7 @@ var LocalTaskStore = class {
7591
7654
  };
7592
7655
 
7593
7656
  // src/stores/LocalTaskWorkItemStore.ts
7594
- var import_protocols14 = require("@axiom-lattice/protocols");
7657
+ var import_protocols15 = require("@axiom-lattice/protocols");
7595
7658
  var import_uuid2 = require("uuid");
7596
7659
  var PROJECT_LIFECYCLE_ACTIONS = /* @__PURE__ */ new Set([
7597
7660
  "in_progress",
@@ -7816,8 +7879,8 @@ var LocalTaskWorkItemStore = class {
7816
7879
  }
7817
7880
  /** List pending execution results using one bounded SQLite anti-join query. */
7818
7881
  async listPendingExecutionResults(params) {
7819
- if (!Number.isSafeInteger(params.limit) || params.limit < 0 || params.limit > import_protocols14.MAX_PENDING_EXECUTION_RESULTS_LIMIT) {
7820
- const error = new RangeError(`limit must be a safe integer between 0 and ${import_protocols14.MAX_PENDING_EXECUTION_RESULTS_LIMIT}`);
7882
+ if (!Number.isSafeInteger(params.limit) || params.limit < 0 || params.limit > import_protocols15.MAX_PENDING_EXECUTION_RESULTS_LIMIT) {
7883
+ const error = new RangeError(`limit must be a safe integer between 0 and ${import_protocols15.MAX_PENDING_EXECUTION_RESULTS_LIMIT}`);
7821
7884
  error.code = "INVALID_LIMIT";
7822
7885
  throw error;
7823
7886
  }
@@ -8009,6 +8072,133 @@ async function createLocalStoreConfig(options = {}) {
8009
8072
  };
8010
8073
  }
8011
8074
 
8075
+ // src/stores/LocalSessionStore.ts
8076
+ var DDL34 = `
8077
+ CREATE TABLE IF NOT EXISTS lt_sessions (
8078
+ id TEXT PRIMARY KEY,
8079
+ family_id TEXT NOT NULL,
8080
+ user_id TEXT NOT NULL,
8081
+ tenant_id TEXT,
8082
+ auth_epoch TEXT NOT NULL DEFAULT '',
8083
+ refresh_token_hash TEXT NOT NULL UNIQUE,
8084
+ created_at TEXT NOT NULL,
8085
+ last_used_at TEXT NOT NULL,
8086
+ idle_expires_at TEXT NOT NULL,
8087
+ absolute_expires_at TEXT NOT NULL,
8088
+ revoked_at TEXT,
8089
+ replaced_by TEXT,
8090
+ ip TEXT,
8091
+ user_agent TEXT,
8092
+ provider_id TEXT NOT NULL,
8093
+ idp_refresh_token_enc TEXT,
8094
+ idp_refresh_expires_at TEXT
8095
+ );
8096
+ CREATE INDEX IF NOT EXISTS idx_lt_sessions_family ON lt_sessions(family_id);
8097
+ CREATE INDEX IF NOT EXISTS idx_lt_sessions_user ON lt_sessions(user_id);
8098
+ `;
8099
+ function mapRow16(row) {
8100
+ return {
8101
+ id: row.id,
8102
+ familyId: row.family_id,
8103
+ userId: row.user_id,
8104
+ ...row.tenant_id ? { tenantId: row.tenant_id } : {},
8105
+ authEpoch: row.auth_epoch,
8106
+ refreshTokenHash: row.refresh_token_hash,
8107
+ createdAt: parseISO(row.created_at),
8108
+ lastUsedAt: parseISO(row.last_used_at),
8109
+ idleExpiresAt: parseISO(row.idle_expires_at),
8110
+ absoluteExpiresAt: parseISO(row.absolute_expires_at),
8111
+ ...row.revoked_at ? { revokedAt: parseISO(row.revoked_at) } : {},
8112
+ ...row.replaced_by ? { replacedBy: row.replaced_by } : {},
8113
+ ...row.ip ? { ip: row.ip } : {},
8114
+ ...row.user_agent ? { userAgent: row.user_agent } : {},
8115
+ providerId: row.provider_id,
8116
+ ...row.idp_refresh_token_enc ? { idpRefreshTokenEnc: row.idp_refresh_token_enc } : {},
8117
+ ...row.idp_refresh_expires_at ? { idpRefreshExpiresAt: parseISO(row.idp_refresh_expires_at) } : {}
8118
+ };
8119
+ }
8120
+ var LocalSessionStore = class {
8121
+ constructor(db) {
8122
+ this.db = db;
8123
+ ensureTable(db, DDL34);
8124
+ }
8125
+ async create(record2) {
8126
+ this.db.prepare(
8127
+ `INSERT INTO lt_sessions (
8128
+ id, family_id, user_id, tenant_id, auth_epoch, refresh_token_hash,
8129
+ created_at, last_used_at, idle_expires_at, absolute_expires_at,
8130
+ revoked_at, replaced_by, ip, user_agent, provider_id,
8131
+ idp_refresh_token_enc, idp_refresh_expires_at
8132
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
8133
+ ).run(
8134
+ record2.id,
8135
+ record2.familyId,
8136
+ record2.userId,
8137
+ record2.tenantId ?? null,
8138
+ record2.authEpoch,
8139
+ record2.refreshTokenHash,
8140
+ record2.createdAt.toISOString(),
8141
+ record2.lastUsedAt.toISOString(),
8142
+ record2.idleExpiresAt.toISOString(),
8143
+ record2.absoluteExpiresAt.toISOString(),
8144
+ record2.revokedAt ? record2.revokedAt.toISOString() : null,
8145
+ record2.replacedBy ?? null,
8146
+ record2.ip ?? null,
8147
+ record2.userAgent ?? null,
8148
+ record2.providerId,
8149
+ record2.idpRefreshTokenEnc ?? null,
8150
+ record2.idpRefreshExpiresAt ? record2.idpRefreshExpiresAt.toISOString() : null
8151
+ );
8152
+ }
8153
+ async findByRefreshTokenHash(hash) {
8154
+ const row = this.db.prepare(
8155
+ `SELECT * FROM lt_sessions WHERE refresh_token_hash = ?`
8156
+ ).get(hash);
8157
+ return row ? mapRow16(row) : null;
8158
+ }
8159
+ async findByFamilyId(familyId) {
8160
+ const active = this.db.prepare(
8161
+ `SELECT * FROM lt_sessions
8162
+ WHERE family_id = ? AND replaced_by IS NULL AND revoked_at IS NULL
8163
+ ORDER BY created_at DESC LIMIT 1`
8164
+ ).get(familyId);
8165
+ if (active) return mapRow16(active);
8166
+ const fallback = this.db.prepare(
8167
+ `SELECT * FROM lt_sessions WHERE family_id = ? ORDER BY created_at DESC LIMIT 1`
8168
+ ).get(familyId);
8169
+ return fallback ? mapRow16(fallback) : null;
8170
+ }
8171
+ async rotate(oldId, next) {
8172
+ this.db.prepare(
8173
+ `UPDATE lt_sessions SET replaced_by = ?, last_used_at = ? WHERE id = ?`
8174
+ ).run(next.id, next.createdAt.toISOString(), oldId);
8175
+ await this.create(next);
8176
+ }
8177
+ async revokeFamily(familyId, _reason) {
8178
+ const now = nowISO();
8179
+ this.db.prepare(
8180
+ `UPDATE lt_sessions SET revoked_at = ? WHERE family_id = ? AND revoked_at IS NULL`
8181
+ ).run(now, familyId);
8182
+ }
8183
+ async revokeAllForUser(userId, _reason) {
8184
+ const now = nowISO();
8185
+ this.db.prepare(
8186
+ `UPDATE lt_sessions SET revoked_at = ? WHERE user_id = ? AND revoked_at IS NULL`
8187
+ ).run(now, userId);
8188
+ }
8189
+ async touch(id, lastUsedAt) {
8190
+ this.db.prepare(
8191
+ `UPDATE lt_sessions SET last_used_at = ? WHERE id = ?`
8192
+ ).run(lastUsedAt.toISOString(), id);
8193
+ }
8194
+ async listForUser(userId) {
8195
+ const rows2 = this.db.prepare(
8196
+ `SELECT * FROM lt_sessions WHERE user_id = ? ORDER BY created_at DESC`
8197
+ ).all(userId);
8198
+ return rows2.map(mapRow16);
8199
+ }
8200
+ };
8201
+
8012
8202
  // src/stores/InMemoryConversationStore.ts
8013
8203
  var isoNow = () => (/* @__PURE__ */ new Date()).toISOString();
8014
8204
  var InMemoryConversationStore = class {
@@ -8077,6 +8267,7 @@ var InMemoryConversationStore = class {
8077
8267
  LocalProjectRoomStore,
8078
8268
  LocalProjectStore,
8079
8269
  LocalScheduleStorage,
8270
+ LocalSessionStore,
8080
8271
  LocalSkillStore,
8081
8272
  LocalStore,
8082
8273
  LocalTaskStore,