@axiom-lattice/local-stores 5.4.1 → 5.5.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 +120 -0
- package/dist/index.d.mts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +52 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +52 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/LocalChannelBindingStore.test.ts +19 -0
- package/src/__tests__/LocalChannelInstallationStore.test.ts +55 -0
- package/src/__tests__/LocalThreadStore.test.ts +58 -1
- package/src/stores/LocalChannelInstallationStore.ts +24 -2
- package/src/stores/LocalThreadStore.ts +34 -0
package/dist/index.mjs
CHANGED
|
@@ -346,6 +346,31 @@ var LocalThreadStore = class {
|
|
|
346
346
|
total: filtered.length
|
|
347
347
|
};
|
|
348
348
|
}
|
|
349
|
+
async listChannelSenders(tenantId, channelInstallationId, limit) {
|
|
350
|
+
const rows2 = this.db.prepare(
|
|
351
|
+
`SELECT * FROM lt_threads
|
|
352
|
+
WHERE tenant_id = ?
|
|
353
|
+
AND json_extract(metadata, '$.channelInstallationId') = ?
|
|
354
|
+
ORDER BY updated_at DESC, id DESC`
|
|
355
|
+
).all(tenantId, channelInstallationId);
|
|
356
|
+
const bySender = /* @__PURE__ */ new Map();
|
|
357
|
+
for (const row of rows2) {
|
|
358
|
+
const thread = mapRowToThread(row);
|
|
359
|
+
const metadata = thread.metadata ?? {};
|
|
360
|
+
if (typeof metadata.senderId !== "string" || !metadata.senderId) continue;
|
|
361
|
+
if (bySender.has(metadata.senderId)) continue;
|
|
362
|
+
bySender.set(metadata.senderId, {
|
|
363
|
+
senderId: metadata.senderId,
|
|
364
|
+
...typeof metadata.senderDisplayName === "string" && metadata.senderDisplayName ? { displayName: metadata.senderDisplayName } : {},
|
|
365
|
+
lastSeenAt: thread.updatedAt,
|
|
366
|
+
lastThreadId: thread.id
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
return [...bySender.values()].slice(
|
|
370
|
+
0,
|
|
371
|
+
Math.max(1, Math.min(200, Math.floor(limit)))
|
|
372
|
+
);
|
|
373
|
+
}
|
|
349
374
|
async getThreadById(tenantId, threadId) {
|
|
350
375
|
const row = this.db.prepare(
|
|
351
376
|
`SELECT * FROM lt_threads WHERE tenant_id = ? AND id = ?`
|
|
@@ -5548,6 +5573,8 @@ CREATE TABLE IF NOT EXISTS lt_channel_installations (
|
|
|
5548
5573
|
config TEXT NOT NULL,
|
|
5549
5574
|
enabled INTEGER NOT NULL DEFAULT 1,
|
|
5550
5575
|
fallback_agent_id TEXT,
|
|
5576
|
+
workspace_id TEXT,
|
|
5577
|
+
project_id TEXT,
|
|
5551
5578
|
reject_when_no_binding INTEGER NOT NULL DEFAULT 0,
|
|
5552
5579
|
created_at TEXT NOT NULL,
|
|
5553
5580
|
updated_at TEXT NOT NULL
|
|
@@ -5558,6 +5585,8 @@ var LocalChannelInstallationStore = class {
|
|
|
5558
5585
|
constructor(db) {
|
|
5559
5586
|
this.db = db;
|
|
5560
5587
|
ensureTable(db, DDL25);
|
|
5588
|
+
this.ensureColumn("lt_channel_installations", "workspace_id", "workspace_id TEXT");
|
|
5589
|
+
this.ensureColumn("lt_channel_installations", "project_id", "project_id TEXT");
|
|
5561
5590
|
}
|
|
5562
5591
|
async getInstallationById(installationId) {
|
|
5563
5592
|
const row = this.db.prepare(
|
|
@@ -5595,8 +5624,8 @@ var LocalChannelInstallationStore = class {
|
|
|
5595
5624
|
const now = nowISO();
|
|
5596
5625
|
this.db.prepare(
|
|
5597
5626
|
`INSERT INTO lt_channel_installations
|
|
5598
|
-
(id, tenant_id, channel, name, config, enabled, fallback_agent_id, reject_when_no_binding, created_at, updated_at)
|
|
5599
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
|
5627
|
+
(id, tenant_id, channel, name, config, enabled, fallback_agent_id, workspace_id, project_id, reject_when_no_binding, created_at, updated_at)
|
|
5628
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
|
5600
5629
|
).run(
|
|
5601
5630
|
installationId,
|
|
5602
5631
|
tenantId,
|
|
@@ -5605,6 +5634,8 @@ var LocalChannelInstallationStore = class {
|
|
|
5605
5634
|
JSON.stringify(data.config),
|
|
5606
5635
|
data.enabled !== false ? 1 : 0,
|
|
5607
5636
|
data.fallbackAgentId || null,
|
|
5637
|
+
data.workspaceId || null,
|
|
5638
|
+
data.projectId || null,
|
|
5608
5639
|
data.rejectWhenNoBinding ? 1 : 0,
|
|
5609
5640
|
now,
|
|
5610
5641
|
now
|
|
@@ -5617,6 +5648,8 @@ var LocalChannelInstallationStore = class {
|
|
|
5617
5648
|
config: { ...data.config },
|
|
5618
5649
|
enabled: data.enabled !== false,
|
|
5619
5650
|
fallbackAgentId: data.fallbackAgentId,
|
|
5651
|
+
workspaceId: data.workspaceId,
|
|
5652
|
+
projectId: data.projectId,
|
|
5620
5653
|
rejectWhenNoBinding: data.rejectWhenNoBinding ?? false,
|
|
5621
5654
|
createdAt: parseISO(now),
|
|
5622
5655
|
updatedAt: parseISO(now)
|
|
@@ -5643,6 +5676,14 @@ var LocalChannelInstallationStore = class {
|
|
|
5643
5676
|
setClauses.push("fallback_agent_id = ?");
|
|
5644
5677
|
values.push(updates.fallbackAgentId || null);
|
|
5645
5678
|
}
|
|
5679
|
+
if (updates.workspaceId !== void 0) {
|
|
5680
|
+
setClauses.push("workspace_id = ?");
|
|
5681
|
+
values.push(updates.workspaceId || null);
|
|
5682
|
+
}
|
|
5683
|
+
if (updates.projectId !== void 0) {
|
|
5684
|
+
setClauses.push("project_id = ?");
|
|
5685
|
+
values.push(updates.projectId || null);
|
|
5686
|
+
}
|
|
5646
5687
|
if (updates.rejectWhenNoBinding !== void 0) {
|
|
5647
5688
|
setClauses.push("reject_when_no_binding = ?");
|
|
5648
5689
|
values.push(updates.rejectWhenNoBinding ? 1 : 0);
|
|
@@ -5664,6 +5705,13 @@ var LocalChannelInstallationStore = class {
|
|
|
5664
5705
|
).run(installationId, tenantId);
|
|
5665
5706
|
return result.changes > 0;
|
|
5666
5707
|
}
|
|
5708
|
+
/** Add a column if it does not exist (SQLite version compatible). */
|
|
5709
|
+
ensureColumn(table, column, ddl2) {
|
|
5710
|
+
const cols = this.db.prepare(`PRAGMA table_info(${table})`).all();
|
|
5711
|
+
if (!cols.some((c) => c.name === column)) {
|
|
5712
|
+
this.db.exec(`ALTER TABLE ${table} ADD COLUMN ${ddl2}`);
|
|
5713
|
+
}
|
|
5714
|
+
}
|
|
5667
5715
|
};
|
|
5668
5716
|
function mapRow15(row) {
|
|
5669
5717
|
return {
|
|
@@ -5674,6 +5722,8 @@ function mapRow15(row) {
|
|
|
5674
5722
|
config: JSON.parse(row.config),
|
|
5675
5723
|
enabled: row.enabled === 1,
|
|
5676
5724
|
fallbackAgentId: row.fallback_agent_id || void 0,
|
|
5725
|
+
workspaceId: row.workspace_id || void 0,
|
|
5726
|
+
projectId: row.project_id || void 0,
|
|
5677
5727
|
rejectWhenNoBinding: row.reject_when_no_binding === 1,
|
|
5678
5728
|
createdAt: parseISO(row.created_at),
|
|
5679
5729
|
updatedAt: parseISO(row.updated_at)
|