Calliope 1.2.0: agents, misc items, motion context, and queue timeout
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,271 @@
|
||||
<script lang="ts">
|
||||
import { assetUrl } from '$lib/api';
|
||||
import SafeMedia from '$lib/components/SafeMedia.svelte';
|
||||
import ImageLightbox from '$lib/components/ImageLightbox.svelte';
|
||||
import Icon from '$lib/components/ui/Icon.svelte';
|
||||
|
||||
export interface ArtifactJob {
|
||||
id: number;
|
||||
kind: string;
|
||||
status: string;
|
||||
output_paths?: string[];
|
||||
error?: string | null;
|
||||
}
|
||||
|
||||
interface Props {
|
||||
job: ArtifactJob;
|
||||
}
|
||||
|
||||
let { job }: Props = $props();
|
||||
|
||||
let preview = $state<{ src: string; kind: 'image' | 'video' } | null>(null);
|
||||
|
||||
const primaryPath = $derived(job.output_paths?.[0] ?? null);
|
||||
const primaryMedia = $derived(primaryPath ? assetUrl(primaryPath) : null);
|
||||
|
||||
function isVideoPath(path: string, kind: string): boolean {
|
||||
const lower = path.toLowerCase();
|
||||
return kind === 'video' || lower.endsWith('.mp4') || lower.endsWith('.webm');
|
||||
}
|
||||
|
||||
const isVideo = $derived(primaryPath ? isVideoPath(primaryPath, job.kind) : job.kind === 'video');
|
||||
|
||||
function statusWord(status: string): string {
|
||||
if (status === 'done') return 'Ready';
|
||||
if (status === 'running') return 'Generating';
|
||||
if (status === 'pending') return 'Queued';
|
||||
if (status === 'failed') return 'Failed';
|
||||
return status;
|
||||
}
|
||||
|
||||
const busy = $derived(job.status === 'pending' || job.status === 'running');
|
||||
const failed = $derived(job.status === 'failed');
|
||||
</script>
|
||||
|
||||
<div class="artifact" class:done={job.status === 'done'} class:failed>
|
||||
<div class="meta">
|
||||
<span class="id mono">#{job.id}</span>
|
||||
<span class="badge {job.status}">{statusWord(job.status)}</span>
|
||||
<span class="kind muted">
|
||||
<Icon name={job.kind === 'video' ? 'video' : 'image'} size={12} />
|
||||
{job.kind}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{#if busy}
|
||||
<div class="waiting" aria-busy="true">
|
||||
<span class="pulse"></span>
|
||||
<span class="waiting-text">{job.status === 'running' ? 'Generating…' : 'Queued'}</span>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if failed && job.error}
|
||||
<p class="err">{job.error}</p>
|
||||
{/if}
|
||||
|
||||
{#if primaryMedia && primaryPath}
|
||||
{#if isVideo}
|
||||
<button
|
||||
type="button"
|
||||
class="media-hit"
|
||||
aria-label="Play video, artifact {job.id}"
|
||||
title="Play in viewer"
|
||||
onclick={() => (preview = { src: primaryMedia, kind: 'video' })}
|
||||
>
|
||||
<div class="media-frame">
|
||||
<SafeMedia
|
||||
class="artifact-media"
|
||||
src={primaryMedia}
|
||||
kind="video"
|
||||
label="Video unavailable"
|
||||
controls={false}
|
||||
/>
|
||||
<span class="play-badge" aria-hidden="true"><Icon name="play" size={20} /></span>
|
||||
</div>
|
||||
</button>
|
||||
{:else}
|
||||
<button
|
||||
type="button"
|
||||
class="media-hit"
|
||||
aria-label="View image, artifact {job.id}"
|
||||
onclick={() => (preview = { src: primaryMedia, kind: 'image' })}
|
||||
>
|
||||
<div class="media-frame">
|
||||
<SafeMedia
|
||||
class="artifact-media"
|
||||
src={primaryMedia}
|
||||
alt="Artifact {job.id}"
|
||||
label="Image unavailable"
|
||||
/>
|
||||
</div>
|
||||
</button>
|
||||
{/if}
|
||||
{:else if job.status === 'done'}
|
||||
<div class="missing">
|
||||
<p>File missing on disk</p>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<ImageLightbox
|
||||
src={preview?.src ?? null}
|
||||
alt={`Artifact #${job.id}`}
|
||||
kind={preview?.kind ?? 'image'}
|
||||
onClose={() => (preview = null)}
|
||||
/>
|
||||
|
||||
<style>
|
||||
.artifact {
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius-md);
|
||||
background: var(--bg-surface);
|
||||
padding: 10px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
min-width: 0;
|
||||
max-width: 260px;
|
||||
overflow: hidden;
|
||||
}
|
||||
.artifact.done {
|
||||
border-color: color-mix(in srgb, var(--success) 30%, var(--border));
|
||||
}
|
||||
.artifact.failed {
|
||||
border-color: rgba(239, 68, 68, 0.4);
|
||||
}
|
||||
.meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
.id {
|
||||
font-size: 12px;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
.kind {
|
||||
font-size: 11px;
|
||||
margin-left: auto;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
}
|
||||
.badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
padding: 2px 8px;
|
||||
border-radius: 9999px;
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.badge.done {
|
||||
background: color-mix(in srgb, var(--success) 15%, transparent);
|
||||
color: var(--success);
|
||||
}
|
||||
.badge.failed {
|
||||
background: color-mix(in srgb, var(--error) 15%, transparent);
|
||||
color: var(--error);
|
||||
}
|
||||
.badge.pending,
|
||||
.badge.running {
|
||||
background: color-mix(in srgb, var(--warning) 15%, transparent);
|
||||
color: var(--warning);
|
||||
}
|
||||
.err {
|
||||
color: var(--error);
|
||||
font-size: 12px;
|
||||
margin: 0;
|
||||
}
|
||||
.waiting {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 6px 2px;
|
||||
}
|
||||
.waiting-text {
|
||||
font-size: 12.5px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
.pulse {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
flex-shrink: 0;
|
||||
border-radius: 9999px;
|
||||
background: var(--warning);
|
||||
animation: pulse 1.2s ease-in-out infinite;
|
||||
}
|
||||
@keyframes pulse {
|
||||
0%,
|
||||
100% {
|
||||
opacity: 0.4;
|
||||
}
|
||||
50% {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
.media-hit {
|
||||
padding: 0;
|
||||
border: none;
|
||||
background: transparent;
|
||||
cursor: zoom-in;
|
||||
display: block;
|
||||
width: 100%;
|
||||
}
|
||||
.media-hit:has(:global(video)) {
|
||||
cursor: pointer;
|
||||
}
|
||||
.media-hit:focus-visible {
|
||||
outline: 2px solid var(--accent);
|
||||
outline-offset: 2px;
|
||||
border-radius: var(--radius-sm);
|
||||
}
|
||||
.media-frame {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
aspect-ratio: 4 / 3;
|
||||
border-radius: var(--radius-sm);
|
||||
overflow: hidden;
|
||||
background: var(--bg-elevated);
|
||||
}
|
||||
.media-frame :global(.artifact-media),
|
||||
.media-frame :global(img),
|
||||
.media-frame :global(video) {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
display: block;
|
||||
border-radius: 0;
|
||||
}
|
||||
.play-badge {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
pointer-events: none;
|
||||
}
|
||||
.play-badge::before {
|
||||
content: '';
|
||||
width: 44px;
|
||||
height: 44px;
|
||||
border-radius: 9999px;
|
||||
background: rgba(0, 0, 0, 0.55);
|
||||
box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.18);
|
||||
}
|
||||
.play-badge :global(svg) {
|
||||
position: absolute;
|
||||
color: #fff;
|
||||
fill: currentColor;
|
||||
filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.6));
|
||||
margin-left: 2px;
|
||||
}
|
||||
.missing {
|
||||
padding: 10px;
|
||||
border-radius: var(--radius-sm);
|
||||
background: var(--bg-elevated);
|
||||
color: var(--text-muted);
|
||||
font-size: 12.5px;
|
||||
}
|
||||
.missing p {
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,511 @@
|
||||
<script lang="ts">
|
||||
import type { AgentMessage, Job } from '$lib/api';
|
||||
import { assetUrl } from '$lib/api';
|
||||
import type { WorkflowMention } from '$lib/agentComposer';
|
||||
import AgentToolCard from './AgentToolCard.svelte';
|
||||
import AgentArtifactCard, { type ArtifactJob } from './AgentArtifactCard.svelte';
|
||||
import ReasoningPanel from './ReasoningPanel.svelte';
|
||||
import { agentColor, agentDisplayName } from './agentPalette';
|
||||
import Icon from '$lib/components/ui/Icon.svelte';
|
||||
|
||||
interface Props {
|
||||
messages: AgentMessage[];
|
||||
/** In-flight tool calls for the current turn (from agent.tool SSE). */
|
||||
liveTools: { tool: string; args?: Record<string, unknown> | null; result?: unknown; phase: 'running' | 'done' | 'error' }[];
|
||||
/** Streaming assistant text for the current turn (from agent.token SSE). */
|
||||
streaming: string;
|
||||
/** Streaming reasoning text for the current turn (from agent.thinking SSE). */
|
||||
streamingReasoning: string;
|
||||
/** Live jobs for the linked project (to resolve enqueued artifacts). */
|
||||
jobs?: Job[];
|
||||
running: boolean;
|
||||
/** Welcome suggestions shown only on an empty (new-chat) timeline. */
|
||||
suggestions?: { label: string; prompt: string }[];
|
||||
/** True while the selected session's history is still fetching. */
|
||||
loading?: boolean;
|
||||
/** Called with a suggestion's prompt to pre-fill the composer. */
|
||||
onSuggestion?: (prompt: string) => void;
|
||||
}
|
||||
|
||||
let {
|
||||
messages,
|
||||
liveTools,
|
||||
streaming,
|
||||
streamingReasoning,
|
||||
jobs = [],
|
||||
running,
|
||||
suggestions = [],
|
||||
loading = false,
|
||||
onSuggestion,
|
||||
}: Props = $props();
|
||||
|
||||
let listEl = $state<HTMLDivElement | null>(null);
|
||||
let pinned = $state(true);
|
||||
|
||||
// Derived tool rows carry no status — infer failure from the result shape,
|
||||
// same as the live SSE path does.
|
||||
function toolPhase(m: AgentMessage): 'done' | 'error' {
|
||||
if (m.status === 'error') return 'error';
|
||||
const r = m.tool_result as { ok?: boolean } | null | undefined;
|
||||
return r && typeof r === 'object' && r.ok === false ? 'error' : 'done';
|
||||
}
|
||||
|
||||
// Tool results that enqueue render jobs expose their job ids — these render
|
||||
// as inline artifact cards (Playground-style) that track live job status.
|
||||
const ENQUEUE_TOOLS = new Set(['enqueue_asset_jobs', 'enqueue_video_jobs', 'run_workflow']);
|
||||
const jobsById = $derived(new Map((jobs ?? []).map((j) => [j.id, j])));
|
||||
|
||||
/** Later tool results (wait_for_jobs) often have the finished status + paths. */
|
||||
const trailJobsById = $derived.by(() => {
|
||||
const map = new Map<number, ArtifactJob>();
|
||||
for (const row of messages) {
|
||||
if (row.role !== 'tool' || !row.tool_result || typeof row.tool_result !== 'object') continue;
|
||||
const listed = (row.tool_result as { jobs?: unknown }).jobs;
|
||||
if (!Array.isArray(listed)) continue;
|
||||
for (const raw of listed) {
|
||||
if (!raw || typeof raw !== 'object') continue;
|
||||
const j = raw as ArtifactJob;
|
||||
if (typeof j.id !== 'number') continue;
|
||||
const prev = map.get(j.id);
|
||||
map.set(j.id, prev ? { ...prev, ...j } : j);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
});
|
||||
|
||||
function artifactJobs(m: AgentMessage): ArtifactJob[] {
|
||||
const result = m.tool_result;
|
||||
if (!result || typeof result !== 'object') return [];
|
||||
const stubs = (result as { jobs?: unknown }).jobs;
|
||||
if (!Array.isArray(stubs)) return [];
|
||||
return stubs
|
||||
.filter((j) => j && typeof j === 'object' && typeof (j as { id?: unknown }).id === 'number')
|
||||
.map((j) => {
|
||||
const stub = j as ArtifactJob;
|
||||
return jobsById.get(stub.id) ?? trailJobsById.get(stub.id) ?? {
|
||||
id: stub.id,
|
||||
kind: stub.kind ?? 'image',
|
||||
status: stub.status ?? 'pending',
|
||||
output_paths: stub.output_paths,
|
||||
error: stub.error,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
// Keep pinned to bottom on new content unless the user scrolled up.
|
||||
$effect(() => {
|
||||
void messages.length;
|
||||
void streaming;
|
||||
void streamingReasoning;
|
||||
void liveTools.length;
|
||||
void jobs.length;
|
||||
if (listEl && pinned) {
|
||||
requestAnimationFrame(() => {
|
||||
listEl?.scrollTo({ top: listEl.scrollHeight });
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function onScroll() {
|
||||
const el = listEl;
|
||||
if (!el) return;
|
||||
pinned = el.scrollHeight - el.scrollTop - el.clientHeight < 60;
|
||||
}
|
||||
|
||||
function escapeRegExp(s: string): string {
|
||||
return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||
}
|
||||
|
||||
function bubbleParts(
|
||||
content: string,
|
||||
mentions: WorkflowMention[],
|
||||
): Array<{ type: 'text' | 'chip'; text: string }> {
|
||||
if (!mentions.length) return [{ type: 'text', text: content }];
|
||||
const names = [...new Set(mentions.map((m) => m.name).filter(Boolean))].sort(
|
||||
(a, b) => b.length - a.length,
|
||||
);
|
||||
if (names.length === 0) return [{ type: 'text', text: content }];
|
||||
const re = new RegExp(`(@(?:${names.map(escapeRegExp).join('|')}))`, 'g');
|
||||
const parts: Array<{ type: 'text' | 'chip'; text: string }> = [];
|
||||
let last = 0;
|
||||
for (const match of content.matchAll(re)) {
|
||||
const idx = match.index ?? 0;
|
||||
if (idx > last) parts.push({ type: 'text', text: content.slice(last, idx) });
|
||||
parts.push({ type: 'chip', text: match[1] ?? '' });
|
||||
last = idx + (match[0]?.length ?? 0);
|
||||
}
|
||||
if (last < content.length) parts.push({ type: 'text', text: content.slice(last) });
|
||||
return parts.length ? parts : [{ type: 'text', text: content }];
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="chat" bind:this={listEl} onscroll={onScroll}>
|
||||
{#if loading}
|
||||
<div class="empty">
|
||||
<p class="empty-hint">Loading chat…</p>
|
||||
</div>
|
||||
{:else if messages.length === 0 && !running}
|
||||
<div class="empty">
|
||||
<div class="empty-mark"><Icon name="sparkle" size={22} /></div>
|
||||
<p class="empty-eyebrow">Calliope</p>
|
||||
<p class="empty-title">What are we making?</p>
|
||||
<p class="empty-hint">
|
||||
Tell your production agent the idea and it takes the story to script to video — or ask it to
|
||||
work on one of your projects.
|
||||
</p>
|
||||
{#if suggestions.length > 0}
|
||||
<div class="suggestions">
|
||||
{#each suggestions as s (s.label)}
|
||||
<button type="button" class="suggestion" onclick={() => onSuggestion?.(s.prompt)}>
|
||||
{s.label}
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#each messages as m (m.id)}
|
||||
{#if m.role === 'user'}
|
||||
<div class="row user">
|
||||
<div class="bubble user-bubble">
|
||||
{#if (m.attachments ?? []).length > 0}
|
||||
<div class="user-thumbs">
|
||||
{#each (m.attachments ?? []) as a (a.path)}
|
||||
{@const href = assetUrl(a.path)}
|
||||
{#if a.kind === 'image' && href}
|
||||
<img class="user-thumb" src={href} alt={a.name} />
|
||||
{:else}
|
||||
<span class="user-thumb file" title={a.name}>
|
||||
<Icon name={a.kind === 'audio' ? 'music' : 'video'} size={14} />
|
||||
</span>
|
||||
{/if}
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
<span class="user-text">
|
||||
{#each bubbleParts(m.content, (m.mentions ?? []) as WorkflowMention[]) as part, i (`${i}-${part.type}`)}
|
||||
{#if part.type === 'chip'}
|
||||
<span class="wf-chip">{part.text}</span>
|
||||
{:else}{part.text}{/if}
|
||||
{/each}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
{:else if m.role === 'tool'}
|
||||
<div class="row tool-row">
|
||||
<AgentToolCard
|
||||
name={m.tool_name ?? 'tool'}
|
||||
args={m.tool_args}
|
||||
result={m.tool_result}
|
||||
phase={toolPhase(m)}
|
||||
/>
|
||||
{#if m.tool_name && ENQUEUE_TOOLS.has(m.tool_name)}
|
||||
{@const arts = artifactJobs(m)}
|
||||
{#if arts.length > 0}
|
||||
<div class="artifacts">
|
||||
{#each arts as job (job.id)}
|
||||
<AgentArtifactCard {job} />
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
{/if}
|
||||
</div>
|
||||
{:else if m.role === 'assistant'}
|
||||
{@const color = agentColor(m.agent_name)}
|
||||
<div class="row assistant" style:--agent={color}>
|
||||
<div class="agent-tag">
|
||||
<span class="agent-dot" style:background={color}></span>
|
||||
{agentDisplayName(m.agent_name)}
|
||||
</div>
|
||||
{#if m.reasoning}
|
||||
<div class="reasoning-wrap">
|
||||
<ReasoningPanel reasoning={m.reasoning} />
|
||||
</div>
|
||||
{/if}
|
||||
<div
|
||||
class="bubble assistant-bubble"
|
||||
class:err={m.status === 'error' || m.status === 'cancelled'}
|
||||
>
|
||||
{m.content}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
{/each}
|
||||
|
||||
{#if running}
|
||||
<div class="row assistant" style:--agent={agentColor(null)}>
|
||||
<div class="agent-tag">
|
||||
<span class="agent-dot" style:background={agentColor(null)}></span>
|
||||
{agentDisplayName(null)}
|
||||
</div>
|
||||
<div class="bubble assistant-bubble live">
|
||||
{#if liveTools.length > 0}
|
||||
<div class="tools">
|
||||
{#each liveTools as t, i (i)}
|
||||
<AgentToolCard name={t.tool} args={t.args} result={t.result} phase={t.phase} />
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
{#if streaming}
|
||||
<div class="stream-text">{streaming}<span class="caret"></span></div>
|
||||
{:else}
|
||||
<div class="thinking"><span class="pulse"></span> working…</div>
|
||||
{/if}
|
||||
{#if streamingReasoning}
|
||||
<ReasoningPanel streaming={streamingReasoning} />
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.chat {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
min-width: 0;
|
||||
width: 100%;
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 14px;
|
||||
padding: 4px 4px 12px;
|
||||
}
|
||||
.empty {
|
||||
margin: auto;
|
||||
max-width: 540px;
|
||||
text-align: center;
|
||||
color: var(--text-muted);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 40px 16px;
|
||||
}
|
||||
.empty-mark {
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
border-radius: var(--radius-md);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: var(--accent);
|
||||
background:
|
||||
radial-gradient(circle at 30% 25%, rgba(139, 92, 246, 0.35) 0%, transparent 60%),
|
||||
var(--bg-elevated);
|
||||
border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
|
||||
box-shadow: 0 0 32px var(--accent-glow);
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
.empty-eyebrow {
|
||||
margin: 0;
|
||||
font-family: var(--font-display);
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.28em;
|
||||
text-transform: uppercase;
|
||||
color: var(--accent);
|
||||
}
|
||||
.empty-title {
|
||||
margin: 0;
|
||||
font-family: var(--font-display);
|
||||
font-size: 26px;
|
||||
font-weight: 700;
|
||||
letter-spacing: -0.02em;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
.empty-hint {
|
||||
margin: 0;
|
||||
font-size: 13.5px;
|
||||
line-height: 1.6;
|
||||
max-width: 420px;
|
||||
}
|
||||
.suggestions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
margin-top: 16px;
|
||||
}
|
||||
.suggestion {
|
||||
border: 1px solid var(--border);
|
||||
background: var(--bg-surface);
|
||||
color: var(--text-secondary);
|
||||
border-radius: 999px;
|
||||
padding: 8px 16px;
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
font-family: inherit;
|
||||
cursor: pointer;
|
||||
transition: all 0.15s;
|
||||
}
|
||||
.suggestion:hover {
|
||||
color: var(--text-primary);
|
||||
border-color: var(--accent);
|
||||
background: color-mix(in srgb, var(--accent) 12%, var(--bg-surface));
|
||||
}
|
||||
.suggestion:focus-visible {
|
||||
outline: 2px solid var(--accent);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
.row {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.row.user {
|
||||
align-items: flex-end;
|
||||
}
|
||||
.row.assistant {
|
||||
align-items: flex-start;
|
||||
}
|
||||
.row.tool-row {
|
||||
align-items: flex-start;
|
||||
padding-left: 6px;
|
||||
width: 100%;
|
||||
}
|
||||
.agent-tag {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-size: 11px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.06em;
|
||||
text-transform: uppercase;
|
||||
color: var(--agent, var(--accent));
|
||||
margin-bottom: 4px;
|
||||
padding-left: 2px;
|
||||
}
|
||||
.agent-dot {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 999px;
|
||||
flex-shrink: 0;
|
||||
box-shadow: 0 0 0 2px color-mix(in srgb, var(--agent, var(--accent)) 25%, transparent);
|
||||
}
|
||||
.reasoning-wrap {
|
||||
margin-bottom: 4px;
|
||||
max-width: 86%;
|
||||
}
|
||||
.bubble {
|
||||
max-width: 86%;
|
||||
border-radius: var(--radius-md);
|
||||
padding: 10px 14px;
|
||||
font-size: 13.5px;
|
||||
line-height: 1.6;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
}
|
||||
.user-bubble {
|
||||
background: color-mix(in srgb, var(--accent) 16%, var(--bg-surface));
|
||||
border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
.user-thumbs {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.user-thumb {
|
||||
display: block;
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
object-fit: cover;
|
||||
border-radius: var(--radius-sm);
|
||||
border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
|
||||
background: var(--bg-elevated);
|
||||
}
|
||||
.user-thumb.file {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
.user-text {
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
.wf-chip {
|
||||
display: inline;
|
||||
padding: 1px 7px;
|
||||
margin: 0 1px;
|
||||
border-radius: 999px;
|
||||
background: color-mix(in srgb, var(--accent) 22%, var(--bg-elevated));
|
||||
border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
|
||||
color: var(--accent);
|
||||
font-weight: 600;
|
||||
font-size: 13px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.assistant-bubble {
|
||||
background: var(--bg-surface);
|
||||
border: 1px solid var(--border);
|
||||
border-left: 3px solid var(--agent, var(--accent));
|
||||
color: var(--text-primary);
|
||||
}
|
||||
.assistant-bubble.err {
|
||||
border-color: rgba(239, 68, 68, 0.4);
|
||||
border-left-color: rgba(239, 68, 68, 0.6);
|
||||
color: var(--error);
|
||||
}
|
||||
.bubble.live {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
max-width: 92%;
|
||||
width: 100%;
|
||||
}
|
||||
.tools {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
}
|
||||
.artifacts {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
margin-top: 8px;
|
||||
padding-left: 4px;
|
||||
}
|
||||
.stream-text {
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
.caret {
|
||||
display: inline-block;
|
||||
width: 7px;
|
||||
height: 14px;
|
||||
margin-left: 2px;
|
||||
background: var(--accent);
|
||||
animation: blink 1s step-end infinite;
|
||||
vertical-align: text-bottom;
|
||||
}
|
||||
@keyframes blink {
|
||||
50% {
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
.thinking {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
color: var(--text-secondary);
|
||||
font-size: 13px;
|
||||
}
|
||||
.pulse {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 999px;
|
||||
background: var(--accent);
|
||||
animation: pulse 1.1s ease-in-out infinite;
|
||||
}
|
||||
@keyframes pulse {
|
||||
0%,
|
||||
100% {
|
||||
opacity: 0.35;
|
||||
}
|
||||
50% {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,668 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
MAX_WORKFLOW_MENTIONS,
|
||||
filterWorkflows,
|
||||
payloadIsEmpty,
|
||||
type AgentAttachment,
|
||||
type AgentComposerPayload,
|
||||
type AttachmentKind,
|
||||
type WorkflowMention,
|
||||
type WorkflowOption,
|
||||
} from '$lib/agentComposer';
|
||||
import { assetUrl } from '$lib/api';
|
||||
import Icon from '$lib/components/ui/Icon.svelte';
|
||||
import { createUploadManager, truncateMiddle } from '$lib/comfy/useUpload.svelte';
|
||||
import { toast } from '$lib/toast';
|
||||
import WorkflowMentionMenu from './WorkflowMentionMenu.svelte';
|
||||
|
||||
interface Props {
|
||||
running: boolean;
|
||||
onSend: (payload: AgentComposerPayload) => void;
|
||||
onCancel: () => void;
|
||||
/** Text to pre-fill into the composer (deep-link handoff or a suggestion). */
|
||||
draft?: string;
|
||||
/** Bumps to re-apply `draft` (including the empty string) and refocus. */
|
||||
draftNonce?: number;
|
||||
/** Enabled ComfyUI workflows for the `@` typeahead. */
|
||||
workflows?: WorkflowOption[];
|
||||
}
|
||||
|
||||
let {
|
||||
running,
|
||||
onSend,
|
||||
onCancel,
|
||||
draft = '',
|
||||
draftNonce = 0,
|
||||
workflows = [],
|
||||
}: Props = $props();
|
||||
|
||||
const ATTACH_LIMIT = 8;
|
||||
const ACCEPT = 'image/*,video/*,audio/*,.png,.jpg,.jpeg,.webp,.gif,.mp4,.webm,.mov,.mkv,.mp3,.wav,.flac,.ogg,.m4a';
|
||||
|
||||
let editorEl = $state<HTMLDivElement | null>(null);
|
||||
let fileInput = $state<HTMLInputElement | null>(null);
|
||||
let editorEmpty = $state(true);
|
||||
let dragOver = $state(false);
|
||||
let attachments = $state<AgentAttachment[]>([]);
|
||||
let uploadingNames = $state<string[]>([]);
|
||||
|
||||
let mentionOpen = $state(false);
|
||||
let mentionQuery = $state('');
|
||||
let mentionIndex = $state(0);
|
||||
let mentionAnchor = $state({ top: 0, bottom: 0, left: 0 });
|
||||
let mentionLocked = $state(false);
|
||||
|
||||
const uploads = createUploadManager();
|
||||
const mentionItems = $derived(filterWorkflows(workflows, mentionQuery));
|
||||
const busy = $derived(running || uploadingNames.length > 0);
|
||||
const sendable = $derived(!busy && (!editorEmpty || attachments.length > 0));
|
||||
|
||||
$effect(() => {
|
||||
void draftNonce;
|
||||
if (draftNonce === 0) return;
|
||||
if (!editorEl) return;
|
||||
editorEl.textContent = draft;
|
||||
placeCaretAtEnd(editorEl);
|
||||
editorEl.focus();
|
||||
syncEmpty();
|
||||
});
|
||||
|
||||
$effect(() => {
|
||||
void mentionItems.length;
|
||||
if (mentionIndex >= mentionItems.length) mentionIndex = Math.max(0, mentionItems.length - 1);
|
||||
});
|
||||
|
||||
$effect(() => {
|
||||
if (!mentionOpen) return;
|
||||
function onDocDown(e: MouseEvent) {
|
||||
const t = e.target as Node | null;
|
||||
if (editorEl?.contains(t)) return;
|
||||
if (t instanceof Element && t.closest('.mention-menu')) return;
|
||||
mentionOpen = false;
|
||||
}
|
||||
document.addEventListener('mousedown', onDocDown);
|
||||
return () => document.removeEventListener('mousedown', onDocDown);
|
||||
});
|
||||
|
||||
function syncEmpty() {
|
||||
if (!editorEl) {
|
||||
editorEmpty = true;
|
||||
return;
|
||||
}
|
||||
editorEmpty = editorEl.innerText.replace(/\u00a0/g, ' ').trim().length === 0
|
||||
&& !editorEl.querySelector('.wf-chip');
|
||||
}
|
||||
|
||||
function serialize(): { content: string; mentions: WorkflowMention[] } {
|
||||
if (!editorEl) return { content: '', mentions: [] };
|
||||
const mentions: WorkflowMention[] = [];
|
||||
let content = '';
|
||||
const walk = (node: Node) => {
|
||||
if (node.nodeType === Node.TEXT_NODE) {
|
||||
content += node.textContent ?? '';
|
||||
return;
|
||||
}
|
||||
if (node instanceof HTMLElement && node.classList.contains('wf-chip')) {
|
||||
const id = Number(node.dataset.workflowId);
|
||||
const name = node.dataset.workflowName ?? node.textContent?.replace(/^@/, '') ?? '';
|
||||
const kind = node.dataset.workflowKind === 'video' ? 'video' : 'image';
|
||||
if (Number.isFinite(id) && name) {
|
||||
mentions.push({ type: 'workflow', id, name, kind });
|
||||
}
|
||||
content += `@${name}`;
|
||||
return;
|
||||
}
|
||||
if (node instanceof HTMLElement && (node.tagName === 'BR' || node.tagName === 'DIV' || node.tagName === 'P')) {
|
||||
if (node !== editorEl && content.length > 0 && !content.endsWith('\n')) content += '\n';
|
||||
}
|
||||
for (const child of Array.from(node.childNodes)) walk(child);
|
||||
};
|
||||
walk(editorEl);
|
||||
return {
|
||||
content: content.replace(/\u00a0/g, ' ').replace(/\n+$/, '').trim(),
|
||||
mentions: mentions.slice(0, MAX_WORKFLOW_MENTIONS),
|
||||
};
|
||||
}
|
||||
|
||||
function submit() {
|
||||
if (busy) return;
|
||||
const { content, mentions } = serialize();
|
||||
const payload: AgentComposerPayload = {
|
||||
content,
|
||||
mentions,
|
||||
attachments: [...attachments],
|
||||
};
|
||||
if (payloadIsEmpty(payload)) return;
|
||||
if (editorEl) editorEl.innerHTML = '';
|
||||
attachments = [];
|
||||
mentionOpen = false;
|
||||
mentionLocked = false;
|
||||
syncEmpty();
|
||||
onSend(payload);
|
||||
}
|
||||
|
||||
function onKeydown(e: KeyboardEvent) {
|
||||
if (e.isComposing || e.keyCode === 229) return;
|
||||
if (mentionOpen) {
|
||||
if (mentionLocked && (e.key === 'Enter' || e.key === 'Tab')) {
|
||||
e.preventDefault();
|
||||
mentionOpen = false;
|
||||
mentionLocked = false;
|
||||
return;
|
||||
}
|
||||
if (e.key === 'ArrowDown') {
|
||||
e.preventDefault();
|
||||
mentionIndex = mentionItems.length === 0 ? 0 : (mentionIndex + 1) % mentionItems.length;
|
||||
return;
|
||||
}
|
||||
if (e.key === 'ArrowUp') {
|
||||
e.preventDefault();
|
||||
mentionIndex = mentionItems.length === 0
|
||||
? 0
|
||||
: (mentionIndex - 1 + mentionItems.length) % mentionItems.length;
|
||||
return;
|
||||
}
|
||||
if (e.key === 'Enter' || e.key === 'Tab') {
|
||||
e.preventDefault();
|
||||
const wf = mentionItems[mentionIndex];
|
||||
if (wf) insertMention(wf);
|
||||
else mentionOpen = false;
|
||||
return;
|
||||
}
|
||||
if (e.key === 'Escape') {
|
||||
e.preventDefault();
|
||||
mentionOpen = false;
|
||||
mentionLocked = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (e.key === 'Enter' && !e.shiftKey) {
|
||||
e.preventDefault();
|
||||
submit();
|
||||
}
|
||||
}
|
||||
|
||||
function onPaste(e: ClipboardEvent) {
|
||||
e.preventDefault();
|
||||
const text = e.clipboardData?.getData('text/plain') ?? '';
|
||||
document.execCommand('insertText', false, text);
|
||||
onEditorInput();
|
||||
}
|
||||
|
||||
function chipCount(): number {
|
||||
return editorEl?.querySelectorAll('.wf-chip').length ?? 0;
|
||||
}
|
||||
|
||||
function onEditorInput() {
|
||||
syncEmpty();
|
||||
const info = readAtQuery(editorEl);
|
||||
if (!info) {
|
||||
mentionOpen = false;
|
||||
mentionLocked = false;
|
||||
return;
|
||||
}
|
||||
mentionQuery = info.query;
|
||||
mentionOpen = true;
|
||||
mentionIndex = 0;
|
||||
mentionAnchor = caretAnchor();
|
||||
mentionLocked = chipCount() >= MAX_WORKFLOW_MENTIONS;
|
||||
}
|
||||
|
||||
function insertMention(wf: WorkflowOption) {
|
||||
if (chipCount() >= MAX_WORKFLOW_MENTIONS) {
|
||||
mentionOpen = false;
|
||||
mentionLocked = false;
|
||||
return;
|
||||
}
|
||||
const info = readAtQuery(editorEl);
|
||||
if (!editorEl) return;
|
||||
if (info) {
|
||||
const range = document.createRange();
|
||||
range.setStart(info.fromNode, info.fromOffset);
|
||||
range.setEnd(info.toNode, info.toOffset);
|
||||
range.deleteContents();
|
||||
const chip = makeChip(wf);
|
||||
range.insertNode(chip);
|
||||
const space = document.createTextNode('\u00a0');
|
||||
chip.after(space);
|
||||
placeCaretAfter(space);
|
||||
} else {
|
||||
editorEl.appendChild(makeChip(wf));
|
||||
const space = document.createTextNode('\u00a0');
|
||||
editorEl.appendChild(space);
|
||||
placeCaretAfter(space);
|
||||
}
|
||||
mentionOpen = false;
|
||||
mentionLocked = false;
|
||||
syncEmpty();
|
||||
editorEl.focus();
|
||||
}
|
||||
|
||||
function makeChip(wf: WorkflowOption): HTMLSpanElement {
|
||||
const chip = document.createElement('span');
|
||||
chip.className = 'wf-chip';
|
||||
chip.contentEditable = 'false';
|
||||
chip.dataset.workflowId = String(wf.id);
|
||||
chip.dataset.workflowName = wf.name;
|
||||
chip.dataset.workflowKind = wf.kind;
|
||||
chip.textContent = `@${wf.name}`;
|
||||
return chip;
|
||||
}
|
||||
|
||||
async function addFiles(files: FileList | File[]) {
|
||||
const list = Array.from(files);
|
||||
for (const file of list) {
|
||||
if (attachments.length >= ATTACH_LIMIT) {
|
||||
toast.error(`At most ${ATTACH_LIMIT} attachments`);
|
||||
break;
|
||||
}
|
||||
const slot = `attach-${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
||||
uploadingNames = [...uploadingNames, file.name];
|
||||
try {
|
||||
const path = await uploads.uploadSafe(slot, file);
|
||||
if (!path) continue;
|
||||
const meta = uploads.uploadMetaFor(path);
|
||||
attachments = [
|
||||
...attachments,
|
||||
{ path, name: meta.name || file.name, kind: meta.kind as AttachmentKind },
|
||||
];
|
||||
} finally {
|
||||
uploadingNames = uploadingNames.filter((n) => n !== file.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function removeAttachment(index: number) {
|
||||
attachments = attachments.filter((_, i) => i !== index);
|
||||
}
|
||||
|
||||
function onFileChosen(e: Event) {
|
||||
const el = e.currentTarget as HTMLInputElement;
|
||||
// FileList is live — clearing the input empties it. Copy File objects first.
|
||||
const files = Array.from(el.files ?? []);
|
||||
el.value = '';
|
||||
if (files.length) void addFiles(files);
|
||||
}
|
||||
|
||||
function onDrop(e: DragEvent) {
|
||||
e.preventDefault();
|
||||
dragOver = false;
|
||||
if (busy) return;
|
||||
const files = e.dataTransfer?.files;
|
||||
if (files && files.length) void addFiles(files);
|
||||
}
|
||||
|
||||
function placeCaretAtEnd(el: HTMLElement) {
|
||||
const range = document.createRange();
|
||||
range.selectNodeContents(el);
|
||||
range.collapse(false);
|
||||
const sel = window.getSelection();
|
||||
sel?.removeAllRanges();
|
||||
sel?.addRange(range);
|
||||
}
|
||||
|
||||
function placeCaretAfter(node: Node) {
|
||||
const range = document.createRange();
|
||||
range.setStartAfter(node);
|
||||
range.collapse(true);
|
||||
const sel = window.getSelection();
|
||||
sel?.removeAllRanges();
|
||||
sel?.addRange(range);
|
||||
}
|
||||
|
||||
function caretRect(): DOMRect | null {
|
||||
const sel = window.getSelection();
|
||||
if (!sel || sel.rangeCount === 0) return null;
|
||||
const range = sel.getRangeAt(0).cloneRange();
|
||||
if (!range.collapsed) return range.getBoundingClientRect();
|
||||
const span = document.createElement('span');
|
||||
span.textContent = '\u200b';
|
||||
range.insertNode(span);
|
||||
const rect = span.getBoundingClientRect();
|
||||
span.parentNode?.removeChild(span);
|
||||
return rect;
|
||||
}
|
||||
|
||||
/** Viewport box of the `@` caret, falling back to the editor when the caret has no size. */
|
||||
function caretAnchor(): { top: number; bottom: number; left: number } {
|
||||
const caret = caretRect();
|
||||
const box = editorEl?.getBoundingClientRect();
|
||||
if (caret && (caret.height > 0 || caret.width > 0)) {
|
||||
return {
|
||||
top: caret.top,
|
||||
bottom: caret.bottom,
|
||||
left: caret.left > 0 ? caret.left : (box?.left ?? 8),
|
||||
};
|
||||
}
|
||||
return {
|
||||
top: box?.top ?? 0,
|
||||
bottom: box?.bottom ?? 0,
|
||||
left: box?.left ?? 8,
|
||||
};
|
||||
}
|
||||
|
||||
function readAtQuery(editor: HTMLElement | null): {
|
||||
query: string;
|
||||
fromNode: Node;
|
||||
fromOffset: number;
|
||||
toNode: Node;
|
||||
toOffset: number;
|
||||
} | null {
|
||||
if (!editor) return null;
|
||||
const sel = window.getSelection();
|
||||
if (!sel || !sel.isCollapsed || !sel.anchorNode || !editor.contains(sel.anchorNode)) {
|
||||
return null;
|
||||
}
|
||||
const node = sel.anchorNode;
|
||||
if (node.nodeType !== Node.TEXT_NODE) return null;
|
||||
if ((node.parentElement as HTMLElement | null)?.closest?.('.wf-chip')) return null;
|
||||
const offset = sel.anchorOffset;
|
||||
const text = node.textContent ?? '';
|
||||
const before = text.slice(0, offset);
|
||||
const at = before.lastIndexOf('@');
|
||||
if (at < 0) return null;
|
||||
if (at > 0 && !/\s/.test(before[at - 1]!)) return null;
|
||||
const query = before.slice(at + 1);
|
||||
if (/[\s]/.test(query)) return null;
|
||||
return { query, fromNode: node, fromOffset: at, toNode: node, toOffset: offset };
|
||||
}
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="composer"
|
||||
class:drag-over={dragOver}
|
||||
role="region"
|
||||
aria-label="Message composer"
|
||||
ondragover={(e) => {
|
||||
e.preventDefault();
|
||||
dragOver = true;
|
||||
}}
|
||||
ondragleave={() => (dragOver = false)}
|
||||
ondrop={onDrop}
|
||||
>
|
||||
{#if attachments.length > 0 || uploadingNames.length > 0}
|
||||
<div class="tray" aria-label="Attachments">
|
||||
{#each attachments as a, i (a.path)}
|
||||
<div class="tile">
|
||||
{#if a.kind === 'image'}
|
||||
{@const src = assetUrl(a.path)}
|
||||
{#if src}
|
||||
<img src={src} alt={a.name} />
|
||||
{/if}
|
||||
{:else}
|
||||
<span class="tile-icon">
|
||||
<Icon name={a.kind === 'audio' ? 'music' : 'video'} size={16} />
|
||||
</span>
|
||||
{/if}
|
||||
<span class="tile-name" title={a.name}>{truncateMiddle(a.name, 18)}</span>
|
||||
<button
|
||||
type="button"
|
||||
class="tile-x"
|
||||
title="Remove"
|
||||
onclick={() => removeAttachment(i)}
|
||||
disabled={running}
|
||||
>
|
||||
<Icon name="close" size={10} />
|
||||
</button>
|
||||
</div>
|
||||
{/each}
|
||||
{#each uploadingNames as name (name)}
|
||||
<div class="tile uploading">
|
||||
<span class="tile-name">{truncateMiddle(name, 18)}</span>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="box">
|
||||
<div
|
||||
bind:this={editorEl}
|
||||
class="editor"
|
||||
class:empty={editorEmpty}
|
||||
contenteditable={busy ? 'false' : 'true'}
|
||||
role="textbox"
|
||||
tabindex="0"
|
||||
aria-multiline="true"
|
||||
aria-label="Message"
|
||||
data-placeholder={running ? 'Agent is working…' : 'Describe what you want to build or change…'}
|
||||
onkeydown={onKeydown}
|
||||
oninput={onEditorInput}
|
||||
onpaste={onPaste}
|
||||
></div>
|
||||
<div class="actions">
|
||||
<input
|
||||
bind:this={fileInput}
|
||||
type="file"
|
||||
class="sr-only"
|
||||
accept={ACCEPT}
|
||||
multiple
|
||||
onchange={onFileChosen}
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
class="attach"
|
||||
title="Attach image, video, or audio"
|
||||
disabled={busy}
|
||||
onclick={() => fileInput?.click()}
|
||||
>
|
||||
<Icon name="paperclip" size={16} />
|
||||
</button>
|
||||
{#if running}
|
||||
<button type="button" class="send stop" onclick={onCancel} title="Stop the agent">
|
||||
<Icon name="stop" size={14} />
|
||||
Stop
|
||||
</button>
|
||||
{:else}
|
||||
<button
|
||||
type="button"
|
||||
class="send"
|
||||
onclick={submit}
|
||||
disabled={!sendable}
|
||||
title="Send (Enter)"
|
||||
>
|
||||
Send
|
||||
<Icon name="chevron-right" size={14} />
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<WorkflowMentionMenu
|
||||
open={mentionOpen}
|
||||
items={mentionLocked ? [] : mentionItems}
|
||||
lockReason={mentionLocked
|
||||
? 'One workflow per message — remove the existing @ tag to pick another.'
|
||||
: null}
|
||||
activeIndex={mentionIndex}
|
||||
anchor={mentionAnchor}
|
||||
onSelect={insertMention}
|
||||
onHover={(i) => (mentionIndex = i)}
|
||||
/>
|
||||
|
||||
<style>
|
||||
.composer {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
padding-top: 10px;
|
||||
border-top: 1px solid var(--border);
|
||||
}
|
||||
.composer.drag-over .box {
|
||||
border-color: var(--accent);
|
||||
background: color-mix(in srgb, var(--accent) 8%, var(--bg-surface));
|
||||
}
|
||||
.tray {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
}
|
||||
.tile {
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
width: 72px;
|
||||
border-radius: var(--radius-sm);
|
||||
overflow: hidden;
|
||||
background: var(--bg-surface);
|
||||
border: 1px solid var(--border);
|
||||
}
|
||||
.tile img {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 48px;
|
||||
object-fit: cover;
|
||||
background: var(--bg-elevated);
|
||||
}
|
||||
.tile-icon {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 48px;
|
||||
color: var(--text-muted);
|
||||
background: var(--bg-elevated);
|
||||
}
|
||||
.tile-name {
|
||||
padding: 3px 6px 4px;
|
||||
font-size: 10px;
|
||||
color: var(--text-secondary);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.tile-x {
|
||||
position: absolute;
|
||||
top: 3px;
|
||||
right: 3px;
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border: none;
|
||||
border-radius: 999px;
|
||||
background: rgba(0, 0, 0, 0.65);
|
||||
color: #fff;
|
||||
cursor: pointer;
|
||||
padding: 0;
|
||||
}
|
||||
.tile.uploading {
|
||||
opacity: 0.7;
|
||||
min-height: 64px;
|
||||
justify-content: center;
|
||||
}
|
||||
.box {
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
gap: 8px;
|
||||
min-width: 0;
|
||||
background: var(--bg-surface);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius-md);
|
||||
padding: 8px 8px 8px 12px;
|
||||
}
|
||||
.editor {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
min-height: 28px;
|
||||
max-height: 160px;
|
||||
overflow-y: auto;
|
||||
color: var(--text-primary);
|
||||
font-family: var(--font-body);
|
||||
font-size: 13.5px;
|
||||
line-height: 1.5;
|
||||
outline: none;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
}
|
||||
.editor.empty::before {
|
||||
content: attr(data-placeholder);
|
||||
color: var(--text-muted);
|
||||
pointer-events: none;
|
||||
}
|
||||
.editor :global(.wf-chip) {
|
||||
display: inline;
|
||||
padding: 1px 7px;
|
||||
margin: 0 1px;
|
||||
border-radius: 999px;
|
||||
background: color-mix(in srgb, var(--accent) 22%, var(--bg-elevated));
|
||||
border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
|
||||
color: var(--accent);
|
||||
font-weight: 600;
|
||||
font-size: 13px;
|
||||
white-space: nowrap;
|
||||
user-select: none;
|
||||
}
|
||||
.actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.attach {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
border: none;
|
||||
border-radius: var(--radius-md);
|
||||
background: transparent;
|
||||
color: var(--text-secondary);
|
||||
cursor: pointer;
|
||||
}
|
||||
.attach:hover:not(:disabled) {
|
||||
color: var(--text-primary);
|
||||
background: var(--bg-elevated);
|
||||
}
|
||||
.attach:disabled {
|
||||
opacity: 0.45;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
.attach:focus-visible {
|
||||
outline: 2px solid var(--accent);
|
||||
outline-offset: 0;
|
||||
}
|
||||
.send {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
height: 36px;
|
||||
padding: 0 14px;
|
||||
border-radius: var(--radius-md);
|
||||
border: 1px solid var(--accent);
|
||||
background: var(--accent);
|
||||
color: #fff;
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.send:disabled {
|
||||
opacity: 0.45;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
.send.stop {
|
||||
background: transparent;
|
||||
color: var(--error);
|
||||
border-color: rgba(239, 68, 68, 0.5);
|
||||
}
|
||||
.send:focus-visible {
|
||||
outline: 2px solid var(--accent);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
.sr-only {
|
||||
position: absolute;
|
||||
width: 1px;
|
||||
height: 1px;
|
||||
padding: 0;
|
||||
margin: -1px;
|
||||
overflow: hidden;
|
||||
clip: rect(0, 0, 0, 0);
|
||||
white-space: nowrap;
|
||||
border: 0;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,197 @@
|
||||
<script lang="ts">
|
||||
import type { AgentPlan } from '$lib/api';
|
||||
import { agentColor, agentDisplayName } from './agentPalette';
|
||||
import Icon from '$lib/components/ui/Icon.svelte';
|
||||
|
||||
interface Props {
|
||||
plan: AgentPlan;
|
||||
}
|
||||
|
||||
let { plan }: Props = $props();
|
||||
|
||||
const tasks = $derived(plan.tasks ?? []);
|
||||
const doneCount = $derived(tasks.filter((t) => t.status === 'done').length);
|
||||
const running = $derived(tasks.some((t) => t.status === 'running'));
|
||||
|
||||
function statusIcon(status: string): 'check' | 'close' | 'clock' | 'stop' {
|
||||
if (status === 'done') return 'check';
|
||||
if (status === 'failed') return 'close';
|
||||
if (status === 'running') return 'clock';
|
||||
return 'stop';
|
||||
}
|
||||
|
||||
function statusLabel(status: string): string {
|
||||
if (status === 'running') return 'Running';
|
||||
if (status === 'done') return 'Done';
|
||||
if (status === 'failed') return 'Failed';
|
||||
return 'Queued';
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="plan-panel">
|
||||
<header class="head">
|
||||
<span class="icon-wrap" class:spinning={running}>
|
||||
<Icon name="sparkle" size={13} />
|
||||
</span>
|
||||
<span class="title">Planner</span>
|
||||
{#if plan.note}
|
||||
<span class="note">{plan.note}</span>
|
||||
{/if}
|
||||
<span class="count mono">{doneCount}/{tasks.length}</span>
|
||||
</header>
|
||||
|
||||
<ol class="tasks">
|
||||
{#each tasks as task, i (i)}
|
||||
{@const color = agentColor(`${task.role}-agent`)}
|
||||
<li class="task" class:active={task.status === 'running'}>
|
||||
<span class="status" class:done={task.status === 'done'} class:failed={task.status === 'failed'} class:running={task.status === 'running'}>
|
||||
{#if task.status === 'running'}
|
||||
<span class="spin-dot" style:background={color}></span>
|
||||
{:else}
|
||||
<Icon name={statusIcon(task.status)} size={12} />
|
||||
{/if}
|
||||
</span>
|
||||
<span class="role" style:color={color} style:--role-color={color}>
|
||||
{agentDisplayName(`${task.role}-agent`)}
|
||||
</span>
|
||||
<span class="goal" class:done={task.status === 'done'}>{task.goal}</span>
|
||||
<span class="state mono">{statusLabel(task.status)}</span>
|
||||
</li>
|
||||
{/each}
|
||||
</ol>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.plan-panel {
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius-md);
|
||||
background: var(--bg-surface);
|
||||
padding: 8px 10px;
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
}
|
||||
.head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
.icon-wrap {
|
||||
display: inline-flex;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
.icon-wrap.spinning {
|
||||
animation: spin 1.5s linear infinite;
|
||||
}
|
||||
@keyframes spin {
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
.title {
|
||||
font-size: 12px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.04em;
|
||||
text-transform: uppercase;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
.note {
|
||||
font-size: 12px;
|
||||
color: var(--text-muted);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
.count {
|
||||
font-size: 11px;
|
||||
color: var(--text-muted);
|
||||
margin-left: auto;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.tasks {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
.task {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 5px 8px;
|
||||
border-radius: var(--radius-sm);
|
||||
border: 1px solid transparent;
|
||||
}
|
||||
.task.active {
|
||||
background: var(--bg-elevated);
|
||||
border-color: var(--border);
|
||||
}
|
||||
.status {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
flex-shrink: 0;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
.status.done {
|
||||
color: var(--success);
|
||||
}
|
||||
.status.failed {
|
||||
color: var(--error);
|
||||
}
|
||||
.status.running {
|
||||
color: var(--warning);
|
||||
}
|
||||
.spin-dot {
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
border-radius: 9999px;
|
||||
animation: pulse 1.1s ease-in-out infinite;
|
||||
}
|
||||
@keyframes pulse {
|
||||
0%,
|
||||
100% {
|
||||
opacity: 0.35;
|
||||
}
|
||||
50% {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
.role {
|
||||
font-size: 11px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.03em;
|
||||
text-transform: uppercase;
|
||||
flex-shrink: 0;
|
||||
border: 1px solid color-mix(in srgb, var(--role-color) 45%, transparent);
|
||||
background: color-mix(in srgb, var(--role-color) 14%, transparent);
|
||||
padding: 2px 8px;
|
||||
border-radius: 999px;
|
||||
}
|
||||
.goal {
|
||||
font-size: 12.5px;
|
||||
color: var(--text-primary);
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.goal.done {
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
.state {
|
||||
font-size: 10.5px;
|
||||
color: var(--text-muted);
|
||||
flex-shrink: 0;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.04em;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,291 @@
|
||||
<script lang="ts">
|
||||
import type { AgentSession } from '$lib/api';
|
||||
import Icon from '$lib/components/ui/Icon.svelte';
|
||||
|
||||
interface Props {
|
||||
sessions: AgentSession[];
|
||||
activeId: number | null;
|
||||
onSelect: (id: number) => void;
|
||||
onNewSandbox: () => void;
|
||||
onNewProjectChat: (projectId: number) => void;
|
||||
onDelete: (id: number) => void;
|
||||
}
|
||||
|
||||
let { sessions, activeId, onSelect, onNewSandbox, onNewProjectChat, onDelete }: Props =
|
||||
$props();
|
||||
|
||||
const sandbox = $derived(sessions.filter((s) => s.project_id == null));
|
||||
const grouped = $derived.by(() => {
|
||||
const map = new Map<number, { project: AgentSession['project']; items: AgentSession[] }>();
|
||||
for (const s of sessions) {
|
||||
if (s.project_id == null) continue;
|
||||
const key = s.project_id;
|
||||
if (!map.has(key)) map.set(key, { project: s.project ?? null, items: [] });
|
||||
map.get(key)!.items.push(s);
|
||||
}
|
||||
return [...map.values()];
|
||||
});
|
||||
</script>
|
||||
|
||||
<aside class="sidebar">
|
||||
<button type="button" class="new-chat" onclick={onNewSandbox}>
|
||||
<Icon name="plus" size={14} />
|
||||
New sandbox chat
|
||||
</button>
|
||||
|
||||
{#if sessions.length === 0}
|
||||
<p class="muted">No sessions yet.</p>
|
||||
{/if}
|
||||
|
||||
{#if sandbox.length > 0}
|
||||
<div class="group">
|
||||
<div class="group-head">
|
||||
<span class="group-title">Sandbox</span>
|
||||
<span class="count">{sandbox.length}</span>
|
||||
</div>
|
||||
{#each sandbox as s (s.id)}
|
||||
<button
|
||||
type="button"
|
||||
class="item"
|
||||
class:active={s.id === activeId}
|
||||
onclick={() => onSelect(s.id)}
|
||||
>
|
||||
<span class="dot" class:run={s.running || s.status === 'running'}></span>
|
||||
<span class="title">{s.title}</span>
|
||||
<span
|
||||
class="del"
|
||||
role="button"
|
||||
tabindex="-1"
|
||||
aria-label="Delete session"
|
||||
onclick={(e) => {
|
||||
e.stopPropagation();
|
||||
onDelete(s.id);
|
||||
}}
|
||||
onkeydown={(e) => {
|
||||
if (e.key === 'Enter') {
|
||||
e.stopPropagation();
|
||||
onDelete(s.id);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Icon name="trash" size={12} />
|
||||
</span>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#each grouped as g (g.project?.id ?? 0)}
|
||||
<div class="group">
|
||||
<div class="group-head">
|
||||
<span class="group-title" title={g.project?.title}>
|
||||
{g.project?.title ?? `Project #${g.project?.id ?? '?'}`}
|
||||
</span>
|
||||
<span class="count">{g.items.length}</span>
|
||||
<span
|
||||
class="add-chat"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
aria-label="New chat for this project"
|
||||
title="New chat for this project"
|
||||
onclick={(e) => {
|
||||
e.stopPropagation();
|
||||
if (g.project) onNewProjectChat(g.project.id);
|
||||
}}
|
||||
onkeydown={(e) => {
|
||||
if (e.key === 'Enter') {
|
||||
e.stopPropagation();
|
||||
if (g.project) onNewProjectChat(g.project.id);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Icon name="plus" size={12} />
|
||||
</span>
|
||||
</div>
|
||||
{#each g.items as s (s.id)}
|
||||
<button
|
||||
type="button"
|
||||
class="item"
|
||||
class:active={s.id === activeId}
|
||||
onclick={() => onSelect(s.id)}
|
||||
>
|
||||
<span class="dot" class:run={s.running || s.status === 'running'}></span>
|
||||
<span class="title">{s.title}</span>
|
||||
<span
|
||||
class="del"
|
||||
role="button"
|
||||
tabindex="-1"
|
||||
aria-label="Delete session"
|
||||
onclick={(e) => {
|
||||
e.stopPropagation();
|
||||
onDelete(s.id);
|
||||
}}
|
||||
onkeydown={(e) => {
|
||||
if (e.key === 'Enter') {
|
||||
e.stopPropagation();
|
||||
onDelete(s.id);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Icon name="trash" size={12} />
|
||||
</span>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
{/each}
|
||||
</aside>
|
||||
|
||||
<style>
|
||||
.sidebar {
|
||||
width: 240px;
|
||||
flex-shrink: 0;
|
||||
border-right: 1px solid var(--border);
|
||||
background: var(--bg-surface);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
padding: 12px 10px;
|
||||
overflow-y: auto;
|
||||
min-height: 0;
|
||||
}
|
||||
.new-chat {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 7px;
|
||||
width: 100%;
|
||||
height: 36px;
|
||||
border-radius: var(--radius-md);
|
||||
border: 1px dashed var(--border);
|
||||
background: transparent;
|
||||
color: var(--text-secondary);
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.new-chat:hover {
|
||||
color: var(--text-primary);
|
||||
border-color: var(--accent);
|
||||
}
|
||||
.new-chat:focus-visible {
|
||||
outline: 2px solid var(--accent);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
.muted {
|
||||
color: var(--text-muted);
|
||||
font-size: 12px;
|
||||
padding: 8px;
|
||||
margin: 0;
|
||||
}
|
||||
.group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
}
|
||||
.group-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 8px 8px 4px;
|
||||
}
|
||||
.group-title {
|
||||
font-size: 10.5px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.06em;
|
||||
text-transform: uppercase;
|
||||
color: var(--text-muted);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.count {
|
||||
font-size: 10px;
|
||||
color: var(--text-muted);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.add-chat {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
border-radius: var(--radius-sm);
|
||||
color: var(--text-muted);
|
||||
cursor: pointer;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.add-chat:hover {
|
||||
color: var(--accent);
|
||||
background: color-mix(in srgb, var(--accent) 14%, transparent);
|
||||
}
|
||||
.item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
width: 100%;
|
||||
padding: 7px 8px;
|
||||
border-radius: var(--radius-sm);
|
||||
border: none;
|
||||
background: transparent;
|
||||
color: var(--text-secondary);
|
||||
font-size: 12.5px;
|
||||
cursor: pointer;
|
||||
text-align: left;
|
||||
}
|
||||
.item:hover {
|
||||
background: var(--bg-elevated);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
.item.active {
|
||||
background: var(--bg-elevated);
|
||||
color: var(--text-primary);
|
||||
box-shadow: inset 0 -2px 0 var(--accent);
|
||||
}
|
||||
.dot {
|
||||
width: 7px;
|
||||
height: 7px;
|
||||
border-radius: 999px;
|
||||
background: var(--text-muted);
|
||||
opacity: 0.5;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.dot.run {
|
||||
background: var(--warning);
|
||||
opacity: 1;
|
||||
animation: pulse 1.1s ease-in-out infinite;
|
||||
}
|
||||
@keyframes pulse {
|
||||
0%,
|
||||
100% {
|
||||
opacity: 0.35;
|
||||
}
|
||||
50% {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
.title {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.del {
|
||||
display: none;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
border-radius: var(--radius-sm);
|
||||
color: var(--text-muted);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.item:hover .del {
|
||||
display: inline-flex;
|
||||
}
|
||||
.del:hover {
|
||||
color: var(--error);
|
||||
background: rgba(239, 68, 68, 0.12);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,162 @@
|
||||
<script lang="ts">
|
||||
import Icon from '$lib/components/ui/Icon.svelte';
|
||||
|
||||
interface Props {
|
||||
name: string;
|
||||
args?: Record<string, unknown> | null;
|
||||
result?: unknown;
|
||||
phase: 'running' | 'done' | 'error';
|
||||
}
|
||||
|
||||
let { name, args = null, result = null, phase }: Props = $props();
|
||||
let open = $state(false);
|
||||
|
||||
function fmt(value: unknown): string {
|
||||
try {
|
||||
return JSON.stringify(value, null, 2) ?? '';
|
||||
} catch {
|
||||
return String(value);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="tool-card" class:error={phase === 'error'}>
|
||||
<button type="button" class="head" onclick={() => (open = !open)} aria-expanded={open}>
|
||||
<span class="dot" class:running={phase === 'running'}></span>
|
||||
<span class="name mono">{name}</span>
|
||||
{#if phase === 'running'}
|
||||
<span class="state">running…</span>
|
||||
{:else if phase === 'error'}
|
||||
<span class="state err-text">failed</span>
|
||||
{:else}
|
||||
<span class="state ok-text">done</span>
|
||||
{/if}
|
||||
<span class="chev"><Icon name="chevron-down" size={13} /></span>
|
||||
</button>
|
||||
{#if open}
|
||||
<div class="body">
|
||||
{#if args && Object.keys(args).length > 0}
|
||||
<div class="section">
|
||||
<span class="label">args</span>
|
||||
<pre>{fmt(args)}</pre>
|
||||
</div>
|
||||
{/if}
|
||||
{#if result != null}
|
||||
<div class="section">
|
||||
<span class="label">result</span>
|
||||
<pre>{fmt(result)}</pre>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.tool-card {
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius-sm);
|
||||
background: var(--bg-elevated);
|
||||
overflow: hidden;
|
||||
}
|
||||
.tool-card.error {
|
||||
border-color: rgba(239, 68, 68, 0.45);
|
||||
}
|
||||
.head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
width: 100%;
|
||||
padding: 7px 10px;
|
||||
background: transparent;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
color: var(--text-secondary);
|
||||
font-size: 12px;
|
||||
text-align: left;
|
||||
}
|
||||
.head:hover {
|
||||
color: var(--text-primary);
|
||||
background: rgba(255, 255, 255, 0.03);
|
||||
}
|
||||
.name {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
font-size: 12px;
|
||||
color: var(--text-primary);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.dot {
|
||||
width: 7px;
|
||||
height: 7px;
|
||||
border-radius: 999px;
|
||||
background: var(--text-muted);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.dot.running {
|
||||
background: var(--warning);
|
||||
animation: pulse 1.1s ease-in-out infinite;
|
||||
}
|
||||
@keyframes pulse {
|
||||
0%,
|
||||
100% {
|
||||
opacity: 0.35;
|
||||
}
|
||||
50% {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
.state {
|
||||
font-size: 11px;
|
||||
color: var(--text-muted);
|
||||
margin-left: auto;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.ok-text {
|
||||
color: var(--success);
|
||||
}
|
||||
.err-text {
|
||||
color: var(--error);
|
||||
}
|
||||
.chev {
|
||||
display: inline-flex;
|
||||
flex-shrink: 0;
|
||||
transition: transform 0.15s;
|
||||
}
|
||||
.head[aria-expanded='true'] .chev {
|
||||
transform: rotate(180deg);
|
||||
}
|
||||
.body {
|
||||
border-top: 1px solid var(--border);
|
||||
padding: 8px 10px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
.section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
min-width: 0;
|
||||
}
|
||||
.label {
|
||||
font-size: 10px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.06em;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
pre {
|
||||
margin: 0;
|
||||
padding: 8px;
|
||||
background: var(--bg-primary);
|
||||
border-radius: var(--radius-sm);
|
||||
font-family: var(--font-mono);
|
||||
font-size: 11px;
|
||||
line-height: 1.5;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
max-height: 220px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,128 @@
|
||||
<script lang="ts">
|
||||
import Icon from '$lib/components/ui/Icon.svelte';
|
||||
|
||||
interface Props {
|
||||
/** Persisted reasoning text (from stored message). */
|
||||
reasoning?: string | null;
|
||||
/** Live-streaming reasoning text (from agent.thinking SSE). */
|
||||
streaming?: string;
|
||||
}
|
||||
|
||||
let { reasoning = null, streaming = '' }: Props = $props();
|
||||
|
||||
let open = $state(false);
|
||||
|
||||
const hasReasoning = $derived(!!reasoning || !!streaming);
|
||||
const display = $derived(streaming || reasoning || '');
|
||||
const isLive = $derived(!!streaming);
|
||||
</script>
|
||||
|
||||
{#if hasReasoning}
|
||||
<div class="reasoning-panel" class:live={isLive}>
|
||||
<button type="button" class="head" onclick={() => (open = !open)} aria-expanded={open}>
|
||||
<span class="icon-wrap" class:spinning={isLive && !open}>
|
||||
<Icon name="sparkle" size={13} />
|
||||
</span>
|
||||
<span class="label">
|
||||
{#if isLive && !open}
|
||||
Thinking…
|
||||
{:else if open}
|
||||
Reasoning
|
||||
{:else}
|
||||
Show reasoning
|
||||
{/if}
|
||||
</span>
|
||||
<span class="chev"><Icon name="chevron-down" size={12} /></span>
|
||||
</button>
|
||||
{#if open}
|
||||
<div class="body">
|
||||
<div class="content">{display}{#if isLive}<span class="caret"></span>{/if}</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.reasoning-panel {
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius-sm);
|
||||
background: var(--bg-elevated);
|
||||
overflow: hidden;
|
||||
}
|
||||
.reasoning-panel.live {
|
||||
border-color: color-mix(in srgb, var(--accent) 30%, transparent);
|
||||
}
|
||||
.head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
width: 100%;
|
||||
padding: 6px 10px;
|
||||
background: transparent;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
color: var(--text-muted);
|
||||
font-size: 12px;
|
||||
text-align: left;
|
||||
}
|
||||
.head:hover {
|
||||
color: var(--text-secondary);
|
||||
background: rgba(255, 255, 255, 0.02);
|
||||
}
|
||||
.icon-wrap {
|
||||
display: inline-flex;
|
||||
flex-shrink: 0;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
.icon-wrap.spinning {
|
||||
animation: spin 1.5s linear infinite;
|
||||
}
|
||||
@keyframes spin {
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
.label {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.chev {
|
||||
display: inline-flex;
|
||||
flex-shrink: 0;
|
||||
transition: transform 0.15s;
|
||||
}
|
||||
.head[aria-expanded='true'] .chev {
|
||||
transform: rotate(180deg);
|
||||
}
|
||||
.body {
|
||||
border-top: 1px solid var(--border);
|
||||
padding: 8px 10px;
|
||||
}
|
||||
.content {
|
||||
font-family: var(--font-mono);
|
||||
font-size: 11.5px;
|
||||
line-height: 1.6;
|
||||
color: var(--text-secondary);
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
max-height: 320px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
.caret {
|
||||
display: inline-block;
|
||||
width: 6px;
|
||||
height: 12px;
|
||||
margin-left: 1px;
|
||||
background: var(--accent);
|
||||
animation: blink 1s step-end infinite;
|
||||
vertical-align: text-bottom;
|
||||
}
|
||||
@keyframes blink {
|
||||
50% {
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,159 @@
|
||||
<script lang="ts">
|
||||
import type { WorkflowOption } from '$lib/agentComposer';
|
||||
|
||||
interface Props {
|
||||
open: boolean;
|
||||
items: WorkflowOption[];
|
||||
activeIndex: number;
|
||||
/** Caret / `@` viewport box — menu opens above this (composer is bottom-docked). */
|
||||
anchor: { top: number; bottom: number; left: number };
|
||||
/** When set, the list is replaced with this explanation (one-workflow guardrail). */
|
||||
lockReason?: string | null;
|
||||
onSelect: (wf: WorkflowOption) => void;
|
||||
onHover: (index: number) => void;
|
||||
}
|
||||
|
||||
let { open, items, activeIndex, anchor, lockReason = null, onSelect, onHover }: Props = $props();
|
||||
|
||||
let menuEl = $state<HTMLDivElement | null>(null);
|
||||
let pos = $state({ top: 0, left: 0, maxHeight: 280 });
|
||||
let placed = $state(false);
|
||||
|
||||
const GAP = 6;
|
||||
const PAD = 8;
|
||||
const MENU_MAX = 280;
|
||||
|
||||
function placeMenu() {
|
||||
if (!menuEl) return;
|
||||
const h = Math.min(menuEl.scrollHeight || 40, MENU_MAX);
|
||||
const spaceAbove = anchor.top - GAP - PAD;
|
||||
const spaceBelow = window.innerHeight - anchor.bottom - GAP - PAD;
|
||||
// Bottom-docked composer: prefer above the `@` unless there is no room.
|
||||
const openUp = spaceAbove >= Math.min(h, 80) || spaceAbove >= spaceBelow;
|
||||
const maxHeight = Math.max(80, Math.min(MENU_MAX, openUp ? spaceAbove : spaceBelow));
|
||||
const used = Math.min(h, maxHeight);
|
||||
let top = openUp ? anchor.top - used - GAP : anchor.bottom + GAP;
|
||||
let left = anchor.left;
|
||||
left = Math.max(PAD, Math.min(left, window.innerWidth - 280 - PAD));
|
||||
top = Math.max(PAD, Math.min(top, window.innerHeight - used - PAD));
|
||||
pos = { top, left, maxHeight };
|
||||
placed = true;
|
||||
}
|
||||
|
||||
$effect(() => {
|
||||
if (!open || !menuEl) return;
|
||||
document.body.appendChild(menuEl);
|
||||
return () => {
|
||||
menuEl?.remove();
|
||||
};
|
||||
});
|
||||
|
||||
$effect(() => {
|
||||
if (!open) {
|
||||
placed = false;
|
||||
return;
|
||||
}
|
||||
if (!menuEl) return;
|
||||
void items.length;
|
||||
void lockReason;
|
||||
void anchor.top;
|
||||
void anchor.left;
|
||||
void anchor.bottom;
|
||||
requestAnimationFrame(placeMenu);
|
||||
});
|
||||
</script>
|
||||
|
||||
{#if open}
|
||||
<div
|
||||
bind:this={menuEl}
|
||||
class="mention-menu"
|
||||
style="top: {pos.top}px; left: {pos.left}px; max-height: {pos.maxHeight}px; visibility: {placed
|
||||
? 'visible'
|
||||
: 'hidden'}"
|
||||
role="listbox"
|
||||
aria-label="Workflows"
|
||||
>
|
||||
{#if lockReason}
|
||||
<div class="empty">{lockReason}</div>
|
||||
{:else if items.length === 0}
|
||||
<div class="empty">No matching workflow</div>
|
||||
{:else}
|
||||
{#each items as wf, i (wf.id)}
|
||||
<button
|
||||
type="button"
|
||||
class="item"
|
||||
class:active={i === activeIndex}
|
||||
role="option"
|
||||
aria-selected={i === activeIndex}
|
||||
onmousedown={(e) => {
|
||||
e.preventDefault();
|
||||
onSelect(wf);
|
||||
}}
|
||||
onmouseenter={() => onHover(i)}
|
||||
>
|
||||
<span class="name">{wf.name}</span>
|
||||
<span class="kind">{wf.kind}</span>
|
||||
</button>
|
||||
{/each}
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.mention-menu {
|
||||
position: fixed;
|
||||
z-index: 10000;
|
||||
min-width: 240px;
|
||||
max-width: 360px;
|
||||
max-height: 280px;
|
||||
overflow-y: auto;
|
||||
background: var(--bg-surface);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius-md);
|
||||
box-shadow:
|
||||
0 8px 24px rgba(0, 0, 0, 0.5),
|
||||
0 0 0 1px rgba(0, 0, 0, 0.3);
|
||||
padding: 4px;
|
||||
}
|
||||
.empty {
|
||||
padding: 10px 12px;
|
||||
font-size: 13px;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
.item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 10px;
|
||||
width: 100%;
|
||||
padding: 8px 12px;
|
||||
border: none;
|
||||
border-radius: var(--radius-sm);
|
||||
background: transparent;
|
||||
color: var(--text-primary);
|
||||
font-size: 13px;
|
||||
font-family: inherit;
|
||||
cursor: pointer;
|
||||
text-align: left;
|
||||
}
|
||||
.item:hover,
|
||||
.item.active {
|
||||
background: var(--bg-elevated);
|
||||
}
|
||||
.item.active .name {
|
||||
color: var(--accent);
|
||||
}
|
||||
.name {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
font-weight: 500;
|
||||
}
|
||||
.kind {
|
||||
flex-shrink: 0;
|
||||
font-size: 11px;
|
||||
color: var(--text-muted);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.04em;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* Agent identity palette: a stable display name + accent color per agent.
|
||||
*
|
||||
* The main loop runs with `agent_name = null`; we label it "Calliope". Each
|
||||
* swarm sub-agent ("planner", "story-agent", …) gets its own fixed color so
|
||||
* differently-authored bubbles are visually distinct, plus a deterministic
|
||||
* fallback for any future agent name.
|
||||
*/
|
||||
|
||||
export const DEFAULT_AGENT_NAME = 'Calliope';
|
||||
|
||||
// Fixed identity map (keyed by the raw agent_name the backend emits).
|
||||
const IDENTITIES: Record<string, { label: string; color: string }> = {
|
||||
planner: { label: 'Planner', color: '#22d3ee' }, // cyan
|
||||
'story-agent': { label: 'Story Agent', color: '#22c55e' }, // green
|
||||
'script-agent': { label: 'Script Agent', color: '#f59e0b' }, // amber
|
||||
'assets-agent': { label: 'Assets Agent', color: '#ec4899' }, // pink
|
||||
'video-agent': { label: 'Video Agent', color: '#fb923c' }, // orange
|
||||
'research-agent': { label: 'Research Agent', color: '#a78bfa' }, // violet
|
||||
};
|
||||
|
||||
// Fallback palette for unknown names (stable hash → deterministic color).
|
||||
const FALLBACK_COLORS = [
|
||||
'#22d3ee',
|
||||
'#22c55e',
|
||||
'#f59e0b',
|
||||
'#ec4899',
|
||||
'#fb923c',
|
||||
'#a78bfa',
|
||||
'#38bdf8',
|
||||
'#4ade80',
|
||||
'#f472b6',
|
||||
'#facc15',
|
||||
];
|
||||
|
||||
function hashString(s: string): number {
|
||||
let h = 0;
|
||||
for (let i = 0; i < s.length; i++) {
|
||||
h = (h * 31 + s.charCodeAt(i)) >>> 0;
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
/** The default "Calliope" accent (matches --accent). */
|
||||
export const DEFAULT_AGENT_COLOR = '#8b5cf6';
|
||||
|
||||
export function agentDisplayName(name: string | null | undefined): string {
|
||||
const key = (name || '').trim().toLowerCase();
|
||||
if (!key) return DEFAULT_AGENT_NAME;
|
||||
return IDENTITIES[key]?.label ?? prettyName(name!);
|
||||
}
|
||||
|
||||
export function agentColor(name: string | null | undefined): string {
|
||||
const key = (name || '').trim().toLowerCase();
|
||||
if (!key) return DEFAULT_AGENT_COLOR;
|
||||
const identity = IDENTITIES[key];
|
||||
if (identity) return identity.color;
|
||||
return FALLBACK_COLORS[hashString(key) % FALLBACK_COLORS.length];
|
||||
}
|
||||
|
||||
function prettyName(raw: string): string {
|
||||
// "story-agent" → "Story Agent", "assets-agent" → "Assets Agent"
|
||||
const title = raw
|
||||
.split(/[-_\s]+/)
|
||||
.filter(Boolean)
|
||||
.map((w) => w.charAt(0).toUpperCase() + w.slice(1))
|
||||
.join(' ');
|
||||
return title || DEFAULT_AGENT_NAME;
|
||||
}
|
||||
Reference in New Issue
Block a user