mirror of
https://github.com/voideditor/void
synced 2026-05-24 09:58:23 +00:00
build works
This commit is contained in:
parent
252af4c863
commit
582b25dc44
5 changed files with 102 additions and 71 deletions
|
|
@ -5,6 +5,46 @@
|
|||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
|
||||
// const voidProviderDefaults = {
|
||||
// "ctrl+L":{
|
||||
// models:[ // select only if present
|
||||
// {
|
||||
// provider:"anthropic",
|
||||
// model:"claude-3-5-sonnet-20240620"
|
||||
// },
|
||||
// ]
|
||||
// },
|
||||
// }
|
||||
|
||||
|
||||
|
||||
export const voidProviderDefaults = {
|
||||
anthropic: {
|
||||
apiKey: '',
|
||||
},
|
||||
openAI: {
|
||||
apiKey: '',
|
||||
},
|
||||
ollama: {
|
||||
endpoint: 'http://127.0.0.1:11434',
|
||||
},
|
||||
openRouter: {
|
||||
apiKey: '',
|
||||
},
|
||||
openAICompatible: {
|
||||
apiKey: '',
|
||||
endpoint: 'http://127.0.0.1:11434/v1',
|
||||
},
|
||||
gemini: {
|
||||
apiKey: '',
|
||||
},
|
||||
groq: {
|
||||
apiKey: ''
|
||||
}
|
||||
} as const
|
||||
|
||||
|
||||
export const voidInitModelOptions = {
|
||||
anthropic: () => ({
|
||||
model: 'claude-3-5-sonnet-20240620',
|
||||
|
|
@ -161,36 +201,10 @@ export const voidInitModelOptions = {
|
|||
"gemma-7b-it"
|
||||
]
|
||||
})
|
||||
}
|
||||
|
||||
export const voidProviderDefaults = {
|
||||
anthropic: {
|
||||
apiKey: '',
|
||||
},
|
||||
openAI: {
|
||||
apiKey: '',
|
||||
},
|
||||
ollama: {
|
||||
endpoint: 'http://127.0.0.1:11434',
|
||||
},
|
||||
openRouter: {
|
||||
apiKey: '',
|
||||
},
|
||||
openAICompatible: {
|
||||
apiKey: '',
|
||||
endpoint: 'http://127.0.0.1:11434/v1',
|
||||
},
|
||||
gemini: {
|
||||
apiKey: '',
|
||||
},
|
||||
groq: {
|
||||
apiKey: ''
|
||||
}
|
||||
} as const
|
||||
|
||||
|
||||
|
||||
|
||||
export type ProviderName = keyof typeof voidProviderDefaults
|
||||
export const providerNames = Object.keys(voidProviderDefaults) as ProviderName[]
|
||||
|
||||
|
|
@ -204,7 +218,7 @@ export type FeatureName = typeof featureNames[number]
|
|||
export type VoidConfigState = {
|
||||
[providerName in ProviderName]: ({
|
||||
enabled: string, // 'true' | 'false'
|
||||
models: string[],
|
||||
models: string[] | null, // if null, user can type in any string as a model
|
||||
model: string,
|
||||
maxTokens: string,
|
||||
} & {
|
||||
|
|
@ -214,6 +228,7 @@ export type VoidConfigState = {
|
|||
|
||||
|
||||
type UnionOfKeys<T> = T extends T ? keyof T : never;
|
||||
|
||||
export const descOfSettingName = (providerName: ProviderName, settingName: UnionOfKeys<VoidConfigState[ProviderName]>) => {
|
||||
if (settingName === 'apiKey')
|
||||
return 'API Key'
|
||||
|
|
@ -230,60 +245,68 @@ export const descOfSettingName = (providerName: ProviderName, settingName: Union
|
|||
else if (settingName === 'models')
|
||||
return 'Available Models'
|
||||
|
||||
throw new Error(`Unknown setting name: "${settingName}"`)
|
||||
throw new Error(`desc: Unknown setting name: "${settingName}"`)
|
||||
}
|
||||
|
||||
export const inputTypeOfSettingName = (settingName: UnionOfKeys<VoidConfigState[ProviderName]>) => {
|
||||
if (settingName === 'apiKey')
|
||||
return 'string'
|
||||
else if (settingName === 'endpoint')
|
||||
return 'string'
|
||||
else if (settingName === 'maxTokens')
|
||||
return 'number'
|
||||
else if (settingName === 'model')
|
||||
return 'string'
|
||||
else if (settingName === 'enabled')
|
||||
return 'boolean'
|
||||
else if (settingName === 'models')
|
||||
return 'string[]?'
|
||||
|
||||
throw new Error(`inputType: Unknown setting name: "${settingName}"`)
|
||||
}
|
||||
|
||||
|
||||
export const defaultVoidConfigState: VoidConfigState = {
|
||||
anthropic: {
|
||||
...voidProviderDefaults.anthropic,
|
||||
...voidInitModelOptions.anthropic(),
|
||||
enabled: 'false',
|
||||
models: [],
|
||||
model: '',
|
||||
apiKey: '',
|
||||
maxTokens: '1000',
|
||||
maxTokens: '',
|
||||
},
|
||||
openAI: {
|
||||
...voidProviderDefaults.openAI,
|
||||
...voidInitModelOptions.openAI(),
|
||||
enabled: 'false',
|
||||
models: [],
|
||||
model: '',
|
||||
apiKey: '',
|
||||
maxTokens: '1000',
|
||||
maxTokens: '',
|
||||
},
|
||||
ollama: {
|
||||
...voidProviderDefaults.ollama,
|
||||
...voidInitModelOptions.ollama(),
|
||||
enabled: 'false',
|
||||
models: [],
|
||||
model: '',
|
||||
endpoint: '',
|
||||
maxTokens: '1000',
|
||||
maxTokens: '',
|
||||
},
|
||||
openRouter: {
|
||||
...voidProviderDefaults.openRouter,
|
||||
...voidInitModelOptions.openRouter(),
|
||||
enabled: 'false',
|
||||
models: [],
|
||||
model: '',
|
||||
apiKey: '',
|
||||
maxTokens: '1000',
|
||||
maxTokens: '',
|
||||
},
|
||||
openAICompatible: {
|
||||
...voidProviderDefaults.openAICompatible,
|
||||
...voidInitModelOptions.openAICompatible(),
|
||||
enabled: 'false',
|
||||
models: [],
|
||||
model: '',
|
||||
apiKey: '',
|
||||
endpoint: '',
|
||||
maxTokens: '1000',
|
||||
maxTokens: '',
|
||||
},
|
||||
gemini: {
|
||||
...voidProviderDefaults.gemini,
|
||||
...voidInitModelOptions.gemini(),
|
||||
enabled: 'false',
|
||||
models: [],
|
||||
model: '',
|
||||
apiKey: '',
|
||||
maxTokens: '1000',
|
||||
maxTokens: '',
|
||||
},
|
||||
groq: {
|
||||
...voidProviderDefaults.groq,
|
||||
...voidInitModelOptions.groq(),
|
||||
enabled: 'false',
|
||||
models: [],
|
||||
model: '',
|
||||
apiKey: '',
|
||||
maxTokens: '1000',
|
||||
maxTokens: '',
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,8 @@ const Sidebar = () => {
|
|||
</div>
|
||||
|
||||
<div className={`${tab === 'settings' ? '' : 'hidden'}`}>
|
||||
{false && <SidebarModelSettings />}
|
||||
<SidebarModelSettings />
|
||||
--------
|
||||
<SidebarProviderSettings />
|
||||
</div>
|
||||
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@ export const SidebarModelSettingsForFeature = ({ featureName }: { featureName: F
|
|||
const models: [string,string][] = []
|
||||
for (const providerName of providerNames) {
|
||||
const providerConfig = voidConfigState[providerName]
|
||||
if (!providerConfig.enabled) continue
|
||||
providerConfig.models.forEach(model => {
|
||||
if (providerConfig.enabled === 'false') continue
|
||||
providerConfig.models?.forEach(model => {
|
||||
models.push([providerName,model])
|
||||
})
|
||||
}
|
||||
|
|
@ -31,7 +31,6 @@ export const SidebarModelSettingsForFeature = ({ featureName }: { featureName: F
|
|||
export const SidebarModelSettings = () => {
|
||||
return <>
|
||||
{featureNames.map(featureName => <SidebarModelSettingsForFeature key={featureName} featureName={featureName} />)}
|
||||
|
||||
|
||||
</>
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import { useConfigState, useService } from '../util/services.js'
|
|||
const SettingsForProvider = ({ providerName }: { providerName: ProviderName }) => {
|
||||
const voidConfigState = useConfigState()
|
||||
const voidConfigService = useService('configStateService')
|
||||
console.log('CONFIG', voidConfigState)
|
||||
console.log('CONFIG!', voidConfigState)
|
||||
console.log('provider:', providerName, voidConfigState[providerName])
|
||||
const { models, model, ...others } = voidConfigState[providerName]
|
||||
|
||||
|
|
@ -36,12 +36,14 @@ const SettingsForProvider = ({ providerName }: { providerName: ProviderName }) =
|
|||
})}
|
||||
|
||||
<h2>{'Models'}</h2>
|
||||
<VoidSelectBox
|
||||
initVal={models[0]}
|
||||
options={models}
|
||||
onChangeSelection={(newVal) => { () => { } }}
|
||||
selectBoxRef={{ current: null }}
|
||||
/>
|
||||
{models === null ?
|
||||
<p>{'No models available.'}</p>
|
||||
: <VoidSelectBox
|
||||
initVal={models[0]}
|
||||
options={models}
|
||||
onChangeSelection={(newVal) => { () => { } }}
|
||||
selectBoxRef={{ current: null }}
|
||||
/>}
|
||||
|
||||
<h2>{'Enabled'}</h2>
|
||||
todo
|
||||
|
|
|
|||
|
|
@ -40,6 +40,10 @@ class VoidConfigStateService extends Disposable implements IVoidConfigStateServi
|
|||
state: VoidConfigState;
|
||||
|
||||
// readonly voidConfigInfo: VoidConfigInfo = voidConfigInfo; // just putting this here for simplicity, it's static though
|
||||
get _defaultState() {
|
||||
return deepClone(defaultVoidConfigState)
|
||||
}
|
||||
|
||||
|
||||
constructor(
|
||||
@IStorageService private readonly _storageService: IStorageService,
|
||||
|
|
@ -50,7 +54,7 @@ class VoidConfigStateService extends Disposable implements IVoidConfigStateServi
|
|||
super()
|
||||
|
||||
// at the start, we haven't read the partial config yet, but we need to set state to something, just treat partialVoidConfig like it's empty
|
||||
this.state = deepClone(defaultVoidConfigState)
|
||||
this.state = this._defaultState
|
||||
|
||||
// read and update the actual state immediately
|
||||
this._readVoidConfigState().then(voidConfigState => {
|
||||
|
|
@ -59,11 +63,13 @@ class VoidConfigStateService extends Disposable implements IVoidConfigStateServi
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private async _readVoidConfigState(): Promise<VoidConfigState> {
|
||||
const encryptedPartialConfig = this._storageService.get(VOID_CONFIG_KEY, StorageScope.APPLICATION)
|
||||
|
||||
if (!encryptedPartialConfig)
|
||||
return deepClone(defaultVoidConfigState)
|
||||
return this._defaultState
|
||||
|
||||
const voidConfigStateStr = await this._encryptionService.decrypt(encryptedPartialConfig)
|
||||
return JSON.parse(voidConfigStateStr)
|
||||
|
|
|
|||
Loading…
Reference in a new issue