//#region src/cognitive/feedback/trust-calculator.ts
/**
* Calculate trust score based on interaction history and feedback.
*
* Trust is a composite of:
* - Interaction depth (total exchanges)
* - Self-disclosure level (how much the user shares about themselves)
* - Response engagement (average response length as proxy)
* - Feedback positivity ratio
*/
const TRUST_BASELINE = .1;
const MAX_TRUST = 1;
/**
* Update trust score based on a feedback event.
*/
function updateTrustFromFeedback(rapport, feedback) {
	const delta = feedbackScoreDelta(feedback.type);
	const newTrust = clampTrust(rapport.trustScore + delta);
	return {
		...rapport,
		trustScore: newTrust,
		totalExchanges: rapport.totalExchanges + 1
	};
}
/**
* Update trust based on implicit feedback signals.
*/
function updateTrustFromImplicit(rapport, signals) {
	let trustDelta = 0;
	let totalResponseLength = rapport.avgResponseLength * rapport.totalExchanges;
	let disclosureDelta = 0;
	for (const signal of signals) switch (signal.type) {
		case "response_length":
			if (signal.value > 100) trustDelta += .02;
			else if (signal.value < 20) trustDelta -= .01;
			totalResponseLength += signal.value;
			break;
		case "response_latency":
			if (signal.value < 6e4) trustDelta += .01;
			else if (signal.value > 36e5) trustDelta -= .01;
			break;
		case "topic_continuation":
			trustDelta += .03;
			break;
		case "topic_abandonment":
			trustDelta -= .02;
			break;
		case "question_depth":
			trustDelta += .02;
			disclosureDelta += .05;
			break;
	}
	const newTotalExchanges = rapport.totalExchanges + signals.length;
	const newAvgResponseLength = newTotalExchanges > 0 ? totalResponseLength / newTotalExchanges : rapport.avgResponseLength;
	return {
		...rapport,
		trustScore: clampTrust(rapport.trustScore + trustDelta),
		totalExchanges: newTotalExchanges,
		avgResponseLength: newAvgResponseLength,
		selfDisclosureLevel: Math.min(1, rapport.selfDisclosureLevel + disclosureDelta)
	};
}
/**
* Determine the interaction phase based on trust score.
* Maps to SARA framework strategies.
*/
function getInteractionPhase(trustScore) {
	if (trustScore < .3) return "orientation";
	if (trustScore < .5) return "exploration";
	if (trustScore < .7) return "rapport";
	return "partnership";
}
/**
* Get recommended behavior based on interaction phase.
*/
function getPhaseBehaviorAdvice(phase) {
	switch (phase) {
		case "orientation": return "Focus on demonstrating capability and active listening. Acknowledge and validate. No proactive suggestions yet.";
		case "exploration": return "Begin sharing observations about the user's interests. Ask occasional curiosity questions (1 per 3 turns). Still prioritize task execution.";
		case "rapport": return "Start connecting patterns across the user's domains. Offer brief insights when relevant. Use 2:1 statement-to-question ratio.";
		case "partnership": return "Proactively suggest insights. Cross-reference domains. Challenge assumptions respectfully. Full thinking partner mode.";
	}
}
function feedbackScoreDelta(type) {
	switch (type) {
		case "positive": return .05;
		case "engaged": return .08;
		case "negative": return -.08;
		case "neutral": return 0;
	}
}
function clampTrust(value) {
	return Math.max(TRUST_BASELINE, Math.min(MAX_TRUST, value));
}
//#endregion
export { updateTrustFromImplicit as i, getPhaseBehaviorAdvice as n, updateTrustFromFeedback as r, getInteractionPhase as t };
