Skip to content

The agent that grows with you

refactor(desktop): gate chat and code-block host checks by capability

Tekniumeab33e43a526
diff --git a/apps/desktop/src/app/chat/composer/controls.tsx b/apps/desktop/src/app/chat/composer/controls.tsx
index 3ff157ff800..d89867d303d 100644
--- a/apps/desktop/src/app/chat/composer/controls.tsx
+++ b/apps/desktop/src/app/chat/composer/controls.tsx
@@ -5,8 +5,8 @@ import { Codicon } from '@/components/ui/codicon'
import { Tip, TipKeybindLabel } from '@/components/ui/tooltip'
import { useI18n } from '@/i18n'
import { triggerHaptic } from '@/lib/haptics'
+import { hostHas } from '@/lib/host-capabilities'
import { Ear, EarOff, iconSize, Layers3, Loader2, Square } from '@/lib/icons'
-import { isBrowserHostedDesktop } from '@/lib/platform'
import { cn } from '@/lib/utils'
import { recordAction } from '@/store/desktop-metrics'
import { $hudMode, closeHud, resetHudLayout } from '@/store/hud'
@@ -30,7 +30,7 @@ export { ACTIVE_ICON_BTN, GHOST_ICON_BTN, ICON_BTN, PRIMARY_ICON_BTN } from './c
// leaves the keyboard as it was. Native Desktop keeps the press's blur, which
// closes an open completion list and clears a composition the IME never ended.
const keepEditorFocus = (event: { preventDefault: () => void }) => {
- if (isBrowserHostedDesktop()) {
+ if (hostHas('keepFocusOnPress')) {
event.preventDefault()
}
}
@@ -136,7 +136,7 @@ export function ComposerControls({
// The browser host's touch-size controls can outgrow a minimal row, so there
// they pack to the end and wrap. Native Desktop keeps main's single row.
- const browserHost = isBrowserHostedDesktop()
+ const browserHost = hostHas('touchSizedControls')
return (
<div
diff --git a/apps/desktop/src/app/chat/composer/hooks/use-composer-metrics.ts b/apps/desktop/src/app/chat/composer/hooks/use-composer-metrics.ts
index 19c69d04223..e891943d975 100644
--- a/apps/desktop/src/app/chat/composer/hooks/use-composer-metrics.ts
+++ b/apps/desktop/src/app/chat/composer/hooks/use-composer-metrics.ts
@@ -9,7 +9,7 @@ import {
setSurfaceVar
} from '@/app/chat/surface-vars'
import { useResizeObserver } from '@/hooks/use-resize-observer'
-import { isBrowserHostedDesktop } from '@/lib/platform'
+import { hostHas } from '@/lib/host-capabilities'
import {
COMPOSER_COMPACT_PILL_PX,
@@ -67,7 +67,7 @@ const DESKTOP_CONTROL_PX = 24
* `--composer-control-size` token and splits into one column below two
* targets. Native Desktop keeps the compact stages and the row, as on main. */
function composerFit(composer: HTMLElement, width: number): ComposerFit {
- if (!isBrowserHostedDesktop()) {
+ if (!hostHas('touchSizedControls')) {
return { ...fitForWidth(width, DESKTOP_CONTROL_PX), singleColumn: false }
}
diff --git a/apps/desktop/src/app/chat/composer/hooks/use-mic-recorder.ts b/apps/desktop/src/app/chat/composer/hooks/use-mic-recorder.ts
index 5f07e580cff..ae823e923c7 100644
--- a/apps/desktop/src/app/chat/composer/hooks/use-mic-recorder.ts
+++ b/apps/desktop/src/app/chat/composer/hooks/use-mic-recorder.ts
@@ -1,7 +1,7 @@
import { useEffect, useRef, useState } from 'react'
+import { hostHas } from '@/lib/host-capabilities'
import { closeMeterContext, meterContextsClosed } from '@/lib/mic-meter-context'
-import { isBrowserHostedDesktop } from '@/lib/platform'
type BrowserAudioContext = typeof AudioContext
@@ -51,7 +51,7 @@ interface MicRecorderHandle {
* insecure context with no mediaDevices: it says HTTPS or a tunnel fixes that. Native Desktop
* keeps the plain copy. */
function unsupportedMicrophone(copy: MicRecorderErrorCopy): string {
- return isBrowserHostedDesktop() && window.isSecureContext === false
+ return hostHas('webappCopy') && window.isSecureContext === false
? copy.microphoneNeedsHttps
: copy.microphoneUnsupported
}
diff --git a/apps/desktop/src/app/chat/right-rail/preview-pane.tsx b/apps/desktop/src/app/chat/right-rail/preview-pane.tsx
index bc560346918..3a5c891033f 100644
--- a/apps/desktop/src/app/chat/right-rail/preview-pane.tsx
+++ b/apps/desktop/src/app/chat/right-rail/preview-pane.tsx
@@ -13,9 +13,9 @@ import { Tip } from '@/components/ui/tooltip'
import { type Translations, useI18n } from '@/i18n'
import { isDesktopFsRemoteMode, isReadFileErrorResult } from '@/lib/desktop-fs'
import { guardGuestPointers } from '@/lib/guest-pointer-guard'
+import { hostHas } from '@/lib/host-capabilities'
import { isLoopbackPreviewUrl, openPreviewTargetInBrowser, remoteHtmlPreviewDocument } from '@/lib/local-preview'
import { isRemoteGateway } from '@/lib/media'
-import { isBrowserHostedDesktop } from '@/lib/platform'
import {
addAnnotatePin,
beginAnnotateMode,
@@ -125,7 +125,7 @@ function webPreviewSurface(isWebPreview: boolean, isRemoteHtml: boolean): 'ifram
return null
}
- return isBrowserHostedDesktop() ? 'iframe' : 'webview'
+ return hostHas('webviewPreview') ? 'webview' : 'iframe'
}
/** The raw Chromium params riding the webview tag's `context-menu` event. */
@@ -1112,7 +1112,7 @@ export function PreviewPane({
// A browser host has no `<webview>` tag: past the guard above, this is
// exactly `usesBrowserIframe`, so the iframe mounts instead.
- if (isBrowserHostedDesktop()) {
+ if (!hostHas('webviewPreview')) {
return mountBrowserPreviewFrame({
host,
navigationRef,
@@ -1445,7 +1445,7 @@ export function PreviewPane({
// guest page gets its own via `app-command` in main), and unhandled they
// walk the HOST document's history. A browser tab keeps its own back button.
onMouseDown={event => {
- if (isBrowserHostedDesktop() || (event.button !== 3 && event.button !== 4)) {
+ if (!hostHas('appMouseHistoryButtons') || (event.button !== 3 && event.button !== 4)) {
return
}
diff --git a/apps/desktop/src/app/chat/sidebar/profile-dropdown-switcher.tsx b/apps/desktop/src/app/chat/sidebar/profile-dropdown-switcher.tsx
index 5051a2d8abe..f2d4fc376fc 100644
--- a/apps/desktop/src/app/chat/sidebar/profile-dropdown-switcher.tsx
+++ b/apps/desktop/src/app/chat/sidebar/profile-dropdown-switcher.tsx
@@ -17,8 +17,8 @@ import {
import { ProfileGlyph } from '@/components/ui/profile-glyph'
import { useI18n } from '@/i18n'
import { triggerHaptic } from '@/lib/haptics'
+import { hostHas } from '@/lib/host-capabilities'
import { Loader2 } from '@/lib/icons'
-import { isBrowserHostedDesktop } from '@/lib/platform'
import { resolveProfileColor } from '@/lib/profile-color'
import { cn } from '@/lib/utils'
import {
@@ -90,7 +90,7 @@ export function ProfileSwitcher({ compact = false }: { compact?: boolean }) {
// The Webapp always takes this dropdown in place of the rail's squares
// (profile-switcher.tsx), so there it keeps the list fresh the same way and
// carries the rail's right-click launch menu. Native Desktop's picker is main's.
- const browserHost = isBrowserHostedDesktop()
+ const browserHost = !hostHas('profileRailSquares')
useProfileRailRefreshOnActive(browserHost)
// The `profile.create` hotkey bumps this request atom; the rail answers it
diff --git a/apps/desktop/src/app/chat/sidebar/profile-switcher.tsx b/apps/desktop/src/app/chat/sidebar/profile-switcher.tsx
index 98ed3654fdb..dd0caa3b716 100644
--- a/apps/desktop/src/app/chat/sidebar/profile-switcher.tsx
+++ b/apps/desktop/src/app/chat/sidebar/profile-switcher.tsx
@@ -49,8 +49,8 @@ import { useResizeObserver } from '@/hooks/use-resize-observer'
import { type Translations, useI18n } from '@/i18n'
import { sortConnectionsForDisplay } from '@/lib/connection-display'
import { triggerHaptic } from '@/lib/haptics'
+import { hostHas } from '@/lib/host-capabilities'
import { Loader2 } from '@/lib/icons'
-import { isBrowserHostedDesktop } from '@/lib/platform'
import { PROFILE_SWATCHES, profileColorSoft, resolveProfileColor } from '@/lib/profile-color'
import { profileShortLabel } from '@/lib/profile-short-label'
import {
@@ -122,7 +122,7 @@ const PROFILE_DROPDOWN_THRESHOLD = 13
// The Webapp always takes the dropdown: squares are a native-window gesture
// surface (drag, hold-to-recolor), and in a browser tab they read as chrome.
-const ALWAYS_CONDENSED = isBrowserHostedDesktop()
+const ALWAYS_CONDENSED = !hostHas('profileRailSquares')
// The home pill's profile when the multi-profile rail shows one: the default profile. A gateway that
// does not serve default (one launched as another profile, in the Webapp) refuses the switch, so the
diff --git a/apps/desktop/src/app/chat/sidebar/unserved-profiles.tsx b/apps/desktop/src/app/chat/sidebar/unserved-profiles.tsx
index dd5393aac42..01f9191379a 100644
--- a/apps/desktop/src/app/chat/sidebar/unserved-profiles.tsx
+++ b/apps/desktop/src/app/chat/sidebar/unserved-profiles.tsx
@@ -2,7 +2,7 @@ import { type ComponentProps, useEffect, useState } from 'react'
import { ProfileGlyph } from '@/components/ui/profile-glyph'
import { useI18n } from '@/i18n'
-import { isBrowserHostedDesktop } from '@/lib/platform'
+import { hostHas } from '@/lib/host-capabilities'
import { cn } from '@/lib/utils'
import { normalizeProfileKey } from '@/store/profile'
import type { ProfileInfo } from '@/types/hermes'
@@ -20,7 +20,7 @@ export function useUnservedProfiles(profiles: readonly ProfileInfo[]): ReadonlyS
const [unserved, setUnserved] = useState(NONE)
useEffect(() => {
- const roster = isBrowserHostedDesktop() ? window.hermesDesktop?.getAgentRoster : undefined
+ const roster = hostHas('servedProfileRoster') ? window.hermesDesktop?.getAgentRoster : undefined
if (!roster || !profiles.length) {
return
diff --git a/apps/desktop/src/components/chat/expandable-block.tsx b/apps/desktop/src/components/chat/expandable-block.tsx
index 3245398b574..7782b93a016 100644
--- a/apps/desktop/src/components/chat/expandable-block.tsx
+++ b/apps/desktop/src/components/chat/expandable-block.tsx
@@ -3,8 +3,8 @@
import { type ReactNode, useCallback, useRef, useState } from 'react'
import { useResizeObserver } from '@/hooks/use-resize-observer'
+import { hostHas } from '@/lib/host-capabilities'
import { ChevronDown } from '@/lib/icons'
-import { isBrowserHostedDesktop } from '@/lib/platform'
import { cn } from '@/lib/utils'
interface ExpandableBlockProps {
@@ -30,7 +30,7 @@ export function ExpandableBlock({ children, className }: ExpandableBlockProps) {
// The sideways cue belongs to the browser host, whose code fences are
// sized to their longest line (shiki-highlighter.tsx) and whose touch
// screens show no scrollbar. Native Desktop keeps main's block.
- const hasHorizontalOverflow = isBrowserHostedDesktop() && el.scrollWidth > el.clientWidth + 1
+ const hasHorizontalOverflow = hostHas('sidewaysCodeFences') && el.scrollWidth > el.clientWidth + 1
setHorizontalOverflowing(hasHorizontalOverflow)
setHorizontalAtEnd(!hasHorizontalOverflow || el.scrollLeft + el.clientWidth >= el.scrollWidth - 1)
diff --git a/apps/desktop/src/components/chat/shiki-highlighter.tsx b/apps/desktop/src/components/chat/shiki-highlighter.tsx
index d0fdbdbefa4..ac93e294fb9 100644
--- a/apps/desktop/src/components/chat/shiki-highlighter.tsx
+++ b/apps/desktop/src/components/chat/shiki-highlighter.tsx
@@ -12,8 +12,8 @@ import { ExpandableBlock } from '@/components/chat/expandable-block'
import { SHIKI_COLOR_REPLACEMENTS } from '@/components/chat/shiki-config'
import { CopyButton } from '@/components/ui/copy-button'
import { useI18n } from '@/i18n'
+import { hostHas } from '@/lib/host-capabilities'
import { isLikelyProseCodeBlock } from '@/lib/markdown-code'
-import { isBrowserHostedDesktop } from '@/lib/platform'
import type { CachedShikiBlockProps } from './shiki-block'
import { isChunkLoadError, ShikiChunkBoundary } from './shiki-chunk-boundary'
@@ -204,7 +204,7 @@ export const SyntaxHighlighter: FC<HermesSyntaxHighlighterProps> = ({
Native Desktop keeps main's fence, whose <pre> scrolls itself. */}
<Pre
className={
- isBrowserHostedDesktop()
+ hostHas('sidewaysCodeFences')
? 'aui-shiki m-0 min-w-max bg-transparent p-0'
: 'aui-shiki m-0 overflow-hidden bg-transparent p-0'
}