MCPcopy
hub / github.com/ValueCell-ai/ClawX / createGatewayApi

Function createGatewayApi

electron/services/gateway-api.ts:32–79  ·  view source on GitHub ↗
(
  gatewayManager: GatewayManager,
  gatewayRpcBackpressure: GatewayRpcBackpressure,
)

Source from the content-addressed store, hash-verified

30}
31
32export function createGatewayApi(
33 gatewayManager: GatewayManager,
34 gatewayRpcBackpressure: GatewayRpcBackpressure,
35): CompleteHostServiceRegistry['gateway'] {
36 return {
37 status: () => gatewayManager.getStatus(),
38 start: async () => {
39 await gatewayManager.start();
40 return { success: true };
41 },
42 stop: async () => {
43 await gatewayManager.stop();
44 return { success: true };
45 },
46 restart: async () => {
47 await gatewayManager.restart();
48 return { success: true };
49 },
50 health: async (payload) => {
51 const body = isRecord(payload) ? payload as HealthPayload : {};
52 return gatewayManager.checkHealth({ probe: body.probe === true });
53 },
54 controlUi: async (payload) => {
55 const body = isRecord(payload) ? payload as ControlUiPayload : {};
56 const status = gatewayManager.getStatus();
57 const token = await getSetting('gatewayToken');
58 const port = status.port || PORTS.OPENCLAW_GATEWAY;
59 const view = body.view === 'dreams' ? 'dreams' : undefined;
60 const url = buildOpenClawControlUiUrl(port, token, { view });
61 scheduleControlUiDeviceAutoApproval(gatewayManager);
62 return { success: true, url, token, port };
63 },
64 rpc: async (payload) => {
65 const body = isRecord(payload) ? payload as RpcPayload : {};
66 const method = typeof body.method === 'string' ? body.method.trim() : '';
67 if (!method) {
68 throw new Error('Invalid gateway RPC method');
69 }
70 const timeoutMs = parseTimeoutMs(body.timeoutMs);
71 return gatewayRpcBackpressure.run(
72 method,
73 body.params,
74 timeoutMs,
75 (rpcMethod, rpcParams, rpcTimeoutMs) => gatewayManager.rpc(rpcMethod, rpcParams, rpcTimeoutMs),
76 );
77 },
78 };
79}

Callers 2

Calls 12

isRecordFunction · 0.90
getSettingFunction · 0.90
parseTimeoutMsFunction · 0.85
restartMethod · 0.80
checkHealthMethod · 0.80
runMethod · 0.80
rpcMethod · 0.80
getStatusMethod · 0.45
startMethod · 0.45
stopMethod · 0.45

Tested by

no test coverage detected