This repository was archived by the owner on Nov 14, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
feat(model): implement dynamic model selection with custom model support #1
Open
wenwen12345
wants to merge
1
commit into
Haleclipse:master
Choose a base branch
from
CometixAI:feat/custom-model
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -46,6 +46,12 @@ export const messageQueueState = reactive<MessageQueueState>({ | |||||||||
| queuedMessages: [] | ||||||||||
| }); | ||||||||||
|
|
||||||||||
| // 模型状态 | ||||||||||
| export const modelState = reactive({ | ||||||||||
| options: [] as string[], | ||||||||||
| selected: 'claude-4-sonnet' | ||||||||||
| }); | ||||||||||
|
|
||||||||||
| // ========== 消息总线 ========== | ||||||||||
|
|
||||||||||
| class WebviewMessageBus { | ||||||||||
|
|
@@ -213,10 +219,26 @@ class WebviewMessageBus { | |||||||||
| console.log('[MessageBus] 新会话已创建:', message.payload.sessionId); | ||||||||||
| }); | ||||||||||
|
|
||||||||||
| // 处理系统就绪 | ||||||||||
| // 处理系统就绪(也作为配置更新使用) | ||||||||||
| this.on('system/ready', (message) => { | ||||||||||
| sessionState.capabilities = message.payload.capabilities; | ||||||||||
| console.log('[MessageBus] 系统就绪:', message.payload.capabilities); | ||||||||||
| console.log('[MessageBus] 系统就绪/更新:', message.payload.capabilities); | ||||||||||
| // 更新模型列表 | ||||||||||
| if (Array.isArray(message.payload.models)) { | ||||||||||
| const newOptions = message.payload.models.slice(); | ||||||||||
| modelState.options = newOptions; | ||||||||||
|
Comment on lines
+228
to
+229
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: Direct assignment to reactive array may not trigger reactivity in some cases. If UI updates are inconsistent, try replacing the array contents with splice: modelState.options.splice(0, modelState.options.length, ...newOptions).
Suggested change
|
||||||||||
|
|
||||||||||
| // 如果当前选择不在新列表里,则回退到推荐或第一个 | ||||||||||
| if (!newOptions.includes(modelState.selected)) { | ||||||||||
| const recommended = message.payload.selectedModel && newOptions.includes(message.payload.selectedModel) | ||||||||||
| ? message.payload.selectedModel | ||||||||||
| : (newOptions[0] || modelState.selected); | ||||||||||
| modelState.selected = recommended; | ||||||||||
| } | ||||||||||
| } else if (message.payload.selectedModel && !modelState.selected) { | ||||||||||
| // 初次初始化:没有 options 时保存默认选择 | ||||||||||
| modelState.selected = message.payload.selectedModel; | ||||||||||
| } | ||||||||||
| }); | ||||||||||
|
|
||||||||||
| // 处理系统错误 | ||||||||||
|
|
@@ -732,7 +754,7 @@ export function sendChatMessage(text: string, sessionId?: string): string { | |||||||||
| // 发送到 Extension | ||||||||||
| messageBus.send({ | ||||||||||
| type: 'chat/send', | ||||||||||
| payload: { text, sessionId } | ||||||||||
| payload: { text, sessionId, model: modelState.selected } | ||||||||||
| }); | ||||||||||
|
|
||||||||||
| return requestId; | ||||||||||
|
|
@@ -876,4 +898,14 @@ if (typeof window !== 'undefined') { | |||||||||
| requestSessionList(); | ||||||||||
| }, 100); | ||||||||||
| }); | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * 打开设置(可传查询) | ||||||||||
| */ | ||||||||||
| export function openSettings(query?: string) { | ||||||||||
| messageBus.send({ | ||||||||||
| type: 'settings/open', | ||||||||||
| payload: { query } | ||||||||||
| }); | ||||||||||
| } | ||||||||||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 normalizing model names to avoid duplicates due to whitespace or casing.
Trimming and filtering helps, but without normalizing case or whitespace, users may still create duplicate model entries. Consider converting names to lower case or documenting the expected format.