@open-slide/core 2.3.1 → 2.4.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 (89) hide show
  1. package/dist/{build-8lRsgsO4.js → build-D7GwYl8d.js} +1 -1
  2. package/dist/cli/bin.js +4 -4
  3. package/dist/{config-CDrYgaEj.d.ts → config-CfhtJxQH.d.ts} +1 -1
  4. package/dist/{config-D2Mq1vSW.js → config-D4uPk_tM.js} +383 -138
  5. package/dist/{dev-BvefEp1Q.js → dev-DyCDMbHB.js} +10 -10
  6. package/dist/index.d.ts +2 -2
  7. package/dist/index.js +9 -1
  8. package/dist/locale/index.d.ts +1 -1
  9. package/dist/locale/index.js +1 -1
  10. package/dist/{preview-D8ognobz.js → preview-DjIFvt0K.js} +1 -1
  11. package/dist/{types-DFK02XVv.d.ts → types-ZfArJF0d.d.ts} +21 -13
  12. package/dist/{update-BivdNgL3.js → update-BKhRM7o4.js} +30 -3
  13. package/dist/vite/index.d.ts +1 -1
  14. package/dist/vite/index.js +1 -1
  15. package/dist/{zh-tw-B1pkKQsc.js → zh-tw-D7LfGVmA.js} +220 -65
  16. package/package.json +5 -6
  17. package/src/agent/provider.ts +8 -1
  18. package/src/agent/types.ts +17 -2
  19. package/src/app/app.tsx +2 -0
  20. package/src/app/components/agent/agent-markdown.tsx +3 -6
  21. package/src/app/components/agent/agent-panel.tsx +36 -258
  22. package/src/app/components/agent/agent-presence.tsx +1 -1
  23. package/src/app/components/agent/composer.tsx +52 -24
  24. package/src/app/components/agent/effort-slider.tsx +172 -0
  25. package/src/app/components/agent/model-menu.tsx +170 -0
  26. package/src/app/components/agent/permission-menu.tsx +88 -0
  27. package/src/app/components/agent/transcript.tsx +23 -31
  28. package/src/app/components/command/home-command-menu.tsx +4 -1
  29. package/src/app/components/command/slide-command-menu.tsx +4 -1
  30. package/src/app/components/export-progress-toast.tsx +3 -1
  31. package/src/app/components/inspector/asset-picker-dialog.tsx +1 -1
  32. package/src/app/components/inspector/comment-layer.tsx +3 -3
  33. package/src/app/components/inspector/inline-text-editor.tsx +1 -12
  34. package/src/app/components/inspector/inspect-overlay.tsx +9 -1
  35. package/src/app/components/inspector/inspector-panel.tsx +8 -35
  36. package/src/app/components/inspector/inspector-provider.tsx +177 -36
  37. package/src/app/components/inspector/page-panel.tsx +270 -0
  38. package/src/app/components/language-toggle.tsx +13 -11
  39. package/src/app/components/note-markdown.test.tsx +12 -6
  40. package/src/app/components/note-markdown.tsx +16 -21
  41. package/src/app/components/overview-grid.tsx +3 -3
  42. package/src/app/components/panel/editor-sidebar.tsx +43 -8
  43. package/src/app/components/panel/panel-shell.tsx +9 -5
  44. package/src/app/components/panel/save-card.tsx +1 -1
  45. package/src/app/components/player.tsx +105 -23
  46. package/src/app/components/present/curtain.tsx +52 -0
  47. package/src/app/components/present/last-slide-hint.tsx +36 -0
  48. package/src/app/components/sidebar/folder-item.tsx +4 -1
  49. package/src/app/components/sidebar/sidebar.tsx +11 -8
  50. package/src/app/components/slide-canvas.tsx +1 -1
  51. package/src/app/components/style-panel/design-provider.tsx +48 -11
  52. package/src/app/components/style-panel/use-design.ts +6 -1
  53. package/src/app/components/theme-toggle.tsx +16 -22
  54. package/src/app/components/thumbnail-rail.tsx +69 -50
  55. package/src/app/components/ui/context-menu.tsx +9 -10
  56. package/src/app/components/ui/dialog.tsx +2 -4
  57. package/src/app/components/ui/dropdown-menu.tsx +9 -10
  58. package/src/app/components/ui/popover.tsx +1 -1
  59. package/src/app/components/ui/select.tsx +2 -2
  60. package/src/app/components/ui/sonner.tsx +2 -2
  61. package/src/app/index.html +7 -0
  62. package/src/app/lib/agent/use-agent.ts +131 -37
  63. package/src/app/lib/desktop-host.ts +31 -0
  64. package/src/app/lib/desktop-routes.test.ts +54 -0
  65. package/src/app/lib/desktop-routes.ts +22 -0
  66. package/src/app/lib/desktop.ts +106 -0
  67. package/src/app/lib/export-pdf.ts +15 -7
  68. package/src/app/lib/inspector/color.ts +51 -0
  69. package/src/app/lib/inspector/fiber.ts +6 -0
  70. package/src/app/lib/inspector/use-editor.ts +2 -1
  71. package/src/app/lib/inspector/use-notes.test.ts +209 -0
  72. package/src/app/lib/inspector/use-notes.ts +331 -57
  73. package/src/app/lib/inspector/use-visual-editor.ts +9 -1
  74. package/src/app/lib/locale-store.ts +14 -2
  75. package/src/app/lib/note-markdown.test.ts +69 -5
  76. package/src/app/lib/note-markdown.ts +97 -22
  77. package/src/app/lib/transition.test.ts +84 -1
  78. package/src/app/lib/transition.ts +43 -0
  79. package/src/app/lib/unsaved.test.ts +253 -0
  80. package/src/app/lib/unsaved.ts +155 -0
  81. package/src/app/routes/home.tsx +14 -6
  82. package/src/app/routes/slide.tsx +184 -130
  83. package/src/app/styles.css +421 -1
  84. package/src/locale/en.ts +41 -15
  85. package/src/locale/es.ts +41 -17
  86. package/src/locale/ja.ts +41 -15
  87. package/src/locale/types.ts +20 -14
  88. package/src/locale/zh-cn.ts +41 -14
  89. package/src/locale/zh-tw.ts +41 -14
