feat(bsk): fix upload function that cannot bypass layout

This commit is contained in:
Ljy-0827
2026-08-31 17:58:33 +08:00
parent 995061514c
commit d5de9b0154
20 changed files with 1033 additions and 630 deletions
+8 -26
View File
@@ -1,11 +1,11 @@
// Upload orchestration: validate the session-scoped request, resolve its click
// target, then delegate the browser protocol transaction to file-chooser.ts.
// target, then delegate the browser protocol transaction to the file-input
// transaction module.
import type { CdpTarget } from "@/browser-driver/frame-graph";
import type { SessionManager } from "@/session-manager/manager";
import type { ClickParams, RpcError, UploadParams, UploadResult } from "@/transport/types";
import { uploadThroughFileChooser } from "./file-chooser";
import { handleClick, type InteractionDeps } from "./interaction";
import { uploadThroughActivatedFileInput } from "./file-input-transaction";
import { handleClick, type InteractionDeps, resolveBackendNode } from "./interaction";
import {
type CdpRunner,
enforceAgentWindow,
@@ -13,7 +13,6 @@ import {
lookupSession,
resolveTargetTab,
} from "./shared";
import { resolveSnapshotRef } from "./snapshot-ref";
const DEFAULT_TIMEOUT_MS = 120_000;
@@ -21,21 +20,6 @@ export interface UploadDeps extends InteractionDeps {
cdp: CdpRunner;
}
function chooserTarget(
params: UploadParams,
tabId: number,
manager: SessionManager,
): CdpTarget | RpcError {
const ctx = manager.get(params.session_id);
if (!ctx) return { code: "not_found", message: `session ${params.session_id} unknown` };
if (params.ref) {
const ref = resolveSnapshotRef(ctx, params.ref, tabId);
if (isRpcError(ref)) return ref;
return { tabId, ...(ref.cdpSessionId ? { sessionId: ref.cdpSessionId } : {}) };
}
return { tabId };
}
export async function handleUpload(
manager: SessionManager,
params: UploadParams,
@@ -47,8 +31,6 @@ export async function handleUpload(
if (isRpcError(target)) return target;
const denied = enforceAgentWindow(ctx, target, "upload");
if (denied) return denied;
if (!deps.cdp?.onEvent)
return { code: "unsupported", message: "CDP event subscription unavailable" };
if (
params.files.length === 0 ||
params.files.length > 20 ||
@@ -56,12 +38,12 @@ export async function handleUpload(
) {
return { code: "invalid_params", message: "upload requires daemon-staged files" };
}
const cdpTarget = chooserTarget(params, target.tabId, manager);
if (isRpcError(cdpTarget)) return cdpTarget;
const address = await resolveBackendNode(deps.cdp, ctx, target, params, "upload");
if (isRpcError(address)) return address;
const timeoutMs = params.timeout_ms ?? DEFAULT_TIMEOUT_MS;
const transaction = await uploadThroughFileChooser({
const transaction = await uploadThroughActivatedFileInput({
cdp: deps.cdp,
target: cdpTarget,
target: address.cdpTarget,
files: params.files.map((file) => file.staged_path as string),
timeoutMs,
signal: deps.signal,