diff --git a/apps/web/src/components/banner.tsx b/apps/web/src/components/banner.tsx index 50a820cf..f5dffd27 100644 --- a/apps/web/src/components/banner.tsx +++ b/apps/web/src/components/banner.tsx @@ -44,34 +44,32 @@ const tones: Record tones[tone].surface; + /** - * A notice tucked behind the composer's top edge, as its tray is tucked under the bottom one: subtle - * and attached to what it is about. Dismissible when `onDismiss` is given; a notice about a state + * A notice as a card of its own. Dismissible when `onDismiss` is given; a notice about a state * clears itself instead. The description is clamped to two lines, whole on hover. */ -export function ComposerNotice({ +function NoticeCard({ title, description, tone, actions = [], onDismiss, - detached = false, -}: Notice & { - readonly onDismiss?: () => void; - /** A card of its own rather than tucked behind the composer's top edge. */ - readonly detached?: boolean; -}) { +}: Notice & { readonly onDismiss?: () => void }) { const { icon: Icon, text, surface } = tones[tone]; return (
- + {/* Centered on the title's line, so a two-line description does not pull it down. */} +
-

{title}

+

{title}

{description !== undefined && ( -

+

{description}

)} @@ -82,7 +80,7 @@ export function ComposerNotice({ type="button" disabled={action.disabled} onClick={action.onClick} - className="inline-flex shrink-0 items-center gap-1.5 rounded-md border border-edge px-2 py-0.5 font-medium text-ink-muted transition-[transform,background-color,color] duration-150 ease-out outline-none hover:bg-ink/5 hover:text-ink focus-visible:bg-ink/5 enabled:active:scale-[0.97] disabled:pointer-events-none disabled:opacity-60" + className="inline-flex shrink-0 items-center gap-1.5 self-center rounded-md border border-edge px-2 py-0.5 text-xs font-medium text-ink-muted transition-[transform,background-color,color] duration-150 ease-out outline-none hover:bg-ink/5 hover:text-ink focus-visible:bg-ink/5 enabled:active:scale-[0.97] disabled:pointer-events-none disabled:opacity-60" > {action.icon !== undefined && } {action.label} @@ -102,6 +100,54 @@ export function ComposerNotice({ ); } +/** + * A notice as a line of the conversation, where a reply would be: the tone's icon, the title, and + * the fact after it, with no box around them. Its dismiss and actions show on hover. + */ +export function NoticeLine({ + title, + description, + tone, + actions = [], + onDismiss, +}: Notice & { readonly onDismiss?: () => void }) { + const { icon: Icon, text } = tones[tone]; + return ( +
+ +

+ {title} + {description !== undefined && · {description}} +

+ {actions.map((action) => ( + + ))} + {onDismiss !== undefined && ( + + )} +
+ ); +} + /** * A notice detached below the composer and out of its flow, so it comes and goes without moving * anything. It eases in, and fades out quicker on the last notice it showed. @@ -115,7 +161,7 @@ export function NoticeSlot({ notice }: { readonly notice: Notice | undefined }) inert={notice === undefined} className="absolute inset-x-0 top-full z-10 pt-2 transition-[opacity,translate] duration-200 ease-out data-[shown=false]:-translate-y-1 data-[shown=false]:opacity-0 data-[shown=false]:duration-150 data-[shown=false]:ease-out motion-reduce:transition-none" > - +
); } diff --git a/apps/web/src/components/model.tsx b/apps/web/src/components/model.tsx index 8bc2b3bf..b1df5224 100644 --- a/apps/web/src/components/model.tsx +++ b/apps/web/src/components/model.tsx @@ -101,12 +101,14 @@ export function useModelName(hostDir: string | undefined, value: ModelRef | unde if (list !== undefined) { const found = lookup(list.providers, current); if (found !== undefined) return found.model.name; + const fallback = list.default; if ( - current.provider === list.default.provider && - current.id === list.default.id && - list.default.name !== undefined + fallback !== undefined && + current.provider === fallback.provider && + current.id === fallback.id && + fallback.name !== undefined ) { - return list.default.name; + return fallback.name; } } return current.id; @@ -145,15 +147,16 @@ function Models({ hostDir, value, onChange }: ModelPickerProps) { // in view, unavailable, so the model a session gets by default never silently drops out of sight. const usable = list?.providers.map((provider) => ({ ...provider, available: true })) ?? []; // With nothing to call, there is no model to keep in view either. + const fallback = list?.default; const providers: ReadonlyArray = - list === undefined || usable.length === 0 || lookup(usable, list.default) !== undefined + fallback === undefined || usable.length === 0 || lookup(usable, fallback) !== undefined ? usable : [ - ...usable.filter((provider) => provider.id !== list.default.provider), + ...usable.filter((provider) => provider.id !== fallback.provider), { - id: list.default.provider, - name: list.default.providerName ?? list.default.provider, - models: [{ id: list.default.id, name: list.default.name ?? list.default.id, thinkingLevels: [] }], + id: fallback.provider, + name: fallback.providerName ?? fallback.provider, + models: [{ id: fallback.id, name: fallback.name ?? fallback.id, thinkingLevels: [] }], available: false, }, ]; @@ -373,7 +376,8 @@ function Thinking({ hostDir, model, value, onChange }: ThinkingPickerProps) { const levels = list === undefined || current === undefined ? [] : (lookup(list.providers, current)?.model.thinkingLevels ?? []); const picked = useRef(null); - const shown = list === undefined ? undefined : clamp(value ?? list.default.thinkingLevel, levels); + const level = value ?? list?.default?.thinkingLevel; + const shown = level === undefined ? undefined : clamp(level, levels); const choosable = shown !== undefined && levels.some((level) => level !== "off"); return ( diff --git a/apps/web/src/widgets/session/composer.tsx b/apps/web/src/widgets/session/composer.tsx index 58550dad..e0a70ce5 100644 --- a/apps/web/src/widgets/session/composer.tsx +++ b/apps/web/src/widgets/session/composer.tsx @@ -62,7 +62,8 @@ export const SessionComposer = memo(function SessionComposer({ const kv = useKv(); const [text, setText] = useState(""); const [loaded, setLoaded] = useState(false); - const [pending, setPending] = useState(false); + // Prompts on their way: the same text twice is a double press, a different one is a new prompt. + const [sending, setSending] = useState>(() => new Set()); // Picks not yet reflected in the session's info; the info wins once it carries them. const [picked, setPicked] = useState<{ model?: ModelRef; thinkingLevel?: ThinkingLevel }>({}); const model = picked.model ?? info.model; @@ -113,7 +114,7 @@ export const SessionComposer = memo(function SessionComposer({ const send = async (submit: Submit) => { const prompt = text.trim(); - if (prompt === "" || pending) return; + if (prompt === "" || sending.has(prompt)) return; const delivery = deliveryFor(running, submit); const messageId = crypto.randomUUID(); // An idle send shows in the conversation at once, so it moves out of the composer with it; a @@ -123,15 +124,20 @@ export const SessionComposer = memo(function SessionComposer({ onSending({ id: messageId, text: prompt, createdAt: Date.now() }); setText(""); } - setPending(true); + setSending((current) => new Set(current).add(prompt)); inFlight.prompt(key, messageId); const sent = await ask( topics.prompt, encodePrompt({ ...thread, messageId, text: prompt, ...(delivery === undefined ? {} : { delivery }) }), ); - setPending(false); + setSending((current) => { + const next = new Set(current); + next.delete(prompt); + return next; + }); if (sent) { - if (!immediate) setText(""); + // Only what was sent leaves: anything typed while it was on its way stays. + if (!immediate) setText((current) => (current.trim() === prompt ? "" : current)); return; } // Refused: never pending again. @@ -184,7 +190,7 @@ export const SessionComposer = memo(function SessionComposer({ )} diff --git a/apps/web/src/widgets/session/queue.tsx b/apps/web/src/widgets/session/queue.tsx index 078171f9..2be21bbe 100644 --- a/apps/web/src/widgets/session/queue.tsx +++ b/apps/web/src/widgets/session/queue.tsx @@ -18,11 +18,24 @@ const decodeReply = Schema.decodeUnknownOption(Json.Reply); const decodeCancelled = Schema.decodeUnknownOption(Json.Cancelled); const unreachable = "The CodeWork server is not reachable."; +/** The shape of a card stacked on the composer's top edge, a queued prompt or a notice; each brings its own colors. */ +export const trayCard = + "border border-b-0 px-3 text-ui text-ink shadow-[0_-2px_6px_-3px_rgb(0_0_0/0.12)] backdrop-blur-xl"; + +/** A card's height, how much of each card behind the front one shows, and how many show at most. */ +const ROW = 32; +const PEEK = 7; +const PEEKS = 3; +/** How much narrower each card further back is, per side. */ +const INSET = 8; +/** Without hover the stack cannot open on demand, so it stays open. */ +const coarse = typeof matchMedia === "function" && matchMedia("(pointer: coarse)").matches; + /** * Prompts sent while the agent works and not yet taken in, tucked behind the composer's top edge * like a notice: steers join at the agent's next step, follow-ups after its turn. Each leaves once - * it is in the conversation, or once removed. Past four, a count heads the list and it scrolls, - * cut mid-row and faded at its edges so more reads as more. + * it is in the conversation, or once removed. Several stack as cards, the newest in front, all behind + * a notice when there is one; hovering or focusing the stack opens it. * * A row moves to the other lane (or, while idle, sends now), is rewritten in place, goes back to the * composer, or is removed. Every action is a request on the session backend; the row changes when @@ -33,6 +46,7 @@ export const Queue = memo(function Queue({ queued, running, parked, + behind, onError, onRestore, }: { @@ -41,11 +55,15 @@ export const Queue = memo(function Queue({ readonly running: boolean; /** Left waiting by a stop or a failure: they run with the next message, not by themselves. */ readonly parked: boolean; + /** A notice holds the front: every prompt sits behind it, and the stack opens above it. */ + readonly behind: boolean; readonly onError: (message: string | undefined) => void; /** Puts a withdrawn prompt's text back in the composer. */ readonly onRestore: (text: string) => void; }) { const bus = useBus(); + const [hovered, setHovered] = useState(false); + const [focused, setFocused] = useState(false); // Rows with a request out; their actions wait for its answer. const [busy, setBusy] = useState>(() => new Set()); const [editing, setEditing] = useState<{ readonly id: string; readonly text: string }>(); @@ -100,90 +118,146 @@ export const Queue = memo(function Queue({ void change(prompt, { text: trimmed }); }; - const many = queued.length > 4; + // Collapsed, the next prompts peek above the front one as a stack; open, every card shows. Open + // overflows upward from a fixed footprint, so it never moves the conversation underneath. + const spread = hovered || focused || editing !== undefined || coarse; + // Behind a notice the newest prompt is one step back too, so only edges show. + const lift = behind ? 1 : 0; + const peeks = Math.min(queued.length - 1 + lift, PEEKS); return ( -
- {parked ? ( -

- {queued.length > 3 ? `${queued.length} parked` : "Parked"} - · Runs with your next message -

- ) : ( - queued.length > 3 &&

{queued.length} queued

- )} +
setHovered(true)} + onPointerLeave={() => setHovered(false)} + onFocus={() => setFocused(true)} + onBlur={(event) => { + if (!event.currentTarget.contains(event.relatedTarget)) setFocused(false); + }} + >