@open-document/core 0.13.3 → 0.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/dist/{build-CvsOak5B.js → build-I0cgoERP.js} +1 -1
  2. package/dist/{check-CbUBwYmf.js → check-Dys96QSL.js} +3 -3
  3. package/dist/cli/bin.js +10 -21
  4. package/dist/{config-BWtOZ1jc.d.ts → config-cAV1OCuY.d.ts} +9 -1
  5. package/dist/{context-CWgfsHoE.js → context-C-osJW5f.js} +1 -1
  6. package/dist/{dev-B8H2qT6G.js → dev-CC4PrIOC.js} +1 -1
  7. package/dist/{diff-BvIjjgnc.js → diff-DhutD4TJ.js} +2 -2
  8. package/dist/{export-DX30_s2q.js → export-KrajVJO7.js} +3 -3
  9. package/dist/{import-DgsdJT5e.js → import-Yv34za3L.js} +3 -2
  10. package/dist/index.d.ts +2 -2
  11. package/dist/ops/index.d.ts +3 -1
  12. package/dist/ops/index.js +2 -2
  13. package/dist/ops-Dux5HlkH.js +401 -0
  14. package/dist/{preview-DYMUNjXL.js → preview-7eqn9Wzf.js} +1 -1
  15. package/dist/rolldown-runtime-D7D4PA-g.js +13 -0
  16. package/dist/{config-CltJJVsw.js → session-BSbrC5gK.js} +3268 -385
  17. package/dist/{templates-B5Tz0AKb.js → templates-s-VLTSRc.js} +3 -3
  18. package/dist/vite/index.d.ts +1 -1
  19. package/dist/vite/index.js +1 -1
  20. package/package.json +1 -1
  21. package/skills/create-doc/SKILL.md +1 -1
  22. package/skills/doc-authoring/SKILL.md +6 -0
  23. package/src/app/app.tsx +2 -0
  24. package/src/app/components/agent/agent-dock.tsx +75 -0
  25. package/src/app/components/agent/agent-markdown.tsx +45 -0
  26. package/src/app/components/agent/agent-panel.tsx +695 -0
  27. package/src/app/components/agent/agent-presence.tsx +74 -0
  28. package/src/app/components/agent/composer.tsx +120 -0
  29. package/src/app/components/agent/connect-view.tsx +183 -0
  30. package/src/app/components/agent/history-view.tsx +134 -0
  31. package/src/app/components/agent/provider-logo.tsx +23 -0
  32. package/src/app/components/agent/transcript.tsx +717 -0
  33. package/src/app/components/comments/comments-panel.tsx +26 -2
  34. package/src/app/components/inspector/inspector.tsx +17 -0
  35. package/src/app/components/note-markdown.tsx +85 -0
  36. package/src/app/components/page-error-boundary.tsx +84 -0
  37. package/src/app/components/page-frame.tsx +2 -1
  38. package/src/app/components/panel/resize-handle.tsx +129 -0
  39. package/src/app/components/ui/button.tsx +97 -0
  40. package/src/app/components/ui/popover.tsx +144 -0
  41. package/src/app/components/ui/tooltip.tsx +123 -0
  42. package/src/app/lib/agent/use-agent.ts +543 -0
  43. package/src/app/lib/diagnostics.ts +13 -0
  44. package/src/app/lib/export-dom.ts +2 -1
  45. package/src/app/lib/export-pdf.ts +2 -1
  46. package/src/app/lib/i18n-ja/agent-panel.ts +115 -0
  47. package/src/app/lib/i18n-ja/agent.ts +9 -0
  48. package/src/app/lib/i18n-ja/index.ts +9 -1
  49. package/src/app/lib/i18n-ko/agent-panel.ts +114 -0
  50. package/src/app/lib/i18n-ko/agent.ts +9 -0
  51. package/src/app/lib/i18n-ko/index.ts +9 -1
  52. package/src/app/lib/i18n-zh-cn/agent-panel.ts +113 -0
  53. package/src/app/lib/i18n-zh-cn/agent.ts +9 -0
  54. package/src/app/lib/i18n-zh-cn/index.ts +9 -1
  55. package/src/app/lib/i18n-zh-tw/agent-panel.ts +113 -0
  56. package/src/app/lib/i18n-zh-tw/agent.ts +9 -0
  57. package/src/app/lib/i18n-zh-tw/index.ts +9 -1
  58. package/src/app/lib/note-markdown.ts +116 -0
  59. package/src/app/lib/toast.ts +50 -0
  60. package/src/app/lib/use-auto-grow.ts +15 -0
  61. package/src/app/lib/use-doc-titles.ts +28 -0
  62. package/src/app/lib/use-locale.ts +151 -0
  63. package/src/app/lib/utils.ts +4 -0
  64. package/src/app/routes/doc-preview.tsx +103 -0
  65. package/src/app/routes/doc.tsx +118 -11
  66. package/src/app/routes/home.tsx +43 -8
  67. package/src/app/styles.css +193 -0
  68. package/dist/ops-CSR5RlrE.js +0 -1673
