Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b00c1115ff | ||
|
|
4ad961da2f |
No files matched your search
@@ -1416,13 +1416,15 @@ async function waitForButtonByText(text: string): Promise<HTMLButtonElement> {
|
||||
return waitForElement(() => findButtonByText(text), `Unable to find "${text}" button.`);
|
||||
}
|
||||
|
||||
function findButtonContainingText(text: string): HTMLButtonElement | null {
|
||||
return (Array.from(document.querySelectorAll("button")).find((button) =>
|
||||
button.textContent?.includes(text),
|
||||
) ?? null) as HTMLButtonElement | null;
|
||||
function findButtonContainingText(text: string): HTMLElement | null {
|
||||
return (
|
||||
Array.from(document.querySelectorAll<HTMLElement>('button, [role="button"]')).find((button) =>
|
||||
button.textContent?.includes(text),
|
||||
) ?? null
|
||||
);
|
||||
}
|
||||
|
||||
async function waitForButtonContainingText(text: string): Promise<HTMLButtonElement> {
|
||||
async function waitForButtonContainingText(text: string): Promise<HTMLElement> {
|
||||
return waitForElement(
|
||||
() => findButtonContainingText(text),
|
||||
`Unable to find button containing "${text}".`,
|
||||
@@ -3219,6 +3221,89 @@ describe("ChatView timeline estimator parity (full app)", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("focuses the composer and inserts printable text typed from the page background", async () => {
|
||||
const mounted = await mountChatView({
|
||||
viewport: DEFAULT_VIEWPORT,
|
||||
snapshot: createSnapshotForTargetUser({
|
||||
targetMessageId: "msg-user-target-type-to-focus" as MessageId,
|
||||
targetText: "type-to-focus target",
|
||||
}),
|
||||
});
|
||||
|
||||
const backgroundTarget = document.createElement("div");
|
||||
backgroundTarget.tabIndex = -1;
|
||||
document.body.append(backgroundTarget);
|
||||
|
||||
try {
|
||||
const composerEditor = await waitForComposerEditor();
|
||||
backgroundTarget.focus();
|
||||
expect(document.activeElement).not.toBe(composerEditor);
|
||||
|
||||
const event = new KeyboardEvent("keydown", {
|
||||
key: "h",
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
});
|
||||
backgroundTarget.dispatchEvent(event);
|
||||
|
||||
await waitForComposerText("h");
|
||||
expect(event.defaultPrevented).toBe(true);
|
||||
expect(document.activeElement).toBe(composerEditor);
|
||||
|
||||
window.dispatchEvent(
|
||||
new KeyboardEvent("keydown", {
|
||||
key: "i",
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
}),
|
||||
);
|
||||
|
||||
await waitForComposerText("hi");
|
||||
} finally {
|
||||
backgroundTarget.remove();
|
||||
await mounted.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
it("does not steal printable keys from editable targets or shortcut modifiers", async () => {
|
||||
const mounted = await mountChatView({
|
||||
viewport: DEFAULT_VIEWPORT,
|
||||
snapshot: createSnapshotForTargetUser({
|
||||
targetMessageId: "msg-user-target-type-to-focus-guards" as MessageId,
|
||||
targetText: "type-to-focus guards target",
|
||||
}),
|
||||
});
|
||||
const input = document.createElement("input");
|
||||
document.body.append(input);
|
||||
|
||||
try {
|
||||
input.focus();
|
||||
input.dispatchEvent(
|
||||
new KeyboardEvent("keydown", {
|
||||
key: "x",
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
}),
|
||||
);
|
||||
await waitForLayout();
|
||||
expect(useComposerDraftStore.getState().draftsByThreadKey[THREAD_KEY]?.prompt ?? "").toBe("");
|
||||
|
||||
window.dispatchEvent(
|
||||
new KeyboardEvent("keydown", {
|
||||
key: "k",
|
||||
metaKey: true,
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
}),
|
||||
);
|
||||
await waitForLayout();
|
||||
expect(useComposerDraftStore.getState().draftsByThreadKey[THREAD_KEY]?.prompt ?? "").toBe("");
|
||||
} finally {
|
||||
input.remove();
|
||||
await mounted.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
it("uses the active draft route session when changing the base branch", async () => {
|
||||
const staleDraftId = draftIdFromPath("/draft/draft-stale-branch-session");
|
||||
const activeDraftId = draftIdFromPath("/draft/draft-active-branch-session");
|
||||
|
||||
@@ -203,6 +203,35 @@ const EMPTY_PROPOSED_PLANS: Thread["proposedPlans"] = [];
|
||||
const EMPTY_PROVIDERS: ServerProvider[] = [];
|
||||
const EMPTY_PROVIDER_SKILLS: ServerProvider["skills"] = [];
|
||||
const EMPTY_PENDING_USER_INPUT_ANSWERS: Record<string, PendingUserInputDraftAnswer> = {};
|
||||
const TYPE_TO_FOCUS_EDITABLE_SELECTOR = [
|
||||
"input",
|
||||
"textarea",
|
||||
"select",
|
||||
'[contenteditable="true"]',
|
||||
'[contenteditable="plaintext-only"]',
|
||||
'[role="textbox"]',
|
||||
].join(",");
|
||||
const TYPE_TO_FOCUS_INTERACTIVE_SELECTOR = [
|
||||
"button",
|
||||
"a[href]",
|
||||
"summary",
|
||||
'[role="button"]',
|
||||
'[role="checkbox"]',
|
||||
'[role="menuitem"]',
|
||||
'[role="option"]',
|
||||
'[role="radio"]',
|
||||
'[role="switch"]',
|
||||
'[role="tab"]',
|
||||
].join(",");
|
||||
const TYPE_TO_FOCUS_FLOATING_LAYER_SELECTOR = [
|
||||
'[data-slot="dialog"]',
|
||||
'[data-slot="menu-popup"]',
|
||||
'[data-slot="select-popup"]',
|
||||
'[data-slot="popover-popup"]',
|
||||
'[data-slot="combobox-popup"]',
|
||||
'[data-slot="autocomplete-popup"]',
|
||||
].join(",");
|
||||
|
||||
type EnvironmentUnavailableState = {
|
||||
readonly environmentId: EnvironmentId;
|
||||
readonly label: string;
|
||||
@@ -211,6 +240,25 @@ type EnvironmentUnavailableState = {
|
||||
|
||||
type ThreadPlanCatalogEntry = Pick<Thread, "id" | "proposedPlans">;
|
||||
|
||||
function eventTargetElement(target: EventTarget | null): Element | null {
|
||||
if (target instanceof Element) return target;
|
||||
if (target instanceof Node) return target.parentElement;
|
||||
return null;
|
||||
}
|
||||
|
||||
function shouldTypeToFocusComposer(event: KeyboardEvent): boolean {
|
||||
if (event.defaultPrevented || event.isComposing) return false;
|
||||
if (event.metaKey || event.ctrlKey || event.altKey) return false;
|
||||
if (event.key.length !== 1) return false;
|
||||
|
||||
const target = eventTargetElement(event.target);
|
||||
if (target?.closest(TYPE_TO_FOCUS_EDITABLE_SELECTOR)) return false;
|
||||
if (target?.closest(TYPE_TO_FOCUS_INTERACTIVE_SELECTOR)) return false;
|
||||
if (document.querySelector(TYPE_TO_FOCUS_FLOATING_LAYER_SELECTOR)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function useThreadPlanCatalog(threadIds: readonly ThreadId[]): ThreadPlanCatalogEntry[] {
|
||||
return useStore(
|
||||
useMemo(() => {
|
||||
@@ -2702,6 +2750,18 @@ export default function ChatView(props: ChatViewProps) {
|
||||
modelPickerOpen: composerRef.current?.isModelPickerOpen() ?? false,
|
||||
};
|
||||
|
||||
if (
|
||||
!shortcutContext.terminalFocus &&
|
||||
!shortcutContext.modelPickerOpen &&
|
||||
shouldTypeToFocusComposer(event)
|
||||
) {
|
||||
if (composerRef.current?.insertTextAtEnd(event.key)) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const command = resolveShortcutCommand(event, keybindings, {
|
||||
context: shortcutContext,
|
||||
});
|
||||
|
||||
@@ -86,6 +86,7 @@ import {
|
||||
BotIcon,
|
||||
CircleAlertIcon,
|
||||
ListTodoIcon,
|
||||
PencilRulerIcon,
|
||||
type LucideIcon,
|
||||
LockIcon,
|
||||
LockOpenIcon,
|
||||
@@ -93,7 +94,7 @@ import {
|
||||
XIcon,
|
||||
} from "lucide-react";
|
||||
import { proposedPlanTitle } from "../../proposedPlan";
|
||||
import { getProviderInteractionModeToggle } from "../../providerModels";
|
||||
import { getProviderDisplayName, getProviderInteractionModeToggle } from "../../providerModels";
|
||||
import {
|
||||
deriveProviderInstanceEntries,
|
||||
resolveProviderDriverKindForInstanceSelection,
|
||||
@@ -105,7 +106,10 @@ import type { UnifiedSettings } from "@t3tools/contracts/settings";
|
||||
import type { SessionPhase, Thread } from "../../types";
|
||||
import type { PendingUserInputDraftAnswer } from "../../pendingUserInput";
|
||||
import type { PendingApproval, PendingUserInput } from "../../session-logic";
|
||||
import { deriveLatestContextWindowSnapshot } from "../../lib/contextWindow";
|
||||
import {
|
||||
deriveLatestContextWindowSnapshot,
|
||||
formatProviderDisplayName,
|
||||
} from "../../lib/contextWindow";
|
||||
import { formatProviderSkillDisplayName } from "../../providerSkillPresentation";
|
||||
import { searchProviderSkills } from "../../providerSkillSearch";
|
||||
import { useMediaQuery } from "../../hooks/useMediaQuery";
|
||||
@@ -195,37 +199,45 @@ const ComposerFooterModeControls = memo(function ComposerFooterModeControls(prop
|
||||
? `Hide ${props.planSidebarLabel.toLowerCase()} sidebar`
|
||||
: `Show ${props.planSidebarLabel.toLowerCase()} sidebar`;
|
||||
|
||||
const interactionModeToggle = props.showInteractionModeToggle ? (
|
||||
<>
|
||||
<Separator orientation="vertical" className="mx-0.5 hidden h-4 sm:block" />
|
||||
<Tooltip>
|
||||
<TooltipTrigger
|
||||
render={
|
||||
<Button
|
||||
variant="ghost"
|
||||
className={cn(
|
||||
"shrink-0 whitespace-nowrap px-2 sm:px-3",
|
||||
props.interactionMode === "plan"
|
||||
? "bg-blue-500/10 text-blue-400 hover:bg-blue-500/15 hover:text-blue-300"
|
||||
: "text-muted-foreground/70 hover:text-foreground/80",
|
||||
)}
|
||||
size="sm"
|
||||
type="button"
|
||||
onClick={props.onToggleInteractionMode}
|
||||
aria-label={interactionModeTooltip}
|
||||
/>
|
||||
}
|
||||
>
|
||||
{props.interactionMode === "plan" ? (
|
||||
<PencilRulerIcon className="text-current opacity-100" />
|
||||
) : (
|
||||
<BotIcon />
|
||||
)}
|
||||
<span className="sr-only sm:not-sr-only">
|
||||
{props.interactionMode === "plan" ? "Plan" : "Build"}
|
||||
</span>
|
||||
</TooltipTrigger>
|
||||
<TooltipPopup side="top">{interactionModeTooltip}</TooltipPopup>
|
||||
</Tooltip>
|
||||
</>
|
||||
) : null;
|
||||
|
||||
return (
|
||||
<>
|
||||
<Separator orientation="vertical" className="mx-0.5 hidden h-4 sm:block" />
|
||||
|
||||
{props.showInteractionModeToggle ? (
|
||||
<>
|
||||
<Tooltip>
|
||||
<TooltipTrigger
|
||||
render={
|
||||
<Button
|
||||
variant="ghost"
|
||||
className="shrink-0 whitespace-nowrap px-2 text-muted-foreground/70 hover:text-foreground/80 sm:px-3"
|
||||
size="sm"
|
||||
type="button"
|
||||
onClick={props.onToggleInteractionMode}
|
||||
aria-label={interactionModeTooltip}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<BotIcon />
|
||||
<span className="sr-only sm:not-sr-only">
|
||||
{props.interactionMode === "plan" ? "Plan" : "Build"}
|
||||
</span>
|
||||
</TooltipTrigger>
|
||||
<TooltipPopup side="top">{interactionModeTooltip}</TooltipPopup>
|
||||
</Tooltip>
|
||||
|
||||
<Separator orientation="vertical" className="mx-0.5 hidden h-4 sm:block" />
|
||||
</>
|
||||
) : null}
|
||||
|
||||
<Tooltip>
|
||||
<Select
|
||||
value={props.runtimeMode}
|
||||
@@ -267,6 +279,8 @@ const ComposerFooterModeControls = memo(function ComposerFooterModeControls(prop
|
||||
<TooltipPopup side="top">{runtimeModeOption.description}</TooltipPopup>
|
||||
</Tooltip>
|
||||
|
||||
{interactionModeToggle}
|
||||
|
||||
{props.showPlanToggle ? (
|
||||
<>
|
||||
<Separator orientation="vertical" className="mx-0.5 hidden h-4 sm:block" />
|
||||
@@ -278,7 +292,7 @@ const ComposerFooterModeControls = memo(function ComposerFooterModeControls(prop
|
||||
className={cn(
|
||||
"shrink-0 whitespace-nowrap px-2 sm:px-3",
|
||||
props.planSidebarOpen
|
||||
? "text-blue-400 hover:text-blue-300"
|
||||
? "bg-blue-500/10 text-blue-400 hover:bg-blue-500/15 hover:text-blue-300"
|
||||
: "text-muted-foreground/70 hover:text-foreground/80",
|
||||
)}
|
||||
size="sm"
|
||||
@@ -288,7 +302,9 @@ const ComposerFooterModeControls = memo(function ComposerFooterModeControls(prop
|
||||
/>
|
||||
}
|
||||
>
|
||||
<ListTodoIcon />
|
||||
<ListTodoIcon
|
||||
className={props.planSidebarOpen ? "text-current opacity-100" : undefined}
|
||||
/>
|
||||
<span className="sr-only sm:not-sr-only">{props.planSidebarLabel}</span>
|
||||
</TooltipTrigger>
|
||||
<TooltipPopup side="top">{planSidebarTooltip}</TooltipPopup>
|
||||
@@ -302,6 +318,7 @@ const ComposerFooterModeControls = memo(function ComposerFooterModeControls(prop
|
||||
const ComposerFooterPrimaryActions = memo(function ComposerFooterPrimaryActions(props: {
|
||||
compact: boolean;
|
||||
activeContextWindow: ReturnType<typeof deriveLatestContextWindowSnapshot>;
|
||||
activeThreadProviderDisplayName: string | null;
|
||||
isPreparingWorktree: boolean;
|
||||
pendingAction: {
|
||||
questionIndex: number;
|
||||
@@ -324,7 +341,12 @@ const ComposerFooterPrimaryActions = memo(function ComposerFooterPrimaryActions(
|
||||
}) {
|
||||
return (
|
||||
<>
|
||||
{props.activeContextWindow ? <ContextWindowMeter usage={props.activeContextWindow} /> : null}
|
||||
{props.activeContextWindow ? (
|
||||
<ContextWindowMeter
|
||||
usage={props.activeContextWindow}
|
||||
providerDisplayName={props.activeThreadProviderDisplayName}
|
||||
/>
|
||||
) : null}
|
||||
{props.isPreparingWorktree ? (
|
||||
<span className="text-muted-foreground/70 text-xs">Preparing worktree...</span>
|
||||
) : null}
|
||||
@@ -355,6 +377,7 @@ const ComposerFooterPrimaryActions = memo(function ComposerFooterPrimaryActions(
|
||||
export interface ChatComposerHandle {
|
||||
focusAtEnd: () => void;
|
||||
focusAt: (cursor: number) => void;
|
||||
insertTextAtEnd: (text: string) => boolean;
|
||||
openModelPicker: () => void;
|
||||
toggleModelPicker: () => void;
|
||||
isModelPickerOpen: () => boolean;
|
||||
@@ -799,6 +822,16 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
() => deriveLatestContextWindowSnapshot(activeThreadActivities ?? []),
|
||||
[activeThreadActivities],
|
||||
);
|
||||
const activeThreadProviderDisplayName = useMemo(() => {
|
||||
if (!activeThreadModelSelection) return null;
|
||||
const entry = providerStatuses.find(
|
||||
(p) => p.instanceId === activeThreadModelSelection.instanceId,
|
||||
);
|
||||
if (entry) {
|
||||
return getProviderDisplayName(providerStatuses, entry.driver);
|
||||
}
|
||||
return formatProviderDisplayName(activeThreadModelSelection.instanceId);
|
||||
}, [providerStatuses, activeThreadModelSelection]);
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Composer-local state
|
||||
@@ -1856,6 +1889,18 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
focusAt: (cursor: number) => {
|
||||
composerEditorRef.current?.focusAt(cursor);
|
||||
},
|
||||
insertTextAtEnd: (text: string) => {
|
||||
if (
|
||||
text.length === 0 ||
|
||||
isConnecting ||
|
||||
isComposerApprovalState ||
|
||||
(environmentUnavailable !== null && activePendingProgress === null)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
const rangeEnd = promptRef.current.length;
|
||||
return applyPromptReplacement(rangeEnd, rangeEnd, text);
|
||||
},
|
||||
openModelPicker: () => {
|
||||
setIsComposerModelPickerOpen(true);
|
||||
},
|
||||
@@ -1940,6 +1985,11 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
promptRef,
|
||||
composerImagesRef,
|
||||
composerTerminalContextsRef,
|
||||
isConnecting,
|
||||
isComposerApprovalState,
|
||||
environmentUnavailable,
|
||||
activePendingProgress,
|
||||
applyPromptReplacement,
|
||||
isComposerModelPickerOpen,
|
||||
readComposerSnapshot,
|
||||
selectedModel,
|
||||
@@ -2153,7 +2203,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
)}
|
||||
>
|
||||
{composerMenuOpen && !isComposerApprovalState && (
|
||||
<div className="absolute inset-x-0 bottom-full z-20 mb-2 px-1">
|
||||
<div className="absolute inset-x-0 bottom-full z-20 mb-2">
|
||||
<ComposerCommandMenu
|
||||
items={composerMenuItems}
|
||||
resolvedTheme={resolvedTheme}
|
||||
@@ -2325,6 +2375,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
data-chat-composer-footer-compact={isComposerFooterCompact ? "true" : "false"}
|
||||
className={cn(
|
||||
"flex min-w-0 flex-nowrap items-center justify-between gap-2 overflow-visible px-2.5 pb-2.5 sm:px-3 sm:pb-3",
|
||||
pendingUserInputs.length > 0 && "pt-2",
|
||||
isComposerFooterCompact ? "gap-1.5" : "gap-2 sm:gap-0",
|
||||
showMobilePendingAnswerActions && "hidden sm:flex",
|
||||
)}
|
||||
@@ -2400,6 +2451,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
<ComposerFooterPrimaryActions
|
||||
compact={isComposerPrimaryActionsCompact}
|
||||
activeContextWindow={activeContextWindow}
|
||||
activeThreadProviderDisplayName={activeThreadProviderDisplayName}
|
||||
pendingAction={pendingPrimaryAction}
|
||||
isRunning={phase === "running"}
|
||||
showPlanFollowUpPrompt={pendingUserInputs.length === 0 && showPlanFollowUpPrompt}
|
||||
|
||||
@@ -141,34 +141,35 @@ export const ComposerCommandMenu = memo(function ComposerCommandMenu(props: {
|
||||
>
|
||||
<div
|
||||
ref={listRef}
|
||||
className="relative overflow-hidden rounded-xl border border-border/80 bg-popover/96 shadow-lg/8 backdrop-blur-xs"
|
||||
className="relative w-full overflow-hidden rounded-[20px] border border-border/80 bg-popover/96 shadow-lg/8 backdrop-blur-xs"
|
||||
>
|
||||
<CommandList className="max-h-72">
|
||||
{groups.map((group, groupIndex) => (
|
||||
<div key={group.id}>
|
||||
{groupIndex > 0 ? <CommandSeparator className="my-0.5" /> : null}
|
||||
<CommandGroup>
|
||||
{group.label ? (
|
||||
<CommandGroupLabel className="px-3 pt-2 pb-1 text-[10px] font-semibold uppercase tracking-[0.08em] text-muted-foreground/55">
|
||||
{group.label}
|
||||
</CommandGroupLabel>
|
||||
) : null}
|
||||
{group.items.map((item) => (
|
||||
<ComposerCommandMenuItem
|
||||
key={item.id}
|
||||
item={item}
|
||||
resolvedTheme={props.resolvedTheme}
|
||||
isActive={props.activeItemId === item.id}
|
||||
onHighlight={props.onHighlightedItemChange}
|
||||
onSelect={props.onSelect}
|
||||
/>
|
||||
))}
|
||||
</CommandGroup>
|
||||
</div>
|
||||
))}
|
||||
</CommandList>
|
||||
{props.items.length === 0 ? (
|
||||
<div className="px-3 py-2">
|
||||
{props.items.length > 0 ? (
|
||||
<CommandList className="max-h-72">
|
||||
{groups.map((group, groupIndex) => (
|
||||
<div key={group.id}>
|
||||
{groupIndex > 0 ? <CommandSeparator className="my-0.5" /> : null}
|
||||
<CommandGroup>
|
||||
{group.label ? (
|
||||
<CommandGroupLabel className="px-3 pt-2 pb-1 text-[10px] font-semibold uppercase tracking-[0.08em] text-muted-foreground/55">
|
||||
{group.label}
|
||||
</CommandGroupLabel>
|
||||
) : null}
|
||||
{group.items.map((item) => (
|
||||
<ComposerCommandMenuItem
|
||||
key={item.id}
|
||||
item={item}
|
||||
resolvedTheme={props.resolvedTheme}
|
||||
isActive={props.activeItemId === item.id}
|
||||
onHighlight={props.onHighlightedItemChange}
|
||||
onSelect={props.onSelect}
|
||||
/>
|
||||
))}
|
||||
</CommandGroup>
|
||||
</div>
|
||||
))}
|
||||
</CommandList>
|
||||
) : (
|
||||
<div className="px-5 py-3.5">
|
||||
{props.triggerKind === "skill" ? (
|
||||
<CommandGroup>
|
||||
<CommandGroupLabel className="px-0 pt-0 pb-1 text-[10px] font-semibold uppercase tracking-[0.08em] text-muted-foreground/55">
|
||||
@@ -192,7 +193,7 @@ export const ComposerCommandMenu = memo(function ComposerCommandMenu(props: {
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
) : null}
|
||||
)}
|
||||
</div>
|
||||
</Command>
|
||||
);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { type ApprovalRequestId } from "@t3tools/contracts";
|
||||
import { memo, useEffect, useEffectEvent, useRef } from "react";
|
||||
import { memo, useEffect, useEffectEvent, useRef, useState } from "react";
|
||||
import { type PendingUserInput } from "../../session-logic";
|
||||
import {
|
||||
derivePendingUserInputProgress,
|
||||
@@ -61,11 +61,36 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
|
||||
const activeQuestion = progress.activeQuestion;
|
||||
const autoAdvanceTimerRef = useRef<number | null>(null);
|
||||
const onAdvanceRef = useRef(onAdvance);
|
||||
const [optimisticSingleSelect, setOptimisticSingleSelect] = useState<{
|
||||
questionId: string;
|
||||
optionLabel: string;
|
||||
} | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
onAdvanceRef.current = onAdvance;
|
||||
}, [onAdvance]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!activeQuestion || activeQuestion.multiSelect || !optimisticSingleSelect) {
|
||||
return;
|
||||
}
|
||||
if (optimisticSingleSelect.questionId !== activeQuestion.id) {
|
||||
setOptimisticSingleSelect(null);
|
||||
return;
|
||||
}
|
||||
if (
|
||||
progress.customAnswer.trim().length === 0 &&
|
||||
progress.selectedOptionLabels.includes(optimisticSingleSelect.optionLabel)
|
||||
) {
|
||||
setOptimisticSingleSelect(null);
|
||||
}
|
||||
}, [
|
||||
activeQuestion,
|
||||
optimisticSingleSelect,
|
||||
progress.customAnswer,
|
||||
progress.selectedOptionLabels,
|
||||
]);
|
||||
|
||||
// Clear auto-advance timer on unmount
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
@@ -76,10 +101,12 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
|
||||
}, []);
|
||||
|
||||
const handleOptionSelection = useEffectEvent((questionId: string, optionLabel: string) => {
|
||||
onToggleOption(questionId, optionLabel);
|
||||
if (activeQuestion?.multiSelect) {
|
||||
onToggleOption(questionId, optionLabel);
|
||||
return;
|
||||
}
|
||||
setOptimisticSingleSelect({ questionId, optionLabel });
|
||||
onToggleOption(questionId, optionLabel);
|
||||
if (autoAdvanceTimerRef.current !== null) {
|
||||
window.clearTimeout(autoAdvanceTimerRef.current);
|
||||
}
|
||||
@@ -123,64 +150,77 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
|
||||
return null;
|
||||
}
|
||||
|
||||
const customAnswerActive = progress.customAnswer.trim().length > 0;
|
||||
|
||||
return (
|
||||
<div className="px-4 py-3 sm:px-5">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="flex items-center gap-2">
|
||||
{prompt.questions.length > 1 ? (
|
||||
<span className="flex h-5 items-center rounded-md bg-muted/60 px-1.5 text-[10px] font-medium tabular-nums text-muted-foreground/60">
|
||||
{questionIndex + 1}/{prompt.questions.length}
|
||||
</span>
|
||||
) : null}
|
||||
<span className="text-[11px] font-semibold tracking-widest text-muted-foreground/50 uppercase">
|
||||
{activeQuestion.header}
|
||||
<div className="mb-2 flex items-center gap-3">
|
||||
<span className="text-[11px] font-semibold tracking-widest text-muted-foreground/55 uppercase">
|
||||
{activeQuestion.header}
|
||||
</span>
|
||||
{prompt.questions.length > 1 ? (
|
||||
<span className="flex h-5 items-center rounded-md bg-muted/60 px-1.5 text-[10px] font-medium tabular-nums text-muted-foreground/60">
|
||||
{questionIndex + 1}/{prompt.questions.length}
|
||||
</span>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
<p className="mt-1.5 text-sm text-foreground/90">{activeQuestion.question}</p>
|
||||
<p className="text-sm text-foreground/90">{activeQuestion.question}</p>
|
||||
{activeQuestion.multiSelect ? (
|
||||
<p className="mt-1 text-xs text-muted-foreground/65">Select one or more options.</p>
|
||||
) : null}
|
||||
<div className="mt-3 space-y-1">
|
||||
<div className="mt-3 space-y-1.5">
|
||||
{activeQuestion.options.map((option, index) => {
|
||||
const isSelected = progress.selectedOptionLabels.includes(option.label);
|
||||
const isOptimisticallySelected =
|
||||
optimisticSingleSelect?.questionId === activeQuestion.id &&
|
||||
optimisticSingleSelect.optionLabel === option.label;
|
||||
const isSelected =
|
||||
isOptimisticallySelected ||
|
||||
(!customAnswerActive && progress.selectedOptionLabels.includes(option.label));
|
||||
const shortcutKey = index < 9 ? index + 1 : null;
|
||||
return (
|
||||
<button
|
||||
key={`${activeQuestion.id}:${option.label}`}
|
||||
type="button"
|
||||
disabled={isResponding}
|
||||
onClick={() => handleOptionSelection(activeQuestion.id, option.label)}
|
||||
className={cn(
|
||||
"group flex w-full items-center gap-3 rounded-lg border px-3 py-2 text-left transition-all duration-150",
|
||||
isSelected
|
||||
? "border-blue-500/40 bg-blue-500/8 text-foreground"
|
||||
: "border-transparent bg-muted/20 text-foreground/80 hover:bg-muted/40 hover:border-border/40",
|
||||
isResponding && "opacity-50 cursor-not-allowed",
|
||||
)}
|
||||
>
|
||||
{shortcutKey !== null ? (
|
||||
const className = cn(
|
||||
"group flex w-full items-center gap-3 rounded-lg border px-3 py-2 text-left transition-all duration-150",
|
||||
isSelected
|
||||
? "border-blue-500/30 bg-blue-500/8 text-foreground"
|
||||
: "border-transparent bg-muted/22 text-foreground/85 hover:border-border/45 hover:bg-muted/34",
|
||||
isResponding && "opacity-50 cursor-not-allowed",
|
||||
!isResponding && "cursor-pointer",
|
||||
);
|
||||
const content = (
|
||||
<>
|
||||
<div className="min-w-0 flex-1 flex flex-col gap-0.5">
|
||||
<span className="text-sm font-medium">{option.label}</span>
|
||||
{option.description && option.description !== option.label ? (
|
||||
<span className="text-xs text-muted-foreground/50">{option.description}</span>
|
||||
) : null}
|
||||
</div>
|
||||
{isSelected ? (
|
||||
<CheckIcon className="size-3.5 shrink-0 text-blue-400" />
|
||||
) : shortcutKey !== null ? (
|
||||
<kbd
|
||||
className={cn(
|
||||
"flex size-5 shrink-0 items-center justify-center rounded text-[11px] font-medium tabular-nums transition-colors duration-150",
|
||||
isSelected
|
||||
? "bg-blue-500/20 text-blue-400"
|
||||
: "bg-muted/40 text-muted-foreground/50 group-hover:bg-muted/60 group-hover:text-muted-foreground/70",
|
||||
"flex size-5 shrink-0 items-center justify-center rounded border border-border/50 text-[11px] font-medium tabular-nums transition-colors duration-150",
|
||||
"bg-background/35 text-muted-foreground/70 group-hover:border-border/70 group-hover:text-muted-foreground",
|
||||
)}
|
||||
>
|
||||
{shortcutKey}
|
||||
</kbd>
|
||||
) : null}
|
||||
<div className="min-w-0 flex-1">
|
||||
<span className="text-sm font-medium">{option.label}</span>
|
||||
{option.description && option.description !== option.label ? (
|
||||
<span className="ml-2 text-xs text-muted-foreground/50">
|
||||
{option.description}
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
{isSelected ? <CheckIcon className="size-3.5 shrink-0 text-blue-400" /> : null}
|
||||
</button>
|
||||
</>
|
||||
);
|
||||
return (
|
||||
<div
|
||||
key={`${activeQuestion.id}:${option.label}`}
|
||||
role="button"
|
||||
tabIndex={isResponding ? -1 : 0}
|
||||
aria-disabled={isResponding}
|
||||
onClick={() => {
|
||||
if (isResponding) return;
|
||||
handleOptionSelection(activeQuestion.id, option.label);
|
||||
}}
|
||||
className={className}
|
||||
>
|
||||
{content}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
@@ -3,6 +3,7 @@ import { ChevronDownIcon, ChevronLeftIcon } from "lucide-react";
|
||||
import { cn } from "~/lib/utils";
|
||||
import { Button } from "../ui/button";
|
||||
import { Menu, MenuItem, MenuPopup, MenuTrigger } from "../ui/menu";
|
||||
import { Spinner } from "../ui/spinner";
|
||||
|
||||
interface PendingActionState {
|
||||
questionIndex: number;
|
||||
@@ -126,7 +127,7 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
className="flex size-8 cursor-pointer items-center justify-center rounded-full bg-rose-500/90 text-white transition-all duration-150 hover:bg-rose-500 hover:scale-105 sm:h-8 sm:w-8"
|
||||
className="flex size-8 cursor-pointer items-center justify-center rounded-full bg-destructive/90 text-white shadow-xs shadow-destructive/24 inset-shadow-[0_1px_--theme(--color-white/16%)] transition-all duration-150 hover:bg-destructive hover:scale-105 active:inset-shadow-[0_1px_--theme(--color-black/8%)] active:shadow-none sm:h-8 sm:w-8"
|
||||
{...pointerFocusProps}
|
||||
onClick={onInterrupt}
|
||||
aria-label="Stop generation"
|
||||
@@ -195,7 +196,7 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
|
||||
return (
|
||||
<button
|
||||
type="submit"
|
||||
className="flex h-9 w-9 enabled:cursor-pointer items-center justify-center rounded-full bg-primary/90 text-primary-foreground transition-all duration-150 hover:bg-primary hover:scale-105 disabled:pointer-events-none disabled:opacity-30 disabled:hover:scale-100 sm:h-8 sm:w-8"
|
||||
className="flex h-9 w-9 enabled:cursor-pointer items-center justify-center rounded-full bg-primary/90 text-primary-foreground shadow-xs enabled:shadow-primary/24 enabled:inset-shadow-[0_1px_--theme(--color-white/16%)] transition-all duration-150 hover:bg-primary hover:scale-105 active:inset-shadow-[0_1px_--theme(--color-black/8%)] active:shadow-none disabled:pointer-events-none disabled:opacity-30 disabled:shadow-none disabled:hover:scale-100 sm:h-8 sm:w-8"
|
||||
{...pointerFocusProps}
|
||||
disabled={isSendBusy || isConnecting || isEnvironmentUnavailable || !hasSendableContent}
|
||||
aria-label={
|
||||
@@ -211,24 +212,7 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
|
||||
}
|
||||
>
|
||||
{isConnecting || isSendBusy ? (
|
||||
<svg
|
||||
width="14"
|
||||
height="14"
|
||||
viewBox="0 0 14 14"
|
||||
fill="none"
|
||||
className="animate-spin"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<circle
|
||||
cx="7"
|
||||
cy="7"
|
||||
r="5.5"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.5"
|
||||
strokeLinecap="round"
|
||||
strokeDasharray="20 12"
|
||||
/>
|
||||
</svg>
|
||||
<Spinner className="size-3.5" aria-hidden="true" />
|
||||
) : (
|
||||
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" aria-hidden="true">
|
||||
<path
|
||||
|
||||
@@ -12,13 +12,20 @@ function formatPercentage(value: number | null): string | null {
|
||||
return `${Math.round(value)}%`;
|
||||
}
|
||||
|
||||
export function ContextWindowMeter(props: { usage: ContextWindowSnapshot }) {
|
||||
const { usage } = props;
|
||||
export function ContextWindowMeter(props: {
|
||||
usage: ContextWindowSnapshot;
|
||||
providerDisplayName?: string | null;
|
||||
}) {
|
||||
const { usage, providerDisplayName } = props;
|
||||
const usedPercentage = formatPercentage(usage.usedPercentage);
|
||||
const normalizedPercentage = Math.max(0, Math.min(100, usage.usedPercentage ?? 0));
|
||||
const radius = 9.75;
|
||||
const circumference = 2 * Math.PI * radius;
|
||||
const dashOffset = circumference - (normalizedPercentage / 100) * circumference;
|
||||
const totalProcessedTokens = usage.totalProcessedTokens ?? null;
|
||||
const showTotalProcessed = totalProcessedTokens !== null && totalProcessedTokens > 0;
|
||||
const isOverloaded = normalizedPercentage > 90;
|
||||
const usageColor = isOverloaded ? "var(--color-red-500)" : "var(--color-blue-500)";
|
||||
|
||||
return (
|
||||
<Popover>
|
||||
@@ -29,17 +36,21 @@ export function ContextWindowMeter(props: { usage: ContextWindowSnapshot }) {
|
||||
render={
|
||||
<button
|
||||
type="button"
|
||||
className="group inline-flex items-center justify-center rounded-full transition-opacity hover:opacity-85"
|
||||
className={cn(
|
||||
"inline-flex size-6 cursor-pointer items-center justify-center rounded-full border border-transparent text-muted-foreground outline-none transition-colors",
|
||||
"hover:bg-accent data-[pressed]:bg-accent",
|
||||
"focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background",
|
||||
)}
|
||||
aria-label={
|
||||
usage.maxTokens !== null && usedPercentage
|
||||
? `Context window ${usedPercentage} used`
|
||||
: `Context window ${formatContextWindowTokens(usage.usedTokens)} tokens used`
|
||||
}
|
||||
>
|
||||
<span className="relative flex h-6 w-6 items-center justify-center">
|
||||
<span className="relative flex size-4 items-center justify-center">
|
||||
<svg
|
||||
viewBox="0 0 24 24"
|
||||
className="-rotate-90 absolute inset-0 h-full w-full transform-gpu"
|
||||
className="-rotate-90 absolute inset-0 size-full transform-gpu"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<circle
|
||||
@@ -47,7 +58,7 @@ export function ContextWindowMeter(props: { usage: ContextWindowSnapshot }) {
|
||||
cy="12"
|
||||
r={radius}
|
||||
fill="none"
|
||||
stroke="color-mix(in oklab, var(--color-muted) 70%, transparent)"
|
||||
stroke="color-mix(in oklab, var(--color-muted-foreground) 35%, transparent)"
|
||||
strokeWidth="3"
|
||||
/>
|
||||
<circle
|
||||
@@ -55,7 +66,7 @@ export function ContextWindowMeter(props: { usage: ContextWindowSnapshot }) {
|
||||
cy="12"
|
||||
r={radius}
|
||||
fill="none"
|
||||
stroke="var(--color-muted-foreground)"
|
||||
stroke={usageColor}
|
||||
strokeWidth="3"
|
||||
strokeLinecap="round"
|
||||
strokeDasharray={circumference}
|
||||
@@ -63,48 +74,55 @@ export function ContextWindowMeter(props: { usage: ContextWindowSnapshot }) {
|
||||
className="transition-[stroke-dashoffset] duration-500 ease-out motion-reduce:transition-none"
|
||||
/>
|
||||
</svg>
|
||||
<span
|
||||
className={cn(
|
||||
"relative flex h-[15px] w-[15px] items-center justify-center rounded-full bg-background text-[8px] font-medium",
|
||||
"text-muted-foreground",
|
||||
)}
|
||||
>
|
||||
{usage.usedPercentage !== null
|
||||
? Math.round(usage.usedPercentage)
|
||||
: formatContextWindowTokens(usage.usedTokens)}
|
||||
</span>
|
||||
</span>
|
||||
</button>
|
||||
}
|
||||
/>
|
||||
<PopoverPopup tooltipStyle side="top" align="end" className="w-max max-w-none px-3 py-2">
|
||||
<div className="space-y-1.5 leading-tight">
|
||||
<div className="text-[11px] font-medium uppercase tracking-[0.08em] text-muted-foreground">
|
||||
Context window
|
||||
<PopoverPopup tooltipStyle side="top" align="end" className="w-64 max-w-none p-0">
|
||||
<div className="flex flex-col gap-2 p-3">
|
||||
<div className="flex items-center justify-between gap-3">
|
||||
<div className="font-medium text-muted-foreground text-xs">Context Window</div>
|
||||
{usage.maxTokens !== null && usedPercentage ? (
|
||||
<div className="text-[11px] tabular-nums text-muted-foreground/70">
|
||||
<span>{usedPercentage}</span>
|
||||
<span className="mx-1">·</span>
|
||||
<span>
|
||||
{formatContextWindowTokens(usage.usedTokens)}/
|
||||
{formatContextWindowTokens(usage.maxTokens ?? null)}
|
||||
</span>
|
||||
</div>
|
||||
) : (
|
||||
<div className="text-[11px] tabular-nums text-muted-foreground/70">
|
||||
{formatContextWindowTokens(usage.usedTokens)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{usage.maxTokens !== null && usedPercentage ? (
|
||||
<div className="whitespace-nowrap text-xs font-medium text-foreground">
|
||||
<span>{usedPercentage}</span>
|
||||
<span className="mx-1">⋅</span>
|
||||
<span>{formatContextWindowTokens(usage.usedTokens)}</span>
|
||||
<span>/</span>
|
||||
<span>{formatContextWindowTokens(usage.maxTokens ?? null)} context used</span>
|
||||
{usage.maxTokens !== null ? (
|
||||
<div
|
||||
className="h-1.5 w-full overflow-hidden rounded-full bg-muted/60"
|
||||
role="progressbar"
|
||||
aria-valuemin={0}
|
||||
aria-valuemax={100}
|
||||
aria-valuenow={Math.round(normalizedPercentage)}
|
||||
aria-label="Context window usage"
|
||||
>
|
||||
<div
|
||||
className="h-full rounded-full transition-[width,background-color] duration-500 ease-out motion-reduce:transition-none"
|
||||
style={{ width: `${normalizedPercentage}%`, backgroundColor: usageColor }}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<div className="text-sm text-foreground">
|
||||
{formatContextWindowTokens(usage.usedTokens)} tokens used so far
|
||||
</div>
|
||||
)}
|
||||
{(usage.totalProcessedTokens ?? null) !== null &&
|
||||
(usage.totalProcessedTokens ?? 0) > usage.usedTokens ? (
|
||||
<div className="text-xs text-muted-foreground">
|
||||
Total processed: {formatContextWindowTokens(usage.totalProcessedTokens ?? null)}{" "}
|
||||
tokens
|
||||
) : null}
|
||||
{showTotalProcessed ? (
|
||||
<div className="flex items-center justify-between gap-3 text-[11px] leading-4">
|
||||
<span className="text-muted-foreground/60">Total processed</span>
|
||||
<span className="font-medium tabular-nums text-muted-foreground/80">
|
||||
{formatContextWindowTokens(totalProcessedTokens)}
|
||||
</span>
|
||||
</div>
|
||||
) : null}
|
||||
{usage.compactsAutomatically ? (
|
||||
<div className="text-xs text-muted-foreground">
|
||||
Automatically compacts its context when needed.
|
||||
<div className="mt-1 text-pretty text-[11px] font-medium text-muted-foreground/70">
|
||||
{providerDisplayName ?? "It"} automatically compacts its context when needed.
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
@@ -56,7 +56,7 @@ function selections(
|
||||
|
||||
const ULTRATHINK_FRAME_CLASSES = {
|
||||
composerFrameClassName: "ultrathink-frame",
|
||||
composerSurfaceClassName: "shadow-[0_0_0_1px_rgba(255,255,255,0.04)_inset]",
|
||||
composerSurfaceClassName: "shadow-[0_0_0_1px_rgba(255,255,255,0.07)_inset]",
|
||||
modelPickerIconClassName: "ultrathink-chroma",
|
||||
} as const;
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ export function getComposerProviderState(input: ComposerProviderStateInput): Com
|
||||
...(ultrathinkActive
|
||||
? {
|
||||
composerFrameClassName: "ultrathink-frame",
|
||||
composerSurfaceClassName: "shadow-[0_0_0_1px_rgba(255,255,255,0.04)_inset]",
|
||||
composerSurfaceClassName: "shadow-[0_0_0_1px_rgba(255,255,255,0.07)_inset]",
|
||||
modelPickerIconClassName: "ultrathink-chroma",
|
||||
}
|
||||
: {}),
|
||||
|
||||
@@ -685,6 +685,7 @@ label:has(> select#reasoning-effort) select {
|
||||
);
|
||||
background-image: var(--ultrathink-spectrum);
|
||||
background-size: 220% 220%;
|
||||
filter: saturate(0.82) brightness(0.92);
|
||||
animation: ultrathink-rainbow 10s linear infinite;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,28 @@ export type ContextWindowSnapshot = NullableContextWindowUsage & {
|
||||
readonly updatedAt: string;
|
||||
};
|
||||
|
||||
/** Map a provider driver kind to a user-facing display name. */
|
||||
export function formatProviderDisplayName(provider: string | null | undefined): string {
|
||||
if (!provider) return "This agent";
|
||||
switch (provider) {
|
||||
case "claudeAgent":
|
||||
case "claude":
|
||||
return "Claude";
|
||||
case "codex":
|
||||
return "Codex";
|
||||
case "cursor":
|
||||
return "Cursor";
|
||||
case "opencode":
|
||||
return "OpenCode";
|
||||
default: {
|
||||
// Title-case unknown driver kinds so they read reasonably.
|
||||
const trimmed = provider.replace(/Agent$/i, "").trim();
|
||||
if (trimmed.length === 0) return provider;
|
||||
return trimmed.charAt(0).toUpperCase() + trimmed.slice(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function deriveLatestContextWindowSnapshot(
|
||||
activities: ReadonlyArray<OrchestrationThreadActivity>,
|
||||
): ContextWindowSnapshot | null {
|
||||
|
||||
Reference in new issue
Block a user