@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.js
CHANGED
|
@@ -54,6 +54,7 @@ __export(index_exports, {
|
|
|
54
54
|
LocalProjectStore: () => LocalProjectStore,
|
|
55
55
|
LocalScheduleStorage: () => LocalScheduleStorage,
|
|
56
56
|
LocalSkillStore: () => LocalSkillStore,
|
|
57
|
+
LocalStore: () => LocalStore,
|
|
57
58
|
LocalTaskStore: () => LocalTaskStore,
|
|
58
59
|
LocalTaskWorkItemStore: () => LocalTaskWorkItemStore,
|
|
59
60
|
LocalTenantStore: () => LocalTenantStore,
|
|
@@ -359,6 +360,7 @@ CREATE TABLE IF NOT EXISTS lt_threads (
|
|
|
359
360
|
metadata TEXT DEFAULT '{}',
|
|
360
361
|
created_at TEXT NOT NULL,
|
|
361
362
|
updated_at TEXT NOT NULL,
|
|
363
|
+
expires_at TEXT,
|
|
362
364
|
PRIMARY KEY (tenant_id, id)
|
|
363
365
|
);
|
|
364
366
|
CREATE INDEX IF NOT EXISTS idx_lt_threads_assistant ON lt_threads(tenant_id, assistant_id);
|
|
@@ -375,6 +377,14 @@ var LocalThreadStore = class {
|
|
|
375
377
|
}
|
|
376
378
|
});
|
|
377
379
|
mm.migrate();
|
|
380
|
+
this.ensureColumn("expires_at", "TEXT");
|
|
381
|
+
}
|
|
382
|
+
/** Add a column if it does not exist (SQLite version compatible). */
|
|
383
|
+
ensureColumn(column, ddl2) {
|
|
384
|
+
const cols = this.db.prepare("PRAGMA table_info(lt_threads)").all();
|
|
385
|
+
if (!cols.some((c) => c.name === column)) {
|
|
386
|
+
this.db.exec(`ALTER TABLE lt_threads ADD COLUMN ${column} ${ddl2}`);
|
|
387
|
+
}
|
|
378
388
|
}
|
|
379
389
|
async getThreadsByAssistantId(tenantId, assistantId, metadataFilter) {
|
|
380
390
|
const rows2 = this.db.prepare(
|
|
@@ -400,20 +410,22 @@ var LocalThreadStore = class {
|
|
|
400
410
|
const now = nowISO();
|
|
401
411
|
const metadata = JSON.stringify(data.metadata || {});
|
|
402
412
|
this.db.prepare(
|
|
403
|
-
`INSERT INTO lt_threads (id, tenant_id, assistant_id, metadata, created_at, updated_at)
|
|
404
|
-
VALUES (?, ?, ?, ?, ?, ?)
|
|
413
|
+
`INSERT INTO lt_threads (id, tenant_id, assistant_id, metadata, created_at, updated_at, expires_at)
|
|
414
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
405
415
|
ON CONFLICT(tenant_id, id) DO UPDATE SET
|
|
406
416
|
assistant_id = excluded.assistant_id,
|
|
407
417
|
metadata = excluded.metadata,
|
|
408
|
-
updated_at = excluded.updated_at
|
|
409
|
-
|
|
418
|
+
updated_at = excluded.updated_at,
|
|
419
|
+
expires_at = excluded.expires_at`
|
|
420
|
+
).run(threadId, tenantId, assistantId, metadata, now, now, data.expiresAt?.toISOString() ?? null);
|
|
410
421
|
return {
|
|
411
422
|
id: threadId,
|
|
412
423
|
tenantId,
|
|
413
424
|
assistantId,
|
|
414
425
|
metadata: data.metadata || {},
|
|
415
426
|
createdAt: parseISO(now),
|
|
416
|
-
updatedAt: parseISO(now)
|
|
427
|
+
updatedAt: parseISO(now),
|
|
428
|
+
expiresAt: data.expiresAt
|
|
417
429
|
};
|
|
418
430
|
}
|
|
419
431
|
async updateThread(tenantId, threadId, updates) {
|
|
@@ -424,13 +436,15 @@ var LocalThreadStore = class {
|
|
|
424
436
|
...updates.metadata || {}
|
|
425
437
|
};
|
|
426
438
|
const now = nowISO();
|
|
439
|
+
const expiresAt = updates.expiresAt !== void 0 ? updates.expiresAt.toISOString() : existing.expiresAt?.toISOString() ?? null;
|
|
427
440
|
this.db.prepare(
|
|
428
|
-
`UPDATE lt_threads SET metadata = ?, updated_at = ? WHERE tenant_id = ? AND id = ?`
|
|
429
|
-
).run(JSON.stringify(updatedMetadata), now, tenantId, threadId);
|
|
441
|
+
`UPDATE lt_threads SET metadata = ?, updated_at = ?, expires_at = ? WHERE tenant_id = ? AND id = ?`
|
|
442
|
+
).run(JSON.stringify(updatedMetadata), now, expiresAt, tenantId, threadId);
|
|
430
443
|
return {
|
|
431
444
|
...existing,
|
|
432
445
|
metadata: updatedMetadata,
|
|
433
|
-
updatedAt: parseISO(now)
|
|
446
|
+
updatedAt: parseISO(now),
|
|
447
|
+
expiresAt: expiresAt ? parseISO(expiresAt) : void 0
|
|
434
448
|
};
|
|
435
449
|
}
|
|
436
450
|
async deleteThread(tenantId, threadId) {
|
|
@@ -445,6 +459,15 @@ var LocalThreadStore = class {
|
|
|
445
459
|
).get(tenantId, threadId);
|
|
446
460
|
return row !== void 0;
|
|
447
461
|
}
|
|
462
|
+
async listExpiredThreads(now, limit) {
|
|
463
|
+
const rows2 = this.db.prepare(
|
|
464
|
+
`SELECT * FROM lt_threads
|
|
465
|
+
WHERE expires_at IS NOT NULL AND expires_at <= ?
|
|
466
|
+
ORDER BY expires_at ASC
|
|
467
|
+
LIMIT ?`
|
|
468
|
+
).all(now.toISOString(), Math.max(0, limit));
|
|
469
|
+
return rows2.map(mapRowToThread);
|
|
470
|
+
}
|
|
448
471
|
};
|
|
449
472
|
function mapRowToThread(row) {
|
|
450
473
|
return {
|
|
@@ -453,12 +476,172 @@ function mapRowToThread(row) {
|
|
|
453
476
|
assistantId: row.assistant_id,
|
|
454
477
|
metadata: JSON.parse(row.metadata || "{}"),
|
|
455
478
|
createdAt: parseISO(row.created_at),
|
|
456
|
-
updatedAt: parseISO(row.updated_at)
|
|
479
|
+
updatedAt: parseISO(row.updated_at),
|
|
480
|
+
expiresAt: row.expires_at ? parseISO(row.expires_at) : void 0
|
|
457
481
|
};
|
|
458
482
|
}
|
|
459
483
|
|
|
460
|
-
// src/stores/
|
|
484
|
+
// src/stores/LocalStore.ts
|
|
485
|
+
var import_protocols = require("@axiom-lattice/protocols");
|
|
486
|
+
var STORE_NAME2 = "lt_store_items";
|
|
487
|
+
var NAMESPACE_SEPARATOR = import_protocols.STORE_IDENTITY_SEPARATOR;
|
|
461
488
|
var DDL2 = `
|
|
489
|
+
CREATE TABLE IF NOT EXISTS lt_store_items (
|
|
490
|
+
tenant_id TEXT NOT NULL,
|
|
491
|
+
namespace_path TEXT NOT NULL,
|
|
492
|
+
key TEXT NOT NULL,
|
|
493
|
+
value TEXT NOT NULL,
|
|
494
|
+
created_at TEXT NOT NULL,
|
|
495
|
+
updated_at TEXT NOT NULL,
|
|
496
|
+
expires_at TEXT,
|
|
497
|
+
PRIMARY KEY (tenant_id, namespace_path, key)
|
|
498
|
+
);
|
|
499
|
+
CREATE INDEX IF NOT EXISTS idx_lt_store_items_tenant_updated
|
|
500
|
+
ON lt_store_items(tenant_id, updated_at DESC);
|
|
501
|
+
CREATE INDEX IF NOT EXISTS idx_lt_store_items_expires
|
|
502
|
+
ON lt_store_items(expires_at) WHERE expires_at IS NOT NULL;
|
|
503
|
+
`;
|
|
504
|
+
function namespacePath(namespace) {
|
|
505
|
+
return namespace.join(NAMESPACE_SEPARATOR);
|
|
506
|
+
}
|
|
507
|
+
function isPlainObject(value) {
|
|
508
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
509
|
+
}
|
|
510
|
+
function deepContains(actual, expected) {
|
|
511
|
+
if (Array.isArray(expected)) {
|
|
512
|
+
return Array.isArray(actual) && expected.every((item) => actual.some((candidate) => deepContains(candidate, item)));
|
|
513
|
+
}
|
|
514
|
+
if (isPlainObject(expected)) {
|
|
515
|
+
if (!isPlainObject(actual)) return false;
|
|
516
|
+
return Object.entries(expected).every(([key, value]) => deepContains(actual[key], value));
|
|
517
|
+
}
|
|
518
|
+
return Object.is(actual, expected);
|
|
519
|
+
}
|
|
520
|
+
function matchesFilter(value, filter) {
|
|
521
|
+
return deepContains(value, filter);
|
|
522
|
+
}
|
|
523
|
+
function hasPrefix(namespace, prefix) {
|
|
524
|
+
return prefix.length === 0 || namespace.length >= prefix.length && prefix.every((segment, index) => namespace[index] === segment);
|
|
525
|
+
}
|
|
526
|
+
function mapRow(row) {
|
|
527
|
+
return {
|
|
528
|
+
namespace: row.namespace_path.split(NAMESPACE_SEPARATOR),
|
|
529
|
+
key: row.key,
|
|
530
|
+
value: JSON.parse(row.value),
|
|
531
|
+
createdAt: parseISO(row.created_at),
|
|
532
|
+
updatedAt: parseISO(row.updated_at),
|
|
533
|
+
expiresAt: row.expires_at ? parseISO(row.expires_at) : void 0
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
var LocalStore = class {
|
|
537
|
+
constructor(db) {
|
|
538
|
+
this.db = db;
|
|
539
|
+
const mm = new MigrationManager(db, STORE_NAME2);
|
|
540
|
+
mm.register({
|
|
541
|
+
version: 1,
|
|
542
|
+
name: "create_lt_store_items",
|
|
543
|
+
up: (database) => {
|
|
544
|
+
database.exec(DDL2);
|
|
545
|
+
}
|
|
546
|
+
});
|
|
547
|
+
mm.migrate();
|
|
548
|
+
}
|
|
549
|
+
async put(tenantId, input) {
|
|
550
|
+
(0, import_protocols.assertStoreIdentity)(input.namespace, input.key);
|
|
551
|
+
const now = nowISO();
|
|
552
|
+
const path2 = namespacePath(input.namespace);
|
|
553
|
+
const existing = this.db.prepare(
|
|
554
|
+
`SELECT created_at FROM lt_store_items WHERE tenant_id = ? AND namespace_path = ? AND key = ?`
|
|
555
|
+
).get(tenantId, path2, input.key);
|
|
556
|
+
const expiresAt = (0, import_protocols.storeExpiresAt)(input.ttlMinutes)?.toISOString() ?? null;
|
|
557
|
+
this.db.prepare(
|
|
558
|
+
`INSERT INTO lt_store_items
|
|
559
|
+
(tenant_id, namespace_path, key, value, created_at, updated_at, expires_at)
|
|
560
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
561
|
+
ON CONFLICT(tenant_id, namespace_path, key) DO UPDATE SET
|
|
562
|
+
value = excluded.value,
|
|
563
|
+
updated_at = excluded.updated_at,
|
|
564
|
+
expires_at = excluded.expires_at`
|
|
565
|
+
).run(
|
|
566
|
+
tenantId,
|
|
567
|
+
path2,
|
|
568
|
+
input.key,
|
|
569
|
+
JSON.stringify(input.value),
|
|
570
|
+
existing?.created_at ?? now,
|
|
571
|
+
now,
|
|
572
|
+
expiresAt
|
|
573
|
+
);
|
|
574
|
+
return {
|
|
575
|
+
namespace: [...input.namespace],
|
|
576
|
+
key: input.key,
|
|
577
|
+
value: structuredClone(input.value),
|
|
578
|
+
createdAt: parseISO(existing?.created_at ?? now),
|
|
579
|
+
updatedAt: parseISO(now),
|
|
580
|
+
expiresAt: expiresAt ? parseISO(expiresAt) : void 0
|
|
581
|
+
};
|
|
582
|
+
}
|
|
583
|
+
async get(tenantId, namespace, key) {
|
|
584
|
+
(0, import_protocols.assertStoreIdentity)(namespace, key);
|
|
585
|
+
const now = nowISO();
|
|
586
|
+
const row = this.db.prepare(
|
|
587
|
+
`SELECT * FROM lt_store_items
|
|
588
|
+
WHERE tenant_id = ? AND namespace_path = ? AND key = ?
|
|
589
|
+
AND (expires_at IS NULL OR expires_at > ?)`
|
|
590
|
+
).get(tenantId, namespacePath(namespace), key, now);
|
|
591
|
+
return row ? mapRow(row) : null;
|
|
592
|
+
}
|
|
593
|
+
async delete(tenantId, namespace, key) {
|
|
594
|
+
(0, import_protocols.assertStoreIdentity)(namespace, key);
|
|
595
|
+
const result = this.db.prepare(
|
|
596
|
+
`DELETE FROM lt_store_items WHERE tenant_id = ? AND namespace_path = ? AND key = ?`
|
|
597
|
+
).run(tenantId, namespacePath(namespace), key);
|
|
598
|
+
return result.changes > 0;
|
|
599
|
+
}
|
|
600
|
+
async search(tenantId, input) {
|
|
601
|
+
const now = nowISO();
|
|
602
|
+
const prefix = input.namespacePrefix ?? [];
|
|
603
|
+
(0, import_protocols.assertStoreNamespacePrefix)(prefix);
|
|
604
|
+
const query = input.query?.toLowerCase();
|
|
605
|
+
const limit = (0, import_protocols.storePaginationValue)(input.limit, 10);
|
|
606
|
+
const offset = (0, import_protocols.storePaginationValue)(input.offset, 0);
|
|
607
|
+
const rows2 = this.db.prepare(
|
|
608
|
+
`SELECT * FROM lt_store_items
|
|
609
|
+
WHERE tenant_id = ? AND (expires_at IS NULL OR expires_at > ?)`
|
|
610
|
+
).all(tenantId, now);
|
|
611
|
+
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);
|
|
612
|
+
}
|
|
613
|
+
async listNamespaces(tenantId, prefix = [], limit = 100) {
|
|
614
|
+
(0, import_protocols.assertStoreNamespacePrefix)(prefix);
|
|
615
|
+
const rows2 = this.db.prepare(
|
|
616
|
+
`SELECT DISTINCT namespace_path FROM lt_store_items
|
|
617
|
+
WHERE tenant_id = ? AND (expires_at IS NULL OR expires_at > ?)`
|
|
618
|
+
).all(tenantId, nowISO());
|
|
619
|
+
const namespaces = /* @__PURE__ */ new Map();
|
|
620
|
+
for (const row of rows2) {
|
|
621
|
+
const namespace = row.namespace_path.split(NAMESPACE_SEPARATOR);
|
|
622
|
+
if (hasPrefix(namespace, prefix)) namespaces.set(row.namespace_path, namespace);
|
|
623
|
+
}
|
|
624
|
+
return Array.from(namespaces.entries()).sort(([left], [right]) => left.localeCompare(right)).slice(0, (0, import_protocols.storePaginationValue)(limit, 100)).map(([, namespace]) => namespace);
|
|
625
|
+
}
|
|
626
|
+
async deleteExpired(now, limit) {
|
|
627
|
+
const rows2 = this.db.prepare(
|
|
628
|
+
`SELECT tenant_id, namespace_path, key FROM lt_store_items
|
|
629
|
+
WHERE expires_at IS NOT NULL AND expires_at <= ?
|
|
630
|
+
LIMIT ?`
|
|
631
|
+
).all(now.toISOString(), (0, import_protocols.storePaginationValue)(limit, 0));
|
|
632
|
+
const statement = this.db.prepare(
|
|
633
|
+
`DELETE FROM lt_store_items WHERE tenant_id = ? AND namespace_path = ? AND key = ?`
|
|
634
|
+
);
|
|
635
|
+
let deleted = 0;
|
|
636
|
+
for (const row of rows2) {
|
|
637
|
+
deleted += statement.run(row.tenant_id, row.namespace_path, row.key).changes;
|
|
638
|
+
}
|
|
639
|
+
return deleted;
|
|
640
|
+
}
|
|
641
|
+
};
|
|
642
|
+
|
|
643
|
+
// src/stores/LocalAssistantStore.ts
|
|
644
|
+
var DDL3 = `
|
|
462
645
|
CREATE TABLE IF NOT EXISTS lt_assistants (
|
|
463
646
|
id TEXT NOT NULL,
|
|
464
647
|
tenant_id TEXT NOT NULL,
|
|
@@ -474,7 +657,7 @@ CREATE TABLE IF NOT EXISTS lt_assistants (
|
|
|
474
657
|
var LocalAssistantStore = class {
|
|
475
658
|
constructor(db) {
|
|
476
659
|
this.db = db;
|
|
477
|
-
ensureTable(db,
|
|
660
|
+
ensureTable(db, DDL3);
|
|
478
661
|
}
|
|
479
662
|
async getAllAssistants(tenantId) {
|
|
480
663
|
const rows2 = this.db.prepare(
|
|
@@ -575,7 +758,7 @@ function mapRowToAssistant(row) {
|
|
|
575
758
|
}
|
|
576
759
|
|
|
577
760
|
// src/stores/LocalWorkspaceStore.ts
|
|
578
|
-
var
|
|
761
|
+
var DDL4 = `
|
|
579
762
|
CREATE TABLE IF NOT EXISTS lt_workspaces (
|
|
580
763
|
id TEXT NOT NULL,
|
|
581
764
|
tenant_id TEXT NOT NULL,
|
|
@@ -590,7 +773,7 @@ CREATE TABLE IF NOT EXISTS lt_workspaces (
|
|
|
590
773
|
var LocalWorkspaceStore = class {
|
|
591
774
|
constructor(db) {
|
|
592
775
|
this.db = db;
|
|
593
|
-
ensureTable(db,
|
|
776
|
+
ensureTable(db, DDL4);
|
|
594
777
|
}
|
|
595
778
|
async getAllWorkspaces(tenantId) {
|
|
596
779
|
const rows2 = this.db.prepare(
|
|
@@ -672,8 +855,8 @@ function mapRowToWorkspace(row) {
|
|
|
672
855
|
}
|
|
673
856
|
|
|
674
857
|
// src/stores/LocalProjectStore.ts
|
|
675
|
-
var
|
|
676
|
-
var
|
|
858
|
+
var import_protocols2 = require("@axiom-lattice/protocols");
|
|
859
|
+
var DDL5 = `
|
|
677
860
|
CREATE TABLE IF NOT EXISTS lt_projects (
|
|
678
861
|
id TEXT NOT NULL,
|
|
679
862
|
tenant_id TEXT NOT NULL,
|
|
@@ -691,7 +874,7 @@ CREATE INDEX IF NOT EXISTS idx_lt_projects_workspace ON lt_projects(tenant_id, w
|
|
|
691
874
|
var LocalProjectStore = class {
|
|
692
875
|
constructor(db) {
|
|
693
876
|
this.db = db;
|
|
694
|
-
ensureTable(db,
|
|
877
|
+
ensureTable(db, DDL5);
|
|
695
878
|
this.ensureColumn("lt_projects", "kind", "kind TEXT DEFAULT 'business'");
|
|
696
879
|
}
|
|
697
880
|
async getProjectsByWorkspace(tenantId, workspaceId, filter) {
|
|
@@ -713,7 +896,7 @@ var LocalProjectStore = class {
|
|
|
713
896
|
return row ? mapRowToProject(row) : null;
|
|
714
897
|
}
|
|
715
898
|
async createProject(tenantId, workspaceId, id, data) {
|
|
716
|
-
(0,
|
|
899
|
+
(0, import_protocols2.assertGenericProjectConfig)(data.config);
|
|
717
900
|
const now = nowISO();
|
|
718
901
|
const kind = data.kind || "business";
|
|
719
902
|
this.db.prepare(
|
|
@@ -734,7 +917,7 @@ var LocalProjectStore = class {
|
|
|
734
917
|
return await this.getProjectById(tenantId, id);
|
|
735
918
|
}
|
|
736
919
|
async updateProject(tenantId, id, updates) {
|
|
737
|
-
(0,
|
|
920
|
+
(0, import_protocols2.assertGenericProjectConfig)(updates.config);
|
|
738
921
|
const existing = await this.getProjectById(tenantId, id);
|
|
739
922
|
if (!existing) return null;
|
|
740
923
|
const setClauses = [];
|
|
@@ -1129,7 +1312,7 @@ function isUniqueError(error) {
|
|
|
1129
1312
|
|
|
1130
1313
|
// src/stores/LocalProjectRoomStore.ts
|
|
1131
1314
|
var columns = "id, tenant_id, workspace_id, project_id, type, name, created_at, updated_at";
|
|
1132
|
-
function
|
|
1315
|
+
function mapRow2(row) {
|
|
1133
1316
|
const createdAt = typeof row.created_at === "string" ? new Date(row.created_at) : void 0;
|
|
1134
1317
|
const updatedAt = typeof row.updated_at === "string" ? new Date(row.updated_at) : void 0;
|
|
1135
1318
|
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");
|
|
@@ -1152,15 +1335,15 @@ var LocalProjectRoomStore = class {
|
|
|
1152
1335
|
async ensureMainRoom(input) {
|
|
1153
1336
|
return transaction(this.db, () => {
|
|
1154
1337
|
const existing = this.getRow(input.tenantId, input.projectId);
|
|
1155
|
-
if (existing) return
|
|
1338
|
+
if (existing) return mapRow2(existing);
|
|
1156
1339
|
const now = timestamp();
|
|
1157
1340
|
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]);
|
|
1158
|
-
return
|
|
1341
|
+
return mapRow2(this.getRow(input.tenantId, input.projectId));
|
|
1159
1342
|
});
|
|
1160
1343
|
}
|
|
1161
1344
|
async getMainRoom(tenantId, projectId) {
|
|
1162
1345
|
const row = this.getRow(tenantId, projectId);
|
|
1163
|
-
return row ?
|
|
1346
|
+
return row ? mapRow2(row) : null;
|
|
1164
1347
|
}
|
|
1165
1348
|
getRow(tenantId, projectId) {
|
|
1166
1349
|
return this.db.prepare(`SELECT ${columns} FROM lt_project_rooms WHERE tenant_id = ? AND project_id = ? AND type = 'main'`).get(tenantId, projectId);
|
|
@@ -1184,7 +1367,7 @@ var ProjectMembershipIdConflictError = class extends Error {
|
|
|
1184
1367
|
function role(value) {
|
|
1185
1368
|
return value === "owner" || value === "admin" || value === "member" || value === "viewer";
|
|
1186
1369
|
}
|
|
1187
|
-
function
|
|
1370
|
+
function mapRow3(row) {
|
|
1188
1371
|
const joinedAt = typeof row.joined_at === "string" ? new Date(row.joined_at) : void 0;
|
|
1189
1372
|
const updatedAt = typeof row.updated_at === "string" ? new Date(row.updated_at) : void 0;
|
|
1190
1373
|
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");
|
|
@@ -1205,11 +1388,11 @@ var LocalProjectMembershipStore = class {
|
|
|
1205
1388
|
ensureProjectRoomSchema(db);
|
|
1206
1389
|
}
|
|
1207
1390
|
async list(tenantId, projectId) {
|
|
1208
|
-
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(
|
|
1391
|
+
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);
|
|
1209
1392
|
}
|
|
1210
1393
|
async findByUser(tenantId, projectId, userId) {
|
|
1211
1394
|
const row = this.db.prepare(`SELECT ${columns2} FROM lt_project_memberships WHERE tenant_id = ? AND project_id = ? AND user_id = ?`).get(tenantId, projectId, userId);
|
|
1212
|
-
return row ?
|
|
1395
|
+
return row ? mapRow3(row) : null;
|
|
1213
1396
|
}
|
|
1214
1397
|
async create(input) {
|
|
1215
1398
|
return transaction(this.db, () => {
|
|
@@ -1221,14 +1404,14 @@ var LocalProjectMembershipStore = class {
|
|
|
1221
1404
|
if (isUniqueError(error)) throw this.classifyUnique(input.tenantId, input.id, input.projectId, input.userId);
|
|
1222
1405
|
throw error;
|
|
1223
1406
|
}
|
|
1224
|
-
return
|
|
1407
|
+
return mapRow3(this.byId(input.tenantId, input.id));
|
|
1225
1408
|
});
|
|
1226
1409
|
}
|
|
1227
1410
|
async createInitialOwner(input) {
|
|
1228
1411
|
return transaction(this.db, () => {
|
|
1229
1412
|
const rows2 = this.db.prepare(`SELECT ${columns2} FROM lt_project_memberships WHERE tenant_id = ? AND project_id = ?`).all(input.tenantId, input.projectId);
|
|
1230
1413
|
if (rows2.length > 0) {
|
|
1231
|
-
const existing = rows2.map(
|
|
1414
|
+
const existing = rows2.map(mapRow3).find((item) => item.userId === input.userId && item.role === "owner" && item.status === "active");
|
|
1232
1415
|
return existing ? { kind: "existing", membership: existing } : { kind: "already_initialized" };
|
|
1233
1416
|
}
|
|
1234
1417
|
if (this.byId(input.tenantId, input.id)) throw new ProjectMembershipIdConflictError();
|
|
@@ -1239,7 +1422,7 @@ var LocalProjectMembershipStore = class {
|
|
|
1239
1422
|
if (isUniqueError(error)) throw this.classifyUnique(input.tenantId, input.id, input.projectId, input.userId);
|
|
1240
1423
|
throw error;
|
|
1241
1424
|
}
|
|
1242
|
-
return { kind: "created", membership:
|
|
1425
|
+
return { kind: "created", membership: mapRow3(this.byId(input.tenantId, input.id)) };
|
|
1243
1426
|
});
|
|
1244
1427
|
}
|
|
1245
1428
|
async updateRole(input) {
|
|
@@ -1252,7 +1435,7 @@ var LocalProjectMembershipStore = class {
|
|
|
1252
1435
|
return transaction(this.db, () => {
|
|
1253
1436
|
const row = this.byId(tenantId, id);
|
|
1254
1437
|
if (!row) return { kind: "not_found" };
|
|
1255
|
-
const current =
|
|
1438
|
+
const current = mapRow3(row);
|
|
1256
1439
|
if (!validDate(expected) || current.updatedAt.getTime() !== expected.getTime()) return { kind: "conflict" };
|
|
1257
1440
|
if (current.role === "owner" && current.status === "active" && (remove || nextRole !== "owner")) {
|
|
1258
1441
|
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);
|
|
@@ -1261,7 +1444,7 @@ var LocalProjectMembershipStore = class {
|
|
|
1261
1444
|
const updatedAt = timestamp(row.updated_at);
|
|
1262
1445
|
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]);
|
|
1263
1446
|
if (changes === 0) return { kind: "conflict" };
|
|
1264
|
-
return { kind: remove ? "removed" : "updated", membership:
|
|
1447
|
+
return { kind: remove ? "removed" : "updated", membership: mapRow3(this.byId(tenantId, id)) };
|
|
1265
1448
|
});
|
|
1266
1449
|
}
|
|
1267
1450
|
byId(tenantId, id) {
|
|
@@ -1288,7 +1471,7 @@ function isRole(value) {
|
|
|
1288
1471
|
function isStatus(value) {
|
|
1289
1472
|
return value === "active" || value === "paused" || value === "removed";
|
|
1290
1473
|
}
|
|
1291
|
-
function
|
|
1474
|
+
function mapRow4(row) {
|
|
1292
1475
|
const joinedAt = typeof row.joined_at === "string" ? new Date(row.joined_at) : void 0;
|
|
1293
1476
|
const updatedAt = typeof row.updated_at === "string" ? new Date(row.updated_at) : void 0;
|
|
1294
1477
|
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");
|
|
@@ -1315,15 +1498,15 @@ var LocalProjectBotMembershipStore = class {
|
|
|
1315
1498
|
ensureProjectRoomSchema(db);
|
|
1316
1499
|
}
|
|
1317
1500
|
async list(tenantId, projectId) {
|
|
1318
|
-
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(
|
|
1501
|
+
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);
|
|
1319
1502
|
}
|
|
1320
1503
|
async findById(tenantId, id) {
|
|
1321
1504
|
const row = this.byId(tenantId, id);
|
|
1322
|
-
return row ?
|
|
1505
|
+
return row ? mapRow4(row) : null;
|
|
1323
1506
|
}
|
|
1324
1507
|
async findByAssistant(tenantId, projectId, assistantId) {
|
|
1325
1508
|
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);
|
|
1326
|
-
return row ?
|
|
1509
|
+
return row ? mapRow4(row) : null;
|
|
1327
1510
|
}
|
|
1328
1511
|
async save(input) {
|
|
1329
1512
|
try {
|
|
@@ -1345,7 +1528,7 @@ var LocalProjectBotMembershipStore = class {
|
|
|
1345
1528
|
if (racedConflict) return { kind: racedConflict };
|
|
1346
1529
|
throw new Error("Unclassified project bot membership uniqueness conflict");
|
|
1347
1530
|
}
|
|
1348
|
-
return { kind: "created", membership:
|
|
1531
|
+
return { kind: "created", membership: mapRow4(this.byId(input.tenantId, input.id)) };
|
|
1349
1532
|
});
|
|
1350
1533
|
} catch (error) {
|
|
1351
1534
|
const conflict = this.conflict(error);
|
|
@@ -1358,7 +1541,7 @@ var LocalProjectBotMembershipStore = class {
|
|
|
1358
1541
|
return transaction(this.db, () => {
|
|
1359
1542
|
const row = this.byId(input.tenantId, input.id);
|
|
1360
1543
|
if (!row) return { kind: "not_found" };
|
|
1361
|
-
const existing =
|
|
1544
|
+
const existing = mapRow4(row);
|
|
1362
1545
|
if (!validDate(input.expectedUpdatedAt) || existing.updatedAt.getTime() !== input.expectedUpdatedAt.getTime()) return { kind: "conflict" };
|
|
1363
1546
|
const candidate = { ...existing, ...input.patch };
|
|
1364
1547
|
const conflict = this.preflight(candidate.tenantId, candidate.projectId, candidate.roomId, candidate.role, candidate.mentionName, candidate.status, candidate.id);
|
|
@@ -1373,7 +1556,7 @@ var LocalProjectBotMembershipStore = class {
|
|
|
1373
1556
|
throw new Error("Unclassified project bot membership uniqueness conflict");
|
|
1374
1557
|
}
|
|
1375
1558
|
if (changes === 0) return { kind: "conflict" };
|
|
1376
|
-
return { kind: "updated", membership:
|
|
1559
|
+
return { kind: "updated", membership: mapRow4(this.byId(input.tenantId, input.id)) };
|
|
1377
1560
|
});
|
|
1378
1561
|
} catch (error) {
|
|
1379
1562
|
const conflict = this.conflict(error);
|
|
@@ -1388,7 +1571,7 @@ var LocalProjectBotMembershipStore = class {
|
|
|
1388
1571
|
return this.db.prepare(`SELECT ${columns3} FROM lt_project_bot_memberships WHERE tenant_id = ? AND project_id = ? AND assistant_id = ?`).get(tenantId, projectId, assistantId);
|
|
1389
1572
|
}
|
|
1390
1573
|
reactivate(existing, input) {
|
|
1391
|
-
const persisted =
|
|
1574
|
+
const persisted = mapRow4(existing);
|
|
1392
1575
|
const wasRemoved = persisted.status === "removed";
|
|
1393
1576
|
const conflict = this.preflight(input.tenantId, input.projectId, persisted.roomId, input.role, input.mentionName, "active", persisted.id);
|
|
1394
1577
|
if (conflict) return { kind: conflict };
|
|
@@ -1400,7 +1583,7 @@ var LocalProjectBotMembershipStore = class {
|
|
|
1400
1583
|
if (racedConflict) return { kind: racedConflict };
|
|
1401
1584
|
throw new Error("Unclassified project bot membership uniqueness conflict");
|
|
1402
1585
|
}
|
|
1403
|
-
return { kind: wasRemoved ? "reactivated" : "updated", membership:
|
|
1586
|
+
return { kind: wasRemoved ? "reactivated" : "updated", membership: mapRow4(this.byId(input.tenantId, persisted.id)) };
|
|
1404
1587
|
}
|
|
1405
1588
|
preflight(tenantId, projectId, roomId, role2, mentionName, status, excludeId) {
|
|
1406
1589
|
if (status === "removed") return void 0;
|
|
@@ -1460,7 +1643,7 @@ function mention(value) {
|
|
|
1460
1643
|
function source(value) {
|
|
1461
1644
|
return value === "user" || value === "agent" || value === "task" || value === "routine" || value === "system";
|
|
1462
1645
|
}
|
|
1463
|
-
function
|
|
1646
|
+
function mapRow5(row) {
|
|
1464
1647
|
const mappedAuthor = author(parseJson(row.author));
|
|
1465
1648
|
const content = parseJson(row.content);
|
|
1466
1649
|
const rawMentions = parseJson(row.mentions);
|
|
@@ -1487,7 +1670,7 @@ function mapRowsTolerant(rows2, scope) {
|
|
|
1487
1670
|
const messages = [];
|
|
1488
1671
|
for (const row of rows2) {
|
|
1489
1672
|
try {
|
|
1490
|
-
messages.push(
|
|
1673
|
+
messages.push(mapRow5(row));
|
|
1491
1674
|
} catch (error) {
|
|
1492
1675
|
console.warn("[ProjectRoomMessageStore] Skipping invalid message row", {
|
|
1493
1676
|
tenantId: scope.tenantId,
|
|
@@ -1518,7 +1701,7 @@ var LocalProjectRoomMessageStore = class {
|
|
|
1518
1701
|
}
|
|
1519
1702
|
async findById(tenantId, id) {
|
|
1520
1703
|
const row = this.byId(tenantId, id);
|
|
1521
|
-
return row ?
|
|
1704
|
+
return row ? mapRow5(row) : null;
|
|
1522
1705
|
}
|
|
1523
1706
|
async countAfter(input) {
|
|
1524
1707
|
if (!validDate(input.after)) throw new RangeError("Project room message count horizon date is invalid");
|
|
@@ -1556,7 +1739,7 @@ var LocalProjectRoomMessageStore = class {
|
|
|
1556
1739
|
return transaction(this.db, () => {
|
|
1557
1740
|
if (idempotent && input.idempotencyKey) {
|
|
1558
1741
|
const canonical = this.byKey(input.tenantId, input.roomId, input.idempotencyKey);
|
|
1559
|
-
if (canonical) return
|
|
1742
|
+
if (canonical) return mapRow5(canonical);
|
|
1560
1743
|
}
|
|
1561
1744
|
if (this.byId(input.tenantId, input.id)) throw new ProjectRoomMessageIdConflictError(input.tenantId, input.id);
|
|
1562
1745
|
try {
|
|
@@ -1566,12 +1749,12 @@ var LocalProjectRoomMessageStore = class {
|
|
|
1566
1749
|
if (this.byId(input.tenantId, input.id)) throw new ProjectRoomMessageIdConflictError(input.tenantId, input.id);
|
|
1567
1750
|
if (input.idempotencyKey) {
|
|
1568
1751
|
const canonical = this.byKey(input.tenantId, input.roomId, input.idempotencyKey);
|
|
1569
|
-
if (canonical && idempotent) return
|
|
1752
|
+
if (canonical && idempotent) return mapRow5(canonical);
|
|
1570
1753
|
if (canonical) throw new DuplicateProjectRoomMessageIdempotencyKeyError(input.tenantId, input.roomId, input.idempotencyKey);
|
|
1571
1754
|
}
|
|
1572
1755
|
throw new Error("Unclassified project room message uniqueness conflict");
|
|
1573
1756
|
}
|
|
1574
|
-
return
|
|
1757
|
+
return mapRow5(this.byId(input.tenantId, input.id));
|
|
1575
1758
|
});
|
|
1576
1759
|
}
|
|
1577
1760
|
byId(tenantId, id) {
|
|
@@ -1584,7 +1767,7 @@ var LocalProjectRoomMessageStore = class {
|
|
|
1584
1767
|
|
|
1585
1768
|
// src/stores/LocalProjectRoomReadStateStore.ts
|
|
1586
1769
|
var columns5 = "tenant_id, room_id, user_id, last_read_at, updated_at";
|
|
1587
|
-
function
|
|
1770
|
+
function mapRow6(row) {
|
|
1588
1771
|
const lastReadAt = new Date(row.last_read_at);
|
|
1589
1772
|
const updatedAt = new Date(row.updated_at);
|
|
1590
1773
|
if (Number.isNaN(lastReadAt.getTime()) || Number.isNaN(updatedAt.getTime())) throw new Error("Invalid project room read state row");
|
|
@@ -1599,7 +1782,7 @@ var LocalProjectRoomReadStateStore = class {
|
|
|
1599
1782
|
/** Returns the user's read marker for a room, or null when never reported. */
|
|
1600
1783
|
async get(tenantId, roomId, userId) {
|
|
1601
1784
|
const row = this.byKey(tenantId, roomId, userId);
|
|
1602
|
-
return row ?
|
|
1785
|
+
return row ? mapRow6(row) : null;
|
|
1603
1786
|
}
|
|
1604
1787
|
/** Upserts the marker monotonically (an older report never regresses the horizon). */
|
|
1605
1788
|
async markRead(input) {
|
|
@@ -1616,7 +1799,7 @@ var LocalProjectRoomReadStateStore = class {
|
|
|
1616
1799
|
[input.tenantId, input.roomId, input.userId, lastReadAt.toISOString(), timestamp()]
|
|
1617
1800
|
);
|
|
1618
1801
|
const row = this.byKey(input.tenantId, input.roomId, input.userId);
|
|
1619
|
-
return
|
|
1802
|
+
return mapRow6(row);
|
|
1620
1803
|
});
|
|
1621
1804
|
}
|
|
1622
1805
|
byKey(tenantId, roomId, userId) {
|
|
@@ -1627,7 +1810,7 @@ var LocalProjectRoomReadStateStore = class {
|
|
|
1627
1810
|
};
|
|
1628
1811
|
|
|
1629
1812
|
// src/stores/LocalUserStore.ts
|
|
1630
|
-
var
|
|
1813
|
+
var DDL6 = `
|
|
1631
1814
|
CREATE TABLE IF NOT EXISTS lt_users (
|
|
1632
1815
|
id TEXT PRIMARY KEY,
|
|
1633
1816
|
email TEXT NOT NULL,
|
|
@@ -1642,7 +1825,7 @@ CREATE UNIQUE INDEX IF NOT EXISTS idx_lt_users_email ON lt_users(email);
|
|
|
1642
1825
|
var LocalUserStore = class {
|
|
1643
1826
|
constructor(db) {
|
|
1644
1827
|
this.db = db;
|
|
1645
|
-
ensureTable(db,
|
|
1828
|
+
ensureTable(db, DDL6);
|
|
1646
1829
|
}
|
|
1647
1830
|
async getAllUsers() {
|
|
1648
1831
|
const rows2 = this.db.prepare(
|
|
@@ -1735,7 +1918,7 @@ function mapRowToUser(row) {
|
|
|
1735
1918
|
}
|
|
1736
1919
|
|
|
1737
1920
|
// src/stores/LocalTenantStore.ts
|
|
1738
|
-
var
|
|
1921
|
+
var DDL7 = `
|
|
1739
1922
|
CREATE TABLE IF NOT EXISTS lt_tenants (
|
|
1740
1923
|
id TEXT PRIMARY KEY,
|
|
1741
1924
|
name TEXT NOT NULL,
|
|
@@ -1749,7 +1932,7 @@ CREATE TABLE IF NOT EXISTS lt_tenants (
|
|
|
1749
1932
|
var LocalTenantStore = class {
|
|
1750
1933
|
constructor(db) {
|
|
1751
1934
|
this.db = db;
|
|
1752
|
-
ensureTable(db,
|
|
1935
|
+
ensureTable(db, DDL7);
|
|
1753
1936
|
}
|
|
1754
1937
|
async getAllTenants() {
|
|
1755
1938
|
const rows2 = this.db.prepare(
|
|
@@ -1836,7 +2019,7 @@ function mapRowToTenant(row) {
|
|
|
1836
2019
|
}
|
|
1837
2020
|
|
|
1838
2021
|
// src/stores/LocalUserTenantLinkStore.ts
|
|
1839
|
-
var
|
|
2022
|
+
var DDL8 = `
|
|
1840
2023
|
CREATE TABLE IF NOT EXISTS lt_user_tenant_links (
|
|
1841
2024
|
user_id TEXT NOT NULL,
|
|
1842
2025
|
tenant_id TEXT NOT NULL,
|
|
@@ -1851,7 +2034,7 @@ CREATE INDEX IF NOT EXISTS idx_lt_utl_tenant ON lt_user_tenant_links(tenant_id);
|
|
|
1851
2034
|
var LocalUserTenantLinkStore = class {
|
|
1852
2035
|
constructor(db) {
|
|
1853
2036
|
this.db = db;
|
|
1854
|
-
ensureTable(db,
|
|
2037
|
+
ensureTable(db, DDL8);
|
|
1855
2038
|
}
|
|
1856
2039
|
async getTenantsByUser(userId) {
|
|
1857
2040
|
const rows2 = this.db.prepare(
|
|
@@ -1935,7 +2118,7 @@ function mapRowToLink(row) {
|
|
|
1935
2118
|
|
|
1936
2119
|
// src/stores/LocalDatabaseConfigStore.ts
|
|
1937
2120
|
var import_core = require("@axiom-lattice/core");
|
|
1938
|
-
var
|
|
2121
|
+
var DDL9 = `
|
|
1939
2122
|
CREATE TABLE IF NOT EXISTS lt_database_configs (
|
|
1940
2123
|
id TEXT NOT NULL,
|
|
1941
2124
|
tenant_id TEXT NOT NULL,
|
|
@@ -1952,7 +2135,7 @@ CREATE UNIQUE INDEX IF NOT EXISTS idx_lt_dbconfig_key ON lt_database_configs(ten
|
|
|
1952
2135
|
var LocalDatabaseConfigStore = class {
|
|
1953
2136
|
constructor(db) {
|
|
1954
2137
|
this.db = db;
|
|
1955
|
-
ensureTable(db,
|
|
2138
|
+
ensureTable(db, DDL9);
|
|
1956
2139
|
}
|
|
1957
2140
|
async getAllConfigs(tenantId) {
|
|
1958
2141
|
const rows2 = this.db.prepare(
|
|
@@ -2075,7 +2258,7 @@ function encryptPasswordInConfig(config) {
|
|
|
2075
2258
|
// src/stores/LocalConnectionStore.ts
|
|
2076
2259
|
var import_uuid = require("uuid");
|
|
2077
2260
|
var import_core2 = require("@axiom-lattice/core");
|
|
2078
|
-
var
|
|
2261
|
+
var DDL10 = `
|
|
2079
2262
|
CREATE TABLE IF NOT EXISTS connection_configs (
|
|
2080
2263
|
id TEXT NOT NULL,
|
|
2081
2264
|
tenant_id TEXT NOT NULL,
|
|
@@ -2106,7 +2289,7 @@ function parseSecretFields(raw) {
|
|
|
2106
2289
|
var LocalConnectionStore = class {
|
|
2107
2290
|
constructor(db) {
|
|
2108
2291
|
this.db = db;
|
|
2109
|
-
ensureTable(db,
|
|
2292
|
+
ensureTable(db, DDL10);
|
|
2110
2293
|
this.ensureColumn("connection_configs", "secret_fields", "secret_fields TEXT");
|
|
2111
2294
|
this.reencryptLegacySecrets();
|
|
2112
2295
|
}
|
|
@@ -2248,7 +2431,7 @@ var LocalConnectionStore = class {
|
|
|
2248
2431
|
};
|
|
2249
2432
|
|
|
2250
2433
|
// src/stores/LocalMetricsServerConfigStore.ts
|
|
2251
|
-
var
|
|
2434
|
+
var DDL11 = `
|
|
2252
2435
|
CREATE TABLE IF NOT EXISTS lt_metrics_configs (
|
|
2253
2436
|
id TEXT NOT NULL,
|
|
2254
2437
|
tenant_id TEXT NOT NULL,
|
|
@@ -2265,7 +2448,7 @@ CREATE UNIQUE INDEX IF NOT EXISTS idx_lt_metrics_key ON lt_metrics_configs(tenan
|
|
|
2265
2448
|
var LocalMetricsServerConfigStore = class {
|
|
2266
2449
|
constructor(db) {
|
|
2267
2450
|
this.db = db;
|
|
2268
|
-
ensureTable(db,
|
|
2451
|
+
ensureTable(db, DDL11);
|
|
2269
2452
|
}
|
|
2270
2453
|
async getAllConfigs(tenantId) {
|
|
2271
2454
|
const rows2 = this.db.prepare(
|
|
@@ -2373,7 +2556,7 @@ function mapRowToEntry2(row) {
|
|
|
2373
2556
|
|
|
2374
2557
|
// src/stores/LocalMcpServerConfigStore.ts
|
|
2375
2558
|
var import_core3 = require("@axiom-lattice/core");
|
|
2376
|
-
var
|
|
2559
|
+
var DDL12 = `
|
|
2377
2560
|
CREATE TABLE IF NOT EXISTS lt_mcp_configs (
|
|
2378
2561
|
id TEXT NOT NULL,
|
|
2379
2562
|
tenant_id TEXT NOT NULL,
|
|
@@ -2393,7 +2576,7 @@ CREATE UNIQUE INDEX IF NOT EXISTS idx_lt_mcp_key ON lt_mcp_configs(tenant_id, ke
|
|
|
2393
2576
|
var LocalMcpServerConfigStore = class {
|
|
2394
2577
|
constructor(db) {
|
|
2395
2578
|
this.db = db;
|
|
2396
|
-
ensureTable(db,
|
|
2579
|
+
ensureTable(db, DDL12);
|
|
2397
2580
|
}
|
|
2398
2581
|
async getAllConfigs(tenantId) {
|
|
2399
2582
|
const rows2 = this.db.prepare(
|
|
@@ -2570,7 +2753,7 @@ function encryptEnvInConfig(config) {
|
|
|
2570
2753
|
|
|
2571
2754
|
// src/stores/LocalModelProviderStore.ts
|
|
2572
2755
|
var import_core4 = require("@axiom-lattice/core");
|
|
2573
|
-
var
|
|
2756
|
+
var DDL13 = `
|
|
2574
2757
|
CREATE TABLE IF NOT EXISTS lt_model_providers (
|
|
2575
2758
|
id TEXT NOT NULL,
|
|
2576
2759
|
tenant_id TEXT NOT NULL,
|
|
@@ -2615,7 +2798,7 @@ CREATE INDEX IF NOT EXISTS idx_lt_model_provider_models_tenant
|
|
|
2615
2798
|
var LocalModelProviderStore = class {
|
|
2616
2799
|
constructor(db) {
|
|
2617
2800
|
this.db = db;
|
|
2618
|
-
ensureTable(db,
|
|
2801
|
+
ensureTable(db, DDL13);
|
|
2619
2802
|
this.ensureColumn(
|
|
2620
2803
|
"lt_model_providers",
|
|
2621
2804
|
"api_style",
|
|
@@ -2894,7 +3077,7 @@ function mapRowToModel(row) {
|
|
|
2894
3077
|
}
|
|
2895
3078
|
|
|
2896
3079
|
// src/stores/LocalWorkflowTrackingStore.ts
|
|
2897
|
-
var
|
|
3080
|
+
var DDL14 = `
|
|
2898
3081
|
CREATE TABLE IF NOT EXISTS lt_workflow_runs (
|
|
2899
3082
|
id TEXT PRIMARY KEY,
|
|
2900
3083
|
tenant_id TEXT NOT NULL,
|
|
@@ -2943,7 +3126,7 @@ ALTER TABLE lt_workflow_steps ADD COLUMN IF NOT EXISTS thread_id TEXT;
|
|
|
2943
3126
|
var LocalWorkflowTrackingStore = class {
|
|
2944
3127
|
constructor(db) {
|
|
2945
3128
|
this.db = db;
|
|
2946
|
-
ensureTable(db,
|
|
3129
|
+
ensureTable(db, DDL14);
|
|
2947
3130
|
}
|
|
2948
3131
|
async createWorkflowRun(request) {
|
|
2949
3132
|
const now = nowISO();
|
|
@@ -3234,7 +3417,7 @@ function mapRowToStep(row) {
|
|
|
3234
3417
|
|
|
3235
3418
|
// src/stores/LocalEvalStore.ts
|
|
3236
3419
|
var import_crypto = require("crypto");
|
|
3237
|
-
var
|
|
3420
|
+
var DDL15 = `
|
|
3238
3421
|
CREATE TABLE IF NOT EXISTS lt_eval_projects (
|
|
3239
3422
|
id TEXT NOT NULL,
|
|
3240
3423
|
tenant_id TEXT NOT NULL,
|
|
@@ -3344,7 +3527,7 @@ function parseOptionalJson(val) {
|
|
|
3344
3527
|
var LocalEvalStore = class {
|
|
3345
3528
|
constructor(db) {
|
|
3346
3529
|
this.db = db;
|
|
3347
|
-
ensureTable(db,
|
|
3530
|
+
ensureTable(db, DDL15);
|
|
3348
3531
|
this.ensureColumn("lt_eval_runs", "interrupted_cases", "interrupted_cases INTEGER NOT NULL DEFAULT 0");
|
|
3349
3532
|
this.ensureColumn("lt_eval_run_results", "interrupted", "interrupted INTEGER NOT NULL DEFAULT 0");
|
|
3350
3533
|
this.ensureColumn("lt_eval_cases", "interrupt_policy", "interrupt_policy TEXT");
|
|
@@ -3929,11 +4112,11 @@ var LocalEvalStore = class {
|
|
|
3929
4112
|
};
|
|
3930
4113
|
|
|
3931
4114
|
// src/stores/LocalChannelBindingStore.ts
|
|
3932
|
-
var
|
|
4115
|
+
var import_protocols4 = require("@axiom-lattice/protocols");
|
|
3933
4116
|
var import_crypto2 = require("crypto");
|
|
3934
4117
|
|
|
3935
4118
|
// src/stores/room-channel-binding-index.ts
|
|
3936
|
-
var
|
|
4119
|
+
var import_protocols3 = require("@axiom-lattice/protocols");
|
|
3937
4120
|
var UNIQUE_INDEX_SQL = `CREATE UNIQUE INDEX IF NOT EXISTS idx_lt_cb_subject_unique
|
|
3938
4121
|
ON lt_channel_bindings(channel, channel_installation_id, tenant_id, sender_id)`;
|
|
3939
4122
|
var LOOKUP_INDEX_SQL = `CREATE INDEX IF NOT EXISTS idx_lt_cb_resolve
|
|
@@ -3947,7 +4130,7 @@ function ensureChannelBindingSubjectIndex(db) {
|
|
|
3947
4130
|
HAVING COUNT(*) > 1
|
|
3948
4131
|
ORDER BY tenant_id, channel, channel_installation_id, sender_id`).all();
|
|
3949
4132
|
if (conflicts.length > 0) {
|
|
3950
|
-
throw new
|
|
4133
|
+
throw new import_protocols3.ChannelBindingMigrationConflictError(conflicts.map(mapConflict));
|
|
3951
4134
|
}
|
|
3952
4135
|
db.exec("DROP INDEX IF EXISTS idx_lt_cb_room_subject");
|
|
3953
4136
|
db.exec(UNIQUE_INDEX_SQL);
|
|
@@ -3973,7 +4156,7 @@ function mapConflict(row) {
|
|
|
3973
4156
|
}
|
|
3974
4157
|
|
|
3975
4158
|
// src/stores/LocalChannelBindingStore.ts
|
|
3976
|
-
var
|
|
4159
|
+
var DDL16 = `
|
|
3977
4160
|
CREATE TABLE IF NOT EXISTS lt_channel_bindings (
|
|
3978
4161
|
id TEXT PRIMARY KEY,
|
|
3979
4162
|
channel TEXT NOT NULL,
|
|
@@ -3995,7 +4178,7 @@ CREATE TABLE IF NOT EXISTS lt_channel_bindings (
|
|
|
3995
4178
|
var LocalChannelBindingStore = class {
|
|
3996
4179
|
constructor(db) {
|
|
3997
4180
|
this.db = db;
|
|
3998
|
-
ensureTable(db,
|
|
4181
|
+
ensureTable(db, DDL16);
|
|
3999
4182
|
ensureChannelBindingSubjectIndex(db);
|
|
4000
4183
|
}
|
|
4001
4184
|
async findById(tenantId, id) {
|
|
@@ -4045,7 +4228,7 @@ var LocalChannelBindingStore = class {
|
|
|
4045
4228
|
);
|
|
4046
4229
|
} catch (error) {
|
|
4047
4230
|
if (error instanceof Error && /UNIQUE constraint failed/.test(error.message)) {
|
|
4048
|
-
throw new
|
|
4231
|
+
throw new import_protocols4.DuplicateChannelBindingSubjectError();
|
|
4049
4232
|
}
|
|
4050
4233
|
throw error;
|
|
4051
4234
|
}
|
|
@@ -4175,7 +4358,7 @@ function mapRowToBinding(row) {
|
|
|
4175
4358
|
}
|
|
4176
4359
|
|
|
4177
4360
|
// src/stores/LocalChannelInstallationStore.ts
|
|
4178
|
-
var
|
|
4361
|
+
var DDL17 = `
|
|
4179
4362
|
CREATE TABLE IF NOT EXISTS lt_channel_installations (
|
|
4180
4363
|
id TEXT PRIMARY KEY,
|
|
4181
4364
|
tenant_id TEXT NOT NULL,
|
|
@@ -4193,13 +4376,13 @@ CREATE INDEX IF NOT EXISTS idx_lt_ci_tenant ON lt_channel_installations(tenant_i
|
|
|
4193
4376
|
var LocalChannelInstallationStore = class {
|
|
4194
4377
|
constructor(db) {
|
|
4195
4378
|
this.db = db;
|
|
4196
|
-
ensureTable(db,
|
|
4379
|
+
ensureTable(db, DDL17);
|
|
4197
4380
|
}
|
|
4198
4381
|
async getInstallationById(installationId) {
|
|
4199
4382
|
const row = this.db.prepare(
|
|
4200
4383
|
`SELECT * FROM lt_channel_installations WHERE id = ?`
|
|
4201
4384
|
).get(installationId);
|
|
4202
|
-
return row ?
|
|
4385
|
+
return row ? mapRow7(row) : null;
|
|
4203
4386
|
}
|
|
4204
4387
|
async getInstallationsByTenant(tenantId, channel) {
|
|
4205
4388
|
let rows2;
|
|
@@ -4212,7 +4395,7 @@ var LocalChannelInstallationStore = class {
|
|
|
4212
4395
|
`SELECT * FROM lt_channel_installations WHERE tenant_id = ? ORDER BY created_at DESC`
|
|
4213
4396
|
).all(tenantId);
|
|
4214
4397
|
}
|
|
4215
|
-
return rows2.map(
|
|
4398
|
+
return rows2.map(mapRow7);
|
|
4216
4399
|
}
|
|
4217
4400
|
async getAllInstallations(channel) {
|
|
4218
4401
|
let rows2;
|
|
@@ -4225,7 +4408,7 @@ var LocalChannelInstallationStore = class {
|
|
|
4225
4408
|
`SELECT * FROM lt_channel_installations ORDER BY created_at DESC`
|
|
4226
4409
|
).all();
|
|
4227
4410
|
}
|
|
4228
|
-
return rows2.map(
|
|
4411
|
+
return rows2.map(mapRow7);
|
|
4229
4412
|
}
|
|
4230
4413
|
async createInstallation(tenantId, installationId, data) {
|
|
4231
4414
|
const now = nowISO();
|
|
@@ -4301,7 +4484,7 @@ var LocalChannelInstallationStore = class {
|
|
|
4301
4484
|
return result.changes > 0;
|
|
4302
4485
|
}
|
|
4303
4486
|
};
|
|
4304
|
-
function
|
|
4487
|
+
function mapRow7(row) {
|
|
4305
4488
|
return {
|
|
4306
4489
|
id: row.id,
|
|
4307
4490
|
tenantId: row.tenant_id,
|
|
@@ -4319,7 +4502,7 @@ function mapRow6(row) {
|
|
|
4319
4502
|
// src/stores/LocalA2AApiKeyStore.ts
|
|
4320
4503
|
var import_core5 = require("@axiom-lattice/core");
|
|
4321
4504
|
var import_crypto3 = require("crypto");
|
|
4322
|
-
var
|
|
4505
|
+
var DDL18 = `
|
|
4323
4506
|
CREATE TABLE IF NOT EXISTS lt_a2a_api_keys (
|
|
4324
4507
|
id TEXT PRIMARY KEY,
|
|
4325
4508
|
key_value TEXT NOT NULL,
|
|
@@ -4357,7 +4540,7 @@ function parseAssistantIds(raw) {
|
|
|
4357
4540
|
var LocalA2AApiKeyStore = class {
|
|
4358
4541
|
constructor(db) {
|
|
4359
4542
|
this.db = db;
|
|
4360
|
-
ensureTable(db,
|
|
4543
|
+
ensureTable(db, DDL18);
|
|
4361
4544
|
this.ensureColumn("lt_a2a_api_keys", "assistant_ids", "assistant_ids TEXT");
|
|
4362
4545
|
this.ensureColumn("lt_a2a_api_keys", "grants", "grants TEXT");
|
|
4363
4546
|
this.repairManagementIds();
|
|
@@ -4538,7 +4721,7 @@ function mapRowToRecord(row) {
|
|
|
4538
4721
|
|
|
4539
4722
|
// src/stores/LocalOpenAuditStore.ts
|
|
4540
4723
|
var import_crypto4 = require("crypto");
|
|
4541
|
-
var
|
|
4724
|
+
var DDL19 = `
|
|
4542
4725
|
CREATE TABLE IF NOT EXISTS lt_open_audit (
|
|
4543
4726
|
id TEXT PRIMARY KEY,
|
|
4544
4727
|
tenant_id TEXT NOT NULL,
|
|
@@ -4557,7 +4740,7 @@ CREATE TABLE IF NOT EXISTS lt_open_audit (
|
|
|
4557
4740
|
var LocalOpenAuditStore = class {
|
|
4558
4741
|
constructor(db) {
|
|
4559
4742
|
this.db = db;
|
|
4560
|
-
ensureTable(db,
|
|
4743
|
+
ensureTable(db, DDL19);
|
|
4561
4744
|
}
|
|
4562
4745
|
async query(params) {
|
|
4563
4746
|
const clauses = ["tenant_id = ?"];
|
|
@@ -4627,9 +4810,9 @@ var LocalOpenAuditStore = class {
|
|
|
4627
4810
|
};
|
|
4628
4811
|
|
|
4629
4812
|
// src/stores/LocalThreadMessageQueueStore.ts
|
|
4630
|
-
var
|
|
4813
|
+
var import_protocols5 = require("@axiom-lattice/protocols");
|
|
4631
4814
|
var import_crypto5 = require("crypto");
|
|
4632
|
-
var
|
|
4815
|
+
var DDL20 = `
|
|
4633
4816
|
CREATE TABLE IF NOT EXISTS lt_thread_message_queue (
|
|
4634
4817
|
id TEXT PRIMARY KEY,
|
|
4635
4818
|
thread_id TEXT NOT NULL,
|
|
@@ -4658,7 +4841,7 @@ var LocalThreadMessageQueueStore = class {
|
|
|
4658
4841
|
constructor(db) {
|
|
4659
4842
|
this.capacityTail = Promise.resolve();
|
|
4660
4843
|
this.db = db;
|
|
4661
|
-
ensureTable(db,
|
|
4844
|
+
ensureTable(db, DDL20);
|
|
4662
4845
|
const columns6 = db.prepare("PRAGMA table_info(lt_thread_message_queue)").all();
|
|
4663
4846
|
const names = new Set(columns6.map(({ name }) => name));
|
|
4664
4847
|
if (!names.has("trusted_run_context")) {
|
|
@@ -4841,14 +5024,20 @@ var LocalThreadMessageQueueStore = class {
|
|
|
4841
5024
|
}
|
|
4842
5025
|
async getThreadsWithPendingMessages() {
|
|
4843
5026
|
const rows2 = this.db.prepare(
|
|
4844
|
-
`SELECT tenant_id, assistant_id, thread_id, workspace_id, project_id
|
|
5027
|
+
`SELECT tenant_id, assistant_id, thread_id, workspace_id, project_id,
|
|
5028
|
+
MAX(status = 'pending') AS has_pending
|
|
5029
|
+
FROM lt_thread_message_queue
|
|
5030
|
+
WHERE status IN ('pending', 'processing')
|
|
5031
|
+
GROUP BY tenant_id, assistant_id, thread_id, workspace_id, project_id
|
|
5032
|
+
ORDER BY thread_id`
|
|
4845
5033
|
).all();
|
|
4846
5034
|
return rows2.map((r) => ({
|
|
4847
5035
|
tenantId: r.tenant_id,
|
|
4848
5036
|
assistantId: r.assistant_id,
|
|
4849
5037
|
threadId: r.thread_id,
|
|
4850
5038
|
workspaceId: r.workspace_id,
|
|
4851
|
-
projectId: r.project_id
|
|
5039
|
+
projectId: r.project_id,
|
|
5040
|
+
hasPending: r.has_pending === 1
|
|
4852
5041
|
}));
|
|
4853
5042
|
}
|
|
4854
5043
|
async removeMessage(messageId, scope) {
|
|
@@ -4884,8 +5073,8 @@ var LocalThreadMessageQueueStore = class {
|
|
|
4884
5073
|
};
|
|
4885
5074
|
function validateQueueTrust(params) {
|
|
4886
5075
|
return {
|
|
4887
|
-
trustedRunContext: params.trusted_run_context === void 0 ? void 0 : (0,
|
|
4888
|
-
executionMode: params.execution_mode === void 0 ? void 0 : (0,
|
|
5076
|
+
trustedRunContext: params.trusted_run_context === void 0 ? void 0 : (0, import_protocols5.parseTrustedRunContext)(params.trusted_run_context),
|
|
5077
|
+
executionMode: params.execution_mode === void 0 ? void 0 : (0, import_protocols5.parseQueuedExecutionMode)(params.execution_mode)
|
|
4889
5078
|
};
|
|
4890
5079
|
}
|
|
4891
5080
|
function scopeClause(scope) {
|
|
@@ -4906,13 +5095,13 @@ function rowToMessage(row) {
|
|
|
4906
5095
|
priority: row.priority || 0,
|
|
4907
5096
|
command: row.command ? JSON.parse(row.command) : void 0,
|
|
4908
5097
|
custom_run_config: row.custom_run_config ? JSON.parse(row.custom_run_config) : void 0,
|
|
4909
|
-
trusted_run_context: row.trusted_run_context ? (0,
|
|
4910
|
-
execution_mode: row.execution_mode == null ? void 0 : (0,
|
|
5098
|
+
trusted_run_context: row.trusted_run_context ? (0, import_protocols5.parseTrustedRunContext)(JSON.parse(row.trusted_run_context)) : void 0,
|
|
5099
|
+
execution_mode: row.execution_mode == null ? void 0 : (0, import_protocols5.parseQueuedExecutionMode)(row.execution_mode)
|
|
4911
5100
|
};
|
|
4912
5101
|
}
|
|
4913
5102
|
|
|
4914
5103
|
// src/stores/LocalSkillStore.ts
|
|
4915
|
-
var
|
|
5104
|
+
var DDL21 = `
|
|
4916
5105
|
CREATE TABLE IF NOT EXISTS lt_skills (
|
|
4917
5106
|
id TEXT NOT NULL,
|
|
4918
5107
|
tenant_id TEXT NOT NULL,
|
|
@@ -4931,7 +5120,7 @@ CREATE TABLE IF NOT EXISTS lt_skills (
|
|
|
4931
5120
|
var LocalSkillStore = class {
|
|
4932
5121
|
constructor(db) {
|
|
4933
5122
|
this.db = db;
|
|
4934
|
-
ensureTable(db,
|
|
5123
|
+
ensureTable(db, DDL21);
|
|
4935
5124
|
}
|
|
4936
5125
|
async getAllSkills(tenantId, _context) {
|
|
4937
5126
|
const rows2 = this.db.prepare(
|
|
@@ -5081,7 +5270,7 @@ function mapRowToSkill(row) {
|
|
|
5081
5270
|
}
|
|
5082
5271
|
|
|
5083
5272
|
// src/stores/LocalScheduleStorage.ts
|
|
5084
|
-
var
|
|
5273
|
+
var DDL22 = `
|
|
5085
5274
|
CREATE TABLE IF NOT EXISTS lt_scheduled_tasks (
|
|
5086
5275
|
task_id TEXT PRIMARY KEY,
|
|
5087
5276
|
task_type TEXT NOT NULL,
|
|
@@ -5114,7 +5303,7 @@ CREATE INDEX IF NOT EXISTS idx_lt_st_tenant ON lt_scheduled_tasks(tenant_id);
|
|
|
5114
5303
|
var LocalScheduleStorage = class {
|
|
5115
5304
|
constructor(db) {
|
|
5116
5305
|
this.db = db;
|
|
5117
|
-
ensureTable(db,
|
|
5306
|
+
ensureTable(db, DDL22);
|
|
5118
5307
|
}
|
|
5119
5308
|
async save(task) {
|
|
5120
5309
|
this.db.prepare(
|
|
@@ -5429,7 +5618,7 @@ function mapRowToTask(row) {
|
|
|
5429
5618
|
}
|
|
5430
5619
|
|
|
5431
5620
|
// src/stores/LocalTaskStore.ts
|
|
5432
|
-
var
|
|
5621
|
+
var import_protocols6 = require("@axiom-lattice/protocols");
|
|
5433
5622
|
var import_crypto6 = require("crypto");
|
|
5434
5623
|
var MAX_CANONICAL_TASK_TIME = "9999-12-31T23:59:59.999Z";
|
|
5435
5624
|
var TASK_STATUSES = /* @__PURE__ */ new Set([
|
|
@@ -5446,7 +5635,7 @@ var NEXT_UPDATED_AT_SQL = `updated_at = CASE
|
|
|
5446
5635
|
THEN strftime('%Y-%m-%dT%H:%M:%fZ', updated_at, '+0.001 seconds')
|
|
5447
5636
|
ELSE ?
|
|
5448
5637
|
END`;
|
|
5449
|
-
var
|
|
5638
|
+
var DDL23 = `
|
|
5450
5639
|
CREATE TABLE IF NOT EXISTS lt_tasks (
|
|
5451
5640
|
id TEXT NOT NULL,
|
|
5452
5641
|
tenant_id TEXT NOT NULL,
|
|
@@ -5519,7 +5708,7 @@ function assertPage(limit, offset = 0) {
|
|
|
5519
5708
|
var LocalTaskStore = class {
|
|
5520
5709
|
constructor(db) {
|
|
5521
5710
|
this.db = db;
|
|
5522
|
-
ensureTable(db,
|
|
5711
|
+
ensureTable(db, DDL23);
|
|
5523
5712
|
this.ensureColumn("lt_tasks", "require_review", "require_review INTEGER DEFAULT 0");
|
|
5524
5713
|
this.ensureColumn("lt_tasks", "dependencies", "dependencies TEXT");
|
|
5525
5714
|
this.ensureColumn("lt_tasks", "result", "result TEXT");
|
|
@@ -5614,7 +5803,7 @@ var LocalTaskStore = class {
|
|
|
5614
5803
|
if (filter.metadata) {
|
|
5615
5804
|
for (const [key, value] of Object.entries(filter.metadata)) {
|
|
5616
5805
|
const safeKey = key.replace(/[^a-zA-Z0-9_]/g, "");
|
|
5617
|
-
const expected = (0,
|
|
5806
|
+
const expected = (0, import_protocols6.normalizeTaskMetadataScalar)(value);
|
|
5618
5807
|
if (!safeKey || expected === void 0) continue;
|
|
5619
5808
|
if (expected === "true" || expected === "false") {
|
|
5620
5809
|
conditions.push(
|
|
@@ -6189,7 +6378,7 @@ var LocalTaskStore = class {
|
|
|
6189
6378
|
};
|
|
6190
6379
|
|
|
6191
6380
|
// src/stores/LocalTaskWorkItemStore.ts
|
|
6192
|
-
var
|
|
6381
|
+
var import_protocols7 = require("@axiom-lattice/protocols");
|
|
6193
6382
|
var import_uuid2 = require("uuid");
|
|
6194
6383
|
var PROJECT_LIFECYCLE_ACTIONS = /* @__PURE__ */ new Set([
|
|
6195
6384
|
"in_progress",
|
|
@@ -6199,7 +6388,7 @@ var PROJECT_LIFECYCLE_ACTIONS = /* @__PURE__ */ new Set([
|
|
|
6199
6388
|
"cancelled",
|
|
6200
6389
|
"reassigned"
|
|
6201
6390
|
]);
|
|
6202
|
-
var
|
|
6391
|
+
var DDL24 = `
|
|
6203
6392
|
CREATE TABLE IF NOT EXISTS lt_task_work_items (
|
|
6204
6393
|
id TEXT NOT NULL,
|
|
6205
6394
|
tenant_id TEXT NOT NULL,
|
|
@@ -6273,7 +6462,7 @@ function assertLifecyclePage(query) {
|
|
|
6273
6462
|
var LocalTaskWorkItemStore = class {
|
|
6274
6463
|
constructor(db) {
|
|
6275
6464
|
this.db = db;
|
|
6276
|
-
ensureTable(db,
|
|
6465
|
+
ensureTable(db, DDL24);
|
|
6277
6466
|
this.ensureColumn("lt_task_work_items", "workspace_id", "workspace_id TEXT");
|
|
6278
6467
|
this.ensureColumn("lt_task_work_items", "project_id", "project_id TEXT");
|
|
6279
6468
|
this.ensureColumn("lt_task_work_items", "event_key", "event_key TEXT");
|
|
@@ -6414,8 +6603,8 @@ var LocalTaskWorkItemStore = class {
|
|
|
6414
6603
|
}
|
|
6415
6604
|
/** List pending execution results using one bounded SQLite anti-join query. */
|
|
6416
6605
|
async listPendingExecutionResults(params) {
|
|
6417
|
-
if (!Number.isSafeInteger(params.limit) || params.limit < 0 || params.limit >
|
|
6418
|
-
const error = new RangeError(`limit must be a safe integer between 0 and ${
|
|
6606
|
+
if (!Number.isSafeInteger(params.limit) || params.limit < 0 || params.limit > import_protocols7.MAX_PENDING_EXECUTION_RESULTS_LIMIT) {
|
|
6607
|
+
const error = new RangeError(`limit must be a safe integer between 0 and ${import_protocols7.MAX_PENDING_EXECUTION_RESULTS_LIMIT}`);
|
|
6419
6608
|
error.code = "INVALID_LIMIT";
|
|
6420
6609
|
throw error;
|
|
6421
6610
|
}
|
|
@@ -6470,7 +6659,7 @@ var LocalTaskWorkItemStore = class {
|
|
|
6470
6659
|
|
|
6471
6660
|
// src/stores/LocalCapabilityBundleStore.ts
|
|
6472
6661
|
var import_crypto7 = require("crypto");
|
|
6473
|
-
var
|
|
6662
|
+
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);`;
|
|
6474
6663
|
var duplicateMessage = "Capability bundle key already exists for tenant";
|
|
6475
6664
|
function map(row) {
|
|
6476
6665
|
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() };
|
|
@@ -6491,7 +6680,7 @@ var LocalCapabilityBundleStore = class {
|
|
|
6491
6680
|
*/
|
|
6492
6681
|
constructor(db) {
|
|
6493
6682
|
this.db = db;
|
|
6494
|
-
ensureTable(db,
|
|
6683
|
+
ensureTable(db, DDL25);
|
|
6495
6684
|
}
|
|
6496
6685
|
async listByTenant(tenantId) {
|
|
6497
6686
|
return this.db.prepare("SELECT * FROM lt_capability_bundles WHERE tenant_id = ? ORDER BY created_at").all(tenantId).map(map);
|
|
@@ -6566,6 +6755,7 @@ async function createLocalStoreConfig(options = {}) {
|
|
|
6566
6755
|
const db = await initDatabase({ dbPath });
|
|
6567
6756
|
return {
|
|
6568
6757
|
thread: new LocalThreadStore(db),
|
|
6758
|
+
store: new LocalStore(db),
|
|
6569
6759
|
assistant: new LocalAssistantStore(db),
|
|
6570
6760
|
workspace: new LocalWorkspaceStore(db),
|
|
6571
6761
|
project: new LocalProjectStore(db),
|
|
@@ -6660,6 +6850,7 @@ var InMemoryConversationStore = class {
|
|
|
6660
6850
|
LocalProjectStore,
|
|
6661
6851
|
LocalScheduleStorage,
|
|
6662
6852
|
LocalSkillStore,
|
|
6853
|
+
LocalStore,
|
|
6663
6854
|
LocalTaskStore,
|
|
6664
6855
|
LocalTaskWorkItemStore,
|
|
6665
6856
|
LocalTenantStore,
|