/**
 * A2ACheckInProxy — Layer 4 orchestration (THREADLINE-A2A-COHERENCE-SPEC).
 *
 * Composes the decision (A2ACheckInPolicy) + the summarizer (A2ACheckInSummarizer) into one
 * flow, with dependencies INJECTED so it is testable without the server and decoupled from the
 * exact runtime wiring:
 *
 *   decideCheckIn → (salience|heartbeat) → getHistory → buildSummaryPrompt → summarize (LLM on
 *   the shared queue's BACKGROUND lane) → guardSummary → surface (to the bound topic, else hub).
 *
 * 'none' short-circuits before any LLM spend. A guard failure drops the check-in (never surfaces
 * an unsafe summary). The server provides the real deps:
 *   - summarize  → llmQueue.enqueue('background', signal => intelligence.evaluate(prompt, {signal}))
 *   - surface    → post to the bound Telegram topic, or CollaborationSurfacer.notify for the hub
 *   - getHistory → ConversationStore / buildHistoryContext for the thread
 * and the cadence (a jittered timer per active a2a thread) calls runCheckIn().
 */
import { decideCheckIn } from './A2ACheckInPolicy.js';
import { buildSummaryPrompt, guardSummary } from './A2ACheckInSummarizer.js';
/**
 * Decide → summarize → guard → surface. Never throws to the caller for an ordinary skip;
 * a dep that throws propagates (the cadence loop wraps this and continues).
 */
export async function runCheckIn(req, deps) {
    const decision = decideCheckIn({
        conversationActive: req.conversationActive,
        hasSalientEvent: req.hasSalientEvent,
        lastSurfaceAt: req.lastSurfaceAt,
        now: req.now,
        heartbeatIntervalMs: req.heartbeatIntervalMs,
        heartbeatEnabled: req.heartbeatEnabled,
    });
    if (decision.kind === 'none') {
        return { surfaced: false, kind: 'none', reason: decision.reason };
    }
    const history = String(await deps.getHistory(req.threadId));
    const prompt = buildSummaryPrompt({ peerName: req.peerName, historyText: history, kind: decision.kind });
    const raw = await deps.summarize(prompt);
    const guard = guardSummary(raw);
    if (!guard.safe) {
        // Drop the check-in: never surface an unsafe summary. (Caller may log guard.reason.)
        return { surfaced: false, kind: decision.kind, reason: `guard-blocked: ${guard.reason}` };
    }
    await deps.surface({
        threadId: req.threadId,
        topicId: req.topicId,
        peerName: req.peerName,
        body: guard.text,
        kind: decision.kind,
    });
    return { surfaced: true, kind: decision.kind, reason: decision.reason };
}
//# sourceMappingURL=A2ACheckInProxy.js.map