Skip to content

Add Memex model service setup#215

Merged
sparkleMing merged 3 commits into
mainfrom
feature/memex-model-service-ui
May 28, 2026
Merged

Add Memex model service setup#215
sparkleMing merged 3 commits into
mainfrom
feature/memex-model-service-ui

Conversation

@sparkleMing
Copy link
Copy Markdown
Collaborator

Summary

  • add a global-only Memex model service setup page with account login, credit top-up, and automatic Memex credential application
  • wire the service into onboarding, personal center, settings search, and model-config recovery paths while keeping CN flavors on regular model configuration
  • refresh localized copy for the Memex model service flow and remove auth UI from advanced model config pages

Tests

  • dart analyze lib/config/app_config.dart lib/data/services/settings_registry.dart lib/ui/settings/widgets/ai_service_setup_page.dart lib/ui/settings/widgets/memex_auth_section.dart lib/ui/settings/widgets/personal_center_screen.dart lib/ui/settings/widgets/model_config_edit_page.dart lib/ui/user_setup/widgets/setup_model_config_page.dart lib/ui/user_setup/widgets/user_setup_screen.dart lib/ui/timeline/widgets/timeline_screen.dart (passes with existing info lints)
  • flutter test test/ui/settings/model_agent_config_pages_test.dart

Closes #201

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 28, 2026

PR AI Review / PR AI 语义预检

中文

  • 风险等级:高风险
  • 需要人工审核:
  • 黄金链路影响:较可能
  • 置信度:high
  • Workflow run:26572932223

PR 为 global flavor 新增 Memex 模型服务设置页(AiServiceSetupPage),集成到 onboarding、个人中心、设置搜索和模型配置恢复路径。CN flavor 保持原有模型配置流程。主要风险:新页面将业务逻辑直接放在 StatefulWidget 中(LLM config 读写、默认值设置),违反 MVVM 架构;多个入口点的路由条件分支增加了回归风险;缺少对 MemexAuthSection 新回调的独立测试。

影响范围

  • ui
  • i18n
  • llm_provider
  • storage
  • tests

黄金链路

  • llm_configuration
  • platform_entry
  • 说明:PR 直接修改 LLM 配置的保存和默认值设置逻辑(通过 AiServiceSetupPage._saveMemexService),并在 onboarding、timeline banner、invalid config dialog、error dialog 等多个入口点切换导航目标。任何凭证保存或默认 config key 设置的 bug 都可能破坏整个 agent pipeline。

