mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 09:40:43 +00:00
refactor: trim browser helper exports
This commit is contained in:
@@ -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");
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export type BrowserTransport = "cdp" | "chrome-mcp";
|
||||
export type BrowserHeadlessSource =
|
||||
type BrowserHeadlessSource =
|
||||
| "request"
|
||||
| "env"
|
||||
| "profile"
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { saveMediaBuffer } from "../media/store.js";
|
||||
|
||||
export type BrowserProxyFile = {
|
||||
type BrowserProxyFile = {
|
||||
path: string;
|
||||
base64: string;
|
||||
mimeType?: string;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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[] };
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
type BrowserFormField,
|
||||
} from "../core-api.js";
|
||||
|
||||
export type BrowserActionContext = {
|
||||
type BrowserActionContext = {
|
||||
parent: BrowserParentOpts;
|
||||
profile: string | undefined;
|
||||
};
|
||||
|
||||
@@ -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<
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user