separate SessionInfo types
This commit is contained in:
parent
3b2ef40e45
commit
8f0978a5e1
12 changed files with 108 additions and 81 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(
|
||||
|
|
|
|||
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,6 +1,7 @@
|
|||
import { v4 as uuidv4 } from "uuid";
|
||||
import { IdeSettings } from "../..";
|
||||
import { getControlPlaneEnv, isHubEnv } from "../env";
|
||||
import { isHubEnv } from "../AuthTypes";
|
||||
import { getControlPlaneEnv } from "../env";
|
||||
|
||||
export async function getAuthUrlForTokenPage(
|
||||
ideSettingsPromise: Promise<IdeSettings>,
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
}
|
||||
|
||||
|
|
@ -108,8 +105,7 @@ export class ControlPlaneClient {
|
|||
rawYaml: string;
|
||||
}[]
|
||||
> {
|
||||
const userId = await this.userId;
|
||||
if (!userId) {
|
||||
if (!this.isSignedIn()) {
|
||||
return [];
|
||||
}
|
||||
|
||||
|
|
@ -128,9 +124,7 @@ export class ControlPlaneClient {
|
|||
}
|
||||
|
||||
public async listOrganizations(): Promise<Array<OrganizationDescription>> {
|
||||
const userId = await this.userId;
|
||||
|
||||
if (!userId) {
|
||||
if (!this.isSignedIn()) {
|
||||
return [];
|
||||
}
|
||||
|
||||
|
|
@ -148,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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,44 +4,17 @@ import {
|
|||
getLocalEnvironmentDotFilePath,
|
||||
getStagingEnvironmentDotFilePath,
|
||||
} from "../util/paths";
|
||||
|
||||
export interface HubEnv {
|
||||
DEFAULT_CONTROL_PLANE_PROXY_URL: string;
|
||||
CONTROL_PLANE_URL: string;
|
||||
AUTH_TYPE: string;
|
||||
WORKOS_CLIENT_ID: string;
|
||||
APP_URL: string;
|
||||
}
|
||||
|
||||
export interface OnPremEnv {
|
||||
AUTH_TYPE: "on-prem";
|
||||
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
|
||||
);
|
||||
}
|
||||
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/",
|
||||
};
|
||||
|
|
@ -49,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/",
|
||||
};
|
||||
|
|
@ -57,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/",
|
||||
};
|
||||
|
|
@ -65,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,11 +1,6 @@
|
|||
import crypto from "crypto";
|
||||
|
||||
import { ControlPlaneSessionInfo } from "core/control-plane/client";
|
||||
import {
|
||||
getControlPlaneEnvSync,
|
||||
HubEnv,
|
||||
isHubEnv,
|
||||
} from "core/control-plane/env";
|
||||
import { getControlPlaneEnvSync } from "core/control-plane/env";
|
||||
import fetch from "node-fetch";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import {
|
||||
|
|
@ -22,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";
|
||||
|
|
@ -507,11 +508,7 @@ export async function getControlPlaneSessionInfo(
|
|||
): Promise<ControlPlaneSessionInfo | undefined> {
|
||||
if (!isHubEnv(controlPlaneEnv)) {
|
||||
return {
|
||||
accessToken: "", // TODO: Could make a discriminated union type instead of doing this
|
||||
account: {
|
||||
id: "",
|
||||
label: "",
|
||||
},
|
||||
AUTH_TYPE: AuthType.OnPrem,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -529,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