需求:在 AI 编程会话中让用户与 Agent 共享同一浏览器页面,并查看控制台与网络信息。 实现:新增沙箱浏览器内核、Host API/渲染器面板、OpenCode 工具接入及安全边界测试。
108 lines
2.2 KiB
TypeScript
108 lines
2.2 KiB
TypeScript
export type AgentBrowserState =
|
|
| 'closed'
|
|
| 'opening'
|
|
| 'attaching'
|
|
| 'attached'
|
|
| 'suspended_devtools'
|
|
| 'detached_fault'
|
|
| 'crashed'
|
|
| 'closing';
|
|
|
|
export interface AgentBrowserBounds {
|
|
x: number;
|
|
y: number;
|
|
width: number;
|
|
height: number;
|
|
}
|
|
|
|
export interface AgentBrowserPayloadRef {
|
|
kind: 'payload';
|
|
handle: string;
|
|
byteLength: number;
|
|
contentType: 'application/json' | 'text/plain' | 'application/octet-stream';
|
|
expiresAt: string;
|
|
}
|
|
|
|
export interface AgentBrowserSnapshot {
|
|
browserId: string | null;
|
|
projectId: string | null;
|
|
projectPath: string | null;
|
|
state: AgentBrowserState;
|
|
generation: number;
|
|
url: string;
|
|
title: string;
|
|
visible: boolean;
|
|
bounds: AgentBrowserBounds | null;
|
|
canGoBack: boolean;
|
|
canGoForward: boolean;
|
|
eventCursor: number;
|
|
error?: {
|
|
code: AgentBrowserErrorCode;
|
|
message: string;
|
|
};
|
|
}
|
|
|
|
export interface AgentBrowserCdpEvent {
|
|
sequence: number;
|
|
generation: number;
|
|
timestamp: number;
|
|
method: string;
|
|
params?: unknown;
|
|
payload?: AgentBrowserPayloadRef;
|
|
sessionRef?: string;
|
|
}
|
|
|
|
export interface AgentBrowserCdpEventPage {
|
|
events: AgentBrowserCdpEvent[];
|
|
nextCursor: number;
|
|
hasMore: boolean;
|
|
gap?: {
|
|
reason: 'evicted' | 'debugger-detached' | 'view-recreated';
|
|
oldestAvailable: number;
|
|
};
|
|
}
|
|
|
|
export type AgentBrowserCdpResult =
|
|
| { kind: 'inline'; value: unknown }
|
|
| AgentBrowserPayloadRef;
|
|
|
|
export interface AgentBrowserPayloadChunk {
|
|
handle: string;
|
|
offset: number;
|
|
nextOffset: number;
|
|
byteLength: number;
|
|
contentType: AgentBrowserPayloadRef['contentType'];
|
|
data: string;
|
|
encoding: 'utf8' | 'base64';
|
|
done: boolean;
|
|
}
|
|
|
|
export type AgentBrowserErrorCode =
|
|
| 'PROJECT_NOT_ACTIVE'
|
|
| 'PROJECT_MISMATCH'
|
|
| 'BROWSER_NOT_OPEN'
|
|
| 'VIEWPORT_NOT_READY'
|
|
| 'DEBUGGER_BUSY'
|
|
| 'ATTACH_FAILED'
|
|
| 'DEVTOOLS_CONFLICT'
|
|
| 'CDP_METHOD_BLOCKED'
|
|
| 'TARGET_DENIED'
|
|
| 'CDP_TIMEOUT'
|
|
| 'CDP_PROTOCOL_ERROR'
|
|
| 'CURSOR_EXPIRED'
|
|
| 'PAYLOAD_NOT_FOUND'
|
|
| 'PAYLOAD_TOO_LARGE'
|
|
| 'TARGET_GONE'
|
|
| 'RENDERER_CRASHED'
|
|
| 'INVALID_URL'
|
|
| 'INVALID_REQUEST'
|
|
| 'CLOSED';
|
|
|
|
export interface AgentBrowserFaultShape {
|
|
code: AgentBrowserErrorCode;
|
|
message: string;
|
|
retryable: boolean;
|
|
generation?: number;
|
|
outcome?: 'unknown';
|
|
}
|