From f7c9d732f595831652f323ce6da3ee5ca968afab Mon Sep 17 00:00:00 2001 From: Andrew Pareles Date: Mon, 9 Dec 2024 19:01:08 -0800 Subject: [PATCH] update type info --- src/vs/platform/void/common/configTypes.ts | 118 ++++++++++++------ .../sidebar-tsx/SidebarProviderSettings.tsx | 10 +- .../browser/react/src/sidebar-tsx/inputs.tsx | 2 + 3 files changed, 88 insertions(+), 42 deletions(-) diff --git a/src/vs/platform/void/common/configTypes.ts b/src/vs/platform/void/common/configTypes.ts index 1a51e9cb..32f63a2b 100644 --- a/src/vs/platform/void/common/configTypes.ts +++ b/src/vs/platform/void/common/configTypes.ts @@ -216,54 +216,93 @@ export type FeatureName = typeof featureNames[number] export type VoidConfigState = { - [providerName in ProviderName]: ({ - enabled: string, // 'true' | 'false' - models: string[] | null, // if null, user can type in any string as a model - model: string, - maxTokens: string, - } & { - [optionName in keyof typeof voidProviderDefaults[providerName]]: string - }) + [providerName in ProviderName]: ( + { + [optionName in keyof typeof voidProviderDefaults[providerName]]: string + } + & + { + enabled: string, // 'true' | 'false' + maxTokens: string, + + models: string[] | null, // if null, user can type in any string as a model + model: string, + }) } type UnionOfKeys = T extends T ? keyof T : never; -export const descOfSettingName = (providerName: ProviderName, settingName: UnionOfKeys) => { - if (settingName === 'apiKey') - return 'API Key' - else if (settingName === 'endpoint') { - if (providerName === 'ollama') return 'The endpoint of your Ollama instance.' - if (providerName === 'openAICompatible') return 'The baseUrl (exluding /chat/completions).' +type SettingName = UnionOfKeys + + + +type DisplayInfo = { + title: string, + type: string, + placeholder: string, +} + +export const displayInfoOfSettingName = (providerName: ProviderName, settingName: SettingName): DisplayInfo => { + if (settingName === 'apiKey') { + return { + title: 'API Key', + type: 'string', + placeholder: providerName === 'anthropic' ? 'sk-ant-api03-abc123...' : + providerName === 'openAI' ? 'sk-proj-abc123...' : + providerName === 'openRouter' ? 'sk-or-v1-abc123...' : + providerName === 'gemini' ? 'abc123...' : + providerName === 'groq' ? 'gsk_abc123...' : + '(never)', + } + } + else if (settingName === 'endpoint') { + return { + title: providerName === 'ollama' ? 'The endpoint of your Ollama instance.' : + providerName === 'openAICompatible' ? 'The baseUrl (exluding /chat/completions).' + : '(never)', + type: 'string', + placeholder: providerName === 'ollama' || providerName === 'openAICompatible' ? + voidProviderDefaults[providerName].endpoint + : '(never)', + } + } + else if (settingName === 'maxTokens') { + return { + title: 'Max Tokens', + type: 'number', + placeholder: '1024', + } + } + else if (settingName === 'model') { + return { + title: 'Model', + type: '(never)', + placeholder: '(never)', + } + } + else if (settingName === 'enabled') { + return { + title: 'Enabled', + type: 'boolean', + placeholder: '(never)', + } + } + else if (settingName === 'models') { + return { + title: 'Available Models', + type: '(never)', + placeholder: '(never)', + } } - else if (settingName === 'maxTokens') - return 'Max Tokens' - else if (settingName === 'model') - return 'Model' - else if (settingName === 'enabled') - return 'Enabled' - else if (settingName === 'models') - return 'Available Models' - throw new Error(`desc: Unknown setting name: "${settingName}"`) + throw new Error(`displayInfo: Unknown setting name: "${settingName}"`) + } -export const inputTypeOfSettingName = (settingName: UnionOfKeys) => { - if (settingName === 'apiKey') - return 'string' as const - else if (settingName === 'endpoint') - return 'string' as const - else if (settingName === 'maxTokens') - return 'number' as const - else if (settingName === 'model') - return 'string' as const - else if (settingName === 'enabled') - return 'boolean' as const - else if (settingName === 'models') - return 'string[]?' as const - throw new Error(`inputType: Unknown setting name: "${settingName}"`) -} + + export const defaultVoidConfigState: VoidConfigState = { @@ -310,3 +349,6 @@ export const defaultVoidConfigState: VoidConfigState = { maxTokens: '', } } + + + diff --git a/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarProviderSettings.tsx b/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarProviderSettings.tsx index 471f162a..d82626a0 100644 --- a/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarProviderSettings.tsx +++ b/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarProviderSettings.tsx @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import React, { Fragment } from 'react' -import { descOfSettingName, inputTypeOfSettingName, ProviderName, providerNames } from '../../../../../../../platform/void/common/configTypes.js' +import { displayInfoOfSettingName, ProviderName, providerNames } from '../../../../../../../platform/void/common/configTypes.js' import { VoidCheckBox, VoidInputBox, VoidSelectBox } from './inputs.js' import { useConfigState, useService } from '../util/services.js' @@ -20,10 +20,12 @@ const SettingsForProvider = ({ providerName }: { providerName: ProviderName }) = {Object.entries(others).map(([settingName, defaultVal], i) => { const sName = settingName as keyof typeof others + const { title, type, placeholder } = displayInfoOfSettingName(providerName, sName) + return -

{descOfSettingName(providerName, sName)}

+

{title}

{ - inputTypeOfSettingName(sName) === 'boolean' ? + type === 'boolean' ? { voidConfigService.setState(providerName, sName, newVal ? 'true' : 'false') }} @@ -33,8 +35,8 @@ const SettingsForProvider = ({ providerName }: { providerName: ProviderName }) = : { () => { voidConfigService.setState(providerName, sName, newVal) } }} - placeholder={defaultVal} multiline={false} inputBoxRef={{ current: null }} />} diff --git a/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/inputs.tsx b/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/inputs.tsx index 731b7233..6c944b5f 100644 --- a/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/inputs.tsx +++ b/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/inputs.tsx @@ -151,3 +151,5 @@ export const VoidCheckBox = ({ onChangeChecked, initVal, label, checkboxRef, }: return
; }; + +