风险项

  • high AiServiceSetupPage 将业务逻辑直接写在 StatefulWidget 中,违反 MVVM 架构。证据:lib/ui/settings/widgets/ai_service_setup_page.dart: _saveMemexService() (lines 284-334) fetches LLM configs, creates/replaces LLMConfig, saves configs, sets default config key — all in widget state, lib/ui/settings/widgets/ai_service_setup_page.dart: _clearMemexService() (lines 336-368) fetches configs, replaces with default, finds fallback, sets default key — all in widget state, AGENTS.md: 'ViewModels extend ChangeNotifier, created at screen level' and 'ViewModel must NOT depend on BuildContext or any widget'。
    建议:将 LLM config 读写逻辑提取到 ViewModel(ChangeNotifier),通过 MemexRouter 委托到 repository/service。页面只通过 ListenableBuilder 绑定 ViewModel 状态。
  • high 直接实例化 MemexRouter() 而非通过依赖注入获取。证据:lib/ui/settings/widgets/ai_service_setup_page.dart:293: final router = MemexRouter();, lib/ui/settings/widgets/ai_service_setup_page.dart:346: final router = MemexRouter();, AGENTS.md: 'ViewModels receive MemexRouter via constructor: MyViewModel({required MemexRouter router})'。
    建议:通过构造函数注入 MemexRouter(遵循已有模式),或至少通过 Provider 获取实例。
  • medium 业务逻辑使用原始 try/catch 而非 Result 模式。证据:lib/ui/settings/widgets/ai_service_setup_page.dart:284-334: _saveMemexService uses try/catch/finally, lib/ui/settings/widgets/ai_service_setup_page.dart:336-368: _clearMemexService uses try/catch, AGENTS.md: 'Sealed Result type (Ok/Error) for explicit error handling — no raw try/catch in ViewModels'。
    建议:使用 runResult() 包装异步操作,返回 Future<Result>,由 ViewModel 消费。
  • medium LLM 配置保存路径被新页面修改,影响 agent pipeline 可用性。证据:lib/ui/settings/widgets/ai_service_setup_page.dart: _saveMemexService overwrites LLMConfig.defaultClientKey and calls setDefaultLLMConfigKey, lib/main.dart: _handleInvalidModelConfig now routes to AiServiceSetupPage when AppConfig.enableMemexModelService is true, lib/main.dart: _handleErrorNotification routes auth errors to AiServiceSetupPage when feature flag is true。
    建议:确保 _saveMemexService 的 config 覆盖逻辑在 credential 缺失或 service 异常时有安全回退。验证 invalid config dialog 和 error dialog 的路由不会导致死循环或状态不一致。
  • info MemexAuthSection 新增的 onLoginStateChanged / onLogout 回调缺少独立测试。证据:lib/ui/settings/widgets/memex_auth_section.dart: onLoginStateChanged and onLogout are new optional callbacks, test/ui/settings/widgets/ai_service_setup_page_test.dart: tests verify page rendering and navigation but not callback wiring。
    建议:为 MemexAuthSection 的 login/logout 回调添加 widget test,验证状态传播正确。
  • info unrelated test change: app_update_service_test.dart waitFor 超时调整。证据:test/data/services/app_update_service_test.dart: loop count 20→50, delay Duration.zero→10ms, This change is unrelated to Memex model service setup。
    建议:建议拆分为独立 PR,保持 PR 聚焦。

测试缺口

  • ui AiServiceSetupPage 的 _saveMemexService / _clearMemexService 核心逻辑缺少测试覆盖(凭证保存、config 覆盖、默认 key 设置、回退逻辑)。 建议检查:Add integration or widget tests that mock MemexRouter and verify LLM config save/clear/default-key behavior
  • ui onboarding 流程中 AiServiceSetupPage 的集成路径缺少端到端测试(skip 和 complete 两条路径)。 建议检查:Add test verifying user_setup_screen navigates to AiServiceSetupPage for global flavor and completes onboarding correctly

English

  • Risk level: HIGH
  • Human review required: YES
  • Golden path impact: LIKELY
  • Confidence: high
  • Workflow run: 26572932223

PR adds a Memex model service setup page (AiServiceSetupPage) for global flavors, wired into onboarding, personal center, settings search, and model-config recovery paths. CN flavors stay on existing model configuration flow. Main risks: the new page puts business logic (LLM config read/write, default key assignment) directly in a StatefulWidget, violating MVVM architecture; conditional routing changes across multiple entry points increase regression risk; new MemexAuthSection callbacks lack dedicated tests.

Affected Areas

  • ui
  • i18n
  • llm_provider
  • storage
  • tests

Golden Path

  • llm_configuration
  • platform_entry
  • Rationale: PR directly modifies LLM config save and default-config-key logic via AiServiceSetupPage._saveMemexService, and re-routes navigation from multiple entry points (onboarding, timeline banner, invalid config dialog, error dialog). Any bug in credential save or default config key assignment could break the entire agent pipeline.

