MCPcopy Create free account
hub / github.com/ChatLab/ChatLab / addLlmConfig

Function addLlmConfig

apps/cli/src/ai/llm-config.ts:108–146  ·  view source on GitHub ↗
(
  aiDataDir: string,
  config: Omit<AIServiceConfig, 'id'>
)

Source from the content-addressed store, hash-verified

106}
107
108export function addLlmConfig(
109 aiDataDir: string,
110 config: Omit<AIServiceConfig, 'id'>
111): { success: boolean; config?: AIServiceConfig; error?: string } {
112 const store = loadLlmConfig(aiDataDir)
113
114 if (store.configs.length >= MAX_CONFIG_COUNT) {
115 return { success: false, error: `Maximum ${MAX_CONFIG_COUNT} configs reached` }
116 }
117
118 const newConfig: AIServiceConfig = {
119 ...config,
120 id: randomUUID(),
121 }
122
123 const storeForSave = loadRawConfigStore(aiDataDir)
124 storeForSave.configs.push({
125 ...newConfig,
126 apiKey: '',
127 })
128
129 if (storeForSave.configs.length === 1) {
130 storeForSave.defaultAssistant = { configId: newConfig.id, modelId: newConfig.model || '' }
131 }
132
133 if (config.apiKey) {
134 const profileName = config.name?.toLowerCase().replace(/\s+/g, '-') || config.provider
135 writeAuthProfile(profileName, {
136 type: 'api_key',
137 provider: config.provider,
138 key: config.apiKey,
139 })
140 ;(storeForSave.configs[storeForSave.configs.length - 1] as unknown as Record<string, unknown>).authProfile =
141 profileName
142 }
143
144 saveLlmConfig(aiDataDir, storeForSave)
145 return { success: true, config: { ...newConfig, apiKey: '' } }
146}
147
148export function updateLlmConfig(
149 aiDataDir: string,

Callers

nothing calls this directly

Calls 4

writeAuthProfileFunction · 0.90
loadLlmConfigFunction · 0.85
loadRawConfigStoreFunction · 0.85
saveLlmConfigFunction · 0.85

Tested by

no test coverage detected