Skip to content

Commit da3fa1e

Browse files
DeJeuneclaude
andcommitted
refactor: move NodeCheckResult to shared types
Extract NodeCheckResult from OpenClawService.ts to packages/shared/config/types.ts so it can be shared across the main process, preload bridge, and renderer without duplication. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent eb2eb62 commit da3fa1e

File tree

4 files changed

+14
-16
lines changed

4 files changed

+14
-16
lines changed

packages/shared/config/types.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
import type { ProcessingStatus } from '@types'
22

3+
// =============================================================================
4+
// OpenClaw IPC Types
5+
// =============================================================================
6+
7+
export type NodeCheckResult =
8+
| { status: 'not_found' }
9+
| { status: 'version_low'; version: string; path: string }
10+
| { status: 'ok'; version: string; path: string }
11+
312
export type LoaderReturn = {
413
entriesAdded: number
514
uniqueId: string

src/main/services/OpenClawService.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { isLinux, isMac, isWin } from '@main/constant'
1010
import { isUserInChina } from '@main/utils/ipService'
1111
import { crossPlatformSpawn, executeCommand, findExecutableInEnv } from '@main/utils/process'
1212
import getShellEnv, { refreshShellEnv } from '@main/utils/shell-env'
13+
import type { NodeCheckResult } from '@shared/config/types'
1314
import { IpcChannel } from '@shared/IpcChannel'
1415
import { hasAPIVersion, withoutTrailingSlash } from '@shared/utils'
1516
import type { Model, Provider, ProviderType, VertexProvider } from '@types'
@@ -31,11 +32,6 @@ const DEFAULT_GATEWAY_PORT = 18790
3132

3233
export type GatewayStatus = 'stopped' | 'starting' | 'running' | 'error'
3334

34-
export type NodeCheckResult =
35-
| { status: 'not_found' }
36-
| { status: 'version_low'; version: string; path: string }
37-
| { status: 'ok'; version: string; path: string }
38-
3935
export interface HealthInfo {
4036
status: 'healthy' | 'unhealthy'
4137
gatewayPort: number

src/preload/index.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type {
1212
LanHandshakeAckMessage,
1313
LocalTransferConnectPayload,
1414
LocalTransferState,
15+
NodeCheckResult,
1516
WebviewKeyEvent
1617
} from '@shared/config/types'
1718
import type { MCPServerLogEntry } from '@shared/config/types'
@@ -671,11 +672,7 @@ const api = {
671672
openclaw: {
672673
checkInstalled: (): Promise<{ installed: boolean; path: string | null }> =>
673674
ipcRenderer.invoke(IpcChannel.OpenClaw_CheckInstalled),
674-
checkNodeVersion: (): Promise<
675-
| { status: 'not_found' }
676-
| { status: 'version_low'; version: string; path: string }
677-
| { status: 'ok'; version: string; path: string }
678-
> => ipcRenderer.invoke(IpcChannel.OpenClaw_CheckNodeVersion),
675+
checkNodeVersion: (): Promise<NodeCheckResult> => ipcRenderer.invoke(IpcChannel.OpenClaw_CheckNodeVersion),
679676
checkGitAvailable: (): Promise<{ available: boolean; path: string | null }> =>
680677
ipcRenderer.invoke(IpcChannel.OpenClaw_CheckGitAvailable),
681678
getNodeDownloadUrl: (): Promise<string> => ipcRenderer.invoke(IpcChannel.OpenClaw_GetNodeDownloadUrl),

src/renderer/src/pages/openclaw/OpenClawPage.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
setLastHealthCheck,
1414
setSelectedModelUniqId
1515
} from '@renderer/store/openclaw'
16+
import type { NodeCheckResult } from '@shared/config/types'
1617
import { IpcChannel } from '@shared/IpcChannel'
1718
import { Alert, Avatar, Button, Result, Space, Spin } from 'antd'
1819
import { Download, ExternalLink, Play, RefreshCw, Square } from 'lucide-react'
@@ -27,12 +28,7 @@ const DEFAULT_DOCS_URL = 'https://docs.openclaw.ai/'
2728
type NodeStatus = { status: 'not_found' } | { status: 'version_low'; version: string } | { status: 'ok' }
2829

2930
/** Map the IPC result to the UI-side NodeStatus (drops the `path` field the renderer doesn't need). */
30-
function toNodeStatus(
31-
result:
32-
| { status: 'not_found' }
33-
| { status: 'version_low'; version: string; path: string }
34-
| { status: 'ok'; version: string; path: string }
35-
): NodeStatus {
31+
function toNodeStatus(result: NodeCheckResult): NodeStatus {
3632
if (result.status === 'version_low') return { status: 'version_low', version: result.version }
3733
if (result.status === 'ok') return { status: 'ok' }
3834
return { status: 'not_found' }

0 commit comments

Comments
 (0)