import { HeddleEventType } from '../../../../../core/event-types.js';
/**
 * Normalizes host-facing engine callbacks into turn-runtime ports.
 */
export class ConversationEngineHostNormalizer {
    static normalize(host) {
        const onActivity = host?.events?.onActivity;
        const onEvent = host?.events?.onEvent;
        const onTraceEvent = host?.trace?.onEvent;
        const requestToolApproval = host?.approvals?.requestToolApproval;
        const turnHost = {
            onEvent: (event) => {
                onEvent?.(event);
                if (ConversationEngineHostNormalizer.isConversationActivity(event)) {
                    onActivity?.(event);
                }
            },
            approveToolCall: requestToolApproval
                ? ((call, tool, autonomyEvaluation) => requestToolApproval({
                    call,
                    tool,
                    ...(autonomyEvaluation ? { autonomyEvaluation } : {}),
                }))
                : undefined,
            onCompactionStatus: (event, phase) => {
                host?.compaction?.onStatus?.(event);
                if (phase === 'preflight') {
                    host?.compaction?.onPreflightCompactionStatus?.(event);
                }
                else {
                    host?.compaction?.onFinalCompactionStatus?.(event);
                }
                onActivity?.(event);
            },
        };
        return {
            turnHost,
            onTraceEvent: (event) => {
                onTraceEvent?.(event);
            },
        };
    }
    static isConversationActivity(event) {
        return event.type !== HeddleEventType.trace
            && event.type !== HeddleEventType.loopResumed
            && event.type !== HeddleEventType.checkpointSaved;
    }
}
//# sourceMappingURL=host-normalizer.js.map