Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
feat(browser): My browser uploads larger files by path through the extension's debugger
Dash746560fce8c9
diff --git a/apps/desktop/src/main/browser-extension/policy.ts b/apps/desktop/src/main/browser-extension/policy.tsindex f0f1662c69..db07e0afc9 100644--- a/apps/desktop/src/main/browser-extension/policy.ts+++ b/apps/desktop/src/main/browser-extension/policy.ts@@ -216,16 +216,30 @@ function validateParityPayload(action: string, payload: BrowserExtensionJobPayloif (action === 'dialog' && payload.promptText != null && !str(payload.promptText, 16000))throw new Error('Invalid promptText.');if (action === 'upload') {+ // Paths let Chrome read the files itself through the debugger (no size bound from the transfer);+ // bytes are the fallback when the debugger is not allowed. At least one, for the same files.const files = payload.files as Array<{ name?: unknown; data?: unknown; mimeType?: unknown }> | undefined;+ const paths = payload.paths as unknown[] | undefined;+ if (files == null && paths == null) throw new Error('upload needs files or paths.');if (- !Array.isArray(files) ||- !files.length ||- files.length > 20 ||- files.some((f) => !f || !str(f.name, 255) || !f.name || typeof f.data !== 'string' || (f.mimeType != null && !str(f.mimeType, 200)))+ files != null &&+ (!Array.isArray(files) ||+ !files.length ||+ files.length > 20 ||+ files.some((f) => !f || !str(f.name, 255) || !f.name || typeof f.data !== 'string' || (f.mimeType != null && !str(f.mimeType, 200)))))throw new Error('upload needs 1–20 files with name and base64 data.');- if (files.reduce((n, f) => n + (f.data as string).length, 0) > 40_000_000)+ if (files != null && files.reduce((n, f) => n + (f.data as string).length, 0) > 40_000_000)throw new Error('Upload files must total at most about 30 MB.');+ if (+ paths != null &&+ (!Array.isArray(paths) ||+ !paths.length ||+ paths.length > 20 ||+ paths.some((p) => !str(p, 4096) || !p || !(/^\//.test(p as string) || /^[A-Za-z]:[\\/]/.test(p as string))) ||+ (files != null && files.length !== paths.length))+ )+ throw new Error('upload paths must be 1–20 absolute file paths, one per file.');}if (action === 'cdp') {if (!['begin', 'end', 'events', 'command'].includes(payload.op as string))diff --git a/apps/desktop/src/main/mcp-integrations/browser-backend/__tests__/user-browser-backend.test.ts b/apps/desktop/src/main/mcp-integrations/browser-backend/__tests__/user-browser-backend.test.tsindex d7241c084d..8c8a5a29c2 100644--- a/apps/desktop/src/main/mcp-integrations/browser-backend/__tests__/user-browser-backend.test.ts+++ b/apps/desktop/src/main/mcp-integrations/browser-backend/__tests__/user-browser-backend.test.ts@@ -644,6 +644,18 @@ describe('UserBrowserBackend · 读取与动作', () => {await call(b, { action: 'upload', targetId: 't1', paths: [big], __mcpSessionId: 's1' }),).toMatchObject({ ok: false, message: expect.stringContaining('30 MB') });expect(fake.jobs.length).toBe(jobsBefore);+ // 2026-10-30: newer extensions also get the checked paths, so Chrome reads the files through the+ // debugger; the bytes go along only when they fit the transfer.+ const newer = fakeControl({ version: '0.4.56' });+ newer.responses.set('upload', () => ({ ok: true, files: [{ name: 'big.bin', size: 31_000_000 }] }));+ const nb = backend(newer.control, async () => [root]);+ await call(nb, { action: 'tabs' });+ expect(await call(nb, { action: 'upload', targetId: 't1', paths: [big], __mcpSessionId: 's1' })).toMatchObject({ ok: true });+ const bigJob = newer.jobs.at(-1)?.[1] as { paths?: string[]; files?: unknown };+ expect(bigJob.files).toBeUndefined();+ expect(bigJob.paths?.[0]).toMatch(/big\.bin$/);+ await call(nb, { action: 'upload', targetId: 't1', paths: [file], __mcpSessionId: 's1' });+ expect(newer.jobs.at(-1)?.[1]).toMatchObject({ files: [{ name: 'a.png', data: 'AQID' }], paths: [expect.stringMatching(/a\.png$/)] });expect(await call(b, {action: 'upload',diff --git a/apps/desktop/src/main/mcp-integrations/browser-backend/user-browser-backend.ts b/apps/desktop/src/main/mcp-integrations/browser-backend/user-browser-backend.tsindex 675c12ccb4..0f6afc8afa 100644--- a/apps/desktop/src/main/mcp-integrations/browser-backend/user-browser-backend.ts+++ b/apps/desktop/src/main/mcp-integrations/browser-backend/user-browser-backend.ts@@ -98,9 +98,16 @@ export const USER_BROWSER_PARITY_CAPABILITIES = Object.freeze({});export function extensionSupportsParity(version: string | null | undefined): boolean {+ return extensionAtLeast(version, USER_BROWSER_PARITY_VERSION);+}++/** Extensions from this version upload by path through Chrome's debugger, without the ~30 MB transfer bound. */+export const USER_BROWSER_PATH_UPLOAD_VERSION = '0.4.56';++function extensionAtLeast(version: string | null | undefined, wanted: string): boolean {const match = /^(\d+)\.(\d+)\.(\d+)$/.exec(version ?? '');if (!match) return false;- const want = USER_BROWSER_PARITY_VERSION.split('.').map(Number);+ const want = wanted.split('.').map(Number);for (let i = 0; i < 3; i++) {const diff = Number(match[i + 1]) - want[i];if (diff) return diff > 0;@@ -151,12 +158,16 @@ function outdated(action: BackendRequest['action'], what: string): BackendResult);}-/** Bytes per upload the extension accepts (its job validation caps base64 at 40 million characters). */+/**+ * Bytes per upload the extension can take as data (its job validation caps base64 at 40 million+ * characters). Newer extensions also get the paths and let Chrome read the files through the debugger,+ * so larger batches work there once the user has allowed the debugger.+ */const UPLOAD_BATCH_BYTES_MAX = 30_000_000;function uploadTooLarge(action: BackendRequest['action']): BackendResult {return actionFailed(action,- '上传文件总大小超过约 30 MB:浏览器扩展一次只能接收这么多,请分批上传',+ `上传文件总大小超过约 30 MB:这个版本的 Cindy 浏览器扩展只能直接传这么多。请告知用户把扩展更新到 ${USER_BROWSER_PATH_UPLOAD_VERSION} 或更新版本(之后经 Chrome 调试接口按文件位置上传,不受此限),或分批上传`,'BROWSER_RUNTIME_INVALID_REQUEST',);}@@ -1273,13 +1284,19 @@ export class UserBrowserBackend implements BrowserBackend {? await this.opts.resolveUploadRoots(sessionId): [];const paths = await resolveUploadFiles(req.paths, roots);- // The extension takes about 30 MB per upload (its base64 limit); refuse before reading anything.let total = 0;for (const file of paths) total += (await fs.stat(file)).size;- if (total > UPLOAD_BATCH_BYTES_MAX) return uploadTooLarge(req.action);+ // Newer extensions get the checked paths and have Chrome read the files through the debugger, with+ // no transfer bound; the bytes go along only when they fit, as the fallback without the debugger.+ const byPath = extensionAtLeast(+ this.connectedClients(gate.control).find((c) => c.id === record.clientId)?.version,+ USER_BROWSER_PATH_UPLOAD_VERSION,+ );+ const withBytes = total <= UPLOAD_BATCH_BYTES_MAX;+ if (!byPath && !withBytes) return uploadTooLarge(req.action);const files: Array<{ name: string; data: string; mimeType: string }> = [];let read = 0;- for (const file of paths) {+ for (const file of withBytes ? paths : []) {// Read from the descriptor that was checked, so a file swapped for a link after the check// cannot pull bytes from outside the allowed roots. One file at a time bounds memory.const bytes = readRecipeInputFileSync(file, roots);@@ -1294,7 +1311,8 @@ export class UserBrowserBackend implements BrowserBackend {const ref = req.inputRef ?? req.ref;const job = await this.pageJob(gate.control, record, 'upload', {...(ref ? { ref } : req.selector ? { selector: req.selector } : { selector: 'input[type=file]' }),- files,+ ...(withBytes ? { files } : {}),+ ...(byPath ? { paths } : {}),});if (!job.ok) return this.failureResult(req.action, job);return actionOk(req.action, {