fix(webui): open the preset for blocked image input (#6724)
This commit is contained in:
1 parent
607de63fb4
commit
ce12bfdd0d
38 files changed
+430
-78
No files matched your search
@@ -2,7 +2,7 @@ import { ChevronLeft } from "lucide-react";
|
||||
import { useCallback, useEffect, useRef, useState, type ReactNode } from "react";
|
||||
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogLayoutContext, DialogTitle } from "@/components/ui/dialog";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import type { SettingsExitGuard, SettingsFocusTarget } from "@/components/settings/contracts";
|
||||
import { imageInputPresetFromFocus, type SettingsExitGuard, type SettingsFocusTarget } from "@/components/settings/contracts";
|
||||
import { isAppsSection, isCapabilitySection, type AppsSectionKey, type SettingsSectionKey } from "@/components/settings/contracts";
|
||||
import { SegmentedControl } from "@/components/ui/segmented-control";
|
||||
import { SettingsFeature } from "@/components/settings/shared/SettingsFeature";
|
||||
@@ -291,6 +291,7 @@ export function SettingsPage({
|
||||
form={modelState.form}
|
||||
setForm={modelState.setForm}
|
||||
editingPresetName={modelState.modelPresetEditingName}
|
||||
imageInputPreset={imageInputPresetFromFocus(focusTarget)}
|
||||
presetNameError={modelState.modelPresetNameError}
|
||||
error={error}
|
||||
settings={settings}
|
||||
|
||||
@@ -46,4 +46,8 @@ export type ApplySettingsPayload = (
|
||||
) => void;
|
||||
|
||||
export type MaybeRestartHostEngine = (payload: RestartAwarePayload) => Promise<void>;
|
||||
export type SettingsFocusTarget = "sandbox" | "sandbox-launcher";
|
||||
export type SettingsFocusTarget = "sandbox" | "sandbox-launcher" | `image-input:${string}`;
|
||||
|
||||
export function imageInputPresetFromFocus(target?: SettingsFocusTarget): string | undefined {
|
||||
return target?.startsWith("image-input:") ? target.slice("image-input:".length) : undefined;
|
||||
}
|
||||
@@ -212,6 +212,7 @@ export function ModelsSettings({
|
||||
form,
|
||||
setForm,
|
||||
editingPresetName,
|
||||
imageInputPreset,
|
||||
presetNameError,
|
||||
error,
|
||||
settings,
|
||||
@@ -243,6 +244,7 @@ export function ModelsSettings({
|
||||
form: AgentSettingsDraft;
|
||||
setForm: Dispatch<SetStateAction<AgentSettingsDraft>>;
|
||||
editingPresetName: string;
|
||||
imageInputPreset?: string;
|
||||
presetNameError: string | null;
|
||||
error?: string | null;
|
||||
settings: SettingsPayload;
|
||||
@@ -286,6 +288,9 @@ export function ModelsSettings({
|
||||
});
|
||||
const editorTriggerRef = useRef<HTMLElement | null>(null);
|
||||
const presetNameInputRef = useRef<HTMLInputElement>(null);
|
||||
const imageInputRef = useRef<HTMLButtonElement>(null);
|
||||
const openedImagePreset = useRef<string>();
|
||||
const focusImageInput = useRef(false);
|
||||
const suggestedPresetNameRef = useRef<string | null>(null);
|
||||
const presetContextInitializedRef = useRef(false);
|
||||
const [editorRowKey, setEditorRowKey] = useState<string | null>(null);
|
||||
@@ -404,20 +409,11 @@ export function ModelsSettings({
|
||||
disabled: callOrderBusy,
|
||||
onReorder: (keys) => onChangeCallOrder(keys.map((key) => presetRows.find((row) => row.key === key)!.name)),
|
||||
});
|
||||
const selectPreset = async (
|
||||
const openPreset = (
|
||||
preset: SettingsPayload["model_presets"][number],
|
||||
rowKey: string,
|
||||
) => {
|
||||
setHideEditorReturnFocus(false);
|
||||
editorTriggerRef.current = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
||||
const toggleCurrentPreset =
|
||||
!creating && selectedPreset?.name === preset.name && activeEditorRowKey === rowKey;
|
||||
if (edits.needsCompletion() && !(await edits.commit())) return;
|
||||
onSelectConfiguration(preset.name);
|
||||
if (toggleCurrentPreset) {
|
||||
setEditorOpen((open) => !open);
|
||||
return;
|
||||
}
|
||||
setForm((prev) => ({
|
||||
...prev,
|
||||
modelPreset: preset.name,
|
||||
@@ -437,6 +433,28 @@ export function ModelsSettings({
|
||||
setEditorRowKey(rowKey);
|
||||
setEditorOpen(true);
|
||||
};
|
||||
const selectPreset = async (
|
||||
preset: SettingsPayload["model_presets"][number],
|
||||
rowKey: string,
|
||||
) => {
|
||||
setHideEditorReturnFocus(false);
|
||||
editorTriggerRef.current = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
||||
if (edits.needsCompletion() && !(await edits.commit())) return;
|
||||
if (!creating && selectedPreset?.name === preset.name && activeEditorRowKey === rowKey) {
|
||||
setEditorOpen((open) => !open);
|
||||
} else {
|
||||
openPreset(preset, rowKey);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (openedImagePreset.current === imageInputPreset) return;
|
||||
const row = presetRows.find(({ name }) => name === imageInputPreset);
|
||||
openedImagePreset.current = imageInputPreset;
|
||||
if (!row?.preset) return;
|
||||
focusImageInput.current = true;
|
||||
openPreset(row.preset, row.key);
|
||||
});
|
||||
|
||||
const moveCallOrderItem = (index: number, offset: -1 | 1) => {
|
||||
if (callOrderBusy) return;
|
||||
@@ -575,6 +593,7 @@ export function ModelsSettings({
|
||||
description={t("settings.models.imageInputHelp")}
|
||||
>
|
||||
<ToggleButton
|
||||
ref={imageInputRef}
|
||||
checked={form.supportsImages}
|
||||
label={t("settings.models.imageInput")}
|
||||
disabled={saving || creatingSaving}
|
||||
@@ -994,6 +1013,12 @@ export function ModelsSettings({
|
||||
onBlurCapture={edits.onBlurCapture}
|
||||
onEscapeKeyDown={() => setHideEditorReturnFocus(true)}
|
||||
className="relative max-h-[85dvh] w-[min(calc(100vw-2rem),40rem)] max-w-none gap-0 overflow-y-auto p-0"
|
||||
onOpenAutoFocus={(event) => {
|
||||
if (!focusImageInput.current || !imageInputRef.current) return;
|
||||
focusImageInput.current = false;
|
||||
event.preventDefault();
|
||||
imageInputRef.current.focus();
|
||||
}}
|
||||
onCloseAutoFocus={(event) => {
|
||||
event.preventDefault();
|
||||
editorTriggerRef.current?.focus();
|
||||
|
||||
@@ -8,16 +8,18 @@ import { useTranslation } from "react-i18next";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { cn } from "@/lib/utils";
|
||||
import type { RecoveryState } from "@/lib/types";
|
||||
import { resolveModelRequestFailureCopy } from "@/lib/model-request-failure";
|
||||
import { isImageRequestFailure, resolveModelRequestFailureCopy } from "@/lib/model-request-failure";
|
||||
|
||||
interface RecoveryNoticeProps {
|
||||
state: RecoveryState;
|
||||
onContinue: () => Promise<void>;
|
||||
onDismiss: () => Promise<void>;
|
||||
onOpenSettings?: () => void;
|
||||
onInspectImagePreset?: () => void;
|
||||
imageInputBlocked?: boolean;
|
||||
}
|
||||
|
||||
export function RecoveryNotice({ state, onContinue, onDismiss, onOpenSettings }: RecoveryNoticeProps) {
|
||||
export function RecoveryNotice({ state, onContinue, onDismiss, onOpenSettings, onInspectImagePreset, imageInputBlocked }: RecoveryNoticeProps) {
|
||||
const { t } = useTranslation();
|
||||
const [pending, setPending] = useState<"continue" | "dismiss" | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
@@ -38,6 +40,8 @@ export function RecoveryNotice({ state, onContinue, onDismiss, onOpenSettings }:
|
||||
const modelFailure = state.reason === "model_request_failed"
|
||||
? resolveModelRequestFailureCopy({ errorKind: state.failure_error_kind }, t)
|
||||
: null;
|
||||
const imageFailure = modelFailure !== null && isImageRequestFailure(state.failure_error_kind);
|
||||
const openSettings = imageFailure ? onInspectImagePreset : onOpenSettings;
|
||||
const title = modelFailure?.title ?? (state.status === "failed"
|
||||
? t("recovery.failed", { defaultValue: "Task recovery failed" })
|
||||
: t("recovery.interrupted", { defaultValue: "Task interrupted" }));
|
||||
@@ -45,7 +49,7 @@ export function RecoveryNotice({ state, onContinue, onDismiss, onOpenSettings }:
|
||||
? t("recovery.failedHelp", {
|
||||
defaultValue: "The saved task could not be restored safely. Review it before continuing.",
|
||||
})
|
||||
: modelFailure && state.reply_preserved === true
|
||||
: modelFailure && !imageFailure && state.reply_preserved === true
|
||||
? t("recovery.replyPreserved", { defaultValue: "Reply saved. You can continue." })
|
||||
: modelFailure?.body ?? t("recovery.review", { defaultValue: "Review the task before continuing. Tools will not be replayed automatically." });
|
||||
const run = (action: "continue" | "dismiss") => {
|
||||
@@ -74,9 +78,9 @@ export function RecoveryNotice({ state, onContinue, onDismiss, onOpenSettings }:
|
||||
<p className="font-medium">
|
||||
{title}
|
||||
</p>
|
||||
{modelFailure && onOpenSettings ? (
|
||||
<Button variant="link" size="sm" className="h-auto px-0 py-1" onClick={onOpenSettings}>
|
||||
{t("thread.composer.reauthSettings")}
|
||||
{modelFailure && openSettings ? (
|
||||
<Button variant="link" size="sm" className="h-auto px-0 py-1" onClick={openSettings}>
|
||||
{t(imageFailure ? "settings.models.viewPreset" : "thread.composer.reauthSettings")}
|
||||
</Button>
|
||||
) : null}
|
||||
<p className={cn(
|
||||
@@ -97,7 +101,7 @@ export function RecoveryNotice({ state, onContinue, onDismiss, onOpenSettings }:
|
||||
<X className="mr-1 h-3.5 w-3.5" aria-hidden />
|
||||
{t("recovery.dismiss", { defaultValue: "Dismiss" })}
|
||||
</Button>
|
||||
{!contextUnavailable ? (
|
||||
{!contextUnavailable && !(state.failure_error_kind === "unsupported_image" && imageInputBlocked) ? (
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
|
||||
@@ -20,7 +20,6 @@ interface StreamErrorNoticeProps {
|
||||
*/
|
||||
export function StreamErrorNotice({ error, onDismiss, onOpenSettings }: StreamErrorNoticeProps) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const { title, body } = resolveCopy(error, t);
|
||||
|
||||
return (
|
||||
|
||||
@@ -238,6 +238,8 @@ interface ThreadComposerProps {
|
||||
modelOptionsControl?: ModelOptionsControlProps;
|
||||
onModelMenuOpenChange?: (open: boolean) => void;
|
||||
onModelPresetChange?: (name: string) => void;
|
||||
imageInputBlocked?: boolean;
|
||||
onInspectImagePreset?: () => void;
|
||||
modelProvider?: string | null;
|
||||
modelProviderLabel?: string | null;
|
||||
modelNeedsSetup?: boolean;
|
||||
@@ -571,6 +573,8 @@ export function ThreadComposer({
|
||||
modelOptionsControl,
|
||||
onModelMenuOpenChange,
|
||||
onModelPresetChange,
|
||||
imageInputBlocked = false,
|
||||
onInspectImagePreset,
|
||||
modelProvider = null,
|
||||
modelProviderLabel = null,
|
||||
modelNeedsSetup = false,
|
||||
@@ -705,6 +709,22 @@ export function ThreadComposer({
|
||||
return null;
|
||||
}, [formatRejection, formatUploadTooLarge, ingressLimits, maxAttachments, maxFileBytes, maxTextBytes, t, textTooLargeMessage]);
|
||||
|
||||
const validatePrompt = useCallback((prompt: QueuedPromptContent): boolean => {
|
||||
if (imageInputBlocked && prompt.images?.some(({ kind }) => kind === "image")) {
|
||||
showToast?.({
|
||||
message: t("errors.modelRequestFailed.imageInputTitle"),
|
||||
tone: "error",
|
||||
action: onInspectImagePreset
|
||||
? { label: t("settings.models.viewPreset"), run: onInspectImagePreset }
|
||||
: undefined,
|
||||
});
|
||||
return false;
|
||||
}
|
||||
const error = queuedPromptError(prompt);
|
||||
if (error) setInlineError(error);
|
||||
return error === null;
|
||||
}, [imageInputBlocked, onInspectImagePreset, queuedPromptError, showToast, t]);
|
||||
|
||||
const {
|
||||
snapshot: queueSnapshot,
|
||||
collect: collectQueuedPrompt,
|
||||
@@ -715,8 +735,7 @@ export function ThreadComposer({
|
||||
} = useQueuedPrompt(pendingQueueKey, { isStreaming, activeTurnId, completedTurnIds }, {
|
||||
disabled: !!disabled || sendPending,
|
||||
onSend,
|
||||
validate: queuedPromptError,
|
||||
onValidationError: setInlineError,
|
||||
validate: validatePrompt,
|
||||
onSendAttempt: focusTextarea,
|
||||
});
|
||||
const queuedPrompt = queueSnapshot.prompt;
|
||||
@@ -1711,11 +1730,7 @@ export function ThreadComposer({
|
||||
slashLifecycle === "finalize_active_turn";
|
||||
if (!isUserShell && !slashLifecycle) {
|
||||
const prompt = collectGuidancePrompt();
|
||||
const error = queuedPromptError(prompt);
|
||||
if (error) {
|
||||
setInlineError(error);
|
||||
return;
|
||||
}
|
||||
if (!validatePrompt(prompt)) return;
|
||||
if (queuedPrompt) {
|
||||
sendQueuedPrompt(prompt, options);
|
||||
if (draftKey) draftStore?.delete(draftKey);
|
||||
@@ -1774,7 +1789,7 @@ export function ThreadComposer({
|
||||
clearComposerText,
|
||||
collectGuidancePrompt,
|
||||
queuedPrompt,
|
||||
queuedPromptError,
|
||||
validatePrompt,
|
||||
sendQueuedPrompt,
|
||||
clearQueuedPrompt,
|
||||
hasTouchPrimaryPointer,
|
||||
|
||||
@@ -38,6 +38,8 @@ import { ThreadHeader } from "@/components/thread/ThreadHeader";
|
||||
import { GoalIsland } from "@/components/thread/GoalIsland";
|
||||
import { ThreadLoadingSkeleton } from "@/components/thread/ThreadLoadingSkeleton";
|
||||
import { StreamErrorNotice } from "@/components/thread/StreamErrorNotice";
|
||||
import { useToast } from "@/components/ui/toast";
|
||||
import { isImageRequestFailure, resolveModelRequestFailureCopy } from "@/lib/model-request-failure";
|
||||
import { ThreadViewport, type ThreadViewportHandle } from "@/components/thread/ThreadViewport";
|
||||
import { ExecSessionCommandsContext } from "@/components/thread/activity/exec-session-context";
|
||||
import { execSessionCommands } from "@/components/thread/activity/exec-session-model";
|
||||
@@ -261,6 +263,7 @@ interface ThreadShellProps {
|
||||
settingsSnapshot?: SettingsPayload | null;
|
||||
settingsLoading?: boolean;
|
||||
onOpenModelSettings?: () => void;
|
||||
onInspectImagePreset?: (name: string) => void;
|
||||
onOpenSandboxSettings?: (target: "sandbox" | "sandbox-launcher") => void;
|
||||
skills?: SkillSummary[];
|
||||
}
|
||||
@@ -401,10 +404,12 @@ export function ThreadShell({
|
||||
settingsSnapshot = null,
|
||||
settingsLoading = false,
|
||||
onOpenModelSettings,
|
||||
onInspectImagePreset,
|
||||
onOpenSandboxSettings,
|
||||
skills = [],
|
||||
}: ThreadShellProps) {
|
||||
const { t } = useTranslation();
|
||||
const showToast = useToast();
|
||||
const chatId = session?.chatId ?? null;
|
||||
const historyKey = temporary ? null : session?.key ?? null;
|
||||
const [visibleWindow, setVisibleWindow] = useState<{ key: string | null; turnIds: string[]; hasMessages: boolean } | null>(null);
|
||||
@@ -802,6 +807,24 @@ export function ThreadShell({
|
||||
|| settings?.agent.model_preset
|
||||
|| "default"
|
||||
);
|
||||
const imageInputBlocked = settings?.image_fallback_configured === false
|
||||
&& settings.model_presets.find((preset) => preset.name === activeModelPreset)?.supports_images === false;
|
||||
const inspectImagePreset = useMemo(() => onInspectImagePreset
|
||||
? () => onInspectImagePreset(activeModelPreset)
|
||||
: onOpenModelSettings, [activeModelPreset, onInspectImagePreset, onOpenModelSettings]);
|
||||
const imageRequestError = streamError?.kind === "model_request_failed" && isImageRequestFailure(streamError.errorKind)
|
||||
? streamError
|
||||
: null;
|
||||
useEffect(() => {
|
||||
if (!imageRequestError) return;
|
||||
showToast?.({
|
||||
message: resolveModelRequestFailureCopy(imageRequestError, t).title,
|
||||
tone: "error",
|
||||
dedupeKey: `image-request-failed:${imageRequestError.chatId}`,
|
||||
action: inspectImagePreset ? { label: t("settings.models.viewPreset"), run: inspectImagePreset } : undefined,
|
||||
});
|
||||
dismissStreamError();
|
||||
}, [dismissStreamError, imageRequestError, inspectImagePreset, showToast, t]);
|
||||
useEffect(() => {
|
||||
setModelFallback(null);
|
||||
if (!chatId) return;
|
||||
@@ -1295,9 +1318,11 @@ export function ThreadShell({
|
||||
onContinue={continueRecovery}
|
||||
onDismiss={dismissRecovery}
|
||||
onOpenSettings={onOpenModelSettings}
|
||||
onInspectImagePreset={inspectImagePreset}
|
||||
imageInputBlocked={imageInputBlocked}
|
||||
/>
|
||||
) : null}
|
||||
{streamError && !hasInlineDeliveryError(messages, streamError) ? (
|
||||
{streamError && !imageRequestError && !hasInlineDeliveryError(messages, streamError) ? (
|
||||
<StreamErrorNotice
|
||||
error={streamError}
|
||||
onDismiss={dismissStreamError}
|
||||
@@ -1322,6 +1347,8 @@ export function ThreadShell({
|
||||
draftStore={draftStore}
|
||||
persistDraft={persistDraft}
|
||||
onSend={handleThreadSend}
|
||||
imageInputBlocked={imageInputBlocked}
|
||||
onInspectImagePreset={inspectImagePreset}
|
||||
disabled={!chatId}
|
||||
inputAriaLabel={composerInputAriaLabel}
|
||||
isStreaming={turnActive}
|
||||
@@ -1380,6 +1407,8 @@ export function ThreadShell({
|
||||
draftStore={draftStore}
|
||||
persistDraft={persistDraft}
|
||||
onSend={handleWelcomeSend}
|
||||
imageInputBlocked={imageInputBlocked}
|
||||
onInspectImagePreset={inspectImagePreset}
|
||||
disabled={booting}
|
||||
inputAriaLabel={composerInputAriaLabel}
|
||||
isStreaming={turnActive}
|
||||
|
||||
@@ -311,8 +311,7 @@ interface QueuedPromptDelivery {
|
||||
images?: SendAttachment[],
|
||||
options?: SendOptions,
|
||||
) => boolean | void | Promise<boolean | void>;
|
||||
validate: (prompt: QueuedPromptContent) => string | null;
|
||||
onValidationError: (error: string) => void;
|
||||
validate: (prompt: QueuedPromptContent) => boolean;
|
||||
onSendAttempt: () => void;
|
||||
}
|
||||
|
||||
@@ -320,7 +319,7 @@ interface QueuedPromptDelivery {
|
||||
export function useQueuedPrompt(
|
||||
pendingQueueKey: string | null,
|
||||
{ isStreaming, activeTurnId, completedTurnIds = EMPTY_COMPLETED_TURN_IDS }: QueuedPromptRun,
|
||||
{ disabled, onSend, validate, onValidationError, onSendAttempt }: QueuedPromptDelivery,
|
||||
{ disabled, onSend, validate, onSendAttempt }: QueuedPromptDelivery,
|
||||
) {
|
||||
const storageKey = queuedPromptsStorageKey(pendingQueueKey);
|
||||
const store = useMemo(() => queuedPromptStoreFor(storageKey), [storageKey]);
|
||||
@@ -356,14 +355,10 @@ export function useQueuedPrompt(
|
||||
}, [activeTurnId, queuedPrompt]);
|
||||
|
||||
const enqueue = useCallback((prompt: QueuedPrompt): boolean => {
|
||||
const error = validate(prompt);
|
||||
if (error) {
|
||||
onValidationError(error);
|
||||
return false;
|
||||
}
|
||||
if (!validate(prompt)) return false;
|
||||
setQueuedPrompt(prompt);
|
||||
return true;
|
||||
}, [onValidationError, setQueuedPrompt, validate]);
|
||||
}, [setQueuedPrompt, validate]);
|
||||
|
||||
const clear = useCallback(() => {
|
||||
setQueuedPrompt(null);
|
||||
@@ -376,10 +371,8 @@ export function useQueuedPrompt(
|
||||
const send = useCallback(
|
||||
(prompt: QueuedPrompt, extraOptions?: SendOptions) => {
|
||||
if (interactionDisabled) return;
|
||||
const error = validate(prompt);
|
||||
if (error) {
|
||||
if (!validate(prompt)) {
|
||||
setQueuedPrompt(pauseQueuedPrompt(prompt));
|
||||
onValidationError(error);
|
||||
return;
|
||||
}
|
||||
const text = prompt.text.trim();
|
||||
@@ -401,7 +394,7 @@ export function useQueuedPrompt(
|
||||
));
|
||||
onSendAttempt();
|
||||
},
|
||||
[interactionDisabled, isStreaming, onSend, onSendAttempt, onValidationError, store, validate, setQueuedPrompt],
|
||||
[interactionDisabled, isStreaming, onSend, onSendAttempt, store, validate, setQueuedPrompt],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
Reference in new issue
Block a user