Files
orca/src/preload/api/runtime-environments-bridge.ts
Neil 0d1220c31f Organize SSH and managed-server modules by concrete owner (#39937)
* refactor(main): organize SSH transport and managed server owners

* Remove orphan deploy readiness fixture and shrink test baselines

* refactor(wsl): import lock records from their defining owner

* refactor(wsl): use the canonical deferred update contract
2026-11-08 12:20:22 -08:00

150 lines
6.5 KiB
TypeScript

import { ipcRenderer } from 'electron'
import {
RUNTIME_HOST_STATUS_CHANNEL,
type RuntimeHostStatusSnapshot
} from '../../shared/remote-runtime/host-status/runtime-host-status'
import type { VerifyAndAddRuntimeEnvironmentResult } from '../../shared/remote-runtime/pairing/remote-pairing-verification'
import type { RuntimeStatus } from '../../shared/runtime-session-contracts'
import type { RuntimeRpcResponse } from '../../shared/runtime-rpc-envelope'
import type {
PublicKnownRuntimeEnvironment,
RuntimeEnvironmentRemoval
} from '../../shared/remote-runtime/host-catalog/runtime-environments'
import type { RemoteRuntimeSharedConnectionDiagnostics } from '../../shared/remote-runtime/control/remote-runtime-shared-control-types'
import { RUNTIME_ENVIRONMENT_DIAGNOSTICS_CHANNEL } from '../../shared/remote-runtime/host-catalog/runtime-environment-diagnostics'
import { RUNTIME_ENVIRONMENT_CATALOG_CHANGED_CHANNEL } from '../../shared/remote-runtime/host-catalog/runtime-environment-catalog-channel'
import {
WSL_ORCAD_ACCOUNT_NOT_APPLIED_CHANNEL,
type WslOrcadAccountNotAppliedEvent
} from '../../shared/wsl-orcad-account-notice'
import {
subscribeRuntimeEnvironmentFromPreload,
subscribeCrewAttemptFromPreload,
cancelRuntimeEnvironmentSubscriptionFromPreload,
type RuntimeEnvironmentSubscriptionHandle
} from '../runtime-environment-subscriptions'
import type { PreloadApi } from '../api-types'
import { managedOrcadApi } from './managed-orcad-api'
import { getWslHostsApi } from './wsl-hosts-api'
export const runtimeEnvironmentsApi = {
desktopCreatedChatIds: (): Promise<string[]> =>
ipcRenderer.invoke('runtimeEnvironments:desktopCreatedChatIds'),
getStatusSnapshots: (): Promise<RuntimeHostStatusSnapshot[]> =>
ipcRenderer.invoke('runtimeEnvironments:getStatusSnapshots'),
onStatusChanged: (callback: (snapshot: RuntimeHostStatusSnapshot) => void): (() => void) => {
const listener = (
_event: Electron.IpcRendererEvent,
snapshot: RuntimeHostStatusSnapshot
): void => callback(snapshot)
ipcRenderer.on(RUNTIME_HOST_STATUS_CHANNEL, listener)
return () => ipcRenderer.removeListener(RUNTIME_HOST_STATUS_CHANNEL, listener)
},
onCatalogChanged: (callback: () => void): (() => void) => {
const listener = (): void => callback()
ipcRenderer.on(RUNTIME_ENVIRONMENT_CATALOG_CHANGED_CHANNEL, listener)
return () => ipcRenderer.removeListener(RUNTIME_ENVIRONMENT_CATALOG_CHANGED_CHANNEL, listener)
},
list: (): Promise<PublicKnownRuntimeEnvironment[]> =>
ipcRenderer.invoke('runtimeEnvironments:list'),
addFromPairingCode: (args: {
name: string
pairingCode: string
}): Promise<{ environment: PublicKnownRuntimeEnvironment }> =>
ipcRenderer.invoke('runtimeEnvironments:addFromPairingCode', args),
verifyAndAddFromPairingCode: (args: {
name: string
pairingCode: string
allowLoopback?: boolean
}): Promise<VerifyAndAddRuntimeEnvironmentResult> =>
ipcRenderer.invoke('runtimeEnvironments:verifyAndAddFromPairingCode', args),
repairFromPairingCode: (args: {
selector: string
pairingCode: string
}): Promise<VerifyAndAddRuntimeEnvironmentResult> =>
ipcRenderer.invoke('runtimeEnvironments:repairFromPairingCode', args),
resolve: (args: { selector: string }): Promise<PublicKnownRuntimeEnvironment> =>
ipcRenderer.invoke('runtimeEnvironments:resolve', args),
remove: (args: { selector: string }): Promise<RuntimeEnvironmentRemoval> =>
ipcRenderer.invoke('runtimeEnvironments:remove', args),
disconnect: (args: {
selector: string
}): Promise<{ disconnected: PublicKnownRuntimeEnvironment }> =>
ipcRenderer.invoke('runtimeEnvironments:disconnect', args),
connect: (args: {
selector: string
timeoutMs?: number
}): Promise<RuntimeRpcResponse<RuntimeStatus>> =>
ipcRenderer.invoke('runtimeEnvironments:connect', args),
getStatus: (args: {
selector: string
timeoutMs?: number
observeOnly?: true
}): Promise<RuntimeRpcResponse<RuntimeStatus>> =>
ipcRenderer.invoke('runtimeEnvironments:getStatus', args),
onSharedControlDiagnostics: (
callback: (event: {
environmentId: string
transportGeneration: number
diagnostics: RemoteRuntimeSharedConnectionDiagnostics
}) => void
): (() => void) => {
const listener = (
_event: Electron.IpcRendererEvent,
data: {
environmentId: string
transportGeneration: number
diagnostics: RemoteRuntimeSharedConnectionDiagnostics
}
): void => callback(data)
ipcRenderer.on(RUNTIME_ENVIRONMENT_DIAGNOSTICS_CHANNEL, listener)
return () => ipcRenderer.removeListener(RUNTIME_ENVIRONMENT_DIAGNOSTICS_CHANNEL, listener)
},
onWslAccountNotApplied: (
callback: (event: WslOrcadAccountNotAppliedEvent) => void
): (() => void) => {
const listener = (
_event: Electron.IpcRendererEvent,
data: WslOrcadAccountNotAppliedEvent
): void => callback(data)
ipcRenderer.on(WSL_ORCAD_ACCOUNT_NOT_APPLIED_CHANNEL, listener)
return () => ipcRenderer.removeListener(WSL_ORCAD_ACCOUNT_NOT_APPLIED_CHANNEL, listener)
},
prepareBrowserClientHostPlacement: (args) =>
ipcRenderer.invoke('runtimeEnvironments:prepareBrowserClientHostPlacement', args),
retryConnectionsNow: (): Promise<void> =>
ipcRenderer.invoke('runtimeEnvironments:retryConnectionsNow'),
call: (args: {
selector: string
method: string
params?: unknown
timeoutMs?: number
expectedEnvironmentPairingRevision?: number
expectedEnvironmentRuntimeId?: string
}): Promise<RuntimeRpcResponse<unknown>> => ipcRenderer.invoke('runtimeEnvironments:call', args),
cancelSubscription: (args: { subscriptionId: string }): Promise<void> =>
cancelRuntimeEnvironmentSubscriptionFromPreload(ipcRenderer, args.subscriptionId),
subscribeCrewAttempt: (args, callbacks) =>
subscribeCrewAttemptFromPreload(ipcRenderer, args, callbacks),
subscribe: async (
args: {
subscriptionId?: string
selector: string
method: string
params?: unknown
timeoutMs?: number
expectedEnvironmentPairingRevision?: number
expectedEnvironmentRuntimeId?: string
},
callbacks: {
onResponse: (response: RuntimeRpcResponse<unknown>) => void
onBinary?: (bytes: Uint8Array<ArrayBufferLike>) => void
onError?: (error: { code: string; message: string }) => void
onClose?: () => void
}
): Promise<RuntimeEnvironmentSubscriptionHandle> =>
subscribeRuntimeEnvironmentFromPreload(ipcRenderer, args, callbacks),
managedOrcad: managedOrcadApi,
wslHosts: getWslHostsApi()
} satisfies PreloadApi['runtimeEnvironments']