@axiom-lattice/local-stores 3.2.12 → 3.3.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.mjs CHANGED
@@ -278,6 +278,7 @@ CREATE TABLE IF NOT EXISTS lt_threads (
278
278
  metadata TEXT DEFAULT '{}',
279
279
  created_at TEXT NOT NULL,
280
280
  updated_at TEXT NOT NULL,
281
+ expires_at TEXT,
281
282
  PRIMARY KEY (tenant_id, id)
282
283
  );
283
284
  CREATE INDEX IF NOT EXISTS idx_lt_threads_assistant ON lt_threads(tenant_id, assistant_id);
@@ -294,6 +295,14 @@ var LocalThreadStore = class {
294
295
  }
295
296
  });
296
297
  mm.migrate();
298
+ this.ensureColumn("expires_at", "TEXT");
299
+ }
300
+ /** Add a column if it does not exist (SQLite version compatible). */
301
+ ensureColumn(column, ddl2) {
302
+ const cols = this.db.prepare("PRAGMA table_info(lt_threads)").all();
303
+ if (!cols.some((c) => c.name === column)) {
304
+ this.db.exec(`ALTER TABLE lt_threads ADD COLUMN ${column} ${ddl2}`);
305
+ }
297
306
  }
298
307
  async getThreadsByAssistantId(tenantId, assistantId, metadataFilter) {
299
308
  const rows2 = this.db.prepare(
@@ -319,20 +328,22 @@ var LocalThreadStore = class {
319
328
  const now = nowISO();
320
329
  const metadata = JSON.stringify(data.metadata || {});
321
330
  this.db.prepare(
322
- `INSERT INTO lt_threads (id, tenant_id, assistant_id, metadata, created_at, updated_at)
323
- VALUES (?, ?, ?, ?, ?, ?)
331
+ `INSERT INTO lt_threads (id, tenant_id, assistant_id, metadata, created_at, updated_at, expires_at)
332
+ VALUES (?, ?, ?, ?, ?, ?, ?)
324
333
  ON CONFLICT(tenant_id, id) DO UPDATE SET
325
334
  assistant_id = excluded.assistant_id,
326
335
  metadata = excluded.metadata,
327
- updated_at = excluded.updated_at`
328
- ).run(threadId, tenantId, assistantId, metadata, now, now);
336
+ updated_at = excluded.updated_at,
337
+ expires_at = excluded.expires_at`
338
+ ).run(threadId, tenantId, assistantId, metadata, now, now, data.expiresAt?.toISOString() ?? null);
329
339
  return {
330
340
  id: threadId,
331
341
  tenantId,
332
342
  assistantId,
333
343
  metadata: data.metadata || {},
334
344
  createdAt: parseISO(now),
335
- updatedAt: parseISO(now)
345
+ updatedAt: parseISO(now),
346
+ expiresAt: data.expiresAt
336
347
  };
337
348
  }
338
349
  async updateThread(tenantId, threadId, updates) {
@@ -343,13 +354,15 @@ var LocalThreadStore = class {
343
354
  ...updates.metadata || {}
344
355
  };
345
356
  const now = nowISO();
357
+ const expiresAt = updates.expiresAt !== void 0 ? updates.expiresAt.toISOString() : existing.expiresAt?.toISOString() ?? null;
346
358
  this.db.prepare(
347
- `UPDATE lt_threads SET metadata = ?, updated_at = ? WHERE tenant_id = ? AND id = ?`
348
- ).run(JSON.stringify(updatedMetadata), now, tenantId, threadId);
359
+ `UPDATE lt_threads SET metadata = ?, updated_at = ?, expires_at = ? WHERE tenant_id = ? AND id = ?`
360
+ ).run(JSON.stringify(updatedMetadata), now, expiresAt, tenantId, threadId);
349
361
  return {
350
362
  ...existing,
351
363
  metadata: updatedMetadata,
352
- updatedAt: parseISO(now)
364
+ updatedAt: parseISO(now),
365
+ expiresAt: expiresAt ? parseISO(expiresAt) : void 0
353
366
  };
354
367
  }
355
368
  async deleteThread(tenantId, threadId) {
@@ -364,6 +377,15 @@ var LocalThreadStore = class {
364
377
  ).get(tenantId, threadId);
365
378
  return row !== void 0;
366
379
  }
380
+ async listExpiredThreads(now, limit) {
381
+ const rows2 = this.db.prepare(
382
+ `SELECT * FROM lt_threads
383
+ WHERE expires_at IS NOT NULL AND expires_at <= ?
384
+ ORDER BY expires_at ASC
385
+ LIMIT ?`
386
+ ).all(now.toISOString(), Math.max(0, limit));
387
+ return rows2.map(mapRowToThread);
388
+ }
367
389
  };
368
390
  function mapRowToThread(row) {
369
391
  return {
@@ -372,12 +394,178 @@ function mapRowToThread(row) {
372
394
  assistantId: row.assistant_id,
373
395
  metadata: JSON.parse(row.metadata || "{}"),
374
396
  createdAt: parseISO(row.created_at),
375
- updatedAt: parseISO(row.updated_at)
397
+ updatedAt: parseISO(row.updated_at),
398
+ expiresAt: row.expires_at ? parseISO(row.expires_at) : void 0
376
399
  };
377
400
  }
378
401
 
379
- // src/stores/LocalAssistantStore.ts
402
+ // src/stores/LocalStore.ts
403
+ import {
404
+ assertStoreIdentity,
405
+ assertStoreNamespacePrefix,
406
+ storeExpiresAt,
407
+ storePaginationValue,
408
+ STORE_IDENTITY_SEPARATOR
409
+ } from "@axiom-lattice/protocols";
410
+ var STORE_NAME2 = "lt_store_items";
411
+ var NAMESPACE_SEPARATOR = STORE_IDENTITY_SEPARATOR;
380
412
  var DDL2 = `
413
+ CREATE TABLE IF NOT EXISTS lt_store_items (
414
+ tenant_id TEXT NOT NULL,
415
+ namespace_path TEXT NOT NULL,
416
+ key TEXT NOT NULL,
417
+ value TEXT NOT NULL,
418
+ created_at TEXT NOT NULL,
419
+ updated_at TEXT NOT NULL,
420
+ expires_at TEXT,
421
+ PRIMARY KEY (tenant_id, namespace_path, key)
422
+ );
423
+ CREATE INDEX IF NOT EXISTS idx_lt_store_items_tenant_updated
424
+ ON lt_store_items(tenant_id, updated_at DESC);
425
+ CREATE INDEX IF NOT EXISTS idx_lt_store_items_expires
426
+ ON lt_store_items(expires_at) WHERE expires_at IS NOT NULL;
427
+ `;
428
+ function namespacePath(namespace) {
429
+ return namespace.join(NAMESPACE_SEPARATOR);
430
+ }
431
+ function isPlainObject(value) {
432
+ return typeof value === "object" && value !== null && !Array.isArray(value);
433
+ }
434
+ function deepContains(actual, expected) {
435
+ if (Array.isArray(expected)) {
436
+ return Array.isArray(actual) && expected.every((item) => actual.some((candidate) => deepContains(candidate, item)));
437
+ }
438
+ if (isPlainObject(expected)) {
439
+ if (!isPlainObject(actual)) return false;
440
+ return Object.entries(expected).every(([key, value]) => deepContains(actual[key], value));
441
+ }
442
+ return Object.is(actual, expected);
443
+ }
444
+ function matchesFilter(value, filter) {
445
+ return deepContains(value, filter);
446
+ }
447
+ function hasPrefix(namespace, prefix) {
448
+ return prefix.length === 0 || namespace.length >= prefix.length && prefix.every((segment, index) => namespace[index] === segment);
449
+ }
450
+ function mapRow(row) {
451
+ return {
452
+ namespace: row.namespace_path.split(NAMESPACE_SEPARATOR),
453
+ key: row.key,
454
+ value: JSON.parse(row.value),
455
+ createdAt: parseISO(row.created_at),
456
+ updatedAt: parseISO(row.updated_at),
457
+ expiresAt: row.expires_at ? parseISO(row.expires_at) : void 0
458
+ };
459
+ }
460
+ var LocalStore = class {
461
+ constructor(db) {
462
+ this.db = db;
463
+ const mm = new MigrationManager(db, STORE_NAME2);
464
+ mm.register({
465
+ version: 1,
466
+ name: "create_lt_store_items",
467
+ up: (database) => {
468
+ database.exec(DDL2);
469
+ }
470
+ });
471
+ mm.migrate();
472
+ }
473
+ async put(tenantId, input) {
474
+ assertStoreIdentity(input.namespace, input.key);
475
+ const now = nowISO();
476
+ const path2 = namespacePath(input.namespace);
477
+ const existing = this.db.prepare(
478
+ `SELECT created_at FROM lt_store_items WHERE tenant_id = ? AND namespace_path = ? AND key = ?`
479
+ ).get(tenantId, path2, input.key);
480
+ const expiresAt = storeExpiresAt(input.ttlMinutes)?.toISOString() ?? null;
481
+ this.db.prepare(
482
+ `INSERT INTO lt_store_items
483
+ (tenant_id, namespace_path, key, value, created_at, updated_at, expires_at)
484
+ VALUES (?, ?, ?, ?, ?, ?, ?)
485
+ ON CONFLICT(tenant_id, namespace_path, key) DO UPDATE SET
486
+ value = excluded.value,
487
+ updated_at = excluded.updated_at,
488
+ expires_at = excluded.expires_at`
489
+ ).run(
490
+ tenantId,
491
+ path2,
492
+ input.key,
493
+ JSON.stringify(input.value),
494
+ existing?.created_at ?? now,
495
+ now,
496
+ expiresAt
497
+ );
498
+ return {
499
+ namespace: [...input.namespace],
500
+ key: input.key,
501
+ value: structuredClone(input.value),
502
+ createdAt: parseISO(existing?.created_at ?? now),
503
+ updatedAt: parseISO(now),
504
+ expiresAt: expiresAt ? parseISO(expiresAt) : void 0
505
+ };
506
+ }
507
+ async get(tenantId, namespace, key) {
508
+ assertStoreIdentity(namespace, key);
509
+ const now = nowISO();
510
+ const row = this.db.prepare(
511
+ `SELECT * FROM lt_store_items
512
+ WHERE tenant_id = ? AND namespace_path = ? AND key = ?
513
+ AND (expires_at IS NULL OR expires_at > ?)`
514
+ ).get(tenantId, namespacePath(namespace), key, now);
515
+ return row ? mapRow(row) : null;
516
+ }
517
+ async delete(tenantId, namespace, key) {
518
+ assertStoreIdentity(namespace, key);
519
+ const result = this.db.prepare(
520
+ `DELETE FROM lt_store_items WHERE tenant_id = ? AND namespace_path = ? AND key = ?`
521
+ ).run(tenantId, namespacePath(namespace), key);
522
+ return result.changes > 0;
523
+ }
524
+ async search(tenantId, input) {
525
+ const now = nowISO();
526
+ const prefix = input.namespacePrefix ?? [];
527
+ assertStoreNamespacePrefix(prefix);
528
+ const query = input.query?.toLowerCase();
529
+ const limit = storePaginationValue(input.limit, 10);
530
+ const offset = storePaginationValue(input.offset, 0);
531
+ const rows2 = this.db.prepare(
532
+ `SELECT * FROM lt_store_items
533
+ WHERE tenant_id = ? AND (expires_at IS NULL OR expires_at > ?)`
534
+ ).all(tenantId, now);
535
+ 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);
536
+ }
537
+ async listNamespaces(tenantId, prefix = [], limit = 100) {
538
+ assertStoreNamespacePrefix(prefix);
539
+ const rows2 = this.db.prepare(
540
+ `SELECT DISTINCT namespace_path FROM lt_store_items
541
+ WHERE tenant_id = ? AND (expires_at IS NULL OR expires_at > ?)`
542
+ ).all(tenantId, nowISO());
543
+ const namespaces = /* @__PURE__ */ new Map();
544
+ for (const row of rows2) {
545
+ const namespace = row.namespace_path.split(NAMESPACE_SEPARATOR);
546
+ if (hasPrefix(namespace, prefix)) namespaces.set(row.namespace_path, namespace);
547
+ }
548
+ return Array.from(namespaces.entries()).sort(([left], [right]) => left.localeCompare(right)).slice(0, storePaginationValue(limit, 100)).map(([, namespace]) => namespace);
549
+ }
550
+ async deleteExpired(now, limit) {
551
+ const rows2 = this.db.prepare(
552
+ `SELECT tenant_id, namespace_path, key FROM lt_store_items
553
+ WHERE expires_at IS NOT NULL AND expires_at <= ?
554
+ LIMIT ?`
555
+ ).all(now.toISOString(), storePaginationValue(limit, 0));
556
+ const statement = this.db.prepare(
557
+ `DELETE FROM lt_store_items WHERE tenant_id = ? AND namespace_path = ? AND key = ?`
558
+ );
559
+ let deleted = 0;
560
+ for (const row of rows2) {
561
+ deleted += statement.run(row.tenant_id, row.namespace_path, row.key).changes;
562
+ }
563
+ return deleted;
564
+ }
565
+ };
566
+
567
+ // src/stores/LocalAssistantStore.ts
568
+ var DDL3 = `
381
569
  CREATE TABLE IF NOT EXISTS lt_assistants (
382
570
  id TEXT NOT NULL,
383
571
  tenant_id TEXT NOT NULL,
@@ -393,7 +581,7 @@ CREATE TABLE IF NOT EXISTS lt_assistants (
393
581
  var LocalAssistantStore = class {
394
582
  constructor(db) {
395
583
  this.db = db;
396
- ensureTable(db, DDL2);
584
+ ensureTable(db, DDL3);
397
585
  }
398
586
  async getAllAssistants(tenantId) {
399
587
  const rows2 = this.db.prepare(
@@ -494,7 +682,7 @@ function mapRowToAssistant(row) {
494
682
  }
495
683
 
496
684
  // src/stores/LocalWorkspaceStore.ts
497
- var DDL3 = `
685
+ var DDL4 = `
498
686
  CREATE TABLE IF NOT EXISTS lt_workspaces (
499
687
  id TEXT NOT NULL,
500
688
  tenant_id TEXT NOT NULL,
@@ -509,7 +697,7 @@ CREATE TABLE IF NOT EXISTS lt_workspaces (
509
697
  var LocalWorkspaceStore = class {
510
698
  constructor(db) {
511
699
  this.db = db;
512
- ensureTable(db, DDL3);
700
+ ensureTable(db, DDL4);
513
701
  }
514
702
  async getAllWorkspaces(tenantId) {
515
703
  const rows2 = this.db.prepare(
@@ -592,7 +780,7 @@ function mapRowToWorkspace(row) {
592
780
 
593
781
  // src/stores/LocalProjectStore.ts
594
782
  import { assertGenericProjectConfig } from "@axiom-lattice/protocols";
595
- var DDL4 = `
783
+ var DDL5 = `
596
784
  CREATE TABLE IF NOT EXISTS lt_projects (
597
785
  id TEXT NOT NULL,
598
786
  tenant_id TEXT NOT NULL,
@@ -610,7 +798,7 @@ CREATE INDEX IF NOT EXISTS idx_lt_projects_workspace ON lt_projects(tenant_id, w
610
798
  var LocalProjectStore = class {
611
799
  constructor(db) {
612
800
  this.db = db;
613
- ensureTable(db, DDL4);
801
+ ensureTable(db, DDL5);
614
802
  this.ensureColumn("lt_projects", "kind", "kind TEXT DEFAULT 'business'");
615
803
  }
616
804
  async getProjectsByWorkspace(tenantId, workspaceId, filter) {
@@ -1048,7 +1236,7 @@ function isUniqueError(error) {
1048
1236
 
1049
1237
  // src/stores/LocalProjectRoomStore.ts
1050
1238
  var columns = "id, tenant_id, workspace_id, project_id, type, name, created_at, updated_at";
1051
- function mapRow(row) {
1239
+ function mapRow2(row) {
1052
1240
  const createdAt = typeof row.created_at === "string" ? new Date(row.created_at) : void 0;
1053
1241
  const updatedAt = typeof row.updated_at === "string" ? new Date(row.updated_at) : void 0;
1054
1242
  if (typeof row.id !== "string" || typeof row.tenant_id !== "string" || typeof row.workspace_id !== "string" || typeof row.project_id !== "string" || row.type !== "main" || typeof row.name !== "string" || !validDate(createdAt) || !validDate(updatedAt)) throw new Error("Invalid project room row");
@@ -1071,15 +1259,15 @@ var LocalProjectRoomStore = class {
1071
1259
  async ensureMainRoom(input) {
1072
1260
  return transaction(this.db, () => {
1073
1261
  const existing = this.getRow(input.tenantId, input.projectId);
1074
- if (existing) return mapRow(existing);
1262
+ if (existing) return mapRow2(existing);
1075
1263
  const now = timestamp();
1076
1264
  write(this.db, "INSERT INTO lt_project_rooms (id, tenant_id, workspace_id, project_id, type, name, created_at, updated_at) VALUES (?, ?, ?, ?, 'main', ?, ?, ?)", [input.id, input.tenantId, input.workspaceId, input.projectId, input.name, now, now]);
1077
- return mapRow(this.getRow(input.tenantId, input.projectId));
1265
+ return mapRow2(this.getRow(input.tenantId, input.projectId));
1078
1266
  });
1079
1267
  }
1080
1268
  async getMainRoom(tenantId, projectId) {
1081
1269
  const row = this.getRow(tenantId, projectId);
1082
- return row ? mapRow(row) : null;
1270
+ return row ? mapRow2(row) : null;
1083
1271
  }
1084
1272
  getRow(tenantId, projectId) {
1085
1273
  return this.db.prepare(`SELECT ${columns} FROM lt_project_rooms WHERE tenant_id = ? AND project_id = ? AND type = 'main'`).get(tenantId, projectId);
@@ -1103,7 +1291,7 @@ var ProjectMembershipIdConflictError = class extends Error {
1103
1291
  function role(value) {
1104
1292
  return value === "owner" || value === "admin" || value === "member" || value === "viewer";
1105
1293
  }
1106
- function mapRow2(row) {
1294
+ function mapRow3(row) {
1107
1295
  const joinedAt = typeof row.joined_at === "string" ? new Date(row.joined_at) : void 0;
1108
1296
  const updatedAt = typeof row.updated_at === "string" ? new Date(row.updated_at) : void 0;
1109
1297
  if (typeof row.id !== "string" || typeof row.tenant_id !== "string" || typeof row.project_id !== "string" || typeof row.user_id !== "string" || !role(row.role) || row.status !== "active" && row.status !== "removed" || !validDate(joinedAt) || !validDate(updatedAt)) throw new Error("Invalid project membership row");
@@ -1124,11 +1312,11 @@ var LocalProjectMembershipStore = class {
1124
1312
  ensureProjectRoomSchema(db);
1125
1313
  }
1126
1314
  async list(tenantId, projectId) {
1127
- return this.db.prepare(`SELECT ${columns2} FROM lt_project_memberships WHERE tenant_id = ? AND project_id = ? ORDER BY joined_at ASC, id ASC`).all(tenantId, projectId).map(mapRow2);
1315
+ return this.db.prepare(`SELECT ${columns2} FROM lt_project_memberships WHERE tenant_id = ? AND project_id = ? ORDER BY joined_at ASC, id ASC`).all(tenantId, projectId).map(mapRow3);
1128
1316
  }
1129
1317
  async findByUser(tenantId, projectId, userId) {
1130
1318
  const row = this.db.prepare(`SELECT ${columns2} FROM lt_project_memberships WHERE tenant_id = ? AND project_id = ? AND user_id = ?`).get(tenantId, projectId, userId);
1131
- return row ? mapRow2(row) : null;
1319
+ return row ? mapRow3(row) : null;
1132
1320
  }
1133
1321
  async create(input) {
1134
1322
  return transaction(this.db, () => {
@@ -1140,14 +1328,14 @@ var LocalProjectMembershipStore = class {
1140
1328
  if (isUniqueError(error)) throw this.classifyUnique(input.tenantId, input.id, input.projectId, input.userId);
1141
1329
  throw error;
1142
1330
  }
1143
- return mapRow2(this.byId(input.tenantId, input.id));
1331
+ return mapRow3(this.byId(input.tenantId, input.id));
1144
1332
  });
1145
1333
  }
1146
1334
  async createInitialOwner(input) {
1147
1335
  return transaction(this.db, () => {
1148
1336
  const rows2 = this.db.prepare(`SELECT ${columns2} FROM lt_project_memberships WHERE tenant_id = ? AND project_id = ?`).all(input.tenantId, input.projectId);
1149
1337
  if (rows2.length > 0) {
1150
- const existing = rows2.map(mapRow2).find((item) => item.userId === input.userId && item.role === "owner" && item.status === "active");
1338
+ const existing = rows2.map(mapRow3).find((item) => item.userId === input.userId && item.role === "owner" && item.status === "active");
1151
1339
  return existing ? { kind: "existing", membership: existing } : { kind: "already_initialized" };
1152
1340
  }
1153
1341
  if (this.byId(input.tenantId, input.id)) throw new ProjectMembershipIdConflictError();
@@ -1158,7 +1346,7 @@ var LocalProjectMembershipStore = class {
1158
1346
  if (isUniqueError(error)) throw this.classifyUnique(input.tenantId, input.id, input.projectId, input.userId);
1159
1347
  throw error;
1160
1348
  }
1161
- return { kind: "created", membership: mapRow2(this.byId(input.tenantId, input.id)) };
1349
+ return { kind: "created", membership: mapRow3(this.byId(input.tenantId, input.id)) };
1162
1350
  });
1163
1351
  }
1164
1352
  async updateRole(input) {
@@ -1171,7 +1359,7 @@ var LocalProjectMembershipStore = class {
1171
1359
  return transaction(this.db, () => {
1172
1360
  const row = this.byId(tenantId, id);
1173
1361
  if (!row) return { kind: "not_found" };
1174
- const current = mapRow2(row);
1362
+ const current = mapRow3(row);
1175
1363
  if (!validDate(expected) || current.updatedAt.getTime() !== expected.getTime()) return { kind: "conflict" };
1176
1364
  if (current.role === "owner" && current.status === "active" && (remove || nextRole !== "owner")) {
1177
1365
  const other = this.db.prepare("SELECT 1 FROM lt_project_memberships WHERE tenant_id = ? AND project_id = ? AND id <> ? AND role = 'owner' AND status = 'active'").get(tenantId, current.projectId, id);
@@ -1180,7 +1368,7 @@ var LocalProjectMembershipStore = class {
1180
1368
  const updatedAt = timestamp(row.updated_at);
1181
1369
  const changes = remove ? write(this.db, "UPDATE lt_project_memberships SET status = 'removed', updated_at = ? WHERE tenant_id = ? AND id = ? AND updated_at = ?", [updatedAt, tenantId, id, row.updated_at]) : write(this.db, "UPDATE lt_project_memberships SET role = ?, updated_at = ? WHERE tenant_id = ? AND id = ? AND updated_at = ?", [nextRole, updatedAt, tenantId, id, row.updated_at]);
1182
1370
  if (changes === 0) return { kind: "conflict" };
1183
- return { kind: remove ? "removed" : "updated", membership: mapRow2(this.byId(tenantId, id)) };
1371
+ return { kind: remove ? "removed" : "updated", membership: mapRow3(this.byId(tenantId, id)) };
1184
1372
  });
1185
1373
  }
1186
1374
  byId(tenantId, id) {
@@ -1207,7 +1395,7 @@ function isRole(value) {
1207
1395
  function isStatus(value) {
1208
1396
  return value === "active" || value === "paused" || value === "removed";
1209
1397
  }
1210
- function mapRow3(row) {
1398
+ function mapRow4(row) {
1211
1399
  const joinedAt = typeof row.joined_at === "string" ? new Date(row.joined_at) : void 0;
1212
1400
  const updatedAt = typeof row.updated_at === "string" ? new Date(row.updated_at) : void 0;
1213
1401
  if (typeof row.id !== "string" || typeof row.tenant_id !== "string" || typeof row.workspace_id !== "string" || typeof row.project_id !== "string" || typeof row.room_id !== "string" || typeof row.assistant_id !== "string" || !isRole(row.role) || typeof row.title !== "string" || row.responsibility !== null && typeof row.responsibility !== "string" || typeof row.mention_name !== "string" || !isStatus(row.status) || typeof row.room_thread_id !== "string" || !validDate(joinedAt) || !validDate(updatedAt)) throw new Error("Invalid project bot membership row");
@@ -1234,15 +1422,15 @@ var LocalProjectBotMembershipStore = class {
1234
1422
  ensureProjectRoomSchema(db);
1235
1423
  }
1236
1424
  async list(tenantId, projectId) {
1237
- return this.db.prepare(`SELECT ${columns3} FROM lt_project_bot_memberships WHERE tenant_id = ? AND project_id = ? ORDER BY joined_at ASC, id ASC`).all(tenantId, projectId).map(mapRow3);
1425
+ return this.db.prepare(`SELECT ${columns3} FROM lt_project_bot_memberships WHERE tenant_id = ? AND project_id = ? ORDER BY joined_at ASC, id ASC`).all(tenantId, projectId).map(mapRow4);
1238
1426
  }
1239
1427
  async findById(tenantId, id) {
1240
1428
  const row = this.byId(tenantId, id);
1241
- return row ? mapRow3(row) : null;
1429
+ return row ? mapRow4(row) : null;
1242
1430
  }
1243
1431
  async findByAssistant(tenantId, projectId, assistantId) {
1244
1432
  const row = this.db.prepare(`SELECT ${columns3} FROM lt_project_bot_memberships WHERE tenant_id = ? AND project_id = ? AND assistant_id = ?`).get(tenantId, projectId, assistantId);
1245
- return row ? mapRow3(row) : null;
1433
+ return row ? mapRow4(row) : null;
1246
1434
  }
1247
1435
  async save(input) {
1248
1436
  try {
@@ -1264,7 +1452,7 @@ var LocalProjectBotMembershipStore = class {
1264
1452
  if (racedConflict) return { kind: racedConflict };
1265
1453
  throw new Error("Unclassified project bot membership uniqueness conflict");
1266
1454
  }
1267
- return { kind: "created", membership: mapRow3(this.byId(input.tenantId, input.id)) };
1455
+ return { kind: "created", membership: mapRow4(this.byId(input.tenantId, input.id)) };
1268
1456
  });
1269
1457
  } catch (error) {
1270
1458
  const conflict = this.conflict(error);
@@ -1277,7 +1465,7 @@ var LocalProjectBotMembershipStore = class {
1277
1465
  return transaction(this.db, () => {
1278
1466
  const row = this.byId(input.tenantId, input.id);
1279
1467
  if (!row) return { kind: "not_found" };
1280
- const existing = mapRow3(row);
1468
+ const existing = mapRow4(row);
1281
1469
  if (!validDate(input.expectedUpdatedAt) || existing.updatedAt.getTime() !== input.expectedUpdatedAt.getTime()) return { kind: "conflict" };
1282
1470
  const candidate = { ...existing, ...input.patch };
1283
1471
  const conflict = this.preflight(candidate.tenantId, candidate.projectId, candidate.roomId, candidate.role, candidate.mentionName, candidate.status, candidate.id);
@@ -1292,7 +1480,7 @@ var LocalProjectBotMembershipStore = class {
1292
1480
  throw new Error("Unclassified project bot membership uniqueness conflict");
1293
1481
  }
1294
1482
  if (changes === 0) return { kind: "conflict" };
1295
- return { kind: "updated", membership: mapRow3(this.byId(input.tenantId, input.id)) };
1483
+ return { kind: "updated", membership: mapRow4(this.byId(input.tenantId, input.id)) };
1296
1484
  });
1297
1485
  } catch (error) {
1298
1486
  const conflict = this.conflict(error);
@@ -1307,7 +1495,7 @@ var LocalProjectBotMembershipStore = class {
1307
1495
  return this.db.prepare(`SELECT ${columns3} FROM lt_project_bot_memberships WHERE tenant_id = ? AND project_id = ? AND assistant_id = ?`).get(tenantId, projectId, assistantId);
1308
1496
  }
1309
1497
  reactivate(existing, input) {
1310
- const persisted = mapRow3(existing);
1498
+ const persisted = mapRow4(existing);
1311
1499
  const wasRemoved = persisted.status === "removed";
1312
1500
  const conflict = this.preflight(input.tenantId, input.projectId, persisted.roomId, input.role, input.mentionName, "active", persisted.id);
1313
1501
  if (conflict) return { kind: conflict };
@@ -1319,7 +1507,7 @@ var LocalProjectBotMembershipStore = class {
1319
1507
  if (racedConflict) return { kind: racedConflict };
1320
1508
  throw new Error("Unclassified project bot membership uniqueness conflict");
1321
1509
  }
1322
- return { kind: wasRemoved ? "reactivated" : "updated", membership: mapRow3(this.byId(input.tenantId, persisted.id)) };
1510
+ return { kind: wasRemoved ? "reactivated" : "updated", membership: mapRow4(this.byId(input.tenantId, persisted.id)) };
1323
1511
  }
1324
1512
  preflight(tenantId, projectId, roomId, role2, mentionName, status, excludeId) {
1325
1513
  if (status === "removed") return void 0;
@@ -1379,7 +1567,7 @@ function mention(value) {
1379
1567
  function source(value) {
1380
1568
  return value === "user" || value === "agent" || value === "task" || value === "routine" || value === "system";
1381
1569
  }
1382
- function mapRow4(row) {
1570
+ function mapRow5(row) {
1383
1571
  const mappedAuthor = author(parseJson(row.author));
1384
1572
  const content = parseJson(row.content);
1385
1573
  const rawMentions = parseJson(row.mentions);
@@ -1406,7 +1594,7 @@ function mapRowsTolerant(rows2, scope) {
1406
1594
  const messages = [];
1407
1595
  for (const row of rows2) {
1408
1596
  try {
1409
- messages.push(mapRow4(row));
1597
+ messages.push(mapRow5(row));
1410
1598
  } catch (error) {
1411
1599
  console.warn("[ProjectRoomMessageStore] Skipping invalid message row", {
1412
1600
  tenantId: scope.tenantId,
@@ -1437,7 +1625,7 @@ var LocalProjectRoomMessageStore = class {
1437
1625
  }
1438
1626
  async findById(tenantId, id) {
1439
1627
  const row = this.byId(tenantId, id);
1440
- return row ? mapRow4(row) : null;
1628
+ return row ? mapRow5(row) : null;
1441
1629
  }
1442
1630
  async countAfter(input) {
1443
1631
  if (!validDate(input.after)) throw new RangeError("Project room message count horizon date is invalid");
@@ -1475,7 +1663,7 @@ var LocalProjectRoomMessageStore = class {
1475
1663
  return transaction(this.db, () => {
1476
1664
  if (idempotent && input.idempotencyKey) {
1477
1665
  const canonical = this.byKey(input.tenantId, input.roomId, input.idempotencyKey);
1478
- if (canonical) return mapRow4(canonical);
1666
+ if (canonical) return mapRow5(canonical);
1479
1667
  }
1480
1668
  if (this.byId(input.tenantId, input.id)) throw new ProjectRoomMessageIdConflictError(input.tenantId, input.id);
1481
1669
  try {
@@ -1485,12 +1673,12 @@ var LocalProjectRoomMessageStore = class {
1485
1673
  if (this.byId(input.tenantId, input.id)) throw new ProjectRoomMessageIdConflictError(input.tenantId, input.id);
1486
1674
  if (input.idempotencyKey) {
1487
1675
  const canonical = this.byKey(input.tenantId, input.roomId, input.idempotencyKey);
1488
- if (canonical && idempotent) return mapRow4(canonical);
1676
+ if (canonical && idempotent) return mapRow5(canonical);
1489
1677
  if (canonical) throw new DuplicateProjectRoomMessageIdempotencyKeyError(input.tenantId, input.roomId, input.idempotencyKey);
1490
1678
  }
1491
1679
  throw new Error("Unclassified project room message uniqueness conflict");
1492
1680
  }
1493
- return mapRow4(this.byId(input.tenantId, input.id));
1681
+ return mapRow5(this.byId(input.tenantId, input.id));
1494
1682
  });
1495
1683
  }
1496
1684
  byId(tenantId, id) {
@@ -1503,7 +1691,7 @@ var LocalProjectRoomMessageStore = class {
1503
1691
 
1504
1692
  // src/stores/LocalProjectRoomReadStateStore.ts
1505
1693
  var columns5 = "tenant_id, room_id, user_id, last_read_at, updated_at";
1506
- function mapRow5(row) {
1694
+ function mapRow6(row) {
1507
1695
  const lastReadAt = new Date(row.last_read_at);
1508
1696
  const updatedAt = new Date(row.updated_at);
1509
1697
  if (Number.isNaN(lastReadAt.getTime()) || Number.isNaN(updatedAt.getTime())) throw new Error("Invalid project room read state row");
@@ -1518,7 +1706,7 @@ var LocalProjectRoomReadStateStore = class {
1518
1706
  /** Returns the user's read marker for a room, or null when never reported. */
1519
1707
  async get(tenantId, roomId, userId) {
1520
1708
  const row = this.byKey(tenantId, roomId, userId);
1521
- return row ? mapRow5(row) : null;
1709
+ return row ? mapRow6(row) : null;
1522
1710
  }
1523
1711
  /** Upserts the marker monotonically (an older report never regresses the horizon). */
1524
1712
  async markRead(input) {
@@ -1535,7 +1723,7 @@ var LocalProjectRoomReadStateStore = class {
1535
1723
  [input.tenantId, input.roomId, input.userId, lastReadAt.toISOString(), timestamp()]
1536
1724
  );
1537
1725
  const row = this.byKey(input.tenantId, input.roomId, input.userId);
1538
- return mapRow5(row);
1726
+ return mapRow6(row);
1539
1727
  });
1540
1728
  }
1541
1729
  byKey(tenantId, roomId, userId) {
@@ -1546,7 +1734,7 @@ var LocalProjectRoomReadStateStore = class {
1546
1734
  };
1547
1735
 
1548
1736
  // src/stores/LocalUserStore.ts
1549
- var DDL5 = `
1737
+ var DDL6 = `
1550
1738
  CREATE TABLE IF NOT EXISTS lt_users (
1551
1739
  id TEXT PRIMARY KEY,
1552
1740
  email TEXT NOT NULL,
@@ -1561,7 +1749,7 @@ CREATE UNIQUE INDEX IF NOT EXISTS idx_lt_users_email ON lt_users(email);
1561
1749
  var LocalUserStore = class {
1562
1750
  constructor(db) {
1563
1751
  this.db = db;
1564
- ensureTable(db, DDL5);
1752
+ ensureTable(db, DDL6);
1565
1753
  }
1566
1754
  async getAllUsers() {
1567
1755
  const rows2 = this.db.prepare(
@@ -1654,7 +1842,7 @@ function mapRowToUser(row) {
1654
1842
  }
1655
1843
 
1656
1844
  // src/stores/LocalTenantStore.ts
1657
- var DDL6 = `
1845
+ var DDL7 = `
1658
1846
  CREATE TABLE IF NOT EXISTS lt_tenants (
1659
1847
  id TEXT PRIMARY KEY,
1660
1848
  name TEXT NOT NULL,
@@ -1668,7 +1856,7 @@ CREATE TABLE IF NOT EXISTS lt_tenants (
1668
1856
  var LocalTenantStore = class {
1669
1857
  constructor(db) {
1670
1858
  this.db = db;
1671
- ensureTable(db, DDL6);
1859
+ ensureTable(db, DDL7);
1672
1860
  }
1673
1861
  async getAllTenants() {
1674
1862
  const rows2 = this.db.prepare(
@@ -1755,7 +1943,7 @@ function mapRowToTenant(row) {
1755
1943
  }
1756
1944
 
1757
1945
  // src/stores/LocalUserTenantLinkStore.ts
1758
- var DDL7 = `
1946
+ var DDL8 = `
1759
1947
  CREATE TABLE IF NOT EXISTS lt_user_tenant_links (
1760
1948
  user_id TEXT NOT NULL,
1761
1949
  tenant_id TEXT NOT NULL,
@@ -1770,7 +1958,7 @@ CREATE INDEX IF NOT EXISTS idx_lt_utl_tenant ON lt_user_tenant_links(tenant_id);
1770
1958
  var LocalUserTenantLinkStore = class {
1771
1959
  constructor(db) {
1772
1960
  this.db = db;
1773
- ensureTable(db, DDL7);
1961
+ ensureTable(db, DDL8);
1774
1962
  }
1775
1963
  async getTenantsByUser(userId) {
1776
1964
  const rows2 = this.db.prepare(
@@ -1854,7 +2042,7 @@ function mapRowToLink(row) {
1854
2042
 
1855
2043
  // src/stores/LocalDatabaseConfigStore.ts
1856
2044
  import { encrypt, decrypt } from "@axiom-lattice/core";
1857
- var DDL8 = `
2045
+ var DDL9 = `
1858
2046
  CREATE TABLE IF NOT EXISTS lt_database_configs (
1859
2047
  id TEXT NOT NULL,
1860
2048
  tenant_id TEXT NOT NULL,
@@ -1871,7 +2059,7 @@ CREATE UNIQUE INDEX IF NOT EXISTS idx_lt_dbconfig_key ON lt_database_configs(ten
1871
2059
  var LocalDatabaseConfigStore = class {
1872
2060
  constructor(db) {
1873
2061
  this.db = db;
1874
- ensureTable(db, DDL8);
2062
+ ensureTable(db, DDL9);
1875
2063
  }
1876
2064
  async getAllConfigs(tenantId) {
1877
2065
  const rows2 = this.db.prepare(
@@ -1994,7 +2182,7 @@ function encryptPasswordInConfig(config) {
1994
2182
  // src/stores/LocalConnectionStore.ts
1995
2183
  import { v4 as uuid } from "uuid";
1996
2184
  import { encryptConfigFields, decryptConfigFields, encrypt as encrypt2, isEncryptedValue } from "@axiom-lattice/core";
1997
- var DDL9 = `
2185
+ var DDL10 = `
1998
2186
  CREATE TABLE IF NOT EXISTS connection_configs (
1999
2187
  id TEXT NOT NULL,
2000
2188
  tenant_id TEXT NOT NULL,
@@ -2025,7 +2213,7 @@ function parseSecretFields(raw) {
2025
2213
  var LocalConnectionStore = class {
2026
2214
  constructor(db) {
2027
2215
  this.db = db;
2028
- ensureTable(db, DDL9);
2216
+ ensureTable(db, DDL10);
2029
2217
  this.ensureColumn("connection_configs", "secret_fields", "secret_fields TEXT");
2030
2218
  this.reencryptLegacySecrets();
2031
2219
  }
@@ -2167,7 +2355,7 @@ var LocalConnectionStore = class {
2167
2355
  };
2168
2356
 
2169
2357
  // src/stores/LocalMetricsServerConfigStore.ts
2170
- var DDL10 = `
2358
+ var DDL11 = `
2171
2359
  CREATE TABLE IF NOT EXISTS lt_metrics_configs (
2172
2360
  id TEXT NOT NULL,
2173
2361
  tenant_id TEXT NOT NULL,
@@ -2184,7 +2372,7 @@ CREATE UNIQUE INDEX IF NOT EXISTS idx_lt_metrics_key ON lt_metrics_configs(tenan
2184
2372
  var LocalMetricsServerConfigStore = class {
2185
2373
  constructor(db) {
2186
2374
  this.db = db;
2187
- ensureTable(db, DDL10);
2375
+ ensureTable(db, DDL11);
2188
2376
  }
2189
2377
  async getAllConfigs(tenantId) {
2190
2378
  const rows2 = this.db.prepare(
@@ -2292,7 +2480,7 @@ function mapRowToEntry2(row) {
2292
2480
 
2293
2481
  // src/stores/LocalMcpServerConfigStore.ts
2294
2482
  import { encrypt as encrypt3, safeDecrypt } from "@axiom-lattice/core";
2295
- var DDL11 = `
2483
+ var DDL12 = `
2296
2484
  CREATE TABLE IF NOT EXISTS lt_mcp_configs (
2297
2485
  id TEXT NOT NULL,
2298
2486
  tenant_id TEXT NOT NULL,
@@ -2312,7 +2500,7 @@ CREATE UNIQUE INDEX IF NOT EXISTS idx_lt_mcp_key ON lt_mcp_configs(tenant_id, ke
2312
2500
  var LocalMcpServerConfigStore = class {
2313
2501
  constructor(db) {
2314
2502
  this.db = db;
2315
- ensureTable(db, DDL11);
2503
+ ensureTable(db, DDL12);
2316
2504
  }
2317
2505
  async getAllConfigs(tenantId) {
2318
2506
  const rows2 = this.db.prepare(
@@ -2489,7 +2677,7 @@ function encryptEnvInConfig(config) {
2489
2677
 
2490
2678
  // src/stores/LocalModelProviderStore.ts
2491
2679
  import { encrypt as encrypt4, safeDecrypt as safeDecrypt2 } from "@axiom-lattice/core";
2492
- var DDL12 = `
2680
+ var DDL13 = `
2493
2681
  CREATE TABLE IF NOT EXISTS lt_model_providers (
2494
2682
  id TEXT NOT NULL,
2495
2683
  tenant_id TEXT NOT NULL,
@@ -2523,6 +2711,7 @@ CREATE TABLE IF NOT EXISTS lt_model_provider_models (
2523
2711
  upstream_created TEXT,
2524
2712
  enabled INTEGER NOT NULL DEFAULT 1,
2525
2713
  stale INTEGER NOT NULL DEFAULT 0,
2714
+ kind TEXT NOT NULL DEFAULT 'chat',
2526
2715
  raw TEXT,
2527
2716
  discovered_at TEXT NOT NULL,
2528
2717
  PRIMARY KEY (tenant_id, provider_id, model_id)
@@ -2533,7 +2722,7 @@ CREATE INDEX IF NOT EXISTS idx_lt_model_provider_models_tenant
2533
2722
  var LocalModelProviderStore = class {
2534
2723
  constructor(db) {
2535
2724
  this.db = db;
2536
- ensureTable(db, DDL12);
2725
+ ensureTable(db, DDL13);
2537
2726
  this.ensureColumn(
2538
2727
  "lt_model_providers",
2539
2728
  "api_style",
@@ -2544,6 +2733,11 @@ var LocalModelProviderStore = class {
2544
2733
  "stale",
2545
2734
  "stale INTEGER NOT NULL DEFAULT 0"
2546
2735
  );
2736
+ this.ensureColumn(
2737
+ "lt_model_provider_models",
2738
+ "kind",
2739
+ "kind TEXT NOT NULL DEFAULT 'chat'"
2740
+ );
2547
2741
  }
2548
2742
  /** Add a column if it does not exist (SQLite version compatible). */
2549
2743
  ensureColumn(table, column, ddl2) {
@@ -2706,7 +2900,7 @@ var LocalModelProviderStore = class {
2706
2900
  const current = new Map(
2707
2901
  (await this.listModels(tenantId, providerId)).map((model) => [
2708
2902
  model.modelId,
2709
- model.enabled
2903
+ model
2710
2904
  ])
2711
2905
  );
2712
2906
  const placeholders = rows2.map(() => "?").join(", ");
@@ -2718,8 +2912,8 @@ var LocalModelProviderStore = class {
2718
2912
  this.db.prepare(
2719
2913
  `INSERT INTO lt_model_provider_models (
2720
2914
  id, tenant_id, provider_id, model_id, display_name, owned_by,
2721
- upstream_created, raw, enabled, stale, discovered_at
2722
- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
2915
+ upstream_created, raw, enabled, stale, kind, discovered_at
2916
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
2723
2917
  ON CONFLICT (tenant_id, provider_id, model_id) DO UPDATE SET
2724
2918
  display_name = excluded.display_name,
2725
2919
  owned_by = excluded.owned_by,
@@ -2727,6 +2921,7 @@ var LocalModelProviderStore = class {
2727
2921
  raw = excluded.raw,
2728
2922
  enabled = excluded.enabled,
2729
2923
  stale = excluded.stale,
2924
+ kind = excluded.kind,
2730
2925
  discovered_at = excluded.discovered_at`
2731
2926
  ).run(
2732
2927
  `${providerId}:${model.id}`,
@@ -2737,8 +2932,10 @@ var LocalModelProviderStore = class {
2737
2932
  model.ownedBy || null,
2738
2933
  model.createdAt || null,
2739
2934
  model.raw === void 0 ? null : JSON.stringify(model.raw),
2740
- model.enabled ?? current.get(model.id) ?? true ? 1 : 0,
2935
+ model.enabled ?? current.get(model.id)?.enabled ?? true ? 1 : 0,
2741
2936
  model.stale ? 1 : 0,
2937
+ // Omitted means "keep the stored kind"; a new row starts as chat.
2938
+ model.kind ?? current.get(model.id)?.kind ?? "chat",
2742
2939
  now
2743
2940
  );
2744
2941
  }
@@ -2798,12 +2995,13 @@ function mapRowToModel(row) {
2798
2995
  upstreamCreatedAt: row.upstream_created ? parseISO(row.upstream_created) : void 0,
2799
2996
  enabled: row.enabled === 1,
2800
2997
  stale: row.stale === 1,
2998
+ kind: row.kind || "chat",
2801
2999
  discoveredAt: parseISO(row.discovered_at)
2802
3000
  };
2803
3001
  }
2804
3002
 
2805
3003
  // src/stores/LocalWorkflowTrackingStore.ts
2806
- var DDL13 = `
3004
+ var DDL14 = `
2807
3005
  CREATE TABLE IF NOT EXISTS lt_workflow_runs (
2808
3006
  id TEXT PRIMARY KEY,
2809
3007
  tenant_id TEXT NOT NULL,
@@ -2852,7 +3050,7 @@ ALTER TABLE lt_workflow_steps ADD COLUMN IF NOT EXISTS thread_id TEXT;
2852
3050
  var LocalWorkflowTrackingStore = class {
2853
3051
  constructor(db) {
2854
3052
  this.db = db;
2855
- ensureTable(db, DDL13);
3053
+ ensureTable(db, DDL14);
2856
3054
  }
2857
3055
  async createWorkflowRun(request) {
2858
3056
  const now = nowISO();
@@ -3143,7 +3341,7 @@ function mapRowToStep(row) {
3143
3341
 
3144
3342
  // src/stores/LocalEvalStore.ts
3145
3343
  import { randomUUID } from "crypto";
3146
- var DDL14 = `
3344
+ var DDL15 = `
3147
3345
  CREATE TABLE IF NOT EXISTS lt_eval_projects (
3148
3346
  id TEXT NOT NULL,
3149
3347
  tenant_id TEXT NOT NULL,
@@ -3253,7 +3451,7 @@ function parseOptionalJson(val) {
3253
3451
  var LocalEvalStore = class {
3254
3452
  constructor(db) {
3255
3453
  this.db = db;
3256
- ensureTable(db, DDL14);
3454
+ ensureTable(db, DDL15);
3257
3455
  this.ensureColumn("lt_eval_runs", "interrupted_cases", "interrupted_cases INTEGER NOT NULL DEFAULT 0");
3258
3456
  this.ensureColumn("lt_eval_run_results", "interrupted", "interrupted INTEGER NOT NULL DEFAULT 0");
3259
3457
  this.ensureColumn("lt_eval_cases", "interrupt_policy", "interrupt_policy TEXT");
@@ -3886,7 +4084,7 @@ function mapConflict(row) {
3886
4084
  }
3887
4085
 
3888
4086
  // src/stores/LocalChannelBindingStore.ts
3889
- var DDL15 = `
4087
+ var DDL16 = `
3890
4088
  CREATE TABLE IF NOT EXISTS lt_channel_bindings (
3891
4089
  id TEXT PRIMARY KEY,
3892
4090
  channel TEXT NOT NULL,
@@ -3908,7 +4106,7 @@ CREATE TABLE IF NOT EXISTS lt_channel_bindings (
3908
4106
  var LocalChannelBindingStore = class {
3909
4107
  constructor(db) {
3910
4108
  this.db = db;
3911
- ensureTable(db, DDL15);
4109
+ ensureTable(db, DDL16);
3912
4110
  ensureChannelBindingSubjectIndex(db);
3913
4111
  }
3914
4112
  async findById(tenantId, id) {
@@ -4088,7 +4286,7 @@ function mapRowToBinding(row) {
4088
4286
  }
4089
4287
 
4090
4288
  // src/stores/LocalChannelInstallationStore.ts
4091
- var DDL16 = `
4289
+ var DDL17 = `
4092
4290
  CREATE TABLE IF NOT EXISTS lt_channel_installations (
4093
4291
  id TEXT PRIMARY KEY,
4094
4292
  tenant_id TEXT NOT NULL,
@@ -4106,13 +4304,13 @@ CREATE INDEX IF NOT EXISTS idx_lt_ci_tenant ON lt_channel_installations(tenant_i
4106
4304
  var LocalChannelInstallationStore = class {
4107
4305
  constructor(db) {
4108
4306
  this.db = db;
4109
- ensureTable(db, DDL16);
4307
+ ensureTable(db, DDL17);
4110
4308
  }
4111
4309
  async getInstallationById(installationId) {
4112
4310
  const row = this.db.prepare(
4113
4311
  `SELECT * FROM lt_channel_installations WHERE id = ?`
4114
4312
  ).get(installationId);
4115
- return row ? mapRow6(row) : null;
4313
+ return row ? mapRow7(row) : null;
4116
4314
  }
4117
4315
  async getInstallationsByTenant(tenantId, channel) {
4118
4316
  let rows2;
@@ -4125,7 +4323,7 @@ var LocalChannelInstallationStore = class {
4125
4323
  `SELECT * FROM lt_channel_installations WHERE tenant_id = ? ORDER BY created_at DESC`
4126
4324
  ).all(tenantId);
4127
4325
  }
4128
- return rows2.map(mapRow6);
4326
+ return rows2.map(mapRow7);
4129
4327
  }
4130
4328
  async getAllInstallations(channel) {
4131
4329
  let rows2;
@@ -4138,7 +4336,7 @@ var LocalChannelInstallationStore = class {
4138
4336
  `SELECT * FROM lt_channel_installations ORDER BY created_at DESC`
4139
4337
  ).all();
4140
4338
  }
4141
- return rows2.map(mapRow6);
4339
+ return rows2.map(mapRow7);
4142
4340
  }
4143
4341
  async createInstallation(tenantId, installationId, data) {
4144
4342
  const now = nowISO();
@@ -4214,7 +4412,7 @@ var LocalChannelInstallationStore = class {
4214
4412
  return result.changes > 0;
4215
4413
  }
4216
4414
  };
4217
- function mapRow6(row) {
4415
+ function mapRow7(row) {
4218
4416
  return {
4219
4417
  id: row.id,
4220
4418
  tenantId: row.tenant_id,
@@ -4232,7 +4430,7 @@ function mapRow6(row) {
4232
4430
  // src/stores/LocalA2AApiKeyStore.ts
4233
4431
  import { encrypt as encrypt5, decrypt as decrypt2, safeDecrypt as safeDecrypt3 } from "@axiom-lattice/core";
4234
4432
  import { randomUUID as randomUUID3 } from "crypto";
4235
- var DDL17 = `
4433
+ var DDL18 = `
4236
4434
  CREATE TABLE IF NOT EXISTS lt_a2a_api_keys (
4237
4435
  id TEXT PRIMARY KEY,
4238
4436
  key_value TEXT NOT NULL,
@@ -4270,7 +4468,7 @@ function parseAssistantIds(raw) {
4270
4468
  var LocalA2AApiKeyStore = class {
4271
4469
  constructor(db) {
4272
4470
  this.db = db;
4273
- ensureTable(db, DDL17);
4471
+ ensureTable(db, DDL18);
4274
4472
  this.ensureColumn("lt_a2a_api_keys", "assistant_ids", "assistant_ids TEXT");
4275
4473
  this.ensureColumn("lt_a2a_api_keys", "grants", "grants TEXT");
4276
4474
  this.repairManagementIds();
@@ -4451,7 +4649,7 @@ function mapRowToRecord(row) {
4451
4649
 
4452
4650
  // src/stores/LocalOpenAuditStore.ts
4453
4651
  import { randomUUID as randomUUID4 } from "crypto";
4454
- var DDL18 = `
4652
+ var DDL19 = `
4455
4653
  CREATE TABLE IF NOT EXISTS lt_open_audit (
4456
4654
  id TEXT PRIMARY KEY,
4457
4655
  tenant_id TEXT NOT NULL,
@@ -4470,7 +4668,7 @@ CREATE TABLE IF NOT EXISTS lt_open_audit (
4470
4668
  var LocalOpenAuditStore = class {
4471
4669
  constructor(db) {
4472
4670
  this.db = db;
4473
- ensureTable(db, DDL18);
4671
+ ensureTable(db, DDL19);
4474
4672
  }
4475
4673
  async query(params) {
4476
4674
  const clauses = ["tenant_id = ?"];
@@ -4545,7 +4743,7 @@ import {
4545
4743
  parseTrustedRunContext
4546
4744
  } from "@axiom-lattice/protocols";
4547
4745
  import { randomUUID as randomUUID5 } from "crypto";
4548
- var DDL19 = `
4746
+ var DDL20 = `
4549
4747
  CREATE TABLE IF NOT EXISTS lt_thread_message_queue (
4550
4748
  id TEXT PRIMARY KEY,
4551
4749
  thread_id TEXT NOT NULL,
@@ -4574,7 +4772,7 @@ var LocalThreadMessageQueueStore = class {
4574
4772
  constructor(db) {
4575
4773
  this.capacityTail = Promise.resolve();
4576
4774
  this.db = db;
4577
- ensureTable(db, DDL19);
4775
+ ensureTable(db, DDL20);
4578
4776
  const columns6 = db.prepare("PRAGMA table_info(lt_thread_message_queue)").all();
4579
4777
  const names = new Set(columns6.map(({ name }) => name));
4580
4778
  if (!names.has("trusted_run_context")) {
@@ -4757,14 +4955,20 @@ var LocalThreadMessageQueueStore = class {
4757
4955
  }
4758
4956
  async getThreadsWithPendingMessages() {
4759
4957
  const rows2 = this.db.prepare(
4760
- `SELECT tenant_id, assistant_id, thread_id, workspace_id, project_id FROM lt_thread_message_queue WHERE status IN ('pending', 'processing') GROUP BY tenant_id, assistant_id, thread_id, workspace_id, project_id ORDER BY thread_id`
4958
+ `SELECT tenant_id, assistant_id, thread_id, workspace_id, project_id,
4959
+ MAX(status = 'pending') AS has_pending
4960
+ FROM lt_thread_message_queue
4961
+ WHERE status IN ('pending', 'processing')
4962
+ GROUP BY tenant_id, assistant_id, thread_id, workspace_id, project_id
4963
+ ORDER BY thread_id`
4761
4964
  ).all();
4762
4965
  return rows2.map((r) => ({
4763
4966
  tenantId: r.tenant_id,
4764
4967
  assistantId: r.assistant_id,
4765
4968
  threadId: r.thread_id,
4766
4969
  workspaceId: r.workspace_id,
4767
- projectId: r.project_id
4970
+ projectId: r.project_id,
4971
+ hasPending: r.has_pending === 1
4768
4972
  }));
4769
4973
  }
4770
4974
  async removeMessage(messageId, scope) {
@@ -4828,7 +5032,7 @@ function rowToMessage(row) {
4828
5032
  }
4829
5033
 
4830
5034
  // src/stores/LocalSkillStore.ts
4831
- var DDL20 = `
5035
+ var DDL21 = `
4832
5036
  CREATE TABLE IF NOT EXISTS lt_skills (
4833
5037
  id TEXT NOT NULL,
4834
5038
  tenant_id TEXT NOT NULL,
@@ -4847,7 +5051,7 @@ CREATE TABLE IF NOT EXISTS lt_skills (
4847
5051
  var LocalSkillStore = class {
4848
5052
  constructor(db) {
4849
5053
  this.db = db;
4850
- ensureTable(db, DDL20);
5054
+ ensureTable(db, DDL21);
4851
5055
  }
4852
5056
  async getAllSkills(tenantId, _context) {
4853
5057
  const rows2 = this.db.prepare(
@@ -4997,7 +5201,7 @@ function mapRowToSkill(row) {
4997
5201
  }
4998
5202
 
4999
5203
  // src/stores/LocalScheduleStorage.ts
5000
- var DDL21 = `
5204
+ var DDL22 = `
5001
5205
  CREATE TABLE IF NOT EXISTS lt_scheduled_tasks (
5002
5206
  task_id TEXT PRIMARY KEY,
5003
5207
  task_type TEXT NOT NULL,
@@ -5030,7 +5234,7 @@ CREATE INDEX IF NOT EXISTS idx_lt_st_tenant ON lt_scheduled_tasks(tenant_id);
5030
5234
  var LocalScheduleStorage = class {
5031
5235
  constructor(db) {
5032
5236
  this.db = db;
5033
- ensureTable(db, DDL21);
5237
+ ensureTable(db, DDL22);
5034
5238
  }
5035
5239
  async save(task) {
5036
5240
  this.db.prepare(
@@ -5362,7 +5566,7 @@ var NEXT_UPDATED_AT_SQL = `updated_at = CASE
5362
5566
  THEN strftime('%Y-%m-%dT%H:%M:%fZ', updated_at, '+0.001 seconds')
5363
5567
  ELSE ?
5364
5568
  END`;
5365
- var DDL22 = `
5569
+ var DDL23 = `
5366
5570
  CREATE TABLE IF NOT EXISTS lt_tasks (
5367
5571
  id TEXT NOT NULL,
5368
5572
  tenant_id TEXT NOT NULL,
@@ -5435,7 +5639,7 @@ function assertPage(limit, offset = 0) {
5435
5639
  var LocalTaskStore = class {
5436
5640
  constructor(db) {
5437
5641
  this.db = db;
5438
- ensureTable(db, DDL22);
5642
+ ensureTable(db, DDL23);
5439
5643
  this.ensureColumn("lt_tasks", "require_review", "require_review INTEGER DEFAULT 0");
5440
5644
  this.ensureColumn("lt_tasks", "dependencies", "dependencies TEXT");
5441
5645
  this.ensureColumn("lt_tasks", "result", "result TEXT");
@@ -6115,7 +6319,7 @@ var PROJECT_LIFECYCLE_ACTIONS = /* @__PURE__ */ new Set([
6115
6319
  "cancelled",
6116
6320
  "reassigned"
6117
6321
  ]);
6118
- var DDL23 = `
6322
+ var DDL24 = `
6119
6323
  CREATE TABLE IF NOT EXISTS lt_task_work_items (
6120
6324
  id TEXT NOT NULL,
6121
6325
  tenant_id TEXT NOT NULL,
@@ -6189,7 +6393,7 @@ function assertLifecyclePage(query) {
6189
6393
  var LocalTaskWorkItemStore = class {
6190
6394
  constructor(db) {
6191
6395
  this.db = db;
6192
- ensureTable(db, DDL23);
6396
+ ensureTable(db, DDL24);
6193
6397
  this.ensureColumn("lt_task_work_items", "workspace_id", "workspace_id TEXT");
6194
6398
  this.ensureColumn("lt_task_work_items", "project_id", "project_id TEXT");
6195
6399
  this.ensureColumn("lt_task_work_items", "event_key", "event_key TEXT");
@@ -6386,7 +6590,7 @@ var LocalTaskWorkItemStore = class {
6386
6590
 
6387
6591
  // src/stores/LocalCapabilityBundleStore.ts
6388
6592
  import { randomUUID as randomUUID7 } from "crypto";
6389
- var DDL24 = `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);`;
6593
+ var DDL25 = `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);`;
6390
6594
  var duplicateMessage = "Capability bundle key already exists for tenant";
6391
6595
  function map(row) {
6392
6596
  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() };
@@ -6407,7 +6611,7 @@ var LocalCapabilityBundleStore = class {
6407
6611
  */
6408
6612
  constructor(db) {
6409
6613
  this.db = db;
6410
- ensureTable(db, DDL24);
6614
+ ensureTable(db, DDL25);
6411
6615
  }
6412
6616
  async listByTenant(tenantId) {
6413
6617
  return this.db.prepare("SELECT * FROM lt_capability_bundles WHERE tenant_id = ? ORDER BY created_at").all(tenantId).map(map);
@@ -6482,6 +6686,7 @@ async function createLocalStoreConfig(options = {}) {
6482
6686
  const db = await initDatabase({ dbPath });
6483
6687
  return {
6484
6688
  thread: new LocalThreadStore(db),
6689
+ store: new LocalStore(db),
6485
6690
  assistant: new LocalAssistantStore(db),
6486
6691
  workspace: new LocalWorkspaceStore(db),
6487
6692
  project: new LocalProjectStore(db),
@@ -6575,6 +6780,7 @@ export {
6575
6780
  LocalProjectStore,
6576
6781
  LocalScheduleStorage,
6577
6782
  LocalSkillStore,
6783
+ LocalStore,
6578
6784
  LocalTaskStore,
6579
6785
  LocalTaskWorkItemStore,
6580
6786
  LocalTenantStore,