@axiom-lattice/local-stores 3.2.13 → 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/.turbo/turbo-build.log +10 -10
- package/CHANGELOG.md +61 -0
- package/dist/index.d.mts +20 -2
- package/dist/index.d.ts +20 -2
- package/dist/index.js +299 -108
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +287 -91
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/LocalStore.test.ts +151 -0
- package/src/__tests__/LocalThreadMessageQueueStore.test.ts +1 -0
- package/src/__tests__/LocalThreadStore.test.ts +51 -0
- package/src/createLocalStoreConfig.ts +2 -0
- package/src/index.ts +1 -0
- package/src/stores/LocalStore.ts +218 -0
- package/src/stores/LocalThreadMessageQueueStore.ts +8 -2
- package/src/stores/LocalThreadStore.ts +34 -6
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
|
-
|
|
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/
|
|
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,
|
|
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
|
|
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,
|
|
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
|
|
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,
|
|
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
|
|
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
|
|
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
|
|
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 ?
|
|
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
|
|
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(
|
|
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 ?
|
|
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
|
|
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(
|
|
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:
|
|
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 =
|
|
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:
|
|
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
|
|
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(
|
|
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 ?
|
|
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 ?
|
|
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:
|
|
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 =
|
|
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:
|
|
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 =
|
|
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:
|
|
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
|
|
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(
|
|
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 ?
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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 ?
|
|
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
|
|
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
|
|
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,
|
|
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
|
|
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,
|
|
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
|
|
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,
|
|
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
|
|
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,
|
|
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
|
|
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,
|
|
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
|
|
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,
|
|
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
|
|
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,
|
|
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
|
|
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,
|
|
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
|
|
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,
|
|
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
|
|
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,
|
|
@@ -3263,7 +3451,7 @@ function parseOptionalJson(val) {
|
|
|
3263
3451
|
var LocalEvalStore = class {
|
|
3264
3452
|
constructor(db) {
|
|
3265
3453
|
this.db = db;
|
|
3266
|
-
ensureTable(db,
|
|
3454
|
+
ensureTable(db, DDL15);
|
|
3267
3455
|
this.ensureColumn("lt_eval_runs", "interrupted_cases", "interrupted_cases INTEGER NOT NULL DEFAULT 0");
|
|
3268
3456
|
this.ensureColumn("lt_eval_run_results", "interrupted", "interrupted INTEGER NOT NULL DEFAULT 0");
|
|
3269
3457
|
this.ensureColumn("lt_eval_cases", "interrupt_policy", "interrupt_policy TEXT");
|
|
@@ -3896,7 +4084,7 @@ function mapConflict(row) {
|
|
|
3896
4084
|
}
|
|
3897
4085
|
|
|
3898
4086
|
// src/stores/LocalChannelBindingStore.ts
|
|
3899
|
-
var
|
|
4087
|
+
var DDL16 = `
|
|
3900
4088
|
CREATE TABLE IF NOT EXISTS lt_channel_bindings (
|
|
3901
4089
|
id TEXT PRIMARY KEY,
|
|
3902
4090
|
channel TEXT NOT NULL,
|
|
@@ -3918,7 +4106,7 @@ CREATE TABLE IF NOT EXISTS lt_channel_bindings (
|
|
|
3918
4106
|
var LocalChannelBindingStore = class {
|
|
3919
4107
|
constructor(db) {
|
|
3920
4108
|
this.db = db;
|
|
3921
|
-
ensureTable(db,
|
|
4109
|
+
ensureTable(db, DDL16);
|
|
3922
4110
|
ensureChannelBindingSubjectIndex(db);
|
|
3923
4111
|
}
|
|
3924
4112
|
async findById(tenantId, id) {
|
|
@@ -4098,7 +4286,7 @@ function mapRowToBinding(row) {
|
|
|
4098
4286
|
}
|
|
4099
4287
|
|
|
4100
4288
|
// src/stores/LocalChannelInstallationStore.ts
|
|
4101
|
-
var
|
|
4289
|
+
var DDL17 = `
|
|
4102
4290
|
CREATE TABLE IF NOT EXISTS lt_channel_installations (
|
|
4103
4291
|
id TEXT PRIMARY KEY,
|
|
4104
4292
|
tenant_id TEXT NOT NULL,
|
|
@@ -4116,13 +4304,13 @@ CREATE INDEX IF NOT EXISTS idx_lt_ci_tenant ON lt_channel_installations(tenant_i
|
|
|
4116
4304
|
var LocalChannelInstallationStore = class {
|
|
4117
4305
|
constructor(db) {
|
|
4118
4306
|
this.db = db;
|
|
4119
|
-
ensureTable(db,
|
|
4307
|
+
ensureTable(db, DDL17);
|
|
4120
4308
|
}
|
|
4121
4309
|
async getInstallationById(installationId) {
|
|
4122
4310
|
const row = this.db.prepare(
|
|
4123
4311
|
`SELECT * FROM lt_channel_installations WHERE id = ?`
|
|
4124
4312
|
).get(installationId);
|
|
4125
|
-
return row ?
|
|
4313
|
+
return row ? mapRow7(row) : null;
|
|
4126
4314
|
}
|
|
4127
4315
|
async getInstallationsByTenant(tenantId, channel) {
|
|
4128
4316
|
let rows2;
|
|
@@ -4135,7 +4323,7 @@ var LocalChannelInstallationStore = class {
|
|
|
4135
4323
|
`SELECT * FROM lt_channel_installations WHERE tenant_id = ? ORDER BY created_at DESC`
|
|
4136
4324
|
).all(tenantId);
|
|
4137
4325
|
}
|
|
4138
|
-
return rows2.map(
|
|
4326
|
+
return rows2.map(mapRow7);
|
|
4139
4327
|
}
|
|
4140
4328
|
async getAllInstallations(channel) {
|
|
4141
4329
|
let rows2;
|
|
@@ -4148,7 +4336,7 @@ var LocalChannelInstallationStore = class {
|
|
|
4148
4336
|
`SELECT * FROM lt_channel_installations ORDER BY created_at DESC`
|
|
4149
4337
|
).all();
|
|
4150
4338
|
}
|
|
4151
|
-
return rows2.map(
|
|
4339
|
+
return rows2.map(mapRow7);
|
|
4152
4340
|
}
|
|
4153
4341
|
async createInstallation(tenantId, installationId, data) {
|
|
4154
4342
|
const now = nowISO();
|
|
@@ -4224,7 +4412,7 @@ var LocalChannelInstallationStore = class {
|
|
|
4224
4412
|
return result.changes > 0;
|
|
4225
4413
|
}
|
|
4226
4414
|
};
|
|
4227
|
-
function
|
|
4415
|
+
function mapRow7(row) {
|
|
4228
4416
|
return {
|
|
4229
4417
|
id: row.id,
|
|
4230
4418
|
tenantId: row.tenant_id,
|
|
@@ -4242,7 +4430,7 @@ function mapRow6(row) {
|
|
|
4242
4430
|
// src/stores/LocalA2AApiKeyStore.ts
|
|
4243
4431
|
import { encrypt as encrypt5, decrypt as decrypt2, safeDecrypt as safeDecrypt3 } from "@axiom-lattice/core";
|
|
4244
4432
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
4245
|
-
var
|
|
4433
|
+
var DDL18 = `
|
|
4246
4434
|
CREATE TABLE IF NOT EXISTS lt_a2a_api_keys (
|
|
4247
4435
|
id TEXT PRIMARY KEY,
|
|
4248
4436
|
key_value TEXT NOT NULL,
|
|
@@ -4280,7 +4468,7 @@ function parseAssistantIds(raw) {
|
|
|
4280
4468
|
var LocalA2AApiKeyStore = class {
|
|
4281
4469
|
constructor(db) {
|
|
4282
4470
|
this.db = db;
|
|
4283
|
-
ensureTable(db,
|
|
4471
|
+
ensureTable(db, DDL18);
|
|
4284
4472
|
this.ensureColumn("lt_a2a_api_keys", "assistant_ids", "assistant_ids TEXT");
|
|
4285
4473
|
this.ensureColumn("lt_a2a_api_keys", "grants", "grants TEXT");
|
|
4286
4474
|
this.repairManagementIds();
|
|
@@ -4461,7 +4649,7 @@ function mapRowToRecord(row) {
|
|
|
4461
4649
|
|
|
4462
4650
|
// src/stores/LocalOpenAuditStore.ts
|
|
4463
4651
|
import { randomUUID as randomUUID4 } from "crypto";
|
|
4464
|
-
var
|
|
4652
|
+
var DDL19 = `
|
|
4465
4653
|
CREATE TABLE IF NOT EXISTS lt_open_audit (
|
|
4466
4654
|
id TEXT PRIMARY KEY,
|
|
4467
4655
|
tenant_id TEXT NOT NULL,
|
|
@@ -4480,7 +4668,7 @@ CREATE TABLE IF NOT EXISTS lt_open_audit (
|
|
|
4480
4668
|
var LocalOpenAuditStore = class {
|
|
4481
4669
|
constructor(db) {
|
|
4482
4670
|
this.db = db;
|
|
4483
|
-
ensureTable(db,
|
|
4671
|
+
ensureTable(db, DDL19);
|
|
4484
4672
|
}
|
|
4485
4673
|
async query(params) {
|
|
4486
4674
|
const clauses = ["tenant_id = ?"];
|
|
@@ -4555,7 +4743,7 @@ import {
|
|
|
4555
4743
|
parseTrustedRunContext
|
|
4556
4744
|
} from "@axiom-lattice/protocols";
|
|
4557
4745
|
import { randomUUID as randomUUID5 } from "crypto";
|
|
4558
|
-
var
|
|
4746
|
+
var DDL20 = `
|
|
4559
4747
|
CREATE TABLE IF NOT EXISTS lt_thread_message_queue (
|
|
4560
4748
|
id TEXT PRIMARY KEY,
|
|
4561
4749
|
thread_id TEXT NOT NULL,
|
|
@@ -4584,7 +4772,7 @@ var LocalThreadMessageQueueStore = class {
|
|
|
4584
4772
|
constructor(db) {
|
|
4585
4773
|
this.capacityTail = Promise.resolve();
|
|
4586
4774
|
this.db = db;
|
|
4587
|
-
ensureTable(db,
|
|
4775
|
+
ensureTable(db, DDL20);
|
|
4588
4776
|
const columns6 = db.prepare("PRAGMA table_info(lt_thread_message_queue)").all();
|
|
4589
4777
|
const names = new Set(columns6.map(({ name }) => name));
|
|
4590
4778
|
if (!names.has("trusted_run_context")) {
|
|
@@ -4767,14 +4955,20 @@ var LocalThreadMessageQueueStore = class {
|
|
|
4767
4955
|
}
|
|
4768
4956
|
async getThreadsWithPendingMessages() {
|
|
4769
4957
|
const rows2 = this.db.prepare(
|
|
4770
|
-
`SELECT tenant_id, assistant_id, thread_id, workspace_id, project_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`
|
|
4771
4964
|
).all();
|
|
4772
4965
|
return rows2.map((r) => ({
|
|
4773
4966
|
tenantId: r.tenant_id,
|
|
4774
4967
|
assistantId: r.assistant_id,
|
|
4775
4968
|
threadId: r.thread_id,
|
|
4776
4969
|
workspaceId: r.workspace_id,
|
|
4777
|
-
projectId: r.project_id
|
|
4970
|
+
projectId: r.project_id,
|
|
4971
|
+
hasPending: r.has_pending === 1
|
|
4778
4972
|
}));
|
|
4779
4973
|
}
|
|
4780
4974
|
async removeMessage(messageId, scope) {
|
|
@@ -4838,7 +5032,7 @@ function rowToMessage(row) {
|
|
|
4838
5032
|
}
|
|
4839
5033
|
|
|
4840
5034
|
// src/stores/LocalSkillStore.ts
|
|
4841
|
-
var
|
|
5035
|
+
var DDL21 = `
|
|
4842
5036
|
CREATE TABLE IF NOT EXISTS lt_skills (
|
|
4843
5037
|
id TEXT NOT NULL,
|
|
4844
5038
|
tenant_id TEXT NOT NULL,
|
|
@@ -4857,7 +5051,7 @@ CREATE TABLE IF NOT EXISTS lt_skills (
|
|
|
4857
5051
|
var LocalSkillStore = class {
|
|
4858
5052
|
constructor(db) {
|
|
4859
5053
|
this.db = db;
|
|
4860
|
-
ensureTable(db,
|
|
5054
|
+
ensureTable(db, DDL21);
|
|
4861
5055
|
}
|
|
4862
5056
|
async getAllSkills(tenantId, _context) {
|
|
4863
5057
|
const rows2 = this.db.prepare(
|
|
@@ -5007,7 +5201,7 @@ function mapRowToSkill(row) {
|
|
|
5007
5201
|
}
|
|
5008
5202
|
|
|
5009
5203
|
// src/stores/LocalScheduleStorage.ts
|
|
5010
|
-
var
|
|
5204
|
+
var DDL22 = `
|
|
5011
5205
|
CREATE TABLE IF NOT EXISTS lt_scheduled_tasks (
|
|
5012
5206
|
task_id TEXT PRIMARY KEY,
|
|
5013
5207
|
task_type TEXT NOT NULL,
|
|
@@ -5040,7 +5234,7 @@ CREATE INDEX IF NOT EXISTS idx_lt_st_tenant ON lt_scheduled_tasks(tenant_id);
|
|
|
5040
5234
|
var LocalScheduleStorage = class {
|
|
5041
5235
|
constructor(db) {
|
|
5042
5236
|
this.db = db;
|
|
5043
|
-
ensureTable(db,
|
|
5237
|
+
ensureTable(db, DDL22);
|
|
5044
5238
|
}
|
|
5045
5239
|
async save(task) {
|
|
5046
5240
|
this.db.prepare(
|
|
@@ -5372,7 +5566,7 @@ var NEXT_UPDATED_AT_SQL = `updated_at = CASE
|
|
|
5372
5566
|
THEN strftime('%Y-%m-%dT%H:%M:%fZ', updated_at, '+0.001 seconds')
|
|
5373
5567
|
ELSE ?
|
|
5374
5568
|
END`;
|
|
5375
|
-
var
|
|
5569
|
+
var DDL23 = `
|
|
5376
5570
|
CREATE TABLE IF NOT EXISTS lt_tasks (
|
|
5377
5571
|
id TEXT NOT NULL,
|
|
5378
5572
|
tenant_id TEXT NOT NULL,
|
|
@@ -5445,7 +5639,7 @@ function assertPage(limit, offset = 0) {
|
|
|
5445
5639
|
var LocalTaskStore = class {
|
|
5446
5640
|
constructor(db) {
|
|
5447
5641
|
this.db = db;
|
|
5448
|
-
ensureTable(db,
|
|
5642
|
+
ensureTable(db, DDL23);
|
|
5449
5643
|
this.ensureColumn("lt_tasks", "require_review", "require_review INTEGER DEFAULT 0");
|
|
5450
5644
|
this.ensureColumn("lt_tasks", "dependencies", "dependencies TEXT");
|
|
5451
5645
|
this.ensureColumn("lt_tasks", "result", "result TEXT");
|
|
@@ -6125,7 +6319,7 @@ var PROJECT_LIFECYCLE_ACTIONS = /* @__PURE__ */ new Set([
|
|
|
6125
6319
|
"cancelled",
|
|
6126
6320
|
"reassigned"
|
|
6127
6321
|
]);
|
|
6128
|
-
var
|
|
6322
|
+
var DDL24 = `
|
|
6129
6323
|
CREATE TABLE IF NOT EXISTS lt_task_work_items (
|
|
6130
6324
|
id TEXT NOT NULL,
|
|
6131
6325
|
tenant_id TEXT NOT NULL,
|
|
@@ -6199,7 +6393,7 @@ function assertLifecyclePage(query) {
|
|
|
6199
6393
|
var LocalTaskWorkItemStore = class {
|
|
6200
6394
|
constructor(db) {
|
|
6201
6395
|
this.db = db;
|
|
6202
|
-
ensureTable(db,
|
|
6396
|
+
ensureTable(db, DDL24);
|
|
6203
6397
|
this.ensureColumn("lt_task_work_items", "workspace_id", "workspace_id TEXT");
|
|
6204
6398
|
this.ensureColumn("lt_task_work_items", "project_id", "project_id TEXT");
|
|
6205
6399
|
this.ensureColumn("lt_task_work_items", "event_key", "event_key TEXT");
|
|
@@ -6396,7 +6590,7 @@ var LocalTaskWorkItemStore = class {
|
|
|
6396
6590
|
|
|
6397
6591
|
// src/stores/LocalCapabilityBundleStore.ts
|
|
6398
6592
|
import { randomUUID as randomUUID7 } from "crypto";
|
|
6399
|
-
var
|
|
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);`;
|
|
6400
6594
|
var duplicateMessage = "Capability bundle key already exists for tenant";
|
|
6401
6595
|
function map(row) {
|
|
6402
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() };
|
|
@@ -6417,7 +6611,7 @@ var LocalCapabilityBundleStore = class {
|
|
|
6417
6611
|
*/
|
|
6418
6612
|
constructor(db) {
|
|
6419
6613
|
this.db = db;
|
|
6420
|
-
ensureTable(db,
|
|
6614
|
+
ensureTable(db, DDL25);
|
|
6421
6615
|
}
|
|
6422
6616
|
async listByTenant(tenantId) {
|
|
6423
6617
|
return this.db.prepare("SELECT * FROM lt_capability_bundles WHERE tenant_id = ? ORDER BY created_at").all(tenantId).map(map);
|
|
@@ -6492,6 +6686,7 @@ async function createLocalStoreConfig(options = {}) {
|
|
|
6492
6686
|
const db = await initDatabase({ dbPath });
|
|
6493
6687
|
return {
|
|
6494
6688
|
thread: new LocalThreadStore(db),
|
|
6689
|
+
store: new LocalStore(db),
|
|
6495
6690
|
assistant: new LocalAssistantStore(db),
|
|
6496
6691
|
workspace: new LocalWorkspaceStore(db),
|
|
6497
6692
|
project: new LocalProjectStore(db),
|
|
@@ -6585,6 +6780,7 @@ export {
|
|
|
6585
6780
|
LocalProjectStore,
|
|
6586
6781
|
LocalScheduleStorage,
|
|
6587
6782
|
LocalSkillStore,
|
|
6783
|
+
LocalStore,
|
|
6588
6784
|
LocalTaskStore,
|
|
6589
6785
|
LocalTaskWorkItemStore,
|
|
6590
6786
|
LocalTenantStore,
|