Merge pull request #6590 from continuedev/pe/req-headers
chore: add ideInfo headers to hub reqs
This commit is contained in:
commit
0bfd72c7f3
10 changed files with 60 additions and 7 deletions
|
|
@ -65,9 +65,11 @@ export class ConfigHandler {
|
|||
) {
|
||||
this.ide = ide;
|
||||
this.ideSettingsPromise = ideSettingsPromise;
|
||||
|
||||
this.controlPlaneClient = new ControlPlaneClient(
|
||||
sessionInfoPromise,
|
||||
ideSettingsPromise,
|
||||
this.ide.getIdeInfo(),
|
||||
);
|
||||
|
||||
// This profile manager will always be available
|
||||
|
|
@ -364,6 +366,7 @@ export class ConfigHandler {
|
|||
this.controlPlaneClient = new ControlPlaneClient(
|
||||
Promise.resolve(sessionInfo),
|
||||
this.ideSettingsPromise,
|
||||
this.ide.getIdeInfo(),
|
||||
);
|
||||
this.abortCascade();
|
||||
await this.cascadeInit("Control plane session info update");
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import {
|
|||
import fetch, { RequestInit, Response } from "node-fetch";
|
||||
|
||||
import { OrganizationDescription } from "../config/ProfileLifecycleManager.js";
|
||||
import { IdeSettings, ModelDescription } from "../index.js";
|
||||
import { IdeInfo, IdeSettings, ModelDescription } from "../index.js";
|
||||
|
||||
import { ControlPlaneSessionInfo, isOnPremSession } from "./AuthTypes.js";
|
||||
import { getControlPlaneEnv } from "./env.js";
|
||||
|
|
@ -40,6 +40,7 @@ export class ControlPlaneClient {
|
|||
ControlPlaneSessionInfo | undefined
|
||||
>,
|
||||
private readonly ideSettingsPromise: Promise<IdeSettings>,
|
||||
private readonly ideInfoPromise: Promise<IdeInfo>,
|
||||
) {}
|
||||
|
||||
async resolveFQSNs(
|
||||
|
|
@ -86,11 +87,17 @@ export class ControlPlaneClient {
|
|||
|
||||
const env = await getControlPlaneEnv(this.ideSettingsPromise);
|
||||
const url = new URL(path, env.CONTROL_PLANE_URL).toString();
|
||||
const ideInfo = await this.ideInfoPromise;
|
||||
|
||||
const resp = await fetch(url, {
|
||||
...init,
|
||||
headers: {
|
||||
...init.headers,
|
||||
Authorization: `Bearer ${accessToken}`,
|
||||
...{
|
||||
"x-extension-version": ideInfo.extensionVersion,
|
||||
"x-is-prerelease": String(ideInfo.isPrerelease),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
|||
1
core/index.d.ts
vendored
1
core/index.d.ts
vendored
|
|
@ -711,6 +711,7 @@ export interface IdeInfo {
|
|||
version: string;
|
||||
remoteName: string;
|
||||
extensionVersion: string;
|
||||
isPrerelease: boolean;
|
||||
}
|
||||
|
||||
export interface BranchAndDir {
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ export const ideSettingsPromise = testIde.getIdeSettings();
|
|||
export const testControlPlaneClient = new ControlPlaneClient(
|
||||
Promise.resolve(undefined),
|
||||
ideSettingsPromise,
|
||||
testIde.getIdeInfo(),
|
||||
);
|
||||
|
||||
export const testConfigHandler = new ConfigHandler(
|
||||
|
|
|
|||
|
|
@ -120,6 +120,7 @@ class FileSystemIde implements IDE {
|
|||
version: "0.1",
|
||||
remoteName: "na",
|
||||
extensionVersion: "na",
|
||||
isPrerelease: false,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
package com.github.continuedev.continueintellijextension.`continue`
|
||||
|
||||
import com.github.continuedev.continueintellijextension.*
|
||||
|
|
@ -86,7 +87,8 @@ class IntelliJIDE(
|
|||
name = ideName,
|
||||
version = ideVersion,
|
||||
remoteName = remoteName,
|
||||
extensionVersion = extensionVersion
|
||||
extensionVersion = extensionVersion,
|
||||
isPrerelease = false // TODO: Implement prerelease detection for JetBrains
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -623,4 +625,3 @@ class IntelliJIDE(
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,8 @@ data class IdeInfo(
|
|||
val name: String,
|
||||
val version: String,
|
||||
val remoteName: String,
|
||||
val extensionVersion: String
|
||||
val extensionVersion: String,
|
||||
val isPrerelease: Boolean
|
||||
)
|
||||
|
||||
data class Problem(
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import type {
|
|||
TerminalOptions,
|
||||
Thread,
|
||||
} from "core";
|
||||
import { getExtensionVersion, isExtensionPrerelease } from "./util/util";
|
||||
|
||||
class VsCodeIde implements IDE {
|
||||
ideUtils: VsCodeIdeUtils;
|
||||
|
|
@ -153,9 +154,8 @@ class VsCodeIde implements IDE {
|
|||
name: vscode.env.appName,
|
||||
version: vscode.version,
|
||||
remoteName: vscode.env.remoteName || "local",
|
||||
extensionVersion:
|
||||
vscode.extensions.getExtension("continue.continue")?.packageJSON
|
||||
.version,
|
||||
extensionVersion: getExtensionVersion(),
|
||||
isPrerelease: isExtensionPrerelease(),
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -126,3 +126,15 @@ export function getExtensionVersion(): string {
|
|||
export function getvsCodeUriScheme(): string {
|
||||
return vscode.env.uriScheme;
|
||||
}
|
||||
|
||||
export function isExtensionPrerelease(): boolean {
|
||||
const extensionVersion = getExtensionVersion();
|
||||
const versionParts = extensionVersion.split(".");
|
||||
if (versionParts.length >= 2) {
|
||||
const minorVersion = parseInt(versionParts[1], 10);
|
||||
if (!isNaN(minorVersion)) {
|
||||
return minorVersion % 2 !== 0;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
26
extensions/vscode/src/util/util.vitest.ts
Normal file
26
extensions/vscode/src/util/util.vitest.ts
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import { expect, test, vi } from "vitest";
|
||||
import * as vscode from "vscode";
|
||||
|
||||
// Mock the vscode module
|
||||
vi.mock("vscode", () => ({
|
||||
extensions: {
|
||||
getExtension: vi.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
// Import the function after mocking
|
||||
import { isExtensionPrerelease } from "./util";
|
||||
|
||||
test("isExtensionPrerelease detects prerelease versions correctly", () => {
|
||||
// 1.0.0 is not prerelease (even minor version)
|
||||
vi.mocked(vscode.extensions.getExtension).mockReturnValue({
|
||||
packageJSON: { version: "1.0.0" },
|
||||
} as any);
|
||||
expect(isExtensionPrerelease()).toBe(false);
|
||||
|
||||
// 1.1.0 is prerelease (odd minor version)
|
||||
vi.mocked(vscode.extensions.getExtension).mockReturnValue({
|
||||
packageJSON: { version: "1.1.0" },
|
||||
} as any);
|
||||
expect(isExtensionPrerelease()).toBe(true);
|
||||
});
|
||||
Loading…
Add table
Reference in a new issue