@axiom-lattice/local-stores 5.1.1 → 5.2.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
@@ -49,6 +49,7 @@ __export(index_exports, {
49
49
  LocalOidcIdentityClaimStore: () => LocalOidcIdentityClaimStore,
50
50
  LocalOidcProviderConfigStore: () => LocalOidcProviderConfigStore,
51
51
  LocalOpenAuditStore: () => LocalOpenAuditStore,
52
+ LocalPlatformAuditStore: () => LocalPlatformAuditStore,
52
53
  LocalPlatformInvitationStore: () => LocalPlatformInvitationStore,
53
54
  LocalPlatformMemberStore: () => LocalPlatformMemberStore,
54
55
  LocalPlatformSettingsStore: () => LocalPlatformSettingsStore,
@@ -2027,6 +2028,7 @@ function mapRowToTenant(row) {
2027
2028
  }
2028
2029
 
2029
2030
  // src/stores/LocalUserTenantLinkStore.ts
2031
+ var import_protocols3 = require("@axiom-lattice/protocols");
2030
2032
  var DDL8 = `
2031
2033
  CREATE TABLE IF NOT EXISTS lt_user_tenant_links (
2032
2034
  user_id TEXT NOT NULL,
@@ -2063,6 +2065,7 @@ var LocalUserTenantLinkStore = class {
2063
2065
  return row ? mapRowToLink(row) : null;
2064
2066
  }
2065
2067
  async createLink(data) {
2068
+ (0, import_protocols3.assertNotPlatformTenant)(data.tenantId);
2066
2069
  const now = nowISO();
2067
2070
  const role2 = data.role || "member";
2068
2071
  const metadata = JSON.stringify(data.metadata || {});
@@ -2125,7 +2128,7 @@ function mapRowToLink(row) {
2125
2128
  }
2126
2129
 
2127
2130
  // src/stores/LocalUserExternalIdentityStore.ts
2128
- var import_protocols3 = require("@axiom-lattice/protocols");
2131
+ var import_protocols4 = require("@axiom-lattice/protocols");
2129
2132
  var DDL9 = `
2130
2133
  CREATE TABLE IF NOT EXISTS lt_user_identities (
2131
2134
  user_id TEXT NOT NULL,
@@ -2184,14 +2187,14 @@ var LocalUserExternalIdentityStore = class {
2184
2187
  identity.subject
2185
2188
  );
2186
2189
  if (!existing) {
2187
- throw new import_protocols3.ExternalIdentityPersistError(
2190
+ throw new import_protocols4.ExternalIdentityPersistError(
2188
2191
  identity.providerId,
2189
2192
  identity.issuer,
2190
2193
  identity.subject
2191
2194
  );
2192
2195
  }
2193
2196
  if (existing.userId !== identity.userId) {
2194
- throw new import_protocols3.ExternalIdentityConflictError(
2197
+ throw new import_protocols4.ExternalIdentityConflictError(
2195
2198
  identity.providerId,
2196
2199
  identity.issuer,
2197
2200
  identity.subject
@@ -2214,7 +2217,7 @@ var LocalUserExternalIdentityStore = class {
2214
2217
 
2215
2218
  // src/stores/LocalOidcProviderConfigStore.ts
2216
2219
  var import_core = require("@axiom-lattice/core");
2217
- var import_protocols4 = require("@axiom-lattice/protocols");
2220
+ var import_protocols5 = require("@axiom-lattice/protocols");
2218
2221
  var DDL10 = `
2219
2222
  CREATE TABLE IF NOT EXISTS lattice_oidc_provider_configs (
2220
2223
  id TEXT NOT NULL PRIMARY KEY,
@@ -2300,7 +2303,7 @@ var LocalOidcProviderConfigStore = class {
2300
2303
  }
2301
2304
  async create(id, input) {
2302
2305
  if (this.db.prepare(`SELECT 1 FROM lattice_oidc_provider_configs WHERE id = ?`).get(id)) {
2303
- throw new import_protocols4.OidcProviderConfigConflictError(id);
2306
+ throw new import_protocols5.OidcProviderConfigConflictError(id);
2304
2307
  }
2305
2308
  const now = nowISO();
2306
2309
  const tenantId = normalizeTenantId(input.defaultTenantId);
@@ -2328,7 +2331,7 @@ var LocalOidcProviderConfigStore = class {
2328
2331
  );
2329
2332
  } catch (error) {
2330
2333
  if (error instanceof Error && /UNIQUE constraint failed/.test(error.message)) {
2331
- throw new import_protocols4.OidcProviderConfigConflictError(id);
2334
+ throw new import_protocols5.OidcProviderConfigConflictError(id);
2332
2335
  }
2333
2336
  throw error;
2334
2337
  }
@@ -2471,7 +2474,7 @@ var LocalPlatformMemberStore = class {
2471
2474
  };
2472
2475
 
2473
2476
  // src/stores/LocalPlatformInvitationStore.ts
2474
- var import_protocols5 = require("@axiom-lattice/protocols");
2477
+ var import_protocols6 = require("@axiom-lattice/protocols");
2475
2478
  var DDL12 = `
2476
2479
  CREATE TABLE IF NOT EXISTS lattice_platform_invitations (
2477
2480
  email TEXT NOT NULL PRIMARY KEY,
@@ -2504,7 +2507,7 @@ var LocalPlatformInvitationStore = class {
2504
2507
  }
2505
2508
  /** Returns the invitation for an email, or null. */
2506
2509
  async get(email) {
2507
- const row = this.db.prepare(`SELECT * FROM lattice_platform_invitations WHERE email = ?`).get((0, import_protocols5.normalizePlatformInvitationEmail)(email));
2510
+ const row = this.db.prepare(`SELECT * FROM lattice_platform_invitations WHERE email = ?`).get((0, import_protocols6.normalizePlatformInvitationEmail)(email));
2508
2511
  return row ? mapRow10(row) : null;
2509
2512
  }
2510
2513
  /**
@@ -2514,7 +2517,7 @@ var LocalPlatformInvitationStore = class {
2514
2517
  * including `expiresAt` and `consumedAt`.
2515
2518
  */
2516
2519
  async upsert(invitation) {
2517
- const email = (0, import_protocols5.normalizePlatformInvitationEmail)(invitation.email);
2520
+ const email = (0, import_protocols6.normalizePlatformInvitationEmail)(invitation.email);
2518
2521
  this.db.prepare(
2519
2522
  `INSERT INTO lattice_platform_invitations
2520
2523
  (email, role, invited_by, created_at, expires_at, consumed_at)
@@ -2541,7 +2544,7 @@ var LocalPlatformInvitationStore = class {
2541
2544
  }
2542
2545
  /** Deletes an invitation. Returns whether a row was removed. */
2543
2546
  async delete(email) {
2544
- const result = this.db.prepare(`DELETE FROM lattice_platform_invitations WHERE email = ?`).run((0, import_protocols5.normalizePlatformInvitationEmail)(email));
2547
+ const result = this.db.prepare(`DELETE FROM lattice_platform_invitations WHERE email = ?`).run((0, import_protocols6.normalizePlatformInvitationEmail)(email));
2545
2548
  return result.changes > 0;
2546
2549
  }
2547
2550
  /**
@@ -2551,7 +2554,7 @@ var LocalPlatformInvitationStore = class {
2551
2554
  * consumed, or expired.
2552
2555
  */
2553
2556
  async consume(email, at) {
2554
- const normalized = (0, import_protocols5.normalizePlatformInvitationEmail)(email);
2557
+ const normalized = (0, import_protocols6.normalizePlatformInvitationEmail)(email);
2555
2558
  const timestamp2 = at.toISOString();
2556
2559
  const result = this.db.prepare(
2557
2560
  `UPDATE lattice_platform_invitations
@@ -2566,7 +2569,7 @@ var LocalPlatformInvitationStore = class {
2566
2569
  };
2567
2570
 
2568
2571
  // src/stores/LocalOidcIdentityClaimStore.ts
2569
- var import_protocols6 = require("@axiom-lattice/protocols");
2572
+ var import_protocols7 = require("@axiom-lattice/protocols");
2570
2573
  var DDL13 = `
2571
2574
  CREATE TABLE IF NOT EXISTS lattice_oidc_identity_claims (
2572
2575
  id TEXT NOT NULL PRIMARY KEY,
@@ -2666,7 +2669,7 @@ var LocalOidcIdentityClaimStore = class {
2666
2669
  ).get(input.providerId, input.issuer, input.subject);
2667
2670
  if (existing) {
2668
2671
  if (parseISO(existing.expires_at).getTime() > now.getTime()) {
2669
- throw new import_protocols6.OidcIdentityClaimConflictError(
2672
+ throw new import_protocols7.OidcIdentityClaimConflictError(
2670
2673
  input.providerId,
2671
2674
  input.issuer,
2672
2675
  input.subject
@@ -2693,7 +2696,7 @@ var LocalOidcIdentityClaimStore = class {
2693
2696
  input.providerId,
2694
2697
  input.issuer,
2695
2698
  input.subject,
2696
- (0, import_protocols6.normalizeOidcIdentityEmail)(input.email),
2699
+ (0, import_protocols7.normalizeOidcIdentityEmail)(input.email),
2697
2700
  input.name ?? null,
2698
2701
  input.picture ?? null,
2699
2702
  timestamp2,
@@ -2709,7 +2712,7 @@ var LocalOidcIdentityClaimStore = class {
2709
2712
  } catch (error) {
2710
2713
  const message = error instanceof Error ? error.message : String(error);
2711
2714
  if (message.toLowerCase().includes("unique")) {
2712
- throw new import_protocols6.OidcIdentityClaimConflictError(
2715
+ throw new import_protocols7.OidcIdentityClaimConflictError(
2713
2716
  input.providerId,
2714
2717
  input.issuer,
2715
2718
  input.subject
@@ -2726,7 +2729,7 @@ var LocalOidcIdentityClaimStore = class {
2726
2729
  const params = [];
2727
2730
  if (updates.email !== void 0) {
2728
2731
  sets.push("email = ?");
2729
- params.push((0, import_protocols6.normalizeOidcIdentityEmail)(updates.email));
2732
+ params.push((0, import_protocols7.normalizeOidcIdentityEmail)(updates.email));
2730
2733
  }
2731
2734
  if (updates.name !== void 0) {
2732
2735
  sets.push("name = ?");
@@ -2776,7 +2779,7 @@ var LocalOidcIdentityClaimStore = class {
2776
2779
 
2777
2780
  // src/stores/LocalInviteLinkStore.ts
2778
2781
  var import_core2 = require("@axiom-lattice/core");
2779
- var import_protocols7 = require("@axiom-lattice/protocols");
2782
+ var import_protocols8 = require("@axiom-lattice/protocols");
2780
2783
  var DDL14 = `
2781
2784
  CREATE TABLE IF NOT EXISTS lattice_invite_links (
2782
2785
  id TEXT NOT NULL PRIMARY KEY,
@@ -2853,7 +2856,7 @@ var LocalInviteLinkStore = class {
2853
2856
  input.scope,
2854
2857
  input.tokenHash,
2855
2858
  (0, import_core2.encrypt)(input.token),
2856
- input.email ? (0, import_protocols7.normalizeInviteLinkEmail)(input.email) : null,
2859
+ input.email ? (0, import_protocols8.normalizeInviteLinkEmail)(input.email) : null,
2857
2860
  input.platformRole ?? null,
2858
2861
  input.tenantId ?? null,
2859
2862
  input.tenantRole ?? null,
@@ -2889,7 +2892,7 @@ var LocalInviteLinkStore = class {
2889
2892
  };
2890
2893
 
2891
2894
  // src/stores/LocalPlatformSettingsStore.ts
2892
- var import_protocols8 = require("@axiom-lattice/protocols");
2895
+ var import_protocols9 = require("@axiom-lattice/protocols");
2893
2896
  var SETTINGS_ID = "default";
2894
2897
  var COLUMNS = "id, document, version, updated_by, updated_at";
2895
2898
  function normalizeUpdatedBy(updatedBy) {
@@ -2953,7 +2956,7 @@ var LocalPlatformSettingsStore = class {
2953
2956
  );
2954
2957
  if (result.changes === 0) {
2955
2958
  const actual = this.db.prepare(`SELECT version FROM lattice_platform_settings WHERE id = ?`).get(SETTINGS_ID);
2956
- throw new import_protocols8.PlatformSettingsVersionConflictError(
2959
+ throw new import_protocols9.PlatformSettingsVersionConflictError(
2957
2960
  expectedVersion,
2958
2961
  actual ? Number(actual.version) : 0
2959
2962
  );
@@ -2964,9 +2967,168 @@ var LocalPlatformSettingsStore = class {
2964
2967
  }
2965
2968
  };
2966
2969
 
2970
+ // src/stores/LocalPlatformAuditStore.ts
2971
+ var import_node_crypto = require("crypto");
2972
+ var DDL16 = `
2973
+ CREATE TABLE IF NOT EXISTS lattice_platform_audit (
2974
+ id TEXT NOT NULL PRIMARY KEY,
2975
+ initiator_user_id TEXT,
2976
+ initiator_role TEXT,
2977
+ initiator_json TEXT NOT NULL,
2978
+ source TEXT NOT NULL,
2979
+ executor_json TEXT NOT NULL,
2980
+ tenant_id TEXT,
2981
+ action TEXT NOT NULL,
2982
+ status TEXT NOT NULL,
2983
+ summary_json TEXT NOT NULL,
2984
+ before_json TEXT,
2985
+ after_json TEXT,
2986
+ error_code TEXT,
2987
+ duration_ms INTEGER NOT NULL,
2988
+ created_at TEXT NOT NULL
2989
+ );
2990
+ CREATE INDEX IF NOT EXISTS idx_lattice_platform_audit_created
2991
+ ON lattice_platform_audit(created_at DESC, id DESC);
2992
+ CREATE INDEX IF NOT EXISTS idx_lattice_platform_audit_initiator
2993
+ ON lattice_platform_audit(initiator_user_id, created_at DESC);
2994
+ CREATE INDEX IF NOT EXISTS idx_lattice_platform_audit_tenant
2995
+ ON lattice_platform_audit(tenant_id, created_at DESC);
2996
+ `;
2997
+ function parseJson2(value) {
2998
+ return JSON.parse(value);
2999
+ }
3000
+ function normalizeBoundary(value) {
3001
+ if (value === void 0) return void 0;
3002
+ const trimmed = value.trim();
3003
+ if (trimmed === "") return void 0;
3004
+ const parsed = new Date(trimmed);
3005
+ if (Number.isNaN(parsed.getTime())) return void 0;
3006
+ return parsed.toISOString();
3007
+ }
3008
+ function normalizePagination(value, fallback) {
3009
+ if (value === void 0 || !Number.isFinite(value)) return fallback;
3010
+ return Math.max(0, Math.trunc(value));
3011
+ }
3012
+ function mapRow14(row) {
3013
+ return {
3014
+ id: row.id,
3015
+ initiator: parseJson2(row.initiator_json),
3016
+ source: row.source,
3017
+ executor: parseJson2(row.executor_json),
3018
+ ...row.tenant_id !== null ? { tenantId: row.tenant_id } : {},
3019
+ action: row.action,
3020
+ status: row.status,
3021
+ summary: parseJson2(row.summary_json),
3022
+ ...row.before_json !== null ? { before: parseJson2(row.before_json) } : {},
3023
+ ...row.after_json !== null ? { after: parseJson2(row.after_json) } : {},
3024
+ ...row.error_code !== null ? { errorCode: row.error_code } : {},
3025
+ durationMs: Number(row.duration_ms),
3026
+ createdAt: parseISO(row.created_at)
3027
+ };
3028
+ }
3029
+ var LocalPlatformAuditStore = class {
3030
+ constructor(db) {
3031
+ this.db = db;
3032
+ ensureTable(db, DDL16);
3033
+ }
3034
+ /** Appends a record, assigning a fresh id and creation timestamp. */
3035
+ async append(record2) {
3036
+ const id = (0, import_node_crypto.randomUUID)();
3037
+ const initiator = record2.initiator;
3038
+ const initiatorUserId = initiator.type === "human" ? initiator.userId : null;
3039
+ const initiatorRole = initiator.type === "human" ? initiator.role : null;
3040
+ const durationMs = Number.isFinite(record2.durationMs) ? Math.max(0, Math.round(record2.durationMs)) : 0;
3041
+ this.db.prepare(
3042
+ `INSERT INTO lattice_platform_audit
3043
+ (id, initiator_user_id, initiator_role, initiator_json, source,
3044
+ executor_json, tenant_id, action, status, summary_json, before_json,
3045
+ after_json, error_code, duration_ms, created_at)
3046
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
3047
+ ).run(
3048
+ id,
3049
+ initiatorUserId,
3050
+ initiatorRole,
3051
+ JSON.stringify(initiator),
3052
+ record2.source,
3053
+ JSON.stringify(record2.executor),
3054
+ record2.tenantId ?? null,
3055
+ record2.action,
3056
+ record2.status,
3057
+ JSON.stringify(record2.summary),
3058
+ record2.before === void 0 ? null : JSON.stringify(record2.before),
3059
+ record2.after === void 0 ? null : JSON.stringify(record2.after),
3060
+ record2.errorCode ?? null,
3061
+ durationMs,
3062
+ nowISO()
3063
+ );
3064
+ const stored = await this.get(id);
3065
+ if (!stored) throw new Error("Platform audit record was not persisted");
3066
+ return stored;
3067
+ }
3068
+ /** Returns a record by id, or null when it does not exist. */
3069
+ async get(id) {
3070
+ const row = this.db.prepare(`SELECT * FROM lattice_platform_audit WHERE id = ?`).get(id);
3071
+ return row ? mapRow14(row) : null;
3072
+ }
3073
+ /**
3074
+ * Returns matching records newest-first.
3075
+ *
3076
+ * `initiatorUserId` only matches human initiators. `from` is inclusive and
3077
+ * `to` is exclusive after both are normalized to instants; invalid or empty
3078
+ * boundaries are ignored. Records are ordered by `createdAt` descending,
3079
+ * then by `id` descending. Results are paginated with a default limit of 100;
3080
+ * non-finite `offset`/`limit` fall back to defaults, finite values are
3081
+ * truncated to integers, and negatives are clamped to 0.
3082
+ */
3083
+ async query(params) {
3084
+ const clauses = [];
3085
+ const values = [];
3086
+ if (params.initiatorUserId !== void 0) {
3087
+ clauses.push("initiator_user_id = ?");
3088
+ values.push(params.initiatorUserId);
3089
+ }
3090
+ if (params.source !== void 0) {
3091
+ clauses.push("source = ?");
3092
+ values.push(params.source);
3093
+ }
3094
+ if (params.tenantId !== void 0) {
3095
+ clauses.push("tenant_id = ?");
3096
+ values.push(params.tenantId);
3097
+ }
3098
+ if (params.action !== void 0) {
3099
+ clauses.push("action = ?");
3100
+ values.push(params.action);
3101
+ }
3102
+ if (params.status !== void 0) {
3103
+ clauses.push("status = ?");
3104
+ values.push(params.status);
3105
+ }
3106
+ const from = normalizeBoundary(params.from);
3107
+ if (from !== void 0) {
3108
+ clauses.push("created_at >= ?");
3109
+ values.push(from);
3110
+ }
3111
+ const to = normalizeBoundary(params.to);
3112
+ if (to !== void 0) {
3113
+ clauses.push("created_at < ?");
3114
+ values.push(to);
3115
+ }
3116
+ const limit = normalizePagination(params.limit, 100);
3117
+ const offset = normalizePagination(params.offset, 0);
3118
+ values.push(limit, offset);
3119
+ const where = clauses.length > 0 ? ` WHERE ${clauses.join(" AND ")}` : "";
3120
+ const rows2 = this.db.prepare(
3121
+ `SELECT * FROM lattice_platform_audit${where}
3122
+ ORDER BY created_at DESC, id DESC
3123
+ LIMIT ? OFFSET ?`
3124
+ ).all(...values);
3125
+ return rows2.map(mapRow14);
3126
+ }
3127
+ };
3128
+
2967
3129
  // src/stores/LocalDatabaseConfigStore.ts
2968
3130
  var import_core3 = require("@axiom-lattice/core");
2969
- var DDL16 = `
3131
+ var DDL17 = `
2970
3132
  CREATE TABLE IF NOT EXISTS lt_database_configs (
2971
3133
  id TEXT NOT NULL,
2972
3134
  tenant_id TEXT NOT NULL,
@@ -2983,7 +3145,7 @@ CREATE UNIQUE INDEX IF NOT EXISTS idx_lt_dbconfig_key ON lt_database_configs(ten
2983
3145
  var LocalDatabaseConfigStore = class {
2984
3146
  constructor(db) {
2985
3147
  this.db = db;
2986
- ensureTable(db, DDL16);
3148
+ ensureTable(db, DDL17);
2987
3149
  }
2988
3150
  async getAllConfigs(tenantId) {
2989
3151
  const rows2 = this.db.prepare(
@@ -3106,7 +3268,7 @@ function encryptPasswordInConfig(config) {
3106
3268
  // src/stores/LocalConnectionStore.ts
3107
3269
  var import_uuid = require("uuid");
3108
3270
  var import_core4 = require("@axiom-lattice/core");
3109
- var DDL17 = `
3271
+ var DDL18 = `
3110
3272
  CREATE TABLE IF NOT EXISTS connection_configs (
3111
3273
  id TEXT NOT NULL,
3112
3274
  tenant_id TEXT NOT NULL,
@@ -3137,7 +3299,7 @@ function parseSecretFields(raw) {
3137
3299
  var LocalConnectionStore = class {
3138
3300
  constructor(db) {
3139
3301
  this.db = db;
3140
- ensureTable(db, DDL17);
3302
+ ensureTable(db, DDL18);
3141
3303
  this.ensureColumn("connection_configs", "secret_fields", "secret_fields TEXT");
3142
3304
  this.reencryptLegacySecrets();
3143
3305
  }
@@ -3280,7 +3442,7 @@ var LocalConnectionStore = class {
3280
3442
 
3281
3443
  // src/stores/LocalMetricsServerConfigStore.ts
3282
3444
  var import_core5 = require("@axiom-lattice/core");
3283
- var DDL18 = `
3445
+ var DDL19 = `
3284
3446
  CREATE TABLE IF NOT EXISTS lt_metrics_configs (
3285
3447
  id TEXT NOT NULL,
3286
3448
  tenant_id TEXT NOT NULL,
@@ -3297,7 +3459,7 @@ CREATE UNIQUE INDEX IF NOT EXISTS idx_lt_metrics_key ON lt_metrics_configs(tenan
3297
3459
  var LocalMetricsServerConfigStore = class {
3298
3460
  constructor(db) {
3299
3461
  this.db = db;
3300
- ensureTable(db, DDL18);
3462
+ ensureTable(db, DDL19);
3301
3463
  }
3302
3464
  async getAllConfigs(tenantId) {
3303
3465
  const rows2 = this.db.prepare(
@@ -3420,7 +3582,7 @@ function decryptSecretsInConfig(config) {
3420
3582
 
3421
3583
  // src/stores/LocalMcpServerConfigStore.ts
3422
3584
  var import_core6 = require("@axiom-lattice/core");
3423
- var DDL19 = `
3585
+ var DDL20 = `
3424
3586
  CREATE TABLE IF NOT EXISTS lt_mcp_configs (
3425
3587
  id TEXT NOT NULL,
3426
3588
  tenant_id TEXT NOT NULL,
@@ -3436,11 +3598,29 @@ CREATE TABLE IF NOT EXISTS lt_mcp_configs (
3436
3598
  PRIMARY KEY (tenant_id, id)
3437
3599
  );
3438
3600
  CREATE UNIQUE INDEX IF NOT EXISTS idx_lt_mcp_key ON lt_mcp_configs(tenant_id, key);
3601
+
3602
+ CREATE TABLE IF NOT EXISTS lt_personal_mcp_configs (
3603
+ id TEXT NOT NULL,
3604
+ tenant_id TEXT NOT NULL,
3605
+ owner_assistant_id TEXT NOT NULL,
3606
+ key TEXT NOT NULL,
3607
+ name TEXT,
3608
+ description TEXT,
3609
+ config TEXT NOT NULL,
3610
+ selected_tools TEXT DEFAULT '[]',
3611
+ is_env_encrypted INTEGER NOT NULL DEFAULT 0,
3612
+ status TEXT NOT NULL DEFAULT 'disconnected',
3613
+ created_at TEXT NOT NULL,
3614
+ updated_at TEXT NOT NULL,
3615
+ PRIMARY KEY (tenant_id, owner_assistant_id, id)
3616
+ );
3617
+ CREATE UNIQUE INDEX IF NOT EXISTS idx_lt_personal_mcp_key
3618
+ ON lt_personal_mcp_configs(tenant_id, owner_assistant_id, key);
3439
3619
  `;
3440
3620
  var LocalMcpServerConfigStore = class {
3441
3621
  constructor(db) {
3442
3622
  this.db = db;
3443
- ensureTable(db, DDL19);
3623
+ ensureTable(db, DDL20);
3444
3624
  }
3445
3625
  async getAllConfigs(tenantId) {
3446
3626
  const rows2 = this.db.prepare(
@@ -3562,6 +3742,147 @@ var LocalMcpServerConfigStore = class {
3562
3742
  ).get(tenantId, id);
3563
3743
  return row !== void 0;
3564
3744
  }
3745
+ async getAllConfigsForAssistant(tenantId, ownerAssistantId) {
3746
+ const rows2 = this.db.prepare(
3747
+ `SELECT * FROM lt_personal_mcp_configs
3748
+ WHERE tenant_id = ? AND owner_assistant_id = ?
3749
+ ORDER BY created_at DESC`
3750
+ ).all(tenantId, ownerAssistantId);
3751
+ return rows2.map(mapPersonalRowToEntry);
3752
+ }
3753
+ async getAllPersonalConfigsWithoutTenant() {
3754
+ const rows2 = this.db.prepare(
3755
+ `SELECT * FROM lt_personal_mcp_configs ORDER BY created_at DESC`
3756
+ ).all();
3757
+ return rows2.map(mapPersonalRowToEntry);
3758
+ }
3759
+ async getConfigByIdForAssistant(tenantId, ownerAssistantId, id) {
3760
+ const row = this.db.prepare(
3761
+ `SELECT * FROM lt_personal_mcp_configs
3762
+ WHERE tenant_id = ? AND owner_assistant_id = ? AND id = ?`
3763
+ ).get(tenantId, ownerAssistantId, id);
3764
+ return row ? mapPersonalRowToEntry(row) : null;
3765
+ }
3766
+ async getConfigByKeyForAssistant(tenantId, ownerAssistantId, key) {
3767
+ const row = this.db.prepare(
3768
+ `SELECT * FROM lt_personal_mcp_configs
3769
+ WHERE tenant_id = ? AND owner_assistant_id = ? AND key = ?`
3770
+ ).get(tenantId, ownerAssistantId, key);
3771
+ return row ? mapPersonalRowToEntry(row) : null;
3772
+ }
3773
+ async createConfigForAssistant(tenantId, ownerAssistantId, id, data) {
3774
+ const now = nowISO();
3775
+ const { config: configWithEncryptedEnv, isEnvEncrypted } = encryptEnvInConfig(data.config);
3776
+ this.db.prepare(
3777
+ `INSERT INTO lt_personal_mcp_configs (id, tenant_id, owner_assistant_id, key, name, description, config, selected_tools, is_env_encrypted, status, created_at, updated_at)
3778
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
3779
+ ON CONFLICT(tenant_id, owner_assistant_id, id) DO UPDATE SET
3780
+ key = excluded.key,
3781
+ name = excluded.name,
3782
+ description = excluded.description,
3783
+ config = excluded.config,
3784
+ selected_tools = excluded.selected_tools,
3785
+ is_env_encrypted = excluded.is_env_encrypted,
3786
+ status = excluded.status,
3787
+ updated_at = excluded.updated_at`
3788
+ ).run(
3789
+ id,
3790
+ tenantId,
3791
+ ownerAssistantId,
3792
+ data.key,
3793
+ data.name || null,
3794
+ data.description || null,
3795
+ JSON.stringify(configWithEncryptedEnv),
3796
+ JSON.stringify(data.selectedTools || []),
3797
+ isEnvEncrypted ? 1 : 0,
3798
+ "disconnected",
3799
+ now,
3800
+ now
3801
+ );
3802
+ return {
3803
+ id,
3804
+ tenantId,
3805
+ ownerAssistantId,
3806
+ key: data.key,
3807
+ config: data.config,
3808
+ name: data.name,
3809
+ description: data.description,
3810
+ selectedTools: data.selectedTools || [],
3811
+ isEnvEncrypted,
3812
+ status: "disconnected",
3813
+ createdAt: parseISO(now),
3814
+ updatedAt: parseISO(now)
3815
+ };
3816
+ }
3817
+ async updateConfigForAssistant(tenantId, ownerAssistantId, id, updates) {
3818
+ const existing = await this.getConfigByIdForAssistant(
3819
+ tenantId,
3820
+ ownerAssistantId,
3821
+ id
3822
+ );
3823
+ if (!existing) return null;
3824
+ const setClauses = [];
3825
+ const values = [];
3826
+ if (updates.key !== void 0) {
3827
+ setClauses.push("key = ?");
3828
+ values.push(updates.key);
3829
+ }
3830
+ if (updates.name !== void 0) {
3831
+ setClauses.push("name = ?");
3832
+ values.push(updates.name || null);
3833
+ }
3834
+ if (updates.description !== void 0) {
3835
+ setClauses.push("description = ?");
3836
+ values.push(updates.description || null);
3837
+ }
3838
+ if (updates.config !== void 0) {
3839
+ const { config: configWithEncryptedEnv, isEnvEncrypted } = encryptEnvInConfig(updates.config);
3840
+ setClauses.push("config = ?");
3841
+ values.push(JSON.stringify(configWithEncryptedEnv));
3842
+ setClauses.push("is_env_encrypted = ?");
3843
+ values.push(isEnvEncrypted ? 1 : 0);
3844
+ }
3845
+ if (updates.selectedTools !== void 0) {
3846
+ setClauses.push("selected_tools = ?");
3847
+ values.push(JSON.stringify(updates.selectedTools));
3848
+ }
3849
+ if (updates.status !== void 0) {
3850
+ setClauses.push("status = ?");
3851
+ values.push(updates.status);
3852
+ }
3853
+ if (setClauses.length === 0) return existing;
3854
+ const now = nowISO();
3855
+ setClauses.push("updated_at = ?");
3856
+ values.push(now);
3857
+ values.push(tenantId, ownerAssistantId, id);
3858
+ this.db.prepare(
3859
+ `UPDATE lt_personal_mcp_configs SET ${setClauses.join(", ")}
3860
+ WHERE tenant_id = ? AND owner_assistant_id = ? AND id = ?`
3861
+ ).run(...values);
3862
+ return this.getConfigByIdForAssistant(tenantId, ownerAssistantId, id);
3863
+ }
3864
+ async deleteConfigForAssistant(tenantId, ownerAssistantId, id) {
3865
+ const result = this.db.prepare(
3866
+ `DELETE FROM lt_personal_mcp_configs
3867
+ WHERE tenant_id = ? AND owner_assistant_id = ? AND id = ?`
3868
+ ).run(tenantId, ownerAssistantId, id);
3869
+ return result.changes > 0;
3870
+ }
3871
+ async deleteConfigsForAssistant(tenantId, ownerAssistantId) {
3872
+ const result = this.db.prepare(
3873
+ `DELETE FROM lt_personal_mcp_configs
3874
+ WHERE tenant_id = ? AND owner_assistant_id = ?`
3875
+ ).run(tenantId, ownerAssistantId);
3876
+ return result.changes;
3877
+ }
3878
+ async hasConfigForAssistant(tenantId, ownerAssistantId, id) {
3879
+ const row = this.db.prepare(
3880
+ `SELECT 1 FROM lt_personal_mcp_configs
3881
+ WHERE tenant_id = ? AND owner_assistant_id = ? AND id = ?
3882
+ LIMIT 1`
3883
+ ).get(tenantId, ownerAssistantId, id);
3884
+ return row !== void 0;
3885
+ }
3565
3886
  };
3566
3887
  function mapRowToEntry3(row) {
3567
3888
  const config = JSON.parse(row.config);
@@ -3593,6 +3914,12 @@ function mapRowToEntry3(row) {
3593
3914
  updatedAt: parseISO(row.updated_at)
3594
3915
  };
3595
3916
  }
3917
+ function mapPersonalRowToEntry(row) {
3918
+ return {
3919
+ ...mapRowToEntry3(row),
3920
+ ownerAssistantId: row.owner_assistant_id
3921
+ };
3922
+ }
3596
3923
  function encryptEnvInConfig(config) {
3597
3924
  const configCopy = { ...config };
3598
3925
  let isEnvEncrypted = false;
@@ -3617,7 +3944,7 @@ function encryptEnvInConfig(config) {
3617
3944
 
3618
3945
  // src/stores/LocalModelProviderStore.ts
3619
3946
  var import_core7 = require("@axiom-lattice/core");
3620
- var DDL20 = `
3947
+ var DDL21 = `
3621
3948
  CREATE TABLE IF NOT EXISTS lt_model_providers (
3622
3949
  id TEXT NOT NULL,
3623
3950
  tenant_id TEXT NOT NULL,
@@ -3662,7 +3989,7 @@ CREATE INDEX IF NOT EXISTS idx_lt_model_provider_models_tenant
3662
3989
  var LocalModelProviderStore = class {
3663
3990
  constructor(db) {
3664
3991
  this.db = db;
3665
- ensureTable(db, DDL20);
3992
+ ensureTable(db, DDL21);
3666
3993
  this.ensureColumn(
3667
3994
  "lt_model_providers",
3668
3995
  "api_style",
@@ -3941,8 +4268,8 @@ function mapRowToModel(row) {
3941
4268
  }
3942
4269
 
3943
4270
  // src/stores/LocalWorkflowTrackingStore.ts
3944
- var import_node_crypto = require("crypto");
3945
- var DDL21 = `
4271
+ var import_node_crypto2 = require("crypto");
4272
+ var DDL22 = `
3946
4273
  CREATE TABLE IF NOT EXISTS lt_workflow_runs (
3947
4274
  id TEXT PRIMARY KEY,
3948
4275
  tenant_id TEXT NOT NULL,
@@ -3989,7 +4316,7 @@ CREATE INDEX IF NOT EXISTS idx_lt_ws_type ON lt_workflow_steps(run_id, step_type
3989
4316
  var LocalWorkflowTrackingStore = class {
3990
4317
  constructor(db) {
3991
4318
  this.db = db;
3992
- ensureTable(db, DDL21);
4319
+ ensureTable(db, DDL22);
3993
4320
  this.ensureColumn("lt_workflow_steps", "thread_id", "thread_id TEXT");
3994
4321
  }
3995
4322
  /** Add a column if it does not exist (SQLite version compatible). */
@@ -4001,7 +4328,7 @@ var LocalWorkflowTrackingStore = class {
4001
4328
  }
4002
4329
  async createWorkflowRun(request) {
4003
4330
  const now = nowISO();
4004
- const id = `${request.threadId}_${Date.now()}_${(0, import_node_crypto.randomUUID)()}`;
4331
+ const id = `${request.threadId}_${Date.now()}_${(0, import_node_crypto2.randomUUID)()}`;
4005
4332
  this.db.prepare(
4006
4333
  `INSERT INTO lt_workflow_runs (id, tenant_id, assistant_id, thread_id, status, topology_edges, total_edges, completed_edges, metadata, started_at, created_at, updated_at)
4007
4334
  VALUES (?, ?, ?, ?, 'running', ?, ?, 0, ?, ?, ?, ?)`
@@ -4288,7 +4615,7 @@ function mapRowToStep(row) {
4288
4615
 
4289
4616
  // src/stores/LocalEvalStore.ts
4290
4617
  var import_crypto = require("crypto");
4291
- var DDL22 = `
4618
+ var DDL23 = `
4292
4619
  CREATE TABLE IF NOT EXISTS lt_eval_projects (
4293
4620
  id TEXT NOT NULL,
4294
4621
  tenant_id TEXT NOT NULL,
@@ -4374,7 +4701,7 @@ CREATE TABLE IF NOT EXISTS lt_eval_run_results (
4374
4701
  PRIMARY KEY (run_id, id)
4375
4702
  );
4376
4703
  `;
4377
- function parseJson2(val, fallback) {
4704
+ function parseJson3(val, fallback) {
4378
4705
  if (val == null) return fallback;
4379
4706
  if (typeof val === "string") {
4380
4707
  try {
@@ -4399,7 +4726,7 @@ function parseOptionalJson(val) {
4399
4726
  var LocalEvalStore = class {
4400
4727
  constructor(db) {
4401
4728
  this.db = db;
4402
- ensureTable(db, DDL22);
4729
+ ensureTable(db, DDL23);
4403
4730
  this.ensureColumn("lt_eval_runs", "interrupted_cases", "interrupted_cases INTEGER NOT NULL DEFAULT 0");
4404
4731
  this.ensureColumn("lt_eval_run_results", "interrupted", "interrupted INTEGER NOT NULL DEFAULT 0");
4405
4732
  this.ensureColumn("lt_eval_cases", "interrupt_policy", "interrupt_policy TEXT");
@@ -4913,8 +5240,8 @@ var LocalEvalStore = class {
4913
5240
  name: row.name,
4914
5241
  description: row.description,
4915
5242
  version: row.version,
4916
- judgeModelConfig: parseJson2(row.judge_model_config, {}),
4917
- targetServerConfig: parseJson2(row.target_server_config, {}),
5243
+ judgeModelConfig: parseJson3(row.judge_model_config, {}),
5244
+ targetServerConfig: parseJson3(row.target_server_config, {}),
4918
5245
  concurrency: row.concurrency ?? 3,
4919
5246
  reportConfig: parseOptionalJson(row.report_config),
4920
5247
  createdAt: parseISO(row.created_at),
@@ -4939,7 +5266,7 @@ var LocalEvalStore = class {
4939
5266
  suiteId: row.suite_id,
4940
5267
  inputMessage: row.input_message,
4941
5268
  inputFiles: parseOptionalJson(row.input_files),
4942
- steps: parseJson2(row.steps, []),
5269
+ steps: parseJson3(row.steps, []),
4943
5270
  outputType: row.output_type || "message_content",
4944
5271
  contentAssertion: row.content_assertion || "",
4945
5272
  rubrics: parseOptionalJson(row.rubrics),
@@ -4992,11 +5319,11 @@ var LocalEvalStore = class {
4992
5319
  };
4993
5320
 
4994
5321
  // src/stores/LocalChannelBindingStore.ts
4995
- var import_protocols10 = require("@axiom-lattice/protocols");
5322
+ var import_protocols11 = require("@axiom-lattice/protocols");
4996
5323
  var import_crypto2 = require("crypto");
4997
5324
 
4998
5325
  // src/stores/room-channel-binding-index.ts
4999
- var import_protocols9 = require("@axiom-lattice/protocols");
5326
+ var import_protocols10 = require("@axiom-lattice/protocols");
5000
5327
  var UNIQUE_INDEX_SQL = `CREATE UNIQUE INDEX IF NOT EXISTS idx_lt_cb_subject_unique
5001
5328
  ON lt_channel_bindings(channel, channel_installation_id, tenant_id, sender_id)`;
5002
5329
  var LOOKUP_INDEX_SQL = `CREATE INDEX IF NOT EXISTS idx_lt_cb_resolve
@@ -5010,7 +5337,7 @@ function ensureChannelBindingSubjectIndex(db) {
5010
5337
  HAVING COUNT(*) > 1
5011
5338
  ORDER BY tenant_id, channel, channel_installation_id, sender_id`).all();
5012
5339
  if (conflicts.length > 0) {
5013
- throw new import_protocols9.ChannelBindingMigrationConflictError(conflicts.map(mapConflict));
5340
+ throw new import_protocols10.ChannelBindingMigrationConflictError(conflicts.map(mapConflict));
5014
5341
  }
5015
5342
  db.exec("DROP INDEX IF EXISTS idx_lt_cb_room_subject");
5016
5343
  db.exec(UNIQUE_INDEX_SQL);
@@ -5036,7 +5363,7 @@ function mapConflict(row) {
5036
5363
  }
5037
5364
 
5038
5365
  // src/stores/LocalChannelBindingStore.ts
5039
- var DDL23 = `
5366
+ var DDL24 = `
5040
5367
  CREATE TABLE IF NOT EXISTS lt_channel_bindings (
5041
5368
  id TEXT PRIMARY KEY,
5042
5369
  channel TEXT NOT NULL,
@@ -5058,7 +5385,7 @@ CREATE TABLE IF NOT EXISTS lt_channel_bindings (
5058
5385
  var LocalChannelBindingStore = class {
5059
5386
  constructor(db) {
5060
5387
  this.db = db;
5061
- ensureTable(db, DDL23);
5388
+ ensureTable(db, DDL24);
5062
5389
  ensureChannelBindingSubjectIndex(db);
5063
5390
  }
5064
5391
  async findById(tenantId, id) {
@@ -5108,7 +5435,7 @@ var LocalChannelBindingStore = class {
5108
5435
  );
5109
5436
  } catch (error) {
5110
5437
  if (error instanceof Error && /UNIQUE constraint failed/.test(error.message)) {
5111
- throw new import_protocols10.DuplicateChannelBindingSubjectError();
5438
+ throw new import_protocols11.DuplicateChannelBindingSubjectError();
5112
5439
  }
5113
5440
  throw error;
5114
5441
  }
@@ -5238,7 +5565,7 @@ function mapRowToBinding(row) {
5238
5565
  }
5239
5566
 
5240
5567
  // src/stores/LocalChannelInstallationStore.ts
5241
- var DDL24 = `
5568
+ var DDL25 = `
5242
5569
  CREATE TABLE IF NOT EXISTS lt_channel_installations (
5243
5570
  id TEXT PRIMARY KEY,
5244
5571
  tenant_id TEXT NOT NULL,
@@ -5256,13 +5583,13 @@ CREATE INDEX IF NOT EXISTS idx_lt_ci_tenant ON lt_channel_installations(tenant_i
5256
5583
  var LocalChannelInstallationStore = class {
5257
5584
  constructor(db) {
5258
5585
  this.db = db;
5259
- ensureTable(db, DDL24);
5586
+ ensureTable(db, DDL25);
5260
5587
  }
5261
5588
  async getInstallationById(installationId) {
5262
5589
  const row = this.db.prepare(
5263
5590
  `SELECT * FROM lt_channel_installations WHERE id = ?`
5264
5591
  ).get(installationId);
5265
- return row ? mapRow14(row) : null;
5592
+ return row ? mapRow15(row) : null;
5266
5593
  }
5267
5594
  async getInstallationsByTenant(tenantId, channel) {
5268
5595
  let rows2;
@@ -5275,7 +5602,7 @@ var LocalChannelInstallationStore = class {
5275
5602
  `SELECT * FROM lt_channel_installations WHERE tenant_id = ? ORDER BY created_at DESC`
5276
5603
  ).all(tenantId);
5277
5604
  }
5278
- return rows2.map(mapRow14);
5605
+ return rows2.map(mapRow15);
5279
5606
  }
5280
5607
  async getAllInstallations(channel) {
5281
5608
  let rows2;
@@ -5288,7 +5615,7 @@ var LocalChannelInstallationStore = class {
5288
5615
  `SELECT * FROM lt_channel_installations ORDER BY created_at DESC`
5289
5616
  ).all();
5290
5617
  }
5291
- return rows2.map(mapRow14);
5618
+ return rows2.map(mapRow15);
5292
5619
  }
5293
5620
  async createInstallation(tenantId, installationId, data) {
5294
5621
  const now = nowISO();
@@ -5364,7 +5691,7 @@ var LocalChannelInstallationStore = class {
5364
5691
  return result.changes > 0;
5365
5692
  }
5366
5693
  };
5367
- function mapRow14(row) {
5694
+ function mapRow15(row) {
5368
5695
  return {
5369
5696
  id: row.id,
5370
5697
  tenantId: row.tenant_id,
@@ -5382,7 +5709,7 @@ function mapRow14(row) {
5382
5709
  // src/stores/LocalA2AApiKeyStore.ts
5383
5710
  var import_core8 = require("@axiom-lattice/core");
5384
5711
  var import_crypto3 = require("crypto");
5385
- var DDL25 = `
5712
+ var DDL26 = `
5386
5713
  CREATE TABLE IF NOT EXISTS lt_a2a_api_keys (
5387
5714
  id TEXT PRIMARY KEY,
5388
5715
  key_value TEXT NOT NULL,
@@ -5420,7 +5747,7 @@ function parseAssistantIds(raw) {
5420
5747
  var LocalA2AApiKeyStore = class {
5421
5748
  constructor(db) {
5422
5749
  this.db = db;
5423
- ensureTable(db, DDL25);
5750
+ ensureTable(db, DDL26);
5424
5751
  this.ensureColumn("lt_a2a_api_keys", "assistant_ids", "assistant_ids TEXT");
5425
5752
  this.ensureColumn("lt_a2a_api_keys", "grants", "grants TEXT");
5426
5753
  this.repairManagementIds();
@@ -5601,7 +5928,7 @@ function mapRowToRecord(row) {
5601
5928
 
5602
5929
  // src/stores/LocalOpenAuditStore.ts
5603
5930
  var import_crypto4 = require("crypto");
5604
- var DDL26 = `
5931
+ var DDL27 = `
5605
5932
  CREATE TABLE IF NOT EXISTS lt_open_audit (
5606
5933
  id TEXT PRIMARY KEY,
5607
5934
  tenant_id TEXT NOT NULL,
@@ -5620,7 +5947,7 @@ CREATE TABLE IF NOT EXISTS lt_open_audit (
5620
5947
  var LocalOpenAuditStore = class {
5621
5948
  constructor(db) {
5622
5949
  this.db = db;
5623
- ensureTable(db, DDL26);
5950
+ ensureTable(db, DDL27);
5624
5951
  }
5625
5952
  async query(params) {
5626
5953
  const clauses = ["tenant_id = ?"];
@@ -5690,9 +6017,9 @@ var LocalOpenAuditStore = class {
5690
6017
  };
5691
6018
 
5692
6019
  // src/stores/LocalThreadMessageQueueStore.ts
5693
- var import_protocols11 = require("@axiom-lattice/protocols");
6020
+ var import_protocols12 = require("@axiom-lattice/protocols");
5694
6021
  var import_crypto5 = require("crypto");
5695
- var DDL27 = `
6022
+ var DDL28 = `
5696
6023
  CREATE TABLE IF NOT EXISTS lt_thread_message_queue (
5697
6024
  id TEXT PRIMARY KEY,
5698
6025
  thread_id TEXT NOT NULL,
@@ -5721,7 +6048,7 @@ var LocalThreadMessageQueueStore = class {
5721
6048
  constructor(db) {
5722
6049
  this.capacityTail = Promise.resolve();
5723
6050
  this.db = db;
5724
- ensureTable(db, DDL27);
6051
+ ensureTable(db, DDL28);
5725
6052
  const columns6 = db.prepare("PRAGMA table_info(lt_thread_message_queue)").all();
5726
6053
  const names = new Set(columns6.map(({ name }) => name));
5727
6054
  if (!names.has("trusted_run_context")) {
@@ -5953,8 +6280,8 @@ var LocalThreadMessageQueueStore = class {
5953
6280
  };
5954
6281
  function validateQueueTrust(params) {
5955
6282
  return {
5956
- trustedRunContext: params.trusted_run_context === void 0 ? void 0 : (0, import_protocols11.parseTrustedRunContext)(params.trusted_run_context),
5957
- executionMode: params.execution_mode === void 0 ? void 0 : (0, import_protocols11.parseQueuedExecutionMode)(params.execution_mode)
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)
5958
6285
  };
5959
6286
  }
5960
6287
  function scopeClause(scope) {
@@ -5975,13 +6302,13 @@ function rowToMessage(row) {
5975
6302
  priority: row.priority || 0,
5976
6303
  command: row.command ? JSON.parse(row.command) : void 0,
5977
6304
  custom_run_config: row.custom_run_config ? JSON.parse(row.custom_run_config) : void 0,
5978
- trusted_run_context: row.trusted_run_context ? (0, import_protocols11.parseTrustedRunContext)(JSON.parse(row.trusted_run_context)) : void 0,
5979
- execution_mode: row.execution_mode == null ? void 0 : (0, import_protocols11.parseQueuedExecutionMode)(row.execution_mode)
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)
5980
6307
  };
5981
6308
  }
5982
6309
 
5983
6310
  // src/stores/LocalSkillStore.ts
5984
- var DDL28 = `
6311
+ var DDL29 = `
5985
6312
  CREATE TABLE IF NOT EXISTS lt_skills (
5986
6313
  id TEXT NOT NULL,
5987
6314
  tenant_id TEXT NOT NULL,
@@ -6000,7 +6327,7 @@ CREATE TABLE IF NOT EXISTS lt_skills (
6000
6327
  var LocalSkillStore = class {
6001
6328
  constructor(db) {
6002
6329
  this.db = db;
6003
- ensureTable(db, DDL28);
6330
+ ensureTable(db, DDL29);
6004
6331
  }
6005
6332
  async getAllSkills(tenantId, _context) {
6006
6333
  const rows2 = this.db.prepare(
@@ -6150,7 +6477,7 @@ function mapRowToSkill(row) {
6150
6477
  }
6151
6478
 
6152
6479
  // src/stores/LocalScheduleStorage.ts
6153
- var DDL29 = `
6480
+ var DDL30 = `
6154
6481
  CREATE TABLE IF NOT EXISTS lt_scheduled_tasks (
6155
6482
  task_id TEXT PRIMARY KEY,
6156
6483
  task_type TEXT NOT NULL,
@@ -6183,7 +6510,7 @@ CREATE INDEX IF NOT EXISTS idx_lt_st_tenant ON lt_scheduled_tasks(tenant_id);
6183
6510
  var LocalScheduleStorage = class {
6184
6511
  constructor(db) {
6185
6512
  this.db = db;
6186
- ensureTable(db, DDL29);
6513
+ ensureTable(db, DDL30);
6187
6514
  }
6188
6515
  async save(task) {
6189
6516
  this.db.prepare(
@@ -6500,7 +6827,7 @@ function mapRowToTask(row) {
6500
6827
  }
6501
6828
 
6502
6829
  // src/stores/LocalTaskStore.ts
6503
- var import_protocols12 = require("@axiom-lattice/protocols");
6830
+ var import_protocols13 = require("@axiom-lattice/protocols");
6504
6831
  var import_crypto6 = require("crypto");
6505
6832
  var MAX_CANONICAL_TASK_TIME = "9999-12-31T23:59:59.999Z";
6506
6833
  var TASK_STATUSES = /* @__PURE__ */ new Set([
@@ -6517,7 +6844,7 @@ var NEXT_UPDATED_AT_SQL = `updated_at = CASE
6517
6844
  THEN strftime('%Y-%m-%dT%H:%M:%fZ', updated_at, '+0.001 seconds')
6518
6845
  ELSE ?
6519
6846
  END`;
6520
- var DDL30 = `
6847
+ var DDL31 = `
6521
6848
  CREATE TABLE IF NOT EXISTS lt_tasks (
6522
6849
  id TEXT NOT NULL,
6523
6850
  tenant_id TEXT NOT NULL,
@@ -6590,7 +6917,7 @@ function assertPage(limit, offset = 0) {
6590
6917
  var LocalTaskStore = class {
6591
6918
  constructor(db) {
6592
6919
  this.db = db;
6593
- ensureTable(db, DDL30);
6920
+ ensureTable(db, DDL31);
6594
6921
  this.ensureColumn("lt_tasks", "require_review", "require_review INTEGER DEFAULT 0");
6595
6922
  this.ensureColumn("lt_tasks", "dependencies", "dependencies TEXT");
6596
6923
  this.ensureColumn("lt_tasks", "result", "result TEXT");
@@ -6689,7 +7016,7 @@ var LocalTaskStore = class {
6689
7016
  if (filter.metadata) {
6690
7017
  for (const [key, value] of Object.entries(filter.metadata)) {
6691
7018
  const safeKey = key.replace(/[^a-zA-Z0-9_]/g, "");
6692
- const expected = (0, import_protocols12.normalizeTaskMetadataScalar)(value);
7019
+ const expected = (0, import_protocols13.normalizeTaskMetadataScalar)(value);
6693
7020
  if (!safeKey || expected === void 0) continue;
6694
7021
  if (expected === "true" || expected === "false") {
6695
7022
  conditions.push(
@@ -7264,7 +7591,7 @@ var LocalTaskStore = class {
7264
7591
  };
7265
7592
 
7266
7593
  // src/stores/LocalTaskWorkItemStore.ts
7267
- var import_protocols13 = require("@axiom-lattice/protocols");
7594
+ var import_protocols14 = require("@axiom-lattice/protocols");
7268
7595
  var import_uuid2 = require("uuid");
7269
7596
  var PROJECT_LIFECYCLE_ACTIONS = /* @__PURE__ */ new Set([
7270
7597
  "in_progress",
@@ -7274,7 +7601,7 @@ var PROJECT_LIFECYCLE_ACTIONS = /* @__PURE__ */ new Set([
7274
7601
  "cancelled",
7275
7602
  "reassigned"
7276
7603
  ]);
7277
- var DDL31 = `
7604
+ var DDL32 = `
7278
7605
  CREATE TABLE IF NOT EXISTS lt_task_work_items (
7279
7606
  id TEXT NOT NULL,
7280
7607
  tenant_id TEXT NOT NULL,
@@ -7348,7 +7675,7 @@ function assertLifecyclePage(query) {
7348
7675
  var LocalTaskWorkItemStore = class {
7349
7676
  constructor(db) {
7350
7677
  this.db = db;
7351
- ensureTable(db, DDL31);
7678
+ ensureTable(db, DDL32);
7352
7679
  this.ensureColumn("lt_task_work_items", "workspace_id", "workspace_id TEXT");
7353
7680
  this.ensureColumn("lt_task_work_items", "project_id", "project_id TEXT");
7354
7681
  this.ensureColumn("lt_task_work_items", "event_key", "event_key TEXT");
@@ -7489,8 +7816,8 @@ var LocalTaskWorkItemStore = class {
7489
7816
  }
7490
7817
  /** List pending execution results using one bounded SQLite anti-join query. */
7491
7818
  async listPendingExecutionResults(params) {
7492
- if (!Number.isSafeInteger(params.limit) || params.limit < 0 || params.limit > import_protocols13.MAX_PENDING_EXECUTION_RESULTS_LIMIT) {
7493
- const error = new RangeError(`limit must be a safe integer between 0 and ${import_protocols13.MAX_PENDING_EXECUTION_RESULTS_LIMIT}`);
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}`);
7494
7821
  error.code = "INVALID_LIMIT";
7495
7822
  throw error;
7496
7823
  }
@@ -7545,7 +7872,7 @@ var LocalTaskWorkItemStore = class {
7545
7872
 
7546
7873
  // src/stores/LocalCapabilityBundleStore.ts
7547
7874
  var import_crypto7 = require("crypto");
7548
- var DDL32 = `CREATE TABLE IF NOT EXISTS lt_capability_bundles (id TEXT NOT NULL, tenant_id TEXT NOT NULL, bundle_key TEXT NOT NULL, name TEXT NOT NULL, description TEXT, capabilities TEXT NOT NULL DEFAULT '[]', created_at TEXT NOT NULL, updated_at TEXT NOT NULL, PRIMARY KEY (tenant_id, id), UNIQUE (tenant_id, bundle_key)); CREATE INDEX IF NOT EXISTS idx_lt_capability_bundles_tenant ON lt_capability_bundles(tenant_id);`;
7875
+ var DDL33 = `CREATE TABLE IF NOT EXISTS lt_capability_bundles (id TEXT NOT NULL, tenant_id TEXT NOT NULL, bundle_key TEXT NOT NULL, name TEXT NOT NULL, description TEXT, capabilities TEXT NOT NULL DEFAULT '[]', created_at TEXT NOT NULL, updated_at TEXT NOT NULL, PRIMARY KEY (tenant_id, id), UNIQUE (tenant_id, bundle_key)); CREATE INDEX IF NOT EXISTS idx_lt_capability_bundles_tenant ON lt_capability_bundles(tenant_id);`;
7549
7876
  var duplicateMessage = "Capability bundle key already exists for tenant";
7550
7877
  function map(row) {
7551
7878
  return { id: row.id, tenantId: row.tenant_id, key: row.bundle_key, name: row.name, description: row.description ?? void 0, capabilities: JSON.parse(row.capabilities), createdAt: parseISO(row.created_at).toISOString(), updatedAt: parseISO(row.updated_at).toISOString() };
@@ -7566,7 +7893,7 @@ var LocalCapabilityBundleStore = class {
7566
7893
  */
7567
7894
  constructor(db) {
7568
7895
  this.db = db;
7569
- ensureTable(db, DDL32);
7896
+ ensureTable(db, DDL33);
7570
7897
  }
7571
7898
  async listByTenant(tenantId) {
7572
7899
  return this.db.prepare("SELECT * FROM lt_capability_bundles WHERE tenant_id = ? ORDER BY created_at").all(tenantId).map(map);
@@ -7660,6 +7987,7 @@ async function createLocalStoreConfig(options = {}) {
7660
7987
  oidcIdentityClaim: new LocalOidcIdentityClaimStore(db),
7661
7988
  inviteLink: new LocalInviteLinkStore(db),
7662
7989
  platformSettings: new LocalPlatformSettingsStore(db),
7990
+ platformAudit: new LocalPlatformAuditStore(db),
7663
7991
  database: new LocalDatabaseConfigStore(db),
7664
7992
  connection: new LocalConnectionStore(db),
7665
7993
  metrics: new LocalMetricsServerConfigStore(db),
@@ -7738,6 +8066,7 @@ var InMemoryConversationStore = class {
7738
8066
  LocalOidcIdentityClaimStore,
7739
8067
  LocalOidcProviderConfigStore,
7740
8068
  LocalOpenAuditStore,
8069
+ LocalPlatformAuditStore,
7741
8070
  LocalPlatformInvitationStore,
7742
8071
  LocalPlatformMemberStore,
7743
8072
  LocalPlatformSettingsStore,