commit
ec76400bbe
12 changed files with 146 additions and 87 deletions
|
|
@ -1,10 +1,6 @@
|
|||
import { ConfigResult } from "@continuedev/config-yaml";
|
||||
|
||||
import {
|
||||
ControlPlaneClient,
|
||||
ControlPlaneSessionInfo,
|
||||
} from "../control-plane/client.js";
|
||||
import { getControlPlaneEnv } from "../control-plane/env.js";
|
||||
import { ControlPlaneClient } from "../control-plane/client.js";
|
||||
import {
|
||||
BrowserSerializedContinueConfig,
|
||||
ContinueConfig,
|
||||
|
|
@ -15,6 +11,11 @@ import {
|
|||
} from "../index.js";
|
||||
import { GlobalContext } from "../util/GlobalContext.js";
|
||||
|
||||
import {
|
||||
AuthType,
|
||||
ControlPlaneSessionInfo,
|
||||
} from "../control-plane/AuthTypes.js";
|
||||
import { getControlPlaneEnv } from "../control-plane/env.js";
|
||||
import { logger } from "../util/logger.js";
|
||||
import {
|
||||
ASSISTANTS,
|
||||
|
|
@ -136,8 +137,7 @@ export class ConfigHandler {
|
|||
}
|
||||
|
||||
private async getOrgs(): Promise<OrgWithProfiles[]> {
|
||||
const userId = await this.controlPlaneClient.userId;
|
||||
if (userId) {
|
||||
if (await this.controlPlaneClient.isSignedIn()) {
|
||||
const orgDescs = await this.controlPlaneClient.listOrganizations();
|
||||
const personalHubOrg = await this.getPersonalHubOrg();
|
||||
const hubOrgs = await Promise.all(
|
||||
|
|
@ -270,6 +270,13 @@ export class ConfigHandler {
|
|||
/**
|
||||
* Users can define as many local assistants as they want in a `.continue/assistants` folder
|
||||
*/
|
||||
|
||||
// Local customization disabled for on-premise deployments
|
||||
const env = await getControlPlaneEnv(this.ide.getIdeSettings());
|
||||
if (env.AUTH_TYPE === AuthType.OnPrem) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const localProfiles: ProfileLifecycleManager[] = [];
|
||||
|
||||
if (options.includeGlobal) {
|
||||
|
|
|
|||
55
core/control-plane/AuthTypes.ts
Normal file
55
core/control-plane/AuthTypes.ts
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
export interface HubSessionInfo {
|
||||
AUTH_TYPE: AuthType.WorkOsProd | AuthType.WorkOsStaging;
|
||||
accessToken: string;
|
||||
account: {
|
||||
label: string;
|
||||
id: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface OnPremSessionInfo {
|
||||
AUTH_TYPE: AuthType.OnPrem;
|
||||
}
|
||||
|
||||
export type ControlPlaneSessionInfo = HubSessionInfo | OnPremSessionInfo;
|
||||
|
||||
export function isHubSession(
|
||||
sessionInfo: ControlPlaneSessionInfo | undefined,
|
||||
): sessionInfo is HubSessionInfo {
|
||||
return (
|
||||
sessionInfo !== undefined &&
|
||||
(sessionInfo.AUTH_TYPE === AuthType.WorkOsProd ||
|
||||
sessionInfo.AUTH_TYPE === AuthType.WorkOsStaging)
|
||||
);
|
||||
}
|
||||
|
||||
export enum AuthType {
|
||||
WorkOsProd = "continue",
|
||||
WorkOsStaging = "continue-staging",
|
||||
OnPrem = "on-prem",
|
||||
}
|
||||
|
||||
export interface HubEnv {
|
||||
DEFAULT_CONTROL_PLANE_PROXY_URL: string;
|
||||
CONTROL_PLANE_URL: string;
|
||||
AUTH_TYPE: AuthType.WorkOsProd | AuthType.WorkOsStaging;
|
||||
WORKOS_CLIENT_ID: string;
|
||||
APP_URL: string;
|
||||
}
|
||||
|
||||
export interface OnPremEnv {
|
||||
AUTH_TYPE: AuthType.OnPrem;
|
||||
DEFAULT_CONTROL_PLANE_PROXY_URL: string;
|
||||
CONTROL_PLANE_URL: string;
|
||||
APP_URL: string;
|
||||
}
|
||||
|
||||
export type ControlPlaneEnv = HubEnv | OnPremEnv;
|
||||
|
||||
export function isHubEnv(env: ControlPlaneEnv): env is HubEnv {
|
||||
return (
|
||||
"AUTH_TYPE" in env &&
|
||||
env.AUTH_TYPE !== "on-prem" &&
|
||||
"WORKOS_CLIENT_ID" in env
|
||||
);
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
import { v4 as uuidv4 } from "uuid";
|
||||
import { IdeSettings } from "../..";
|
||||
import { isHubEnv } from "../AuthTypes";
|
||||
import { getControlPlaneEnv } from "../env";
|
||||
|
||||
export async function getAuthUrlForTokenPage(
|
||||
|
|
@ -7,6 +8,11 @@ export async function getAuthUrlForTokenPage(
|
|||
useOnboarding: boolean,
|
||||
): Promise<string> {
|
||||
const env = await getControlPlaneEnv(ideSettingsPromise);
|
||||
|
||||
if (!isHubEnv(env)) {
|
||||
throw new Error("Sign in disabled");
|
||||
}
|
||||
|
||||
const url = new URL("https://api.workos.com/user_management/authorize");
|
||||
const params = {
|
||||
response_type: "code",
|
||||
|
|
|
|||
|
|
@ -12,16 +12,9 @@ import fetch, { RequestInit, Response } from "node-fetch";
|
|||
import { OrganizationDescription } from "../config/ProfileLifecycleManager.js";
|
||||
import { IdeSettings, ModelDescription } from "../index.js";
|
||||
|
||||
import { ControlPlaneSessionInfo, isHubSession } from "./AuthTypes.js";
|
||||
import { getControlPlaneEnv } from "./env.js";
|
||||
|
||||
export interface ControlPlaneSessionInfo {
|
||||
accessToken: string;
|
||||
account: {
|
||||
label: string;
|
||||
id: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface ControlPlaneWorkspace {
|
||||
id: string;
|
||||
name: string;
|
||||
|
|
@ -45,8 +38,7 @@ export class ControlPlaneClient {
|
|||
fqsns: FQSN[],
|
||||
orgScopeId: string | null,
|
||||
): Promise<(SecretResult | undefined)[]> {
|
||||
const userId = await this.userId;
|
||||
if (!userId) {
|
||||
if (!this.isSignedIn()) {
|
||||
return fqsns.map((fqsn) => ({
|
||||
found: false,
|
||||
fqsn,
|
||||
|
|
@ -64,19 +56,24 @@ export class ControlPlaneClient {
|
|||
return (await resp.json()) as any;
|
||||
}
|
||||
|
||||
get userId(): Promise<string | undefined> {
|
||||
return this.sessionInfoPromise.then(
|
||||
(sessionInfo) => sessionInfo?.account.id,
|
||||
);
|
||||
async isSignedIn(): Promise<boolean> {
|
||||
const sessionInfo = await this.sessionInfoPromise;
|
||||
return !!sessionInfo;
|
||||
}
|
||||
|
||||
async getAccessToken(): Promise<string | undefined> {
|
||||
return (await this.sessionInfoPromise)?.accessToken;
|
||||
const sessionInfo = await this.sessionInfoPromise;
|
||||
return isHubSession(sessionInfo) ? sessionInfo.accessToken : undefined;
|
||||
}
|
||||
|
||||
private async request(path: string, init: RequestInit): Promise<Response> {
|
||||
const accessToken = await this.getAccessToken();
|
||||
if (!accessToken) {
|
||||
const sessionInfo = await this.sessionInfoPromise;
|
||||
const hubSession = isHubSession(sessionInfo);
|
||||
|
||||
const accessToken = hubSession ? sessionInfo.accessToken : undefined;
|
||||
|
||||
// Bearer token not necessary for on-prem auth type
|
||||
if (!accessToken && hubSession) {
|
||||
throw new Error("No access token");
|
||||
}
|
||||
|
||||
|
|
@ -99,22 +96,6 @@ export class ControlPlaneClient {
|
|||
return resp;
|
||||
}
|
||||
|
||||
public async listWorkspaces(): Promise<ControlPlaneWorkspace[]> {
|
||||
const userId = await this.userId;
|
||||
if (!userId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
try {
|
||||
const resp = await this.request("workspaces", {
|
||||
method: "GET",
|
||||
});
|
||||
return (await resp.json()) as any;
|
||||
} catch (e) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public async listAssistants(organizationId: string | null): Promise<
|
||||
{
|
||||
configResult: ConfigResult<AssistantUnrolled>;
|
||||
|
|
@ -124,8 +105,7 @@ export class ControlPlaneClient {
|
|||
rawYaml: string;
|
||||
}[]
|
||||
> {
|
||||
const userId = await this.userId;
|
||||
if (!userId) {
|
||||
if (!this.isSignedIn()) {
|
||||
return [];
|
||||
}
|
||||
|
||||
|
|
@ -144,9 +124,7 @@ export class ControlPlaneClient {
|
|||
}
|
||||
|
||||
public async listOrganizations(): Promise<Array<OrganizationDescription>> {
|
||||
const userId = await this.userId;
|
||||
|
||||
if (!userId) {
|
||||
if (!this.isSignedIn()) {
|
||||
return [];
|
||||
}
|
||||
|
||||
|
|
@ -164,8 +142,7 @@ export class ControlPlaneClient {
|
|||
public async listAssistantFullSlugs(
|
||||
organizationId: string | null,
|
||||
): Promise<FullSlug[] | null> {
|
||||
const userId = await this.userId;
|
||||
if (!userId) {
|
||||
if (!this.isSignedIn()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -183,16 +160,4 @@ export class ControlPlaneClient {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async getSettingsForWorkspace(workspaceId: string): Promise<ConfigJson> {
|
||||
const userId = await this.userId;
|
||||
if (!userId) {
|
||||
throw new Error("No user id");
|
||||
}
|
||||
|
||||
const resp = await this.request(`workspaces/${workspaceId}`, {
|
||||
method: "GET",
|
||||
});
|
||||
return ((await resp.json()) as any).settings;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,27 +4,17 @@ import {
|
|||
getLocalEnvironmentDotFilePath,
|
||||
getStagingEnvironmentDotFilePath,
|
||||
} from "../util/paths";
|
||||
|
||||
export interface ControlPlaneEnv {
|
||||
DEFAULT_CONTROL_PLANE_PROXY_URL: string;
|
||||
CONTROL_PLANE_URL: string;
|
||||
AUTH_TYPE: string;
|
||||
WORKOS_CLIENT_ID: string;
|
||||
APP_URL: string;
|
||||
}
|
||||
import { AuthType, ControlPlaneEnv } from "./AuthTypes";
|
||||
|
||||
export const EXTENSION_NAME = "continue";
|
||||
|
||||
const WORKOS_CLIENT_ID_PRODUCTION = "client_01J0FW6XN8N2XJAECF7NE0Y65J";
|
||||
const WORKOS_CLIENT_ID_STAGING = "client_01J0FW6XCPMJMQ3CG51RB4HBZQ";
|
||||
|
||||
const WORKOS_ENV_ID_PRODUCTION = "continue";
|
||||
const WORKOS_ENV_ID_STAGING = "continue-staging";
|
||||
|
||||
const PRODUCTION_HUB_ENV: ControlPlaneEnv = {
|
||||
DEFAULT_CONTROL_PLANE_PROXY_URL: "https://api.continue.dev/",
|
||||
CONTROL_PLANE_URL: "https://api.continue.dev/",
|
||||
AUTH_TYPE: WORKOS_ENV_ID_PRODUCTION,
|
||||
AUTH_TYPE: AuthType.WorkOsProd,
|
||||
WORKOS_CLIENT_ID: WORKOS_CLIENT_ID_PRODUCTION,
|
||||
APP_URL: "https://hub.continue.dev/",
|
||||
};
|
||||
|
|
@ -32,7 +22,7 @@ const PRODUCTION_HUB_ENV: ControlPlaneEnv = {
|
|||
const STAGING_ENV: ControlPlaneEnv = {
|
||||
DEFAULT_CONTROL_PLANE_PROXY_URL: "https://api.continue-stage.tools/",
|
||||
CONTROL_PLANE_URL: "https://api.continue-stage.tools/",
|
||||
AUTH_TYPE: WORKOS_ENV_ID_STAGING,
|
||||
AUTH_TYPE: AuthType.WorkOsStaging,
|
||||
WORKOS_CLIENT_ID: WORKOS_CLIENT_ID_STAGING,
|
||||
APP_URL: "https://hub.continue-stage.tools/",
|
||||
};
|
||||
|
|
@ -40,7 +30,7 @@ const STAGING_ENV: ControlPlaneEnv = {
|
|||
const TEST_ENV: ControlPlaneEnv = {
|
||||
DEFAULT_CONTROL_PLANE_PROXY_URL: "https://api-test.continue.dev/",
|
||||
CONTROL_PLANE_URL: "https://api-test.continue.dev/",
|
||||
AUTH_TYPE: WORKOS_ENV_ID_STAGING,
|
||||
AUTH_TYPE: AuthType.WorkOsStaging,
|
||||
WORKOS_CLIENT_ID: WORKOS_CLIENT_ID_STAGING,
|
||||
APP_URL: "https://app-test.continue.dev/",
|
||||
};
|
||||
|
|
@ -48,7 +38,7 @@ const TEST_ENV: ControlPlaneEnv = {
|
|||
const LOCAL_ENV: ControlPlaneEnv = {
|
||||
DEFAULT_CONTROL_PLANE_PROXY_URL: "http://localhost:3001/",
|
||||
CONTROL_PLANE_URL: "http://localhost:3001/",
|
||||
AUTH_TYPE: WORKOS_ENV_ID_STAGING,
|
||||
AUTH_TYPE: AuthType.WorkOsStaging,
|
||||
WORKOS_CLIENT_ID: WORKOS_CLIENT_ID_STAGING,
|
||||
APP_URL: "http://localhost:3000/",
|
||||
};
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ import {
|
|||
ToolCall,
|
||||
} from "../";
|
||||
import { SerializedOrgWithProfiles } from "../config/ProfileLifecycleManager";
|
||||
import { ControlPlaneSessionInfo } from "../control-plane/client";
|
||||
import { ControlPlaneSessionInfo } from "../control-plane/AuthTypes";
|
||||
|
||||
export type OnboardingModes = "Local" | "Best" | "Custom" | "Quickstart";
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
import { ControlPlaneSessionInfo } from "../control-plane/client";
|
||||
|
||||
import type {
|
||||
ContinueRcJson,
|
||||
DiffLine,
|
||||
|
|
@ -16,6 +14,7 @@ import type {
|
|||
TerminalOptions,
|
||||
Thread,
|
||||
} from "../";
|
||||
import { ControlPlaneSessionInfo } from "../control-plane/AuthTypes";
|
||||
|
||||
export interface GetGhTokenArgs {
|
||||
force?: boolean;
|
||||
|
|
@ -99,7 +98,7 @@ export type ToIdeFromWebviewOrCoreProtocol = {
|
|||
ControlPlaneSessionInfo | undefined,
|
||||
];
|
||||
logoutOfControlPlane: [undefined, void];
|
||||
reportError:[any, void];
|
||||
reportError: [any, void];
|
||||
closeSidebar: [undefined, void];
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { ConfigResult } from "@continuedev/config-yaml";
|
||||
import { SerializedOrgWithProfiles } from "../config/ProfileLifecycleManager.js";
|
||||
import { ControlPlaneSessionInfo } from "../control-plane/client.js";
|
||||
import { ControlPlaneSessionInfo } from "../control-plane/AuthTypes.js";
|
||||
import type {
|
||||
BrowserSerializedContinueConfig,
|
||||
ContextItemWithId,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import crypto from "crypto";
|
||||
|
||||
import { ControlPlaneSessionInfo } from "core/control-plane/client";
|
||||
import { getControlPlaneEnvSync } from "core/control-plane/env";
|
||||
import fetch from "node-fetch";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
|
|
@ -18,6 +17,12 @@ import {
|
|||
window,
|
||||
} from "vscode";
|
||||
|
||||
import {
|
||||
AuthType,
|
||||
ControlPlaneSessionInfo,
|
||||
HubEnv,
|
||||
isHubEnv,
|
||||
} from "core/control-plane/AuthTypes";
|
||||
import { PromiseAdapter, promiseFromEvent } from "./promiseUtils";
|
||||
import { SecretStorage } from "./SecretStorage";
|
||||
import { UriEventHandler } from "./uriHandler";
|
||||
|
|
@ -280,12 +285,21 @@ export class WorkOsAuthProvider implements AuthenticationProvider, Disposable {
|
|||
try {
|
||||
const codeVerifier = generateRandomString(64);
|
||||
const codeChallenge = await generateCodeChallenge(codeVerifier);
|
||||
const token = await this.login(codeChallenge, scopes);
|
||||
|
||||
if (!isHubEnv(controlPlaneEnv)) {
|
||||
throw new Error("Login is disabled");
|
||||
}
|
||||
|
||||
const token = await this.login(codeChallenge, controlPlaneEnv, scopes);
|
||||
if (!token) {
|
||||
throw new Error(`Continue login failure`);
|
||||
}
|
||||
|
||||
const userInfo = (await this.getUserInfo(token, codeVerifier)) as any;
|
||||
const userInfo = (await this.getUserInfo(
|
||||
token,
|
||||
codeVerifier,
|
||||
controlPlaneEnv,
|
||||
)) as any;
|
||||
const { user, access_token, refresh_token } = userInfo;
|
||||
|
||||
const session: ContinueAuthenticationSession = {
|
||||
|
|
@ -352,7 +366,11 @@ export class WorkOsAuthProvider implements AuthenticationProvider, Disposable {
|
|||
/**
|
||||
* Log in to Continue
|
||||
*/
|
||||
private async login(codeChallenge: string, scopes: string[] = []) {
|
||||
private async login(
|
||||
codeChallenge: string,
|
||||
hubEnv: HubEnv,
|
||||
scopes: string[] = [],
|
||||
) {
|
||||
return await window.withProgress<string>(
|
||||
{
|
||||
location: ProgressLocation.Notification,
|
||||
|
|
@ -369,7 +387,7 @@ export class WorkOsAuthProvider implements AuthenticationProvider, Disposable {
|
|||
const url = new URL("https://api.workos.com/user_management/authorize");
|
||||
const params = {
|
||||
response_type: "code",
|
||||
client_id: controlPlaneEnv.WORKOS_CLIENT_ID,
|
||||
client_id: hubEnv.WORKOS_CLIENT_ID,
|
||||
redirect_uri: this.redirectUri,
|
||||
state: stateId,
|
||||
code_challenge: codeChallenge,
|
||||
|
|
@ -458,7 +476,11 @@ export class WorkOsAuthProvider implements AuthenticationProvider, Disposable {
|
|||
* @param token
|
||||
* @returns
|
||||
*/
|
||||
private async getUserInfo(token: string, codeVerifier: string) {
|
||||
private async getUserInfo(
|
||||
token: string,
|
||||
codeVerifier: string,
|
||||
hubEnv: HubEnv,
|
||||
) {
|
||||
const resp = await fetch(
|
||||
"https://api.workos.com/user_management/authenticate",
|
||||
{
|
||||
|
|
@ -467,7 +489,7 @@ export class WorkOsAuthProvider implements AuthenticationProvider, Disposable {
|
|||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
client_id: controlPlaneEnv.WORKOS_CLIENT_ID,
|
||||
client_id: hubEnv.WORKOS_CLIENT_ID,
|
||||
code_verifier: codeVerifier,
|
||||
grant_type: "authorization_code",
|
||||
code: token,
|
||||
|
|
@ -484,6 +506,12 @@ export async function getControlPlaneSessionInfo(
|
|||
silent: boolean,
|
||||
useOnboarding: boolean,
|
||||
): Promise<ControlPlaneSessionInfo | undefined> {
|
||||
if (!isHubEnv(controlPlaneEnv)) {
|
||||
return {
|
||||
AUTH_TYPE: AuthType.OnPrem,
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
if (useOnboarding) {
|
||||
WorkOsAuthProvider.useOnboardingUri = true;
|
||||
|
|
@ -498,6 +526,7 @@ export async function getControlPlaneSessionInfo(
|
|||
return undefined;
|
||||
}
|
||||
return {
|
||||
AUTH_TYPE: controlPlaneEnv.AUTH_TYPE,
|
||||
accessToken: session.accessToken,
|
||||
account: {
|
||||
id: session.account.id,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import {
|
|||
OrganizationDescription,
|
||||
ProfileDescription,
|
||||
} from "core/config/ProfileLifecycleManager";
|
||||
import { ControlPlaneSessionInfo } from "core/control-plane/client";
|
||||
import { ControlPlaneSessionInfo } from "core/control-plane/AuthTypes";
|
||||
import React, {
|
||||
createContext,
|
||||
useCallback,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { IDE, PromptLog } from "core";
|
||||
import { AuthType } from "core/control-plane/AuthTypes";
|
||||
import {
|
||||
FromIdeProtocol,
|
||||
FromWebviewProtocol,
|
||||
|
|
@ -38,6 +39,7 @@ async function defaultMockHandleMessage<T extends keyof FromWebviewProtocol>(
|
|||
]);
|
||||
case "getControlPlaneSessionInfo":
|
||||
return returnFor("getControlPlaneSessionInfo", {
|
||||
AUTH_TYPE: AuthType.WorkOsStaging,
|
||||
accessToken: "",
|
||||
account: {
|
||||
label: "",
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { UserCircleIcon } from "@heroicons/react/24/solid";
|
||||
|
||||
import { isHubSession } from "core/control-plane/AuthTypes";
|
||||
import { SecondaryButton } from "../../components";
|
||||
import {
|
||||
Popover,
|
||||
|
|
@ -27,6 +28,11 @@ export function AccountButton() {
|
|||
);
|
||||
}
|
||||
|
||||
// No login button for on-prem deployments
|
||||
if (!isHubSession(session)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<Popover className="relative">
|
||||
{({ close }) => (
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue