Skip to content

Conversation

Copy link

Copilot AI commented Nov 1, 2025

Ports 70 files (5,920 insertions, 1,633 deletions) from upstream Electron app's src/renderer/src/aiCore to React Native app's src/aiCore, covering last 100 commits through 28bc89ac7ccd9acf502f9e564848ed1530a7b373.

Changes

New Files (16)

  • Middleware: openrouterGenerateImageMiddleware, qwenThinkingMiddleware, toolChoiceMiddleware
  • Clients: AWS Bedrock, Anthropic Vertex, Cherry AI, OVMS, Vertex
  • Tools: Knowledge search, telemetry plugin, tracing adapter
  • Tests: API client factory, compatibility types

Modified Files (54)

  • Enhanced chunk processing with AISDKError handling and improved tool call image extraction
  • Updated reasoning effort calculations for Claude 4.5, Qwen3, Grok, Gemini models
  • Extended provider support (HuggingFace, Mistral, Perplexity, GitHub Copilot)
  • Refined parameter builders, message converters, file processors

Import Transformations

All files transformed for React Native:

@renderer/**              → @/**
@logger                   → @/services/LoggerService  
@shared/config/constant   → @/constants
@shared/anthropic         → @/aiCore/provider/config/anthropic
@shared/utils             → @/utils

Known Issues

~80 lint errors, ~200 type errors expected due to missing React Native equivalents for Electron-specific code:

  • Services: KnowledgeService, SpanManagerService, FileManager
  • Hooks: useAwsBedrock, useVertexAI, useLMStudio
  • Packages: @cherrystudio/openai, @anthropic-ai/vertex-sdk, various AI SDK providers
  • Electron APIs: window.api.*, window.keyv.* need React Native bridge equivalents

See PORTING_SUMMARY.md for complete breakdown and required follow-up work.

State file .github/port-bot-state updated with upstream commit hash for future incremental ports.

Original prompt

TASK: Port ALL code changes from upstream CherryHQ/cherry-studio's src/renderer/src/aiCore to this repo's src/aiCore directory.

IMPORTANT: This is NOT just creating a tracking file. You MUST apply ALL actual code changes from upstream.

Source: https://github.com/CherryHQ/cherry-studio
Last ported: HEAD~10
New commits: 0
Context: React Native/Expo app (target) ← Electron desktop app (source)

MANDATORY STEPS - DO ALL OF THESE:

  1. Fetch and analyze upstream changes:

    git clone https://github.com/CherryHQ/cherry-studio.git /tmp/upstream
    cd /tmp/upstream
    git diff HEAD~100..HEAD -- src/renderer/src/aiCore > /tmp/changes.patch
  2. Review the patch - identify all changed files, additions, deletions, modifications

  3. Apply changes to src/aiCore/ with transformations:

    Path transformations:

    • Source path: src/renderer/src/aiCore/foo.ts
    • Target path: src/aiCore/foo.ts

    Import transformations (use ast-grep):

    # MUST run these on ALL modified files:
    cd /home/runner/work/cherry-studio-app/cherry-studio-app
    
    # @renderer/** → @/**
    sg --pattern 'import $$$ from "@renderer/$$REST"' \
       --rewrite 'import $$$ from "@/$$REST"' \
       -i 'src/aiCore/**/*.ts' 'src/aiCore/**/*.tsx'
    
    # import type from @renderer
    sg --pattern 'import type $$$ from "@renderer/$$REST"' \
       --rewrite 'import type $$$ from "@/$$REST"' \
       -i 'src/aiCore/**/*.ts' 'src/aiCore/**/*.tsx'
    
    # @logger → @/services/LoggerService
    sg --pattern 'import $$$ from "@logger"' \
       --rewrite 'import $$$ from "@/services/LoggerService"' \
       -i 'src/aiCore/**/*.ts' 'src/aiCore/**/*.tsx'

    Code adaptations:

    • Remove import { ipcRenderer } from 'electron'
    • Replace import fs from 'fs' with import * as FileSystem from 'expo-file-system'
    • Replace import path from 'path' with path string manipulation
    • Make all file operations async/await
  4. Handle conflicts manually:

    • If upstream adds new Node.js APIs → replace with Expo equivalents
    • If upstream adds Electron IPC → remove or adapt to RN bridge
    • Compare upstream changes line-by-line with existing code
  5. Run quality checks:

    yarn format
    yarn lint --fix
    yarn typecheck
  6. Update state file:

    echo "dc06c103e0e1ea93c66fec586df665a6c4a42194" > .github/port-bot-state
  7. Create comprehensive PR with:

    • List of all upstream commits ported
    • All file changes made
    • Import transformations applied
    • Electron→RN adaptations made

