6 directories, 29 files

tinai

Home / tinai
import { formatHistoryItem } from './util/conversation-format-utils.js';

/**
 * Class Conversation
 * Renders complete chat conversation histories into HTML by processing history turns with formatting utilities.
 */
class Conversation {

	/**
	 * Initializes a new instance of the Conversation class.
	 */
	constructor() {
	}

	/**
	 * Renders an entire conversation's history turns into an HTML string.
	 * @param {Object} conversation - The conversation object containing HISTORY array.
	 * @param {Object} [options={}] - Render options (e.g. show_suggested, show_related).
	 * @returns {string} The complete HTML string for the conversation.
	 */
	render(conversation, options = {}) {
		if (!conversation) return '<p>Enter a query to get started.</p>';
		const history = conversation.HISTORY || conversation.history || (Array.isArray(conversation) ? conversation : []);
		if (!Array.isArray(history) || history.length === 0) return '<p>Enter a query to get started.</p>';

		let html = '';
		history.forEach((data, index) => {
			html += formatHistoryItem(data, index, options);
		});
		return html;
	}
}

export default Conversation;
🌐
conversation.js ×
Type: Web, text/plain
1.11 Kilobytes
Last Modified 2026-09-23 02:24:21
⬇ Download File