Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix(ui): mobile chat UX — agent route picker + iOS keyboard composer (#411)

Call Whiteaa7b53600eb6
diff --git a/ui/index.html b/ui/index.html
index a86de3ea7..d25a9ad46 100644
--- a/ui/index.html
+++ b/ui/index.html
@@ -3,10 +3,12 @@
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/png" href="/logo.png" />
- <!-- maximum-scale=1 + user-scalable=no stops iOS Safari from auto-zooming
- when a sub-16px input gains focus; this is an app shell, not a content
- page, so pinch-zoom isn't expected. -->
- <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
+ <!-- maximum-scale=1 + user-scalable=no stops iOS Safari from auto-zooming when
+ a sub-16px input gains focus (app shell, not a content page).
+ interactive-widget=resizes-content lets Android shrink the layout for the
+ keyboard; iOS uses the visualViewport-driven --app-vvh instead (see
+ useViewportHeightVar). -->
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, interactive-widget=resizes-content" />
<title>Vibe Remote</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
diff --git a/ui/src/components/AppShell.tsx b/ui/src/components/AppShell.tsx
index e11514d62..c3261b621 100644
--- a/ui/src/components/AppShell.tsx
+++ b/ui/src/components/AppShell.tsx
@@ -16,6 +16,7 @@ import { NewSessionSheet } from './workbench/NewSessionSheet';
import { Button } from './ui/button';
import logoImg from '../assets/logo.png';
import { getEnabledPlatforms, platformSupportsChannels } from '../lib/platforms';
+import { useViewportHeightVar } from '../lib/useViewportHeightVar';
type ShellNavItem = {
to: string;
@@ -127,6 +128,8 @@ export const AppShell: React.FC = () => {
const [enabledPlatforms, setEnabledPlatforms] = useState<string[]>([]);
const [config, setConfig] = useState<any>(null);
const [newSessionOpen, setNewSessionOpen] = useState(false);
+ // Track the visual viewport so the chat composer stays flush above the iOS keyboard.
+ useViewportHeightVar();
useEffect(() => {
api.getConfig().then((c: any) => {
diff --git a/ui/src/components/Workbench.tsx b/ui/src/components/Workbench.tsx
index ecd8567ac..f8ed1fa17 100644
--- a/ui/src/components/Workbench.tsx
+++ b/ui/src/components/Workbench.tsx
@@ -7,7 +7,7 @@ import { useNewSession } from '../lib/useNewSession';
import { NewProjectDialog } from './workbench/NewProjectDialog';
import { Composer } from './workbench/Composer';
import { ProjectPicker } from './workbench/ProjectPicker';
-import { AgentPicker } from './workbench/AgentPicker';
+import { AgentRoutePicker } from './workbench/AgentRoutePicker';
// Mirrors design.pen DnkGJ "Workbench" canvas: a centered hero panel +
// suggestion chips with the shared chat Composer below it. The Composer is
@@ -89,13 +89,18 @@ export const Workbench: React.FC = () => {
disabled={ns.sending}
/>
)}
- <AgentPicker
- agents={ns.agents}
- defaultAgentName={ns.defaultAgentName}
- value={ns.selectedAgent}
- onChange={ns.setSelectedAgent}
- disabled={ns.sending}
- />
+ <div className="flex min-w-0 flex-col gap-2">
+ <div className="font-mono text-[11px] font-bold uppercase tracking-[0.08em] text-muted">{t('newSession.agent')}</div>
+ <AgentRoutePicker
+ value={ns.agentRoute}
+ agents={ns.agents}
+ onChange={ns.setAgentRoute}
+ defaultLabel={ns.defaultAgentName ? t('newSession.defaultAgentNamed', { name: ns.defaultAgentName }) : t('newSession.defaultAgent')}
+ disabled={ns.sending}
+ align="start"
+ triggerClassName="w-full max-w-full"
+ />
+ </div>
<Composer
onSend={send}
placeholder={t('workbench.canvas.inputPlaceholder')}
diff --git a/ui/src/components/workbench/AgentPicker.tsx b/ui/src/components/workbench/AgentPicker.tsx
deleted file mode 100644
index 1330f13de..000000000
--- a/ui/src/components/workbench/AgentPicker.tsx
+++ /dev/null
@@ -1,67 +0,0 @@
-import { useTranslation } from 'react-i18next';
-import { Bot, Sparkles } from 'lucide-react';
-import clsx from 'clsx';
-
-import type { VibeAgentBrief } from '../../context/ApiContext';
-import { Button } from '../ui/button';
-
-interface AgentPickerProps {
- agents: VibeAgentBrief[];
- defaultAgentName: string | null;
- /** Selected agent, or null for the server default (agents.default_backend). */
- value: VibeAgentBrief | null;
- onChange: (id: string | null) => void;
- disabled?: boolean;
-}
-
-// Shared agent (backend) picker for the create surfaces. A horizontal scroll
-// row: a Default chip (null → the server's default backend, labelled with the
-// resolved agent when known) followed by every enabled Vibe Agent, each tagged
-// with its backend. Hidden entirely when no agents are loaded (the create then
-// just uses the default).
-export const AgentPicker: React.FC<AgentPickerProps> = ({ agents, defaultAgentName, value, onChange, disabled }) => {
- const { t } = useTranslation();
- if (agents.length === 0) return null;
- const chipClass = (active: boolean) =>
- clsx(
- 'h-auto shrink-0 gap-1.5 rounded-full px-3 py-1.5 text-[12.5px] font-medium',
- active ? 'border-cyan/40 bg-cyan/[0.08] text-cyan hover:bg-cyan/[0.08] hover:text-cyan' : 'text-foreground',
- );
- return (
- <div className="flex flex-col gap-2">
- <div className="font-mono text-[11px] font-bold uppercase tracking-[0.08em] text-muted">
- {t('newSession.agent')}
- </div>
- <div className="-mx-1 flex gap-2 overflow-x-auto px-1 pb-1">
- <Button
- type="button"
- variant="outline"
- size="sm"
- onClick={() => onChange(null)}
- disabled={disabled}
- className={chipClass(value === null)}
- >
- <Sparkles className="size-3.5" />
- <span className="max-w-[160px] truncate">
- {defaultAgentName ? t('newSession.defaultAgentNamed', { name: defaultAgentName }) : t('newSession.defaultAgent')}
- </span>
- </Button>
- {agents.map((agent) => (
- <Button
- key={agent.id}
- type="button"
- variant="outline"
- size="sm"
- onClick={() => onChange(agent.id)}
- disabled={disabled}
- className={chipClass(value?.id === agent.id)}
- >
- <Bot className="size-3.5" />
- <span className="max-w-[140px] truncate">{agent.name}</span>
- <span className="rounded bg-foreground/[0.06] px-1 font-mono text-[9px] uppercase text-muted">{agent.backend}</span>
- </Button>
- ))}
- </div>
- </div>
- );
-};
diff --git a/ui/src/components/workbench/AgentRoutePicker.tsx b/ui/src/components/workbench/AgentRoutePicker.tsx
new file mode 100644
index 000000000..adaf08feb
--- /dev/null
+++ b/ui/src/components/workbench/AgentRoutePicker.tsx
@@ -0,0 +1,329 @@
+import { useCallback, useEffect, useMemo, useState } from 'react';
+import { useTranslation } from 'react-i18next';
+import { useNavigate } from 'react-router-dom';
+import { Bot, ChevronDown, Loader2, Plus, Sparkles } from 'lucide-react';
+import clsx from 'clsx';
+
+import { useApi } from '../../context/ApiContext';
+import type { VibeAgentBrief } from '../../context/ApiContext';
+import { fetchBackendModels } from '../../lib/backendModels';
+import { resolveEffortOptions } from '../../lib/effortOptions';
+import { Popover, PopoverContent, PopoverTrigger } from '../ui/popover';
+import { Button } from '../ui/button';
+
+// The route fields the picker reads. A subset of WorkbenchSession (chat) and of
+// WorkbenchSessionCreate (the create flow), so both can pass their object directly.
+export interface AgentRouteValue {
+ agent_backend?: string | null;
+ agent_name?: string | null;
+ agent_id?: string | null;
+ model?: string | null;
+ reasoning_effort?: string | null;
+}
+
+// The patch onChange emits. agent_variant tracks the backend so a session can
+// resume its native thread (the native-session map is keyed by agent_variant).
+export interface AgentRoutePatch extends AgentRouteValue {
+ agent_variant?: string | null;
+}
+
+interface AgentRoutePickerProps {
+ value: AgentRouteValue;
+ agents: VibeAgentBrief[];
+ onChange: (patch: AgentRoutePatch) => void | Promise<void>;
+ /** Trigger label when no agent is selected — the create flow shows "默认 · …". */
+ defaultLabel?: string;
+ disabled?: boolean;
+ align?: 'start' | 'end';
+ /** Override the trigger width (chat caps at 62%; the create surfaces go full width). */
+ triggerClassName?: string;
+ /** Make the popover a modal layer — required when nested in a modal Dialog (the
+ * new-session sheet) so its content isn't aria-hidden/inert by the dialog. */
+ modal?: boolean;
+ /** Called before navigating to /agents — the create sheet uses it to close
+ * itself so the destination isn't left behind a focus-trapped modal. */
+ onNavigateAway?: () => void;
+}
+
+// design.pen Q5xIZa — one cyan-ringed trigger showing `[backend] agent · model ·
+// effort` that opens a three-column cascading menu (Agent → Model → Effort).
+// Picking an agent seeds model/effort from its defaults; the model column is
+// fetched lazily per backend. CONTROLLED so it serves both the chat header
+// (value=session, onChange patches the session) and the create surfaces
+// (value=draft route, onChange updates the draft) — one source of truth. On
+// phones the three columns stack into one scrollable list.
+export const AgentRoutePicker: React.FC<AgentRoutePickerProps> = ({
+ value,
+ agents,
+ onChange,
+ defaultLabel,
+ disabled,
+ align = 'end',
+ triggerClassName,
+ modal,
+ onNavigateAway,
+}) => {
+ const { t } = useTranslation();
+ const api = useApi();
+ const navigate = useNavigate();
+ const [open, setOpen] = useState(false);
+ const [modelsByBackend, setModelsByBackend] = useState<Record<string, string[]>>({});
+ // Claude reasoning efforts are MODEL-specific (newer Opus/Sonnet add xhigh/max),
+ // so the backend returns them keyed by model. Cached so the effort column offers
+ // exactly the efforts the selected model supports.
+ const [claudeReasoning, setClaudeReasoning] = useState<Record<string, { value: string; label: string }[]>>({});
+ const [loadingModels, setLoadingModels] = useState(false);
+ const [patching, setPatching] = useState(false);
+
+ // Serialize patches: an agent pick carries its default model/effort, so if it
+ // resolves AFTER a later model/effort pick the later choice would be rolled
+ // back. One patch at a time, items disabled while it's in flight.
+ const applyPatch = useCallback(
+ async (changes: AgentRoutePatch) => {
+ if (patching) return;
+ setPatching(true);
+ try {
+ await onChange(changes);
+ } finally {
+ setPatching(false);
+ }
+ },
+ [patching, onChange],
+ );
+
+ const backend = value.agent_backend || '';
+ const currentAgent = value.agent_name;
+ const currentModel = value.model;
+ const currentEffort = value.reasoning_effort;
+
+ const grouped = useMemo(() => {
+ const groups: Record<string, VibeAgentBrief[]> = {};
+ for (const agent of agents) {
+ (groups[agent.backend] ||= []).push(agent);
+ }
+ return groups;
+ }, [agents]);
+
+ // Fetch the active backend's model list the first time the menu opens for it;
+ // cached per backend so toggling agents doesn't refetch.
+ useEffect(() => {
+ if (!open || !backend || modelsByBackend[backend]) return;
+ let cancelled = false;
+ setLoadingModels(true);
+ (async () => {
+ try {
+ const { models, reasoningOptions } = await fetchBackendModels(api, backend);
+ if (!cancelled) {
+ if (reasoningOptions) setClaudeReasoning(reasoningOptions);
+ setModelsByBackend((prev) => ({ ...prev, [backend]: models }));
+ }
+ } catch {
+ if (!cancelled) setModelsByBackend((prev) => ({ ...prev, [backend]: [] }));
+ } finally {
+ if (!cancelled) setLoadingModels(false);
+ }
+ })();
+ return () => {
+ cancelled = true;
+ };
+ }, [open, backend, api, modelsByBackend]);
+
+ const models = modelsByBackend[backend] ?? [];
+ const effortOptions = useMemo(
+ () => resolveEffortOptions(backend, currentModel, claudeReasoning),
+ [backend, currentModel, claudeReasoning],
+ );
+
+ return (
+ <Popover open={open} onOpenChange={setOpen} modal={modal}>
+ <PopoverTrigger asChild>
+ <Button
+ type="button"
+ variant="outline"
+ disabled={disabled}
+ className={clsx(
+ 'inline-flex h-auto items-center justify-start gap-1.5 rounded-lg border-cyan/40 bg-surface-2 px-2.5 py-1.5 text-[12px] font-normal hover:bg-cyan/[0.06]',
+ triggerClassName ?? 'max-w-[62%]',
+ )}
+ >
+ {backend && (
+ <span className="inline-flex shrink-0 items-center gap-1 rounded border border-cyan/30 bg-cyan/[0.08] px-1.5 py-0.5 font-mono text-[9px] font-bold uppercase text-cyan">
+ <Bot className="size-3" />
+ {backend}
+ </span>
+ )}
+ <span className="truncate font-semibold text-foreground">{currentAgent || defaultLabel || t('chat.pickAgent')}</span>
+ {currentModel && (
+ <>
+ <span className="text-muted">·</span>
+ <span className="truncate font-mono text-[10px] text-muted">{currentModel}</span>
+ </>
+ )}
+ {currentEffort && (
+ <>
+ <span className="text-muted">·</span>
+ {/* Localize via the same key the column uses so the closed trigger
+ doesn't show raw low/max in zh builds; unknown falls back to raw. */}
+ <span className="shrink-0 text-[10px] capitalize text-muted">
+ {t(`chat.picker.effortOptions.${currentEffort}`, { defaultValue: currentEffort })}
+ </span>
+ </>
+ )}
+ <ChevronDown className="ml-auto size-3 shrink-0 text-muted" />
+ </Button>
+ </PopoverTrigger>
+ <PopoverContent align={align} className="z-50 max-h-[70vh] w-[620px] max-w-[92vw] overflow-y-auto p-0">
+ {/* On phones the three columns stack into one scrollable list; sm+ keeps
+ the side-by-side cascading menu. */}
+ <div className="grid grid-cols-1 divide-y divide-border sm:grid-cols-3 sm:divide-x sm:divide-y-0">
+ {/* Column 1 — Agent */}
+ <RouteColumn title={t('chat.picker.agent')}>
+ {/* Default option (create surfaces only — they pass defaultLabel): clears
+ the draft route back to {} so the user can return to the server
+ default after picking an agent, without a page refresh. */}
+ {defaultLabel && (
+ <RouteItem
+ active={!currentAgent}
+ disabled={patching}
+ onClick={() =>
+ void applyPatch({
+ agent_name: null,
+ agent_id: null,
+ agent_backend: null,
+ agent_variant: null,
+ model: null,
+ reasoning_effort: null,
+ })
+ }
+ >
+ <Sparkles className="size-3.5 shrink-0 text-cyan" />
+ <span className="flex-1 truncate font-semibold">{defaultLabel}</span>
+ </RouteItem>
+ )}
+ {agents.length === 0 && (
+ <div className="px-2 py-3 text-center text-[11px] text-muted">{t('chat.noAgents')}</div>
+ )}
+ {Object.entries(grouped).map(([be, list]) => (
+ <div key={be} className="flex flex-col gap-0.5 pb-1">
+ <div className="px-2 pt-1.5 font-mono text-[9px] font-bold uppercase tracking-[0.12em] text-muted">{be}</div>
+ {list.map((agent) => (
+ <RouteItem
+ key={agent.id}
+ active={agent.name === currentAgent}
+ disabled={patching}
+ onClick={() =>
+ void applyPatch({
+ agent_name: agent.name,
+ agent_id: agent.id,
+ agent_backend: agent.backend,
+ agent_variant: agent.backend,
+ // Explicit null (not undefined) so switching to an agent with
+ // no default model/effort clears the previous override.
+ model: agent.model ?? null,
+ reasoning_effort: agent.reasoning_effort ?? null,
+ })
+ }
+ >
+ <span className="flex-1 truncate font-semibold">{agent.name}</span>
+ {agent.model && <span className="truncate font-mono text-[9px] text-muted">{agent.model}</span>}
+ </RouteItem>
+ ))}
+ </div>
+ ))}
+ <Button
+ type="button"
+ variant="ghost"
+ size="sm"
+ onClick={() => {
+ setOpen(false);
+ onNavigateAway?.(); // close the create sheet before leaving, if any
+ navigate('/agents');
+ }}
+ className="mt-1 h-auto w-full justify-start gap-1.5 rounded px-2 py-1.5 text-[11px] font-medium text-cyan hover:bg-cyan/[0.08] hover:text-cyan"
+ >
+ <Plus className="size-3.5" />
+ {t('chat.picker.newAgent')}
+ </Button>
+ </RouteColumn>
+
+ {/* Column 2 — Model (lazy-loaded for the active backend) */}
+ <RouteColumn title={t('chat.picker.model')}>
+ {loadingModels && models.length === 0 ? (
+ <div className="flex items-center gap-1.5 px-2 py-3 text-[11px] text-muted">
+ <Loader2 className="size-3 animate-spin" />
+ {t('common.loading')}
+ </div>
+ ) : models.length === 0 ? (
+ <div className="px-2 py-3 text-[11px] text-muted">{t('chat.picker.noModels')}</div>
+ ) : (
+ models.map((model) => (
+ <RouteItem
+ key={model}
+ active={model === currentModel}
+ disabled={patching}
+ onClick={() => {
+ const patch: AgentRoutePatch = { model };
+ // Switching to a Claude model whose effort set no longer includes
+ // the current effort: clear it in the same patch so the displayed
+ // route matches what dispatches.
+ if (backend === 'claude' && currentEffort) {
+ const opts = claudeReasoning[model];
+ if (opts && !opts.some((o) => o.value === currentEffort)) patch.reasoning_effort = null;
+ }
+ void applyPatch(patch);
+ }}
+ >
+ <span className="flex-1 truncate font-mono text-[11px]">{model}</span>
+ </RouteItem>
+ ))
+ )}
+ </RouteColumn>
+
+ {/* Column 3 — Effort (Claude: model-specific; others: backend superset) */}
+ <RouteColumn title={t('chat.picker.effort')}>
+ {effortOptions.map((opt) => (
+ <RouteItem
+ key={opt}
+ active={opt === currentEffort}
+ disabled={patching}
+ onClick={() => void applyPatch({ reasoning_effort: opt })}
+ >
+ <span className="flex-1 capitalize">{t(`chat.picker.effortOptions.${opt}`)}</span>
+ </RouteItem>
+ ))}
+ </RouteColumn>
+ </div>
+ </PopoverContent>
+ </Popover>
+ );
+};
+
+const RouteColumn: React.FC<{ title: string; children: React.ReactNode }> = ({ title, children }) => (
+ <div className="flex min-w-0 flex-col overflow-y-auto p-1.5 sm:max-h-[320px]">
+ <div className="px-2 pb-1 pt-0.5 text-[10px] font-bold uppercase tracking-[0.1em] text-muted">{title}</div>
+ {children}
+ </div>
+);
+
+// A picker row on the shared Button primitive (variant + className overrides)
+// so it inherits the design system's focus/disabled behavior.
+const RouteItem: React.FC<{
+ active: boolean;
+ onClick: () => void;
+ disabled?: boolean;
+ children: React.ReactNode;
+}> = ({ active, onClick, disabled, children }) => (
+ <Button
+ type="button"
+ variant="ghost"
+ size="sm"
+ onClick={onClick}
+ disabled={disabled}
+ className={clsx(
+ 'h-auto w-full justify-start gap-2 rounded px-2 py-1.5 text-left text-[12px] font-normal',
+ active ? 'bg-cyan/[0.10] text-cyan hover:bg-cyan/[0.10] hover:text-cyan' : 'text-foreground hover:bg-foreground/[0.04]',
+ )}
+ >
+ {children}
+ </Button>
+);
diff --git a/ui/src/components/workbench/ChatPage.tsx b/ui/src/components/workbench/ChatPage.tsx
index 69974fccd..504ad8695 100644
--- a/ui/src/components/workbench/ChatPage.tsx
+++ b/ui/src/components/workbench/ChatPage.tsx
@@ -1,7 +1,7 @@
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useLocation, useNavigate, useParams } from 'react-router-dom';
-import { ArrowLeft, Bot, ChevronDown, Clock, Loader2, MessageSquare, Pencil, Plus, X } from 'lucide-react';
+import { ArrowLeft, ChevronDown, Clock, Loader2, MessageSquare, Pencil, X } from 'lucide-react';
import clsx from 'clsx';
import { useApi } from '../../context/ApiContext';
@@ -10,15 +10,13 @@ import type { VibeAgentBrief, WorkbenchMessage, WorkbenchSession } from '../../c
import { apiFetch } from '../../lib/apiFetch';
import { isProxyMediaUrl } from '../../lib/mediaProxy';
import { formatLocalDateTime } from '../../lib/relativeTime';
-import { fetchBackendModels } from '../../lib/backendModels';
-import { resolveEffortOptions } from '../../lib/effortOptions';
+import { AgentRoutePicker } from './AgentRoutePicker';
import { Button } from '../ui/button';
import { ChatImage } from '../ui/chat-image';
import { FileCard } from '../ui/file-card';
import { ImageViewerProvider } from '../ui/image-viewer';
import { Input } from '../ui/input';
import { Markdown } from '../ui/markdown';
-import { Popover, PopoverContent, PopoverTrigger } from '../ui/popover';
import { Composer, type ComposerAttachment } from './Composer';
// While a turn is in flight, reconcile the working/Stop state against the
@@ -709,7 +707,7 @@ export const ChatPage: React.FC = () => {
// and left a 4rem dead gap below the compose bar. On mobile the sticky
// ``h-16`` header occupies 4rem at the top, so subtract that instead.
<ImageViewerProvider images={sessionImages}>
- <div className="-mx-4 -my-5 flex h-[calc(100dvh-4rem)] flex-col md:-mx-10 md:-my-8 md:h-[100dvh]">
+ <div className="-mx-4 -my-5 flex h-[calc(var(--app-vvh)_-_4rem)] flex-col md:-mx-10 md:-my-8 md:h-[var(--app-vvh)]">
<ChatHeaderBar session={session} agents={agents} onPatch={patch} onBack={goBack} />
{error && (
@@ -838,7 +836,7 @@ const ChatHeaderBar: React.FC<ChatHeaderBarProps> = ({ session, agents, onPatch,
<ArrowLeft className="size-3.5" />
</Button>
<TitleField key={session.id} title={session.title} onCommit={(title) => onPatch({ title })} />
- <AgentRoutePicker session={session} agents={agents} onPatch={onPatch} />
+ <AgentRoutePicker value={session} agents={agents} onChange={onPatch} />
</div>
</div>
);
@@ -905,289 +903,6 @@ const TitleField: React.FC<TitleFieldProps> = ({ title, onCommit }) => {
);
};
-interface AgentRoutePickerProps {
- session: WorkbenchSession;
- agents: VibeAgentBrief[];
- onPatch: (changes: Partial<WorkbenchSession>) => Promise<void>;
-}
-
-// design.pen Q5xIZa + its open-state mock: one cyan-ringed trigger showing
-// ``[backend] agent · model · effort`` that opens a three-column cascading
-// menu — Agent → Model → Effort (regression feedback #2, replacing the old
-// popover + free-text model input + segmented-effort trio). Picking an agent
-// seeds model/effort from its defaults; the model column is fetched lazily
-// per backend (Claude / Codex / OpenCode each expose their own model list) so
-// the user selects a real model instead of typing an override by hand.
-const AgentRoutePicker: React.FC<AgentRoutePickerProps> = ({ session, agents, onPatch }) => {
- const { t } = useTranslation();
- const api = useApi();
- const navigate = useNavigate();
- const [open, setOpen] = useState(false);
- const [modelsByBackend, setModelsByBackend] = useState<Record<string, string[]>>({});
- // Claude reasoning efforts are MODEL-specific (newer Opus/Sonnet add
- // xhigh/max), so the backend returns them keyed by model (plus a '' default).
- // Cached from /api/claude/models so the effort column can offer exactly the
- // efforts the selected model supports instead of a static low/medium/high
- // that hides xhigh/max (Codex P2).
- const [claudeReasoning, setClaudeReasoning] = useState<Record<string, { value: string; label: string }[]>>({});
- const [loadingModels, setLoadingModels] = useState(false);
- const [patching, setPatching] = useState(false);
-
- // Serialize picker patches: an agent pick carries the agent's default
- // model/effort, so if it resolves AFTER a subsequent model/effort pick the
- // later choice would be rolled back to the defaults. One patch at a time, with
- // the items disabled while it's in flight (Codex P2).
- const applyPatch = useCallback(
- async (changes: Partial<WorkbenchSession>) => {
- if (patching) return;
- setPatching(true);
- try {
- await onPatch(changes);
- } finally {
- setPatching(false);
- }
- },
- [patching, onPatch],
- );
-
- const backend = session.agent_backend || '';
- const currentAgent = session.agent_name;
- const currentModel = session.model;
- const currentEffort = session.reasoning_effort;
-
- const grouped = useMemo(() => {
- const groups: Record<string, VibeAgentBrief[]> = {};
- for (const agent of agents) {
- (groups[agent.backend] ||= []).push(agent);
- }
- return groups;
- }, [agents]);
-
- // Fetch the active backend's model list the first time the menu opens for
- // it; cached per backend so toggling agents doesn't refetch.
- useEffect(() => {
- if (!open || !backend || modelsByBackend[backend]) return;
- let cancelled = false;
- setLoadingModels(true);
- (async () => {
- try {
- // Shared resolver (lib/backendModels) — OpenCode's provider-prefixing
- // and the per-backend fetch live there so every model picker stays
- // consistent (Agents detail panel, New Agent dialog, this menu).
- const { models, reasoningOptions } = await fetchBackendModels(api, backend);
- if (!cancelled) {
- // Claude returns per-model effort sets so Column 3 can offer
- // xhigh/max only for the models that actually support them.
- if (reasoningOptions) setClaudeReasoning(reasoningOptions);
- setModelsByBackend((prev) => ({ ...prev, [backend]: models }));
- }
- } catch {
- if (!cancelled) setModelsByBackend((prev) => ({ ...prev, [backend]: [] }));
- } finally {
- if (!cancelled) setLoadingModels(false);
- }
- })();
- return () => {
- cancelled = true;
- };
- }, [open, backend, api, modelsByBackend]);
-
- const models = modelsByBackend[backend] ?? [];
-
- // Effort options for Column 3. Claude is model-aware: prefer the selected
- // model's reasoning set, fall back to the backend's '' default set, then the
- // static list (before /api/claude/models has resolved). The '__default__'
- // sentinel is dropped — effort is cleared by switching agents, not via a
- // pseudo-option. Other backends keep their static superset (Codex P2).
- const effortOptions = useMemo(
- () => resolveEffortOptions(backend, currentModel, claudeReasoning),
- [backend, currentModel, claudeReasoning],
- );
-
- return (
- <Popover open={open} onOpenChange={setOpen}>
- <PopoverTrigger asChild>
- <Button
- type="button"
- variant="outline"
- className="inline-flex h-auto max-w-[62%] items-center justify-start gap-1.5 rounded-lg border-cyan/40 bg-surface-2 px-2.5 py-1.5 text-[12px] font-normal hover:bg-cyan/[0.06]"
- >
- {backend && (
- <span className="inline-flex shrink-0 items-center gap-1 rounded border border-cyan/30 bg-cyan/[0.08] px-1.5 py-0.5 font-mono text-[9px] font-bold uppercase text-cyan">
- <Bot className="size-3" />
- {backend}
- </span>
- )}
- <span className="truncate font-semibold text-foreground">{currentAgent || t('chat.pickAgent')}</span>
- {currentModel && (
- <>
- <span className="text-muted">·</span>
- <span className="truncate font-mono text-[10px] text-muted">{currentModel}</span>
- </>
- )}
- {currentEffort && (
- <>
- <span className="text-muted">·</span>
- {/* Localize the selected effort through the SAME key the column uses,
- so the closed trigger doesn't show raw `low`/`max` in zh builds
- (Codex P2). Unknown values fall back to the key (then raw). */}
- <span className="shrink-0 text-[10px] capitalize text-muted">
- {t(`chat.picker.effortOptions.${currentEffort}`, { defaultValue: currentEffort })}
- </span>
- </>
- )}
- <ChevronDown className="size-3 shrink-0 text-muted" />
- </Button>
- </PopoverTrigger>
- <PopoverContent align="end" className="max-h-[70vh] w-[620px] max-w-[92vw] overflow-y-auto p-0">
- {/* On phones the three columns stack into one scrollable list (the
- popover anchors near the bottom like a sheet); sm+ keeps the
- side-by-side cascading menu. */}
- <div className="grid grid-cols-1 divide-y divide-border sm:grid-cols-3 sm:divide-x sm:divide-y-0">
- {/* Column 1 — Agent */}
- <RouteColumn title={t('chat.picker.agent')}>
- {agents.length === 0 && (
- <div className="px-2 py-3 text-center text-[11px] text-muted">{t('chat.noAgents')}</div>
- )}
- {Object.entries(grouped).map(([be, list]) => (
- <div key={be} className="flex flex-col gap-0.5 pb-1">
- <div className="px-2 pt-1.5 font-mono text-[9px] font-bold uppercase tracking-[0.12em] text-muted">
- {be}
- </div>
- {list.map((agent) => (
- <RouteItem
- key={agent.id}
- active={agent.name === currentAgent}
- disabled={patching}
- onClick={() =>
- void applyPatch({
- agent_name: agent.name,
- agent_id: agent.id,
- agent_backend: agent.backend,
- // Track agent_variant to the backend: the persisted
- // native-session map is keyed by agent_variant while
- // Claude/Codex resume by backend name, so leaving a stale
- // variant (old agent name / 'default') means the session
- // can't resume its native thread after a restart and starts
- // fresh (Codex P2).
- agent_variant: agent.backend,
- // Explicit null (not undefined, which JSON.stringify
- // drops) so switching to an agent with no default model /
- // effort CLEARS the previous agent's override server-side.
- model: agent.model ?? null,
- reasoning_effort: agent.reasoning_effort ?? null,
- })
- }
- >
- <span className="flex-1 truncate font-semibold">{agent.name}</span>
- {agent.model && <span className="truncate font-mono text-[9px] text-muted">{agent.model}</span>}
- </RouteItem>
- ))}
- </div>
- ))}
- <Button
- type="button"
- variant="ghost"
- size="sm"
- onClick={() => {
- setOpen(false);
- navigate('/agents');
- }}
- className="mt-1 h-auto w-full justify-start gap-1.5 rounded px-2 py-1.5 text-[11px] font-medium text-cyan hover:bg-cyan/[0.08] hover:text-cyan"
- >
- <Plus className="size-3.5" />
- {t('chat.picker.newAgent')}
- </Button>
- </RouteColumn>
-
- {/* Column 2 — Model (lazy-loaded for the active backend) */}
- <RouteColumn title={t('chat.picker.model')}>
- {loadingModels && models.length === 0 ? (
- <div className="flex items-center gap-1.5 px-2 py-3 text-[11px] text-muted">
- <Loader2 className="size-3 animate-spin" />
- {t('common.loading')}
- </div>
- ) : models.length === 0 ? (
- <div className="px-2 py-3 text-[11px] text-muted">{t('chat.picker.noModels')}</div>
- ) : (
- models.map((model) => (
- <RouteItem
- key={model}
- active={model === currentModel}
- disabled={patching}
- onClick={() => {
- const patch: Partial<WorkbenchSession> = { model };
- // Switching to a Claude model whose effort set no longer includes
- // the current effort (e.g. xhigh/max → a model without them):
- // clear it in the SAME patch. Otherwise the header keeps showing
- // /storing an effort the new model can't run — the backend drops
- // it via normalize_claude_reasoning_effort, so the displayed route
- // wouldn't match what actually dispatches (Codex P2).
- if (backend === 'claude' && currentEffort) {
- const opts = claudeReasoning[model];
- if (opts && !opts.some((o) => o.value === currentEffort)) {
- patch.reasoning_effort = null;
- }
- }
- void applyPatch(patch);
- }}
- >
- <span className="flex-1 truncate font-mono text-[11px]">{model}</span>
- </RouteItem>
- ))
- )}
- </RouteColumn>
-
- {/* Column 3 — Effort (Claude: model-specific; others: backend superset) */}
- <RouteColumn title={t('chat.picker.effort')}>
- {effortOptions.map((opt) => (
- <RouteItem
- key={opt}
- active={opt === currentEffort}
- disabled={patching}
- onClick={() => void applyPatch({ reasoning_effort: opt })}
- >
- <span className="flex-1 capitalize">{t(`chat.picker.effortOptions.${opt}`)}</span>
- </RouteItem>
- ))}
- </RouteColumn>
- </div>
- </PopoverContent>
- </Popover>
- );
-};
-
-const RouteColumn: React.FC<{ title: string; children: React.ReactNode }> = ({ title, children }) => (
- <div className="flex min-w-0 flex-col overflow-y-auto p-1.5 sm:max-h-[320px]">
- <div className="px-2 pb-1 pt-0.5 text-[10px] font-bold uppercase tracking-[0.1em] text-muted">{title}</div>
- {children}
- </div>
-);
-
-// A picker row built on the shared Button primitive (variant + className
-// overrides) rather than a raw <button>, so it inherits the design system's
-// focus/disabled behavior instead of re-rolling token classes (per AGENTS.md).
-const RouteItem: React.FC<{
- active: boolean;
- onClick: () => void;
- disabled?: boolean;
- children: React.ReactNode;
-}> = ({ active, onClick, disabled, children }) => (
- <Button
- type="button"
- variant="ghost"
- size="sm"
- onClick={onClick}
- disabled={disabled}
- className={clsx(
- 'h-auto w-full justify-start gap-2 rounded px-2 py-1.5 text-left text-[12px] font-normal',
- active ? 'bg-cyan/[0.10] text-cyan hover:bg-cyan/[0.10] hover:text-cyan' : 'text-foreground hover:bg-foreground/[0.04]',
- )}
- >
- {children}
- </Button>
-);
-
interface TranscriptProps {
messages: WorkbenchMessage[];
session: WorkbenchSession;
diff --git a/ui/src/components/workbench/NewSessionSheet.tsx b/ui/src/components/workbench/NewSessionSheet.tsx
index aadf642a5..60063bfa9 100644
--- a/ui/src/components/workbench/NewSessionSheet.tsx
+++ b/ui/src/components/workbench/NewSessionSheet.tsx
@@ -7,7 +7,7 @@ import { Dialog, DialogContent, DialogTitle } from '../ui/dialog';
import { Composer } from './Composer';
import { NewProjectDialog } from './NewProjectDialog';
import { ProjectPicker } from './ProjectPicker';
-import { AgentPicker } from './AgentPicker';
+import { AgentRoutePicker } from './AgentRoutePicker';
interface NewSessionSheetProps {
open: boolean;
@@ -79,13 +79,20 @@ export const NewSessionSheet: React.FC<NewSessionSheetProps> = ({ open, onClose,
onNewProject={openNewProject}
disabled={ns.sending}
/>
- <AgentPicker
- agents={ns.agents}
- defaultAgentName={ns.defaultAgentName}
- value={ns.selectedAgent}
- onChange={ns.setSelectedAgent}
- disabled={ns.sending}
- />
+ <div className="flex min-w-0 flex-col gap-2">
+ <div className="font-mono text-[11px] font-bold uppercase tracking-[0.08em] text-muted">{t('newSession.agent')}</div>
+ <AgentRoutePicker
+ value={ns.agentRoute}
+ agents={ns.agents}
+ onChange={ns.setAgentRoute}
+ defaultLabel={ns.defaultAgentName ? t('newSession.defaultAgentNamed', { name: ns.defaultAgentName }) : t('newSession.defaultAgent')}
+ disabled={ns.sending}
+ align="start"
+ triggerClassName="w-full max-w-full"
+ modal
+ onNavigateAway={onClose}
+ />
+ </div>
{ns.error && (
<div className="rounded-md border border-destructive/40 bg-destructive/[0.06] px-3 py-2 text-[12px] text-destructive">
diff --git a/ui/src/components/workbench/ProjectPicker.tsx b/ui/src/components/workbench/ProjectPicker.tsx
index 1f69f1fe3..576995695 100644
--- a/ui/src/components/workbench/ProjectPicker.tsx
+++ b/ui/src/components/workbench/ProjectPicker.tsx
@@ -21,7 +21,9 @@ interface ProjectPickerProps {
export const ProjectPicker: React.FC<ProjectPickerProps> = ({ projects, targetId, onSelect, onNewProject, disabled }) => {
const { t } = useTranslation();
return (
- <div className="flex flex-col gap-2">
+ // min-w-0 lets this shrink inside the sheet's CSS grid so the chip row
+ // scrolls horizontally instead of stretching the whole sheet wide.
+ <div className="flex min-w-0 flex-col gap-2">
<div className="font-mono text-[11px] font-bold uppercase tracking-[0.08em] text-muted">
{t('newSession.project')}
</div>
diff --git a/ui/src/index.css b/ui/src/index.css
index 2c431d668..ee8101c06 100644
--- a/ui/src/index.css
+++ b/ui/src/index.css
@@ -1,6 +1,13 @@
@import "tailwindcss";
@import "tw-animate-css";
+/* Visual-viewport height (px), kept in sync by useViewportHeightVar so full-height
+ surfaces (chat) stay flush above the iOS keyboard. Defaults to the dynamic
+ viewport height before/without JS. */
+:root {
+ --app-vvh: 100dvh;
+}
+
@theme inline {
--color-background: var(--background);
--color-foreground: var(--foreground);
diff --git a/ui/src/lib/useNewSession.ts b/ui/src/lib/useNewSession.ts
index cfc0a6f08..e9f425ad4 100644
--- a/ui/src/lib/useNewSession.ts
+++ b/ui/src/lib/useNewSession.ts
@@ -2,7 +2,7 @@ import { useCallback, useEffect, useMemo, useState } from 'react';
import { useApi } from '../context/ApiContext';
import { useWorkbenchProjectsTree } from '../context/WorkbenchProjectsContext';
-import type { VibeAgentBrief, WorkbenchProject } from '../context/ApiContext';
+import type { VibeAgentBrief, WorkbenchProject, WorkbenchSessionCreate } from '../context/ApiContext';
interface UseNewSessionOptions {
/** Re-run the per-open reset on the rising edge — sheets pass their `open`. Default true. */
@@ -12,6 +12,19 @@ interface UseNewSessionOptions {
createFailedText: string;
}
+// The agent/model/effort selection (agent route). Empty = the server default
+// (agents.default_backend). Fields allow null because the AgentRoutePicker emits
+// null to clear model/effort when switching agents; send() drops nulls before
+// creating so the create payload only carries real values.
+export interface AgentRouteSelection {
+ agent_backend?: string | null;
+ agent_name?: string | null;
+ agent_id?: string | null;
+ agent_variant?: string | null;
+ model?: string | null;
+ reasoning_effort?: string | null;
+}
+
export interface NewSessionState {
projects: WorkbenchProject[];
loaded: boolean;
@@ -21,14 +34,13 @@ export interface NewSessionState {
setSelected: (id: string) => void;
target: WorkbenchProject | null;
needsProject: boolean;
- // Agent (backend) selection — null = the server default (agents.default_backend).
+ // Agent route (agent + model + effort). Empty = the server default.
agents: VibeAgentBrief[];
defaultAgentName: string | null;
- selectedAgent: VibeAgentBrief | null;
- setSelectedAgent: (id: string | null) => void;
- /** Creates a session under `target` (with the picked agent, if any) and returns the nav
- * target; null if it couldn't start (empty / in-flight / not loaded / no project / error).
- * The hook never navigates — the caller does, since the provider is mounted outside the router. */
+ agentRoute: AgentRouteSelection;
+ setAgentRoute: (patch: AgentRouteSelection) => void;
+ /** Creates a session under `target` (with the picked agent route, if any) and returns the
+ * nav target; null if it couldn't start. The hook never navigates — the caller does. */
send: (text: string) => Promise<{ sessionId: string; initialMessage: string } | null>;
upsertSelectProject: (project: WorkbenchProject) => void;
}
@@ -42,8 +54,9 @@ const sortByRecent = (list: WorkbenchProject[]) =>
// and the mobile NewSessionSheet. A thin layer over the shared projects provider
// (the project LIST + the create itself come from there, so a project/session
// created here shows up in the sidebar + Projects tree). It adds the picker
-// selections (project + agent), the transient sending/error state, and target
-// resolution. Navigation + draft + the sheet's open/close lifecycle stay in the consumer.
+// selections (project + agent route), the transient sending/error state, and
+// target resolution. Navigation + draft + the sheet's open/close lifecycle stay
+// in the consumer.
export function useNewSession({ active = true, loadErrorText, createFailedText }: UseNewSessionOptions): NewSessionState {
const api = useApi();
const { projects: rawProjects, projectsError, createSessionForProject, upsertProjectToTop } = useWorkbenchProjectsTree();
@@ -52,14 +65,15 @@ export function useNewSession({ active = true, loadErrorText, createFailedText }
const [sending, setSending] = useState(false);
const [agents, setAgents] = useState<VibeAgentBrief[]>([]);
const [defaultAgentName, setDefaultAgentName] = useState<string | null>(null);
- const [selectedAgentId, setSelectedAgentId] = useState<string | null>(null);
+ // The chosen agent route (agent/model/effort) as create fields; {} = default.
+ const [agentRoute, setAgentRoute] = useState<AgentRouteSelection>({});
const projects = useMemo(() => (rawProjects ? sortByRecent(rawProjects) : []), [rawProjects]);
const loaded = rawProjects !== null;
- // Agents rarely change → fetch once per mount (not per sheet-open). Lets the
- // user pick which Vibe Agent (backend) runs the session instead of always
- // falling back to the server default.
+ // Agents rarely change → fetch once per mount (not per sheet-open). Feeds the
+ // shared AgentRoutePicker so the user can pick agent + model + effort instead
+ // of always falling back to the server default.
useEffect(() => {
let cancelled = false;
api
@@ -92,7 +106,11 @@ export function useNewSession({ active = true, loadErrorText, createFailedText }
// null or now-hidden selection still resolves a sane target.
const target = projects.find((p) => p.id === selectedId) ?? projects[0] ?? null;
const needsProject = loaded && !target;
- const selectedAgent = useMemo(() => agents.find((a) => a.id === selectedAgentId) ?? null, [agents, selectedAgentId]);
+
+ const applyAgentRoute = useCallback(
+ (patch: AgentRouteSelection) => setAgentRoute((prev) => ({ ...prev, ...patch })),
+ [],
+ );
const send = useCallback(
async (text: string): Promise<{ sessionId: string; initialMessage: string } | null> => {
@@ -101,19 +119,16 @@ export function useNewSession({ active = true, loadErrorText, createFailedText }
if (!trimmed || sending || !loaded || !target) return null;
setSending(true);
setError(null);
- // null selectedAgent → omit agent fields so the server uses its default.
- const overrides = selectedAgent
- ? {
- agent_id: selectedAgent.id,
- agent_name: selectedAgent.name,
- agent_backend: selectedAgent.backend,
- // Match agent_variant to the backend so the session can resume its
- // native thread (mirrors the chat AgentRoutePicker).
- agent_variant: selectedAgent.backend,
- model: selectedAgent.model ?? undefined,
- reasoning_effort: selectedAgent.reasoning_effort ?? undefined,
- }
- : undefined;
+ // Empty agentRoute → no agent fields → the server uses its default backend.
+ // Drop null/undefined (the picker stores null to clear) so the create
+ // payload only carries the fields the user actually set.
+ const overrides: Partial<WorkbenchSessionCreate> = {};
+ if (agentRoute.agent_backend) overrides.agent_backend = agentRoute.agent_backend;
+ if (agentRoute.agent_name) overrides.agent_name = agentRoute.agent_name;
+ if (agentRoute.agent_id) overrides.agent_id = agentRoute.agent_id;
+ if (agentRoute.agent_variant) overrides.agent_variant = agentRoute.agent_variant;
+ if (agentRoute.model) overrides.model = agentRoute.model;
+ if (agentRoute.reasoning_effort) overrides.reasoning_effort = agentRoute.reasoning_effort;
const session = await createSessionForProject(target.id, overrides);
setSending(false);
if (!session) {
@@ -122,7 +137,7 @@ export function useNewSession({ active = true, loadErrorText, createFailedText }
}
return { sessionId: session.id, initialMessage: trimmed };
},
- [sending, loaded, target, selectedAgent, createSessionForProject, createFailedText],
+ [sending, loaded, target, agentRoute, createSessionForProject, createFailedText],
);
const upsertSelectProject = useCallback(
@@ -148,8 +163,8 @@ export function useNewSession({ active = true, loadErrorText, createFailedText }
needsProject,
agents,
defaultAgentName,
- selectedAgent,
- setSelectedAgent: setSelectedAgentId,
+ agentRoute,
+ setAgentRoute: applyAgentRoute,
send,
upsertSelectProject,
};
diff --git a/ui/src/lib/useViewportHeightVar.ts b/ui/src/lib/useViewportHeightVar.ts
new file mode 100644
index 000000000..3c4677cd0
--- /dev/null
+++ b/ui/src/lib/useViewportHeightVar.ts
@@ -0,0 +1,35 @@
+import { useEffect } from 'react';
+
+// iOS Safari keeps the layout viewport (and 100dvh) at full height when the
+// virtual keyboard opens — only the VISUAL viewport shrinks — so a bottom-pinned
+// chat composer ends up stranded with a large gap above the keyboard (dvh alone
+// doesn't fix it on iOS, and interactive-widget=resizes-content isn't supported
+// there). Mirror window.visualViewport.height into the --app-vvh CSS var
+// (rAF-throttled) so full-height surfaces can size to the actually-visible area
+// and keep the input flush above the keyboard. Refs:
+// https://www.bram.us/2021/09/13/prevent-items-from-being-hidden-underneath-the-virtual-keyboard-by-means-of-the-virtualkeyboard-api/
+// https://dev.to/franciscomoretti/fix-mobile-keyboard-overlap-with-visualviewport-3a4a
+export function useViewportHeightVar(): void {
+ useEffect(() => {
+ const vv = window.visualViewport;
+ // No visualViewport (older browsers / SSR) → CSS keeps its 100dvh default.
+ if (!vv) return;
+ let raf = 0;
+ const apply = () => {
+ raf = 0;
+ document.documentElement.style.setProperty('--app-vvh', `${Math.round(vv.height)}px`);
+ };
+ const schedule = () => {
+ if (raf) return;
+ raf = requestAnimationFrame(apply);
+ };
+ apply();
+ vv.addEventListener('resize', schedule);
+ vv.addEventListener('scroll', schedule);
+ return () => {
+ if (raf) cancelAnimationFrame(raf);
+ vv.removeEventListener('resize', schedule);
+ vv.removeEventListener('scroll', schedule);
+ };
+ }, []);
+}