1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
<script lang="ts">
import type { Tab } from "../tabs";
import { shortHandle } from "../tabs";
let {
tabs,
activeConversationId,
statusFor,
onSelect,
onClose,
onNewDraft,
onRename,
}: {
tabs: readonly Tab[];
activeConversationId: string | null;
/** Returns the conversation's lifecycle status, or undefined when unknown. */
statusFor?: (conversationId: string) => string | undefined;
onSelect: (conversationId: string) => void;
onClose: (conversationId: string) => void;
onNewDraft: () => void;
onRename?: (conversationId: string, title: string) => void;
} = $props();
// Git-style short handle (shortest unique prefix) per open tab — the visible
// "tab ID". Derived from the set of open conversation ids; pure helper.
const handles = $derived.by(() => {
const ids = tabs.map((t) => t.conversationId);
const map = new Map<string, string>();
for (const id of ids) map.set(id, shortHandle(id, ids));
return map;
});
// Inline rename: double-click a tab's title to edit, Enter/blur to save.
let editingId = $state<string | null>(null);
let editValue = $state("");
let editEl = $state<HTMLInputElement>();
function startRename(tab: Tab): void {
if (onRename === undefined) return;
editingId = tab.conversationId;
editValue = tab.title;
// Focus the input after it renders.
queueMicrotask(() => editEl?.focus());
}
function commitRename(): void {
const id = editingId;
if (id !== null && onRename !== undefined) {
const trimmed = editValue.trim();
if (trimmed.length > 0) onRename(id, trimmed);
}
editingId = null;
}
function cancelRename(): void {
editingId = null;
}
// Click-to-copy the agent (conversation) id: clicking the ID badge copies the
// FULL conversationId to the clipboard (the stable, useful id — the badge
// only shows a short prefix) and highlights the badge text as feedback. The
// highlight (text selection) is the indicator — no text is swapped, so the
// badge keeps a stable width. If the clipboard write fails, the selection is
// already in place so the user can Ctrl+C the text manually.
async function copyId(conversationId: string, el: HTMLElement): Promise<void> {
selectText(el);
const clipboard = navigator.clipboard;
if (clipboard === undefined) return;
try {
await clipboard.writeText(conversationId);
} catch {
// Selection already lets the user copy manually.
}
}
function selectText(el: HTMLElement): void {
const range = document.createRange();
range.selectNodeContents(el);
const selection = window.getSelection();
selection?.removeAllRanges();
selection?.addRange(range);
}
</script>
<div class="flex flex-col gap-2">
<!-- Single-column vertical tab list. Fixed at 40% of the viewport height so a
long tab set scrolls inside this region instead of growing the whole sidebar. -->
<div class="flex h-[40vh] flex-col gap-1 overflow-y-auto pr-1">
{#each tabs as tab (tab.conversationId)}
<div
class="flex items-center gap-1.5 rounded px-2 py-1.5 text-sm hover:bg-base-300"
class:bg-base-300={tab.conversationId === activeConversationId}
role="tab"
tabindex="0"
aria-selected={tab.conversationId === activeConversationId}
title={tab.title}
onclick={() => onSelect(tab.conversationId)}
onkeydown={(e) => {
if (e.key === "Enter") onSelect(tab.conversationId);
}}
>
<button
type="button"
class="shrink-0 rounded bg-base-300 px-1 py-0.5 font-mono text-[10px] leading-none text-base-content/60 transition-colors hover:bg-primary hover:text-primary-content"
data-copy-id={tab.conversationId}
title="Click to copy conversation id"
aria-label={`Copy conversation id ${tab.conversationId}`}
onclick={(e) => {
e.stopPropagation();
void copyId(tab.conversationId, e.currentTarget);
}}
>
{handles.get(tab.conversationId) ?? tab.conversationId}
</button>
{#if editingId === tab.conversationId}
<input
bind:this={editEl}
bind:value={editValue}
class="min-w-0 flex-1 rounded bg-base-100 px-1 py-0.5 text-left text-sm outline outline-1 outline-primary"
onclick={(e) => e.stopPropagation()}
onkeydown={(e) => {
if (e.key === "Enter") {
e.preventDefault();
commitRename();
} else if (e.key === "Escape") {
e.preventDefault();
cancelRename();
}
}}
onblur={commitRename}
/>
{:else}
<span
class="min-w-0 flex-1 cursor-pointer truncate text-left"
role="button"
tabindex="-1"
title={tab.title}
ondblclick={(e) => {
e.stopPropagation();
startRename(tab);
}}
>
{tab.title}
</span>
{/if}
{#if statusFor?.(tab.conversationId) === "queued"}
<!-- Waiting for a concurrency slot — a ring (vs the dots of `active`). -->
<span
class="loading loading-ring loading-xs shrink-0 text-primary"
aria-label="Queued"
title="Waiting for a concurrency slot"
></span>
{:else if statusFor?.(tab.conversationId) === "active"}
<span class="loading loading-dots loading-xs shrink-0 text-primary"></span>
{/if}
<button
class="btn btn-ghost btn-xs shrink-0"
aria-label="Close tab"
onclick={(e) => {
e.stopPropagation();
onClose(tab.conversationId);
}}
>
×
</button>
</div>
{/each}
</div>
<button
type="button"
class="btn btn-ghost btn-sm w-full border border-base-300"
class:btn-primary={activeConversationId === null}
aria-label="New chat"
onclick={() => onNewDraft()}
>
{#if activeConversationId === null}
New Chat
{:else}
+ New chat
{/if}
</button>
</div>
|