jb-onboarding flow

This commit is contained in:
Nate 2025-01-25 12:21:58 -08:00
parent 1a21a287c5
commit e23e9c9a71
12 changed files with 103 additions and 64 deletions

View file

@ -4,13 +4,14 @@ import { getControlPlaneEnv } from "../env";
export async function getAuthUrlForTokenPage(
ideSettingsPromise: Promise<IdeSettings>,
useOnboarding: boolean,
): Promise<string> {
const env = await getControlPlaneEnv(ideSettingsPromise);
const url = new URL("https://api.workos.com/user_management/authorize");
const params = {
response_type: "code",
client_id: env.WORKOS_CLIENT_ID,
redirect_uri: `${env.APP_URL}tokens/callback`,
redirect_uri: `${env.APP_URL}tokens/${useOnboarding ? "onboarding-" : ""}callback`,
// redirect_uri: "http://localhost:3000/tokens/callback",
state: uuidv4(),
provider: "authkit",

View file

@ -873,7 +873,10 @@ export class Core {
this.configHandler.updateControlPlaneSessionInfo(msg.data.sessionInfo);
});
on("auth/getAuthUrl", async (msg) => {
const url = await getAuthUrlForTokenPage(ideSettingsPromise);
const url = await getAuthUrlForTokenPage(
ideSettingsPromise,
msg.data.useOnboarding,
);
return { url };
});

View file

@ -185,7 +185,7 @@ export type ToCoreFromIdeOrWebviewProtocol = {
"profiles/switch": [{ id: string }, undefined];
"auth/getAuthUrl": [undefined, { url: string }];
"auth/getAuthUrl": [{ useOnboarding: boolean }, { url: string }];
"tools/call": [
{ toolCall: ToolCall; selectedModelTitle: string },
{ contextItems: ContextItem[] },

View file

@ -196,7 +196,7 @@ class ContinuePluginStartupActivity : StartupActivity, DumbAware {
connection.subscribe(AuthListener.TOPIC, object : AuthListener {
override fun startAuthFlow() {
authService.startAuthFlow(project)
authService.startAuthFlow(project, false)
}
override fun handleUpdatedSessionInfo(sessionInfo: ControlPlaneSessionInfo?) {

View file

@ -7,7 +7,8 @@ import javax.swing.JComponent
import javax.swing.JPanel
import java.awt.BorderLayout
class ContinueAuthDialog(private val onTokenEntered: (String) -> Unit) : DialogWrapper(true) {
class ContinueAuthDialog(private val useOnboarding: Boolean, private val onTokenEntered: (String) -> Unit) :
DialogWrapper(true) {
private val tokenField = JBTextField()
init {
@ -17,7 +18,9 @@ class ContinueAuthDialog(private val onTokenEntered: (String) -> Unit) : DialogW
override fun createCenterPanel(): JComponent {
val panel = JPanel(BorderLayout())
panel.add(JBLabel("Please enter your Continue authentication token:"), BorderLayout.NORTH)
val message =
if (useOnboarding) "After onboarding you will be shown an authentication token. Please enter it here:" else "Please enter your Continue authentication token:"
panel.add(JBLabel(message), BorderLayout.NORTH)
panel.add(tokenField, BorderLayout.CENTER)
return panel
}

View file

@ -33,8 +33,18 @@ class ContinueAuthService {
private const val REFRESH_TOKEN_KEY = "ContinueRefreshToken"
private const val ACCOUNT_ID_KEY = "ContinueAccountId"
private const val ACCOUNT_LABEL_KEY = "ContinueAccountLabel"
private const val CONTROL_PLANE_URL = "https://control-plane-api-service-i3dqylpbqa-uc.a.run.app"
// private const val CONTROL_PLANE_URL = "http://localhost:3001"
}
private fun getControlPlaneUrl(): String {
val env = service<ContinueExtensionSettings>().continueState.continueTestEnvironment;
when (env) {
"none" -> return "https://control-plane-api-service-i3dqylpbqa-uc.a.run.app"
"local" -> return "http://localhost:3001"
"production" -> return "https://api.continue.dev"
"test" -> return "https://api-test.continue.dev"
}
return "https://control-plane-api-service-i3dqylpbqa-uc.a.run.app"
}
init {
@ -44,13 +54,13 @@ class ContinueAuthService {
}
}
fun startAuthFlow(project: Project) {
fun startAuthFlow(project: Project, useOnboarding: Boolean) {
// Open login page
openSignInPage(project)
openSignInPage(project, useOnboarding)
// Open a dialog where the user should paste their sign-in token
ApplicationManager.getApplication().invokeLater {
val dialog = ContinueAuthDialog() { token ->
val dialog = ContinueAuthDialog(useOnboarding) { token ->
// Store the token
updateRefreshToken(token)
}
@ -111,7 +121,7 @@ class ContinueAuthService {
private suspend fun refreshToken(refreshToken: String) = withContext(Dispatchers.IO) {
val client = OkHttpClient()
val url = URL(CONTROL_PLANE_URL).toURI().resolve("/auth/refresh").toURL()
val url = URL(getControlPlaneUrl()).toURI().resolve("/auth/refresh").toURL()
val jsonBody = mapOf("refreshToken" to refreshToken)
val jsonString = Gson().toJson(jsonBody)
val requestBody = jsonString.toRequestBody("application/json".toMediaType())
@ -132,9 +142,13 @@ class ContinueAuthService {
}
private fun openSignInPage(project: Project) {
private fun openSignInPage(project: Project, useOnboarding: Boolean) {
val coreMessenger = project.service<ContinuePluginService>().coreMessenger
coreMessenger?.request("auth/getAuthUrl", null, null) { response ->
coreMessenger?.request(
"auth/getAuthUrl", mapOf(
"useOnboarding" to useOnboarding
), null
) { response ->
val authUrl = ((response as? Map<*, *>)?.get("content") as? Map<*, *>)?.get("url") as? String
if (authUrl != null) {
// Open the auth URL in the browser

View file

@ -97,7 +97,7 @@ class IdeProtocolClient(
val sessionInfo = authService.loadControlPlaneSessionInfo()
respond(sessionInfo)
} else {
authService.startAuthFlow(project)
authService.startAuthFlow(project, params.useOnboarding)
respond(null)
}
}

View file

@ -93,6 +93,7 @@ class IntelliJIDE(
remoteConfigSyncPeriod = settings.continueState.remoteConfigSyncPeriod,
userToken = settings.continueState.userToken ?: "",
enableControlServerBeta = settings.continueState.enableContinueTeamsBeta,
continueTestEnvironment = settings.continueState.continueTestEnvironment,
pauseCodebaseIndexOnStart = false, // TODO: Needs to be implemented
enableDebugLogs = false // TODO: Needs to be implemented
)

View file

@ -2,7 +2,7 @@ package com.github.continuedev.continueintellijextension.protocol
import com.github.continuedev.continueintellijextension.*
data class GetControlPlaneSessionInfoParams(val silent: Boolean)
data class GetControlPlaneSessionInfoParams(val silent: Boolean, val useOnboarding: Boolean)
data class WriteFileParams(
val path: String,

View file

@ -2,6 +2,7 @@ package com.github.continuedev.continueintellijextension.services
import com.github.continuedev.continueintellijextension.constants.getConfigJsPath
import com.github.continuedev.continueintellijextension.constants.getConfigJsonPath
import com.intellij.execution.target.value.constant
import com.intellij.openapi.application.ApplicationInfo
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.*
@ -33,6 +34,7 @@ class ContinueSettingsComponent : DumbAware {
val enableOSR: JCheckBox = JCheckBox("Enable Off-Screen Rendering")
val displayEditorTooltip: JCheckBox = JCheckBox("Display Editor Tooltip")
val showIDECompletionSideBySide: JCheckBox = JCheckBox("Show IDE completions side-by-side")
val continueTestEnvironment: JComboBox<String> = JComboBox(arrayOf("none", "production", "test", "local"))
init {
val constraints = GridBagConstraints()
@ -66,6 +68,11 @@ class ContinueSettingsComponent : DumbAware {
constraints.gridy++
panel.add(showIDECompletionSideBySide, constraints)
constraints.gridy++
panel.add(JLabel("Continue test environment"), constraints)
constraints.gridy++
constraints.gridy++
panel.add(continueTestEnvironment, constraints)
constraints.gridy++
// Add a "filler" component that takes up all remaining vertical space
constraints.weighty = 1.0
@ -98,6 +105,7 @@ open class ContinueExtensionSettings : PersistentStateComponent<ContinueExtensio
var enableOSR: Boolean = shouldRenderOffScreen()
var displayEditorTooltip: Boolean = true
var showIDECompletionSideBySide: Boolean = false
var continueTestEnvironment: String = "none"
}
var continueState: ContinueState = ContinueState()
@ -211,7 +219,8 @@ class ContinueExtensionConfigurable : Configurable {
mySettingsComponent?.enableContinueTeamsBeta?.isSelected != settings.continueState.enableContinueTeamsBeta ||
mySettingsComponent?.enableOSR?.isSelected != settings.continueState.enableOSR ||
mySettingsComponent?.displayEditorTooltip?.isSelected != settings.continueState.displayEditorTooltip ||
mySettingsComponent?.showIDECompletionSideBySide?.isSelected != settings.continueState.showIDECompletionSideBySide
mySettingsComponent?.showIDECompletionSideBySide?.isSelected != settings.continueState.showIDECompletionSideBySide ||
mySettingsComponent?.continueTestEnvironment?.selectedItem.toString() != settings.continueState.continueTestEnvironment
return modified
}
@ -227,6 +236,8 @@ class ContinueExtensionConfigurable : Configurable {
settings.continueState.displayEditorTooltip = mySettingsComponent?.displayEditorTooltip?.isSelected ?: true
settings.continueState.showIDECompletionSideBySide =
mySettingsComponent?.showIDECompletionSideBySide?.isSelected ?: false
settings.continueState.continueTestEnvironment =
mySettingsComponent?.continueTestEnvironment?.selectedItem.toString()
ApplicationManager.getApplication().messageBus.syncPublisher(SettingsListener.TOPIC)
.settingsUpdated(settings.continueState)
@ -244,6 +255,7 @@ class ContinueExtensionConfigurable : Configurable {
mySettingsComponent?.displayEditorTooltip?.isSelected = settings.continueState.displayEditorTooltip
mySettingsComponent?.showIDECompletionSideBySide?.isSelected =
settings.continueState.showIDECompletionSideBySide
mySettingsComponent?.continueTestEnvironment?.selectedItem = settings.continueState.continueTestEnvironment
ContinueExtensionSettings.instance.addRemoteSyncJob()
}

View file

@ -88,7 +88,8 @@ data class IdeSettings(
val userToken: String,
val enableControlServerBeta: Boolean,
val pauseCodebaseIndexOnStart: Boolean,
val enableDebugLogs: Boolean
val enableDebugLogs: Boolean,
val continueTestEnvironment: String
)
data class ContinueRcJson(

View file

@ -53,7 +53,7 @@ export default function AccountDialog() {
);
}
if (!controlServerBetaEnabled) {
if (!controlServerBetaEnabled && !session) {
return (
<div className="p-4 pt-0">
<h1 className="mb-1 text-2xl">Account</h1>
@ -89,53 +89,57 @@ export default function AccountDialog() {
</span>
</div>
<div className="w-full">
<span className="mb-1 block text-sm">Current workspace</span>
{controlServerBetaEnabled && (
<div className="w-full">
<span className="mb-1 block text-sm">Current workspace</span>
<Listbox value={"local"} onChange={changeProfileId}>
{({ open }) => (
<div className="relative w-full">
<Listbox.Button className="border-vsc-input-border bg-vsc-background hover:bg-vsc-input-background text-vsc-foreground relative m-0 flex w-full cursor-pointer items-center justify-between rounded-md border border-solid px-3 py-2 text-left">
<span className="lines lines-1">{selectedProfile?.title}</span>
<div className="pointer-events-none flex items-center">
<ChevronUpDownIcon className="h-5 w-5" aria-hidden="true" />
</div>
</Listbox.Button>
<Listbox value={"local"} onChange={changeProfileId}>
{({ open }) => (
<div className="relative w-full">
<Listbox.Button className="border-vsc-input-border bg-vsc-background hover:bg-vsc-input-background text-vsc-foreground relative m-0 flex w-full cursor-pointer items-center justify-between rounded-md border border-solid px-3 py-2 text-left">
<span className="lines lines-1">
{selectedProfile?.title}
</span>
<div className="pointer-events-none flex items-center">
<ChevronUpDownIcon className="h-5 w-5" aria-hidden="true" />
</div>
</Listbox.Button>
<Transition
as={Fragment}
show={open}
enter="transition ease-out duration-100"
enterFrom="transform opacity-0 scale-95"
enterTo="transform opacity-100 scale-100"
leave="transition ease-in duration-75"
leaveFrom="transform opacity-100 scale-100"
leaveTo="transform opacity-0 scale-95"
>
<Listbox.Options className="bg-vsc-background max-h-80vh absolute mt-0.5 w-full overflow-y-scroll rounded-sm p-0">
{profiles.map((option, idx) => (
<StyledListboxOption
key={idx}
selected={selectedProfile?.id === option.id}
value={option.id}
className="w-full"
>
<span className="lines lines-1 relative flex h-5 items-center justify-between gap-3 pr-2 text-xs">
{option.title}
</span>
</StyledListboxOption>
))}
{profiles.length === 0 && (
<div className="px-4 py-2">
<i>No workspaces found</i>
</div>
)}
</Listbox.Options>
</Transition>
</div>
)}
</Listbox>
</div>
<Transition
as={Fragment}
show={open}
enter="transition ease-out duration-100"
enterFrom="transform opacity-0 scale-95"
enterTo="transform opacity-100 scale-100"
leave="transition ease-in duration-75"
leaveFrom="transform opacity-100 scale-100"
leaveTo="transform opacity-0 scale-95"
>
<Listbox.Options className="bg-vsc-background max-h-80vh absolute mt-0.5 w-full overflow-y-scroll rounded-sm p-0">
{profiles.map((option, idx) => (
<StyledListboxOption
key={idx}
selected={selectedProfile?.id === option.id}
value={option.id}
className="w-full"
>
<span className="lines lines-1 relative flex h-5 items-center justify-between gap-3 pr-2 text-xs">
{option.title}
</span>
</StyledListboxOption>
))}
{profiles.length === 0 && (
<div className="px-4 py-2">
<i>No workspaces found</i>
</div>
)}
</Listbox.Options>
</Transition>
</div>
)}
</Listbox>
</div>
)}
<div className="flex w-full justify-end gap-2">
<SecondaryButton className="w-auto" onClick={logout}>