@axiom-lattice/local-stores 3.2.13 → 4.0.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,
@@ -2534,7 +2722,7 @@ CREATE INDEX IF NOT EXISTS idx_lt_model_provider_models_tenant
2534
2722
  var LocalModelProviderStore = class {
2535
2723
  constructor(db) {
2536
2724
  this.db = db;
2537
- ensureTable(db, DDL12);
2725
+ ensureTable(db, DDL13);
2538
2726
  this.ensureColumn(
2539
2727
  "lt_model_providers",
2540
2728
  "api_style",
@@ -2813,7 +3001,7 @@ function mapRowToModel(row) {
2813
3001
  }
2814
3002
 
2815
3003
  // src/stores/LocalWorkflowTrackingStore.ts
2816
- var DDL13 = `
3004
+ var DDL14 = `
2817
3005
  CREATE TABLE IF NOT EXISTS lt_workflow_runs (
2818
3006
  id TEXT PRIMARY KEY,
2819
3007
  tenant_id TEXT NOT NULL,
@@ -2862,7 +3050,7 @@ ALTER TABLE lt_workflow_steps ADD COLUMN IF NOT EXISTS thread_id TEXT;
2862
3050
  var LocalWorkflowTrackingStore = class {
2863
3051
  constructor(db) {
2864
3052
  this.db = db;
2865
- ensureTable(db, DDL13);
3053
+ ensureTable(db, DDL14);
2866
3054
  }
2867
3055
  async createWorkflowRun(request) {
2868
3056
  const now = nowISO();
@@ -3153,7 +3341,7 @@ function mapRowToStep(row) {
3153
3341
 
3154
3342
  // src/stores/LocalEvalStore.ts
3155
3343
  import { randomUUID } from "crypto";
3156
- var DDL14 = `
3344
+ var DDL15 = `
3157
3345
  CREATE TABLE IF NOT EXISTS lt_eval_projects (
3158
3346
  id TEXT NOT NULL,
3159
3347
  tenant_id TEXT NOT NULL,
@@ -3209,6 +3397,7 @@ CREATE TABLE IF NOT EXISTS lt_eval_runs (
3209
3397
  interrupted_cases INTEGER NOT NULL DEFAULT 0,
3210
3398
  avg_score REAL NOT NULL DEFAULT 0,
3211
3399
  error TEXT,
3400
+ cancel_requested INTEGER NOT NULL DEFAULT 0,
3212
3401
  holdout INTEGER NOT NULL DEFAULT 0,
3213
3402
  env_project_id TEXT,
3214
3403
  env_workspace_id TEXT,
@@ -3263,11 +3452,12 @@ function parseOptionalJson(val) {
3263
3452
  var LocalEvalStore = class {
3264
3453
  constructor(db) {
3265
3454
  this.db = db;
3266
- ensureTable(db, DDL14);
3455
+ ensureTable(db, DDL15);
3267
3456
  this.ensureColumn("lt_eval_runs", "interrupted_cases", "interrupted_cases INTEGER NOT NULL DEFAULT 0");
3268
3457
  this.ensureColumn("lt_eval_run_results", "interrupted", "interrupted INTEGER NOT NULL DEFAULT 0");
3269
3458
  this.ensureColumn("lt_eval_cases", "interrupt_policy", "interrupt_policy TEXT");
3270
3459
  this.ensureColumn("lt_eval_runs", "task_id", "task_id TEXT");
3460
+ this.ensureColumn("lt_eval_runs", "cancel_requested", "cancel_requested INTEGER NOT NULL DEFAULT 0");
3271
3461
  this.db.exec(`
3272
3462
  UPDATE lt_eval_suites
3273
3463
  SET project_id = (
@@ -3639,6 +3829,12 @@ var LocalEvalStore = class {
3639
3829
  ).run(...vals);
3640
3830
  return this.getRunById(tenantId, id);
3641
3831
  }
3832
+ async requestCancel(tenantId, id) {
3833
+ const result = this.db.prepare(
3834
+ `UPDATE lt_eval_runs SET cancel_requested = 1 WHERE tenant_id = ? AND id = ? AND status = 'running'`
3835
+ ).run(tenantId, id);
3836
+ return result.changes > 0;
3837
+ }
3642
3838
  async deleteRun(tenantId, id) {
3643
3839
  const result = this.db.prepare(`DELETE FROM lt_eval_runs WHERE tenant_id = ? AND id = ?`).run(tenantId, id);
3644
3840
  return result.changes > 0;
@@ -3818,6 +4014,7 @@ var LocalEvalStore = class {
3818
4014
  interruptedCases: row.interrupted_cases ?? 0,
3819
4015
  avgScore: row.avg_score ?? 0,
3820
4016
  error: row.error,
4017
+ cancelRequested: Boolean(row.cancel_requested),
3821
4018
  holdout: row.holdout ? Boolean(row.holdout) : void 0,
3822
4019
  envProjectId: row.env_project_id,
3823
4020
  envWorkspaceId: row.env_workspace_id,
@@ -3896,7 +4093,7 @@ function mapConflict(row) {
3896
4093
  }
3897
4094
 
3898
4095
  // src/stores/LocalChannelBindingStore.ts
3899
- var DDL15 = `
4096
+ var DDL16 = `
3900
4097
  CREATE TABLE IF NOT EXISTS lt_channel_bindings (
3901
4098
  id TEXT PRIMARY KEY,
3902
4099
  channel TEXT NOT NULL,
@@ -3918,7 +4115,7 @@ CREATE TABLE IF NOT EXISTS lt_channel_bindings (
3918
4115
  var LocalChannelBindingStore = class {
3919
4116
  constructor(db) {
3920
4117
  this.db = db;
3921
- ensureTable(db, DDL15);
4118
+ ensureTable(db, DDL16);
3922
4119
  ensureChannelBindingSubjectIndex(db);
3923
4120
  }
3924
4121
  async findById(tenantId, id) {
@@ -4098,7 +4295,7 @@ function mapRowToBinding(row) {
4098
4295
  }
4099
4296
 
4100
4297
  // src/stores/LocalChannelInstallationStore.ts
4101
- var DDL16 = `
4298
+ var DDL17 = `
4102
4299
  CREATE TABLE IF NOT EXISTS lt_channel_installations (
4103
4300
  id TEXT PRIMARY KEY,
4104
4301
  tenant_id TEXT NOT NULL,
@@ -4116,13 +4313,13 @@ CREATE INDEX IF NOT EXISTS idx_lt_ci_tenant ON lt_channel_installations(tenant_i
4116
4313
  var LocalChannelInstallationStore = class {
4117
4314
  constructor(db) {
4118
4315
  this.db = db;
4119
- ensureTable(db, DDL16);
4316
+ ensureTable(db, DDL17);
4120
4317
  }
4121
4318
  async getInstallationById(installationId) {
4122
4319
  const row = this.db.prepare(
4123
4320
  `SELECT * FROM lt_channel_installations WHERE id = ?`
4124
4321
  ).get(installationId);
4125
- return row ? mapRow6(row) : null;
4322
+ return row ? mapRow7(row) : null;
4126
4323
  }
4127
4324
  async getInstallationsByTenant(tenantId, channel) {
4128
4325
  let rows2;
@@ -4135,7 +4332,7 @@ var LocalChannelInstallationStore = class {
4135
4332
  `SELECT * FROM lt_channel_installations WHERE tenant_id = ? ORDER BY created_at DESC`
4136
4333
  ).all(tenantId);
4137
4334
  }
4138
- return rows2.map(mapRow6);
4335
+ return rows2.map(mapRow7);
4139
4336
  }
4140
4337
  async getAllInstallations(channel) {
4141
4338
  let rows2;
@@ -4148,7 +4345,7 @@ var LocalChannelInstallationStore = class {
4148
4345
  `SELECT * FROM lt_channel_installations ORDER BY created_at DESC`
4149
4346
  ).all();
4150
4347
  }
4151
- return rows2.map(mapRow6);
4348
+ return rows2.map(mapRow7);
4152
4349
  }
4153
4350
  async createInstallation(tenantId, installationId, data) {
4154
4351
  const now = nowISO();
@@ -4224,7 +4421,7 @@ var LocalChannelInstallationStore = class {
4224
4421
  return result.changes > 0;
4225
4422
  }
4226
4423
  };
4227
- function mapRow6(row) {
4424
+ function mapRow7(row) {
4228
4425
  return {
4229
4426
  id: row.id,
4230
4427
  tenantId: row.tenant_id,
@@ -4242,7 +4439,7 @@ function mapRow6(row) {
4242
4439
  // src/stores/LocalA2AApiKeyStore.ts
4243
4440
  import { encrypt as encrypt5, decrypt as decrypt2, safeDecrypt as safeDecrypt3 } from "@axiom-lattice/core";
4244
4441
  import { randomUUID as randomUUID3 } from "crypto";
4245
- var DDL17 = `
4442
+ var DDL18 = `
4246
4443
  CREATE TABLE IF NOT EXISTS lt_a2a_api_keys (
4247
4444
  id TEXT PRIMARY KEY,
4248
4445
  key_value TEXT NOT NULL,
@@ -4280,7 +4477,7 @@ function parseAssistantIds(raw) {
4280
4477
  var LocalA2AApiKeyStore = class {
4281
4478
  constructor(db) {
4282
4479
  this.db = db;
4283
- ensureTable(db, DDL17);
4480
+ ensureTable(db, DDL18);
4284
4481
  this.ensureColumn("lt_a2a_api_keys", "assistant_ids", "assistant_ids TEXT");
4285
4482
  this.ensureColumn("lt_a2a_api_keys", "grants", "grants TEXT");
4286
4483
  this.repairManagementIds();
@@ -4461,7 +4658,7 @@ function mapRowToRecord(row) {
4461
4658
 
4462
4659
  // src/stores/LocalOpenAuditStore.ts
4463
4660
  import { randomUUID as randomUUID4 } from "crypto";
4464
- var DDL18 = `
4661
+ var DDL19 = `
4465
4662
  CREATE TABLE IF NOT EXISTS lt_open_audit (
4466
4663
  id TEXT PRIMARY KEY,
4467
4664
  tenant_id TEXT NOT NULL,
@@ -4480,7 +4677,7 @@ CREATE TABLE IF NOT EXISTS lt_open_audit (
4480
4677
  var LocalOpenAuditStore = class {
4481
4678
  constructor(db) {
4482
4679
  this.db = db;
4483
- ensureTable(db, DDL18);
4680
+ ensureTable(db, DDL19);
4484
4681
  }
4485
4682
  async query(params) {
4486
4683
  const clauses = ["tenant_id = ?"];
@@ -4555,7 +4752,7 @@ import {
4555
4752
  parseTrustedRunContext
4556
4753
  } from "@axiom-lattice/protocols";
4557
4754
  import { randomUUID as randomUUID5 } from "crypto";
4558
- var DDL19 = `
4755
+ var DDL20 = `
4559
4756
  CREATE TABLE IF NOT EXISTS lt_thread_message_queue (
4560
4757
  id TEXT PRIMARY KEY,
4561
4758
  thread_id TEXT NOT NULL,
@@ -4584,7 +4781,7 @@ var LocalThreadMessageQueueStore = class {
4584
4781
  constructor(db) {
4585
4782
  this.capacityTail = Promise.resolve();
4586
4783
  this.db = db;
4587
- ensureTable(db, DDL19);
4784
+ ensureTable(db, DDL20);
4588
4785
  const columns6 = db.prepare("PRAGMA table_info(lt_thread_message_queue)").all();
4589
4786
  const names = new Set(columns6.map(({ name }) => name));
4590
4787
  if (!names.has("trusted_run_context")) {
@@ -4767,14 +4964,20 @@ var LocalThreadMessageQueueStore = class {
4767
4964
  }
4768
4965
  async getThreadsWithPendingMessages() {
4769
4966
  const rows2 = this.db.prepare(
4770
- `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`
4967
+ `SELECT tenant_id, assistant_id, thread_id, workspace_id, project_id,
4968
+ MAX(status = 'pending') AS has_pending
4969
+ FROM lt_thread_message_queue
4970
+ WHERE status IN ('pending', 'processing')
4971
+ GROUP BY tenant_id, assistant_id, thread_id, workspace_id, project_id
4972
+ ORDER BY thread_id`
4771
4973
  ).all();
4772
4974
  return rows2.map((r) => ({
4773
4975
  tenantId: r.tenant_id,
4774
4976
  assistantId: r.assistant_id,
4775
4977
  threadId: r.thread_id,
4776
4978
  workspaceId: r.workspace_id,
4777
- projectId: r.project_id
4979
+ projectId: r.project_id,
4980
+ hasPending: r.has_pending === 1
4778
4981
  }));
4779
4982
  }
4780
4983
  async removeMessage(messageId, scope) {
@@ -4838,7 +5041,7 @@ function rowToMessage(row) {
4838
5041
  }
4839
5042
 
4840
5043
  // src/stores/LocalSkillStore.ts
4841
- var DDL20 = `
5044
+ var DDL21 = `
4842
5045
  CREATE TABLE IF NOT EXISTS lt_skills (
4843
5046
  id TEXT NOT NULL,
4844
5047
  tenant_id TEXT NOT NULL,
@@ -4857,7 +5060,7 @@ CREATE TABLE IF NOT EXISTS lt_skills (
4857
5060
  var LocalSkillStore = class {
4858
5061
  constructor(db) {
4859
5062
  this.db = db;
4860
- ensureTable(db, DDL20);
5063
+ ensureTable(db, DDL21);
4861
5064
  }
4862
5065
  async getAllSkills(tenantId, _context) {
4863
5066
  const rows2 = this.db.prepare(
@@ -5007,7 +5210,7 @@ function mapRowToSkill(row) {
5007
5210
  }
5008
5211
 
5009
5212
  // src/stores/LocalScheduleStorage.ts
5010
- var DDL21 = `
5213
+ var DDL22 = `
5011
5214
  CREATE TABLE IF NOT EXISTS lt_scheduled_tasks (
5012
5215
  task_id TEXT PRIMARY KEY,
5013
5216
  task_type TEXT NOT NULL,
@@ -5040,7 +5243,7 @@ CREATE INDEX IF NOT EXISTS idx_lt_st_tenant ON lt_scheduled_tasks(tenant_id);
5040
5243
  var LocalScheduleStorage = class {
5041
5244
  constructor(db) {
5042
5245
  this.db = db;
5043
- ensureTable(db, DDL21);
5246
+ ensureTable(db, DDL22);
5044
5247
  }
5045
5248
  async save(task) {
5046
5249
  this.db.prepare(
@@ -5372,7 +5575,7 @@ var NEXT_UPDATED_AT_SQL = `updated_at = CASE
5372
5575
  THEN strftime('%Y-%m-%dT%H:%M:%fZ', updated_at, '+0.001 seconds')
5373
5576
  ELSE ?
5374
5577
  END`;
5375
- var DDL22 = `
5578
+ var DDL23 = `
5376
5579
  CREATE TABLE IF NOT EXISTS lt_tasks (
5377
5580
  id TEXT NOT NULL,
5378
5581
  tenant_id TEXT NOT NULL,
@@ -5445,7 +5648,7 @@ function assertPage(limit, offset = 0) {
5445
5648
  var LocalTaskStore = class {
5446
5649
  constructor(db) {
5447
5650
  this.db = db;
5448
- ensureTable(db, DDL22);
5651
+ ensureTable(db, DDL23);
5449
5652
  this.ensureColumn("lt_tasks", "require_review", "require_review INTEGER DEFAULT 0");
5450
5653
  this.ensureColumn("lt_tasks", "dependencies", "dependencies TEXT");
5451
5654
  this.ensureColumn("lt_tasks", "result", "result TEXT");
@@ -5520,6 +5723,10 @@ var LocalTaskStore = class {
5520
5723
  conditions.push("priority = ?");
5521
5724
  params.push(filter.priority);
5522
5725
  }
5726
+ if (filter.threadId) {
5727
+ conditions.push("json_extract(context, '$.thread_id') = ?");
5728
+ params.push(filter.threadId);
5729
+ }
5523
5730
  if (filter.workspaceId) {
5524
5731
  conditions.push("workspace_id = ?");
5525
5732
  params.push(filter.workspaceId);
@@ -6125,7 +6332,7 @@ var PROJECT_LIFECYCLE_ACTIONS = /* @__PURE__ */ new Set([
6125
6332
  "cancelled",
6126
6333
  "reassigned"
6127
6334
  ]);
6128
- var DDL23 = `
6335
+ var DDL24 = `
6129
6336
  CREATE TABLE IF NOT EXISTS lt_task_work_items (
6130
6337
  id TEXT NOT NULL,
6131
6338
  tenant_id TEXT NOT NULL,
@@ -6199,7 +6406,7 @@ function assertLifecyclePage(query) {
6199
6406
  var LocalTaskWorkItemStore = class {
6200
6407
  constructor(db) {
6201
6408
  this.db = db;
6202
- ensureTable(db, DDL23);
6409
+ ensureTable(db, DDL24);
6203
6410
  this.ensureColumn("lt_task_work_items", "workspace_id", "workspace_id TEXT");
6204
6411
  this.ensureColumn("lt_task_work_items", "project_id", "project_id TEXT");
6205
6412
  this.ensureColumn("lt_task_work_items", "event_key", "event_key TEXT");
@@ -6396,7 +6603,7 @@ var LocalTaskWorkItemStore = class {
6396
6603
 
6397
6604
  // src/stores/LocalCapabilityBundleStore.ts
6398
6605
  import { randomUUID as randomUUID7 } from "crypto";
6399
- 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);`;
6606
+ 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);`;
6400
6607
  var duplicateMessage = "Capability bundle key already exists for tenant";
6401
6608
  function map(row) {
6402
6609
  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() };
@@ -6417,7 +6624,7 @@ var LocalCapabilityBundleStore = class {
6417
6624
  */
6418
6625
  constructor(db) {
6419
6626
  this.db = db;
6420
- ensureTable(db, DDL24);
6627
+ ensureTable(db, DDL25);
6421
6628
  }
6422
6629
  async listByTenant(tenantId) {
6423
6630
  return this.db.prepare("SELECT * FROM lt_capability_bundles WHERE tenant_id = ? ORDER BY created_at").all(tenantId).map(map);
@@ -6492,6 +6699,7 @@ async function createLocalStoreConfig(options = {}) {
6492
6699
  const db = await initDatabase({ dbPath });
6493
6700
  return {
6494
6701
  thread: new LocalThreadStore(db),
6702
+ store: new LocalStore(db),
6495
6703
  assistant: new LocalAssistantStore(db),
6496
6704
  workspace: new LocalWorkspaceStore(db),
6497
6705
  project: new LocalProjectStore(db),
@@ -6585,6 +6793,7 @@ export {
6585
6793
  LocalProjectStore,
6586
6794
  LocalScheduleStorage,
6587
6795
  LocalSkillStore,
6796
+ LocalStore,
6588
6797
  LocalTaskStore,
6589
6798
  LocalTaskWorkItemStore,
6590
6799
  LocalTenantStore,