fix(model): 统一模型配置解析,修复类型切换数据串扰#271
Open
XiaoBuHaly wants to merge 16 commits intoChevey339:masterfrom
Open
Conversation
…models - Clear chat-only state when switching to embedding; keep embedding input modalities configurable - Persist embedding input only; omit chat-only output/abilities from overrides - Migrate stored embedding overrides to drop abilities (versioned, one-time) - Use shared ModelTagWrap/ModelCapsulesRow for consistent tags/capsules (show eye for image input) - Ensure effective embedding model info never carries chat abilities while preserving modalities
…ution - Treat embedding output as text-only and clear chat-only abilities everywhere (service, lists, provider details) - Make override type parsing robust with trim().toLowerCase() - Harden edit flows: init-time embedding normalization, cache-first restore with inference fallback, omit builtInTools for embeddings - Prevent potential desktop Row overflow by wrapping ModelCapsulesRow with Flexible - Dedupe modalities/abilities in ModelTagWrap and refactor embedding override migration for clarity + debug stats
…akage - Normalize override type parsing to avoid unsafe casts - Enforce embedding invariants (text-only output, no abilities/tools) in effective resolution and migrations - Use explicit chat defaults when switching embedding -> chat without cache - Disable built-in tools toggles for embedding and improve model capsule semantics/dedup
- Add shared ModelOverrideResolver for consistent override parsing (type/modality/abilities) across UI and API resolution - Ignore unknown override values instead of coercing to valid enums to avoid mislabeling capabilities - Enforce non-empty chat input/output defaults and guard cache restores to prevent invalid empty modality sets - Extract migration constants and add release-visible logging for embedding override cleanup failures - Remove unused provider helper to reduce dead code
- Move model type enums and ModelInfo into core/models/model_types.dart - Dedupe and strictly parse override modalities/abilities while preserving order - Normalize override map keys to String on desktop to avoid cast issues - Add tooltip/semantics labels to model capability capsules - Reduce provider modelOverrides migration log verbosity
- Enforce embedding invariants on type overrides (clear abilities, force text-only output) - Add value equality/hashCode to ModelInfo for stable comparisons - Refactor model ability chips rendering and remove unused UI helpers - Add coverage for ModelOverrideResolver.applyModelOverride
- Remove `Flexible` wrapping around `ModelCapsulesRow` in desktop model selector tiles so capsules + actions stay right-aligned - Minor formatting cleanup in `_desktopModelTile` for readability (no behavior change besides alignment)
- Treat explicit empty modalities/abilities overrides as “clear” - Prefer apiModelId override when inferring base model info - Extract and reuse model type-switch cache helper across UI - Dispose dynamic header/body controllers to avoid leaks - Make ModelInfo list fields unmodifiable and normalize alpha usage - Add test to ignore unknown type override
…sing - Backup provider configs before migrating embedding modelOverrides and add migration logs. - Treat non-empty but invalid modalities/abilities lists as "no override" (avoid unintended clears). - Reset type-switch state safely (embedding defaults to text-only; restore cached chat state consistently). - Normalize override maps to `Map<String, dynamic>` across UI to prevent cast/runtime issues. - Guard model fetch actions against double taps and surface failures via snackbar. - Use built-in tool name constants and add coverage for `applyDisplayName` behavior.
- Treat override `name` as a string (trimmed) in model edit/detail and provider model display. - Dispose header/body field controllers when removing rows in model edit/detail UI. - Make model tags/capsules resilient to missing l10n and wrap chips on narrow layouts. - Add regression test to ensure non-model override keys are a no-op.
- Normalize `ModelInfo` modalities/abilities (dedupe + stable ordering). - Apply model overrides consistently in desktop editors/sheets; treat invalid list overrides as explicit clears. - Guard override application to avoid crashes on malformed configs, and harden model fetch dialog error handling. - Enforce mutual exclusion for URL Context vs Code Execution tool toggles.
- Persist provider configs only on successful writes and only run the migration when configs are loaded - Guard override parsing for headers/body and coerce values to strings to avoid type crashes - Add a shared modality toggle helper to keep a valid default selection - Deep-copy cached edit state to prevent cross-type mutation leaks - Improve resilience when applying overrides with debug-only error logging - Use override display name and effective model tags in provider model cards
- Normalize embedding invariants in the model registry (force text output; clear abilities) - Make embedding overrides migration accept legacy type keys/values and avoid marking migration on write failure - Add JSON-safe sanitization for provider modelOverrides before passing to UI - Improve diagnostics for unknown modality/ability values in overrides (debug-only) - Guard desktop fetch dialog actions when widget is unmounted - Show user feedback when saving a duplicate apiModelId key or when persistence fails
- Default empty modality lists to `text` and enforce embedding output invariants - Sanitize persisted override maps by normalizing keys to strings - Replace debug-only override failures with `FlutterLogger` error reporting (include stack traces) - Make provider model cards resilient when a provider config is missing - Localize duplicate `apiModelId` warning and save-failure message in model detail sheet - Add `SvgPicture` error fallbacks for model tags and guard modality toggles by index
- Always include text modality when normalizing model modalities - Expand embedding override cleanup to cover tools/built_in_tools aliases - Persist migrated provider configs safely (encode/write guards, abort on backup failure) and add debug-only decode/migration diagnostics - Make model type switch state immutable to prevent cross-type mutation leakage and honor cached embedding input - Add configurable ModelOverrideResolver logging and disable platform logging inside background isolates - Improve override apply failure logging with stack traces and reduce UI error detail leakage - Log missing deepthink icon in debug to aid asset troubleshooting
Contributor
|
|
Contributor
|
Contributor
Author
|
@luosc 我这次本来只想修切换模型种类时的模型能力异常,结果已经顺带改了一些偏离目标的安全修复性质的代码。为了保持 PR 聚焦,剩下的那个建议单独提一个 PR,这样回滚或追溯也更清晰。 |
Contributor
嗯嗯谢谢啦,我打算新PR,就提一嘴,希望owner能先并你这个我好在此基础上修改 |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
fix(model): 统一模型配置解析,修复类型切换数据串扰
统一 overrides 解析 · 修复 Chat/Embedding 切换串数据 · 存量配置迁移
Fixes #223
Bug Fix
否
18
███████░░░+1677
-711核心目标
架构设计总览
flowchart LR subgraph Data["数据层"] A["Raw Overrides\n(Map)"] --清洗--> B["ModelOverrideResolver"] B --解析 & 约束--> C["ModelInfo\n(有效实例)"] end subgraph State["状态 & 迁移"] Switch["ModelEditTypeSwitch\n(编辑器状态切换)"] --缓存/恢复--> C Migrate["SettingsProvider\n(启动迁移)"] --清理脏数据--> A end subgraph UI["表现层"] Mobile["移动端\nModelSelectSheet\nModelDetailSheet"] --> Tag["ModelTagWrap\nModelCapsulesRow"] Desktop["桌面端\nDesktopEditDialog\nSettingsPage"] --> Tag end C ==> UI C ==> State展开:编辑器类型切换时序图
sequenceDiagram participant 用户 participant 编辑器UI participant ModelEditTypeSwitch participant 状态缓存 rect rgb(240, 248, 255) Note over 用户,状态缓存: Chat → Embedding 用户->>编辑器UI: 点击切换到 Embedding 编辑器UI->>ModelEditTypeSwitch: apply(prev=Chat, next=Embedding) ModelEditTypeSwitch->>状态缓存: 保存当前 Chat 设置 ModelEditTypeSwitch->>ModelEditTypeSwitch: 清空 abilities, 锁定 output=text ModelEditTypeSwitch-->>编辑器UI: 返回新状态 (frozen sets) 编辑器UI->>编辑器UI: 刷新 UI (Tools 置灰) end rect rgb(255, 248, 240) Note over 用户,状态缓存: Embedding → Chat 用户->>编辑器UI: 点击切换回 Chat 编辑器UI->>ModelEditTypeSwitch: apply(prev=Embedding, next=Chat) ModelEditTypeSwitch->>状态缓存: 读取之前保存的 Chat 设置 ModelEditTypeSwitch-->>编辑器UI: 返回恢复后的状态 编辑器UI->>编辑器UI: 刷新 UI (Tools 恢复) end变更详情漫游
核心服务与模型
model_override_resolver.dartlib/core/services/
集中化解析服务 / 强制 Embedding 约束
embedding,强制abilities = [],output = [text]model_types.dartlib/core/models/
类型定义抽取 / 数据归一化
ModelType,Modality,ModelAbilityModelInfo不可变类chat_api_service.dartlib/core/services/api/
运行时接入 Resolver
ModelOverrideResolvertry-catch兜底-20状态管理与迁移
settings_provider.dartlib/core/providers/
存量数据清洗 / 自动备份
provider_configs_backup_v1tools,abilities,outputmodel_edit_state_helper.dartlib/features/model/widgets/
编辑器状态机 / 防串数据
model_provider.dartlib/core/providers/
ModelInfo类型定义,简化infer逻辑-37UI 组件与交互
model_tag_wrap.dartlib/shared/widgets/
统一能力标签组件
model_select_sheet.dartlib/features/model/widgets/
接入 Resolver / Isolate 清洗
ModelTagWrap替换散落逻辑-209model_edit_dialog.dartmodel_detail_sheet.dartModelEditTypeSwitch,保存时过滤无效字段,修复 Controller 释放遗漏-164provider_detail_page.dart
model_fetch_dialog.dart
desktop_settings_page.dart
-281测试与国际化
model_override_resolver_test.dartlib/l10n/*.arb行为变化对比
abilities 残留,UI 仍显示"工具调用"标签之前的 Chat 设置丢失Embedding 模型可能含 abilities/tools 字段散落在 5+ 个文件,行为不一致各页面样式/逻辑不统一风险控制与回滚
try-catch包裹,失败仅打印日志,不阻塞启动migrations_version_v1,从provider_configs_backup_v1恢复审阅指引
验证清单
自动化测试
flutter test test/core/services/model_override_resolver_test.dart预期:全部通过
手动验证 - 迁移
provider_configs_v1[Migration]日志手动验证 - 编辑交互
UI 走查