diff --git a/core/control-plane/client.ts b/core/control-plane/client.ts index 72523aa08..5a045f4b3 100644 --- a/core/control-plane/client.ts +++ b/core/control-plane/client.ts @@ -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 { IdeSettings, IdeType, ModelDescription } from "../index.js"; import { ControlPlaneSessionInfo, isOnPremSession } from "./AuthTypes.js"; import { getControlPlaneEnv } from "./env.js"; @@ -182,4 +182,24 @@ export class ControlPlaneClient { return null; } } + + public async getModelsAddOnUpgradeUrl( + ide: IdeType, + ): Promise<{ url: string } | null> { + if (!(await this.isSignedIn())) { + return null; + } + + try { + const resp = await this.request( + `ide/get-models-add-on-upgrade-url?ide=${encodeURIComponent(ide)}`, + { + method: "GET", + }, + ); + return (await resp.json()) as { url: string }; + } catch (e) { + return null; + } + } } diff --git a/core/core.ts b/core/core.ts index dfa91e1f7..dc03537a8 100644 --- a/core/core.ts +++ b/core/core.ts @@ -342,6 +342,12 @@ export class Core { return this.configHandler.controlPlaneClient.getFreeTrialStatus(); }); + on("controlPlane/getModelsAddOnUpgradeUrl", async (msg) => { + return this.configHandler.controlPlaneClient.getModelsAddOnUpgradeUrl( + msg.data.ide, + ); + }); + on("mcp/reloadServer", async (msg) => { await MCPManagerSingleton.getInstance().refreshConnection(msg.data.id); }); diff --git a/core/llm/streamChat.ts b/core/llm/streamChat.ts index c899e437f..e56e321a3 100644 --- a/core/llm/streamChat.ts +++ b/core/llm/streamChat.ts @@ -135,6 +135,8 @@ export async function* llmStreamChat( true, ); + void checkForFreeTrialExceeded(configHandler, messenger); + if (!next.done) { throw new Error("Will never happen"); } @@ -142,3 +144,22 @@ export async function* llmStreamChat( return next.value; } } + +async function checkForFreeTrialExceeded( + configHandler: ConfigHandler, + messenger: IMessenger, +) { + try { + const freeTrialStatus = + await configHandler.controlPlaneClient.getFreeTrialStatus(); + if ( + freeTrialStatus && + freeTrialStatus.chatCount && + freeTrialStatus.chatCount > freeTrialStatus.chatLimit + ) { + void messenger.request("freeTrialExceeded", undefined); + } + } catch (error) { + console.error("Error checking free trial status:", error); + } +} diff --git a/core/protocol/core.ts b/core/protocol/core.ts index 1358e0a3a..7251a8497 100644 --- a/core/protocol/core.ts +++ b/core/protocol/core.ts @@ -21,6 +21,7 @@ import { ExperimentalModelRoles, FileSymbolMap, IdeSettings, + IdeType, LLMFullCompletionOptions, ModelDescription, PromptLog, @@ -40,6 +41,7 @@ import { FreeTrialStatus } from "../control-plane/client"; export enum OnboardingModes { PROVIDERS = "Providers", LOCAL = "Local", + MODELS_ADD_ON = "Models Add-On", } export interface ListHistoryOptions { @@ -199,6 +201,10 @@ export type ToCoreFromIdeOrWebviewProtocol = { "clipboardCache/add": [{ content: string }, void]; "controlPlane/openUrl": [{ path: string; orgSlug?: string }, void]; "controlPlane/getFreeTrialStatus": [undefined, FreeTrialStatus | null]; + "controlPlane/getModelsAddOnUpgradeUrl": [ + { ide: IdeType }, + { url: string } | null, + ]; isItemTooBig: [{ item: ContextItemWithId }, boolean]; didChangeControlPlaneSessionInfo: [ { sessionInfo: ControlPlaneSessionInfo | undefined }, diff --git a/core/protocol/ideWebview.ts b/core/protocol/ideWebview.ts index 39ae205a5..074e3837f 100644 --- a/core/protocol/ideWebview.ts +++ b/core/protocol/ideWebview.ts @@ -76,7 +76,7 @@ export type ToWebviewFromIdeProtocol = ToWebviewFromIdeOrCoreProtocol & { setColors: [{ [key: string]: string }, void]; "jetbrains/editorInsetRefresh": [undefined, void]; "jetbrains/isOSREnabled": [boolean, void]; - addApiKey: [undefined, void]; + setupApiKey: [undefined, void]; setupLocalConfig: [undefined, void]; incrementFtc: [undefined, void]; openOnboardingCard: [undefined, void]; diff --git a/core/protocol/passThrough.ts b/core/protocol/passThrough.ts index d1e1a0e8f..622b4e6f5 100644 --- a/core/protocol/passThrough.ts +++ b/core/protocol/passThrough.ts @@ -61,6 +61,7 @@ export const WEBVIEW_TO_CORE_PASS_THROUGH: (keyof ToCoreFromWebviewProtocol)[] = "didChangeSelectedOrg", "tools/call", "controlPlane/openUrl", + "controlPlane/getModelsAddOnUpgradeUrl", "isItemTooBig", "process/markAsBackgrounded", "process/isBackgrounded", @@ -83,4 +84,5 @@ export const CORE_TO_WEBVIEW_PASS_THROUGH: (keyof ToWebviewFromCoreProtocol)[] = "sessionUpdate", "didCloseFiles", "toolCallPartialOutput", + "freeTrialExceeded", ]; diff --git a/core/protocol/webview.ts b/core/protocol/webview.ts index 5ba47e3d4..1a8d40313 100644 --- a/core/protocol/webview.ts +++ b/core/protocol/webview.ts @@ -43,4 +43,5 @@ export type ToWebviewFromIdeOrCoreProtocol = { "jetbrains/setColors": [Record, void]; sessionUpdate: [{ sessionInfo: ControlPlaneSessionInfo | undefined }, void]; toolCallPartialOutput: [{ toolCallId: string; contextItems: any[] }, void]; + freeTrialExceeded: [undefined, void]; }; diff --git a/extensions/vscode/src/webviewProtocol.ts b/extensions/vscode/src/webviewProtocol.ts index 5778371a3..013e10d03 100644 --- a/extensions/vscode/src/webviewProtocol.ts +++ b/extensions/vscode/src/webviewProtocol.ts @@ -129,7 +129,7 @@ export class VsCodeWebviewProtocol .showInformationMessage(message, "Add API Key", "Use Local Model") .then((selection) => { if (selection === "Add API Key") { - this.request("addApiKey", undefined); + this.request("setupApiKey", undefined); } else if (selection === "Use Local Model") { this.request("setupLocalConfig", undefined); } diff --git a/gui/src/components/Layout.tsx b/gui/src/components/Layout.tsx index 811297e81..a046d33ef 100644 --- a/gui/src/components/Layout.tsx +++ b/gui/src/components/Layout.tsx @@ -9,7 +9,7 @@ import { LocalStorageProvider } from "../context/LocalStorage"; import { useWebviewListener } from "../hooks/useWebviewListener"; import { useAppDispatch, useAppSelector } from "../redux/hooks"; import { setCodeToEdit } from "../redux/slices/editState"; -import { setShowDialog } from "../redux/slices/uiSlice"; +import { setDialogMessage, setShowDialog } from "../redux/slices/uiSlice"; import { enterEdit, exitEdit } from "../redux/thunks/edit"; import { saveCurrentSession } from "../redux/thunks/session"; import { fontSize, isMetaEquivalentKeyPressed } from "../util"; @@ -20,7 +20,11 @@ import TextDialog from "./dialogs"; import Footer from "./Footer"; import { LumpProvider } from "./mainInput/Lump/LumpContext"; import { useMainEditor } from "./mainInput/TipTapEditor"; -import { isNewUserOnboarding, useOnboardingCard } from "./OnboardingCard"; +import { + isNewUserOnboarding, + OnboardingCard, + useOnboardingCard, +} from "./OnboardingCard"; import OSRContextMenu from "./OSRContextMenu"; import PostHogPageView from "./PosthogPageView"; @@ -130,17 +134,33 @@ const Layout = () => { ); useWebviewListener( - "openOnboardingCard", + "setupLocalConfig", async () => { - onboardingCard.open(OnboardingModes.PROVIDERS); + onboardingCard.open(OnboardingModes.LOCAL); }, [], ); useWebviewListener( - "setupLocalConfig", + "freeTrialExceeded", async () => { - onboardingCard.open(OnboardingModes.LOCAL); + dispatch(setShowDialog(true)); + onboardingCard.setActiveTab(OnboardingModes.MODELS_ADD_ON); + dispatch( + setDialogMessage( +
+ +
, + ), + ); + }, + [], + ); + + useWebviewListener( + "setupApiKey", + async () => { + onboardingCard.open(OnboardingModes.PROVIDERS); }, [], ); diff --git a/gui/src/components/OnboardingCard/OnboardingCard.tsx b/gui/src/components/OnboardingCard/OnboardingCard.tsx index 1c0569c80..855b1f0e5 100644 --- a/gui/src/components/OnboardingCard/OnboardingCard.tsx +++ b/gui/src/components/OnboardingCard/OnboardingCard.tsx @@ -1,11 +1,13 @@ import { OnboardingModes } from "core/protocol/core"; import { useAppSelector } from "../../redux/hooks"; import { getLocalStorage, setLocalStorage } from "../../util/localStorage"; +import Alert from "../gui/Alert"; import { ReusableCard } from "../ReusableCard"; import { OnboardingCardLanding, OnboardingCardTabs, OnboardingLocalTab, + OnboardingModelsAddOnTab, OnboardingProvidersTab, } from "./components"; import { useOnboardingCard } from "./hooks"; @@ -17,9 +19,13 @@ export interface OnboardingCardState { interface OnboardingCardProps { isDialog?: boolean; + showFreeTrialExceededAlert?: boolean; } -export function OnboardingCard({ isDialog }: OnboardingCardProps) { +export function OnboardingCard({ + isDialog, + showFreeTrialExceededAlert, +}: OnboardingCardProps) { const { activeTab, close, setActiveTab } = useOnboardingCard(); const config = useAppSelector((store) => store.config.config); @@ -33,6 +39,8 @@ export function OnboardingCard({ isDialog }: OnboardingCardProps) { return ; case OnboardingModes.LOCAL: return ; + case OnboardingModes.MODELS_ADD_ON: + return ; default: return ; } @@ -45,7 +53,24 @@ export function OnboardingCard({ isDialog }: OnboardingCardProps) { onClose={close} testId="onboarding-card" > - + {showFreeTrialExceededAlert && ( +
+ +

+ Free trial completed +

+ + To keep using Continue, select an option below to setup your + models + +
+
+ )} + {renderTabContent()} ); diff --git a/gui/src/components/OnboardingCard/components/OnboardingCardLanding.tsx b/gui/src/components/OnboardingCard/components/OnboardingCardLanding.tsx index efef32934..3af954188 100644 --- a/gui/src/components/OnboardingCard/components/OnboardingCardLanding.tsx +++ b/gui/src/components/OnboardingCard/components/OnboardingCardLanding.tsx @@ -5,8 +5,8 @@ import { IdeMessengerContext } from "../../../context/IdeMessenger"; import { selectCurrentOrg } from "../../../redux"; import { useAppSelector } from "../../../redux/hooks"; import { hasPassedFTL } from "../../../util/freeTrial"; -import ContinueLogo from "../../gui/ContinueLogo"; import { ToolTip } from "../../gui/Tooltip"; +import ContinueLogo from "../../svg/ContinueLogo"; import { useOnboardingCard } from "../hooks"; export function OnboardingCardLanding({ diff --git a/gui/src/components/OnboardingCard/components/OnboardingCardTabs.tsx b/gui/src/components/OnboardingCard/components/OnboardingCardTabs.tsx index 07de1e42e..5c3eb4829 100644 --- a/gui/src/components/OnboardingCard/components/OnboardingCardTabs.tsx +++ b/gui/src/components/OnboardingCard/components/OnboardingCardTabs.tsx @@ -1,26 +1,64 @@ import { KeyIcon } from "@heroicons/react/24/outline"; import { OnboardingModes } from "core/protocol/core"; +import ContinueSignet from "../../svg/ContinueSignet"; +import OllamaLogo from "../../svg/OllamaLogo"; interface OnboardingCardTabsProps { - /** The currently active tab */ activeTab: OnboardingModes; - /** Callback function called when a tab is clicked */ onTabClick: (tabName: OnboardingModes) => void; + showFreeTrialExceededAlert?: boolean; } -const getTabIcon = (tabTitle: OnboardingModes) => { +const renderTabButton = ( + tabTitle: OnboardingModes, + index: number, + activeTab: OnboardingModes, + onTabClick: (tabName: OnboardingModes) => void, +) => { + const baseButtonClass = `text-foreground -mb-px cursor-pointer rounded-t-sm border-none bg-transparent py-2 font-medium hover:brightness-125 focus:outline-none ${index === 0 ? "pl-1.5 pr-3" : "px-3"} ${activeTab === tabTitle ? "brightness-125" : "brightness-75"}`; + if (tabTitle === OnboardingModes.PROVIDERS) { - return ; - } - if (tabTitle === OnboardingModes.LOCAL) { return ( - Ollama + ); } + + if (tabTitle === OnboardingModes.LOCAL) { + return ( + + ); + } + + if (tabTitle === OnboardingModes.MODELS_ADD_ON) { + return ( + + ); + } + return null; }; @@ -30,28 +68,34 @@ const getTabIcon = (tabTitle: OnboardingModes) => { export function OnboardingCardTabs({ activeTab, onTabClick, + showFreeTrialExceededAlert, }: OnboardingCardTabsProps) { + /** + * When users initially install, we only render these tabs after they've + * declined the free trial, so we show the upgrade tab last since they've + * indicated they want don't want to use the Hub. + * + * If `showFreeTrialExceededAlert` is true, they've used the Hub, so show + * upgrade first. + */ + const tabs = showFreeTrialExceededAlert + ? [ + OnboardingModes.MODELS_ADD_ON, + OnboardingModes.PROVIDERS, + OnboardingModes.LOCAL, + ] + : [ + OnboardingModes.PROVIDERS, + OnboardingModes.LOCAL, + OnboardingModes.MODELS_ADD_ON, + ]; return (
- {Object.values(OnboardingModes).map((tabTitle) => { - const isActive = activeTab === tabTitle; - - return ( - - ); - })} + {tabs.map((tabTitle, index) => + renderTabButton(tabTitle, index, activeTab, onTabClick), + )}
@@ -61,7 +105,7 @@ export function OnboardingCardTabs({ value={activeTab} onChange={(e) => onTabClick(e.target.value as OnboardingModes)} > - {Object.values(OnboardingModes).map((tabTitle) => { + {tabs.map((tabTitle) => { return (