Merge pull request #6047 from continuedev/pe/onboarding-card-refactor
feat: onboarding card upgrade tab
This commit is contained in:
commit
20d325d33e
31 changed files with 1889 additions and 845 deletions
344
core/config/usesFreeTrialApiKey.test.ts
Normal file
344
core/config/usesFreeTrialApiKey.test.ts
Normal file
|
|
@ -0,0 +1,344 @@
|
|||
import { jest } from "@jest/globals";
|
||||
import { BrowserSerializedContinueConfig } from "..";
|
||||
|
||||
// Create the mock before importing anything else
|
||||
const mockDecodeSecretLocation = jest.fn();
|
||||
|
||||
// Mock the module
|
||||
jest.unstable_mockModule("@continuedev/config-yaml", () => ({
|
||||
SecretType: {
|
||||
User: "user",
|
||||
Organization: "organization",
|
||||
FreeTrial: "free_trial",
|
||||
},
|
||||
decodeSecretLocation: mockDecodeSecretLocation,
|
||||
}));
|
||||
|
||||
// Import after mocking
|
||||
const { usesFreeTrialApiKey } = await import("./usesFreeTrialApiKey");
|
||||
const { SecretType } = await import("@continuedev/config-yaml");
|
||||
|
||||
beforeEach(() => {
|
||||
mockDecodeSecretLocation.mockReset();
|
||||
});
|
||||
|
||||
test("usesFreeTrialApiKey should return false when config is null", () => {
|
||||
const result = usesFreeTrialApiKey(null);
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
|
||||
test("usesFreeTrialApiKey should return false when config is undefined", () => {
|
||||
const result = usesFreeTrialApiKey(undefined as any);
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
|
||||
test("usesFreeTrialApiKey should return false when no models have apiKeyLocation", () => {
|
||||
const config: BrowserSerializedContinueConfig = {
|
||||
modelsByRole: {
|
||||
chat: [
|
||||
{
|
||||
title: "Model 1",
|
||||
provider: "test",
|
||||
model: "test-model",
|
||||
underlyingProviderName: "test",
|
||||
},
|
||||
{
|
||||
title: "Model 2",
|
||||
provider: "test",
|
||||
model: "test-model-2",
|
||||
underlyingProviderName: "test",
|
||||
},
|
||||
],
|
||||
edit: [],
|
||||
apply: [],
|
||||
summarize: [],
|
||||
autocomplete: [],
|
||||
rerank: [],
|
||||
embed: [],
|
||||
},
|
||||
selectedModelByRole: {
|
||||
chat: null,
|
||||
edit: null,
|
||||
apply: null,
|
||||
summarize: null,
|
||||
autocomplete: null,
|
||||
rerank: null,
|
||||
embed: null,
|
||||
},
|
||||
contextProviders: [],
|
||||
slashCommands: [],
|
||||
tools: [],
|
||||
mcpServerStatuses: [],
|
||||
usePlatform: false,
|
||||
rules: [],
|
||||
};
|
||||
|
||||
const result = usesFreeTrialApiKey(config);
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
|
||||
test("usesFreeTrialApiKey should return false when models have apiKeyLocation but none are free trial", () => {
|
||||
const config: BrowserSerializedContinueConfig = {
|
||||
modelsByRole: {
|
||||
chat: [
|
||||
{
|
||||
title: "Model 1",
|
||||
provider: "test",
|
||||
model: "test-model",
|
||||
apiKeyLocation: "user:testuser/api-key",
|
||||
underlyingProviderName: "test",
|
||||
},
|
||||
],
|
||||
edit: [
|
||||
{
|
||||
title: "Model 2",
|
||||
provider: "test",
|
||||
model: "test-model-2",
|
||||
apiKeyLocation: "organization:testorg/api-key",
|
||||
underlyingProviderName: "test",
|
||||
},
|
||||
],
|
||||
apply: [],
|
||||
summarize: [],
|
||||
autocomplete: [],
|
||||
rerank: [],
|
||||
embed: [],
|
||||
},
|
||||
selectedModelByRole: {
|
||||
chat: null,
|
||||
edit: null,
|
||||
apply: null,
|
||||
summarize: null,
|
||||
autocomplete: null,
|
||||
rerank: null,
|
||||
embed: null,
|
||||
},
|
||||
contextProviders: [],
|
||||
slashCommands: [],
|
||||
tools: [],
|
||||
mcpServerStatuses: [],
|
||||
usePlatform: false,
|
||||
rules: [],
|
||||
};
|
||||
|
||||
mockDecodeSecretLocation
|
||||
.mockReturnValueOnce({
|
||||
secretType: SecretType.User,
|
||||
userSlug: "testuser",
|
||||
secretName: "api-key",
|
||||
})
|
||||
.mockReturnValueOnce({
|
||||
secretType: SecretType.Organization,
|
||||
orgSlug: "testorg",
|
||||
secretName: "api-key",
|
||||
});
|
||||
|
||||
const result = usesFreeTrialApiKey(config);
|
||||
expect(result).toBe(false);
|
||||
expect(mockDecodeSecretLocation).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
test("usesFreeTrialApiKey should return true when at least one model uses free trial API key", () => {
|
||||
const config: BrowserSerializedContinueConfig = {
|
||||
modelsByRole: {
|
||||
chat: [
|
||||
{
|
||||
title: "Model 1",
|
||||
provider: "test",
|
||||
model: "test-model",
|
||||
apiKeyLocation: "user:testuser/api-key",
|
||||
underlyingProviderName: "test",
|
||||
},
|
||||
{
|
||||
title: "Free Trial Model",
|
||||
provider: "test",
|
||||
model: "free-trial-model",
|
||||
apiKeyLocation: "free_trial:owner/package/api-key",
|
||||
underlyingProviderName: "test",
|
||||
},
|
||||
],
|
||||
edit: [],
|
||||
apply: [],
|
||||
summarize: [],
|
||||
autocomplete: [],
|
||||
rerank: [],
|
||||
embed: [],
|
||||
},
|
||||
selectedModelByRole: {
|
||||
chat: null,
|
||||
edit: null,
|
||||
apply: null,
|
||||
summarize: null,
|
||||
autocomplete: null,
|
||||
rerank: null,
|
||||
embed: null,
|
||||
},
|
||||
contextProviders: [],
|
||||
slashCommands: [],
|
||||
tools: [],
|
||||
mcpServerStatuses: [],
|
||||
usePlatform: false,
|
||||
rules: [],
|
||||
};
|
||||
|
||||
mockDecodeSecretLocation
|
||||
.mockReturnValueOnce({
|
||||
secretType: SecretType.User,
|
||||
userSlug: "testuser",
|
||||
secretName: "api-key",
|
||||
})
|
||||
.mockReturnValueOnce({
|
||||
secretType: SecretType.FreeTrial,
|
||||
blockSlug: { ownerSlug: "owner", packageSlug: "package" },
|
||||
secretName: "api-key",
|
||||
});
|
||||
|
||||
const result = usesFreeTrialApiKey(config);
|
||||
expect(result).toBe(true);
|
||||
expect(mockDecodeSecretLocation).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
test("usesFreeTrialApiKey should return true when free trial model is in a different role", () => {
|
||||
const config: BrowserSerializedContinueConfig = {
|
||||
modelsByRole: {
|
||||
chat: [
|
||||
{
|
||||
title: "Model 1",
|
||||
provider: "test",
|
||||
model: "test-model",
|
||||
apiKeyLocation: "user:testuser/api-key",
|
||||
underlyingProviderName: "test",
|
||||
},
|
||||
],
|
||||
edit: [
|
||||
{
|
||||
title: "Free Trial Edit Model",
|
||||
provider: "test",
|
||||
model: "free-trial-edit-model",
|
||||
apiKeyLocation: "free_trial:owner/package/api-key",
|
||||
underlyingProviderName: "test",
|
||||
},
|
||||
],
|
||||
apply: [],
|
||||
summarize: [],
|
||||
autocomplete: [],
|
||||
rerank: [],
|
||||
embed: [],
|
||||
},
|
||||
selectedModelByRole: {
|
||||
chat: null,
|
||||
edit: null,
|
||||
apply: null,
|
||||
summarize: null,
|
||||
autocomplete: null,
|
||||
rerank: null,
|
||||
embed: null,
|
||||
},
|
||||
contextProviders: [],
|
||||
slashCommands: [],
|
||||
tools: [],
|
||||
mcpServerStatuses: [],
|
||||
usePlatform: false,
|
||||
rules: [],
|
||||
};
|
||||
|
||||
mockDecodeSecretLocation
|
||||
.mockReturnValueOnce({
|
||||
secretType: SecretType.User,
|
||||
userSlug: "testuser",
|
||||
secretName: "api-key",
|
||||
})
|
||||
.mockReturnValueOnce({
|
||||
secretType: SecretType.FreeTrial,
|
||||
blockSlug: { ownerSlug: "owner", packageSlug: "package" },
|
||||
secretName: "api-key",
|
||||
});
|
||||
|
||||
const result = usesFreeTrialApiKey(config);
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
test("usesFreeTrialApiKey should return false and log error when decodeSecretLocation throws", () => {
|
||||
const consoleSpy = jest.spyOn(console, "error").mockImplementation(() => {});
|
||||
|
||||
const config: BrowserSerializedContinueConfig = {
|
||||
modelsByRole: {
|
||||
chat: [
|
||||
{
|
||||
title: "Model 1",
|
||||
provider: "test",
|
||||
model: "test-model",
|
||||
apiKeyLocation: "invalid-secret-location",
|
||||
underlyingProviderName: "test",
|
||||
},
|
||||
],
|
||||
edit: [],
|
||||
apply: [],
|
||||
summarize: [],
|
||||
autocomplete: [],
|
||||
rerank: [],
|
||||
embed: [],
|
||||
},
|
||||
selectedModelByRole: {
|
||||
chat: null,
|
||||
edit: null,
|
||||
apply: null,
|
||||
summarize: null,
|
||||
autocomplete: null,
|
||||
rerank: null,
|
||||
embed: null,
|
||||
},
|
||||
contextProviders: [],
|
||||
slashCommands: [],
|
||||
tools: [],
|
||||
mcpServerStatuses: [],
|
||||
usePlatform: false,
|
||||
rules: [],
|
||||
};
|
||||
|
||||
mockDecodeSecretLocation.mockImplementation(() => {
|
||||
throw new Error("Invalid secret location format");
|
||||
});
|
||||
|
||||
const result = usesFreeTrialApiKey(config);
|
||||
expect(result).toBe(false);
|
||||
expect(consoleSpy).toHaveBeenCalledWith(
|
||||
"Error checking for free trial API key:",
|
||||
expect.any(Error),
|
||||
);
|
||||
|
||||
consoleSpy.mockRestore();
|
||||
});
|
||||
|
||||
test("usesFreeTrialApiKey should handle empty modelsByRole object", () => {
|
||||
const config: BrowserSerializedContinueConfig = {
|
||||
modelsByRole: {
|
||||
chat: [],
|
||||
edit: [],
|
||||
apply: [],
|
||||
summarize: [],
|
||||
autocomplete: [],
|
||||
rerank: [],
|
||||
embed: [],
|
||||
},
|
||||
selectedModelByRole: {
|
||||
chat: null,
|
||||
edit: null,
|
||||
apply: null,
|
||||
summarize: null,
|
||||
autocomplete: null,
|
||||
rerank: null,
|
||||
embed: null,
|
||||
},
|
||||
contextProviders: [],
|
||||
slashCommands: [],
|
||||
tools: [],
|
||||
mcpServerStatuses: [],
|
||||
usePlatform: false,
|
||||
rules: [],
|
||||
};
|
||||
|
||||
const result = usesFreeTrialApiKey(config);
|
||||
expect(result).toBe(false);
|
||||
expect(mockDecodeSecretLocation).not.toHaveBeenCalled();
|
||||
});
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
import { decodeSecretLocation, SecretType } from "@continuedev/config-yaml";
|
||||
import { BrowserSerializedContinueConfig } from "core";
|
||||
import { BrowserSerializedContinueConfig } from "..";
|
||||
|
||||
/**
|
||||
* Helper function to determine if the config uses a free trial API key
|
||||
* @param config The serialized config object
|
||||
|
|
@ -182,4 +182,38 @@ export class ControlPlaneClient {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* JetBrains does not support deep links, so we only check for `vsCodeUriScheme`
|
||||
* @param vsCodeUriScheme
|
||||
* @returns
|
||||
*/
|
||||
public async getModelsAddOnCheckoutUrl(
|
||||
vsCodeUriScheme?: string,
|
||||
): Promise<{ url: string } | null> {
|
||||
if (!(await this.isSignedIn())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
const params = new URLSearchParams({
|
||||
// LocalProfileLoader ID
|
||||
profile_id: "local",
|
||||
});
|
||||
|
||||
if (vsCodeUriScheme) {
|
||||
params.set("vscode_uri_scheme", vsCodeUriScheme);
|
||||
}
|
||||
|
||||
const resp = await this.request(
|
||||
`ide/get-models-add-on-checkout-url?${params.toString()}`,
|
||||
{
|
||||
method: "GET",
|
||||
},
|
||||
);
|
||||
return (await resp.json()) as { url: string };
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -357,6 +357,12 @@ export class Core {
|
|||
return this.configHandler.controlPlaneClient.getFreeTrialStatus();
|
||||
});
|
||||
|
||||
on("controlPlane/getModelsAddOnUpgradeUrl", async (msg) => {
|
||||
return this.configHandler.controlPlaneClient.getModelsAddOnCheckoutUrl(
|
||||
msg.data.vsCodeUriScheme,
|
||||
);
|
||||
});
|
||||
|
||||
on("mcp/reloadServer", async (msg) => {
|
||||
await MCPManagerSingleton.getInstance().refreshConnection(msg.data.id);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { fetchwithRequestOptions } from "@continuedev/fetch";
|
||||
import { ChatMessage, IDE, PromptLog } from "..";
|
||||
import { ConfigHandler } from "../config/ConfigHandler";
|
||||
import { usesFreeTrialApiKey } from "../config/usesFreeTrialApiKey";
|
||||
import { FromCoreProtocol, ToCoreProtocol } from "../protocol";
|
||||
import { IMessenger, Message } from "../protocol/messenger";
|
||||
import { Telemetry } from "../util/posthog";
|
||||
|
|
@ -135,6 +136,8 @@ export async function* llmStreamChat(
|
|||
true,
|
||||
);
|
||||
|
||||
void checkForFreeTrialExceeded(configHandler, messenger);
|
||||
|
||||
if (!next.done) {
|
||||
throw new Error("Will never happen");
|
||||
}
|
||||
|
|
@ -142,3 +145,29 @@ export async function* llmStreamChat(
|
|||
return next.value;
|
||||
}
|
||||
}
|
||||
|
||||
async function checkForFreeTrialExceeded(
|
||||
configHandler: ConfigHandler,
|
||||
messenger: IMessenger<ToCoreProtocol, FromCoreProtocol>,
|
||||
) {
|
||||
const { config } = await configHandler.getSerializedConfig();
|
||||
|
||||
// Only check if the user is using the free trial
|
||||
if (config && !usesFreeTrialApiKey(config)) {
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ import { FreeTrialStatus } from "../control-plane/client";
|
|||
export enum OnboardingModes {
|
||||
API_KEY = "API Key",
|
||||
LOCAL = "Local",
|
||||
MODELS_ADD_ON = "Models Add-On",
|
||||
}
|
||||
|
||||
export interface ListHistoryOptions {
|
||||
|
|
@ -199,6 +200,10 @@ export type ToCoreFromIdeOrWebviewProtocol = {
|
|||
"clipboardCache/add": [{ content: string }, void];
|
||||
"controlPlane/openUrl": [{ path: string; orgSlug?: string }, void];
|
||||
"controlPlane/getFreeTrialStatus": [undefined, FreeTrialStatus | null];
|
||||
"controlPlane/getModelsAddOnUpgradeUrl": [
|
||||
{ vsCodeUriScheme?: string },
|
||||
{ url: string } | null,
|
||||
];
|
||||
isItemTooBig: [{ item: ContextItemWithId }, boolean];
|
||||
didChangeControlPlaneSessionInfo: [
|
||||
{ sessionInfo: ControlPlaneSessionInfo | undefined },
|
||||
|
|
|
|||
|
|
@ -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];
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
@ -84,4 +85,5 @@ export const CORE_TO_WEBVIEW_PASS_THROUGH: (keyof ToWebviewFromCoreProtocol)[] =
|
|||
"sessionUpdate",
|
||||
"didCloseFiles",
|
||||
"toolCallPartialOutput",
|
||||
"freeTrialExceeded",
|
||||
];
|
||||
|
|
|
|||
|
|
@ -43,4 +43,5 @@ export type ToWebviewFromIdeOrCoreProtocol = {
|
|||
"jetbrains/setColors": [Record<string, string | null | undefined>, void];
|
||||
sessionUpdate: [{ sessionInfo: ControlPlaneSessionInfo | undefined }, void];
|
||||
toolCallPartialOutput: [{ toolCallId: string; contextItems: any[] }, void];
|
||||
freeTrialExceeded: [undefined, void];
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { ConfigHandler } from "core/config/ConfigHandler";
|
|||
import * as vscode from "vscode";
|
||||
|
||||
import { getTheme } from "./util/getTheme";
|
||||
import { getExtensionVersion } from "./util/util";
|
||||
import { getExtensionVersion, getvsCodeUriScheme } from "./util/util";
|
||||
import { getExtensionUri, getNonce, getUniqueId } from "./util/vscode";
|
||||
import { VsCodeWebviewProtocol } from "./webviewProtocol";
|
||||
|
||||
|
|
@ -161,6 +161,7 @@ export class ContinueGUIWebviewViewProvider
|
|||
<script type="module" nonce="${nonce}" src="${scriptUri}"></script>
|
||||
|
||||
<script>localStorage.setItem("ide", '"vscode"')</script>
|
||||
<script>localStorage.setItem("vsCodeUriScheme", '"${getvsCodeUriScheme()}"')</script>
|
||||
<script>localStorage.setItem("extensionVersion", '"${getExtensionVersion()}"')</script>
|
||||
<script>window.windowId = "${this.windowId}"</script>
|
||||
<script>window.vscMachineId = "${getUniqueId()}"</script>
|
||||
|
|
|
|||
|
|
@ -122,3 +122,7 @@ export function getExtensionVersion(): string {
|
|||
const extension = vscode.extensions.getExtension("continue.continue");
|
||||
return extension?.packageJSON.version || "0.1.0";
|
||||
}
|
||||
|
||||
export function getvsCodeUriScheme(): string {
|
||||
return vscode.env.uriScheme;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.API_KEY);
|
||||
onboardingCard.open(OnboardingModes.LOCAL);
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
useWebviewListener(
|
||||
"setupLocalConfig",
|
||||
"freeTrialExceeded",
|
||||
async () => {
|
||||
onboardingCard.open(OnboardingModes.LOCAL);
|
||||
dispatch(setShowDialog(true));
|
||||
onboardingCard.setActiveTab(OnboardingModes.MODELS_ADD_ON);
|
||||
dispatch(
|
||||
setDialogMessage(
|
||||
<div className="flex-1">
|
||||
<OnboardingCard isDialog showFreeTrialExceededAlert />
|
||||
</div>,
|
||||
),
|
||||
);
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
useWebviewListener(
|
||||
"setupApiKey",
|
||||
async () => {
|
||||
onboardingCard.open(OnboardingModes.API_KEY);
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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 <OnboardingProvidersTab />;
|
||||
case OnboardingModes.LOCAL:
|
||||
return <OnboardingLocalTab />;
|
||||
case OnboardingModes.MODELS_ADD_ON:
|
||||
return <OnboardingModelsAddOnTab />;
|
||||
default:
|
||||
return <OnboardingProvidersTab />;
|
||||
}
|
||||
|
|
@ -45,7 +53,24 @@ export function OnboardingCard({ isDialog }: OnboardingCardProps) {
|
|||
onClose={close}
|
||||
testId="onboarding-card"
|
||||
>
|
||||
<OnboardingCardTabs activeTab={activeTab} onTabClick={setActiveTab} />
|
||||
{showFreeTrialExceededAlert && (
|
||||
<div className="mb-3 mt-4">
|
||||
<Alert>
|
||||
<h4 className="mb-1 mt-0 text-sm font-semibold">
|
||||
Free trial completed
|
||||
</h4>
|
||||
<span className="text-xs">
|
||||
To keep using Continue, select an option below to setup your
|
||||
models
|
||||
</span>
|
||||
</Alert>
|
||||
</div>
|
||||
)}
|
||||
<OnboardingCardTabs
|
||||
activeTab={activeTab}
|
||||
onTabClick={setActiveTab}
|
||||
showFreeTrialExceededAlert
|
||||
/>
|
||||
{renderTabContent()}
|
||||
</ReusableCard>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ import { selectCurrentOrg } from "../../../redux";
|
|||
import { useAppDispatch, useAppSelector } from "../../../redux/hooks";
|
||||
import { selectFirstHubProfile } from "../../../redux/thunks";
|
||||
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({
|
||||
|
|
|
|||
|
|
@ -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.API_KEY) {
|
||||
return <KeyIcon className="h-4 w-4" />;
|
||||
}
|
||||
if (tabTitle === OnboardingModes.LOCAL) {
|
||||
return (
|
||||
<img
|
||||
src={`${window.vscMediaUrl}/logos/ollama.png`}
|
||||
alt="Ollama"
|
||||
className="h-4 w-4 object-contain"
|
||||
/>
|
||||
<button
|
||||
className={baseButtonClass}
|
||||
key={tabTitle}
|
||||
onClick={() => onTabClick(tabTitle as OnboardingModes)}
|
||||
data-testid={`onboarding-tab-${tabTitle}`}
|
||||
>
|
||||
<KeyIcon className="-mb-0.5 mr-2 h-4 w-4" />
|
||||
{tabTitle}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
if (tabTitle === OnboardingModes.LOCAL) {
|
||||
return (
|
||||
<button
|
||||
className={baseButtonClass}
|
||||
key={tabTitle}
|
||||
onClick={() => onTabClick(tabTitle as OnboardingModes)}
|
||||
data-testid={`onboarding-tab-${tabTitle}`}
|
||||
>
|
||||
<OllamaLogo width={18} height={18} className="-mb-0.5 mr-2" />
|
||||
{tabTitle}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
if (tabTitle === OnboardingModes.MODELS_ADD_ON) {
|
||||
return (
|
||||
<button
|
||||
className={`${baseButtonClass} -ml-1.5`}
|
||||
key={tabTitle}
|
||||
onClick={() => onTabClick(tabTitle as OnboardingModes)}
|
||||
data-testid={`onboarding-tab-${tabTitle}`}
|
||||
>
|
||||
<ContinueSignet width={32} height={32} className="-mb-2.5" />
|
||||
Upgrade
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
|
|
@ -30,38 +68,44 @@ 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.API_KEY,
|
||||
OnboardingModes.LOCAL,
|
||||
]
|
||||
: [
|
||||
OnboardingModes.API_KEY,
|
||||
OnboardingModes.LOCAL,
|
||||
OnboardingModes.MODELS_ADD_ON,
|
||||
];
|
||||
return (
|
||||
<div>
|
||||
<div className="xs:block hidden">
|
||||
<div className="hidden sm:block">
|
||||
<div className="border-foreground border-x-0 border-b border-t-0 border-solid">
|
||||
{Object.values(OnboardingModes).map((tabTitle) => {
|
||||
const isActive = activeTab === tabTitle;
|
||||
|
||||
return (
|
||||
<button
|
||||
className={`xs:py-2 xs:px-3 text-foreground -mb-px cursor-pointer rounded-t-sm border-none bg-transparent px-6 py-2 font-medium hover:brightness-125 focus:outline-none sm:px-5 ${isActive ? "font-semibold" : ""}`}
|
||||
key={tabTitle}
|
||||
onClick={() => onTabClick(tabTitle as OnboardingModes)}
|
||||
data-testid={`onboarding-tab-${tabTitle}`}
|
||||
>
|
||||
<p className="m-0 flex items-center gap-2">
|
||||
{getTabIcon(tabTitle)}
|
||||
{tabTitle}
|
||||
</p>
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
{tabs.map((tabTitle, index) =>
|
||||
renderTabButton(tabTitle, index, activeTab, onTabClick),
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="xs:hidden block">
|
||||
<div className="block sm:hidden">
|
||||
<select
|
||||
className="text-foreground border-foreground w-full cursor-pointer rounded-none border-b border-none bg-transparent p-2 text-base focus:outline-none"
|
||||
className="text-foreground border-border mt-4 w-full cursor-pointer rounded-none border-x-0 border-b border-t-0 bg-transparent p-2 text-base focus:outline-none"
|
||||
value={activeTab}
|
||||
onChange={(e) => onTabClick(e.target.value as OnboardingModes)}
|
||||
>
|
||||
{Object.values(OnboardingModes).map((tabTitle) => {
|
||||
{tabs.map((tabTitle) => {
|
||||
return (
|
||||
<option key={tabTitle} value={tabTitle}>
|
||||
{tabTitle}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,134 @@
|
|||
import { ArrowPathIcon } from "@heroicons/react/24/outline";
|
||||
import { useContext, useEffect, useState } from "react";
|
||||
import { Button } from "../..";
|
||||
import { IdeMessengerContext } from "../../../context/IdeMessenger";
|
||||
import { getLocalStorage } from "../../../util/localStorage";
|
||||
import { useOnboardingCard } from "../hooks";
|
||||
|
||||
/**
|
||||
* Models Add-On tab component displaying pricing and tier information
|
||||
*/
|
||||
export function OnboardingModelsAddOnTab() {
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
const { close } = useOnboardingCard();
|
||||
const [isPolling, setIsPolling] = useState(false);
|
||||
|
||||
const isJetbrains = getLocalStorage("ide") === "jetbrains";
|
||||
|
||||
// Polling effect for JetBrains
|
||||
useEffect(() => {
|
||||
if (!isPolling || !isJetbrains) return;
|
||||
|
||||
const interval = setInterval(() => {
|
||||
ideMessenger.post("config/refreshProfiles", {
|
||||
selectProfileId: "local",
|
||||
});
|
||||
}, 5000);
|
||||
|
||||
return () => clearInterval(interval);
|
||||
}, [isPolling, isJetbrains, ideMessenger]);
|
||||
|
||||
function openPricingPage() {
|
||||
ideMessenger.post("controlPlane/openUrl", {
|
||||
path: "pricing",
|
||||
});
|
||||
}
|
||||
|
||||
async function handleUpgrade() {
|
||||
try {
|
||||
const response = await ideMessenger.request(
|
||||
"controlPlane/getModelsAddOnUpgradeUrl",
|
||||
{
|
||||
vsCodeUriScheme: getLocalStorage("vsCodeUriScheme"),
|
||||
},
|
||||
);
|
||||
|
||||
if (response.status === "success" && response.content?.url) {
|
||||
await ideMessenger.request("openUrl", response.content.url);
|
||||
} else {
|
||||
console.error("Failed to get upgrade URL");
|
||||
openPricingPage();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error during upgrade process:", error);
|
||||
openPricingPage();
|
||||
} finally {
|
||||
if (isJetbrains) {
|
||||
setIsPolling(true);
|
||||
} else {
|
||||
close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Show polling UI for JetBrains after upgrade
|
||||
if (isPolling && isJetbrains) {
|
||||
return (
|
||||
<div className="flex h-full w-full flex-col items-center justify-center text-center">
|
||||
<h2 className="text-foreground mb-4 items-center text-lg font-semibold">
|
||||
<ArrowPathIcon className="text-foreground animate-spin-slow mr-2 h-4 w-4" />
|
||||
You may close this dialog after upgrading
|
||||
</h2>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex h-full w-full flex-col items-center justify-center text-center">
|
||||
<div className="mb-4 flex flex-col items-center text-center">
|
||||
<div className="mb-1">
|
||||
<h2 className="text-foreground mb-1 text-2xl font-semibold">
|
||||
Models Add-on
|
||||
</h2>
|
||||
</div>
|
||||
|
||||
<div className="bg-badge text-badge-foreground mb-4 rounded-full px-3 py-1 text-xs font-medium">
|
||||
$20/month
|
||||
</div>
|
||||
|
||||
<span className="text-description text-base">
|
||||
Use a{" "}
|
||||
<span
|
||||
className="cursor-pointer underline hover:brightness-125"
|
||||
onClick={openPricingPage}
|
||||
>
|
||||
variety of frontier models
|
||||
</span>{" "}
|
||||
for a flat monthly fee
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="mb-6 mt-4 space-y-3 text-left">
|
||||
<p className="text-foreground text-sm">
|
||||
<span className="font-bold">Base Tier:</span> 500 Chat/Edit and 25,000
|
||||
Autocomplete requests per month
|
||||
</p>
|
||||
<p className="text-foreground text-sm">
|
||||
<span className="font-bold">Plus Tier (2.5x):</span> 1,250 Chat/Edit
|
||||
and 62,500 Autocomplete requests per month
|
||||
</p>
|
||||
<p className="text-foreground text-sm">
|
||||
<span className="font-bold">Pro Tier (5x):</span> 2,500 Chat/Edit and
|
||||
125,000 Autocomplete requests per month
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="w-full">
|
||||
<Button onClick={handleUpgrade} className="w-full max-w-xs">
|
||||
Upgrade
|
||||
</Button>
|
||||
</div>
|
||||
<div className="w-full text-center">
|
||||
<span className="text-description">
|
||||
<span
|
||||
className="cursor-pointer underline hover:brightness-125"
|
||||
onClick={openPricingPage}
|
||||
>
|
||||
Click here
|
||||
</span>{" "}
|
||||
to view pricing details
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
@ -109,7 +109,7 @@ export function OnboardingProvidersTab({
|
|||
</Button>
|
||||
|
||||
<div className="w-full text-center">
|
||||
<span className="text-description-muted">
|
||||
<span className="text-description">
|
||||
<span
|
||||
className="cursor-pointer underline hover:brightness-125"
|
||||
onClick={handleClickMoreProviders}
|
||||
|
|
|
|||
|
|
@ -4,4 +4,5 @@ export * from "./OllamaStatus";
|
|||
export * from "./OnboardingCardLanding";
|
||||
export * from "./OnboardingCardTabs";
|
||||
export * from "./OnboardingLocalTab";
|
||||
export * from "./OnboardingModelsAddOnTab";
|
||||
export * from "./OnboardingProvidersTab";
|
||||
|
|
|
|||
|
|
@ -194,7 +194,8 @@ body[data-color-mode*="light"] {
|
|||
}
|
||||
.wmde-markdown {
|
||||
-webkit-text-size-adjust: 100%;
|
||||
font-family: -apple-system, "Segoe UI", Helvetica, Arial, sans-serif,
|
||||
font-family:
|
||||
-apple-system, "Segoe UI", Helvetica, Arial, sans-serif,
|
||||
"Apple Color Emoji", "Segoe UI Emoji";
|
||||
font-size: 16px;
|
||||
line-height: 1.5;
|
||||
|
|
|
|||
|
|
@ -1,25 +0,0 @@
|
|||
import { useEffect } from "react";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { useAppSelector } from "../../redux/hooks";
|
||||
import { setDialogMessage, setShowDialog } from "../../redux/slices/uiSlice";
|
||||
import { OnboardingCard } from "../OnboardingCard";
|
||||
|
||||
function FreeTrialOverDialog() {
|
||||
const dispatch = useDispatch();
|
||||
const history = useAppSelector((store) => store.session.history);
|
||||
|
||||
useEffect(() => {
|
||||
if (history.length === 0) {
|
||||
dispatch(setShowDialog(false));
|
||||
dispatch(setDialogMessage(undefined));
|
||||
}
|
||||
}, [history]);
|
||||
|
||||
return (
|
||||
<div className="flex-1">
|
||||
<OnboardingCard isDialog />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default FreeTrialOverDialog;
|
||||
|
|
@ -6,9 +6,9 @@
|
|||
}
|
||||
|
||||
.keyboard-key-normal {
|
||||
font-family: "JetBrains Mono", "SF Mono", Monaco, Menlo, Consolas,
|
||||
"Ubuntu Mono", "Liberation Mono", "DejaVu Sans Mono", "Courier New",
|
||||
monospace;
|
||||
font-family:
|
||||
"JetBrains Mono", "SF Mono", Monaco, Menlo, Consolas, "Ubuntu Mono",
|
||||
"Liberation Mono", "DejaVu Sans Mono", "Courier New", monospace;
|
||||
font-weight: 300;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,8 +23,8 @@ import { ErrorsSectionTooltip } from "../sections/errors/ErrorsSectionTooltip";
|
|||
import { McpSectionTooltip } from "../sections/mcp/MCPTooltip";
|
||||
import { ToolsSectionTooltip } from "../sections/tool-policies/ToolPoliciesSectionTooltip";
|
||||
|
||||
import { usesFreeTrialApiKey } from "core/config/usesFreeTrialApiKey";
|
||||
import type { FreeTrialStatus } from "core/control-plane/client";
|
||||
import { usesFreeTrialApiKey } from "../../../../util/freeTrialHelpers";
|
||||
|
||||
interface BlockSettingsToolbarIcon {
|
||||
title: string;
|
||||
|
|
|
|||
35
gui/src/components/svg/ContinueSignet.tsx
Normal file
35
gui/src/components/svg/ContinueSignet.tsx
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
import { vscForeground } from "..";
|
||||
|
||||
interface ContinueSignetProps {
|
||||
/** Height of the signet in pixels */
|
||||
height?: number;
|
||||
/** Width of the signet in pixels */
|
||||
width?: number;
|
||||
/** Additional CSS classes to apply to the SVG */
|
||||
className?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Continue signet/logo symbol without text
|
||||
*/
|
||||
export default function ContinueSignet({
|
||||
height = 103,
|
||||
width = 107,
|
||||
className = "",
|
||||
}: ContinueSignetProps) {
|
||||
return (
|
||||
<svg
|
||||
width={width}
|
||||
height={height}
|
||||
viewBox="0 0 106.67 103.11"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
className={className}
|
||||
>
|
||||
<path
|
||||
d="m68.65,34.69l-2.71,4.7,6.85,11.86c.05.09.08.2.08.3s-.03.21-.08.3l-6.85,11.87,2.71,4.7,9.74-16.87-9.74-16.87Zm-3.76,4.09l2.71-4.7h-5.42s-2.71,4.7-2.71,4.7h5.43Zm-5.43,1.22l6.33,10.95h5.42l-6.32-10.95h-5.43Zm5.43,23.12l6.32-10.96h-5.42l-6.33,10.96h5.43Zm-5.43,1.22l2.71,4.68h5.42s-2.71-4.68-2.71-4.68h-5.43Zm-18.37,5.84c-.11,0-.21-.03-.3-.08-.09-.05-.17-.13-.22-.22l-6.86-11.87h-5.42s9.74,16.86,9.74,16.86h19.47s-2.71-4.69-2.71-4.69h-13.69Zm14.75-.61l2.71,4.69,2.71-4.7-2.71-4.7-2.71,4.7Zm1.66-5.31h-12.64s-2.71,4.7-2.71,4.7h12.64s2.71-4.7,2.71-4.7Zm-13.7-.6l-6.33-10.96-2.71,4.7,6.33,10.96,2.71-4.7Zm-15.52-6.87h5.42s2.71-4.7,2.71-4.7h-5.41s-2.72,4.7-2.72,4.7Zm12.26-23.53c.05-.09.13-.17.22-.22.09-.05.2-.08.3-.08h13.71s2.71-4.7,2.71-4.7h-19.48l-9.74,16.87h5.42s6.84-11.86,6.84-11.86Zm-4.13,17.78l-2.71-4.7h-5.42s2.71,4.7,2.71,4.7h5.42Zm4.66-16.26l-6.32,10.95,2.71,4.7,6.32-10.95-2.71-4.7Zm13.71-.61h-12.66s2.71,4.7,2.71,4.7h12.66s-2.71-4.7-2.71-4.7Zm3.77,4.09l2.7-4.69-2.7-4.7-2.71,4.69,2.71,4.7Z"
|
||||
fill={vscForeground}
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
51
gui/src/components/svg/OllamaLogo.tsx
Normal file
51
gui/src/components/svg/OllamaLogo.tsx
Normal file
File diff suppressed because one or more lines are too long
|
|
@ -51,7 +51,7 @@ export function ScopeSelect({ onSelect }: ScopeSelectProps) {
|
|||
return (
|
||||
<Listbox value={selectedOrgId} onChange={handleChange}>
|
||||
<div className="relative">
|
||||
<ListboxButton className="hover:bg-list-active hover:text-list-active-foreground min-w-[140px] justify-between px-4 py-2 sm:min-w-[200px]">
|
||||
<ListboxButton className="hover:bg-list-active hover:text-list-active-foreground w-full min-w-[140px] justify-between px-4 py-2 sm:min-w-[200px]">
|
||||
<div className="flex items-center gap-2">
|
||||
{selectedDisplay?.iconUrl ? (
|
||||
<img src={selectedDisplay.iconUrl} alt="" className="h-5 w-5" />
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import { Editor, JSONContent } from "@tiptap/react";
|
|||
import { InputModifiers } from "core";
|
||||
import { streamResponse } from "core/llm/stream";
|
||||
import { renderChatMessage } from "core/util/messageContent";
|
||||
import { usePostHog } from "posthog-js/react";
|
||||
import {
|
||||
useCallback,
|
||||
useContext,
|
||||
|
|
@ -49,7 +48,6 @@ import { streamEditThunk } from "../../redux/thunks/edit";
|
|||
import { loadLastSession } from "../../redux/thunks/session";
|
||||
import { isJetBrains, isMetaEquivalentKeyPressed } from "../../util";
|
||||
|
||||
import { OnboardingModes } from "core/protocol/core";
|
||||
import { getLocalStorage, setLocalStorage } from "../../util/localStorage";
|
||||
import { EmptyChatBody } from "./EmptyChatBody";
|
||||
import { ExploreDialogWatcher } from "./ExploreDialogWatcher";
|
||||
|
|
@ -92,7 +90,6 @@ function fallbackRender({ error, resetErrorBoundary }: any) {
|
|||
}
|
||||
|
||||
export function Chat() {
|
||||
const posthog = usePostHog();
|
||||
const dispatch = useAppDispatch();
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
const onboardingCard = useOnboardingCard();
|
||||
|
|
@ -202,10 +199,6 @@ export function Chat() {
|
|||
// "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(OnboardingModes.API_KEY);
|
||||
|
||||
// // If history, show the dialog, which will automatically close if there is not history
|
||||
// if (history.length) {
|
||||
// dispatch(setDialogMessage(<FreeTrialOverDialog />));
|
||||
|
|
|
|||
|
|
@ -1,341 +0,0 @@
|
|||
import { SecretType } from "@continuedev/config-yaml";
|
||||
import { BrowserSerializedContinueConfig } from "core";
|
||||
import { usesFreeTrialApiKey } from "./freeTrialHelpers";
|
||||
|
||||
// Mock the decodeSecretLocation function
|
||||
vi.mock("@continuedev/config-yaml", async () => {
|
||||
const actual = await vi.importActual("@continuedev/config-yaml");
|
||||
return {
|
||||
...actual,
|
||||
decodeSecretLocation: vi.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
const { decodeSecretLocation } = await import("@continuedev/config-yaml");
|
||||
|
||||
describe("usesFreeTrialApiKey", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it("should return false when config is null", () => {
|
||||
const result = usesFreeTrialApiKey(null);
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
|
||||
it("should return false when config is undefined", () => {
|
||||
const result = usesFreeTrialApiKey(undefined as any);
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
|
||||
it("should return false when no models have apiKeyLocation", () => {
|
||||
const config: BrowserSerializedContinueConfig = {
|
||||
modelsByRole: {
|
||||
chat: [
|
||||
{
|
||||
title: "Model 1",
|
||||
provider: "test",
|
||||
model: "test-model",
|
||||
underlyingProviderName: "test",
|
||||
},
|
||||
{
|
||||
title: "Model 2",
|
||||
provider: "test",
|
||||
model: "test-model-2",
|
||||
underlyingProviderName: "test",
|
||||
},
|
||||
],
|
||||
edit: [],
|
||||
apply: [],
|
||||
summarize: [],
|
||||
autocomplete: [],
|
||||
rerank: [],
|
||||
embed: [],
|
||||
},
|
||||
selectedModelByRole: {
|
||||
chat: null,
|
||||
edit: null,
|
||||
apply: null,
|
||||
summarize: null,
|
||||
autocomplete: null,
|
||||
rerank: null,
|
||||
embed: null,
|
||||
},
|
||||
contextProviders: [],
|
||||
slashCommands: [],
|
||||
tools: [],
|
||||
mcpServerStatuses: [],
|
||||
usePlatform: false,
|
||||
rules: [],
|
||||
};
|
||||
|
||||
const result = usesFreeTrialApiKey(config);
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
|
||||
it("should return false when models have apiKeyLocation but none are free trial", () => {
|
||||
const config: BrowserSerializedContinueConfig = {
|
||||
modelsByRole: {
|
||||
chat: [
|
||||
{
|
||||
title: "Model 1",
|
||||
provider: "test",
|
||||
model: "test-model",
|
||||
apiKeyLocation: "user:testuser/api-key",
|
||||
underlyingProviderName: "test",
|
||||
},
|
||||
],
|
||||
edit: [
|
||||
{
|
||||
title: "Model 2",
|
||||
provider: "test",
|
||||
model: "test-model-2",
|
||||
apiKeyLocation: "organization:testorg/api-key",
|
||||
underlyingProviderName: "test",
|
||||
},
|
||||
],
|
||||
apply: [],
|
||||
summarize: [],
|
||||
autocomplete: [],
|
||||
rerank: [],
|
||||
embed: [],
|
||||
},
|
||||
selectedModelByRole: {
|
||||
chat: null,
|
||||
edit: null,
|
||||
apply: null,
|
||||
summarize: null,
|
||||
autocomplete: null,
|
||||
rerank: null,
|
||||
embed: null,
|
||||
},
|
||||
contextProviders: [],
|
||||
slashCommands: [],
|
||||
tools: [],
|
||||
mcpServerStatuses: [],
|
||||
usePlatform: false,
|
||||
rules: [],
|
||||
};
|
||||
|
||||
vi.mocked(decodeSecretLocation)
|
||||
.mockReturnValueOnce({
|
||||
secretType: SecretType.User,
|
||||
userSlug: "testuser",
|
||||
secretName: "api-key",
|
||||
})
|
||||
.mockReturnValueOnce({
|
||||
secretType: SecretType.Organization,
|
||||
orgSlug: "testorg",
|
||||
secretName: "api-key",
|
||||
});
|
||||
|
||||
const result = usesFreeTrialApiKey(config);
|
||||
expect(result).toBe(false);
|
||||
expect(decodeSecretLocation).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it("should return true when at least one model uses free trial API key", () => {
|
||||
const config: BrowserSerializedContinueConfig = {
|
||||
modelsByRole: {
|
||||
chat: [
|
||||
{
|
||||
title: "Model 1",
|
||||
provider: "test",
|
||||
model: "test-model",
|
||||
apiKeyLocation: "user:testuser/api-key",
|
||||
underlyingProviderName: "test",
|
||||
},
|
||||
{
|
||||
title: "Free Trial Model",
|
||||
provider: "test",
|
||||
model: "free-trial-model",
|
||||
apiKeyLocation: "free_trial:owner/package/api-key",
|
||||
underlyingProviderName: "test",
|
||||
},
|
||||
],
|
||||
edit: [],
|
||||
apply: [],
|
||||
summarize: [],
|
||||
autocomplete: [],
|
||||
rerank: [],
|
||||
embed: [],
|
||||
},
|
||||
selectedModelByRole: {
|
||||
chat: null,
|
||||
edit: null,
|
||||
apply: null,
|
||||
summarize: null,
|
||||
autocomplete: null,
|
||||
rerank: null,
|
||||
embed: null,
|
||||
},
|
||||
contextProviders: [],
|
||||
slashCommands: [],
|
||||
tools: [],
|
||||
mcpServerStatuses: [],
|
||||
usePlatform: false,
|
||||
rules: [],
|
||||
};
|
||||
|
||||
vi.mocked(decodeSecretLocation)
|
||||
.mockReturnValueOnce({
|
||||
secretType: SecretType.User,
|
||||
userSlug: "testuser",
|
||||
secretName: "api-key",
|
||||
})
|
||||
.mockReturnValueOnce({
|
||||
secretType: SecretType.FreeTrial,
|
||||
blockSlug: { ownerSlug: "owner", packageSlug: "package" },
|
||||
secretName: "api-key",
|
||||
});
|
||||
|
||||
const result = usesFreeTrialApiKey(config);
|
||||
expect(result).toBe(true);
|
||||
expect(decodeSecretLocation).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it("should return true when free trial model is in a different role", () => {
|
||||
const config: BrowserSerializedContinueConfig = {
|
||||
modelsByRole: {
|
||||
chat: [
|
||||
{
|
||||
title: "Model 1",
|
||||
provider: "test",
|
||||
model: "test-model",
|
||||
apiKeyLocation: "user:testuser/api-key",
|
||||
underlyingProviderName: "test",
|
||||
},
|
||||
],
|
||||
edit: [
|
||||
{
|
||||
title: "Free Trial Edit Model",
|
||||
provider: "test",
|
||||
model: "free-trial-edit-model",
|
||||
apiKeyLocation: "free_trial:owner/package/api-key",
|
||||
underlyingProviderName: "test",
|
||||
},
|
||||
],
|
||||
apply: [],
|
||||
summarize: [],
|
||||
autocomplete: [],
|
||||
rerank: [],
|
||||
embed: [],
|
||||
},
|
||||
selectedModelByRole: {
|
||||
chat: null,
|
||||
edit: null,
|
||||
apply: null,
|
||||
summarize: null,
|
||||
autocomplete: null,
|
||||
rerank: null,
|
||||
embed: null,
|
||||
},
|
||||
contextProviders: [],
|
||||
slashCommands: [],
|
||||
tools: [],
|
||||
mcpServerStatuses: [],
|
||||
usePlatform: false,
|
||||
rules: [],
|
||||
};
|
||||
|
||||
vi.mocked(decodeSecretLocation)
|
||||
.mockReturnValueOnce({
|
||||
secretType: SecretType.User,
|
||||
userSlug: "testuser",
|
||||
secretName: "api-key",
|
||||
})
|
||||
.mockReturnValueOnce({
|
||||
secretType: SecretType.FreeTrial,
|
||||
blockSlug: { ownerSlug: "owner", packageSlug: "package" },
|
||||
secretName: "api-key",
|
||||
});
|
||||
|
||||
const result = usesFreeTrialApiKey(config);
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
it("should return false and log error when decodeSecretLocation throws", () => {
|
||||
const consoleSpy = vi.spyOn(console, "error").mockImplementation(() => {});
|
||||
|
||||
const config: BrowserSerializedContinueConfig = {
|
||||
modelsByRole: {
|
||||
chat: [
|
||||
{
|
||||
title: "Model 1",
|
||||
provider: "test",
|
||||
model: "test-model",
|
||||
apiKeyLocation: "invalid-secret-location",
|
||||
underlyingProviderName: "test",
|
||||
},
|
||||
],
|
||||
edit: [],
|
||||
apply: [],
|
||||
summarize: [],
|
||||
autocomplete: [],
|
||||
rerank: [],
|
||||
embed: [],
|
||||
},
|
||||
selectedModelByRole: {
|
||||
chat: null,
|
||||
edit: null,
|
||||
apply: null,
|
||||
summarize: null,
|
||||
autocomplete: null,
|
||||
rerank: null,
|
||||
embed: null,
|
||||
},
|
||||
contextProviders: [],
|
||||
slashCommands: [],
|
||||
tools: [],
|
||||
mcpServerStatuses: [],
|
||||
usePlatform: false,
|
||||
rules: [],
|
||||
};
|
||||
|
||||
vi.mocked(decodeSecretLocation).mockImplementation(() => {
|
||||
throw new Error("Invalid secret location format");
|
||||
});
|
||||
|
||||
const result = usesFreeTrialApiKey(config);
|
||||
expect(result).toBe(false);
|
||||
expect(consoleSpy).toHaveBeenCalledWith(
|
||||
"Error checking for free trial API key:",
|
||||
expect.any(Error),
|
||||
);
|
||||
|
||||
consoleSpy.mockRestore();
|
||||
});
|
||||
|
||||
it("should handle empty modelsByRole object", () => {
|
||||
const config: BrowserSerializedContinueConfig = {
|
||||
modelsByRole: {
|
||||
chat: [],
|
||||
edit: [],
|
||||
apply: [],
|
||||
summarize: [],
|
||||
autocomplete: [],
|
||||
rerank: [],
|
||||
embed: [],
|
||||
},
|
||||
selectedModelByRole: {
|
||||
chat: null,
|
||||
edit: null,
|
||||
apply: null,
|
||||
summarize: null,
|
||||
autocomplete: null,
|
||||
rerank: null,
|
||||
embed: null,
|
||||
},
|
||||
contextProviders: [],
|
||||
slashCommands: [],
|
||||
tools: [],
|
||||
mcpServerStatuses: [],
|
||||
usePlatform: false,
|
||||
rules: [],
|
||||
};
|
||||
|
||||
const result = usesFreeTrialApiKey(config);
|
||||
expect(result).toBe(false);
|
||||
expect(decodeSecretLocation).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
|
@ -8,6 +8,7 @@ type LocalStorageTypes = {
|
|||
hasDismissedOnboardingCard: boolean;
|
||||
mainTextEntryCounter: number;
|
||||
ide: "vscode" | "jetbrains";
|
||||
vsCodeUriScheme: string;
|
||||
ftc: number;
|
||||
fontSize: number;
|
||||
[key: `inputHistory_${string}`]: JSONContent[];
|
||||
|
|
|
|||
1518
package-lock.json
generated
1518
package-lock.json
generated
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue