feat(web): add web demo and polish Lit web components UI and demo tooling
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @push.rocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartchat',
|
||||
version: '0.1.0',
|
||||
description: 'Interactive chat interfaces for AI agents — CLI TUI and web components, built on @push.rocks/smartagent.'
|
||||
}
|
||||
+101
-33
@@ -16,51 +16,100 @@ export class SmartchatInput extends LitElement {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.input-row {
|
||||
.input-wrap {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
align-items: flex-end;
|
||||
gap: 8px;
|
||||
padding: 8px;
|
||||
background: var(--smartchat-input-bg, #1f2937);
|
||||
border-radius: 8px;
|
||||
border: 1px solid var(--smartchat-input-border, #374151);
|
||||
padding: 10px 12px;
|
||||
background: rgba(255, 255, 255, 0.04);
|
||||
border-radius: 16px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.07);
|
||||
transition: border-color 0.2s ease, box-shadow 0.2s ease;
|
||||
}
|
||||
|
||||
.input-row:focus-within {
|
||||
border-color: var(--smartchat-input-focus, #6366f1);
|
||||
.input-wrap:focus-within {
|
||||
border-color: rgba(99, 102, 241, 0.45);
|
||||
box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.08);
|
||||
}
|
||||
|
||||
input {
|
||||
.input-wrap.disabled {
|
||||
opacity: 0.45;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
textarea {
|
||||
flex: 1;
|
||||
background: transparent;
|
||||
border: none;
|
||||
outline: none;
|
||||
color: var(--smartchat-input-text, #e5e7eb);
|
||||
color: #e4e4e7;
|
||||
font-size: 14px;
|
||||
font-family: inherit;
|
||||
line-height: 1.5;
|
||||
resize: none;
|
||||
min-height: 22px;
|
||||
max-height: 110px;
|
||||
padding: 2px 0;
|
||||
}
|
||||
|
||||
input::placeholder {
|
||||
color: var(--smartchat-input-placeholder, #6b7280);
|
||||
textarea::placeholder {
|
||||
color: rgba(255, 255, 255, 0.22);
|
||||
}
|
||||
|
||||
button {
|
||||
background: var(--smartchat-send-bg, #6366f1);
|
||||
color: var(--smartchat-send-text, #fff);
|
||||
.send-btn {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
border-radius: 50%;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
padding: 6px 16px;
|
||||
background: linear-gradient(135deg, #6366f1, #7c3aed);
|
||||
color: #fff;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-shrink: 0;
|
||||
transition: transform 0.12s ease, opacity 0.12s ease, box-shadow 0.12s ease;
|
||||
box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
|
||||
}
|
||||
|
||||
button:hover {
|
||||
opacity: 0.9;
|
||||
.send-btn:hover:not(:disabled) {
|
||||
transform: scale(1.08);
|
||||
box-shadow: 0 3px 12px rgba(99, 102, 241, 0.45);
|
||||
}
|
||||
|
||||
button:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
.send-btn:active:not(:disabled) {
|
||||
transform: scale(0.94);
|
||||
}
|
||||
|
||||
.send-btn:disabled {
|
||||
opacity: 0.25;
|
||||
cursor: default;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.send-btn svg {
|
||||
width: 15px;
|
||||
height: 15px;
|
||||
}
|
||||
|
||||
.hint {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
padding: 5px 2px 0;
|
||||
}
|
||||
|
||||
.hint-text {
|
||||
font-size: 10.5px;
|
||||
color: rgba(255, 255, 255, 0.13);
|
||||
}
|
||||
|
||||
kbd {
|
||||
padding: 0 3px;
|
||||
border-radius: 3px;
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
border: 1px solid rgba(255, 255, 255, 0.07);
|
||||
font-family: inherit;
|
||||
font-size: 10px;
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -71,13 +120,17 @@ export class SmartchatInput extends LitElement {
|
||||
}
|
||||
|
||||
private handleKeydown(e: KeyboardEvent) {
|
||||
if (e.key === 'Enter' && !e.shiftKey && this.value.trim()) {
|
||||
if (e.key === 'Enter' && !e.shiftKey) {
|
||||
e.preventDefault();
|
||||
this.submit();
|
||||
}
|
||||
}
|
||||
|
||||
private handleInput(e: Event) {
|
||||
this.value = (e.target as HTMLInputElement).value;
|
||||
const textarea = e.target as HTMLTextAreaElement;
|
||||
this.value = textarea.value;
|
||||
textarea.style.height = 'auto';
|
||||
textarea.style.height = Math.min(textarea.scrollHeight, 110) + 'px';
|
||||
}
|
||||
|
||||
private submit() {
|
||||
@@ -90,25 +143,40 @@ export class SmartchatInput extends LitElement {
|
||||
}),
|
||||
);
|
||||
this.value = '';
|
||||
const input = this.shadowRoot?.querySelector('input');
|
||||
if (input) input.value = '';
|
||||
const textarea = this.shadowRoot?.querySelector('textarea');
|
||||
if (textarea) {
|
||||
textarea.value = '';
|
||||
textarea.style.height = 'auto';
|
||||
}
|
||||
}
|
||||
|
||||
render(): TemplateResult {
|
||||
const canSend = !this.disabled && !!this.value.trim();
|
||||
return html`
|
||||
<div class="input-row">
|
||||
<input
|
||||
type="text"
|
||||
<div class="input-wrap ${this.disabled ? 'disabled' : ''}">
|
||||
<textarea
|
||||
rows="1"
|
||||
.value=${this.value}
|
||||
@input=${this.handleInput}
|
||||
@keydown=${this.handleKeydown}
|
||||
placeholder=${this.disabled ? 'Waiting for response...' : this.placeholder}
|
||||
?disabled=${this.disabled}
|
||||
/>
|
||||
<button @click=${this.submit} ?disabled=${this.disabled}>
|
||||
Send
|
||||
></textarea>
|
||||
<button
|
||||
class="send-btn"
|
||||
@click=${this.submit}
|
||||
?disabled=${!canSend}
|
||||
aria-label="Send message"
|
||||
>
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
|
||||
<line x1="12" y1="19" x2="12" y2="5"></line>
|
||||
<polyline points="5 12 12 5 19 12"></polyline>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
<div class="hint">
|
||||
<span class="hint-text"><kbd>Enter</kbd> send · <kbd>Shift+Enter</kbd> new line</span>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
||||
+138
-31
@@ -5,54 +5,138 @@ export class SmartchatMessage extends LitElement {
|
||||
declare role: 'user' | 'assistant' | 'tool';
|
||||
declare content: string;
|
||||
declare toolName: string;
|
||||
declare timestamp: number;
|
||||
|
||||
static properties = {
|
||||
role: { type: String },
|
||||
content: { type: String },
|
||||
toolName: { type: String },
|
||||
timestamp: { type: Number },
|
||||
};
|
||||
|
||||
static styles: CSSResult = css`
|
||||
:host {
|
||||
display: block;
|
||||
margin-bottom: 8px;
|
||||
animation: msg-in 0.3s ease-out both;
|
||||
}
|
||||
|
||||
.message {
|
||||
padding: 8px 12px;
|
||||
border-radius: 8px;
|
||||
max-width: 85%;
|
||||
word-wrap: break-word;
|
||||
@keyframes msg-in {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(6px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
/* ── Message Row ── */
|
||||
.row {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
align-items: flex-end;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.row.user {
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.row.assistant {
|
||||
justify-content: flex-start;
|
||||
}
|
||||
|
||||
/* ── Avatar ── */
|
||||
.avatar {
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 12px;
|
||||
flex-shrink: 0;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.avatar.user {
|
||||
background: linear-gradient(135deg, #3b82f6, #2563eb);
|
||||
color: #fff;
|
||||
order: 2;
|
||||
}
|
||||
|
||||
.avatar.assistant {
|
||||
background: linear-gradient(135deg, #6366f1, #7c3aed);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
/* ── Bubble ── */
|
||||
.bubble {
|
||||
padding: 10px 14px;
|
||||
border-radius: 18px;
|
||||
word-break: break-word;
|
||||
white-space: pre-wrap;
|
||||
font-size: 14px;
|
||||
line-height: 1.55;
|
||||
max-width: min(75%, 480px);
|
||||
}
|
||||
|
||||
.user {
|
||||
background: var(--smartchat-user-bubble, #2563eb);
|
||||
color: var(--smartchat-user-text, #fff);
|
||||
margin-left: auto;
|
||||
border-bottom-right-radius: 2px;
|
||||
.bubble.user {
|
||||
background: linear-gradient(135deg, #3b82f6, #2563eb);
|
||||
color: #fff;
|
||||
border-bottom-right-radius: 6px;
|
||||
}
|
||||
|
||||
.assistant {
|
||||
background: var(--smartchat-assistant-bubble, #374151);
|
||||
color: var(--smartchat-assistant-text, #e5e7eb);
|
||||
margin-right: auto;
|
||||
border-bottom-left-radius: 2px;
|
||||
.bubble.assistant {
|
||||
background: var(--smartchat-assistant-bg, #1e1e2e);
|
||||
border: 1px solid var(--smartchat-assistant-border, rgba(255, 255, 255, 0.08));
|
||||
color: var(--smartchat-assistant-text, #d1d5db);
|
||||
border-bottom-left-radius: 6px;
|
||||
}
|
||||
|
||||
.tool {
|
||||
background: var(--smartchat-tool-bubble, #1e293b);
|
||||
color: var(--smartchat-tool-text, #94a3b8);
|
||||
margin-right: auto;
|
||||
font-size: 0.85em;
|
||||
font-family: monospace;
|
||||
border-left: 3px solid var(--smartchat-tool-accent, #6366f1);
|
||||
/* ── Tool ── */
|
||||
.tool-row {
|
||||
display: flex;
|
||||
justify-content: flex-start;
|
||||
padding: 2px 0 2px 38px;
|
||||
}
|
||||
|
||||
.tool-pill {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
padding: 4px 10px;
|
||||
background: rgba(99, 102, 241, 0.1);
|
||||
border: 1px solid rgba(99, 102, 241, 0.15);
|
||||
border-radius: 20px;
|
||||
font-size: 11px;
|
||||
font-family: 'SF Mono', 'Fira Code', ui-monospace, monospace;
|
||||
color: #a5b4fc;
|
||||
}
|
||||
|
||||
.tool-icon {
|
||||
font-size: 10px;
|
||||
}
|
||||
|
||||
.tool-name {
|
||||
font-weight: bold;
|
||||
margin-bottom: 4px;
|
||||
color: var(--smartchat-tool-accent, #6366f1);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
/* ── Timestamp ── */
|
||||
.time-row {
|
||||
padding: 1px 38px 6px;
|
||||
font-size: 10px;
|
||||
color: rgba(255, 255, 255, 0.2);
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.time-row.user {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.time-row.assistant {
|
||||
text-align: left;
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -61,16 +145,39 @@ export class SmartchatMessage extends LitElement {
|
||||
this.role = 'user';
|
||||
this.content = '';
|
||||
this.toolName = '';
|
||||
this.timestamp = 0;
|
||||
}
|
||||
|
||||
private formatTime(ts: number): string {
|
||||
if (!ts) return '';
|
||||
const d = new Date(ts);
|
||||
return d.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
|
||||
}
|
||||
|
||||
render(): TemplateResult {
|
||||
if (this.role === 'tool') {
|
||||
return html`
|
||||
<div class="tool-row">
|
||||
<div class="tool-pill">
|
||||
<span class="tool-icon">⚡</span>
|
||||
<span class="tool-name">${this.toolName || 'tool'}</span>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
return html`
|
||||
<div class="message ${this.role}">
|
||||
${this.role === 'tool' && this.toolName
|
||||
? html`<div class="tool-name">${this.toolName}</div>`
|
||||
: ''}
|
||||
<div>${this.content}</div>
|
||||
<div class="row ${this.role}">
|
||||
<div class="avatar ${this.role}">
|
||||
${this.role === 'user' ? '⬆' : '✦'}
|
||||
</div>
|
||||
<div class="bubble ${this.role}">
|
||||
${this.content}
|
||||
</div>
|
||||
</div>
|
||||
${this.timestamp
|
||||
? html`<div class="time-row ${this.role}">${this.formatTime(this.timestamp)}</div>`
|
||||
: ''}
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
||||
+254
-34
@@ -7,11 +7,13 @@ interface IDisplayMessage {
|
||||
role: 'user' | 'assistant' | 'tool';
|
||||
content: string;
|
||||
toolName?: string;
|
||||
timestamp?: number;
|
||||
}
|
||||
|
||||
export class SmartchatWindow extends LitElement {
|
||||
declare chatSession: ChatSession;
|
||||
declare placeholder: string;
|
||||
declare headerTitle: string;
|
||||
private messages: IDisplayMessage[] = [];
|
||||
private busy = false;
|
||||
private streamingText = '';
|
||||
@@ -19,6 +21,7 @@ export class SmartchatWindow extends LitElement {
|
||||
static properties = {
|
||||
chatSession: { attribute: false },
|
||||
placeholder: { type: String },
|
||||
headerTitle: { type: String, attribute: 'header-title' },
|
||||
};
|
||||
|
||||
static styles: CSSResult = css`
|
||||
@@ -26,63 +29,244 @@ export class SmartchatWindow extends LitElement {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
background: var(--smartchat-bg, #111827);
|
||||
color: var(--smartchat-text, #e5e7eb);
|
||||
font-family: var(--smartchat-font, system-ui, -apple-system, sans-serif);
|
||||
border-radius: var(--smartchat-radius, 12px);
|
||||
background: var(--smartchat-bg, #0c0c14);
|
||||
color: var(--smartchat-text, #e4e4e7);
|
||||
font-family: var(--smartchat-font, 'Inter', system-ui, -apple-system, sans-serif);
|
||||
font-size: 14px;
|
||||
line-height: 1.6;
|
||||
border-radius: var(--smartchat-radius, 16px);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.message-list {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 16px;
|
||||
/* ── Header ── */
|
||||
.header {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 14px 20px;
|
||||
background: var(--smartchat-header-bg, rgba(255, 255, 255, 0.025));
|
||||
border-bottom: 1px solid rgba(255, 255, 255, 0.06);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
.header-icon {
|
||||
width: 34px;
|
||||
height: 34px;
|
||||
border-radius: 50%;
|
||||
background: linear-gradient(135deg, #6366f1, #7c3aed);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex: 1;
|
||||
color: var(--smartchat-muted, #6b7280);
|
||||
font-size: 14px;
|
||||
font-size: 15px;
|
||||
color: #fff;
|
||||
flex-shrink: 0;
|
||||
box-shadow: 0 2px 10px rgba(99, 102, 241, 0.35);
|
||||
}
|
||||
|
||||
.streaming {
|
||||
padding: 8px 12px;
|
||||
background: var(--smartchat-assistant-bubble, #374151);
|
||||
color: var(--smartchat-assistant-text, #e5e7eb);
|
||||
border-radius: 8px;
|
||||
border-bottom-left-radius: 2px;
|
||||
max-width: 85%;
|
||||
.header-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1px;
|
||||
}
|
||||
|
||||
.header-title {
|
||||
font-weight: 600;
|
||||
font-size: 14px;
|
||||
color: #f0f0f3;
|
||||
letter-spacing: -0.01em;
|
||||
}
|
||||
|
||||
.header-status {
|
||||
font-size: 11px;
|
||||
color: #71717a;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.status-dot {
|
||||
width: 7px;
|
||||
height: 7px;
|
||||
border-radius: 50%;
|
||||
background: #22c55e;
|
||||
box-shadow: 0 0 6px rgba(34, 197, 94, 0.5);
|
||||
}
|
||||
|
||||
.status-dot.busy {
|
||||
background: #f59e0b;
|
||||
box-shadow: 0 0 6px rgba(245, 158, 11, 0.5);
|
||||
animation: pulse-dot 1.4s ease-in-out infinite;
|
||||
}
|
||||
|
||||
@keyframes pulse-dot {
|
||||
0%, 100% { opacity: 1; }
|
||||
50% { opacity: 0.35; }
|
||||
}
|
||||
|
||||
/* ── Message List ── */
|
||||
.message-list {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 16px 20px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0;
|
||||
scroll-behavior: smooth;
|
||||
overscroll-behavior: contain;
|
||||
}
|
||||
|
||||
.message-list::-webkit-scrollbar {
|
||||
width: 5px;
|
||||
}
|
||||
|
||||
.message-list::-webkit-scrollbar-track {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.message-list::-webkit-scrollbar-thumb {
|
||||
background: rgba(255, 255, 255, 0.07);
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.message-list::-webkit-scrollbar-thumb:hover {
|
||||
background: rgba(255, 255, 255, 0.14);
|
||||
}
|
||||
|
||||
/* ── Empty State ── */
|
||||
.empty-state {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex: 1;
|
||||
gap: 14px;
|
||||
padding: 40px 20px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.empty-icon {
|
||||
width: 56px;
|
||||
height: 56px;
|
||||
border-radius: 50%;
|
||||
background: linear-gradient(135deg, rgba(99, 102, 241, 0.12), rgba(124, 58, 237, 0.06));
|
||||
border: 1px solid rgba(99, 102, 241, 0.12);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 22px;
|
||||
color: #818cf8;
|
||||
}
|
||||
|
||||
.empty-title {
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
color: #e4e4e7;
|
||||
}
|
||||
|
||||
.empty-subtitle {
|
||||
font-size: 13px;
|
||||
color: #52525b;
|
||||
max-width: 260px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
/* ── Streaming ── */
|
||||
.streaming-row {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
align-items: flex-end;
|
||||
margin-bottom: 4px;
|
||||
padding-top: 4px;
|
||||
}
|
||||
|
||||
.stream-avatar {
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
border-radius: 50%;
|
||||
background: linear-gradient(135deg, #6366f1, #7c3aed);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 12px;
|
||||
color: #fff;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.stream-bubble {
|
||||
background: #1e1e2e;
|
||||
border: 1px solid rgba(255, 255, 255, 0.08);
|
||||
color: #d1d5db;
|
||||
padding: 10px 14px;
|
||||
border-radius: 18px;
|
||||
border-bottom-left-radius: 6px;
|
||||
max-width: min(75%, 480px);
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
font-size: 14px;
|
||||
line-height: 1.55;
|
||||
}
|
||||
|
||||
.cursor {
|
||||
display: inline-block;
|
||||
width: 2px;
|
||||
height: 1em;
|
||||
background: var(--smartchat-cursor, #6366f1);
|
||||
animation: blink 1s step-end infinite;
|
||||
height: 1.1em;
|
||||
background: #818cf8;
|
||||
vertical-align: text-bottom;
|
||||
margin-left: 1px;
|
||||
animation: cursor-blink 0.8s step-end infinite;
|
||||
}
|
||||
|
||||
@keyframes blink {
|
||||
@keyframes cursor-blink {
|
||||
50% { opacity: 0; }
|
||||
}
|
||||
|
||||
/* ── Thinking Indicator ── */
|
||||
.thinking-bubble {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
padding: 12px 18px;
|
||||
background: #1e1e2e;
|
||||
border: 1px solid rgba(255, 255, 255, 0.08);
|
||||
border-radius: 18px;
|
||||
border-bottom-left-radius: 6px;
|
||||
}
|
||||
|
||||
.thinking-dot {
|
||||
width: 7px;
|
||||
height: 7px;
|
||||
border-radius: 50%;
|
||||
background: #6366f1;
|
||||
animation: thinking-bounce 1.4s ease-in-out infinite;
|
||||
}
|
||||
|
||||
.thinking-dot:nth-child(2) { animation-delay: 0.16s; }
|
||||
.thinking-dot:nth-child(3) { animation-delay: 0.32s; }
|
||||
|
||||
@keyframes thinking-bounce {
|
||||
0%, 60%, 100% {
|
||||
transform: translateY(0);
|
||||
opacity: 0.3;
|
||||
}
|
||||
30% {
|
||||
transform: translateY(-5px);
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* ── Input Area ── */
|
||||
.input-area {
|
||||
padding: 12px 16px;
|
||||
border-top: 1px solid var(--smartchat-border, #1f2937);
|
||||
padding: 12px 20px 16px;
|
||||
border-top: 1px solid rgba(255, 255, 255, 0.06);
|
||||
background: var(--smartchat-input-area-bg, rgba(255, 255, 255, 0.015));
|
||||
flex-shrink: 0;
|
||||
}
|
||||
`;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.placeholder = 'Type a message...';
|
||||
this.headerTitle = 'SmartChat';
|
||||
}
|
||||
|
||||
connectedCallback() {
|
||||
@@ -97,7 +281,7 @@ export class SmartchatWindow extends LitElement {
|
||||
onToolCall: (name: string) => {
|
||||
this.messages = [
|
||||
...this.messages,
|
||||
{ role: 'tool', content: '', toolName: name },
|
||||
{ role: 'tool', content: '', toolName: name, timestamp: Date.now() },
|
||||
];
|
||||
this.requestUpdate();
|
||||
this.scrollToBottom();
|
||||
@@ -119,7 +303,7 @@ export class SmartchatWindow extends LitElement {
|
||||
if (this.busy) return;
|
||||
|
||||
const text = e.detail.text;
|
||||
this.messages = [...this.messages, { role: 'user', content: text }];
|
||||
this.messages = [...this.messages, { role: 'user', content: text, timestamp: Date.now() }];
|
||||
this.busy = true;
|
||||
this.streamingText = '';
|
||||
this.requestUpdate();
|
||||
@@ -128,12 +312,12 @@ export class SmartchatWindow extends LitElement {
|
||||
try {
|
||||
const result = await this.chatSession.send(text);
|
||||
this.streamingText = '';
|
||||
this.messages = [...this.messages, { role: 'assistant', content: result.text }];
|
||||
this.messages = [...this.messages, { role: 'assistant', content: result.text, timestamp: Date.now() }];
|
||||
} catch (error) {
|
||||
const errMsg = error instanceof Error ? error.message : String(error);
|
||||
this.messages = [
|
||||
...this.messages,
|
||||
{ role: 'assistant', content: `Error: ${errMsg}` },
|
||||
{ role: 'assistant', content: `Error: ${errMsg}`, timestamp: Date.now() },
|
||||
];
|
||||
} finally {
|
||||
this.busy = false;
|
||||
@@ -144,9 +328,28 @@ export class SmartchatWindow extends LitElement {
|
||||
|
||||
render(): TemplateResult {
|
||||
return html`
|
||||
<div class="header">
|
||||
<div class="header-icon">✦</div>
|
||||
<div class="header-info">
|
||||
<div class="header-title">${this.headerTitle}</div>
|
||||
<div class="header-status">
|
||||
<span class="status-dot ${this.busy ? 'busy' : ''}"></span>
|
||||
${this.busy ? 'Thinking...' : 'Online'}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="message-list">
|
||||
${this.messages.length === 0 && !this.busy
|
||||
? html`<div class="empty-state">Start a conversation...</div>`
|
||||
? html`
|
||||
<div class="empty-state">
|
||||
<div class="empty-icon">✦</div>
|
||||
<div class="empty-title">Start a conversation</div>
|
||||
<div class="empty-subtitle">
|
||||
Send a message below to begin chatting.
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
: ''}
|
||||
${this.messages.map(
|
||||
(msg) => html`
|
||||
@@ -154,17 +357,34 @@ export class SmartchatWindow extends LitElement {
|
||||
role=${msg.role}
|
||||
content=${msg.content}
|
||||
.toolName=${msg.toolName ?? ''}
|
||||
.timestamp=${msg.timestamp ?? 0}
|
||||
></smartchat-message>
|
||||
`,
|
||||
)}
|
||||
${this.busy && this.streamingText
|
||||
? html`
|
||||
<div class="streaming">
|
||||
${this.streamingText}<span class="cursor"></span>
|
||||
<div class="streaming-row">
|
||||
<div class="stream-avatar">✦</div>
|
||||
<div class="stream-bubble">
|
||||
${this.streamingText}<span class="cursor"></span>
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
: ''}
|
||||
${this.busy && !this.streamingText
|
||||
? html`
|
||||
<div class="streaming-row">
|
||||
<div class="stream-avatar">✦</div>
|
||||
<div class="thinking-bubble">
|
||||
<span class="thinking-dot"></span>
|
||||
<span class="thinking-dot"></span>
|
||||
<span class="thinking-dot"></span>
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
: ''}
|
||||
</div>
|
||||
|
||||
<div class="input-area">
|
||||
<smartchat-input
|
||||
?disabled=${this.busy}
|
||||
|
||||
Reference in New Issue
Block a user