Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 42 additions & 26 deletions core/continueServer/stubs/client.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { fetchwithRequestOptions } from "@continuedev/fetch";

import type { RequestOptions } from "../../index.js";
import type {
ArtifactType,
EmbeddingsCacheResponse,
Expand All @@ -10,6 +13,7 @@ export class ContinueServerClient implements IContinueServerClient {
constructor(
serverUrl: string | undefined,
private readonly userToken: string | undefined,
private readonly requestOptions?: RequestOptions,
) {
try {
this.url =
Expand All @@ -32,18 +36,22 @@ export class ContinueServerClient implements IContinueServerClient {

public async getConfig(): Promise<{ configJson: string }> {
const userToken = await this.userToken;
const response = await fetch(new URL("sync", this.url).href, {
method: "GET",
headers: {
Authorization: `Bearer ${userToken}`,
const response = await fetchwithRequestOptions(
new URL("sync", this.url),
{
method: "GET",
headers: {
Authorization: `Bearer ${userToken}`,
},
},
});
this.requestOptions,
);
if (!response.ok) {
throw new Error(
`Failed to sync remote config (HTTP ${response.status}): ${response.statusText}`,
);
}
const data = await response.json();
const data = (await response.json()) as { configJson: string };
return data;
}

Expand All @@ -66,17 +74,21 @@ export class ContinueServerClient implements IContinueServerClient {
const url = new URL("indexing/cache", this.url);

try {
const response = await fetch(url, {
method: "POST",
headers: {
Authorization: `Bearer ${await this.userToken}`,
const response = await fetchwithRequestOptions(
url,
{
method: "POST",
headers: {
Authorization: `Bearer ${await this.userToken}`,
},
body: JSON.stringify({
keys,
artifactId,
repo: repoName ?? "NONE",
}),
},
body: JSON.stringify({
keys,
artifactId,
repo: repoName ?? "NONE",
}),
});
this.requestOptions,
);

if (!response.ok) {
const text = await response.text();
Expand All @@ -88,7 +100,7 @@ export class ContinueServerClient implements IContinueServerClient {
};
}

const data = await response.json();
const data = (await response.json()) as EmbeddingsCacheResponse<T>;
return data;
} catch (e) {
console.warn("Failed to retrieve from remote cache", e);
Expand All @@ -105,15 +117,19 @@ export class ContinueServerClient implements IContinueServerClient {

const url = new URL("feedback", this.url);

const response = await fetch(url, {
method: "POST",
headers: {
Authorization: `Bearer ${await this.userToken}`,
const response = await fetchwithRequestOptions(
url,
{
method: "POST",
headers: {
Authorization: `Bearer ${await this.userToken}`,
},
body: JSON.stringify({
feedback,
data,
}),
},
body: JSON.stringify({
feedback,
data,
}),
});
this.requestOptions,
);
}
}
55 changes: 55 additions & 0 deletions core/continueServer/stubs/client.vitest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { fetchwithRequestOptions } from "@continuedev/fetch";
import { beforeEach, expect, test, vi } from "vitest";
import type { RequestOptions } from "../../index.js";
import { ContinueServerClient } from "./client.js";

vi.mock("@continuedev/fetch");

const requestOptions: RequestOptions = {
proxy: "http://proxy.example.com:8080",
verifySsl: false,
};

beforeEach(() => {
vi.mocked(fetchwithRequestOptions).mockResolvedValue({
ok: true,
json: async () => ({ configJson: "{}" }),
} as any);
});

test("getConfig forwards requestOptions to the fetch layer", async () => {
const client = new ContinueServerClient(
"https://server.example.com",
"token",
requestOptions,
);

await client.getConfig();

expect(fetchwithRequestOptions).toHaveBeenCalledWith(
expect.any(URL),
expect.objectContaining({ method: "GET" }),
requestOptions,
);
});

test("getFromIndexCache forwards requestOptions to the fetch layer", async () => {
vi.mocked(fetchwithRequestOptions).mockResolvedValue({
ok: true,
json: async () => ({ files: {} }),
} as any);

const client = new ContinueServerClient(
"https://server.example.com",
"token",
requestOptions,
);

await client.getFromIndexCache(["key"], "embeddings" as any, "repo");

expect(fetchwithRequestOptions).toHaveBeenCalledWith(
expect.any(URL),
expect.objectContaining({ method: "POST" }),
requestOptions,
);
});
1 change: 1 addition & 0 deletions core/indexing/CodebaseIndexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export class CodebaseIndexer {
const continueServerClient = new ContinueServerClient(
ideSettings.remoteConfigServerUrl,
ideSettings.userToken,
config.requestOptions,
);
if (!continueServerClient) {
return [];
Expand Down
Loading