refactor(core): message tracker abstraction and formatter plugin registry

This commit is contained in:
RhenCloud 2026-08-15 15:42:24 +08:00
parent 486f38365f
commit eaec039ad4
No known key found for this signature in database
GPG key ID: A574A617378C4E0B
9 changed files with 361 additions and 90 deletions

View file

@ -0,0 +1,24 @@
export interface MessageTracker {
get(eventId: string, targetId: string): Promise<string | null>;
set(eventId: string, targetId: string, messageId: string): Promise<void>;
delete(eventId: string, targetId: string): Promise<void>;
}
const MESSAGE_KEY_TTL_SECONDS = 604800;
export function kvMessageTracker(kv: KVNamespace): MessageTracker {
const key = (eventId: string, targetId: string): string => `msg:${eventId}:${targetId}`;
return {
async get(eventId: string, targetId: string): Promise<string | null> {
return kv.get(key(eventId, targetId));
},
async set(eventId: string, targetId: string, messageId: string): Promise<void> {
await kv.put(key(eventId, targetId), messageId, {
expirationTtl: MESSAGE_KEY_TTL_SECONDS,
});
},
async delete(eventId: string, targetId: string): Promise<void> {
await kv.delete(key(eventId, targetId));
},
};
}