Elffuss BraidHub

kikocis/continue public

main · 971 BRawPermalink
1import {
2 ILLMLogger,
3 ILLMInteractionLog,
4 LLMInteractionItem,
5 LLMInteractionItemDetails,
6} from "..";
7
8type LLMLogItemFunction = (item: LLMInteractionItem) => void;
9
10export class LLMLogger implements ILLMLogger {
11 private nextId = 0;
12
13 public createInteractionLog(): LLMInteractionLog {
14 return new LLMInteractionLog(this, (this.nextId++).toString());
15 }
16
17 private logItemListeners: LLMLogItemFunction[] = [];
18
19 onLogItem(listener: LLMLogItemFunction) {
20 this.logItemListeners.push(listener);
21 }
22
23 public _logItem(item: LLMInteractionItem) {
24 for (const listener of this.logItemListeners) {
25 listener(item);
26 }
27 }
28}
29
30export class LLMInteractionLog implements ILLMInteractionLog {
31 constructor(
32 private logger: LLMLogger,
33 public interactionId: string,
34 ) {}
35
36 logItem(item: LLMInteractionItemDetails) {
37 this.logger._logItem({
38 ...item,
39 interactionId: this.interactionId,
40 timestamp: Date.now(),
41 });
42 }
43}