Add User-Agent headers to Continue Proxy and CLI requests (#8532)

* Add User-Agent headers to Continue Proxy and CLI requests

* fix: tests
This commit is contained in:
Nate Sesti 2025-11-02 20:33:06 -08:00 • committed by GitHub
parent c029738122
commit c3c5224340
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 45 additions and 3 deletions

View file

@ -101,9 +101,18 @@ class ContinueProxy extends OpenAI {
protected _getHeaders() {
const headers: any = super._getHeaders();
headers["x-continue-unique-id"] = Telemetry.uniqueId;
headers["user-agent"] = this._getUserAgent();
return headers;
}
private _getUserAgent(): string {
const ideInfo = Telemetry.ideInfo;
const extensionVersion = ideInfo?.extensionVersion ?? "unknown";
const ideName = ideInfo?.name ?? "unknown";
const ideType = ideInfo?.ideType ?? "unknown";
return `Continue/${extensionVersion} (${ideName}; ${ideType})`;
}
supportsCompletions(): boolean {
// This was a hotfix and contains duplicate logic from class-specific completion support methods
if (this.underlyingProviderName === "vllm") {
@ -129,6 +138,7 @@ class ContinueProxy extends OpenAI {
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${this.apiKey}`,
"user-agent": this._getUserAgent(),
},
body: JSON.stringify({
query,

View file

@ -15,6 +15,30 @@ import {
getOrganizationId,
} from "./auth/workos.js";
import { env } from "./env.js";
import { getVersion } from "./version.js";
/**
* Creates User-Agent header value for CLI requests
*/
function getUserAgent(): string {
const version = getVersion();
return `Continue-CLI/${version}`;
}
/**
* Merges User-Agent header into request options
*/
function mergeUserAgentIntoRequestOptions(
requestOptions: ModelConfig["requestOptions"],
): ModelConfig["requestOptions"] {
return {
...requestOptions,
headers: {
...requestOptions?.headers,
"User-Agent": getUserAgent(),
},
};
}
/**
* Creates an LLM API instance from a ModelConfig and auth configuration
@ -31,7 +55,9 @@ export function createLlmApi(
model.provider === "continue-proxy"
? {
provider: model.provider,
requestOptions: model.requestOptions,
requestOptions: mergeUserAgentIntoRequestOptions(
model.requestOptions,
),
apiBase: model.apiBase,
apiKey: accessToken ?? undefined,
env: {
@ -46,7 +72,9 @@ export function createLlmApi(
provider: model.provider as any,
apiKey: model.apiKey,
apiBase: model.apiBase,
requestOptions: model.requestOptions,
requestOptions: mergeUserAgentIntoRequestOptions(
model.requestOptions,
),
env: model.env,
};

View file

@ -9,7 +9,11 @@ import * as versionModule from "./version.js";
// Mock all dependencies
vi.mock("./auth/workos.js");
vi.mock("./version.js");
vi.mock("./version.js", () => ({
getVersion: vi.fn(() => "1.2.3"),
getLatestVersion: vi.fn(() => Promise.resolve(null)),
compareVersions: vi.fn(() => "same"),
}));
vi.mock("./session.js");
vi.mock("./telemetry/posthogService.js");