//#region src/core/pii.ts
/**
* Lightweight PII masking for LLM calls (Einstein-Trust-Layer-style).
* Replaces emails and phone numbers with stable placeholders before text is
* sent to an LLM, and can restore them in the response. Opt-in via
* DXCRM_PII_MASKING=on so default behaviour and quality are unchanged.
*/
const EMAIL_RE = /[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g;
const PHONE_RE = /\+?\d[\d\s().-]{6,}\d/g;
function piiMaskingEnabled() {
	return process.env["DXCRM_PII_MASKING"] === "on";
}
function maskPii(input) {
	const mapping = /* @__PURE__ */ new Map();
	let emailCount = 0;
	let phoneCount = 0;
	let masked = input.replace(EMAIL_RE, (match) => {
		let ph = mapping.get(match);
		if (!ph) {
			ph = `[EMAIL_${emailCount++}]`;
			mapping.set(match, ph);
		}
		return ph;
	});
	masked = masked.replace(PHONE_RE, (match) => {
		let ph = mapping.get(match);
		if (!ph) {
			ph = `[PHONE_${phoneCount++}]`;
			mapping.set(match, ph);
		}
		return ph;
	});
	const reverse = /* @__PURE__ */ new Map();
	for (const [orig, ph] of mapping) reverse.set(ph, orig);
	const unmask = (text) => {
		let out = text;
		for (const [ph, orig] of reverse) out = out.split(ph).join(orig);
		return out;
	};
	return {
		masked,
		unmask
	};
}
//#endregion
//#region src/core/guardrails.ts
/**
* Guardrails against (indirect) prompt injection in untrusted CRM content
* (emails, transcripts, imported notes). Detection is always available;
* neutralization is applied to LLM inputs when DXCRM_GUARDRAILS=on.
*/
const INJECTION_PATTERNS = [
	/ignore\s+(all\s+|the\s+|any\s+)?(previous|above|prior|preceding)\s+(instructions?|prompts?|messages?)/gi,
	/disregard\s+(all\s+|the\s+|any\s+)?(previous|above|prior|preceding)/gi,
	/forget\s+(all\s+|the\s+|everything\s+)?(previous|above|prior|you were told)/gi,
	/you\s+are\s+now\b/gi,
	/reveal\s+(your|the)\s+(system\s+)?(instructions?|prompt|prompts?)/gi,
	/(print|show|repeat)\s+(your|the)\s+(system\s+)?(instructions?|prompt)/gi,
	/act\s+as\s+(an?\s+)?(system|admin|administrator|developer|root)\b/gi,
	/<\/?(system|assistant|tool)\b[^>]*>/gi,
	/\bBEGIN\s+SYSTEM\b/gi
];
function guardrailsEnabled() {
	return process.env["DXCRM_GUARDRAILS"] === "on";
}
/** Replace known injection spans with a [filtered] marker, keeping other text. */
function neutralizeUntrusted(text) {
	let out = text;
	for (const re of INJECTION_PATTERNS) out = out.replace(re, "[filtered]");
	return out;
}
//#endregion
//#region src/core/compliance.ts
const DISCLOSURES = {
	de: "Hinweis: Dieser Inhalt wurde mithilfe von KI erstellt (EU-AI-Act Art. 50).",
	en: "Note: This content was generated with the help of AI (EU AI Act Art. 50)."
};
/** Localized Art. 50 disclosure string. */
function aiDisclosure(lang = "en") {
	return DISCLOSURES[lang] ?? DISCLOSURES.en;
}
/** Disclosure is ON by default (Art. 50); opt out with DXCRM_AI_DISCLOSURE=off. */
function aiDisclosureEnabled() {
	return process.env["DXCRM_AI_DISCLOSURE"] !== "off";
}
/** Prepend the Art. 50 disclosure to generated content (unless disabled). */
function labelAiContent(text, opts = {}) {
	if (!(opts.enabled ?? aiDisclosureEnabled())) return text;
	return `${aiDisclosure(opts.lang ?? (process.env["DXCRM_AI_DISCLOSURE_LANG"] || "en"))}\n\n${text}`;
}
/** Resolve the configured LLM provider (default Anthropic). */
function llmProvider() {
	const p = (process.env["DXCRM_LLM_PROVIDER"] ?? "anthropic").toLowerCase();
	if (p === "ollama" || p === "openai" || p === "local") return p;
	return "anthropic";
}
/** OpenAI-compatible local endpoint config (Ollama defaults), env-overridable. */
function localLlmConfig() {
	return {
		baseUrl: process.env["DXCRM_LLM_BASE_URL"] ?? "http://127.0.0.1:11434/v1",
		model: process.env["DXCRM_LLM_MODEL"] ?? "llama3.1"
	};
}
/** A single read-out of the active privacy/compliance posture. */
function complianceConfig() {
	const provider = llmProvider();
	return {
		provider,
		local: provider === "anthropic" ? null : localLlmConfig(),
		aiDisclosure: aiDisclosureEnabled(),
		piiMasking: piiMaskingEnabled(),
		guardrails: guardrailsEnabled()
	};
}
//#endregion
export { llmProvider as a, neutralizeUntrusted as c, labelAiContent as i, maskPii as l, aiDisclosureEnabled as n, localLlmConfig as o, complianceConfig as r, guardrailsEnabled as s, aiDisclosure as t, piiMaskingEnabled as u };

//# sourceMappingURL=compliance-Bc12Hn9a.js.map