Skip to content

fix(providers): discover import paths#1649

Merged
zerob13 merged 4 commits into
devfrom
feat/import-ccswitch
May 21, 2026
Merged

fix(providers): discover import paths#1649
zerob13 merged 4 commits into
devfrom
feat/import-ccswitch

Conversation

@zerob13
Copy link
Copy Markdown
Collaborator

@zerob13 zerob13 commented May 21, 2026

Summary

  • discover CC Switch Desktop app data overrides from app_paths.json before scanning the default database
  • discover Cherry Studio custom app data paths from ~/.cherrystudio/config/config.json before scanning the default LevelDB
  • keep existing provider parsing and Codex exclusion behavior unchanged

Tests

  • pnpm exec vitest --config vitest.config.ts test/main/routes/providers/providerImportService.test.ts
  • pnpm run format
  • pnpm run i18n
  • pnpm run lint
  • pnpm run typecheck
  • git diff --check

Summary by CodeRabbit

Release Notes

  • New Features

    • Added support for importing provider settings from CC Switch
    • Introduced credentials-only import mode, preserving built-in provider endpoints while importing API keys
    • Enhanced automatic detection of CC Switch and Cherry Studio custom configuration paths
  • User Interface

    • Improved provider import dialog to hide unsupported sources
    • Added warning indicators for credential-only imports and configuration conflicts
  • Localization

    • Updated UI strings across all supported languages to reflect new features and warnings

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 21, 2026

📝 Walkthrough

Walkthrough

This PR adds comprehensive CC Switch provider import support to DeepChat, including SQLite-based provider scanning, credential-only import mode (preserving built-in endpoints when credentials differ), desktop configuration path discovery for both CC Switch and Cherry Studio, UI visibility filtering, 12-language localization updates, and extensive test coverage with mock SQLite infrastructure.

Changes

Provider Import: CC Switch and Cherry Studio Discovery