VERIFICATION CHECKLIST - confirm ALL before creating PR:

  • Applied EVERY changed file from upstream (not just created state file)
  • Transformed ALL @Renderer imports to @/
  • Replaced ALL Node.js APIs with Expo equivalents
  • Removed ALL Electron APIs (ipcRenderer, etc)
  • yarn lint passes
  • yarn typecheck passes
  • .github/port-bot-state updated with latest commit

DON'T:

  • ❌ Only create tracking file without porting code
  • ❌ Skip any upstream changes
  • ❌ Leave @Renderer imports unchanged
  • ❌ Leave Node.js/Electron APIs in code
  • ❌ Modify .github/workflows/

Tools available: sg (ast-grep) for AST-based transformations


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Port code changes from upstream CherryHQ/cherry-studio to src/aiCore Port aiCore changes from upstream cherry-studio (HEAD~100..28bc89ac) Nov 1, 2025
Copilot AI requested a review from DeJeune November 1, 2025 16:31
- Upgrade AI SDK packages to latest versions and add new providers (Google Vertex, HuggingFace, Mistral, Perplexity)
- Replace OpenAI package with @cherrystudio/openai and add GitHub Copilot integration
- Add React Native crypto packages (react-native-crypto, react-native-quick-crypto, react-native-quick-base64)
- Remove unsupported providers (CherryAI, OVMS) and disable telemetry/tracing features
- Update file handling to use Expo FileSystem API instead of Electron IPC
- Fix ESLint configuration to support TypeScript function overloading
- Add integration directory to Prettier ignore list
- Import react-native-quick-crypto for cryptographic functionality
- Set global.crypto synchronously for Node.js-style require support
- Maintain existing structuredClone and async polyfill setup
…Copilot

- Implement AWS Bedrock settings component with region, access key ID, and secret access key fields
- Add VertexAI settings component for project ID, location, client email, and private key configuration
- Create GitHub Copilot authentication flow with device code verification and user info display
- Integrate provider-specific settings into API service screen based on provider type
- Convert `useAwsBedrock` and `useVertexAI` hooks into `AwsBedrockService` and `VertexAIService` singleton classes
- Update settings components to use service methods instead of hook imports
- Replace hook usage in API service screen with service class methods
- Maintain identical functionality while improving code organization
- Move AWS Bedrock credential logic from hooks to AwsBedrockService with async loading
- Refactor Vertex AI configuration to use VertexAIService with async credential loading
- Update provider config to handle async credential loading for special providers
- Add prepareSpecialProviderConfig for runtime credential injection
- Fix package.json typo in expo-secure-store dependency name
- Implement KeyValueService using MMKV storage for React Native
- Remove LMStudio keep-alive and Redux state dependencies in BaseApiClient
- Clean up unused constructors and commented AnthropicVertexClient code
- Update Vertex API host formatting to work without Redux store
…ntations

- Delete obsolete ApiClientFactory test files that were testing deprecated client factory logic
- Replace Electron-specific Vertex AI auth with React Native JWT-based service account authentication
- Remove Electron store dependencies and use mobile-compatible key-value service for API key rotation
- Add Google Cloud auth utility for generating OAuth tokens from service account credentials
- Add buffer polyfill to Metro config for Node.js compatibility
- Extend API key configuration exclusion to include VertexAI providers
- Maintain existing exclusions for Copilot and AWS Bedrock providers
@DeJeune DeJeune marked this pull request as ready for review November 2, 2025 16:04
- Add `usesNonExemptEncryption: false` to iOS config for App Store compliance
- Configure expo-secure-store with Android backup and Face ID permission
- Pin expo-secure-store version to ~15.0.7 for stability
- Remove unused crypto polyfill from polyfills.js
…lasses

- Replace direct SecureStore imports with lazy loading to prevent early native module access
- Convert service classes to singleton pattern with private constructors and getInstance methods
- Update all SecureStore method calls to use the lazy-loaded instance
- Maintain existing functionality while improving initialization safety
- Replace direct service calls with custom hooks for AWS Bedrock, Vertex AI, and Copilot token management
- Add loading states and disable save buttons during async operations
- Move SecureStore operations to dedicated useSecureStorage hook for lazy loading
- Update services to focus on business logic while hooks handle storage
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.

2 participants