"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/chat/chat-signatures.ts
var chat_signatures_exports = {};
__export(chat_signatures_exports, {
  buildChatMessageSignature: () => buildChatMessageSignature,
  buildChatTailDeliverySignature: () => buildChatTailDeliverySignature,
  buildSessionModalDeliverySignature: () => buildSessionModalDeliverySignature,
  hashSignatureParts: () => hashSignatureParts
});
module.exports = __toCommonJS(chat_signatures_exports);
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("") : ""
  ]);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  buildChatMessageSignature,
  buildChatTailDeliverySignature,
  buildSessionModalDeliverySignature,
  hashSignatureParts
});
//# sourceMappingURL=chat-signatures.js.map