Skip to content

chore: add scaffoldings for Apple foundational model#48

Merged
EggerMarc merged 5 commits into
mainfrom
feat/applefm-provider
Jun 6, 2026
Merged

chore: add scaffoldings for Apple foundational model#48
EggerMarc merged 5 commits into
mainfrom
feat/applefm-provider

Conversation

@EggerMarc

@EggerMarc EggerMarc commented Jun 6, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features
    • Added support for querying Apple on-device foundation model availability on compatible systems.
    • Introduced optional applefm feature for Apple foundation model integration.
    • Added example tool to check model availability on your machine.

@coderabbitai

coderabbitai Bot commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@EggerMarc, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 18 minutes and 58 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3dd7492c-19b3-416e-84c7-8cbeca178d4f

📥 Commits

Reviewing files that changed from the base of the PR and between b92c436 and cad7e58.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (22)
  • Cargo.toml
  • build.rs
  • examples/applefm/completion.rs
  • examples/applefm/stream.rs
  • providers/AGENTS.md
  • providers/applefm/Cargo.toml
  • providers/applefm/bridge/Sources/AppleFMBridge/Complete.swift
  • providers/applefm/bridge/Sources/AppleFMBridge/Exports.swift
  • providers/applefm/bridge/Sources/AppleFMBridge/Session.swift
  • providers/applefm/bridge/Sources/AppleFMBridge/Stream.swift
  • providers/applefm/bridge/Sources/AppleFMBridge/WireTypes.swift
  • providers/applefm/build.rs
  • providers/applefm/src/api/completion.rs
  • providers/applefm/src/api/mod.rs
  • providers/applefm/src/api/stream.rs
  • providers/applefm/src/api/types/mod.rs
  • providers/applefm/src/api/types/request.rs
  • providers/applefm/src/api/types/response.rs
  • providers/applefm/src/builder.rs
  • providers/applefm/src/client.rs
  • providers/applefm/src/ffi.rs
  • providers/applefm/src/lib.rs
📝 Walkthrough

Walkthrough

This PR introduces an applefm provider crate for querying Apple on-device foundation model availability. It includes a Swift bridge compiled on macOS, Rust FFI bindings, a build script for conditional compilation, a public Rust API, feature-gated integration into the main crate, and an example demonstrating usage.

Changes

Apple Foundation Model Availability Feature

Layer / File(s) Summary
Workspace setup and crate metadata
Cargo.toml, providers/applefm/Cargo.toml
Register providers/applefm as a workspace member, add chat-applefm as an optional dependency, introduce the applefm Cargo feature, and define the new crate's package metadata with serde/serde_json dependencies.
Swift bridge for availability queries
providers/applefm/bridge/Package.swift, providers/applefm/bridge/Sources/AppleFMBridge/Exports.swift
Create the AppleFMBridge Swift package with afm_availability() and afm_string_free() C-ABI entry points; implement availabilityJSON() that conditionally queries FoundationModels and encodes availability status with explanatory reasons as JSON.
Build script: Swift compilation and linking
providers/applefm/build.rs
Implement conditional Swift bridge compilation and linking on macOS via swift build, emit linker directives for the static library and Swift runtime paths, weak-link FoundationModels for compatibility, and set the applefm_bridge cfg to control code paths.
Rust FFI wrapper and public availability API
providers/applefm/src/ffi.rs, providers/applefm/src/lib.rs
Create ffi.rs with real FFI bindings (when applefm_bridge enabled) and a stub fallback; implement lib.rs with the Availability struct and availability() function that queries the bridge JSON and deserializes into a structured result.
Integration into main crate
src/lib.rs
Add the applefm module re-exporting chat_applefm symbols behind the #[cfg(feature = "applefm")] guard; extend the prelude with the same feature-gated export.
Example and development setup
Cargo.toml, examples/applefm/availability.rs, .gitignore
Register the applefm-availability example target with feature gating; implement the example calling availability() and reporting results with appropriate exit codes; update .gitignore to exclude /target, /example-data, .DS_Store, .env, and .build/.

Sequence Diagram

sequenceDiagram
  participant Caller as Example (main)
  participant API as chat_rs::applefm::availability()
  participant FFI as ffi::availability_json()
  participant Bridge as Swift: afm_availability()
  participant Models as FoundationModels
  Caller->>API: availability()
  API->>FFI: availability_json()
  alt applefm_bridge enabled (macOS)
    FFI->>Bridge: FFI call
    Bridge->>Models: query FoundationModels
    Models-->>Bridge: available or error reason
    Bridge-->>FFI: JSON char* (allocated)
    FFI->>FFI: convert and free
    FFI-->>API: JSON String
  else applefm_bridge disabled or non-macOS
    FFI-->>API: static stub JSON
  end
  API->>API: serde_json::from_str
  API-->>Caller: Availability { available, reason }
  Caller->>Caller: print AVAILABLE or UNAVAILABLE
