Add client-only desktop backend mode #4444
Closedcolonelpanic8(GitHub profile, opens in a new tab)wants to merge 18 commits into
main fromrefs/pull/4444/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
- apps/server/src/serverRuntimeStartup.ts line 452OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -450,3 +451,3 @@450451 if (serverConfig.startupPresentation === "headless") {451452 yield* Effect.logDebug("startup phase: headless access info");452453 const accessInfo = yield* issueHeadlessServeAccessInfo();
- apps/web/src/environments/primary/target.ts line 300Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -292,3 +297,4 @@292297 resolveWindowOriginPrimaryTarget()293298 );294299 }300+apps/desktop/src/app/DesktopLocalServerDiscovery.ts line 142OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -0,0 +122,21 @@122+ actualUid: recordInfo.value.uid,123+ expectedUid: options.uid,124+ actualMode: recordInfo.value.mode,125+ expectedMode: LOCAL_SERVER_ADVERTISEMENT_FILE_MODE,126+ })127+ ) {128+ return null;129+ }130+131+ const canonicalRecordPath = yield* fileSystem.realPath(recordPath).pipe(Effect.option);132+ if (133+ Option.isNone(canonicalRecordPath) ||134+ path.dirname(canonicalRecordPath.value) !== canonicalDirectory.value135+ ) {136+ return null;137+ }138+139+ const raw = yield* fileSystem.readFileString(recordPath).pipe(Effect.option);140+ if (Option.isNone(raw)) {141+ return null;142+ }apps/desktop/src/electron/ElectronProtocol.ts line 248Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -106,0 +226,21 @@226+ new Response(null, {227+ status: 405,228+ headers: { Allow: "GET, HEAD" },229+ }),230+ contentSecurityPolicy,231+ );232+ }233+234+ const resolution = resolveDesktopStaticPath(staticRoot, requestUrl.pathname);235+ if (resolution._tag === "Invalid") {236+ return withContentSecurityPolicy(237+ new Response(null, { status: resolution.status }),238+ contentSecurityPolicy,239+ );240+ }241+242+ let response = await fetchStaticFile(resolution.path);243+ let responsePath = resolution.path;244+ if (response.status === 404 && shouldUseSpaFallback(request, resolution.relativePath)) {245+ responsePath = NodePath.join(staticRoot, "index.html");246+ response = await fetchStaticFile(responsePath);
- apps/server/src/localServerAdvertisement.ts line 137OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -0,0 +117,21 @@117+ version: 1,118+ instanceId,119+ pid: process.pid,120+ startedAt,121+ httpBaseUrl,122+ pairingUrl: buildPairingUrl(httpBaseUrl, accessInfo.token),123+ pairingExpiresAt: accessInfo.pairingExpiresAt,124+ environmentId: environment.environmentId,125+ label: environment.label,126+ },127+ });128+ });129+130+ const revoke = (accessInfo: HeadlessServeAccessInfo) =>131+ serverAuth.revokePairingLink(accessInfo.pairingCredentialId).pipe(132+ Effect.catch((error) =>133+ Effect.logWarning("Could not revoke a local discovery pairing credential.", {134+ pairingCredentialId: accessInfo.pairingCredentialId,135+ error,136+ }),137+ ),
- apps/server/src/localServerAdvertisement.ts line 177OutdatedResolvedby colonelpanic8(GitHub profile, opens in a new tab)@@ -0,0 +157,21 @@157+ ),158+ );159+160+ const initialAccessInfoExit = yield* Effect.exit(issueAccessInfo);161+ if (Exit.isFailure(initialAccessInfoExit)) {162+ yield* Effect.logWarning("Local T3 Code server discovery is unavailable.", {163+ recordPath,164+ cause: initialAccessInfoExit.cause,165+ });166+ return;167+ }168+ const initialAccessInfo = initialAccessInfoExit.value;169+ const currentAccessInfo = yield* Ref.make(initialAccessInfo);170+171+ const cleanup = Effect.gen(function* () {172+ yield* fileSystem.remove(recordPath, { force: true }).pipe(Effect.ignore);173+ yield* fileSystem.remove(tempPath, { force: true }).pipe(Effect.ignore);174+ yield* revoke(yield* Ref.get(currentAccessInfo));175+ });176+177+ const initialPublish = yield* Effect.exit(publish(initialAccessInfo));
colonelpanic8(GitHub profile, opens in a new tab) changed the title
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:XXL
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
- @@ -35,3 +35,11 @@3535 }3636 return result as ReturnType<DesktopBridge["getAppBranding"]>;3737 },38+ getBackendModeState: () => {39+ const result = ipcRenderer.sendSync(IpcChannels.GET_BACKEND_MODE_STATE_CHANNEL);40+ if (typeof result !== "object" || result === null) {41+ return {42+ effectiveMode: "managed",43+ configuredMode: "managed",44+ cliOverride: null,45+ };apps/desktop/src/app/DesktopApp.ts line 224Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -149,0 +183,21 @@183+ scheme: ElectronProtocol.getDesktopScheme(true),184+ source: "proxy",185+ targetOrigin: Option.getOrThrow(environment.devServerUrl),186+ clerkFrontendApiHostname: DesktopClerk.desktopClerkFrontendApiHostname,187+ });188+ } else {189+ const staticRoot = yield* resolvePackagedClientRoot(environment.packagedClientRootCandidates);190+ yield* electronProtocol.registerDesktopProtocol({191+ scheme: ElectronProtocol.getDesktopScheme(false),192+ source: "static",193+ staticRoot,194+ clerkFrontendApiHostname: DesktopClerk.desktopClerkFrontendApiHostname,195+ });196+ yield* logBootstrapInfo("bootstrap resolved packaged renderer", { staticRoot });197+ }198+199+ yield* installDesktopIpcHandlers();200+ yield* logBootstrapInfo("bootstrap ipc handlers registered");201+ if (!(yield* Ref.get(state.quitting))) {202+ yield* desktopWindow.handleRendererReady;203+ }apps/desktop/src/ipc/methods/backendMode.ts line 61Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -0,0 +38,21 @@38+ channel: IpcChannels.SET_BACKEND_MODE_CHANNEL,39+ payload: DesktopBackendModeSchema,40+ result: DesktopBackendModeStateSchema,41+ handler: Effect.fn("desktop.ipc.backendMode.set")(function* (mode) {42+ const launchMode = yield* DesktopBackendMode.DesktopBackendMode;43+ const lifecycle = yield* DesktopLifecycle.DesktopLifecycle;44+ const settings = yield* DesktopAppSettings.DesktopAppSettings;45+ const change = yield* settings.setBackendMode(mode);46+ const launchState = yield* launchMode.get;47+ const state = {48+ ...launchState,49+ configuredMode: change.settings.backendMode,50+ };51+ if (52+ change.changed &&53+ launchState.cliOverride === null &&54+ launchState.effectiveMode !== change.settings.backendMode55+ ) {56+ yield* lifecycle.relaunch(`backendMode=${mode}`);57+ }58+ return state;
- apps/desktop/src/app/DesktopLifecycle.ts line 160Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -146,3 +146,15 @@146146 const environment = yield* DesktopEnvironment.DesktopEnvironment;147147 const state = yield* DesktopState.DesktopState;148148 yield* logLifecycleInfo("desktop relaunch requested", { reason });149+ if (!environment.isDevelopment) {150+ yield* electronApp151+ .relaunch({152+ execPath: process.execPath,153+ args: process.argv.slice(1),154+ })155+ .pipe(156+ Effect.catchCause((cause) =>157+ Effect.fail(new DesktopLifecycleRelaunchError({ reason, cause })),158+ ),159+ );160+ }
- apps/desktop/src/app/DesktopApp.ts lines 202 to 209OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -149,0 +189,21 @@189+ const staticRoot = yield* resolvePackagedClientRoot(environment.packagedClientRootCandidates);190+ yield* electronProtocol.registerDesktopProtocol({191+ scheme: ElectronProtocol.getDesktopScheme(false),192+ source: "static",193+ staticRoot,194+ clerkFrontendApiHostname: DesktopClerk.desktopClerkFrontendApiHostname,195+ });196+ yield* logBootstrapInfo("bootstrap resolved packaged renderer", { staticRoot });197+ }198+199+ yield* installDesktopIpcHandlers();200+ yield* logBootstrapInfo("bootstrap ipc handlers registered");201+ if (!(yield* Ref.get(state.quitting))) {202+ yield* desktopWindow.handleRendererReady.pipe(203+ Effect.catch((error) =>204+ logBootstrapWarning("failed to open main window after renderer readiness", {205+ error: error.message,206+ }),207+ ),208+ );209+ }
- apps/desktop/src/app/DesktopApp.ts line 301OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -223,11 +289,13 @@223289 const clerk = yield* DesktopClerk.DesktopClerk;224290 const shellEnvironment = yield* DesktopShellEnvironment.DesktopShellEnvironment;225291 const desktopSettings = yield* DesktopAppSettings.DesktopAppSettings;292+ const backendMode = yield* DesktopBackendMode.DesktopBackendMode;226293 const updates = yield* DesktopUpdates.DesktopUpdates;227294 const environment = yield* DesktopEnvironment.DesktopEnvironment;228295229296 yield* shellEnvironment.installIntoProcess;230297 const userDataPath = yield* appIdentity.resolveUserDataPath;231298 yield* electronApp.setPath("userData", userDataPath);232299 yield* logStartupInfo("runtime logging configured", { logDir: environment.logDir });233- yield* desktopSettings.load;300+ const settings = yield* desktopSettings.load;301+ const launchMode = yield* backendMode.latch(settings.backendMode);
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:XL
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
- apps/web/src/hooks/useDefaultServerConfig.ts lines 19 to 33Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +4,21 @@4+import { useActiveEnvironmentId } from "../state/entities";5+import { useEnvironments, usePrimaryEnvironmentId } from "../state/environments";6+import { serverEnvironment } from "../state/server";7+8+/**9+ * Server configuration for global client surfaces.10+ *11+ * A managed client keeps using its primary backend. A client without a12+ * managed backend follows the active saved environment instead.13+ */14+export function useDefaultServerConfig(): ServerConfig | null {15+ const environmentId = useDefaultEnvironmentId();16+ return useAtomValue(serverEnvironment.configValueAtom(environmentId));17+}18+19+export function useDefaultEnvironmentId() {20+ const primaryEnvironmentId = usePrimaryEnvironmentId();21+ const activeEnvironmentId = useActiveEnvironmentId();22+ const { environments } = useEnvironments();23+ return primaryEnvironmentId ?? activeEnvironmentId ?? environments[0]?.environmentId ?? null;24+}apps/web/src/components/settings/ProviderSettingsPanel.tsx line 361Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +340,21 @@340+ if (refreshingRef.current) return;341+ refreshingRef.current = true;342+ setIsRefreshingProviders(true);343+ void (async () => {344+ const result = await refreshServerProviders({345+ environmentId,346+ input: {},347+ });348+ refreshingRef.current = false;349+ setIsRefreshingProviders(false);350+ if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {351+ console.warn("Failed to refresh providers", {352+ operation: "refresh-providers",353+ environmentId,354+ ...safeErrorLogAttributes(squashAtomCommandFailure(result)),355+ });356+ }357+ })();358+ }, [environmentId, refreshServerProviders]);359+360+ const runProviderUpdate = useCallback(
- apps/web/src/components/settings/AddProviderInstanceDialog.tsx line 16Resolvedby colonelpanic8(GitHub profile, opens in a new tab)@@ -1,12 +1,16 @@11 "use client";2233 import { Radio as RadioPrimitive } from "@base-ui/react/radio";4+import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";45 import { CheckIcon } from "lucide-react";56 import { useMemo, useState } from "react";67 import {78 ProviderInstanceId,89 ProviderDriverKind,10+ type EnvironmentId,911 type ProviderInstanceConfig,1012 } from "@t3tools/contracts";111312-import { usePrimarySettings, useUpdatePrimarySettings } from "../../hooks/useSettings";14+import {15+ useEnvironmentSettings,16+ usePersistEnvironmentSettings,
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.





Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
76f5a485-2760-41bb-b19f-f63af805e9feYou can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share