import { useCallback } from "react";
export function useAgentRunDeltaRouter(input) {
    const { agent, messagesRef, clearHeartbeatMessages, handleContentChunk, handleToolCall, handleToolResult, handleHeartbeatMessage, handleContextUpdate, appendToolUiEvent, } = input;
    return useCallback((delta) => {
        if (!agent) {
            return;
        }
        const agentStreamMessage = {
            type: delta.type,
            data: delta.data,
            cost: delta.cost,
            timestamp: new Date().toISOString(),
        };
        const shouldClearHeartbeat = delta.type === "ContentChunk" ||
            delta.type === "contentChunk" ||
            delta.type === "ToolCall" ||
            delta.type === "toolCall" ||
            delta.type === "ToolResult" ||
            delta.type === "toolResult";
        if (shouldClearHeartbeat) {
            clearHeartbeatMessages();
        }
        if (delta.type === "ContentChunk" || delta.type === "contentChunk") {
            handleContentChunk(agentStreamMessage, agent);
        }
        else if (delta.type === "ToolCall" || delta.type === "toolCall") {
            appendToolUiEvent("ui:tool-delta-received", `ToolCall:${String(delta.data?.functionName || delta.data?.name || delta.data?.displayName || "unknown")} messageId=${String(delta.data?.messageId || "none")} activeStreaming=${messagesRef.current.some((message) => !message.isCompleted && message.messageType === "streaming") ? "yes" : "no"}`, delta.seq ?? null);
            handleToolCall(agentStreamMessage, agent);
        }
        else if (delta.type === "ToolResult" || delta.type === "toolResult") {
            appendToolUiEvent("ui:tool-delta-received", `ToolResult:${String(delta.data?.functionName || delta.data?.name || delta.data?.displayName || "unknown")} messageId=${String(delta.data?.messageId || "none")} activeStreaming=${messagesRef.current.some((message) => !message.isCompleted && message.messageType === "streaming") ? "yes" : "no"}`, delta.seq ?? null);
            handleToolResult(agentStreamMessage, agent);
        }
        else if (delta.type === "Heartbeat" || delta.type === "heartbeat") {
            handleHeartbeatMessage(agentStreamMessage);
        }
        else if (delta.type === "ContextUpdate" ||
            delta.type === "contextUpdate") {
            handleContextUpdate(delta.data);
        }
    }, [
        agent,
        appendToolUiEvent,
        clearHeartbeatMessages,
        handleContentChunk,
        handleContextUpdate,
        handleHeartbeatMessage,
        handleToolCall,
        handleToolResult,
        messagesRef,
    ]);
}
//# sourceMappingURL=useAgentRunDeltaRouter.js.map