From 87dfb0d0f575a8a146acef2b319b532634c54e2f Mon Sep 17 00:00:00 2001 From: QQ Date: Sat, 14 Nov 2026 14:53:57 +0800 Subject: [PATCH] Import packages/plugin/src/client/types.ts --- packages/plugin/src/client/types.ts | 300 ++++++++++++++++++++++++++++ 1 file changed, 300 insertions(+) create mode 100644 packages/plugin/src/client/types.ts diff --git a/packages/plugin/src/client/types.ts b/packages/plugin/src/client/types.ts new file mode 100644 index 0000000..9871389 --- /dev/null +++ b/packages/plugin/src/client/types.ts @@ -0,0 +1,300 @@ +import type { LocaleKey } from '../client-locale.js' +import type { RemoteFileContentProvider } from '../remote-file-content-provider.js' + +export interface ControlResult { + ok: boolean + value?: T + error?: { code?: string; message?: string; details?: Record } +} + +export interface FileViewerClientServiceLike { + registerContentProvider(provider: RemoteFileContentProvider): () => void +} + +export type RemoteTransportPreference = 'lan' | 'p2p' | 'turn' | 'relay' + +export interface RemoteStatus { + mode: 'local' | 'remote' + backend?: 'harness' | 'codex' | 'cursor' | 'antigravity' | 'pi' | 'opencode' | 'claude' | 'hermes' + target?: { deviceId: string; name: string } + workspaceSelection?: RemoteWorkspaceSelection + available: boolean + controlUnavailable?: boolean + startupError?: { + code: string + message: string + } + deviceName?: string + deviceId?: string + serverUrl?: string + connected?: boolean + recoveryGeneration?: number + clientAuthRequired?: boolean + connectedTargetDeviceId?: string + transport?: 'LAN' | 'P2P' | 'TURN' | 'Relay' | 'Disconnected' + preferredTransports?: RemoteTransportPreference[] + connectionProgress?: { + targetDeviceId: string + phase: 'checking-host' | 'authorizing-peer' | 'probing' | 'connected' + activeTransports?: RemoteTransportPreference[] + } + remoteFeatures?: { + commandList: boolean + fileViewer: boolean + terminal?: boolean + pluginRoute?: boolean + codex?: boolean + cursor?: boolean + antigravity?: boolean + pi?: boolean + opencode?: boolean + claude?: boolean + hermes?: boolean + workspaceTypes?: ReadonlyArray<{ id: string; name: string; capability: string; available: boolean }> + } + network?: RemoteNetworkDetails + /** npm dist-tags lookup result; present after the plugin's first successful registry check. */ + update?: { + currentVersion: string + latestVersion: string + checkedAt: number + } + hostAuthorizationAvailable: boolean + host?: { + deviceId?: string + pairingHostOnly?: boolean + configured: boolean + online: boolean + reconnecting: boolean + recoveryExpiresAt?: number + lastActiveAt?: number + error?: string + account?: string + authorized: boolean + accountRequired: boolean + connectedClients?: Array<{ + deviceId: string + name: string + platform?: string + mode?: 'LAN' | 'P2P' | 'TURN' | 'Relay' + }> + } +} + +interface RemoteNetworkDetails { + connectionId?: string + connectedAt?: number + recoveryExpiresAt?: number + controlChannelUrl: string + controlChannelState: 'connecting' | 'open' | 'closing' | 'closed' + preferredTransports: RemoteTransportPreference[] + local: { deviceId: string; name: string; platform: string } + remote: { deviceId: string; name: string; platform: string } + webRtc?: { + mode?: 'LAN' | 'P2P' | 'TURN' + connectionState: string + iceConnectionState: string + dataChannelState?: string + localCandidateType?: string + remoteCandidateType?: string + localAddress?: string + remoteAddress?: string + protocol?: string + relayProtocol?: string + currentRoundTripTimeMs?: number + availableOutgoingBitrate?: number + bytesSent?: number + bytesReceived?: number + } +} + +export interface RemoteDevice { + deviceId: string + name: string + platform: string + online: boolean + clientVersion?: string + harnessVersion?: string +} + +export interface OAuthQrSession { + qrId: string + scanUrl: string + expiresIn: number +} + +export type OAuthProvider = string + +export type LoginMethod = `oauth:${string}` | 'password' + +export interface OAuthQrPollResult { + status: 'pending' | 'expired' | 'complete' +} + +interface RemoteDirectoryEntry { + name: string + path: string + hidden: boolean +} + +export interface RemoteDirectoryListing { + path: string + home: string + crumbs: RemoteDirectoryEntry[] + entries: RemoteDirectoryEntry[] + truncated: boolean +} + +export interface RemoteWorkspaceView { + workspaceId: string + path: string + title: string +} + +export interface CodexWorkspaceView extends RemoteWorkspaceView { + sessionCount: number +} + +export interface CursorWorkspaceView extends RemoteWorkspaceView { + sessionCount: number +} + +export interface RemoteWorkspaceSelection { + targetDeviceId: string + workspaceId: string + backend?: 'harness' | 'codex' | 'cursor' | 'antigravity' | 'pi' | 'opencode' | 'claude' | 'hermes' + sessionId?: string +} + +export interface WorkspacesClientServiceLike { + list: { + getSnapshot(): { + items: ReadonlyArray<{ workspaceId: string }> + baselinesReady?: boolean + phase?: string + } + subscribe(listener: () => void): () => void + } + connectWorkspace(workspaceId: string): Promise + /** Harness 0.2 owns the main Session retain/release lifecycle here. */ + openSession?(sessionId: string): void +} + +export interface SessionsClientServiceLike { + list: { + getSnapshot(): { ids: ReadonlyArray; phase: string } + subscribe(listener: () => void): () => void + } + refresh?(): Promise + open?(sessionId: string): void + retain?(target: string, options: { source: string }): { sessionId: string; ready?: Promise; release(): void } +} + +export interface UiWorkspaceClientServiceLike { + connectWorkspace(workspaceId: string): Promise + openSession(sessionId: string): void +} + +interface PluginSettings { + enabled?: boolean + role?: 'host' | 'client' | 'both' + serverUrl?: string + terminal?: { enabled?: boolean } + hostControl?: { enabled?: boolean } + loopback?: { ports?: number[] } + remoteTools?: { enabled?: boolean } + forceRelay?: boolean + logLevel?: 'debug' | 'info' | 'warn' | 'error' + liteMode?: boolean + reconnect?: boolean | { + enabled?: boolean + initialDelayMs?: number + maxDelayMs?: number + jitter?: number + } + codex?: { + enabled?: boolean + binary?: string + } + cursor?: { + enabled?: boolean + binary?: string + } + acp?: { enabled?: boolean; backends?: Array<{ id: string; enabled?: boolean; command?: string; args?: string[]; cwd?: string }> } + sidebar?: { entry?: SidebarEntryStyle } +} + +/** + * Where the Remote entry lives in the Desktop sidebar: among the footer actions + * (Standard) or as an icon at the end of the account row (Compact). + */ +export type SidebarEntryStyle = 'standard' | 'compact' + +/** + * The entry style shared between the settings page and the sidebar entry, so a + * toggle takes effect without a reload. Owned by the client entry point. + */ +export interface SidebarEntryPreference { + read: () => SidebarEntryStyle + subscribe: (listener: () => void) => () => void + publish: (style: SidebarEntryStyle) => void +} + +/** `ReactDOM.createPortal`, resolved once by the ModuleLoader factory. */ +export type PortalRenderer = (children: unknown, container: Element) => unknown + +export interface PluginSettingsView { + config: PluginSettings + deviceName: string + writable: boolean + applies: 'live' | 'restart' + association?: PluginAssociation + associations?: Partial> + acpAvailability?: Record + acpInstallResult?: { + backend: string + action: 'configured' | 'installed' | 'download_required' + downloadUrl?: string + } + startupError?: { + code: string + message: string + } +} + +export interface PluginAssociation { + method: 'account' | 'host_registration_code' | 'owned_device' | 'device_pairing' + account?: string +} + +export interface PluginConfigureResult { + status: 'authorized' + role: 'host' | 'client' + account?: string + settings: PluginSettingsView +} + +export interface RemoteConnectionProgress { + label: LocaleKey + detail: LocaleKey + percent: number + transports?: RemoteTransportPreference[] + activeTransports?: RemoteTransportPreference[] + routeVerb?: 'trying' | 'using' +} + +/** React is supplied by Harness ModuleLoader, never bundled as a second runtime. */ +export type ClientReact = { + Fragment: unknown + createElement(type: unknown, props?: Record | null, ...children: unknown[]): unknown + useEffect(effect: () => void | (() => void), deps: unknown[]): void + useCallback(callback: T, deps: unknown[]): T + useMemo(factory: () => T, deps: unknown[]): T + useRef(initial: T): { current: T } + useState(initial: T | (() => T)): [T, (value: T | ((previous: T) => T)) => void] + useSyncExternalStore( + subscribe: (onStoreChange: () => void) => () => void, + getSnapshot: () => T, + getServerSnapshot?: () => T, + ): T +}