select and number inputs

This commit is contained in:
Dallin Romney 2025-01-24 12:43:34 -08:00
parent 34d025f497
commit 33f2dceacc
8 changed files with 324 additions and 233 deletions

View file

@ -7,12 +7,16 @@ import { SharedConfigSchema } from "./sharedConfig";
import { GlobalContext } from "../util/GlobalContext";
import { editConfigJson } from "../util/paths";
import { resolveSerializedConfig } from "./load";
import { deduplicateArray } from "../util";
/*
This migration function eliminates deprecated values from the json file
And writes them to the shared config
*/
export function migrateJsonSharedConfig(filepath: string, ide: IDE): void {
const globalContext = new GlobalContext();
const currentSharedConfig = globalContext.getSharedConfig(); // for merging security concerns
try {
let config = resolveSerializedConfig(filepath);
const shareConfigUpdates: SharedConfigSchema = {};
@ -21,21 +25,30 @@ export function migrateJsonSharedConfig(filepath: string, ide: IDE): void {
const { allowAnonymousTelemetry, ...withoutAllowTelemetry } = config;
if (allowAnonymousTelemetry !== undefined) {
shareConfigUpdates.allowAnonymousTelemetry = allowAnonymousTelemetry;
if (currentSharedConfig.allowAnonymousTelemetry !== false) {
// safe merge for security
shareConfigUpdates.allowAnonymousTelemetry = allowAnonymousTelemetry;
}
config = withoutAllowTelemetry;
effected = true;
}
const { disableIndexing, ...withoutDisableIndexing } = config;
if (disableIndexing !== undefined) {
shareConfigUpdates.disableIndexing = disableIndexing;
if (currentSharedConfig.disableIndexing !== true) {
// safe merge for security
shareConfigUpdates.disableIndexing = disableIndexing;
}
config = withoutDisableIndexing;
effected = true;
}
const { disableSessionTitles, ...withoutDisableSessionTitles } = config;
if (config.disableSessionTitles !== undefined) {
shareConfigUpdates.disableSessionTitles = config.disableSessionTitles;
if (currentSharedConfig.disableSessionTitles !== true) {
// safe merge for security
shareConfigUpdates.disableSessionTitles = config.disableSessionTitles;
}
config = withoutDisableSessionTitles;
effected = true;
}
@ -62,15 +75,31 @@ export function migrateJsonSharedConfig(filepath: string, ide: IDE): void {
const { disableInFiles, ...withoutDisableInFiles } = migratedAutocomplete;
if (disableInFiles !== undefined) {
if (currentSharedConfig.disableAutocompleteInFiles !== undefined) {
// safe merge for security
shareConfigUpdates.disableAutocompleteInFiles = deduplicateArray(
[
...currentSharedConfig.disableAutocompleteInFiles,
...disableInFiles,
],
(a, b) => a === b,
);
} else {
shareConfigUpdates.disableAutocompleteInFiles = disableInFiles;
}
shareConfigUpdates.disableAutocompleteInFiles = disableInFiles;
migratedAutocomplete = withoutDisableInFiles;
effected = true;
}
config = {
...withoutAutocompleteOptions,
tabAutocompleteOptions: migratedAutocomplete,
};
if (Object.keys(migratedAutocomplete).length > 0) {
config = {
...withoutAutocompleteOptions,
tabAutocompleteOptions: migratedAutocomplete,
};
} else {
config = withoutAutocompleteOptions;
}
}
const { experimental, ...withoutExperimental } = config;
@ -99,10 +128,14 @@ export function migrateJsonSharedConfig(filepath: string, ide: IDE): void {
effected = true;
}
config = {
...withoutExperimental,
experimental: migratedExperimental,
};
if (Object.keys(migratedExperimental).length > 0) {
config = {
...withoutExperimental,
experimental: migratedExperimental,
};
} else {
config = withoutExperimental;
}
}
const { ui, ...withoutUI } = config;
@ -145,10 +178,14 @@ export function migrateJsonSharedConfig(filepath: string, ide: IDE): void {
effected = true;
}
config = {
...withoutUI,
ui: migratedUI,
};
if (Object.keys(migratedUI).length > 0) {
config = {
...withoutUI,
ui: migratedUI,
};
} else {
config = withoutUI;
}
}
if (effected) {

View file

@ -1,12 +1,12 @@
{
"name": "continue",
"version": "0.9.254",
"version": "0.9.255",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "continue",
"version": "0.9.254",
"version": "0.9.255",
"license": "Apache-2.0",
"dependencies": {
"@continuedev/fetch": "^1.0.3",

View file

@ -0,0 +1,61 @@
import React from "react";
interface NumberInputProps {
value: number;
onChange: (value: number) => void;
max: number;
min: number;
}
const NumberInput: React.FC<NumberInputProps> = ({
value,
onChange,
max,
min,
}) => {
const handleIncrement = () => {
if (value < max) {
onChange(value + 1);
}
};
const handleDecrement = () => {
if (value > min) {
onChange(value - 1);
}
};
return (
<div className="border-vsc-input-border bg-vsc-input-background flex flex-row overflow-hidden rounded-md border border-solid">
<input
type="text"
value={value}
readOnly
className="text-vsc-foreground max-w-7 border-none bg-inherit pr-1.5 text-right outline-none ring-0 focus:border-none focus:outline-none focus:ring-0"
style={{
appearance: "none",
WebkitAppearance: "none",
MozAppearance: "none",
}}
/>
<div className="flex flex-col">
<button
onClick={handleIncrement}
disabled={value >= max}
className="text-vsc-foreground m-0 mb-0.5 cursor-pointer border-none bg-inherit px-1.5 py-0 hover:opacity-80"
>
▲
</button>
<button
className="text-vsc-foreground m-0 mb-0.5 cursor-pointer border-none bg-inherit px-1.5 py-0 hover:opacity-80"
onClick={handleDecrement}
disabled={value <= min}
>
▼
</button>
</div>
</div>
);
};
export default NumberInput;

View file

@ -0,0 +1,48 @@
// export const Select = styled.select`
// padding: 8px 12px;
// border-radius: ${defaultBorderRadius};
// border: 1px solid ${vscInputBorder};
// background-color: ${vscBackground};
// color: ${vscForeground};
import { vscBackground, vscForeground, vscInputBorder } from "..";
// appearance: none;
// -webkit-appearance: none;
// -moz-appearance: none;
// padding-right: 30px;
// background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 6"><path fill="currentColor" d="M0 0l5 5 5-5Z"/></svg>')
// no-repeat right 10px center;
// background-size: 10px 10px;
// `;
// // gui/src/components/gui/Select.tsx
// import React from 'react';
export const Select: React.FC<React.SelectHTMLAttributes<HTMLSelectElement>> = (
props,
) => (
<div
style={{
color: vscForeground,
}}
>
<select
{...props}
className="rounded border px-3 py-2"
style={{
borderColor: vscInputBorder,
backgroundColor: vscBackground,
color: vscForeground,
appearance: "none",
WebkitAppearance: "none",
MozAppearance: "none",
paddingRight: "30px",
background: `url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 6"><path fill="${encodeURIComponent(vscForeground)}" d="M0 0l5 5 5-5Z"/></svg>') no-repeat right 10px center`,
backgroundSize: "10px 10px",
}}
>
{props.children}
</select>
</div>
);

View file

@ -12,14 +12,10 @@ const ToggleSwitch: React.FC<ToggleSwitchProps> = ({
text,
}) => {
return (
<label
htmlFor="toggle"
className="flex cursor-pointer select-none items-center justify-end gap-3"
>
<span className="lines lines-1 text-right">{text}</span>
<div className="flex cursor-pointer select-none items-center justify-end gap-3">
<span className="truncate-right text-right">{text}</span>
<div>
<div
id={`toggle-${text}`}
className={`border-vsc-input-border bg-vsc-input-background flex h-5 w-10 items-center rounded-full border border-solid p-0.5`}
onClick={onToggle}
>
@ -30,7 +26,7 @@ const ToggleSwitch: React.FC<ToggleSwitchProps> = ({
</div>
</div>
</div>
</label>
</div>
);
};

View file

@ -154,6 +154,13 @@ export const Button = styled.button`
}
`;
type NumberInputProps = {
value: number;
onChange: (value: number) => void;
max?: number;
min?: number;
};
export const SecondaryButton = styled.button`
padding: 10px 12px;
margin: 8px 0;
@ -250,17 +257,6 @@ export const Input = styled.input`
}
`;
export const Select = styled.select`
padding: 8px 12px;
margin: 8px 0;
box-sizing: border-box;
border-radius: ${defaultBorderRadius};
outline: 1px solid ${lightGray};
border: none;
background-color: ${vscBackground};
color: ${vscForeground};
`;
export const Label = styled.label<{ fontSize?: number }>`
font-size: ${(props) => props.fontSize || getFontSize()}px;
`;

View file

@ -1,100 +0,0 @@
import { useState } from "react";
import { useFormContext } from "react-hook-form";
import styled from "styled-components";
import { Input, Label, Select, defaultBorderRadius, lightGray } from "..";
import { getFontSize } from "../../util";
const Div = styled.div<{ dashed: boolean }>`
border: 1px ${(props) => (props.dashed ? "dashed" : "solid")} ${lightGray};
border-radius: ${defaultBorderRadius};
padding: 8px;
margin-bottom: 16px;
`;
type ModelOption = "apiKey" | "model" | "contextLength";
const DefaultModelOptions: {
[key: string]: { [key in ModelOption]?: string };
} = {
OpenAI: {
apiKey: "",
model: "gpt-4",
},
OpenAIFreeTrial: {
apiKey: "",
model: "gpt-4",
},
Anthropic: {
apiKey: "",
model: "claude-2",
},
default: {
apiKey: "",
model: "gpt-4",
},
};
function ModelSettings(props: { llm: any | undefined; role: string }) {
const [modelOptions, setModelOptions] = useState<{
[key in ModelOption]?: string;
}>(DefaultModelOptions[props.llm?.class_name || "default"]);
const { register, setValue, getValues } = useFormContext();
return (
<Div dashed={typeof props.llm === undefined}>
{props.llm ? (
<>
<b>{props.role}</b>: <b> {props.llm?.class_name || "gpt-4"}</b>
<form>
{typeof modelOptions.apiKey !== undefined && (
<>
<Label fontSize={getFontSize()}>API Key</Label>
<Input
type="text"
defaultValue={props.llm.apiKey}
placeholder="API Key"
{...register(`models.${props.role}.apiKey`)}
/>
</>
)}
{modelOptions.model && (
<>
<Label fontSize={getFontSize()}>Model</Label>
<Input
type="text"
defaultValue={props.llm.model}
placeholder="Model"
{...register(`models.${props.role}.model`)}
/>
</>
)}
</form>
</>
) : (
<div>
<b>Add Model</b>
<div className="my-4">
<Select
defaultValue=""
onChange={(e) => {
if (e.target.value) {
e.target.value = "";
}
}}
>
<option disabled value="">
Select Model Type
</option>
<option value="newModel1">New Model 1</option>
<option value="newModel2">New Model 2</option>
<option value="newModel3">New Model 3</option>
</Select>
</div>
</div>
)}
</Div>
);
}
export default ModelSettings;

View file

@ -8,11 +8,13 @@ import {
modifyContinueConfigWithSharedConfig,
SharedConfigSchema,
} from "core/config/sharedConfig";
import { Switch } from "@headlessui/react";
import { updateConfig } from "../../redux/slices/configSlice";
import ToggleSwitch from "../../components/gui/Switch";
import { useAuth } from "../../context/Auth";
import { Button } from "../../components";
import { getFontSize } from "../../util";
import NumberInput from "../../components/gui/NumberInput";
import { Select } from "../../components/gui/Select";
function ConfigPage() {
useNavigationListener();
@ -37,6 +39,8 @@ function ConfigPage() {
}
// Account for default values
// TODO - duplicate defaults here, should consolidate defaults to one place
// And write defaults earlier in the config process
const codeWrap = config.ui?.codeWrap ?? false;
const showChatScrollbar = config.ui?.showChatScrollbar ?? false;
const displayRawMarkdown = config.ui?.displayRawMarkdown ?? false;
@ -49,6 +53,11 @@ function ConfigPage() {
const useAutocompleteCache = config.tabAutocompleteOptions?.useCache ?? false;
const useChromiumForDocsCrawling =
config.experimental?.useChromiumForDocsCrawling ?? false;
const codeBlockToolbarPosition = config.ui?.codeBlockToolbarPosition ?? "top";
const useAutocompleteMultilineCompletions =
config.tabAutocompleteOptions?.multilineCompletions ?? "auto";
const fontSize = getFontSize();
function handleOpenConfig() {
if (!selectedProfile) {
@ -62,117 +71,161 @@ function ConfigPage() {
return (
<div className="overflow-y-scroll px-2">
<PageHeader onClick={() => navigate("/")} title="Chat" />
<h1 className="text-center">Continue Configuration</h1>
<h1 className="text-center">Continue Config</h1>
{!selectedProfile ? (
<p>No config profile selected</p>
) : (
<div className="flex flex-col gap-2 px-3">
<Button onClick={handleOpenConfig}>
{selectedProfile.id === "local" ? "Open Config File" : "Nooooo"}
</Button>
<div className="flex flex-col items-center justify-center gap-2 px-3">
<div>
<Button onClick={handleOpenConfig}>
{selectedProfile.id === "local" ? "Open Config File" : "Nooooo"}
</Button>
</div>
<h2 className="text-center">Other Settings</h2>
<ToggleSwitch
isToggled={codeWrap}
onToggle={() =>
handleUpdate({
codeWrap: !codeWrap,
})
}
text="Wrap Codeblocks"
></ToggleSwitch>
<ToggleSwitch
isToggled={displayRawMarkdown}
onToggle={() =>
handleUpdate({
displayRawMarkdown: !displayRawMarkdown,
})
}
text="Display Raw Markdown"
></ToggleSwitch>
<ToggleSwitch
isToggled={allowAnonymousTelemetry}
onToggle={() =>
handleUpdate({
allowAnonymousTelemetry: !allowAnonymousTelemetry,
})
}
text="Allow Anonymous Telemetry"
></ToggleSwitch>
<ToggleSwitch
isToggled={disableIndexing}
onToggle={() =>
handleUpdate({
disableIndexing: !disableIndexing,
})
}
text="Disable Indexing"
></ToggleSwitch>
<div className="flex flex-col items-end gap-2">
<ToggleSwitch
isToggled={codeWrap}
onToggle={() =>
handleUpdate({
codeWrap: !codeWrap,
})
}
text="Wrap Codeblocks"
/>
<ToggleSwitch
isToggled={displayRawMarkdown}
onToggle={() =>
handleUpdate({
displayRawMarkdown: !displayRawMarkdown,
})
}
text="Display Raw Markdown"
/>
<ToggleSwitch
isToggled={allowAnonymousTelemetry}
onToggle={() =>
handleUpdate({
allowAnonymousTelemetry: !allowAnonymousTelemetry,
})
}
text="Allow Anonymous Telemetry"
/>
<ToggleSwitch
isToggled={disableIndexing}
onToggle={() =>
handleUpdate({
disableIndexing: !disableIndexing,
})
}
text="Disable Indexing"
/>
<ToggleSwitch
isToggled={disableSessionTitles}
onToggle={() =>
handleUpdate({
disableSessionTitles: !disableSessionTitles,
})
}
text="Disable Session Titles"
></ToggleSwitch>
<ToggleSwitch
isToggled={disableSessionTitles}
onToggle={() =>
handleUpdate({
disableSessionTitles: !disableSessionTitles,
})
}
text="Disable Session Titles"
/>
<ToggleSwitch
isToggled={readResponseTTS}
onToggle={() =>
handleUpdate({
readResponseTTS: !readResponseTTS,
})
}
text="Response Text to Speech"
/>
<ToggleSwitch
isToggled={readResponseTTS}
onToggle={() =>
handleUpdate({
readResponseTTS: !readResponseTTS,
})
}
text="Read Response TTS"
></ToggleSwitch>
<ToggleSwitch
isToggled={showChatScrollbar}
onToggle={() =>
handleUpdate({
showChatScrollbar: !showChatScrollbar,
})
}
text="Show Chat Scrollbar"
/>
<ToggleSwitch
isToggled={showChatScrollbar}
onToggle={() =>
handleUpdate({
showChatScrollbar: !showChatScrollbar,
})
}
text="Show Chat Scrollbar"
></ToggleSwitch>
{/* disableAutocompleteInFiles: z.array(z.string()), */}
{/* <label>
fontSize
<input></input>
</label> */}
{/* promptPath: z.string(), */}
{/* codeBlockToolbarPosition: z.enum(["top", "bottom"]), */}
{/* Other */}
<ToggleSwitch
isToggled={useAutocompleteCache}
onToggle={() =>
handleUpdate({
useAutocompleteCache: !useAutocompleteCache,
})
}
text="Use Autocomplete Cache"
/>
{/* disableAutocompleteInFiles: z.array(z.string()), */}
{/* Other */}
<ToggleSwitch
isToggled={useChromiumForDocsCrawling}
onToggle={() =>
handleUpdate({
useChromiumForDocsCrawling: !useChromiumForDocsCrawling,
})
}
text="Use Chromium for Docs Crawling"
/>
{/* promptPath: z.string(), */}
<label className="flex items-center justify-end gap-3">
<span className="text-right">Codeblock Actions Position</span>
<Select
value={codeBlockToolbarPosition}
onChange={(e) =>
handleUpdate({
codeBlockToolbarPosition: e.target.value as
| "top"
| "bottom",
})
}
>
<option value="top">Top</option>
<option value="bottom">Bottom</option>
</Select>
</label>
{/* useAutocompleteMultilineCompletions: z.enum(["always", "never", "auto"]), */}
<label className="flex items-center justify-end gap-3">
<span className="text-right">Multiline Autocompletions</span>
<Select
value={useAutocompleteMultilineCompletions}
onChange={(e) =>
handleUpdate({
useAutocompleteMultilineCompletions: e.target.value as
| "auto"
| "always"
| "never",
})
}
>
<option value="auto">Auto</option>
<option value="always">Always</option>
<option value="never">Never</option>
</Select>
</label>
{/* Other */}
<ToggleSwitch
isToggled={useAutocompleteCache}
onToggle={() =>
handleUpdate({
useAutocompleteCache: !useAutocompleteCache,
})
}
text="Use Chromium for Docs Crawling"
></ToggleSwitch>
{/* Other */}
<ToggleSwitch
isToggled={useChromiumForDocsCrawling}
onToggle={() =>
handleUpdate({
useChromiumForDocsCrawling: !useChromiumForDocsCrawling,
})
}
text="Use Chromium for Docs Crawling"
></ToggleSwitch>
<label className="flex items-center justify-end gap-3">
<span className="text-right">Font Size</span>
<NumberInput
value={fontSize}
onChange={(val) =>
handleUpdate({
fontSize: val,
})
}
min={7}
max={50}
/>
</label>
</div>
</div>
)}
</div>