@axiom-lattice/local-stores 3.2.12 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +10 -10
- package/CHANGELOG.md +78 -0
- package/dist/index.d.mts +20 -2
- package/dist/index.d.ts +20 -2
- package/dist/index.js +313 -112
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +301 -95
- 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/LocalModelProviderStore.ts +16 -4
- 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,
|
|
@@ -2604,6 +2787,7 @@ CREATE TABLE IF NOT EXISTS lt_model_provider_models (
|
|
|
2604
2787
|
upstream_created TEXT,
|
|
2605
2788
|
enabled INTEGER NOT NULL DEFAULT 1,
|
|
2606
2789
|
stale INTEGER NOT NULL DEFAULT 0,
|
|
2790
|
+
kind TEXT NOT NULL DEFAULT 'chat',
|
|
2607
2791
|
raw TEXT,
|
|
2608
2792
|
discovered_at TEXT NOT NULL,
|
|
2609
2793
|
PRIMARY KEY (tenant_id, provider_id, model_id)
|
|
@@ -2614,7 +2798,7 @@ CREATE INDEX IF NOT EXISTS idx_lt_model_provider_models_tenant
|
|
|
2614
2798
|
var LocalModelProviderStore = class {
|
|
2615
2799
|
constructor(db) {
|
|
2616
2800
|
this.db = db;
|
|
2617
|
-
ensureTable(db,
|
|
2801
|
+
ensureTable(db, DDL13);
|
|
2618
2802
|
this.ensureColumn(
|
|
2619
2803
|
"lt_model_providers",
|
|
2620
2804
|
"api_style",
|
|
@@ -2625,6 +2809,11 @@ var LocalModelProviderStore = class {
|
|
|
2625
2809
|
"stale",
|
|
2626
2810
|
"stale INTEGER NOT NULL DEFAULT 0"
|
|
2627
2811
|
);
|
|
2812
|
+
this.ensureColumn(
|
|
2813
|
+
"lt_model_provider_models",
|
|
2814
|
+
"kind",
|
|
2815
|
+
"kind TEXT NOT NULL DEFAULT 'chat'"
|
|
2816
|
+
);
|
|
2628
2817
|
}
|
|
2629
2818
|
/** Add a column if it does not exist (SQLite version compatible). */
|
|
2630
2819
|
ensureColumn(table, column, ddl2) {
|
|
@@ -2787,7 +2976,7 @@ var LocalModelProviderStore = class {
|
|
|
2787
2976
|
const current = new Map(
|
|
2788
2977
|
(await this.listModels(tenantId, providerId)).map((model) => [
|
|
2789
2978
|
model.modelId,
|
|
2790
|
-
model
|
|
2979
|
+
model
|
|
2791
2980
|
])
|
|
2792
2981
|
);
|
|
2793
2982
|
const placeholders = rows2.map(() => "?").join(", ");
|
|
@@ -2799,8 +2988,8 @@ var LocalModelProviderStore = class {
|
|
|
2799
2988
|
this.db.prepare(
|
|
2800
2989
|
`INSERT INTO lt_model_provider_models (
|
|
2801
2990
|
id, tenant_id, provider_id, model_id, display_name, owned_by,
|
|
2802
|
-
upstream_created, raw, enabled, stale, discovered_at
|
|
2803
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
2991
|
+
upstream_created, raw, enabled, stale, kind, discovered_at
|
|
2992
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
2804
2993
|
ON CONFLICT (tenant_id, provider_id, model_id) DO UPDATE SET
|
|
2805
2994
|
display_name = excluded.display_name,
|
|
2806
2995
|
owned_by = excluded.owned_by,
|
|
@@ -2808,6 +2997,7 @@ var LocalModelProviderStore = class {
|
|
|
2808
2997
|
raw = excluded.raw,
|
|
2809
2998
|
enabled = excluded.enabled,
|
|
2810
2999
|
stale = excluded.stale,
|
|
3000
|
+
kind = excluded.kind,
|
|
2811
3001
|
discovered_at = excluded.discovered_at`
|
|
2812
3002
|
).run(
|
|
2813
3003
|
`${providerId}:${model.id}`,
|
|
@@ -2818,8 +3008,10 @@ var LocalModelProviderStore = class {
|
|
|
2818
3008
|
model.ownedBy || null,
|
|
2819
3009
|
model.createdAt || null,
|
|
2820
3010
|
model.raw === void 0 ? null : JSON.stringify(model.raw),
|
|
2821
|
-
model.enabled ?? current.get(model.id) ?? true ? 1 : 0,
|
|
3011
|
+
model.enabled ?? current.get(model.id)?.enabled ?? true ? 1 : 0,
|
|
2822
3012
|
model.stale ? 1 : 0,
|
|
3013
|
+
// Omitted means "keep the stored kind"; a new row starts as chat.
|
|
3014
|
+
model.kind ?? current.get(model.id)?.kind ?? "chat",
|
|
2823
3015
|
now
|
|
2824
3016
|
);
|
|
2825
3017
|
}
|
|
@@ -2879,12 +3071,13 @@ function mapRowToModel(row) {
|
|
|
2879
3071
|
upstreamCreatedAt: row.upstream_created ? parseISO(row.upstream_created) : void 0,
|
|
2880
3072
|
enabled: row.enabled === 1,
|
|
2881
3073
|
stale: row.stale === 1,
|
|
3074
|
+
kind: row.kind || "chat",
|
|
2882
3075
|
discoveredAt: parseISO(row.discovered_at)
|
|
2883
3076
|
};
|
|
2884
3077
|
}
|
|
2885
3078
|
|
|
2886
3079
|
// src/stores/LocalWorkflowTrackingStore.ts
|
|
2887
|
-
var
|
|
3080
|
+
var DDL14 = `
|
|
2888
3081
|
CREATE TABLE IF NOT EXISTS lt_workflow_runs (
|
|
2889
3082
|
id TEXT PRIMARY KEY,
|
|
2890
3083
|
tenant_id TEXT NOT NULL,
|
|
@@ -2933,7 +3126,7 @@ ALTER TABLE lt_workflow_steps ADD COLUMN IF NOT EXISTS thread_id TEXT;
|
|
|
2933
3126
|
var LocalWorkflowTrackingStore = class {
|
|
2934
3127
|
constructor(db) {
|
|
2935
3128
|
this.db = db;
|
|
2936
|
-
ensureTable(db,
|
|
3129
|
+
ensureTable(db, DDL14);
|
|
2937
3130
|
}
|
|
2938
3131
|
async createWorkflowRun(request) {
|
|
2939
3132
|
const now = nowISO();
|
|
@@ -3224,7 +3417,7 @@ function mapRowToStep(row) {
|
|
|
3224
3417
|
|
|
3225
3418
|
// src/stores/LocalEvalStore.ts
|
|
3226
3419
|
var import_crypto = require("crypto");
|
|
3227
|
-
var
|
|
3420
|
+
var DDL15 = `
|
|
3228
3421
|
CREATE TABLE IF NOT EXISTS lt_eval_projects (
|
|
3229
3422
|
id TEXT NOT NULL,
|
|
3230
3423
|
tenant_id TEXT NOT NULL,
|
|
@@ -3334,7 +3527,7 @@ function parseOptionalJson(val) {
|
|
|
3334
3527
|
var LocalEvalStore = class {
|
|
3335
3528
|
constructor(db) {
|
|
3336
3529
|
this.db = db;
|
|
3337
|
-
ensureTable(db,
|
|
3530
|
+
ensureTable(db, DDL15);
|
|
3338
3531
|
this.ensureColumn("lt_eval_runs", "interrupted_cases", "interrupted_cases INTEGER NOT NULL DEFAULT 0");
|
|
3339
3532
|
this.ensureColumn("lt_eval_run_results", "interrupted", "interrupted INTEGER NOT NULL DEFAULT 0");
|
|
3340
3533
|
this.ensureColumn("lt_eval_cases", "interrupt_policy", "interrupt_policy TEXT");
|
|
@@ -3919,11 +4112,11 @@ var LocalEvalStore = class {
|
|
|
3919
4112
|
};
|
|
3920
4113
|
|
|
3921
4114
|
// src/stores/LocalChannelBindingStore.ts
|
|
3922
|
-
var
|
|
4115
|
+
var import_protocols4 = require("@axiom-lattice/protocols");
|
|
3923
4116
|
var import_crypto2 = require("crypto");
|
|
3924
4117
|
|
|
3925
4118
|
// src/stores/room-channel-binding-index.ts
|
|
3926
|
-
var
|
|
4119
|
+
var import_protocols3 = require("@axiom-lattice/protocols");
|
|
3927
4120
|
var UNIQUE_INDEX_SQL = `CREATE UNIQUE INDEX IF NOT EXISTS idx_lt_cb_subject_unique
|
|
3928
4121
|
ON lt_channel_bindings(channel, channel_installation_id, tenant_id, sender_id)`;
|
|
3929
4122
|
var LOOKUP_INDEX_SQL = `CREATE INDEX IF NOT EXISTS idx_lt_cb_resolve
|
|
@@ -3937,7 +4130,7 @@ function ensureChannelBindingSubjectIndex(db) {
|
|
|
3937
4130
|
HAVING COUNT(*) > 1
|
|
3938
4131
|
ORDER BY tenant_id, channel, channel_installation_id, sender_id`).all();
|
|
3939
4132
|
if (conflicts.length > 0) {
|
|
3940
|
-
throw new
|
|
4133
|
+
throw new import_protocols3.ChannelBindingMigrationConflictError(conflicts.map(mapConflict));
|
|
3941
4134
|
}
|
|
3942
4135
|
db.exec("DROP INDEX IF EXISTS idx_lt_cb_room_subject");
|
|
3943
4136
|
db.exec(UNIQUE_INDEX_SQL);
|
|
@@ -3963,7 +4156,7 @@ function mapConflict(row) {
|
|
|
3963
4156
|
}
|
|
3964
4157
|
|
|
3965
4158
|
// src/stores/LocalChannelBindingStore.ts
|
|
3966
|
-
var
|
|
4159
|
+
var DDL16 = `
|
|
3967
4160
|
CREATE TABLE IF NOT EXISTS lt_channel_bindings (
|
|
3968
4161
|
id TEXT PRIMARY KEY,
|
|
3969
4162
|
channel TEXT NOT NULL,
|
|
@@ -3985,7 +4178,7 @@ CREATE TABLE IF NOT EXISTS lt_channel_bindings (
|
|
|
3985
4178
|
var LocalChannelBindingStore = class {
|
|
3986
4179
|
constructor(db) {
|
|
3987
4180
|
this.db = db;
|
|
3988
|
-
ensureTable(db,
|
|
4181
|
+
ensureTable(db, DDL16);
|
|
3989
4182
|
ensureChannelBindingSubjectIndex(db);
|
|
3990
4183
|
}
|
|
3991
4184
|
async findById(tenantId, id) {
|
|
@@ -4035,7 +4228,7 @@ var LocalChannelBindingStore = class {
|
|
|
4035
4228
|
);
|
|
4036
4229
|
} catch (error) {
|
|
4037
4230
|
if (error instanceof Error && /UNIQUE constraint failed/.test(error.message)) {
|
|
4038
|
-
throw new
|
|
4231
|
+
throw new import_protocols4.DuplicateChannelBindingSubjectError();
|
|
4039
4232
|
}
|
|
4040
4233
|
throw error;
|
|
4041
4234
|
}
|
|
@@ -4165,7 +4358,7 @@ function mapRowToBinding(row) {
|
|
|
4165
4358
|
}
|
|
4166
4359
|
|
|
4167
4360
|
// src/stores/LocalChannelInstallationStore.ts
|
|
4168
|
-
var
|
|
4361
|
+
var DDL17 = `
|
|
4169
4362
|
CREATE TABLE IF NOT EXISTS lt_channel_installations (
|
|
4170
4363
|
id TEXT PRIMARY KEY,
|
|
4171
4364
|
tenant_id TEXT NOT NULL,
|
|
@@ -4183,13 +4376,13 @@ CREATE INDEX IF NOT EXISTS idx_lt_ci_tenant ON lt_channel_installations(tenant_i
|
|
|
4183
4376
|
var LocalChannelInstallationStore = class {
|
|
4184
4377
|
constructor(db) {
|
|
4185
4378
|
this.db = db;
|
|
4186
|
-
ensureTable(db,
|
|
4379
|
+
ensureTable(db, DDL17);
|
|
4187
4380
|
}
|
|
4188
4381
|
async getInstallationById(installationId) {
|
|
4189
4382
|
const row = this.db.prepare(
|
|
4190
4383
|
`SELECT * FROM lt_channel_installations WHERE id = ?`
|
|
4191
4384
|
).get(installationId);
|
|
4192
|
-
return row ?
|
|
4385
|
+
return row ? mapRow7(row) : null;
|
|
4193
4386
|
}
|
|
4194
4387
|
async getInstallationsByTenant(tenantId, channel) {
|
|
4195
4388
|
let rows2;
|
|
@@ -4202,7 +4395,7 @@ var LocalChannelInstallationStore = class {
|
|
|
4202
4395
|
`SELECT * FROM lt_channel_installations WHERE tenant_id = ? ORDER BY created_at DESC`
|
|
4203
4396
|
).all(tenantId);
|
|
4204
4397
|
}
|
|
4205
|
-
return rows2.map(
|
|
4398
|
+
return rows2.map(mapRow7);
|
|
4206
4399
|
}
|
|
4207
4400
|
async getAllInstallations(channel) {
|
|
4208
4401
|
let rows2;
|
|
@@ -4215,7 +4408,7 @@ var LocalChannelInstallationStore = class {
|
|
|
4215
4408
|
`SELECT * FROM lt_channel_installations ORDER BY created_at DESC`
|
|
4216
4409
|
).all();
|
|
4217
4410
|
}
|
|
4218
|
-
return rows2.map(
|
|
4411
|
+
return rows2.map(mapRow7);
|
|
4219
4412
|
}
|
|
4220
4413
|
async createInstallation(tenantId, installationId, data) {
|
|
4221
4414
|
const now = nowISO();
|
|
@@ -4291,7 +4484,7 @@ var LocalChannelInstallationStore = class {
|
|
|
4291
4484
|
return result.changes > 0;
|
|
4292
4485
|
}
|
|
4293
4486
|
};
|
|
4294
|
-
function
|
|
4487
|
+
function mapRow7(row) {
|
|
4295
4488
|
return {
|
|
4296
4489
|
id: row.id,
|
|
4297
4490
|
tenantId: row.tenant_id,
|
|
@@ -4309,7 +4502,7 @@ function mapRow6(row) {
|
|
|
4309
4502
|
// src/stores/LocalA2AApiKeyStore.ts
|
|
4310
4503
|
var import_core5 = require("@axiom-lattice/core");
|
|
4311
4504
|
var import_crypto3 = require("crypto");
|
|
4312
|
-
var
|
|
4505
|
+
var DDL18 = `
|
|
4313
4506
|
CREATE TABLE IF NOT EXISTS lt_a2a_api_keys (
|
|
4314
4507
|
id TEXT PRIMARY KEY,
|
|
4315
4508
|
key_value TEXT NOT NULL,
|
|
@@ -4347,7 +4540,7 @@ function parseAssistantIds(raw) {
|
|
|
4347
4540
|
var LocalA2AApiKeyStore = class {
|
|
4348
4541
|
constructor(db) {
|
|
4349
4542
|
this.db = db;
|
|
4350
|
-
ensureTable(db,
|
|
4543
|
+
ensureTable(db, DDL18);
|
|
4351
4544
|
this.ensureColumn("lt_a2a_api_keys", "assistant_ids", "assistant_ids TEXT");
|
|
4352
4545
|
this.ensureColumn("lt_a2a_api_keys", "grants", "grants TEXT");
|
|
4353
4546
|
this.repairManagementIds();
|
|
@@ -4528,7 +4721,7 @@ function mapRowToRecord(row) {
|
|
|
4528
4721
|
|
|
4529
4722
|
// src/stores/LocalOpenAuditStore.ts
|
|
4530
4723
|
var import_crypto4 = require("crypto");
|
|
4531
|
-
var
|
|
4724
|
+
var DDL19 = `
|
|
4532
4725
|
CREATE TABLE IF NOT EXISTS lt_open_audit (
|
|
4533
4726
|
id TEXT PRIMARY KEY,
|
|
4534
4727
|
tenant_id TEXT NOT NULL,
|
|
@@ -4547,7 +4740,7 @@ CREATE TABLE IF NOT EXISTS lt_open_audit (
|
|
|
4547
4740
|
var LocalOpenAuditStore = class {
|
|
4548
4741
|
constructor(db) {
|
|
4549
4742
|
this.db = db;
|
|
4550
|
-
ensureTable(db,
|
|
4743
|
+
ensureTable(db, DDL19);
|
|
4551
4744
|
}
|
|
4552
4745
|
async query(params) {
|
|
4553
4746
|
const clauses = ["tenant_id = ?"];
|
|
@@ -4617,9 +4810,9 @@ var LocalOpenAuditStore = class {
|
|
|
4617
4810
|
};
|
|
4618
4811
|
|
|
4619
4812
|
// src/stores/LocalThreadMessageQueueStore.ts
|
|
4620
|
-
var
|
|
4813
|
+
var import_protocols5 = require("@axiom-lattice/protocols");
|
|
4621
4814
|
var import_crypto5 = require("crypto");
|
|
4622
|
-
var
|
|
4815
|
+
var DDL20 = `
|
|
4623
4816
|
CREATE TABLE IF NOT EXISTS lt_thread_message_queue (
|
|
4624
4817
|
id TEXT PRIMARY KEY,
|
|
4625
4818
|
thread_id TEXT NOT NULL,
|
|
@@ -4648,7 +4841,7 @@ var LocalThreadMessageQueueStore = class {
|
|
|
4648
4841
|
constructor(db) {
|
|
4649
4842
|
this.capacityTail = Promise.resolve();
|
|
4650
4843
|
this.db = db;
|
|
4651
|
-
ensureTable(db,
|
|
4844
|
+
ensureTable(db, DDL20);
|
|
4652
4845
|
const columns6 = db.prepare("PRAGMA table_info(lt_thread_message_queue)").all();
|
|
4653
4846
|
const names = new Set(columns6.map(({ name }) => name));
|
|
4654
4847
|
if (!names.has("trusted_run_context")) {
|
|
@@ -4831,14 +5024,20 @@ var LocalThreadMessageQueueStore = class {
|
|
|
4831
5024
|
}
|
|
4832
5025
|
async getThreadsWithPendingMessages() {
|
|
4833
5026
|
const rows2 = this.db.prepare(
|
|
4834
|
-
`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`
|
|
4835
5033
|
).all();
|
|
4836
5034
|
return rows2.map((r) => ({
|
|
4837
5035
|
tenantId: r.tenant_id,
|
|
4838
5036
|
assistantId: r.assistant_id,
|
|
4839
5037
|
threadId: r.thread_id,
|
|
4840
5038
|
workspaceId: r.workspace_id,
|
|
4841
|
-
projectId: r.project_id
|
|
5039
|
+
projectId: r.project_id,
|
|
5040
|
+
hasPending: r.has_pending === 1
|
|
4842
5041
|
}));
|
|
4843
5042
|
}
|
|
4844
5043
|
async removeMessage(messageId, scope) {
|
|
@@ -4874,8 +5073,8 @@ var LocalThreadMessageQueueStore = class {
|
|
|
4874
5073
|
};
|
|
4875
5074
|
function validateQueueTrust(params) {
|
|
4876
5075
|
return {
|
|
4877
|
-
trustedRunContext: params.trusted_run_context === void 0 ? void 0 : (0,
|
|
4878
|
-
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)
|
|
4879
5078
|
};
|
|
4880
5079
|
}
|
|
4881
5080
|
function scopeClause(scope) {
|
|
@@ -4896,13 +5095,13 @@ function rowToMessage(row) {
|
|
|
4896
5095
|
priority: row.priority || 0,
|
|
4897
5096
|
command: row.command ? JSON.parse(row.command) : void 0,
|
|
4898
5097
|
custom_run_config: row.custom_run_config ? JSON.parse(row.custom_run_config) : void 0,
|
|
4899
|
-
trusted_run_context: row.trusted_run_context ? (0,
|
|
4900
|
-
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)
|
|
4901
5100
|
};
|
|
4902
5101
|
}
|
|
4903
5102
|
|
|
4904
5103
|
// src/stores/LocalSkillStore.ts
|
|
4905
|
-
var
|
|
5104
|
+
var DDL21 = `
|
|
4906
5105
|
CREATE TABLE IF NOT EXISTS lt_skills (
|
|
4907
5106
|
id TEXT NOT NULL,
|
|
4908
5107
|
tenant_id TEXT NOT NULL,
|
|
@@ -4921,7 +5120,7 @@ CREATE TABLE IF NOT EXISTS lt_skills (
|
|
|
4921
5120
|
var LocalSkillStore = class {
|
|
4922
5121
|
constructor(db) {
|
|
4923
5122
|
this.db = db;
|
|
4924
|
-
ensureTable(db,
|
|
5123
|
+
ensureTable(db, DDL21);
|
|
4925
5124
|
}
|
|
4926
5125
|
async getAllSkills(tenantId, _context) {
|
|
4927
5126
|
const rows2 = this.db.prepare(
|
|
@@ -5071,7 +5270,7 @@ function mapRowToSkill(row) {
|
|
|
5071
5270
|
}
|
|
5072
5271
|
|
|
5073
5272
|
// src/stores/LocalScheduleStorage.ts
|
|
5074
|
-
var
|
|
5273
|
+
var DDL22 = `
|
|
5075
5274
|
CREATE TABLE IF NOT EXISTS lt_scheduled_tasks (
|
|
5076
5275
|
task_id TEXT PRIMARY KEY,
|
|
5077
5276
|
task_type TEXT NOT NULL,
|
|
@@ -5104,7 +5303,7 @@ CREATE INDEX IF NOT EXISTS idx_lt_st_tenant ON lt_scheduled_tasks(tenant_id);
|
|
|
5104
5303
|
var LocalScheduleStorage = class {
|
|
5105
5304
|
constructor(db) {
|
|
5106
5305
|
this.db = db;
|
|
5107
|
-
ensureTable(db,
|
|
5306
|
+
ensureTable(db, DDL22);
|
|
5108
5307
|
}
|
|
5109
5308
|
async save(task) {
|
|
5110
5309
|
this.db.prepare(
|
|
@@ -5419,7 +5618,7 @@ function mapRowToTask(row) {
|
|
|
5419
5618
|
}
|
|
5420
5619
|
|
|
5421
5620
|
// src/stores/LocalTaskStore.ts
|
|
5422
|
-
var
|
|
5621
|
+
var import_protocols6 = require("@axiom-lattice/protocols");
|
|
5423
5622
|
var import_crypto6 = require("crypto");
|
|
5424
5623
|
var MAX_CANONICAL_TASK_TIME = "9999-12-31T23:59:59.999Z";
|
|
5425
5624
|
var TASK_STATUSES = /* @__PURE__ */ new Set([
|
|
@@ -5436,7 +5635,7 @@ var NEXT_UPDATED_AT_SQL = `updated_at = CASE
|
|
|
5436
5635
|
THEN strftime('%Y-%m-%dT%H:%M:%fZ', updated_at, '+0.001 seconds')
|
|
5437
5636
|
ELSE ?
|
|
5438
5637
|
END`;
|
|
5439
|
-
var
|
|
5638
|
+
var DDL23 = `
|
|
5440
5639
|
CREATE TABLE IF NOT EXISTS lt_tasks (
|
|
5441
5640
|
id TEXT NOT NULL,
|
|
5442
5641
|
tenant_id TEXT NOT NULL,
|
|
@@ -5509,7 +5708,7 @@ function assertPage(limit, offset = 0) {
|
|
|
5509
5708
|
var LocalTaskStore = class {
|
|
5510
5709
|
constructor(db) {
|
|
5511
5710
|
this.db = db;
|
|
5512
|
-
ensureTable(db,
|
|
5711
|
+
ensureTable(db, DDL23);
|
|
5513
5712
|
this.ensureColumn("lt_tasks", "require_review", "require_review INTEGER DEFAULT 0");
|
|
5514
5713
|
this.ensureColumn("lt_tasks", "dependencies", "dependencies TEXT");
|
|
5515
5714
|
this.ensureColumn("lt_tasks", "result", "result TEXT");
|
|
@@ -5604,7 +5803,7 @@ var LocalTaskStore = class {
|
|
|
5604
5803
|
if (filter.metadata) {
|
|
5605
5804
|
for (const [key, value] of Object.entries(filter.metadata)) {
|
|
5606
5805
|
const safeKey = key.replace(/[^a-zA-Z0-9_]/g, "");
|
|
5607
|
-
const expected = (0,
|
|
5806
|
+
const expected = (0, import_protocols6.normalizeTaskMetadataScalar)(value);
|
|
5608
5807
|
if (!safeKey || expected === void 0) continue;
|
|
5609
5808
|
if (expected === "true" || expected === "false") {
|
|
5610
5809
|
conditions.push(
|
|
@@ -6179,7 +6378,7 @@ var LocalTaskStore = class {
|
|
|
6179
6378
|
};
|
|
6180
6379
|
|
|
6181
6380
|
// src/stores/LocalTaskWorkItemStore.ts
|
|
6182
|
-
var
|
|
6381
|
+
var import_protocols7 = require("@axiom-lattice/protocols");
|
|
6183
6382
|
var import_uuid2 = require("uuid");
|
|
6184
6383
|
var PROJECT_LIFECYCLE_ACTIONS = /* @__PURE__ */ new Set([
|
|
6185
6384
|
"in_progress",
|
|
@@ -6189,7 +6388,7 @@ var PROJECT_LIFECYCLE_ACTIONS = /* @__PURE__ */ new Set([
|
|
|
6189
6388
|
"cancelled",
|
|
6190
6389
|
"reassigned"
|
|
6191
6390
|
]);
|
|
6192
|
-
var
|
|
6391
|
+
var DDL24 = `
|
|
6193
6392
|
CREATE TABLE IF NOT EXISTS lt_task_work_items (
|
|
6194
6393
|
id TEXT NOT NULL,
|
|
6195
6394
|
tenant_id TEXT NOT NULL,
|
|
@@ -6263,7 +6462,7 @@ function assertLifecyclePage(query) {
|
|
|
6263
6462
|
var LocalTaskWorkItemStore = class {
|
|
6264
6463
|
constructor(db) {
|
|
6265
6464
|
this.db = db;
|
|
6266
|
-
ensureTable(db,
|
|
6465
|
+
ensureTable(db, DDL24);
|
|
6267
6466
|
this.ensureColumn("lt_task_work_items", "workspace_id", "workspace_id TEXT");
|
|
6268
6467
|
this.ensureColumn("lt_task_work_items", "project_id", "project_id TEXT");
|
|
6269
6468
|
this.ensureColumn("lt_task_work_items", "event_key", "event_key TEXT");
|
|
@@ -6404,8 +6603,8 @@ var LocalTaskWorkItemStore = class {
|
|
|
6404
6603
|
}
|
|
6405
6604
|
/** List pending execution results using one bounded SQLite anti-join query. */
|
|
6406
6605
|
async listPendingExecutionResults(params) {
|
|
6407
|
-
if (!Number.isSafeInteger(params.limit) || params.limit < 0 || params.limit >
|
|
6408
|
-
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}`);
|
|
6409
6608
|
error.code = "INVALID_LIMIT";
|
|
6410
6609
|
throw error;
|
|
6411
6610
|
}
|
|
@@ -6460,7 +6659,7 @@ var LocalTaskWorkItemStore = class {
|
|
|
6460
6659
|
|
|
6461
6660
|
// src/stores/LocalCapabilityBundleStore.ts
|
|
6462
6661
|
var import_crypto7 = require("crypto");
|
|
6463
|
-
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);`;
|
|
6464
6663
|
var duplicateMessage = "Capability bundle key already exists for tenant";
|
|
6465
6664
|
function map(row) {
|
|
6466
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() };
|
|
@@ -6481,7 +6680,7 @@ var LocalCapabilityBundleStore = class {
|
|
|
6481
6680
|
*/
|
|
6482
6681
|
constructor(db) {
|
|
6483
6682
|
this.db = db;
|
|
6484
|
-
ensureTable(db,
|
|
6683
|
+
ensureTable(db, DDL25);
|
|
6485
6684
|
}
|
|
6486
6685
|
async listByTenant(tenantId) {
|
|
6487
6686
|
return this.db.prepare("SELECT * FROM lt_capability_bundles WHERE tenant_id = ? ORDER BY created_at").all(tenantId).map(map);
|
|
@@ -6556,6 +6755,7 @@ async function createLocalStoreConfig(options = {}) {
|
|
|
6556
6755
|
const db = await initDatabase({ dbPath });
|
|
6557
6756
|
return {
|
|
6558
6757
|
thread: new LocalThreadStore(db),
|
|
6758
|
+
store: new LocalStore(db),
|
|
6559
6759
|
assistant: new LocalAssistantStore(db),
|
|
6560
6760
|
workspace: new LocalWorkspaceStore(db),
|
|
6561
6761
|
project: new LocalProjectStore(db),
|
|
@@ -6650,6 +6850,7 @@ var InMemoryConversationStore = class {
|
|
|
6650
6850
|
LocalProjectStore,
|
|
6651
6851
|
LocalScheduleStorage,
|
|
6652
6852
|
LocalSkillStore,
|
|
6853
|
+
LocalStore,
|
|
6653
6854
|
LocalTaskStore,
|
|
6654
6855
|
LocalTaskWorkItemStore,
|
|
6655
6856
|
LocalTenantStore,
|