import { useCallback } from "react";
export function useAgentHeartbeatMessages(input) {
    const { agent, agentStubId, actions, messagesRef } = input;
    const stripHeartbeatMessages = useCallback((list) => {
        return list.filter((message) => message.messageType !== "heartbeat");
    }, []);
    const handleHeartbeatMessage = useCallback((message) => {
        const heartbeatText = (message.data?.message ||
            message.data?.Message ||
            "Still working on your request. This is taking a little longer than usual.").trim() ||
            "Still working on your request. This is taking a little longer than usual.";
        const createdDate = message.timestamp || new Date().toISOString();
        const heartbeatId = `heartbeat-${agent?.id || agentStubId}`;
        const heartbeatMessage = {
            id: heartbeatId,
            agentId: agent?.id || agentStubId,
            messageIndex: -1,
            role: "system",
            content: heartbeatText,
            name: "system",
            messageType: "heartbeat",
            isCompleted: true,
            model: "",
            tokensUsed: 0,
            inputTokens: 0,
            outputTokens: 0,
            cachedInputTokens: 0,
            inputTokenCost: 0,
            outputTokenCost: 0,
            cachedInputTokenCost: 0,
            totalCost: 0,
            currency: "USD",
            createdDate,
            toolCalls: [],
        };
        messagesRef.current = [
            ...stripHeartbeatMessages(messagesRef.current),
            heartbeatMessage,
        ];
        actions.heartbeatMessage(heartbeatMessage);
    }, [actions, agent?.id, agentStubId, messagesRef, stripHeartbeatMessages]);
    const clearHeartbeatMessages = useCallback(() => {
        const updated = stripHeartbeatMessages(messagesRef.current);
        if (updated.length !== messagesRef.current.length) {
            messagesRef.current = updated;
        }
        actions.clearHeartbeatMessages();
    }, [actions, messagesRef, stripHeartbeatMessages]);
    return {
        stripHeartbeatMessages,
        handleHeartbeatMessage,
        clearHeartbeatMessages,
    };
}
//# sourceMappingURL=useAgentHeartbeatMessages.js.map