@@ -0,0 +1,695 @@
1
+ import {
2
+ Check,
3
+ ChevronDown,
4
+ ChevronLeft,
5
+ History,
6
+ MessageSquare,
7
+ Palette,
8
+ Pencil,
9
+ Plus,
10
+ Presentation,
11
+ Settings2,
12
+ X,
13
+ } from 'lucide-react';
14
+ import { type ReactNode, useCallback, useEffect, useRef, useState } from 'react';
15
+ import { useNavigate } from 'react-router-dom';
16
+ import { Button } from '@/components/ui/button';
17
+ import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover';
18
+ import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip';
19
+ import {
20
+ autoConnect,
21
+ clearNewDoc,
22
+ consumeRequest,
23
+ createSession,
24
+ deleteSession,
25
+ readyProviders,
26
+ resolveModelChoice,
27
+ respond,
28
+ sendMessage,
29
+ setActiveSession,
30
+ setAutoApprove,
31
+ setModelChoice,
32
+ stopSession,
33
+ useAgentSession,
34
+ useAgentSessions,
35
+ useAgentState,
36
+ useAgentStatus,
37
+ useCreateDoc,
38
+ } from '@/lib/agent/use-agent';
39
+ import { toast } from '@/lib/toast';
40
+ import { format, plural, useLocale } from '@/lib/use-locale';
41
+ import { cn } from '@/lib/utils';
42
+ import { applyCommentsPrompt } from '../../../agent/prompt';
43
+ import type {
44
+ AgentEffort,
45
+ AgentModelOption,
46
+ AgentProviderId,
47
+ AgentTurnContext,
48
+ RespondPayload,
49
+ } from '../../../agent/types';
50
+ import { Composer, ContextChip } from './composer';
51
+ import { ConnectView } from './connect-view';
52
+ import { HistoryView } from './history-view';
53
+ import { ProviderLogo } from './provider-logo';
54
+ import { Transcript } from './transcript';
55
+
56
+ const CREATE_THEME_PROMPT =
57
+ 'Use the create-theme skill to create a reusable theme. Ask me what it should look like first.';
58
+
59
+ export function AgentPanel({
60
+ context,
61
+ onClose,
62
+ }: {
63
+ context: AgentTurnContext;
64
+ onClose: () => void;
65
+ }) {
66
+ const t = useLocale();
67
+ const { status, loading, connected, provider, model, effort, modelChoices } = useAgentStatus();
68
+ const { sessions, loaded: sessionsLoaded, activeId } = useAgentSessions();
69
+ const session = useAgentSession(activeId);
70
+ const { request, autoApprove, newDoc } = useAgentState();
71
+ const [draft, setDraft] = useState('');
72
+ const [sending, setSending] = useState(false);
73
+ const sendingRef = useRef(false);
74
+ const [manage, setManage] = useState(false);
75
+ const [view, setView] = useState<'chat' | 'history'>('chat');
76
+ const navigate = useNavigate();
77
+ const textareaRef = useRef<HTMLTextAreaElement>(null);
78
+ const running = session?.status === 'running';
79
+ const showConnect = !loading && (!connected || manage);
80
+
81
+ useEffect(() => {
82
+ if (status) void autoConnect();
83
+ }, [status]);
84
+
85
+ const contextRef = useRef(context);
86
+ contextRef.current = context;
87
+
88
+ // Arriving at another deck starts a new conversation; the previous one stays
89
+ // in history. Picking a chat from history navigates to its own deck, so it
90
+ // survives this check.
91
+ const docId = context.docId ?? null;
92
+ const checkedDocRef = useRef<string | null | undefined>(undefined);
93
+ useEffect(() => {
94
+ if (!sessionsLoaded || checkedDocRef.current === docId) return;
95
+ checkedDocRef.current = docId;
96
+ const active = activeId ? sessions.find((s) => s.id === activeId) : null;
97
+ if (active?.docId && active.docId !== docId) setActiveSession(null);
98
+ }, [docId, sessionsLoaded, activeId, sessions]);
99
+ const isNewDoc = Boolean(context.docId) && newDoc === context.docId;
100
+
101
+ const ensureSession = useCallback(
102
+ async (fresh: boolean) => {
103
+ const current = activeId ? sessions.find((s) => s.id === activeId) : null;
104
+ if (!provider) throw new Error('no agent connected');
105
+ if (!fresh && current && current.status !== 'running' && current.provider === provider.id) {
106
+ return current.id;
107
+ }
108
+ const created = await createSession(provider.id, contextRef.current.docId ?? null);
109
+ return created.id;
110
+ },
111
+ [activeId, sessions, provider],
112
+ );
113
+
114
+ const send = useCallback(
115
+ async (text: string, fresh = false) => {
116
+ const trimmed = text.trim();
117
+ // A second agent would edit the same deck alongside the running one.
118
+ if (!trimmed || sendingRef.current || (running && !fresh)) return;
119
+ sendingRef.current = true;
120
+ setSending(true);
121
+ try {
122
+ const id = await ensureSession(fresh || isNewDoc);
123
+ setDraft('');
124
+ await sendMessage(
125
+ id,
126
+ trimmed,
127
+ isNewDoc ? { ...contextRef.current, newDoc: true } : contextRef.current,
128
+ );
129
+ if (isNewDoc) clearNewDoc();
130
+ } catch (err) {
131
+ toast.error(t.agent.toastSendFailed, {
132
+ description: err instanceof Error ? err.message : undefined,
133
+ });
134
+ } finally {
135
+ sendingRef.current = false;
136
+ setSending(false);
137
+ }
138
+ },
139
+ [ensureSession, isNewDoc, running, t],
140
+ );
141
+
142
+ const createDoc = useCreateDoc();
143
+
144
+ useEffect(() => {
145
+ if (isNewDoc && connected) textareaRef.current?.focus();
146
+ }, [isNewDoc, connected]);
147
+
148
+ // A request made while a turn runs waits for it to end, then joins the same
149
+ // conversation.
150
+ useEffect(() => {
151
+ if (!request || loading || !connected || running) return;
152
+ const req = consumeRequest();
153
+ if (!req) return;
154
+ setManage(false);
155
+ void send(req.text);
156
+ }, [request, loading, connected, running, send]);
157
+
158
+ const onRespond = useCallback(
159
+ async (itemId: string, payload: RespondPayload) => {
160
+ if (!session) return;
161
+ try {
162
+ await respond(session.id, itemId, payload, contextRef.current);
163
+ } catch (err) {
164
+ toast.error(err instanceof Error ? err.message : String(err));
165
+ }
166
+ },
167
+ [session],
168
+ );
169
+
170
+ const providerName = provider?.name ?? '';
171
+ const onEdit = useCallback(
172
+ async (itemId: string, text: string) => {
173
+ if (!session) return;
174
+ try {
175
+ await sendMessage(session.id, text, contextRef.current, itemId);
176
+ } catch (err) {
177
+ toast.error(t.agent.toastSendFailed, {
178
+ description: err instanceof Error ? err.message : undefined,
179
+ });
180
+ }
181
+ },
182
+ [session, t],
183
+ );
184
+
185
+ const pendingComments = context.pendingComments ?? 0;
186
+
187
+ const chips: ReactNode = context.docId ? (
188
+ <>
189
+ <ContextChip title={context.docId}>
190
+ {context.docTitle ?? context.docId}
191
+ {context.pageNumber ? ` · ${format(t.agent.contextPage, { n: context.pageNumber })}` : ''}
192
+ </ContextChip>
193
+ {context.selection && (
194
+ <ContextChip title={context.selection.text || undefined}>
195
+ {`<${context.selection.tagName}>`} {t.agent.contextSelection}
196
+ </ContextChip>
197
+ )}
198
+ {pendingComments > 0 && (
199
+ <ContextChip
200
+ tone="brand"
201
+ title={t.agent.quickApplyHint}
202
+ onClick={
203
+ running ? undefined : () => context.docId && send(applyCommentsPrompt(context.docId))
204
+ }
205
+ >
206
+ {format(plural(pendingComments, t.agent.pendingComments), { count: pendingComments })} ·{' '}
207
+ {t.agent.applyComments}
208
+ </ContextChip>
209
+ )}
210
+ </>
211
+ ) : null;
212
+
213
+ return (
214
+ <div
215
+ data-agent-provider={provider?.id}
216
+ className="relative flex h-full min-h-0 flex-col bg-sidebar"
217
+ >
218
+ {running && <span aria-hidden className="agent-progress z-10" />}
219
+ <header className="relative z-10 flex h-9 shrink-0 items-center justify-between gap-1 bg-sidebar px-2">
220
+ <span
221
+ aria-hidden
222
+ className="pointer-events-none absolute inset-x-0 top-full h-5 bg-gradient-to-b from-sidebar to-transparent"
223
+ />
224
+ <div className="flex min-w-0 items-center gap-0.5">
225
+ {showConnect && connected ? (
226
+ <Button size="xs" variant="ghost" onClick={() => setManage(false)}>
227
+ {t.agent.backToChat}
228
+ </Button>
229
+ ) : view === 'history' ? (
230
+ <Button size="xs" variant="ghost" onClick={() => setView('chat')}>
231
+ <ChevronLeft className="size-3.5" />
232
+ {t.agent.sessions}
233
+ </Button>
234
+ ) : (
235
+ <ModelMenu
236
+ status={status}
237
+ providerId={provider?.id ?? null}
238
+ model={model}
239
+ effort={effort}
240
+ modelChoices={modelChoices}
241
+ autoApprove={autoApprove}
242
+ onManage={() => setManage(true)}
243
+ />
244
+ )}
245
+ <BetaBadge />
246
+ </div>
247
+ <div className="flex shrink-0 items-center gap-0.5">
248
+ {connected && !showConnect && (
249
+ <>
250
+ <Button
251
+ size="icon-sm"
252
+ variant="ghost"
253
+ aria-label={t.agent.sessions}
254
+ aria-pressed={view === 'history'}
255
+ title={t.agent.sessions}
256
+ className="aria-pressed:bg-muted aria-pressed:text-foreground"
257
+ onClick={() => setView((v) => (v === 'history' ? 'chat' : 'history'))}
258
+ >
259
+ <History className="size-3.5" />
260
+ </Button>
261
+ <Button
262
+ size="icon-sm"
263
+ variant="ghost"
264
+ aria-label={t.agent.newSession}
265
+ title={t.agent.newSession}
266
+ onClick={() => {
267
+ setActiveSession(null);
268
+ setView('chat');
269
+ setDraft('');
270
+ queueMicrotask(() => textareaRef.current?.focus());
271
+ }}
272
+ >
273
+ <Plus className="size-3.5" />
274
+ </Button>
275
+ </>
276
+ )}
277
+ <Button
278
+ size="icon-sm"
279
+ variant="ghost"
280
+ aria-label={t.agent.close}
281
+ title={t.agent.close}
282
+ onClick={onClose}
283
+ >
284
+ <X className="size-3.5" />
285
+ </Button>
286
+ </div>
287
+ </header>
288
+
289
+ {loading ? (
290
+ <p className="px-4 py-5 text-[12px] text-muted-foreground">{t.agent.statusLoading}…</p>
291
+ ) : showConnect ? (
292
+ <div className="min-h-0 flex-1 overflow-y-auto">
293
+ <ConnectView />
294
+ </div>
295
+ ) : view === 'history' ? (
296
+ <HistoryView
297
+ sessions={sessions}
298
+ activeId={activeId}
299
+ docId={context.docId ?? null}
300
+ onSelect={(s) => {
301
+ setActiveSession(s.id);
302
+ setView('chat');
303
+ if (s.docId && s.docId !== context.docId) navigate(`/d/${s.docId}`);
304
+ }}
305
+ onDelete={async (id) => {
306
+ try {
307
+ await deleteSession(id);
308
+ } catch (err) {
309
+ toast.error(err instanceof Error ? err.message : String(err));
310
+ }
311
+ }}
312
+ />
313
+ ) : (
314
+ <>
315
+ {session && session.items.length > 0 ? (
316
+ <Transcript
317
+ session={session}
318
+ onRespond={onRespond}
319
+ onEdit={onEdit}
320
+ onFix={(text) => send(text)}
321
+ />
322
+ ) : isNewDoc ? (
323
+ <NewDocState providerName={providerName} />
324
+ ) : (
325
+ <EmptyState
326
+ pendingComments={pendingComments}
327
+ hasDoc={Boolean(context.docId)}
328
+ onCreate={createDoc}
329
+ onApply={() => context.docId && send(applyCommentsPrompt(context.docId))}
330
+ onTheme={() => send(CREATE_THEME_PROMPT, true)}
331
+ onEdit={() => textareaRef.current?.focus()}
332
+ />
333
+ )}
334
+ <Composer
335
+ value={draft}
336
+ onChange={setDraft}
337
+ onSend={() => send(draft)}
338
+ onStop={() =>
339
+ session &&
340
+ stopSession(session.id).catch((err) => {
341
+ toast.error(err instanceof Error ? err.message : String(err));
342
+ })
343
+ }
344
+ running={Boolean(running)}
345
+ busy={sending}
346
+ placeholder={
347
+ isNewDoc
348
+ ? t.agent.newDocPlaceholder
349
+ : format(t.agent.composerPlaceholder, { provider: providerName })
350
+ }
351
+ chips={chips}
352
+ textareaRef={textareaRef}
353
+ />
354
+ </>
355
+ )}
356
+ </div>
357
+ );
358
+ }
359
+
360
+ function modelLabel(model: AgentModelOption, t: ReturnType<typeof useLocale>): string {
361
+ return model.id ? model.label : t.agent.modelDefault;
362
+ }
363
+
364
+ function ModelMenu({
365
+ status,
366
+ providerId,
367
+ model,
368
+ effort,
369
+ modelChoices,
370
+ autoApprove,
371
+ onManage,
372
+ }: {
373
+ status: ReturnType<typeof useAgentStatus>['status'];
374
+ providerId: AgentProviderId | null;
375
+ model: AgentModelOption | null;
376
+ effort: AgentEffort | null;
377
+ modelChoices: ReturnType<typeof useAgentStatus>['modelChoices'];
378
+ autoApprove: boolean;
379
+ onManage: () => void;
380
+ }) {
381
+ const t = useLocale();
382
+ const [open, setOpen] = useState(false);
383
+ const providers = status?.enabled ? status.providers : [];
384
+ const [tab, setTab] = useState<AgentProviderId | null>(providerId);
385
+ const shownId = tab ?? providerId ?? providers[0]?.id ?? null;
386
+ const shown = providers.find((p) => p.id === shownId) ?? null;
387
+ const choice = shown?.ready ? resolveModelChoice(shown.models, modelChoices[shown.id]) : null;
388
+ const selectedModel = shown?.id === providerId ? (model ?? choice?.model) : choice?.model;
389
+ const selectedEffort = shown?.id === providerId ? effort : (choice?.effort ?? null);
390
+
391
+ return (
392
+ <Popover
393
+ open={open}
394
+ onOpenChange={(next) => {
395
+ setOpen(next);
396
+ if (next) setTab(providerId);
397
+ }}
398
+ >
399
+ <PopoverTrigger
400
+ type="button"
401
+ className="flex h-7 min-w-0 items-center gap-1.5 rounded-[5px] px-2 text-[12.5px] font-medium outline-none transition-colors duration-100 hover:bg-muted focus-visible:ring-2 focus-visible:ring-ring/30 aria-expanded:bg-muted"
402
+ >
403
+ {providerId ? (
404
+ <ProviderLogo provider={providerId} className="size-3.5 shrink-0" />
405
+ ) : (
406
+ <span aria-hidden className="size-1.5 rounded-full bg-muted-foreground/50" />
407
+ )}
408
+ <span className="truncate">{model ? modelLabel(model, t) : t.agent.title}</span>
409
+ {effort && (
410
+ <span className="shrink-0 font-normal text-muted-foreground">
411
+ {t.agent.efforts[effort]}
412
+ </span>
413
+ )}
414
+ <ChevronDown className="size-3 text-muted-foreground" aria-hidden />
415
+ </PopoverTrigger>
416
+ <PopoverContent align="start" className="w-[272px] p-1.5" data-agent-model-menu>
417
+ {providers.length > 1 && (
418
+ <div role="tablist" className="mb-1.5 flex gap-0.5 rounded-[6px] bg-muted p-0.5">
419
+ {providers.map((p) => (
420
+ <button
421
+ key={p.id}
422
+ type="button"
423
+ role="tab"
424
+ aria-selected={p.id === shownId}
425
+ onClick={() => setTab(p.id)}
426
+ className={cn(
427
+ 'flex h-7 flex-1 items-center justify-center gap-1.5 rounded-[5px] text-[12px] font-medium text-muted-foreground outline-none transition-colors duration-100 hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/30',
428
+ p.id === shownId && 'bg-background text-foreground shadow-edge',
429
+ )}
430
+ >
431
+ <ProviderLogo provider={p.id} className="size-3.5 shrink-0" />
432
+ {p.name}
433
+ </button>
434
+ ))}
435
+ </div>
436
+ )}
437
+
438
+ {shown && !shown.ready ? (
439
+ <div className="flex flex-col items-start gap-2 px-2 py-2.5">
440
+ <p className="text-[12px] leading-relaxed text-muted-foreground">
441
+ {shown.cliFound
442
+ ? format(t.agent.connectInstallHint, {
443
+ pkg: shown.sdkPackage,
444
+ pm: status?.packageManager ?? 'npm',
445
+ })
446
+ : format(t.agent.cliHint, { name: shown.name })}
447
+ </p>
448
+ <Button
449
+ size="xs"
450
+ variant="outline"
451
+ onClick={() => {
452
+ setOpen(false);
453
+ onManage();
454
+ }}
455
+ >
456
+ {t.agent.connect}
457
+ </Button>
458
+ </div>
459
+ ) : shown ? (
460
+ <div className="flex flex-col gap-px">
461
+ {shown.models.map((m) => {
462
+ const checked = m.id === selectedModel?.id;
463
+ return (
464
+ <button
465
+ key={m.id}
466
+ type="button"
467
+ aria-pressed={checked}
468
+ onClick={() =>
469
+ setModelChoice(shown.id, {
470
+ model: m.id,
471
+ effort: modelChoices[shown.id]?.effort ?? null,
472
+ })
473
+ }
474
+ className={cn(
475
+ 'flex h-7 items-center justify-between gap-2 rounded-[5px] px-2 text-left text-[12.5px] outline-none transition-colors duration-100 hover:bg-muted focus-visible:bg-muted',
476
+ checked && 'font-medium',
477
+ )}
478
+ >
479
+ <span className="truncate">{modelLabel(m, t)}</span>
480
+ {checked && <Check className="size-3.5 shrink-0" aria-hidden />}
481
+ </button>
482
+ );
483
+ })}
484
+ </div>
485
+ ) : null}
486
+
487
+ {shown?.ready && selectedModel && selectedModel.efforts.length > 0 && (
488
+ <div className="mt-1.5 border-t border-hairline px-1 pt-2 pb-1">
489
+ <div className="mb-1.5 px-1 text-[11px] font-medium text-muted-foreground">
490
+ {t.agent.reasoning}
491
+ </div>
492
+ <div className="flex gap-0.5 rounded-[6px] bg-muted p-0.5">
493
+ {([null, ...selectedModel.efforts] as (AgentEffort | null)[]).map((e) => {
494
+ const checked = e === selectedEffort;
495
+ return (
496
+ <button
497
+ key={e ?? 'auto'}
498
+ type="button"
499
+ aria-pressed={checked}
500
+ onClick={() => setModelChoice(shown.id, { model: selectedModel.id, effort: e })}
501
+ className={cn(
502
+ 'h-6 min-w-0 flex-1 truncate rounded-[4px] px-1 text-[11.5px] text-muted-foreground outline-none transition-colors duration-100 hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/30',
503
+ checked && 'bg-background font-medium text-foreground shadow-edge',
504
+ )}
505
+ >
506
+ {e ? t.agent.efforts[e] : t.agent.effortAuto}
507
+ </button>
508
+ );
509
+ })}
510
+ </div>
511
+ </div>
512
+ )}
513
+
514
+ <div className="mt-1.5 flex flex-col gap-px border-t border-hairline pt-1.5">
515
+ {readyProviders(status).length > 0 && (
516
+ <button
517
+ type="button"
518
+ role="switch"
519
+ aria-checked={autoApprove}
520
+ title={t.agent.autoApproveHint}
521
+ onClick={() => setAutoApprove(!autoApprove)}
522
+ className="flex h-7 items-center justify-between gap-2 rounded-[5px] px-2 text-[12.5px] outline-none transition-colors duration-100 hover:bg-muted focus-visible:bg-muted"
523
+ >
524
+ {t.agent.autoApprove}
525
+ <span
526
+ aria-hidden
527
+ className={cn(
528
+ 'relative h-4 w-7 shrink-0 rounded-full transition-colors duration-150',
529
+ autoApprove ? 'bg-foreground' : 'bg-foreground/15',
530
+ )}
531
+ >
532
+ <span
533
+ className={cn(
534
+ 'absolute top-0.5 left-0.5 size-3 rounded-full bg-background shadow-sm transition-transform duration-150',
535
+ autoApprove && 'translate-x-3',
536
+ )}
537
+ />
538
+ </span>
539
+ </button>
540
+ )}
541
+ <button
542
+ type="button"
543
+ onClick={() => {
544
+ setOpen(false);
545
+ onManage();
546
+ }}
547
+ className="flex h-7 items-center gap-2 rounded-[5px] px-2 text-[12.5px] text-muted-foreground outline-none transition-colors duration-100 hover:bg-muted hover:text-foreground focus-visible:bg-muted"
548
+ >
549
+ <Settings2 className="size-3.5" />
550
+ {t.agent.manageConnections}
551
+ </button>
552
+ </div>
553
+ </PopoverContent>
554
+ </Popover>
555
+ );
556
+ }
557
+
558
+ function NewDocState({ providerName }: { providerName: string }) {
559
+ const t = useLocale();
560
+ return (
561
+ <div className="flex min-h-0 flex-1 flex-col justify-end overflow-y-auto px-4 py-5">
562
+ <h2 className="font-heading text-[15px] font-semibold tracking-tight">
563
+ {t.agent.newDocTitle}
564
+ </h2>
565
+ <p className="mt-1 text-[12.5px] leading-relaxed text-muted-foreground">
566
+ {format(t.agent.newDocHint, { provider: providerName })}
567
+ </p>
568
+ </div>
569
+ );
570
+ }
571
+
572
+ function EmptyState({
573
+ pendingComments,
574
+ hasDoc,
575
+ onCreate,
576
+ onApply,
577
+ onTheme,
578
+ onEdit,
579
+ }: {
580
+ pendingComments: number;
581
+ hasDoc: boolean;
582
+ onCreate: () => void;
583
+ onApply: () => void;
584
+ onTheme: () => void;
585
+ onEdit: () => void;
586
+ }) {
587
+ const t = useLocale();
588
+ return (
589
+ <div className="flex min-h-0 flex-1 flex-col justify-end overflow-y-auto px-4 py-5">
590
+ <span className="eyebrow">{t.agent.title}</span>
591
+ <h2 className="mt-1.5 font-heading text-[15px] font-semibold tracking-tight">
592
+ {t.agent.emptyTitle}
593
+ </h2>
594
+ <p className="mt-1 text-[12.5px] text-muted-foreground">{t.agent.emptyHint}</p>
595
+ <div className="mt-4 flex flex-col gap-1.5">
596
+ {hasDoc && pendingComments > 0 && (
597
+ <QuickAction
598
+ icon={<MessageSquare />}
599
+ label={`${t.agent.quickApply} · ${format(plural(pendingComments, t.agent.pendingComments), { count: pendingComments })}`}
600
+ hint={t.agent.quickApplyHint}
601
+ tone="brand"
602
+ onClick={onApply}
603
+ />
604
+ )}
605
+ {hasDoc && (
606
+ <QuickAction
607
+ icon={<Pencil />}
608
+ label={t.agent.quickEdit}
609
+ hint={t.agent.quickEditHint}
610
+ onClick={onEdit}
611
+ />
612
+ )}
613
+ <QuickAction
614
+ icon={<Presentation />}
615
+ label={t.agent.quickCreate}
616
+ hint={t.agent.quickCreateHint}
617
+ onClick={onCreate}
618
+ />
619
+ <QuickAction
620
+ icon={<Palette />}
621
+ label={t.agent.quickTheme}
622
+ hint={t.agent.quickThemeHint}
623
+ onClick={onTheme}
624
+ />
625
+ </div>
626
+ </div>
627
+ );
628
+ }
629
+
630
+ function QuickAction({
631
+ icon,
632
+ label,
633
+ hint,
634
+ tone = 'default',
635
+ onClick,
636
+ }: {
637
+ icon: ReactNode;
638
+ label: string;
639
+ hint: string;
640
+ tone?: 'default' | 'brand';
641
+ onClick: () => void;
642
+ }) {
643
+ return (
644
+ <button
645
+ type="button"
646
+ onClick={onClick}
647
+ className={cn(
648
+ 'flex items-start gap-2.5 rounded-[8px] border px-3 py-2.5 text-left outline-none transition-colors duration-100 focus-visible:ring-2 focus-visible:ring-ring/30',
649
+ tone === 'brand'
650
+ ? 'border-brand/40 bg-brand/[0.06] hover:bg-brand/[0.1]'
651
+ : 'border-border bg-card hover:border-foreground/25 hover:bg-muted/40',
652
+ )}
653
+ >
654
+ <span
655
+ className={cn(
656
+ 'mt-0.5 grid size-5 shrink-0 place-items-center [&_svg]:size-3.5',
657
+ tone === 'brand' ? 'text-brand' : 'text-muted-foreground',
658
+ )}
659
+ >
660
+ {icon}
661
+ </span>
662
+ <span className="min-w-0">
663
+ <span className="block text-[12.5px] font-medium">{label}</span>
664
+ <span className="mt-0.5 block text-[11px] leading-snug text-muted-foreground">{hint}</span>
665
+ </span>
666
+ </button>
667
+ );
668
+ }
669
+
670
+ function BetaBadge() {
671
+ const t = useLocale();
672
+ return (
673
+ <Tooltip>
674
+ <TooltipTrigger
675
+ render={
676
+ <button
677
+ type="button"
678
+ className="ml-1 shrink-0 cursor-default rounded-[3px] border border-border px-1 py-px font-medium text-[9px] text-muted-foreground uppercase leading-none tracking-wider outline-none focus-visible:ring-1 focus-visible:ring-brand"
679
+ >
680
+ {t.agent.beta}
681
+ </button>
682
+ }
683
+ />
684
+ <TooltipContent
685
+ side="bottom"
686
+ align="start"
687
+ sideOffset={6}
688
+ className="w-64 px-3 py-2.5 text-left text-pretty"
689
+ >
690
+ <p className="font-medium text-[12px]">{t.agent.betaTitle}</p>
691
+ <p className="mt-1 text-[11.5px] text-background/70 leading-relaxed">{t.agent.betaHint}</p>
692
+ </TooltipContent>
693
+ </Tooltip>
694
+ );
695
+ }