Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 61 additions & 15 deletions apps/web/src/components/banner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,34 +44,32 @@ const tones: Record<Notice["tone"], { readonly icon: IconComponent; readonly tex
},
};

/** The tone's tint and border, for a notice set on a surface of its own. */
export const noticeSurface = (tone: Notice["tone"]) => 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 (
<div
role="alert"
className={`flex items-center gap-2.5 border ${detached ? "rounded-xl" : "mx-3 rounded-t-xl border-b-0 transition-[transform,opacity] duration-180 ease-out starting:translate-y-1 starting:opacity-0"} ${surface} px-3 py-2 text-xs leading-snug`}
className={`flex items-start gap-2 rounded-xl border ${surface} px-3 py-2 transition-[transform,opacity] duration-180 ease-out starting:translate-y-1 starting:opacity-0`}
>
<Icon className={`size-4 shrink-0 ${text}`} strokeWidth={2} aria-hidden />
{/* Centered on the title's line, so a two-line description does not pull it down. */}
<Icon className={`mt-0.5 size-3.5 shrink-0 ${text}`} strokeWidth={2} aria-hidden />
<div className="min-w-0 flex-1">
<p className="font-medium text-ink">{title}</p>
<p className="text-ui font-medium text-ink">{title}</p>
{description !== undefined && (
<p title={description} className="mt-0.5 line-clamp-2 text-ink-muted">
<p title={description} className="mt-0.5 line-clamp-2 text-xs leading-snug text-ink-muted">
{description}
</p>
)}
Expand All @@ -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.icon className="size-3" strokeWidth={2} aria-hidden />}
{action.label}
Expand All @@ -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 (
<div
role="alert"
className="group flex max-w-full items-start gap-2 text-ui transition-[opacity,translate] duration-180 ease-out starting:translate-y-1 starting:opacity-0"
>
<Icon className={`mt-0.5 size-3.5 shrink-0 ${text}`} strokeWidth={2} aria-hidden />
<p className="min-w-0 text-ink-muted">
<span className="font-medium text-ink">{title}</span>
{description !== undefined && <span> · {description}</span>}
</p>
{actions.map((action) => (
<button
key={action.label}
type="button"
disabled={action.disabled}
onClick={action.onClick}
className="inline-flex shrink-0 items-center gap-1 rounded-md px-1 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.icon className="size-3" strokeWidth={2} aria-hidden />}
{action.label}
</button>
))}
{onDismiss !== undefined && (
<button
type="button"
aria-label="Dismiss"
onClick={onDismiss}
className="grid size-5 shrink-0 place-items-center rounded-md text-ink-muted transition-[transform,background-color,color,opacity] duration-150 ease-out hover:bg-ink/10 hover:text-ink focus-visible:opacity-100 active:scale-95 pointer-fine:opacity-0 pointer-fine:group-hover:opacity-100"
>
<X className="size-3" strokeWidth={2} aria-hidden />
</button>
)}
</div>
);
}

/**
* 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.
Expand All @@ -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"
>
<ComposerNotice {...shown} detached />
<NoticeCard {...shown} />
</div>
);
}
24 changes: 14 additions & 10 deletions apps/web/src/components/model.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ModelProvider & { readonly available: boolean }> =
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,
},
];
Expand Down Expand Up @@ -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<HTMLDivElement>(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 (
Expand Down
18 changes: 12 additions & 6 deletions apps/web/src/widgets/session/composer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<ReadonlySet<string>>(() => 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;
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -184,7 +190,7 @@ export const SessionComposer = memo(function SessionComposer({
)}
<ComposerSubmit
label={running ? "Steer" : "Reply"}
disabled={empty || pending}
disabled={empty || sending.has(text.trim())}
title={running ? "Steer now; Mod+Enter queues a follow-up" : "Reply (Enter)"}
/>
</>
Expand Down
Loading