feat: use hub blocks for local onboarding
This commit is contained in:
parent
d9318d623f
commit
1b453083b1
29 changed files with 581 additions and 684 deletions
|
|
@ -8,6 +8,21 @@ export const LOCAL_ONBOARDING_CHAT_TITLE = "Llama 3.1 8B";
|
|||
export const LOCAL_ONBOARDING_EMBEDDINGS_MODEL = "nomic-embed-text:latest";
|
||||
export const LOCAL_ONBOARDING_EMBEDDINGS_TITLE = "Nomic Embed";
|
||||
|
||||
const ANTHROPIC_MODEL_CONFIG = {
|
||||
slugs: ["anthropic/claude-3-7-sonnet", "anthropic/claude-4-sonnet"],
|
||||
apiKeyInputName: "ANTHROPIC_API_KEY",
|
||||
};
|
||||
const OPENAI_MODEL_CONFIG = {
|
||||
slugs: ["openai/o3", "openai/gpt-4.1-mini", "openai/gpt-4.1"],
|
||||
apiKeyInputName: "OPENAI_API_KEY",
|
||||
};
|
||||
|
||||
// TODO: These need updating on the hub
|
||||
const GEMINI_MODEL_CONFIG = {
|
||||
slugs: ["google/gemini-2.0-flash", "google/gemini-2.5-pro"],
|
||||
apiKeyInputName: "GEMINI_API_KEY",
|
||||
};
|
||||
|
||||
/**
|
||||
* We set the "best" chat + autocopmlete models by default
|
||||
* whenever a user doesn't have a config.json
|
||||
|
|
@ -49,3 +64,45 @@ export function setupLocalConfig(config: ConfigYaml): ConfigYaml {
|
|||
export function setupQuickstartConfig(config: ConfigYaml): ConfigYaml {
|
||||
return config;
|
||||
}
|
||||
|
||||
export function setupProviderConfig(
|
||||
config: ConfigYaml,
|
||||
provider: string,
|
||||
apiKey: string,
|
||||
): ConfigYaml {
|
||||
let newModels;
|
||||
|
||||
switch (provider) {
|
||||
case "openai":
|
||||
newModels = OPENAI_MODEL_CONFIG.slugs.map((slug) => ({
|
||||
uses: slug,
|
||||
with: {
|
||||
[OPENAI_MODEL_CONFIG.apiKeyInputName]: apiKey,
|
||||
},
|
||||
}));
|
||||
break;
|
||||
case "anthropic":
|
||||
newModels = ANTHROPIC_MODEL_CONFIG.slugs.map((slug) => ({
|
||||
uses: slug,
|
||||
with: {
|
||||
[ANTHROPIC_MODEL_CONFIG.apiKeyInputName]: apiKey,
|
||||
},
|
||||
}));
|
||||
break;
|
||||
case "gemini":
|
||||
newModels = GEMINI_MODEL_CONFIG.slugs.map((slug) => ({
|
||||
uses: slug,
|
||||
with: {
|
||||
[GEMINI_MODEL_CONFIG.apiKeyInputName]: apiKey,
|
||||
},
|
||||
}));
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unknown provider: ${provider}`);
|
||||
}
|
||||
|
||||
return {
|
||||
...config,
|
||||
models: [...(config.models ?? []), ...newModels],
|
||||
};
|
||||
}
|
||||
|
|
|
|||
34
core/core.ts
34
core/core.ts
|
|
@ -34,6 +34,7 @@ import { getSymbolsForManyFiles } from "./util/treeSitter";
|
|||
import { TTS } from "./util/tts";
|
||||
|
||||
import {
|
||||
CompleteOnboardingPayload,
|
||||
ContextItemWithId,
|
||||
IdeSettings,
|
||||
ModelDescription,
|
||||
|
|
@ -46,7 +47,11 @@ import {
|
|||
import { ConfigYaml } from "@continuedev/config-yaml";
|
||||
import { getDiffFn, GitDiffCache } from "./autocomplete/snippets/gitDiffCache";
|
||||
import { isLocalAssistantFile } from "./config/loadLocalAssistants";
|
||||
import { setupLocalConfig, setupQuickstartConfig } from "./config/onboarding";
|
||||
import {
|
||||
setupLocalConfig,
|
||||
setupProviderConfig,
|
||||
setupQuickstartConfig,
|
||||
} from "./config/onboarding";
|
||||
import { createNewWorkspaceBlockFile } from "./config/workspace/workspaceBlocks";
|
||||
import { MCPManagerSingleton } from "./context/mcp/MCPManagerSingleton";
|
||||
import { setMdmLicenseKey } from "./control-plane/mdm/mdm";
|
||||
|
|
@ -506,7 +511,7 @@ export class Core {
|
|||
abortManager.clear();
|
||||
});
|
||||
|
||||
on("completeOnboarding", this.handleCompleteOnboarding.bind(this));
|
||||
on("onboarding/complete", this.handleCompleteOnboarding.bind(this));
|
||||
|
||||
on("addAutocompleteModel", this.handleAddAutocompleteModel.bind(this));
|
||||
|
||||
|
|
@ -874,32 +879,21 @@ export class Core {
|
|||
}
|
||||
|
||||
private async handleCompleteOnboarding(
|
||||
msg: Message<{ mode: OnboardingModes; models?: any[] }>,
|
||||
msg: Message<CompleteOnboardingPayload>,
|
||||
) {
|
||||
const { mode, models } = msg.data;
|
||||
const { mode, provider, apiKey } = msg.data;
|
||||
|
||||
let editConfigYamlCallback: (config: ConfigYaml) => ConfigYaml;
|
||||
|
||||
switch (mode) {
|
||||
case OnboardingModes.OLLAMA:
|
||||
case OnboardingModes.LOCAL:
|
||||
editConfigYamlCallback = setupLocalConfig;
|
||||
break;
|
||||
|
||||
case OnboardingModes.API_KEYS:
|
||||
if (models && models.length > 0) {
|
||||
editConfigYamlCallback = (config: ConfigYaml) => ({
|
||||
...config,
|
||||
models: [
|
||||
...(config.models ?? []),
|
||||
...models.map((model) => ({
|
||||
name: model.title,
|
||||
provider: model.provider,
|
||||
model: model.model,
|
||||
apiKey: model.apiKey,
|
||||
roles: ["chat", "edit"] as any,
|
||||
})),
|
||||
],
|
||||
});
|
||||
case OnboardingModes.PROVIDERS:
|
||||
if (provider && apiKey) {
|
||||
editConfigYamlCallback = (config: ConfigYaml) =>
|
||||
setupProviderConfig(config, provider, apiKey);
|
||||
} else {
|
||||
editConfigYamlCallback = setupQuickstartConfig;
|
||||
}
|
||||
|
|
|
|||
0
core/core_temp.ts
Normal file
0
core/core_temp.ts
Normal file
6
core/index.d.ts
vendored
6
core/index.d.ts
vendored
|
|
@ -1578,3 +1578,9 @@ export interface RuleWithSource {
|
|||
ruleFile?: string;
|
||||
alwaysApply?: boolean;
|
||||
}
|
||||
|
||||
export interface CompleteOnboardingPayload {
|
||||
mode: OnboardingModes;
|
||||
provider?: string;
|
||||
apiKey?: string;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import { GlobalContextModelSelections } from "../util/GlobalContext";
|
|||
import {
|
||||
BrowserSerializedContinueConfig,
|
||||
ChatMessage,
|
||||
CompleteOnboardingPayload,
|
||||
ContextItem,
|
||||
ContextItemWithId,
|
||||
ContextSubmenuItem,
|
||||
|
|
@ -37,8 +38,8 @@ import { ControlPlaneSessionInfo } from "../control-plane/AuthTypes";
|
|||
import { FreeTrialStatus } from "../control-plane/client";
|
||||
|
||||
export enum OnboardingModes {
|
||||
API_KEYS = "API Keys",
|
||||
OLLAMA = "Ollama",
|
||||
PROVIDERS = "Providers",
|
||||
LOCAL = "Local",
|
||||
}
|
||||
|
||||
export interface ListHistoryOptions {
|
||||
|
|
@ -172,13 +173,7 @@ export type ToCoreFromIdeOrWebviewProtocol = {
|
|||
void,
|
||||
];
|
||||
"index/indexingProgressBarInitialized": [undefined, void];
|
||||
completeOnboarding: [
|
||||
{
|
||||
mode: OnboardingModes;
|
||||
models?: any[];
|
||||
},
|
||||
void,
|
||||
];
|
||||
"onboarding/complete": [CompleteOnboardingPayload, void];
|
||||
|
||||
// File changes
|
||||
"files/changed": [{ uris?: string[] }, void];
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ export const WEBVIEW_TO_CORE_PASS_THROUGH: (keyof ToCoreFromWebviewProtocol)[] =
|
|||
"docs/initStatuses",
|
||||
"docs/getDetails",
|
||||
//
|
||||
"completeOnboarding",
|
||||
"onboarding/complete",
|
||||
"addAutocompleteModel",
|
||||
"didChangeSelectedProfile",
|
||||
"didChangeSelectedOrg",
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ class MessageTypes {
|
|||
"docs/initStatuses",
|
||||
"docs/getDetails",
|
||||
//
|
||||
"completeOnboarding",
|
||||
onboarding/complete,
|
||||
"addAutocompleteModel",
|
||||
"didChangeSelectedProfile",
|
||||
"didChangeSelectedOrg",
|
||||
|
|
|
|||
4
extensions/vscode/package-lock.json
generated
4
extensions/vscode/package-lock.json
generated
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "continue",
|
||||
"version": "1.1.44",
|
||||
"version": "1.1.45",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "continue",
|
||||
"version": "1.1.44",
|
||||
"version": "1.1.45",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@continuedev/config-types": "^1.0.14",
|
||||
|
|
|
|||
14
gui/package-lock.json
generated
14
gui/package-lock.json
generated
|
|
@ -8,6 +8,7 @@
|
|||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@continuedev/config-yaml": "file:../packages/config-yaml",
|
||||
"@continuedev/llm-info": "file:../packages/llm-info",
|
||||
"@headlessui/react": "^2.2.0",
|
||||
"@heroicons/react": "^2.0.18",
|
||||
"@reduxjs/toolkit": "^2.3.0",
|
||||
|
|
@ -232,6 +233,15 @@
|
|||
"zod-to-json-schema": "^3.24.5"
|
||||
}
|
||||
},
|
||||
"../packages/llm-info": {
|
||||
"name": "@continuedev/llm-info",
|
||||
"version": "1.0.9",
|
||||
"license": "Apache-2.0",
|
||||
"devDependencies": {
|
||||
"@types/node": "^22.15.29",
|
||||
"typescript": "^5.5.2"
|
||||
}
|
||||
},
|
||||
"node_modules/@adobe/css-tools": {
|
||||
"version": "4.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@adobe/css-tools/-/css-tools-4.4.0.tgz",
|
||||
|
|
@ -576,6 +586,10 @@
|
|||
"resolved": "../packages/config-yaml",
|
||||
"link": true
|
||||
},
|
||||
"node_modules/@continuedev/llm-info": {
|
||||
"resolved": "../packages/llm-info",
|
||||
"link": true
|
||||
},
|
||||
"node_modules/@emotion/is-prop-valid": {
|
||||
"version": "1.3.1",
|
||||
"resolved": "https://registry.npmjs.org/@emotion/is-prop-valid/-/is-prop-valid-1.3.1.tgz",
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"@continuedev/config-yaml": "file:../packages/config-yaml",
|
||||
"@continuedev/llm-info": "file:../packages/llm-info",
|
||||
"@headlessui/react": "^2.2.0",
|
||||
"@heroicons/react": "^2.0.18",
|
||||
"@reduxjs/toolkit": "^2.3.0",
|
||||
|
|
|
|||
|
|
@ -1,25 +0,0 @@
|
|||
import { useContext } from "react";
|
||||
import { ButtonSubtext } from ".";
|
||||
import { IdeMessengerContext } from "../context/IdeMessenger";
|
||||
|
||||
function AddModelButtonSubtext() {
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
|
||||
return (
|
||||
<ButtonSubtext>
|
||||
This will update your{" "}
|
||||
<span
|
||||
className="cursor-pointer underline hover:brightness-125"
|
||||
onClick={() =>
|
||||
ideMessenger.post("config/openProfile", {
|
||||
profileId: undefined,
|
||||
})
|
||||
}
|
||||
>
|
||||
config file
|
||||
</span>
|
||||
</ButtonSubtext>
|
||||
);
|
||||
}
|
||||
|
||||
export default AddModelButtonSubtext;
|
||||
|
|
@ -133,7 +133,7 @@ const Layout = () => {
|
|||
useWebviewListener(
|
||||
"openOnboardingCard",
|
||||
async () => {
|
||||
onboardingCard.open(OnboardingModes.API_KEYS);
|
||||
onboardingCard.open(OnboardingModes.PROVIDERS);
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
|
@ -141,7 +141,7 @@ const Layout = () => {
|
|||
useWebviewListener(
|
||||
"setupLocalConfig",
|
||||
async () => {
|
||||
onboardingCard.open(OnboardingModes.OLLAMA);
|
||||
onboardingCard.open(OnboardingModes.LOCAL);
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@ import { useAppSelector } from "../../redux/hooks";
|
|||
import { getLocalStorage, setLocalStorage } from "../../util/localStorage";
|
||||
import { ReusableCard } from "../ReusableCard";
|
||||
import {
|
||||
OnboardingApiKeyTab,
|
||||
OnboardingCardLanding,
|
||||
OnboardingCardTabs,
|
||||
OnboardingOllamaTab,
|
||||
OnboardingLocalTab,
|
||||
OnboardingProvidersTab,
|
||||
} from "./components";
|
||||
import { useOnboardingCard } from "./hooks";
|
||||
|
||||
|
|
@ -29,12 +29,12 @@ export function OnboardingCard({ isDialog }: OnboardingCardProps) {
|
|||
|
||||
function renderTabContent() {
|
||||
switch (activeTab) {
|
||||
case OnboardingModes.API_KEYS:
|
||||
return <OnboardingApiKeyTab />;
|
||||
case OnboardingModes.OLLAMA:
|
||||
return <OnboardingOllamaTab />;
|
||||
case OnboardingModes.PROVIDERS:
|
||||
return <OnboardingProvidersTab />;
|
||||
case OnboardingModes.LOCAL:
|
||||
return <OnboardingLocalTab />;
|
||||
default:
|
||||
return <OnboardingApiKeyTab />;
|
||||
return <OnboardingProvidersTab />;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -58,7 +58,7 @@ export function OnboardingCard({ isDialog }: OnboardingCardProps) {
|
|||
>
|
||||
<div className="flex h-full w-full items-center justify-center">
|
||||
<OnboardingCardLanding
|
||||
onSelectConfigure={() => setActiveTab(OnboardingModes.API_KEYS)}
|
||||
onSelectConfigure={() => setActiveTab(OnboardingModes.PROVIDERS)}
|
||||
isDialog={isDialog}
|
||||
/>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,43 +0,0 @@
|
|||
import { OnboardingModes } from "core/protocol/core";
|
||||
import { useContext } from "react";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { Button, ButtonSubtext } from "../..";
|
||||
import { IdeMessengerContext } from "../../../context/IdeMessenger";
|
||||
import { useSubmitOnboarding } from "../hooks";
|
||||
|
||||
interface ApiKeySubmitButtonProps {
|
||||
isDialog?: boolean;
|
||||
}
|
||||
|
||||
function ApiKeySubmitButton({ isDialog }: ApiKeySubmitButtonProps) {
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
const dispatch = useDispatch();
|
||||
const { submitOnboarding } = useSubmitOnboarding(
|
||||
OnboardingModes.API_KEYS,
|
||||
isDialog,
|
||||
);
|
||||
|
||||
function onComplete() {
|
||||
submitOnboarding();
|
||||
}
|
||||
|
||||
async function onClick() {
|
||||
// REMOVED THIS LOGIC TO GET GITHUB TOKEN
|
||||
// SINCE NOW USES THE HUB FOR FREE TRIAL
|
||||
// AND COMPONENT IS CURRENTLY UNUSED
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="mt-4 w-full">
|
||||
<Button
|
||||
onClick={onClick}
|
||||
className="grid w-full grid-flow-col items-center gap-2"
|
||||
>
|
||||
Get started using our API keys
|
||||
</Button>
|
||||
<ButtonSubtext>Try 50 chat and 2k autocomplete requests</ButtonSubtext>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default ApiKeySubmitButton;
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
import { OnboardingModes } from "core/protocol/core";
|
||||
import { useContext } from "react";
|
||||
import { IdeMessengerContext } from "../../../context/IdeMessenger";
|
||||
import { AddModelForm } from "../../../forms";
|
||||
import { useSubmitOnboarding } from "../hooks/useSubmitOnboarding";
|
||||
|
||||
interface OnboardingApiKeyTabProps {
|
||||
isDialog?: boolean;
|
||||
}
|
||||
|
||||
export function OnboardingApiKeyTab({ isDialog }: OnboardingApiKeyTabProps) {
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
const { submitOnboarding } = useSubmitOnboarding(
|
||||
OnboardingModes.API_KEYS,
|
||||
isDialog,
|
||||
);
|
||||
|
||||
const handleSubmit = (models: any[]) => {
|
||||
// Send the models to core for configuration
|
||||
ideMessenger.post("completeOnboarding", {
|
||||
mode: OnboardingModes.API_KEYS,
|
||||
models,
|
||||
});
|
||||
|
||||
// Complete the onboarding flow
|
||||
submitOnboarding();
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex h-full w-full items-center justify-center">
|
||||
<AddModelForm onSubmit={handleSubmit} hideFreeTrialLimitMessage={true} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
import { ChevronRightIcon } from "@heroicons/react/24/outline";
|
||||
import { useContext } from "react";
|
||||
import { Button, ButtonSubtext } from "../..";
|
||||
import { Button, SecondaryButton } from "../..";
|
||||
import { useAuth } from "../../../context/Auth";
|
||||
import { IdeMessengerContext } from "../../../context/IdeMessenger";
|
||||
import { selectCurrentOrg } from "../../../redux";
|
||||
|
|
@ -61,7 +60,7 @@ export function OnboardingCardLanding({
|
|||
</>
|
||||
) : (
|
||||
<>
|
||||
<p className="w-full text-sm">
|
||||
<p className="mb-5 mt-0 w-full text-sm">
|
||||
Log in to access a free trial of the
|
||||
<br />
|
||||
<span
|
||||
|
|
@ -90,12 +89,9 @@ export function OnboardingCardLanding({
|
|||
</>
|
||||
)}
|
||||
|
||||
<ButtonSubtext onClick={onSelectConfigure}>
|
||||
<div className="mt-1 flex cursor-pointer items-center justify-center gap-1 hover:brightness-125">
|
||||
<span>Or, configure your own models</span>
|
||||
<ChevronRightIcon className="h-3 w-3" />
|
||||
</div>
|
||||
</ButtonSubtext>
|
||||
<SecondaryButton onClick={onSelectConfigure} className="w-full">
|
||||
Or, configure your own models
|
||||
</SecondaryButton>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,79 +1,64 @@
|
|||
import { KeyIcon } from "@heroicons/react/24/outline";
|
||||
import { OnboardingModes } from "core/protocol/core";
|
||||
import styled from "styled-components";
|
||||
import { vscForeground } from "../..";
|
||||
|
||||
interface OnboardingCardTabsProps {
|
||||
/** The currently active tab */
|
||||
activeTab: OnboardingModes;
|
||||
/** Callback function called when a tab is clicked */
|
||||
onTabClick: (tabName: OnboardingModes) => void;
|
||||
}
|
||||
|
||||
const StyledSelect = styled.select`
|
||||
width: 100%;
|
||||
padding: 0.5rem;
|
||||
background-color: transparent;
|
||||
color: ${vscForeground};
|
||||
border: none;
|
||||
border-bottom: 1px solid ${vscForeground};
|
||||
border-radius: 0;
|
||||
font-size: 1rem;
|
||||
cursor: pointer;
|
||||
display: block;
|
||||
|
||||
&:focus {
|
||||
outline: none;
|
||||
const getTabIcon = (tabTitle: OnboardingModes) => {
|
||||
if (tabTitle === OnboardingModes.PROVIDERS) {
|
||||
return <KeyIcon className="h-4 w-4" />;
|
||||
}
|
||||
`;
|
||||
|
||||
const TabButton = styled.button<{ isActive: boolean }>`
|
||||
margin-bottom: -1px;
|
||||
focus: outline-none;
|
||||
background: transparent;
|
||||
cursor: pointer;
|
||||
color: ${vscForeground};
|
||||
border: none;
|
||||
|
||||
${({ isActive }) =>
|
||||
isActive &&
|
||||
`
|
||||
border-style: solid;
|
||||
border-width: 0 0 2.5px 0;
|
||||
border-color: ${vscForeground};
|
||||
font-weight: bold;
|
||||
`}
|
||||
`;
|
||||
|
||||
const TabList = styled.div`
|
||||
border-style: solid;
|
||||
border-width: 0 0 0.5px 0;
|
||||
border-color: ${vscForeground};
|
||||
`;
|
||||
if (tabTitle === OnboardingModes.LOCAL) {
|
||||
return (
|
||||
<img
|
||||
src={`${window.vscMediaUrl}/logos/ollama.png`}
|
||||
alt="Ollama"
|
||||
className="h-4 w-4 object-contain"
|
||||
/>
|
||||
);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Tab navigation component for onboarding modes with responsive design
|
||||
*/
|
||||
export function OnboardingCardTabs({
|
||||
activeTab,
|
||||
onTabClick,
|
||||
}: OnboardingCardTabsProps) {
|
||||
console.log({ keys: Object.values(OnboardingModes) });
|
||||
return (
|
||||
<div>
|
||||
{/* Desktop/tablet tabs */}
|
||||
<div className="xs:block hidden">
|
||||
<TabList>
|
||||
<div className="border-foreground border-x-0 border-b border-t-0 border-solid">
|
||||
{Object.values(OnboardingModes).map((tabTitle) => {
|
||||
const isActive = activeTab === tabTitle;
|
||||
|
||||
return (
|
||||
<TabButton
|
||||
className="xs:py-2 xs:px-3 rounded-t-sm px-6 py-2 hover:brightness-125 sm:px-5"
|
||||
<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}
|
||||
isActive={activeTab === tabTitle}
|
||||
onClick={() => onTabClick(tabTitle as OnboardingModes)}
|
||||
data-testid={`onboarding-tab-${tabTitle}`}
|
||||
>
|
||||
<p className="m-0 font-medium">{tabTitle}</p>
|
||||
</TabButton>
|
||||
<p className="m-0 flex items-center gap-2">
|
||||
{getTabIcon(tabTitle)}
|
||||
{tabTitle}
|
||||
</p>
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</TabList>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="xs:hidden block">
|
||||
<StyledSelect
|
||||
<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"
|
||||
value={activeTab}
|
||||
onChange={(e) => onTabClick(e.target.value as OnboardingModes)}
|
||||
>
|
||||
|
|
@ -84,7 +69,7 @@ export function OnboardingCardTabs({
|
|||
</option>
|
||||
);
|
||||
})}
|
||||
</StyledSelect>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -7,28 +7,27 @@ import {
|
|||
} from "core/config/onboarding";
|
||||
import { OnboardingModes } from "core/protocol/core";
|
||||
import { useContext, useEffect, useState } from "react";
|
||||
import { Button, ButtonSubtext } from "../..";
|
||||
import { Button } from "../..";
|
||||
import { useAuth } from "../../../context/Auth";
|
||||
import { IdeMessengerContext } from "../../../context/IdeMessenger";
|
||||
import { useAppDispatch } from "../../../redux/hooks";
|
||||
import { setDialogMessage, setShowDialog } from "../../../redux/slices/uiSlice";
|
||||
import { updateSelectedModelByRole } from "../../../redux/thunks";
|
||||
import Alert from "../../gui/Alert";
|
||||
import { useSubmitOnboarding } from "../hooks";
|
||||
import OllamaModelDownload from "./OllamaModelDownload";
|
||||
import { OllamaStatus } from "./OllamaStatus";
|
||||
|
||||
const OLLAMA_CHECK_INTERVAL_MS = 3000;
|
||||
|
||||
interface OnboardingOllamaTabProps {
|
||||
interface OnboardingLocalTabProps {
|
||||
isDialog?: boolean;
|
||||
}
|
||||
|
||||
export function OnboardingOllamaTab({ isDialog }: OnboardingOllamaTabProps) {
|
||||
export function OnboardingLocalTab({ isDialog }: OnboardingLocalTabProps) {
|
||||
const dispatch = useAppDispatch();
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
const { submitOnboarding } = useSubmitOnboarding(
|
||||
OnboardingModes.OLLAMA,
|
||||
OnboardingModes.LOCAL,
|
||||
isDialog,
|
||||
);
|
||||
const [hasLoadedChatModel, setHasLoadedChatModel] = useState(false);
|
||||
|
|
@ -114,7 +113,7 @@ export function OnboardingOllamaTab({ isDialog }: OnboardingOllamaTabProps) {
|
|||
dispatch(setShowDialog(false));
|
||||
}
|
||||
|
||||
dispatch(
|
||||
void dispatch(
|
||||
updateSelectedModelByRole({
|
||||
selectedProfile,
|
||||
role: "chat",
|
||||
|
|
@ -137,45 +136,52 @@ export function OnboardingOllamaTab({ isDialog }: OnboardingOllamaTabProps) {
|
|||
};
|
||||
|
||||
return (
|
||||
<div className="mt-3 flex flex-col gap-1 px-2">
|
||||
<Alert>Configure Continue to run models locally using Ollama</Alert>
|
||||
<div className="flex h-full w-full items-center justify-center">
|
||||
<div className="w-full max-w-md">
|
||||
<div className="mt-3 flex flex-col gap-1 px-2">
|
||||
<div className="flex flex-col">
|
||||
<p className="mb-0 text-base font-bold leading-tight">
|
||||
Install Ollama
|
||||
</p>
|
||||
<OllamaStatus isOllamaConnected={isOllamaConnected} />
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col">
|
||||
<p className="mb-0 text-base font-bold leading-tight">Install Ollama</p>
|
||||
<OllamaStatus isOllamaConnected={isOllamaConnected} />
|
||||
</div>
|
||||
<OllamaModelDownload
|
||||
title="Download Chat model"
|
||||
modelName={LOCAL_ONBOARDING_CHAT_MODEL}
|
||||
hasDownloaded={hasDownloadedChatModel}
|
||||
/>
|
||||
|
||||
<OllamaModelDownload
|
||||
title="Download Chat model"
|
||||
modelName={LOCAL_ONBOARDING_CHAT_MODEL}
|
||||
hasDownloaded={hasDownloadedChatModel}
|
||||
/>
|
||||
<OllamaModelDownload
|
||||
title="Download Autocomplete model"
|
||||
modelName={LOCAL_ONBOARDING_FIM_MODEL}
|
||||
hasDownloaded={hasDownloadedAutocompleteModel}
|
||||
/>
|
||||
|
||||
<OllamaModelDownload
|
||||
title="Download Autocomplete model"
|
||||
modelName={LOCAL_ONBOARDING_FIM_MODEL}
|
||||
hasDownloaded={hasDownloadedAutocompleteModel}
|
||||
/>
|
||||
<OllamaModelDownload
|
||||
title="Download Embeddings model"
|
||||
modelName={LOCAL_ONBOARDING_EMBEDDINGS_MODEL}
|
||||
hasDownloaded={hasDownloadedEmbeddingsModel}
|
||||
/>
|
||||
|
||||
<OllamaModelDownload
|
||||
title="Download Embeddings model"
|
||||
modelName={LOCAL_ONBOARDING_EMBEDDINGS_MODEL}
|
||||
hasDownloaded={hasDownloadedEmbeddingsModel}
|
||||
/>
|
||||
|
||||
<div className="mt-4 w-full">
|
||||
<Button
|
||||
onClick={onClickSubmitOnboarding}
|
||||
className="w-full"
|
||||
disabled={!allDownloaded}
|
||||
>
|
||||
Connect
|
||||
</Button>
|
||||
<ButtonSubtext>
|
||||
<span className="cursor-pointer underline" onClick={onClickSkip}>
|
||||
Skip and configure manually
|
||||
</span>
|
||||
</ButtonSubtext>
|
||||
<div className="mt-4 w-full">
|
||||
<Button
|
||||
onClick={onClickSubmitOnboarding}
|
||||
className="w-full"
|
||||
disabled={!allDownloaded}
|
||||
>
|
||||
Connect
|
||||
</Button>
|
||||
<div className="w-full text-center">
|
||||
<span
|
||||
className="text-description-muted cursor-pointer underline"
|
||||
onClick={onClickSkip}
|
||||
>
|
||||
Skip and configure manually
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
|
@ -0,0 +1,105 @@
|
|||
import { OnboardingModes } from "core/protocol/core";
|
||||
import { FormProvider, useForm } from "react-hook-form";
|
||||
import { providers } from "../../../pages/AddNewModel/configs/providers";
|
||||
import { Button, Input } from "../../index";
|
||||
import { useSubmitOnboarding } from "../hooks/useSubmitOnboarding";
|
||||
|
||||
interface OnboardingProvidersTabProps {
|
||||
/** Whether this is being shown in a dialog context */
|
||||
isDialog?: boolean;
|
||||
}
|
||||
|
||||
export function OnboardingProvidersTab({
|
||||
isDialog,
|
||||
}: OnboardingProvidersTabProps) {
|
||||
const formMethods = useForm();
|
||||
const { submitOnboarding } = useSubmitOnboarding(
|
||||
OnboardingModes.PROVIDERS,
|
||||
isDialog,
|
||||
);
|
||||
|
||||
const providerConfigs = [
|
||||
providers["openai"],
|
||||
providers["anthropic"],
|
||||
providers["gemini"],
|
||||
];
|
||||
|
||||
const handleFormSubmit = () => {
|
||||
// Find the first provider with an API key entered
|
||||
for (const config of providerConfigs) {
|
||||
const apiKey = formMethods.watch(`${config?.provider}_apiKey`);
|
||||
if (apiKey?.trim()) {
|
||||
submitOnboarding(config?.provider, apiKey);
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const hasAnyApiKey = providerConfigs.some((config) => {
|
||||
const apiKey = formMethods.watch(`${config?.provider}_apiKey`);
|
||||
return apiKey?.trim();
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="flex h-full w-full items-center justify-center">
|
||||
<div className="w-full max-w-md">
|
||||
<FormProvider {...formMethods}>
|
||||
<div className="mt-5 space-y-6">
|
||||
<div className="space-y-4">
|
||||
{providerConfigs.map((config) => (
|
||||
<div key={config?.provider}>
|
||||
<label className="mb-1 flex items-center gap-3 text-sm font-medium">
|
||||
{window.vscMediaUrl && (
|
||||
<img
|
||||
src={`${window.vscMediaUrl}/logos/${config?.icon}`}
|
||||
alt={config?.provider}
|
||||
className="h-4 w-4 object-contain"
|
||||
/>
|
||||
)}
|
||||
{config?.title}
|
||||
</label>
|
||||
<Input
|
||||
id={`${config?.provider}_apiKey`}
|
||||
type="password"
|
||||
placeholder={`Enter your ${config?.title} API key`}
|
||||
className="w-full"
|
||||
{...formMethods.register(`${config?.provider}_apiKey`)}
|
||||
/>
|
||||
<span className="text-description-muted mt-1 block text-xs">
|
||||
<a
|
||||
href={config?.apiKeyUrl}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="cursor-pointer text-inherit underline hover:text-inherit hover:brightness-125"
|
||||
>
|
||||
Click here
|
||||
</a>{" "}
|
||||
to create a {config?.title} API key
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Button
|
||||
type="button"
|
||||
onClick={handleFormSubmit}
|
||||
disabled={!hasAnyApiKey}
|
||||
className="w-full"
|
||||
>
|
||||
Connect
|
||||
</Button>
|
||||
|
||||
<div className="w-full text-center">
|
||||
<span className="text-description-muted">
|
||||
<span className="cursor-pointer underline">Click here</span>{" "}
|
||||
to view more providers
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</FormProvider>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
@ -1,9 +1,7 @@
|
|||
export * from "./ApiKeySubmitButton";
|
||||
export * from "./JetBrainsFetchGitHubTokenDialog";
|
||||
export * from "./OllamaCompletedStep";
|
||||
export * from "./OllamaModelDownload";
|
||||
export * from "./OllamaStatus";
|
||||
export * from "./OnboardingApiKeyTab";
|
||||
export * from "./OnboardingCardLanding";
|
||||
export * from "./OnboardingCardTabs";
|
||||
export * from "./OnboardingOllamaTab";
|
||||
export * from "./OnboardingLocalTab";
|
||||
export * from "./OnboardingProvidersTab";
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ export function useOnboardingCard(): UseOnboardingCard {
|
|||
dispatch(
|
||||
setOnboardingCard({
|
||||
show: true,
|
||||
activeTab: tab ?? OnboardingModes.API_KEYS,
|
||||
activeTab: tab ?? OnboardingModes.PROVIDERS,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,13 +10,16 @@ export function useSubmitOnboarding(mode: OnboardingModes, isDialog = false) {
|
|||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
const { close: closeOnboardingCard } = useOnboardingCard();
|
||||
|
||||
function submitOnboarding() {
|
||||
function submitOnboarding(provider?: string, apiKey?: string) {
|
||||
const onboardingStatus = getLocalStorage("onboardingStatus");
|
||||
|
||||
// Always close the onboarding card and update config.json
|
||||
// Always close the onboarding card and update config.yaml
|
||||
closeOnboardingCard(isDialog);
|
||||
ideMessenger.post("completeOnboarding", {
|
||||
|
||||
ideMessenger.post("onboarding/complete", {
|
||||
mode,
|
||||
provider,
|
||||
apiKey,
|
||||
});
|
||||
|
||||
if (onboardingStatus === "Started") {
|
||||
|
|
@ -32,6 +35,8 @@ export function useSubmitOnboarding(mode: OnboardingModes, isDialog = false) {
|
|||
// Move to next step in onboarding
|
||||
ideMessenger.post("showTutorial", undefined);
|
||||
}
|
||||
|
||||
ideMessenger.post("config/openProfile", { profileId: undefined });
|
||||
}
|
||||
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ export function isNewUserOnboarding() {
|
|||
|
||||
export const defaultOnboardingCardState: OnboardingCardState = {
|
||||
show: false,
|
||||
activeTab: OnboardingModes.API_KEYS,
|
||||
activeTab: OnboardingModes.PROVIDERS,
|
||||
};
|
||||
|
||||
export enum OllamaConnectionStatuses {
|
||||
|
|
|
|||
|
|
@ -4,16 +4,6 @@ import {
|
|||
CubeIcon,
|
||||
} from "@heroicons/react/24/outline";
|
||||
import { Fragment } from "react";
|
||||
import styled from "styled-components";
|
||||
import {
|
||||
defaultBorderRadius,
|
||||
lightGray,
|
||||
vscBackground,
|
||||
vscForeground,
|
||||
vscInputBackground,
|
||||
vscListActiveBackground,
|
||||
vscListActiveForeground,
|
||||
} from "..";
|
||||
import {
|
||||
Listbox,
|
||||
ListboxButton,
|
||||
|
|
@ -23,87 +13,8 @@ import {
|
|||
} from "../../components/ui";
|
||||
import { DisplayInfo } from "../../pages/AddNewModel/configs/models";
|
||||
|
||||
export const StyledListbox = styled(Listbox)`
|
||||
background-color: ${vscBackground};
|
||||
`;
|
||||
|
||||
export const StyledListboxButton = styled(ListboxButton)`
|
||||
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 ${lightGray};
|
||||
|
||||
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(ListboxOptions)`
|
||||
background-color: ${vscInputBackground};
|
||||
padding: 0;
|
||||
|
||||
position: absolute;
|
||||
top: 100%;
|
||||
left: 0;
|
||||
|
||||
margin-top: 0.25rem;
|
||||
|
||||
height: fit-content;
|
||||
max-height: 15rem;
|
||||
width: 60%;
|
||||
|
||||
border-radius: ${defaultBorderRadius};
|
||||
overflow-y: auto;
|
||||
z-index: 10;
|
||||
|
||||
&:focus {
|
||||
outline: none;
|
||||
}
|
||||
`;
|
||||
|
||||
export const StyledListboxOption = styled(ListboxOption)<{
|
||||
selected: boolean;
|
||||
}>`
|
||||
background-color: ${({ selected }) =>
|
||||
selected ? vscListActiveBackground : vscInputBackground};
|
||||
cursor: pointer;
|
||||
padding: 6px 8px 6px 12px;
|
||||
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
|
||||
&:hover {
|
||||
background-color: ${vscListActiveBackground};
|
||||
color: ${vscListActiveForeground};
|
||||
}
|
||||
`;
|
||||
|
||||
interface ModelSelectionListboxProps {
|
||||
/** Model selection listbox for choosing AI providers */
|
||||
selectedProvider: DisplayInfo;
|
||||
setSelectedProvider: (val: DisplayInfo) => void;
|
||||
topOptions?: DisplayInfo[];
|
||||
|
|
@ -117,9 +28,9 @@ function ModelSelectionListbox({
|
|||
otherOptions = [],
|
||||
}: ModelSelectionListboxProps) {
|
||||
return (
|
||||
<StyledListbox value={selectedProvider} onChange={setSelectedProvider}>
|
||||
<Listbox value={selectedProvider} onChange={setSelectedProvider}>
|
||||
<div className="relative mb-2 mt-1">
|
||||
<StyledListboxButton>
|
||||
<ListboxButton className="bg-background border-border text-foreground hover:bg-input relative m-0 grid h-full w-full cursor-pointer grid-cols-[1fr_auto] items-center rounded-lg border border-solid py-2 pl-3 pr-10 text-left focus:outline-none">
|
||||
<span className="flex items-center">
|
||||
{window.vscMediaUrl && selectedProvider.icon && (
|
||||
<img
|
||||
|
|
@ -135,21 +46,26 @@ function ModelSelectionListbox({
|
|||
aria-hidden="true"
|
||||
/>
|
||||
</span>
|
||||
</StyledListboxButton>
|
||||
</ListboxButton>
|
||||
|
||||
<Transition
|
||||
as={Fragment}
|
||||
leave="transition ease-in duration-100"
|
||||
leaveFrom="opacity-100"
|
||||
leaveTo="opacity-0"
|
||||
>
|
||||
<StyledListboxOptions>
|
||||
<ListboxOptions className="bg-input rounded-default absolute left-0 top-full z-10 mt-1 h-fit w-3/5 overflow-y-auto p-0 focus:outline-none [&]:!max-h-[30vh]">
|
||||
{topOptions.length > 0 && (
|
||||
<div className="py-1">
|
||||
<div className="text-description-muted px-3 py-1 text-xs font-medium uppercase tracking-wider">
|
||||
Popular
|
||||
</div>
|
||||
{topOptions.map((option, index) => (
|
||||
<StyledListboxOption
|
||||
selected={selectedProvider.title === option.title}
|
||||
<ListboxOption
|
||||
key={index}
|
||||
className="relative cursor-default select-none py-2 pr-4"
|
||||
className={({ selected }: { selected: boolean }) =>
|
||||
` ${selected ? "bg-list-active" : "bg-input"} hover:bg-list-active hover:text-list-active-foreground relative flex cursor-default cursor-pointer select-none items-center justify-between gap-2 p-1.5 px-3 py-2 pr-4`
|
||||
}
|
||||
value={option}
|
||||
>
|
||||
{({ selected }) => (
|
||||
|
|
@ -173,22 +89,24 @@ function ModelSelectionListbox({
|
|||
)}
|
||||
</>
|
||||
)}
|
||||
</StyledListboxOption>
|
||||
</ListboxOption>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{topOptions.length > 0 && otherOptions.length > 0 && (
|
||||
<div className="bg-border my-1 h-px min-h-px" />
|
||||
)}
|
||||
|
||||
{otherOptions.length > 0 && (
|
||||
<div className="py-1">
|
||||
<div className="text-description-muted px-3 py-1 text-xs font-medium uppercase tracking-wider">
|
||||
Additional providers
|
||||
</div>
|
||||
{otherOptions.map((option, index) => (
|
||||
<StyledListboxOption
|
||||
selected={selectedProvider.title === option.title}
|
||||
<ListboxOption
|
||||
key={index}
|
||||
className="relative cursor-default select-none py-2 pr-4"
|
||||
className={({ selected }: { selected: boolean }) =>
|
||||
` ${selected ? "bg-list-active" : "bg-input"} hover:bg-list-active hover:text-list-active-foreground relative flex cursor-default cursor-pointer select-none items-center justify-between gap-2 p-1.5 px-3 py-2 pr-4`
|
||||
}
|
||||
value={option}
|
||||
>
|
||||
{({ selected }) => (
|
||||
|
|
@ -213,14 +131,14 @@ function ModelSelectionListbox({
|
|||
)}
|
||||
</>
|
||||
)}
|
||||
</StyledListboxOption>
|
||||
</ListboxOption>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</StyledListboxOptions>
|
||||
</ListboxOptions>
|
||||
</Transition>
|
||||
</div>
|
||||
</StyledListbox>
|
||||
</Listbox>
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,18 +1,7 @@
|
|||
import {
|
||||
ArrowTopRightOnSquareIcon,
|
||||
PlusCircleIcon,
|
||||
XCircleIcon,
|
||||
} from "@heroicons/react/24/outline";
|
||||
import { useContext } from "react";
|
||||
import { FormProvider, useFieldArray, useForm } from "react-hook-form";
|
||||
import {
|
||||
Button,
|
||||
GhostButton,
|
||||
Input,
|
||||
SecondaryButton,
|
||||
StyledActionButton,
|
||||
} from "../components";
|
||||
import AddModelButtonSubtext from "../components/AddModelButtonSubtext";
|
||||
import { ArrowTopRightOnSquareIcon } from "@heroicons/react/24/outline";
|
||||
import { useContext, useEffect, useState } from "react";
|
||||
import { FormProvider, useForm } from "react-hook-form";
|
||||
import { Button, Input, StyledActionButton } from "../components";
|
||||
import Alert from "../components/gui/Alert";
|
||||
import ModelSelectionListbox from "../components/modelSelection/ModelSelectionListbox";
|
||||
import { useAuth } from "../context/Auth";
|
||||
|
|
@ -26,9 +15,8 @@ import {
|
|||
import { useAppDispatch } from "../redux/hooks";
|
||||
import { updateSelectedModelByRole } from "../redux/thunks";
|
||||
|
||||
interface QuickModelSetupProps {
|
||||
onDone?: () => void;
|
||||
onSubmit?: (models: any[]) => void;
|
||||
interface AddModelFormProps {
|
||||
onDone: () => void;
|
||||
hideFreeTrialLimitMessage?: boolean;
|
||||
}
|
||||
|
||||
|
|
@ -37,41 +25,19 @@ const MODEL_PROVIDERS_URL =
|
|||
const CODESTRAL_URL = "https://console.mistral.ai/codestral";
|
||||
const CONTINUE_SETUP_URL = "https://docs.continue.dev/setup/overview";
|
||||
|
||||
interface ProviderFormData {
|
||||
provider: ProviderInfo;
|
||||
apiKey?: string;
|
||||
selectedModels: string[];
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
interface FormData {
|
||||
providers: ProviderFormData[];
|
||||
}
|
||||
|
||||
export function AddModelForm({
|
||||
onDone,
|
||||
onSubmit: onSubmitProp,
|
||||
hideFreeTrialLimitMessage,
|
||||
}: QuickModelSetupProps) {
|
||||
}: AddModelFormProps) {
|
||||
const [selectedProvider, setSelectedProvider] = useState<ProviderInfo>(
|
||||
providers["openai"]!,
|
||||
);
|
||||
const dispatch = useAppDispatch();
|
||||
const { selectedProfile } = useAuth();
|
||||
|
||||
const formMethods = useForm<FormData>({
|
||||
defaultValues: {
|
||||
providers: [
|
||||
{
|
||||
provider: providers["openai"]!,
|
||||
selectedModels: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
const { fields, append, remove } = useFieldArray({
|
||||
control: formMethods.control,
|
||||
name: "providers",
|
||||
});
|
||||
|
||||
const [selectedModel, setSelectedModel] = useState(
|
||||
selectedProvider.packages[0],
|
||||
);
|
||||
const formMethods = useForm();
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
|
||||
const popularProviderTitles = [
|
||||
|
|
@ -81,14 +47,13 @@ export function AddModelForm({
|
|||
providers["gemini"]?.title || "",
|
||||
providers["azure"]?.title || "",
|
||||
providers["ollama"]?.title || "",
|
||||
providers["deepseek"]?.title || "",
|
||||
];
|
||||
|
||||
const allProviders = Object.entries(providers)
|
||||
.filter(([key]) => !["openai-aiohttp"].includes(key))
|
||||
.map(([, provider]) => provider)
|
||||
.filter((provider) => !!provider)
|
||||
.map((provider) => provider!);
|
||||
.map((provider) => provider!); // for type checking
|
||||
|
||||
const popularProviders = allProviders
|
||||
.filter((provider) => popularProviderTitles.includes(provider.title))
|
||||
|
|
@ -98,6 +63,12 @@ export function AddModelForm({
|
|||
.filter((provider) => !popularProviderTitles.includes(provider.title))
|
||||
.sort((a, b) => a.title.localeCompare(b.title));
|
||||
|
||||
const selectedProviderApiKeyUrl = selectedModel.params.model.startsWith(
|
||||
"codestral",
|
||||
)
|
||||
? CODESTRAL_URL
|
||||
: selectedProvider.apiKeyUrl;
|
||||
|
||||
function isDisabled() {
|
||||
if (selectedProvider.downloadUrl) {
|
||||
return false;
|
||||
|
|
@ -110,86 +81,51 @@ export function AddModelForm({
|
|||
return value;
|
||||
});
|
||||
|
||||
if (
|
||||
!required?.every((value) => value !== undefined && value.length > 0)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return !required?.every((value) => value !== undefined && value.length > 0);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
setSelectedModel(selectedProvider.packages[0]);
|
||||
}, [selectedProvider]);
|
||||
|
||||
function onSubmit() {
|
||||
const providersData = formMethods.watch("providers");
|
||||
const models: any[] = [];
|
||||
const apiKey = formMethods.watch("apiKey");
|
||||
const hasValidApiKey = apiKey !== undefined && apiKey !== "";
|
||||
|
||||
providersData.forEach((providerData) => {
|
||||
const selectedProvider = providerData.provider;
|
||||
const reqInputFields: Record<string, any> = {};
|
||||
for (let input of selectedProvider.collectInputFor ?? []) {
|
||||
reqInputFields[input.key] = formMethods.watch(input.key);
|
||||
}
|
||||
|
||||
providerData.selectedModels.forEach((modelTitle) => {
|
||||
const modelPackage = selectedProvider.packages.find(
|
||||
(pkg) => pkg.title === modelTitle,
|
||||
);
|
||||
const model = {
|
||||
...selectedProvider.params,
|
||||
...selectedModel.params,
|
||||
...reqInputFields,
|
||||
provider: selectedProvider.provider,
|
||||
title: selectedModel.title,
|
||||
...(hasValidApiKey ? { apiKey } : {}),
|
||||
};
|
||||
|
||||
if (modelPackage) {
|
||||
const apiKey = providerData.apiKey;
|
||||
const hasValidApiKey = apiKey !== undefined && apiKey !== "";
|
||||
const reqInputFields: Record<string, any> = {};
|
||||
ideMessenger.post("config/addModel", { model });
|
||||
|
||||
for (let input of selectedProvider.collectInputFor ?? []) {
|
||||
if (input.key !== "apiKey") {
|
||||
reqInputFields[input.key] = (providerData as any)[input.key];
|
||||
}
|
||||
}
|
||||
|
||||
const model = {
|
||||
...selectedProvider.params,
|
||||
...modelPackage.params,
|
||||
...reqInputFields,
|
||||
provider: selectedProvider.provider,
|
||||
title: modelPackage.title,
|
||||
...(hasValidApiKey ? { apiKey } : {}),
|
||||
};
|
||||
|
||||
models.push(model);
|
||||
}
|
||||
});
|
||||
ideMessenger.post("config/openProfile", {
|
||||
profileId: "local",
|
||||
});
|
||||
|
||||
if (onSubmitProp) {
|
||||
onSubmitProp(models);
|
||||
} else {
|
||||
models.forEach((model) => {
|
||||
ideMessenger.post("config/addModel", { model });
|
||||
});
|
||||
void dispatch(
|
||||
updateSelectedModelByRole({
|
||||
selectedProfile,
|
||||
role: "chat",
|
||||
modelTitle: model.title,
|
||||
}),
|
||||
);
|
||||
|
||||
ideMessenger.post("config/openProfile", {
|
||||
profileId: "local",
|
||||
});
|
||||
|
||||
if (models.length > 0) {
|
||||
void dispatch(
|
||||
updateSelectedModelByRole({
|
||||
selectedProfile,
|
||||
role: "chat",
|
||||
modelTitle: models[0].title,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (onDone) {
|
||||
onDone();
|
||||
}
|
||||
onDone();
|
||||
}
|
||||
|
||||
function addProvider() {
|
||||
append({
|
||||
provider: providers["openai"]!,
|
||||
selectedModels: [],
|
||||
});
|
||||
function onClickDownloadProvider() {
|
||||
selectedProvider.downloadUrl &&
|
||||
ideMessenger.post("openUrl", selectedProvider.downloadUrl);
|
||||
}
|
||||
|
||||
return (
|
||||
|
|
@ -197,6 +133,7 @@ export function AddModelForm({
|
|||
<form onSubmit={formMethods.handleSubmit(onSubmit)}>
|
||||
<div className="mx-auto max-w-md p-6">
|
||||
<h1 className="mb-0 text-center text-2xl">Add Chat model</h1>
|
||||
|
||||
{/* TODO sync free trial limit with hub */}
|
||||
{/* {!hideFreeTrialLimitMessage && hasPassedFTL() && (
|
||||
<p className="text-sm text-gray-400">
|
||||
|
|
@ -213,221 +150,172 @@ export function AddModelForm({
|
|||
</p>
|
||||
)} */}
|
||||
|
||||
<div className="mt-4 flex flex-col gap-4">
|
||||
{fields.map((field, index) => {
|
||||
const selectedProvider = formMethods.watch(
|
||||
`providers.${index}.provider`,
|
||||
);
|
||||
const selectedModels =
|
||||
formMethods.watch(`providers.${index}.selectedModels`) || [];
|
||||
|
||||
const selectedProviderApiKeyUrl = selectedProvider.packages.some(
|
||||
(pkg) => pkg.params.model?.startsWith("codestral"),
|
||||
)
|
||||
? CODESTRAL_URL
|
||||
: selectedProvider.apiKeyUrl;
|
||||
|
||||
return (
|
||||
<div
|
||||
key={field.id}
|
||||
className="border-border rounded-lg border border-solid px-4 py-3"
|
||||
<div className="my-8 flex flex-col gap-6">
|
||||
<div>
|
||||
<label className="block text-sm font-medium">Provider</label>
|
||||
<ModelSelectionListbox
|
||||
selectedProvider={selectedProvider}
|
||||
setSelectedProvider={(val: DisplayInfo) => {
|
||||
const match = [...popularProviders, ...otherProviders].find(
|
||||
(provider) => provider.title === val.title,
|
||||
);
|
||||
if (match) {
|
||||
setSelectedProvider(match);
|
||||
}
|
||||
}}
|
||||
topOptions={popularProviders}
|
||||
otherOptions={otherProviders}
|
||||
/>
|
||||
<span className="text-description-muted mt-1 block text-xs">
|
||||
Don't see your provider?{" "}
|
||||
<a
|
||||
className="cursor-pointer text-inherit underline hover:text-inherit"
|
||||
onClick={() =>
|
||||
ideMessenger.post("openUrl", MODEL_PROVIDERS_URL)
|
||||
}
|
||||
>
|
||||
<div className="mb-4 flex items-center justify-between">
|
||||
<label className="text-base font-medium">
|
||||
{selectedProvider.title} Provider
|
||||
</label>
|
||||
{fields.length > 1 && (
|
||||
<GhostButton
|
||||
onClick={() => remove(index)}
|
||||
className="text-description-muted"
|
||||
>
|
||||
<XCircleIcon className="h-3 w-3" />
|
||||
</GhostButton>
|
||||
)}
|
||||
</div>
|
||||
Click here
|
||||
</a>{" "}
|
||||
to view the full list
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="space-y-4">
|
||||
<div>
|
||||
<label className="font-medium">Provider</label>
|
||||
<ModelSelectionListbox
|
||||
selectedProvider={selectedProvider}
|
||||
setSelectedProvider={(val: DisplayInfo) => {
|
||||
const match = [
|
||||
...popularProviders,
|
||||
...otherProviders,
|
||||
].find((provider) => provider.title === val.title);
|
||||
if (match) {
|
||||
formMethods.setValue(
|
||||
`providers.${index}.provider`,
|
||||
match,
|
||||
);
|
||||
formMethods.setValue(
|
||||
`providers.${index}.selectedModels`,
|
||||
[],
|
||||
);
|
||||
}
|
||||
}}
|
||||
topOptions={popularProviders}
|
||||
otherOptions={otherProviders}
|
||||
{selectedProvider.downloadUrl && (
|
||||
<div>
|
||||
<label className="mb-1 block text-sm font-medium">
|
||||
Install provider
|
||||
</label>
|
||||
<StyledActionButton onClick={onClickDownloadProvider}>
|
||||
<p className="text-sm underline">
|
||||
{selectedProvider.downloadUrl}
|
||||
</p>
|
||||
<ArrowTopRightOnSquareIcon width={24} height={24} />
|
||||
</StyledActionButton>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div>
|
||||
<label className="block text-sm font-medium">Model</label>
|
||||
<ModelSelectionListbox
|
||||
selectedProvider={selectedModel}
|
||||
setSelectedProvider={(val: DisplayInfo) => {
|
||||
const options =
|
||||
Object.entries(providers).find(
|
||||
([, provider]) =>
|
||||
provider?.title === selectedProvider.title,
|
||||
)?.[1]?.packages ?? [];
|
||||
const match = options.find(
|
||||
(option) => option.title === val.title,
|
||||
);
|
||||
if (match) {
|
||||
setSelectedModel(match);
|
||||
}
|
||||
}}
|
||||
otherOptions={
|
||||
Object.entries(providers).find(
|
||||
([, provider]) =>
|
||||
provider?.title === selectedProvider.title,
|
||||
)?.[1]?.packages
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{selectedModel.params.model.startsWith("codestral") && (
|
||||
<div className="my-2">
|
||||
<Alert>
|
||||
<p className="m-0 text-sm font-bold">Codestral API key</p>
|
||||
<p className="m-0 mt-1">
|
||||
Note that codestral requires a different API key from other
|
||||
Mistral models
|
||||
</p>
|
||||
</Alert>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{selectedProvider.apiKeyUrl && (
|
||||
<div>
|
||||
<>
|
||||
<label className="mb-1 block text-sm font-medium">
|
||||
API key
|
||||
</label>
|
||||
<Input
|
||||
id="apiKey"
|
||||
className="w-full"
|
||||
type="password"
|
||||
placeholder={`Enter your ${selectedProvider.title} API key`}
|
||||
{...formMethods.register("apiKey")}
|
||||
/>
|
||||
<span className="text-description-muted mt-1 block text-xs">
|
||||
<a
|
||||
className="cursor-pointer text-inherit underline hover:text-inherit hover:brightness-125"
|
||||
onClick={() => {
|
||||
if (selectedProviderApiKeyUrl) {
|
||||
ideMessenger.post(
|
||||
"openUrl",
|
||||
selectedProviderApiKeyUrl,
|
||||
);
|
||||
}
|
||||
}}
|
||||
>
|
||||
Click here
|
||||
</a>{" "}
|
||||
to create a {selectedProvider.title} API key
|
||||
</span>
|
||||
</>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{selectedProvider.collectInputFor &&
|
||||
selectedProvider.collectInputFor
|
||||
.filter(
|
||||
(field) =>
|
||||
!Object.values(completionParamsInputs).some(
|
||||
(input) => input.key === field.key,
|
||||
) &&
|
||||
field.required &&
|
||||
field.key !== "apiKey",
|
||||
)
|
||||
.map((field) => (
|
||||
<div key={field.key}>
|
||||
<>
|
||||
<label className="mb-1 block text-sm font-medium">
|
||||
{field.label}
|
||||
</label>
|
||||
<Input
|
||||
id={field.key}
|
||||
className="w-full"
|
||||
defaultValue={field.defaultValue}
|
||||
placeholder={`${field.placeholder}`}
|
||||
{...formMethods.register(field.key)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{selectedProvider.downloadUrl && (
|
||||
<div>
|
||||
<label className="mb-1 block text-sm font-medium">
|
||||
Install provider
|
||||
</label>
|
||||
<StyledActionButton
|
||||
onClick={() => {
|
||||
selectedProvider.downloadUrl &&
|
||||
ideMessenger.post(
|
||||
"openUrl",
|
||||
selectedProvider.downloadUrl,
|
||||
);
|
||||
}}
|
||||
>
|
||||
<p className="text-sm underline">
|
||||
{selectedProvider.downloadUrl}
|
||||
</p>
|
||||
<ArrowTopRightOnSquareIcon width={24} height={24} />
|
||||
</StyledActionButton>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{selectedProvider.packages.some((pkg) =>
|
||||
pkg.params.model?.startsWith("codestral"),
|
||||
) && (
|
||||
<div className="my-2">
|
||||
<Alert>
|
||||
<p className="m-0 text-sm font-bold">
|
||||
Codestral API key
|
||||
</p>
|
||||
<p className="m-0 mt-1">
|
||||
Note that codestral requires a different API key
|
||||
from other Mistral models
|
||||
</p>
|
||||
</Alert>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{selectedProvider.apiKeyUrl && (
|
||||
<div>
|
||||
<label className="mb-1 font-medium">API key</label>
|
||||
<Input
|
||||
id={`providers.${index}.apiKey`}
|
||||
className="w-full"
|
||||
placeholder={`Enter your ${selectedProvider.title} API key`}
|
||||
{...formMethods.register(`providers.${index}.apiKey`)}
|
||||
/>
|
||||
<span className="text-description-muted text-xs">
|
||||
<a
|
||||
className="cursor-pointer text-inherit underline hover:text-inherit hover:brightness-125"
|
||||
onClick={() => {
|
||||
if (selectedProviderApiKeyUrl) {
|
||||
ideMessenger.post(
|
||||
"openUrl",
|
||||
selectedProviderApiKeyUrl,
|
||||
);
|
||||
}
|
||||
}}
|
||||
>
|
||||
Click here
|
||||
</a>{" "}
|
||||
to create a {selectedProvider.title} API key
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{selectedProvider.collectInputFor &&
|
||||
selectedProvider.collectInputFor
|
||||
.filter(
|
||||
(field) =>
|
||||
!Object.values(completionParamsInputs).some(
|
||||
(input) => input.key === field.key,
|
||||
) &&
|
||||
field.required &&
|
||||
field.key !== "apiKey",
|
||||
)
|
||||
.map((field) => (
|
||||
<div key={field.key}>
|
||||
<label className="mb-1 block text-sm font-medium">
|
||||
{field.label}
|
||||
</label>
|
||||
<Input
|
||||
id={`providers.${index}.${field.key}`}
|
||||
className="w-full"
|
||||
defaultValue={field.defaultValue}
|
||||
placeholder={`${field.placeholder}`}
|
||||
{...formMethods.register(
|
||||
`providers.${index}.${field.key}`,
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
|
||||
<div>
|
||||
<label className="font-medium">Models</label>
|
||||
<div className="max-h-40 space-y-2 overflow-y-auto rounded border border-gray-200 py-2">
|
||||
{selectedProvider.packages.map((model) => (
|
||||
<div key={model.title} className="flex items-center">
|
||||
<input
|
||||
type="checkbox"
|
||||
id={`providers.${index}.models.${model.title}`}
|
||||
value={model.title}
|
||||
checked={selectedModels.includes(model.title)}
|
||||
onChange={(e) => {
|
||||
const currentSelected = selectedModels;
|
||||
if (e.target.checked) {
|
||||
formMethods.setValue(
|
||||
`providers.${index}.selectedModels`,
|
||||
[...currentSelected, model.title],
|
||||
);
|
||||
} else {
|
||||
formMethods.setValue(
|
||||
`providers.${index}.selectedModels`,
|
||||
currentSelected.filter(
|
||||
(m) => m !== model.title,
|
||||
),
|
||||
);
|
||||
}
|
||||
}}
|
||||
className="mr-2"
|
||||
/>
|
||||
<label
|
||||
htmlFor={`providers.${index}.models.${model.title}`}
|
||||
className="flex cursor-pointer items-center text-sm"
|
||||
>
|
||||
{window.vscMediaUrl && model.icon && (
|
||||
<img
|
||||
src={`${window.vscMediaUrl}/logos/${model.icon}`}
|
||||
className="mr-2 h-4 w-4 object-contain object-center"
|
||||
/>
|
||||
)}
|
||||
{model.title}
|
||||
</label>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
|
||||
<SecondaryButton onClick={addProvider} type="button">
|
||||
<PlusCircleIcon className="mr-2 h-3 w-3" />
|
||||
Add another provider
|
||||
</SecondaryButton>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="mt-4 w-full">
|
||||
<Button type="submit" className="w-full" disabled={isDisabled()}>
|
||||
Connect
|
||||
</Button>
|
||||
<AddModelButtonSubtext />
|
||||
|
||||
<span className="text-description-muted block w-full text-center text-xs">
|
||||
This will update your{" "}
|
||||
<span
|
||||
className="cursor-pointer underline hover:brightness-125"
|
||||
onClick={() =>
|
||||
ideMessenger.post("config/openProfile", {
|
||||
profileId: undefined,
|
||||
})
|
||||
}
|
||||
>
|
||||
config file
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</FormProvider>
|
||||
);
|
||||
}
|
||||
|
||||
export default AddModelForm;
|
||||
|
|
|
|||
|
|
@ -204,7 +204,7 @@ export function Chat() {
|
|||
|
||||
// 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_KEYS);
|
||||
onboardingCard.open(OnboardingModes.PROVIDERS);
|
||||
|
||||
// // If history, show the dialog, which will automatically close if there is not history
|
||||
// if (history.length) {
|
||||
|
|
|
|||
29
gui/src/util/providers.ts
Normal file
29
gui/src/util/providers.ts
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import { providers } from "../pages/AddNewModel/configs/providers";
|
||||
|
||||
export const popularProviderTitles = [
|
||||
providers["openai"]?.title || "",
|
||||
providers["anthropic"]?.title || "",
|
||||
providers["mistral"]?.title || "",
|
||||
providers["gemini"]?.title || "",
|
||||
providers["azure"]?.title || "",
|
||||
providers["ollama"]?.title || "",
|
||||
providers["deepseek"]?.title || "",
|
||||
].filter(Boolean);
|
||||
|
||||
export const getSortedProviders = () => {
|
||||
const allProviders = Object.entries(providers)
|
||||
.filter(([key]) => !["freetrial", "openai-aiohttp"].includes(key))
|
||||
.map(([, provider]) => provider)
|
||||
.filter((provider) => !!provider)
|
||||
.map((provider) => provider!);
|
||||
|
||||
const popularProviders = allProviders
|
||||
.filter((provider) => popularProviderTitles.includes(provider.title))
|
||||
.sort((a, b) => a.title.localeCompare(b.title));
|
||||
|
||||
const otherProviders = allProviders
|
||||
.filter((provider) => !popularProviderTitles.includes(provider.title))
|
||||
.sort((a, b) => a.title.localeCompare(b.title));
|
||||
|
||||
return { popularProviders, otherProviders };
|
||||
};
|
||||
|
|
@ -38,3 +38,5 @@ export function findLlmInfo(model: string): LlmInfo | undefined {
|
|||
export function getAllRecommendedFor(useCase: UseCase): LlmInfo[] {
|
||||
return allLlms.filter((llm) => llm.recommendedFor?.includes(useCase));
|
||||
}
|
||||
|
||||
export { Anthropic, Gemini, OpenAi };
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@
|
|||
"noEmitOnError": false,
|
||||
"types": ["node"],
|
||||
"outDir": "dist",
|
||||
"declaration": true
|
||||
// "sourceMap": true
|
||||
"declaration": true,
|
||||
"sourceMap": true
|
||||
},
|
||||
"include": ["src/**/*"]
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue