( filePath: string, fileName?: string, mimeType?: string )
| 52 | } |
| 53 | |
| 54 | function buildFileUploadPayload( |
| 55 | filePath: string, |
| 56 | fileName?: string, |
| 57 | mimeType?: string |
| 58 | ): { name: string; mimeType?: string; base64: string } { |
| 59 | const absPath = resolveUploadPath(filePath); |
| 60 | const stats = statSync(absPath); |
| 61 | if (!stats.isFile()) throw new Error(`Not a file: ${absPath}`); |
| 62 | if (stats.size > MAX_UPLOAD_BYTES) { |
| 63 | throw new Error( |
| 64 | `File too large (${stats.size} bytes). Max is ${MAX_UPLOAD_BYTES} bytes (OPENCODE_BROWSER_MAX_UPLOAD_BYTES). ` + |
| 65 | `For larger uploads, use OPENCODE_BROWSER_BACKEND=agent.` |
| 66 | ); |
| 67 | } |
| 68 | const base64 = readFileSync(absPath).toString("base64"); |
| 69 | const name = typeof fileName === "string" && fileName.trim() ? fileName.trim() : basename(absPath); |
| 70 | const mt = typeof mimeType === "string" && mimeType.trim() ? mimeType.trim() : undefined; |
| 71 | return { name, mimeType: mt, base64 }; |
| 72 | } |
| 73 | |
| 74 | type BrokerResponse = |
| 75 | | { type: "response"; id: number; ok: true; data: any } |
no test coverage detected