需求:在 AI 编程会话中让用户与 Agent 共享同一浏览器页面,并查看控制台与网络信息。 实现:新增沙箱浏览器内核、Host API/渲染器面板、OpenCode 工具接入及安全边界测试。
70 lines
2.2 KiB
TypeScript
70 lines
2.2 KiB
TypeScript
import type { BrowserWindow } from 'electron';
|
|
import type { OpencodeManager } from '../opencode/manager';
|
|
import type { OpencodeProjectStore } from '../opencode/project-store';
|
|
import type { HostEventBus } from './event-bus';
|
|
import type { createWorksCloudDeployment } from '../services/works-cloud-deployment';
|
|
import type { LocalImageWorkspace } from '../image-workspace/local-workspace';
|
|
import type {
|
|
AgentBrowserBounds,
|
|
AgentBrowserCdpEventPage,
|
|
AgentBrowserCdpResult,
|
|
AgentBrowserPayloadChunk,
|
|
AgentBrowserSnapshot,
|
|
} from '../../shared/agent-browser';
|
|
|
|
export type WorksCloudDeploymentCoordinator = ReturnType<typeof createWorksCloudDeployment>;
|
|
|
|
export interface AgentBrowserService {
|
|
getSnapshot(projectPath?: string): Promise<AgentBrowserSnapshot> | AgentBrowserSnapshot;
|
|
open(input: {
|
|
projectId: string;
|
|
projectPath: string;
|
|
url: string;
|
|
bounds?: AgentBrowserBounds;
|
|
visible?: boolean;
|
|
}): Promise<AgentBrowserSnapshot>;
|
|
present(input: {
|
|
projectPath: string;
|
|
visible: boolean;
|
|
bounds?: AgentBrowserBounds;
|
|
}): Promise<AgentBrowserSnapshot>;
|
|
navigate(input: {
|
|
projectPath: string;
|
|
action: 'url' | 'back' | 'forward' | 'reload';
|
|
url?: string;
|
|
}): Promise<AgentBrowserSnapshot>;
|
|
sendCdp(input: {
|
|
projectPath: string;
|
|
method: string;
|
|
params?: Record<string, unknown>;
|
|
sessionRef?: string;
|
|
timeoutMs?: number;
|
|
}): Promise<AgentBrowserCdpResult>;
|
|
readEvents(input: {
|
|
projectPath: string;
|
|
after?: number;
|
|
methods?: string[];
|
|
limit?: number;
|
|
waitMs?: number;
|
|
}): Promise<AgentBrowserCdpEventPage>;
|
|
readPayload(input: {
|
|
projectPath: string;
|
|
handle: string;
|
|
offset?: number;
|
|
maxBytes?: number;
|
|
}): Promise<AgentBrowserPayloadChunk>;
|
|
close(projectPath?: string): Promise<AgentBrowserSnapshot>;
|
|
resetProfile(projectPath: string): Promise<AgentBrowserSnapshot>;
|
|
dispose(): Promise<void>;
|
|
}
|
|
|
|
export interface HostApiContext {
|
|
opencodeManager: OpencodeManager;
|
|
opencodeProjectStore: OpencodeProjectStore;
|
|
eventBus: HostEventBus;
|
|
mainWindow: BrowserWindow | null;
|
|
agentBrowser?: AgentBrowserService;
|
|
worksCloudDeployment?: WorksCloudDeploymentCoordinator;
|
|
imageWorkspace?: LocalImageWorkspace;
|
|
}
|