Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions apps/web/src/appSettings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
getCustomModelsByProvider,
getCustomModelsForProvider,
getDefaultCustomModelsForProvider,
getProviderStartOptions,
MODEL_PROVIDER_SETTINGS,
normalizeCustomModelSlugs,
patchCustomModels,
Expand Down Expand Up @@ -118,6 +119,35 @@ describe("provider-specific custom models", () => {
});
});

describe("getProviderStartOptions", () => {
it("returns only populated provider overrides", () => {
expect(
getProviderStartOptions({
claudeBinaryPath: "/usr/local/bin/claude",
codexBinaryPath: "",
codexHomePath: "/Users/you/.codex",
}),
).toEqual({
claudeAgent: {
binaryPath: "/usr/local/bin/claude",
},
codex: {
homePath: "/Users/you/.codex",
},
});
});

it("returns undefined when no provider overrides are configured", () => {
expect(
getProviderStartOptions({
claudeBinaryPath: "",
codexBinaryPath: "",
codexHomePath: "",
}),
).toBeUndefined();
});
});

describe("provider-indexed custom model settings", () => {
const settings = {
customCodexModels: ["custom/codex-model"],
Expand Down Expand Up @@ -209,6 +239,7 @@ describe("AppSettingsSchema", () => {
}),
),
).toMatchObject({
claudeBinaryPath: "",
codexBinaryPath: "/usr/local/bin/codex",
codexHomePath: "",
defaultThreadEnvMode: "local",
Expand Down
31 changes: 30 additions & 1 deletion apps/web/src/appSettings.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { useCallback } from "react";
import { Option, Schema } from "effect";
import { TrimmedNonEmptyString, type ProviderKind } from "@t3tools/contracts";
import {
TrimmedNonEmptyString,
type ProviderKind,
type ProviderStartOptions,
} from "@t3tools/contracts";
import {
getDefaultModel,
getModelOptions,
Expand Down Expand Up @@ -47,6 +51,7 @@ const withDefaults =
);

export const AppSettingsSchema = Schema.Struct({
claudeBinaryPath: Schema.String.check(Schema.isMaxLength(4096)).pipe(withDefaults(() => "")),
codexBinaryPath: Schema.String.check(Schema.isMaxLength(4096)).pipe(withDefaults(() => "")),
codexHomePath: Schema.String.check(Schema.isMaxLength(4096)).pipe(withDefaults(() => "")),
defaultThreadEnvMode: EnvMode.pipe(withDefaults(() => "local" as const satisfies EnvMode)),
Expand Down Expand Up @@ -221,6 +226,30 @@ export function getCustomModelOptionsByProvider(
};
}

export function getProviderStartOptions(
settings: Pick<AppSettings, "claudeBinaryPath" | "codexBinaryPath" | "codexHomePath">,
): ProviderStartOptions | undefined {
const providerOptions: ProviderStartOptions = {
...(settings.codexBinaryPath || settings.codexHomePath
? {
codex: {
...(settings.codexBinaryPath ? { binaryPath: settings.codexBinaryPath } : {}),
...(settings.codexHomePath ? { homePath: settings.codexHomePath } : {}),
},
}
: {}),
...(settings.claudeBinaryPath
? {
claudeAgent: {
binaryPath: settings.claudeBinaryPath,
},
}
: {}),
};

return Object.keys(providerOptions).length > 0 ? providerOptions : undefined;
}

export function useAppSettings() {
const [settings, setSettings] = useLocalStorage(
APP_SETTINGS_STORAGE_KEY,
Expand Down
13 changes: 2 additions & 11 deletions apps/web/src/components/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ import { readNativeApi } from "~/nativeApi";
import {
getCustomModelOptionsByProvider,
getCustomModelsByProvider,
getProviderStartOptions,
resolveAppModelSelection,
useAppSettings,
} from "../appSettings";
Expand Down Expand Up @@ -618,17 +619,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
);
const selectedPromptEffort = composerProviderState.promptEffort;
const selectedModelOptionsForDispatch = composerProviderState.modelOptionsForDispatch;
const providerOptionsForDispatch = useMemo(() => {
if (!settings.codexBinaryPath && !settings.codexHomePath) {
return undefined;
}
return {
codex: {
...(settings.codexBinaryPath ? { binaryPath: settings.codexBinaryPath } : {}),
...(settings.codexHomePath ? { homePath: settings.codexHomePath } : {}),
},
};
}, [settings.codexBinaryPath, settings.codexHomePath]);
const providerOptionsForDispatch = useMemo(() => getProviderStartOptions(settings), [settings]);
const selectedModelForPicker = selectedModel;
const modelOptionsByProvider = useMemo(
() => getCustomModelOptionsByProvider(settings),
Expand Down
49 changes: 31 additions & 18 deletions apps/web/src/components/ui/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,32 +164,45 @@ function SelectPopup({
);
}

function SelectItem({ className, children, ...props }: SelectPrimitive.Item.Props) {
function SelectItem({
className,
children,
hideIndicator = false,
...props
}: SelectPrimitive.Item.Props & {
hideIndicator?: boolean;
}) {
return (
<SelectPrimitive.Item
className={cn(
"grid min-h-8 in-data-[side=none]:min-w-[calc(var(--anchor-width)+1.25rem)] cursor-default grid-cols-[1rem_1fr] items-center gap-2 rounded-sm py-1 ps-2 pe-4 text-base outline-none data-disabled:pointer-events-none data-highlighted:bg-accent data-highlighted:text-accent-foreground data-disabled:opacity-64 sm:min-h-7 sm:text-sm [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0",
"grid min-h-8 in-data-[side=none]:min-w-[calc(var(--anchor-width)+1.25rem)] cursor-default items-center gap-2 rounded-sm py-1 text-base outline-none data-disabled:pointer-events-none data-highlighted:bg-accent data-highlighted:text-accent-foreground data-disabled:opacity-64 sm:min-h-7 sm:text-sm [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0",
hideIndicator ? "grid-cols-[1fr] ps-3 pe-3" : "grid-cols-[1rem_1fr] ps-2 pe-4",
className,
)}
data-slot="select-item"
{...props}
>
<SelectPrimitive.ItemIndicator className="col-start-1">
<svg
fill="none"
height="24"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
viewBox="0 0 24 24"
width="24"
xmlns="http://www.w3.org/1500/svg"
>
<path d="M5.252 12.7 10.2 18.63 18.748 5.37" />
</svg>
</SelectPrimitive.ItemIndicator>
<SelectPrimitive.ItemText className="col-start-2 min-w-0">
{hideIndicator ? null : (
<SelectPrimitive.ItemIndicator className="col-start-1" data-slot="select-item-indicator">
<svg
fill="none"
height="24"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
viewBox="0 0 24 24"
width="24"
xmlns="http://www.w3.org/1500/svg"
>
<path d="M5.252 12.7 10.2 18.63 18.748 5.37" />
</svg>
</SelectPrimitive.ItemIndicator>
)}
<SelectPrimitive.ItemText
className={cn("min-w-0", hideIndicator ? "col-start-1" : "col-start-2")}
data-slot="select-item-text"
>
{children}
</SelectPrimitive.ItemText>
</SelectPrimitive.Item>
Expand Down
Loading