|
1 | 1 | import { useCallback } from "react"; |
2 | 2 | import { Option, Schema } from "effect"; |
3 | | -import { TrimmedNonEmptyString, type ProviderKind } from "@t3tools/contracts"; |
| 3 | +import { |
| 4 | + TrimmedNonEmptyString, |
| 5 | + type ProviderKind, |
| 6 | + type ProviderStartOptions, |
| 7 | +} from "@t3tools/contracts"; |
4 | 8 | import { |
5 | 9 | getDefaultModel, |
6 | 10 | getModelOptions, |
@@ -47,6 +51,7 @@ const withDefaults = |
47 | 51 | ); |
48 | 52 |
|
49 | 53 | export const AppSettingsSchema = Schema.Struct({ |
| 54 | + claudeBinaryPath: Schema.String.check(Schema.isMaxLength(4096)).pipe(withDefaults(() => "")), |
50 | 55 | codexBinaryPath: Schema.String.check(Schema.isMaxLength(4096)).pipe(withDefaults(() => "")), |
51 | 56 | codexHomePath: Schema.String.check(Schema.isMaxLength(4096)).pipe(withDefaults(() => "")), |
52 | 57 | defaultThreadEnvMode: EnvMode.pipe(withDefaults(() => "local" as const satisfies EnvMode)), |
@@ -221,6 +226,30 @@ export function getCustomModelOptionsByProvider( |
221 | 226 | }; |
222 | 227 | } |
223 | 228 |
|
| 229 | +export function getProviderStartOptions( |
| 230 | + settings: Pick<AppSettings, "claudeBinaryPath" | "codexBinaryPath" | "codexHomePath">, |
| 231 | +): ProviderStartOptions | undefined { |
| 232 | + const providerOptions: ProviderStartOptions = { |
| 233 | + ...(settings.codexBinaryPath || settings.codexHomePath |
| 234 | + ? { |
| 235 | + codex: { |
| 236 | + ...(settings.codexBinaryPath ? { binaryPath: settings.codexBinaryPath } : {}), |
| 237 | + ...(settings.codexHomePath ? { homePath: settings.codexHomePath } : {}), |
| 238 | + }, |
| 239 | + } |
| 240 | + : {}), |
| 241 | + ...(settings.claudeBinaryPath |
| 242 | + ? { |
| 243 | + claudeAgent: { |
| 244 | + binaryPath: settings.claudeBinaryPath, |
| 245 | + }, |
| 246 | + } |
| 247 | + : {}), |
| 248 | + }; |
| 249 | + |
| 250 | + return Object.keys(providerOptions).length > 0 ? providerOptions : undefined; |
| 251 | +} |
| 252 | + |
224 | 253 | export function useAppSettings() { |
225 | 254 | const [settings, setSettings] = useLocalStorage( |
226 | 255 | APP_SETTINGS_STORAGE_KEY, |
|
0 commit comments