@tanstack-ai-browser/apfel 0.0.0-stage → 0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 daveycodez
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,18 @@
1
- # Temporary Holding Version
1
+ # @tanstack-ai-browser/apfel
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A [TanStack AI](https://tanstack.com/ai) adapter for Apple's on-device Foundation Model, served on your Mac by [apfel](https://apfel.franzai.com)'s OpenAI-compatible server. The browser streams straight from localhost: start it with `apfel --serve --cors`.
4
+
5
+ ```sh
6
+ npm install @tanstack-ai-browser/apfel @tanstack/ai
7
+ ```
8
+
9
+ ```ts
10
+ import { chat } from "@tanstack/ai"
11
+ import { apfel, isApfelAvailable } from "@tanstack-ai-browser/apfel"
12
+
13
+ if (await isApfelAvailable()) {
14
+ const stream = chat({ adapter: apfel(), messages, threadId })
15
+ }
16
+ ```
17
+
18
+ **Status:** early (0.0.x); the API may change. See the [repository README](https://github.com/daveycodez/tanstack-ai-browser#readme).
@@ -0,0 +1,91 @@
1
+ import type { AdapterYieldChunk, TextOptions } from "@tanstack/ai";
2
+ import { BaseTextAdapter } from "@tanstack/ai/adapters";
3
+ import type { StructuredOutputOptions, StructuredOutputResult } from "@tanstack/ai/adapters";
4
+ /** Where `apfel --serve` listens by default. */
5
+ export declare const APFEL_BASE_URL = "http://127.0.0.1:11434/v1";
6
+ /** The model id apfel serves Apple's Foundation Model under. */
7
+ export declare const APFEL_MODEL = "apple-foundationmodel";
8
+ /**
9
+ * A model call's token counts and timings. apfel reports token counts only
10
+ * in the usage at the end of the stream; counts it doesn't report are left
11
+ * out.
12
+ */
13
+ export type ApfelStats = {
14
+ /** Tokens of the prompt. */
15
+ inputTokens?: number;
16
+ /** Prompt tokens served from a cache, if apfel reports them. */
17
+ cachedTokens?: number;
18
+ /** Tokens the model generated. */
19
+ outputTokens?: number;
20
+ /** From sending the request to the first generated token, in ms. */
21
+ firstTokenMs?: number;
22
+ /** Tokens generated after the first chunk (estimated, see below). */
23
+ decodeTokens?: number;
24
+ /** From the first generated chunk to the last, in ms. */
25
+ decodeMs?: number;
26
+ };
27
+ export type ApfelOptions = {
28
+ /** apfel's OpenAI-compatible API, up to `/v1`. */
29
+ baseUrl?: string;
30
+ /** The model id to ask apfel for. */
31
+ model?: string;
32
+ /**
33
+ * The call's stats at its first token (`done: false`, time to first token
34
+ * only) and when it ends (`done: true`). `callId` is unique per model
35
+ * call; `chat()` makes one per step of its agent loop.
36
+ */
37
+ onStats?: (stats: ApfelStats, run: {
38
+ threadId: string;
39
+ runId: string;
40
+ callId: string;
41
+ done: boolean;
42
+ }) => void;
43
+ };
44
+ /**
45
+ * Request fields apfel takes for Apple's model. apfel rejects parameters
46
+ * the model doesn't support (stop, penalties, n…) with HTTP 400.
47
+ */
48
+ export type ApfelModelOptions = {
49
+ temperature?: number;
50
+ max_tokens?: number;
51
+ seed?: number;
52
+ };
53
+ type ApfelReasoning = never;
54
+ type MetadataByModality = {
55
+ text: unknown;
56
+ image: unknown;
57
+ audio: unknown;
58
+ video: unknown;
59
+ document: unknown;
60
+ };
61
+ export declare class ApfelTextAdapter extends BaseTextAdapter<string, ApfelModelOptions, readonly ["text"], MetadataByModality, ReadonlyArray<string>, unknown, never, ApfelReasoning> {
62
+ readonly name: "apfel";
63
+ readonly api: "apfel";
64
+ private readonly baseUrl;
65
+ private readonly onStats;
66
+ constructor(options?: ApfelOptions);
67
+ chatStream(options: TextOptions<ApfelModelOptions>): AsyncIterable<AdapterYieldChunk>;
68
+ /**
69
+ * A JSON answer for `chat({ outputSchema })`, from apfel's JSON mode:
70
+ * `response_format: json_schema` constrains Apple's model to the schema
71
+ * (guided generation). `chat()` validates the result.
72
+ */
73
+ structuredOutput(options: StructuredOutputOptions<ApfelModelOptions>): Promise<StructuredOutputResult<unknown>>;
74
+ }
75
+ /**
76
+ * A TanStack AI adapter for Apple's on-device Foundation Model through
77
+ * apfel (`apfel --serve --cors`).
78
+ *
79
+ * @example
80
+ * ```ts
81
+ * chat({ adapter: apfel(), messages, threadId })
82
+ * ```
83
+ */
84
+ export declare function apfel(options?: ApfelOptions): ApfelTextAdapter;
85
+ /**
86
+ * Whether apfel is running and serves the model: true if `GET /v1/models`
87
+ * lists it within 10 seconds.
88
+ */
89
+ export declare function isApfelAvailable(options?: Pick<ApfelOptions, "baseUrl" | "model">): Promise<boolean>;
90
+ export {};
91
+ //# sourceMappingURL=adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EACV,iBAAiB,EAEjB,WAAW,EAEZ,MAAM,cAAc,CAAA;AACrB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