apple-fm 0.1.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,21 +4,14 @@
4
4
  the on-device **Foundation Models** on **macOS 26+ / Apple Silicon** — free,
5
5
  private, and fully offline. No API key, no network, nothing leaves your Mac.
6
6
 
7
- Apple ships `FoundationModels` as a Swift-only framework with no command-line
8
- front-end. apple-fm provides one: a tiny Swift helper does the model work, and a
9
- tested, **zero-runtime-dependency** Node layer gives you a CLI and a library.
7
+ Apple ships these models as a Swift-only framework with no command-line
8
+ front-end. apple-fm provides one — a fast, lightweight CLI and a TypeScript
9
+ library, so you can use the on-device model from your terminal or your code.
10
10
 
11
11
  <p align="center">
12
12
  <img src="assets/demos/generate.svg" alt="apple-fm generate &quot;Explain a closure in one sentence.&quot; runs Apple's on-device model and prints the answer — fully offline, no API key." width="820">
13
13
  </p>
14
14
 
15
- > ⚠️ **Pre-release.** The Node layer is fully unit-tested and the Swift helper is
16
- > smoke-verified on a macOS 26 / Apple Intelligence machine — probe, generate
17
- > (freeform / guided / streamed), native guaranteed-structure output, and a
18
- > persistent multi-turn chat all work on-device. Still in flight: an automated
19
- > on-device test in CI and the first signed + notarized npm release — see
20
- > [docs/3-requirements.md](docs/3-requirements.md).
21
-
22
15
  ## Why apple-fm
23
16
 
24
17
  - **On-device & private.** Runs on the model Apple Intelligence already
@@ -34,8 +27,8 @@ tested, **zero-runtime-dependency** Node layer gives you a CLI and a library.
34
27
  session across turns, reusing the model's cache instead of replaying the
35
28
  transcript, and automatically summarizes older turns as the small context
36
29
  window fills.
37
- - **Zero runtime dependencies.** The Node layer only spawns the helper and speaks
38
- JSON. Strict TypeScript, ESM, lint-clean.
30
+ - **Lightweight, nothing to audit.** Zero runtime dependencies — apple-fm just
31
+ talks to the on-device model and gets out of your way.
39
32
  - **Future-proof.** The helper resolves the current on-device model at runtime,
40
33
  so OS and model updates are picked up without a rebuild.
41
34
 
@@ -46,15 +39,28 @@ npm install -g apple-fm # CLI
46
39
  npm install apple-fm # library
