mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-26 04:15:48 -06:00
69 lines
2.3 KiB
TypeScript
69 lines
2.3 KiB
TypeScript
/**
|
|
* Browser-local SDK config bridge plus Browser-specific default port helpers.
|
|
*/
|
|
import { parseBooleanValue } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
|
|
export {
|
|
getRuntimeConfig,
|
|
getRuntimeConfigSourceSnapshot,
|
|
} from "openclaw/plugin-sdk/runtime-config-snapshot";
|
|
export { mutateConfigFile } from "openclaw/plugin-sdk/config-mutation";
|
|
export {
|
|
type BrowserConfig,
|
|
type BrowserProfileConfig,
|
|
type OpenClawConfig,
|
|
} from "openclaw/plugin-sdk/config-contracts";
|
|
export {
|
|
normalizePluginsConfig,
|
|
resolveEffectiveEnableState,
|
|
} from "openclaw/plugin-sdk/plugin-config-runtime";
|
|
export { resolveGatewayPort } from "openclaw/plugin-sdk/core";
|
|
export {
|
|
CONFIG_DIR,
|
|
escapeRegExp,
|
|
resolveUserPath,
|
|
shortenHomePath,
|
|
} from "openclaw/plugin-sdk/text-utility-runtime";
|
|
type PortRange = { start: number; end: number };
|
|
|
|
const DEFAULT_BROWSER_CDP_PORT_RANGE_START = 18800;
|
|
const DEFAULT_BROWSER_CDP_PORT_RANGE_END = 18899;
|
|
const DEFAULT_BROWSER_CDP_PORT_RANGE_SPAN =
|
|
DEFAULT_BROWSER_CDP_PORT_RANGE_END - DEFAULT_BROWSER_CDP_PORT_RANGE_START;
|
|
|
|
/** Default loopback port for the Browser control server. */
|
|
export const DEFAULT_BROWSER_CONTROL_PORT = 18791;
|
|
|
|
function isValidPort(port: number): boolean {
|
|
return Number.isFinite(port) && port > 0 && port <= 65535;
|
|
}
|
|
|
|
function clampPort(port: number, fallback: number): number {
|
|
return isValidPort(port) ? port : fallback;
|
|
}
|
|
|
|
function derivePort(base: number, offset: number, fallback: number): number {
|
|
return clampPort(base + offset, fallback);
|
|
}
|
|
|
|
/** Derives the Browser control port from the gateway port. */
|
|
export function deriveDefaultBrowserControlPort(gatewayPort: number): number {
|
|
return derivePort(gatewayPort, 2, DEFAULT_BROWSER_CONTROL_PORT);
|
|
}
|
|
|
|
/** Derives the managed Chrome CDP port range from the Browser control port. */
|
|
export function deriveDefaultBrowserCdpPortRange(browserControlPort: number): PortRange {
|
|
const start = derivePort(browserControlPort, 9, DEFAULT_BROWSER_CDP_PORT_RANGE_START);
|
|
const end = start + DEFAULT_BROWSER_CDP_PORT_RANGE_SPAN;
|
|
if (end <= 65535) {
|
|
return { start, end };
|
|
}
|
|
return {
|
|
start: DEFAULT_BROWSER_CDP_PORT_RANGE_START,
|
|
end: DEFAULT_BROWSER_CDP_PORT_RANGE_END,
|
|
};
|
|
}
|
|
|
|
/** Parses common string booleans with optional custom truthy/falsy tokens. */
|
|
export { parseBooleanValue };
|