@open-document/core 0.13.3 → 0.14.0

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 (67) hide show
  1. package/dist/{build-CvsOak5B.js → build-CyBlmrjS.js} +1 -1
  2. package/dist/{check-CbUBwYmf.js → check-DUKDEem-.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/{config-CltJJVsw.js → config-cNpYUpF6.js} +2746 -369
  6. package/dist/{context-CWgfsHoE.js → context-BPApOW9n.js} +1 -1
  7. package/dist/{dev-B8H2qT6G.js → dev-DrnOvsX3.js} +1 -1
  8. package/dist/{diff-BvIjjgnc.js → diff-BPMD2Knh.js} +2 -2
  9. package/dist/{export-DX30_s2q.js → export-DeVtL8aX.js} +3 -3
  10. package/dist/{import-DgsdJT5e.js → import-WAgWsuOv.js} +3 -2
  11. package/dist/index.d.ts +2 -2
  12. package/dist/ops/index.d.ts +3 -1
  13. package/dist/ops/index.js +2 -2
  14. package/dist/{ops-CSR5RlrE.js → ops-raK6424A.js} +2 -854
  15. package/dist/{preview-DYMUNjXL.js → preview-B8Vw9QCh.js} +1 -1
  16. package/dist/rolldown-runtime-D7D4PA-g.js +13 -0
  17. package/dist/{templates-B5Tz0AKb.js → templates-D9jAFJ8R.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 +690 -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 +609 -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 +107 -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 +106 -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 +105 -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 +105 -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 +144 -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
@@ -0,0 +1,690 @@
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 session={session} onRespond={onRespond} onEdit={onEdit} />
317
+ ) : isNewDoc ? (
318
+ <NewDocState providerName={providerName} />
319
+ ) : (
320
+ <EmptyState
321
+ pendingComments={pendingComments}
322
+ hasDoc={Boolean(context.docId)}
323
+ onCreate={createDoc}
324
+ onApply={() => context.docId && send(applyCommentsPrompt(context.docId))}
325
+ onTheme={() => send(CREATE_THEME_PROMPT, true)}
326
+ onEdit={() => textareaRef.current?.focus()}
327
+ />
328
+ )}
329
+ <Composer
330
+ value={draft}
331
+ onChange={setDraft}
332
+ onSend={() => send(draft)}
333
+ onStop={() =>
334
+ session &&
335
+ stopSession(session.id).catch((err) => {
336
+ toast.error(err instanceof Error ? err.message : String(err));
337
+ })
338
+ }
339
+ running={Boolean(running)}
340
+ busy={sending}
341
+ placeholder={
342
+ isNewDoc
343
+ ? t.agent.newDocPlaceholder
344
+ : format(t.agent.composerPlaceholder, { provider: providerName })
345
+ }
346
+ chips={chips}
347
+ textareaRef={textareaRef}
348
+ />
349
+ </>
350
+ )}
351
+ </div>
352
+ );
353
+ }
354
+
355
+ function modelLabel(model: AgentModelOption, t: ReturnType<typeof useLocale>): string {
356
+ return model.id ? model.label : t.agent.modelDefault;
357
+ }
358
+
359
+ function ModelMenu({
360
+ status,
361
+ providerId,
362
+ model,
363
+ effort,
364
+ modelChoices,
365
+ autoApprove,
366
+ onManage,
367
+ }: {
368
+ status: ReturnType<typeof useAgentStatus>['status'];
369
+ providerId: AgentProviderId | null;
370
+ model: AgentModelOption | null;
371
+ effort: AgentEffort | null;
372
+ modelChoices: ReturnType<typeof useAgentStatus>['modelChoices'];
373
+ autoApprove: boolean;
374
+ onManage: () => void;
375
+ }) {
376
+ const t = useLocale();
377
+ const [open, setOpen] = useState(false);
378
+ const providers = status?.enabled ? status.providers : [];
379
+ const [tab, setTab] = useState<AgentProviderId | null>(providerId);
380
+ const shownId = tab ?? providerId ?? providers[0]?.id ?? null;
381
+ const shown = providers.find((p) => p.id === shownId) ?? null;
382
+ const choice = shown?.ready ? resolveModelChoice(shown.models, modelChoices[shown.id]) : null;
383
+ const selectedModel = shown?.id === providerId ? (model ?? choice?.model) : choice?.model;
384
+ const selectedEffort = shown?.id === providerId ? effort : (choice?.effort ?? null);
385
+
386
+ return (
387
+ <Popover
388
+ open={open}
389
+ onOpenChange={(next) => {
390
+ setOpen(next);
391
+ if (next) setTab(providerId);
392
+ }}
393
+ >
394
+ <PopoverTrigger
395
+ type="button"
396
+ 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"
397
+ >
398
+ {providerId ? (
399
+ <ProviderLogo provider={providerId} className="size-3.5 shrink-0" />
400
+ ) : (
401
+ <span aria-hidden className="size-1.5 rounded-full bg-muted-foreground/50" />
402
+ )}
403
+ <span className="truncate">{model ? modelLabel(model, t) : t.agent.title}</span>
404
+ {effort && (
405
+ <span className="shrink-0 font-normal text-muted-foreground">
406
+ {t.agent.efforts[effort]}
407
+ </span>
408
+ )}
409
+ <ChevronDown className="size-3 text-muted-foreground" aria-hidden />
410
+ </PopoverTrigger>
411
+ <PopoverContent align="start" className="w-[272px] p-1.5" data-agent-model-menu>
412
+ {providers.length > 1 && (
413
+ <div role="tablist" className="mb-1.5 flex gap-0.5 rounded-[6px] bg-muted p-0.5">
414
+ {providers.map((p) => (
415
+ <button
416
+ key={p.id}
417
+ type="button"
418
+ role="tab"
419
+ aria-selected={p.id === shownId}
420
+ onClick={() => setTab(p.id)}
421
+ className={cn(
422
+ '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',
423
+ p.id === shownId && 'bg-background text-foreground shadow-edge',
424
+ )}
425
+ >
426
+ <ProviderLogo provider={p.id} className="size-3.5 shrink-0" />
427
+ {p.name}
428
+ </button>
429
+ ))}
430
+ </div>
431
+ )}
432
+
433
+ {shown && !shown.ready ? (
434
+ <div className="flex flex-col items-start gap-2 px-2 py-2.5">
435
+ <p className="text-[12px] leading-relaxed text-muted-foreground">
436
+ {shown.cliFound
437
+ ? format(t.agent.connectInstallHint, {
438
+ pkg: shown.sdkPackage,
439
+ pm: status?.packageManager ?? 'npm',
440
+ })
441
+ : format(t.agent.cliHint, { name: shown.name })}
442
+ </p>
443
+ <Button
444
+ size="xs"
445
+ variant="outline"
446
+ onClick={() => {
447
+ setOpen(false);
448
+ onManage();
449
+ }}
450
+ >
451
+ {t.agent.connect}
452
+ </Button>
453
+ </div>
454
+ ) : shown ? (
455
+ <div className="flex flex-col gap-px">
456
+ {shown.models.map((m) => {
457
+ const checked = m.id === selectedModel?.id;
458
+ return (
459
+ <button
460
+ key={m.id}
461
+ type="button"
462
+ aria-pressed={checked}
463
+ onClick={() =>
464
+ setModelChoice(shown.id, {
465
+ model: m.id,
466
+ effort: modelChoices[shown.id]?.effort ?? null,
467
+ })
468
+ }
469
+ className={cn(
470
+ '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',
471
+ checked && 'font-medium',
472
+ )}
473
+ >
474
+ <span className="truncate">{modelLabel(m, t)}</span>
475
+ {checked && <Check className="size-3.5 shrink-0" aria-hidden />}
476
+ </button>
477
+ );
478
+ })}
479
+ </div>
480
+ ) : null}
481
+
482
+ {shown?.ready && selectedModel && selectedModel.efforts.length > 0 && (
483
+ <div className="mt-1.5 border-t border-hairline px-1 pt-2 pb-1">
484
+ <div className="mb-1.5 px-1 text-[11px] font-medium text-muted-foreground">
485
+ {t.agent.reasoning}
486
+ </div>
487
+ <div className="flex gap-0.5 rounded-[6px] bg-muted p-0.5">
488
+ {([null, ...selectedModel.efforts] as (AgentEffort | null)[]).map((e) => {
489
+ const checked = e === selectedEffort;
490
+ return (
491
+ <button
492
+ key={e ?? 'auto'}
493
+ type="button"
494
+ aria-pressed={checked}
495
+ onClick={() => setModelChoice(shown.id, { model: selectedModel.id, effort: e })}
496
+ className={cn(
497
+ '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',
498
+ checked && 'bg-background font-medium text-foreground shadow-edge',
499
+ )}
500
+ >
501
+ {e ? t.agent.efforts[e] : t.agent.effortAuto}
502
+ </button>
503
+ );
504
+ })}
505
+ </div>
506
+ </div>
507
+ )}
508
+
509
+ <div className="mt-1.5 flex flex-col gap-px border-t border-hairline pt-1.5">
510
+ {readyProviders(status).length > 0 && (
511
+ <button
512
+ type="button"
513
+ role="switch"
514
+ aria-checked={autoApprove}
515
+ title={t.agent.autoApproveHint}
516
+ onClick={() => setAutoApprove(!autoApprove)}
517
+ 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"
518
+ >
519
+ {t.agent.autoApprove}
520
+ <span
521
+ aria-hidden
522
+ className={cn(
523
+ 'relative h-4 w-7 shrink-0 rounded-full transition-colors duration-150',
524
+ autoApprove ? 'bg-foreground' : 'bg-foreground/15',
525
+ )}
526
+ >
527
+ <span
528
+ className={cn(
529
+ 'absolute top-0.5 left-0.5 size-3 rounded-full bg-background shadow-sm transition-transform duration-150',
530
+ autoApprove && 'translate-x-3',
531
+ )}
532
+ />
533
+ </span>
534
+ </button>
535
+ )}
536
+ <button
537
+ type="button"
538
+ onClick={() => {
539
+ setOpen(false);
540
+ onManage();
541
+ }}
542
+ 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"
543
+ >
544
+ <Settings2 className="size-3.5" />
545
+ {t.agent.manageConnections}
546
+ </button>
547
+ </div>
548
+ </PopoverContent>
549
+ </Popover>
550
+ );
551
+ }
552
+
553
+ function NewDocState({ providerName }: { providerName: string }) {
554
+ const t = useLocale();
555
+ return (
556
+ <div className="flex min-h-0 flex-1 flex-col justify-end overflow-y-auto px-4 py-5">
557
+ <h2 className="font-heading text-[15px] font-semibold tracking-tight">
558
+ {t.agent.newDocTitle}
559
+ </h2>
560
+ <p className="mt-1 text-[12.5px] leading-relaxed text-muted-foreground">
561
+ {format(t.agent.newDocHint, { provider: providerName })}
562
+ </p>
563
+ </div>
564
+ );
565
+ }
566
+
567
+ function EmptyState({
568
+ pendingComments,
569
+ hasDoc,
570
+ onCreate,
571
+ onApply,
572
+ onTheme,
573
+ onEdit,
574
+ }: {
575
+ pendingComments: number;
576
+ hasDoc: boolean;
577
+ onCreate: () => void;
578
+ onApply: () => void;
579
+ onTheme: () => void;
580
+ onEdit: () => void;
581
+ }) {
582
+ const t = useLocale();
583
+ return (
584
+ <div className="flex min-h-0 flex-1 flex-col justify-end overflow-y-auto px-4 py-5">
585
+ <span className="eyebrow">{t.agent.title}</span>
586
+ <h2 className="mt-1.5 font-heading text-[15px] font-semibold tracking-tight">
587
+ {t.agent.emptyTitle}
588
+ </h2>
589
+ <p className="mt-1 text-[12.5px] text-muted-foreground">{t.agent.emptyHint}</p>
590
+ <div className="mt-4 flex flex-col gap-1.5">
591
+ {hasDoc && pendingComments > 0 && (
592
+ <QuickAction
593
+ icon={<MessageSquare />}
594
+ label={`${t.agent.quickApply} · ${format(plural(pendingComments, t.agent.pendingComments), { count: pendingComments })}`}
595
+ hint={t.agent.quickApplyHint}
596
+ tone="brand"
597
+ onClick={onApply}
598
+ />
599
+ )}
600
+ {hasDoc && (
601
+ <QuickAction
602
+ icon={<Pencil />}
603
+ label={t.agent.quickEdit}
604
+ hint={t.agent.quickEditHint}
605
+ onClick={onEdit}
606
+ />
607
+ )}
608
+ <QuickAction
609
+ icon={<Presentation />}
610
+ label={t.agent.quickCreate}
611
+ hint={t.agent.quickCreateHint}
612
+ onClick={onCreate}
613
+ />
614
+ <QuickAction
615
+ icon={<Palette />}
616
+ label={t.agent.quickTheme}
617
+ hint={t.agent.quickThemeHint}
618
+ onClick={onTheme}
619
+ />
620
+ </div>
621
+ </div>
622
+ );
623
+ }
624
+
625
+ function QuickAction({
626
+ icon,
627
+ label,
628
+ hint,
629
+ tone = 'default',
630
+ onClick,
631
+ }: {
632
+ icon: ReactNode;
633
+ label: string;
634
+ hint: string;
635
+ tone?: 'default' | 'brand';
636
+ onClick: () => void;
637
+ }) {
638
+ return (
639
+ <button
640
+ type="button"
641
+ onClick={onClick}
642
+ className={cn(
643
+ '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',
644
+ tone === 'brand'
645
+ ? 'border-brand/40 bg-brand/[0.06] hover:bg-brand/[0.1]'
646
+ : 'border-border bg-card hover:border-foreground/25 hover:bg-muted/40',
647
+ )}
648
+ >
649
+ <span
650
+ className={cn(
651
+ 'mt-0.5 grid size-5 shrink-0 place-items-center [&_svg]:size-3.5',
652
+ tone === 'brand' ? 'text-brand' : 'text-muted-foreground',
653
+ )}
654
+ >
655
+ {icon}
656
+ </span>
657
+ <span className="min-w-0">
658
+ <span className="block text-[12.5px] font-medium">{label}</span>
659
+ <span className="mt-0.5 block text-[11px] leading-snug text-muted-foreground">{hint}</span>
660
+ </span>
661
+ </button>
662
+ );
663
+ }
664
+
665
+ function BetaBadge() {
666
+ const t = useLocale();
667
+ return (
668
+ <Tooltip>
669
+ <TooltipTrigger
670
+ render={
671
+ <button
672
+ type="button"
673
+ 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"
674
+ >
675
+ {t.agent.beta}
676
+ </button>
677
+ }
678
+ />
679
+ <TooltipContent
680
+ side="bottom"
681
+ align="start"
682
+ sideOffset={6}
683
+ className="w-64 px-3 py-2.5 text-left text-pretty"
684
+ >
685
+ <p className="font-medium text-[12px]">{t.agent.betaTitle}</p>
686
+ <p className="mt-1 text-[11.5px] text-background/70 leading-relaxed">{t.agent.betaHint}</p>
687
+ </TooltipContent>
688
+ </Tooltip>
689
+ );
690
+ }