Initialize onboarding agent scaffold
This commit is contained in:
commit
4294f3c92e
57 files changed
+14388
No files matched your search
@@ -0,0 +1,70 @@
|
||||
import type { GarnetClient } from "@common/garnet";
|
||||
import { getBlackboardTtlSeconds } from "../../../config.js";
|
||||
import type { Blackboard } from "../types.js";
|
||||
|
||||
function getBlackboardKey(chatroomId: string, userId: string): string {
|
||||
return `lolympus-agent:bb:${chatroomId}:${userId}`;
|
||||
}
|
||||
|
||||
function createDefaultBlackboard(): Blackboard {
|
||||
return {
|
||||
flaggedIssues: [],
|
||||
openQuestions: [],
|
||||
recentNicknameAttempts: [],
|
||||
toneMemory: {},
|
||||
};
|
||||
}
|
||||
|
||||
function mergeBlackboard(
|
||||
current: Blackboard | null,
|
||||
next: Partial<Blackboard>,
|
||||
): Blackboard {
|
||||
const base = current ?? createDefaultBlackboard();
|
||||
|
||||
return {
|
||||
flaggedIssues: next.flaggedIssues ?? base.flaggedIssues,
|
||||
lastIntent: next.lastIntent ?? base.lastIntent,
|
||||
lastIntentAt: next.lastIntentAt ?? base.lastIntentAt,
|
||||
openQuestions: next.openQuestions ?? base.openQuestions,
|
||||
recentNicknameAttempts:
|
||||
next.recentNicknameAttempts ?? base.recentNicknameAttempts,
|
||||
toneMemory: {
|
||||
...base.toneMemory,
|
||||
...next.toneMemory,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export class OnboardingBlackboardStore {
|
||||
constructor(private readonly garnetClient: GarnetClient) {}
|
||||
|
||||
async load(chatroomId: string, userId: string): Promise<Blackboard> {
|
||||
const key = getBlackboardKey(chatroomId, userId);
|
||||
const saved = await this.garnetClient.getJson<Blackboard>(key);
|
||||
return mergeBlackboard(saved, {});
|
||||
}
|
||||
|
||||
async save(
|
||||
chatroomId: string,
|
||||
userId: string,
|
||||
value: Blackboard,
|
||||
): Promise<void> {
|
||||
const key = getBlackboardKey(chatroomId, userId);
|
||||
await this.garnetClient.setJson(
|
||||
key,
|
||||
value,
|
||||
getBlackboardTtlSeconds(),
|
||||
);
|
||||
}
|
||||
|
||||
async update(
|
||||
chatroomId: string,
|
||||
userId: string,
|
||||
updater: (current: Blackboard) => Blackboard,
|
||||
): Promise<Blackboard> {
|
||||
const current = await this.load(chatroomId, userId);
|
||||
const next = updater(current);
|
||||
await this.save(chatroomId, userId, next);
|
||||
return next;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user