// src/behavior-signals.ts
import { createHash } from "crypto";
function normalizeSignalText(input) {
  return input.replace(/\s+/g, " ").trim().toLowerCase();
}
function buildBehaviorSignalHash(category, content) {
  const normalized = `${category}:${normalizeSignalText(content)}`;
  return createHash("sha256").update(normalized).digest("hex").slice(0, 16);
}
function buildBehaviorSignalsForMemory(input) {
  const timestamp = input.timestamp ?? (/* @__PURE__ */ new Date()).toISOString();
  const signalHash = buildBehaviorSignalHash(input.category, input.content);
  const source = input.source ?? "extraction";
  if (input.category === "correction") {
    return [
      {
        timestamp,
        namespace: input.namespace,
        memoryId: input.memoryId,
        category: "correction",
        signalType: "correction_override",
        direction: "negative",
        confidence: input.confidence,
        signalHash,
        source
      }
    ];
  }
  if (input.category === "preference") {
    return [
      {
        timestamp,
        namespace: input.namespace,
        memoryId: input.memoryId,
        category: "preference",
        signalType: "preference_affinity",
        direction: "positive",
        confidence: input.confidence,
        signalHash,
        source
      }
    ];
  }
  return [];
}
function dedupeBehaviorSignalsByMemoryAndHash(signals) {
  const seen = /* @__PURE__ */ new Set();
  const out = [];
  for (const signal of signals) {
    const key = `${signal.memoryId}:${signal.signalHash}`;
    if (seen.has(key)) continue;
    seen.add(key);
    out.push(signal);
  }
  return out;
}

export {
  buildBehaviorSignalHash,
  buildBehaviorSignalsForMemory,
  dedupeBehaviorSignalsByMemoryAndHash
};
//# sourceMappingURL=chunk-JWPLJLDU.js.map