@sixb/app 0.1.16 → 0.1.18
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.
- package/README.md +8 -0
- package/dist/agent/agent-chat.d.ts.map +1 -1
- package/dist/agent/bash/interpret.d.ts +6 -2
- package/dist/agent/bash/interpret.d.ts.map +1 -1
- package/dist/agent/components/approval-mode-icons.d.ts +5 -0
- package/dist/agent/components/approval-mode-icons.d.ts.map +1 -0
- package/dist/agent/components/composer-add-menu.d.ts +15 -0
- package/dist/agent/components/composer-add-menu.d.ts.map +1 -0
- package/dist/agent/components/composer-commands.d.ts +37 -0
- package/dist/agent/components/composer-commands.d.ts.map +1 -0
- package/dist/agent/components/composer-menu.d.ts +18 -15
- package/dist/agent/components/composer-menu.d.ts.map +1 -1
- package/dist/agent/components/composer-settings.d.ts +34 -0
- package/dist/agent/components/composer-settings.d.ts.map +1 -0
- package/dist/agent/components/composer.d.ts +10 -3
- package/dist/agent/components/composer.d.ts.map +1 -1
- package/dist/agent/components/context-chips.d.ts +5 -0
- package/dist/agent/components/context-chips.d.ts.map +1 -1
- package/dist/agent/components/conversation-panel.d.ts +3 -1
- package/dist/agent/components/conversation-panel.d.ts.map +1 -1
- package/dist/agent/components/dictation-bar.d.ts +7 -3
- package/dist/agent/components/dictation-bar.d.ts.map +1 -1
- package/dist/agent/components/model-picker-row.d.ts +1 -3
- package/dist/agent/components/model-picker-row.d.ts.map +1 -1
- package/dist/agent/components/reasoning-effort-slider.d.ts.map +1 -1
- package/dist/agent/components/shared-thread-notice.d.ts +4 -2
- package/dist/agent/components/shared-thread-notice.d.ts.map +1 -1
- package/dist/agent/delegation/use-children.d.ts.map +1 -1
- package/dist/agent/hooks/use-agent-conversation.d.ts +2 -0
- package/dist/agent/hooks/use-agent-conversation.d.ts.map +1 -1
- package/dist/agent/hooks/use-thread-lists.d.ts +8 -0
- package/dist/agent/hooks/use-thread-lists.d.ts.map +1 -1
- package/dist/agent/i18n/en.d.ts +69 -8
- package/dist/agent/i18n/en.d.ts.map +1 -1
- package/dist/agent/i18n/fr.d.ts.map +1 -1
- package/dist/agent/i18n/index.d.ts +126 -12
- package/dist/agent/i18n/index.d.ts.map +1 -1
- package/dist/agent/model-selection.d.ts +1 -0
- package/dist/agent/model-selection.d.ts.map +1 -1
- package/dist/agent/run-sounds.d.ts +18 -0
- package/dist/agent/run-sounds.d.ts.map +1 -0
- package/dist/chunk-6n5pdqp0.js.map +1 -1
- package/dist/{chunk-12v6y89k.js → chunk-btky7c9w.js} +11678 -11190
- package/dist/{chunk-12v6y89k.js.map → chunk-btky7c9w.js.map} +59 -57
- package/dist/{chunk-bpj9mg5c.js → chunk-gq6xek89.js} +1 -1
- package/dist/{chunk-bpj9mg5c.js.map → chunk-gq6xek89.js.map} +1 -1
- package/dist/{chunk-hzy2g13h.js → chunk-hdbmj6f0.js} +1 -1
- package/dist/{chunk-hzy2g13h.js.map → chunk-hdbmj6f0.js.map} +1 -1
- package/dist/chunk-md3p7qdt.js.map +1 -1
- package/dist/{chunk-2a69ge8h.js → chunk-pkcm8rn8.js} +1 -1
- package/dist/{chunk-2a69ge8h.js.map → chunk-pkcm8rn8.js.map} +1 -1
- package/dist/chunk-yvhzn4ye.js.map +1 -1
- package/dist/codegen.d.ts.map +1 -1
- package/dist/createCustomApp.d.ts.map +1 -1
- package/dist/frame-origins.d.ts +10 -0
- package/dist/frame-origins.d.ts.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -6
- package/dist/index.js.map +3 -3
- package/dist/pages/settings/messages.d.ts +16 -0
- package/dist/pages/settings/messages.d.ts.map +1 -1
- package/dist/pages/settings/personal.d.ts +2 -2
- package/dist/pages/settings/personal.d.ts.map +1 -1
- package/dist/pages.js +49 -3
- package/dist/pages.js.map +4 -4
- package/dist/server.js +97 -22
- package/dist/server.js.map +6 -5
- package/package.json +3 -3
- package/src/agent/agent-chat.tsx +6 -1
- package/src/agent/agent.css +145 -14
- package/src/agent/bash/interpret.ts +41 -5
- package/src/agent/components/approval-mode-icons.ts +9 -0
- package/src/agent/components/composer-add-menu.tsx +126 -0
- package/src/agent/components/composer-commands.tsx +165 -0
- package/src/agent/components/composer-menu.tsx +33 -46
- package/src/agent/components/composer-settings.tsx +437 -0
- package/src/agent/components/composer.tsx +312 -153
- package/src/agent/components/context-chips.tsx +21 -8
- package/src/agent/components/conversation-panel.tsx +16 -9
- package/src/agent/components/dictation-bar.tsx +28 -23
- package/src/agent/components/model-picker-row.tsx +14 -24
- package/src/agent/components/reasoning-effort-slider.tsx +14 -10
- package/src/agent/components/shared-thread-notice.tsx +7 -2
- package/src/agent/components/transcript.tsx +2 -1
- package/src/agent/hooks/use-agent-conversation.ts +18 -6
- package/src/agent/i18n/en.ts +58 -15
- package/src/agent/i18n/fr.ts +77 -13
- package/src/agent/model-selection.ts +4 -0
- package/src/agent/publish-artifact/publish-artifact-tool-view.tsx +3 -2
- package/src/agent/run-sounds.ts +171 -0
- package/src/codegen.ts +44 -0
- package/src/createCustomApp.ts +53 -26
- package/src/frame-origins.ts +61 -0
- package/src/index.ts +5 -1
- package/src/pages/settings/messages.ts +8 -0
- package/src/pages/settings/personal.tsx +60 -3
- package/dist/agent/components/approval-mode-chip.d.ts +0 -15
- package/dist/agent/components/approval-mode-chip.d.ts.map +0 -1
- package/dist/agent/components/auto-model-chip.d.ts +0 -23
- package/dist/agent/components/auto-model-chip.d.ts.map +0 -1
- package/dist/agent/components/model-controls.d.ts +0 -41
- package/dist/agent/components/model-controls.d.ts.map +0 -1
- package/src/agent/components/approval-mode-chip.tsx +0 -120
- package/src/agent/components/auto-model-chip.tsx +0 -219
- package/src/agent/components/model-controls.tsx +0 -238
|
@@ -26,13 +26,13 @@ import {
|
|
|
26
26
|
File as FileIcon,
|
|
27
27
|
FileText,
|
|
28
28
|
Image as ImageIcon,
|
|
29
|
-
Plus,
|
|
30
29
|
Square,
|
|
31
30
|
Table2,
|
|
32
31
|
UploadCloud,
|
|
33
32
|
X,
|
|
34
33
|
} from "lucide-react"
|
|
35
34
|
import {
|
|
35
|
+
type ClipboardEvent,
|
|
36
36
|
type KeyboardEvent,
|
|
37
37
|
useCallback,
|
|
38
38
|
useEffect,
|
|
@@ -44,7 +44,6 @@ import {
|
|
|
44
44
|
import { createPortal } from "react-dom"
|
|
45
45
|
import { type AgentApprovalMode, toggledApprovalMode } from "../approvals"
|
|
46
46
|
import { useAgentMessages } from "../i18n"
|
|
47
|
-
import type { AgentMessages } from "../i18n/en"
|
|
48
47
|
import type { AgentFileRef, LanguageModel } from "../types"
|
|
49
48
|
import { agentContextLabel, mergeAgentContext } from "../utils/context-display"
|
|
50
49
|
import {
|
|
@@ -52,11 +51,23 @@ import {
|
|
|
52
51
|
findAgentContextMention,
|
|
53
52
|
removeAgentContextMention,
|
|
54
53
|
} from "../utils/context-mention"
|
|
55
|
-
import {
|
|
56
|
-
import {
|
|
54
|
+
import { ComposerAddMenu } from "./composer-add-menu"
|
|
55
|
+
import {
|
|
56
|
+
builtInCommands,
|
|
57
|
+
type ComposerCommand,
|
|
58
|
+
ComposerCommandList,
|
|
59
|
+
commandQuery,
|
|
60
|
+
matchCommands,
|
|
61
|
+
} from "./composer-commands"
|
|
62
|
+
import { ComposerSettings } from "./composer-settings"
|
|
63
|
+
import {
|
|
64
|
+
COMPOSER_CHIP_CLASS_NAME,
|
|
65
|
+
COMPOSER_CHIP_REMOVE_CLASS_NAME,
|
|
66
|
+
COMPOSER_CHIP_THUMB_CLASS_NAME,
|
|
67
|
+
ContextChips,
|
|
68
|
+
} from "./context-chips"
|
|
57
69
|
import { ContextPicker } from "./context-picker"
|
|
58
70
|
import { DictationBar } from "./dictation-bar"
|
|
59
|
-
import { ModelControls } from "./model-controls"
|
|
60
71
|
|
|
61
72
|
export interface ComposerProps {
|
|
62
73
|
readonly onSend: (
|
|
@@ -68,7 +79,8 @@ export interface ComposerProps {
|
|
|
68
79
|
readonly pending?: boolean
|
|
69
80
|
/**
|
|
70
81
|
* A run is in flight: the send button becomes a stop button that calls {@link onStop}, or stays
|
|
71
|
-
* disabled without one, when the reader may not stop someone else's answer.
|
|
82
|
+
* disabled without one, when the reader may not stop someone else's answer. The reader writes
|
|
83
|
+
* the next message meanwhile, and sends it once the run ends.
|
|
72
84
|
*/
|
|
73
85
|
readonly running?: boolean
|
|
74
86
|
/** A stop has been requested and we're waiting for the run to end. */
|
|
@@ -122,6 +134,11 @@ export interface ComposerProps {
|
|
|
122
134
|
* input. Omit for no microphone.
|
|
123
135
|
*/
|
|
124
136
|
readonly dictation?: SpeechRecognizer
|
|
137
|
+
/**
|
|
138
|
+
* Slash commands of your own, listed after the built-in ones (`/auto`, one per model, `/ask`,
|
|
139
|
+
* `/edits`, `/full`). A command is typed as the whole message and runs with Enter.
|
|
140
|
+
*/
|
|
141
|
+
readonly commands?: readonly ComposerCommand[]
|
|
125
142
|
}
|
|
126
143
|
|
|
127
144
|
type ComposerAttachment =
|
|
@@ -147,9 +164,15 @@ type ComposerAttachment =
|
|
|
147
164
|
|
|
148
165
|
const MAX_HEIGHT_PX = 200
|
|
149
166
|
|
|
150
|
-
//
|
|
167
|
+
// The microphone and Cancel: round, quiet until hovered.
|
|
168
|
+
const ICON_BUTTON_CLASS_NAME = cn(
|
|
169
|
+
"flex size-10 shrink-0 items-center justify-center rounded-full text-foreground/80 outline-none transition-colors",
|
|
170
|
+
"hover:bg-black/[0.05] focus-visible:ring-2 focus-visible:ring-ring/40 disabled:opacity-50 dark:hover:bg-white/[0.08]"
|
|
171
|
+
)
|
|
172
|
+
|
|
173
|
+
// Send, stop and Done: the one filled control in the box.
|
|
151
174
|
const SEND_BUTTON_CLASS_NAME = cn(
|
|
152
|
-
"flex size-
|
|
175
|
+
"sixb-composer-send flex size-10 shrink-0 items-center justify-center rounded-full outline-none transition-colors",
|
|
153
176
|
"bg-foreground text-background hover:bg-foreground/85 focus-visible:ring-2 focus-visible:ring-ring/50 focus-visible:ring-offset-2 focus-visible:ring-offset-card",
|
|
154
177
|
"disabled:bg-foreground/25 disabled:text-background dark:disabled:bg-white/20 dark:disabled:text-white/70"
|
|
155
178
|
)
|
|
@@ -157,9 +180,8 @@ const SEND_BUTTON_CLASS_NAME = cn(
|
|
|
157
180
|
export function composerCanFocus({
|
|
158
181
|
disabled,
|
|
159
182
|
pending,
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
return !disabled && !pending && !running
|
|
183
|
+
}: Pick<ComposerProps, "disabled" | "pending">): boolean {
|
|
184
|
+
return !disabled && !pending
|
|
163
185
|
}
|
|
164
186
|
|
|
165
187
|
export function Composer({
|
|
@@ -194,6 +216,7 @@ export function Composer({
|
|
|
194
216
|
onApprovalModeChange,
|
|
195
217
|
awaitingApproval = false,
|
|
196
218
|
dictation,
|
|
219
|
+
commands = [],
|
|
197
220
|
}: ComposerProps) {
|
|
198
221
|
const agentMessages = useAgentMessages()
|
|
199
222
|
const messages = agentMessages.composer
|
|
@@ -206,11 +229,19 @@ export function Composer({
|
|
|
206
229
|
const [mention, setMention] = useState<AgentContextMention | null>(null)
|
|
207
230
|
const [dismissedMention, setDismissedMention] = useState<string | null>(null)
|
|
208
231
|
const [activeContextResult, setActiveContextResult] = useState(0)
|
|
232
|
+
const [activeCommand, setActiveCommand] = useState(0)
|
|
233
|
+
// A command list the reader closed with Escape stays closed for that text.
|
|
234
|
+
const [dismissedCommand, setDismissedCommand] = useState<string | null>(null)
|
|
235
|
+
// The text no longer fits beside the controls: it gets a row of its own.
|
|
236
|
+
const [wraps, setWraps] = useState(false)
|
|
209
237
|
const [draggingFiles, setDraggingFiles] = useState(false)
|
|
210
238
|
// Said once the mode changes from the keyboard, where the chip itself may be out of sight.
|
|
211
239
|
const [modeAnnouncement, setModeAnnouncement] = useState("")
|
|
212
240
|
const rootRef = useRef<HTMLDivElement>(null)
|
|
213
241
|
const textareaRef = useRef<HTMLTextAreaElement>(null)
|
|
242
|
+
const sizerRef = useRef<HTMLSpanElement>(null)
|
|
243
|
+
// The text's width in a single row, measured while it has one.
|
|
244
|
+
const inlineWidthRef = useRef(0)
|
|
214
245
|
const fileInputRef = useRef<HTMLInputElement>(null)
|
|
215
246
|
const dragDepthRef = useRef(0)
|
|
216
247
|
const uploadFile = useUploadFile()
|
|
@@ -225,7 +256,6 @@ export function Composer({
|
|
|
225
256
|
autoRestart: false,
|
|
226
257
|
})
|
|
227
258
|
const wasDictatingRef = useRef(false)
|
|
228
|
-
const wasRunningRef = useRef(Boolean(running))
|
|
229
259
|
const dismissedAmbientRef = useRef(new Set<string>())
|
|
230
260
|
const ambientKey = JSON.stringify(ambientContext.map(agentContextFingerprint))
|
|
231
261
|
|
|
@@ -262,9 +292,18 @@ export function Composer({
|
|
|
262
292
|
)
|
|
263
293
|
const failedCount = attachments.filter((attachment) => attachment.status === "error").length
|
|
264
294
|
const canAttachFiles = !disabled && !pending
|
|
295
|
+
const showPermissions = approvalMode !== undefined && onApprovalModeChange !== undefined
|
|
296
|
+
const commandText = commandQuery(value)
|
|
297
|
+
const commandMatches =
|
|
298
|
+
commandText === null || dismissedCommand === value || voice.isActive
|
|
299
|
+
? []
|
|
300
|
+
: matchCommands(allCommands(), commandText).slice(0, 6)
|
|
301
|
+
const commandsOpen = commandMatches.length > 0
|
|
302
|
+
// Files alone are a message too.
|
|
265
303
|
const canSend =
|
|
266
|
-
value.trim().length > 0 &&
|
|
304
|
+
(value.trim().length > 0 || readyAttachments.length > 0) &&
|
|
267
305
|
mention === null &&
|
|
306
|
+
!commandsOpen &&
|
|
268
307
|
!disabled &&
|
|
269
308
|
!pending &&
|
|
270
309
|
!running &&
|
|
@@ -332,18 +371,9 @@ export function Composer({
|
|
|
332
371
|
input.setSelectionRange(input.value.length, input.value.length)
|
|
333
372
|
}, [voice.isActive])
|
|
334
373
|
|
|
335
|
-
useEffect(() => {
|
|
336
|
-
const wasRunning = wasRunningRef.current
|
|
337
|
-
wasRunningRef.current = Boolean(running)
|
|
338
|
-
if (!wasRunning || !composerCanFocus({ disabled, pending, running })) return
|
|
339
|
-
|
|
340
|
-
const frame = requestAnimationFrame(() => textareaRef.current?.focus())
|
|
341
|
-
return () => cancelAnimationFrame(frame)
|
|
342
|
-
}, [disabled, pending, running])
|
|
343
|
-
|
|
344
374
|
useEffect(() => {
|
|
345
375
|
const focusWhenAvailable = () => {
|
|
346
|
-
if (!composerCanFocus({ disabled, pending
|
|
376
|
+
if (!composerCanFocus({ disabled, pending })) return
|
|
347
377
|
textareaRef.current?.focus()
|
|
348
378
|
}
|
|
349
379
|
const handleVisibilityChange = () => {
|
|
@@ -356,8 +386,17 @@ export function Composer({
|
|
|
356
386
|
window.removeEventListener("focus", focusWhenAvailable)
|
|
357
387
|
document.removeEventListener("visibilitychange", handleVisibilityChange)
|
|
358
388
|
}
|
|
359
|
-
}, [disabled, pending
|
|
389
|
+
}, [disabled, pending])
|
|
360
390
|
|
|
391
|
+
// A draft that no longer fits in one row beside the controls takes a row of its own, with the
|
|
392
|
+
// controls under it. The row's width is measured while the draft still has it, so the box only
|
|
393
|
+
// folds back once the text fits there again.
|
|
394
|
+
const expanded =
|
|
395
|
+
wraps ||
|
|
396
|
+
value.includes("\n") ||
|
|
397
|
+
attachments.length > 0 ||
|
|
398
|
+
contextEntries.length > 0 ||
|
|
399
|
+
(voice.isActive && value.trim().length > 0)
|
|
361
400
|
// Grow the textarea to fit its content, up to a max height where it starts scrolling.
|
|
362
401
|
// Keep overflow hidden until the content actually exceeds the cap so an empty input does not
|
|
363
402
|
// render a scrollbar in browsers configured to always show scroll bars.
|
|
@@ -365,10 +404,15 @@ export function Composer({
|
|
|
365
404
|
useLayoutEffect(() => {
|
|
366
405
|
const el = textareaRef.current
|
|
367
406
|
if (!el) return
|
|
407
|
+
if (!expanded) inlineWidthRef.current = el.clientWidth
|
|
408
|
+
const sizer = sizerRef.current
|
|
409
|
+
setWraps(
|
|
410
|
+
sizer !== null && inlineWidthRef.current > 0 && sizer.offsetWidth > inlineWidthRef.current
|
|
411
|
+
)
|
|
368
412
|
el.style.height = "auto"
|
|
369
413
|
el.style.overflowY = el.scrollHeight > MAX_HEIGHT_PX ? "auto" : "hidden"
|
|
370
414
|
el.style.height = `${Math.min(el.scrollHeight, MAX_HEIGHT_PX)}px`
|
|
371
|
-
}, [value, attachments.length, contextEntries.length])
|
|
415
|
+
}, [value, attachments.length, contextEntries.length, expanded])
|
|
372
416
|
|
|
373
417
|
const submit = () => {
|
|
374
418
|
if (!canSend) return
|
|
@@ -380,6 +424,8 @@ export function Composer({
|
|
|
380
424
|
setContextEntries(ambientContext.map((context) => ({ context, origin: "ambient" })))
|
|
381
425
|
setMention(null)
|
|
382
426
|
if (fileInputRef.current) fileInputRef.current.value = ""
|
|
427
|
+
// Stop replaces the send button a click left the focus on: the next message starts here.
|
|
428
|
+
textareaRef.current?.focus()
|
|
383
429
|
}
|
|
384
430
|
|
|
385
431
|
const insertNewline = () => {
|
|
@@ -452,6 +498,19 @@ export function Composer({
|
|
|
452
498
|
[startUpload]
|
|
453
499
|
)
|
|
454
500
|
|
|
501
|
+
// A pasted screenshot or copied image uploads as a dropped file does. Text wins: Excel or Word
|
|
502
|
+
// copy a picture of the selection beside its text, and whoever pastes cells wants the text.
|
|
503
|
+
const handlePaste = (event: ClipboardEvent<HTMLTextAreaElement>) => {
|
|
504
|
+
const files = clipboardFiles(event.clipboardData)
|
|
505
|
+
if (files.length === 0 || event.clipboardData.getData("text/plain").trim()) return
|
|
506
|
+
|
|
507
|
+
event.preventDefault()
|
|
508
|
+
if (!canAttachFiles) return
|
|
509
|
+
for (const file of files) {
|
|
510
|
+
startUpload(file)
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
|
|
455
514
|
useEffect(() => {
|
|
456
515
|
const resetDragState = () => {
|
|
457
516
|
dragDepthRef.current = 0
|
|
@@ -577,9 +636,50 @@ export function Composer({
|
|
|
577
636
|
)
|
|
578
637
|
}
|
|
579
638
|
|
|
639
|
+
function allCommands(): readonly ComposerCommand[] {
|
|
640
|
+
const choosesModel = onSelectModel !== undefined && onSelectReasoning !== undefined
|
|
641
|
+
return [
|
|
642
|
+
...builtInCommands({
|
|
643
|
+
models,
|
|
644
|
+
onSelectModel: choosesModel ? onSelectModel : undefined,
|
|
645
|
+
onResetModelSelection: choosesModel ? onResetModelSelection : undefined,
|
|
646
|
+
// Called on Enter, long after the render that lists it.
|
|
647
|
+
onApprovalModeChange: showPermissions ? (mode) => changeApprovalMode(mode) : undefined,
|
|
648
|
+
messages: agentMessages.commands,
|
|
649
|
+
}),
|
|
650
|
+
...commands,
|
|
651
|
+
]
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
const runCommand = (command: ComposerCommand) => {
|
|
655
|
+
command.run()
|
|
656
|
+
setValue("")
|
|
657
|
+
setActiveCommand(0)
|
|
658
|
+
setDismissedCommand(null)
|
|
659
|
+
textareaRef.current?.focus()
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
// Types at the caret, as the `+` menu's mention and command do, and keeps the focus there.
|
|
663
|
+
const insertAtCaret = (text: string) => {
|
|
664
|
+
const el = textareaRef.current
|
|
665
|
+
const start = el?.selectionStart ?? value.length
|
|
666
|
+
const end = el?.selectionEnd ?? value.length
|
|
667
|
+
const spaced = start > 0 && !/\s/.test(value[start - 1] ?? "") ? ` ${text}` : text
|
|
668
|
+
const next = `${value.slice(0, start)}${spaced}${value.slice(end)}`
|
|
669
|
+
const caret = start + spaced.length
|
|
670
|
+
setValue(next)
|
|
671
|
+
setDismissedMention(null)
|
|
672
|
+
updateMention(next, caret)
|
|
673
|
+
requestAnimationFrame(() => {
|
|
674
|
+
el?.focus()
|
|
675
|
+
el?.setSelectionRange(caret, caret)
|
|
676
|
+
})
|
|
677
|
+
}
|
|
678
|
+
|
|
580
679
|
// Enter sends; Cmd/Ctrl+Enter and Shift+Enter insert a newline (and let the field grow).
|
|
581
|
-
// Shift+Tab in an empty input cycles
|
|
582
|
-
// something is typed, it moves focus back as everywhere else.
|
|
680
|
+
// Shift+Tab in an empty input cycles Ask first, Allow edits and Full access, as in a terminal
|
|
681
|
+
// agent; once something is typed, it moves focus back as everywhere else. A slash command being
|
|
682
|
+
// typed runs on Enter instead of being sent.
|
|
583
683
|
const handleKeyDown = (event: KeyboardEvent<HTMLTextAreaElement>) => {
|
|
584
684
|
// While dictating, Enter finishes and Escape cancels from the input too, as from the bar.
|
|
585
685
|
if (voice.isActive) {
|
|
@@ -604,6 +704,32 @@ export function Composer({
|
|
|
604
704
|
changeApprovalMode(toggledApprovalMode(approvalMode))
|
|
605
705
|
return
|
|
606
706
|
}
|
|
707
|
+
if (commandsOpen) {
|
|
708
|
+
if (event.key === "Escape") {
|
|
709
|
+
event.preventDefault()
|
|
710
|
+
setDismissedCommand(value)
|
|
711
|
+
return
|
|
712
|
+
}
|
|
713
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
714
|
+
event.preventDefault()
|
|
715
|
+
const direction = event.key === "ArrowDown" ? 1 : -1
|
|
716
|
+
setActiveCommand(
|
|
717
|
+
(current) => (current + direction + commandMatches.length) % commandMatches.length
|
|
718
|
+
)
|
|
719
|
+
return
|
|
720
|
+
}
|
|
721
|
+
if (
|
|
722
|
+
(event.key === "Enter" || event.key === "Tab") &&
|
|
723
|
+
!event.shiftKey &&
|
|
724
|
+
!event.metaKey &&
|
|
725
|
+
!event.ctrlKey
|
|
726
|
+
) {
|
|
727
|
+
event.preventDefault()
|
|
728
|
+
const command = commandMatches[activeCommand % commandMatches.length]
|
|
729
|
+
if (command) runCommand(command)
|
|
730
|
+
return
|
|
731
|
+
}
|
|
732
|
+
}
|
|
607
733
|
if (mention) {
|
|
608
734
|
if (event.key === "Escape") {
|
|
609
735
|
event.preventDefault()
|
|
@@ -661,7 +787,10 @@ export function Composer({
|
|
|
661
787
|
: (voice.error ?? hint)
|
|
662
788
|
const statusIsError = !uploading && (failedCount > 0 || voice.error !== null)
|
|
663
789
|
|
|
664
|
-
const
|
|
790
|
+
const hasDraft = value.trim().length > 0 || readyAttachments.length > 0
|
|
791
|
+
// With a microphone, send appears once there is something to send; it waits there otherwise. A
|
|
792
|
+
// command being typed is run, not sent.
|
|
793
|
+
const showSend = (hasDraft && !commandsOpen) || pending || uploading || running || !dictation
|
|
665
794
|
|
|
666
795
|
return (
|
|
667
796
|
<div ref={rootRef} className={cn("relative bg-background px-4 pt-2 pb-3", className)}>
|
|
@@ -681,10 +810,7 @@ export function Composer({
|
|
|
681
810
|
<MarkerContent>{error}</MarkerContent>
|
|
682
811
|
</Marker>
|
|
683
812
|
) : null}
|
|
684
|
-
<div
|
|
685
|
-
data-dragging={draggingFiles || undefined}
|
|
686
|
-
className="sixb-composer-surface relative rounded-3xl bg-card"
|
|
687
|
-
>
|
|
813
|
+
<div className="relative">
|
|
688
814
|
<ContextPicker
|
|
689
815
|
open={mention !== null}
|
|
690
816
|
query={mentionQuery}
|
|
@@ -694,42 +820,95 @@ export function Composer({
|
|
|
694
820
|
onActiveIndexChange={setActiveContextResult}
|
|
695
821
|
onSelect={selectContextResult}
|
|
696
822
|
/>
|
|
697
|
-
<
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
823
|
+
<ComposerCommandList
|
|
824
|
+
open={commandsOpen}
|
|
825
|
+
query={commandText ?? ""}
|
|
826
|
+
commands={commandMatches}
|
|
827
|
+
activeIndex={activeCommand % Math.max(commandMatches.length, 1)}
|
|
828
|
+
onActiveIndexChange={setActiveCommand}
|
|
829
|
+
onRun={runCommand}
|
|
701
830
|
/>
|
|
702
|
-
{
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
key={attachment.id}
|
|
707
|
-
attachment={attachment}
|
|
708
|
-
onRemove={() => removeAttachment(attachment.id)}
|
|
709
|
-
/>
|
|
710
|
-
))}
|
|
711
|
-
</div>
|
|
712
|
-
) : null}
|
|
831
|
+
{/*
|
|
832
|
+
One row while the draft fits beside the controls; once it doesn't, the draft gets a row
|
|
833
|
+
of its own and the controls sit under it. Attachments and context lead, on their own row.
|
|
834
|
+
*/}
|
|
713
835
|
<div
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
)}
|
|
836
|
+
data-dragging={draggingFiles || undefined}
|
|
837
|
+
data-expanded={expanded || undefined}
|
|
838
|
+
className="group/composer sixb-composer-surface relative flex flex-wrap items-end gap-0.5 rounded-[30px] p-2.5 data-[expanded]:gap-y-1 data-[expanded]:rounded-[26px]"
|
|
718
839
|
>
|
|
840
|
+
{/* The draft on one line, to tell when it stops fitting there. */}
|
|
841
|
+
<span
|
|
842
|
+
aria-hidden="true"
|
|
843
|
+
className="pointer-events-none invisible absolute inset-0 overflow-hidden"
|
|
844
|
+
>
|
|
845
|
+
<span
|
|
846
|
+
ref={sizerRef}
|
|
847
|
+
className="absolute whitespace-pre px-2 text-[16px] tracking-[-0.012em]"
|
|
848
|
+
>
|
|
849
|
+
{value}
|
|
850
|
+
</span>
|
|
851
|
+
</span>
|
|
852
|
+
{contextEntries.length > 0 || attachments.length > 0 ? (
|
|
853
|
+
<div className="order-first flex basis-full flex-wrap gap-1.5 px-0.5 pt-0.5 pb-1">
|
|
854
|
+
<ContextChips
|
|
855
|
+
entries={contextEntries}
|
|
856
|
+
onRemove={removeContext}
|
|
857
|
+
className="contents"
|
|
858
|
+
/>
|
|
859
|
+
{attachments.map((attachment) => (
|
|
860
|
+
<AttachmentChip
|
|
861
|
+
key={attachment.id}
|
|
862
|
+
attachment={attachment}
|
|
863
|
+
onRemove={() => removeAttachment(attachment.id)}
|
|
864
|
+
/>
|
|
865
|
+
))}
|
|
866
|
+
</div>
|
|
867
|
+
) : null}
|
|
868
|
+
<input
|
|
869
|
+
ref={fileInputRef}
|
|
870
|
+
type="file"
|
|
871
|
+
multiple
|
|
872
|
+
className="sr-only"
|
|
873
|
+
onChange={(event) => handleFilesSelected(event.target.files)}
|
|
874
|
+
disabled={!canAttachFiles}
|
|
875
|
+
aria-hidden="true"
|
|
876
|
+
tabIndex={-1}
|
|
877
|
+
/>
|
|
878
|
+
{voice.isActive ? null : (
|
|
879
|
+
<>
|
|
880
|
+
<ComposerAddMenu
|
|
881
|
+
disabled={disabled}
|
|
882
|
+
onAddFiles={canAttachFiles ? () => fileInputRef.current?.click() : undefined}
|
|
883
|
+
onMention={() => insertAtCaret("@")}
|
|
884
|
+
onCommand={
|
|
885
|
+
value.length === 0 && allCommands().length > 0
|
|
886
|
+
? () => insertAtCaret("/")
|
|
887
|
+
: undefined
|
|
888
|
+
}
|
|
889
|
+
/>
|
|
890
|
+
<span
|
|
891
|
+
aria-hidden="true"
|
|
892
|
+
className="hidden flex-1 group-data-[expanded]/composer:block"
|
|
893
|
+
/>
|
|
894
|
+
</>
|
|
895
|
+
)}
|
|
719
896
|
<Textarea
|
|
720
897
|
ref={textareaRef}
|
|
721
|
-
autoFocus={composerCanFocus({ disabled, pending
|
|
898
|
+
autoFocus={composerCanFocus({ disabled, pending })}
|
|
722
899
|
value={value}
|
|
723
900
|
onChange={(event) => {
|
|
724
901
|
setValue(event.target.value)
|
|
725
902
|
if (voice.error) voice.reset()
|
|
726
903
|
setDismissedMention(null)
|
|
904
|
+
setActiveCommand(0)
|
|
727
905
|
updateMention(event.target.value, event.target.selectionStart)
|
|
728
906
|
}}
|
|
729
907
|
onSelect={(event) =>
|
|
730
908
|
updateMention(event.currentTarget.value, event.currentTarget.selectionStart)
|
|
731
909
|
}
|
|
732
910
|
onKeyDown={handleKeyDown}
|
|
911
|
+
onPaste={handlePaste}
|
|
733
912
|
disabled={disabled}
|
|
734
913
|
readOnly={voice.isActive}
|
|
735
914
|
rows={1}
|
|
@@ -743,63 +922,48 @@ export function Composer({
|
|
|
743
922
|
: (placeholder ?? messages.placeholder)
|
|
744
923
|
}
|
|
745
924
|
aria-label={messages.message}
|
|
746
|
-
className=
|
|
925
|
+
className={cn(
|
|
926
|
+
"max-h-[200px] min-h-10 min-w-0 flex-1 resize-none overflow-y-hidden rounded-none border-0 bg-transparent px-2 py-2 text-[16px] leading-6 tracking-[-0.012em] shadow-none placeholder:text-muted-foreground focus-visible:ring-0 md:text-[16px] dark:bg-transparent",
|
|
927
|
+
"group-data-[expanded]/composer:order-[-1] group-data-[expanded]/composer:basis-full group-data-[expanded]/composer:px-2.5 group-data-[expanded]/composer:pt-1.5 group-data-[expanded]/composer:pb-1",
|
|
928
|
+
// While dictating, the text being spoken into stays; an empty field makes way.
|
|
929
|
+
voice.isActive && "read-only:text-muted-foreground",
|
|
930
|
+
voice.isActive && value.trim().length === 0 && "hidden"
|
|
931
|
+
)}
|
|
747
932
|
/>
|
|
748
|
-
</div>
|
|
749
|
-
<div className="relative flex min-w-0 items-center gap-0.5 px-2 pb-2">
|
|
750
933
|
{voice.isActive ? (
|
|
751
|
-
<DictationBar
|
|
934
|
+
<DictationBar
|
|
935
|
+
dictation={voice}
|
|
936
|
+
buttonClassName={ICON_BUTTON_CLASS_NAME}
|
|
937
|
+
doneClassName={SEND_BUTTON_CLASS_NAME}
|
|
938
|
+
/>
|
|
752
939
|
) : (
|
|
753
940
|
<>
|
|
754
|
-
<
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
941
|
+
<ComposerSettings
|
|
942
|
+
models={models}
|
|
943
|
+
selectedModel={selectedModel}
|
|
944
|
+
selectedReasoning={selectedReasoning}
|
|
945
|
+
modelsLoading={modelsLoading}
|
|
946
|
+
modelsError={modelsError}
|
|
947
|
+
onSelectModel={onSelectModel}
|
|
948
|
+
onSelectReasoning={onSelectReasoning}
|
|
949
|
+
onResetReasoning={onResetReasoning}
|
|
950
|
+
usingDefaultModel={usingDefaultModel}
|
|
951
|
+
onResetModelSelection={onResetModelSelection}
|
|
952
|
+
modelRouting={modelRouting}
|
|
953
|
+
approvalMode={showPermissions ? approvalMode : undefined}
|
|
954
|
+
onApprovalModeChange={showPermissions ? changeApprovalMode : undefined}
|
|
955
|
+
disabled={disabled || pending || running}
|
|
762
956
|
/>
|
|
763
|
-
<button
|
|
764
|
-
type="button"
|
|
765
|
-
onClick={() => fileInputRef.current?.click()}
|
|
766
|
-
disabled={!canAttachFiles}
|
|
767
|
-
aria-label={messages.attachFiles}
|
|
768
|
-
className={cn(
|
|
769
|
-
"flex size-8 shrink-0 items-center justify-center rounded-full text-muted-foreground outline-none transition-colors",
|
|
770
|
-
"hover:bg-muted hover:text-foreground focus-visible:bg-muted focus-visible:ring-2 focus-visible:ring-ring/40",
|
|
771
|
-
"disabled:cursor-not-allowed disabled:opacity-50"
|
|
772
|
-
)}
|
|
773
|
-
>
|
|
774
|
-
<Plus className="size-[18px]" strokeWidth={1.75} />
|
|
775
|
-
</button>
|
|
776
|
-
{showPermissions ? (
|
|
777
|
-
<ApprovalModeChip mode={approvalMode} onChange={changeApprovalMode} />
|
|
778
|
-
) : null}
|
|
779
|
-
<span className="min-w-2 flex-1" />
|
|
780
|
-
{onSelectModel && onSelectReasoning ? (
|
|
781
|
-
<ModelControls
|
|
782
|
-
models={models}
|
|
783
|
-
selectedModel={selectedModel}
|
|
784
|
-
selectedReasoning={selectedReasoning}
|
|
785
|
-
loading={modelsLoading}
|
|
786
|
-
error={modelsError}
|
|
787
|
-
disabled={disabled || pending || running}
|
|
788
|
-
onSelectModel={onSelectModel}
|
|
789
|
-
onSelectReasoning={onSelectReasoning}
|
|
790
|
-
onResetReasoning={onResetReasoning}
|
|
791
|
-
usingDefault={usingDefaultModel}
|
|
792
|
-
onResetToDefault={onResetModelSelection}
|
|
793
|
-
routing={modelRouting}
|
|
794
|
-
/>
|
|
795
|
-
) : null}
|
|
796
957
|
{dictation ? (
|
|
797
958
|
<DictationButton
|
|
798
959
|
dictation={voice}
|
|
799
960
|
disabled={disabled}
|
|
800
961
|
variant="ghost"
|
|
801
|
-
size="icon
|
|
802
|
-
className=
|
|
962
|
+
size="icon"
|
|
963
|
+
className={cn(
|
|
964
|
+
ICON_BUTTON_CLASS_NAME,
|
|
965
|
+
"bg-transparent shadow-none [&_svg]:size-5"
|
|
966
|
+
)}
|
|
803
967
|
/>
|
|
804
968
|
) : null}
|
|
805
969
|
{running && onStop ? (
|
|
@@ -808,29 +972,29 @@ export function Composer({
|
|
|
808
972
|
onClick={onStop}
|
|
809
973
|
disabled={stopping}
|
|
810
974
|
aria-label={messages.stop}
|
|
811
|
-
className={
|
|
975
|
+
className={SEND_BUTTON_CLASS_NAME}
|
|
812
976
|
>
|
|
813
977
|
{stopping ? (
|
|
814
|
-
<Spinner className="size-
|
|
978
|
+
<Spinner className="size-4" />
|
|
815
979
|
) : (
|
|
816
|
-
<Square className="size-
|
|
980
|
+
<Square className="size-3 fill-current" />
|
|
817
981
|
)}
|
|
818
982
|
</button>
|
|
819
|
-
) : (
|
|
983
|
+
) : showSend ? (
|
|
820
984
|
<button
|
|
821
985
|
type="button"
|
|
822
986
|
onClick={submit}
|
|
823
987
|
disabled={!canSend}
|
|
824
988
|
aria-label={messages.send}
|
|
825
|
-
className={
|
|
989
|
+
className={SEND_BUTTON_CLASS_NAME}
|
|
826
990
|
>
|
|
827
991
|
{pending || uploading ? (
|
|
828
|
-
<Spinner className="size-
|
|
992
|
+
<Spinner className="size-4" />
|
|
829
993
|
) : (
|
|
830
|
-
<ArrowUp className="size-
|
|
994
|
+
<ArrowUp className="size-[18px]" strokeWidth={2.4} />
|
|
831
995
|
)}
|
|
832
996
|
</button>
|
|
833
|
-
)}
|
|
997
|
+
) : null}
|
|
834
998
|
</>
|
|
835
999
|
)}
|
|
836
1000
|
</div>
|
|
@@ -882,7 +1046,7 @@ function DropFilesOverlay({ compact }: { readonly compact: boolean }) {
|
|
|
882
1046
|
)
|
|
883
1047
|
}
|
|
884
1048
|
|
|
885
|
-
function
|
|
1049
|
+
function AttachmentChip({
|
|
886
1050
|
attachment,
|
|
887
1051
|
onRemove,
|
|
888
1052
|
}: {
|
|
@@ -894,69 +1058,52 @@ function AttachmentPreview({
|
|
|
894
1058
|
const fileName = attachment.status === "ready" ? attachment.fileRef.fileName : attachment.fileName
|
|
895
1059
|
const mediaType =
|
|
896
1060
|
attachment.status === "ready" ? attachment.fileRef.mediaType : attachment.mediaType
|
|
897
|
-
const
|
|
898
|
-
const
|
|
1061
|
+
const Icon = fileIcon(fileName, mediaType)
|
|
1062
|
+
const status =
|
|
899
1063
|
attachment.status === "uploading"
|
|
900
1064
|
? messages.uploading
|
|
901
1065
|
: attachment.status === "error"
|
|
902
1066
|
? messages.uploadFailed
|
|
903
|
-
:
|
|
1067
|
+
: null
|
|
904
1068
|
|
|
905
1069
|
return (
|
|
906
|
-
<
|
|
907
|
-
className={cn(
|
|
908
|
-
"relative flex max-w-full items-center gap-3 rounded-2xl border border-border bg-background py-2 pr-10 pl-2 shadow-sm",
|
|
909
|
-
attachment.status === "error" && "border-destructive/40"
|
|
910
|
-
)}
|
|
1070
|
+
<span
|
|
1071
|
+
className={cn(COMPOSER_CHIP_CLASS_NAME, "pr-1.5")}
|
|
911
1072
|
title={attachment.status === "error" ? messages.uploadError : fileName}
|
|
912
1073
|
>
|
|
913
|
-
<
|
|
914
|
-
className={cn(
|
|
915
|
-
"flex size-10 shrink-0 items-center justify-center rounded-xl text-white",
|
|
916
|
-
tone === "green" && "bg-emerald-500",
|
|
917
|
-
tone === "red" && "bg-red-500",
|
|
918
|
-
tone === "blue" && "bg-blue-500",
|
|
919
|
-
tone === "zinc" && "bg-zinc-500"
|
|
920
|
-
)}
|
|
921
|
-
>
|
|
1074
|
+
<span className={COMPOSER_CHIP_THUMB_CLASS_NAME}>
|
|
922
1075
|
{attachment.status === "uploading" ? (
|
|
923
|
-
<Spinner className="size-
|
|
1076
|
+
<Spinner className="size-3" />
|
|
924
1077
|
) : (
|
|
925
|
-
<Icon className="size-
|
|
1078
|
+
<Icon className="size-3" strokeWidth={2} aria-hidden="true" />
|
|
926
1079
|
)}
|
|
927
|
-
</
|
|
928
|
-
<
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
</p>
|
|
932
|
-
<p
|
|
1080
|
+
</span>
|
|
1081
|
+
<span className="min-w-0 flex-1 truncate">{fileName || agentMessages.files.file}</span>
|
|
1082
|
+
{status ? (
|
|
1083
|
+
<span
|
|
933
1084
|
className={cn(
|
|
934
|
-
"
|
|
1085
|
+
"shrink-0 text-xs text-muted-foreground",
|
|
935
1086
|
attachment.status === "error" && "text-destructive"
|
|
936
1087
|
)}
|
|
937
1088
|
>
|
|
938
|
-
{
|
|
939
|
-
</
|
|
940
|
-
|
|
1089
|
+
{status}
|
|
1090
|
+
</span>
|
|
1091
|
+
) : null}
|
|
941
1092
|
<button
|
|
942
1093
|
type="button"
|
|
943
1094
|
onClick={onRemove}
|
|
944
1095
|
aria-label={
|
|
945
1096
|
fileName ? messages.removeAttachment(fileName) : messages.removeUnnamedAttachment
|
|
946
1097
|
}
|
|
947
|
-
className=
|
|
1098
|
+
className={COMPOSER_CHIP_REMOVE_CLASS_NAME}
|
|
948
1099
|
>
|
|
949
|
-
<X className="size-
|
|
1100
|
+
<X className="size-[11px]" strokeWidth={2.6} />
|
|
950
1101
|
</button>
|
|
951
|
-
</
|
|
1102
|
+
</span>
|
|
952
1103
|
)
|
|
953
1104
|
}
|
|
954
1105
|
|
|
955
|
-
function
|
|
956
|
-
fileName: string | undefined,
|
|
957
|
-
mediaType: string | undefined,
|
|
958
|
-
messages: AgentMessages["files"]
|
|
959
|
-
) {
|
|
1106
|
+
function fileIcon(fileName: string | undefined, mediaType: string | undefined) {
|
|
960
1107
|
const normalizedName = fileName?.toLowerCase() ?? ""
|
|
961
1108
|
const normalizedType = mediaType?.toLowerCase() ?? ""
|
|
962
1109
|
if (
|
|
@@ -964,21 +1111,22 @@ function fileKind(
|
|
|
964
1111
|
normalizedType.includes("csv") ||
|
|
965
1112
|
/\.(csv|tsv|xls|xlsx)$/i.test(normalizedName)
|
|
966
1113
|
) {
|
|
967
|
-
return
|
|
1114
|
+
return Table2
|
|
968
1115
|
}
|
|
969
1116
|
if (
|
|
970
1117
|
normalizedType.startsWith("image/") ||
|
|
971
1118
|
/\.(png|jpe?g|gif|webp|bmp|svg)$/i.test(normalizedName)
|
|
972
1119
|
) {
|
|
973
|
-
return
|
|
974
|
-
}
|
|
975
|
-
if (normalizedType === "application/pdf" || normalizedName.endsWith(".pdf")) {
|
|
976
|
-
return { Icon: FileText, label: messages.pdf, tone: "red" as const }
|
|
1120
|
+
return ImageIcon
|
|
977
1121
|
}
|
|
978
|
-
if (
|
|
979
|
-
|
|
1122
|
+
if (
|
|
1123
|
+
normalizedType === "application/pdf" ||
|
|
1124
|
+
normalizedType.startsWith("text/") ||
|
|
1125
|
+
/\.(pdf|txt|md|json|yaml|yml)$/i.test(normalizedName)
|
|
1126
|
+
) {
|
|
1127
|
+
return FileText
|
|
980
1128
|
}
|
|
981
|
-
return
|
|
1129
|
+
return FileIcon
|
|
982
1130
|
}
|
|
983
1131
|
|
|
984
1132
|
function attachmentId(): string {
|
|
@@ -993,6 +1141,17 @@ function hasDraggedFiles(event: DragEvent): boolean {
|
|
|
993
1141
|
return Array.from(event.dataTransfer?.types ?? []).includes("Files")
|
|
994
1142
|
}
|
|
995
1143
|
|
|
1144
|
+
/** The files a paste carries; a browser that lists none may still hold them as items. */
|
|
1145
|
+
function clipboardFiles(data: DataTransfer): File[] {
|
|
1146
|
+
const files = Array.from(data.files)
|
|
1147
|
+
if (files.length > 0) return files
|
|
1148
|
+
|
|
1149
|
+
return Array.from(data.items).flatMap((item) => {
|
|
1150
|
+
const file = item.kind === "file" ? item.getAsFile() : null
|
|
1151
|
+
return file ? [file] : []
|
|
1152
|
+
})
|
|
1153
|
+
}
|
|
1154
|
+
|
|
996
1155
|
function contextLabel(label: string): { readonly label?: string } {
|
|
997
1156
|
const trimmed = label.trim()
|
|
998
1157
|
if (!trimmed) return {}
|