openclaw/src/telegram/proxy.ts

15 lines
678 B
TypeScript
Raw Normal View History

import { ProxyAgent, fetch as undiciFetch } from "undici";
import { wrapFetchWithAbortSignal } from "../infra/fetch.js";
export function makeProxyFetch(proxyUrl: string): typeof fetch {
const agent = new ProxyAgent(proxyUrl);
// undici's fetch is runtime-compatible with global fetch but the types diverge
// on stream/body internals. Single cast at the boundary keeps the rest type-safe.
2026-02-04 04:09:53 -08:00
const fetcher = ((input: RequestInfo | URL, init?: RequestInit) =>
undiciFetch(input as string | URL, {
...(init as Record<string, unknown>),
dispatcher: agent,
2026-02-04 04:09:53 -08:00
}) as unknown as Promise<Response>) as typeof fetch;
return wrapFetchWithAbortSignal(fetcher);
}