2 directories, 29 files

tinai

Home / testing / ai / tinai
import Conversation from './conversation.js';
import { escapeHtml } from './util/format-utils.js';

/**
 * Class ScratchpadConversation
 * Handles formatting and rendering specifically for scratchpad conversation items.
 */
class ScratchpadConversation {

	#conversation;

	/**
	 * Initializes a new instance of ScratchpadConversation.
	 */
	constructor() {
		this.#conversation = new Conversation();
	}

	/**
	 * Formats a single scratchpad item as HTML.
	 * @param {Object} data - The data object for the scratchpad item.
	 * @param {number} index - The index of the item in history.
	 * @param {Object} [conversation_settings={}] - Settings for the conversation.
	 * @returns {string} The formatted HTML string.
	 */
	format_scratchpad_item(data, index, conversation_settings = {}) {
		if (!data) return '';

		let html = '';

		const rawTitle = data['summary'] || data.title || data.query || 'Scratchpad Entry';
		const titleText = escapeHtml(rawTitle);
		html += `<h3 class="scratchpad-header">${titleText}</h3>`;

		if (!data.pending) {
			html += `
				<div class="div-chat-response-buttons">
					<div class="div-chat-response-buttons-left">
						<button class="btn-copy-scratchpad" data-index="${index}">Copy</button>
					</div>
					<div class="div-chat-response-buttons-right">
						<button class="btn-redo-scratchpad" data-index="${index}">Redo</button>
						<button class="btn-undo-scratchpad" data-index="${index}">Undo</button>
						<button class="btn-delete-scratchpad" data-index="${index}">Delete</button>
					</div>
				</div>
			`;
		}

		html += this.#conversation.format_thinking_block(data.thinking, !!data.pending, index);

		if (data.pending) {
			return html;
		}

		let response_html = this.#conversation.format_content_block(data.content);
		response_html += this.#conversation.format_annotations_block(data.annotations);

		html += `<div class="div-response-content" data-index="${index}">${response_html}</div>`;
		html += this.#conversation.format_suggestions(data, conversation_settings);
		html += this.#conversation.format_cost_summary(data);

		return html;
	}
}

export default ScratchpadConversation;
🌐
scratchpad-conversation.js ×
Type: Web, text/plain
2.09 Kilobytes
Last Modified 2026-09-04 14:24:06
⬇ Download File