@@ -25,14 +25,11 @@ function splitFences(text: string): Segment[] {
25
25
  export function AgentMarkdown({ text }: { text: string }) {
26
26
  const segments = useMemo(() => splitFences(text), [text]);
27
27
  return (
28
- <div className="space-y-2 text-[12.5px] leading-[1.55] [&_ol]:my-1 [&_ul]:my-1">
28
+ <div className="agent-prose">
29
29
  {segments.map((segment, i) =>
30
30
  segment.type === 'code' ? (
31
- <pre
32
- // biome-ignore lint/suspicious/noArrayIndexKey: static parse output, never reordered
33
- key={i}
34
- className="overflow-x-auto rounded-[6px] border border-hairline bg-muted/60 px-2.5 py-2 font-mono text-[11px] leading-relaxed"
35
- >
31
+ // biome-ignore lint/suspicious/noArrayIndexKey: static parse output, never reordered
32
+ <pre key={i}>
36
33
  <code>{segment.code}</code>
37
34
  </pre>
38
35
  ) : (
@@ -1,35 +1,28 @@
1
1
  import {
2
- Check,
3
- ChevronDown,
4
2
  ChevronLeft,
5
3
  History,
6
4
  MessageSquare,
5
+ MousePointer2,
7
6
  Palette,
8
7
  Pencil,
9
8
  Plus,
10
9
  Presentation,
11
- Settings2,
12
10
  X,
13
11
  } from 'lucide-react';
14
12
  import { type ReactNode, useCallback, useEffect, useRef, useState } from 'react';
15
13
  import { useNavigate } from 'react-router-dom';
16
14
  import { toast } from 'sonner';
17
15
  import { Button } from '@/components/ui/button';
18
- import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover';
19
- import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip';
20
16
  import {
21
17
  autoConnect,
22
18
  clearNewDeck,
23
19
  consumeRequest,
24
20
  createSession,
25
21
  deleteSession,
26
- readyProviders,
27
- resolveModelChoice,
22
+ openSessionInHost,
28
23
  respond,
29
24
  sendMessage,
30
25
  setActiveSession,
31
- setAutoApprove,
32
- setModelChoice,
33
26
  stopSession,
34
27
  useAgentSession,
35
28
  useAgentSessions,
@@ -40,17 +33,12 @@ import {
40
33
  import { format, plural, useLocale } from '@/lib/use-locale';
41
34
  import { cn } from '@/lib/utils';
42
35
  import { applyCommentsPrompt } from '../../../agent/prompt';
43
- import type {
44
- AgentEffort,
45
- AgentModelOption,
46
- AgentProviderId,
47
- AgentTurnContext,
48
- RespondPayload,
49
- } from '../../../agent/types';
36
+ import type { AgentTurnContext, RespondPayload } from '../../../agent/types';
50
37
  import { Composer, ContextChip } from './composer';
51
38
  import { ConnectView } from './connect-view';
52
39
  import { HistoryView } from './history-view';
53
- import { ProviderLogo } from './provider-logo';
40
+ import { ModelMenu } from './model-menu';
41
+ import { PermissionMenu } from './permission-menu';
54
42
  import { Transcript } from './transcript';
55
43
 
56
44
  const CREATE_THEME_PROMPT =
@@ -67,7 +55,7 @@ export function AgentPanel({
67
55
  const { status, loading, connected, provider, model, effort, modelChoices } = useAgentStatus();
68
56
  const { sessions, loaded: sessionsLoaded, activeId } = useAgentSessions();
69
57
  const session = useAgentSession(activeId);
70
- const { request, autoApprove, newDeck } = useAgentState();
58
+ const { request, permissionMode, newDeck, handoffs } = useAgentState();
71
59
  const [draft, setDraft] = useState('');
72
60
  const [sending, setSending] = useState(false);
73
61
  const sendingRef = useRef(false);
@@ -98,6 +86,12 @@ export function AgentPanel({
98
86
  }, [slideId, sessionsLoaded, activeId, sessions]);
99
87
  const isNewDeck = Boolean(context.slideId) && newDeck === context.slideId;
100
88
 
89
+ // A handoff from another tab can arrive while history shows, naming the active session.
90
+ // biome-ignore lint/correctness/useExhaustiveDependencies: every handoff shows the chat again
91
+ useEffect(() => {
92
+ if (activeId) setView('chat');
93
+ }, [activeId, handoffs]);
94
+
101
95
  const ensureSession = useCallback(
102
96
  async (fresh: boolean) => {
103
97
  const current = activeId ? sessions.find((s) => s.id === activeId) : null;
@@ -186,18 +180,19 @@ export function AgentPanel({
186
180
 
187
181
  const chips: ReactNode = context.slideId ? (
188
182
  <>
189
- <ContextChip title={context.slideId}>
183
+ <ContextChip icon={<Presentation />} title={context.slideId}>
190
184
  {context.slideTitle ?? context.slideId}
191
185
  {context.pageNumber ? ` · ${format(t.agent.contextPage, { n: context.pageNumber })}` : ''}
192
186
  </ContextChip>
193
187
  {context.selection && (
194
- <ContextChip title={context.selection.text || undefined}>
188
+ <ContextChip icon={<MousePointer2 />} title={context.selection.text || undefined}>
195
189
  {`<${context.selection.tagName}>`} {t.agent.contextSelection}
196
190
  </ContextChip>
197
191
  )}
198
192
  {pendingComments > 0 && (
199
193
  <ContextChip
200
194
  tone="brand"
195
+ icon={<MessageSquare />}
201
196
  title={t.agent.quickApplyHint}
202
197
  onClick={
203
198
  running
@@ -234,17 +229,10 @@ export function AgentPanel({
234
229
  {t.agent.sessions}
235
230
  </Button>
236
231
  ) : (
237
- <ModelMenu
238
- status={status}
239
- providerId={provider?.id ?? null}
240
- model={model}
241
- effort={effort}
242
- modelChoices={modelChoices}
243
- autoApprove={autoApprove}
244
- onManage={() => setManage(true)}
245
- />
232
+ <h2 className="truncate px-2 text-[12.5px] font-medium">
233
+ {session?.title || t.agent.title}
234
+ </h2>
246
235
  )}
247
- <BetaBadge />
248
236
  </div>
249
237
  <div className="flex shrink-0 items-center gap-0.5">
250
238
  {connected && !showConnect && (
@@ -300,9 +288,11 @@ export function AgentPanel({
300
288
  activeId={activeId}
301
289
  slideId={context.slideId ?? null}
302
290
  onSelect={(s) => {
303
- setActiveSession(s.id);
304
291
  setView('chat');
305
- if (s.slideId && s.slideId !== context.slideId) navigate(`/s/${s.slideId}`);
292
+ const deck = s.slideId && s.slideId !== context.slideId ? s.slideId : null;
293
+ if (deck && openSessionInHost(deck, s.id)) return;
294
+ setActiveSession(s.id);
295
+ if (deck) navigate(`/s/${deck}`);
306
296
  }}
307
297
  onDelete={async (id) => {
308
298
  try {
@@ -345,7 +335,20 @@ export function AgentPanel({
345
335
  ? t.agent.newDeckPlaceholder
346
336
  : format(t.agent.composerPlaceholder, { provider: providerName })
347
337
  }
348
- chips={chips}
338
+ context={chips}
339
+ controls={
340
+ <>
341
+ <ModelMenu
342
+ status={status}
343
+ providerId={provider?.id ?? null}
344
+ model={model}
345
+ effort={effort}
346
+ modelChoices={modelChoices}
347
+ onManage={() => setManage(true)}
348
+ />
349
+ <PermissionMenu mode={permissionMode} providerId={provider?.id ?? null} />
350
+ </>
351
+ }
349
352
  textareaRef={textareaRef}
350
353
  />
351
354
  </>
@@ -354,204 +357,6 @@ export function AgentPanel({
354
357
  );
355
358
  }
356
359
 
357
- function modelLabel(model: AgentModelOption, t: ReturnType<typeof useLocale>): string {
358
- return model.id ? model.label : t.agent.modelDefault;
359
- }
360
-
361
- function ModelMenu({
362
- status,
363
- providerId,
364
- model,
365
- effort,
366
- modelChoices,
367
- autoApprove,
368
- onManage,
369
- }: {
370
- status: ReturnType<typeof useAgentStatus>['status'];
371
- providerId: AgentProviderId | null;
372
- model: AgentModelOption | null;
373
- effort: AgentEffort | null;
374
- modelChoices: ReturnType<typeof useAgentStatus>['modelChoices'];
375
- autoApprove: boolean;
376
- onManage: () => void;
377
- }) {
378
- const t = useLocale();
379
- const [open, setOpen] = useState(false);
380
- const providers = status?.enabled ? status.providers : [];
381
- const [tab, setTab] = useState<AgentProviderId | null>(providerId);
382
- const shownId = tab ?? providerId ?? providers[0]?.id ?? null;
383
- const shown = providers.find((p) => p.id === shownId) ?? null;
384
- const choice = shown?.ready ? resolveModelChoice(shown.models, modelChoices[shown.id]) : null;
385
- const selectedModel = shown?.id === providerId ? (model ?? choice?.model) : choice?.model;
386
- const selectedEffort = shown?.id === providerId ? effort : (choice?.effort ?? null);
387
-
388
- return (
389
- <Popover
390
- open={open}
391
- onOpenChange={(next) => {
392
- setOpen(next);
393
- if (next) setTab(providerId);
394
- }}
395
- >
396
- <PopoverTrigger
397
- type="button"
398
- 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"
399
- >
400
- {providerId ? (
401
- <ProviderLogo provider={providerId} className="size-3.5 shrink-0" />
402
- ) : (
403
- <span aria-hidden className="size-1.5 rounded-full bg-muted-foreground/50" />
404
- )}
405
- <span className="truncate">{model ? modelLabel(model, t) : t.agent.title}</span>
406
- {effort && (
407
- <span className="shrink-0 font-normal text-muted-foreground">
408
- {t.agent.efforts[effort]}
409
- </span>
410
- )}
411
- <ChevronDown className="size-3 text-muted-foreground" aria-hidden />
412
- </PopoverTrigger>
413
- <PopoverContent align="start" className="w-[272px] p-1.5" data-agent-model-menu>
414
- {providers.length > 1 && (
415
- <div role="tablist" className="mb-1.5 flex gap-0.5 rounded-[6px] bg-muted p-0.5">
416
- {providers.map((p) => (
417
- <button
418
- key={p.id}
419
- type="button"
420
- role="tab"
421
- aria-selected={p.id === shownId}
422
- onClick={() => setTab(p.id)}
423
- className={cn(
424
- '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',
425
- p.id === shownId && 'bg-background text-foreground shadow-edge',
426
- )}
427
- >
428
- <ProviderLogo provider={p.id} className="size-3.5 shrink-0" />
429
- {p.name}
430
- </button>
431
- ))}
432
- </div>
433
- )}
434
-
435
- {shown && !shown.ready ? (
436
- <div className="flex flex-col items-start gap-2 px-2 py-2.5">
437
- <p className="text-[12px] leading-relaxed text-muted-foreground">
438
- {shown.cliFound
439
- ? format(t.agent.connectInstallHint, {
440
- pkg: shown.sdkPackage,
441
- pm: status?.packageManager ?? 'npm',
442
- })
443
- : format(t.agent.cliHint, { name: shown.name })}
444
- </p>
445
- <Button
446
- size="xs"
447
- variant="outline"
448
- onClick={() => {
449
- setOpen(false);
450
- onManage();
451
- }}
452
- >
453
- {t.agent.connect}
454
- </Button>
455
- </div>
456
- ) : shown ? (
457
- <div className="flex flex-col gap-px">
458
- {shown.models.map((m) => {
459
- const checked = m.id === selectedModel?.id;
460
- return (
461
- <button
462
- key={m.id}
463
- type="button"
464
- aria-pressed={checked}
465
- onClick={() =>
466
- setModelChoice(shown.id, {
467
- model: m.id,
468
- effort: modelChoices[shown.id]?.effort ?? null,
469
- })
470
- }
471
- className={cn(
472
- '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',
473
- checked && 'font-medium',
474
- )}
475
- >
476
- <span className="truncate">{modelLabel(m, t)}</span>
477
- {checked && <Check className="size-3.5 shrink-0" aria-hidden />}
478
- </button>
479
- );
480
- })}
481
- </div>
482
- ) : null}
483
-
484
- {shown?.ready && selectedModel && selectedModel.efforts.length > 0 && (
485
- <div className="mt-1.5 border-t border-hairline px-1 pt-2 pb-1">
486
- <div className="mb-1.5 px-1 text-[11px] font-medium text-muted-foreground">
487
- {t.agent.reasoning}
488
- </div>
489
- <div className="flex gap-0.5 rounded-[6px] bg-muted p-0.5">
490
- {([null, ...selectedModel.efforts] as (AgentEffort | null)[]).map((e) => {
491
- const checked = e === selectedEffort;
492
- return (
493
- <button
494
- key={e ?? 'auto'}
495
- type="button"
496
- aria-pressed={checked}
497
- onClick={() => setModelChoice(shown.id, { model: selectedModel.id, effort: e })}
498
- className={cn(
499
- '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',
500
- checked && 'bg-background font-medium text-foreground shadow-edge',
501
- )}
502
- >
503
- {e ? t.agent.efforts[e] : t.agent.effortAuto}
504
- </button>
505
- );
506
- })}
507
- </div>
508
- </div>
509
- )}
510
-
511
- <div className="mt-1.5 flex flex-col gap-px border-t border-hairline pt-1.5">
512
- {readyProviders(status).length > 0 && (
513
- <button
514
- type="button"
515
- role="switch"
516
- aria-checked={autoApprove}
517
- title={t.agent.autoApproveHint}
518
- onClick={() => setAutoApprove(!autoApprove)}
519
- 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"
520
- >
521
- {t.agent.autoApprove}
522
- <span
523
- aria-hidden
524
- className={cn(
525
- 'relative h-4 w-7 shrink-0 rounded-full transition-colors duration-150',
526
- autoApprove ? 'bg-foreground' : 'bg-foreground/15',
527
- )}
528
- >
529
- <span
530
- className={cn(
531
- 'absolute top-0.5 left-0.5 size-3 rounded-full bg-background shadow-sm transition-transform duration-150',
532
- autoApprove && 'translate-x-3',
533
- )}
534
- />
535
- </span>
536
- </button>
537
- )}
538
- <button
539
- type="button"
540
- onClick={() => {
541
- setOpen(false);
542
- onManage();
543
- }}
544
- 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"
545
- >
546
- <Settings2 className="size-3.5" />
547
- {t.agent.manageConnections}
548
- </button>
549
- </div>
550
- </PopoverContent>
551
- </Popover>
552
- );
553
- }
554
-
555
360
  function NewDeckState({ providerName }: { providerName: string }) {
556
361
  const t = useLocale();
557
362
  return (
@@ -663,30 +468,3 @@ function QuickAction({
663
468
  </button>
664
469
  );
665
470
  }
666
-
667
- function BetaBadge() {
668
- const t = useLocale();
669
- return (
670
- <Tooltip>
671
- <TooltipTrigger
672
- render={
673
- <button
674
- type="button"
675
- 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"
676
- >
677
- {t.agent.beta}
678
- </button>
679
- }
680
- />
681
- <TooltipContent
682
- side="bottom"
683
- align="start"
684
- sideOffset={6}
685
- className="w-64 px-3 py-2.5 text-left text-pretty"
686
- >
687
- <p className="font-medium text-[12px]">{t.agent.betaTitle}</p>
688
- <p className="mt-1 text-[11.5px] text-background/70 leading-relaxed">{t.agent.betaHint}</p>
689
- </TooltipContent>
690
- </Tooltip>
691
- );
692
- }
@@ -53,7 +53,7 @@ function AgentPresencePill({ activity }: { activity: AgentActivity }) {
53
53
  <button
54
54
  type="button"
55
55
  onClick={() => setDockOpen(true)}
56
- className="island-enter absolute top-2 left-1/2 z-20 flex h-7 max-w-[min(420px,calc(100%-1rem))] -translate-x-1/2 items-center gap-2 rounded-full border border-hairline bg-popover/90 px-2.5 text-[11.5px] shadow-floating backdrop-blur-md md:top-3"
56
+ className="island-enter absolute top-2 left-1/2 z-20 flex h-7 max-w-[min(420px,calc(100%-1rem))] -translate-x-1/2 items-center gap-2 rounded-full border border-hairline bg-material px-2.5 text-[11.5px] shadow-floating backdrop-blur-xl backdrop-saturate-150 md:top-3"
57
57
  >
58
58
  <ProviderLogo provider={activity.provider} className="size-3.5 shrink-0" />
59
59
  <span className="shrink-0 font-medium">
@@ -1,10 +1,11 @@
1
1
  import { ArrowUp, Square } from 'lucide-react';
2
- import type { ReactNode, RefObject } from 'react';
3
- import { Button } from '@/components/ui/button';
2
+ import type { MouseEvent, ReactNode, RefObject } from 'react';
4
3
  import { useAutoGrow } from '@/lib/use-auto-grow';
5
4
  import { useLocale } from '@/lib/use-locale';
6
5
  import { cn } from '@/lib/utils';
7
6
 
7
+ const INTERACTIVE = 'button, a, input, textarea';
8
+
8
9
  export function Composer({
9
10
  value,
10
11
  onChange,
@@ -13,7 +14,8 @@ export function Composer({
13
14
  running,
14
15
  busy,
15
16
  placeholder,
16
- chips,
17
+ context,
18
+ controls,
17
19
  textareaRef,
18
20
  }: {
19
21
  value: string;
@@ -23,25 +25,39 @@ export function Composer({
23
25
  running: boolean;
24
26
  busy?: boolean;
25
27
  placeholder: string;
26
- chips?: ReactNode;
28
+ context?: ReactNode;
29
+ controls?: ReactNode;
27
30
  textareaRef: RefObject<HTMLTextAreaElement | null>;
28
31
  }) {
29
32
  const t = useLocale();
30
33
  const canSend = !running && !busy && value.trim().length > 0;
31
- useAutoGrow(textareaRef, value, 160);
34
+ useAutoGrow(textareaRef, value, 200);
35
+
36
+ const focusField = (e: MouseEvent<HTMLDivElement>) => {
37
+ const target = e.target;
38
+ // React bubbles events out of portals, so the model menu's clicks land here too.
39
+ if (!(target instanceof Element) || !e.currentTarget.contains(target)) return;
40
+ if (target.closest(INTERACTIVE)) return;
41
+ e.preventDefault();
42
+ textareaRef.current?.focus();
43
+ };
32
44
 
33
45
  return (
34
- <div className="relative z-10 shrink-0 bg-sidebar px-3 pt-1 pb-3">
46
+ <div className="relative z-10 shrink-0 bg-sidebar px-3 pb-3">
35
47
  <span
36
48
  aria-hidden
37
- className="pointer-events-none absolute inset-x-0 bottom-full h-5 bg-gradient-to-t from-sidebar to-transparent"
49
+ className="pointer-events-none absolute inset-x-0 bottom-full h-5 bg-gradient-to-t from-sidebar to-transparent supports-[animation-timeline:scroll()]:hidden"
38
50
  />
51
+ {/* biome-ignore lint/a11y/noStaticElementInteractions: pointer-only shortcut; the textarea stays the keyboard target */}
39
52
  <div
53
+ data-agent-composer
54
+ onMouseDown={focusField}
40
55
  className={cn(
41
- 'relative flex flex-col rounded-[8px] border border-border bg-background shadow-edge transition-colors duration-100',
42
- 'focus-within:border-foreground/40 focus-within:ring-2 focus-within:ring-ring/30',
56
+ 'relative flex cursor-text flex-col rounded-[12px] border border-border bg-background shadow-edge transition-[border-color,box-shadow] duration-150',
57
+ 'focus-within:border-foreground/30 focus-within:ring-[3px] focus-within:ring-ring/15',
43
58
  )}
44
59
  >
60
+ {context && <div className="flex flex-wrap items-center gap-1 px-2 pt-2">{context}</div>}
45
61
  <textarea
46
62
  ref={textareaRef}
47
63
  value={value}
@@ -55,30 +71,34 @@ export function Composer({
55
71
  }
56
72
  }}
57
73
  placeholder={placeholder}
58
- className="w-full resize-none bg-transparent px-3 pt-2.5 text-[12.5px] leading-[1.5] outline-none placeholder:text-muted-foreground/60 disabled:opacity-60"
74
+ className={cn(
75
+ 'w-full resize-none bg-transparent px-3 text-[12.5px] leading-[1.5] outline-none placeholder:text-muted-foreground/60',
76
+ context ? 'pt-1.5' : 'pt-2.5',
77
+ )}
59
78
  />
60
- <div className="flex items-end justify-between gap-2 px-2 pb-2">
61
- <div className="flex min-w-0 flex-wrap items-center gap-1">{chips}</div>
79
+ <div className="flex items-center justify-between gap-1 px-1.5 pb-1.5">
80
+ <div className="flex min-w-0 items-center gap-0.5">{controls}</div>
62
81
  {running ? (
63
- <Button
64
- size="icon-sm"
65
- variant="outline"
82
+ <button
83
+ type="button"
66
84
  aria-label={t.agent.stop}
67
85
  title={t.agent.stop}
68
86
  onClick={onStop}
87
+ className="grid size-7 shrink-0 place-items-center rounded-full bg-foreground text-background outline-none transition-opacity duration-100 hover:opacity-85 focus-visible:ring-2 focus-visible:ring-ring/40"
69
88
  >
70
- <Square className="size-3 fill-current" />
71
- </Button>
89
+ <Square className="size-2.5 fill-current" />
90
+ </button>
72
91
  ) : (
73
- <Button
74
- size="icon-sm"
92
+ <button
93
+ type="button"
75
94
  aria-label={t.agent.send}
76
95
  title={t.agent.send}
77
96
  disabled={!canSend}
78
97
  onClick={onSend}
98
+ className="grid size-7 shrink-0 place-items-center rounded-full bg-foreground text-background outline-none transition-[background-color,color,opacity] duration-100 hover:opacity-85 focus-visible:ring-2 focus-visible:ring-ring/40 disabled:bg-foreground/10 disabled:text-muted-foreground disabled:hover:opacity-100"
79
99
  >
80
- <ArrowUp className="size-3.5" />
81
- </Button>
100
+ <ArrowUp className="size-3.5" strokeWidth={2.25} />
101
+ </button>
82
102
  )}
83
103
  </div>
84
104
  </div>
@@ -88,33 +108,41 @@ export function Composer({
88
108
 
89
109
  export function ContextChip({
90
110
  children,
111
+ icon,
91
112
  tone = 'default',
92
113
  onClick,
93
114
  title,
94
115
  }: {
95
116
  children: ReactNode;
117
+ icon?: ReactNode;
96
118
  tone?: 'default' | 'brand';
97
119
  onClick?: () => void;
98
120
  title?: string;
99
121
  }) {
100
122
  const className = cn(
101
- 'inline-flex h-6 max-w-[180px] items-center gap-1 rounded-[5px] border px-1.5 text-[10.5px] leading-none',
123
+ 'inline-flex h-6 max-w-[200px] items-center gap-1 rounded-[6px] border px-1.5 text-[11px] leading-none [&_svg]:size-3 [&_svg]:shrink-0',
102
124
  tone === 'brand'
103
125
  ? 'border-brand/40 bg-brand/10 text-brand'
104
126
  : 'border-hairline bg-muted/50 text-muted-foreground',
105
127
  onClick &&
106
128
  'cursor-pointer outline-none hover:border-foreground/30 hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/30',
107
129
  );
130
+ const body = (
131
+ <>
132
+ {icon}
133
+ <span className="truncate">{children}</span>
134
+ </>
135
+ );
108
136
  if (onClick) {
109
137
  return (
110
138
  <button type="button" onClick={onClick} title={title} className={className}>
111
- <span className="truncate">{children}</span>
139
+ {body}
112
140
  </button>
113
141
  );
114
142
  }
115
143
  return (
116
144
  <span title={title} className={className}>
117
- <span className="truncate">{children}</span>
145
+ {body}
118
146
  </span>
119
147
  );
120
148
  }