import { classifyBrowserConsole } from "./classifiers/browser-console-classifier.js";
import { classifyEvidenceGap } from "./classifiers/evidence-gap-classifier.js";
import { classifyStalledRun } from "./classifiers/stalled-run-classifier.js";
export function createNoticerEngine() {
    const notices = [];
    const classifiers = [
        defaultClassifier,
    ];
    async function defaultClassifier(event) {
        switch (event.kind) {
            case "browser-observation":
                return classifyBrowserConsole(event.observation);
            case "goal-evidence":
                return classifyEvidenceGap(event.goal, event.evidence);
            case "run-state":
                return classifyStalledRun(event.runId, event.status, event.lastActivity);
            case "user-feedback":
                return classifyUserFeedback(event);
            default:
                return null;
        }
    }
    function classifyUserFeedback(event) {
        return {
            id: `ntc_uf_${Date.now()}`,
            createdAt: new Date().toISOString(),
            source: "user",
            type: "user-feedback",
            severity: "info",
            confidence: 1.0,
            summary: event.text.slice(0, 200),
            evidenceRefs: event.context ? [event.context] : [],
            suggestedAction: "ask-human",
        };
    }
    return {
        addClassifier(classifier) {
            classifiers.push(classifier);
        },
        async ingest(event) {
            const produced = [];
            for (const classifier of classifiers) {
                try {
                    const result = await classifier(event);
                    if (!result)
                        continue;
                    const batch = Array.isArray(result) ? result : [result];
                    for (const notice of batch) {
                        notices.push(notice);
                        produced.push(notice);
                    }
                }
                catch {
                    // classifier errors are swallowed to keep engine resilient
                }
            }
            return produced;
        },
        getNotices() {
            return [...notices];
        },
    };
}
