//#region src/tui/chat-history.ts
/** Replay persisted transcript into the scroll log (synthetic run ids per assistant row). */
function appendHistoryToChatLog(chatLog, messages, toolsExpanded) {
	chatLog.setToolsExpanded(toolsExpanded);
	messages.forEach((hm, idx) => {
		const runId = `history:${idx}`;
		if (hm.role === "user") {
			chatLog.addUser(hm.content);
			return;
		}
		if (hm.role === "system") {
			chatLog.addSystem(hm.content);
			return;
		}
		const tools = hm.toolCalls ?? [];
		for (let t = 0; t < tools.length; t++) {
			const tc = tools[t];
			const tid = `history:${idx}:t:${t}`;
			chatLog.startTool(tid, tc.name, tc.args ?? {}, runId);
			if (tc.result !== void 0) chatLog.updateToolResult(tid, tc.result, tc.isError ?? false);
		}
		const body = hm.content.trim() ? hm.content : " ";
		chatLog.finalizeAssistant(body, runId);
	});
}
//#endregion
export { appendHistoryToChatLog };

//# sourceMappingURL=chat-history.js.map