需求:在 AI 编程会话中让用户与 Agent 共享同一浏览器页面,并查看控制台与网络信息。 实现:新增沙箱浏览器内核、Host API/渲染器面板、OpenCode 工具接入及安全边界测试。
53 lines
1.6 KiB
TypeScript
53 lines
1.6 KiB
TypeScript
import type { AgentBrowserBounds } from '../../shared/agent-browser';
|
|
|
|
export type PortListener = (...args: unknown[]) => void;
|
|
|
|
export interface AgentBrowserDebuggerPort {
|
|
attach(protocolVersion: string): void;
|
|
detach(): void;
|
|
isAttached(): boolean;
|
|
sendCommand(
|
|
method: string,
|
|
params?: Record<string, unknown>,
|
|
sessionRef?: string,
|
|
): Promise<unknown>;
|
|
on(event: 'message' | 'detach', listener: PortListener): void;
|
|
removeListener(event: 'message' | 'detach', listener: PortListener): void;
|
|
}
|
|
|
|
export interface AgentBrowserNavigationPort {
|
|
canGoBack(): boolean;
|
|
canGoForward(): boolean;
|
|
goBack(): void;
|
|
goForward(): void;
|
|
clear(): void;
|
|
}
|
|
|
|
export interface AgentBrowserWebContentsPort {
|
|
readonly debugger: AgentBrowserDebuggerPort;
|
|
readonly navigationHistory: AgentBrowserNavigationPort;
|
|
loadURL(url: string): Promise<void>;
|
|
getURL(): string;
|
|
getTitle(): string;
|
|
isDestroyed(): boolean;
|
|
isDevToolsOpened(): boolean;
|
|
reload(): void;
|
|
denyWindowOpen(): void;
|
|
on(event: string, listener: PortListener): void;
|
|
removeListener(event: string, listener: PortListener): void;
|
|
}
|
|
|
|
export interface AgentBrowserViewPort {
|
|
readonly webContents: AgentBrowserWebContentsPort;
|
|
setBounds(bounds: AgentBrowserBounds): void;
|
|
setVisible(visible: boolean): void;
|
|
}
|
|
|
|
export interface AgentBrowserAdapter {
|
|
createView(partition: string): AgentBrowserViewPort;
|
|
mount(view: AgentBrowserViewPort): void;
|
|
unmount(view: AgentBrowserViewPort): void;
|
|
destroy(view: AgentBrowserViewPort): void;
|
|
resetPartition(partition: string): Promise<void>;
|
|
}
|