FEATURE_FLAG_DISABLE_CUSTOM_FETCH and proper types for fetch

This commit is contained in:
Dallin Romney 2025-06-25 15:41:17 -07:00
parent 61f9592a33
commit b2fbb83d81
2 changed files with 23 additions and 5 deletions

View file

@ -67,7 +67,6 @@ export class RelaceApi implements BaseLlmApi {
body: ChatCompletionCreateParamsStreaming,
signal: AbortSignal,
): AsyncGenerator<ChatCompletionChunk> {
const fetch = customFetch(this.config.requestOptions);
const headers = {
"Content-Type": "application/json",
Authorization: `Bearer ${this.config.apiKey}`,
@ -98,7 +97,7 @@ export class RelaceApi implements BaseLlmApi {
};
const url = this.apiBase + "code/apply";
const response = await fetch(url, {
const response = await customFetch(this.config.requestOptions)(url, {
method: "POST",
headers,
body: JSON.stringify(data),

View file

@ -1,11 +1,18 @@
import { RequestOptions } from "@continuedev/config-types";
import { fetchwithRequestOptions } from "@continuedev/fetch";
import fetch from "node-fetch";
import {
type RequestInfo,
type RequestInit,
type Response,
} from "openai/_shims/index";
import {
ChatCompletionChunk,
CompletionUsage,
CreateEmbeddingResponse,
Model,
} from "openai/resources/index";
import { ChatCompletion } from "openai/src/resources/index.js";
import { CreateRerankResponse } from "./apis/base.js";
@ -136,7 +143,19 @@ export function model(options: { id: string; owned_by?: string }): Model {
};
}
export function customFetch(requestOptions: RequestOptions | undefined) {
return (url: any, init: any) =>
fetchwithRequestOptions(url, init, requestOptions);
export function customFetch(
requestOptions: RequestOptions | undefined,
): (req: URL | RequestInfo, init?: RequestInit) => Promise<Response> {
if (process.env.FEATURE_FLAG_DISABLE_CUSTOM_FETCH) {
return fetch;
}
return (req: URL | RequestInfo, init?: RequestInit) => {
if (typeof req === "string") {
return fetchwithRequestOptions(req, init, requestOptions);
} else if (req instanceof URL) {
return fetchwithRequestOptions(req, init, requestOptions);
} else {
return fetchwithRequestOptions(req.url, req, requestOptions);
}
};
}