Skip to content

Allow Foundation Models to use other models#1529

Merged
cyanzhong merged 1 commit into
mainfrom
develop
Jul 6, 2026
Merged

Allow Foundation Models to use other models#1529
cyanzhong merged 1 commit into
mainfrom
develop

Conversation

@cyanzhong

@cyanzhong cyanzhong commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Be prepared to support "Private Cloud Compute" model. This will not be functional until we migrate to Xcode 27.

Copilot AI 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.

Pull request overview

This PR updates the Foundation Models bridge (JS ↔ native Swift) to carry an explicit modelName so the editor can route requests to different underlying models in the future (e.g., “Private Cloud Compute”).

Changes:

  • Extend the native Foundation Models protocol/bridge to accept modelName for availability checks and session creation.
  • Update the CoreEditor TypeScript native module interface and languageModel() API to pass a selected model name through to native.
  • Add native-side model selection plumbing (createModel(named:)) to map modelName to a SystemLanguageModel.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 5 comments.

File Description
MarkEditKit/Sources/Bridge/Native/Modules/EditorModuleFoundationModels.swift Adds modelName plumbing and model selection helper for macOS 26 FoundationModels usage.
MarkEditKit/Sources/Bridge/Native/Generated/NativeModuleFoundationModels.swift Updates generated native bridge decoding/routing to pass modelName.
CoreEditor/src/bridge/native/foundationModels.ts Updates TS bridge interface signatures to include modelName.
CoreEditor/src/api/languageModel.ts Updates public languageModel() API to require a model name and forwards it to native.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread MarkEditKit/Sources/Bridge/Native/Modules/EditorModuleFoundationModels.swift Outdated
Comment thread CoreEditor/src/bridge/native/foundationModels.ts
Comment thread CoreEditor/src/api/languageModel.ts Outdated
@cyanzhong cyanzhong force-pushed the develop branch 2 times, most recently from 7462ce9 to 6678d74 Compare July 5, 2026 13:28
@cyanzhong

Copy link
Copy Markdown
Contributor Author

@copilot Review from scratch since the implementation has been fundamentally changed.

Copilot AI commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

@copilot Review from scratch since the implementation has been fundamentally changed.

Reviewed the current implementation from scratch. Overall it looks sound — no correctness or security issues found. Notes:

Model routing is correct. In languageModel(named:), the default branch returns SystemLanguageModel.default, which is Apple's on‑device Foundation Models. Since markedit-api v0.27.0 only exports LanguageModelName = 'Apple-Foundation-Models', every valid call today lands on that branch and gets the correct model. The "Private-Cloud-Compute" case is forward-looking and currently unreachable until the API adds that name — just make sure the string literal here matches the future LanguageModelName value exactly when you migrate to Xcode 27.

macOS 26 (< 27) silently ignores modelName. In both createSession and availability, when only macOS 26 is available the code always uses the default model regardless of modelName. That's fine today (PCC requires macOS 27 and the only valid name maps to default anyway), but worth keeping in mind once a second selectable model exists — a request for a non‑default model would silently fall back to the default rather than report unavailable.

availability(of:) looks right — it returns PCC-specific availability when the model is PrivateCloudComputeLanguageModel and defaultModelAvailability otherwise.

The version gating (#if canImport(FoundationModels, _version: 2) + #available(macOS 27.0, *)) and the com.apple.developer.private-cloud-compute entitlement are consistent with the "not functional until Xcode 27" intent. No changes needed.

Note: automated review flagged the default → SystemLanguageModel.default path as a bug — that's a false positive, since that path correctly handles 'Apple-Foundation-Models'.

@cyanzhong cyanzhong merged commit 5dac899 into main Jul 6, 2026
2 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.

3 participants