/**
 * remote/gateway/render — turn a SessionEvent into chat-surface text.
 *
 * A chat platform wants milestones, not a token firehose. Noisy events
 * (`assistant.delta`, `run.step`, `state`, raw `tool.call.start`) are always
 * dropped; `tool.*` detail renders only in verbose mode. The result is a
 * short, human-readable line — or `null` to skip the event entirely.
 *
 * @public @since 2.14.0 — preste remote-control T4
 */
const DEFAULT_MAX = 3500;
/** Clip `s` to `max` characters with an ellipsis marker. */
export function truncate(s, max) {
    if (max <= 1)
        return s.slice(0, Math.max(0, max));
    return s.length <= max ? s : `${s.slice(0, max - 1)}…`;
}
/**
 * Render one SessionEvent as human-readable chat text — or `null` to skip.
 */
export function renderEventForChat(event, opts = {}) {
    const max = opts.maxChars ?? DEFAULT_MAX;
    const verbose = opts.verbose ?? false;
    switch (event.type) {
        case "run.start":
            return event.data.task
                ? `▶️ run started — ${truncate(event.data.task, 200)}`
                : "▶️ run started";
        case "assistant.message": {
            const c = event.data.content.trim();
            return c === "" ? null : truncate(c, max);
        }
        case "tool.intent":
            return verbose
                ? `🛠️ intends ${event.data.toolName}(${truncate(event.data.argsPreview, 160)})`
                : null;
        case "tool.call.end":
            return verbose
                ? `${event.data.ok ? "✓" : "✗"} ${event.data.toolName} — ${truncate(event.data.resultPreview, 200)}`
                : null;
        case "hitl.request":
            return `⚠️ approval needed: ${truncate(event.data.action, 200)}\n${truncate(event.data.context, 400)}\nreply /approve or /reject`;
        case "hitl.resolved":
            return `${event.data.approved ? "✅ approved" : "🛑 rejected"} by ${event.data.by}`;
        case "instruction.injected":
            // A whisper is out-of-band by design — do not echo it back to chat.
            return event.data.whisper
                ? null
                : `📨 instruction received: ${truncate(event.data.text, 200)}`;
        case "run.finished":
            return `⏹️ run finished (${event.data.stopReason}) — ${event.data.stepCount} steps, $${event.data.costUsd.toFixed(4)}`;
        default:
            // assistant.delta, run.step, tool.call.start, state — too noisy for chat.
            return null;
    }
}
//# sourceMappingURL=render.js.map