-
-
- {{ message.role }}
- {{ message.model || 'local' }}
-
-
-
-
-
- {{ attachment.filename }} · {{ attachment.width }}×{{ attachment.height }}
-
-
-
- Thinking · {{ thinkingDuration(message) }}
- {{ message.thinking?.content }}
-
-
-
-
-
+
+
+
+
+ {{ message.role }}
+ {{ message.model || 'local' }}
+
+
+
+
+
+
+ {{ block.language || 'code' }}
+
+
+ {{ block.code }}
+
+
+
+
+
+
+ {{ attachment.filename }} · {{ attachment.width }}×{{ attachment.height }}
+
+
+
+
+
+ Thinking...
+
+
+ Thought for {{ thinkingDuration(message) }}
+ {{ message.thinking.content || 'Thinking in progress' }}
+
+
+
+
+
+
+
+
+
+
+
+
`,
styles: [
`
- .thread { display: grid; gap: 1rem; align-content: start; }
+ .thread-shell { position: relative; min-height: 100%; height: 100%; }
+ .thread { display: grid; gap: 1rem; align-content: start; min-height: 0; max-height: 100%; overflow: auto; padding-right: 0.25rem; }
.bubble { max-width: 54rem; padding: 1rem 1.1rem; border-radius: 1.25rem; background: rgba(11, 27, 44, 0.88); border: 1px solid rgba(125, 211, 252, 0.12); box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18); }
.bubble--user { margin-left: auto; background: linear-gradient(135deg, rgba(8, 47, 73, 0.95), rgba(14, 116, 144, 0.7)); }
header, footer { display: flex; justify-content: space-between; gap: 1rem; color: #7dd3fc; font-size: 0.72rem; }
header { margin-bottom: 0.65rem; text-transform: uppercase; letter-spacing: 0.08em; }
- footer { margin-top: 0.9rem; color: #94a3b8; }
+ footer { margin-top: 0.9rem; color: #94a3b8; opacity: 0; transition: opacity 0.2s ease; }
+ .bubble:hover footer { opacity: 1; }
.content { color: #ecfeff; line-height: 1.6; }
.attachments { display: flex; gap: 0.8rem; flex-wrap: wrap; margin-top: 0.9rem; }
.attachment { width: min(16rem, 100%); margin: 0; display: grid; gap: 0.4rem; }
.attachment img { width: 100%; border-radius: 1rem; }
.attachment figcaption { color: #cbd5e1; font-size: 0.76rem; }
.thinking, .tool { margin-top: 0.85rem; padding-top: 0.85rem; border-top: 1px solid rgba(125, 211, 252, 0.12); color: #cbd5e1; }
+ .thinking { display: grid; gap: 0.5rem; }
+ .thinking__badge { display: inline-flex; width: fit-content; gap: 0.45rem; align-items: center; border-radius: 999px; padding: 0.3rem 0.65rem; background: rgba(15, 23, 42, 0.7); color: #f8fafc; }
+ .thinking__badge--active::before { content: ''; width: 0.55rem; height: 0.55rem; border-radius: 50%; background: #f59e0b; box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.5); animation: pulse 1.4s infinite; }
+ details summary { cursor: pointer; color: #e2e8f0; }
.tool { display: grid; gap: 0.65rem; }
.tool__block { display: grid; gap: 0.35rem; }
.tool__title { color: #f8fafc; font-weight: 700; }
- pre { margin: 0; overflow: auto; background: rgba(2, 6, 23, 0.6); padding: 0.85rem; border-radius: 0.8rem; white-space: pre-wrap; }
+ .code-block { margin-top: 0.9rem; overflow: hidden; border-radius: 0.95rem; border: 1px solid rgba(148, 163, 184, 0.16); background: rgba(2, 6, 23, 0.64); }
+ .code-block__bar { display: flex; justify-content: space-between; gap: 1rem; align-items: center; padding: 0.55rem 0.8rem; border-bottom: 1px solid rgba(148, 163, 184, 0.12); color: #cbd5e1; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; }
+ .code-block__copy { border: 1px solid rgba(148, 163, 184, 0.2); border-radius: 999px; background: rgba(15, 23, 42, 0.8); color: #e2e8f0; padding: 0.3rem 0.7rem; cursor: pointer; text-transform: none; letter-spacing: normal; }
+ pre { margin: 0; overflow: auto; padding: 0.85rem; white-space: pre-wrap; color: #f8fafc; }
+ .scroll-pill { position: absolute; right: 0.75rem; bottom: 0.75rem; border: 1px solid rgba(251, 191, 36, 0.28); border-radius: 999px; background: rgba(124, 45, 18, 0.92); color: #fde68a; padding: 0.75rem 1rem; cursor: pointer; box-shadow: 0 10px 24px rgba(0, 0, 0, 0.25); }
+ @keyframes pulse {
+ 0% { transform: scale(0.92); opacity: 0.75; }
+ 70% { transform: scale(1.08); opacity: 1; }
+ 100% { transform: scale(0.92); opacity: 0.75; }
+ }
`,
],
})
-export class MessageListComponent {
+export class MessageListComponent implements OnChanges, AfterViewChecked {
@Input() messages: ChatMessage[] = [];
+ @Input() streaming = false;
+
+ @ViewChild('viewport') private readonly viewport?: ElementRef
;
+
+ private pendingScroll = false;
+ pinnedToBottom = true;
constructor(private readonly sanitizer: DomSanitizer) {}
+ ngOnChanges(changes: SimpleChanges): void {
+ if (changes['messages'] || changes['streaming']) {
+ this.pendingScroll = true;
+ }
+ }
+
+ ngAfterViewChecked(): void {
+ if (this.pendingScroll) {
+ this.pendingScroll = false;
+ if (this.pinnedToBottom) {
+ queueMicrotask(() => this.scrollToBottom());
+ }
+ }
+ }
+
+ trackByMessage(_index: number, message: ChatMessage): string {
+ return message.id;
+ }
+
attachmentSource(attachment: ImageAttachment): string {
return `data:${attachment.mime_type};base64,${attachment.data}`;
}
@@ -78,13 +158,81 @@ export class MessageListComponent {
return duration > 0 ? `${(duration / 1000).toFixed(1)}s` : 'in progress';
}
- renderMarkdown(content: string): SafeHtml {
+ renderBlocks(content: string): RenderBlock[] {
+ const source = content ?? '';
+ if (!source.trim()) {
+ return [];
+ }
+
+ const blocks: RenderBlock[] = [];
+ const pattern = /```([\w-]+)?\n([\s\S]*?)```/g;
+ let lastIndex = 0;
+ let match: RegExpExecArray | null;
+
+ while ((match = pattern.exec(source)) !== null) {
+ const before = source.slice(lastIndex, match.index).trim();
+ if (before) {
+ blocks.push({ kind: 'text', html: this.renderInlineMarkdown(before) });
+ }
+ blocks.push({
+ kind: 'code',
+ language: match[1] ?? '',
+ code: match[2].replace(/\n+$/, ''),
+ });
+ lastIndex = pattern.lastIndex;
+ }
+
+ const after = source.slice(lastIndex).trim();
+ if (after) {
+ blocks.push({ kind: 'text', html: this.renderInlineMarkdown(after) });
+ }
+
+ if (blocks.length === 0) {
+ blocks.push({ kind: 'text', html: this.renderInlineMarkdown(source) });
+ }
+ return blocks;
+ }
+
+ copyCode(code: string): void {
+ if (!code) {
+ return;
+ }
+ if (navigator.clipboard?.writeText) {
+ void navigator.clipboard.writeText(code);
+ return;
+ }
+ const textarea = document.createElement('textarea');
+ textarea.value = code;
+ textarea.style.position = 'fixed';
+ textarea.style.opacity = '0';
+ document.body.appendChild(textarea);
+ textarea.focus();
+ textarea.select();
+ document.execCommand('copy');
+ document.body.removeChild(textarea);
+ }
+
+ onScroll(): void {
+ const element = this.viewport?.nativeElement;
+ if (!element) {
+ return;
+ }
+ const distanceFromBottom = element.scrollHeight - element.scrollTop - element.clientHeight;
+ this.pinnedToBottom = distanceFromBottom < 48;
+ }
+
+ scrollToBottom(): void {
+ const element = this.viewport?.nativeElement;
+ if (!element) {
+ return;
+ }
+ element.scrollTop = element.scrollHeight;
+ this.pinnedToBottom = true;
+ }
+
+ private renderInlineMarkdown(content: string): SafeHtml {
const escaped = this.escapeHTML(content ?? '');
- const blocks = escaped.replace(/```([\w-]+)?\n([\s\S]*?)```/g, (_, language, code) => {
- const label = language ? `${language}
` : '';
- return `${label}${code.trim()}
`;
- });
- const inline = blocks
+ const inline = escaped
.replace(/\*\*(.+?)\*\*/g, '$1')
.replace(/\*(.+?)\*/g, '$1')
.replace(/`([^`]+)`/g, '$1')
diff --git a/ui/src/chat/model-selector.component.ts b/ui/src/chat/model-selector.component.ts
index ca5149d1..e3298b3d 100644
--- a/ui/src/chat/model-selector.component.ts
+++ b/ui/src/chat/model-selector.component.ts
@@ -10,22 +10,29 @@ import { ModelEntry } from './chat.types';
template: `
`,
styles: [
`
.selector { display: grid; gap: 0.35rem; color: #cbd5e1; font-size: 0.82rem; }
+ .selector__row { display: flex; align-items: center; gap: 0.65rem; }
select { min-width: 18rem; border-radius: 0.8rem; border: 1px solid rgba(124, 156, 191, 0.2); background: rgba(8, 21, 35, 0.8); color: #e2e8f0; padding: 0.72rem 0.9rem; }
+ .spinner { width: 1rem; height: 1rem; border-radius: 999px; border: 2px solid rgba(148, 163, 184, 0.24); border-top-color: #f59e0b; animation: spin 0.8s linear infinite; }
+ @keyframes spin { to { transform: rotate(360deg); } }
`,
],
})
export class ModelSelectorComponent {
@Input() models: ModelEntry[] = [];
@Input() value = '';
+ @Input() loading = false;
@Output() valueChange = new EventEmitter();
}