export function convertPiAgentEventToStreamMessages(event, sessionId) {
    const results = [];
    switch (event.type) {
        case "message_update": {
            const assistantEvent = event.assistantMessageEvent;
            if (assistantEvent.type === "text_end" && assistantEvent.content) {
                results.push({
                    type: "assistant",
                    session_id: sessionId,
                    message: {
                        role: "assistant",
                        content: [{ type: "text", text: assistantEvent.content }],
                    },
                });
            }
            else if (assistantEvent.type === "thinking_end" && assistantEvent.content) {
                results.push({
                    type: "assistant",
                    session_id: sessionId,
                    message: {
                        role: "assistant",
                        content: [{ type: "thinking", thinking: assistantEvent.content }],
                    },
                });
            }
            break;
        }
        case "tool_execution_start": {
            results.push({
                type: "assistant",
                session_id: sessionId,
                message: {
                    role: "assistant",
                    content: [{
                            type: "tool_use",
                            id: event.toolCallId,
                            tool_use_id: event.toolCallId,
                            name: event.toolName,
                            input: event.args,
                        }],
                },
            });
            break;
        }
        case "tool_execution_end": {
            const rawResult = event.result;
            const resultContent = rawResult?.content;
            const textParts = Array.isArray(resultContent)
                ? resultContent
                    .filter((c) => c.type === "text")
                    .map((c) => c.text ?? "")
                    .join("\n")
                : typeof resultContent === "string" ? resultContent : JSON.stringify(resultContent);
            results.push({
                type: "user",
                session_id: sessionId,
                parent_tool_use_id: null,
                message: {
                    role: "user",
                    content: [{
                            type: "tool_result",
                            tool_use_id: event.toolCallId,
                            content: textParts,
                            is_error: event.isError,
                        }],
                },
            });
            break;
        }
    }
    return results;
}
//# sourceMappingURL=event-converter.js.map