Files
archived-orca/src/preload/api/runtime-api.ts
T
Jinwoo HongandOmar Shahine 3b82d8de64 fix(runtime): let connections own host status recovery (#20003)
* fix(runtime): let connections own host status recovery

Verify runtime status after authenticated connection recovery and publish
ordered snapshots to desktop and browser viewers. Consolidate failed-status
retries in the connection owner and remove renderer retry/diagnostics merging.

Adapt sidebar host-state derivation and regression coverage from Omar
Shahine's original fix in https://github.com/stablyai/orca/pull/19163.

Co-authored-by: Omar Shahine <10343873+omarshahine@users.noreply.github.com>

* fix(runtime): show blocked hosts honestly and remove obsolete status options

* fix(runtime): preserve timeout guidance and update IPC test fixtures

* fix(runtime): preserve status evidence and address review gaps

* test(sidebar): assert workspace host icons dimming and recovery tooltips

* fix(palette): require available hosts before adding implicit badges

* fix: retain disconnected host snapshots for new renderers

---------

Co-authored-by: Omar Shahine <10343873+omarshahine@users.noreply.github.com>
2026-09-11 03:19:01 -04:00

154 lines
5.8 KiB
TypeScript

import type { RuntimeHostStatusSnapshot } from '../../shared/runtime-host-status'
import type {
RuntimeBrowserDriverState,
RuntimeRendererSyncWindowGraph,
RuntimeStatus,
RuntimeSyncWindowGraphResult,
RuntimeTerminalDriverState
} from '../../shared/runtime-types'
import type { RuntimeRpcResponse } from '../../shared/runtime-rpc-envelope'
import type { ClientHostedBrowserRowsEvent } from '../../shared/client-hosted-browser-rows'
import type { PublicKnownRuntimeEnvironment } from '../../shared/runtime-environments'
import type { VerifyAndAddRuntimeEnvironmentResult } from '../../shared/remote-pairing-verification'
import type {
BrowserClientHostPlacementPreparationRequest,
BrowserPageCreationPlacement
} from '../../shared/browser-client-host-placement'
import type { RemoteRuntimeSharedConnectionDiagnostics } from '../../shared/remote-runtime-shared-control-types'
export type RuntimeEnvironmentSubscriptionHandle = {
unsubscribe: () => void
sendBinary: (bytes: Uint8Array<ArrayBufferLike>) => void
}
export type RuntimeApi = {
runtime: {
syncWindowGraph: (
graph: RuntimeRendererSyncWindowGraph
) => Promise<RuntimeSyncWindowGraphResult>
getStatus: () => Promise<RuntimeStatus>
call: (args: { method: string; params?: unknown }) => Promise<RuntimeRpcResponse<unknown>>
subscribe: (
args: { method: string; params?: unknown },
callback: (response: RuntimeRpcResponse<unknown>) => void
) => Promise<RuntimeEnvironmentSubscriptionHandle>
getTerminalFitOverrides: () => Promise<
{ ptyId: string; mode: 'mobile-fit' | 'remote-desktop-fit'; cols: number; rows: number }[]
>
getTerminalDrivers: () => Promise<
{
ptyId: string
driver: RuntimeTerminalDriverState
}[]
>
getBrowserDrivers: () => Promise<
{
browserPageId: string
driver: RuntimeBrowserDriverState
}[]
>
getBrowserRemoteViewerPages?: () => Promise<string[]>
getClientHostedBrowserRows: () => Promise<ClientHostedBrowserRowsEvent[]>
restoreTerminalFit: (ptyId: string) => Promise<{ restored: boolean }>
reclaimBrowserForDesktop: (browserPageId: string) => Promise<{ reclaimed: boolean }>
onTerminalFitOverrideChanged: (
callback: (event: {
ptyId: string
mode: 'mobile-fit' | 'remote-desktop-fit' | 'desktop-fit'
cols: number
rows: number
}) => void
) => () => void
onTerminalDriverChanged: (
callback: (event: { ptyId: string; driver: RuntimeTerminalDriverState }) => void
) => () => void
onNativeChatLaunchDraftResolved?: (
callback: (event: { tabId: string; text: string; createdAt: number }) => void
) => () => void
onBrowserDriverChanged: (
callback: (event: { browserPageId: string; driver: RuntimeBrowserDriverState }) => void
) => () => void
// Why optional: matches onNativeChatLaunchDraftResolved — a renderer running against an older
// preload keeps working without the retention signal instead of throwing on every mount.
onBrowserRemoteViewersChanged?: (
callback: (event: { browserPageId: string; hasRemoteViewers: boolean }) => void
) => () => void
onClientHostedBrowserRowsChanged: (
callback: (event: ClientHostedBrowserRowsEvent) => void
) => () => void
}
runtimeEnvironments: {
getStatusSnapshots: () => Promise<RuntimeHostStatusSnapshot[]>
onStatusChanged: (callback: (snapshot: RuntimeHostStatusSnapshot) => void) => () => void
list: () => Promise<PublicKnownRuntimeEnvironment[]>
addFromPairingCode: (args: {
name: string
pairingCode: string
}) => Promise<{ environment: PublicKnownRuntimeEnvironment }>
verifyAndAddFromPairingCode: (args: {
name: string
pairingCode: string
allowLoopback?: boolean
}) => Promise<VerifyAndAddRuntimeEnvironmentResult>
resolve: (args: { selector: string }) => Promise<PublicKnownRuntimeEnvironment>
remove: (args: { selector: string }) => Promise<{ removed: PublicKnownRuntimeEnvironment }>
disconnect: (args: {
selector: string
}) => Promise<{ disconnected: PublicKnownRuntimeEnvironment }>
connect: (args: {
selector: string
timeoutMs?: number
}) => Promise<RuntimeRpcResponse<RuntimeStatus>>
getStatus: (args: {
selector: string
timeoutMs?: number
observeOnly?: true
}) => Promise<RuntimeRpcResponse<RuntimeStatus>>
retryControlConnection?: (args: { selector: string }) => Promise<void>
onSharedControlDiagnostics?: (
callback: (event: {
environmentId: string
transportGeneration: number
diagnostics: RemoteRuntimeSharedConnectionDiagnostics
}) => void
) => () => void
prepareBrowserClientHostPlacement: (
args: BrowserClientHostPlacementPreparationRequest
) => Promise<BrowserPageCreationPlacement>
// Why: system resume / browser online advance pending shared-control reconnect timers only.
retryConnectionsNow?: () => Promise<void>
call: (args: {
selector: string
method: string
params?: unknown
timeoutMs?: number
expectedEnvironmentPairingRevision?: number
}) => Promise<RuntimeRpcResponse<unknown>>
subscribe: (
args: {
selector: string
method: string
params?: unknown
timeoutMs?: number
expectedEnvironmentPairingRevision?: number
},
callbacks: {
onResponse: (response: RuntimeRpcResponse<unknown>) => void
onBinary?: (bytes: Uint8Array<ArrayBufferLike>) => void
onError?: (error: { code: string; message: string }) => void
onClose?: () => void
}
) => Promise<RuntimeEnvironmentSubscriptionHandle>
}
wsl: {
isAvailable: () => Promise<boolean>
listDistros: () => Promise<string[]>
}
pwsh: {
isAvailable: () => Promise<boolean>
}
gitBash: {
isAvailable: () => Promise<boolean>
}
}