Findings

  • high AiServiceSetupPage puts business logic directly in StatefulWidget, violating MVVM architecture. Evidence: lib/ui/settings/widgets/ai_service_setup_page.dart: _saveMemexService() (lines 284-334) fetches LLM configs, creates/replaces LLMConfig, saves configs, sets default config key — all in widget state, lib/ui/settings/widgets/ai_service_setup_page.dart: _clearMemexService() (lines 336-368) fetches configs, replaces with default, finds fallback, sets default key — all in widget state, AGENTS.md: 'ViewModels extend ChangeNotifier, created at screen level' and 'ViewModel must NOT depend on BuildContext or any widget'.
    Recommendation: Extract LLM config read/write logic into a ViewModel (ChangeNotifier) that delegates to MemexRouter. The page should bind ViewModel state via ListenableBuilder only.
  • high Direct MemexRouter() instantiation instead of dependency injection. Evidence: lib/ui/settings/widgets/ai_service_setup_page.dart:293: final router = MemexRouter();, lib/ui/settings/widgets/ai_service_setup_page.dart:346: final router = MemexRouter();, AGENTS.md: 'ViewModels receive MemexRouter via constructor: MyViewModel({required MemexRouter router})'.
    Recommendation: Inject MemexRouter via constructor (following existing pattern), or at minimum obtain it via Provider.
  • medium Business logic uses raw try/catch instead of Result pattern. Evidence: lib/ui/settings/widgets/ai_service_setup_page.dart:284-334: _saveMemexService uses try/catch/finally, lib/ui/settings/widgets/ai_service_setup_page.dart:336-368: _clearMemexService uses try/catch, AGENTS.md: 'Sealed Result type (Ok/Error) for explicit error handling — no raw try/catch in ViewModels'.
    Recommendation: Wrap async operations with runResult() returning Future<Result>, consumed by ViewModel.
  • medium LLM config save path modified by new page, affecting agent pipeline availability. Evidence: lib/ui/settings/widgets/ai_service_setup_page.dart: _saveMemexService overwrites LLMConfig.defaultClientKey and calls setDefaultLLMConfigKey, lib/main.dart: _handleInvalidModelConfig now routes to AiServiceSetupPage when AppConfig.enableMemexModelService is true, lib/main.dart: _handleErrorNotification routes auth errors to AiServiceSetupPage when feature flag is true.
    Recommendation: Ensure _saveMemexService config-overwrite logic has safe fallback when credentials are missing or service errors. Verify invalid-config and error-dialog routing doesn't cause loops or state inconsistency.
  • info New MemexAuthSection callbacks (onLoginStateChanged / onLogout) lack dedicated tests. Evidence: lib/ui/settings/widgets/memex_auth_section.dart: onLoginStateChanged and onLogout are new optional callbacks, test/ui/settings/widgets/ai_service_setup_page_test.dart: tests verify page rendering and navigation but not callback wiring.
    Recommendation: Add widget tests for MemexAuthSection login/logout callbacks to verify state propagation.
  • info Unrelated test change: app_update_service_test.dart waitFor timeout adjustment. Evidence: test/data/services/app_update_service_test.dart: loop count 20→50, delay Duration.zero→10ms, This change is unrelated to Memex model service setup.
    Recommendation: Split into a separate PR to keep this PR focused.

Test Gaps

  • ui AiServiceSetupPage's _saveMemexService / _clearMemexService core logic lacks test coverage (credential save, config overwrite, default key assignment, fallback logic). Suggested check: Add integration or widget tests that mock MemexRouter and verify LLM config save/clear/default-key behavior.
  • ui Onboarding flow integration path for AiServiceSetupPage lacks end-to-end tests (both skip and complete paths). Suggested check: Add test verifying user_setup_screen navigates to AiServiceSetupPage for global flavor and completes onboarding correctly.

AI review is advisory. Maintainers should verify the result before merging.

@github-actions github-actions Bot added ai: medium risk AI review classified the PR as medium risk golden path impact AI review found possible impact to a core user flow needs human review AI review or policy signals require maintainer review labels May 28, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 28, 2026

PR Preflight Summary / PR 预检汇总

中文

  • 统一结论:低风险:两个预检均已完成,质量预检通过,可走普通手动合并流程。
  • Policy preflight:低风险。未命中打回或高风险规则,仅有 8 条警告供 review 参考。
  • Flutter quality:通过。Analyzer 和 test baseline 均未发现新增问题。
  • PR head:9b8c3b507e7ac694ccc32e0047d8723825abdb94
  • Policy run:26572932160
  • Flutter run:26572932794

English

  • Combined result: Low risk: both preflights completed and quality passed; use the normal manual merge flow.
  • Policy preflight: LOW RISK. No blocking or high-risk policy signal; 8 warning(s) remain for review context.
  • Flutter quality: PASS. Analyzer and test baselines found no newly introduced issue.
  • PR head: 9b8c3b507e7ac694ccc32e0047d8723825abdb94
  • Policy run: 26572932160
  • Flutter run: 26572932794
