Skip to content

Multi-Provider AI Unification & UX Overhaul - #39

Open
kkbin505 wants to merge 7 commits into
ArtifexSoftware:masterfrom
kkbin505:feat-ai-webview-render
Open

Multi-Provider AI Unification & UX Overhaul#39
kkbin505 wants to merge 7 commits into
ArtifexSoftware:masterfrom
kkbin505:feat-ai-webview-render

Conversation

@kkbin505

Copy link
Copy Markdown

Description

This PR unifies the AI integration architecture, enabling seamless switching between major AI providers without credential re-entry. It also polishes the AI Assistant's interactive flow for a more "frictionless" reading experience.

Key Changes

1. Smart Credential Management

  • The "Multi-Key" System: Users can now store API keys for OpenAI, Anthropic, Google Gemini, DeepSeek, and Alibaba Qwen simultaneously.
  • Auto-Routing: The app automatically selects the correct key based on the active Model ID and Base URL.

2. Redesigned AI Settings Dialog

  • Replaced the single-key field with a secure multi-provider input grid.
  • Added 12 Presets covering the most popular models, making it one-click to switch from a reasoning model (like DeepSeek R1) to a fast model (like GPT-4o-mini).

3. Core Engine Upgrades (AiClient)

  • Claude Native Support: Added specialized protocol handling for Anthropic's unique API structure.
  • Filtering Logic: Implemented strict JSON null-check to prevent "null" string accumulation in the UI during model reasoning phases.
  • Reliability: Increased timeouts to 60s to accommodate the slower initial response times of reasoning-heavy models.

4. Interaction Flow (心流优化)

  • Automatic State Recovery: Closing the AI panel now automatically deactivates AI mode, allowing the user to resume reading and page-turning instantly.
  • Precise Error Reporting: If a key is missing, the app now specifies which provider's key needs to be set.

Testing Performed

  • Verified successful streaming from DeepSeek V3, Qwen 2.5, Claude 3.5, and Gemini 2.5.
  • Verified automatic AI mode deactivation on panel close.
  • Build verified on Windows/Android environment (BUILD SUCCESSFUL).

kkbin505 and others added 7 commits May 9, 2026 09:56
Add two major feature areas on top of the MuPDF Android viewer base.

### E-ink Screen Optimizations

- Add `setAnimationsEnabled(bool)` to ReaderView: when disabled, scroll
  duration drops from 400 ms to 1 ms and drag scrolling is suppressed,
  eliminating ghosting on e-ink panels.
- Add `setEinkRefreshEnabled(bool)` to ReaderView: posts an invalidate()
  after each page settlement to trigger a full-screen refresh cycle.
- Fling gestures now jump directly to the next/previous page instead of
  smooth-scrolling when animations are off.
- Add a Settings button (wrench icon) to the top bar with a popup menu
  for toggling animations, e-ink refresh, and setting the OpenAI API key.
  All settings are persisted via SharedPreferences.

### AI-Assisted Reading

- Add AiDocumentActivity (extends DocumentActivity) that overlays a
  Jetpack Compose UI onto the existing PDF reader without replacing it.
- Add IonizationOverlay: a full-screen Canvas gesture layer that detects
  free-form draw gestures and fires a vibration + AI request on release.
- Add OpenAiClient: streams chat completions from the OpenAI API over SSE
  using OkHttp. The system prompt produces two structured sections —
  an AI Explanation and an Atomic Note (core concept / key insight /
  connections).
- Add AiPanel: a bottom sheet built in Compose that slides up and renders
  the streaming response token-by-token in real time.
- Expose MuPDFCore.getPageText() to extract structured text from the
  current page via MuPDF's StructuredText API for use as AI context.
- Add SecurePreferences: stores the OpenAI API key in
  EncryptedSharedPreferences (AES256-GCM) so the key is never stored
  in plain text.
- Add ObsidianExporter: saves AI responses as Markdown files under
  Documents/ObsidianVault/Atoms/ with #atom #atomread tags for
  integration with Obsidian.
- Add AtomReadActivity registered as an alternate PDF intent handler
  (application/pdf MIME), combining the PDF viewer with the AI overlay.
- Add BondingView: prototype Compose component for visually linking
  atomic notes via drag-and-drop collision (not yet wired to main flow).
…ocument viewing ,DeepSeek V3/R1 和 GPT 4.1/5.4 Mini 支持
## Body
- **Multi-Key Secure Storage**: Refactored `SecurePreferences` to support 5 independent API key slots (OpenAI, DeepSeek, Qwen, Anthropic, Gemini) with smart auto-routing based on model/URL.
- **Enhanced AI Settings**: Redesigned the settings dialog with a secure multi-input layout and 12 "Quick Presets" for instant configuration of top-tier models (GPT-4o, Claude 3.5, Gemini 2.0, DeepSeek R1, etc.).
- **Unified AiClient**:
    - Native support for Anthropic Messages API (Claude).
    - Robust streaming parser for OpenAI-compatible providers.
    - Improved stability with 60s timeouts and null-chunk filtering (fixed "nullnullnull" output).
- **UX Polishing**:
    - Automatic exit from AI mode upon closing the assistant panel to restore page-turning.
    - Context-aware error messages identifying which specific API key is missing.
    - Removed redundant reasoning/thinking blocks for a cleaner user experience.

## Footer
Co-authored-by: Antigravity <antigravity@google.com>
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