diff --git a/src/app/TitleBar.tsx b/src/app/TitleBar.tsx index f9e39f8..15e5045 100644 --- a/src/app/TitleBar.tsx +++ b/src/app/TitleBar.tsx @@ -7,7 +7,7 @@ import { Button } from "@/components/ui/button"; // @ts-ignore import logo from "../../assets/logo_transparent.png"; import { providerSettingsRoute } from "@/routes/settings/providers/$provider"; - +import { cn } from "@/lib/utils"; export const TitleBar = () => { const [selectedAppId] = useAtom(selectedAppIdAtom); const { apps } = useLoadApps(); @@ -27,6 +27,7 @@ export const TitleBar = () => { }; const isDyadPro = !!settings?.providerSettings?.auto?.apiKey?.value; + const isDyadProEnabled = settings?.enableDyadPro; return (
@@ -51,10 +52,13 @@ export const TitleBar = () => { }); }} variant="outline" - className="ml-4 no-app-region-drag h-7 bg-indigo-600 text-white dark:bg-indigo-600 dark:text-white" + className={cn( + "ml-4 no-app-region-drag h-7 bg-indigo-600 text-white dark:bg-indigo-600 dark:text-white", + !isDyadProEnabled && "bg-zinc-600 dark:bg-zinc-600" + )} size="sm" > - Dyad Pro + {isDyadProEnabled ? "Dyad Pro" : "Dyad Pro (disabled)"} )}
diff --git a/src/components/settings/ProviderSettingsPage.tsx b/src/components/settings/ProviderSettingsPage.tsx index 9fabff1..3316f71 100644 --- a/src/components/settings/ProviderSettingsPage.tsx +++ b/src/components/settings/ProviderSettingsPage.tsx @@ -23,6 +23,9 @@ import { import { Input } from "@/components/ui/input"; import { Button } from "@/components/ui/button"; import { IpcClient } from "@/ipc/ipc_client"; +import { Switch } from "@/components/ui/switch"; +import { showError } from "@/lib/toast"; +import { UserSettings } from "@/lib/schemas"; interface ProviderSettingsPageProps { provider: string; @@ -44,6 +47,8 @@ export function ProviderSettingsPage({ provider }: ProviderSettingsPageProps) { updateSettings, } = useSettings(); + const isDyad = provider === "auto"; + const [apiKeyInput, setApiKeyInput] = useState(""); const [isSaving, setIsSaving] = useState(false); const [saveError, setSaveError] = useState(null); @@ -95,7 +100,7 @@ export function ProviderSettingsPage({ provider }: ProviderSettingsPageProps) { setIsSaving(true); setSaveError(null); try { - await updateSettings({ + const settingsUpdate: Partial = { providerSettings: { ...settings?.providerSettings, [provider]: { @@ -105,7 +110,11 @@ export function ProviderSettingsPage({ provider }: ProviderSettingsPageProps) { }, }, }, - }); + }; + if (isDyad) { + settingsUpdate.enableDyadPro = true; + } + await updateSettings(settingsUpdate); setApiKeyInput(""); // Clear input on success // Optionally show a success message } catch (error: any) { @@ -139,6 +148,20 @@ export function ProviderSettingsPage({ provider }: ProviderSettingsPageProps) { } }; + // --- Toggle Dyad Pro Handler --- + const handleToggleDyadPro = async (enabled: boolean) => { + setIsSaving(true); + try { + await updateSettings({ + enableDyadPro: enabled, + }); + } catch (error: any) { + showError(`Error toggling Dyad Pro: ${error}`); + } finally { + setIsSaving(false); + } + }; + // Effect to clear input error when input changes useEffect(() => { if (saveError) { @@ -205,7 +228,7 @@ export function ProviderSettingsPage({ provider }: ProviderSettingsPageProps) { ) : ( )} - {isConfigured ? "Manage API Keys" : "Setup API Key"} + {getKeyButtonText({ isConfigured, isDyad })} )} @@ -299,60 +322,93 @@ export function ProviderSettingsPage({ provider }: ProviderSettingsPageProps) { - - - API Key from Environment Variable - - - {hasEnvKey ? ( - - - - Environment Variable Key ({envVarName}) - - -

- {maskEnvApiKey(envApiKey)} -

- {activeKeySource === "env" && ( -

- This key is currently active (no settings key set). + {!isDyad && ( + + + API Key from Environment Variable + + + {hasEnvKey ? ( + + + + Environment Variable Key ({envVarName}) + + +

+ {maskEnvApiKey(envApiKey)}

- )} - {activeKeySource === "settings" && ( -

- This key is currently being overridden by the key set - in Settings. -

- )} -
-
- ) : ( - - - Environment Variable Not Set - - The{" "} - - {envVarName} - {" "} - environment variable is not set. - - - )} -

- This key is set outside the application. If present, it will - be used only if no key is configured in the Settings section - above. Requires app restart to detect changes. -

-
-
+ {activeKeySource === "env" && ( +

+ This key is currently active (no settings key set). +

+ )} + {activeKeySource === "settings" && ( +

+ This key is currently being overridden by the key + set in Settings. +

+ )} + + + ) : ( + + + Environment Variable Not Set + + The{" "} + + {envVarName} + {" "} + environment variable is not set. + + + )} +

+ This key is set outside the application. If present, it will + be used only if no key is configured in the Settings section + above. Requires app restart to detect changes. +

+ + + )} )} + + {isDyad && !settingsLoading && ( +
+
+

Enable Dyad Pro

+

+ Toggle to enable Dyad Pro +

+
+ +
+ )} ); } + +function getKeyButtonText({ + isConfigured, + isDyad, +}: { + isConfigured: boolean; + isDyad: boolean; +}) { + if (isDyad) { + return isConfigured + ? "Manage Dyad Pro Subscription" + : "Setup Dyad Pro Subscription"; + } + return isConfigured ? "Manage API Keys" : "Setup API Key"; +} diff --git a/src/ipc/utils/get_model_client.ts b/src/ipc/utils/get_model_client.ts index b7aa77b..0556b01 100644 --- a/src/ipc/utils/get_model_client.ts +++ b/src/ipc/utils/get_model_client.ts @@ -46,7 +46,7 @@ export function getModelClient( } const dyadApiKey = settings.providerSettings?.auto?.apiKey?.value; - if (dyadApiKey) { + if (dyadApiKey && settings.enableDyadPro) { const provider = createOpenAI({ apiKey: dyadApiKey, baseURL: "https://llm-gateway.dyad.sh/v1", diff --git a/src/lib/schemas.ts b/src/lib/schemas.ts index 0bbe639..2a040b9 100644 --- a/src/lib/schemas.ts +++ b/src/lib/schemas.ts @@ -107,6 +107,7 @@ export const UserSettingsSchema = z.object({ telemetryConsent: z.enum(["opted_in", "opted_out", "unset"]).optional(), telemetryUserId: z.string().optional(), hasRunBefore: z.boolean().optional(), + enableDyadPro: z.boolean().optional(), experiments: ExperimentsSchema.optional(), // DEPRECATED.