Merge branch 'preview' into nate/mistral-prefilling

This commit is contained in:
Nate Sesti 2024-05-27 20:40:34 -07:00
commit 507010bdf1
25 changed files with 507 additions and 13809 deletions

View file

@ -51,7 +51,7 @@ async function installNodeModuleInTempDirAndCopyToCurrent(packageName, toCopy) {
console.log(`Copying ${packageName} to ${toCopy}`);
// This is a way to install only one package without npm trying to install all the dependencies
// Create a temporary directory for installing the package
const adjustedName = packageName.replace(/^@/, "").replace("/", "-");
const adjustedName = toCopy.replace(/^@/, "").replace("/", "-");
const tempDir = path.join(
__dirname,
"tmp",

5916
binary/pnpm-lock.yaml generated

File diff suppressed because it is too large Load diff

View file

@ -2,6 +2,7 @@ import {
ContextProviderWithParams,
ModelDescription,
SerializedContinueConfig,
SlashCommandDescription,
} from "../index.js";
export const FREE_TRIAL_MODELS: ModelDescription[] = [
@ -65,7 +66,7 @@ export const defaultConfigJetBrains: SerializedContinueConfig = {
},
};
export const defaultSlashCommandsVscode = [
export const defaultSlashCommandsVscode: SlashCommandDescription[] = [
{
name: "edit",
description: "Edit selected code",
@ -82,6 +83,10 @@ export const defaultSlashCommandsVscode = [
name: "cmd",
description: "Generate a shell command",
},
{
name: "commit",
description: "Generate a git commit message",
},
];
export const defaultSlashCommandsJetBrains = [
@ -97,6 +102,10 @@ export const defaultSlashCommandsJetBrains = [
name: "share",
description: "Export the current chat session to markdown",
},
{
name: "commit",
description: "Generate a git commit message",
},
];
export const defaultContextProvidersVsCode: ContextProviderWithParams[] = [

View file

@ -14,6 +14,7 @@ import { ContinueServerClient } from "./continueServer/stubs/client";
import { indexDocs } from "./indexing/docs";
import TransformersJsEmbeddingsProvider from "./indexing/embeddings/TransformersJsEmbeddingsProvider";
import { CodebaseIndexer, PauseToken } from "./indexing/indexCodebase";
import Ollama from "./llm/llms/Ollama";
import { FromCoreProtocol, ToCoreProtocol } from "./protocol";
import { GlobalContext } from "./util/GlobalContext";
import { logDevData } from "./util/devdata";
@ -357,7 +358,15 @@ export class Core {
const model =
config.models.find((model) => model.title === msg.data.title) ??
config.models.find((model) => model.title?.startsWith(msg.data.title));
return model?.listModels();
if (model) {
return model.listModels();
} else {
if (msg.data.title === "Ollama") {
return new Ollama({ model: "" }).listModels();
} else {
return undefined;
}
}
});
async function* runNodeJsSlashCommand(
@ -484,6 +493,16 @@ export class Core {
this.configHandler.reloadConfig();
});
on("addAutocompleteModel", (msg) => {
editConfigJson((config) => {
return {
...config,
tabAutocompleteModel: msg.data.model,
};
});
this.configHandler.reloadConfig();
});
on("stats/getTokensPerDay", async (msg) => {
const rows = await DevDataSqliteDb.getTokensPerDay();
return rows;

1
core/index.d.ts vendored
View file

@ -538,6 +538,7 @@ type ModelProvider =
| "flowise"
| "groq"
| "continue-proxy"
| "fireworks"
| "custom";
export type ModelName =

View file

@ -241,6 +241,11 @@ const configs: SiteIndexingConfig[] = [
startUrl: "https://alpinejs.dev/start-here",
rootUrl: "https://alpinejs.dev/",
},
{
title: "C# Language Reference",
startUrl: "https://learn.microsoft.com/en-us/dotnet/csharp/",
rootUrl: "https://learn.microsoft.com/en-us/dotnet/csharp/",
},
];
export default configs;

View file

@ -17,7 +17,14 @@ class EmbeddingsPipeline {
env.allowLocalModels = true;
env.allowRemoteModels = false;
env.localModelPath = path.join(__dirname, "..", "models");
env.localModelPath = path.join(
typeof __dirname === "undefined"
? // @ts-ignore
path.dirname(new URL(import.meta.url).pathname)
: __dirname,
"..",
"models",
);
EmbeddingsPipeline.instance = await pipeline(
EmbeddingsPipeline.task,

View file

@ -0,0 +1,18 @@
import { LLMOptions, ModelProvider } from "../../index.js";
import OpenAI from "./OpenAI.js";
class Fireworks extends OpenAI {
static providerName: ModelProvider = "fireworks";
static defaultOptions: Partial<LLMOptions> = {
apiBase: "https://api.fireworks.ai/inference/v1",
};
private static modelConversion: { [key: string]: string } = {
"starcoder-7b": "accounts/fireworks/models/starcoder-7b",
};
protected _convertModelName(model: string): string {
return Fireworks.modelConversion[model] ?? model;
}
}
export default Fireworks;

View file

@ -12,6 +12,7 @@ import Anthropic from "./Anthropic.js";
import Bedrock from "./Bedrock.js";
import Cohere from "./Cohere.js";
import DeepInfra from "./DeepInfra.js";
import Fireworks from "./Fireworks.js";
import Flowise from "./Flowise.js";
import FreeTrial from "./FreeTrial.js";
import Gemini from "./Gemini.js";
@ -96,6 +97,7 @@ const LLMs = [
DeepInfra,
Flowise,
Groq,
Fireworks,
ContinueProxy,
];

View file

@ -1,6 +1,6 @@
{
"name": "@continuedev/core",
"version": "1.0.12",
"version": "1.0.13",
"description": "The Continue Core contains functionality that can be shared across web, VS Code, or Node.js server. It is written in TypeScript and contains much of the functionality that was previously inside of the legacy Continue Python Server.",
"scripts": {
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" jest ./test/diff.test.ts",

7734
core/pnpm-lock.yaml generated

File diff suppressed because it is too large Load diff

View file

@ -6,6 +6,7 @@ import {
DiffLine,
LLMFullCompletionOptions,
MessageContent,
ModelDescription,
PersistedSessionInfo,
RangeInFile,
SerializedContinueConfig,
@ -133,4 +134,5 @@ export type ToCoreFromIdeOrWebviewProtocol = {
},
void,
];
addAutocompleteModel: [{ model: ModelDescription }, void];
};

View file

@ -37,6 +37,7 @@ export const WEBVIEW_TO_CORE_PASS_THROUGH: (keyof ToCoreFromWebviewProtocol)[] =
"index/setPaused",
"index/forceReIndex",
"completeOnboarding",
"addAutocompleteModel",
];
// Message types to pass through from core to webview

View file

@ -65,7 +65,8 @@ class ContinueBrowser(val project: Project, url: String, useOsr: Boolean = false
"stats/getTokensPerModel",
"index/setPaused",
"index/forceReIndex",
"completeOnboarding"
"completeOnboarding",
"addAutocompleteModel"
)
private fun registerAppSchemeHandler() {

View file

@ -149,6 +149,7 @@
"deepinfra",
"flowise",
"groq",
"fireworks",
"continue-proxy"
],
"markdownEnumDescriptions": [
@ -825,6 +826,23 @@
}
}
},
{
"if": {
"properties": {
"provider": {
"enum": ["fireworks"]
}
},
"required": ["provider"]
},
"then": {
"properties": {
"model": {
"enum": ["starcoder-7b"]
}
}
}
},
{
"if": {
"properties": {

View file

@ -316,7 +316,7 @@ const exe = os === "win32" ? ".exe" : "";
console.log(`Copying ${packageName} to ${toCopy}`);
// This is a way to install only one package without npm trying to install all the dependencies
// Create a temporary directory for installing the package
const adjustedName = packageName.replace(/^@/, "").replace("/", "-");
const adjustedName = toCopy.replace(/^@/, "").replace("/", "-");
const tempDir = `/tmp/continue-node_modules-${adjustedName}`;
const currentDir = process.cwd();

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

View file

@ -17,6 +17,7 @@ import useSubmenuContextProviders from "./hooks/useSubmenuContextProviders";
import { useVscTheme } from "./hooks/useVscTheme";
import GUI from "./pages/gui";
import LocalOnboarding from "./pages/localOnboarding";
import ApiKeyAutocompleteOnboarding from "./pages/onboarding/apiKeyAutocompleteOnboarding";
import ApiKeyOnboarding from "./pages/onboarding/apiKeyOnboarding";
import ExistingUserOnboarding from "./pages/onboarding/existingUserOnboarding";
import Onboarding from "./pages/onboarding/onboarding";
@ -88,6 +89,10 @@ const router = createMemoryRouter([
path: "/apiKeyOnboarding",
element: <ApiKeyOnboarding />,
},
{
path: "/apiKeyAutocompleteOnboarding",
element: <ApiKeyAutocompleteOnboarding />,
},
],
},
]);

View file

@ -0,0 +1,87 @@
import { useContext, useState } from "react";
import { useNavigate } from "react-router-dom";
import { Button, Input, SecondaryButton, vscForeground } from "../..";
import { IdeMessengerContext } from "../../../context/IdeMessenger";
import { isJetBrains } from "../../../util";
interface GitHubSignInButtonProps {
onComplete: (token: string) => void;
}
function GitHubSignInButton(props: GitHubSignInButtonProps) {
const ideMessenger = useContext(IdeMessengerContext);
const navigate = useNavigate();
const [jbGhAuthToken, setJbGhAuthToken] = useState("");
return isJetBrains() ? (
<div className="text-center">
<div className="flex justify-center">
<SecondaryButton
onClick={() => {
ideMessenger.post(
"openUrl",
"https://github.com/settings/tokens/new?scopes=user:email&description=Continue%20Free%20Trial%20Token%20",
);
}}
className="grid grid-flow-col items-center gap-2"
>
<svg
viewBox="0 0 98 96"
height={24}
xmlns="http://www.w3.org/2000/svg"
>
<path
fill-rule="evenodd"
clip-rule="evenodd"
d="M48.854 0C21.839 0 0 22 0 49.217c0 21.756 13.993 40.172 33.405 46.69 2.427.49 3.316-1.059 3.316-2.362 0-1.141-.08-5.052-.08-9.127-13.59 2.934-16.42-5.867-16.42-5.867-2.184-5.704-5.42-7.17-5.42-7.17-4.448-3.015.324-3.015.324-3.015 4.934.326 7.523 5.052 7.523 5.052 4.367 7.496 11.404 5.378 14.235 4.074.404-3.178 1.699-5.378 3.074-6.6-10.839-1.141-22.243-5.378-22.243-24.283 0-5.378 1.94-9.778 5.014-13.2-.485-1.222-2.184-6.275.486-13.038 0 0 4.125-1.304 13.426 5.052a46.97 46.97 0 0 1 12.214-1.63c4.125 0 8.33.571 12.213 1.63 9.302-6.356 13.427-5.052 13.427-5.052 2.67 6.763.97 11.816.485 13.038 3.155 3.422 5.015 7.822 5.015 13.2 0 18.905-11.404 23.06-22.324 24.283 1.78 1.548 3.316 4.481 3.316 9.126 0 6.6-.08 11.897-.08 13.526 0 1.304.89 2.853 3.316 2.364 19.412-6.52 33.405-24.935 33.405-46.691C97.707 22 75.788 0 48.854 0z"
fill={vscForeground}
/>
</svg>
Generate Token
</SecondaryButton>
</div>
<Input
placeholder="Paste token here"
value={jbGhAuthToken}
onChange={(e) => setJbGhAuthToken(e.target.value)}
/>
<Button
disabled={!jbGhAuthToken}
onClick={async () => {
await ideMessenger.request("setGitHubAuthToken", {
token: jbGhAuthToken,
});
props.onComplete(jbGhAuthToken);
}}
>
Continue
</Button>
</div>
) : (
<div className="flex justify-center">
<SecondaryButton
onClick={async () => {
const token = await ideMessenger.request(
"getGitHubAuthToken",
undefined,
);
props.onComplete(token);
}}
className="grid grid-flow-col items-center gap-2"
>
<svg viewBox="0 0 98 96" height={24} xmlns="http://www.w3.org/2000/svg">
<path
fill-rule="evenodd"
clip-rule="evenodd"
d="M48.854 0C21.839 0 0 22 0 49.217c0 21.756 13.993 40.172 33.405 46.69 2.427.49 3.316-1.059 3.316-2.362 0-1.141-.08-5.052-.08-9.127-13.59 2.934-16.42-5.867-16.42-5.867-2.184-5.704-5.42-7.17-5.42-7.17-4.448-3.015.324-3.015.324-3.015 4.934.326 7.523 5.052 7.523 5.052 4.367 7.496 11.404 5.378 14.235 4.074.404-3.178 1.699-5.378 3.074-6.6-10.839-1.141-22.243-5.378-22.243-24.283 0-5.378 1.94-9.778 5.014-13.2-.485-1.222-2.184-6.275.486-13.038 0 0 4.125-1.304 13.426 5.052a46.97 46.97 0 0 1 12.214-1.63c4.125 0 8.33.571 12.213 1.63 9.302-6.356 13.427-5.052 13.427-5.052 2.67 6.763.97 11.816.485 13.038 3.155 3.422 5.015 7.822 5.015 13.2 0 18.905-11.404 23.06-22.324 24.283 1.78 1.548 3.316 4.481 3.316 9.126 0 6.6-.08 11.897-.08 13.526 0 1.304.89 2.853 3.316 2.364 19.412-6.52 33.405-24.935 33.405-46.691C97.707 22 75.788 0 48.854 0z"
fill={vscForeground}
/>
</svg>
Sign in with GitHub
</SecondaryButton>
</div>
);
}
export default GitHubSignInButton;

View file

@ -12,6 +12,7 @@ import QuickSetupListBox from "./QuickSetupListBox";
interface QuickModelSetupProps {
onDone: () => void;
hideFreeTrialLimitMessage?: boolean;
}
function QuickModelSetup(props: QuickModelSetupProps) {
@ -41,7 +42,7 @@ function QuickModelSetup(props: QuickModelSetupProps) {
: "Add a new model"}
</h1> */}
{getLocalStorage("ftc") > ftl() && (
{!props.hideFreeTrialLimitMessage && getLocalStorage("ftc") > ftl() && (
<p className="text-sm text-gray-500">
You've reached the free trial limit of {ftl()} free inputs. To keep
using Continue, you can either use your own API key, or use a local

View file

@ -1,70 +1,13 @@
import { Listbox, Transition } from "@headlessui/react";
import { Transition } from "@headlessui/react";
import { CheckIcon, ChevronUpDownIcon } from "@heroicons/react/24/outline";
import { Dispatch, Fragment, SetStateAction } from "react";
import styled from "styled-components";
import {
defaultBorderRadius,
vscBackground,
vscButtonBackground,
vscForeground,
vscInputBackground,
vscListActiveBackground,
vscListActiveForeground,
} from "../..";
import { DisplayInfo } from "../../../util/modelData";
const StyledListbox = styled(Listbox)`
background-color: ${vscBackground};
`;
const StyledListboxButton = styled(Listbox.Button)`
cursor: pointer;
background-color: ${vscBackground};
text-align: left;
border: 1px solid ${vscButtonBackground};
margin: 0;
height: 100%;
width: 100%;
display: grid;
grid-template-columns: 1fr auto;
align-items: center;
color: ${vscForeground};
&:focus {
outline: none;
}
&:hover {
background-color: ${vscInputBackground};
}
`;
const StyledListboxOptions = styled(Listbox.Options)`
background-color: ${vscInputBackground};
padding: 0;
border-radius: ${defaultBorderRadius};
overflow-y: scroll;
z-index: 10;
`;
const StyledListboxOption = styled(Listbox.Option)<{ selected: boolean }>`
background-color: ${({ selected }) =>
selected ? vscListActiveBackground : vscInputBackground};
cursor: pointer;
padding: 6px 8px;
display: flex;
gap: 8px;
align-items: center;
&:hover {
background-color: ${vscListActiveBackground};
color: ${vscListActiveForeground};
}
`;
import {
StyledListbox,
StyledListboxButton,
StyledListboxOption,
StyledListboxOptions,
} from "./StyledListbox";
interface QuickSetupListBoxProps {
selectedProvider: DisplayInfo;
@ -80,7 +23,7 @@ function QuickSetupListBox({
return (
<StyledListbox value={selectedProvider} onChange={setSelectedProvider}>
<div className="relative mt-1">
<StyledListboxButton className="relative w-full cursor-default rounded-lg bg-white py-2 pl-3 pr-10 text-left shadow-md focus:outline-none sm:text-sm">
<StyledListboxButton>
<span className="flex items-center">
{window.vscMediaUrl && selectedProvider.icon && (
<img
@ -104,7 +47,7 @@ function QuickSetupListBox({
leaveFrom="opacity-100"
leaveTo="opacity-0"
>
<StyledListboxOptions className="absolute mt-1 max-h-60 w-full overflow-auto rounded-md bg-white py-1 text-base shadow-lg focus:outline-none sm:text-sm">
<StyledListboxOptions>
{options.map((option, index) => (
<StyledListboxOption
selected={selectedProvider.title === option.title}

View file

@ -0,0 +1,90 @@
import { Listbox } from "@headlessui/react";
import styled from "styled-components";
import {
defaultBorderRadius,
vscBackground,
vscButtonBackground,
vscForeground,
vscInputBackground,
vscListActiveBackground,
vscListActiveForeground,
} from "../..";
export const StyledListbox = styled(Listbox)`
background-color: ${vscBackground};
`;
export const StyledListboxButton = styled(Listbox.Button)`
cursor: pointer;
background-color: ${vscBackground};
text-align: left;
padding-left: 0.75rem;
padding-right: 2.5rem;
padding-top: 0.5rem;
padding-bottom: 0.5rem;
border-radius: 0.5em;
border: 1px solid ${vscButtonBackground};
margin: 0;
height: 100%;
width: 100%;
position: relative;
display: grid;
grid-template-columns: 1fr auto;
align-items: center;
color: ${vscForeground};
&:focus {
outline: none;
}
&:hover {
background-color: ${vscInputBackground};
}
`;
export const StyledListboxOptions = styled(Listbox.Options)`
background-color: ${vscInputBackground};
padding: 0;
position: absolute;
top: 100%;
left: 0;
right: 0;
margin-top: 0.25rem;
max-height: 15rem;
overflow: auto;
border-radius: ${defaultBorderRadius};
overflow-y: scroll;
z-index: 10;
&:focus {
outline: none;
}
`;
export const StyledListboxOption = styled(Listbox.Option)<{
selected: boolean;
}>`
background-color: ${({ selected }) =>
selected ? vscListActiveBackground : vscInputBackground};
cursor: pointer;
padding: 6px 8px;
display: flex;
gap: 8px;
align-items: center;
&:hover {
background-color: ${vscListActiveBackground};
color: ${vscListActiveForeground};
}
`;

View file

@ -0,0 +1,212 @@
import { Transition } from "@headlessui/react";
import { CheckIcon, ChevronUpDownIcon } from "@heroicons/react/24/outline";
import { ModelProvider } from "core";
import { Fragment, useContext, useState } from "react";
import { useNavigate } from "react-router-dom";
import { Button, Input, SecondaryButton } from "../../components";
import GitHubSignInButton from "../../components/modelSelection/quickSetup/GitHubSignInButton";
import {
StyledListbox,
StyledListboxButton,
StyledListboxOption,
StyledListboxOptions,
} from "../../components/modelSelection/quickSetup/StyledListbox";
import { IdeMessengerContext } from "../../context/IdeMessenger";
interface AutocompleteOption {
provider: ModelProvider;
title: string;
icon?: string;
}
const AUTOCOMPLETE_PROVIDER_OPTIONS: AutocompleteOption[] = [
{
provider: "free-trial",
title: "Free Trial",
icon: "fireworks.png",
},
{
provider: "fireworks",
title: "Fireworks AI",
icon: "fireworks.png",
},
{
provider: "ollama",
title: "Ollama",
icon: "ollama.png",
},
];
interface AutocompleteModelDropdownProps {
selectedProvider: AutocompleteOption;
setSelectedProvider: any;
}
function AutocompleteModelDropdown({
selectedProvider,
setSelectedProvider,
}: AutocompleteModelDropdownProps) {
return (
<StyledListbox value={selectedProvider} onChange={setSelectedProvider}>
<div className="relative mt-1">
<StyledListboxButton>
<span className="flex items-center">
{window.vscMediaUrl && selectedProvider.icon && (
<img
src={`${window.vscMediaUrl}/logos/${selectedProvider.icon}`}
height="24px"
style={{ marginRight: "10px" }}
/>
)}
<span className="text-md">{selectedProvider.title}</span>
</span>
<span className="pointer-events-none absolute inset-y-0 right-0 flex items-center pr-2">
<ChevronUpDownIcon
className="h-5 w-5 text-gray-400"
aria-hidden="true"
/>
</span>
</StyledListboxButton>
<Transition
as={Fragment}
leave="transition ease-in duration-100"
leaveFrom="opacity-100"
leaveTo="opacity-0"
>
<StyledListboxOptions>
{AUTOCOMPLETE_PROVIDER_OPTIONS.map((option, index) => (
<StyledListboxOption
selected={selectedProvider.title === option.title}
key={index}
className={({ active }) =>
`relative cursor-default select-none py-2 pl-10 pr-4 ${
active ? "bg-amber-100 text-amber-900" : "text-gray-900"
}`
}
value={option}
>
{({ selected }) => (
<>
{window.vscMediaUrl && option.icon && (
<img
src={`${window.vscMediaUrl}/logos/${option.icon}`}
height="24px"
style={{ marginRight: "10px" }}
/>
)}
<span className="text-md">{option.title}</span>
{selected ? (
<span className="inset-y-0 ml-auto flex items-center pl-3 text-amber-600">
<CheckIcon className="h-5 w-5" aria-hidden="true" />
</span>
) : null}
</>
)}
</StyledListboxOption>
))}
</StyledListboxOptions>
</Transition>
</div>
</StyledListbox>
);
}
function ApiKeyAutocompleteOnboarding() {
const ideMessenger = useContext(IdeMessengerContext);
const navigate = useNavigate();
const [selectedProvider, setSelectedProvider] = useState<AutocompleteOption>(
AUTOCOMPLETE_PROVIDER_OPTIONS[0],
);
const [apiKeyValue, setApiKeyValue] = useState<string>("");
return (
<div className="p-2 max-w-96 mt-16 mx-auto">
<h1 className="text-center">Autocomplete Model</h1>
<p className="text-center">
Tab autocomplete requires a separate model. Currently we are supporting
free usage by signing in with GitHub. Alternatively, select another
option from the dropdown.
</p>
<br />
<br />
<AutocompleteModelDropdown
selectedProvider={selectedProvider}
setSelectedProvider={setSelectedProvider}
></AutocompleteModelDropdown>
<br />
<br />
{selectedProvider.provider === "ollama" && (
<div className="text-center">
<Button
onClick={() => {
navigate("/localOnboarding");
}}
>
Set up Ollama
</Button>
</div>
)}
{selectedProvider.provider === "free-trial" && (
<div className="text-center">
<p>Sign in to GitHub to try autocomplete for free</p>
<GitHubSignInButton
onComplete={async (token) => {
await ideMessenger.request("addAutocompleteModel", {
model: {
title: "Autocomplete Trial",
provider: "free-trial",
model: "starcoder-7b",
},
});
navigate("/");
}}
></GitHubSignInButton>
</div>
)}
{selectedProvider.provider === "fireworks" && (
<div className="text-center">
<h4>Paste your API key</h4>
<SecondaryButton
className="w-full border-2 border-solid"
onClick={() => {
ideMessenger.post("openUrl", "https://fireworks.ai/api-keys");
}}
>
Get API Key
</SecondaryButton>
<Input
id="apiKey"
className="w-full"
placeholder="Enter API Key"
value={apiKeyValue}
onChange={(e) => {
setApiKeyValue(e.target.value);
}}
/>
<Button
onClick={async () => {
await ideMessenger.request("addAutocompleteModel", {
model: {
title: "Fireworks Autocomplete",
provider: "fireworks",
model: "starcoder-7b",
apiKey: apiKeyValue,
},
});
navigate("/");
}}
>
Save
</Button>
</div>
)}
</div>
);
}
export default ApiKeyAutocompleteOnboarding;

View file

@ -23,7 +23,7 @@ function ApiKeyOnboarding() {
<QuickModelSetup
onDone={() => {
ideMessenger.post("showTutorial", undefined);
navigate("/");
navigate("/apiKeyAutocompleteOnboarding");
}}
></QuickModelSetup>
</div>

View file

@ -1,15 +1,9 @@
import { useContext, useState } from "react";
import { useNavigate } from "react-router-dom";
import {
Button,
Input,
SecondaryButton,
greenButtonColor,
vscForeground,
} from "../../components";
import { greenButtonColor } from "../../components";
import { ftl } from "../../components/dialogs/FTCDialog";
import GitHubSignInButton from "../../components/modelSelection/quickSetup/GitHubSignInButton";
import { IdeMessengerContext } from "../../context/IdeMessenger";
import { isJetBrains } from "../../util";
import { getLocalStorage, setLocalStorage } from "../../util/localStorage";
import { Div, StyledButton } from "./components";
@ -22,8 +16,6 @@ function Onboarding() {
const [selected, setSelected] = useState(-1);
const [jbGhAuthToken, setJbGhAuthToken] = useState("");
return (
<div className="p-2 max-w-96 mt-16 mx-auto">
{getLocalStorage("ftc") > ftl() ? (
@ -139,80 +131,15 @@ function Onboarding() {
<p className="text-center">
OR sign in with GitHub to try 25 free requests
</p>
{isJetBrains() ? (
<div className="text-center">
<div className="flex justify-center">
<SecondaryButton
onClick={() => {
ideMessenger.post(
"openUrl",
"https://github.com/settings/tokens/new?scopes=user:email&description=Continue%20Free%20Trial%20Token%20",
);
}}
className="grid grid-flow-col items-center gap-2"
>
<svg
viewBox="0 0 98 96"
height={24}
xmlns="http://www.w3.org/2000/svg"
>
<path
fill-rule="evenodd"
clip-rule="evenodd"
d="M48.854 0C21.839 0 0 22 0 49.217c0 21.756 13.993 40.172 33.405 46.69 2.427.49 3.316-1.059 3.316-2.362 0-1.141-.08-5.052-.08-9.127-13.59 2.934-16.42-5.867-16.42-5.867-2.184-5.704-5.42-7.17-5.42-7.17-4.448-3.015.324-3.015.324-3.015 4.934.326 7.523 5.052 7.523 5.052 4.367 7.496 11.404 5.378 14.235 4.074.404-3.178 1.699-5.378 3.074-6.6-10.839-1.141-22.243-5.378-22.243-24.283 0-5.378 1.94-9.778 5.014-13.2-.485-1.222-2.184-6.275.486-13.038 0 0 4.125-1.304 13.426 5.052a46.97 46.97 0 0 1 12.214-1.63c4.125 0 8.33.571 12.213 1.63 9.302-6.356 13.427-5.052 13.427-5.052 2.67 6.763.97 11.816.485 13.038 3.155 3.422 5.015 7.822 5.015 13.2 0 18.905-11.404 23.06-22.324 24.283 1.78 1.548 3.316 4.481 3.316 9.126 0 6.6-.08 11.897-.08 13.526 0 1.304.89 2.853 3.316 2.364 19.412-6.52 33.405-24.935 33.405-46.691C97.707 22 75.788 0 48.854 0z"
fill={vscForeground}
/>
</svg>
Generate Token
</SecondaryButton>
</div>
<Input
placeholder="Paste token here"
value={jbGhAuthToken}
onChange={(e) => setJbGhAuthToken(e.target.value)}
/>
<Button
disabled={!jbGhAuthToken}
onClick={async () => {
await ideMessenger.request("setGitHubAuthToken", {
token: jbGhAuthToken,
});
setLocalStorage("onboardingComplete", true);
navigate("/");
}}
>
Continue
</Button>
</div>
) : (
<div className="flex justify-center">
<SecondaryButton
onClick={async () => {
await ideMessenger.request("getGitHubAuthToken", undefined);
setLocalStorage("onboardingComplete", true);
await ideMessenger.request("completeOnboarding", {
mode: "freeTrial",
});
navigate("/");
}}
className="grid grid-flow-col items-center gap-2"
>
<svg
viewBox="0 0 98 96"
height={24}
xmlns="http://www.w3.org/2000/svg"
>
<path
fill-rule="evenodd"
clip-rule="evenodd"
d="M48.854 0C21.839 0 0 22 0 49.217c0 21.756 13.993 40.172 33.405 46.69 2.427.49 3.316-1.059 3.316-2.362 0-1.141-.08-5.052-.08-9.127-13.59 2.934-16.42-5.867-16.42-5.867-2.184-5.704-5.42-7.17-5.42-7.17-4.448-3.015.324-3.015.324-3.015 4.934.326 7.523 5.052 7.523 5.052 4.367 7.496 11.404 5.378 14.235 4.074.404-3.178 1.699-5.378 3.074-6.6-10.839-1.141-22.243-5.378-22.243-24.283 0-5.378 1.94-9.778 5.014-13.2-.485-1.222-2.184-6.275.486-13.038 0 0 4.125-1.304 13.426 5.052a46.97 46.97 0 0 1 12.214-1.63c4.125 0 8.33.571 12.213 1.63 9.302-6.356 13.427-5.052 13.427-5.052 2.67 6.763.97 11.816.485 13.038 3.155 3.422 5.015 7.822 5.015 13.2 0 18.905-11.404 23.06-22.324 24.283 1.78 1.548 3.316 4.481 3.316 9.126 0 6.6-.08 11.897-.08 13.526 0 1.304.89 2.853 3.316 2.364 19.412-6.52 33.405-24.935 33.405-46.691C97.707 22 75.788 0 48.854 0z"
fill={vscForeground}
/>
</svg>
Sign in with GitHub
</SecondaryButton>
</div>
)}
<GitHubSignInButton
onComplete={async (token) => {
setLocalStorage("onboardingComplete", true);
await ideMessenger.request("completeOnboarding", {
mode: "freeTrial",
});
navigate("/");
}}
></GitHubSignInButton>
</>
)}
</div>