fix(opencode): handle child approvals, stops, and model catalogs (#8480)
This commit is contained in:
1 parent
0009aacdf1
commit
cb49e5d720
42 files changed
+7889
-581
No files matched your search
@@ -997,16 +997,24 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
// Instance-keyed option list so the picker can show each configured
|
||||
// instance (built-in + custom) as a first-class sidebar entry. The
|
||||
// options are server-reported models plus that exact instance's
|
||||
// configured custom models; selected slugs are not injected into lists.
|
||||
// configured custom models. A missing OpenCode selection is included as
|
||||
// an unavailable row until the catalog reports it again.
|
||||
const modelOptionsByInstance = useMemo<
|
||||
ReadonlyMap<ProviderInstanceId, ReadonlyArray<AppModelOption>>
|
||||
>(() => {
|
||||
const out = new Map<ProviderInstanceId, ReadonlyArray<AppModelOption>>();
|
||||
for (const entry of providerInstanceEntries) {
|
||||
out.set(entry.instanceId, getAppModelOptionsForInstance(settings, entry));
|
||||
out.set(
|
||||
entry.instanceId,
|
||||
getAppModelOptionsForInstance(
|
||||
settings,
|
||||
entry,
|
||||
entry.instanceId === selectedInstanceId ? selectedModelForPicker : null,
|
||||
),
|
||||
);
|
||||
}
|
||||
return out;
|
||||
}, [providerInstanceEntries, settings]);
|
||||
}, [providerInstanceEntries, selectedInstanceId, selectedModelForPicker, settings]);
|
||||
const selectedModelForPickerWithCustomFallback = useMemo(() => {
|
||||
const currentOptions = modelOptionsByInstance.get(selectedInstanceId) ?? [];
|
||||
return currentOptions.some((option) => option.slug === selectedModelForPicker)
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
} from "./providerIconUtils";
|
||||
import { ComboboxItem } from "../ui/combobox";
|
||||
import { Button } from "../ui/button";
|
||||
import { Badge } from "../ui/badge";
|
||||
import { Kbd } from "../ui/kbd";
|
||||
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
|
||||
import { cn } from "~/lib/utils";
|
||||
@@ -34,6 +35,7 @@ export const ModelListRow = memo(function ModelListRow(props: {
|
||||
preferShortName?: boolean;
|
||||
useTriggerLabel?: boolean;
|
||||
showNewBadge?: boolean;
|
||||
unavailable?: boolean;
|
||||
jumpLabel?: string | null;
|
||||
disabledReason?: string | null;
|
||||
onToggleFavorite: () => void;
|
||||
@@ -75,6 +77,11 @@ export const ModelListRow = memo(function ModelListRow(props: {
|
||||
New
|
||||
</span>
|
||||
) : null}
|
||||
{props.unavailable ? (
|
||||
<Badge variant="outline" size="sm">
|
||||
Unavailable
|
||||
</Badge>
|
||||
) : null}
|
||||
</div>
|
||||
{props.showProvider && (
|
||||
<div className="mt-1 flex items-center gap-1.5">
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
import { ProviderDriverKind, ProviderInstanceId, type ServerProvider } from "@t3tools/contracts";
|
||||
import { describe, expect, it } from "vite-plus/test";
|
||||
|
||||
import { deriveProviderInstanceEntries } from "../../providerInstances";
|
||||
import { shouldIncludeModelPickerOption } from "./ModelPickerContent";
|
||||
|
||||
function entry(status: ServerProvider["status"]) {
|
||||
return deriveProviderInstanceEntries([
|
||||
{
|
||||
instanceId: ProviderInstanceId.make("opencode_work"),
|
||||
driver: ProviderDriverKind.make("opencode"),
|
||||
enabled: true,
|
||||
installed: true,
|
||||
version: null,
|
||||
status,
|
||||
auth: { status: "authenticated" },
|
||||
checkedAt: "2026-08-28T00:00:00.000Z",
|
||||
models: [],
|
||||
slashCommands: [],
|
||||
skills: [],
|
||||
},
|
||||
])[0]!;
|
||||
}
|
||||
|
||||
describe("shouldIncludeModelPickerOption", () => {
|
||||
it.each(["error", "warning"] as const)(
|
||||
"keeps only the active synthetic OpenCode row when the provider status is %s",
|
||||
(status) => {
|
||||
const providerEntry = entry(status);
|
||||
const activeInstanceId = ProviderInstanceId.make("opencode_work");
|
||||
const activeModel = "openrouter/kimi-k3";
|
||||
|
||||
expect(
|
||||
shouldIncludeModelPickerOption({
|
||||
entry: providerEntry,
|
||||
option: {
|
||||
slug: activeModel,
|
||||
name: activeModel,
|
||||
isUnavailable: true,
|
||||
},
|
||||
activeInstanceId,
|
||||
activeModel,
|
||||
}),
|
||||
).toBe(true);
|
||||
expect(
|
||||
shouldIncludeModelPickerOption({
|
||||
entry: providerEntry,
|
||||
option: { slug: "stale/model", name: "Stale model" },
|
||||
activeInstanceId,
|
||||
activeModel,
|
||||
}),
|
||||
).toBe(false);
|
||||
expect(
|
||||
shouldIncludeModelPickerOption({
|
||||
entry: providerEntry,
|
||||
option: {
|
||||
slug: "other/missing",
|
||||
name: "Other missing",
|
||||
isUnavailable: true,
|
||||
},
|
||||
activeInstanceId,
|
||||
activeModel,
|
||||
}),
|
||||
).toBe(false);
|
||||
},
|
||||
);
|
||||
});
|
||||
@@ -53,8 +53,25 @@ type ModelPickerItem = {
|
||||
instanceAccentColor?: string | undefined;
|
||||
continuationGroupKey?: string | undefined;
|
||||
isLegacy?: boolean | undefined;
|
||||
isUnavailable?: boolean | undefined;
|
||||
};
|
||||
|
||||
export function shouldIncludeModelPickerOption(input: {
|
||||
readonly entry: ProviderInstanceEntry;
|
||||
readonly option: ModelEsque;
|
||||
readonly activeInstanceId: ProviderInstanceId;
|
||||
readonly activeModel: string;
|
||||
}): boolean {
|
||||
if (isProviderInstancePickerReady(input.entry)) return true;
|
||||
return (
|
||||
input.entry.enabled &&
|
||||
input.entry.driverKind === "opencode" &&
|
||||
input.entry.instanceId === input.activeInstanceId &&
|
||||
input.option.slug === input.activeModel &&
|
||||
input.option.isUnavailable === true
|
||||
);
|
||||
}
|
||||
|
||||
const EMPTY_MODEL_JUMP_LABELS = new Map<string, string>();
|
||||
|
||||
function ModelListSeparator() {
|
||||
@@ -107,9 +124,23 @@ export const ModelPickerContent = memo(function ModelPickerContent(props: {
|
||||
const modelListRef = useRef<LegendListRef | null>(null);
|
||||
const highlightedModelKeyRef = useRef<string | null>(null);
|
||||
const favorites = useClientSettings((s) => s.favorites ?? []);
|
||||
const activeEntry = props.instanceEntries.find(
|
||||
(entry) => entry.instanceId === props.activeInstanceId,
|
||||
);
|
||||
const activeInstanceHasSelectableUnavailableModel =
|
||||
activeEntry !== undefined &&
|
||||
(modelOptionsByInstance.get(props.activeInstanceId) ?? []).some((option) =>
|
||||
shouldIncludeModelPickerOption({
|
||||
entry: activeEntry,
|
||||
option,
|
||||
activeInstanceId: props.activeInstanceId,
|
||||
activeModel: props.model,
|
||||
}),
|
||||
) &&
|
||||
!isProviderInstancePickerReady(activeEntry);
|
||||
const [selectedInstanceId, setSelectedInstanceId] = useState<ProviderInstanceId | "favorites">(
|
||||
() => {
|
||||
if (props.lockedProvider !== null) {
|
||||
if (props.lockedProvider !== null || activeInstanceHasSelectableUnavailableModel) {
|
||||
// When locked, prime the sidebar to the currently-active instance
|
||||
// so jumping into the picker keeps the focused instance visible.
|
||||
return props.activeInstanceId;
|
||||
@@ -189,15 +220,12 @@ export const ModelPickerContent = memo(function ModelPickerContent(props: {
|
||||
[props.lockedContinuationGroupKey, props.lockedProvider],
|
||||
);
|
||||
|
||||
const readyInstanceSet = useMemo(() => {
|
||||
const ready = new Set<ProviderInstanceId>();
|
||||
for (const entry of instanceEntries) {
|
||||
if (isProviderInstancePickerReady(entry)) {
|
||||
ready.add(entry.instanceId);
|
||||
}
|
||||
const selectableUnavailableInstanceIds = useMemo(() => {
|
||||
if (!activeInstanceHasSelectableUnavailableModel) {
|
||||
return undefined;
|
||||
}
|
||||
return ready;
|
||||
}, [instanceEntries]);
|
||||
return new Set([props.activeInstanceId]);
|
||||
}, [activeInstanceHasSelectableUnavailableModel, props.activeInstanceId]);
|
||||
|
||||
// Flatten models into a searchable array. One pass over the
|
||||
// instance-keyed map; each model carries its instance id + driver kind
|
||||
@@ -212,16 +240,24 @@ export const ModelPickerContent = memo(function ModelPickerContent(props: {
|
||||
// its models — stale options shouldn't appear in the picker.
|
||||
continue;
|
||||
}
|
||||
if (!readyInstanceSet.has(instanceId)) {
|
||||
continue;
|
||||
}
|
||||
for (const model of models) {
|
||||
if (
|
||||
!shouldIncludeModelPickerOption({
|
||||
entry,
|
||||
option: model,
|
||||
activeInstanceId: props.activeInstanceId,
|
||||
activeModel: props.model,
|
||||
})
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
out.push({
|
||||
slug: model.slug,
|
||||
name: model.name,
|
||||
...(model.shortName ? { shortName: model.shortName } : {}),
|
||||
...(model.subProvider ? { subProvider: model.subProvider } : {}),
|
||||
...(model.isLegacy ? { isLegacy: true } : {}),
|
||||
...(model.isUnavailable ? { isUnavailable: true } : {}),
|
||||
instanceId,
|
||||
driverKind: entry.driverKind,
|
||||
instanceDisplayName: entry.displayName,
|
||||
@@ -233,7 +269,7 @@ export const ModelPickerContent = memo(function ModelPickerContent(props: {
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}, [modelOptionsByInstance, entryByInstanceId, readyInstanceSet]);
|
||||
}, [modelOptionsByInstance, entryByInstanceId, props.activeInstanceId, props.model]);
|
||||
|
||||
const isLocked = props.lockedProvider !== null;
|
||||
const isSearching = searchQuery.trim().length > 0;
|
||||
@@ -609,6 +645,7 @@ export const ModelPickerContent = memo(function ModelPickerContent(props: {
|
||||
onSelectInstance={handleSelectInstance}
|
||||
instanceEntries={sidebarInstanceEntries}
|
||||
showFavorites
|
||||
{...(selectableUnavailableInstanceIds ? { selectableUnavailableInstanceIds } : {})}
|
||||
{...(lockedDisabledInstanceIds
|
||||
? {
|
||||
disabledInstanceIds: lockedDisabledInstanceIds,
|
||||
@@ -768,6 +805,7 @@ export const ModelPickerContent = memo(function ModelPickerContent(props: {
|
||||
preferShortName={!isLocked}
|
||||
useTriggerLabel={false}
|
||||
showNewBadge={isModelPickerNewModel(model.driverKind, model.slug)}
|
||||
unavailable={model.isUnavailable === true}
|
||||
jumpLabel={modelJumpLabelByKey.get(modelKey) ?? null}
|
||||
disabledReason={disabledReason}
|
||||
onToggleFavorite={() => toggleFavorite(model.instanceId, model.slug)}
|
||||
|
||||
@@ -54,6 +54,8 @@ export const ModelPickerSidebar = memo(function ModelPickerSidebar(props: {
|
||||
showFavorites?: boolean;
|
||||
/** Instance ids shown in the rail but unavailable for the current picker context. */
|
||||
disabledInstanceIds?: ReadonlySet<ProviderInstanceId>;
|
||||
/** Non-ready instances whose selected unavailable model remains reachable. */
|
||||
selectableUnavailableInstanceIds?: ReadonlySet<ProviderInstanceId>;
|
||||
getDisabledInstanceTooltip?: (entry: ProviderInstanceEntry) => string;
|
||||
/**
|
||||
* Instance id values that should render the "new" sparkle badge. Callers
|
||||
@@ -135,7 +137,10 @@ export const ModelPickerSidebar = memo(function ModelPickerSidebar(props: {
|
||||
{props.instanceEntries.map((entry) => {
|
||||
const isUnavailable = !isProviderInstancePickerReady(entry);
|
||||
const isContextDisabled = props.disabledInstanceIds?.has(entry.instanceId) ?? false;
|
||||
const isDisabled = isUnavailable || isContextDisabled;
|
||||
const unavailableSelectionIsReachable =
|
||||
props.selectableUnavailableInstanceIds?.has(entry.instanceId) ?? false;
|
||||
const isDisabled =
|
||||
(isUnavailable && !unavailableSelectionIsReachable) || isContextDisabled;
|
||||
const isSelected = props.selectedInstanceId === entry.instanceId;
|
||||
const isHovered = hoveredInstanceId === entry.instanceId;
|
||||
const showNewBadge = props.newBadgeInstanceIds?.has(entry.instanceId) ?? false;
|
||||
@@ -168,7 +173,7 @@ export const ModelPickerSidebar = memo(function ModelPickerSidebar(props: {
|
||||
disabled={isDisabled}
|
||||
type="button"
|
||||
aria-label={
|
||||
isDisabled
|
||||
isUnavailable || isContextDisabled
|
||||
? tooltip
|
||||
: showNewBadge
|
||||
? `${entry.displayName}, new`
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
import { ProviderDriverKind, ProviderInstanceId, type ServerProvider } from "@t3tools/contracts";
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
import { describe, expect, it } from "vite-plus/test";
|
||||
|
||||
import { deriveProviderInstanceEntries } from "../../providerInstances";
|
||||
import { ProviderModelPicker } from "./ProviderModelPicker";
|
||||
import type { ModelEsque } from "./providerIconUtils";
|
||||
|
||||
function providerEntry(instanceId: string, driver: string) {
|
||||
const provider: ServerProvider = {
|
||||
instanceId: ProviderInstanceId.make(instanceId),
|
||||
driver: ProviderDriverKind.make(driver),
|
||||
enabled: true,
|
||||
installed: true,
|
||||
version: null,
|
||||
status: "ready",
|
||||
auth: { status: "authenticated" },
|
||||
checkedAt: "2026-08-28T00:00:00.000Z",
|
||||
models: [],
|
||||
slashCommands: [],
|
||||
skills: [],
|
||||
};
|
||||
return deriveProviderInstanceEntries([provider])[0]!;
|
||||
}
|
||||
|
||||
function renderPicker(input: {
|
||||
instanceId: string;
|
||||
driver: string;
|
||||
model: string;
|
||||
options: ReadonlyArray<ModelEsque>;
|
||||
includeEntry?: boolean;
|
||||
}) {
|
||||
const instanceId = ProviderInstanceId.make(input.instanceId);
|
||||
const entry = providerEntry(input.instanceId, input.driver);
|
||||
return renderToStaticMarkup(
|
||||
<ProviderModelPicker
|
||||
activeInstanceId={instanceId}
|
||||
model={input.model}
|
||||
lockedProvider={null}
|
||||
instanceEntries={input.includeEntry === false ? [] : [entry]}
|
||||
modelOptionsByInstance={new Map([[instanceId, input.options]])}
|
||||
onInstanceModelChange={() => {}}
|
||||
/>,
|
||||
);
|
||||
}
|
||||
|
||||
describe("ProviderModelPicker", () => {
|
||||
it("shows a missing model slug for a custom OpenCode instance", () => {
|
||||
const markup = renderPicker({
|
||||
instanceId: "team_runtime",
|
||||
driver: "opencode",
|
||||
model: "openrouter/missing-model",
|
||||
options: [{ slug: "openrouter/fallback", name: "Fallback model" }],
|
||||
});
|
||||
|
||||
expect(markup).toContain("openrouter/missing-model");
|
||||
expect(markup).not.toContain("Fallback model");
|
||||
});
|
||||
|
||||
it.each(["codex", "claudeAgent", "cursor", "grok"])(
|
||||
"uses the first option label for a missing %s model",
|
||||
(driver) => {
|
||||
const markup = renderPicker({
|
||||
instanceId: `${driver}_work`,
|
||||
driver,
|
||||
model: "missing-model",
|
||||
options: [{ slug: "fallback-model", name: "Fallback model" }],
|
||||
});
|
||||
|
||||
expect(markup).toContain("Fallback model");
|
||||
expect(markup).not.toContain(">missing-model<");
|
||||
},
|
||||
);
|
||||
|
||||
it("prefers a matching model for OpenCode", () => {
|
||||
const markup = renderPicker({
|
||||
instanceId: "custom_runtime",
|
||||
driver: "opencode",
|
||||
model: "openrouter/selected",
|
||||
options: [
|
||||
{ slug: "openrouter/fallback", name: "Fallback model" },
|
||||
{ slug: "openrouter/selected", name: "Selected model" },
|
||||
],
|
||||
});
|
||||
|
||||
expect(markup).toContain("Selected model");
|
||||
expect(markup).not.toContain("Fallback model");
|
||||
});
|
||||
|
||||
it("uses the first option when the active instance entry is missing", () => {
|
||||
const markup = renderPicker({
|
||||
instanceId: "missing_instance",
|
||||
driver: "opencode",
|
||||
model: "missing-model",
|
||||
options: [{ slug: "fallback-model", name: "Fallback model" }],
|
||||
includeEntry: false,
|
||||
});
|
||||
|
||||
expect(markup).toContain("Fallback model");
|
||||
expect(markup).not.toContain(">missing-model<");
|
||||
});
|
||||
});
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
} from "@t3tools/contracts";
|
||||
import { memo, useEffect, useMemo, useState } from "react";
|
||||
import type { VariantProps } from "class-variance-authority";
|
||||
import { Badge } from "../ui/badge";
|
||||
import { buttonVariants } from "../ui/button";
|
||||
import { Popover, PopoverPopup, PopoverTrigger } from "../ui/popover";
|
||||
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
|
||||
@@ -58,15 +59,15 @@ export const ProviderModelPicker = memo(function ProviderModelPicker(props: {
|
||||
|
||||
const activeInstanceId = props.activeInstanceId;
|
||||
const selectedInstanceOptions = props.modelOptionsByInstance.get(activeInstanceId) ?? [];
|
||||
// If the current slug belongs to a different instance (for example after
|
||||
// a provider switch or disable), prefer the active instance's first
|
||||
// option so the trigger icon and label stay in sync instead of showing
|
||||
// a stale foreign slug.
|
||||
// OpenCode can keep a model through a transient catalog refresh. Other
|
||||
// providers keep the active instance's first option as their normal fallback.
|
||||
const selectedModel =
|
||||
selectedInstanceOptions.find((option) => option.slug === props.model) ??
|
||||
selectedInstanceOptions[0];
|
||||
(activeEntry?.driverKind === "opencode" ? undefined : selectedInstanceOptions[0]);
|
||||
const triggerTitle = selectedModel ? getTriggerDisplayModelName(selectedModel) : props.model;
|
||||
const triggerLabel = selectedModel ? getTriggerDisplayModelLabel(selectedModel) : props.model;
|
||||
const triggerLabel = selectedModel
|
||||
? `${getTriggerDisplayModelLabel(selectedModel)}${selectedModel.isUnavailable ? " (Unavailable)" : ""}`
|
||||
: props.model;
|
||||
const showInstanceBadge =
|
||||
activeEntry !== null && shouldShowInstanceBadge(activeEntry, props.instanceEntries);
|
||||
|
||||
@@ -179,6 +180,11 @@ export const ProviderModelPicker = memo(function ProviderModelPicker(props: {
|
||||
</TooltipTrigger>
|
||||
<TooltipPopup side="top">{triggerLabel}</TooltipPopup>
|
||||
</Tooltip>
|
||||
{selectedModel?.isUnavailable ? (
|
||||
<Badge variant="outline" size="sm">
|
||||
Unavailable
|
||||
</Badge>
|
||||
) : null}
|
||||
</span>
|
||||
<span aria-hidden="true" className="flex items-center">
|
||||
<ComposerControlChevron />
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it } from "vite-plus/test";
|
||||
import { ProviderDriverKind, type ProviderOptionDescriptor } from "@t3tools/contracts";
|
||||
import { buildTraitsTriggerDisplay } from "./TraitsPicker";
|
||||
import { buildTraitsTriggerDisplay, buildUnavailableModelOptionDescriptors } from "./TraitsPicker";
|
||||
|
||||
function selectDescriptor(
|
||||
id: string,
|
||||
@@ -155,3 +155,36 @@ describe("buildTraitsTriggerDisplay", () => {
|
||||
).toEqual({ label: "Ultrathink", showFastModeIcon: true });
|
||||
});
|
||||
});
|
||||
|
||||
describe("buildUnavailableModelOptionDescriptors", () => {
|
||||
it("shows only saved values without inventing alternatives", () => {
|
||||
expect(
|
||||
buildUnavailableModelOptionDescriptors([
|
||||
{ id: "variant", value: "max" },
|
||||
{ id: "agent", value: "build" },
|
||||
{ id: "fastMode", value: true },
|
||||
]),
|
||||
).toEqual([
|
||||
{
|
||||
id: "variant",
|
||||
label: "Variant",
|
||||
type: "select",
|
||||
options: [{ id: "max", label: "max" }],
|
||||
currentValue: "max",
|
||||
},
|
||||
{
|
||||
id: "agent",
|
||||
label: "Agent",
|
||||
type: "select",
|
||||
options: [{ id: "build", label: "build" }],
|
||||
currentValue: "build",
|
||||
},
|
||||
{
|
||||
id: "fastMode",
|
||||
label: "Fast Mode",
|
||||
type: "boolean",
|
||||
currentValue: true,
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
getProviderOptionCurrentValue,
|
||||
getProviderOptionDescriptors,
|
||||
isClaudeUltrathinkPrompt,
|
||||
normalizeModelSlug,
|
||||
} from "@t3tools/shared/model";
|
||||
import { memo, useCallback, useState } from "react";
|
||||
import type { VariantProps } from "class-variance-authority";
|
||||
@@ -35,6 +36,42 @@ import { ComposerControl, ComposerControlChevron, ComposerControlIcon } from "./
|
||||
|
||||
type ProviderOptions = ReadonlyArray<ProviderOptionSelection>;
|
||||
|
||||
const SAVED_OPTION_LABELS: Readonly<Record<string, string>> = {
|
||||
agent: "Agent",
|
||||
effort: "Effort",
|
||||
reasoningEffort: "Reasoning effort",
|
||||
variant: "Variant",
|
||||
};
|
||||
|
||||
function savedOptionLabel(id: string): string {
|
||||
return (
|
||||
SAVED_OPTION_LABELS[id] ??
|
||||
id.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/^./, (character) => character.toUpperCase())
|
||||
);
|
||||
}
|
||||
|
||||
/** Read-only descriptors for saved values whose OpenCode model metadata is unavailable. */
|
||||
export function buildUnavailableModelOptionDescriptors(
|
||||
selections: ProviderOptions | null | undefined,
|
||||
): ReadonlyArray<ProviderOptionDescriptor> {
|
||||
return (selections ?? []).map((selection) =>
|
||||
typeof selection.value === "boolean"
|
||||
? {
|
||||
id: selection.id,
|
||||
label: savedOptionLabel(selection.id),
|
||||
type: "boolean" as const,
|
||||
currentValue: selection.value,
|
||||
}
|
||||
: {
|
||||
id: selection.id,
|
||||
label: savedOptionLabel(selection.id),
|
||||
type: "select" as const,
|
||||
options: [{ id: selection.value, label: selection.value }],
|
||||
currentValue: selection.value,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
type TraitsPersistence =
|
||||
| {
|
||||
threadRef?: ScopedThreadRef;
|
||||
@@ -99,10 +136,19 @@ function getSelectedTraits(
|
||||
planModeEnabled: boolean,
|
||||
) {
|
||||
const caps = getProviderModelCapabilities(models, model, provider, planModeEnabled);
|
||||
const descriptors = getProviderOptionDescriptors({
|
||||
caps,
|
||||
selections: modelOptions,
|
||||
});
|
||||
const modelIsUnavailable =
|
||||
provider === "opencode" &&
|
||||
!models.some((candidate) => candidate.slug === normalizeModelSlug(model, provider));
|
||||
const descriptors = modelIsUnavailable
|
||||
? buildUnavailableModelOptionDescriptors(
|
||||
planModeEnabled
|
||||
? modelOptions
|
||||
: modelOptions?.filter((option) => option.id !== "agent" || option.value !== "plan"),
|
||||
)
|
||||
: getProviderOptionDescriptors({
|
||||
caps,
|
||||
selections: modelOptions,
|
||||
});
|
||||
const selectDescriptors = descriptors.filter(
|
||||
(descriptor): descriptor is Extract<ProviderOptionDescriptor, { type: "select" }> =>
|
||||
descriptor.type === "select",
|
||||
@@ -158,6 +204,7 @@ function getSelectedTraits(
|
||||
ultrathinkInBodyText,
|
||||
selectedAgent,
|
||||
selectedAgentLabel,
|
||||
modelIsUnavailable,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -193,7 +240,13 @@ function getTraitsSectionVisibility(input: {
|
||||
showFastMode,
|
||||
showContextWindow,
|
||||
showAgent,
|
||||
hasAnyControls: showEffort || showThinking || showFastMode || showContextWindow || showAgent,
|
||||
hasAnyControls:
|
||||
showEffort ||
|
||||
showThinking ||
|
||||
showFastMode ||
|
||||
showContextWindow ||
|
||||
showAgent ||
|
||||
(selected.modelIsUnavailable && selected.descriptors.length > 0),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -262,6 +315,7 @@ export const TraitsMenuContent = memo(function TraitsMenuContentImpl({
|
||||
ultrathinkPromptControlled,
|
||||
ultrathinkInBodyText,
|
||||
hasAnyControls,
|
||||
modelIsUnavailable,
|
||||
} = getTraitsSectionVisibility({
|
||||
provider,
|
||||
models,
|
||||
@@ -300,6 +354,28 @@ export const TraitsMenuContent = memo(function TraitsMenuContentImpl({
|
||||
return null;
|
||||
}
|
||||
|
||||
if (modelIsUnavailable) {
|
||||
return (
|
||||
<>
|
||||
{descriptors.map((descriptor, index) => {
|
||||
const value = getProviderOptionCurrentLabel(descriptor);
|
||||
if (!value) return null;
|
||||
return (
|
||||
<div key={descriptor.id}>
|
||||
{index > 0 ? <MenuDivider /> : null}
|
||||
<MenuGroup>
|
||||
<div className="px-2 pt-1.5 pb-1 font-medium text-muted-foreground text-xs">
|
||||
{descriptor.label}
|
||||
</div>
|
||||
<div className="px-2 pb-1.5 text-muted-foreground/80 text-xs">{value}</div>
|
||||
</MenuGroup>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
{selectDescriptors.map((descriptor, index) => {
|
||||
|
||||
@@ -238,6 +238,94 @@ describe("getComposerProviderState", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("preserves explicit options when the selected model is absent from the catalog", () => {
|
||||
const state = getComposerProviderState({
|
||||
provider: ProviderDriverKind.make("opencode"),
|
||||
model: "opencode/kimi-k3",
|
||||
models: [
|
||||
{
|
||||
slug: "opencode/big-pickle",
|
||||
name: "Big Pickle",
|
||||
isCustom: false,
|
||||
capabilities: {},
|
||||
},
|
||||
],
|
||||
modelOptions: selections(["variant", "max"], ["agent", "build"]),
|
||||
planModeEnabled: false,
|
||||
});
|
||||
|
||||
expect(state.modelOptionsForDispatch).toEqual(
|
||||
selections(["variant", "max"], ["agent", "build"]),
|
||||
);
|
||||
});
|
||||
|
||||
it.each(["codex", "claudeAgent", "cursor", "grok"])(
|
||||
"does not preserve unknown options for a missing %s model",
|
||||
(provider) => {
|
||||
const state = getComposerProviderState({
|
||||
provider: ProviderDriverKind.make(provider),
|
||||
model: "missing-model",
|
||||
models: modelWith([]),
|
||||
modelOptions: selections(["unknown", "value"]),
|
||||
planModeEnabled: true,
|
||||
});
|
||||
|
||||
expect(state.modelOptionsForDispatch).toBeUndefined();
|
||||
},
|
||||
);
|
||||
|
||||
it("preserves explicit options while the catalog is empty", () => {
|
||||
const state = getComposerProviderState({
|
||||
provider: ProviderDriverKind.make("opencode"),
|
||||
model: "opencode/kimi-k3",
|
||||
models: [],
|
||||
modelOptions: selections(["variant", "max"], ["agent", "build"]),
|
||||
planModeEnabled: false,
|
||||
});
|
||||
|
||||
expect(state.modelOptionsForDispatch).toEqual(
|
||||
selections(["variant", "max"], ["agent", "build"]),
|
||||
);
|
||||
});
|
||||
|
||||
it("validates options for a known model selected through a legacy alias", () => {
|
||||
const state = getComposerProviderState({
|
||||
provider: ProviderDriverKind.make("claudeAgent"),
|
||||
model: "opus",
|
||||
models: [
|
||||
{
|
||||
slug: "claude-opus-5",
|
||||
name: "Claude Opus 5",
|
||||
isCustom: false,
|
||||
capabilities: {
|
||||
optionDescriptors: [
|
||||
selectDescriptor("effort", [
|
||||
{ id: "low", label: "Low" },
|
||||
{ id: "high", label: "High", isDefault: true },
|
||||
]),
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
modelOptions: selections(["effort", "low"], ["unknown", "value"]),
|
||||
planModeEnabled: false,
|
||||
});
|
||||
|
||||
expect(state.modelOptionsForDispatch).toEqual(selections(["effort", "low"]));
|
||||
});
|
||||
|
||||
it("still drops the plan agent when an absent model has a saved plan selection", () => {
|
||||
const state = getComposerProviderState({
|
||||
provider: ProviderDriverKind.make("opencode"),
|
||||
model: "opencode/kimi-k3",
|
||||
models: [],
|
||||
modelOptions: selections(["variant", "max"], ["agent", "plan"]),
|
||||
planModeEnabled: false,
|
||||
});
|
||||
|
||||
expect(state.modelOptionsForDispatch).toEqual(selections(["variant", "max"]));
|
||||
});
|
||||
|
||||
it("adds ultrathink class names when the prompt triggers a promptInjectedValues descriptor", () => {
|
||||
const state = getComposerProviderState({
|
||||
provider: PROVIDER,
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
getProviderOptionCurrentValue,
|
||||
getProviderOptionDescriptors,
|
||||
isClaudeUltrathinkPrompt,
|
||||
normalizeModelSlug,
|
||||
} from "@t3tools/shared/model";
|
||||
import type { ReactNode } from "react";
|
||||
|
||||
@@ -63,6 +64,21 @@ export function getComposerProviderState(input: ComposerProviderStateInput): Com
|
||||
promptInjectionState = "none",
|
||||
planModeEnabled,
|
||||
} = input;
|
||||
if (provider === "opencode") {
|
||||
const normalizedModel = normalizeModelSlug(model, provider);
|
||||
const modelIsInCatalog = models.some((candidate) => candidate.slug === normalizedModel);
|
||||
if (!modelIsInCatalog) {
|
||||
const preservedOptions = modelOptions?.filter(
|
||||
(option) => planModeEnabled || option.id !== "agent" || option.value !== "plan",
|
||||
);
|
||||
return {
|
||||
provider,
|
||||
promptEffort: null,
|
||||
modelOptionsForDispatch:
|
||||
preservedOptions && preservedOptions.length > 0 ? preservedOptions : undefined,
|
||||
};
|
||||
}
|
||||
}
|
||||
const caps = getProviderModelCapabilities(models, model, provider, planModeEnabled);
|
||||
const descriptors = getProviderOptionDescriptors({ caps, selections: modelOptions });
|
||||
const primarySelectDescriptor = descriptors.find(
|
||||
|
||||
@@ -27,6 +27,7 @@ export type ModelEsque = {
|
||||
shortName?: string | undefined;
|
||||
subProvider?: string | undefined;
|
||||
isLegacy?: boolean | undefined;
|
||||
isUnavailable?: boolean | undefined;
|
||||
};
|
||||
|
||||
function escapeRegExp(value: string): string {
|
||||
|
||||
@@ -417,6 +417,8 @@ function ProjectDetail({ group }: { group: SidebarProjectSnapshot }) {
|
||||
// ----- default model -----
|
||||
const storedSelection = representative.defaultModelSelection;
|
||||
const resolvedSelection = resolveDefaultProviderModelSelection(serverProviders, storedSelection);
|
||||
const resolvedInstanceId = resolvedSelection?.instanceId ?? null;
|
||||
const resolvedModel = resolvedSelection?.model ?? null;
|
||||
const instanceEntries = useMemo(
|
||||
() =>
|
||||
sortProviderInstanceEntries(
|
||||
@@ -425,12 +427,11 @@ function ProjectDetail({ group }: { group: SidebarProjectSnapshot }) {
|
||||
[serverProviders, settings],
|
||||
);
|
||||
const modelOptionsByInstance = useMemo(
|
||||
() => getCustomModelOptionsByInstance(settings, serverProviders),
|
||||
[serverProviders, settings],
|
||||
);
|
||||
const activeEntry = instanceEntries.find(
|
||||
(entry) => entry.instanceId === resolvedSelection?.instanceId,
|
||||
() =>
|
||||
getCustomModelOptionsByInstance(settings, serverProviders, resolvedInstanceId, resolvedModel),
|
||||
[resolvedInstanceId, resolvedModel, serverProviders, settings],
|
||||
);
|
||||
const activeEntry = instanceEntries.find((entry) => entry.instanceId === resolvedInstanceId);
|
||||
const setDefaultModel = useCallback(
|
||||
(selection: ModelSelection | null) =>
|
||||
void updateAllMembers({ defaultModelSelection: selection }, "Failed to update default model"),
|
||||
|
||||
Reference in new issue
Block a user