fix(agent-browser): restore bounded presentation lifecycle

This commit is contained in:
2026-09-06 12:50:18 +08:00
parent 5c61110f46
commit 9fed0cc7c4
20 changed files with 1714 additions and 49 deletions

View File

@@ -80,9 +80,9 @@ function requireSuccess<T extends { success: boolean; error?: string }>(
}
export async function getAgentBrowserState(
projectPath: string,
projectId: string,
): Promise<AgentBrowserSnapshot> {
const query = new URLSearchParams({ project_path: projectPath });
const query = new URLSearchParams({ project_id: projectId });
const response = await hostApiFetch<BrowserEnvelope>(
`/api/agent-browser/state?${query.toString()}`,
);
@@ -90,14 +90,14 @@ export async function getAgentBrowserState(
}
export async function openAgentBrowser(input: {
projectPath: string;
projectId: string;
url: string;
bounds?: AgentBrowserBounds;
}): Promise<AgentBrowserSnapshot> {
const response = await hostApiFetch<BrowserEnvelope>(
'/api/agent-browser/open',
jsonBody({
project_path: input.projectPath,
project_id: input.projectId,
url: input.url,
visible: true,
...(input.bounds ? { bounds: input.bounds } : {}),
@@ -107,14 +107,14 @@ export async function openAgentBrowser(input: {
}
export async function presentAgentBrowser(input: {
projectPath: string;
projectId: string;
visible: boolean;
bounds?: AgentBrowserBounds;
}): Promise<AgentBrowserSnapshot> {
const response = await hostApiFetch<BrowserEnvelope>(
'/api/agent-browser/present',
jsonBody({
project_path: input.projectPath,
project_id: input.projectId,
visible: input.visible,
...(input.bounds ? { bounds: input.bounds } : {}),
}),
@@ -123,13 +123,13 @@ export async function presentAgentBrowser(input: {
}
export async function setAgentBrowserDiagnostics(input: {
projectPath: string;
projectId: string;
enabled: boolean;
}): Promise<AgentBrowserSnapshot> {
const response = await hostApiFetch<BrowserEnvelope>(
'/api/agent-browser/diagnostics',
jsonBody({
project_path: input.projectPath,
project_id: input.projectId,
enabled: input.enabled,
}),
);
@@ -137,14 +137,14 @@ export async function setAgentBrowserDiagnostics(input: {
}
export async function navigateAgentBrowser(input: {
projectPath: string;
projectId: string;
action: AgentBrowserNavigateAction;
url?: string;
}): Promise<AgentBrowserSnapshot> {
const response = await hostApiFetch<BrowserEnvelope>(
'/api/agent-browser/navigate',
jsonBody({
project_path: input.projectPath,
project_id: input.projectId,
action: input.action,
...(input.url ? { url: input.url } : {}),
}),
@@ -153,7 +153,7 @@ export async function navigateAgentBrowser(input: {
}
export async function sendAgentBrowserCdp(input: {
projectPath: string;
projectId: string;
method: string;
params?: Record<string, unknown>;
sessionRef?: string;
@@ -162,7 +162,7 @@ export async function sendAgentBrowserCdp(input: {
const response = await hostApiFetch<CdpResultEnvelope>(
'/api/agent-browser/cdp/send',
jsonBody({
project_path: input.projectPath,
project_id: input.projectId,
method: input.method,
...(input.params ? { params: input.params } : {}),
...(input.sessionRef ? { session_ref: input.sessionRef } : {}),
@@ -173,7 +173,7 @@ export async function sendAgentBrowserCdp(input: {
}
export async function readAgentBrowserEvents(input: {
projectPath: string;
projectId: string;
after?: number;
methods?: string[];
limit?: number;
@@ -182,7 +182,7 @@ export async function readAgentBrowserEvents(input: {
const response = await hostApiFetch<EventPageEnvelope>(
'/api/agent-browser/cdp/events',
jsonBody({
project_path: input.projectPath,
project_id: input.projectId,
...(input.after !== undefined ? { after: input.after } : {}),
...(input.methods ? { methods: input.methods } : {}),
...(input.limit !== undefined ? { limit: input.limit } : {}),
@@ -193,7 +193,7 @@ export async function readAgentBrowserEvents(input: {
}
export async function readAgentBrowserPayload(input: {
projectPath: string;
projectId: string;
handle: string;
offset?: number;
maxBytes?: number;
@@ -201,7 +201,7 @@ export async function readAgentBrowserPayload(input: {
const response = await hostApiFetch<PayloadEnvelope>(
'/api/agent-browser/payload/read',
jsonBody({
project_path: input.projectPath,
project_id: input.projectId,
handle: input.handle,
...(input.offset !== undefined ? { offset: input.offset } : {}),
...(input.maxBytes !== undefined ? { max_bytes: input.maxBytes } : {}),
@@ -211,21 +211,21 @@ export async function readAgentBrowserPayload(input: {
}
export async function closeAgentBrowser(
projectPath: string,
projectId: string,
): Promise<AgentBrowserSnapshot> {
const response = await hostApiFetch<BrowserEnvelope>(
'/api/agent-browser/close',
jsonBody({ project_path: projectPath }),
jsonBody({ project_id: projectId }),
);
return requireSuccess(response).browser;
}
export async function resetAgentBrowserProfile(
projectPath: string,
projectId: string,
): Promise<AgentBrowserSnapshot> {
const response = await hostApiFetch<BrowserEnvelope>(
'/api/agent-browser/reset-profile',
jsonBody({ project_path: projectPath }),
jsonBody({ project_id: projectId }),
);
return requireSuccess(response).browser;
}