AUDIT / src /lib /agentLoop /conversationIdComputer.ts
Arypulka98's picture
feat(audit): deploy full backend cluster node (part 3)
95eb75a verified
Raw
History Blame Contribute Delete
909 Bytes
// S528 — estratto da agentLoop.ts: S274 Fix#6 conversationId derivation
// Calcola un namespace ID non-criptograficamente per isolare la cache per conversazione.
export interface ConvIdOptions {
conversationId?: string | null;
}
/**
* S528/S274-Fix6: deriva il conversationId per la cache persistente.
* - Usa options.conversationId se fornito
* - Altrimenti hash semplice (non-security) dei primi 64 char del primo messaggio utente
*/
export function computeConversationId(
options: ConvIdOptions | null | undefined,
initialMessages: Array<{ role: string; content: string }>,
): string {
if (options?.conversationId) return options.conversationId;
const _fu = initialMessages.find(m => m.role === "user")?.content ?? "";
let _h = 0;
for (let _i = 0; _i < Math.min(_fu.length, 64); _i++) {
_h = ((_h << 5) - _h + _fu.charCodeAt(_i)) >>> 0;
}
return "anon-" + _h.toString(36);
}