mirror of
https://github.com/wu736139669/hapi.git
synced 2026-08-05 06:24:37 +00:00
refactor: reuse shared machine socket types
This commit is contained in:
@@ -8,7 +8,7 @@ import { realpathSync } from 'node:fs'
|
||||
import { basename, dirname, isAbsolute, join, relative, resolve as resolvePath } from 'node:path'
|
||||
import { logger } from '@/ui/logger'
|
||||
import { configuration } from '@/configuration'
|
||||
import type { Update, UpdateMachineBody } from '@hapi/protocol'
|
||||
import type { ClientToServerEvents, ServerToClientEvents, Update, UpdateMachineBody } from '@hapi/protocol'
|
||||
import type { MachineDirectoryEntry, MachineListDirectoryResponse, PathExistsResponse } from '@hapi/protocol/apiTypes'
|
||||
import { RPC_METHODS } from '@hapi/protocol/rpcMethods'
|
||||
import type { RunnerState, Machine, MachineMetadata } from './types'
|
||||
@@ -26,40 +26,6 @@ import type { SpawnSessionOptions, SpawnSessionResult } from '../modules/common/
|
||||
import { applyVersionedAck } from './versionedUpdate'
|
||||
import { buildSocketIoExtraHeaderOptions } from './hubExtraHeaders'
|
||||
|
||||
interface ServerToRunnerEvents {
|
||||
update: (data: Update) => void
|
||||
'rpc-request': (data: { method: string; params: string }, callback: (response: string) => void) => void
|
||||
error: (data: { message: string }) => void
|
||||
}
|
||||
|
||||
interface RunnerToServerEvents {
|
||||
'machine-alive': (data: { machineId: string; time: number }) => void
|
||||
'machine-update-metadata': (data: { machineId: string; metadata: unknown; expectedVersion: number }, cb: (answer: {
|
||||
result: 'error'
|
||||
} | {
|
||||
result: 'version-mismatch'
|
||||
version: number
|
||||
metadata: unknown | null
|
||||
} | {
|
||||
result: 'success'
|
||||
version: number
|
||||
metadata: unknown | null
|
||||
}) => void) => void
|
||||
'machine-update-state': (data: { machineId: string; runnerState: unknown | null; expectedVersion: number }, cb: (answer: {
|
||||
result: 'error'
|
||||
} | {
|
||||
result: 'version-mismatch'
|
||||
version: number
|
||||
runnerState: unknown | null
|
||||
} | {
|
||||
result: 'success'
|
||||
version: number
|
||||
runnerState: unknown | null
|
||||
}) => void) => void
|
||||
'rpc-register': (data: { method: string }) => void
|
||||
'rpc-unregister': (data: { method: string }) => void
|
||||
}
|
||||
|
||||
type MachineRpcHandlers = {
|
||||
spawnSession: (options: SpawnSessionOptions) => Promise<SpawnSessionResult>
|
||||
stopSession: (sessionId: string) => boolean
|
||||
@@ -105,7 +71,7 @@ function formatWorkspaceRoots(paths?: string[]): string {
|
||||
}
|
||||
|
||||
export class ApiMachineClient {
|
||||
private socket!: Socket<ServerToRunnerEvents, RunnerToServerEvents>
|
||||
private socket!: Socket<ServerToClientEvents, ClientToServerEvents>
|
||||
private keepAliveInterval: NodeJS.Timeout | null = null
|
||||
private rpcHandlerManager: RpcHandlerManager
|
||||
|
||||
|
||||
Reference in New Issue
Block a user