Elffuss BraidHub

kikocis/continue public

Merge pull request #6295 from continuedev/dallin/oai-adapters-custom-fetch-flag

Custom Fetch Env Flag
Changeset79e9aa43867eaa7618a0e384a6a7e3da831df8bf7d9a5d7a7b33f3ed8455d92d
AuthorTomasz Stefaniak <tomasz.p.stefaniak@gmail.com> · 2025-06-30 10:43 -07:00
CommitterGitHub <noreply@github.com> · 2025-06-30 10:43 -07:00
Parents483c37bb84f4, a10cd9114232

Browse the files at this changeset

8 files changed

modified packages/fetch/package-lock.json +2 −2
@@ -1,12 +1,12 @@
11 {
22 "name": "@continuedev/fetch",
3- "version": "1.0.13",
3+ "version": "1.0.15",
44 "lockfileVersion": 3,
55 "requires": true,
66 "packages": {
77 "": {
88 "name": "@continuedev/fetch",
9- "version": "1.0.13",
9+ "version": "1.0.15",
1010 "license": "Apache-2.0",
1111 "dependencies": {
1212 "@continuedev/config-types": "^1.0.5",
modified packages/fetch/package.json +1 −1
@@ -1,6 +1,6 @@
11 {
22 "name": "@continuedev/fetch",
3- "version": "1.0.14",
3+ "version": "1.0.15",
44 "description": "",
55 "main": "dist/index.js",
66 "types": "dist/index.d.ts",
modified packages/fetch/src/fetch.ts +2 −2
@@ -4,7 +4,7 @@
44 import { HttpsProxyAgent } from "https-proxy-agent";
55 import { BodyInit, RequestInit, Response } from "node-fetch";
66 import { getAgentOptions } from "./getAgentOptions.js";
7-import fetch from "./node-fetch-patch.js";
7+import patchedFetch from "./node-fetch-patch.js";
88 import { getProxy, shouldBypassProxy } from "./util.js";
99
1010 const { http, https } = (followRedirects as any).default;
@@ -144,7 +144,7 @@
144144
145145 // fetch the request with the provided options
146146 try {
147- const resp = await fetch(url, {
147+ const resp = await patchedFetch(url, {
148148 ...init,
149149 body: finalBody,
150150 headers: headers,
modified packages/fetch/src/index.ts +3 −0
@@ -5,10 +5,13 @@
55 toAsyncIterable,
66 } from "./stream.js";
77
8+import patchedFetch from "./node-fetch-patch.js";
9+
810 import { fetchwithRequestOptions } from "./fetch.js";
911
1012 export {
1113 fetchwithRequestOptions,
14+ patchedFetch,
1215 streamJSON,
1316 streamResponse,
1417 streamSse,
modified packages/openai-adapters/package-lock.json +7 −6
@@ -1,17 +1,17 @@
11 {
22 "name": "@continuedev/openai-adapters",
3- "version": "1.0.42",
3+ "version": "1.0.44",
44 "lockfileVersion": 3,
55 "requires": true,
66 "packages": {
77 "": {
88 "name": "@continuedev/openai-adapters",
9- "version": "1.0.42",
9+ "version": "1.0.44",
1010 "license": "Apache-2.0",
1111 "dependencies": {
1212 "@continuedev/config-types": "^1.0.5",
1313 "@continuedev/config-yaml": "^1.0.51",
14- "@continuedev/fetch": "^1.0.11",
14+ "@continuedev/fetch": "^1.0.15",
1515 "dotenv": "^16.5.0",
1616 "json-schema": "^0.4.0",
1717 "node-fetch": "^3.3.2",
@@ -595,9 +595,10 @@
595595 }
596596 },
597597 "node_modules/@continuedev/fetch": {
598- "version": "1.0.11",
599- "resolved": "https://registry.npmjs.org/@continuedev/fetch/-/fetch-1.0.11.tgz",
600- "integrity": "sha512-GRYqAdV3DhRxg463zeSzOdVIk/bhjuuxAxzX0fG35Kz6sHUsU2wr7SDY91zO2ataYUkjnbOa3q1xIpnRnOoRHA==",
598+ "version": "1.0.15",
599+ "resolved": "https://registry.npmjs.org/@continuedev/fetch/-/fetch-1.0.15.tgz",
600+ "integrity": "sha512-49jLwAwAOczcFLfa2Og9+c+qxrq+Z6+p+B5BbXgHENrQIsuST1liKTXEiga5gSVAyHD+m+1Ftl4jqRq2oxMngw==",
601+ "license": "Apache-2.0",
601602 "dependencies": {
602603 "@continuedev/config-types": "^1.0.5",
603604 "follow-redirects": "^1.15.6",
modified packages/openai-adapters/package.json +2 −2
@@ -1,6 +1,6 @@
11 {
22 "name": "@continuedev/openai-adapters",
3- "version": "1.0.42",
3+ "version": "1.0.44",
44 "description": "",
55 "main": "dist/index.js",
66 "types": "dist/index.d.ts",
@@ -14,7 +14,7 @@
1414 "dependencies": {
1515 "@continuedev/config-types": "^1.0.5",
1616 "@continuedev/config-yaml": "^1.0.51",
17- "@continuedev/fetch": "^1.0.11",
17+ "@continuedev/fetch": "^1.0.15",
1818 "dotenv": "^16.5.0",
1919 "json-schema": "^0.4.0",
2020 "node-fetch": "^3.3.2",
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 +16 −4
@@ -1,11 +1,13 @@
11 import { RequestOptions } from "@continuedev/config-types";
2-import { fetchwithRequestOptions } from "@continuedev/fetch";
2+import { fetchwithRequestOptions, patchedFetch } from "@continuedev/fetch";
3+import { type RequestInfo, type RequestInit } from "openai/_shims/index";
34 import {
45 ChatCompletionChunk,
56 CompletionUsage,
67 CreateEmbeddingResponse,
78 Model,
89 } from "openai/resources/index";
10+
911 import { ChatCompletion } from "openai/src/resources/index.js";
1012 import { CreateRerankResponse } from "./apis/base.js";
1113
@@ -136,7 +138,17 @@
136138 };
137139 }
138140
139-export function customFetch(requestOptions: RequestOptions | undefined) {
140- return (url: any, init: any) =>
141- fetchwithRequestOptions(url, init, requestOptions);
141+export function customFetch(
142+ requestOptions: RequestOptions | undefined,
143+): typeof patchedFetch {
144+ if (process.env.FEATURE_FLAG_DISABLE_CUSTOM_FETCH) {
145+ return patchedFetch;
146+ }
147+ return (req: URL | RequestInfo, init?: RequestInit) => {
148+ if (typeof req === "string" || req instanceof URL) {
149+ return fetchwithRequestOptions(req, init, requestOptions);
150+ } else {
151+ return fetchwithRequestOptions(req.url, req, requestOptions);
152+ }
153+ };
142154 }