Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2bda93bd3d |
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@t3tools/desktop",
|
||||
"version": "0.0.28",
|
||||
"version": "0.0.27",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "dist-electron/main.cjs",
|
||||
|
||||
@@ -607,7 +607,6 @@ export const make = Effect.gen(function* () {
|
||||
const backendExposure = yield* serverExposure.backendConfig;
|
||||
const persistedSettings = yield* settings.get;
|
||||
const shared = yield* sharedInputs;
|
||||
yield* wslEnvironment.preWarm(persistedSettings.wslDistro);
|
||||
return yield* resolveWslStartConfig({
|
||||
...shared,
|
||||
port: backendExposure.port,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "t3",
|
||||
"version": "0.0.28",
|
||||
"version": "0.0.27",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@@ -193,36 +193,6 @@ const BUILT_IN_MODELS: ReadonlyArray<ServerProviderModel> = [
|
||||
],
|
||||
}),
|
||||
},
|
||||
{
|
||||
slug: "claude-sonnet-5",
|
||||
name: "Claude Sonnet 5",
|
||||
isCustom: false,
|
||||
capabilities: createModelCapabilities({
|
||||
optionDescriptors: [
|
||||
buildSelectOptionDescriptor({
|
||||
id: "effort",
|
||||
label: "Reasoning",
|
||||
options: [
|
||||
{ value: "low", label: "Low" },
|
||||
{ value: "medium", label: "Medium" },
|
||||
{ value: "high", label: "High", isDefault: true },
|
||||
{ value: "xhigh", label: "Extra High" },
|
||||
{ value: "max", label: "Max" },
|
||||
{ value: "ultrathink", label: "Ultrathink" },
|
||||
],
|
||||
promptInjectedValues: ["ultrathink"],
|
||||
}),
|
||||
buildSelectOptionDescriptor({
|
||||
id: "contextWindow",
|
||||
label: "Context Window",
|
||||
options: [
|
||||
{ value: "200k", label: "200k", isDefault: true },
|
||||
{ value: "1m", label: "1M" },
|
||||
],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
},
|
||||
{
|
||||
slug: "claude-sonnet-4-6",
|
||||
name: "Claude Sonnet 4.6",
|
||||
@@ -352,12 +322,7 @@ export function normalizeClaudeCliEffort(
|
||||
if (effort === "ultracode") {
|
||||
return "xhigh";
|
||||
}
|
||||
if (
|
||||
effort === "xhigh" &&
|
||||
model !== "claude-fable-5" &&
|
||||
model !== "claude-opus-4-8" &&
|
||||
model !== "claude-sonnet-5"
|
||||
) {
|
||||
if (effort === "xhigh" && model !== "claude-fable-5" && model !== "claude-opus-4-8") {
|
||||
return "max";
|
||||
}
|
||||
if (effort === "max" && model === "claude-sonnet-4-6") {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@t3tools/web",
|
||||
"version": "0.0.28",
|
||||
"version": "0.0.27",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
||||
@@ -239,7 +239,7 @@ export const BranchToolbar = memo(function BranchToolbar({
|
||||
if (!hasActiveThread || !activeProject) return null;
|
||||
|
||||
return (
|
||||
<div className="mx-auto flex w-full max-w-3xl items-center gap-2 px-2.5 pb-3 pt-1 sm:px-3">
|
||||
<div className="mx-auto flex w-full max-w-208 items-center gap-2 px-2.5 pb-3 pt-1 sm:px-3">
|
||||
{isMobile ? (
|
||||
<MobileRunContextSelector
|
||||
envLocked={envLocked}
|
||||
|
||||
@@ -85,7 +85,6 @@ import {
|
||||
isLatestTurnSettled,
|
||||
} from "../session-logic";
|
||||
import { type LegendListRef } from "@legendapp/list/react";
|
||||
import { getAnchoredTurnMetrics, type TimelineScrollMode } from "./chat/timelineScrollAnchoring";
|
||||
import {
|
||||
buildPendingUserInputAnswers,
|
||||
derivePendingUserInputProgress,
|
||||
@@ -1162,7 +1161,6 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
|
||||
const updateHeight = () => {
|
||||
const nextHeight = Math.ceil(composerOverlayElement.getBoundingClientRect().height);
|
||||
if (nextHeight <= 0) return;
|
||||
setComposerOverlayHeight((currentHeight) =>
|
||||
currentHeight === nextHeight ? currentHeight : nextHeight,
|
||||
);
|
||||
@@ -2014,6 +2012,7 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
: // Spread only fires for the few messages that actually changed;
|
||||
// unchanged ones early-return their original reference.
|
||||
// In-place mutation would break React's immutable state contract.
|
||||
// oxlint-disable-next-line no-map-spread
|
||||
messages.map((message) => {
|
||||
if (
|
||||
message.role !== "user" ||
|
||||
@@ -3149,158 +3148,31 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
],
|
||||
);
|
||||
|
||||
// Debounce *showing* the scroll-to-bottom pill so it doesn't flash during
|
||||
// thread switches. LegendList fires scroll events with isAtEnd=false while
|
||||
// initialScrollAtEnd is settling; hiding is always immediate.
|
||||
const showScrollDebouncer = useRef(
|
||||
new Debouncer(() => setShowScrollToBottom(true), { wait: 150 }),
|
||||
);
|
||||
const timelineScrollModeRef = useRef<TimelineScrollMode>("following-end");
|
||||
const pendingTimelineAnchorRef = useRef<MessageId | null>(null);
|
||||
// Scrolling is explicit so streamed timeline updates never take control away
|
||||
// from the user after the newly sent row has been positioned once.
|
||||
const scrollToEnd = useCallback((animated = false) => {
|
||||
void legendListRef.current?.scrollToEnd?.({ animated });
|
||||
}, []);
|
||||
const positionedTimelineAnchorRef = useRef<MessageId | null>(null);
|
||||
const settledTimelineAnchorRef = useRef<MessageId | null>(null);
|
||||
const activeTimelineAnchorIndexRef = useRef<number | null>(null);
|
||||
const anchorUserScrollGenerationRef = useRef(0);
|
||||
const liveFollowUserScrollGenerationRef = useRef<number | null>(0);
|
||||
const pendingAnchorScrollRestoreRef = useRef<{
|
||||
readonly messageId: MessageId;
|
||||
readonly offset: number;
|
||||
readonly userScrollGeneration: number;
|
||||
} | null>(null);
|
||||
const anchorScrollRestoreFrameRef = useRef<number | null>(null);
|
||||
const cancelTimelineLiveFollowForUserNavigation = useCallback(() => {
|
||||
anchorUserScrollGenerationRef.current += 1;
|
||||
timelineScrollModeRef.current = "free-scrolling";
|
||||
liveFollowUserScrollGenerationRef.current = null;
|
||||
pendingTimelineAnchorRef.current = null;
|
||||
positionedTimelineAnchorRef.current = null;
|
||||
settledTimelineAnchorRef.current = null;
|
||||
activeTimelineAnchorIndexRef.current = null;
|
||||
pendingAnchorScrollRestoreRef.current = null;
|
||||
if (anchorScrollRestoreFrameRef.current !== null) {
|
||||
cancelAnimationFrame(anchorScrollRestoreFrameRef.current);
|
||||
anchorScrollRestoreFrameRef.current = null;
|
||||
}
|
||||
}, []);
|
||||
const cancelTimelineLiveFollowForUserNavigationRef = useRef(
|
||||
cancelTimelineLiveFollowForUserNavigation,
|
||||
);
|
||||
useEffect(() => {
|
||||
cancelTimelineLiveFollowForUserNavigationRef.current =
|
||||
cancelTimelineLiveFollowForUserNavigation;
|
||||
}, [cancelTimelineLiveFollowForUserNavigation]);
|
||||
const getActiveTimelineTurnMetrics = useCallback(
|
||||
(list?: LegendListRef | null) => {
|
||||
const resolvedList = list ?? legendListRef.current;
|
||||
const anchorIndex = activeTimelineAnchorIndexRef.current;
|
||||
const state = resolvedList?.getState();
|
||||
if (!resolvedList || !state || anchorIndex === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return getAnchoredTurnMetrics({
|
||||
state,
|
||||
anchorIndex,
|
||||
composerOverlayHeight,
|
||||
anchorOffset: CHAT_LIST_ANCHOR_OFFSET,
|
||||
});
|
||||
},
|
||||
[composerOverlayHeight],
|
||||
);
|
||||
const timelineRealContentOverflowsViewport = useCallback(
|
||||
(list?: LegendListRef | null) => {
|
||||
const resolvedList = list ?? legendListRef.current;
|
||||
const state = resolvedList?.getState();
|
||||
if (!resolvedList || !state || state.data.length === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const lastRowIndex = state.data.length - 1;
|
||||
const lastRowTop = state.positionAtIndex(lastRowIndex);
|
||||
const lastRowHeight = state.sizeAtIndex(lastRowIndex);
|
||||
if (
|
||||
typeof lastRowTop !== "number" ||
|
||||
typeof lastRowHeight !== "number" ||
|
||||
!Number.isFinite(lastRowTop) ||
|
||||
!Number.isFinite(lastRowHeight)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const realContentBottom = lastRowTop + Math.max(1, lastRowHeight);
|
||||
const visibleScrollLength = Math.max(
|
||||
0,
|
||||
(state.scrollLength ?? 0) - composerOverlayHeight - CHAT_LIST_ANCHOR_OFFSET,
|
||||
);
|
||||
return realContentBottom > visibleScrollLength;
|
||||
},
|
||||
[composerOverlayHeight],
|
||||
);
|
||||
|
||||
// Live-follow stays active after send/thread-open until an actual list scroll
|
||||
// gesture opts out.
|
||||
const scrollToEnd = useCallback((animated = false) => {
|
||||
isAtEndRef.current = true;
|
||||
timelineScrollModeRef.current = "following-end";
|
||||
liveFollowUserScrollGenerationRef.current = anchorUserScrollGenerationRef.current;
|
||||
pendingTimelineAnchorRef.current = null;
|
||||
activeTimelineAnchorIndexRef.current = null;
|
||||
showScrollDebouncer.current.cancel();
|
||||
setShowScrollToBottom(false);
|
||||
void legendListRef.current?.scrollToEnd?.({ animated });
|
||||
}, []);
|
||||
useEffect(() => {
|
||||
let removeListeners: (() => void) | null = null;
|
||||
const frame = requestAnimationFrame(() => {
|
||||
const scrollNode = legendListRef.current?.getScrollableNode();
|
||||
if (!scrollNode) {
|
||||
return;
|
||||
}
|
||||
const handleManualNavigation = () => {
|
||||
cancelTimelineLiveFollowForUserNavigationRef.current();
|
||||
};
|
||||
scrollNode.addEventListener("wheel", handleManualNavigation, {
|
||||
passive: true,
|
||||
});
|
||||
scrollNode.addEventListener("touchmove", handleManualNavigation, {
|
||||
passive: true,
|
||||
});
|
||||
scrollNode.addEventListener("pointerdown", handleManualNavigation, {
|
||||
passive: true,
|
||||
});
|
||||
removeListeners = () => {
|
||||
scrollNode.removeEventListener("wheel", handleManualNavigation);
|
||||
scrollNode.removeEventListener("touchmove", handleManualNavigation);
|
||||
scrollNode.removeEventListener("pointerdown", handleManualNavigation);
|
||||
};
|
||||
});
|
||||
|
||||
return () => {
|
||||
cancelAnimationFrame(frame);
|
||||
removeListeners?.();
|
||||
};
|
||||
}, [activeThread?.id]);
|
||||
|
||||
const onTimelineAnchorReady = useCallback((messageId: MessageId, anchorIndex: number) => {
|
||||
if (pendingTimelineAnchorRef.current === messageId) {
|
||||
pendingTimelineAnchorRef.current = null;
|
||||
}
|
||||
activeTimelineAnchorIndexRef.current = anchorIndex;
|
||||
if (positionedTimelineAnchorRef.current === messageId) {
|
||||
return;
|
||||
}
|
||||
positionedTimelineAnchorRef.current = messageId;
|
||||
settledTimelineAnchorRef.current = null;
|
||||
const positionAnchor = (remainingAttempts: number) => {
|
||||
requestAnimationFrame(() => {
|
||||
requestAnimationFrame(() => {
|
||||
if (positionedTimelineAnchorRef.current !== messageId) {
|
||||
return;
|
||||
}
|
||||
const list = legendListRef.current;
|
||||
if (!list) {
|
||||
if (remainingAttempts > 0) {
|
||||
positionAnchor(remainingAttempts - 1);
|
||||
}
|
||||
return;
|
||||
}
|
||||
const scrollNode = list.getScrollableNode();
|
||||
@@ -3328,26 +3200,18 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
viewOffset: CHAT_LIST_ANCHOR_OFFSET,
|
||||
});
|
||||
});
|
||||
};
|
||||
requestAnimationFrame(() => positionAnchor(12));
|
||||
});
|
||||
}, []);
|
||||
const onTimelineAnchorSizeChanged = useCallback((messageId: MessageId) => {
|
||||
if (settledTimelineAnchorRef.current !== messageId) {
|
||||
return;
|
||||
}
|
||||
if (liveFollowUserScrollGenerationRef.current === anchorUserScrollGenerationRef.current) {
|
||||
return;
|
||||
}
|
||||
const scrollOffset = legendListRef.current?.getState().scroll;
|
||||
if (scrollOffset === undefined) {
|
||||
return;
|
||||
}
|
||||
if (pendingAnchorScrollRestoreRef.current === null) {
|
||||
pendingAnchorScrollRestoreRef.current = {
|
||||
messageId,
|
||||
offset: scrollOffset,
|
||||
userScrollGeneration: anchorUserScrollGenerationRef.current,
|
||||
};
|
||||
pendingAnchorScrollRestoreRef.current = { messageId, offset: scrollOffset };
|
||||
}
|
||||
if (anchorScrollRestoreFrameRef.current !== null) {
|
||||
return;
|
||||
@@ -3356,121 +3220,32 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
anchorScrollRestoreFrameRef.current = null;
|
||||
const pending = pendingAnchorScrollRestoreRef.current;
|
||||
pendingAnchorScrollRestoreRef.current = null;
|
||||
if (
|
||||
pending &&
|
||||
settledTimelineAnchorRef.current === pending.messageId &&
|
||||
pending.userScrollGeneration === anchorUserScrollGenerationRef.current
|
||||
) {
|
||||
const list = legendListRef.current;
|
||||
const currentScrollOffset = list?.getState().scroll;
|
||||
if (
|
||||
typeof currentScrollOffset === "number" &&
|
||||
Math.abs(currentScrollOffset - pending.offset) <= 2
|
||||
) {
|
||||
void list?.scrollToOffset({ offset: pending.offset, animated: false });
|
||||
}
|
||||
if (pending && settledTimelineAnchorRef.current === pending.messageId) {
|
||||
void legendListRef.current?.scrollToOffset({ offset: pending.offset, animated: false });
|
||||
}
|
||||
});
|
||||
}, []);
|
||||
|
||||
// Debounce *showing* the scroll-to-bottom pill so it doesn't flash during
|
||||
// thread switches. LegendList fires scroll events with isAtEnd=false while
|
||||
// initialScrollAtEnd is settling; hiding is always immediate.
|
||||
const showScrollDebouncer = useRef(
|
||||
new Debouncer(() => setShowScrollToBottom(true), { wait: 150 }),
|
||||
);
|
||||
const onIsAtEndChange = useCallback((isAtEnd: boolean) => {
|
||||
if (
|
||||
!isAtEnd &&
|
||||
liveFollowUserScrollGenerationRef.current === anchorUserScrollGenerationRef.current
|
||||
) {
|
||||
showScrollDebouncer.current.cancel();
|
||||
setShowScrollToBottom(false);
|
||||
return;
|
||||
}
|
||||
if (isAtEndRef.current === isAtEnd) return;
|
||||
isAtEndRef.current = isAtEnd;
|
||||
if (isAtEnd) {
|
||||
timelineScrollModeRef.current = "following-end";
|
||||
liveFollowUserScrollGenerationRef.current = anchorUserScrollGenerationRef.current;
|
||||
showScrollDebouncer.current.cancel();
|
||||
setShowScrollToBottom(false);
|
||||
} else {
|
||||
timelineScrollModeRef.current = "free-scrolling";
|
||||
liveFollowUserScrollGenerationRef.current = null;
|
||||
showScrollDebouncer.current.maybeExecute();
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!activeThread?.id) {
|
||||
return;
|
||||
}
|
||||
if (liveFollowUserScrollGenerationRef.current !== anchorUserScrollGenerationRef.current) {
|
||||
return;
|
||||
}
|
||||
|
||||
let secondFrame: number | null = null;
|
||||
const frame = requestAnimationFrame(() => {
|
||||
secondFrame = requestAnimationFrame(() => {
|
||||
if (liveFollowUserScrollGenerationRef.current !== anchorUserScrollGenerationRef.current) {
|
||||
return;
|
||||
}
|
||||
if (pendingTimelineAnchorRef.current !== null) {
|
||||
return;
|
||||
}
|
||||
if (
|
||||
positionedTimelineAnchorRef.current !== null &&
|
||||
settledTimelineAnchorRef.current !== positionedTimelineAnchorRef.current
|
||||
) {
|
||||
return;
|
||||
}
|
||||
const list = legendListRef.current;
|
||||
if (!list) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (timelineScrollModeRef.current === "anchoring-new-turn") {
|
||||
const metrics = getActiveTimelineTurnMetrics(list);
|
||||
if (!metrics) {
|
||||
return;
|
||||
}
|
||||
if (metrics.scrollDeltaToRevealEnd <= 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
const nextOffset = list.getState().scroll + metrics.scrollDeltaToRevealEnd;
|
||||
void list.scrollToOffset({ offset: nextOffset, animated: false });
|
||||
return;
|
||||
}
|
||||
|
||||
if (timelineScrollModeRef.current !== "following-end") {
|
||||
return;
|
||||
}
|
||||
if (!timelineRealContentOverflowsViewport(list)) {
|
||||
return;
|
||||
}
|
||||
|
||||
void list.scrollToEnd?.({ animated: false });
|
||||
});
|
||||
});
|
||||
|
||||
return () => {
|
||||
cancelAnimationFrame(frame);
|
||||
if (secondFrame !== null) {
|
||||
cancelAnimationFrame(secondFrame);
|
||||
}
|
||||
};
|
||||
}, [
|
||||
activeThread?.id,
|
||||
timelineEntries,
|
||||
getActiveTimelineTurnMetrics,
|
||||
timelineRealContentOverflowsViewport,
|
||||
]);
|
||||
|
||||
useEffect(() => {
|
||||
setPullRequestDialogState(null);
|
||||
isAtEndRef.current = true;
|
||||
timelineScrollModeRef.current = "following-end";
|
||||
liveFollowUserScrollGenerationRef.current = anchorUserScrollGenerationRef.current;
|
||||
pendingTimelineAnchorRef.current = null;
|
||||
positionedTimelineAnchorRef.current = null;
|
||||
settledTimelineAnchorRef.current = null;
|
||||
activeTimelineAnchorIndexRef.current = null;
|
||||
showScrollDebouncer.current.cancel();
|
||||
setShowScrollToBottom(false);
|
||||
if (planSidebarOpenOnNextThreadRef.current) {
|
||||
@@ -3481,6 +3256,7 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
}
|
||||
planSidebarDismissedForTurnRef.current = null;
|
||||
// activeThreadRef resets transitively with the active thread.
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [activeThread?.id]);
|
||||
|
||||
// Auto-open the plan sidebar when plan/todo steps arrive for the current turn.
|
||||
@@ -4030,10 +3806,6 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
// anchored end-space target so it lands near the top while the response
|
||||
// streams into the reserved space below it.
|
||||
isAtEndRef.current = true;
|
||||
timelineScrollModeRef.current = "anchoring-new-turn";
|
||||
liveFollowUserScrollGenerationRef.current = anchorUserScrollGenerationRef.current;
|
||||
pendingTimelineAnchorRef.current = messageIdForSend;
|
||||
activeTimelineAnchorIndexRef.current = null;
|
||||
showScrollDebouncer.current.cancel();
|
||||
setShowScrollToBottom(false);
|
||||
setTimelineAnchor({
|
||||
@@ -4467,10 +4239,6 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
|
||||
// Position this sent row once LegendList has measured the anchored tail.
|
||||
isAtEndRef.current = true;
|
||||
timelineScrollModeRef.current = "anchoring-new-turn";
|
||||
liveFollowUserScrollGenerationRef.current = anchorUserScrollGenerationRef.current;
|
||||
pendingTimelineAnchorRef.current = messageIdForSend;
|
||||
activeTimelineAnchorIndexRef.current = null;
|
||||
showScrollDebouncer.current.cancel();
|
||||
setShowScrollToBottom(false);
|
||||
setTimelineAnchor({
|
||||
@@ -5100,10 +4868,9 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
onAnchorSizeChanged={onTimelineAnchorSizeChanged}
|
||||
contentInsetEndAdjustment={composerOverlayHeight}
|
||||
onIsAtEndChange={onIsAtEndChange}
|
||||
onManualNavigation={cancelTimelineLiveFollowForUserNavigation}
|
||||
/>
|
||||
|
||||
{/* scroll to end pill — shown when user has scrolled away from the live edge */}
|
||||
{/* scroll to bottom pill — shown when user has scrolled away from the bottom */}
|
||||
{showScrollToBottom && (
|
||||
<div
|
||||
className="pointer-events-none absolute left-1/2 z-30 flex -translate-x-1/2 justify-center py-1.5"
|
||||
@@ -5111,13 +4878,11 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
aria-label="Scroll to end"
|
||||
title="Scroll to end"
|
||||
onClick={() => scrollToEnd(true)}
|
||||
className="pointer-events-auto flex items-center gap-1.5 rounded-full border border-border/60 bg-card px-3 py-1 text-muted-foreground text-xs shadow-sm transition-colors hover:border-border hover:text-foreground hover:cursor-pointer"
|
||||
>
|
||||
<ChevronDownIcon className="size-3.5" />
|
||||
Scroll to end
|
||||
Scroll to bottom
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
@@ -5133,7 +4898,7 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
aria-hidden="true"
|
||||
className="chat-composer-horizontal-inset pointer-events-none absolute inset-x-0 top-1.5 bottom-0 z-0 sm:top-2"
|
||||
>
|
||||
<div className="relative mx-auto h-full w-full max-w-3xl overflow-clip rounded-t-[20px]">
|
||||
<div className="relative mx-auto h-full w-full max-w-208 overflow-clip rounded-t-[20px]">
|
||||
<div className="chat-composer-shared-blur absolute -inset-8" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -331,19 +331,6 @@ export function RightPanelTabs(props: RightPanelTabsProps) {
|
||||
},
|
||||
[props],
|
||||
);
|
||||
const handleTabMouseDown = useCallback((event: ReactMouseEvent) => {
|
||||
if (event.button !== 1) return;
|
||||
event.preventDefault();
|
||||
}, []);
|
||||
const handleTabAuxClick = useCallback(
|
||||
(event: ReactMouseEvent, surface: RightPanelSurface) => {
|
||||
if (event.button !== 1) return;
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
props.onCloseSurface(surface);
|
||||
},
|
||||
[props],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const activeTab = tabListRef.current?.querySelector<HTMLElement>("[data-active-tab='true']");
|
||||
@@ -380,8 +367,6 @@ export function RightPanelTabs(props: RightPanelTabsProps) {
|
||||
<div
|
||||
key={surface.id}
|
||||
data-active-tab={active}
|
||||
onMouseDown={handleTabMouseDown}
|
||||
onAuxClick={(event) => handleTabAuxClick(event, surface)}
|
||||
onContextMenu={(event) => void handleTabContextMenu(event, surface)}
|
||||
className={cn(
|
||||
"group flex h-7 min-w-25 max-w-44 shrink-0 items-center gap-1.5 rounded-md px-2 text-sm",
|
||||
|
||||
@@ -1861,6 +1861,9 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
const handleImplementPlanInNewThreadPrimaryAction = useCallback(() => {
|
||||
void onImplementPlanInNewThread();
|
||||
}, [onImplementPlanInNewThread]);
|
||||
const handleComposerModelPickerOpenChange = useCallback((open: boolean) => {
|
||||
setIsComposerModelPickerOpen(open);
|
||||
}, []);
|
||||
const scheduleComposerCollapseCheck = useCallback(() => {
|
||||
if (!isMobileViewport) {
|
||||
return;
|
||||
@@ -2044,7 +2047,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
<form
|
||||
ref={composerFormRef}
|
||||
onSubmit={submitComposer}
|
||||
className="mx-auto w-full min-w-0 max-w-3xl"
|
||||
className="mx-auto w-full min-w-0 max-w-208"
|
||||
data-chat-composer-form="true"
|
||||
>
|
||||
<div
|
||||
@@ -2486,9 +2489,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
activeProviderIconClassName: composerProviderState.modelPickerIconClassName,
|
||||
}
|
||||
: {})}
|
||||
onOpenChange={(open) => {
|
||||
setIsComposerModelPickerOpen(open);
|
||||
}}
|
||||
onOpenChange={handleComposerModelPickerOpenChange}
|
||||
getModelDisabledReason={getModelDisabledReason}
|
||||
onInstanceModelChange={onProviderModelSelect}
|
||||
/>
|
||||
|
||||
@@ -82,7 +82,7 @@ export function ComposerBannerStack({ className, items }: ComposerBannerStackPro
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={cn("group/banner-stack mx-auto mb-2 max-w-3xl", className)}>
|
||||
<div className={cn("group/banner-stack mx-auto mb-2 max-w-208", className)}>
|
||||
<div
|
||||
className={cn(
|
||||
"relative",
|
||||
|
||||
@@ -10,59 +10,6 @@ import { type ChatMessage, type ProposedPlan, type TurnDiffSummary } from "../..
|
||||
import { type MessageId, type OrchestrationLatestTurn, type TurnId } from "@t3tools/contracts";
|
||||
|
||||
export const MAX_VISIBLE_WORK_LOG_ENTRIES = 1;
|
||||
export const TIMELINE_MINIMAP_ITEM_SPACING = 8;
|
||||
export const TIMELINE_MINIMAP_MIN_ITEMS = 2;
|
||||
export const TIMELINE_MINIMAP_MAX_HEIGHT_CSS = "calc(100vh - 18rem)";
|
||||
export const TIMELINE_CONTENT_MAX_WIDTH = 768;
|
||||
export const TIMELINE_MINIMAP_PERSISTENT_GUTTER = 48;
|
||||
|
||||
export interface TimelineEndState {
|
||||
readonly isAtEnd?: boolean;
|
||||
readonly isNearEnd?: boolean;
|
||||
}
|
||||
|
||||
export function resolveTimelineIsAtEnd(state: TimelineEndState | undefined): boolean | undefined {
|
||||
return state?.isNearEnd ?? state?.isAtEnd;
|
||||
}
|
||||
|
||||
export function resolveTimelineMinimapHeightStyle(itemCount: number): string {
|
||||
const naturalHeight = Math.max(1, (itemCount - 1) * TIMELINE_MINIMAP_ITEM_SPACING);
|
||||
return `min(${naturalHeight}px, ${TIMELINE_MINIMAP_MAX_HEIGHT_CSS})`;
|
||||
}
|
||||
|
||||
export function resolveTimelineMinimapTopPercent(index: number, itemCount: number): number {
|
||||
if (itemCount <= 1) {
|
||||
return 0;
|
||||
}
|
||||
return (Math.max(0, Math.min(index, itemCount - 1)) / (itemCount - 1)) * 100;
|
||||
}
|
||||
|
||||
export function resolveTimelineMinimapIndexFromPointer(input: {
|
||||
readonly itemCount: number;
|
||||
readonly railTop: number;
|
||||
readonly railHeight: number;
|
||||
readonly pointerY: number;
|
||||
}): number | null {
|
||||
if (input.itemCount <= 0 || input.railHeight <= 0) {
|
||||
return null;
|
||||
}
|
||||
if (input.itemCount === 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const progress = Math.max(0, Math.min(1, (input.pointerY - input.railTop) / input.railHeight));
|
||||
return Math.max(0, Math.min(input.itemCount - 1, Math.round(progress * (input.itemCount - 1))));
|
||||
}
|
||||
|
||||
export function resolveTimelineMinimapHasPersistentGutter(viewportWidth: number): boolean {
|
||||
if (!Number.isFinite(viewportWidth) || viewportWidth <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const contentWidth = Math.min(viewportWidth, TIMELINE_CONTENT_MAX_WIDTH);
|
||||
const sideGutter = Math.max(0, (viewportWidth - contentWidth) / 2);
|
||||
return sideGutter >= TIMELINE_MINIMAP_PERSISTENT_GUTTER;
|
||||
}
|
||||
|
||||
function computeElapsedMs(startIso: string, endIso: string): number | null {
|
||||
const start = Date.parse(startIso);
|
||||
|
||||
@@ -22,16 +22,7 @@ vi.mock("@legendapp/list/react", async () => {
|
||||
};
|
||||
contentInsetEndAdjustment?: number;
|
||||
className?: string;
|
||||
maintainScrollAtEnd?:
|
||||
| boolean
|
||||
| {
|
||||
animated?: boolean;
|
||||
on?: {
|
||||
dataChange?: boolean;
|
||||
itemLayout?: boolean;
|
||||
layout?: boolean;
|
||||
};
|
||||
};
|
||||
maintainScrollAtEnd?: boolean;
|
||||
maintainVisibleContentPosition?:
|
||||
| boolean
|
||||
| {
|
||||
@@ -54,27 +45,7 @@ vi.mock("@legendapp/list/react", async () => {
|
||||
data-anchor-on-ready={Boolean(props.anchoredEndSpace?.onReady)}
|
||||
data-content-inset-end={props.contentInsetEndAdjustment}
|
||||
data-class-name={props.className}
|
||||
data-maintain-scroll-at-end={props.maintainScrollAtEnd ? "enabled" : undefined}
|
||||
data-maintain-scroll-at-end-animated={
|
||||
typeof props.maintainScrollAtEnd === "object"
|
||||
? props.maintainScrollAtEnd.animated
|
||||
: undefined
|
||||
}
|
||||
data-maintain-scroll-at-end-data-change={
|
||||
typeof props.maintainScrollAtEnd === "object"
|
||||
? props.maintainScrollAtEnd.on?.dataChange
|
||||
: undefined
|
||||
}
|
||||
data-maintain-scroll-at-end-item-layout={
|
||||
typeof props.maintainScrollAtEnd === "object"
|
||||
? props.maintainScrollAtEnd.on?.itemLayout
|
||||
: undefined
|
||||
}
|
||||
data-maintain-scroll-at-end-layout={
|
||||
typeof props.maintainScrollAtEnd === "object"
|
||||
? props.maintainScrollAtEnd.on?.layout
|
||||
: undefined
|
||||
}
|
||||
data-maintain-scroll-at-end={props.maintainScrollAtEnd}
|
||||
data-maintain-visible-content-position={
|
||||
typeof props.maintainVisibleContentPosition === "object"
|
||||
? "object"
|
||||
@@ -191,7 +162,6 @@ function buildProps() {
|
||||
onAnchorSizeChanged: () => {},
|
||||
contentInsetEndAdjustment: 0,
|
||||
onIsAtEndChange: () => {},
|
||||
onManualNavigation: () => {},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -219,43 +189,6 @@ function buildUserTimelineEntry(text: string) {
|
||||
}
|
||||
|
||||
describe("MessagesTimeline", () => {
|
||||
it("uses LegendList isNearEnd when deciding whether the live edge is visible", async () => {
|
||||
const {
|
||||
resolveTimelineIsAtEnd,
|
||||
resolveTimelineMinimapHasPersistentGutter,
|
||||
resolveTimelineMinimapHeightStyle,
|
||||
resolveTimelineMinimapIndexFromPointer,
|
||||
resolveTimelineMinimapTopPercent,
|
||||
} = await import("./MessagesTimeline.logic");
|
||||
|
||||
expect(resolveTimelineIsAtEnd({ isNearEnd: true, isAtEnd: false })).toBe(true);
|
||||
expect(resolveTimelineIsAtEnd({ isNearEnd: false, isAtEnd: true })).toBe(false);
|
||||
expect(resolveTimelineIsAtEnd({ isAtEnd: true })).toBe(true);
|
||||
expect(resolveTimelineIsAtEnd(undefined)).toBeUndefined();
|
||||
|
||||
expect(resolveTimelineMinimapHeightStyle(5)).toBe("min(32px, calc(100vh - 18rem))");
|
||||
expect(resolveTimelineMinimapTopPercent(2, 5)).toBe(50);
|
||||
expect(
|
||||
resolveTimelineMinimapIndexFromPointer({
|
||||
itemCount: 101,
|
||||
railTop: 100,
|
||||
railHeight: 500,
|
||||
pointerY: 350,
|
||||
}),
|
||||
).toBe(50);
|
||||
expect(
|
||||
resolveTimelineMinimapIndexFromPointer({
|
||||
itemCount: 101,
|
||||
railTop: 100,
|
||||
railHeight: 500,
|
||||
pointerY: 999,
|
||||
}),
|
||||
).toBe(100);
|
||||
expect(resolveTimelineMinimapHasPersistentGutter(832)).toBe(false);
|
||||
expect(resolveTimelineMinimapHasPersistentGutter(863)).toBe(false);
|
||||
expect(resolveTimelineMinimapHasPersistentGutter(864)).toBe(true);
|
||||
});
|
||||
|
||||
it("anchors a sent attachment message using its measured height", async () => {
|
||||
const { MessagesTimeline } = await import("./MessagesTimeline");
|
||||
const onAnchorReady = vi.fn();
|
||||
@@ -296,7 +229,7 @@ describe("MessagesTimeline", () => {
|
||||
expect(markup).not.toContain("data-anchor-max-size=");
|
||||
expect(markup).toContain('data-content-inset-end="144"');
|
||||
expect(markup).toContain("[overflow-anchor:none]");
|
||||
expect(markup).not.toContain('data-maintain-scroll-at-end="enabled"');
|
||||
expect(markup).not.toContain("data-maintain-scroll-at-end=");
|
||||
expect(markup).toContain('data-maintain-visible-content-position="object"');
|
||||
expect(markup).toContain('data-maintain-visible-content-position-data="true"');
|
||||
expect(markup).toContain('data-maintain-visible-content-position-size="false"');
|
||||
@@ -315,11 +248,6 @@ describe("MessagesTimeline", () => {
|
||||
);
|
||||
|
||||
expect(markup).toContain("Show full message");
|
||||
expect(markup).toContain('data-maintain-scroll-at-end="enabled"');
|
||||
expect(markup).toContain('data-maintain-scroll-at-end-animated="false"');
|
||||
expect(markup).toContain('data-maintain-scroll-at-end-data-change="true"');
|
||||
expect(markup).toContain('data-maintain-scroll-at-end-item-layout="true"');
|
||||
expect(markup).toContain('data-maintain-scroll-at-end-layout="true"');
|
||||
expect(markup).toContain('data-user-message-collapsed="true"');
|
||||
expect(markup).toContain('data-user-message-fade="true"');
|
||||
expect(markup).toContain('data-user-message-footer="true"');
|
||||
|
||||
@@ -18,7 +18,6 @@ import {
|
||||
useRef,
|
||||
useState,
|
||||
type KeyboardEvent,
|
||||
type MouseEvent,
|
||||
type ReactNode,
|
||||
} from "react";
|
||||
import { flushSync } from "react-dom";
|
||||
@@ -70,14 +69,8 @@ import {
|
||||
deriveMessagesTimelineRows,
|
||||
normalizeCompactToolLabel,
|
||||
resolveAssistantMessageCopyState,
|
||||
resolveTimelineIsAtEnd,
|
||||
resolveTimelineMinimapHasPersistentGutter,
|
||||
resolveTimelineMinimapHeightStyle,
|
||||
resolveTimelineMinimapIndexFromPointer,
|
||||
resolveTimelineMinimapTopPercent,
|
||||
type StableMessagesTimelineRowsState,
|
||||
type MessagesTimelineRow,
|
||||
TIMELINE_MINIMAP_MIN_ITEMS,
|
||||
type TimelineLatestTurn,
|
||||
} from "./MessagesTimeline.logic";
|
||||
import { TerminalContextInlineChip } from "./TerminalContextInlineChip";
|
||||
@@ -178,7 +171,6 @@ interface MessagesTimelineProps {
|
||||
onAnchorSizeChanged: (messageId: MessageId, size: number) => void;
|
||||
contentInsetEndAdjustment: number;
|
||||
onIsAtEndChange: (isAtEnd: boolean) => void;
|
||||
onManualNavigation: () => void;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -211,11 +203,9 @@ export const MessagesTimeline = memo(function MessagesTimeline({
|
||||
onAnchorSizeChanged,
|
||||
contentInsetEndAdjustment,
|
||||
onIsAtEndChange,
|
||||
onManualNavigation,
|
||||
}: MessagesTimelineProps) {
|
||||
const [expandedTurnIds, setExpandedTurnIds] = useState<ReadonlySet<TurnId>>(new Set());
|
||||
const [expandedWorkGroupIds, setExpandedWorkGroupIds] = useState<ReadonlySet<string>>(new Set());
|
||||
const [minimapStripMap] = useState(() => new Map<string, HTMLSpanElement>());
|
||||
|
||||
const onToggleTurnFold = useCallback((turnId: TurnId) => {
|
||||
setExpandedTurnIds((existing) => {
|
||||
@@ -317,11 +307,6 @@ export const MessagesTimeline = memo(function MessagesTimeline({
|
||||
],
|
||||
);
|
||||
const rows = useStableRows(rawRows);
|
||||
const minimapItems = useMemo(() => deriveTimelineMinimapItems(rows), [rows]);
|
||||
const [timelineViewportElement, setTimelineViewportElement] = useState<HTMLDivElement | null>(
|
||||
null,
|
||||
);
|
||||
const [minimapHasPersistentGutter, setMinimapHasPersistentGutter] = useState(false);
|
||||
const handleAnchorReady = useCallback(
|
||||
(info: { anchorIndex: number | undefined }) => {
|
||||
if (anchorMessageId !== null && info.anchorIndex !== undefined) {
|
||||
@@ -349,62 +334,10 @@ export const MessagesTimeline = memo(function MessagesTimeline({
|
||||
|
||||
const handleScroll = useCallback(() => {
|
||||
const state = listRef.current?.getState?.();
|
||||
const isAtEnd = resolveTimelineIsAtEnd(state);
|
||||
if (isAtEnd !== undefined) {
|
||||
onIsAtEndChange(isAtEnd);
|
||||
if (state) {
|
||||
onIsAtEndChange(state.isAtEnd);
|
||||
}
|
||||
if (!state || minimapItems.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const scrollTop = state.scroll ?? 0;
|
||||
const scrollBottom = scrollTop + (state.scrollLength ?? 0);
|
||||
|
||||
for (const item of minimapItems) {
|
||||
const strip = minimapStripMap.get(item.id);
|
||||
if (!strip) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const rowTop = resolveTimelineRowTop(state, item.rowIndex);
|
||||
const rowHeight = resolveTimelineRowHeight(state, item.rowIndex);
|
||||
const inView =
|
||||
rowTop !== null &&
|
||||
rowTop < scrollBottom &&
|
||||
rowTop + Math.max(1, rowHeight ?? 1) > scrollTop;
|
||||
|
||||
strip.dataset.inView = inView ? "true" : "false";
|
||||
}
|
||||
}, [listRef, minimapItems, minimapStripMap, onIsAtEndChange]);
|
||||
|
||||
useEffect(() => {
|
||||
const frame = requestAnimationFrame(handleScroll);
|
||||
return () => cancelAnimationFrame(frame);
|
||||
}, [handleScroll, rows.length]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!timelineViewportElement) {
|
||||
return;
|
||||
}
|
||||
|
||||
const measure = () => {
|
||||
const viewportWidth = timelineViewportElement.getBoundingClientRect().width;
|
||||
const nextHasPersistentGutter = resolveTimelineMinimapHasPersistentGutter(viewportWidth);
|
||||
setMinimapHasPersistentGutter((current) =>
|
||||
current === nextHasPersistentGutter ? current : nextHasPersistentGutter,
|
||||
);
|
||||
};
|
||||
|
||||
const frame = requestAnimationFrame(measure);
|
||||
|
||||
const observer = new ResizeObserver(measure);
|
||||
observer.observe(timelineViewportElement);
|
||||
|
||||
return () => {
|
||||
cancelAnimationFrame(frame);
|
||||
observer.disconnect();
|
||||
};
|
||||
}, [timelineViewportElement, rows.length]);
|
||||
}, [listRef, onIsAtEndChange]);
|
||||
|
||||
const sharedState = useMemo<TimelineRowSharedState>(
|
||||
() => ({
|
||||
@@ -470,53 +403,25 @@ export const MessagesTimeline = memo(function MessagesTimeline({
|
||||
return (
|
||||
<TimelineRowCtx value={sharedState}>
|
||||
<TimelineRowActivityCtx value={activityState}>
|
||||
<div ref={setTimelineViewportElement} className="relative h-full min-h-0">
|
||||
<LegendList<MessagesTimelineRow>
|
||||
ref={listRef}
|
||||
data={rows}
|
||||
keyExtractor={keyExtractor}
|
||||
getItemType={getItemType}
|
||||
renderItem={renderItem}
|
||||
estimatedItemSize={90}
|
||||
initialScrollAtEnd
|
||||
{...(anchoredEndSpace ? { anchoredEndSpace } : {})}
|
||||
contentInsetEndAdjustment={contentInsetEndAdjustment}
|
||||
maintainScrollAtEnd={
|
||||
anchoredEndSpace
|
||||
? false
|
||||
: {
|
||||
animated: false,
|
||||
on: {
|
||||
dataChange: true,
|
||||
itemLayout: true,
|
||||
layout: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
maintainVisibleContentPosition={{
|
||||
data: true,
|
||||
size: false,
|
||||
}}
|
||||
onScroll={handleScroll}
|
||||
className="scrollbar-gutter-both h-full min-h-0 overflow-x-hidden overscroll-y-contain px-3 [overflow-anchor:none] sm:px-5"
|
||||
ListHeaderComponent={TIMELINE_LIST_HEADER}
|
||||
ListFooterComponent={TIMELINE_LIST_FOOTER}
|
||||
/>
|
||||
<TimelineMinimap
|
||||
items={minimapItems}
|
||||
bottomInset={contentInsetEndAdjustment}
|
||||
hasPersistentGutter={minimapHasPersistentGutter}
|
||||
stripMap={minimapStripMap}
|
||||
onSelect={(item) => {
|
||||
onManualNavigation();
|
||||
void listRef.current?.scrollToIndex({
|
||||
index: item.rowIndex,
|
||||
animated: true,
|
||||
viewOffset: 24,
|
||||
});
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<LegendList<MessagesTimelineRow>
|
||||
ref={listRef}
|
||||
data={rows}
|
||||
keyExtractor={keyExtractor}
|
||||
getItemType={getItemType}
|
||||
renderItem={renderItem}
|
||||
estimatedItemSize={90}
|
||||
initialScrollAtEnd
|
||||
{...(anchoredEndSpace ? { anchoredEndSpace } : {})}
|
||||
contentInsetEndAdjustment={contentInsetEndAdjustment}
|
||||
maintainVisibleContentPosition={{
|
||||
data: true,
|
||||
size: false,
|
||||
}}
|
||||
onScroll={handleScroll}
|
||||
className="scrollbar-gutter-both h-full min-h-0 overflow-x-hidden overscroll-y-contain px-3 [overflow-anchor:none] sm:px-5"
|
||||
ListHeaderComponent={TIMELINE_LIST_HEADER}
|
||||
ListFooterComponent={TIMELINE_LIST_FOOTER}
|
||||
/>
|
||||
</TimelineRowActivityCtx>
|
||||
</TimelineRowCtx>
|
||||
);
|
||||
@@ -530,261 +435,6 @@ function getItemType(item: MessagesTimelineRow) {
|
||||
return item.kind === "message" ? `message:${item.message.role}` : item.kind;
|
||||
}
|
||||
|
||||
interface TimelineMinimapItem {
|
||||
readonly id: string;
|
||||
readonly rowIndex: number;
|
||||
readonly userText: string | null;
|
||||
readonly assistantText: string | null;
|
||||
}
|
||||
|
||||
interface TimelinePositionState {
|
||||
readonly contentLength?: number;
|
||||
readonly scroll?: number;
|
||||
readonly scrollLength?: number;
|
||||
readonly positionAtIndex?: (index: number) => number | undefined;
|
||||
readonly sizeAtIndex?: (index: number) => number | undefined;
|
||||
}
|
||||
|
||||
function deriveTimelineMinimapItems(
|
||||
rows: ReadonlyArray<MessagesTimelineRow>,
|
||||
): TimelineMinimapItem[] {
|
||||
const items: TimelineMinimapItem[] = [];
|
||||
for (let index = 0; index < rows.length; index += 1) {
|
||||
const row = rows[index];
|
||||
if (row?.kind !== "message" || row.message.role !== "user") {
|
||||
continue;
|
||||
}
|
||||
|
||||
items.push({
|
||||
id: row.id,
|
||||
rowIndex: index,
|
||||
userText: compactMinimapPreview(row.message.text),
|
||||
assistantText: compactMinimapPreview(resolveFinalAssistantTextForTurn(rows, index)),
|
||||
});
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
function resolveFinalAssistantTextForTurn(
|
||||
rows: ReadonlyArray<MessagesTimelineRow>,
|
||||
userRowIndex: number,
|
||||
) {
|
||||
let finalAssistantText: string | null = null;
|
||||
for (let index = userRowIndex + 1; index < rows.length; index += 1) {
|
||||
const row = rows[index];
|
||||
if (row?.kind !== "message") {
|
||||
continue;
|
||||
}
|
||||
if (row.message.role === "user") {
|
||||
break;
|
||||
}
|
||||
if (row.message.role === "assistant") {
|
||||
finalAssistantText = row.message.text ?? null;
|
||||
}
|
||||
}
|
||||
return finalAssistantText;
|
||||
}
|
||||
|
||||
function compactMinimapPreview(text: string | null | undefined) {
|
||||
const compact = text?.replace(/\s+/g, " ").trim() ?? "";
|
||||
return compact.length > 0 ? compact : null;
|
||||
}
|
||||
|
||||
function resolveTimelineRowTop(state: TimelinePositionState, rowIndex: number) {
|
||||
const top = state.positionAtIndex?.(rowIndex);
|
||||
return typeof top === "number" && Number.isFinite(top) ? top : null;
|
||||
}
|
||||
|
||||
function resolveTimelineRowHeight(state: TimelinePositionState, rowIndex: number) {
|
||||
const height = state.sizeAtIndex?.(rowIndex);
|
||||
return typeof height === "number" && Number.isFinite(height) ? height : null;
|
||||
}
|
||||
|
||||
function TimelineMinimap({
|
||||
bottomInset,
|
||||
hasPersistentGutter,
|
||||
items,
|
||||
stripMap,
|
||||
onSelect,
|
||||
}: {
|
||||
bottomInset: number;
|
||||
hasPersistentGutter: boolean;
|
||||
items: ReadonlyArray<TimelineMinimapItem>;
|
||||
stripMap: Map<string, HTMLSpanElement>;
|
||||
onSelect: (item: TimelineMinimapItem) => void;
|
||||
}) {
|
||||
const [activeIndex, setActiveIndex] = useState<number | null>(null);
|
||||
|
||||
const resolvedActiveIndex =
|
||||
activeIndex !== null && activeIndex < items.length ? activeIndex : null;
|
||||
const activeItem = resolvedActiveIndex === null ? null : (items[resolvedActiveIndex] ?? null);
|
||||
const activeTopPercent =
|
||||
resolvedActiveIndex === null
|
||||
? 0
|
||||
: resolveTimelineMinimapTopPercent(resolvedActiveIndex, items.length);
|
||||
const activeTooltipTranslate =
|
||||
resolvedActiveIndex === null
|
||||
? "-50%"
|
||||
: resolvedActiveIndex === 0
|
||||
? "0%"
|
||||
: resolvedActiveIndex === items.length - 1
|
||||
? "-100%"
|
||||
: "-50%";
|
||||
|
||||
const resolveActiveIndexFromPointer = useCallback(
|
||||
(event: MouseEvent<HTMLElement>) => {
|
||||
const rect = event.currentTarget.getBoundingClientRect();
|
||||
return resolveTimelineMinimapIndexFromPointer({
|
||||
itemCount: items.length,
|
||||
railTop: rect.top,
|
||||
railHeight: rect.height,
|
||||
pointerY: event.clientY,
|
||||
});
|
||||
},
|
||||
[items.length],
|
||||
);
|
||||
|
||||
const updateActiveIndexFromPointer = useCallback(
|
||||
(event: MouseEvent<HTMLElement>) => {
|
||||
const nextIndex = resolveActiveIndexFromPointer(event);
|
||||
setActiveIndex(nextIndex);
|
||||
},
|
||||
[resolveActiveIndexFromPointer],
|
||||
);
|
||||
|
||||
const moveActiveIndex = useCallback(
|
||||
(delta: number) => {
|
||||
setActiveIndex((current) => {
|
||||
const base = current ?? 0;
|
||||
return Math.max(0, Math.min(items.length - 1, base + delta));
|
||||
});
|
||||
},
|
||||
[items.length],
|
||||
);
|
||||
|
||||
if (items.length < TIMELINE_MINIMAP_MIN_ITEMS) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const safeBottomInset = Math.max(0, Math.ceil(bottomInset));
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
"group/minimap pointer-events-auto absolute top-0 left-0 z-40 hidden w-18 [@media(pointer:fine)]:block",
|
||||
hasPersistentGutter
|
||||
? "opacity-100"
|
||||
: "opacity-0 transition-opacity duration-150 hover:opacity-100 focus-within:opacity-100",
|
||||
)}
|
||||
data-testid="timeline-minimap"
|
||||
data-persistent-gutter={hasPersistentGutter ? "true" : "false"}
|
||||
style={{ bottom: safeBottomInset }}
|
||||
>
|
||||
<div className="relative h-full w-full select-none">
|
||||
<button
|
||||
aria-label={`Jump to message: ${activeItem?.userText ?? "User message"}`}
|
||||
className="pointer-events-auto absolute top-1/2 left-3 w-10 -translate-y-1/2 cursor-pointer bg-transparent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70"
|
||||
onBlur={() => setActiveIndex(null)}
|
||||
onClick={(event) => {
|
||||
const nextIndex = resolveActiveIndexFromPointer(event);
|
||||
const nextItem = nextIndex === null ? null : (items[nextIndex] ?? null);
|
||||
if (nextItem) {
|
||||
onSelect(nextItem);
|
||||
}
|
||||
event.currentTarget.blur();
|
||||
}}
|
||||
onFocus={() => setActiveIndex((current) => current ?? 0)}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key === "ArrowDown") {
|
||||
event.preventDefault();
|
||||
moveActiveIndex(1);
|
||||
} else if (event.key === "ArrowUp") {
|
||||
event.preventDefault();
|
||||
moveActiveIndex(-1);
|
||||
} else if (event.key === "Home") {
|
||||
event.preventDefault();
|
||||
setActiveIndex(0);
|
||||
} else if (event.key === "End") {
|
||||
event.preventDefault();
|
||||
setActiveIndex(items.length - 1);
|
||||
} else if (event.key === "Enter" || event.key === " ") {
|
||||
event.preventDefault();
|
||||
if (activeItem) {
|
||||
onSelect(activeItem);
|
||||
}
|
||||
}
|
||||
}}
|
||||
onMouseLeave={() => setActiveIndex(null)}
|
||||
onMouseMove={updateActiveIndexFromPointer}
|
||||
onMouseDown={(event) => {
|
||||
event.preventDefault();
|
||||
}}
|
||||
style={{ height: resolveTimelineMinimapHeightStyle(items.length) }}
|
||||
type="button"
|
||||
>
|
||||
<div className="absolute top-0 left-3 h-full w-px bg-border/15" />
|
||||
{items.map((item, index) => {
|
||||
const top = `${resolveTimelineMinimapTopPercent(index, items.length)}%`;
|
||||
const activeDistance =
|
||||
resolvedActiveIndex === null ? null : Math.abs(index - resolvedActiveIndex);
|
||||
return (
|
||||
<span
|
||||
aria-hidden="true"
|
||||
className={cn(
|
||||
"pointer-events-none absolute left-0 h-0.5 -translate-y-1/2 rounded-full bg-muted-foreground/35 transition-[background-color,width] duration-150 data-[in-view=true]:bg-foreground/90",
|
||||
activeDistance === 0
|
||||
? "w-6 bg-muted-foreground/75"
|
||||
: activeDistance === 1
|
||||
? "w-4"
|
||||
: activeDistance === 2
|
||||
? "w-2.5"
|
||||
: "w-2",
|
||||
)}
|
||||
data-in-view="false"
|
||||
data-minimap-strip
|
||||
key={item.id}
|
||||
ref={(node) => {
|
||||
if (node) {
|
||||
stripMap.set(item.id, node);
|
||||
} else {
|
||||
stripMap.delete(item.id);
|
||||
}
|
||||
}}
|
||||
style={{ top }}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
{activeItem ? (
|
||||
<span
|
||||
className="pointer-events-none absolute left-8 w-80 rounded-xl border border-border/70 bg-popover/95 p-3 text-left text-popover-foreground shadow-xl shadow-black/25 backdrop-blur"
|
||||
style={{
|
||||
top: `${activeTopPercent}%`,
|
||||
transform: `translateY(${activeTooltipTranslate})`,
|
||||
}}
|
||||
>
|
||||
<span className="block max-w-full overflow-hidden text-ellipsis whitespace-nowrap text-sm font-medium leading-5">
|
||||
{activeItem.userText ?? "User message"}
|
||||
</span>
|
||||
{activeItem.assistantText ? (
|
||||
<span
|
||||
className="mt-1 max-h-[3.75rem] overflow-hidden text-muted-foreground text-sm leading-5"
|
||||
style={{
|
||||
display: "-webkit-box",
|
||||
WebkitBoxOrient: "vertical",
|
||||
WebkitLineClamp: 3,
|
||||
}}
|
||||
>
|
||||
{activeItem.assistantText}
|
||||
</span>
|
||||
) : null}
|
||||
</span>
|
||||
) : null}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// TimelineRowContent — the actual row component
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
@@ -43,10 +43,6 @@ type ModelPickerItem = {
|
||||
|
||||
const EMPTY_MODEL_JUMP_LABELS = new Map<string, string>();
|
||||
|
||||
function normalizeModelPickerSearchQuery(value: string): string {
|
||||
return value.trim();
|
||||
}
|
||||
|
||||
// Split a `${instanceId}:${slug}` combobox key back into its pieces. Slugs
|
||||
// can contain colons (e.g. some vendor model ids), so we only split on the
|
||||
// first colon — anything after that is the slug.
|
||||
@@ -61,115 +57,6 @@ function splitInstanceModelKey(key: string): { instanceId: ProviderInstanceId; s
|
||||
};
|
||||
}
|
||||
|
||||
function useModelPickerJumpShortcuts(input: {
|
||||
readonly keybindings: ResolvedKeybindingsConfig;
|
||||
readonly modelJumpModelKeys: ReadonlyArray<string>;
|
||||
readonly modelJumpShortcutContext: {
|
||||
readonly terminalFocus: false;
|
||||
readonly terminalOpen: boolean;
|
||||
readonly modelPickerOpen: true;
|
||||
};
|
||||
readonly onModelSelect: (modelSlug: string, instanceId: ProviderInstanceId) => void;
|
||||
}) {
|
||||
const { keybindings, modelJumpModelKeys, modelJumpShortcutContext, onModelSelect } = input;
|
||||
|
||||
useEffect(() => {
|
||||
const onWindowKeyDown = (event: globalThis.KeyboardEvent) => {
|
||||
if (event.defaultPrevented || event.repeat) {
|
||||
return;
|
||||
}
|
||||
|
||||
const command = resolveShortcutCommand(event, keybindings, {
|
||||
platform: navigator.platform,
|
||||
context: modelJumpShortcutContext,
|
||||
});
|
||||
const jumpIndex = modelPickerJumpIndexFromCommand(command ?? "");
|
||||
if (jumpIndex === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
const targetModelKey = modelJumpModelKeys[jumpIndex];
|
||||
if (!targetModelKey) {
|
||||
return;
|
||||
}
|
||||
const { instanceId, slug } = splitInstanceModelKey(targetModelKey);
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
onModelSelect(slug, instanceId);
|
||||
};
|
||||
|
||||
window.addEventListener("keydown", onWindowKeyDown, true);
|
||||
|
||||
return () => {
|
||||
window.removeEventListener("keydown", onWindowKeyDown, true);
|
||||
};
|
||||
}, [keybindings, modelJumpModelKeys, modelJumpShortcutContext, onModelSelect]);
|
||||
}
|
||||
|
||||
function ModelPickerSearchInput(props: {
|
||||
readonly focusRequest: number;
|
||||
readonly onSearchQueryChange: (query: string) => void;
|
||||
readonly onRequestClose: (() => void) | undefined;
|
||||
readonly onHighlightedModelSelect: () => boolean;
|
||||
}) {
|
||||
const [rawSearchQuery, setRawSearchQuery] = useState("");
|
||||
const searchInputRef = useRef<HTMLInputElement>(null);
|
||||
const normalizedSearchQueryRef = useRef("");
|
||||
|
||||
useLayoutEffect(() => {
|
||||
searchInputRef.current?.focus({ preventScroll: true });
|
||||
const frame = window.requestAnimationFrame(() => {
|
||||
searchInputRef.current?.focus({ preventScroll: true });
|
||||
});
|
||||
return () => {
|
||||
window.cancelAnimationFrame(frame);
|
||||
};
|
||||
}, [props.focusRequest]);
|
||||
|
||||
return (
|
||||
<ComboboxInput
|
||||
ref={searchInputRef}
|
||||
className="[&_input]:h-6.5 [&_input]:font-sans [&_input]:leading-6.5"
|
||||
inputClassName="rounded-none bg-transparent text-sm"
|
||||
placeholder="Search models..."
|
||||
showTrigger={false}
|
||||
startAddon={
|
||||
<SearchIcon className="-translate-x-0.5 size-4 shrink-0 text-muted-foreground/55" />
|
||||
}
|
||||
value={rawSearchQuery}
|
||||
onChange={(event) => {
|
||||
const nextRawSearchQuery = event.target.value;
|
||||
setRawSearchQuery(nextRawSearchQuery);
|
||||
const nextNormalizedSearchQuery = normalizeModelPickerSearchQuery(nextRawSearchQuery);
|
||||
if (nextNormalizedSearchQuery === normalizedSearchQueryRef.current) {
|
||||
return;
|
||||
}
|
||||
normalizedSearchQueryRef.current = nextNormalizedSearchQuery;
|
||||
props.onSearchQueryChange(nextNormalizedSearchQuery);
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key === "Escape") {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
props.onRequestClose?.();
|
||||
return;
|
||||
}
|
||||
if (event.key === "Enter" && props.onHighlightedModelSelect()) {
|
||||
(event as typeof event & { preventBaseUIHandler?: () => void }).preventBaseUIHandler?.();
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return;
|
||||
}
|
||||
event.stopPropagation();
|
||||
}}
|
||||
onMouseDown={(event) => event.stopPropagation()}
|
||||
onTouchStart={(event) => event.stopPropagation()}
|
||||
size="sm"
|
||||
unstyled
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export const ModelPickerContent = memo(function ModelPickerContent(props: {
|
||||
/** The instance currently selected in the composer (combobox "value"). */
|
||||
activeInstanceId: ProviderInstanceId;
|
||||
@@ -212,7 +99,7 @@ export const ModelPickerContent = memo(function ModelPickerContent(props: {
|
||||
const [searchQuery, setSearchQuery] = useState("");
|
||||
const [showTopScrollFade, setShowTopScrollFade] = useState(false);
|
||||
const [showBottomScrollFade, setShowBottomScrollFade] = useState(false);
|
||||
const [searchFocusRequest, setSearchFocusRequest] = useState(0);
|
||||
const searchInputRef = useRef<HTMLInputElement>(null);
|
||||
const modelListRef = useRef<LegendListRef | null>(null);
|
||||
const highlightedModelKeyRef = useRef<string | null>(null);
|
||||
const favorites = useClientSettings((s) => s.favorites ?? []);
|
||||
@@ -232,10 +119,33 @@ export const ModelPickerContent = memo(function ModelPickerContent(props: {
|
||||
);
|
||||
const updateSettings = useUpdateClientSettings();
|
||||
|
||||
const handleSelectInstance = (instanceId: ProviderInstanceId | "favorites") => {
|
||||
setSelectedInstanceId(instanceId);
|
||||
setSearchFocusRequest((request) => request + 1);
|
||||
};
|
||||
const focusSearchInput = useCallback(() => {
|
||||
searchInputRef.current?.focus({ preventScroll: true });
|
||||
}, []);
|
||||
|
||||
const handleSelectInstance = useCallback(
|
||||
(instanceId: ProviderInstanceId | "favorites") => {
|
||||
setSelectedInstanceId(instanceId);
|
||||
window.requestAnimationFrame(() => {
|
||||
focusSearchInput();
|
||||
});
|
||||
},
|
||||
[focusSearchInput],
|
||||
);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
focusSearchInput();
|
||||
const frame = window.requestAnimationFrame(() => {
|
||||
focusSearchInput();
|
||||
});
|
||||
const timeout = window.setTimeout(() => {
|
||||
focusSearchInput();
|
||||
}, 0);
|
||||
return () => {
|
||||
window.cancelAnimationFrame(frame);
|
||||
window.clearTimeout(timeout);
|
||||
};
|
||||
}, [focusSearchInput]);
|
||||
|
||||
// Create a Set for efficient lookup. Favorites are keyed by
|
||||
// `${instanceId}:${slug}`; the storage schema widened from ProviderDriverKind
|
||||
@@ -311,7 +221,7 @@ export const ModelPickerContent = memo(function ModelPickerContent(props: {
|
||||
}, [modelOptionsByInstance, entryByInstanceId, readyInstanceSet]);
|
||||
|
||||
const isLocked = props.lockedProvider !== null;
|
||||
const isSearching = searchQuery.length > 0;
|
||||
const isSearching = searchQuery.trim().length > 0;
|
||||
const lockedDisabledInstanceIds = useMemo(() => {
|
||||
if (!isLocked) {
|
||||
return undefined;
|
||||
@@ -351,7 +261,7 @@ export const ModelPickerContent = memo(function ModelPickerContent(props: {
|
||||
let result = flatModels;
|
||||
|
||||
// Apply tokenized fuzzy search across the combined provider/model search fields.
|
||||
if (searchQuery) {
|
||||
if (searchQuery.trim()) {
|
||||
const rankedMatches = result
|
||||
.map((model) => ({
|
||||
model,
|
||||
@@ -475,15 +385,6 @@ export const ModelPickerContent = memo(function ModelPickerContent(props: {
|
||||
},
|
||||
[entryByInstanceId, getModelDisabledReason, modelOptionsByInstance, onInstanceModelChange],
|
||||
);
|
||||
const selectHighlightedModel = () => {
|
||||
const highlightedModelKey = highlightedModelKeyRef.current;
|
||||
if (!highlightedModelKey) {
|
||||
return false;
|
||||
}
|
||||
const { instanceId, slug } = splitInstanceModelKey(highlightedModelKey);
|
||||
handleModelSelect(slug, instanceId);
|
||||
return true;
|
||||
};
|
||||
|
||||
const toggleFavorite = useCallback(
|
||||
(instanceId: ProviderInstanceId, model: string) => {
|
||||
@@ -571,14 +472,41 @@ export const ModelPickerContent = memo(function ModelPickerContent(props: {
|
||||
return mapping.size > 0 ? mapping : EMPTY_MODEL_JUMP_LABELS;
|
||||
}, [keybindings, modelJumpCommandByKey, modelJumpShortcutContext]);
|
||||
|
||||
useModelPickerJumpShortcuts({
|
||||
keybindings,
|
||||
modelJumpModelKeys,
|
||||
modelJumpShortcutContext,
|
||||
onModelSelect: handleModelSelect,
|
||||
});
|
||||
useEffect(() => {
|
||||
const onWindowKeyDown = (event: globalThis.KeyboardEvent) => {
|
||||
if (event.defaultPrevented || event.repeat) {
|
||||
return;
|
||||
}
|
||||
|
||||
const command = resolveShortcutCommand(event, keybindings, {
|
||||
platform: navigator.platform,
|
||||
context: modelJumpShortcutContext,
|
||||
});
|
||||
const jumpIndex = modelPickerJumpIndexFromCommand(command ?? "");
|
||||
if (jumpIndex === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
const targetModelKey = modelJumpModelKeys[jumpIndex];
|
||||
if (!targetModelKey) {
|
||||
return;
|
||||
}
|
||||
const { instanceId, slug } = splitInstanceModelKey(targetModelKey);
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
handleModelSelect(slug, instanceId);
|
||||
};
|
||||
|
||||
window.addEventListener("keydown", onWindowKeyDown, true);
|
||||
|
||||
return () => {
|
||||
window.removeEventListener("keydown", onWindowKeyDown, true);
|
||||
};
|
||||
}, [handleModelSelect, keybindings, modelJumpModelKeys, modelJumpShortcutContext]);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
setShowTopScrollFade(false);
|
||||
setShowBottomScrollFade(filteredModelKeys.length > 5);
|
||||
let nestedFrame = 0;
|
||||
const frame = window.requestAnimationFrame(() => {
|
||||
updateModelListScrollFades();
|
||||
@@ -649,11 +577,42 @@ export const ModelPickerContent = memo(function ModelPickerContent(props: {
|
||||
{/* Search bar */}
|
||||
<div className="px-4 pt-2.5">
|
||||
<div className="-translate-y-px border-b border-border/70 pb-2.5 transition-colors focus-within:border-ring">
|
||||
<ModelPickerSearchInput
|
||||
focusRequest={searchFocusRequest}
|
||||
onSearchQueryChange={setSearchQuery}
|
||||
onRequestClose={props.onRequestClose}
|
||||
onHighlightedModelSelect={selectHighlightedModel}
|
||||
<ComboboxInput
|
||||
ref={searchInputRef}
|
||||
className="[&_input]:h-6.5 [&_input]:font-sans [&_input]:leading-6.5"
|
||||
inputClassName="rounded-none bg-transparent text-sm"
|
||||
placeholder="Search models..."
|
||||
showTrigger={false}
|
||||
startAddon={
|
||||
<SearchIcon className="-translate-x-0.5 size-4 shrink-0 text-muted-foreground/55" />
|
||||
}
|
||||
value={searchQuery}
|
||||
onChange={(e) => setSearchQuery(e.target.value)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Escape") {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
props.onRequestClose?.();
|
||||
return;
|
||||
}
|
||||
if (e.key === "Enter" && highlightedModelKeyRef.current) {
|
||||
(
|
||||
e as typeof e & { preventBaseUIHandler?: () => void }
|
||||
).preventBaseUIHandler?.();
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
const { instanceId, slug } = splitInstanceModelKey(
|
||||
highlightedModelKeyRef.current,
|
||||
);
|
||||
handleModelSelect(slug, instanceId);
|
||||
return;
|
||||
}
|
||||
e.stopPropagation();
|
||||
}}
|
||||
onMouseDown={(e) => e.stopPropagation()}
|
||||
onTouchStart={(e) => e.stopPropagation()}
|
||||
size="sm"
|
||||
unstyled
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,138 +0,0 @@
|
||||
import { describe, expect, it } from "vite-plus/test";
|
||||
import { getAnchoredTurnMetrics, getRowBottom } from "./timelineScrollAnchoring";
|
||||
|
||||
function buildState({
|
||||
positions,
|
||||
sizes,
|
||||
scroll = 0,
|
||||
scrollLength = 700,
|
||||
}: {
|
||||
readonly positions: readonly number[];
|
||||
readonly sizes: readonly number[];
|
||||
readonly scroll?: number;
|
||||
readonly scrollLength?: number;
|
||||
}) {
|
||||
return {
|
||||
data: positions.map((_, index) => index),
|
||||
scroll,
|
||||
scrollLength,
|
||||
positionAtIndex: (index: number) => positions[index],
|
||||
sizeAtIndex: (index: number) => sizes[index],
|
||||
};
|
||||
}
|
||||
|
||||
describe("timeline scroll anchoring", () => {
|
||||
it("measures row bottoms from LegendList row position and size", () => {
|
||||
const state = buildState({
|
||||
positions: [0, 120],
|
||||
sizes: [80, 40],
|
||||
});
|
||||
|
||||
expect(getRowBottom(state, 1)).toBe(160);
|
||||
});
|
||||
|
||||
it("treats the active turn as fitting when it fits above the composer", () => {
|
||||
const state = buildState({
|
||||
positions: [0, 300, 460],
|
||||
sizes: [240, 80, 140],
|
||||
scrollLength: 760,
|
||||
});
|
||||
|
||||
const metrics = getAnchoredTurnMetrics({
|
||||
state,
|
||||
anchorIndex: 1,
|
||||
composerOverlayHeight: 180,
|
||||
anchorOffset: 16,
|
||||
});
|
||||
|
||||
expect(metrics?.turnHeight).toBe(300);
|
||||
expect(metrics?.usableViewportHeight).toBe(564);
|
||||
expect(metrics?.overflowsUsableViewport).toBe(false);
|
||||
expect(metrics?.targetScrollToRevealEnd).toBe(36);
|
||||
expect(metrics?.scrollDeltaToRevealEnd).toBe(36);
|
||||
});
|
||||
|
||||
it("targets the real row end instead of any temporary reserved tail", () => {
|
||||
const state = buildState({
|
||||
positions: [0, 1720, 1880],
|
||||
sizes: [1600, 80, 120],
|
||||
scroll: 1900,
|
||||
scrollLength: 760,
|
||||
});
|
||||
|
||||
const metrics = getAnchoredTurnMetrics({
|
||||
state,
|
||||
anchorIndex: 1,
|
||||
composerOverlayHeight: 180,
|
||||
anchorOffset: 16,
|
||||
});
|
||||
|
||||
expect(metrics?.lastBottom).toBe(2000);
|
||||
expect(metrics?.targetScrollToRevealEnd).toBe(1436);
|
||||
expect(metrics?.scrollDeltaToRevealEnd).toBe(0);
|
||||
});
|
||||
|
||||
it("reports overflow only for the current anchored turn", () => {
|
||||
const state = buildState({
|
||||
positions: [0, 900, 1180],
|
||||
sizes: [800, 220, 300],
|
||||
scroll: 900,
|
||||
scrollLength: 760,
|
||||
});
|
||||
|
||||
const metrics = getAnchoredTurnMetrics({
|
||||
state,
|
||||
anchorIndex: 1,
|
||||
composerOverlayHeight: 180,
|
||||
anchorOffset: 16,
|
||||
});
|
||||
|
||||
expect(metrics?.turnHeight).toBe(580);
|
||||
expect(metrics?.usableViewportHeight).toBe(564);
|
||||
expect(metrics?.overflowsUsableViewport).toBe(true);
|
||||
});
|
||||
|
||||
it("returns the minimal positive scroll delta needed to reveal the turn end", () => {
|
||||
const state = buildState({
|
||||
positions: [0, 900, 1180],
|
||||
sizes: [800, 220, 360],
|
||||
scroll: 900,
|
||||
scrollLength: 760,
|
||||
});
|
||||
|
||||
const metrics = getAnchoredTurnMetrics({
|
||||
state,
|
||||
anchorIndex: 1,
|
||||
composerOverlayHeight: 180,
|
||||
anchorOffset: 16,
|
||||
});
|
||||
|
||||
expect(metrics?.lastBottom).toBe(1540);
|
||||
expect(metrics?.visibleUsableBottom).toBe(1464);
|
||||
expect(metrics?.scrollDeltaToRevealEnd).toBe(76);
|
||||
});
|
||||
|
||||
it("subtracts composer height from usable viewport height", () => {
|
||||
const state = buildState({
|
||||
positions: [0, 300],
|
||||
sizes: [120, 470],
|
||||
scrollLength: 700,
|
||||
});
|
||||
|
||||
const withoutComposer = getAnchoredTurnMetrics({
|
||||
state,
|
||||
anchorIndex: 1,
|
||||
composerOverlayHeight: 0,
|
||||
anchorOffset: 16,
|
||||
});
|
||||
const withComposer = getAnchoredTurnMetrics({
|
||||
state,
|
||||
anchorIndex: 1,
|
||||
composerOverlayHeight: 220,
|
||||
anchorOffset: 16,
|
||||
});
|
||||
|
||||
expect(withoutComposer?.overflowsUsableViewport).toBe(false);
|
||||
expect(withComposer?.overflowsUsableViewport).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -1,78 +0,0 @@
|
||||
export type TimelineScrollMode = "following-end" | "anchoring-new-turn" | "free-scrolling";
|
||||
|
||||
export interface TimelineListMeasurementState {
|
||||
readonly data: readonly unknown[];
|
||||
readonly scroll: number;
|
||||
readonly scrollLength: number;
|
||||
readonly positionAtIndex: (index: number) => number | undefined;
|
||||
readonly sizeAtIndex: (index: number) => number | undefined;
|
||||
}
|
||||
|
||||
export interface AnchoredTurnMetrics {
|
||||
readonly anchorTop: number;
|
||||
readonly lastBottom: number;
|
||||
readonly turnHeight: number;
|
||||
readonly usableViewportHeight: number;
|
||||
readonly visibleUsableBottom: number;
|
||||
readonly overflowsUsableViewport: boolean;
|
||||
readonly targetScrollToRevealEnd: number;
|
||||
readonly scrollDeltaToRevealEnd: number;
|
||||
}
|
||||
|
||||
export function getRowBottom(state: TimelineListMeasurementState, index: number): number | null {
|
||||
const top = state.positionAtIndex(index);
|
||||
const height = state.sizeAtIndex(index);
|
||||
if (
|
||||
typeof top !== "number" ||
|
||||
typeof height !== "number" ||
|
||||
!Number.isFinite(top) ||
|
||||
!Number.isFinite(height)
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return top + Math.max(1, height);
|
||||
}
|
||||
|
||||
export function getAnchoredTurnMetrics({
|
||||
state,
|
||||
anchorIndex,
|
||||
composerOverlayHeight,
|
||||
anchorOffset,
|
||||
}: {
|
||||
readonly state: TimelineListMeasurementState;
|
||||
readonly anchorIndex: number;
|
||||
readonly composerOverlayHeight: number;
|
||||
readonly anchorOffset: number;
|
||||
}): AnchoredTurnMetrics | null {
|
||||
if (state.data.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const boundedAnchorIndex = Math.max(0, Math.min(anchorIndex, state.data.length - 1));
|
||||
const anchorTop = state.positionAtIndex(boundedAnchorIndex);
|
||||
const lastBottom = getRowBottom(state, state.data.length - 1);
|
||||
if (typeof anchorTop !== "number" || !Number.isFinite(anchorTop) || lastBottom === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const usableViewportHeight = Math.max(
|
||||
0,
|
||||
state.scrollLength - composerOverlayHeight - anchorOffset,
|
||||
);
|
||||
const turnHeight = Math.max(0, lastBottom - anchorTop);
|
||||
const visibleUsableBottom = state.scroll + usableViewportHeight;
|
||||
const targetScrollToRevealEnd = Math.max(0, lastBottom - usableViewportHeight);
|
||||
const scrollDeltaToRevealEnd = Math.max(0, targetScrollToRevealEnd - state.scroll);
|
||||
|
||||
return {
|
||||
anchorTop,
|
||||
lastBottom,
|
||||
turnHeight,
|
||||
usableViewportHeight,
|
||||
visibleUsableBottom,
|
||||
overflowsUsableViewport: turnHeight > usableViewportHeight,
|
||||
targetScrollToRevealEnd,
|
||||
scrollDeltaToRevealEnd,
|
||||
};
|
||||
}
|
||||
@@ -32,7 +32,7 @@ import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
|
||||
*/
|
||||
const CUSTOM_MODEL_PLACEHOLDER_BY_KIND: Partial<Record<ProviderDriverKind, string>> = {
|
||||
[ProviderDriverKind.make("codex")]: "gpt-6.7-codex-ultra-preview",
|
||||
[ProviderDriverKind.make("claudeAgent")]: "claude-sonnet-5",
|
||||
[ProviderDriverKind.make("claudeAgent")]: "claude-sonnet-5-0",
|
||||
[ProviderDriverKind.make("cursor")]: "claude-sonnet-4-6",
|
||||
[ProviderDriverKind.make("opencode")]: "openai/gpt-5",
|
||||
};
|
||||
|
||||
@@ -812,35 +812,12 @@ label:has(> select#reasoning-effort) select {
|
||||
#ec4899 90%,
|
||||
#ff6b6b 100%
|
||||
);
|
||||
position: relative;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.ultrathink-frame::before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
border-radius: inherit;
|
||||
padding: 2px;
|
||||
background-image: var(--ultrathink-spectrum);
|
||||
background-size: 220% 220%;
|
||||
pointer-events: none;
|
||||
filter: saturate(0.82) brightness(0.92);
|
||||
-webkit-mask:
|
||||
linear-gradient(#000 0 0) content-box,
|
||||
linear-gradient(#000 0 0);
|
||||
-webkit-mask-composite: xor;
|
||||
mask:
|
||||
linear-gradient(#000 0 0) content-box,
|
||||
linear-gradient(#000 0 0);
|
||||
mask-composite: exclude;
|
||||
animation: ultrathink-rainbow 10s linear infinite;
|
||||
}
|
||||
|
||||
.ultrathink-frame > * {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.ultrathink-chroma {
|
||||
animation: ultrathink-chroma-shift 10s linear infinite;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@t3tools/contracts",
|
||||
"version": "0.0.28",
|
||||
"version": "0.0.27",
|
||||
"private": true,
|
||||
"files": [
|
||||
"dist"
|
||||
|
||||
@@ -138,7 +138,7 @@ export const DEFAULT_GIT_TEXT_GENERATION_MODEL = "gpt-5.4-mini";
|
||||
|
||||
export const DEFAULT_MODEL_BY_PROVIDER: Partial<Record<ProviderDriverKind, string>> = {
|
||||
[CODEX_DRIVER_KIND]: DEFAULT_MODEL,
|
||||
[CLAUDE_DRIVER_KIND]: "claude-sonnet-5",
|
||||
[CLAUDE_DRIVER_KIND]: "claude-sonnet-4-6",
|
||||
[CURSOR_DRIVER_KIND]: "auto",
|
||||
[GROK_DRIVER_KIND]: "grok-build",
|
||||
[OPENCODE_DRIVER_KIND]: "openai/gpt-5",
|
||||
@@ -174,10 +174,7 @@ export const MODEL_SLUG_ALIASES_BY_PROVIDER: Partial<
|
||||
"opus-4.6": "claude-opus-4-6",
|
||||
"claude-opus-4.6": "claude-opus-4-6",
|
||||
"claude-opus-4-6-20251117": "claude-opus-4-6",
|
||||
sonnet: "claude-sonnet-5",
|
||||
"sonnet-5": "claude-sonnet-5",
|
||||
"claude-sonnet-5.0": "claude-sonnet-5",
|
||||
"claude-sonnet-5-0": "claude-sonnet-5",
|
||||
sonnet: "claude-sonnet-4-6",
|
||||
"sonnet-4.6": "claude-sonnet-4-6",
|
||||
"claude-sonnet-4.6": "claude-sonnet-4-6",
|
||||
"claude-sonnet-4-6-20251117": "claude-sonnet-4-6",
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
import { describe, expect, it } from "vite-plus/test";
|
||||
import { ProviderInstanceId, type ModelCapabilities } from "@t3tools/contracts";
|
||||
import {
|
||||
DEFAULT_MODEL,
|
||||
ProviderDriverKind,
|
||||
ProviderInstanceId,
|
||||
type ModelCapabilities,
|
||||
} from "@t3tools/contracts";
|
||||
|
||||
import {
|
||||
applyClaudePromptEffortPrefix,
|
||||
buildProviderOptionSelectionsFromDescriptors,
|
||||
createModelCapabilities,
|
||||
createModelSelection,
|
||||
@@ -10,6 +16,11 @@ import {
|
||||
getProviderOptionDescriptors,
|
||||
getProviderOptionBooleanSelectionValue,
|
||||
getProviderOptionStringSelectionValue,
|
||||
isClaudeUltrathinkPrompt,
|
||||
normalizeModelSlug,
|
||||
resolveModelSlugForProvider,
|
||||
resolveSelectableModel,
|
||||
trimOrNull,
|
||||
} from "./model.ts";
|
||||
|
||||
const codexCaps: ModelCapabilities = createModelCapabilities({
|
||||
@@ -59,6 +70,82 @@ const claudeCaps: ModelCapabilities = createModelCapabilities({
|
||||
],
|
||||
});
|
||||
|
||||
describe("normalizeModelSlug", () => {
|
||||
it("maps known aliases to canonical slugs", () => {
|
||||
const claude = ProviderDriverKind.make("claudeAgent");
|
||||
expect(normalizeModelSlug("gpt-5-codex")).toBe("gpt-5.4");
|
||||
expect(normalizeModelSlug("5.3")).toBe("gpt-5.3-codex");
|
||||
expect(normalizeModelSlug("sonnet", claude)).toBe("claude-sonnet-4-6");
|
||||
});
|
||||
|
||||
it("returns null for empty or missing values", () => {
|
||||
expect(normalizeModelSlug("")).toBeNull();
|
||||
expect(normalizeModelSlug(" ")).toBeNull();
|
||||
expect(normalizeModelSlug(null)).toBeNull();
|
||||
expect(normalizeModelSlug(undefined)).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveModelSlugForProvider", () => {
|
||||
it("returns defaults when the model is missing", () => {
|
||||
expect(resolveModelSlugForProvider(ProviderDriverKind.make("codex"), undefined)).toBe(
|
||||
DEFAULT_MODEL,
|
||||
);
|
||||
expect(resolveModelSlugForProvider(ProviderDriverKind.make("ollama"), undefined)).toBe(
|
||||
DEFAULT_MODEL,
|
||||
);
|
||||
expect(resolveModelSlugForProvider(ProviderDriverKind.make("grok"), undefined)).toBe(
|
||||
"grok-build",
|
||||
);
|
||||
});
|
||||
|
||||
it("preserves normalized unknown models", () => {
|
||||
expect(
|
||||
resolveModelSlugForProvider(ProviderDriverKind.make("codex"), "custom/internal-model"),
|
||||
).toBe("custom/internal-model");
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveSelectableModel", () => {
|
||||
it("resolves exact slugs, labels, and aliases", () => {
|
||||
const options = [
|
||||
{ slug: "gpt-5.3-codex", name: "GPT-5.3 Codex" },
|
||||
{ slug: "claude-sonnet-4-6", name: "Claude Sonnet 4.6" },
|
||||
];
|
||||
expect(resolveSelectableModel(ProviderDriverKind.make("codex"), "gpt-5.3-codex", options)).toBe(
|
||||
"gpt-5.3-codex",
|
||||
);
|
||||
expect(resolveSelectableModel(ProviderDriverKind.make("codex"), "gpt-5.3 codex", options)).toBe(
|
||||
"gpt-5.3-codex",
|
||||
);
|
||||
expect(resolveSelectableModel(ProviderDriverKind.make("claudeAgent"), "sonnet", options)).toBe(
|
||||
"claude-sonnet-4-6",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("misc helpers", () => {
|
||||
it("detects ultrathink prompts", () => {
|
||||
expect(isClaudeUltrathinkPrompt("Please ultrathink about this")).toBe(true);
|
||||
expect(isClaudeUltrathinkPrompt("Ultrathink:\nInvestigate")).toBe(true);
|
||||
expect(isClaudeUltrathinkPrompt("Investigate")).toBe(false);
|
||||
});
|
||||
|
||||
it("prefixes ultrathink prompts once", () => {
|
||||
expect(applyClaudePromptEffortPrefix("Investigate", "ultrathink")).toBe(
|
||||
"Ultrathink:\nInvestigate",
|
||||
);
|
||||
expect(applyClaudePromptEffortPrefix("Ultrathink:\nInvestigate", "ultrathink")).toBe(
|
||||
"Ultrathink:\nInvestigate",
|
||||
);
|
||||
});
|
||||
|
||||
it("trims strings to null", () => {
|
||||
expect(trimOrNull(" hi ")).toBe("hi");
|
||||
expect(trimOrNull(" ")).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("descriptor helpers", () => {
|
||||
it("applies selection values to capability descriptors", () => {
|
||||
expect(
|
||||
|
||||
Generated
+10
-10
Reference in new issue
Block a user