Elffuss BraidHub

kikocis/continue public

FEATURE_FLAG_DISABLE_CUSTOM_FETCH and proper types for fetch
Changeset6496d1ed92c1bebc42bcfd7c76e1bd4fa9376137ce609df9cd18dd711dd51cc5
AuthorDallin Romney <dallinromney@gmail.com> · 2025-06-25 15:41 -07:00
CommitterDallin Romney <dallinromney@gmail.com> · 2025-06-25 15:41 -07:00
Parents607dd12e068c

Browse the files at this changeset

2 files changed

modified packages/openai-adapters/src/apis/Relace.ts +1 −2
@@ -67,7 +67,6 @@
6767 body: ChatCompletionCreateParamsStreaming,
6868 signal: AbortSignal,
6969 ): AsyncGenerator<ChatCompletionChunk> {
70- const fetch = customFetch(this.config.requestOptions);
7170 const headers = {
7271 "Content-Type": "application/json",
7372 Authorization: `Bearer ${this.config.apiKey}`,
@@ -98,7 +97,7 @@
9897 };
9998
10099 const url = this.apiBase + "code/apply";
101- const response = await fetch(url, {
100+ const response = await customFetch(this.config.requestOptions)(url, {
102101 method: "POST",
103102 headers,
104103 body: JSON.stringify(data),
modified packages/openai-adapters/src/util.ts +22 −3
@@ -1,11 +1,18 @@
11 import { RequestOptions } from "@continuedev/config-types";
22 import { fetchwithRequestOptions } from "@continuedev/fetch";
3+import fetch from "node-fetch";
4+import {
5+ type RequestInfo,
6+ type RequestInit,
7+ type Response,
8+} from "openai/_shims/index";
39 import {
410 ChatCompletionChunk,
511 CompletionUsage,
612 CreateEmbeddingResponse,
713 Model,
814 } from "openai/resources/index";
15+
916 import { ChatCompletion } from "openai/src/resources/index.js";
1017 import { CreateRerankResponse } from "./apis/base.js";
1118
@@ -136,7 +143,19 @@
136143 };
137144 }
138145
139-export function customFetch(requestOptions: RequestOptions | undefined) {
140- return (url: any, init: any) =>
141- fetchwithRequestOptions(url, init, requestOptions);
146+export function customFetch(
147+ requestOptions: RequestOptions | undefined,
148+): (req: URL | RequestInfo, init?: RequestInit) => Promise<Response> {
149+ if (process.env.FEATURE_FLAG_DISABLE_CUSTOM_FETCH) {
150+ return fetch;
151+ }
152+ return (req: URL | RequestInfo, init?: RequestInit) => {
153+ if (typeof req === "string") {
154+ return fetchwithRequestOptions(req, init, requestOptions);
155+ } else if (req instanceof URL) {
156+ return fetchwithRequestOptions(req, init, requestOptions);
157+ } else {
158+ return fetchwithRequestOptions(req.url, req, requestOptions);
159+ }
160+ };
142161 }