Restructure chat service, web routes, and add test suite
Split monolithic chat service into modular structure with Matrix client support, extract web server into per-resource route modules, introduce bootstrap/main-loop separation, and add comprehensive vitest coverage across services, repositories, and utilities. Adds project docs and CLAUDE.md agent instructions.
This commit is contained in:
1 parent
dfa0580859
commit
633bb0ec04
84 files changed
+19278
-3888
No files matched your search
@@ -0,0 +1,44 @@
|
||||
import type { ActivityItem } from './types.js';
|
||||
import type { ActivityLogRepository } from '../database/repositories.js';
|
||||
|
||||
const MAX_ITEMS = 200;
|
||||
|
||||
/**
|
||||
* Bounded log of bot actions surfaced on the dashboard.
|
||||
* Hydrates from SQLite on construction and persists every push,
|
||||
* so the feed survives restarts.
|
||||
*/
|
||||
export class ActivityLog {
|
||||
private items: ActivityItem[] = [];
|
||||
|
||||
constructor(private repo: ActivityLogRepository) {
|
||||
const rows = repo.getRecent(MAX_ITEMS);
|
||||
this.items = rows
|
||||
.map((r) => ({
|
||||
timestamp: r.timestamp,
|
||||
type: r.type as ActivityItem['type'],
|
||||
message: r.message,
|
||||
recipient: r.recipient ?? undefined,
|
||||
imageUrl: r.imageUrl ?? undefined,
|
||||
}))
|
||||
.reverse();
|
||||
}
|
||||
|
||||
push(type: ActivityItem['type'], message: string, recipient?: string, imageUrl?: string): void {
|
||||
const item: ActivityItem = { timestamp: Date.now(), type, message, recipient, imageUrl };
|
||||
this.items.push(item);
|
||||
if (this.items.length > MAX_ITEMS) {
|
||||
this.items = this.items.slice(-MAX_ITEMS);
|
||||
}
|
||||
this.repo.insert(item);
|
||||
this.repo.prune(MAX_ITEMS);
|
||||
}
|
||||
|
||||
recent(limit: number): ActivityItem[] {
|
||||
return this.items.slice(-limit).reverse();
|
||||
}
|
||||
|
||||
totalProcessed(): number {
|
||||
return this.repo.countSentSkipped();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user