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 = {
|
export const voidInitModelOptions = {
|
||||||
anthropic: () => ({
|
anthropic: () => ({
|
||||||
model: 'claude-3-5-sonnet-20240620',
|
model: 'claude-3-5-sonnet-20240620',
|
||||||
|
|
@ -161,36 +201,10 @@ export const voidInitModelOptions = {
|
||||||
"gemma-7b-it"
|
"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
|
} as const
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export type ProviderName = keyof typeof voidProviderDefaults
|
export type ProviderName = keyof typeof voidProviderDefaults
|
||||||
export const providerNames = Object.keys(voidProviderDefaults) as ProviderName[]
|
export const providerNames = Object.keys(voidProviderDefaults) as ProviderName[]
|
||||||
|
|
||||||
|
|
@ -204,7 +218,7 @@ export type FeatureName = typeof featureNames[number]
|
||||||
export type VoidConfigState = {
|
export type VoidConfigState = {
|
||||||
[providerName in ProviderName]: ({
|
[providerName in ProviderName]: ({
|
||||||
enabled: string, // 'true' | 'false'
|
enabled: string, // 'true' | 'false'
|
||||||
models: string[],
|
models: string[] | null, // if null, user can type in any string as a model
|
||||||
model: string,
|
model: string,
|
||||||
maxTokens: string,
|
maxTokens: string,
|
||||||
} & {
|
} & {
|
||||||
|
|
@ -214,6 +228,7 @@ export type VoidConfigState = {
|
||||||
|
|
||||||
|
|
||||||
type UnionOfKeys<T> = T extends T ? keyof T : never;
|
type UnionOfKeys<T> = T extends T ? keyof T : never;
|
||||||
|
|
||||||
export const descOfSettingName = (providerName: ProviderName, settingName: UnionOfKeys<VoidConfigState[ProviderName]>) => {
|
export const descOfSettingName = (providerName: ProviderName, settingName: UnionOfKeys<VoidConfigState[ProviderName]>) => {
|
||||||
if (settingName === 'apiKey')
|
if (settingName === 'apiKey')
|
||||||
return 'API Key'
|
return 'API Key'
|
||||||
|
|
@ -230,60 +245,68 @@ export const descOfSettingName = (providerName: ProviderName, settingName: Union
|
||||||
else if (settingName === 'models')
|
else if (settingName === 'models')
|
||||||
return 'Available 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 = {
|
export const defaultVoidConfigState: VoidConfigState = {
|
||||||
anthropic: {
|
anthropic: {
|
||||||
|
...voidProviderDefaults.anthropic,
|
||||||
|
...voidInitModelOptions.anthropic(),
|
||||||
enabled: 'false',
|
enabled: 'false',
|
||||||
models: [],
|
maxTokens: '',
|
||||||
model: '',
|
|
||||||
apiKey: '',
|
|
||||||
maxTokens: '1000',
|
|
||||||
},
|
},
|
||||||
openAI: {
|
openAI: {
|
||||||
|
...voidProviderDefaults.openAI,
|
||||||
|
...voidInitModelOptions.openAI(),
|
||||||
enabled: 'false',
|
enabled: 'false',
|
||||||
models: [],
|
maxTokens: '',
|
||||||
model: '',
|
|
||||||
apiKey: '',
|
|
||||||
maxTokens: '1000',
|
|
||||||
},
|
},
|
||||||
ollama: {
|
ollama: {
|
||||||
|
...voidProviderDefaults.ollama,
|
||||||
|
...voidInitModelOptions.ollama(),
|
||||||
enabled: 'false',
|
enabled: 'false',
|
||||||
models: [],
|
maxTokens: '',
|
||||||
model: '',
|
|
||||||
endpoint: '',
|
|
||||||
maxTokens: '1000',
|
|
||||||
},
|
},
|
||||||
openRouter: {
|
openRouter: {
|
||||||
|
...voidProviderDefaults.openRouter,
|
||||||
|
...voidInitModelOptions.openRouter(),
|
||||||
enabled: 'false',
|
enabled: 'false',
|
||||||
models: [],
|
maxTokens: '',
|
||||||
model: '',
|
|
||||||
apiKey: '',
|
|
||||||
maxTokens: '1000',
|
|
||||||
},
|
},
|
||||||
openAICompatible: {
|
openAICompatible: {
|
||||||
|
...voidProviderDefaults.openAICompatible,
|
||||||
|
...voidInitModelOptions.openAICompatible(),
|
||||||
enabled: 'false',
|
enabled: 'false',
|
||||||
models: [],
|
maxTokens: '',
|
||||||
model: '',
|
|
||||||
apiKey: '',
|
|
||||||
endpoint: '',
|
|
||||||
maxTokens: '1000',
|
|
||||||
},
|
},
|
||||||
gemini: {
|
gemini: {
|
||||||
|
...voidProviderDefaults.gemini,
|
||||||
|
...voidInitModelOptions.gemini(),
|
||||||
enabled: 'false',
|
enabled: 'false',
|
||||||
models: [],
|
maxTokens: '',
|
||||||
model: '',
|
|
||||||
apiKey: '',
|
|
||||||
maxTokens: '1000',
|
|
||||||
},
|
},
|
||||||
groq: {
|
groq: {
|
||||||
|
...voidProviderDefaults.groq,
|
||||||
|
...voidInitModelOptions.groq(),
|
||||||
enabled: 'false',
|
enabled: 'false',
|
||||||
models: [],
|
maxTokens: '',
|
||||||
model: '',
|
|
||||||
apiKey: '',
|
|
||||||
maxTokens: '1000',
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,8 @@ const Sidebar = () => {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className={`${tab === 'settings' ? '' : 'hidden'}`}>
|
<div className={`${tab === 'settings' ? '' : 'hidden'}`}>
|
||||||
{false && <SidebarModelSettings />}
|
<SidebarModelSettings />
|
||||||
|
--------
|
||||||
<SidebarProviderSettings />
|
<SidebarProviderSettings />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,8 @@ export const SidebarModelSettingsForFeature = ({ featureName }: { featureName: F
|
||||||
const models: [string,string][] = []
|
const models: [string,string][] = []
|
||||||
for (const providerName of providerNames) {
|
for (const providerName of providerNames) {
|
||||||
const providerConfig = voidConfigState[providerName]
|
const providerConfig = voidConfigState[providerName]
|
||||||
if (!providerConfig.enabled) continue
|
if (providerConfig.enabled === 'false') continue
|
||||||
providerConfig.models.forEach(model => {
|
providerConfig.models?.forEach(model => {
|
||||||
models.push([providerName,model])
|
models.push([providerName,model])
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -31,7 +31,6 @@ export const SidebarModelSettingsForFeature = ({ featureName }: { featureName: F
|
||||||
export const SidebarModelSettings = () => {
|
export const SidebarModelSettings = () => {
|
||||||
return <>
|
return <>
|
||||||
{featureNames.map(featureName => <SidebarModelSettingsForFeature key={featureName} featureName={featureName} />)}
|
{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 SettingsForProvider = ({ providerName }: { providerName: ProviderName }) => {
|
||||||
const voidConfigState = useConfigState()
|
const voidConfigState = useConfigState()
|
||||||
const voidConfigService = useService('configStateService')
|
const voidConfigService = useService('configStateService')
|
||||||
console.log('CONFIG', voidConfigState)
|
console.log('CONFIG!', voidConfigState)
|
||||||
console.log('provider:', providerName, voidConfigState[providerName])
|
console.log('provider:', providerName, voidConfigState[providerName])
|
||||||
const { models, model, ...others } = voidConfigState[providerName]
|
const { models, model, ...others } = voidConfigState[providerName]
|
||||||
|
|
||||||
|
|
@ -36,12 +36,14 @@ const SettingsForProvider = ({ providerName }: { providerName: ProviderName }) =
|
||||||
})}
|
})}
|
||||||
|
|
||||||
<h2>{'Models'}</h2>
|
<h2>{'Models'}</h2>
|
||||||
<VoidSelectBox
|
{models === null ?
|
||||||
initVal={models[0]}
|
<p>{'No models available.'}</p>
|
||||||
options={models}
|
: <VoidSelectBox
|
||||||
onChangeSelection={(newVal) => { () => { } }}
|
initVal={models[0]}
|
||||||
selectBoxRef={{ current: null }}
|
options={models}
|
||||||
/>
|
onChangeSelection={(newVal) => { () => { } }}
|
||||||
|
selectBoxRef={{ current: null }}
|
||||||
|
/>}
|
||||||
|
|
||||||
<h2>{'Enabled'}</h2>
|
<h2>{'Enabled'}</h2>
|
||||||
todo
|
todo
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,10 @@ class VoidConfigStateService extends Disposable implements IVoidConfigStateServi
|
||||||
state: VoidConfigState;
|
state: VoidConfigState;
|
||||||
|
|
||||||
// readonly voidConfigInfo: VoidConfigInfo = voidConfigInfo; // just putting this here for simplicity, it's static though
|
// readonly voidConfigInfo: VoidConfigInfo = voidConfigInfo; // just putting this here for simplicity, it's static though
|
||||||
|
get _defaultState() {
|
||||||
|
return deepClone(defaultVoidConfigState)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@IStorageService private readonly _storageService: IStorageService,
|
@IStorageService private readonly _storageService: IStorageService,
|
||||||
|
|
@ -50,7 +54,7 @@ class VoidConfigStateService extends Disposable implements IVoidConfigStateServi
|
||||||
super()
|
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
|
// 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
|
// read and update the actual state immediately
|
||||||
this._readVoidConfigState().then(voidConfigState => {
|
this._readVoidConfigState().then(voidConfigState => {
|
||||||
|
|
@ -59,11 +63,13 @@ class VoidConfigStateService extends Disposable implements IVoidConfigStateServi
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private async _readVoidConfigState(): Promise<VoidConfigState> {
|
private async _readVoidConfigState(): Promise<VoidConfigState> {
|
||||||
const encryptedPartialConfig = this._storageService.get(VOID_CONFIG_KEY, StorageScope.APPLICATION)
|
const encryptedPartialConfig = this._storageService.get(VOID_CONFIG_KEY, StorageScope.APPLICATION)
|
||||||
|
|
||||||
if (!encryptedPartialConfig)
|
if (!encryptedPartialConfig)
|
||||||
return deepClone(defaultVoidConfigState)
|
return this._defaultState
|
||||||
|
|
||||||
const voidConfigStateStr = await this._encryptionService.decrypt(encryptedPartialConfig)
|
const voidConfigStateStr = await this._encryptionService.decrypt(encryptedPartialConfig)
|
||||||
return JSON.parse(voidConfigStateStr)
|
return JSON.parse(voidConfigStateStr)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue