Skip to content

feat: integrate built-in AI provider support#16

Merged
CoolSpring8 merged 6 commits into
mainfrom
built-in-ai
Nov 23, 2025
Merged

feat: integrate built-in AI provider support#16
CoolSpring8 merged 6 commits into
mainfrom
built-in-ai

Conversation

@CoolSpring8
Copy link
Copy Markdown
Owner

@CoolSpring8 CoolSpring8 commented Nov 22, 2025

  • Added support for a new built-in AI provider, allowing users to select between OpenAI-compatible and built-in AI options.
  • Updated the App component to manage provider selection and model handling accordingly.
  • Enhanced the SettingsModal to include provider selection and adjusted form handling based on the selected provider.
  • Updated README with configuration instructions for the new built-in AI provider.
  • Refactored components to accommodate the new provider logic and ensure seamless user experience.

Summary by CodeRabbit

  • New Features
    • Dual-provider system: choose OpenAI-Compatible API or Built-in AI (Chrome/Edge).
    • Provider selection persisted and available in Settings with provider-specific UI.
    • Built-in AI auto-checks availability, shows download progress, and can download models.
    • OpenAI inputs (API key, base URL) shown only for OpenAI-Compatible provider.
    • UI adapts: model selector, status text, and predict controls reflect provider and availability.
    • Predict control is disabled with a clear reason when the current provider or model is unavailable.

✏️ Tip: You can customize this high-level summary in your review settings.

- Added support for a new built-in AI provider, allowing users to select between OpenAI-compatible and built-in AI options.
- Updated the App component to manage provider selection and model handling accordingly.
- Enhanced the SettingsModal to include provider selection and adjusted form handling based on the selected provider.
- Updated README with configuration instructions for the new built-in AI provider.
- Refactored components to accommodate the new provider logic and ensure seamless user experience.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Nov 22, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Adds a selectable provider model: either OpenAI-Compatible (API-based, model sync) or Built-in AI (no API key, automatic availability/download). Updates app state, settings, UI props, routing, and runtime checks to handle provider-specific flows and built-in download/availability lifecycle.

Changes

