@mu-agent/mu 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +236 -74
- package/dist/index.js +886 -192
- package/dist/mu.js +993 -273
- package/dist/types/ai/catalog.d.ts +0 -1
- package/dist/types/ai/providers/openai.d.ts +2 -0
- package/dist/types/ai/types.d.ts +50 -2
- package/dist/types/core/compaction.d.ts +9 -2
- package/dist/types/core/events.d.ts +7 -1
- package/dist/types/core/index.d.ts +3 -3
- package/dist/types/core/loop.d.ts +2 -1
- package/dist/types/core/messages.d.ts +4 -1
- package/dist/types/core/microcompaction.d.ts +3 -0
- package/dist/types/core/permission.d.ts +12 -0
- package/dist/types/core/profile.d.ts +8 -0
- package/dist/types/core/session.d.ts +1 -0
- package/dist/types/core/tools.d.ts +5 -0
- package/dist/types/index.d.ts +8 -4
- package/dist/types/profile-browser/actions/classify.d.ts +19 -0
- package/dist/types/profile-browser/actions/click.d.ts +48 -0
- package/dist/types/profile-browser/actions/dates.d.ts +11 -0
- package/dist/types/profile-browser/actions/files.d.ts +9 -0
- package/dist/types/profile-browser/actions/filetype.d.ts +8 -0
- package/dist/types/profile-browser/actions/input.d.ts +17 -0
- package/dist/types/profile-browser/actions/keyboard.d.ts +16 -0
- package/dist/types/profile-browser/actions/navigate.d.ts +11 -0
- package/dist/types/profile-browser/actions/page.d.ts +8 -0
- package/dist/types/profile-browser/actions/pointer.d.ts +39 -0
- package/dist/types/profile-browser/actions/scroll.d.ts +8 -0
- package/dist/types/profile-browser/actions/submission.d.ts +7 -0
- package/dist/types/profile-browser/actions/types.d.ts +38 -0
- package/dist/types/profile-browser/agent/dataflow.d.ts +18 -0
- package/dist/types/profile-browser/agent/handoff.d.ts +15 -0
- package/dist/types/profile-browser/agent/ledger.d.ts +4 -0
- package/dist/types/profile-browser/agent/notes.d.ts +6 -0
- package/dist/types/profile-browser/agent/permissions.d.ts +18 -0
- package/dist/types/profile-browser/agent/prompts.d.ts +4 -0
- package/dist/types/profile-browser/agent/state.d.ts +48 -0
- package/dist/types/profile-browser/browser/connect.d.ts +44 -0
- package/dist/types/profile-browser/browser/discover.d.ts +31 -0
- package/dist/types/profile-browser/browser/downloads.d.ts +24 -0
- package/dist/types/profile-browser/browser/frames.d.ts +34 -0
- package/dist/types/profile-browser/browser/launch.d.ts +42 -0
- package/dist/types/profile-browser/browser/manager.d.ts +135 -0
- package/dist/types/profile-browser/browser/tabs.d.ts +52 -0
- package/dist/types/profile-browser/cdp/connection.d.ts +53 -0
- package/dist/types/profile-browser/cdp/session.d.ts +23 -0
- package/dist/types/profile-browser/cdp/types.d.ts +10 -0
- package/dist/types/profile-browser/commands.d.ts +5 -0
- package/dist/types/profile-browser/config.d.ts +73 -0
- package/dist/types/profile-browser/evals/live.d.ts +64 -0
- package/dist/types/profile-browser/index.d.ts +21 -0
- package/dist/types/profile-browser/page/capture-script.d.ts +1 -0
- package/dist/types/profile-browser/page/injection.d.ts +2 -0
- package/dist/types/profile-browser/page/model.d.ts +67 -0
- package/dist/types/profile-browser/page/network.d.ts +12 -0
- package/dist/types/profile-browser/page/observe.d.ts +39 -0
- package/dist/types/profile-browser/page/refs.d.ts +38 -0
- package/dist/types/profile-browser/page/render.d.ts +27 -0
- package/dist/types/profile-browser/page/resolve.d.ts +15 -0
- package/dist/types/profile-browser/page/screenshot.d.ts +25 -0
- package/dist/types/profile-browser/page/secrets.d.ts +7 -0
- package/dist/types/profile-browser/page/settle.d.ts +13 -0
- package/dist/types/profile-browser/page/snapshot.d.ts +9 -0
- package/dist/types/profile-browser/page/text.d.ts +22 -0
- package/dist/types/profile-browser/testing/agent-scenarios.d.ts +27 -0
- package/dist/types/profile-browser/testing/bench.d.ts +19 -0
- package/dist/types/profile-browser/testing/chrome.d.ts +12 -0
- package/dist/types/profile-browser/testing/fixture-site.d.ts +14 -0
- package/dist/types/profile-browser/testing/pdf.d.ts +1 -0
- package/dist/types/profile-browser/testing/wait.d.ts +1 -0
- package/dist/types/profile-browser/tools/delegate.d.ts +23 -0
- package/dist/types/profile-browser/tools/files.d.ts +3 -0
- package/dist/types/profile-browser/tools/gate.d.ts +8 -0
- package/dist/types/profile-browser/tools/interact.d.ts +86 -0
- package/dist/types/profile-browser/tools/navigate.d.ts +5 -0
- package/dist/types/profile-browser/tools/observe.d.ts +18 -0
- package/dist/types/profile-browser/tools/shared.d.ts +23 -0
- package/dist/types/profile-browser/tools/tabs.d.ts +8 -0
- package/dist/types/profile-coding/index.d.ts +3 -3
- package/dist/types/profile-coding/prompts.d.ts +1 -1
- package/dist/types/sdk/agent.d.ts +5 -0
- package/dist/types/sdk/index.d.ts +3 -1
- package/dist/types/sdk/recall.d.ts +3 -0
- package/dist/types/sdk/subagents.d.ts +2 -1
- package/dist/types/{profile-coding/tools → sdk}/todo.d.ts +2 -2
- package/dist/types/sdk/web-search.d.ts +8 -0
- package/package.json +2 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { PermissionMode, PermissionRule } from "../../core/index.js";
|
|
2
|
+
export declare const SCOPES: {
|
|
3
|
+
readonly observe: "browser:observe";
|
|
4
|
+
readonly navigate: "browser:navigate";
|
|
5
|
+
readonly interact: "browser:interact";
|
|
6
|
+
readonly commit: "browser:commit";
|
|
7
|
+
readonly secret: "browser:secret";
|
|
8
|
+
readonly upload: "browser:upload";
|
|
9
|
+
readonly script: "browser:script";
|
|
10
|
+
readonly delegate: "browser:delegate";
|
|
11
|
+
readonly share: "browser:share";
|
|
12
|
+
};
|
|
13
|
+
export declare const BROWSER_PERMISSION_DEFAULTS: PermissionRule[];
|
|
14
|
+
export declare function hostRules(allowedHosts: string[], blockedHosts: string[]): PermissionRule[];
|
|
15
|
+
export declare function browserPermissionModes(hosts?: PermissionRule[]): PermissionMode[];
|
|
16
|
+
export declare function rememberedPermissionsPath(home: string): string;
|
|
17
|
+
export declare function loadRememberedPermissions(home: string, onWarning?: (message: string) => void): PermissionRule[];
|
|
18
|
+
export declare function rememberAllow(home: string, permission: string, pattern: string): PermissionRule[];
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { PromptSection } from "../../ai/index.js";
|
|
2
|
+
export declare function browserPrompt(modelRef: string): PromptSection[];
|
|
3
|
+
export declare const BROWSER_TASK_PROMPT = "You are a browser sub-task, running alongside others for the main agent in a browser window of your own.\n- Your first browser action opens your window. You see and use only the tabs you open (and popups from them); other tabs belong to the main agent or other sub-tasks.\n- The brief is all you know about the task; the rules above still apply. Only take consequential actions the brief explicitly authorizes (the user still approves each one), and stop where the brief says to stop.\n- Keep the progress file the brief names (under progress/) up to date as you finish steps; never edit another sub-task's file.\n- Anything only the user can do (sign in, a CAPTCHA, an answer your files do not give) is a blocker: stop and report exactly what is needed.\n- Before finishing, close the tabs you no longer need. Leave open only a tab the user should review (for example a filled form waiting for their submit) and name it in your report.\n- Report the outcome, what was submitted and the confirmation the page showed, what is left and why, and any tab left open.";
|
|
4
|
+
export declare const BROWSER_SIDE_BOUNDARY = "This is a side conversation about the browser session. Do not operate the browser, submit forms or change pages unless the user deliberately changes the side conversation's permission mode.";
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type AgentMessage } from "../../core/index.js";
|
|
2
|
+
import type { CommitStrength } from "../actions/classify.js";
|
|
3
|
+
export interface NoteEntry {
|
|
4
|
+
key: string;
|
|
5
|
+
text: string;
|
|
6
|
+
}
|
|
7
|
+
export interface CommitRecord {
|
|
8
|
+
id: string;
|
|
9
|
+
at: number;
|
|
10
|
+
host: string;
|
|
11
|
+
url: string;
|
|
12
|
+
action: string;
|
|
13
|
+
target: string;
|
|
14
|
+
valuesDigest?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface CommitDetails extends CommitRecord {
|
|
17
|
+
name?: string;
|
|
18
|
+
sends?: string[];
|
|
19
|
+
strength: CommitStrength;
|
|
20
|
+
}
|
|
21
|
+
export declare const STATE_TYPE = "browser-state";
|
|
22
|
+
export declare const DEFAULT_NOTE_KEY = "notes";
|
|
23
|
+
export declare class NotesStore {
|
|
24
|
+
private readonly notes;
|
|
25
|
+
entries(): NoteEntry[];
|
|
26
|
+
get(key: string): string | undefined;
|
|
27
|
+
append(key: string, text: string): void;
|
|
28
|
+
replace(key: string, text: string): void;
|
|
29
|
+
clear(key?: string): void;
|
|
30
|
+
load(entries: NoteEntry[]): void;
|
|
31
|
+
}
|
|
32
|
+
export declare class CommitLedger {
|
|
33
|
+
private list;
|
|
34
|
+
records(): CommitRecord[];
|
|
35
|
+
append(record: CommitRecord): void;
|
|
36
|
+
load(records: CommitRecord[]): void;
|
|
37
|
+
}
|
|
38
|
+
export declare function formatNotes(entries: NoteEntry[]): string;
|
|
39
|
+
export declare function formatLedger(records: CommitRecord[]): string;
|
|
40
|
+
export declare class BrowserState {
|
|
41
|
+
readonly ledger: CommitLedger;
|
|
42
|
+
readonly notes: NotesStore;
|
|
43
|
+
sessionId: string | undefined;
|
|
44
|
+
constructor(ledger?: CommitLedger);
|
|
45
|
+
rebuild(messages: AgentMessage[]): void;
|
|
46
|
+
private snapshotText;
|
|
47
|
+
snapshotIfChanged(messages: AgentMessage[]): AgentMessage[];
|
|
48
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type CdpConnection } from "../cdp/connection.js";
|
|
2
|
+
import { type DiscoveredBrowser } from "./discover.js";
|
|
3
|
+
import { type BrowserEndpoint, type LaunchOptions, type Size } from "./launch.js";
|
|
4
|
+
export interface BrowserLauncher {
|
|
5
|
+
discover(prefs: {
|
|
6
|
+
executable?: string | undefined;
|
|
7
|
+
channel?: string | undefined;
|
|
8
|
+
}): Promise<DiscoveredBrowser>;
|
|
9
|
+
launch(options: LaunchOptions): Promise<BrowserEndpoint>;
|
|
10
|
+
}
|
|
11
|
+
export declare const defaultLauncher: BrowserLauncher;
|
|
12
|
+
interface Signals {
|
|
13
|
+
signal?: AbortSignal | undefined;
|
|
14
|
+
timeoutMs?: number | undefined;
|
|
15
|
+
}
|
|
16
|
+
export declare function endpointAlive(wsUrl: string, options?: Signals): Promise<boolean>;
|
|
17
|
+
export declare function resolveCdpUrl(endpoint: string, options?: Signals): Promise<string>;
|
|
18
|
+
export declare function profileLocked(userDataDir: string): boolean;
|
|
19
|
+
export interface ManagedConnectOptions {
|
|
20
|
+
userDataDir: string;
|
|
21
|
+
headless: boolean;
|
|
22
|
+
viewport: Size;
|
|
23
|
+
executable?: string | undefined;
|
|
24
|
+
channel?: string | undefined;
|
|
25
|
+
args?: string[] | undefined;
|
|
26
|
+
url?: string | undefined;
|
|
27
|
+
launcher?: BrowserLauncher | undefined;
|
|
28
|
+
signal?: AbortSignal | undefined;
|
|
29
|
+
}
|
|
30
|
+
export interface ConnectedBrowser {
|
|
31
|
+
connection: CdpConnection;
|
|
32
|
+
endpoint: BrowserEndpoint;
|
|
33
|
+
browser?: DiscoveredBrowser;
|
|
34
|
+
}
|
|
35
|
+
export declare function connectManaged(options: ManagedConnectOptions): Promise<ConnectedBrowser>;
|
|
36
|
+
export declare function connectToEndpoint(endpoint: string, options?: Signals): Promise<ConnectedBrowser>;
|
|
37
|
+
export interface ManagedState {
|
|
38
|
+
running: boolean;
|
|
39
|
+
endpoint?: string;
|
|
40
|
+
locked: boolean;
|
|
41
|
+
}
|
|
42
|
+
export declare function managedState(userDataDir: string): Promise<ManagedState>;
|
|
43
|
+
export declare function closeManaged(userDataDir: string): Promise<boolean>;
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export type BrowserChannel = "chrome" | "chromium" | "brave" | "edge";
|
|
2
|
+
export declare const BROWSER_CHANNELS: BrowserChannel[];
|
|
3
|
+
export interface BrowserCandidate {
|
|
4
|
+
channel: BrowserChannel;
|
|
5
|
+
path: string;
|
|
6
|
+
}
|
|
7
|
+
export interface DiscoveredBrowser {
|
|
8
|
+
path: string;
|
|
9
|
+
channel: BrowserChannel | "custom";
|
|
10
|
+
product: string;
|
|
11
|
+
version: string;
|
|
12
|
+
}
|
|
13
|
+
export interface DiscoverDeps {
|
|
14
|
+
platform: NodeJS.Platform;
|
|
15
|
+
env: Record<string, string | undefined>;
|
|
16
|
+
home: string;
|
|
17
|
+
exists: (path: string) => boolean;
|
|
18
|
+
which: (command: string) => string | null;
|
|
19
|
+
probeVersion: (path: string) => Promise<string | undefined>;
|
|
20
|
+
}
|
|
21
|
+
export declare function knownPaths(platform: NodeJS.Platform, env: Record<string, string | undefined>, home: string): BrowserCandidate[];
|
|
22
|
+
export declare function parseVersionOutput(output: string): {
|
|
23
|
+
product: string;
|
|
24
|
+
version: string;
|
|
25
|
+
};
|
|
26
|
+
export declare function defaultDiscoverDeps(): DiscoverDeps;
|
|
27
|
+
export declare function findCandidates(channel: BrowserChannel | undefined, deps: DiscoverDeps): BrowserCandidate[];
|
|
28
|
+
export declare function discoverBrowser(prefs?: {
|
|
29
|
+
executable?: string | undefined;
|
|
30
|
+
channel?: string | undefined;
|
|
31
|
+
}, deps?: DiscoverDeps): Promise<DiscoveredBrowser>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { CdpConnection } from "../cdp/connection.js";
|
|
2
|
+
export interface DownloadRecord {
|
|
3
|
+
guid: string;
|
|
4
|
+
url: string;
|
|
5
|
+
filename: string;
|
|
6
|
+
path: string;
|
|
7
|
+
state: "in progress" | "completed" | "canceled";
|
|
8
|
+
receivedBytes: number;
|
|
9
|
+
totalBytes: number;
|
|
10
|
+
startedAt: number;
|
|
11
|
+
}
|
|
12
|
+
export declare class DownloadTracker {
|
|
13
|
+
readonly directory: string;
|
|
14
|
+
private readonly records;
|
|
15
|
+
private readonly listeners;
|
|
16
|
+
constructor(directory: string);
|
|
17
|
+
attach(connection: CdpConnection, signal?: AbortSignal): Promise<void>;
|
|
18
|
+
private notify;
|
|
19
|
+
list(): DownloadRecord[];
|
|
20
|
+
since(time: number): DownloadRecord[];
|
|
21
|
+
waitForStart(time: number, capMs: number, signal?: AbortSignal): Promise<void>;
|
|
22
|
+
waitForFinished(time: number, capMs: number, signal?: AbortSignal): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
export declare function formatDownloads(records: DownloadRecord[]): string;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { CdpConnection } from "../cdp/connection.js";
|
|
2
|
+
import { CdpSession } from "../cdp/session.js";
|
|
3
|
+
export interface FrameInfo {
|
|
4
|
+
frameId: string;
|
|
5
|
+
parentId?: string | undefined;
|
|
6
|
+
url: string;
|
|
7
|
+
loaderId?: string | undefined;
|
|
8
|
+
session: CdpSession;
|
|
9
|
+
}
|
|
10
|
+
export declare class FrameRegistry {
|
|
11
|
+
private readonly connection;
|
|
12
|
+
readonly root: CdpSession;
|
|
13
|
+
private readonly frames;
|
|
14
|
+
private readonly children;
|
|
15
|
+
private readonly offs;
|
|
16
|
+
private readonly worlds;
|
|
17
|
+
private readonly sessionHooks;
|
|
18
|
+
private readonly hookOffs;
|
|
19
|
+
constructor(connection: CdpConnection, root: CdpSession);
|
|
20
|
+
get mainFrameId(): string | undefined;
|
|
21
|
+
list(): FrameInfo[];
|
|
22
|
+
get(frameId: string): FrameInfo | undefined;
|
|
23
|
+
childSessions(): CdpSession[];
|
|
24
|
+
onSession(hook: (session: CdpSession) => () => void): void;
|
|
25
|
+
private runHook;
|
|
26
|
+
start(signal?: AbortSignal): Promise<void>;
|
|
27
|
+
isolatedWorld(frameId: string, signal?: AbortSignal): Promise<number>;
|
|
28
|
+
forgetWorlds(frameId?: string): void;
|
|
29
|
+
dispose(): void;
|
|
30
|
+
private record;
|
|
31
|
+
private watchSession;
|
|
32
|
+
private removeFrame;
|
|
33
|
+
private adoptChild;
|
|
34
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export interface Size {
|
|
2
|
+
width: number;
|
|
3
|
+
height: number;
|
|
4
|
+
}
|
|
5
|
+
export interface BrowserEndpoint {
|
|
6
|
+
wsUrl: string;
|
|
7
|
+
launched: boolean;
|
|
8
|
+
pid?: number;
|
|
9
|
+
}
|
|
10
|
+
export interface LaunchOptions {
|
|
11
|
+
path: string;
|
|
12
|
+
userDataDir: string;
|
|
13
|
+
headless: boolean;
|
|
14
|
+
viewport: Size;
|
|
15
|
+
args?: string[] | undefined;
|
|
16
|
+
url?: string | undefined;
|
|
17
|
+
signal?: AbortSignal | undefined;
|
|
18
|
+
timeoutMs?: number | undefined;
|
|
19
|
+
}
|
|
20
|
+
export declare const LAUNCH_LOG = "mu-browser.log";
|
|
21
|
+
export declare function managedArgs(options: {
|
|
22
|
+
userDataDir: string;
|
|
23
|
+
headless: boolean;
|
|
24
|
+
viewport: Size;
|
|
25
|
+
args?: string[] | undefined;
|
|
26
|
+
}): string[];
|
|
27
|
+
export declare function ensureProfileDir(userDataDir: string): void;
|
|
28
|
+
export declare function parseDevToolsActivePort(content: string): string | undefined;
|
|
29
|
+
export declare function readDevToolsActivePort(userDataDir: string): string | undefined;
|
|
30
|
+
export declare function launchBrowser(options: LaunchOptions): Promise<BrowserEndpoint>;
|
|
31
|
+
export declare function killBrowserProcess(pid: number | undefined): void;
|
|
32
|
+
export interface SignInBrowser {
|
|
33
|
+
pid: number | undefined;
|
|
34
|
+
exited: Promise<number | null>;
|
|
35
|
+
close: () => Promise<void>;
|
|
36
|
+
}
|
|
37
|
+
export declare function launchForSignIn(options: {
|
|
38
|
+
path: string;
|
|
39
|
+
userDataDir: string;
|
|
40
|
+
url: string;
|
|
41
|
+
args?: string[] | undefined;
|
|
42
|
+
}): SignInBrowser;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { DataFlowGuard } from "../agent/dataflow.js";
|
|
2
|
+
import { type CdpConnection } from "../cdp/connection.js";
|
|
3
|
+
import { SecretRegistry } from "../page/secrets.js";
|
|
4
|
+
import { type BrowserLauncher, type ConnectedBrowser } from "./connect.js";
|
|
5
|
+
import { DownloadTracker } from "./downloads.js";
|
|
6
|
+
import type { Size } from "./launch.js";
|
|
7
|
+
import { Tab, type TabInfo } from "./tabs.js";
|
|
8
|
+
export interface BrowserManagerOptions {
|
|
9
|
+
connect: "managed" | "cdp";
|
|
10
|
+
profileName: string;
|
|
11
|
+
userDataDir: string;
|
|
12
|
+
cdpUrl?: string | undefined;
|
|
13
|
+
executable?: string | undefined;
|
|
14
|
+
channel?: string | undefined;
|
|
15
|
+
headless: boolean;
|
|
16
|
+
viewport: Size;
|
|
17
|
+
args?: string[] | undefined;
|
|
18
|
+
keepOpen: boolean;
|
|
19
|
+
launcher?: BrowserLauncher | undefined;
|
|
20
|
+
downloadsDir?: string | undefined;
|
|
21
|
+
}
|
|
22
|
+
export interface BrowserStatus {
|
|
23
|
+
mode: "managed" | "cdp";
|
|
24
|
+
profile: string;
|
|
25
|
+
userDataDir?: string;
|
|
26
|
+
endpoint?: string;
|
|
27
|
+
connected: boolean;
|
|
28
|
+
launched: boolean;
|
|
29
|
+
pid?: number;
|
|
30
|
+
product?: string;
|
|
31
|
+
version?: string;
|
|
32
|
+
executable?: string;
|
|
33
|
+
headless: boolean;
|
|
34
|
+
tabs: number;
|
|
35
|
+
activeTab?: TabInfo;
|
|
36
|
+
}
|
|
37
|
+
interface PageTarget {
|
|
38
|
+
targetId: string;
|
|
39
|
+
tabId: string;
|
|
40
|
+
url: string;
|
|
41
|
+
title: string;
|
|
42
|
+
openerId?: string | undefined;
|
|
43
|
+
openedByAgent: boolean;
|
|
44
|
+
createdAt: number;
|
|
45
|
+
lastUsed: number;
|
|
46
|
+
owner: string;
|
|
47
|
+
leftBy?: string | undefined;
|
|
48
|
+
}
|
|
49
|
+
export declare const MAX_LANES = 3;
|
|
50
|
+
declare class SharedBrowser {
|
|
51
|
+
connected: ConnectedBrowser | undefined;
|
|
52
|
+
connecting: Promise<ConnectedBrowser> | undefined;
|
|
53
|
+
readonly pages: Map<string, PageTarget>;
|
|
54
|
+
readonly attached: Map<string, Tab>;
|
|
55
|
+
readonly attaching: Map<string, Promise<Tab>>;
|
|
56
|
+
readonly tabIds: Map<string, string>;
|
|
57
|
+
nextTab: number;
|
|
58
|
+
nextLane: number;
|
|
59
|
+
closingIntentionally: boolean;
|
|
60
|
+
product: {
|
|
61
|
+
product: string;
|
|
62
|
+
version: string;
|
|
63
|
+
executable?: string;
|
|
64
|
+
} | undefined;
|
|
65
|
+
abort: AbortController;
|
|
66
|
+
readonly lanes: Set<BrowserManager>;
|
|
67
|
+
readonly waiting: Set<() => void>;
|
|
68
|
+
readonly downloads: DownloadTracker;
|
|
69
|
+
readonly secrets: SecretRegistry;
|
|
70
|
+
readonly dataflow: DataFlowGuard;
|
|
71
|
+
constructor(downloadsDir: string | undefined);
|
|
72
|
+
}
|
|
73
|
+
export declare class BrowserManager {
|
|
74
|
+
readonly options: BrowserManagerOptions;
|
|
75
|
+
private readonly shared;
|
|
76
|
+
readonly laneId: string;
|
|
77
|
+
readonly label: string | undefined;
|
|
78
|
+
private activeTargetId;
|
|
79
|
+
private notices;
|
|
80
|
+
withoutScreenshot: number;
|
|
81
|
+
switchStreak: number;
|
|
82
|
+
approvedRetry: {
|
|
83
|
+
key: string;
|
|
84
|
+
url: string;
|
|
85
|
+
remaining: number;
|
|
86
|
+
} | undefined;
|
|
87
|
+
private slots;
|
|
88
|
+
constructor(options: BrowserManagerOptions, shared?: SharedBrowser, lane?: {
|
|
89
|
+
id: string;
|
|
90
|
+
label: string;
|
|
91
|
+
});
|
|
92
|
+
get downloads(): DownloadTracker;
|
|
93
|
+
get secrets(): SecretRegistry;
|
|
94
|
+
get dataflow(): DataFlowGuard;
|
|
95
|
+
private get pages();
|
|
96
|
+
private get attached();
|
|
97
|
+
get isConnected(): boolean;
|
|
98
|
+
get connection(): CdpConnection | undefined;
|
|
99
|
+
actionSignal(signal?: AbortSignal): AbortSignal;
|
|
100
|
+
stop(): void;
|
|
101
|
+
drainNotices(): string[];
|
|
102
|
+
ensureConnected(signal?: AbortSignal): Promise<CdpConnection>;
|
|
103
|
+
private connect;
|
|
104
|
+
private requireCdpUrl;
|
|
105
|
+
private onDisconnect;
|
|
106
|
+
private tabIdFor;
|
|
107
|
+
private trackTarget;
|
|
108
|
+
observationSlot(tabId: string): number;
|
|
109
|
+
private forgetTarget;
|
|
110
|
+
private targetGone;
|
|
111
|
+
currentTab(): Tab | undefined;
|
|
112
|
+
private own;
|
|
113
|
+
private info;
|
|
114
|
+
tabs(): TabInfo[];
|
|
115
|
+
openedSince(since: number, openerTargetIds: string[]): TabInfo[];
|
|
116
|
+
private attach;
|
|
117
|
+
activeTab(signal?: AbortSignal): Promise<Tab>;
|
|
118
|
+
ensureForeground(tab: Tab, signal?: AbortSignal): Promise<void>;
|
|
119
|
+
private recoverCrashed;
|
|
120
|
+
private closeStaleAgentTab;
|
|
121
|
+
private touch;
|
|
122
|
+
openTab(url?: string, signal?: AbortSignal): Promise<Tab>;
|
|
123
|
+
private targetFor;
|
|
124
|
+
switchTab(tabId: string, signal?: AbortSignal): Promise<Tab>;
|
|
125
|
+
closeTab(tabId: string, signal?: AbortSignal): Promise<void>;
|
|
126
|
+
openLane(label: string, signal: AbortSignal): Promise<BrowserManager>;
|
|
127
|
+
private laneFreed;
|
|
128
|
+
release(): Promise<void>;
|
|
129
|
+
status(): BrowserStatus;
|
|
130
|
+
shutdown(options?: {
|
|
131
|
+
close?: boolean;
|
|
132
|
+
}): Promise<void>;
|
|
133
|
+
}
|
|
134
|
+
export declare function isDisconnectError(error: unknown): boolean;
|
|
135
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { CdpConnection } from "../cdp/connection.js";
|
|
2
|
+
import { type CdpSession } from "../cdp/session.js";
|
|
3
|
+
import { NetworkTracker } from "../page/network.js";
|
|
4
|
+
import { RefTable } from "../page/refs.js";
|
|
5
|
+
import { FrameRegistry } from "./frames.js";
|
|
6
|
+
export interface TabInfo {
|
|
7
|
+
tabId: string;
|
|
8
|
+
url: string;
|
|
9
|
+
title: string;
|
|
10
|
+
active: boolean;
|
|
11
|
+
openedByAgent: boolean;
|
|
12
|
+
leftBy?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface JsDialog {
|
|
15
|
+
type: "alert" | "confirm" | "prompt" | "beforeunload";
|
|
16
|
+
message: string;
|
|
17
|
+
defaultPrompt?: string;
|
|
18
|
+
}
|
|
19
|
+
export declare class Tab {
|
|
20
|
+
readonly tabId: string;
|
|
21
|
+
readonly targetId: string;
|
|
22
|
+
readonly session: CdpSession;
|
|
23
|
+
readonly frames: FrameRegistry;
|
|
24
|
+
url: string;
|
|
25
|
+
title: string;
|
|
26
|
+
readonly openedByAgent: boolean;
|
|
27
|
+
dialog: JsDialog | undefined;
|
|
28
|
+
crashed: boolean;
|
|
29
|
+
readonly refs: RefTable;
|
|
30
|
+
readonly links: Set<string>;
|
|
31
|
+
readonly network: NetworkTracker;
|
|
32
|
+
previous: {
|
|
33
|
+
documentId: string;
|
|
34
|
+
refs: Set<string>;
|
|
35
|
+
texts: Set<string>;
|
|
36
|
+
} | undefined;
|
|
37
|
+
lastFingerprint: string | undefined;
|
|
38
|
+
unchangedStreak: number;
|
|
39
|
+
private readonly offs;
|
|
40
|
+
private constructor();
|
|
41
|
+
static attach(connection: CdpConnection, target: {
|
|
42
|
+
targetId: string;
|
|
43
|
+
url: string;
|
|
44
|
+
title: string;
|
|
45
|
+
}, tabId: string, openedByAgent: boolean, signal?: AbortSignal, emulateViewport?: {
|
|
46
|
+
width: number;
|
|
47
|
+
height: number;
|
|
48
|
+
}): Promise<Tab>;
|
|
49
|
+
get detached(): boolean;
|
|
50
|
+
info(active: boolean): TabInfo;
|
|
51
|
+
dispose(): void;
|
|
52
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { CommandName, CommandParams, CommandResult, EventName, EventParams, SendOptions } from "./types.js";
|
|
2
|
+
export declare const DEFAULT_CDP_TIMEOUT_MS = 10000;
|
|
3
|
+
export type CdpErrorKind = "stale-node" | "context-gone" | "target-closed" | "timeout" | "aborted" | "protocol";
|
|
4
|
+
export declare function classifyProtocolError(message: string): CdpErrorKind;
|
|
5
|
+
export declare class CdpError extends Error {
|
|
6
|
+
readonly kind: CdpErrorKind;
|
|
7
|
+
readonly method: string;
|
|
8
|
+
readonly code: number;
|
|
9
|
+
constructor(kind: CdpErrorKind, method: string, message: string, code?: number);
|
|
10
|
+
}
|
|
11
|
+
export declare function isCdpError(error: unknown, ...kinds: CdpErrorKind[]): error is CdpError;
|
|
12
|
+
export interface CdpTransport {
|
|
13
|
+
send(message: string): void;
|
|
14
|
+
close(): void;
|
|
15
|
+
onMessage(handler: (data: string) => void): void;
|
|
16
|
+
onClose(handler: (reason: string) => void): void;
|
|
17
|
+
}
|
|
18
|
+
export declare class CdpConnection {
|
|
19
|
+
private readonly transport;
|
|
20
|
+
private nextId;
|
|
21
|
+
private readonly pending;
|
|
22
|
+
private readonly listeners;
|
|
23
|
+
private readonly closeWatchers;
|
|
24
|
+
private closeReason;
|
|
25
|
+
private resolveClosed;
|
|
26
|
+
readonly closed: Promise<{
|
|
27
|
+
reason: string;
|
|
28
|
+
}>;
|
|
29
|
+
constructor(transport: CdpTransport);
|
|
30
|
+
get isClosed(): boolean;
|
|
31
|
+
send<M extends CommandName>(method: M, params?: CommandParams<M>, options?: SendOptions): Promise<CommandResult<M>>;
|
|
32
|
+
on<E extends EventName>(event: E, handler: (params: EventParams<E>, sessionId: string | undefined) => void, options?: {
|
|
33
|
+
sessionId?: string | undefined;
|
|
34
|
+
}): () => void;
|
|
35
|
+
waitFor<E extends EventName>(event: E, options?: {
|
|
36
|
+
sessionId?: string | undefined;
|
|
37
|
+
predicate?: (params: EventParams<E>) => boolean;
|
|
38
|
+
signal?: AbortSignal | undefined;
|
|
39
|
+
timeoutMs?: number | undefined;
|
|
40
|
+
}): Promise<EventParams<E>>;
|
|
41
|
+
close(): Promise<void>;
|
|
42
|
+
private receive;
|
|
43
|
+
private dropSession;
|
|
44
|
+
private shutdown;
|
|
45
|
+
}
|
|
46
|
+
export declare function openWebSocketTransport(url: string, options?: {
|
|
47
|
+
signal?: AbortSignal | undefined;
|
|
48
|
+
timeoutMs?: number | undefined;
|
|
49
|
+
}): Promise<CdpTransport>;
|
|
50
|
+
export declare function connectCdp(wsUrl: string, options?: {
|
|
51
|
+
signal?: AbortSignal | undefined;
|
|
52
|
+
timeoutMs?: number | undefined;
|
|
53
|
+
}): Promise<CdpConnection>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { CdpConnection } from "./connection.js";
|
|
2
|
+
import type { CommandName, CommandParams, CommandResult, EventName, EventParams, SendOptions } from "./types.js";
|
|
3
|
+
export declare class CdpSession {
|
|
4
|
+
readonly connection: CdpConnection;
|
|
5
|
+
readonly sessionId: string;
|
|
6
|
+
readonly targetId: string;
|
|
7
|
+
private detachedFlag;
|
|
8
|
+
private readonly offDetach;
|
|
9
|
+
constructor(connection: CdpConnection, sessionId: string, targetId: string);
|
|
10
|
+
get detached(): boolean;
|
|
11
|
+
send<M extends CommandName>(method: M, params?: CommandParams<M>, options?: Omit<SendOptions, "sessionId">): Promise<CommandResult<M>>;
|
|
12
|
+
on<E extends EventName>(event: E, handler: (params: EventParams<E>) => void): () => void;
|
|
13
|
+
waitFor<E extends EventName>(event: E, options?: {
|
|
14
|
+
predicate?: (params: EventParams<E>) => boolean;
|
|
15
|
+
signal?: AbortSignal | undefined;
|
|
16
|
+
timeoutMs?: number | undefined;
|
|
17
|
+
}): Promise<EventParams<E>>;
|
|
18
|
+
detach(): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
export declare function attachToTarget(connection: CdpConnection, targetId: string, options?: {
|
|
21
|
+
signal?: AbortSignal | undefined;
|
|
22
|
+
timeoutMs?: number | undefined;
|
|
23
|
+
}): Promise<CdpSession>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type CommandName = string;
|
|
2
|
+
export type EventName = string;
|
|
3
|
+
export type CommandParams<_M extends CommandName> = Record<string, unknown> | undefined;
|
|
4
|
+
export type CommandResult<_M extends CommandName> = any;
|
|
5
|
+
export type EventParams<_E extends EventName> = any;
|
|
6
|
+
export interface SendOptions {
|
|
7
|
+
sessionId?: string | undefined;
|
|
8
|
+
signal?: AbortSignal | undefined;
|
|
9
|
+
timeoutMs?: number | undefined;
|
|
10
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Command } from "../core/index.js";
|
|
2
|
+
import type { CommitLedger } from "./agent/state.js";
|
|
3
|
+
import type { BrowserManager } from "./browser/manager.js";
|
|
4
|
+
export declare function formatStatus(browser: BrowserManager, ledger: CommitLedger): string;
|
|
5
|
+
export declare function browserCommands(browser: BrowserManager, ledger: CommitLedger): Command[];
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { BrowserLauncher } from "./browser/connect.js";
|
|
3
|
+
import type { Size } from "./browser/launch.js";
|
|
4
|
+
export interface BrowserProfileOptions {
|
|
5
|
+
browserProfile?: string | undefined;
|
|
6
|
+
connect?: "managed" | "cdp" | undefined;
|
|
7
|
+
cdpUrl?: string | undefined;
|
|
8
|
+
executable?: string | undefined;
|
|
9
|
+
channel?: "chrome" | "chromium" | "brave" | "edge" | undefined;
|
|
10
|
+
headless?: boolean | undefined;
|
|
11
|
+
vision?: "auto" | "on" | "off" | undefined;
|
|
12
|
+
viewport?: Size | undefined;
|
|
13
|
+
keepOpen?: boolean | undefined;
|
|
14
|
+
downloadsDir?: string | undefined;
|
|
15
|
+
allowedHosts?: string[] | undefined;
|
|
16
|
+
blockedHosts?: string[] | undefined;
|
|
17
|
+
home?: string | undefined;
|
|
18
|
+
launcher?: BrowserLauncher | undefined;
|
|
19
|
+
workspace?: string | undefined;
|
|
20
|
+
codingCommand?: string[] | undefined;
|
|
21
|
+
}
|
|
22
|
+
export interface ResolvedBrowserOptions {
|
|
23
|
+
browserProfile: string;
|
|
24
|
+
connect: "managed" | "cdp";
|
|
25
|
+
cdpUrl?: string;
|
|
26
|
+
executable?: string;
|
|
27
|
+
channel?: "chrome" | "chromium" | "brave" | "edge";
|
|
28
|
+
headless: boolean;
|
|
29
|
+
vision: "auto" | "on" | "off";
|
|
30
|
+
viewport: Size;
|
|
31
|
+
keepOpen: boolean;
|
|
32
|
+
downloadsDir: string;
|
|
33
|
+
allowedHosts: string[];
|
|
34
|
+
blockedHosts: string[];
|
|
35
|
+
home: string;
|
|
36
|
+
userDataDir: string;
|
|
37
|
+
launcher?: BrowserLauncher;
|
|
38
|
+
workspace: string;
|
|
39
|
+
codingCommand: string[];
|
|
40
|
+
}
|
|
41
|
+
export declare const browserConfigSchema: z.ZodObject<{
|
|
42
|
+
browserProfile: z.ZodOptional<z.ZodString>;
|
|
43
|
+
connect: z.ZodOptional<z.ZodEnum<{
|
|
44
|
+
managed: "managed";
|
|
45
|
+
cdp: "cdp";
|
|
46
|
+
}>>;
|
|
47
|
+
cdpUrl: z.ZodOptional<z.ZodString>;
|
|
48
|
+
executable: z.ZodOptional<z.ZodString>;
|
|
49
|
+
channel: z.ZodOptional<z.ZodEnum<{
|
|
50
|
+
chrome: "chrome";
|
|
51
|
+
chromium: "chromium";
|
|
52
|
+
brave: "brave";
|
|
53
|
+
edge: "edge";
|
|
54
|
+
}>>;
|
|
55
|
+
headless: z.ZodOptional<z.ZodBoolean>;
|
|
56
|
+
vision: z.ZodOptional<z.ZodEnum<{
|
|
57
|
+
auto: "auto";
|
|
58
|
+
on: "on";
|
|
59
|
+
off: "off";
|
|
60
|
+
}>>;
|
|
61
|
+
viewport: z.ZodOptional<z.ZodObject<{
|
|
62
|
+
width: z.ZodNumber;
|
|
63
|
+
height: z.ZodNumber;
|
|
64
|
+
}, z.core.$strip>>;
|
|
65
|
+
keepOpen: z.ZodOptional<z.ZodBoolean>;
|
|
66
|
+
downloadsDir: z.ZodOptional<z.ZodString>;
|
|
67
|
+
allowedHosts: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
68
|
+
blockedHosts: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
69
|
+
workspace: z.ZodOptional<z.ZodString>;
|
|
70
|
+
codingCommand: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
71
|
+
}, z.core.$strict>;
|
|
72
|
+
export declare function readBrowserConfig(home: string, onWarning: (message: string) => void): z.infer<typeof browserConfigSchema>;
|
|
73
|
+
export declare function resolveBrowserOptions(options?: BrowserProfileOptions, onWarning?: (message: string) => void): ResolvedBrowserOptions;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { Credential, Provider } from "../../ai/index.js";
|
|
2
|
+
import { type AgentMessage, type PermissionRequest } from "../../core/index.js";
|
|
3
|
+
import { type BrowserProfile, browserProfile } from "../index.js";
|
|
4
|
+
import type { FixtureSite } from "../testing/fixture-site.js";
|
|
5
|
+
export type Mode = "default" | "autonomous";
|
|
6
|
+
export interface EvalContext {
|
|
7
|
+
site: FixtureSite;
|
|
8
|
+
selfEmail?: string | undefined;
|
|
9
|
+
tag?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface Judgement {
|
|
12
|
+
pass: boolean;
|
|
13
|
+
note: string;
|
|
14
|
+
}
|
|
15
|
+
export interface RunFacts {
|
|
16
|
+
text: string;
|
|
17
|
+
asks: PermissionRequest[];
|
|
18
|
+
messages: AgentMessage[];
|
|
19
|
+
profile: BrowserProfile;
|
|
20
|
+
}
|
|
21
|
+
export interface EvalTask {
|
|
22
|
+
id: number;
|
|
23
|
+
name: string;
|
|
24
|
+
modes: Mode[];
|
|
25
|
+
google?: boolean;
|
|
26
|
+
fresh?: boolean;
|
|
27
|
+
prompt: (ctx: EvalContext) => string;
|
|
28
|
+
files?: Record<string, string>;
|
|
29
|
+
approve?: (request: PermissionRequest) => "allow" | "deny";
|
|
30
|
+
check: (facts: RunFacts, ctx: EvalContext) => Promise<Judgement>;
|
|
31
|
+
}
|
|
32
|
+
export declare const TASKS: EvalTask[];
|
|
33
|
+
export interface RunMetrics {
|
|
34
|
+
task: number;
|
|
35
|
+
mode: Mode;
|
|
36
|
+
run: number;
|
|
37
|
+
pass: boolean;
|
|
38
|
+
note: string;
|
|
39
|
+
turns: number;
|
|
40
|
+
wallMs: number;
|
|
41
|
+
modelMs: number;
|
|
42
|
+
browserMs: number;
|
|
43
|
+
inputTokens: number;
|
|
44
|
+
outputTokens: number;
|
|
45
|
+
costUsd: number;
|
|
46
|
+
asks: string[];
|
|
47
|
+
askDetails?: string[];
|
|
48
|
+
answer?: string;
|
|
49
|
+
calls?: string[];
|
|
50
|
+
error?: string;
|
|
51
|
+
}
|
|
52
|
+
export declare function runTask(task: EvalTask, mode: Mode, run: number, options: {
|
|
53
|
+
ctx: EvalContext;
|
|
54
|
+
provider: Provider;
|
|
55
|
+
modelRef: string;
|
|
56
|
+
getCredentials: (provider: string) => Promise<Credential | undefined>;
|
|
57
|
+
profileOptions: Parameters<typeof browserProfile>[0];
|
|
58
|
+
maxTurns?: number;
|
|
59
|
+
}): Promise<RunMetrics>;
|
|
60
|
+
export declare function formatResults(runs: RunMetrics[], meta: {
|
|
61
|
+
model: string;
|
|
62
|
+
date: string;
|
|
63
|
+
skipped: string[];
|
|
64
|
+
}): string;
|