Files
DeepSeek-TUI/web/lib/install-platform.ts
Hmbown 86c6e0d1c6 fix(web): detect Intel Macs for the install snippet via client hints (#5168)
detectFromBrowserSignals declared 'macos-x64' in its Arch union but
could never return it: every non-Windows, non-Linux UA fell through to
'macos-arm64', silently handing Intel Mac users the Apple Silicon
binary snippet.

Since Big Sur the macOS UA reports 'Intel Mac OS X' on Apple Silicon
too, so UA parsing fundamentally cannot distinguish the two — only
User-Agent Client Hints can. The component already requests
architecture/bitness hints; the detector now honors them on the macOS
branch (x86 -> macos-x64). Without hints the default stays arm64 (every
Mac sold since late 2020) and the page's existing arch chooser remains
the honest fallback, so nobody is silently misdetected.

Vitest pins: x86 hint -> macos-x64, arm hint -> macos-arm64, and the
deliberate no-hint arm64 default on the frozen Intel UA.

Agent-assisted change.
2026-08-02 22:55:02 -07:00

44 lines
1.3 KiB
TypeScript

export type Arch =
| "macos-arm64"
| "macos-x64"
| "linux-x64"
| "linux-arm64"
| "windows-x64"
| "windows-arm64";
export interface UserAgentArchitecture {
architecture?: string;
bitness?: string;
}
export function detectFromBrowserSignals(
userAgent: string,
userAgentArchitecture?: UserAgentArchitecture,
): Arch {
const ua = userAgent.toLowerCase();
const architecture = userAgentArchitecture?.architecture?.toLowerCase();
const bitness = userAgentArchitecture?.bitness;
if (ua.includes("win")) {
if (
architecture === "arm64" ||
(architecture === "arm" && bitness === "64") ||
ua.includes("aarch64") ||
ua.includes("arm64")
) {
return "windows-arm64";
}
return "windows-x64";
}
if (ua.includes("linux")) {
if (ua.includes("aarch64") || ua.includes("arm64")) return "linux-arm64";
return "linux-x64";
}
// macOS. Since Big Sur the UA reports "Intel Mac OS X" on Apple Silicon
// too, so the UA string cannot distinguish architectures — only
// User-Agent Client Hints can (#5168). Without hints we default to arm64
// (every Mac sold since late 2020); the arch chooser on the install page
// stays the honest fallback for Intel users.
if (architecture === "x86") return "macos-x64";
return "macos-arm64";
}