refactor: trim browser helper exports

This commit is contained in:
Peter Steinberger
2026-05-01 18:17:29 +01:00
parent 8ba84e8bf2
commit 11dc38cd55
20 changed files with 25 additions and 34 deletions

View File

@@ -1,4 +1,4 @@
export type ChromeMcpModule = typeof import("./chrome-mcp.js");
type ChromeMcpModule = typeof import("./chrome-mcp.js");
export async function getChromeMcpModule(): Promise<ChromeMcpModule> {
return await import("./chrome-mcp.js");

View File

@@ -11,9 +11,9 @@ import {
DEFAULT_BROWSER_SCREENSHOT_TIMEOUT_MS,
} from "./constants.js";
export type { BrowserActRequest, BrowserFormField } from "./client-actions.types.js";
export type { BrowserFormField } from "./client-actions.types.js";
export type BrowserActResponse = {
type BrowserActResponse = {
ok: true;
targetId: string;
url?: string;

View File

@@ -8,12 +8,7 @@ import type {
} from "./client.types.js";
import type { BrowserDoctorReport } from "./doctor.js";
export type {
BrowserStatus,
BrowserTab,
BrowserTransport,
SnapshotAriaNode,
} from "./client.types.js";
export type { BrowserStatus, BrowserTab, BrowserTransport } from "./client.types.js";
export type { BrowserDoctorCheck, BrowserDoctorReport } from "./doctor.js";
export type ProfileStatus = {

View File

@@ -1,5 +1,5 @@
export type BrowserTransport = "cdp" | "chrome-mcp";
export type BrowserHeadlessSource =
type BrowserHeadlessSource =
| "request"
| "env"
| "profile"

View File

@@ -1,6 +1,6 @@
import type { BrowserStatus, BrowserTransport } from "./client.types.js";
export type BrowserDoctorCheckStatus = "pass" | "warn" | "fail" | "info";
type BrowserDoctorCheckStatus = "pass" | "warn" | "fail" | "info";
export type BrowserDoctorCheck = {
id: string;

View File

@@ -5,11 +5,11 @@ export const DEFAULT_FILL_FIELD_TYPE = "text";
type BrowserFormFieldValue = NonNullable<BrowserFormField["value"]>;
export function normalizeBrowserFormFieldRef(value: unknown): string {
function normalizeBrowserFormFieldRef(value: unknown): string {
return normalizeOptionalString(value) ?? "";
}
export function normalizeBrowserFormFieldType(value: unknown): string {
function normalizeBrowserFormFieldType(value: unknown): string {
const type = normalizeOptionalString(value) ?? "";
return type || DEFAULT_FILL_FIELD_TYPE;
}

View File

@@ -22,7 +22,7 @@ function canUseNodeFs(): boolean {
}
}
export const DEFAULT_BROWSER_TMP_DIR = canUseNodeFs()
const DEFAULT_BROWSER_TMP_DIR = canUseNodeFs()
? resolvePreferredOpenClawTmpDir()
: DEFAULT_FALLBACK_BROWSER_TMP_DIR;
export const DEFAULT_TRACE_DIR = DEFAULT_BROWSER_TMP_DIR;

View File

@@ -15,7 +15,7 @@
export const CDP_PORT_RANGE_START = 18800;
export const CDP_PORT_RANGE_END = 18899;
export const PROFILE_NAME_REGEX = /^[a-z0-9][a-z0-9-]*$/;
const PROFILE_NAME_REGEX = /^[a-z0-9][a-z0-9-]*$/;
export function isValidProfileName(name: string): boolean {
if (!name || name.length > 64) {

View File

@@ -1,6 +1,6 @@
import { saveMediaBuffer } from "../media/store.js";
export type BrowserProxyFile = {
type BrowserProxyFile = {
path: string;
base64: string;
mimeType?: string;

View File

@@ -1,7 +1,7 @@
import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/text-runtime";
import { CONTENT_ROLES, INTERACTIVE_ROLES, STRUCTURAL_ROLES } from "./snapshot-roles.js";
export type RoleRef = {
type RoleRef = {
role: string;
name?: string;
/** Index used only when role+name duplicates exist. */
@@ -10,7 +10,7 @@ export type RoleRef = {
export type RoleRefMap = Record<string, RoleRef>;
export type RoleSnapshotStats = {
type RoleSnapshotStats = {
lines: number;
chars: number;
refs: number;

View File

@@ -9,7 +9,7 @@ export const ACT_ERROR_CODES = {
targetIdMismatch: "ACT_TARGET_ID_MISMATCH",
} as const;
export type ActErrorCode = (typeof ACT_ERROR_CODES)[keyof typeof ACT_ERROR_CODES];
type ActErrorCode = (typeof ACT_ERROR_CODES)[keyof typeof ACT_ERROR_CODES];
export function jsonActError(
res: BrowserResponse,

View File

@@ -24,8 +24,8 @@ export function isActKind(value: unknown): value is ActKind {
return (ACT_KINDS as readonly string[]).includes(value);
}
export type ClickButton = "left" | "right" | "middle";
export type ClickModifier = "Alt" | "Control" | "ControlOrMeta" | "Meta" | "Shift";
type ClickButton = "left" | "right" | "middle";
type ClickModifier = "Alt" | "Control" | "ControlOrMeta" | "Meta" | "Shift";
const ALLOWED_CLICK_MODIFIERS = new Set<ClickModifier>([
"Alt",

View File

@@ -19,7 +19,7 @@ function normalizeOptionalString(value: unknown): string | undefined {
return readStringValue(value)?.trim() || undefined;
}
export type BrowserSnapshotPlan = {
type BrowserSnapshotPlan = {
format: "ai" | "aria";
mode?: "efficient";
labels?: boolean;

View File

@@ -4,8 +4,6 @@ import type { MockFn } from "../test-utils/vitest-mock-fn.js";
import { installChromeUserDataDirHooks } from "./chrome-user-data-dir.test-harness.js";
import { getFreePort } from "./test-port.js";
export { getFreePort } from "./test-port.js";
type HarnessState = {
testPort: number;
cdpBaseUrl: string;
@@ -49,7 +47,7 @@ export function getBrowserControlServerBaseUrl(): string {
return `http://127.0.0.1:${state.testPort}`;
}
export function restoreGatewayPortEnv(prevGatewayPort: string | undefined): void {
function restoreGatewayPortEnv(prevGatewayPort: string | undefined): void {
if (prevGatewayPort === undefined) {
delete process.env.OPENCLAW_GATEWAY_PORT;
return;
@@ -486,7 +484,7 @@ export async function startBrowserControlServerFromConfig() {
return await (await loadBrowserServerModule()).startBrowserControlServerFromConfig();
}
export async function stopBrowserControlServer(): Promise<void> {
async function stopBrowserControlServer(): Promise<void> {
await (await loadBrowserServerModule()).stopBrowserControlServer();
}
@@ -535,7 +533,7 @@ export async function resetBrowserControlServerTestContext(): Promise<void> {
delete process.env.OPENCLAW_GATEWAY_PASSWORD;
}
export function restoreGatewayAuthEnv(
function restoreGatewayAuthEnv(
prevGatewayToken: string | undefined,
prevGatewayPassword: string | undefined,
): void {

View File

@@ -21,7 +21,7 @@ export function isPrimaryTrackedBrowserSessionKey(sessionKey: string): boolean {
);
}
export function resolveBrowserTabCleanupRuntimeConfig(): ResolvedBrowserTabCleanupConfig {
function resolveBrowserTabCleanupRuntimeConfig(): ResolvedBrowserTabCleanupConfig {
const cfg = getRuntimeConfig();
return resolveBrowserConfig(cfg.browser, cfg).tabCleanup;
}

View File

@@ -4,7 +4,7 @@ import {
} from "openclaw/plugin-sdk/text-runtime";
import { browserCloseTab } from "./client.js";
export type TrackedSessionBrowserTab = {
type TrackedSessionBrowserTab = {
sessionKey: string;
targetId: string;
baseUrl?: string;

View File

@@ -1,6 +1,6 @@
import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/text-runtime";
export type TargetIdResolution =
type TargetIdResolution =
| { ok: true; targetId: string }
| { ok: false; reason: "not_found" | "ambiguous"; matches?: string[] };

View File

@@ -9,7 +9,7 @@ import {
type BrowserFormField,
} from "../core-api.js";
export type BrowserActionContext = {
type BrowserActionContext = {
parent: BrowserParentOpts;
profile: string | undefined;
};

View File

@@ -10,7 +10,7 @@ type BrowserRequest = {
};
type BrowserRuntimeOptions = { timeoutMs?: number };
export type BrowserManageCall = [unknown, BrowserRequest, BrowserRuntimeOptions | undefined];
type BrowserManageCall = [unknown, BrowserRequest, BrowserRuntimeOptions | undefined];
const browserManageMocks = vi.hoisted(() => ({
callBrowserRequest: vi.fn<

View File

@@ -22,8 +22,6 @@ export {
resolveUserPath,
shortenHomePath,
} from "openclaw/plugin-sdk/text-runtime";
export { normalizeOptionalLowercaseString };
type PortRange = { start: number; end: number };
const DEFAULT_BROWSER_CDP_PORT_RANGE_START = 18800;