// src/chat/chat-signatures.ts
function hashSignatureParts(parts) {
  let hash = 2166136261;
  for (const part of parts) {
    const text = String(part || "");
    for (let i = 0; i < text.length; i += 1) {
      hash ^= text.charCodeAt(i);
      hash = Math.imul(hash, 16777619) >>> 0;
    }
    hash ^= 255;
    hash = Math.imul(hash, 16777619) >>> 0;
  }
  return hash.toString(16).padStart(8, "0");
}
function stringifySignatureContent(content) {
  try {
    return JSON.stringify(content ?? "");
  } catch {
    return String(content ?? "");
  }
}
function stringifySignatureMessages(messages) {
  try {
    return JSON.stringify(messages);
  } catch {
    return String(messages.length);
  }
}
function buildChatMessageSignature(message) {
  if (!message) return "";
  return hashSignatureParts([
    String(message.id || ""),
    String(message.index ?? ""),
    String(message.role || ""),
    String(message.receivedAt ?? message.timestamp ?? ""),
    stringifySignatureContent(message.content)
  ]);
}
function buildChatTailDeliverySignature(payload) {
  return hashSignatureParts([
    payload.sessionId,
    payload.historySessionId || "",
    payload.status,
    payload.title || "",
    payload.syncMode,
    String(payload.replaceFrom),
    String(payload.totalMessages),
    payload.lastMessageSignature,
    payload.activeModal ? `${payload.activeModal.message}|${payload.activeModal.buttons.join("")}` : "",
    stringifySignatureMessages(payload.messages)
  ]);
}
function buildSessionModalDeliverySignature(payload) {
  return hashSignatureParts([
    payload.sessionId,
    payload.status,
    payload.title || "",
    payload.modalMessage || "",
    Array.isArray(payload.modalButtons) ? payload.modalButtons.join("") : ""
  ]);
}
export {
  buildChatMessageSignature,
  buildChatTailDeliverySignature,
  buildSessionModalDeliverySignature,
  hashSignatureParts
};
//# sourceMappingURL=chat-signatures.mjs.map