Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f991605be7 | ||
|
|
bf48aa2fba |
No files matched your search
@@ -147,14 +147,6 @@ const COMPOSER_FLOATING_LAYER_SELECTOR = [
|
||||
'[data-slot="autocomplete-popup"]',
|
||||
].join(",");
|
||||
|
||||
function useStableCallback<Args extends unknown[], Return>(
|
||||
callback: (...args: Args) => Return,
|
||||
): (...args: Args) => Return {
|
||||
const callbackRef = useRef(callback);
|
||||
callbackRef.current = callback;
|
||||
return useCallback((...args: Args) => callbackRef.current(...args), []);
|
||||
}
|
||||
|
||||
const extendReplacementRangeForTrailingSpace = (
|
||||
text: string,
|
||||
rangeEnd: number,
|
||||
@@ -606,15 +598,6 @@ export const ChatComposer = memo(
|
||||
() => sortProviderInstanceEntries(deriveProviderInstanceEntries(providerStatuses)),
|
||||
[providerStatuses],
|
||||
);
|
||||
const providerInstanceEntryById = useMemo<
|
||||
ReadonlyMap<ProviderInstanceId, ProviderInstanceEntry>
|
||||
>(() => {
|
||||
const entriesById = new Map<ProviderInstanceId, ProviderInstanceEntry>();
|
||||
for (const entry of providerInstanceEntries) {
|
||||
entriesById.set(entry.instanceId, entry);
|
||||
}
|
||||
return entriesById;
|
||||
}, [providerInstanceEntries]);
|
||||
const selectedProviderByThreadId = composerDraft.activeProvider ?? null;
|
||||
const threadProvider =
|
||||
activeThread?.session?.providerInstanceId ??
|
||||
@@ -635,12 +618,15 @@ export const ChatComposer = memo(
|
||||
const lockedInstanceId =
|
||||
activeThread.session?.providerInstanceId ?? activeThreadModelSelection?.instanceId;
|
||||
if (!lockedInstanceId) return null;
|
||||
return providerInstanceEntryById.get(lockedInstanceId)?.continuationGroupKey ?? null;
|
||||
return (
|
||||
providerInstanceEntries.find((entry) => entry.instanceId === lockedInstanceId)
|
||||
?.continuationGroupKey ?? null
|
||||
);
|
||||
}, [
|
||||
activeThread,
|
||||
activeThreadModelSelection?.instanceId,
|
||||
lockedProvider,
|
||||
providerInstanceEntryById,
|
||||
providerInstanceEntries,
|
||||
]);
|
||||
|
||||
// Resolve which configured instance the composer is currently targeting.
|
||||
@@ -662,9 +648,10 @@ export const ChatComposer = memo(
|
||||
];
|
||||
for (const candidate of candidates) {
|
||||
if (!candidate) continue;
|
||||
const match = providerInstanceEntryById.get(ProviderInstanceId.make(candidate));
|
||||
const match = providerInstanceEntries.find(
|
||||
(entry) => entry.instanceId === candidate && entry.enabled,
|
||||
);
|
||||
if (match) {
|
||||
if (!match.enabled) continue;
|
||||
// When locked to a specific driver kind, ignore persisted instance
|
||||
// ids from a different kind or continuation group.
|
||||
if (lockedProvider && match.driverKind !== lockedProvider) continue;
|
||||
@@ -704,7 +691,6 @@ export const ChatComposer = memo(
|
||||
explicitSelectedInstanceId,
|
||||
lockedContinuationGroupKey,
|
||||
lockedProvider,
|
||||
providerInstanceEntryById,
|
||||
providerInstanceEntries,
|
||||
selectedProvider,
|
||||
]);
|
||||
@@ -723,8 +709,8 @@ export const ChatComposer = memo(
|
||||
// instance gets its own slash commands, skills, and model list — not
|
||||
// the first snapshot for the same driver kind.
|
||||
const selectedProviderEntry = useMemo(
|
||||
() => providerInstanceEntryById.get(selectedInstanceId),
|
||||
[providerInstanceEntryById, selectedInstanceId],
|
||||
() => providerInstanceEntries.find((entry) => entry.instanceId === selectedInstanceId),
|
||||
[providerInstanceEntries, selectedInstanceId],
|
||||
);
|
||||
const selectedProviderStatus = useMemo(
|
||||
() => selectedProviderEntry?.snapshot ?? null,
|
||||
@@ -942,24 +928,20 @@ export const ChatComposer = memo(
|
||||
const composerMenuSearchKey = composerTrigger
|
||||
? `${composerTrigger.kind}:${composerTrigger.query.trim().toLowerCase()}`
|
||||
: null;
|
||||
const activeComposerMenuItemId = useMemo(
|
||||
() =>
|
||||
resolveComposerMenuActiveItemId({
|
||||
items: composerMenuItems,
|
||||
highlightedItemId: composerHighlightedItemId,
|
||||
currentSearchKey: composerMenuSearchKey,
|
||||
highlightedSearchKey: composerHighlightedSearchKey,
|
||||
}),
|
||||
[
|
||||
composerHighlightedItemId,
|
||||
composerHighlightedSearchKey,
|
||||
composerMenuItems,
|
||||
composerMenuSearchKey,
|
||||
],
|
||||
);
|
||||
const activeComposerMenuItem = useMemo(() => {
|
||||
return composerMenuItems.find((item) => item.id === activeComposerMenuItemId) ?? null;
|
||||
}, [activeComposerMenuItemId, composerMenuItems]);
|
||||
const activeItemId = resolveComposerMenuActiveItemId({
|
||||
items: composerMenuItems,
|
||||
highlightedItemId: composerHighlightedItemId,
|
||||
currentSearchKey: composerMenuSearchKey,
|
||||
highlightedSearchKey: composerHighlightedSearchKey,
|
||||
});
|
||||
return composerMenuItems.find((item) => item.id === activeItemId) ?? null;
|
||||
}, [
|
||||
composerHighlightedItemId,
|
||||
composerHighlightedSearchKey,
|
||||
composerMenuItems,
|
||||
composerMenuSearchKey,
|
||||
]);
|
||||
|
||||
composerMenuOpenRef.current = composerMenuOpen;
|
||||
composerMenuItemsRef.current = composerMenuItems;
|
||||
@@ -1146,6 +1128,35 @@ export const ChatComposer = memo(
|
||||
composerTerminalContextsRef.current = composerTerminalContexts;
|
||||
}, [composerTerminalContexts, composerTerminalContextsRef]);
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Composer menu highlight sync
|
||||
// ------------------------------------------------------------------
|
||||
useEffect(() => {
|
||||
if (!composerMenuOpen) {
|
||||
setComposerHighlightedItemId(null);
|
||||
setComposerHighlightedSearchKey(null);
|
||||
return;
|
||||
}
|
||||
const nextActiveItemId = resolveComposerMenuActiveItemId({
|
||||
items: composerMenuItems,
|
||||
highlightedItemId: composerHighlightedItemId,
|
||||
currentSearchKey: composerMenuSearchKey,
|
||||
highlightedSearchKey: composerHighlightedSearchKey,
|
||||
});
|
||||
setComposerHighlightedItemId((existing) =>
|
||||
existing === nextActiveItemId ? existing : nextActiveItemId,
|
||||
);
|
||||
setComposerHighlightedSearchKey((existing) =>
|
||||
existing === composerMenuSearchKey ? existing : composerMenuSearchKey,
|
||||
);
|
||||
}, [
|
||||
composerHighlightedItemId,
|
||||
composerHighlightedSearchKey,
|
||||
composerMenuItems,
|
||||
composerMenuOpen,
|
||||
composerMenuSearchKey,
|
||||
]);
|
||||
|
||||
const lastSyncedPendingInputRef = useRef<{
|
||||
requestId: string | null;
|
||||
questionId: string | null;
|
||||
@@ -1562,7 +1573,7 @@ export const ChatComposer = memo(
|
||||
(key: "ArrowDown" | "ArrowUp") => {
|
||||
if (composerMenuItems.length === 0) return;
|
||||
const highlightedIndex = composerMenuItems.findIndex(
|
||||
(item) => item.id === activeComposerMenuItemId,
|
||||
(item) => item.id === composerHighlightedItemId,
|
||||
);
|
||||
const normalizedIndex =
|
||||
highlightedIndex >= 0 ? highlightedIndex : key === "ArrowDown" ? -1 : 0;
|
||||
@@ -1571,9 +1582,8 @@ export const ChatComposer = memo(
|
||||
(normalizedIndex + offset + composerMenuItems.length) % composerMenuItems.length;
|
||||
const nextItem = composerMenuItems[nextIndex];
|
||||
setComposerHighlightedItemId(nextItem?.id ?? null);
|
||||
setComposerHighlightedSearchKey(composerMenuSearchKey);
|
||||
},
|
||||
[activeComposerMenuItemId, composerMenuItems, composerMenuSearchKey],
|
||||
[composerHighlightedItemId, composerMenuItems],
|
||||
);
|
||||
|
||||
const blurMobileComposerAfterSend = useCallback(() => {
|
||||
@@ -1642,95 +1652,86 @@ export const ChatComposer = memo(
|
||||
// ------------------------------------------------------------------
|
||||
// Callbacks: command key
|
||||
// ------------------------------------------------------------------
|
||||
const onComposerCommandKey = useStableCallback(
|
||||
(key: "ArrowDown" | "ArrowUp" | "Enter" | "Tab", event: KeyboardEvent) => {
|
||||
if (key === "Tab" && event.shiftKey) {
|
||||
toggleInteractionMode();
|
||||
const onComposerCommandKey = (
|
||||
key: "ArrowDown" | "ArrowUp" | "Enter" | "Tab",
|
||||
event: KeyboardEvent,
|
||||
) => {
|
||||
if (key === "Tab" && event.shiftKey) {
|
||||
toggleInteractionMode();
|
||||
return true;
|
||||
}
|
||||
const { trigger } = resolveActiveComposerTrigger();
|
||||
const menuIsActive = composerMenuOpenRef.current || trigger !== null;
|
||||
if (menuIsActive) {
|
||||
const currentItems = composerMenuItemsRef.current;
|
||||
const selectedItem = activeComposerMenuItemRef.current ?? currentItems[0];
|
||||
if (key === "ArrowDown" && currentItems.length > 0) {
|
||||
nudgeComposerMenuHighlight("ArrowDown");
|
||||
return true;
|
||||
}
|
||||
const { trigger } = resolveActiveComposerTrigger();
|
||||
const menuIsActive = composerMenuOpenRef.current || trigger !== null;
|
||||
if (menuIsActive) {
|
||||
const currentItems = composerMenuItemsRef.current;
|
||||
const selectedItem = activeComposerMenuItemRef.current ?? currentItems[0];
|
||||
if (key === "ArrowDown" && currentItems.length > 0) {
|
||||
nudgeComposerMenuHighlight("ArrowDown");
|
||||
return true;
|
||||
}
|
||||
if (key === "ArrowUp" && currentItems.length > 0) {
|
||||
nudgeComposerMenuHighlight("ArrowUp");
|
||||
return true;
|
||||
}
|
||||
if ((key === "Enter" || key === "Tab") && selectedItem) {
|
||||
onSelectComposerItem(selectedItem);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (key === "Enter" && !event.shiftKey) {
|
||||
submitComposer();
|
||||
if (key === "ArrowUp" && currentItems.length > 0) {
|
||||
nudgeComposerMenuHighlight("ArrowUp");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
);
|
||||
if ((key === "Enter" || key === "Tab") && selectedItem) {
|
||||
onSelectComposerItem(selectedItem);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (key === "Enter" && !event.shiftKey) {
|
||||
submitComposer();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Callbacks: images
|
||||
// ------------------------------------------------------------------
|
||||
const addComposerImages = useCallback(
|
||||
(files: File[]) => {
|
||||
if (!activeThreadId || files.length === 0) return;
|
||||
if (pendingUserInputs.length > 0) {
|
||||
toastManager.add({
|
||||
type: "error",
|
||||
title: "Attach images after answering plan questions.",
|
||||
});
|
||||
return;
|
||||
const addComposerImages = (files: File[]) => {
|
||||
if (!activeThreadId || files.length === 0) return;
|
||||
if (pendingUserInputs.length > 0) {
|
||||
toastManager.add({
|
||||
type: "error",
|
||||
title: "Attach images after answering plan questions.",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const nextImages: ComposerImageAttachment[] = [];
|
||||
let nextImageCount = composerImagesRef.current.length;
|
||||
let error: string | null = null;
|
||||
for (const file of files) {
|
||||
if (!file.type.startsWith("image/")) {
|
||||
error = `Unsupported file type for '${file.name}'. Please attach image files only.`;
|
||||
continue;
|
||||
}
|
||||
const nextImages: ComposerImageAttachment[] = [];
|
||||
let nextImageCount = composerImagesRef.current.length;
|
||||
let error: string | null = null;
|
||||
for (const file of files) {
|
||||
if (!file.type.startsWith("image/")) {
|
||||
error = `Unsupported file type for '${file.name}'. Please attach image files only.`;
|
||||
continue;
|
||||
}
|
||||
if (file.size > PROVIDER_SEND_TURN_MAX_IMAGE_BYTES) {
|
||||
error = `'${file.name}' exceeds the ${IMAGE_SIZE_LIMIT_LABEL} attachment limit.`;
|
||||
continue;
|
||||
}
|
||||
if (nextImageCount >= PROVIDER_SEND_TURN_MAX_ATTACHMENTS) {
|
||||
error = `You can attach up to ${PROVIDER_SEND_TURN_MAX_ATTACHMENTS} images per message.`;
|
||||
break;
|
||||
}
|
||||
const previewUrl = URL.createObjectURL(file);
|
||||
nextImages.push({
|
||||
type: "image",
|
||||
id: randomUUID(),
|
||||
name: file.name || "image",
|
||||
mimeType: file.type,
|
||||
sizeBytes: file.size,
|
||||
previewUrl,
|
||||
file,
|
||||
});
|
||||
nextImageCount += 1;
|
||||
if (file.size > PROVIDER_SEND_TURN_MAX_IMAGE_BYTES) {
|
||||
error = `'${file.name}' exceeds the ${IMAGE_SIZE_LIMIT_LABEL} attachment limit.`;
|
||||
continue;
|
||||
}
|
||||
if (nextImages.length === 1 && nextImages[0]) {
|
||||
addComposerImage(nextImages[0]);
|
||||
} else if (nextImages.length > 1) {
|
||||
addComposerImagesToDraft(nextImages);
|
||||
if (nextImageCount >= PROVIDER_SEND_TURN_MAX_ATTACHMENTS) {
|
||||
error = `You can attach up to ${PROVIDER_SEND_TURN_MAX_ATTACHMENTS} images per message.`;
|
||||
break;
|
||||
}
|
||||
setThreadError(activeThreadId, error);
|
||||
},
|
||||
[
|
||||
activeThreadId,
|
||||
addComposerImage,
|
||||
addComposerImagesToDraft,
|
||||
composerImagesRef,
|
||||
pendingUserInputs.length,
|
||||
setThreadError,
|
||||
],
|
||||
);
|
||||
const previewUrl = URL.createObjectURL(file);
|
||||
nextImages.push({
|
||||
type: "image",
|
||||
id: randomUUID(),
|
||||
name: file.name || "image",
|
||||
mimeType: file.type,
|
||||
sizeBytes: file.size,
|
||||
previewUrl,
|
||||
file,
|
||||
});
|
||||
nextImageCount += 1;
|
||||
}
|
||||
if (nextImages.length === 1 && nextImages[0]) {
|
||||
addComposerImage(nextImages[0]);
|
||||
} else if (nextImages.length > 1) {
|
||||
addComposerImagesToDraft(nextImages);
|
||||
}
|
||||
setThreadError(activeThreadId, error);
|
||||
};
|
||||
|
||||
const removeComposerImage = (imageId: string) => {
|
||||
removeComposerImageFromDraft(imageId);
|
||||
@@ -1739,14 +1740,14 @@ export const ChatComposer = memo(
|
||||
// ------------------------------------------------------------------
|
||||
// Callbacks: paste / drag
|
||||
// ------------------------------------------------------------------
|
||||
const onComposerPaste = useStableCallback((event: React.ClipboardEvent<HTMLElement>) => {
|
||||
const onComposerPaste = (event: React.ClipboardEvent<HTMLElement>) => {
|
||||
const files = Array.from(event.clipboardData.files);
|
||||
if (files.length === 0) return;
|
||||
const imageFiles = files.filter((file) => file.type.startsWith("image/"));
|
||||
if (imageFiles.length === 0) return;
|
||||
event.preventDefault();
|
||||
addComposerImages(imageFiles);
|
||||
});
|
||||
};
|
||||
|
||||
const onComposerDragEnter = (event: React.DragEvent<HTMLDivElement>) => {
|
||||
if (!event.dataTransfer.types.includes("Files")) return;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import { CheckIcon } from "lucide-react";
|
||||
import { Radio as RadioPrimitive } from "@base-ui/react/radio";
|
||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import { useCallback, useMemo, useState } from "react";
|
||||
import {
|
||||
ProviderInstanceId,
|
||||
ProviderDriverKind,
|
||||
@@ -114,6 +114,18 @@ interface AddProviderInstanceDialogProps {
|
||||
}
|
||||
|
||||
export function AddProviderInstanceDialog({ open, onOpenChange }: AddProviderInstanceDialogProps) {
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
{open ? <AddProviderInstanceDialogContent onOpenChange={onOpenChange} /> : null}
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
function AddProviderInstanceDialogContent({
|
||||
onOpenChange,
|
||||
}: {
|
||||
readonly onOpenChange: (open: boolean) => void;
|
||||
}) {
|
||||
const settings = useSettings();
|
||||
const { updateSettings } = useUpdateSettings();
|
||||
|
||||
@@ -121,8 +133,7 @@ export function AddProviderInstanceDialog({ open, onOpenChange }: AddProviderIns
|
||||
const [driver, setDriver] = useState<ProviderDriverKind>(DEFAULT_DRIVER_KIND);
|
||||
const [label, setLabel] = useState("");
|
||||
const [accentColor, setAccentColor] = useState<string>("");
|
||||
const [instanceId, setInstanceId] = useState("");
|
||||
const [instanceIdDirty, setInstanceIdDirty] = useState(false);
|
||||
const [manualInstanceId, setManualInstanceId] = useState<string | null>(null);
|
||||
// Driver-specific config drafts keyed by driver so toggling between drivers
|
||||
// during the same dialog session does not lose in-progress input.
|
||||
const [configByDriver, setConfigByDriver] = useState<Record<string, Record<string, unknown>>>({});
|
||||
@@ -135,32 +146,12 @@ export function AddProviderInstanceDialog({ open, onOpenChange }: AddProviderIns
|
||||
[settings.providerInstances],
|
||||
);
|
||||
|
||||
// Reset the form every time the dialog opens so each creation starts
|
||||
// from a clean slate.
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
setDriver(DEFAULT_DRIVER_KIND);
|
||||
setLabel("");
|
||||
setAccentColor("");
|
||||
setInstanceId("");
|
||||
setWizardStep(0);
|
||||
setInstanceIdDirty(false);
|
||||
setConfigByDriver({});
|
||||
setHasAttemptedSubmit(false);
|
||||
}, [open]);
|
||||
|
||||
// Auto-derive the instance id from driver + label until the user types
|
||||
// in the Instance ID field directly (after which they own its value).
|
||||
useEffect(() => {
|
||||
if (instanceIdDirty) return;
|
||||
setInstanceId(deriveInstanceId(driver, label));
|
||||
}, [driver, label, instanceIdDirty]);
|
||||
|
||||
const driverOption = DRIVER_OPTION_BY_VALUE[driver] ?? DEFAULT_DRIVER_OPTION;
|
||||
const driverSettingsFields = useMemo(
|
||||
() => deriveProviderSettingsFields(driverOption),
|
||||
[driverOption],
|
||||
);
|
||||
const instanceId = manualInstanceId ?? deriveInstanceId(driver, label);
|
||||
const instanceIdError = validateInstanceId(instanceId, existingIds);
|
||||
const showInstanceIdError = hasAttemptedSubmit && instanceIdError !== null;
|
||||
const previewLabel = label.trim() || `${driverOption.label} Workspace`;
|
||||
@@ -236,256 +227,250 @@ export function AddProviderInstanceDialog({ open, onOpenChange }: AddProviderIns
|
||||
]);
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogPopup className="max-w-xl overflow-hidden">
|
||||
<div className="flex min-h-0 flex-col overflow-hidden border-foreground/10 bg-background shadow-2xl">
|
||||
<DialogHeader className="border-b border-border/70 bg-background">
|
||||
<DialogTitle>Add provider instance</DialogTitle>
|
||||
<DialogDescription>
|
||||
Configure an additional provider instance — for example, a second Codex install
|
||||
pointed at a different workspace.
|
||||
</DialogDescription>
|
||||
<div className="grid grid-cols-3 gap-2">
|
||||
{wizardSteps.map((step, index) => (
|
||||
<button
|
||||
key={step}
|
||||
type="button"
|
||||
className={cn(
|
||||
"grid min-w-0 grid-cols-[1rem_minmax(0,1fr)] gap-x-2 rounded-lg border px-3 py-2 text-left",
|
||||
index === wizardStep
|
||||
? "border-primary bg-primary/10 ring-1 ring-primary/25"
|
||||
: index < wizardStep
|
||||
? "border-border bg-background"
|
||||
: "border-border bg-muted/40",
|
||||
)}
|
||||
onClick={() => setWizardStep(index)}
|
||||
>
|
||||
<span
|
||||
className={cn(
|
||||
"row-span-2 mt-0.5 grid size-4 place-items-center rounded-full border",
|
||||
index < wizardStep
|
||||
? "border-primary bg-primary text-primary-foreground"
|
||||
: index === wizardStep
|
||||
? "border-primary bg-background"
|
||||
: "border-muted-foreground/35 bg-background",
|
||||
)}
|
||||
aria-hidden
|
||||
>
|
||||
{index < wizardStep ? <CheckIcon className="size-3" /> : null}
|
||||
</span>
|
||||
<span className="text-[10px] font-medium uppercase text-muted-foreground">
|
||||
Step {index + 1}
|
||||
</span>
|
||||
<span className="truncate text-xs font-semibold text-foreground">
|
||||
{step}
|
||||
{index < wizardStep && wizardStepSummaries[index]
|
||||
? `: ${wizardStepSummaries[index]}`
|
||||
: ""}
|
||||
</span>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</DialogHeader>
|
||||
|
||||
<div
|
||||
data-slot="dialog-panel"
|
||||
className="space-y-4 border-b border-border/70 bg-muted/20 px-6 py-5"
|
||||
>
|
||||
<AnimatedHeight>
|
||||
<div className={cn("grid gap-2", wizardStep !== 0 && "hidden")}>
|
||||
<span
|
||||
id="add-instance-driver-label"
|
||||
className="text-xs font-medium text-foreground"
|
||||
>
|
||||
Driver
|
||||
</span>
|
||||
<RadioGroup
|
||||
value={driver}
|
||||
onValueChange={(value) => setDriver(ProviderDriverKind.make(value))}
|
||||
aria-labelledby="add-instance-driver-label"
|
||||
className="grid grid-cols-2 gap-2.5"
|
||||
>
|
||||
{DRIVER_OPTIONS.map((option) => {
|
||||
const IconComponent = option.icon;
|
||||
const isSelected = option.value === driver;
|
||||
return (
|
||||
<RadioPrimitive.Root
|
||||
key={option.value}
|
||||
value={option.value}
|
||||
className={cn(
|
||||
"relative flex cursor-pointer items-center gap-3 rounded-lg border px-3 py-3 text-left outline-none transition-[background-color,border-color,box-shadow]",
|
||||
"focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background",
|
||||
isSelected
|
||||
? "border-primary bg-background shadow-sm ring-2 ring-primary/35"
|
||||
: "border-border bg-background hover:border-foreground/20 hover:bg-muted/50",
|
||||
)}
|
||||
>
|
||||
<IconComponent className="size-5 shrink-0" aria-hidden />
|
||||
<span className="min-w-0 flex-1 truncate text-sm font-medium text-foreground">
|
||||
{option.label}
|
||||
</span>
|
||||
{option.badgeLabel ? (
|
||||
<Badge variant="warning" size="sm">
|
||||
{option.badgeLabel}
|
||||
</Badge>
|
||||
) : null}
|
||||
</RadioPrimitive.Root>
|
||||
);
|
||||
})}
|
||||
{COMING_SOON_DRIVER_OPTIONS.map((option) => {
|
||||
const IconComponent = option.icon;
|
||||
return (
|
||||
<RadioPrimitive.Root
|
||||
key={option.value}
|
||||
value={option.value}
|
||||
disabled
|
||||
className={cn(
|
||||
"relative flex cursor-not-allowed items-center gap-3 rounded-lg border border-border bg-background px-3 py-3 text-left opacity-55 outline-none",
|
||||
)}
|
||||
>
|
||||
<IconComponent
|
||||
className="size-5 shrink-0 text-muted-foreground"
|
||||
aria-hidden
|
||||
/>
|
||||
<span className="min-w-0 flex-1 truncate text-sm font-medium text-foreground">
|
||||
{option.label}
|
||||
</span>
|
||||
<Badge variant="warning" size="sm">
|
||||
Coming Soon
|
||||
</Badge>
|
||||
</RadioPrimitive.Root>
|
||||
);
|
||||
})}
|
||||
</RadioGroup>
|
||||
</div>
|
||||
|
||||
<label className={cn("grid gap-2", wizardStep !== 1 && "hidden")}>
|
||||
<span className="text-xs font-medium text-foreground">Label</span>
|
||||
<Input
|
||||
className="bg-background"
|
||||
placeholder="e.g. Work"
|
||||
value={label}
|
||||
onChange={(event) => setLabel(event.target.value)}
|
||||
/>
|
||||
<span className="text-[11px] text-muted-foreground">
|
||||
Shown in the provider list. Optional.
|
||||
</span>
|
||||
</label>
|
||||
|
||||
<label className={cn("grid gap-2", wizardStep !== 1 && "hidden")}>
|
||||
<span className="text-xs font-medium text-foreground">Instance ID</span>
|
||||
<Input
|
||||
className="bg-background"
|
||||
placeholder={`${driver}_work`}
|
||||
value={instanceId}
|
||||
onChange={(event) => {
|
||||
setInstanceIdDirty(true);
|
||||
setInstanceId(event.target.value);
|
||||
}}
|
||||
aria-invalid={showInstanceIdError}
|
||||
/>
|
||||
{showInstanceIdError ? (
|
||||
<span className="text-[11px] text-destructive">{instanceIdError}</span>
|
||||
) : (
|
||||
<span className="text-[11px] text-muted-foreground">
|
||||
Routing key used by threads and sessions. Letters, digits, '-', or '_'.
|
||||
</span>
|
||||
<DialogPopup className="max-w-xl overflow-hidden">
|
||||
<div className="flex min-h-0 flex-col overflow-hidden border-foreground/10 bg-background shadow-2xl">
|
||||
<DialogHeader className="border-b border-border/70 bg-background">
|
||||
<DialogTitle>Add provider instance</DialogTitle>
|
||||
<DialogDescription>
|
||||
Configure an additional provider instance — for example, a second Codex install pointed
|
||||
at a different workspace.
|
||||
</DialogDescription>
|
||||
<div className="grid grid-cols-3 gap-2">
|
||||
{wizardSteps.map((step, index) => (
|
||||
<button
|
||||
key={step}
|
||||
type="button"
|
||||
className={cn(
|
||||
"grid min-w-0 grid-cols-[1rem_minmax(0,1fr)] gap-x-2 rounded-lg border px-3 py-2 text-left",
|
||||
index === wizardStep
|
||||
? "border-primary bg-primary/10 ring-1 ring-primary/25"
|
||||
: index < wizardStep
|
||||
? "border-border bg-background"
|
||||
: "border-border bg-muted/40",
|
||||
)}
|
||||
</label>
|
||||
|
||||
<div className={cn("grid gap-2", wizardStep !== 1 && "hidden")}>
|
||||
<span className="text-xs font-medium text-foreground">Accent color</span>
|
||||
<div className="flex min-w-0 flex-wrap items-center gap-2">
|
||||
<input
|
||||
type="color"
|
||||
value={normalizeProviderAccentColor(accentColor) ?? PROVIDER_ACCENT_SWATCHES[0]}
|
||||
onChange={(event) => setAccentColor(event.target.value)}
|
||||
aria-label="Provider instance accent color"
|
||||
className="h-8 w-10 cursor-pointer rounded-xl border border-input bg-background p-0.5"
|
||||
/>
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{PROVIDER_ACCENT_SWATCHES.map((swatch) => {
|
||||
const selected = accentColor.toLowerCase() === swatch;
|
||||
return (
|
||||
<button
|
||||
key={swatch}
|
||||
type="button"
|
||||
className={cn(
|
||||
"size-6 cursor-pointer rounded-full border transition",
|
||||
selected
|
||||
? "scale-110 border-foreground ring-2 ring-ring ring-offset-1 ring-offset-background"
|
||||
: "border-black/10 hover:scale-105 dark:border-white/20",
|
||||
)}
|
||||
style={{ backgroundColor: swatch }}
|
||||
onClick={() => setAccentColor(swatch)}
|
||||
aria-label={`Use ${swatch} accent`}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
{accentColor ? (
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
className="h-7 px-2 text-xs text-muted-foreground"
|
||||
onClick={() => setAccentColor("")}
|
||||
>
|
||||
Clear
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
<span className="text-[11px] text-muted-foreground">
|
||||
Optional marker shown in the picker.
|
||||
onClick={() => setWizardStep(index)}
|
||||
>
|
||||
<span
|
||||
className={cn(
|
||||
"row-span-2 mt-0.5 grid size-4 place-items-center rounded-full border",
|
||||
index < wizardStep
|
||||
? "border-primary bg-primary text-primary-foreground"
|
||||
: index === wizardStep
|
||||
? "border-primary bg-background"
|
||||
: "border-muted-foreground/35 bg-background",
|
||||
)}
|
||||
aria-hidden
|
||||
>
|
||||
{index < wizardStep ? <CheckIcon className="size-3" /> : null}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{driverSettingsFields.length > 0 ? (
|
||||
<div className={cn("grid gap-4", wizardStep !== 2 && "hidden")}>
|
||||
<ProviderSettingsForm
|
||||
definition={driverOption}
|
||||
value={configDraft}
|
||||
idPrefix={`add-provider-${driver}`}
|
||||
variant="dialog"
|
||||
onChange={setConfigDraft}
|
||||
/>
|
||||
</div>
|
||||
) : wizardStep === 2 ? (
|
||||
<div className="grid gap-2">
|
||||
<p className="text-sm text-muted-foreground">
|
||||
This driver has no required configuration. You can add the instance now.
|
||||
</p>
|
||||
</div>
|
||||
) : null}
|
||||
</AnimatedHeight>
|
||||
<span className="text-[10px] font-medium uppercase text-muted-foreground">
|
||||
Step {index + 1}
|
||||
</span>
|
||||
<span className="truncate text-xs font-semibold text-foreground">
|
||||
{step}
|
||||
{index < wizardStep && wizardStepSummaries[index]
|
||||
? `: ${wizardStepSummaries[index]}`
|
||||
: ""}
|
||||
</span>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</DialogHeader>
|
||||
|
||||
<DialogFooter className="border-t bg-background">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => {
|
||||
if (wizardStep === 0) {
|
||||
onOpenChange(false);
|
||||
return;
|
||||
}
|
||||
setWizardStep((step) => Math.max(0, step - 1));
|
||||
}}
|
||||
>
|
||||
{wizardStep === 0 ? "Cancel" : "Back"}
|
||||
</Button>
|
||||
{wizardStep < wizardSteps.length - 1 ? (
|
||||
<Button size="sm" onClick={() => setWizardStep((step) => Math.min(2, step + 1))}>
|
||||
Next
|
||||
</Button>
|
||||
) : (
|
||||
<Button size="sm" onClick={handleSave}>
|
||||
Add instance
|
||||
</Button>
|
||||
)}
|
||||
</DialogFooter>
|
||||
<div
|
||||
data-slot="dialog-panel"
|
||||
className="space-y-4 border-b border-border/70 bg-muted/20 px-6 py-5"
|
||||
>
|
||||
<AnimatedHeight>
|
||||
<div className={cn("grid gap-2", wizardStep !== 0 && "hidden")}>
|
||||
<span id="add-instance-driver-label" className="text-xs font-medium text-foreground">
|
||||
Driver
|
||||
</span>
|
||||
<RadioGroup
|
||||
value={driver}
|
||||
onValueChange={(value) => setDriver(ProviderDriverKind.make(value))}
|
||||
aria-labelledby="add-instance-driver-label"
|
||||
className="grid grid-cols-2 gap-2.5"
|
||||
>
|
||||
{DRIVER_OPTIONS.map((option) => {
|
||||
const IconComponent = option.icon;
|
||||
const isSelected = option.value === driver;
|
||||
return (
|
||||
<RadioPrimitive.Root
|
||||
key={option.value}
|
||||
value={option.value}
|
||||
className={cn(
|
||||
"relative flex cursor-pointer items-center gap-3 rounded-lg border px-3 py-3 text-left outline-none transition-[background-color,border-color,box-shadow]",
|
||||
"focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background",
|
||||
isSelected
|
||||
? "border-primary bg-background shadow-sm ring-2 ring-primary/35"
|
||||
: "border-border bg-background hover:border-foreground/20 hover:bg-muted/50",
|
||||
)}
|
||||
>
|
||||
<IconComponent className="size-5 shrink-0" aria-hidden />
|
||||
<span className="min-w-0 flex-1 truncate text-sm font-medium text-foreground">
|
||||
{option.label}
|
||||
</span>
|
||||
{option.badgeLabel ? (
|
||||
<Badge variant="warning" size="sm">
|
||||
{option.badgeLabel}
|
||||
</Badge>
|
||||
) : null}
|
||||
</RadioPrimitive.Root>
|
||||
);
|
||||
})}
|
||||
{COMING_SOON_DRIVER_OPTIONS.map((option) => {
|
||||
const IconComponent = option.icon;
|
||||
return (
|
||||
<RadioPrimitive.Root
|
||||
key={option.value}
|
||||
value={option.value}
|
||||
disabled
|
||||
className={cn(
|
||||
"relative flex cursor-not-allowed items-center gap-3 rounded-lg border border-border bg-background px-3 py-3 text-left opacity-55 outline-none",
|
||||
)}
|
||||
>
|
||||
<IconComponent
|
||||
className="size-5 shrink-0 text-muted-foreground"
|
||||
aria-hidden
|
||||
/>
|
||||
<span className="min-w-0 flex-1 truncate text-sm font-medium text-foreground">
|
||||
{option.label}
|
||||
</span>
|
||||
<Badge variant="warning" size="sm">
|
||||
Coming Soon
|
||||
</Badge>
|
||||
</RadioPrimitive.Root>
|
||||
);
|
||||
})}
|
||||
</RadioGroup>
|
||||
</div>
|
||||
|
||||
<label className={cn("grid gap-2", wizardStep !== 1 && "hidden")}>
|
||||
<span className="text-xs font-medium text-foreground">Label</span>
|
||||
<Input
|
||||
className="bg-background"
|
||||
placeholder="e.g. Work"
|
||||
value={label}
|
||||
onChange={(event) => setLabel(event.target.value)}
|
||||
/>
|
||||
<span className="text-[11px] text-muted-foreground">
|
||||
Shown in the provider list. Optional.
|
||||
</span>
|
||||
</label>
|
||||
|
||||
<label className={cn("grid gap-2", wizardStep !== 1 && "hidden")}>
|
||||
<span className="text-xs font-medium text-foreground">Instance ID</span>
|
||||
<Input
|
||||
className="bg-background"
|
||||
placeholder={`${driver}_work`}
|
||||
value={instanceId}
|
||||
onChange={(event) => {
|
||||
setManualInstanceId(event.target.value);
|
||||
}}
|
||||
aria-invalid={showInstanceIdError}
|
||||
/>
|
||||
{showInstanceIdError ? (
|
||||
<span className="text-[11px] text-destructive">{instanceIdError}</span>
|
||||
) : (
|
||||
<span className="text-[11px] text-muted-foreground">
|
||||
Routing key used by threads and sessions. Letters, digits, '-', or '_'.
|
||||
</span>
|
||||
)}
|
||||
</label>
|
||||
|
||||
<div className={cn("grid gap-2", wizardStep !== 1 && "hidden")}>
|
||||
<span className="text-xs font-medium text-foreground">Accent color</span>
|
||||
<div className="flex min-w-0 flex-wrap items-center gap-2">
|
||||
<input
|
||||
type="color"
|
||||
value={normalizeProviderAccentColor(accentColor) ?? PROVIDER_ACCENT_SWATCHES[0]}
|
||||
onChange={(event) => setAccentColor(event.target.value)}
|
||||
aria-label="Provider instance accent color"
|
||||
className="h-8 w-10 cursor-pointer rounded-xl border border-input bg-background p-0.5"
|
||||
/>
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{PROVIDER_ACCENT_SWATCHES.map((swatch) => {
|
||||
const selected = accentColor.toLowerCase() === swatch;
|
||||
return (
|
||||
<button
|
||||
key={swatch}
|
||||
type="button"
|
||||
className={cn(
|
||||
"size-6 cursor-pointer rounded-full border transition",
|
||||
selected
|
||||
? "scale-110 border-foreground ring-2 ring-ring ring-offset-1 ring-offset-background"
|
||||
: "border-black/10 hover:scale-105 dark:border-white/20",
|
||||
)}
|
||||
style={{ backgroundColor: swatch }}
|
||||
onClick={() => setAccentColor(swatch)}
|
||||
aria-label={`Use ${swatch} accent`}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
{accentColor ? (
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
className="h-7 px-2 text-xs text-muted-foreground"
|
||||
onClick={() => setAccentColor("")}
|
||||
>
|
||||
Clear
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
<span className="text-[11px] text-muted-foreground">
|
||||
Optional marker shown in the picker.
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{driverSettingsFields.length > 0 ? (
|
||||
<div className={cn("grid gap-4", wizardStep !== 2 && "hidden")}>
|
||||
<ProviderSettingsForm
|
||||
definition={driverOption}
|
||||
value={configDraft}
|
||||
idPrefix={`add-provider-${driver}`}
|
||||
variant="dialog"
|
||||
onChange={setConfigDraft}
|
||||
/>
|
||||
</div>
|
||||
) : wizardStep === 2 ? (
|
||||
<div className="grid gap-2">
|
||||
<p className="text-sm text-muted-foreground">
|
||||
This driver has no required configuration. You can add the instance now.
|
||||
</p>
|
||||
</div>
|
||||
) : null}
|
||||
</AnimatedHeight>
|
||||
</div>
|
||||
</DialogPopup>
|
||||
</Dialog>
|
||||
|
||||
<DialogFooter className="border-t bg-background">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => {
|
||||
if (wizardStep === 0) {
|
||||
onOpenChange(false);
|
||||
return;
|
||||
}
|
||||
setWizardStep((step) => Math.max(0, step - 1));
|
||||
}}
|
||||
>
|
||||
{wizardStep === 0 ? "Cancel" : "Back"}
|
||||
</Button>
|
||||
{wizardStep < wizardSteps.length - 1 ? (
|
||||
<Button size="sm" onClick={() => setWizardStep((step) => Math.min(2, step + 1))}>
|
||||
Next
|
||||
</Button>
|
||||
) : (
|
||||
<Button size="sm" onClick={handleSave}>
|
||||
Add instance
|
||||
</Button>
|
||||
)}
|
||||
</DialogFooter>
|
||||
</div>
|
||||
</DialogPopup>
|
||||
);
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Reference in new issue
Block a user