Created
May 17, 2026 14:33
-
-
Save amol-/f477ede239598707b0ff4968f276ca14 to your computer and use it in GitHub Desktop.
pi extension to fix mistral
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import type { ExtensionAPI } from "@earendil-works/pi-coding-agent"; | |
| const PATCH_APPLIED = Symbol.for("amol.pi.fetch-request-fix"); | |
| export default function (_pi: ExtensionAPI) { | |
| const state = globalThis as typeof globalThis & { [PATCH_APPLIED]?: boolean }; | |
| if (state[PATCH_APPLIED]) return; | |
| const originalFetch: typeof fetch = globalThis.fetch.bind(globalThis); | |
| globalThis.fetch = (input: RequestInfo | URL, init?: RequestInit) => { | |
| if (typeof Request !== "undefined" && input instanceof Request) { | |
| const requestInit: RequestInit & { duplex?: "half" } = { | |
| method: input.method, | |
| headers: input.headers, | |
| body: input.body, | |
| signal: input.signal, | |
| ...init, | |
| }; | |
| if (input.body !== null && !requestInit.duplex) requestInit.duplex = "half"; | |
| return originalFetch(input.url, requestInit); | |
| } | |
| return originalFetch(input, init); | |
| }; | |
| state[PATCH_APPLIED] = true; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment