MCPcopy
hub / github.com/HisMax/RedInk / saveTextProvider

Function saveTextProvider

frontend/src/composables/useProviderForm.ts:253–299  ·  view source on GitHub ↗

* 保存文本服务商

()

Source from the content-addressed store, hash-verified

251 * 保存文本服务商
252 */
253 async function saveTextProvider() {
254 const name = editingTextProvider.value || textForm.value.name
255
256 if (!name) {
257 setError('请填写服务商名称', '配置不完整')
258 return
259 }
260
261 if (!textForm.value.type) {
262 setError('请选择服务商类型', '配置不完整')
263 return
264 }
265
266 // 新增时必须填写 API Key
267 if (!editingTextProvider.value && !textForm.value.api_key) {
268 setError('请填写 API Key', '配置不完整')
269 return
270 }
271
272 const existingProvider = textConfig.value.providers[name] || {}
273
274 const providerData: any = {
275 type: textForm.value.type,
276 model: textForm.value.model
277 }
278
279 // 如果填写了新的 API Key,使用新的;否则保留原有的
280 if (textForm.value.api_key) {
281 providerData.api_key = textForm.value.api_key
282 } else if (existingProvider.api_key) {
283 providerData.api_key = existingProvider.api_key
284 }
285
286 if (textForm.value.base_url) {
287 providerData.base_url = textForm.value.base_url
288 }
289
290 // 如果是 OpenAI 兼容接口,保存 endpoint_type
291 if (textForm.value.type === 'openai_compatible') {
292 providerData.endpoint_type = textForm.value.endpoint_type
293 }
294
295 textConfig.value.providers[name] = providerData
296
297 closeTextModal()
298 await autoSaveConfig()
299 }
300
301 /**
302 * 删除文本服务商

Callers

nothing calls this directly

Calls 3

setErrorFunction · 0.85
closeTextModalFunction · 0.85
autoSaveConfigFunction · 0.85

Tested by

no test coverage detected