Layer / File(s) Summary
Shared Type Contracts and Import Modes
src/shared/providerImport.ts, src/shared/contracts/routes/providers.routes.ts
New ProviderImportApplyMode union type ('full' | 'credentials_only'), importMode field on ProviderImportMapping, expanded PROVIDER_IMPORT_SOURCE_IDS to include cc-switch, and route warning schema extended with overwrites_previous_selection and credential_only_import enum values.
CC Switch Source Definition and Constants
src/main/routes/providers/providerImportService.ts (lines 49–181)
SOURCE_DEFINITIONS adds cc-switch with Unix and Windows database paths, PROVIDER_ID_ALIASES expanded with new provider mappings, CC Switch app types and database constants defined, OPENAI_COMPATIBLE_TYPES and API_KEY_PLACEHOLDERS sets updated, and SOURCE_PREFIX includes cc-switch for display.
Provider Normalization and Validation Helpers
src/main/routes/providers/providerImportService.ts (lines 222–332)
isImportableApiKey rejects empty keys and placeholder values, toObjectValue normalizes non-array objects, normalizeModelCollection handles both array and object-shaped model structures, and detected-path display generation for Windows/Unix with containment and relative-path helpers.
CC Switch Database Reader and Provider Extraction
src/main/routes/providers/providerImportService.ts (lines 615–1023)
readCcSwitch reads SQLite providers table for supported app types (Claude, Gemini, OpenCode, OpenClaw, Hermes), parses JSON settings, extracts metadata (type, API key, base URL, models), normalizes CC Switch API type strings (OpenAI response/completions, Anthropic, Gemini, Bedrock), filters importable providers, and excludes Codex rows and blank keys from previews.
Provider Mapping and Import Mode Resolution
src/main/routes/providers/providerImportService.ts (lines 1036–1201)
detectProviderIdFromBaseUrl matches providers by base URL heuristics, resolveBuiltinImportMode determines mode based on source/target API type differences, builtin mapping sets importMode, custom mapping always uses full mode, and unsupported cases (e.g., CC Switch aws-bedrock) are handled.
Apply Logic Respecting Credentials-Only Mode
src/main/routes/providers/providerImportService.ts (lines 1220–1340)
When importMode is credentials_only, target's base URL is preserved (not overwritten), planned models are set to empty list, modelCount derived from planned models, and custom provider credential validation requires both API key and HTTP(S) base URL.
Desktop Config Path Discovery and Cherry Studio Custom Data
src/main/routes/providers/providerImportService.ts (lines 1470–1685)
resolveSourcePath detects CC Switch Desktop app_paths.json override path (OS-specific resolution for macOS/Windows/Linux) and Cherry Studio custom LevelDB directories from ~/.cherrystudio/config/config.json, supports legacy and array appDataPath formats, candidate directory selection, fallback behavior, and consistent detected-path display.
Renderer UI: Visible Source Filtering
src/renderer/settings/components/ProviderConfigImportDialog.vue
Introduces visibleSources computed property filtering orderedSources to exclude not_found and unsupported_platform statuses, updates template and derived computed values (selectableSourceCount, selectedSourceIds) to use visibleSources.
Localization: 12 Languages Updated
src/renderer/src/i18n/{da-DK,en-US,fa-IR,fr-FR,he-IL,ja-JP,ko-KR,pt-BR,ru-RU,zh-CN,zh-HK,zh-TW}/settings.json
Updates providerImport.entryDescription in all 12 languages to include "CC Switch" in scanned sources list, adds new credential_only_import warning message in all languages describing credential-only import behavior.
Test Infrastructure: Mock SQLite and Setup
test/main/routes/providers/providerImportService.test.ts (lines 8–173)
Establishes in-memory mockSqlite registry backing better-sqlite3-multiple-ciphers query results, adds helpers for creating CC Switch mock databases, writing Desktop override JSON, writing Cherry Studio config, and populating Cherry Studio LevelDB test data. Setup/teardown clears registry and unstubs environment variables.
Test Coverage: CC Switch and Cherry Studio Scenarios
test/main/routes/providers/providerImportService.test.ts (lines 326–1585), test/main/routes/providers/providerRouteHandler.test.ts (line 61)
CC Switch Desktop path discovery tests (Windows HOME fallback, macOS override precedence, invalid/missing override JSON, unregistered DB errors, Codex hiding), CC Switch non-Codex scanning with filtering, mapping to builtin/custom providers with warnings, import with model creation, Cherry Studio custom data directory and fallback tests, LevelDB snapshot reading. Adjusts Hermes and custom provider expectations for updated filtering.
Feature Documentation: Specs, Plans, and Tasks
docs/features/cc-switch-provider-import/{spec,plan,tasks}.md, docs/issues/cc-switch-config-path-discovery/{spec,plan,tasks}.md, docs/issues/cherry-studio-config-path-discovery/{spec,plan,tasks}.md
Comprehensive documentation covering CC Switch provider import implementation steps, compatibility expectations, risk handling, acceptance criteria, user stories, and completed work items for both CC Switch config path discovery and Cherry Studio custom data directory resolution.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

The PR introduces substantial new logic across multiple layers: CC Switch SQLite reading with app-type-specific parsing, a new credentials-only import mode affecting provider application behavior, desktop configuration path discovery for two different providers with platform-specific handling, refactored provider mapping logic with base-URL detection, UI visibility filtering, and extensive test coverage. The changes are heterogeneous, spanning contracts, core service logic, UI/rendering, localization across 12 languages, and test infrastructure with mock databases. While individual sections follow consistent patterns, each layer requires separate reasoning about correctness and interaction with existing code.

Possibly related PRs

  • ThinkInAIXYZ/deepchat#1647: Implements CC Switch provider import in ProviderImportService with the same cc-switch source, credential-only importMode, provider mapping, warning behavior, and matching test coverage.

Poem

🐰 A switch is flipped, the cherry blooms bright,
Desktop paths discovered—no more lost sight!
Credentials flow gently, endpoints stay true,
Deep Chat now imports from many a crew! 🌸

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(providers): discover import paths' directly reflects the main change: discovering custom configuration paths for CC Switch and Cherry Studio imports rather than using hardcoded defaults.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/import-ccswitch
⚔️ Resolve merge conflicts
  • Resolve merge conflict in branch feat/import-ccswitch

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/main/routes/providers/providerImportService.ts (1)

