import { renderMarkdown, attachCopyButtons } from '../markdown.js'; import { icon } from '../icons.js'; const MAX_VISIBLE = 50; function escapeHtml(str) { return String(str) .replace(/&/g, '&') .replace(//g, '>') .replace(/"/g, '"'); } function getTextContent(message) { if (typeof message.content === 'string') return message.content; if (Array.isArray(message.content)) { const textParts = message.content.filter(p => p.type === 'text').map(p => p.text); return textParts.join('\n'); } return ''; } function getImageParts(message) { if (!Array.isArray(message.content)) return []; return message.content.filter(p => p.type === 'image_url'); } function getVideoParts(message) { if (!Array.isArray(message.content)) return []; return message.content.filter(p => p.type === 'video_url'); } function formatTime(iso) { try { return new Date(iso).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }); } catch { return ''; } } export class Chat { constructor() { this.el = null; this._messages = []; this._offset = 0; // how many messages we've hidden this._streamingEl = null; this._typingEl = null; this._errorEl = null; } render() { const el = document.createElement('div'); el.className = 'flex flex-col h-full'; el.innerHTML = `
直接开始提问,或先在 Settings 中配置模型与上下文限制。