feat: move free trial out of assistant
This commit is contained in:
parent
ef9dd90236
commit
2c58a33a6a
2 changed files with 29 additions and 28 deletions
|
|
@ -9,11 +9,13 @@ import {
|
|||
Squares2X2Icon,
|
||||
WrenchScrewdriverIcon,
|
||||
} from "@heroicons/react/24/outline";
|
||||
import { ReactNode } from "react";
|
||||
import { ReactNode, useContext, useEffect, useState } from "react";
|
||||
import { vscBadgeForeground } from "../../..";
|
||||
import { IdeMessengerContext } from "../../../../context/IdeMessenger";
|
||||
import { useAppSelector } from "../../../../redux/hooks";
|
||||
import { ToolTip } from "../../../gui/Tooltip";
|
||||
import AssistantSelect from "../../../modelSelection/platform/AssistantSelect";
|
||||
import FreeTrialButton from "../../../modelSelection/platform/FreeTrialButton";
|
||||
import { useFontSize } from "../../../ui/font";
|
||||
import HoverItem from "../../InputToolbar/HoverItem";
|
||||
import { useLump } from "../LumpContext";
|
||||
|
|
@ -21,6 +23,9 @@ import { ErrorsSectionTooltip } from "../sections/errors/ErrorsSectionTooltip";
|
|||
import { McpSectionTooltip } from "../sections/mcp/MCPTooltip";
|
||||
import { ToolsSectionTooltip } from "../sections/tool-policies/ToolPoliciesSectionTooltip";
|
||||
|
||||
import type { FreeTrialStatus } from "core/control-plane/client";
|
||||
import { usesFreeTrialApiKey } from "../../../../util/freeTrialHelpers";
|
||||
|
||||
interface BlockSettingsToolbarIcon {
|
||||
title: string;
|
||||
tooltip: ReactNode;
|
||||
|
|
@ -141,6 +146,23 @@ export function BlockSettingsTopToolbar() {
|
|||
} = useLump();
|
||||
|
||||
const configError = useAppSelector((store) => store.config.configError);
|
||||
const config = useAppSelector((state) => state.config.config);
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
|
||||
const [freeTrialStatus, setFreeTrialStatus] =
|
||||
useState<FreeTrialStatus | null>(null);
|
||||
const isUsingFreeTrial = usesFreeTrialApiKey(config);
|
||||
|
||||
useEffect(() => {
|
||||
ideMessenger
|
||||
.request("controlPlane/getFreeTrialStatus", undefined)
|
||||
.then((resp) => {
|
||||
if (resp.status === "success") {
|
||||
setFreeTrialStatus(resp.content);
|
||||
}
|
||||
})
|
||||
.catch(() => {});
|
||||
}, []);
|
||||
|
||||
const handleEllipsisClick = () => {
|
||||
if (isToolbarExpanded) {
|
||||
|
|
@ -195,9 +217,13 @@ export function BlockSettingsTopToolbar() {
|
|||
data-tooltip-id="assistant-select-tooltip"
|
||||
className="!m-0 !p-0"
|
||||
>
|
||||
<AssistantSelect />
|
||||
{isUsingFreeTrial ? (
|
||||
<FreeTrialButton freeTrialStatus={freeTrialStatus} />
|
||||
) : (
|
||||
<AssistantSelect />
|
||||
)}
|
||||
<ToolTip id="assistant-select-tooltip" place="top">
|
||||
Select Assistant
|
||||
{isUsingFreeTrial ? "View free trial usage" : "Select Assistant"}
|
||||
</ToolTip>
|
||||
</HoverItem>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -31,17 +31,13 @@ import {
|
|||
} from "../../ui";
|
||||
|
||||
import type { ProfileDescription } from "core/config/ConfigHandler";
|
||||
import { FreeTrialStatus } from "core/control-plane/client";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { vscCommandCenterInactiveBorder } from "../..";
|
||||
import { cn } from "../../../util/cn";
|
||||
import { usesFreeTrialApiKey } from "../../../util/freeTrialHelpers";
|
||||
import { ROUTES } from "../../../util/navigation";
|
||||
import { useLump } from "../../mainInput/Lump/LumpContext";
|
||||
import { useFontSize } from "../../ui/font";
|
||||
import AssistantIcon from "./AssistantIcon";
|
||||
import FreeTrialButton from "./FreeTrialButton";
|
||||
|
||||
interface AssistantSelectOptionProps {
|
||||
profile: ProfileDescription;
|
||||
selected: boolean;
|
||||
|
|
@ -158,33 +154,12 @@ export default function AssistantSelect() {
|
|||
const buttonRef = useRef<HTMLButtonElement>(null);
|
||||
const currentOrg = useAppSelector(selectCurrentOrg);
|
||||
const orgs = useAppSelector((store) => store.profiles.organizations);
|
||||
const config = useAppSelector((state) => state.config.config);
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
const { isToolbarExpanded } = useLump();
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [freeTrialStatus, setFreeTrialStatus] =
|
||||
useState<FreeTrialStatus | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
ideMessenger
|
||||
.request("controlPlane/getFreeTrialStatus", undefined)
|
||||
.then((resp) => {
|
||||
if (resp.status === "success") {
|
||||
setFreeTrialStatus(resp.content);
|
||||
}
|
||||
})
|
||||
.catch(() => {});
|
||||
}, []);
|
||||
|
||||
const { profiles, session, login, selectedProfile, refreshProfiles } =
|
||||
useAuth();
|
||||
|
||||
// If using free trial, show the FreeTrialButton instead
|
||||
const isUsingFreeTrial = usesFreeTrialApiKey(config);
|
||||
if (isUsingFreeTrial) {
|
||||
return <FreeTrialButton freeTrialStatus={freeTrialStatus} />;
|
||||
}
|
||||
|
||||
function close() {
|
||||
if (buttonRef.current) {
|
||||
buttonRef.current.click();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue