Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d9380cdecb |
No files matched your search
@@ -147,7 +147,7 @@ import { ExpandedImageDialog } from "./chat/ExpandedImageDialog";
|
||||
import { PullRequestThreadDialog } from "./PullRequestThreadDialog";
|
||||
import { MessagesTimeline } from "./chat/MessagesTimeline";
|
||||
import { ChatHeader } from "./chat/ChatHeader";
|
||||
import { type ExpandedImagePreview } from "./chat/ExpandedImagePreview";
|
||||
import { getExpandedImagePreviewKey, type ExpandedImagePreview } from "./chat/ExpandedImagePreview";
|
||||
import { NoActiveThreadState } from "./NoActiveThreadState";
|
||||
import { resolveEffectiveEnvMode, resolveEnvironmentOptionLabel } from "./BranchToolbar.logic";
|
||||
import { ProviderStatusBanner } from "./chat/ProviderStatusBanner";
|
||||
@@ -3773,7 +3773,11 @@ export default function ChatView(props: ChatViewProps) {
|
||||
) : null}
|
||||
|
||||
{expandedImage && (
|
||||
<ExpandedImageDialog preview={expandedImage} onClose={closeExpandedImage} />
|
||||
<ExpandedImageDialog
|
||||
key={getExpandedImagePreviewKey(expandedImage)}
|
||||
preview={expandedImage}
|
||||
onClose={closeExpandedImage}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -727,16 +727,9 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
model: selectedModel,
|
||||
models: selectedProviderModels,
|
||||
prompt,
|
||||
modelOptions: composerModelOptions?.[selectedInstanceId],
|
||||
modelOptions: composerModelOptions?.[selectedProvider],
|
||||
}),
|
||||
[
|
||||
composerModelOptions,
|
||||
prompt,
|
||||
selectedInstanceId,
|
||||
selectedModel,
|
||||
selectedProvider,
|
||||
selectedProviderModels,
|
||||
],
|
||||
[composerModelOptions, prompt, selectedModel, selectedProvider, selectedProviderModels],
|
||||
);
|
||||
|
||||
const selectedPromptEffort = composerProviderState.promptEffort;
|
||||
@@ -1025,23 +1018,21 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
|
||||
const providerTraitsMenuContent = renderProviderTraitsMenuContent({
|
||||
provider: selectedProvider,
|
||||
instanceId: selectedInstanceId,
|
||||
...(routeKind === "server" ? { threadRef: routeThreadRef } : {}),
|
||||
...(routeKind === "draft" && draftId ? { draftId } : {}),
|
||||
model: selectedModel,
|
||||
models: selectedProviderModels,
|
||||
modelOptions: composerModelOptions?.[selectedInstanceId],
|
||||
modelOptions: composerModelOptions?.[selectedProvider],
|
||||
prompt,
|
||||
onPromptChange: setPromptFromTraits,
|
||||
});
|
||||
const providerTraitsPicker = renderProviderTraitsPicker({
|
||||
provider: selectedProvider,
|
||||
instanceId: selectedInstanceId,
|
||||
...(routeKind === "server" ? { threadRef: routeThreadRef } : {}),
|
||||
...(routeKind === "draft" && draftId ? { draftId } : {}),
|
||||
model: selectedModel,
|
||||
models: selectedProviderModels,
|
||||
modelOptions: composerModelOptions?.[selectedInstanceId],
|
||||
modelOptions: composerModelOptions?.[selectedProvider],
|
||||
prompt,
|
||||
onPromptChange: setPromptFromTraits,
|
||||
});
|
||||
|
||||
@@ -1,11 +1,4 @@
|
||||
import {
|
||||
useEffect,
|
||||
useRef,
|
||||
useState,
|
||||
type CSSProperties,
|
||||
type ReactNode,
|
||||
type RefObject,
|
||||
} from "react";
|
||||
import { useEffect, useRef, useState, type CSSProperties, type ReactNode } from "react";
|
||||
import { XIcon } from "lucide-react";
|
||||
|
||||
import { cn } from "~/lib/utils";
|
||||
@@ -41,19 +34,6 @@ export interface ComposerBannerStackItem {
|
||||
readonly onDismiss?: () => void;
|
||||
}
|
||||
|
||||
function useDismissTimeoutCleanup(timeoutRef: RefObject<ReturnType<typeof setTimeout> | null>) {
|
||||
useEffect(() => {
|
||||
return () => clearDismissTimeout(timeoutRef);
|
||||
}, [timeoutRef]);
|
||||
}
|
||||
|
||||
function clearDismissTimeout(timeoutRef: RefObject<ReturnType<typeof setTimeout> | null>) {
|
||||
const timeout = timeoutRef.current;
|
||||
if (timeout) {
|
||||
clearTimeout(timeout);
|
||||
}
|
||||
}
|
||||
|
||||
interface ComposerBannerStackProps {
|
||||
readonly className?: string;
|
||||
readonly items: ReadonlyArray<ComposerBannerStackItem>;
|
||||
@@ -62,9 +42,20 @@ interface ComposerBannerStackProps {
|
||||
export function ComposerBannerStack({ className, items }: ComposerBannerStackProps) {
|
||||
const [exitingItemId, setExitingItemId] = useState<string | null>(null);
|
||||
const dismissTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||
const activeExitingItemId =
|
||||
exitingItemId && items.some((item) => item.id === exitingItemId) ? exitingItemId : null;
|
||||
useDismissTimeoutCleanup(dismissTimeoutRef);
|
||||
|
||||
useEffect(() => {
|
||||
if (exitingItemId && !items.some((item) => item.id === exitingItemId)) {
|
||||
setExitingItemId(null);
|
||||
}
|
||||
}, [exitingItemId, items]);
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
if (dismissTimeoutRef.current) {
|
||||
clearTimeout(dismissTimeoutRef.current);
|
||||
}
|
||||
};
|
||||
}, []);
|
||||
|
||||
if (items.length === 0) {
|
||||
return null;
|
||||
@@ -76,10 +67,10 @@ export function ComposerBannerStack({ className, items }: ComposerBannerStackPro
|
||||
}
|
||||
const stackedItems = items.slice(1);
|
||||
const hasStack = stackedItems.length > 0;
|
||||
const showCollapsedStackCap = hasStack && activeExitingItemId !== frontItem.id;
|
||||
const showCollapsedStackCap = hasStack && exitingItemId !== frontItem.id;
|
||||
|
||||
const requestDismiss = (item: ComposerBannerStackItem) => {
|
||||
if (!item.onDismiss || activeExitingItemId) {
|
||||
if (!item.onDismiss || exitingItemId) {
|
||||
return;
|
||||
}
|
||||
setExitingItemId(item.id);
|
||||
@@ -115,16 +106,16 @@ export function ComposerBannerStack({ className, items }: ComposerBannerStackPro
|
||||
<div
|
||||
className={cn(
|
||||
"relative z-10",
|
||||
activeExitingItemId === frontItem.id ? "pointer-events-none" : null,
|
||||
exitingItemId === frontItem.id ? "pointer-events-none" : null,
|
||||
)}
|
||||
style={{
|
||||
...exitTransitionStyle,
|
||||
...(activeExitingItemId === frontItem.id ? frontExitStyle : restingStyle),
|
||||
...(exitingItemId === frontItem.id ? frontExitStyle : restingStyle),
|
||||
}}
|
||||
>
|
||||
<ComposerBannerStackAlert
|
||||
item={frontItem}
|
||||
exiting={activeExitingItemId === frontItem.id}
|
||||
exiting={exitingItemId === frontItem.id}
|
||||
onDismissRequest={() => requestDismiss(frontItem)}
|
||||
/>
|
||||
</div>
|
||||
@@ -141,15 +132,15 @@ export function ComposerBannerStack({ className, items }: ComposerBannerStackPro
|
||||
{stackedItems.map((item) => (
|
||||
<div
|
||||
key={item.id}
|
||||
className={cn(activeExitingItemId === item.id ? "pointer-events-none" : null)}
|
||||
className={cn(exitingItemId === item.id ? "pointer-events-none" : null)}
|
||||
style={{
|
||||
...exitTransitionStyle,
|
||||
...(activeExitingItemId === item.id ? stackedExitStyle : restingStyle),
|
||||
...(exitingItemId === item.id ? stackedExitStyle : restingStyle),
|
||||
}}
|
||||
>
|
||||
<ComposerBannerStackAlert
|
||||
item={item}
|
||||
exiting={activeExitingItemId === item.id}
|
||||
exiting={exitingItemId === item.id}
|
||||
onDismissRequest={() => requestDismiss(item)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -8,27 +8,20 @@ interface ExpandedImageDialogProps {
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
export const ExpandedImageDialog = memo(function ExpandedImageDialog({
|
||||
preview: initialPreview,
|
||||
function clampImageIndex(index: number, imageCount: number): number {
|
||||
if (imageCount <= 0) return 0;
|
||||
return Math.min(Math.max(index, 0), imageCount - 1);
|
||||
}
|
||||
|
||||
function useExpandedImageDialogKeyboardNavigation({
|
||||
imageCount,
|
||||
navigateImage,
|
||||
onClose,
|
||||
}: ExpandedImageDialogProps) {
|
||||
const [preview, setPreview] = useState(initialPreview);
|
||||
|
||||
// Sync when the parent hands us a new preview reference.
|
||||
useEffect(() => {
|
||||
setPreview(initialPreview);
|
||||
}, [initialPreview]);
|
||||
|
||||
const navigateImage = useCallback((direction: -1 | 1) => {
|
||||
setPreview((existing) => {
|
||||
if (existing.images.length <= 1) return existing;
|
||||
const nextIndex =
|
||||
(existing.index + direction + existing.images.length) % existing.images.length;
|
||||
if (nextIndex === existing.index) return existing;
|
||||
return { ...existing, index: nextIndex };
|
||||
});
|
||||
}, []);
|
||||
|
||||
}: {
|
||||
imageCount: number;
|
||||
navigateImage: (direction: -1 | 1) => void;
|
||||
onClose: () => void;
|
||||
}) {
|
||||
useEffect(() => {
|
||||
const onKeyDown = (event: globalThis.KeyboardEvent) => {
|
||||
if (event.key === "Escape") {
|
||||
@@ -37,7 +30,7 @@ export const ExpandedImageDialog = memo(function ExpandedImageDialog({
|
||||
onClose();
|
||||
return;
|
||||
}
|
||||
if (preview.images.length <= 1) return;
|
||||
if (imageCount <= 1) return;
|
||||
if (event.key === "ArrowLeft") {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
@@ -51,9 +44,40 @@ export const ExpandedImageDialog = memo(function ExpandedImageDialog({
|
||||
};
|
||||
window.addEventListener("keydown", onKeyDown);
|
||||
return () => window.removeEventListener("keydown", onKeyDown);
|
||||
}, [navigateImage, onClose, preview.images.length]);
|
||||
}, [imageCount, navigateImage, onClose]);
|
||||
}
|
||||
|
||||
const item = preview.images[preview.index];
|
||||
export const ExpandedImageDialog = memo(function ExpandedImageDialog({
|
||||
preview,
|
||||
onClose,
|
||||
}: ExpandedImageDialogProps) {
|
||||
const imageCount = preview.images.length;
|
||||
const [imageIndex, setImageIndex] = useState(() => clampImageIndex(preview.index, imageCount));
|
||||
const activeImageIndex = clampImageIndex(imageIndex, imageCount);
|
||||
|
||||
const navigateImage = useCallback(
|
||||
(direction: -1 | 1) => {
|
||||
setImageIndex((existing) => {
|
||||
if (imageCount <= 1) return existing;
|
||||
return (existing + direction + imageCount) % imageCount;
|
||||
});
|
||||
},
|
||||
[imageCount],
|
||||
);
|
||||
const navigateToPreviousImage = useCallback(() => {
|
||||
navigateImage(-1);
|
||||
}, [navigateImage]);
|
||||
const navigateToNextImage = useCallback(() => {
|
||||
navigateImage(1);
|
||||
}, [navigateImage]);
|
||||
|
||||
useExpandedImageDialogKeyboardNavigation({
|
||||
imageCount,
|
||||
navigateImage,
|
||||
onClose,
|
||||
});
|
||||
|
||||
const item = preview.images[activeImageIndex];
|
||||
if (!item) return null;
|
||||
|
||||
return (
|
||||
@@ -69,14 +93,14 @@ export const ExpandedImageDialog = memo(function ExpandedImageDialog({
|
||||
aria-label="Close image preview"
|
||||
onClick={onClose}
|
||||
/>
|
||||
{preview.images.length > 1 && (
|
||||
{imageCount > 1 && (
|
||||
<Button
|
||||
type="button"
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
className="absolute left-2 top-1/2 z-20 -translate-y-1/2 text-white/90 hover:bg-white/10 hover:text-white sm:left-6"
|
||||
aria-label="Previous image"
|
||||
onClick={() => navigateImage(-1)}
|
||||
onClick={navigateToPreviousImage}
|
||||
>
|
||||
<ChevronLeftIcon className="size-5" />
|
||||
</Button>
|
||||
@@ -100,17 +124,17 @@ export const ExpandedImageDialog = memo(function ExpandedImageDialog({
|
||||
/>
|
||||
<p className="mt-2 max-w-[92vw] truncate text-center text-xs text-muted-foreground/80">
|
||||
{item.name}
|
||||
{preview.images.length > 1 ? ` (${preview.index + 1}/${preview.images.length})` : ""}
|
||||
{imageCount > 1 ? ` (${activeImageIndex + 1}/${imageCount})` : ""}
|
||||
</p>
|
||||
</div>
|
||||
{preview.images.length > 1 && (
|
||||
{imageCount > 1 && (
|
||||
<Button
|
||||
type="button"
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
className="absolute right-2 top-1/2 z-20 -translate-y-1/2 text-white/90 hover:bg-white/10 hover:text-white sm:right-6"
|
||||
aria-label="Next image"
|
||||
onClick={() => navigateImage(1)}
|
||||
onClick={navigateToNextImage}
|
||||
>
|
||||
<ChevronRightIcon className="size-5" />
|
||||
</Button>
|
||||
|
||||
@@ -8,6 +8,11 @@ export interface ExpandedImagePreview {
|
||||
index: number;
|
||||
}
|
||||
|
||||
export function getExpandedImagePreviewKey(preview: ExpandedImagePreview): string {
|
||||
const selectedImage = preview.images[preview.index];
|
||||
return `${preview.index}:${preview.images.length}:${selectedImage?.src ?? ""}`;
|
||||
}
|
||||
|
||||
export function buildExpandedImagePreview(
|
||||
images: ReadonlyArray<{ id: string; name: string; previewUrl?: string }>,
|
||||
selectedImageId: string,
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import {
|
||||
type ProviderDriverKind,
|
||||
type ProviderInstanceId,
|
||||
type ProviderOptionDescriptor,
|
||||
type ProviderOptionSelection,
|
||||
type ScopedThreadRef,
|
||||
@@ -197,7 +196,6 @@ export function shouldRenderTraitsControls(input: {
|
||||
|
||||
export interface TraitsMenuContentProps {
|
||||
provider: ProviderDriverKind;
|
||||
instanceId?: ProviderInstanceId;
|
||||
models: ReadonlyArray<ServerProviderModel>;
|
||||
model: string | null | undefined;
|
||||
prompt: string;
|
||||
@@ -210,7 +208,6 @@ export interface TraitsMenuContentProps {
|
||||
|
||||
export const TraitsMenuContent = memo(function TraitsMenuContentImpl({
|
||||
provider,
|
||||
instanceId,
|
||||
models,
|
||||
model,
|
||||
prompt,
|
||||
@@ -231,12 +228,11 @@ export const TraitsMenuContent = memo(function TraitsMenuContentImpl({
|
||||
return;
|
||||
}
|
||||
setProviderModelOptions(threadTarget, provider, nextOptions, {
|
||||
...(instanceId ? { instanceId } : {}),
|
||||
model,
|
||||
persistSticky: true,
|
||||
});
|
||||
},
|
||||
[instanceId, model, persistence, provider, setProviderModelOptions],
|
||||
[model, persistence, provider, setProviderModelOptions],
|
||||
);
|
||||
const {
|
||||
descriptors,
|
||||
@@ -347,7 +343,6 @@ export const TraitsMenuContent = memo(function TraitsMenuContentImpl({
|
||||
|
||||
export const TraitsPicker = memo(function TraitsPicker({
|
||||
provider,
|
||||
instanceId,
|
||||
models,
|
||||
model,
|
||||
prompt,
|
||||
@@ -436,7 +431,6 @@ export const TraitsPicker = memo(function TraitsPicker({
|
||||
<MenuPopup align="start">
|
||||
<TraitsMenuContent
|
||||
provider={provider}
|
||||
{...(instanceId ? { instanceId } : {})}
|
||||
models={models}
|
||||
model={model}
|
||||
prompt={prompt}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import {
|
||||
type ProviderDriverKind,
|
||||
type ProviderInstanceId,
|
||||
type ProviderOptionSelection,
|
||||
type ScopedThreadRef,
|
||||
type ServerProviderModel,
|
||||
@@ -36,7 +35,6 @@ export type ComposerProviderState = {
|
||||
|
||||
type TraitsRenderInput = {
|
||||
provider: ProviderDriverKind;
|
||||
instanceId?: ProviderInstanceId;
|
||||
threadRef?: ScopedThreadRef;
|
||||
draftId?: DraftId;
|
||||
model: string;
|
||||
@@ -78,17 +76,8 @@ function renderTraitsControl(
|
||||
Component: typeof TraitsMenuContent | typeof TraitsPicker,
|
||||
input: TraitsRenderInput,
|
||||
): ReactNode {
|
||||
const {
|
||||
provider,
|
||||
instanceId,
|
||||
threadRef,
|
||||
draftId,
|
||||
model,
|
||||
models,
|
||||
modelOptions,
|
||||
prompt,
|
||||
onPromptChange,
|
||||
} = input;
|
||||
const { provider, threadRef, draftId, model, models, modelOptions, prompt, onPromptChange } =
|
||||
input;
|
||||
const hasTarget = threadRef !== undefined || draftId !== undefined;
|
||||
if (
|
||||
!hasTarget ||
|
||||
@@ -99,7 +88,6 @@ function renderTraitsControl(
|
||||
return (
|
||||
<Component
|
||||
provider={provider}
|
||||
{...(instanceId ? { instanceId } : {})}
|
||||
models={models}
|
||||
{...(threadRef ? { threadRef } : {})}
|
||||
{...(draftId ? { draftId } : {})}
|
||||
|
||||
@@ -21,7 +21,6 @@ import { createModelSelection } from "@t3tools/shared/model";
|
||||
// `stickyModelSelectionByProvider` maps are keyed by `ProviderInstanceId`
|
||||
// in production; these aliases keep the legacy-key migration tests concise.
|
||||
const CODEX_INSTANCE = ProviderInstanceId.make("codex");
|
||||
const CODEX_SECONDARY_INSTANCE = ProviderInstanceId.make("codex_secondary");
|
||||
const CLAUDE_AGENT_INSTANCE = ProviderInstanceId.make("claudeAgent");
|
||||
const CURSOR_INSTANCE = ProviderInstanceId.make("cursor");
|
||||
const CODEX_DRIVER = ProviderDriverKind.make("codex");
|
||||
@@ -1202,43 +1201,6 @@ describe("composerDraftStore modelSelection", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("stores provider option changes on a selected custom instance", () => {
|
||||
const store = useComposerDraftStore.getState();
|
||||
|
||||
store.setProviderModelOptions(
|
||||
threadRef,
|
||||
CODEX_DRIVER,
|
||||
toSelections({ reasoningEffort: "low" }),
|
||||
{
|
||||
instanceId: CODEX_SECONDARY_INSTANCE,
|
||||
model: "gpt-5-codex",
|
||||
persistSticky: true,
|
||||
},
|
||||
);
|
||||
|
||||
expect(
|
||||
draftFor(threadId, TEST_ENVIRONMENT_ID)?.modelSelectionByProvider[CODEX_SECONDARY_INSTANCE],
|
||||
).toEqual(
|
||||
expect.objectContaining({
|
||||
instanceId: CODEX_SECONDARY_INSTANCE,
|
||||
options: [{ id: "reasoningEffort", value: "low" }],
|
||||
}),
|
||||
);
|
||||
expect(draftFor(threadId, TEST_ENVIRONMENT_ID)?.activeProvider).toBe(CODEX_SECONDARY_INSTANCE);
|
||||
expect(useComposerDraftStore.getState().stickyActiveProvider).toBe(CODEX_SECONDARY_INSTANCE);
|
||||
expect(useComposerDraftStore.getState().stickyModelSelectionByProvider[CODEX_INSTANCE]).toBe(
|
||||
undefined,
|
||||
);
|
||||
expect(
|
||||
useComposerDraftStore.getState().stickyModelSelectionByProvider[CODEX_SECONDARY_INSTANCE],
|
||||
).toEqual(
|
||||
expect.objectContaining({
|
||||
instanceId: CODEX_SECONDARY_INSTANCE,
|
||||
options: [{ id: "reasoningEffort", value: "low" }],
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("updates only the draft when sticky persistence is disabled", () => {
|
||||
const store = useComposerDraftStore.getState();
|
||||
|
||||
|
||||
@@ -371,7 +371,6 @@ interface ComposerDraftStoreState {
|
||||
provider: ProviderDriverKind,
|
||||
nextProviderOptions: ReadonlyArray<ProviderOptionSelection> | null | undefined,
|
||||
options?: {
|
||||
instanceId?: ProviderInstanceId | null | undefined;
|
||||
model?: string | null | undefined;
|
||||
persistSticky?: boolean;
|
||||
},
|
||||
@@ -2457,7 +2456,7 @@ const composerDraftStore = create<ComposerDraftStoreState>()(
|
||||
if (normalizedProvider === null) {
|
||||
return;
|
||||
}
|
||||
const instanceKey = options?.instanceId ?? defaultInstanceIdForDriver(normalizedProvider);
|
||||
const instanceKey = defaultInstanceIdForDriver(normalizedProvider);
|
||||
const fallbackModel =
|
||||
normalizeModelSlug(options?.model, normalizedProvider) ??
|
||||
DEFAULT_MODEL_BY_PROVIDER[normalizedProvider] ??
|
||||
@@ -2502,9 +2501,7 @@ const composerDraftStore = create<ComposerDraftStoreState>()(
|
||||
const { options: _, ...rest } = stickyBase;
|
||||
nextStickyMap[instanceKey] = rest as ModelSelection;
|
||||
}
|
||||
nextStickyActiveProvider = options.instanceId
|
||||
? instanceKey
|
||||
: (base.activeProvider ?? instanceKey);
|
||||
nextStickyActiveProvider = base.activeProvider ?? instanceKey;
|
||||
}
|
||||
|
||||
if (
|
||||
@@ -2517,7 +2514,6 @@ const composerDraftStore = create<ComposerDraftStoreState>()(
|
||||
|
||||
const nextDraft: ComposerThreadDraftState = {
|
||||
...base,
|
||||
...(options?.instanceId ? { activeProvider: instanceKey } : {}),
|
||||
modelSelectionByProvider: nextMap,
|
||||
};
|
||||
const nextDraftsByThreadKey = { ...state.draftsByThreadKey };
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in new issue
Block a user