merge: 集成共享 Agent Browser 调试能力
Some checks failed
Electron E2E / Electron E2E (macos-latest) (push) Has been cancelled
Electron E2E / Electron E2E (ubuntu-latest) (push) Has been cancelled
Electron E2E / Electron E2E (windows-latest) (push) Has been cancelled

需求:将 Agent Browser 独立功能提交合并到包含 AI 设计 Workspace 的最新主线。

实现:保留双方模块初始化、Host API 路由和 README 产品说明。

# Conflicts:
#	electron/api/context.ts
This commit is contained in:
2026-07-31 14:56:45 +08:00
39 changed files with 6734 additions and 9 deletions

107
shared/agent-browser.ts Normal file
View File

@@ -0,0 +1,107 @@
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';
}