47
40
  ```
48
41
 
49
- Requires macOS 26+ on Apple Silicon with Apple Intelligence enabled. Releases
50
- bundle a signed + notarized helper; you can also build it from source:
42
+ Requires macOS 26+ on Apple Silicon with Apple Intelligence enabled. Every
43
+ release is Developer-ID signed and notarized, so it runs without security
44
+ prompts.
51
45
 
52
- ```bash
53
- npm run build:helper # → bin/apple-fm-helper (needs Xcode 26 / macOS 26 SDK)
54
- ```
46
+ ### Platform support
55
47
 
56
- The helper is located via `APPLE_FM_BIN`, then the bundled `bin/apple-fm-helper`,
57
- then `apple-fm-helper` on `PATH`.
48
+ apple-fm **installs on any OS** — so it can be a dependency of a cross-platform
49
+ project — but the on-device model only *runs* on **macOS 26+ Apple Silicon**.
50
+ Everywhere else it degrades gracefully instead of crashing: `probe()` returns
51
+ `{ available: false, reason: 'unsupportedPlatform' }`, and `generate` / `chat`
52
+ throw a clear `[unsupportedPlatform]` error. Gate on `isPlatformSupported()` or
53
+ `probe()`:
54
+
55
+ ```ts
56
+ import { isPlatformSupported, probe, generate } from 'apple-fm';
57
+
58
+ if ((await probe()).available) {
59
+ await generate({ prompt: '…' });
60
+ } else {
61
+ // fall back (cloud model, cached result, skip the feature, …)
62
+ }
63
+ ```
58
64
 
59
65
  ## CLI
60
66
 
@@ -123,23 +129,16 @@ documented in [docs/ai/code-summary.md](docs/ai/code-summary.md).
123
129
 
124
130
  ## How it works
125
131
 
126
- A single binary, three shapes (probe / generate / chat), all over one
127
- line-delimited JSON protocol ([docs/4-protocol.md](docs/4-protocol.md)). Only the
128
- Swift helper imports `FoundationModels`; all policy — argument parsing, the wire
129
- protocol, chat history, auto-compaction — lives in strict TypeScript and is
130
- unit-tested against a stub helper, so the suite runs on any platform. For chat the
131
- helper holds one `LanguageModelSession` across turns (so the model's cache is
132
- reused instead of replaying the transcript), while the Node side keeps the
133
- transcript so it can summarize older turns as the small context window fills — so
134
- long conversations stay coherent and cheap. Because the helper resolves the
135
- current on-device model at runtime, OS and model updates are picked up without a
136
- rebuild.
132
+ apple-fm talks to the same on-device model that powers Apple Intelligence —
133
+ nothing is sent to the cloud. For chat it keeps one model session alive across
134
+ turns so replies stay fast, and automatically summarizes older messages as the
135
+ context window fills, so long conversations stay coherent and cheap. And because
136
+ it resolves the current on-device model at runtime, OS and model updates are
137
+ picked up automatically — no reinstall.
137
138
 
138
139
  ## Documentation
139
140
 
140
- - [Overview](docs/1-overview.md) · [Architecture](docs/2-architecture.md) ·
141
- [Requirements](docs/3-requirements.md) · [Protocol](docs/4-protocol.md) ·
142
- [Releasing](docs/5-releasing.md)
141
+ - [Overview](docs/1-overview.md)
143
142
 
144
143
  ## Disclaimer
145
144
 
Binary file
package/dist/cli.js CHANGED
@@ -163,6 +163,19 @@ function estimateConversationTokens(system, messages) {
163
163
  // src/helper.ts
164
164
  var HELPER_BIN_ENV = "APPLE_FM_BIN";
165
165
  var DEFAULT_TIMEOUT_MS = 12e4;
166
+ function isPlatformSupported() {
167
+ return process.platform === "darwin" && process.arch === "arm64";
168
+ }
169
+ function usingBundledHelper(options = {}) {
170
+ if (options.binPath !== void 0 && options.binPath.length > 0) return false;
171
+ const fromEnv = process.env[HELPER_BIN_ENV];
172
+ return fromEnv === void 0 || fromEnv.length === 0;
173
+ }
174
+ function unsupportedPlatformError() {
175
+ return new Error(
176
+ `[unsupportedPlatform] apple-fm requires macOS 26+ on Apple Silicon; the on-device model cannot run on ${process.platform}/${process.arch}`
177
+ );
178
+ }
166
179
  function resolveHelperPath(options = {}) {
167
180
  if (options.binPath !== void 0 && options.binPath.length > 0) return options.binPath;
168
181
  const fromEnv = process.env[HELPER_BIN_ENV];
@@ -228,6 +241,9 @@ function runHelper(args, options, input, onLine) {
228
241
  });
229
242
  }
230
243
  async function probe(options = {}) {
244
+ if (usingBundledHelper(options) && !isPlatformSupported()) {
245
+ return { available: false, reason: "unsupportedPlatform" };
246
+ }
231
247
  let result;
232
248
  await runHelper(["--probe"], options, void 0, (line) => {
233
249
  result = JSON.parse(line);
@@ -236,6 +252,7 @@ async function probe(options = {}) {
236
252
  return result;
237
253
  }
238
254
  async function generate(request, options = {}, onDelta, onSnapshot) {
255
+ if (usingBundledHelper(options) && !isPlatformSupported()) throw unsupportedPlatformError();
239
256
  let content;
240
257
  await runHelper(["--generate"], options, encodeRequest(request), (line) => {
241
258
  const event = parseEvent(line);
@@ -267,6 +284,8 @@ var LiveSession = class {
267
284
  command;
268
285
  timeoutMs;
269
286
  options;
287
+ /** Whether we'd spawn the bundled macOS helper (subject to the platform gate). */
288
+ bundled;
270
289
  child;
271
290
  buffer = "";
272
291
  nextId = 0;
@@ -275,6 +294,7 @@ var LiveSession = class {
275
294
  this.command = resolveHelperPath(config);
276
295
  this.timeoutMs = config.timeoutMs ?? DEFAULT_TURN_TIMEOUT_MS;
277
296
  this.options = config.options;
297
+ this.bundled = usingBundledHelper(config);
278
298
  }
279
299
  /** Recreate the underlying session with new instructions + seed turns. */
280
300
  async reset(system, seed = []) {
@@ -374,6 +394,7 @@ var LiveSession = class {
374
394
  pending.reject(new Error(message));
375
395
  }
376
396
  dispatch(command, onDelta) {
397
+ if (this.bundled && !isPlatformSupported()) return Promise.reject(unsupportedPlatformError());
377
398
  const child = this.ensureChild();
378
399
  const id = String(this.nextId++);
379
400
  return new Promise((resolve, reject) => {
package/dist/index.d.ts CHANGED
@@ -40,8 +40,13 @@ interface GenerateRequest {
40
40
  /** Stream partial output as `delta` events (default: false). */
41
41
  stream?: boolean;
42
42
  }
43
- /** Why the on-device model is or isn't usable right now. */
44
- type UnavailableReason = 'deviceNotEligible' | 'appleIntelligenceNotEnabled' | 'modelNotReady' | 'unknown';
43
+ /**
44
+ * Why the on-device model is or isn't usable right now. The first three +
45
+ * `unknown` come from the Swift helper; `unsupportedPlatform` is reported by the
46
+ * Node layer *without* running the helper, when the OS/CPU can't run it at all
47
+ * (not macOS on Apple Silicon).
48
+ */
49
+ type UnavailableReason = 'deviceNotEligible' | 'appleIntelligenceNotEnabled' | 'modelNotReady' | 'unsupportedPlatform' | 'unknown';
45
50
  /** Result of `apple-fm-helper --probe`. */
46
51
  interface ProbeResult {
47
52
  available: boolean;
@@ -87,6 +92,15 @@ type SnapshotHandler = (content: string) => void;
87
92
 
88
93
  /** Environment variable that pins the helper binary path. */
89
94
  declare const HELPER_BIN_ENV = "APPLE_FM_BIN";
95
+ /**
96
+ * Whether this platform can run the bundled on-device helper at all: macOS on
97
+ * Apple Silicon. (Whether the *model* is usable then — macOS 26+, Apple
98
+ * Intelligence enabled — is what {@link probe} checks.) apple-fm installs on any
99
+ * OS so it can be a dependency of cross-platform projects; off-platform it
100
+ * degrades gracefully rather than crashing — `probe` reports `unsupportedPlatform`
101
+ * and `generate` / `ChatSession` throw a clear `[unsupportedPlatform]` error.
102
+ */
103
+ declare function isPlatformSupported(): boolean;
90
104
  /**
91
105
  * Resolve the helper binary path: `APPLE_FM_BIN`, then the prebuilt binary
92
106
  * bundled with the package (`bin/apple-fm-helper`), then bare `apple-fm-helper`
@@ -122,6 +136,8 @@ declare class LiveSession implements ChatBackend {
122
136
  private readonly command;
123
137
  private readonly timeoutMs;
124
138
  private readonly options;
139
+ /** Whether we'd spawn the bundled macOS helper (subject to the platform gate). */
140
+ private readonly bundled;
125
141
  private child;
126
142
  private buffer;
127
143
  private nextId;
@@ -250,4 +266,4 @@ declare class ChatSession {
250
266
  close(): void;
251
267
  }
252
268
 
253
- export { type ChatBackend, ChatSession, type ChatSessionConfig, type DeltaHandler, type GenerateFn, type GenerateOptions, type GenerateRequest, HELPER_BIN_ENV, type HelperEvent, type HelperOptions, LiveSession, type LiveSessionConfig, type Message, type ProbeResult, type Role, type SnapshotHandler, type UnavailableReason, encodeRequest, estimateConversationTokens, estimateTokens, flattenMessages, generate, parseEvent, probe, resolveHelperPath, splitLines };
269
+ export { type ChatBackend, ChatSession, type ChatSessionConfig, type DeltaHandler, type GenerateFn, type GenerateOptions, type GenerateRequest, HELPER_BIN_ENV, type HelperEvent, type HelperOptions, LiveSession, type LiveSessionConfig, type Message, type ProbeResult, type Role, type SnapshotHandler, type UnavailableReason, encodeRequest, estimateConversationTokens, estimateTokens, flattenMessages, generate, isPlatformSupported, parseEvent, probe, resolveHelperPath, splitLines };
package/dist/index.js CHANGED
@@ -51,6 +51,19 @@ function estimateConversationTokens(system, messages) {
51
51
  // src/helper.ts
52
52
  var HELPER_BIN_ENV = "APPLE_FM_BIN";
53
53
  var DEFAULT_TIMEOUT_MS = 12e4;
54
+ function isPlatformSupported() {
55
+ return process.platform === "darwin" && process.arch === "arm64";
56
+ }
57
+ function usingBundledHelper(options = {}) {
58
+ if (options.binPath !== void 0 && options.binPath.length > 0) return false;
59
+ const fromEnv = process.env[HELPER_BIN_ENV];
60
+ return fromEnv === void 0 || fromEnv.length === 0;
61
+ }
62
+ function unsupportedPlatformError() {
63
+ return new Error(
64
+ `[unsupportedPlatform] apple-fm requires macOS 26+ on Apple Silicon; the on-device model cannot run on ${process.platform}/${process.arch}`
65
+ );
66
+ }
54
67
  function resolveHelperPath(options = {}) {
55
68
  if (options.binPath !== void 0 && options.binPath.length > 0) return options.binPath;
56
69
  const fromEnv = process.env[HELPER_BIN_ENV];
@@ -116,6 +129,9 @@ function runHelper(args, options, input, onLine) {
116
129
  });
117
130
  }
118
131
  async function probe(options = {}) {
132
+ if (usingBundledHelper(options) && !isPlatformSupported()) {
133
+ return { available: false, reason: "unsupportedPlatform" };
134
+ }
119
135
  let result;
120
136
  await runHelper(["--probe"], options, void 0, (line) => {
121
137
  result = JSON.parse(line);
@@ -124,6 +140,7 @@ async function probe(options = {}) {
124
140
  return result;
125
141
  }
126
142
  async function generate(request, options = {}, onDelta, onSnapshot) {
143
+ if (usingBundledHelper(options) && !isPlatformSupported()) throw unsupportedPlatformError();
127
144
  let content;
128
145
  await runHelper(["--generate"], options, encodeRequest(request), (line) => {
129
146
  const event = parseEvent(line);
@@ -152,6 +169,8 @@ var LiveSession = class {
152
169
  command;
153
170
  timeoutMs;
154
171
  options;
172
+ /** Whether we'd spawn the bundled macOS helper (subject to the platform gate). */
173
+ bundled;
155
174
  child;
156
175
  buffer = "";
157
176
  nextId = 0;
@@ -160,6 +179,7 @@ var LiveSession = class {
160
179
  this.command = resolveHelperPath(config);
161
180
  this.timeoutMs = config.timeoutMs ?? DEFAULT_TURN_TIMEOUT_MS;
162
181
  this.options = config.options;
182
+ this.bundled = usingBundledHelper(config);
163
183
  }
164
184
  /** Recreate the underlying session with new instructions + seed turns. */
165
185
  async reset(system, seed = []) {
@@ -259,6 +279,7 @@ var LiveSession = class {
259
279
  pending.reject(new Error(message));
260
280
  }
261
281
  dispatch(command, onDelta) {
282
+ if (this.bundled && !isPlatformSupported()) return Promise.reject(unsupportedPlatformError());
262
283
  const child = this.ensureChild();
263
284
  const id = String(this.nextId++);
264
285
  return new Promise((resolve, reject) => {
@@ -387,6 +408,7 @@ export {
387
408
  estimateTokens,
388
409
  flattenMessages,
389
410
  generate,
411
+ isPlatformSupported,
390
412
  parseEvent,
391
413
  probe,
392
414
  resolveHelperPath,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apple-fm",
3
- "version": "0.1.0",
3
+ "version": "1.0.1",
4
4
  "description": "Command-line and programmatic access to Apple's on-device Foundation Models (Apple Intelligence) on macOS 26+.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -20,9 +20,6 @@
20
20
  "cli",
21
21
  "chat"
22
22
  ],
23
- "os": [
24
- "darwin"
25
- ],
26
23
  "engines": {
27
24
  "node": ">=20"
28
25
  },