Cohort / File(s) Summary
Type Definitions
src/types.ts
Added ProviderKind (`"openai-compatible"
Dependencies
package.json
Added dependency @built-in-ai/core ^2.0.1.
Core Application Logic
src/App.tsx
Introduced providerKind state and persistence, built-in availability state and helpers, provider-aware model sync and request routing, provider-specific validations, and updated settings load/save to include providerKind.
Header UI
src/components/Header.tsx
Added props modelSelectorDisabled?: boolean, modelPlaceholder?: string, modelStatus?: string; conditionally render model selector or non-interactive status display.
Settings Modal
src/components/SettingsModal.tsx
Added providerKind form field and props (builtInAvailability, onBuiltInAvailabilityChange); UI now selects OpenAI-Compatible vs Built-in, includes built-in availability checks, download workflow, progress/error state, and conditional OpenAI inputs; emits providerKind on save.
Text Completion UI
src/components/TextCompletionView.tsx
Added props isPredictDisabled?: boolean and disabledReason?: string; Predict button disables and shows reason when provided.
Docs
README.md
Updated setup and user flow to describe OpenAI-Compatible vs Built-in AI choices, required inputs, and built-in model download/status behavior.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant App
    participant Settings
    participant OpenAI as OpenAI-Compatible
    participant BuiltIn as Built-in AI

    User->>Settings: open settings
    Settings->>User: show provider choice
    User->>Settings: select provider & save
    Settings->>App: set providerKind

    alt provider == openai-compatible
        App->>OpenAI: syncModels (if configured)
        OpenAI-->>App: model list
        App->>User: enable model selector
    else provider == built-in
        App->>BuiltIn: check availability
        BuiltIn-->>App: status (downloadable/downloading/available)
        App->>User: show built-in status & progress
    end

    User->>App: send text / predict
    alt provider == openai-compatible
        App->>OpenAI: request with API key & model
        OpenAI-->>App: response
    else provider == built-in
        App->>BuiltIn: local call (requires available)
        BuiltIn-->>App: response or error
    end

    App->>User: display result or error
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • Review src/App.tsx for providerKind persistence, branching in send/predict flows, and syncModels early-exit.
  • Check src/components/SettingsModal.tsx built-in download/check lifecycle, progress/error handling, and form validation.
  • Verify new props and defaults in src/components/Header.tsx and src/components/TextCompletionView.tsx are wired and used consistently.

Possibly related PRs

Suggested labels

codex

Poem

🐰 I hopped into settings, two paths in view,
One speaks with keys, the other downloads anew.
I twitch my whiskers at progress bars that gleam,
Syncs or local models — a rabbit's small dream.
Hooray for choices, code, and a download stream.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely summarizes the main change—integrating built-in AI provider support—which is reflected throughout the changeset in new types, provider selection logic, settings management, and UI components.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch built-in-ai

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6953db1 and 2d3bc51.

📒 Files selected for processing (2)
  • src/App.tsx (15 hunks)
  • src/components/SettingsModal.tsx (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src/App.tsx (1)
src/types.ts (2)
  • ProviderKind (21-21)
  • BuiltInAvailability (23-28)
src/components/SettingsModal.tsx (1)
src/types.ts (2)
  • ProviderKind (21-21)
  • BuiltInAvailability (23-28)
🔇 Additional comments (1)
src/App.tsx (1)

307-311: Consistent enforcement that built‑in AI is chat‑only

You’ve layered the “chat only” constraint for built‑in AI in three places:

  • An effect that toasts when view === "text" and providerKind === "built-in",
  • A guard in handleTextPredict that early‑returns with a toast when providerKind !== "openai-compatible", and
  • TextCompletionView props isPredictDisabled / disabledReason derived from providerKind.

This gives both UX feedback and hard guards against misusing the built‑in provider for text completion. The redundancy here is appropriate and keeps the invariants strong.

Also applies to: 445-452, 786-791


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

Copy link
Copy Markdown

@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.

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/components/Header.tsx (1)

8-10: Model selector/status UX for provider switching is well‑structured

The modelSelectorDisabled, modelPlaceholder, and modelStatus props cleanly separate the “selectable list” vs “status display” modes, and the conditional rendering around the Select is straightforward. You might optionally consider adding role="status" (and possibly aria-live) to the status <div> to improve screen‑reader feedback, but functionally this looks solid.

Also applies to: 33-35, 46-63

src/App.tsx (1)

117-120: Provider‑specific routing for chat vs text is consistent; consider a minor UX tweak

  • syncModels early‑returns when providerKind !== "openai-compatible", and the header’s modelSelectorDisabled mirrors that, so models are only fetched/used for the OpenAI‑compatible path.
  • handleTextPredict, the view === "text" && providerKind === "built-in" toast, and the TextCompletionView props (isPredictDisabled/disabledReason) all consistently enforce “built‑in supports chat only”.
  • handleSend routes correctly between OpenAI and built‑in by using usingOpenAI and conditionally calling ensureBuiltInModelReady.

If you want to reduce user friction further, you could optionally disable or hide the “Text” view in the header when providerKind === "built-in" instead of allowing selection then showing an error toast.

Also applies to: 160-160, 326-331, 468-471, 520-534, 559-562, 673-680, 802-810, 822-822

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d256b7e and d5ca0c9.

⛔ Files ignored due to path filters (1)
  • bun.lock is excluded by !**/*.lock
📒 Files selected for processing (7)
  • README.md (1 hunks)
  • package.json (1 hunks)
  • src/App.tsx (16 hunks)
  • src/components/Header.tsx (3 hunks)
  • src/components/SettingsModal.tsx (3 hunks)
  • src/components/TextCompletionView.tsx (3 hunks)
  • src/types.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src/components/SettingsModal.tsx (1)
src/types.ts (1)
  • ProviderKind (21-21)
src/App.tsx (1)
src/types.ts (1)
  • ProviderKind (21-21)
🪛 markdownlint-cli2 (0.18.1)
README.md

15-15: Hard tabs
Column: 1

(MD010, no-hard-tabs)


16-16: Hard tabs
Column: 1

(MD010, no-hard-tabs)

🔇 Additional comments (5)
package.json (1)

15-15: Built-in AI core dependency wiring looks consistent

The added @built-in-ai/core dependency aligns with its usage in src/App.tsx and the new providerKind flow; no issues from this file alone.

src/types.ts (1)

20-21: ProviderKind union type is clear and future‑proof

The "openai-compatible" | "built-in" union is a good, explicit discriminant for provider-specific logic and keeps call sites type-safe.

src/components/TextCompletionView.tsx (1)

6-7: Predict button disable behavior is correctly integrated

isPredictDisabled with a default of false, combined with disabledReason mapped to title, cleanly gates the Predict action while still allowing Stop when generating. No issues here.

Also applies to: 16-17, 45-47

src/components/SettingsModal.tsx (1)

1-8: Provider‑aware settings flow is correctly wired

  • Including providerKind in SettingsFormValues and default/reset values keeps the modal in sync with app state.
  • The provider <Select> plus watch("providerKind") and conditional rendering of base URL/API key and “Sync from API” only for "openai-compatible" behaves as expected.
  • Validation rules tied to selectedProvider === "openai-compatible" avoid forcing credentials when using the built‑in provider.

Overall, the modal’s new provider logic looks consistent and safe.

Also applies to: 11-17, 23-27, 33-47, 61-75, 76-108

src/App.tsx (1)

1-1: Built‑in AI lifecycle and providerKind persistence look robust

The new providerKind state, providerKindKey persistence, builtInStatus (with progress), and builtInModelRef combined with ensureBuiltInModelReady give a clear, fault‑tolerant path for using the built‑in model. Availability checks, progress updates, and error toasts are all handled, and resetting builtInStatus when switching back to the OpenAI‑compatible provider avoids stale UI. No correctness issues stand out here.

Also applies to: 29-50, 60-80, 164-167, 191-196, 197-212

Comment thread README.md Outdated
- Refactored the App component to replace built-in model status management with a new BuiltInAvailability type.
- Enhanced the SettingsModal to include download progress and error handling for the built-in AI model.
- Updated the logic for checking and downloading the built-in model, improving user feedback during the process.
- Adjusted the integration of built-in AI provider to streamline availability checks and model readiness.
- Adjusted formatting for the provider selection instructions to enhance readability.
- Ensured consistent indentation for better visual structure in the documentation.
@CoolSpring8
Copy link
Copy Markdown
Owner Author

@codex review

Copy link
Copy Markdown

@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.

Actionable comments posted: 3

♻️ Duplicate comments (1)
README.md (1)

14-16: Hard tabs violation on lines 15-16 already flagged in previous review

This issue was already identified in a previous review. Lines 15-16 contain leading tab characters that violate the no-hard-tabs markdownlint rule (MD010). Replace the leading tabs with spaces.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d5ca0c9 and 6953db1.

📒 Files selected for processing (4)
  • README.md (1 hunks)
  • src/App.tsx (16 hunks)
  • src/components/SettingsModal.tsx (3 hunks)
  • src/types.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src/App.tsx (1)
src/types.ts (2)
  • ProviderKind (21-21)
  • BuiltInAvailability (23-28)
src/components/SettingsModal.tsx (1)
src/types.ts (2)
  • ProviderKind (21-21)
  • BuiltInAvailability (23-28)
🔇 Additional comments (7)
src/types.ts (1)

21-28: LGTM! Clean type definitions for the dual-provider model

The new ProviderKind and BuiltInAvailability types are well-defined and appropriately model the state space for the built-in AI integration.

src/components/SettingsModal.tsx (2)

98-157: LGTM! Comprehensive built-in model download flow with proper error handling

The handleDownloadModel function correctly handles all availability states, provides progress feedback, and includes proper cleanup in the finally block. The guard conditions prevent invalid state transitions.


214-296: Well-structured provider-specific UI branching

The conditional rendering based on selectedProvider cleanly separates OpenAI-Compatible inputs from Built-in AI status/download UI. The form validation correctly applies required only when the OpenAI-Compatible provider is selected.

src/App.tsx (4)

124-126: Correct early-exit for non-OpenAI providers

The guard prevents unnecessary model syncing when using the built-in provider, aligning with the dual-provider design.


206-210: Good: Clear active model when switching to built-in provider

This effect correctly resets the active model when switching to built-in, since built-in AI doesn't use the model list.


519-532: Provider-specific validation is clear and comprehensive

The conditional validation for OpenAI vs. built-in providers is well-structured, with descriptive error messages for each failure mode.


638-652: Settings persistence and provider-specific behavior handled correctly

The save handler properly persists providerKind, then triggers the appropriate behavior: syncing models for OpenAI-Compatible or clearing the active model for built-in.

Comment thread src/App.tsx Outdated
Comment thread src/components/SettingsModal.tsx Outdated
Comment thread src/components/SettingsModal.tsx Outdated
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/App.tsx Outdated
…Modal

- Removed the normalizeAvailability function from both App and SettingsModal components.
- Updated built-in availability handling to directly cast the availability response to BuiltInAvailability type.
- Streamlined the logic for setting built-in availability, enhancing code clarity and maintainability.
…ngsModal

- Updated the logic for checking built-in availability to ensure it only triggers when the selected provider is "built-in" and the availability status is "unknown".
- Enhanced dependency array in useEffect hooks for better performance and clarity.
…to OpenAI

- Introduced a new `force` parameter to bypass the provider compatibility check for "openai-compatible".
- Updated the logic in the App component to utilize the `force` option when setting the active model, enhancing flexibility in provider management.
@CoolSpring8 CoolSpring8 merged commit 26aa4a5 into main Nov 23, 2025
1 check passed
@CoolSpring8 CoolSpring8 deleted the built-in-ai branch November 23, 2025 01:57
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