PR Policy Preflight / PR 规则预检

PR Policy Preflight / PR 规则预检

中文

  • 判定:低风险
  • 变更文件数:17
  • 变更行数:1604
  • Diff 是否截断:false

规则命中

  • 警告 large-single-file-change lib/ui/settings/widgets/ai_service_setup_page.dart: 单个文件变更 521 行,超过 review 关注阈值 400。
  • 警告 large-single-file-change lib/ui/settings/widgets/memex_auth_section.dart: 单个文件变更 610 行,超过 review 关注阈值 400。
  • 警告 too-many-lines: PR 修改了 1604 行,超过 review 关注阈值 800。
  • 警告 sensitive-keyword lib/data/services/settings_registry.dart: UserStorage 引用发生变化。
  • 警告 sensitive-keyword lib/ui/settings/widgets/ai_service_setup_page.dart: UserStorage 引用发生变化。
  • 警告 sensitive-keyword lib/ui/settings/widgets/ai_service_setup_page.dart: 疑似凭证标识符发生变化。
  • 警告 sensitive-keyword lib/ui/settings/widgets/memex_auth_section.dart: UserStorage 引用发生变化。
  • 警告 sensitive-keyword lib/ui/settings/widgets/personal_center_screen.dart: UserStorage 引用发生变化。

English

  • Decision: LOW RISK
  • Changed files: 17
  • Changed lines: 1604
  • Diff truncated: false

Findings

  • warn large-single-file-change lib/ui/settings/widgets/ai_service_setup_page.dart: Single file changed 521 lines, above the review-attention threshold 400.
  • warn large-single-file-change lib/ui/settings/widgets/memex_auth_section.dart: Single file changed 610 lines, above the review-attention threshold 400.
  • warn too-many-lines: PR changes 1604 lines, above the review-attention threshold 800.
  • warn sensitive-keyword lib/data/services/settings_registry.dart: UserStorage reference changed.
  • warn sensitive-keyword lib/ui/settings/widgets/ai_service_setup_page.dart: UserStorage reference changed.
  • warn sensitive-keyword lib/ui/settings/widgets/ai_service_setup_page.dart: Credential-like identifier changed.
  • warn sensitive-keyword lib/ui/settings/widgets/memex_auth_section.dart: UserStorage reference changed.
  • warn sensitive-keyword lib/ui/settings/widgets/personal_center_screen.dart: UserStorage reference changed.
PR Flutter Quality / Flutter 质量预检

PR Flutter Quality / Flutter 质量预检

中文

  • 总体:通过
  • Analyzer baseline:通过
  • Test baseline:通过

English

  • Overall: PASS
  • Analyzer baseline: PASS
  • Test baseline: PASS

Flutter Analyzer Baseline

  • Base issues: 307
  • PR issues: 307
  • New issues: 0

No new analyzer issues introduced by this PR.

Flutter Test Baseline

  • Base failures: 0
  • PR failures: 0
  • New failures: 0

No new Flutter test failures introduced by this PR.

@github-actions github-actions Bot added ai: high risk AI review classified the PR as high risk golden path impact AI review found possible impact to a core user flow needs human review AI review or policy signals require maintainer review and removed ai: medium risk AI review classified the PR as medium risk needs human review AI review or policy signals require maintainer review golden path impact AI review found possible impact to a core user flow labels May 28, 2026
@github-actions github-actions Bot added ai: high risk AI review classified the PR as high risk golden path impact AI review found possible impact to a core user flow needs human review AI review or policy signals require maintainer review and removed ai: high risk AI review classified the PR as high risk needs human review AI review or policy signals require maintainer review golden path impact AI review found possible impact to a core user flow labels May 28, 2026
@sparkleMing sparkleMing merged commit 160417a into main May 28, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai: high risk AI review classified the PR as high risk golden path impact AI review found possible impact to a core user flow needs human review AI review or policy signals require maintainer review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Roadmap] MemexAI 服务化交互优化

1 participant