apple-fm 0.1.0 → 1.0.0

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
@@ -12,11 +12,12 @@ tested, **zero-runtime-dependency** Node layer gives you a CLI and a library.
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
15
+ > ℹ️ **Status.** Published to npm with a Developer-ID **signed + notarized**
16
+ > helper, and smoke-verified on a macOS 26 / Apple Intelligence machine — probe,
17
+ > generate (freeform / guided / streamed), native guaranteed-structure output, and
18
+ > persistent multi-turn chat all work on-device. The one tracked gap is an
19
+ > automated on-device *generation* test in CI: hosted runners build, sign, and
20
+ > notarize the helper but can't run the model (it needs Apple Intelligence). See
20
21
  > [docs/3-requirements.md](docs/3-requirements.md).
21
22
 
22
23
  ## Why apple-fm
@@ -56,6 +57,25 @@ npm run build:helper # → bin/apple-fm-helper (needs Xcode 26 / macOS 26
56
57
  The helper is located via `APPLE_FM_BIN`, then the bundled `bin/apple-fm-helper`,
57
58
  then `apple-fm-helper` on `PATH`.
58
59
 
60
+ ### Platform support
61
+
62
+ apple-fm **installs on any OS** — so it can be a dependency of a cross-platform
63
+ project — but the on-device model only *runs* on **macOS 26+ Apple Silicon**.
64
+ Everywhere else it degrades gracefully instead of crashing: `probe()` returns
65
+ `{ available: false, reason: 'unsupportedPlatform' }`, and `generate` / `chat`
66
+ throw a clear `[unsupportedPlatform]` error. Gate on `isPlatformSupported()` or
67
+ `probe()`:
68
+
69
+ ```ts
70
+ import { isPlatformSupported, probe, generate } from 'apple-fm';
71
+
72
+ if ((await probe()).available) {
73
+ await generate({ prompt: '…' });
74
+ } else {
75
+ // fall back (cloud model, cached result, skip the feature, …)
76
+ }
77
+ ```
78
+
59
79
  ## CLI
60
80
 
61
81
  ```bash
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.0",
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
  },