/**
 * gRPC Protocol for Clawx Agent Communication
 *
 * Replaces SSE/WebSocket with structured gRPC streaming
 */
// Helper functions for creating frames
export const GrpcFrames = {
    createRegister(agentId, agentName, endpoint, persona, capabilities = []) {
        return {
            id: `reg_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
            type: 'register',
            timestamp: Date.now(),
            fromAgentId: agentId,
            toAgentId: 'server',
            payload: {
                agentId,
                agentName,
                endpoint,
                persona,
                capabilities,
            },
        };
    },
    createRegistered(agentId, status, message, masterEndpoint) {
        return {
            id: `regack_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
            type: 'registered',
            timestamp: Date.now(),
            fromAgentId: 'server',
            toAgentId: agentId,
            payload: {
                agentId,
                status,
                message,
                masterEndpoint,
            },
        };
    },
    createHeartbeat(agentId) {
        return {
            id: `hb_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
            type: 'heartbeat',
            timestamp: Date.now(),
            fromAgentId: agentId,
            toAgentId: 'server',
        };
    },
    createAgentMessageStart(turnId, fromAgentId, toAgentId, persona) {
        return {
            id: `msg_start_${turnId}`,
            type: 'agent_message_start',
            timestamp: Date.now(),
            fromAgentId,
            toAgentId,
            parentOperationId: turnId,
            parentOperationType: 'chat',
            payload: {
                turnId,
                persona,
            },
        };
    },
    createAgentMessageDelta(turnId, fromAgentId, toAgentId, delta) {
        return {
            id: `msg_delta_${turnId}_${Date.now()}`,
            type: 'agent_message_delta',
            timestamp: Date.now(),
            fromAgentId,
            toAgentId,
            parentOperationId: turnId,
            parentOperationType: 'chat',
            payload: {
                turnId,
                delta,
            },
        };
    },
    createAgentMessageEnd(turnId, fromAgentId, toAgentId, finalMessage) {
        return {
            id: `msg_end_${turnId}`,
            type: 'agent_message_end',
            timestamp: Date.now(),
            fromAgentId,
            toAgentId,
            parentOperationId: turnId,
            parentOperationType: 'chat',
            payload: {
                turnId,
                finalMessage,
            },
        };
    },
    createTaskStarted(taskId, fromAgentId, toAgentId, tool, params) {
        return {
            id: `task_start_${taskId}`,
            type: 'task_started',
            timestamp: Date.now(),
            fromAgentId,
            toAgentId,
            parentOperationId: taskId,
            parentOperationType: 'task',
            payload: {
                taskId,
                tool,
                params,
            },
        };
    },
    createTaskProgress(taskId, fromAgentId, toAgentId, progress, message) {
        return {
            id: `task_prog_${taskId}_${Date.now()}`,
            type: 'task_progress',
            timestamp: Date.now(),
            fromAgentId,
            toAgentId,
            parentOperationId: taskId,
            parentOperationType: 'task',
            payload: {
                taskId,
                progress,
                message,
            },
        };
    },
    createToolStarted(taskId, fromAgentId, toAgentId, toolName, params, parentOperationType = 'task') {
        return {
            id: `tool_start_${taskId}_${Date.now()}`,
            type: 'tool_started',
            timestamp: Date.now(),
            fromAgentId,
            toAgentId,
            parentOperationId: taskId,
            parentOperationType,
            payload: {
                taskId,
                toolName,
                params,
            },
        };
    },
    createToolStdout(taskId, fromAgentId, toAgentId, data, parentOperationType = 'task') {
        return {
            id: `tool_stdout_${taskId}_${Date.now()}`,
            type: 'tool_stdout',
            timestamp: Date.now(),
            fromAgentId,
            toAgentId,
            parentOperationId: taskId,
            parentOperationType,
            payload: {
                taskId,
                data,
            },
        };
    },
    createToolStderr(taskId, fromAgentId, toAgentId, data, parentOperationType = 'task') {
        return {
            id: `tool_stderr_${taskId}_${Date.now()}`,
            type: 'tool_stderr',
            timestamp: Date.now(),
            fromAgentId,
            toAgentId,
            parentOperationId: taskId,
            parentOperationType,
            payload: {
                taskId,
                data,
            },
        };
    },
    createToolFinished(taskId, fromAgentId, toAgentId, result, parentOperationType = 'task') {
        return {
            id: `tool_finish_${taskId}`,
            type: 'tool_finished',
            timestamp: Date.now(),
            fromAgentId,
            toAgentId,
            parentOperationId: taskId,
            parentOperationType,
            payload: {
                taskId,
                result,
            },
        };
    },
    createTaskCompleted(taskId, fromAgentId, toAgentId, result) {
        return {
            id: `task_complete_${taskId}`,
            type: 'task_completed',
            timestamp: Date.now(),
            fromAgentId,
            toAgentId,
            parentOperationId: taskId,
            parentOperationType: 'task',
            payload: {
                taskId,
                result,
            },
        };
    },
    createTaskFailed(taskId, fromAgentId, toAgentId, error) {
        return {
            id: `task_fail_${taskId}`,
            type: 'task_failed',
            timestamp: Date.now(),
            fromAgentId,
            toAgentId,
            parentOperationId: taskId,
            parentOperationType: 'task',
            payload: {
                taskId,
                error,
            },
        };
    },
    createTaskCancelled(taskId, fromAgentId, toAgentId, reason) {
        return {
            id: `task_cancel_${taskId}`,
            type: 'task_cancelled',
            timestamp: Date.now(),
            fromAgentId,
            toAgentId,
            parentOperationId: taskId,
            parentOperationType: 'task',
            payload: {
                taskId,
                reason,
            },
        };
    },
    createChatMessage(fromAgentId, toAgentId, message, conversationId, extraPayload) {
        return {
            id: `chat_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
            type: 'chat_message',
            timestamp: Date.now(),
            fromAgentId,
            toAgentId,
            parentOperationId: conversationId,
            parentOperationType: 'chat',
            payload: {
                message,
                conversationId,
                ...(extraPayload || {}),
            },
        };
    },
    createSystemMessage(toAgentId, message, data) {
        return {
            id: `sys_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
            type: 'system',
            timestamp: Date.now(),
            fromAgentId: 'server',
            toAgentId,
            payload: {
                message,
                data,
            },
        };
    },
    createErrorMessage(toAgentId, error, fromAgentId = 'server') {
        return {
            id: `err_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
            type: 'error',
            timestamp: Date.now(),
            fromAgentId,
            toAgentId,
            error,
        };
    },
};
//# sourceMappingURL=protocol.js.map