Merge pull request #3796 from continuedev/dallin/free-trial-over
Free Trial Over Dialog and Onboarding Card
This commit is contained in:
commit
d4b72ca0ce
21 changed files with 203 additions and 105 deletions
|
|
@ -55,6 +55,7 @@ import {
|
|||
import { usePlatform } from "./control-plane/flags";
|
||||
import type { FromCoreProtocol, ToCoreProtocol } from "./protocol";
|
||||
import type { IMessenger, Message } from "./protocol/messenger";
|
||||
import { controlPlaneEnv } from "./control-plane/env";
|
||||
|
||||
export class Core {
|
||||
// implements IMessenger<ToCoreProtocol, FromCoreProtocol>
|
||||
|
|
@ -294,6 +295,13 @@ export class Core {
|
|||
addContextProvider(msg.data);
|
||||
});
|
||||
|
||||
on("controlPlane/openUrl", async (msg) => {
|
||||
await this.messenger.request(
|
||||
"openUrl",
|
||||
`${controlPlaneEnv.APP_URL}${msg.data.path}`,
|
||||
);
|
||||
});
|
||||
|
||||
// Context providers
|
||||
on("context/addDocs", async (msg) => {
|
||||
void this.docsService.indexAndAdd(msg.data);
|
||||
|
|
|
|||
|
|
@ -191,4 +191,5 @@ export type ToCoreFromIdeOrWebviewProtocol = {
|
|||
{ contextItems: ContextItem[] },
|
||||
];
|
||||
"clipboardCache/add": [{ content: string }, void];
|
||||
"controlPlane/openUrl": [{ path: string }, void];
|
||||
};
|
||||
|
|
|
|||
|
|
@ -58,6 +58,7 @@ export const WEBVIEW_TO_CORE_PASS_THROUGH: (keyof ToCoreFromWebviewProtocol)[] =
|
|||
"profiles/switch",
|
||||
"didChangeSelectedProfile",
|
||||
"tools/call",
|
||||
"controlPlane/openUrl",
|
||||
];
|
||||
|
||||
// Message types to pass through from core to webview
|
||||
|
|
|
|||
|
|
@ -116,6 +116,7 @@ class MessageTypes {
|
|||
"profiles/switch",
|
||||
"didChangeSelectedProfile",
|
||||
"tools/call",
|
||||
"controlPlane/openUrl"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
import { useAppSelector } from "../redux/hooks";
|
||||
import { selectDefaultModel } from "../redux/slices/configSlice";
|
||||
import { FREE_TRIAL_LIMIT_REQUESTS } from "../util/freeTrial";
|
||||
import { getLocalStorage } from "../util/localStorage";
|
||||
import FreeTrialProgressBar from "./loaders/FreeTrialProgressBar";
|
||||
|
||||
function Footer() {
|
||||
|
|
@ -10,7 +11,7 @@ function Footer() {
|
|||
return (
|
||||
<footer className="flex flex-col border-0 border-t border-solid border-t-zinc-700 px-2 py-2">
|
||||
<FreeTrialProgressBar
|
||||
completed={parseInt(localStorage.getItem("ftc") || "0")}
|
||||
completed={getLocalStorage("ftc") ?? 0}
|
||||
total={FREE_TRIAL_LIMIT_REQUESTS}
|
||||
/>
|
||||
</footer>
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ import {
|
|||
newSession,
|
||||
} from "../redux/slices/sessionSlice";
|
||||
import { getFontSize, isMetaEquivalentKeyPressed } from "../util";
|
||||
import { getLocalStorage, setLocalStorage } from "../util/localStorage";
|
||||
import { ROUTES } from "../util/navigation";
|
||||
import TextDialog from "./dialogs";
|
||||
import Footer from "./Footer";
|
||||
|
|
@ -23,6 +22,7 @@ import AccountDialog from "./AccountDialog";
|
|||
import { AuthProvider } from "../context/Auth";
|
||||
import { exitEditMode } from "../redux/thunks";
|
||||
import { loadLastSession, saveCurrentSession } from "../redux/thunks/session";
|
||||
import { incrementFreeTrialCount } from "../util/freeTrial";
|
||||
|
||||
const LayoutTopDiv = styled(CustomScrollbarDiv)`
|
||||
height: 100%;
|
||||
|
|
@ -150,12 +150,7 @@ const Layout = () => {
|
|||
useWebviewListener(
|
||||
"incrementFtc",
|
||||
async () => {
|
||||
const u = getLocalStorage("ftc");
|
||||
if (u) {
|
||||
setLocalStorage("ftc", u + 1);
|
||||
} else {
|
||||
setLocalStorage("ftc", 1);
|
||||
}
|
||||
incrementFreeTrialCount();
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
|
|
|||
|
|
@ -20,7 +20,11 @@ export interface OnboardingCardState {
|
|||
activeTab?: TabTitle;
|
||||
}
|
||||
|
||||
export function OnboardingCard() {
|
||||
interface OnboardingCardProps {
|
||||
isDialog?: boolean;
|
||||
}
|
||||
|
||||
export function OnboardingCard({ isDialog }: OnboardingCardProps) {
|
||||
const onboardingCard = useOnboardingCard();
|
||||
|
||||
function renderTabContent() {
|
||||
|
|
@ -49,9 +53,11 @@ export function OnboardingCard() {
|
|||
activeTab={onboardingCard.activeTab || "Best"}
|
||||
onTabClick={onboardingCard.setActiveTab}
|
||||
/>
|
||||
<CloseButton onClick={onboardingCard.close}>
|
||||
<XMarkIcon className="mt-1.5 hidden h-5 w-5 hover:brightness-125 sm:flex" />
|
||||
</CloseButton>
|
||||
{!isDialog && (
|
||||
<CloseButton onClick={() => onboardingCard.close()}>
|
||||
<XMarkIcon className="mt-1.5 hidden h-5 w-5 hover:brightness-125 sm:flex" />
|
||||
</CloseButton>
|
||||
)}
|
||||
<div className="content py-4">{renderTabContent()}</div>
|
||||
</StyledCard>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -9,11 +9,15 @@ import { useSubmitOnboarding } from "../hooks";
|
|||
import JetBrainsFetchGitHubTokenDialog from "./JetBrainsFetchGitHubTokenDialog";
|
||||
import { setDefaultModel } from "../../../redux/slices/configSlice";
|
||||
|
||||
function QuickstartSubmitButton() {
|
||||
interface QuickstartSubmitButtonProps {
|
||||
isDialog?: boolean;
|
||||
}
|
||||
|
||||
function QuickstartSubmitButton({ isDialog }: QuickstartSubmitButtonProps) {
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
const dispatch = useDispatch();
|
||||
|
||||
const { submitOnboarding } = useSubmitOnboarding("Quickstart");
|
||||
const { submitOnboarding } = useSubmitOnboarding("Quickstart", isDialog);
|
||||
|
||||
function onComplete() {
|
||||
submitOnboarding();
|
||||
|
|
|
|||
|
|
@ -1,7 +1,11 @@
|
|||
import { useDispatch } from "react-redux";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { TabTitle } from "../components/OnboardingCardTabs";
|
||||
import { setOnboardingCard } from "../../../redux/slices/uiSlice";
|
||||
import {
|
||||
setDialogMessage,
|
||||
setOnboardingCard,
|
||||
setShowDialog,
|
||||
} from "../../../redux/slices/uiSlice";
|
||||
import { OnboardingCardState } from "..";
|
||||
import { getLocalStorage, setLocalStorage } from "../../../util/localStorage";
|
||||
import { useAppDispatch, useAppSelector } from "../../../redux/hooks";
|
||||
|
|
@ -12,7 +16,7 @@ export interface UseOnboardingCard {
|
|||
activeTab: OnboardingCardState["activeTab"];
|
||||
setActiveTab: (tab: TabTitle) => void;
|
||||
open: (tab: TabTitle) => void;
|
||||
close: () => void;
|
||||
close: (isDialog?: boolean) => void;
|
||||
}
|
||||
|
||||
export function useOnboardingCard(): UseOnboardingCard {
|
||||
|
|
@ -38,20 +42,16 @@ export function useOnboardingCard(): UseOnboardingCard {
|
|||
|
||||
async function open(tab: TabTitle) {
|
||||
navigate("/");
|
||||
|
||||
// Used to clear the chat panel before showing onboarding card
|
||||
dispatch(
|
||||
saveCurrentSession({
|
||||
openNewSession: true,
|
||||
}),
|
||||
);
|
||||
|
||||
dispatch(setOnboardingCard({ show: true, activeTab: tab }));
|
||||
}
|
||||
|
||||
function close() {
|
||||
function close(isDialog = false) {
|
||||
setLocalStorage("hasDismissedOnboardingCard", true);
|
||||
dispatch(setOnboardingCard({ show: false }));
|
||||
if (isDialog) {
|
||||
dispatch(setDialogMessage(undefined));
|
||||
dispatch(setShowDialog(false));
|
||||
}
|
||||
}
|
||||
|
||||
function setActiveTab(tab: TabTitle) {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import { OnboardingModes } from "core/protocol/core";
|
|||
import { useTutorialCard } from "../../../hooks/useTutorialCard";
|
||||
import { useOnboardingCard } from "./useOnboardingCard";
|
||||
|
||||
export function useSubmitOnboarding(mode: OnboardingModes) {
|
||||
export function useSubmitOnboarding(mode: OnboardingModes, isDialog = false) {
|
||||
const posthog = usePostHog();
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
const { openTutorialCard } = useTutorialCard();
|
||||
|
|
@ -16,7 +16,7 @@ export function useSubmitOnboarding(mode: OnboardingModes) {
|
|||
const onboardingStatus = getLocalStorage("onboardingStatus");
|
||||
|
||||
// Always close the onboarding card and update config.json
|
||||
closeOnboardingCard();
|
||||
closeOnboardingCard(isDialog);
|
||||
ideMessenger.post("completeOnboarding", {
|
||||
mode,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -23,7 +23,11 @@ export interface OnboardingCardState {
|
|||
activeTab?: TabTitle;
|
||||
}
|
||||
|
||||
export function PlatformOnboardingCard() {
|
||||
interface OnboardingCardProps {
|
||||
isDialog: boolean;
|
||||
}
|
||||
|
||||
export function PlatformOnboardingCard({ isDialog }: OnboardingCardProps) {
|
||||
const onboardingCard = useOnboardingCard();
|
||||
|
||||
if (getLocalStorage("onboardingStatus") === undefined) {
|
||||
|
|
@ -34,13 +38,18 @@ export function PlatformOnboardingCard() {
|
|||
|
||||
return (
|
||||
<StyledCard className="xs:py-4 xs:px-4 relative px-2 py-3">
|
||||
<CloseButton onClick={onboardingCard.close}>
|
||||
<XMarkIcon className="mt-1.5 hidden h-5 w-5 hover:brightness-125 sm:flex" />
|
||||
</CloseButton>
|
||||
{!isDialog && (
|
||||
<CloseButton onClick={() => onboardingCard.close()}>
|
||||
<XMarkIcon className="mt-1.5 hidden h-5 w-5 hover:brightness-125 sm:flex" />
|
||||
</CloseButton>
|
||||
)}
|
||||
<div className="content py-4">
|
||||
<div className="flex h-full w-full items-center justify-center">
|
||||
{currentTab === "main" ? (
|
||||
<MainTab onRemainLocal={() => setCurrentTab("local")} />
|
||||
<MainTab
|
||||
onRemainLocal={() => setCurrentTab("local")}
|
||||
isDialog={isDialog}
|
||||
/>
|
||||
) : (
|
||||
<div className="mt-4">
|
||||
<Alert type="info">
|
||||
|
|
@ -53,7 +62,7 @@ export function PlatformOnboardingCard() {
|
|||
</a>
|
||||
</Alert>
|
||||
|
||||
<OnboardingLocalTab />
|
||||
<OnboardingLocalTab isDialog={isDialog} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,26 +0,0 @@
|
|||
import { useAuth } from "../../../../context/Auth";
|
||||
import ContinueLogo from "../../../gui/ContinueLogo";
|
||||
import { useOnboardingCard } from "../../hooks";
|
||||
|
||||
export default function LocalTab() {
|
||||
const onboardingCard = useOnboardingCard();
|
||||
const auth = useAuth();
|
||||
|
||||
return (
|
||||
<div className="xs:px-0 flex w-full max-w-full flex-col items-center justify-center px-4 text-center">
|
||||
<div className="xs:flex hidden">
|
||||
<ContinueLogo height={75} />
|
||||
</div>
|
||||
|
||||
<p className="xs:w-3/4 w-full text-sm">
|
||||
Log in to quickly build your first custom AI code assistant
|
||||
</p>
|
||||
|
||||
{/* <p className="xs:w-3/4 w-full text-sm">
|
||||
To prevent abuse, we'll ask you to sign in to GitHub.
|
||||
</p> */}
|
||||
|
||||
<div className="mt-4 w-full"></div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
@ -3,47 +3,78 @@ import { Button, ButtonSubtext } from "../../..";
|
|||
import { useAuth } from "../../../../context/Auth";
|
||||
import ContinueLogo from "../../../gui/ContinueLogo";
|
||||
import { useOnboardingCard } from "../../hooks";
|
||||
import { hasPassedFTL } from "../../../../util/freeTrial";
|
||||
import { useContext } from "react";
|
||||
import { IdeMessengerContext } from "../../../../context/IdeMessenger";
|
||||
|
||||
export default function MainTab({
|
||||
onRemainLocal,
|
||||
isDialog,
|
||||
}: {
|
||||
onRemainLocal: () => void;
|
||||
isDialog: boolean;
|
||||
}) {
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
const onboardingCard = useOnboardingCard();
|
||||
const auth = useAuth();
|
||||
|
||||
function onGetStarted() {
|
||||
auth.login(true).then((success) => {
|
||||
if (success) {
|
||||
onboardingCard.close();
|
||||
onboardingCard.close(isDialog);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function openPastFreeTrialOnboarding() {
|
||||
ideMessenger.post("controlPlane/openUrl", {
|
||||
path: "setup-models",
|
||||
});
|
||||
onboardingCard.close(isDialog);
|
||||
}
|
||||
|
||||
const pastFreeTrialLimit = hasPassedFTL();
|
||||
|
||||
return (
|
||||
<div className="xs:px-0 flex w-full max-w-full flex-col items-center justify-center px-4 text-center">
|
||||
<div className="xs:flex hidden">
|
||||
<ContinueLogo height={75} />
|
||||
</div>
|
||||
|
||||
<p className="xs:w-3/4 w-full text-sm">
|
||||
Log in to quickly build your first custom AI code assistant
|
||||
</p>
|
||||
{pastFreeTrialLimit ? (
|
||||
<>
|
||||
<p className="xs:w-3/4 w-full text-sm">
|
||||
You've reached the free trial limit. Visit the Continue Platform to
|
||||
select a Coding Assistant.
|
||||
</p>
|
||||
<Button
|
||||
onClick={openPastFreeTrialOnboarding}
|
||||
className="mt-4 grid w-full grid-flow-col items-center gap-2"
|
||||
>
|
||||
Go to Continue Platform
|
||||
</Button>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<p className="xs:w-3/4 w-full text-sm">
|
||||
Log in to quickly build your first custom AI code assistant
|
||||
</p>
|
||||
|
||||
<div className="mt-4 w-full">
|
||||
<Button
|
||||
onClick={onGetStarted}
|
||||
className="grid w-full grid-flow-col items-center gap-2"
|
||||
>
|
||||
Get started
|
||||
</Button>
|
||||
<ButtonSubtext onClick={onRemainLocal}>
|
||||
<div className="mt-4 flex cursor-pointer items-center justify-center gap-1">
|
||||
<span>Or, remain local</span>
|
||||
<ChevronRightIcon className="h-3 w-3" />
|
||||
</div>
|
||||
</ButtonSubtext>
|
||||
</div>
|
||||
<Button
|
||||
onClick={onGetStarted}
|
||||
className="mt-4 grid w-full grid-flow-col items-center gap-2"
|
||||
>
|
||||
Get started
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
|
||||
<ButtonSubtext onClick={onRemainLocal}>
|
||||
<div className="mt-4 flex cursor-pointer items-center justify-center gap-1">
|
||||
<span>Or, remain local</span>
|
||||
<ChevronRightIcon className="h-3 w-3" />
|
||||
</div>
|
||||
</ButtonSubtext>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,12 @@ import BestExperienceConfigForm from "../components/BestExperienceConfigForm";
|
|||
import ProviderAlert from "../components/ProviderAlert";
|
||||
import { useSubmitOnboarding } from "../hooks";
|
||||
|
||||
function OnboardingBestTab() {
|
||||
const { submitOnboarding } = useSubmitOnboarding("Best");
|
||||
interface OnboardingBestTabProps {
|
||||
isDialog?: boolean;
|
||||
}
|
||||
|
||||
function OnboardingBestTab({ isDialog }: OnboardingBestTabProps) {
|
||||
const { submitOnboarding } = useSubmitOnboarding("Best", isDialog);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-8">
|
||||
|
|
|
|||
|
|
@ -14,14 +14,20 @@ import OllamaModelDownload from "../components/OllamaModelDownload";
|
|||
import { OllamaStatus } from "../components/OllamaStatus";
|
||||
import { useSubmitOnboarding } from "../hooks";
|
||||
import { setDefaultModel } from "../../../redux/slices/configSlice";
|
||||
import { setDialogMessage, setShowDialog } from "../../../redux/slices/uiSlice";
|
||||
|
||||
const OLLAMA_CHECK_INTERVAL_MS = 3000;
|
||||
|
||||
function OnboardingLocalTab() {
|
||||
interface OnboardingLocalTabProps {
|
||||
isDialog?: boolean;
|
||||
}
|
||||
|
||||
function OnboardingLocalTab({ isDialog }: OnboardingLocalTabProps) {
|
||||
const dispatch = useDispatch();
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
const { submitOnboarding } = useSubmitOnboarding(
|
||||
hasPassedFTL() ? "LocalAfterFreeTrial" : "Local",
|
||||
isDialog,
|
||||
);
|
||||
const [hasLoadedChatModel, setHasLoadedChatModel] = useState(false);
|
||||
const [downloadedOllamaModels, setDownloadedOllamaModels] = useState<
|
||||
|
|
@ -117,6 +123,11 @@ function OnboardingLocalTab() {
|
|||
onClick={() => {
|
||||
submitOnboarding();
|
||||
|
||||
if (isDialog) {
|
||||
dispatch(setDialogMessage(undefined));
|
||||
dispatch(setShowDialog(false));
|
||||
}
|
||||
|
||||
// Set the selected model to the local chat model
|
||||
dispatch(
|
||||
setDefaultModel({
|
||||
|
|
|
|||
|
|
@ -1,7 +1,11 @@
|
|||
import ContinueLogo from "../../gui/ContinueLogo";
|
||||
import QuickStartSubmitButton from "../components/QuickStartSubmitButton";
|
||||
|
||||
function OnboardingQuickstartTab() {
|
||||
interface OnboardingQuickstartTabProps {
|
||||
isDialog?: boolean;
|
||||
}
|
||||
|
||||
function OnboardingQuickstartTab({ isDialog }: OnboardingQuickstartTabProps) {
|
||||
return (
|
||||
<div className="flex h-full w-full items-center justify-center">
|
||||
<div className="xs:px-0 flex w-full max-w-full flex-col items-center justify-center px-4 text-center">
|
||||
|
|
@ -18,7 +22,7 @@ function OnboardingQuickstartTab() {
|
|||
To prevent abuse, we'll ask you to sign in to GitHub.
|
||||
</p>
|
||||
|
||||
<QuickStartSubmitButton />
|
||||
<QuickStartSubmitButton isDialog={isDialog} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
|
|
|||
32
gui/src/components/dialogs/FreeTrialOverDialog.tsx
Normal file
32
gui/src/components/dialogs/FreeTrialOverDialog.tsx
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import { useDispatch } from "react-redux";
|
||||
import { setDialogMessage, setShowDialog } from "../../redux/slices/uiSlice";
|
||||
import { useAppSelector } from "../../redux/hooks";
|
||||
import { useEffect } from "react";
|
||||
import { selectUsePlatform } from "../../redux/selectors";
|
||||
import { PlatformOnboardingCard } from "../OnboardingCard/platform/PlatformOnboardingCard";
|
||||
import { OnboardingCard } from "../OnboardingCard";
|
||||
|
||||
function FreeTrialOverDialog() {
|
||||
const dispatch = useDispatch();
|
||||
const history = useAppSelector((store) => store.session.history);
|
||||
const usePlatform = useAppSelector(selectUsePlatform);
|
||||
|
||||
useEffect(() => {
|
||||
if (history.length === 0) {
|
||||
dispatch(setShowDialog(false));
|
||||
dispatch(setDialogMessage(undefined));
|
||||
}
|
||||
}, [history]);
|
||||
|
||||
return (
|
||||
<div className="flex-1">
|
||||
{usePlatform ? (
|
||||
<PlatformOnboardingCard isDialog />
|
||||
) : (
|
||||
<OnboardingCard isDialog />
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default FreeTrialOverDialog;
|
||||
|
|
@ -78,7 +78,7 @@ const TextDialog = (props: TextDialogProps) => {
|
|||
>
|
||||
<Dialog>
|
||||
<CloseButton onClick={props.onClose}>
|
||||
<XMarkIcon className="h-5 w-5 hover:brightness-125" />
|
||||
<XMarkIcon className="z-50 h-5 w-5 hover:brightness-125" />
|
||||
</CloseButton>
|
||||
|
||||
{typeof props.message === "string" ? (
|
||||
|
|
|
|||
|
|
@ -25,7 +25,9 @@ export function AssistantSelect(props: AssistantSelectProps) {
|
|||
const dispatch = useAppDispatch();
|
||||
|
||||
function onNewAssistant() {
|
||||
ideMessenger.post("openUrl", "https://app-test.continue.dev/new");
|
||||
ideMessenger.post("controlPlane/openUrl", {
|
||||
path: "new",
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -66,13 +66,17 @@ import {
|
|||
getMetaKeyLabel,
|
||||
isMetaEquivalentKeyPressed,
|
||||
} from "../../util";
|
||||
import { FREE_TRIAL_LIMIT_REQUESTS } from "../../util/freeTrial";
|
||||
import {
|
||||
FREE_TRIAL_LIMIT_REQUESTS,
|
||||
incrementFreeTrialCount,
|
||||
} from "../../util/freeTrial";
|
||||
import getMultifileEditPrompt from "../../util/getMultifileEditPrompt";
|
||||
import { getLocalStorage, setLocalStorage } from "../../util/localStorage";
|
||||
import ConfigErrorIndicator from "./ConfigError";
|
||||
import { ToolCallDiv } from "./ToolCallDiv";
|
||||
import { ToolCallButtons } from "./ToolCallDiv/ToolCallButtonsDiv";
|
||||
import ToolOutput from "./ToolCallDiv/ToolOutput";
|
||||
import FreeTrialOverDialog from "../../components/dialogs/FreeTrialOverDialog";
|
||||
|
||||
const StopButton = styled.div`
|
||||
background-color: ${vscBackground};
|
||||
|
|
@ -247,21 +251,29 @@ export function Chat() {
|
|||
editorToClearOnSend?: Editor,
|
||||
) => {
|
||||
if (defaultModel?.provider === "free-trial") {
|
||||
const u = getLocalStorage("ftc");
|
||||
if (u) {
|
||||
setLocalStorage("ftc", u + 1);
|
||||
const newCount = incrementFreeTrialCount();
|
||||
|
||||
if (u >= FREE_TRIAL_LIMIT_REQUESTS) {
|
||||
onboardingCard.open("Best");
|
||||
posthog?.capture("ftc_reached");
|
||||
ideMessenger.ide.showToast(
|
||||
"info",
|
||||
"You've reached the free trial limit. Please configure a model to continue.",
|
||||
);
|
||||
return;
|
||||
if (newCount === FREE_TRIAL_LIMIT_REQUESTS) {
|
||||
posthog?.capture("ftc_reached");
|
||||
}
|
||||
if (newCount >= FREE_TRIAL_LIMIT_REQUESTS) {
|
||||
// Show this message whether using platform or not
|
||||
// So that something happens if in new chat
|
||||
ideMessenger.ide.showToast(
|
||||
"error",
|
||||
"You've reached the free trial limit. Please configure a model to continue.",
|
||||
);
|
||||
|
||||
// Card in chat will only show if no history
|
||||
// Also, note that platform card ignore the "Best", always opens to main tab
|
||||
onboardingCard.open("Best");
|
||||
|
||||
// If history, show the dialog, which will automatically close if there is not history
|
||||
if (history.length) {
|
||||
dispatch(setDialogMessage(<FreeTrialOverDialog />));
|
||||
dispatch(setShowDialog(true));
|
||||
}
|
||||
} else {
|
||||
setLocalStorage("ftc", 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -543,9 +555,9 @@ export function Chat() {
|
|||
{onboardingCard.show && (
|
||||
<div className="mx-2 mt-10">
|
||||
{usePlatform ? (
|
||||
<PlatformOnboardingCard />
|
||||
<PlatformOnboardingCard isDialog={false} />
|
||||
) : (
|
||||
<OnboardingCard />
|
||||
<OnboardingCard isDialog={false} />
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
import { getLocalStorage } from "./localStorage";
|
||||
import { getLocalStorage, setLocalStorage } from "./localStorage";
|
||||
|
||||
export const FREE_TRIAL_LIMIT_REQUESTS = 50;
|
||||
|
||||
/**
|
||||
*
|
||||
* @returns {boolean} true if the user has passed the free trial limit, false otherwise.
|
||||
*/
|
||||
export function hasPassedFTL(): boolean {
|
||||
return (getLocalStorage("ftc") ?? 0) > FREE_TRIAL_LIMIT_REQUESTS;
|
||||
}
|
||||
|
||||
export function incrementFreeTrialCount(): number {
|
||||
const u = getLocalStorage("ftc") ?? 0;
|
||||
setLocalStorage("ftc", u + 1);
|
||||
return u + 1;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue