mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
feat(frontend): condense the prompt composer into one session config surface
This commit is contained in:
1 parent
86794e896b
commit
c586bcb4ad
12 files changed
+875
-889
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { Fragment, memo, useState, type ReactNode } from 'react'
|
||||
import { Box, Cpu, Paperclip, Shield, ShieldCheck, SlidersHorizontal, Target } from 'lucide-react'
|
||||
import { memo, useEffect, useState, type CSSProperties, type ReactNode } from 'react'
|
||||
import { Box, Check, ChevronLeft, ChevronRight, Cpu, Paperclip, Shield, ShieldCheck, SlidersHorizontal, Target } from 'lucide-react'
|
||||
import type { AgentInfo } from '@opencode-manager/shared/opencode'
|
||||
import { useAgents, useSession } from '@/hooks/useOpenCode'
|
||||
import { useContextUsage } from '@/hooks/useContextUsage'
|
||||
@@ -19,23 +19,12 @@ import {
|
||||
formatContextUsage,
|
||||
} from '@/lib/contextUsage'
|
||||
import { cn } from '@/lib/utils'
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuCheckboxItem,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuRadioGroup,
|
||||
DropdownMenuRadioItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from '@/components/ui/dropdown-menu'
|
||||
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'
|
||||
import { BottomSheet, BottomSheetContent, BottomSheetHeader } from '@/components/ui/bottom-sheet'
|
||||
import { getIconToggleButtonClassName } from '@/components/ui/icon-toggle-button'
|
||||
import { ContextUsageMeter } from '@/components/session/ContextUsageMeter'
|
||||
import { ModelQuickSelect } from '@/components/model/ModelQuickSelect'
|
||||
import { ModelPicker } from '@/components/model/ModelPicker'
|
||||
import { SessionSandboxResourcesDialog } from './SessionSandboxResourcesDialog'
|
||||
import { ToolMenuItemContent } from './ToolMenuItemContent'
|
||||
|
||||
interface SessionConfigMenuProps {
|
||||
sessionID: string
|
||||
@@ -56,37 +45,113 @@ interface SessionConfigMenuProps {
|
||||
onAttachFile: () => void
|
||||
}
|
||||
|
||||
interface SessionConfigEntryBase {
|
||||
key: string
|
||||
title: string
|
||||
detail?: string
|
||||
disabled?: boolean
|
||||
icon?: ReactNode
|
||||
className?: string
|
||||
}
|
||||
|
||||
type SessionConfigEntry =
|
||||
| (SessionConfigEntryBase & { kind: 'radio'; checked: boolean; onSelect: () => void })
|
||||
| (SessionConfigEntryBase & { kind: 'checkbox'; checked: boolean; onSelect: () => void })
|
||||
| (SessionConfigEntryBase & { kind: 'action'; onSelect: () => void })
|
||||
|
||||
interface SessionConfigSection {
|
||||
key: string
|
||||
label: string
|
||||
entries: SessionConfigEntry[]
|
||||
}
|
||||
|
||||
type SelectableAgent = Pick<AgentInfo, 'id' | 'name' | 'color' | 'description'>
|
||||
|
||||
type SessionMenuView = 'main' | 'agent' | 'model'
|
||||
|
||||
type SessionMenuItemRole = 'menuitem' | 'menuitemradio' | 'menuitemcheckbox'
|
||||
|
||||
const BACK_BUTTON_CLASS =
|
||||
'flex shrink-0 items-center justify-center rounded-full border border-border bg-muted text-foreground/80 hover:bg-accent'
|
||||
|
||||
const backButtonClassName = (mobile: boolean) => cn(BACK_BUTTON_CLASS, mobile ? 'h-11 w-11' : 'h-9 w-9')
|
||||
|
||||
const capitalize = (value: string) => value.charAt(0).toUpperCase() + value.slice(1).toLowerCase()
|
||||
|
||||
const findAgent = (agents: SelectableAgent[], agentId: string): SelectableAgent | undefined =>
|
||||
agents.find((agent) => agent.id.toLowerCase() === agentId.toLowerCase())
|
||||
|
||||
const EMPTY_ICON = <span aria-hidden="true" className="block h-4 w-4" />
|
||||
const chipClassName = (mobile: boolean) =>
|
||||
cn(
|
||||
'inline-flex shrink-0 items-center justify-center rounded-md border text-xs font-medium outline-none transition-colors focus-visible:ring-2 focus-visible:ring-ring',
|
||||
mobile ? 'min-h-9 px-3' : 'h-7 px-2',
|
||||
)
|
||||
|
||||
const TRIGGER_CLASS =
|
||||
'relative px-2.5 py-0.5 md:px-3 min-h-11 md:min-h-9 min-w-0 rounded-lg text-xs md:text-sm font-medium border bg-muted border-border text-muted-foreground hover:bg-muted-foreground/10 hover:border-foreground/30 transition-colors cursor-pointer flex-1 md:flex-initial md:w-auto md:max-w-[260px] dark:border-border/30 flex flex-col items-start justify-center overflow-hidden'
|
||||
const rowClassName = (mobile: boolean) =>
|
||||
cn(
|
||||
'flex w-full min-w-0 items-center gap-2 rounded-md pl-2 pr-2 text-left text-sm text-foreground outline-none transition-colors hover:bg-accent focus:bg-accent',
|
||||
mobile ? 'min-h-11 py-2' : 'py-1.5',
|
||||
)
|
||||
|
||||
interface SessionMenuItemProps {
|
||||
role: SessionMenuItemRole
|
||||
checked?: boolean
|
||||
disabled?: boolean
|
||||
onSelect: () => void
|
||||
className?: string
|
||||
style?: CSSProperties
|
||||
title?: string
|
||||
ariaLabel?: string
|
||||
children: ReactNode
|
||||
}
|
||||
|
||||
function SessionMenuItem({
|
||||
role,
|
||||
checked,
|
||||
disabled,
|
||||
onSelect,
|
||||
className,
|
||||
style,
|
||||
title,
|
||||
ariaLabel,
|
||||
children,
|
||||
}: SessionMenuItemProps) {
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
role={role}
|
||||
aria-checked={role === 'menuitem' ? undefined : checked}
|
||||
aria-label={ariaLabel}
|
||||
title={title}
|
||||
disabled={disabled}
|
||||
aria-disabled={disabled ? 'true' : undefined}
|
||||
onClick={onSelect}
|
||||
style={style}
|
||||
className={cn('min-w-0', className)}
|
||||
>
|
||||
{children}
|
||||
</button>
|
||||
)
|
||||
}
|
||||
|
||||
function SwitchPill({ checked }: { checked: boolean }) {
|
||||
return (
|
||||
<span
|
||||
aria-hidden="true"
|
||||
data-state={checked ? 'checked' : 'unchecked'}
|
||||
className={cn(
|
||||
'pointer-events-none inline-flex h-4 w-7 shrink-0 items-center rounded-full border transition-colors',
|
||||
checked ? 'border-success bg-success' : 'border-border bg-input',
|
||||
)}
|
||||
>
|
||||
<span
|
||||
data-state={checked ? 'checked' : 'unchecked'}
|
||||
className={cn(
|
||||
'pointer-events-none block h-2.5 w-2.5 rounded-full bg-background shadow-sm transition-transform',
|
||||
checked ? 'translate-x-3.5' : 'translate-x-0.5',
|
||||
)}
|
||||
/>
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
interface ConfigSectionProps {
|
||||
label?: string
|
||||
children: ReactNode
|
||||
}
|
||||
|
||||
function ConfigSection({ label, children }: ConfigSectionProps) {
|
||||
return (
|
||||
<div className="flex flex-col gap-1">
|
||||
{label ? (
|
||||
<div role="presentation" className="px-2 text-[11px] font-medium uppercase tracking-wide text-muted-foreground">
|
||||
{label}
|
||||
</div>
|
||||
) : null}
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export const SessionConfigMenu = memo(function SessionConfigMenu({
|
||||
sessionID,
|
||||
@@ -118,8 +183,15 @@ export const SessionConfigMenu = memo(function SessionConfigMenu({
|
||||
const permission = usePermissionModeToggle(sessionID, directory ?? '', { enabled: directory !== undefined })
|
||||
const sandbox = useSandboxToggle(sessionID, { enabled: isLocalServer })
|
||||
const [open, setOpen] = useState(false)
|
||||
const [view, setView] = useState<SessionMenuView>('main')
|
||||
const [resourcesOpen, setResourcesOpen] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
if (!modelPickerOpen) return
|
||||
setOpen(true)
|
||||
setView('model')
|
||||
}, [modelPickerOpen])
|
||||
|
||||
const currentAgentInfo = findAgent(agents, currentAgent)
|
||||
const agentLabel = isBashMode ? 'Bash' : capitalize(currentAgentInfo?.name ?? currentAgent)
|
||||
const agentStyleVars = getAgentStyleVars(
|
||||
@@ -137,247 +209,382 @@ export const SessionConfigMenu = memo(function SessionConfigMenu({
|
||||
contextUsage ? contextUsageAccessibleLabel(contextUsage) : null,
|
||||
].filter(Boolean).join(', ')}`
|
||||
|
||||
const sections: SessionConfigSection[] = [
|
||||
{
|
||||
key: 'agent',
|
||||
label: 'Agent',
|
||||
entries: getPrimaryAgents(agents).map((agent) => ({
|
||||
kind: 'radio',
|
||||
key: `agent:${agent.id}`,
|
||||
title: capitalize(agent.name),
|
||||
detail: agent.description || undefined,
|
||||
checked: agent.id.toLowerCase() === currentAgent.toLowerCase(),
|
||||
onSelect: () => onAgentChange(agent.id),
|
||||
})),
|
||||
},
|
||||
{
|
||||
key: 'model',
|
||||
label: 'Model',
|
||||
entries: [
|
||||
{
|
||||
kind: 'action',
|
||||
key: 'model',
|
||||
title: modelName || 'Select model',
|
||||
detail: 'Change model',
|
||||
onSelect: () => {
|
||||
setOpen(false)
|
||||
setTimeout(() => onModelPickerOpenChange(true), 0)
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
]
|
||||
const primaryAgents = getPrimaryAgents(agents)
|
||||
|
||||
const handleOpenChange = (nextOpen: boolean) => {
|
||||
setOpen(nextOpen)
|
||||
if (nextOpen) return
|
||||
setView('main')
|
||||
onModelPickerOpenChange(false)
|
||||
}
|
||||
|
||||
const handleModelBack = () => {
|
||||
setView('main')
|
||||
onModelPickerOpenChange(false)
|
||||
}
|
||||
|
||||
const handleModelSelected = () => {
|
||||
setView('main')
|
||||
onModelPickerOpenChange(false)
|
||||
}
|
||||
|
||||
const renderMainView = (mobile: boolean) => {
|
||||
const sections: Array<{ key: string; node: ReactNode }> = []
|
||||
|
||||
if (hasVariants) {
|
||||
sections.push({
|
||||
key: 'variant',
|
||||
label: 'Variant',
|
||||
entries: [
|
||||
{
|
||||
kind: 'radio',
|
||||
key: 'variant:default',
|
||||
title: 'Default',
|
||||
checked: currentVariant === undefined,
|
||||
onSelect: clearVariant,
|
||||
},
|
||||
...availableVariants.map((variant) => ({
|
||||
kind: 'radio' as const,
|
||||
key: `variant:${variant}`,
|
||||
title: variant,
|
||||
className: 'capitalize',
|
||||
checked: currentVariant === variant,
|
||||
onSelect: () => setVariant(variant),
|
||||
})),
|
||||
],
|
||||
key: 'agent',
|
||||
node: (
|
||||
<ConfigSection label="Agent">
|
||||
<SessionMenuItem
|
||||
role="menuitem"
|
||||
ariaLabel={`Change agent: ${agentLabel}`}
|
||||
onSelect={() => setView('agent')}
|
||||
className={rowClassName(mobile)}
|
||||
>
|
||||
<span
|
||||
aria-hidden="true"
|
||||
className="h-2.5 w-2.5 shrink-0 rounded-full"
|
||||
style={{ backgroundColor: agentStyleVars['--agent-color'] }}
|
||||
/>
|
||||
<span className="min-w-0 flex-1 truncate">{agentLabel}</span>
|
||||
<ChevronRight aria-hidden="true" className="h-4 w-4 shrink-0 text-muted-foreground" />
|
||||
</SessionMenuItem>
|
||||
</ConfigSection>
|
||||
),
|
||||
})
|
||||
}
|
||||
|
||||
sections.push({
|
||||
key: 'context',
|
||||
label: 'Context',
|
||||
entries: [
|
||||
{
|
||||
kind: 'action',
|
||||
key: 'context',
|
||||
title: 'Compact session',
|
||||
detail: contextUsage ? contextUsageAccessibleLabel(contextUsage) : undefined,
|
||||
disabled: isCompacting,
|
||||
onSelect: () => {
|
||||
onCompact()
|
||||
setOpen(false)
|
||||
},
|
||||
},
|
||||
],
|
||||
})
|
||||
sections.push({
|
||||
key: 'model',
|
||||
node: (
|
||||
<ConfigSection label="Model">
|
||||
<SessionMenuItem
|
||||
role="menuitem"
|
||||
ariaLabel={`Change model: ${modelName || 'Select model'}`}
|
||||
onSelect={() => setView('model')}
|
||||
className={rowClassName(mobile)}
|
||||
>
|
||||
<span className="min-w-0 flex-1 truncate">{modelName || 'Select model'}</span>
|
||||
<ChevronRight aria-hidden="true" className="h-4 w-4 shrink-0 text-muted-foreground" />
|
||||
</SessionMenuItem>
|
||||
</ConfigSection>
|
||||
),
|
||||
})
|
||||
|
||||
if (directory !== undefined) {
|
||||
const sessionEntries: SessionConfigEntry[] = [
|
||||
{
|
||||
kind: 'checkbox',
|
||||
key: 'permission',
|
||||
title: 'Accept all permissions',
|
||||
detail: permission.disabled ? permission.label : undefined,
|
||||
checked: permission.isAuto,
|
||||
disabled: permission.disabled,
|
||||
icon: permission.isAuto ? <ShieldCheck className="h-4 w-4" /> : <Shield className="h-4 w-4" />,
|
||||
onSelect: permission.toggle,
|
||||
},
|
||||
]
|
||||
|
||||
if (isLocalServer && sandbox.available) {
|
||||
sessionEntries.push({
|
||||
kind: 'checkbox',
|
||||
key: 'sandbox',
|
||||
title: 'Sandbox commands',
|
||||
detail: sandbox.disabled ? sandbox.label : undefined,
|
||||
checked: sandbox.isSandboxed,
|
||||
disabled: sandbox.disabled,
|
||||
icon: <Box className="h-4 w-4" />,
|
||||
onSelect: sandbox.toggle,
|
||||
if (hasVariants) {
|
||||
sections.push({
|
||||
key: 'variant',
|
||||
node: (
|
||||
<ConfigSection label="Variant">
|
||||
<div className="flex flex-wrap gap-1 px-2">
|
||||
<SessionMenuItem
|
||||
role="menuitemradio"
|
||||
checked={currentVariant === undefined}
|
||||
onSelect={clearVariant}
|
||||
className={cn(
|
||||
chipClassName(mobile),
|
||||
currentVariant === undefined
|
||||
? 'border-primary bg-primary text-primary-foreground'
|
||||
: 'border-border/60 text-muted-foreground hover:border-foreground/30 hover:text-foreground',
|
||||
)}
|
||||
>
|
||||
Default
|
||||
</SessionMenuItem>
|
||||
{availableVariants.map((variant) => (
|
||||
<SessionMenuItem
|
||||
key={variant}
|
||||
role="menuitemradio"
|
||||
checked={currentVariant === variant}
|
||||
onSelect={() => setVariant(variant)}
|
||||
className={cn(
|
||||
chipClassName(mobile),
|
||||
'capitalize',
|
||||
currentVariant === variant
|
||||
? 'border-primary bg-primary text-primary-foreground'
|
||||
: 'border-border/60 text-muted-foreground hover:border-foreground/30 hover:text-foreground',
|
||||
)}
|
||||
>
|
||||
{variant}
|
||||
</SessionMenuItem>
|
||||
))}
|
||||
</div>
|
||||
</ConfigSection>
|
||||
),
|
||||
})
|
||||
|
||||
if (shouldShowSandboxResources(sandbox)) {
|
||||
sessionEntries.push({
|
||||
kind: 'action',
|
||||
key: 'sandbox-resources',
|
||||
title: 'Sandbox resources…',
|
||||
detail: `${formatSandboxResources(sandbox.effectiveResources!)}${sandbox.resources ? ' · custom' : ''}`,
|
||||
icon: <Cpu className="h-4 w-4" />,
|
||||
onSelect: () => {
|
||||
setOpen(false)
|
||||
setTimeout(() => setResourcesOpen(true), 0)
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
sessionEntries.push({
|
||||
kind: 'checkbox',
|
||||
key: 'goal',
|
||||
title: 'Goal mode',
|
||||
detail: goalDisabled ? goalLabel : undefined,
|
||||
checked: goalArmed,
|
||||
disabled: goalDisabled,
|
||||
icon: <Target className="h-4 w-4" />,
|
||||
onSelect: onToggleGoal,
|
||||
sections.push({
|
||||
key: 'context',
|
||||
node: (
|
||||
<ConfigSection label="Context">
|
||||
<div className="flex items-center gap-2 px-2">
|
||||
<div className="flex min-w-0 flex-1 flex-col gap-1">
|
||||
{usageLabel ? (
|
||||
<>
|
||||
<span className={cn('truncate text-xs font-medium', usageTone)}>{usageLabel}</span>
|
||||
{contextUsage ? (
|
||||
<ContextUsageMeter percentage={contextUsage.usagePercentage} className="h-1" />
|
||||
) : null}
|
||||
</>
|
||||
) : (
|
||||
<span className="text-xs text-muted-foreground">No context usage yet</span>
|
||||
)}
|
||||
</div>
|
||||
<SessionMenuItem
|
||||
role="menuitem"
|
||||
ariaLabel="Compact session"
|
||||
disabled={isCompacting}
|
||||
onSelect={() => {
|
||||
onCompact()
|
||||
handleOpenChange(false)
|
||||
}}
|
||||
className={cn(
|
||||
rowClassName(mobile),
|
||||
'w-auto shrink-0 justify-center rounded-md border border-border/70 px-2 py-1 text-xs font-medium',
|
||||
mobile ? 'min-h-9' : 'min-h-0',
|
||||
)}
|
||||
>
|
||||
Compact
|
||||
</SessionMenuItem>
|
||||
</div>
|
||||
</ConfigSection>
|
||||
),
|
||||
})
|
||||
|
||||
sections.push({ key: 'session', label: 'Session', entries: sessionEntries })
|
||||
}
|
||||
if (directory !== undefined) {
|
||||
sections.push({
|
||||
key: 'session',
|
||||
node: (
|
||||
<ConfigSection label="Session">
|
||||
<SessionMenuItem
|
||||
role="menuitemcheckbox"
|
||||
checked={permission.isAuto}
|
||||
disabled={permission.disabled}
|
||||
onSelect={permission.toggle}
|
||||
className={rowClassName(mobile)}
|
||||
>
|
||||
<span className="shrink-0 text-muted-foreground">
|
||||
{permission.isAuto ? <ShieldCheck className="h-4 w-4" /> : <Shield className="h-4 w-4" />}
|
||||
</span>
|
||||
<span className="flex min-w-0 flex-1 flex-col">
|
||||
<span className="truncate">Accept all permissions</span>
|
||||
{permission.disabled ? (
|
||||
<span className="text-xs leading-snug text-muted-foreground">{permission.label}</span>
|
||||
) : null}
|
||||
</span>
|
||||
<SwitchPill checked={permission.isAuto} />
|
||||
</SessionMenuItem>
|
||||
|
||||
sections.push({
|
||||
key: 'attach',
|
||||
label: '',
|
||||
entries: [
|
||||
{
|
||||
kind: 'action',
|
||||
key: 'attach',
|
||||
title: 'Attach image or PDF',
|
||||
icon: <Paperclip className="h-4 w-4" />,
|
||||
onSelect: () => {
|
||||
onAttachFile()
|
||||
setOpen(false)
|
||||
},
|
||||
},
|
||||
],
|
||||
})
|
||||
{isLocalServer && sandbox.available ? (
|
||||
<SessionMenuItem
|
||||
role="menuitemcheckbox"
|
||||
checked={sandbox.isSandboxed}
|
||||
disabled={sandbox.disabled}
|
||||
onSelect={sandbox.toggle}
|
||||
className={rowClassName(mobile)}
|
||||
>
|
||||
<span className="shrink-0 text-muted-foreground">
|
||||
<Box className="h-4 w-4" />
|
||||
</span>
|
||||
<span className="flex min-w-0 flex-1 flex-col">
|
||||
<span className="truncate">Sandbox commands</span>
|
||||
{sandbox.disabled ? (
|
||||
<span className="text-xs leading-snug text-muted-foreground">{sandbox.label}</span>
|
||||
) : null}
|
||||
</span>
|
||||
<SwitchPill checked={sandbox.isSandboxed} />
|
||||
</SessionMenuItem>
|
||||
) : null}
|
||||
|
||||
const renderDesktopEntry = (entry: SessionConfigEntry) => {
|
||||
const fallbackClass = entry.kind === 'action' ? 'pl-8' : undefined
|
||||
{isLocalServer && sandbox.available && shouldShowSandboxResources(sandbox) ? (
|
||||
<SessionMenuItem
|
||||
role="menuitem"
|
||||
onSelect={() => {
|
||||
handleOpenChange(false)
|
||||
setTimeout(() => setResourcesOpen(true), 0)
|
||||
}}
|
||||
className={rowClassName(mobile)}
|
||||
>
|
||||
<span className="shrink-0 text-muted-foreground">
|
||||
<Cpu className="h-4 w-4" />
|
||||
</span>
|
||||
<span className="flex min-w-0 flex-1 flex-col">
|
||||
<span className="truncate">Sandbox resources…</span>
|
||||
<span className="text-xs leading-snug text-muted-foreground">
|
||||
{formatSandboxResources(sandbox.effectiveResources!)}
|
||||
{sandbox.resources ? ' · custom' : ''}
|
||||
</span>
|
||||
</span>
|
||||
<ChevronRight aria-hidden="true" className="h-4 w-4 shrink-0 text-muted-foreground" />
|
||||
</SessionMenuItem>
|
||||
) : null}
|
||||
|
||||
if (entry.kind === 'radio') {
|
||||
return (
|
||||
<DropdownMenuRadioItem
|
||||
key={entry.key}
|
||||
value={entry.key}
|
||||
disabled={entry.disabled}
|
||||
className={cn(fallbackClass, entry.className)}
|
||||
onSelect={(event) => event.preventDefault()}
|
||||
>
|
||||
<ToolMenuItemContent icon={entry.icon ?? EMPTY_ICON} title={entry.title} detail={entry.detail} />
|
||||
</DropdownMenuRadioItem>
|
||||
)
|
||||
<SessionMenuItem
|
||||
role="menuitemcheckbox"
|
||||
checked={goalArmed}
|
||||
disabled={goalDisabled}
|
||||
onSelect={onToggleGoal}
|
||||
className={rowClassName(mobile)}
|
||||
>
|
||||
<span className="shrink-0 text-muted-foreground">
|
||||
<Target className="h-4 w-4" />
|
||||
</span>
|
||||
<span className="flex min-w-0 flex-1 flex-col">
|
||||
<span className="truncate">Goal mode</span>
|
||||
{goalDisabled ? (
|
||||
<span className="text-xs leading-snug text-muted-foreground">{goalLabel}</span>
|
||||
) : null}
|
||||
</span>
|
||||
<SwitchPill checked={goalArmed} />
|
||||
</SessionMenuItem>
|
||||
</ConfigSection>
|
||||
),
|
||||
})
|
||||
}
|
||||
|
||||
if (entry.kind === 'checkbox') {
|
||||
return (
|
||||
<DropdownMenuCheckboxItem
|
||||
key={entry.key}
|
||||
checked={entry.checked}
|
||||
disabled={entry.disabled}
|
||||
className={cn(fallbackClass, entry.className)}
|
||||
onSelect={(event) => event.preventDefault()}
|
||||
onCheckedChange={() => entry.onSelect()}
|
||||
>
|
||||
<ToolMenuItemContent icon={entry.icon ?? EMPTY_ICON} title={entry.title} detail={entry.detail} />
|
||||
</DropdownMenuCheckboxItem>
|
||||
)
|
||||
}
|
||||
sections.push({
|
||||
key: 'attach',
|
||||
node: (
|
||||
<ConfigSection>
|
||||
<SessionMenuItem
|
||||
role="menuitem"
|
||||
onSelect={() => {
|
||||
onAttachFile()
|
||||
handleOpenChange(false)
|
||||
}}
|
||||
className={rowClassName(mobile)}
|
||||
>
|
||||
<Paperclip aria-hidden="true" className="h-4 w-4 shrink-0 text-muted-foreground" />
|
||||
<span className="truncate">Attach image or PDF</span>
|
||||
</SessionMenuItem>
|
||||
</ConfigSection>
|
||||
),
|
||||
})
|
||||
|
||||
return (
|
||||
<DropdownMenuItem
|
||||
key={entry.key}
|
||||
disabled={entry.disabled}
|
||||
className={cn(fallbackClass, entry.className)}
|
||||
onSelect={() => entry.onSelect()}
|
||||
>
|
||||
<ToolMenuItemContent icon={entry.icon ?? EMPTY_ICON} title={entry.title} detail={entry.detail} />
|
||||
</DropdownMenuItem>
|
||||
<div className="flex flex-col gap-2">
|
||||
{sections.map((section, index) => (
|
||||
<div key={section.key} className={index > 0 ? 'border-t border-border/50 pt-2' : undefined}>
|
||||
{section.node}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const renderDesktopSection = (section: SessionConfigSection) => {
|
||||
const checkedKey = section.entries.find((entry) => entry.kind === 'radio' && entry.checked)?.key
|
||||
const hasRadio = section.entries.some((entry) => entry.kind === 'radio')
|
||||
|
||||
if (hasRadio) {
|
||||
return (
|
||||
<DropdownMenuRadioGroup
|
||||
value={checkedKey}
|
||||
onValueChange={(value) => {
|
||||
section.entries.find((entry) => entry.kind === 'radio' && entry.key === value)?.onSelect()
|
||||
}}
|
||||
const renderAgentView = (mobile: boolean) => (
|
||||
<div className="flex flex-col gap-1">
|
||||
<div className="flex items-center gap-2 px-1 pb-1">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setView('main')}
|
||||
className={backButtonClassName(mobile)}
|
||||
aria-label="Back to session config"
|
||||
>
|
||||
{section.entries.map(renderDesktopEntry)}
|
||||
</DropdownMenuRadioGroup>
|
||||
)
|
||||
}
|
||||
<ChevronLeft className="h-5 w-5" />
|
||||
</button>
|
||||
<h2 className="truncate text-sm font-semibold text-foreground">Agent</h2>
|
||||
</div>
|
||||
<div role="menu" aria-label="Agent">
|
||||
{primaryAgents.map((agent) => {
|
||||
const checked = agent.id.toLowerCase() === currentAgent.toLowerCase()
|
||||
return (
|
||||
<SessionMenuItem
|
||||
key={agent.id}
|
||||
role="menuitemradio"
|
||||
checked={checked}
|
||||
title={agent.description || undefined}
|
||||
onSelect={() => {
|
||||
onAgentChange(agent.id)
|
||||
setView('main')
|
||||
}}
|
||||
className={rowClassName(mobile)}
|
||||
>
|
||||
<span
|
||||
aria-hidden="true"
|
||||
className="h-2.5 w-2.5 shrink-0 rounded-full"
|
||||
style={{ backgroundColor: getAgentStyleVars(agent.id, agent.color)['--agent-color'] }}
|
||||
/>
|
||||
<span className="flex min-w-0 flex-1 flex-col">
|
||||
<span className="truncate">{capitalize(agent.name)}</span>
|
||||
{agent.description ? (
|
||||
<span className="truncate text-xs leading-snug text-muted-foreground">{agent.description}</span>
|
||||
) : null}
|
||||
</span>
|
||||
{checked ? <Check aria-hidden="true" className="h-4 w-4 shrink-0 text-highlight" /> : null}
|
||||
</SessionMenuItem>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
return section.entries.map(renderDesktopEntry)
|
||||
}
|
||||
const renderModelView = () => (
|
||||
<ModelPicker
|
||||
directory={directory}
|
||||
session={modelSelectionSession}
|
||||
onSelect={handleModelSelected}
|
||||
onBack={handleModelBack}
|
||||
active
|
||||
/>
|
||||
)
|
||||
|
||||
const meter = contextUsage
|
||||
? <ContextUsageMeter percentage={contextUsage.usagePercentage} className="absolute inset-x-0 bottom-0" />
|
||||
: null
|
||||
|
||||
const desktopTrigger = (
|
||||
const gutterCardClassName = isMobile
|
||||
? undefined
|
||||
: cn(
|
||||
'@min-[86rem]/composer:absolute @min-[86rem]/composer:bottom-0 @min-[86rem]/composer:right-full @min-[86rem]/composer:mr-4',
|
||||
'@min-[86rem]/composer:h-10 @min-[86rem]/composer:w-[min(22rem,calc((100cqw_-_56rem)/2_-_2.5rem))]',
|
||||
'@min-[86rem]/composer:items-center @min-[86rem]/composer:justify-start',
|
||||
'@min-[86rem]/composer:rounded-lg @min-[86rem]/composer:border-border @min-[86rem]/composer:bg-background/95',
|
||||
'@min-[86rem]/composer:p-2.5 @min-[86rem]/composer:shadow-none',
|
||||
'@min-[86rem]/composer:hover:scale-100 @min-[86rem]/composer:hover:bg-accent @min-[86rem]/composer:active:scale-100',
|
||||
)
|
||||
|
||||
const renderTrigger = (onClick?: () => void) => (
|
||||
<button
|
||||
type="button"
|
||||
aria-label={configName}
|
||||
title={configName}
|
||||
data-active={isAnySessionToggleActive ? 'true' : undefined}
|
||||
className={TRIGGER_CLASS}
|
||||
onClick={onClick}
|
||||
className={cn(
|
||||
getIconToggleButtonClassName(isAnySessionToggleActive),
|
||||
'relative flex shrink-0 items-center justify-center overflow-hidden p-0',
|
||||
isMobile ? 'size-11' : 'size-9',
|
||||
gutterCardClassName,
|
||||
)}
|
||||
>
|
||||
<span className="flex w-full min-w-0 items-center gap-1 text-left">
|
||||
<SlidersHorizontal className={cn('h-3.5 w-3.5 shrink-0', isAnySessionToggleActive && 'text-highlight')} />
|
||||
<span className="truncate">
|
||||
<span style={{ color: agentStyleVars['--agent-color'] }}>{agentLabel}</span>
|
||||
<span> · {modelName || 'Select model'}</span>
|
||||
<SlidersHorizontal
|
||||
className={cn(isMobile ? 'h-5 w-5' : 'h-4 w-4', !isMobile && '@min-[86rem]/composer:hidden')}
|
||||
/>
|
||||
<span
|
||||
className={cn(
|
||||
'hidden w-full min-w-0 flex-row items-center gap-1.5 whitespace-nowrap text-left',
|
||||
!isMobile && '@min-[86rem]/composer:flex',
|
||||
)}
|
||||
>
|
||||
<span
|
||||
aria-hidden="true"
|
||||
className="h-2 w-2 shrink-0 rounded-full"
|
||||
style={{ backgroundColor: agentStyleVars['--agent-color'] }}
|
||||
/>
|
||||
<span className="shrink-0 text-xs font-medium text-foreground">{agentLabel}</span>
|
||||
<span className="min-w-0 flex-1 truncate text-xs text-muted-foreground">
|
||||
· {modelName || 'Select model'}
|
||||
</span>
|
||||
{showVariant && currentVariant ? (
|
||||
<span className="shrink-0 text-[11px] text-muted-foreground">{capitalize(currentVariant)}</span>
|
||||
) : null}
|
||||
<span className={cn('shrink-0 text-[11px] font-medium', usageLabel ? usageTone : 'text-muted-foreground')}>
|
||||
{usageLabel ?? 'No context yet'}
|
||||
</span>
|
||||
</span>
|
||||
{(showVariant || usageLabel) && (
|
||||
<span className="flex w-full min-w-0 items-center gap-1 text-[10px] leading-tight">
|
||||
{showVariant && <span className="truncate capitalize text-highlight">{currentVariant}</span>}
|
||||
{showVariant && usageLabel && (
|
||||
<span aria-hidden="true" className="text-muted-foreground">·</span>
|
||||
)}
|
||||
{usageLabel && (
|
||||
<span data-testid="composer-config-context-usage" className={cn('shrink-0 font-medium', usageTone)}>
|
||||
{usageLabel}
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
)}
|
||||
{isAnySessionToggleActive ? (
|
||||
<span aria-hidden="true" className="absolute right-1.5 top-1.5 h-1.5 w-1.5 rounded-full bg-highlight" />
|
||||
) : null}
|
||||
{meter}
|
||||
</button>
|
||||
)
|
||||
@@ -386,87 +593,58 @@ export const SessionConfigMenu = memo(function SessionConfigMenu({
|
||||
<>
|
||||
{isMobile ? (
|
||||
<>
|
||||
<button
|
||||
type="button"
|
||||
aria-label={configName}
|
||||
title={configName}
|
||||
data-active={isAnySessionToggleActive ? 'true' : undefined}
|
||||
onClick={() => setOpen(true)}
|
||||
className={cn(
|
||||
getIconToggleButtonClassName(isAnySessionToggleActive),
|
||||
'relative flex items-center justify-center size-11 p-0 overflow-hidden',
|
||||
)}
|
||||
>
|
||||
<SlidersHorizontal className="h-5 w-5" />
|
||||
{meter}
|
||||
</button>
|
||||
{renderTrigger(() => {
|
||||
setView('main')
|
||||
setOpen(true)
|
||||
})}
|
||||
<BottomSheet
|
||||
isOpen={open}
|
||||
onClose={() => setOpen(false)}
|
||||
onClose={() => handleOpenChange(false)}
|
||||
ariaLabel="Session config"
|
||||
heightClass="h-auto max-h-[85dvh]"
|
||||
heightClass="h-[70dvh] max-h-[720px]"
|
||||
>
|
||||
<BottomSheetHeader title="Session config" />
|
||||
<BottomSheetContent>
|
||||
<div role="menu" aria-label="Session config">
|
||||
{sections.map((section, index) => (
|
||||
<div key={section.key} className={index > 0 ? 'mt-2 border-t border-border pt-2' : ''}>
|
||||
{section.label ? (
|
||||
<div role="presentation" className="px-2 py-1 text-sm font-semibold text-muted-foreground">
|
||||
{section.label}
|
||||
</div>
|
||||
) : null}
|
||||
{section.entries.map((entry) => (
|
||||
<button
|
||||
key={entry.key}
|
||||
type="button"
|
||||
role={entry.kind === 'radio' ? 'menuitemradio' : entry.kind === 'checkbox' ? 'menuitemcheckbox' : 'menuitem'}
|
||||
aria-checked={entry.kind === 'action' ? undefined : entry.checked}
|
||||
disabled={entry.disabled}
|
||||
aria-disabled={entry.disabled ? 'true' : undefined}
|
||||
onClick={entry.onSelect}
|
||||
className={cn(
|
||||
'flex w-full min-h-11 items-center rounded-lg px-2 py-2 text-left text-sm hover:bg-accent',
|
||||
entry.className,
|
||||
)}
|
||||
>
|
||||
<ToolMenuItemContent icon={entry.icon ?? EMPTY_ICON} title={entry.title} detail={entry.detail} />
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<BottomSheetContent
|
||||
className={view === 'model' ? 'flex min-h-0 flex-1 flex-col overflow-hidden p-0 pb-safe' : undefined}
|
||||
>
|
||||
{view === 'main' ? (
|
||||
<div role="menu" aria-label="Session config">
|
||||
{renderMainView(true)}
|
||||
</div>
|
||||
) : view === 'agent' ? (
|
||||
renderAgentView(true)
|
||||
) : (
|
||||
renderModelView()
|
||||
)}
|
||||
</BottomSheetContent>
|
||||
</BottomSheet>
|
||||
</>
|
||||
) : (
|
||||
<DropdownMenu open={open} onOpenChange={setOpen}>
|
||||
<DropdownMenuTrigger asChild>{desktopTrigger}</DropdownMenuTrigger>
|
||||
<DropdownMenuContent
|
||||
<Popover open={open} onOpenChange={handleOpenChange}>
|
||||
<PopoverTrigger asChild>{renderTrigger()}</PopoverTrigger>
|
||||
<PopoverContent
|
||||
side="top"
|
||||
align="start"
|
||||
collisionPadding={8}
|
||||
className="w-72 max-h-[70vh] overflow-y-auto"
|
||||
avoidCollisions={false}
|
||||
className="h-[min(70vh,560px)] w-[22rem] max-w-[calc(100vw-1rem)] overflow-hidden p-0"
|
||||
>
|
||||
{sections.map((section, index) => (
|
||||
<Fragment key={section.key}>
|
||||
{index > 0 ? <DropdownMenuSeparator /> : null}
|
||||
{section.label ? <DropdownMenuLabel>{section.label}</DropdownMenuLabel> : null}
|
||||
{renderDesktopSection(section)}
|
||||
</Fragment>
|
||||
))}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
{view === 'main' ? (
|
||||
<div role="menu" aria-label="Session config" className="h-full overflow-y-auto p-1.5">
|
||||
{renderMainView(false)}
|
||||
</div>
|
||||
) : view === 'agent' ? (
|
||||
<div className="h-full overflow-y-auto p-1.5">
|
||||
{renderAgentView(false)}
|
||||
</div>
|
||||
) : (
|
||||
<div className="h-full overflow-hidden">
|
||||
{renderModelView()}
|
||||
</div>
|
||||
)}
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
)}
|
||||
<ModelQuickSelect
|
||||
directory={directory}
|
||||
open={modelPickerOpen}
|
||||
onOpenChange={onModelPickerOpenChange}
|
||||
session={modelSelectionSession}
|
||||
contextUsage={contextUsage}
|
||||
isCompacting={isCompacting}
|
||||
onCompact={onCompact}
|
||||
/>
|
||||
{shouldShowSandboxResources(sandbox) ? (
|
||||
<SessionSandboxResourcesDialog
|
||||
sessionID={sessionID}
|
||||
|
||||
Reference in new issue
Block a user