1204-1208: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Align preview selectability with apply-time URL validation.

canSelectCustomProviderWithOptions() only requires a non-empty baseUrl, but hasRequiredCredentials() now rejects custom imports unless that URL is HTTP(S). That makes some providers selectable in the dialog even though apply() can only return skipped for them. Reuse hasHttpBaseUrl() here so scan results and apply behavior stay consistent.

Suggested fix
   private canSelectCustomProviderWithOptions(
     rawProvider: ProviderImportRawProvider,
     mapping: ProviderImportMapping
   ): boolean {
-    return mapping.targetKind === 'custom' && Boolean(rawProvider.baseUrl.trim())
+    return mapping.targetKind === 'custom' && hasHttpBaseUrl(rawProvider.baseUrl)
   }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/main/routes/providers/providerImportService.ts` around lines 1204 - 1208,
canSelectCustomProviderWithOptions currently only checks for a non-empty baseUrl
causing UI selectability to mismatch apply() which uses
hasRequiredCredentials/hasHttpBaseUrl; change canSelectCustomProviderWithOptions
to reuse hasHttpBaseUrl(rawProvider) (instead of
Boolean(rawProvider.baseUrl.trim())) so preview selection matches the HTTP(S)
URL validation used by hasRequiredCredentials and apply().
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/main/routes/providers/providerImportService.ts`:
- Around line 1204-1208: canSelectCustomProviderWithOptions currently only
checks for a non-empty baseUrl causing UI selectability to mismatch apply()
which uses hasRequiredCredentials/hasHttpBaseUrl; change
canSelectCustomProviderWithOptions to reuse hasHttpBaseUrl(rawProvider) (instead
of Boolean(rawProvider.baseUrl.trim())) so preview selection matches the HTTP(S)
URL validation used by hasRequiredCredentials and apply().

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: eb04dc4c-27d0-4dff-9c46-342f5ef7e2cf

📥 Commits

Reviewing files that changed from the base of the PR and between c2e0e08 and 1ec9fd1.

📒 Files selected for processing (27)
  • docs/features/cc-switch-provider-import/plan.md
  • docs/features/cc-switch-provider-import/spec.md
  • docs/features/cc-switch-provider-import/tasks.md
  • docs/issues/cc-switch-config-path-discovery/plan.md
  • docs/issues/cc-switch-config-path-discovery/spec.md
  • docs/issues/cc-switch-config-path-discovery/tasks.md
  • docs/issues/cherry-studio-config-path-discovery/plan.md
  • docs/issues/cherry-studio-config-path-discovery/spec.md
  • docs/issues/cherry-studio-config-path-discovery/tasks.md
  • src/main/routes/providers/providerImportService.ts
  • src/renderer/settings/components/ProviderConfigImportDialog.vue
  • src/renderer/src/i18n/da-DK/settings.json
  • src/renderer/src/i18n/en-US/settings.json
  • src/renderer/src/i18n/fa-IR/settings.json
  • src/renderer/src/i18n/fr-FR/settings.json
  • src/renderer/src/i18n/he-IL/settings.json
  • src/renderer/src/i18n/ja-JP/settings.json
  • src/renderer/src/i18n/ko-KR/settings.json
  • src/renderer/src/i18n/pt-BR/settings.json
  • src/renderer/src/i18n/ru-RU/settings.json
  • src/renderer/src/i18n/zh-CN/settings.json
  • src/renderer/src/i18n/zh-HK/settings.json
  • src/renderer/src/i18n/zh-TW/settings.json
  • src/shared/contracts/routes/providers.routes.ts
  • src/shared/providerImport.ts
  • test/main/routes/providers/providerImportService.test.ts
  • test/main/routes/providers/providerRouteHandler.test.ts

@zerob13 zerob13 merged commit 446564c into dev May 21, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant