-
-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add setting preview for global search
- Loading branch information
1 parent
a2ad9d0
commit 207e2aa
Showing
33 changed files
with
1,020 additions
and
759 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { v4 as uuidv4 } from 'uuid' | ||
|
||
import { BaseEntity, type IBaseEntity } from '../base-entity' | ||
import type { SettingKey, SettingValue } from './setting-config' | ||
|
||
export interface Settings extends IBaseEntity { | ||
key: SettingKey | ||
value: SettingValue<SettingKey> | ||
updatedAt: number | ||
} | ||
|
||
export class SettingsEntity extends BaseEntity<Settings> { | ||
protected getDefaults(data?: Partial<Settings>): Settings { | ||
return { | ||
id: uuidv4(), | ||
key: 'unknown' as SettingKey, | ||
value: 'unknown', | ||
updatedAt: Date.now(), | ||
...data | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export * from './entity' | ||
export * from './render-options' | ||
export * from './setting-config' | ||
export * from './setting-items-config' | ||
export * from './types' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
export type SettingsSaveType = 'global' | 'workspace' | ||
|
||
interface BaseRenderOptions<FormType, ValueType> { | ||
type: FormType | ||
label: string | ||
description: string | ||
placeholder?: string | ||
defaultValue: ValueType | ||
} | ||
|
||
export type InputRenderOptions = BaseRenderOptions<'input', string> | ||
export type TextareaRenderOptions = BaseRenderOptions<'textarea', string> | ||
export type SwitchRenderOptions = BaseRenderOptions<'switch', boolean> | ||
export type NumberInputRenderOptions = BaseRenderOptions<'numberInput', number> | ||
export type SelectInputRenderOptions = BaseRenderOptions< | ||
'selectInput', | ||
string | ||
> & { | ||
options: Array<string | { label: string; value: string }> | ||
} | ||
export type ArrayInputRenderOptions = BaseRenderOptions<'arrayInput', any[]> | ||
export type ObjectInputRenderOptions = BaseRenderOptions< | ||
'objectInput', | ||
Record<string, any> | ||
> | ||
export type ModelManagementRenderOptions = BaseRenderOptions< | ||
'modelManagement', | ||
any | ||
> | ||
export type DocIndexingRenderOptions = BaseRenderOptions<'docManagement', any> | ||
export type CodebaseIndexingRenderOptions = BaseRenderOptions< | ||
'codebaseIndexing', | ||
any | ||
> | ||
|
||
export type RenderOptions = | ||
| InputRenderOptions | ||
| TextareaRenderOptions | ||
| SwitchRenderOptions | ||
| NumberInputRenderOptions | ||
| SelectInputRenderOptions | ||
| ArrayInputRenderOptions | ||
| ObjectInputRenderOptions | ||
| ModelManagementRenderOptions | ||
| DocIndexingRenderOptions | ||
| CodebaseIndexingRenderOptions | ||
|
||
export type RenderOptionsType = RenderOptions['type'] | ||
export type RenderOptionsMap = { | ||
[T in RenderOptionsType]: Extract<RenderOptions, { type: T }> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
import type { ValueUnion } from '@shared/types/common' | ||
|
||
import * as settingItemsConfig from './setting-items-config' | ||
import { | ||
aiCommandAutoRunConfig, | ||
aiCommandConfig, | ||
aiCommandCopyBeforeRunConfig, | ||
aiPromptConfig, | ||
apiConcurrencyConfig, | ||
autoRememberConvertLanguagePairsConfig, | ||
codeViewerHelperPromptConfig, | ||
convertLanguagePairsConfig, | ||
docManagementConfig, | ||
expertCodeEnhancerPromptListConfig, | ||
ignorePatternsConfig, | ||
modelsConfig, | ||
openaiBaseUrlConfig, | ||
openaiKeyConfig, | ||
openaiModelConfig, | ||
readClipboardImageConfig, | ||
respectGitIgnoreConfig, | ||
useSystemProxyConfig | ||
} from './setting-items-config' | ||
import type { SettingConfig, SettingConfigItem } from './types' | ||
|
||
// Setting groups and pages configuration | ||
export const settingsConfig: SettingConfig = { | ||
pages: [ | ||
{ | ||
id: 'general', | ||
label: 'General', | ||
settings: [ | ||
openaiKeyConfig, | ||
openaiModelConfig, | ||
openaiBaseUrlConfig, | ||
apiConcurrencyConfig, | ||
useSystemProxyConfig, | ||
ignorePatternsConfig, | ||
respectGitIgnoreConfig | ||
] | ||
} | ||
], | ||
groups: [ | ||
{ | ||
id: 'chat', | ||
label: 'Chat', | ||
pages: [ | ||
{ | ||
id: 'chatModel', | ||
label: 'AI Models', | ||
settings: [modelsConfig] | ||
}, | ||
{ | ||
id: 'chatDoc', | ||
label: 'Doc Sites Indexing', | ||
settings: [docManagementConfig] | ||
} | ||
] | ||
}, | ||
{ | ||
id: 'tools', | ||
label: 'Tools', | ||
pages: [ | ||
{ | ||
id: 'copyAsPrompt', | ||
label: 'Copy As Prompt', | ||
settings: [aiPromptConfig] | ||
}, | ||
{ | ||
id: 'codeConvert', | ||
label: 'Code Convert', | ||
settings: [ | ||
convertLanguagePairsConfig, | ||
autoRememberConvertLanguagePairsConfig | ||
] | ||
}, | ||
{ | ||
id: 'codeViewerHelper', | ||
label: 'Code Viewer Helper', | ||
settings: [codeViewerHelperPromptConfig] | ||
}, | ||
{ | ||
id: 'expertCodeEnhancer', | ||
label: 'Expert Code Enhancer', | ||
settings: [expertCodeEnhancerPromptListConfig] | ||
}, | ||
{ | ||
id: 'smartPaste', | ||
label: 'Smart Paste', | ||
settings: [readClipboardImageConfig] | ||
}, | ||
{ | ||
id: 'askAI', | ||
label: 'Ask AI', | ||
settings: [ | ||
aiCommandConfig, | ||
aiCommandCopyBeforeRunConfig, | ||
aiCommandAutoRunConfig | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} | ||
|
||
type SettingItemsConfig = typeof settingItemsConfig | ||
export type SettingKey = ValueUnion<SettingItemsConfig>['key'] | ||
|
||
type SettingItemConfigFromKey<K extends SettingKey> = SettingConfigItem< | ||
Extract<ValueUnion<SettingItemsConfig>, { key: K }>['renderOptions']['type'] | ||
> | ||
|
||
export type SettingValue<K extends SettingKey> = | ||
SettingItemConfigFromKey<K>['renderOptions']['defaultValue'] | ||
|
||
export const settingKeyItemConfigMap = Object.values(settingItemsConfig).reduce( | ||
(acc, item) => { | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
acc[item.key] = item | ||
return acc | ||
}, | ||
{} as { | ||
[K in SettingKey]: SettingItemConfigFromKey<K> | ||
} | ||
) |
Oops, something went wrong.