-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Fix(WebUi): allow batch resetting provider config to "follow" (iss#6749) #6825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
c542654
e04c753
f6ef3f7
ddd3f27
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -137,7 +137,7 @@ | |
| </v-select> | ||
| </v-col> | ||
| <v-col cols="12" md="6" lg="3"> | ||
| <v-select v-model="batchChatProvider" :items="chatProviderOptions" item-title="label" item-value="value" | ||
| <v-select v-model="batchChatProvider" :items="batchChatProviderOptions" item-title="label" item-value="value" | ||
| :label="tm('batchOperations.chatProvider')" hide-details clearable variant="solo-filled" flat density="comfortable"> | ||
| </v-select> | ||
| </v-col> | ||
|
|
@@ -584,9 +584,9 @@ export default { | |
|
|
||
| // Provider 配置 | ||
| providerConfig: { | ||
| chat_completion: null, | ||
| speech_to_text: null, | ||
| text_to_speech: null, | ||
| chat_completion: '__astrbot_follow_config__', | ||
| speech_to_text: '__astrbot_follow_config__', | ||
| text_to_speech: '__astrbot_follow_config__', | ||
| }, | ||
|
|
||
| // 插件配置 | ||
|
|
@@ -671,7 +671,7 @@ export default { | |
|
|
||
| chatProviderOptions() { | ||
| return [ | ||
| { label: this.tm('provider.followConfig'), value: null }, | ||
| { label: this.tm('provider.followConfig'), value: '__astrbot_follow_config__' }, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Extract the follow-config sentinel string into a shared constant to avoid duplication and typo risk. The Suggested implementation:
|
||
| ...this.availableChatProviders.map(p => ({ | ||
| label: `${p.name} (${p.model})`, | ||
| value: p.id | ||
|
|
@@ -681,7 +681,7 @@ export default { | |
|
|
||
| sttProviderOptions() { | ||
| return [ | ||
| { label: this.tm('provider.followConfig'), value: null }, | ||
| { label: this.tm('provider.followConfig'), value: '__astrbot_follow_config__' }, | ||
| ...this.availableSttProviders.map(p => ({ | ||
| label: `${p.name} (${p.model})`, | ||
| value: p.id | ||
|
|
@@ -691,7 +691,27 @@ export default { | |
|
|
||
| ttsProviderOptions() { | ||
| return [ | ||
| { label: this.tm('provider.followConfig'), value: null }, | ||
| { label: this.tm('provider.followConfig'), value: '__astrbot_follow_config__' }, | ||
| ...this.availableTtsProviders.map(p => ({ | ||
| label: `${p.name} (${p.model})`, | ||
| value: p.id | ||
| })) | ||
| ] | ||
| }, | ||
|
|
||
| batchChatProviderOptions() { | ||
| return [ | ||
| { label: this.tm('provider.followConfig'), value: '__astrbot_follow_config__' }, | ||
| ...this.availableChatProviders.map(p => ({ | ||
| label: `${p.name} (${p.model})`, | ||
| value: p.id | ||
| })) | ||
| ] | ||
| }, | ||
|
|
||
| batchTtsProviderOptions() { | ||
| return [ | ||
| { label: this.tm('provider.followConfig'), value: '__astrbot_follow_config__' }, | ||
| ...this.availableTtsProviders.map(p => ({ | ||
| label: `${p.name} (${p.model})`, | ||
| value: p.id | ||
|
|
@@ -914,9 +934,9 @@ export default { | |
|
|
||
| // 初始化 Provider 配置 | ||
| this.providerConfig = { | ||
| chat_completion: this.editingRules['provider_perf_chat_completion'] || null, | ||
| speech_to_text: this.editingRules['provider_perf_speech_to_text'] || null, | ||
| text_to_speech: this.editingRules['provider_perf_text_to_speech'] || null, | ||
| chat_completion: this.editingRules['provider_perf_chat_completion'] || '__astrbot_follow_config__', | ||
| speech_to_text: this.editingRules['provider_perf_speech_to_text'] || '__astrbot_follow_config__', | ||
| text_to_speech: this.editingRules['provider_perf_text_to_speech'] || '__astrbot_follow_config__', | ||
| } | ||
|
|
||
| // 初始化插件配置 | ||
|
|
@@ -997,7 +1017,7 @@ export default { | |
|
|
||
| for (const type of providerTypes) { | ||
| const value = this.providerConfig[type] | ||
| if (value) { | ||
| if (value && value !== '__astrbot_follow_config__') { | ||
| // 有值时更新 | ||
| updateTasks.push( | ||
| axios.post('/api/session/update-rule', { | ||
|
|
@@ -1007,7 +1027,7 @@ export default { | |
| }) | ||
| ) | ||
| } else if (this.editingRules[`provider_perf_${type}`]) { | ||
| // 选择了"跟随配置文件"(null)且之前有配置,则删除 | ||
| // 选择了"跟随配置文件" (__astrbot_follow_config__) 且之前有配置,则删除 | ||
| deleteTasks.push( | ||
| axios.post('/api/session/delete-rule', { | ||
| umo: this.selectedUmo.umo, | ||
|
|
@@ -1035,9 +1055,10 @@ export default { | |
| this.rulesList.push(item) | ||
| } | ||
| for (const type of providerTypes) { | ||
| if (this.providerConfig[type]) { | ||
| item.rules[`provider_perf_${type}`] = this.providerConfig[type] | ||
| this.editingRules[`provider_perf_${type}`] = this.providerConfig[type] | ||
| const val = this.providerConfig[type] | ||
| if (val && val !== '__astrbot_follow_config__') { | ||
| item.rules[`provider_perf_${type}`] = val | ||
| this.editingRules[`provider_perf_${type}`] = val | ||
| } else { | ||
| // 删除本地数据 | ||
| delete item.rules[`provider_perf_${type}`] | ||
|
|
@@ -1354,23 +1375,41 @@ export default { | |
| } | ||
|
|
||
| if (this.batchChatProvider !== null) { | ||
| tasks.push(axios.post('/api/session/batch-update-provider', { | ||
| scope, | ||
| umos, | ||
| group_id: groupId, | ||
| provider_type: 'chat_completion', | ||
| provider_id: this.batchChatProvider || null | ||
| })) | ||
| if (this.batchChatProvider === '__astrbot_follow_config__') { | ||
| tasks.push(axios.post('/api/session/batch-delete-rule', { | ||
| scope, | ||
| umos, | ||
| group_id: groupId, | ||
| rule_key: 'provider_perf_chat_completion' | ||
| })) | ||
| } else { | ||
| tasks.push(axios.post('/api/session/batch-update-provider', { | ||
| scope, | ||
| umos, | ||
| group_id: groupId, | ||
| provider_type: 'chat_completion', | ||
| provider_id: this.batchChatProvider | ||
| })) | ||
| } | ||
| } | ||
|
|
||
| if (this.batchTtsProvider !== null) { | ||
| tasks.push(axios.post('/api/session/batch-update-provider', { | ||
| scope, | ||
| umos, | ||
| group_id: groupId, | ||
| provider_type: 'text_to_speech', | ||
| provider_id: this.batchTtsProvider || null | ||
| })) | ||
| if (this.batchTtsProvider === '__astrbot_follow_config__') { | ||
| tasks.push(axios.post('/api/session/batch-delete-rule', { | ||
| scope, | ||
| umos, | ||
| group_id: groupId, | ||
| rule_key: 'provider_perf_text_to_speech' | ||
| })) | ||
| } else { | ||
| tasks.push(axios.post('/api/session/batch-update-provider', { | ||
| scope, | ||
| umos, | ||
| group_id: groupId, | ||
| provider_type: 'text_to_speech', | ||
| provider_id: this.batchTtsProvider | ||
| })) | ||
| } | ||
| } | ||
|
|
||
| if (tasks.length === 0) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Consider validating
scopevalues explicitly to produce clearer errors for invalid input.An unsupported
scope(e.g. a typo) currently just leavesumosempty and triggers the generic "缺少必要参数: umos 或有效的 scope" error, which hides thatscopeitself was invalid. Please validatescopeagainst the allowed set and return a specific error (e.g. "不支持的 scope 值") before expanding it intoumosso invalid scopes aren’t treated the same as missingumos.Suggested implementation:
To fully align this change with the rest of the function:
allowed_scopesto include all currently支持的 scope 值(例如如果上文有if scope == "online",if scope == "selected"等分支,请将这些字符串也加入到allowed_scopes集合中),确保不会误报合法 scope 为无效。AVAILABLE_SESSION_SCOPES), replace the hardcodedallowed_scopesset with that constant to keep things DRY and consistent.