mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 02:31:22 +00:00
chore: migrate to oxlint and oxfmt
Co-authored-by: Christoph Nakazawa <christoph.pojer@gmail.com>
This commit is contained in:
@@ -62,8 +62,7 @@ describe("node bridge server", () => {
|
||||
const ifaces = os.networkInterfaces();
|
||||
for (const entries of Object.values(ifaces)) {
|
||||
for (const info of entries ?? []) {
|
||||
if (info.family === "IPv4" && info.internal === false)
|
||||
return info.address;
|
||||
if (info.family === "IPv4" && info.internal === false) return info.address;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@@ -231,8 +230,7 @@ describe("node bridge server", () => {
|
||||
});
|
||||
|
||||
it("handles req/res RPC after authentication", async () => {
|
||||
let lastRequest: { nodeId?: string; id?: string; method?: string } | null =
|
||||
null;
|
||||
let lastRequest: { nodeId?: string; id?: string; method?: string } | null = null;
|
||||
|
||||
const server = await startNodeBridgeServer({
|
||||
host: "127.0.0.1",
|
||||
@@ -386,10 +384,9 @@ describe("node bridge server", () => {
|
||||
const line3 = JSON.parse(await readLine2()) as { type: string };
|
||||
expect(line3.type).toBe("hello-ok");
|
||||
|
||||
await pollUntil(
|
||||
async () => (lastAuthed?.nodeId === "n4" ? lastAuthed : null),
|
||||
{ timeoutMs: 3000 },
|
||||
);
|
||||
await pollUntil(async () => (lastAuthed?.nodeId === "n4" ? lastAuthed : null), {
|
||||
timeoutMs: 3000,
|
||||
});
|
||||
|
||||
expect(lastAuthed?.nodeId).toBe("n4");
|
||||
// Prefer paired metadata over hello payload (token verifies the stored node record).
|
||||
|
||||
@@ -62,8 +62,7 @@ describe("node bridge server", () => {
|
||||
const ifaces = os.networkInterfaces();
|
||||
for (const entries of Object.values(ifaces)) {
|
||||
for (const info of entries ?? []) {
|
||||
if (info.family === "IPv4" && info.internal === false)
|
||||
return info.address;
|
||||
if (info.family === "IPv4" && info.internal === false) return info.address;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@@ -206,21 +205,13 @@ describe("node bridge server", () => {
|
||||
expect(node?.deviceFamily).toBe("iPad");
|
||||
expect(node?.modelIdentifier).toBe("iPad14,5");
|
||||
expect(node?.caps).toEqual(["canvas", "camera"]);
|
||||
expect(node?.commands).toEqual([
|
||||
"canvas.eval",
|
||||
"canvas.snapshot",
|
||||
"camera.snap",
|
||||
]);
|
||||
expect(node?.commands).toEqual(["canvas.eval", "canvas.snapshot", "camera.snap"]);
|
||||
expect(node?.permissions).toEqual({ accessibility: true });
|
||||
|
||||
const after = await listNodePairing(baseDir);
|
||||
const paired = after.paired.find((p) => p.nodeId === "n-caps");
|
||||
expect(paired?.caps).toEqual(["canvas", "camera"]);
|
||||
expect(paired?.commands).toEqual([
|
||||
"canvas.eval",
|
||||
"canvas.snapshot",
|
||||
"camera.snap",
|
||||
]);
|
||||
expect(paired?.commands).toEqual(["canvas.eval", "canvas.snapshot", "camera.snap"]);
|
||||
expect(paired?.permissions).toEqual({ accessibility: true });
|
||||
|
||||
socket.destroy();
|
||||
|
||||
@@ -101,20 +101,15 @@ export function createNodeBridgeConnectionHandler(params: {
|
||||
const family = String(frame.deviceFamily ?? "")
|
||||
.trim()
|
||||
.toLowerCase();
|
||||
if (platform.includes("ios") || platform.includes("ipados"))
|
||||
return ["canvas", "camera"];
|
||||
if (platform.includes("ios") || platform.includes("ipados")) return ["canvas", "camera"];
|
||||
if (platform.includes("android")) return ["canvas", "camera"];
|
||||
if (family === "ipad" || family === "iphone" || family === "ios")
|
||||
return ["canvas", "camera"];
|
||||
if (family === "ipad" || family === "iphone" || family === "ios") return ["canvas", "camera"];
|
||||
if (family === "android") return ["canvas", "camera"];
|
||||
return undefined;
|
||||
};
|
||||
|
||||
const normalizePermissions = (
|
||||
raw: unknown,
|
||||
): Record<string, boolean> | undefined => {
|
||||
if (!raw || typeof raw !== "object" || Array.isArray(raw))
|
||||
return undefined;
|
||||
const normalizePermissions = (raw: unknown): Record<string, boolean> | undefined => {
|
||||
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return undefined;
|
||||
const entries = Object.entries(raw as Record<string, unknown>)
|
||||
.map(([key, value]) => [String(key).trim(), value === true] as const)
|
||||
.filter(([key]) => key.length > 0);
|
||||
@@ -136,11 +131,7 @@ export function createNodeBridgeConnectionHandler(params: {
|
||||
return;
|
||||
}
|
||||
|
||||
const verified = await verifyNodeToken(
|
||||
nodeId,
|
||||
token,
|
||||
opts.pairingBaseDir,
|
||||
);
|
||||
const verified = await verifyNodeToken(nodeId, token, opts.pairingBaseDir);
|
||||
if (!verified.ok || !verified.node) {
|
||||
sendError("UNAUTHORIZED", "invalid token");
|
||||
return;
|
||||
@@ -212,15 +203,11 @@ export function createNodeBridgeConnectionHandler(params: {
|
||||
requestId: string;
|
||||
nodeId: string;
|
||||
ts: number;
|
||||
}): Promise<
|
||||
{ ok: true; token: string } | { ok: false; reason: string }
|
||||
> => {
|
||||
}): Promise<{ ok: true; token: string } | { ok: false; reason: string }> => {
|
||||
const deadline = Date.now() + 5 * 60 * 1000;
|
||||
while (!abort.signal.aborted && Date.now() < deadline) {
|
||||
const list = await listNodePairing(opts.pairingBaseDir);
|
||||
const stillPending = list.pending.some(
|
||||
(p) => p.requestId === request.requestId,
|
||||
);
|
||||
const stillPending = list.pending.some((p) => p.requestId === request.requestId);
|
||||
if (stillPending) {
|
||||
await sleep(250);
|
||||
continue;
|
||||
@@ -301,9 +288,7 @@ export function createNodeBridgeConnectionHandler(params: {
|
||||
version: req.version,
|
||||
deviceFamily: req.deviceFamily,
|
||||
modelIdentifier: req.modelIdentifier,
|
||||
caps: Array.isArray(req.caps)
|
||||
? req.caps.map((c) => String(c)).filter(Boolean)
|
||||
: undefined,
|
||||
caps: Array.isArray(req.caps) ? req.caps.map((c) => String(c)).filter(Boolean) : undefined,
|
||||
commands: Array.isArray(req.commands)
|
||||
? req.commands.map((c) => String(c)).filter(Boolean)
|
||||
: undefined,
|
||||
|
||||
@@ -4,10 +4,7 @@ import os from "node:os";
|
||||
|
||||
import { resolveCanvasHostUrl } from "../../canvas-host-url.js";
|
||||
|
||||
import {
|
||||
type ConnectionState,
|
||||
createNodeBridgeConnectionHandler,
|
||||
} from "./connection.js";
|
||||
import { type ConnectionState, createNodeBridgeConnectionHandler } from "./connection.js";
|
||||
import { createDisabledNodeBridgeServer } from "./disabled.js";
|
||||
import { encodeLine } from "./encode.js";
|
||||
import { shouldAlsoListenOnLoopback } from "./loopback.js";
|
||||
@@ -20,13 +17,8 @@ import type {
|
||||
NodeBridgeServerOpts,
|
||||
} from "./types.js";
|
||||
|
||||
export async function startNodeBridgeServer(
|
||||
opts: NodeBridgeServerOpts,
|
||||
): Promise<NodeBridgeServer> {
|
||||
if (
|
||||
isNodeBridgeTestEnv() &&
|
||||
process.env.CLAWDBOT_ENABLE_BRIDGE_IN_TESTS !== "1"
|
||||
) {
|
||||
export async function startNodeBridgeServer(opts: NodeBridgeServerOpts): Promise<NodeBridgeServer> {
|
||||
if (isNodeBridgeTestEnv() && process.env.CLAWDBOT_ENABLE_BRIDGE_IN_TESTS !== "1") {
|
||||
return createDisabledNodeBridgeServer();
|
||||
}
|
||||
|
||||
@@ -70,8 +62,7 @@ export async function startNodeBridgeServer(
|
||||
});
|
||||
|
||||
const address = primary.address();
|
||||
const port =
|
||||
typeof address === "object" && address ? address.port : opts.port;
|
||||
const port = typeof address === "object" && address ? address.port : opts.port;
|
||||
|
||||
if (shouldAlsoListenOnLoopback(opts.host)) {
|
||||
const loopback = net.createServer(onConnection);
|
||||
@@ -137,16 +128,11 @@ export async function startNodeBridgeServer(
|
||||
invoke: async ({ nodeId, command, paramsJSON, timeoutMs }) => {
|
||||
const normalizedNodeId = String(nodeId ?? "").trim();
|
||||
const normalizedCommand = String(command ?? "").trim();
|
||||
if (!normalizedNodeId)
|
||||
throw new Error("INVALID_REQUEST: nodeId required");
|
||||
if (!normalizedCommand)
|
||||
throw new Error("INVALID_REQUEST: command required");
|
||||
if (!normalizedNodeId) throw new Error("INVALID_REQUEST: nodeId required");
|
||||
if (!normalizedCommand) throw new Error("INVALID_REQUEST: command required");
|
||||
|
||||
const conn = connections.get(normalizedNodeId);
|
||||
if (!conn)
|
||||
throw new Error(
|
||||
`UNAVAILABLE: node not connected (${normalizedNodeId})`,
|
||||
);
|
||||
if (!conn) throw new Error(`UNAVAILABLE: node not connected (${normalizedNodeId})`);
|
||||
|
||||
const id = randomUUID();
|
||||
const timeout = Number.isFinite(timeoutMs) ? Number(timeoutMs) : 15_000;
|
||||
|
||||
@@ -101,11 +101,7 @@ export type NodeBridgeServer = {
|
||||
paramsJSON?: string | null;
|
||||
timeoutMs?: number;
|
||||
}) => Promise<BridgeInvokeResponseFrame>;
|
||||
sendEvent: (opts: {
|
||||
nodeId: string;
|
||||
event: string;
|
||||
payloadJSON?: string | null;
|
||||
}) => void;
|
||||
sendEvent: (opts: { nodeId: string; event: string; payloadJSON?: string | null }) => void;
|
||||
listConnected: () => NodeBridgeClientInfo[];
|
||||
listeners: Array<{ host: string; port: number }>;
|
||||
};
|
||||
@@ -139,8 +135,6 @@ export type NodeBridgeServerOpts = {
|
||||
>;
|
||||
onAuthenticated?: (node: NodeBridgeClientInfo) => Promise<void> | void;
|
||||
onDisconnected?: (node: NodeBridgeClientInfo) => Promise<void> | void;
|
||||
onPairRequested?: (
|
||||
request: NodePairingPendingRequest,
|
||||
) => Promise<void> | void;
|
||||
onPairRequested?: (request: NodePairingPendingRequest) => Promise<void> | void;
|
||||
serverName?: string;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user