Loading

🎯 3 (Moderate) | ⏱️ ~20 minutes

🐰 A swift bridge now hops through the meadow,
Querying models with queries so mellow,
From Swift to Rust, JSON flows free,
Availability dances for all to see! 🌟

🚥 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 accurately summarizes the main change: adding foundational scaffolding for Apple foundation model support, which is reflected across all file changes.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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 unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/applefm-provider

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.

@EggerMarc EggerMarc marked this pull request as draft June 6, 2026 12:24

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

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

⚠️ Outside diff range comments (1)
providers/applefm/Cargo.toml (1)

1-14: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Add required provider feature contract (default + stream).

The crate is missing the required default = [] and stream feature wiring (chat-core/stream, dep:async-stream, dep:futures), which breaks workspace-wide feature consistency.

Suggested features block
+[features]
+default = []
+stream = ["chat-core/stream", "dep:async-stream", "dep:futures"]

As per coding guidelines, "Provider crate Cargo.toml must define a stream feature that enables the stream feature in chat-core, includes optional dependencies on async-stream and futures, and defaults to an empty feature set."

🤖 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 `@providers/applefm/Cargo.toml` around lines 1 - 14, Add a features section to
the Cargo.toml that sets default = [] and defines a stream feature that enables
the chat-core "stream" feature and makes async-stream and futures optional
dependencies for this crate; update the [dependencies] block to mark
async-stream and futures as optional (and referenced by the stream feature) so
the stream feature toggles chat-core/stream plus the optional deps (symbols:
Cargo.toml, feature name "stream", default = [], dependency names "async-stream"
and "futures", and enabling "chat-core/stream").

Sources: Coding guidelines, Learnings

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

Inline comments:
In `@Cargo.toml`:
- Around line 120-122: The root Cargo.toml's "stream" feature list is missing
the conditional propagation for the AppleFM provider; update the stream array to
include "chat-applefm?/stream" so that enabling --features stream,applefm also
enables the provider's stream feature; specifically modify the stream feature
declaration (the entry containing "chat-core/stream",
"chat-completions?/stream", ... ) to add "chat-applefm?/stream" alongside the
other conditional provider entries.

In `@providers/applefm/Cargo.toml`:
- Around line 11-13: The Cargo.toml dependencies block is missing required
provider crates; update the [dependencies] section (where serde.workspace and
serde_json.workspace are declared) to add chat-core, transport-reqwest,
async-trait, tools-rs, and schemars, and also add optional/feature-gated
streaming deps futures and async-stream (mark them optional or behind a
"streaming" feature if your repo uses features); ensure versions match workspace
conventions or use workspace = true where appropriate and keep serde/serde_json
as currently declared.

---

Outside diff comments:
In `@providers/applefm/Cargo.toml`:
- Around line 1-14: Add a features section to the Cargo.toml that sets default =
[] and defines a stream feature that enables the chat-core "stream" feature and
makes async-stream and futures optional dependencies for this crate; update the
[dependencies] block to mark async-stream and futures as optional (and
referenced by the stream feature) so the stream feature toggles chat-core/stream
plus the optional deps (symbols: Cargo.toml, feature name "stream", default =
[], dependency names "async-stream" and "futures", and enabling
"chat-core/stream").
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 424c38b1-6125-4324-8d83-05b2fb5b108f

📥 Commits

Reviewing files that changed from the base of the PR and between 3ca7d2c and b92c436.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (10)
  • .gitignore
  • Cargo.toml
  • examples/applefm/availability.rs
  • providers/applefm/Cargo.toml
  • providers/applefm/bridge/Package.swift
  • providers/applefm/bridge/Sources/AppleFMBridge/Exports.swift
  • providers/applefm/build.rs
  • providers/applefm/src/ffi.rs
  • providers/applefm/src/lib.rs
  • src/lib.rs

Comment thread Cargo.toml Outdated
Comment thread providers/applefm/Cargo.toml Outdated
@EggerMarc EggerMarc marked this pull request as ready for review June 6, 2026 13:05
@EggerMarc

Copy link
Copy Markdown
Owner Author

@CodeRabbit review

@coderabbitai

coderabbitai Bot commented Jun 6, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@EggerMarc EggerMarc merged commit c25e82a into main Jun 6, 2026
3 of 4 checks passed
@EggerMarc EggerMarc deleted the feat/applefm-provider branch June 6, 2026 13:13
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