useOnboarding in getControlPlaneSessionInfo
This commit is contained in:
parent
af3e2f3154
commit
b01a97ebef
8 changed files with 65 additions and 36 deletions
|
|
@ -48,3 +48,6 @@ export const controlPlaneEnv =
|
|||
: process.env.CONTROL_PLANE_ENV === "staging"
|
||||
? STAGING_ENV
|
||||
: PRODUCTION_ENV;
|
||||
|
||||
export const USE_PLATFORM =
|
||||
process.env.CONTROL_PLANE_ENV === "local" ? true : false;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import path from "path";
|
|||
|
||||
import { fetchwithRequestOptions } from "@continuedev/fetch";
|
||||
import ignore from "ignore";
|
||||
import * as URI from "uri-js";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
|
||||
import { CompletionProvider } from "./autocomplete/CompletionProvider";
|
||||
|
|
@ -40,10 +41,9 @@ import { getSymbolsForManyFiles } from "./util/treeSitter";
|
|||
import { TTS } from "./util/tts";
|
||||
|
||||
import { type ContextItemId, type IDE, type IndexingProgressUpdate } from ".";
|
||||
import type { FromCoreProtocol, ToCoreProtocol } from "./protocol";
|
||||
|
||||
import * as URI from "uri-js";
|
||||
import { SYSTEM_PROMPT_DOT_FILE } from "./config/getSystemPromptDotFile";
|
||||
import { USE_PLATFORM } from "./control-plane/env";
|
||||
import type { FromCoreProtocol, ToCoreProtocol } from "./protocol";
|
||||
import type { IMessenger, Message } from "./protocol/messenger";
|
||||
import { localPathToUri } from "./util/pathToUri";
|
||||
|
||||
|
|
@ -102,6 +102,7 @@ export class Core {
|
|||
const ideSettingsPromise = messenger.request("getIdeSettings", undefined);
|
||||
const sessionInfoPromise = messenger.request("getControlPlaneSessionInfo", {
|
||||
silent: true,
|
||||
useOnboarding: USE_PLATFORM,
|
||||
});
|
||||
|
||||
this.controlPlaneClient = new ControlPlaneClient(sessionInfoPromise);
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ export type ToIdeFromWebviewOrCoreProtocol = {
|
|||
|
||||
getGitHubAuthToken: [GetGhTokenArgs, string | undefined];
|
||||
getControlPlaneSessionInfo: [
|
||||
{ silent: boolean },
|
||||
{ silent: boolean; useOnboarding: boolean },
|
||||
ControlPlaneSessionInfo | undefined,
|
||||
];
|
||||
logoutOfControlPlane: [undefined, void];
|
||||
|
|
|
|||
|
|
@ -301,7 +301,7 @@ export class VsCodeExtension {
|
|||
true,
|
||||
);
|
||||
|
||||
const sessionInfo = await getControlPlaneSessionInfo(true);
|
||||
const sessionInfo = await getControlPlaneSessionInfo(true, false);
|
||||
this.webviewProtocolPromise.then(async (webviewProtocol) => {
|
||||
void webviewProtocol.request("didChangeControlPlaneSessionInfo", {
|
||||
sessionInfo,
|
||||
|
|
|
|||
|
|
@ -447,7 +447,10 @@ export class VsCodeMessenger {
|
|||
ide.getGitHubAuthToken(msg.data),
|
||||
);
|
||||
this.onWebviewOrCore("getControlPlaneSessionInfo", async (msg) => {
|
||||
return getControlPlaneSessionInfo(msg.data.silent);
|
||||
return getControlPlaneSessionInfo(
|
||||
msg.data.silent,
|
||||
msg.data.useOnboarding,
|
||||
);
|
||||
});
|
||||
this.onWebviewOrCore("logoutOfControlPlane", async (msg) => {
|
||||
const sessions = await this.workOsAuthProvider.getSessions();
|
||||
|
|
|
|||
|
|
@ -163,12 +163,6 @@ export class WorkOsAuthProvider implements AuthenticationProvider, Disposable {
|
|||
}
|
||||
|
||||
get ideRedirectUri() {
|
||||
const publisher = this.context.extension.packageJSON.publisher;
|
||||
const name = this.context.extension.packageJSON.name;
|
||||
return `${env.uriScheme}://${publisher}.${name}`;
|
||||
}
|
||||
|
||||
get redirectUri() {
|
||||
if (
|
||||
env.uriScheme === "vscode-insiders" ||
|
||||
env.uriScheme === "vscode" ||
|
||||
|
|
@ -179,6 +173,18 @@ export class WorkOsAuthProvider implements AuthenticationProvider, Disposable {
|
|||
url.pathname = `/auth/${env.uriScheme}-redirect`;
|
||||
return url.toString();
|
||||
}
|
||||
const publisher = this.context.extension.packageJSON.publisher;
|
||||
const name = this.context.extension.packageJSON.name;
|
||||
return `${env.uriScheme}://${publisher}.${name}`;
|
||||
}
|
||||
|
||||
public static useOnboardingUri: boolean = false;
|
||||
get redirectUri() {
|
||||
if (WorkOsAuthProvider.useOnboardingUri) {
|
||||
const url = new URL(controlPlaneEnv.APP_URL);
|
||||
url.pathname = `/onboarding/redirect/${env.uriScheme}`;
|
||||
return url.toString();
|
||||
}
|
||||
return this.ideRedirectUri;
|
||||
}
|
||||
|
||||
|
|
@ -407,8 +413,9 @@ export class WorkOsAuthProvider implements AuthenticationProvider, Disposable {
|
|||
try {
|
||||
return await Promise.race([
|
||||
codeExchangePromise.promise,
|
||||
new Promise<string>((_, reject) =>
|
||||
setTimeout(() => reject("Cancelled"), 15 * 60 * 1_000),
|
||||
new Promise<string>(
|
||||
(_, reject) =>
|
||||
setTimeout(() => reject("Cancelled"), 60 * 60 * 1_000), // 60min timeout
|
||||
),
|
||||
promiseFromEvent<any, any>(
|
||||
token.onCancellationRequested,
|
||||
|
|
@ -488,20 +495,29 @@ export class WorkOsAuthProvider implements AuthenticationProvider, Disposable {
|
|||
|
||||
export async function getControlPlaneSessionInfo(
|
||||
silent: boolean,
|
||||
useOnboarding: boolean,
|
||||
): Promise<ControlPlaneSessionInfo | undefined> {
|
||||
const session = await authentication.getSession(
|
||||
controlPlaneEnv.AUTH_TYPE,
|
||||
[],
|
||||
silent ? { silent: true } : { createIfNone: true },
|
||||
);
|
||||
if (!session) {
|
||||
return undefined;
|
||||
try {
|
||||
if (useOnboarding) {
|
||||
WorkOsAuthProvider.useOnboardingUri = true;
|
||||
}
|
||||
|
||||
const session = await authentication.getSession(
|
||||
controlPlaneEnv.AUTH_TYPE,
|
||||
[],
|
||||
silent ? { silent: true } : { createIfNone: true },
|
||||
);
|
||||
if (!session) {
|
||||
return undefined;
|
||||
}
|
||||
return {
|
||||
accessToken: session.accessToken,
|
||||
account: {
|
||||
id: session.account.id,
|
||||
label: session.account.label,
|
||||
},
|
||||
};
|
||||
} finally {
|
||||
WorkOsAuthProvider.useOnboardingUri = false;
|
||||
}
|
||||
return {
|
||||
accessToken: session.accessToken,
|
||||
account: {
|
||||
id: session.account.id,
|
||||
label: session.account.label,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { Listbox, Transition } from "@headlessui/react";
|
||||
import { ChevronUpDownIcon } from "@heroicons/react/24/outline";
|
||||
import { Fragment, useContext } from "react";
|
||||
import { useDispatch } from "react-redux";
|
||||
import styled from "styled-components";
|
||||
import {
|
||||
Button,
|
||||
|
|
@ -9,10 +10,9 @@ import {
|
|||
vscListActiveBackground,
|
||||
vscListActiveForeground,
|
||||
} from ".";
|
||||
import { IdeMessengerContext } from "../context/IdeMessenger";
|
||||
import { useAuth } from "../context/Auth";
|
||||
import { IdeMessengerContext } from "../context/IdeMessenger";
|
||||
import { setSelectedProfileId } from "../redux/slices/sessionSlice";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { setDialogMessage, setShowDialog } from "../redux/slices/uiSlice";
|
||||
|
||||
const StyledListboxOption = styled(Listbox.Option)<{ selected: boolean }>`
|
||||
|
|
@ -46,7 +46,7 @@ export default function AccountDialog() {
|
|||
<span className="text-lightgray mb-4 block text-center">
|
||||
Signed out
|
||||
</span>
|
||||
<Button className="w-full" onClick={login}>
|
||||
<Button className="w-full" onClick={() => login(false)}>
|
||||
Sign in
|
||||
</Button>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ import { IdeMessengerContext } from "./IdeMessenger";
|
|||
interface AuthContextType {
|
||||
session: ControlPlaneSessionInfo | undefined;
|
||||
logout: () => void;
|
||||
login: () => void;
|
||||
login: (useOnboarding: boolean) => void;
|
||||
selectedProfile: ProfileDescription | undefined;
|
||||
profiles: ProfileDescription[];
|
||||
controlServerBetaEnabled: boolean;
|
||||
|
|
@ -49,9 +49,12 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({
|
|||
(state) => state.misc.lastControlServerBetaEnabledStatus,
|
||||
);
|
||||
|
||||
const login = () => {
|
||||
const login = (useOnboarding: boolean) => {
|
||||
ideMessenger
|
||||
.request("getControlPlaneSessionInfo", { silent: false })
|
||||
.request("getControlPlaneSessionInfo", {
|
||||
silent: false,
|
||||
useOnboarding,
|
||||
})
|
||||
.then((result) => {
|
||||
if (result.status === "error") {
|
||||
return;
|
||||
|
|
@ -102,12 +105,15 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({
|
|||
});
|
||||
|
||||
useWebviewListener("signInToControlPlane", async () => {
|
||||
login();
|
||||
login(false);
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
ideMessenger
|
||||
.request("getControlPlaneSessionInfo", { silent: true })
|
||||
.request("getControlPlaneSessionInfo", {
|
||||
silent: true,
|
||||
useOnboarding: false,
|
||||
})
|
||||
.then(
|
||||
(result) => result.status === "success" && setSession(result.content),
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue