Something went wrong. Try again.
opencode v2 mirror
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162import { createSimpleContext } from "@opencode/ui/context"import type { AsyncStorage, SyncStorage } from "@solid-primitives/storage"import type { Accessor } from "solid-js"import type { DesktopMenuAction } from "@/shell/commands/desktop-menu"import { ServerConnection } from "@/runtime/server/registry"import type { WslServersPlatform } from "@/servers/wsl/types"import type { SshPlatform } from "@/servers/ssh/types"import type { UpdaterPlatform } from "@/shell/updates/types"import type { DraftStore } from "@/runtime/persistence/drafts"import type { BrowserPanePlatform } from "./browser-pane"
type PickerPaths = string | string[] | nulltype OpenDirectoryPickerOptions = { title?: string; multiple?: boolean }type OpenAttachmentPickerOptions = { title?: string multiple?: boolean accept?: string[] extensions?: string[] defaultPath?: string}type SaveFilePickerOptions = { title?: string; defaultPath?: string }type PlatformName = "web" | "desktop"type DesktopOS = "macos" | "windows" | "linux"
export type PairingInfo = { readonly urls: readonly string[] readonly username: "opencode" readonly password: string}
export type FatalRendererErrorLog = { error: string url: string version?: string platform: PlatformName os?: DesktopOS}
type PlatformBase = { /** App version */ version?: string
/** Open a web or mail URL in the default system application */ openExternal(url: string): void
/** Open a local path in a local app (desktop only) */ openPath?(path: string, app?: string): Promise<void>
/** Open a local file URL in its default app (desktop only) */ openLocalFile?(url: string): void
/** Reveal a local path in the system file manager; false when the path does not exist (desktop only) */ revealPath?(path: string): Promise<boolean>
/** Restart the app */ restart(): Promise<void>
/** Send a system notification */ notify(title: string, description?: string, onClick?: () => void): Promise<void>
/** Open a native attachment picker and read selected files sequentially (desktop only) */ openAttachmentPickerDialog?( opts: OpenAttachmentPickerOptions, onFile: (file: File) => Promise<unknown>, ): Promise<void>
/** Resolve the native source path for a desktop File. */ getPathForFile?(file: File): string
/** Observe native drag cancellation that does not reach the renderer event loop. */ onDragCancel?(callback: () => void): () => void
/** Open a native save file dialog and write content to the selected path (desktop only) */ saveFile?(opts: SaveFilePickerOptions, content: string): Promise<boolean>
/** Storage mechanism, defaults to localStorage */ storage?: (name?: string) => SyncStorage | AsyncStorage
/** Prompt drafts, history, and their blobs. */ draftStore?: DraftStore
/** Application-global desktop updater */ updater?: UpdaterPlatform
/** Fetch override */ fetch?: typeof fetch
/** Get the configured default server URL (platform-specific) */ getDefaultServer?(): Promise<ServerConnection.Key | null>
/** Set the default server URL to use on app startup (platform-specific) */ setDefaultServer?(url: ServerConnection.Key | null): Promise<void> | void
/** Manage WSL sidecar servers (Electron on Windows only) */ wslServers?: WslServersPlatform sshServers?: SshPlatform
/** Webview zoom level (desktop only) */ webviewZoom?: Accessor<number>
/** Whether the native desktop window is fullscreen */ windowFullscreen?: Accessor<boolean>
/** Get whether native pinch/Ctrl-scroll zoom gestures are enabled (desktop only) */ getPinchZoomEnabled?(): Promise<boolean> | boolean
/** Allow native pinch/Ctrl-scroll zoom gestures (desktop only) */ setPinchZoomEnabled?(enabled: boolean): Promise<void> | void
/** Prevent the local display from sleeping while the desktop app is running. */ getKeepScreenActive?(): Promise<boolean> setKeepScreenActive?(enabled: boolean): Promise<void>
/** Run a desktop-only menu action from the app chrome */ runDesktopMenuAction?(action: DesktopMenuAction): Promise<void> | void
/** Check if an editor app exists (desktop only) */ checkAppExists?(appName: string): Promise<boolean>
/** Read image from clipboard (desktop only) */ readClipboardImage?(): Promise<File | null>
/** Write text to the native clipboard (desktop only) */ writeClipboardText?(text: string): Promise<void>
/** Export collected diagnostic logs (desktop only) */ exportDebugLogs?(): Promise<string>
/** Force focus styles on interactive elements through desktop devtools (desktop only) */ setForceFocus?(enabled: boolean): Promise<void>
/** Record a fatal renderer error in platform logs (desktop only) */ recordFatalRendererError?(error: FatalRendererErrorLog): Promise<void>
/** Native browser pane hosted by the platform (desktop only). */ browserPane?: BrowserPanePlatform
/** Pair another device with the local desktop server. */ pair?: { info(): Promise<PairingInfo> }}
export type Platform = PlatformBase & ( | { platform: "web"; os?: never; windowID?: never } | { platform: "desktop" os?: DesktopOS /** Stable platform window identity for window-scoped persistence */ windowID: string openDirectoryPickerDialog(opts?: OpenDirectoryPickerOptions): Promise<PickerPaths> } )
export const { use: usePlatform, provider: PlatformProvider } = createSimpleContext({ name: "Platform", init: (props: { value: Platform }) => { return props.value },})