@entro314labs/apple-intelligence-sdk 0.2.1 → 0.3.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 +2 -0
- package/package.json +7 -7
- package/dist/index.cjs +0 -416
- package/dist/index.d.cts +0 -143
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.mts +0 -143
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs +0 -415
- package/dist/index.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
This package provides a **Vercel AI SDK v6 provider** for Apple Intelligence using a **pluggable transport**. It does **not** ship any native binaries.
|
|
4
4
|
|
|
5
|
+
Companion Tauri bridge crate: https://github.com/entro314-labs/tauri-apple-intelligence
|
|
6
|
+
|
|
5
7
|
## Why a transport?
|
|
6
8
|
|
|
7
9
|
Apple Intelligence runs on-device and requires macOS 26+ on Apple Silicon. Different runtimes (Tauri, Node, etc.) need different bridges. This SDK keeps the provider logic reusable while the transport does platform-specific work.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@entro314labs/apple-intelligence-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Apple Intelligence provider for the Vercel AI SDK with pluggable transports (Tauri, Node, etc.)",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -31,18 +31,18 @@
|
|
|
31
31
|
"LICENSE"
|
|
32
32
|
],
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@ai-sdk/provider": "^3.0.
|
|
35
|
-
"@ai-sdk/provider-utils": "^4.0.
|
|
36
|
-
"@tauri-apps/api": "^2.
|
|
34
|
+
"@ai-sdk/provider": "^3.0.10",
|
|
35
|
+
"@ai-sdk/provider-utils": "^4.0.27",
|
|
36
|
+
"@tauri-apps/api": "^2.11.0",
|
|
37
37
|
"json-schema": "^0.4.0"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"ai": "^6.0.69"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"rimraf": "^6.1.
|
|
44
|
-
"tsdown": "^0.
|
|
45
|
-
"typescript": "^
|
|
43
|
+
"rimraf": "^6.1.3",
|
|
44
|
+
"tsdown": "^0.22.0",
|
|
45
|
+
"typescript": "^6.0.3"
|
|
46
46
|
},
|
|
47
47
|
"keywords": [
|
|
48
48
|
"apple",
|
package/dist/index.cjs
DELETED
|
@@ -1,416 +0,0 @@
|
|
|
1
|
-
let _ai_sdk_provider_utils = require("@ai-sdk/provider-utils");
|
|
2
|
-
let _tauri_apps_api_core = require("@tauri-apps/api/core");
|
|
3
|
-
let _tauri_apps_api_event = require("@tauri-apps/api/event");
|
|
4
|
-
|
|
5
|
-
//#region src/provider.ts
|
|
6
|
-
function createAppleIntelligenceProvider(settings) {
|
|
7
|
-
const createModel = (modelId, modelSettings = {}) => new AppleIntelligenceChatLanguageModel(modelId, modelSettings, settings);
|
|
8
|
-
const provider = function(modelId, modelSettings) {
|
|
9
|
-
if (new.target) throw new Error("The Apple Intelligence provider cannot be called with the new keyword.");
|
|
10
|
-
return createModel(modelId, modelSettings);
|
|
11
|
-
};
|
|
12
|
-
provider.chat = createModel;
|
|
13
|
-
provider.languageModel = createModel;
|
|
14
|
-
return provider;
|
|
15
|
-
}
|
|
16
|
-
var AppleIntelligenceChatLanguageModel = class {
|
|
17
|
-
specificationVersion = "v3";
|
|
18
|
-
provider = "apple-intelligence";
|
|
19
|
-
modelId;
|
|
20
|
-
defaultObjectGenerationMode = "json";
|
|
21
|
-
supportsImageUrls = false;
|
|
22
|
-
supportsStructuredOutputs = true;
|
|
23
|
-
settings;
|
|
24
|
-
transport;
|
|
25
|
-
generateId;
|
|
26
|
-
constructor(modelId, settings, providerSettings) {
|
|
27
|
-
this.modelId = modelId;
|
|
28
|
-
this.settings = settings;
|
|
29
|
-
this.transport = providerSettings.transport;
|
|
30
|
-
this.generateId = providerSettings.generateId ?? _ai_sdk_provider_utils.generateId;
|
|
31
|
-
}
|
|
32
|
-
supportedUrls = {};
|
|
33
|
-
async doGenerate(options) {
|
|
34
|
-
await this.assertAvailability();
|
|
35
|
-
if (options.responseFormat?.type === "json" && Boolean(options.responseFormat.schema)) return this.handleStructuredGeneration(options);
|
|
36
|
-
return this.handleRegularGeneration(options);
|
|
37
|
-
}
|
|
38
|
-
async doStream(options) {
|
|
39
|
-
await this.assertAvailability();
|
|
40
|
-
const messages = this.convertPromptToMessages(options.prompt);
|
|
41
|
-
const tools = options.tools?.length ? this.convertTools(options.tools) : void 0;
|
|
42
|
-
return { stream: tools?.length ? this.createStreamFromEvents(this.transport.stream({
|
|
43
|
-
messages,
|
|
44
|
-
tools,
|
|
45
|
-
temperature: this.settings.temperature,
|
|
46
|
-
maxTokens: options.maxOutputTokens ?? this.settings.maxTokens,
|
|
47
|
-
stopAfterToolCalls: true
|
|
48
|
-
})) : this.createStreamFromChunks(this.transport.stream({
|
|
49
|
-
messages,
|
|
50
|
-
temperature: this.settings.temperature,
|
|
51
|
-
maxTokens: options.maxOutputTokens ?? this.settings.maxTokens
|
|
52
|
-
})) };
|
|
53
|
-
}
|
|
54
|
-
supportsUrl(_url) {
|
|
55
|
-
return true;
|
|
56
|
-
}
|
|
57
|
-
async assertAvailability() {
|
|
58
|
-
if (this.settings.requireAvailability === false) return {
|
|
59
|
-
available: true,
|
|
60
|
-
reason: "Skipped availability check"
|
|
61
|
-
};
|
|
62
|
-
const availability = await this.transport.checkAvailability();
|
|
63
|
-
if (!availability.available) throw new Error(`Apple Intelligence not available: ${availability.reason}`);
|
|
64
|
-
return availability;
|
|
65
|
-
}
|
|
66
|
-
async handleStructuredGeneration(options) {
|
|
67
|
-
const schema = options.responseFormat?.schema;
|
|
68
|
-
if (!schema) throw new Error("Structured generation requires a JSON schema in responseFormat.");
|
|
69
|
-
const messages = this.convertPromptToMessages(options.prompt);
|
|
70
|
-
const result = await this.transport.generate({
|
|
71
|
-
messages,
|
|
72
|
-
schema,
|
|
73
|
-
temperature: this.settings.temperature,
|
|
74
|
-
maxTokens: options.maxOutputTokens ?? this.settings.maxTokens
|
|
75
|
-
});
|
|
76
|
-
if (result.object !== void 0) return {
|
|
77
|
-
content: [{
|
|
78
|
-
type: "text",
|
|
79
|
-
text: JSON.stringify(result.object)
|
|
80
|
-
}],
|
|
81
|
-
finishReason: {
|
|
82
|
-
unified: "stop",
|
|
83
|
-
raw: "stop"
|
|
84
|
-
},
|
|
85
|
-
usage: this.emptyUsage(),
|
|
86
|
-
warnings: []
|
|
87
|
-
};
|
|
88
|
-
return {
|
|
89
|
-
content: [{
|
|
90
|
-
type: "text",
|
|
91
|
-
text: result.text ?? ""
|
|
92
|
-
}],
|
|
93
|
-
finishReason: {
|
|
94
|
-
unified: "stop",
|
|
95
|
-
raw: "stop"
|
|
96
|
-
},
|
|
97
|
-
usage: this.emptyUsage(),
|
|
98
|
-
warnings: []
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
async handleRegularGeneration(options) {
|
|
102
|
-
const messages = this.convertPromptToMessages(options.prompt);
|
|
103
|
-
const tools = options.tools?.length ? this.convertTools(options.tools) : void 0;
|
|
104
|
-
const result = await this.transport.generate({
|
|
105
|
-
messages,
|
|
106
|
-
tools,
|
|
107
|
-
temperature: this.settings.temperature,
|
|
108
|
-
maxTokens: options.maxOutputTokens ?? this.settings.maxTokens,
|
|
109
|
-
stopAfterToolCalls: true
|
|
110
|
-
});
|
|
111
|
-
if (result.toolCalls?.length) return {
|
|
112
|
-
content: result.toolCalls.map((call) => ({
|
|
113
|
-
type: "tool-call",
|
|
114
|
-
toolCallId: call.id,
|
|
115
|
-
toolName: call.function.name,
|
|
116
|
-
input: call.function.arguments
|
|
117
|
-
})),
|
|
118
|
-
finishReason: {
|
|
119
|
-
unified: "tool-calls",
|
|
120
|
-
raw: "tool-calls"
|
|
121
|
-
},
|
|
122
|
-
usage: this.emptyUsage(),
|
|
123
|
-
warnings: []
|
|
124
|
-
};
|
|
125
|
-
return {
|
|
126
|
-
content: [{
|
|
127
|
-
type: "text",
|
|
128
|
-
text: result.text ?? ""
|
|
129
|
-
}],
|
|
130
|
-
finishReason: {
|
|
131
|
-
unified: "stop",
|
|
132
|
-
raw: "stop"
|
|
133
|
-
},
|
|
134
|
-
usage: this.emptyUsage(),
|
|
135
|
-
warnings: []
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
convertTools(tools) {
|
|
139
|
-
return tools ? tools.map((tool) => {
|
|
140
|
-
if (tool.type !== "function") throw new Error(`Unsupported tool type: ${tool.type}`);
|
|
141
|
-
return {
|
|
142
|
-
name: tool.name,
|
|
143
|
-
description: tool.description,
|
|
144
|
-
parameters: tool.inputSchema
|
|
145
|
-
};
|
|
146
|
-
}) : [];
|
|
147
|
-
}
|
|
148
|
-
convertPromptToMessages(prompt) {
|
|
149
|
-
return prompt.map((message) => {
|
|
150
|
-
switch (message.role) {
|
|
151
|
-
case "system": return {
|
|
152
|
-
role: "system",
|
|
153
|
-
content: message.content
|
|
154
|
-
};
|
|
155
|
-
case "user": return {
|
|
156
|
-
role: "user",
|
|
157
|
-
content: Array.isArray(message.content) ? message.content.map((part) => part.type === "text" ? part.text : "[unsupported content]").join("\n") : message.content
|
|
158
|
-
};
|
|
159
|
-
case "assistant": return this.convertAssistantMessage(message);
|
|
160
|
-
case "tool": return this.convertToolMessage(message);
|
|
161
|
-
default: return {
|
|
162
|
-
role: "user",
|
|
163
|
-
content: String(message.content ?? "")
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
convertAssistantMessage(message) {
|
|
169
|
-
if (Array.isArray(message.content)) {
|
|
170
|
-
const toolCalls = message.content.filter((part) => part.type === "tool-call");
|
|
171
|
-
const textParts = message.content.filter((part) => part.type === "text");
|
|
172
|
-
if (toolCalls.length > 0) return {
|
|
173
|
-
role: "assistant",
|
|
174
|
-
content: textParts.map((part) => part.text).join("\n") || "",
|
|
175
|
-
toolCalls: toolCalls.map((part) => ({
|
|
176
|
-
id: part.toolCallId,
|
|
177
|
-
type: "function",
|
|
178
|
-
function: {
|
|
179
|
-
name: part.toolName,
|
|
180
|
-
arguments: typeof part.input === "string" ? part.input : JSON.stringify(part.input)
|
|
181
|
-
}
|
|
182
|
-
}))
|
|
183
|
-
};
|
|
184
|
-
return {
|
|
185
|
-
role: "assistant",
|
|
186
|
-
content: message.content.map((part) => {
|
|
187
|
-
switch (part.type) {
|
|
188
|
-
case "text":
|
|
189
|
-
case "reasoning": return part.text;
|
|
190
|
-
default: return `[unsupported content - ${part.type}]`;
|
|
191
|
-
}
|
|
192
|
-
}).join("\n")
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
return {
|
|
196
|
-
role: "assistant",
|
|
197
|
-
content: message.content || ""
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
convertToolMessage(message) {
|
|
201
|
-
const toolCalls = message.content.map((part) => {
|
|
202
|
-
if (part.type === "tool-result") return {
|
|
203
|
-
id: part.toolCallId,
|
|
204
|
-
toolName: part.toolName,
|
|
205
|
-
segments: [{
|
|
206
|
-
type: "text",
|
|
207
|
-
text: this.formatToolResultOutput(part.output)
|
|
208
|
-
}]
|
|
209
|
-
};
|
|
210
|
-
if (part.type === "tool-approval-response") return {
|
|
211
|
-
id: part.approvalId,
|
|
212
|
-
toolName: "tool-approval",
|
|
213
|
-
segments: [{
|
|
214
|
-
type: "text",
|
|
215
|
-
text: part.approved ? `Tool approval granted${part.reason ? `: ${part.reason}` : ""}` : `Tool approval denied${part.reason ? `: ${part.reason}` : ""}`
|
|
216
|
-
}]
|
|
217
|
-
};
|
|
218
|
-
return null;
|
|
219
|
-
}).filter(Boolean);
|
|
220
|
-
return {
|
|
221
|
-
role: "tool",
|
|
222
|
-
content: JSON.stringify({ tool_calls: toolCalls })
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
formatToolResultOutput(output) {
|
|
226
|
-
switch (output.type) {
|
|
227
|
-
case "text":
|
|
228
|
-
case "error-text": return output.value;
|
|
229
|
-
case "json":
|
|
230
|
-
case "error-json": return JSON.stringify(output.value);
|
|
231
|
-
case "execution-denied": return output.reason ? `Tool execution denied: ${output.reason}` : "Tool execution denied";
|
|
232
|
-
case "content": return output.value.map((part) => {
|
|
233
|
-
if (part.type === "text") return part.text;
|
|
234
|
-
if (part.type === "file-data") return `[file-data:${part.mediaType}]`;
|
|
235
|
-
if (part.type === "file-url") return `[file-url:${part.url}]`;
|
|
236
|
-
return "[file]";
|
|
237
|
-
}).join("\n");
|
|
238
|
-
default: return "[unsupported tool output]";
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
createStreamFromEvents(nativeStream) {
|
|
242
|
-
return new ReadableStream({ async start(controller) {
|
|
243
|
-
controller.enqueue({
|
|
244
|
-
type: "stream-start",
|
|
245
|
-
warnings: []
|
|
246
|
-
});
|
|
247
|
-
const textId = crypto.randomUUID();
|
|
248
|
-
let hasText = false;
|
|
249
|
-
let hasToolCalls = false;
|
|
250
|
-
try {
|
|
251
|
-
for await (const event of nativeStream) if (event.type === "text") {
|
|
252
|
-
if (!hasText) {
|
|
253
|
-
controller.enqueue({
|
|
254
|
-
type: "text-start",
|
|
255
|
-
id: textId
|
|
256
|
-
});
|
|
257
|
-
hasText = true;
|
|
258
|
-
}
|
|
259
|
-
controller.enqueue({
|
|
260
|
-
type: "text-delta",
|
|
261
|
-
delta: event.text,
|
|
262
|
-
id: textId
|
|
263
|
-
});
|
|
264
|
-
} else if (event.type === "tool-call") {
|
|
265
|
-
hasToolCalls = true;
|
|
266
|
-
controller.enqueue({
|
|
267
|
-
type: "tool-call",
|
|
268
|
-
toolCallId: event.toolCallId,
|
|
269
|
-
toolName: event.toolName,
|
|
270
|
-
input: JSON.stringify(event.args)
|
|
271
|
-
});
|
|
272
|
-
} else if (event.type === "error") {
|
|
273
|
-
controller.error(new Error(event.message));
|
|
274
|
-
return;
|
|
275
|
-
} else if (event.type === "done") break;
|
|
276
|
-
if (hasText) controller.enqueue({
|
|
277
|
-
type: "text-end",
|
|
278
|
-
id: textId
|
|
279
|
-
});
|
|
280
|
-
controller.enqueue({
|
|
281
|
-
type: "finish",
|
|
282
|
-
finishReason: hasToolCalls ? {
|
|
283
|
-
unified: "tool-calls",
|
|
284
|
-
raw: "tool-calls"
|
|
285
|
-
} : {
|
|
286
|
-
unified: "stop",
|
|
287
|
-
raw: "stop"
|
|
288
|
-
},
|
|
289
|
-
usage: {
|
|
290
|
-
inputTokens: void 0,
|
|
291
|
-
outputTokens: void 0,
|
|
292
|
-
totalTokens: void 0
|
|
293
|
-
}
|
|
294
|
-
});
|
|
295
|
-
controller.close();
|
|
296
|
-
} catch (err) {
|
|
297
|
-
controller.error(err);
|
|
298
|
-
}
|
|
299
|
-
} });
|
|
300
|
-
}
|
|
301
|
-
createStreamFromChunks(stream) {
|
|
302
|
-
return new ReadableStream({ async start(controller) {
|
|
303
|
-
controller.enqueue({
|
|
304
|
-
type: "stream-start",
|
|
305
|
-
warnings: []
|
|
306
|
-
});
|
|
307
|
-
const textId = crypto.randomUUID();
|
|
308
|
-
let hasText = false;
|
|
309
|
-
try {
|
|
310
|
-
for await (const event of stream) if (event.type === "text") {
|
|
311
|
-
if (!hasText) {
|
|
312
|
-
controller.enqueue({
|
|
313
|
-
type: "text-start",
|
|
314
|
-
id: textId
|
|
315
|
-
});
|
|
316
|
-
hasText = true;
|
|
317
|
-
}
|
|
318
|
-
controller.enqueue({
|
|
319
|
-
type: "text-delta",
|
|
320
|
-
delta: event.text,
|
|
321
|
-
id: textId
|
|
322
|
-
});
|
|
323
|
-
} else if (event.type === "error") {
|
|
324
|
-
controller.error(new Error(event.message));
|
|
325
|
-
return;
|
|
326
|
-
} else if (event.type === "done") break;
|
|
327
|
-
if (hasText) controller.enqueue({
|
|
328
|
-
type: "text-end",
|
|
329
|
-
id: textId
|
|
330
|
-
});
|
|
331
|
-
controller.enqueue({
|
|
332
|
-
type: "finish",
|
|
333
|
-
finishReason: {
|
|
334
|
-
unified: "stop",
|
|
335
|
-
raw: "stop"
|
|
336
|
-
},
|
|
337
|
-
usage: {
|
|
338
|
-
inputTokens: void 0,
|
|
339
|
-
outputTokens: void 0,
|
|
340
|
-
totalTokens: void 0
|
|
341
|
-
}
|
|
342
|
-
});
|
|
343
|
-
controller.close();
|
|
344
|
-
} catch (err) {
|
|
345
|
-
controller.error(err);
|
|
346
|
-
}
|
|
347
|
-
} });
|
|
348
|
-
}
|
|
349
|
-
emptyUsage() {
|
|
350
|
-
return {
|
|
351
|
-
inputTokens: void 0,
|
|
352
|
-
outputTokens: void 0,
|
|
353
|
-
totalTokens: void 0
|
|
354
|
-
};
|
|
355
|
-
}
|
|
356
|
-
};
|
|
357
|
-
|
|
358
|
-
//#endregion
|
|
359
|
-
//#region src/tauri.ts
|
|
360
|
-
function createTauriAppleIntelligenceTransport(options = {}) {
|
|
361
|
-
const prefix = options.commandPrefix ?? "apple_ai";
|
|
362
|
-
const command = (name) => `${prefix}_${name}`;
|
|
363
|
-
return {
|
|
364
|
-
async checkAvailability() {
|
|
365
|
-
return (0, _tauri_apps_api_core.invoke)(command("check_availability"));
|
|
366
|
-
},
|
|
367
|
-
async generate(request) {
|
|
368
|
-
return (0, _tauri_apps_api_core.invoke)(command("generate"), { request });
|
|
369
|
-
},
|
|
370
|
-
async *stream(request) {
|
|
371
|
-
const start = await (0, _tauri_apps_api_core.invoke)(command("stream"), { request });
|
|
372
|
-
const queue = [];
|
|
373
|
-
let done = false;
|
|
374
|
-
let pendingResolve = null;
|
|
375
|
-
const unlisten = await (0, _tauri_apps_api_event.listen)(start.eventName, (event) => {
|
|
376
|
-
const payload = event.payload;
|
|
377
|
-
if (pendingResolve) {
|
|
378
|
-
pendingResolve({
|
|
379
|
-
value: payload,
|
|
380
|
-
done: false
|
|
381
|
-
});
|
|
382
|
-
pendingResolve = null;
|
|
383
|
-
} else queue.push(payload);
|
|
384
|
-
if (payload.type === "done" || payload.type === "error") {
|
|
385
|
-
done = true;
|
|
386
|
-
unlisten();
|
|
387
|
-
}
|
|
388
|
-
});
|
|
389
|
-
try {
|
|
390
|
-
while (true) {
|
|
391
|
-
if (queue.length > 0) {
|
|
392
|
-
const value = queue.shift();
|
|
393
|
-
yield value;
|
|
394
|
-
if (value.type === "done" || value.type === "error") return;
|
|
395
|
-
continue;
|
|
396
|
-
}
|
|
397
|
-
if (done) return;
|
|
398
|
-
const value = await new Promise((resolve) => {
|
|
399
|
-
pendingResolve = resolve;
|
|
400
|
-
});
|
|
401
|
-
if (value.value) {
|
|
402
|
-
yield value.value;
|
|
403
|
-
if (value.value.type === "done" || value.value.type === "error") return;
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
} finally {
|
|
407
|
-
if (!done) unlisten();
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
};
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
//#endregion
|
|
414
|
-
exports.AppleIntelligenceChatLanguageModel = AppleIntelligenceChatLanguageModel;
|
|
415
|
-
exports.createAppleIntelligenceProvider = createAppleIntelligenceProvider;
|
|
416
|
-
exports.createTauriAppleIntelligenceTransport = createTauriAppleIntelligenceTransport;
|
package/dist/index.d.cts
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import { JSONSchema7 } from "json-schema";
|
|
2
|
-
import { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3Content, LanguageModelV3FinishReason, LanguageModelV3ResponseMetadata, LanguageModelV3StreamPart, LanguageModelV3Usage, SharedV3Headers, SharedV3ProviderMetadata, SharedV3Warning } from "@ai-sdk/provider";
|
|
3
|
-
|
|
4
|
-
//#region src/transport.d.ts
|
|
5
|
-
type AppleIntelligenceMessage = {
|
|
6
|
-
role: "system" | "user" | "assistant" | "tool" | "tool_calls";
|
|
7
|
-
content?: string;
|
|
8
|
-
name?: string;
|
|
9
|
-
toolCallId?: string;
|
|
10
|
-
toolCalls?: Array<{
|
|
11
|
-
id: string;
|
|
12
|
-
type: "function";
|
|
13
|
-
function: {
|
|
14
|
-
name: string;
|
|
15
|
-
arguments: string;
|
|
16
|
-
};
|
|
17
|
-
}>;
|
|
18
|
-
};
|
|
19
|
-
type AppleIntelligenceAvailability = {
|
|
20
|
-
available: boolean;
|
|
21
|
-
reason: string;
|
|
22
|
-
};
|
|
23
|
-
type AppleIntelligenceToolDefinition = {
|
|
24
|
-
name: string;
|
|
25
|
-
description?: string;
|
|
26
|
-
parameters: JSONSchema7;
|
|
27
|
-
};
|
|
28
|
-
type AppleIntelligenceToolCall = {
|
|
29
|
-
id: string;
|
|
30
|
-
type: "function";
|
|
31
|
-
function: {
|
|
32
|
-
name: string;
|
|
33
|
-
arguments: string;
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
type AppleIntelligenceGenerateOptions = {
|
|
37
|
-
messages: AppleIntelligenceMessage[];
|
|
38
|
-
tools?: AppleIntelligenceToolDefinition[];
|
|
39
|
-
schema?: JSONSchema7;
|
|
40
|
-
temperature?: number;
|
|
41
|
-
maxTokens?: number;
|
|
42
|
-
stopAfterToolCalls?: boolean;
|
|
43
|
-
};
|
|
44
|
-
type AppleIntelligenceGenerateResult = {
|
|
45
|
-
text: string;
|
|
46
|
-
toolCalls?: AppleIntelligenceToolCall[];
|
|
47
|
-
object?: unknown;
|
|
48
|
-
};
|
|
49
|
-
type AppleIntelligenceStreamEvent = {
|
|
50
|
-
type: "text";
|
|
51
|
-
text: string;
|
|
52
|
-
} | {
|
|
53
|
-
type: "tool-call";
|
|
54
|
-
toolCallId: string;
|
|
55
|
-
toolName: string;
|
|
56
|
-
args: Record<string, unknown>;
|
|
57
|
-
} | {
|
|
58
|
-
type: "done";
|
|
59
|
-
} | {
|
|
60
|
-
type: "error";
|
|
61
|
-
message: string;
|
|
62
|
-
};
|
|
63
|
-
type AppleIntelligenceStreamOptions = {
|
|
64
|
-
messages: AppleIntelligenceMessage[];
|
|
65
|
-
tools?: AppleIntelligenceToolDefinition[];
|
|
66
|
-
temperature?: number;
|
|
67
|
-
maxTokens?: number;
|
|
68
|
-
stopAfterToolCalls?: boolean;
|
|
69
|
-
};
|
|
70
|
-
interface AppleIntelligenceTransport {
|
|
71
|
-
checkAvailability(): Promise<AppleIntelligenceAvailability>;
|
|
72
|
-
generate(options: AppleIntelligenceGenerateOptions): Promise<AppleIntelligenceGenerateResult>;
|
|
73
|
-
stream(options: AppleIntelligenceStreamOptions): AsyncIterable<AppleIntelligenceStreamEvent>;
|
|
74
|
-
}
|
|
75
|
-
//#endregion
|
|
76
|
-
//#region src/tauri.d.ts
|
|
77
|
-
type TauriAppleIntelligenceTransportOptions = {
|
|
78
|
-
commandPrefix?: string;
|
|
79
|
-
};
|
|
80
|
-
declare function createTauriAppleIntelligenceTransport(options?: TauriAppleIntelligenceTransportOptions): AppleIntelligenceTransport;
|
|
81
|
-
//#endregion
|
|
82
|
-
//#region src/provider.d.ts
|
|
83
|
-
type AppleIntelligenceModelId = "apple-on-device" | (string & {});
|
|
84
|
-
type AppleIntelligenceSettings = {
|
|
85
|
-
temperature?: number;
|
|
86
|
-
maxTokens?: number;
|
|
87
|
-
requireAvailability?: boolean;
|
|
88
|
-
};
|
|
89
|
-
type AppleIntelligenceProviderSettings = {
|
|
90
|
-
transport: AppleIntelligenceTransport;
|
|
91
|
-
generateId?: () => string;
|
|
92
|
-
};
|
|
93
|
-
interface AppleIntelligenceProvider {
|
|
94
|
-
(modelId: AppleIntelligenceModelId, settings?: AppleIntelligenceSettings): AppleIntelligenceChatLanguageModel;
|
|
95
|
-
languageModel(modelId: AppleIntelligenceModelId, settings?: AppleIntelligenceSettings): AppleIntelligenceChatLanguageModel;
|
|
96
|
-
chat(modelId: AppleIntelligenceModelId, settings?: AppleIntelligenceSettings): AppleIntelligenceChatLanguageModel;
|
|
97
|
-
}
|
|
98
|
-
declare function createAppleIntelligenceProvider(settings: AppleIntelligenceProviderSettings): AppleIntelligenceProvider;
|
|
99
|
-
declare class AppleIntelligenceChatLanguageModel implements LanguageModelV3 {
|
|
100
|
-
readonly specificationVersion = "v3";
|
|
101
|
-
readonly provider = "apple-intelligence";
|
|
102
|
-
readonly modelId: string;
|
|
103
|
-
readonly defaultObjectGenerationMode = "json";
|
|
104
|
-
supportsImageUrls: boolean;
|
|
105
|
-
supportsStructuredOutputs: boolean;
|
|
106
|
-
private readonly settings;
|
|
107
|
-
private readonly transport;
|
|
108
|
-
private readonly generateId;
|
|
109
|
-
constructor(modelId: AppleIntelligenceModelId, settings: AppleIntelligenceSettings, providerSettings: AppleIntelligenceProviderSettings);
|
|
110
|
-
supportedUrls: Record<string, RegExp[]> | PromiseLike<Record<string, RegExp[]>>;
|
|
111
|
-
doGenerate(options: LanguageModelV3CallOptions): Promise<{
|
|
112
|
-
content: Array<LanguageModelV3Content>;
|
|
113
|
-
finishReason: LanguageModelV3FinishReason;
|
|
114
|
-
usage: LanguageModelV3Usage;
|
|
115
|
-
providerMetadata?: SharedV3ProviderMetadata;
|
|
116
|
-
request?: {
|
|
117
|
-
body?: unknown;
|
|
118
|
-
};
|
|
119
|
-
response?: LanguageModelV3ResponseMetadata & {
|
|
120
|
-
headers?: SharedV3Headers;
|
|
121
|
-
body?: unknown;
|
|
122
|
-
};
|
|
123
|
-
warnings: Array<SharedV3Warning>;
|
|
124
|
-
}>;
|
|
125
|
-
doStream(options: LanguageModelV3CallOptions): Promise<{
|
|
126
|
-
stream: ReadableStream<LanguageModelV3StreamPart>;
|
|
127
|
-
}>;
|
|
128
|
-
supportsUrl?(_url: typeof URL): boolean;
|
|
129
|
-
private assertAvailability;
|
|
130
|
-
private handleStructuredGeneration;
|
|
131
|
-
private handleRegularGeneration;
|
|
132
|
-
private convertTools;
|
|
133
|
-
private convertPromptToMessages;
|
|
134
|
-
private convertAssistantMessage;
|
|
135
|
-
private convertToolMessage;
|
|
136
|
-
private formatToolResultOutput;
|
|
137
|
-
private createStreamFromEvents;
|
|
138
|
-
private createStreamFromChunks;
|
|
139
|
-
private emptyUsage;
|
|
140
|
-
}
|
|
141
|
-
//#endregion
|
|
142
|
-
export { type AppleIntelligenceAvailability, AppleIntelligenceChatLanguageModel, type AppleIntelligenceGenerateOptions, type AppleIntelligenceGenerateResult, type AppleIntelligenceMessage, type AppleIntelligenceStreamEvent, type AppleIntelligenceStreamOptions, type AppleIntelligenceToolCall, type AppleIntelligenceToolDefinition, type AppleIntelligenceTransport, type TauriAppleIntelligenceTransportOptions, createAppleIntelligenceProvider, createTauriAppleIntelligenceTransport };
|
|
143
|
-
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/transport.ts","../src/tauri.ts","../src/provider.ts"],"mappings":";;;;KAEY,wBAAA;EACV,IAAA;EACA,OAAA;EACA,IAAA;EACA,UAAA;EACA,SAAA,GAAY,KAAA;IACV,EAAA;IACA,IAAA;IACA,QAAA;MACE,IAAA;MACA,SAAA;IAAA;EAAA;AAAA;AAAA,KAKM,6BAAA;EACV,SAAA;EACA,MAAA;AAAA;AAAA,KAGU,+BAAA;EACV,IAAA;EACA,WAAA;EACA,UAAA,EAAY,WAAA;AAAA;AAAA,KAGF,yBAAA;EACV,EAAA;EACA,IAAA;EACA,QAAA;IACE,IAAA;IACA,SAAA;EAAA;AAAA;AAAA,KAIQ,gCAAA;EACV,QAAA,EAAU,wBAAA;EACV,KAAA,GAAQ,+BAAA;EACR,MAAA,GAAS,WAAA;EACT,WAAA;EACA,SAAA;EACA,kBAAA;AAAA;AAAA,KAGU,+BAAA;EACV,IAAA;EACA,SAAA,GAAY,yBAAA;EACZ,MAAA;AAAA;AAAA,KAGU,4BAAA;EACN,IAAA;EAAc,IAAA;AAAA;EAEd,IAAA;EACA,UAAA;EACA,QAAA;EACA,IAAA,EAAM,MAAA;AAAA;EAEN,IAAA;AAAA;EACA,IAAA;EAAe,OAAA;AAAA;AAAA,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ACf,YAAA,EAAc,2BAAA;IACd,KAAA,EAAO,oBAAA;IACP,gBAAA,GAAmB,wBAAA;IACnB,OAAA;MAAY,IAAA;IAAA;IACZ,QAAA,GAAW,+BAAA;MACT,OAAA,GAAU,eAAA;MACV,IAAA;IAAA;IAEF,QAAA,EAAU,KAAA,CAAM,eAAA;EAAA;EAeZ,QAAA,CACJ,OAAA,EAAS,0BAAA,GACR,OAAA;IAAU,MAAA,EAAQ,cAAA,CAAe,yBAAA;EAAA;EA6BpC,WAAA,CAAA,CAAa,IAAA,SAAa,GAAA;EAAA,QAIZ,kBAAA;EAAA,QAeA,0BAAA;EAAA,QA6CA,uBAAA;EAAA,QA+CN,YAAA;EAAA,QAkBA,uBAAA;EAAA,QAkCA,uBAAA;EAAA,QAiDA,kBAAA;EAAA,QA6CA,sBAAA;EAAA,QAkCA,sBAAA;EAAA,QA6DA,sBAAA;EAAA,QAkDA,UAAA;AAAA"}
|
package/dist/index.d.mts
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import { JSONSchema7 } from "json-schema";
|
|
2
|
-
import { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3Content, LanguageModelV3FinishReason, LanguageModelV3ResponseMetadata, LanguageModelV3StreamPart, LanguageModelV3Usage, SharedV3Headers, SharedV3ProviderMetadata, SharedV3Warning } from "@ai-sdk/provider";
|
|
3
|
-
|
|
4
|
-
//#region src/transport.d.ts
|
|
5
|
-
type AppleIntelligenceMessage = {
|
|
6
|
-
role: "system" | "user" | "assistant" | "tool" | "tool_calls";
|
|
7
|
-
content?: string;
|
|
8
|
-
name?: string;
|
|
9
|
-
toolCallId?: string;
|
|
10
|
-
toolCalls?: Array<{
|
|
11
|
-
id: string;
|
|
12
|
-
type: "function";
|
|
13
|
-
function: {
|
|
14
|
-
name: string;
|
|
15
|
-
arguments: string;
|
|
16
|
-
};
|
|
17
|
-
}>;
|
|
18
|
-
};
|
|
19
|
-
type AppleIntelligenceAvailability = {
|
|
20
|
-
available: boolean;
|
|
21
|
-
reason: string;
|
|
22
|
-
};
|
|
23
|
-
type AppleIntelligenceToolDefinition = {
|
|
24
|
-
name: string;
|
|
25
|
-
description?: string;
|
|
26
|
-
parameters: JSONSchema7;
|
|
27
|
-
};
|
|
28
|
-
type AppleIntelligenceToolCall = {
|
|
29
|
-
id: string;
|
|
30
|
-
type: "function";
|
|
31
|
-
function: {
|
|
32
|
-
name: string;
|
|
33
|
-
arguments: string;
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
type AppleIntelligenceGenerateOptions = {
|
|
37
|
-
messages: AppleIntelligenceMessage[];
|
|
38
|
-
tools?: AppleIntelligenceToolDefinition[];
|
|
39
|
-
schema?: JSONSchema7;
|
|
40
|
-
temperature?: number;
|
|
41
|
-
maxTokens?: number;
|
|
42
|
-
stopAfterToolCalls?: boolean;
|
|
43
|
-
};
|
|
44
|
-
type AppleIntelligenceGenerateResult = {
|
|
45
|
-
text: string;
|
|
46
|
-
toolCalls?: AppleIntelligenceToolCall[];
|
|
47
|
-
object?: unknown;
|
|
48
|
-
};
|
|
49
|
-
type AppleIntelligenceStreamEvent = {
|
|
50
|
-
type: "text";
|
|
51
|
-
text: string;
|
|
52
|
-
} | {
|
|
53
|
-
type: "tool-call";
|
|
54
|
-
toolCallId: string;
|
|
55
|
-
toolName: string;
|
|
56
|
-
args: Record<string, unknown>;
|
|
57
|
-
} | {
|
|
58
|
-
type: "done";
|
|
59
|
-
} | {
|
|
60
|
-
type: "error";
|
|
61
|
-
message: string;
|
|
62
|
-
};
|
|
63
|
-
type AppleIntelligenceStreamOptions = {
|
|
64
|
-
messages: AppleIntelligenceMessage[];
|
|
65
|
-
tools?: AppleIntelligenceToolDefinition[];
|
|
66
|
-
temperature?: number;
|
|
67
|
-
maxTokens?: number;
|
|
68
|
-
stopAfterToolCalls?: boolean;
|
|
69
|
-
};
|
|
70
|
-
interface AppleIntelligenceTransport {
|
|
71
|
-
checkAvailability(): Promise<AppleIntelligenceAvailability>;
|
|
72
|
-
generate(options: AppleIntelligenceGenerateOptions): Promise<AppleIntelligenceGenerateResult>;
|
|
73
|
-
stream(options: AppleIntelligenceStreamOptions): AsyncIterable<AppleIntelligenceStreamEvent>;
|
|
74
|
-
}
|
|
75
|
-
//#endregion
|
|
76
|
-
//#region src/tauri.d.ts
|
|
77
|
-
type TauriAppleIntelligenceTransportOptions = {
|
|
78
|
-
commandPrefix?: string;
|
|
79
|
-
};
|
|
80
|
-
declare function createTauriAppleIntelligenceTransport(options?: TauriAppleIntelligenceTransportOptions): AppleIntelligenceTransport;
|
|
81
|
-
//#endregion
|
|
82
|
-
//#region src/provider.d.ts
|
|
83
|
-
type AppleIntelligenceModelId = "apple-on-device" | (string & {});
|
|
84
|
-
type AppleIntelligenceSettings = {
|
|
85
|
-
temperature?: number;
|
|
86
|
-
maxTokens?: number;
|
|
87
|
-
requireAvailability?: boolean;
|
|
88
|
-
};
|
|
89
|
-
type AppleIntelligenceProviderSettings = {
|
|
90
|
-
transport: AppleIntelligenceTransport;
|
|
91
|
-
generateId?: () => string;
|
|
92
|
-
};
|
|
93
|
-
interface AppleIntelligenceProvider {
|
|
94
|
-
(modelId: AppleIntelligenceModelId, settings?: AppleIntelligenceSettings): AppleIntelligenceChatLanguageModel;
|
|
95
|
-
languageModel(modelId: AppleIntelligenceModelId, settings?: AppleIntelligenceSettings): AppleIntelligenceChatLanguageModel;
|
|
96
|
-
chat(modelId: AppleIntelligenceModelId, settings?: AppleIntelligenceSettings): AppleIntelligenceChatLanguageModel;
|
|
97
|
-
}
|
|
98
|
-
declare function createAppleIntelligenceProvider(settings: AppleIntelligenceProviderSettings): AppleIntelligenceProvider;
|
|
99
|
-
declare class AppleIntelligenceChatLanguageModel implements LanguageModelV3 {
|
|
100
|
-
readonly specificationVersion = "v3";
|
|
101
|
-
readonly provider = "apple-intelligence";
|
|
102
|
-
readonly modelId: string;
|
|
103
|
-
readonly defaultObjectGenerationMode = "json";
|
|
104
|
-
supportsImageUrls: boolean;
|
|
105
|
-
supportsStructuredOutputs: boolean;
|
|
106
|
-
private readonly settings;
|
|
107
|
-
private readonly transport;
|
|
108
|
-
private readonly generateId;
|
|
109
|
-
constructor(modelId: AppleIntelligenceModelId, settings: AppleIntelligenceSettings, providerSettings: AppleIntelligenceProviderSettings);
|
|
110
|
-
supportedUrls: Record<string, RegExp[]> | PromiseLike<Record<string, RegExp[]>>;
|
|
111
|
-
doGenerate(options: LanguageModelV3CallOptions): Promise<{
|
|
112
|
-
content: Array<LanguageModelV3Content>;
|
|
113
|
-
finishReason: LanguageModelV3FinishReason;
|
|
114
|
-
usage: LanguageModelV3Usage;
|
|
115
|
-
providerMetadata?: SharedV3ProviderMetadata;
|
|
116
|
-
request?: {
|
|
117
|
-
body?: unknown;
|
|
118
|
-
};
|
|
119
|
-
response?: LanguageModelV3ResponseMetadata & {
|
|
120
|
-
headers?: SharedV3Headers;
|
|
121
|
-
body?: unknown;
|
|
122
|
-
};
|
|
123
|
-
warnings: Array<SharedV3Warning>;
|
|
124
|
-
}>;
|
|
125
|
-
doStream(options: LanguageModelV3CallOptions): Promise<{
|
|
126
|
-
stream: ReadableStream<LanguageModelV3StreamPart>;
|
|
127
|
-
}>;
|
|
128
|
-
supportsUrl?(_url: typeof URL): boolean;
|
|
129
|
-
private assertAvailability;
|
|
130
|
-
private handleStructuredGeneration;
|
|
131
|
-
private handleRegularGeneration;
|
|
132
|
-
private convertTools;
|
|
133
|
-
private convertPromptToMessages;
|
|
134
|
-
private convertAssistantMessage;
|
|
135
|
-
private convertToolMessage;
|
|
136
|
-
private formatToolResultOutput;
|
|
137
|
-
private createStreamFromEvents;
|
|
138
|
-
private createStreamFromChunks;
|
|
139
|
-
private emptyUsage;
|
|
140
|
-
}
|
|
141
|
-
//#endregion
|
|
142
|
-
export { type AppleIntelligenceAvailability, AppleIntelligenceChatLanguageModel, type AppleIntelligenceGenerateOptions, type AppleIntelligenceGenerateResult, type AppleIntelligenceMessage, type AppleIntelligenceStreamEvent, type AppleIntelligenceStreamOptions, type AppleIntelligenceToolCall, type AppleIntelligenceToolDefinition, type AppleIntelligenceTransport, type TauriAppleIntelligenceTransportOptions, createAppleIntelligenceProvider, createTauriAppleIntelligenceTransport };
|
|
143
|
-
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/transport.ts","../src/tauri.ts","../src/provider.ts"],"mappings":";;;;KAEY,wBAAA;EACV,IAAA;EACA,OAAA;EACA,IAAA;EACA,UAAA;EACA,SAAA,GAAY,KAAA;IACV,EAAA;IACA,IAAA;IACA,QAAA;MACE,IAAA;MACA,SAAA;IAAA;EAAA;AAAA;AAAA,KAKM,6BAAA;EACV,SAAA;EACA,MAAA;AAAA;AAAA,KAGU,+BAAA;EACV,IAAA;EACA,WAAA;EACA,UAAA,EAAY,WAAA;AAAA;AAAA,KAGF,yBAAA;EACV,EAAA;EACA,IAAA;EACA,QAAA;IACE,IAAA;IACA,SAAA;EAAA;AAAA;AAAA,KAIQ,gCAAA;EACV,QAAA,EAAU,wBAAA;EACV,KAAA,GAAQ,+BAAA;EACR,MAAA,GAAS,WAAA;EACT,WAAA;EACA,SAAA;EACA,kBAAA;AAAA;AAAA,KAGU,+BAAA;EACV,IAAA;EACA,SAAA,GAAY,yBAAA;EACZ,MAAA;AAAA;AAAA,KAGU,4BAAA;EACN,IAAA;EAAc,IAAA;AAAA;EAEd,IAAA;EACA,UAAA;EACA,QAAA;EACA,IAAA,EAAM,MAAA;AAAA;EAEN,IAAA;AAAA;EACA,IAAA;EAAe,OAAA;AAAA;AAAA,KAET,8BAAA;EACV,QAAA,EAAU,wBAAA;EACV,KAAA,GAAQ,+BAAA;EACR,WAAA;EACA,SAAA;EACA,kBAAA;AAAA;AAAA,UAGe,0BAAA;EACf,iBAAA,IAAqB,OAAA,CAAQ,6BAAA;EAC7B,QAAA,CAAS,OAAA,EAAS,gCAAA,GAAmC,OAA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;EAeZ,QAAA,CACJ,OAAA,EAAS,0BAAA,GACR,OAAA;IAAU,MAAA,EAAQ,cAAA,CAAe,yBAAA;EAAA;EA6BpC,WAAA,CAAA,CAAa,IAAA,SAAa,GAAA;EAAA,QAIZ,kBAAA;EAAA,QAeA,0BAAA;EAAA,QA6CA,uBAAA;EAAA,QA+CN,YAAA;EAAA,QAkBA,uBAAA;EAAA,QAkCA,uBAAA;EAAA,QAiDA,kBAAA;EAAA,QA6CA,sBAAA;EAAA,QAkCA,sBAAA;EAAA,QA6DA,sBAAA;EAAA,QAkDA,UAAA;AAAA"}
|
package/dist/index.mjs
DELETED
|
@@ -1,415 +0,0 @@
|
|
|
1
|
-
import { generateId } from "@ai-sdk/provider-utils";
|
|
2
|
-
import { invoke } from "@tauri-apps/api/core";
|
|
3
|
-
import { listen } from "@tauri-apps/api/event";
|
|
4
|
-
|
|
5
|
-
//#region src/provider.ts
|
|
6
|
-
function createAppleIntelligenceProvider(settings) {
|
|
7
|
-
const createModel = (modelId, modelSettings = {}) => new AppleIntelligenceChatLanguageModel(modelId, modelSettings, settings);
|
|
8
|
-
const provider = function(modelId, modelSettings) {
|
|
9
|
-
if (new.target) throw new Error("The Apple Intelligence provider cannot be called with the new keyword.");
|
|
10
|
-
return createModel(modelId, modelSettings);
|
|
11
|
-
};
|
|
12
|
-
provider.chat = createModel;
|
|
13
|
-
provider.languageModel = createModel;
|
|
14
|
-
return provider;
|
|
15
|
-
}
|
|
16
|
-
var AppleIntelligenceChatLanguageModel = class {
|
|
17
|
-
specificationVersion = "v3";
|
|
18
|
-
provider = "apple-intelligence";
|
|
19
|
-
modelId;
|
|
20
|
-
defaultObjectGenerationMode = "json";
|
|
21
|
-
supportsImageUrls = false;
|
|
22
|
-
supportsStructuredOutputs = true;
|
|
23
|
-
settings;
|
|
24
|
-
transport;
|
|
25
|
-
generateId;
|
|
26
|
-
constructor(modelId, settings, providerSettings) {
|
|
27
|
-
this.modelId = modelId;
|
|
28
|
-
this.settings = settings;
|
|
29
|
-
this.transport = providerSettings.transport;
|
|
30
|
-
this.generateId = providerSettings.generateId ?? generateId;
|
|
31
|
-
}
|
|
32
|
-
supportedUrls = {};
|
|
33
|
-
async doGenerate(options) {
|
|
34
|
-
await this.assertAvailability();
|
|
35
|
-
if (options.responseFormat?.type === "json" && Boolean(options.responseFormat.schema)) return this.handleStructuredGeneration(options);
|
|
36
|
-
return this.handleRegularGeneration(options);
|
|
37
|
-
}
|
|
38
|
-
async doStream(options) {
|
|
39
|
-
await this.assertAvailability();
|
|
40
|
-
const messages = this.convertPromptToMessages(options.prompt);
|
|
41
|
-
const tools = options.tools?.length ? this.convertTools(options.tools) : void 0;
|
|
42
|
-
return { stream: tools?.length ? this.createStreamFromEvents(this.transport.stream({
|
|
43
|
-
messages,
|
|
44
|
-
tools,
|
|
45
|
-
temperature: this.settings.temperature,
|
|
46
|
-
maxTokens: options.maxOutputTokens ?? this.settings.maxTokens,
|
|
47
|
-
stopAfterToolCalls: true
|
|
48
|
-
})) : this.createStreamFromChunks(this.transport.stream({
|
|
49
|
-
messages,
|
|
50
|
-
temperature: this.settings.temperature,
|
|
51
|
-
maxTokens: options.maxOutputTokens ?? this.settings.maxTokens
|
|
52
|
-
})) };
|
|
53
|
-
}
|
|
54
|
-
supportsUrl(_url) {
|
|
55
|
-
return true;
|
|
56
|
-
}
|
|
57
|
-
async assertAvailability() {
|
|
58
|
-
if (this.settings.requireAvailability === false) return {
|
|
59
|
-
available: true,
|
|
60
|
-
reason: "Skipped availability check"
|
|
61
|
-
};
|
|
62
|
-
const availability = await this.transport.checkAvailability();
|
|
63
|
-
if (!availability.available) throw new Error(`Apple Intelligence not available: ${availability.reason}`);
|
|
64
|
-
return availability;
|
|
65
|
-
}
|
|
66
|
-
async handleStructuredGeneration(options) {
|
|
67
|
-
const schema = options.responseFormat?.schema;
|
|
68
|
-
if (!schema) throw new Error("Structured generation requires a JSON schema in responseFormat.");
|
|
69
|
-
const messages = this.convertPromptToMessages(options.prompt);
|
|
70
|
-
const result = await this.transport.generate({
|
|
71
|
-
messages,
|
|
72
|
-
schema,
|
|
73
|
-
temperature: this.settings.temperature,
|
|
74
|
-
maxTokens: options.maxOutputTokens ?? this.settings.maxTokens
|
|
75
|
-
});
|
|
76
|
-
if (result.object !== void 0) return {
|
|
77
|
-
content: [{
|
|
78
|
-
type: "text",
|
|
79
|
-
text: JSON.stringify(result.object)
|
|
80
|
-
}],
|
|
81
|
-
finishReason: {
|
|
82
|
-
unified: "stop",
|
|
83
|
-
raw: "stop"
|
|
84
|
-
},
|
|
85
|
-
usage: this.emptyUsage(),
|
|
86
|
-
warnings: []
|
|
87
|
-
};
|
|
88
|
-
return {
|
|
89
|
-
content: [{
|
|
90
|
-
type: "text",
|
|
91
|
-
text: result.text ?? ""
|
|
92
|
-
}],
|
|
93
|
-
finishReason: {
|
|
94
|
-
unified: "stop",
|
|
95
|
-
raw: "stop"
|
|
96
|
-
},
|
|
97
|
-
usage: this.emptyUsage(),
|
|
98
|
-
warnings: []
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
async handleRegularGeneration(options) {
|
|
102
|
-
const messages = this.convertPromptToMessages(options.prompt);
|
|
103
|
-
const tools = options.tools?.length ? this.convertTools(options.tools) : void 0;
|
|
104
|
-
const result = await this.transport.generate({
|
|
105
|
-
messages,
|
|
106
|
-
tools,
|
|
107
|
-
temperature: this.settings.temperature,
|
|
108
|
-
maxTokens: options.maxOutputTokens ?? this.settings.maxTokens,
|
|
109
|
-
stopAfterToolCalls: true
|
|
110
|
-
});
|
|
111
|
-
if (result.toolCalls?.length) return {
|
|
112
|
-
content: result.toolCalls.map((call) => ({
|
|
113
|
-
type: "tool-call",
|
|
114
|
-
toolCallId: call.id,
|
|
115
|
-
toolName: call.function.name,
|
|
116
|
-
input: call.function.arguments
|
|
117
|
-
})),
|
|
118
|
-
finishReason: {
|
|
119
|
-
unified: "tool-calls",
|
|
120
|
-
raw: "tool-calls"
|
|
121
|
-
},
|
|
122
|
-
usage: this.emptyUsage(),
|
|
123
|
-
warnings: []
|
|
124
|
-
};
|
|
125
|
-
return {
|
|
126
|
-
content: [{
|
|
127
|
-
type: "text",
|
|
128
|
-
text: result.text ?? ""
|
|
129
|
-
}],
|
|
130
|
-
finishReason: {
|
|
131
|
-
unified: "stop",
|
|
132
|
-
raw: "stop"
|
|
133
|
-
},
|
|
134
|
-
usage: this.emptyUsage(),
|
|
135
|
-
warnings: []
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
convertTools(tools) {
|
|
139
|
-
return tools ? tools.map((tool) => {
|
|
140
|
-
if (tool.type !== "function") throw new Error(`Unsupported tool type: ${tool.type}`);
|
|
141
|
-
return {
|
|
142
|
-
name: tool.name,
|
|
143
|
-
description: tool.description,
|
|
144
|
-
parameters: tool.inputSchema
|
|
145
|
-
};
|
|
146
|
-
}) : [];
|
|
147
|
-
}
|
|
148
|
-
convertPromptToMessages(prompt) {
|
|
149
|
-
return prompt.map((message) => {
|
|
150
|
-
switch (message.role) {
|
|
151
|
-
case "system": return {
|
|
152
|
-
role: "system",
|
|
153
|
-
content: message.content
|
|
154
|
-
};
|
|
155
|
-
case "user": return {
|
|
156
|
-
role: "user",
|
|
157
|
-
content: Array.isArray(message.content) ? message.content.map((part) => part.type === "text" ? part.text : "[unsupported content]").join("\n") : message.content
|
|
158
|
-
};
|
|
159
|
-
case "assistant": return this.convertAssistantMessage(message);
|
|
160
|
-
case "tool": return this.convertToolMessage(message);
|
|
161
|
-
default: return {
|
|
162
|
-
role: "user",
|
|
163
|
-
content: String(message.content ?? "")
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
convertAssistantMessage(message) {
|
|
169
|
-
if (Array.isArray(message.content)) {
|
|
170
|
-
const toolCalls = message.content.filter((part) => part.type === "tool-call");
|
|
171
|
-
const textParts = message.content.filter((part) => part.type === "text");
|
|
172
|
-
if (toolCalls.length > 0) return {
|
|
173
|
-
role: "assistant",
|
|
174
|
-
content: textParts.map((part) => part.text).join("\n") || "",
|
|
175
|
-
toolCalls: toolCalls.map((part) => ({
|
|
176
|
-
id: part.toolCallId,
|
|
177
|
-
type: "function",
|
|
178
|
-
function: {
|
|
179
|
-
name: part.toolName,
|
|
180
|
-
arguments: typeof part.input === "string" ? part.input : JSON.stringify(part.input)
|
|
181
|
-
}
|
|
182
|
-
}))
|
|
183
|
-
};
|
|
184
|
-
return {
|
|
185
|
-
role: "assistant",
|
|
186
|
-
content: message.content.map((part) => {
|
|
187
|
-
switch (part.type) {
|
|
188
|
-
case "text":
|
|
189
|
-
case "reasoning": return part.text;
|
|
190
|
-
default: return `[unsupported content - ${part.type}]`;
|
|
191
|
-
}
|
|
192
|
-
}).join("\n")
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
return {
|
|
196
|
-
role: "assistant",
|
|
197
|
-
content: message.content || ""
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
convertToolMessage(message) {
|
|
201
|
-
const toolCalls = message.content.map((part) => {
|
|
202
|
-
if (part.type === "tool-result") return {
|
|
203
|
-
id: part.toolCallId,
|
|
204
|
-
toolName: part.toolName,
|
|
205
|
-
segments: [{
|
|
206
|
-
type: "text",
|
|
207
|
-
text: this.formatToolResultOutput(part.output)
|
|
208
|
-
}]
|
|
209
|
-
};
|
|
210
|
-
if (part.type === "tool-approval-response") return {
|
|
211
|
-
id: part.approvalId,
|
|
212
|
-
toolName: "tool-approval",
|
|
213
|
-
segments: [{
|
|
214
|
-
type: "text",
|
|
215
|
-
text: part.approved ? `Tool approval granted${part.reason ? `: ${part.reason}` : ""}` : `Tool approval denied${part.reason ? `: ${part.reason}` : ""}`
|
|
216
|
-
}]
|
|
217
|
-
};
|
|
218
|
-
return null;
|
|
219
|
-
}).filter(Boolean);
|
|
220
|
-
return {
|
|
221
|
-
role: "tool",
|
|
222
|
-
content: JSON.stringify({ tool_calls: toolCalls })
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
formatToolResultOutput(output) {
|
|
226
|
-
switch (output.type) {
|
|
227
|
-
case "text":
|
|
228
|
-
case "error-text": return output.value;
|
|
229
|
-
case "json":
|
|
230
|
-
case "error-json": return JSON.stringify(output.value);
|
|
231
|
-
case "execution-denied": return output.reason ? `Tool execution denied: ${output.reason}` : "Tool execution denied";
|
|
232
|
-
case "content": return output.value.map((part) => {
|
|
233
|
-
if (part.type === "text") return part.text;
|
|
234
|
-
if (part.type === "file-data") return `[file-data:${part.mediaType}]`;
|
|
235
|
-
if (part.type === "file-url") return `[file-url:${part.url}]`;
|
|
236
|
-
return "[file]";
|
|
237
|
-
}).join("\n");
|
|
238
|
-
default: return "[unsupported tool output]";
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
createStreamFromEvents(nativeStream) {
|
|
242
|
-
return new ReadableStream({ async start(controller) {
|
|
243
|
-
controller.enqueue({
|
|
244
|
-
type: "stream-start",
|
|
245
|
-
warnings: []
|
|
246
|
-
});
|
|
247
|
-
const textId = crypto.randomUUID();
|
|
248
|
-
let hasText = false;
|
|
249
|
-
let hasToolCalls = false;
|
|
250
|
-
try {
|
|
251
|
-
for await (const event of nativeStream) if (event.type === "text") {
|
|
252
|
-
if (!hasText) {
|
|
253
|
-
controller.enqueue({
|
|
254
|
-
type: "text-start",
|
|
255
|
-
id: textId
|
|
256
|
-
});
|
|
257
|
-
hasText = true;
|
|
258
|
-
}
|
|
259
|
-
controller.enqueue({
|
|
260
|
-
type: "text-delta",
|
|
261
|
-
delta: event.text,
|
|
262
|
-
id: textId
|
|
263
|
-
});
|
|
264
|
-
} else if (event.type === "tool-call") {
|
|
265
|
-
hasToolCalls = true;
|
|
266
|
-
controller.enqueue({
|
|
267
|
-
type: "tool-call",
|
|
268
|
-
toolCallId: event.toolCallId,
|
|
269
|
-
toolName: event.toolName,
|
|
270
|
-
input: JSON.stringify(event.args)
|
|
271
|
-
});
|
|
272
|
-
} else if (event.type === "error") {
|
|
273
|
-
controller.error(new Error(event.message));
|
|
274
|
-
return;
|
|
275
|
-
} else if (event.type === "done") break;
|
|
276
|
-
if (hasText) controller.enqueue({
|
|
277
|
-
type: "text-end",
|
|
278
|
-
id: textId
|
|
279
|
-
});
|
|
280
|
-
controller.enqueue({
|
|
281
|
-
type: "finish",
|
|
282
|
-
finishReason: hasToolCalls ? {
|
|
283
|
-
unified: "tool-calls",
|
|
284
|
-
raw: "tool-calls"
|
|
285
|
-
} : {
|
|
286
|
-
unified: "stop",
|
|
287
|
-
raw: "stop"
|
|
288
|
-
},
|
|
289
|
-
usage: {
|
|
290
|
-
inputTokens: void 0,
|
|
291
|
-
outputTokens: void 0,
|
|
292
|
-
totalTokens: void 0
|
|
293
|
-
}
|
|
294
|
-
});
|
|
295
|
-
controller.close();
|
|
296
|
-
} catch (err) {
|
|
297
|
-
controller.error(err);
|
|
298
|
-
}
|
|
299
|
-
} });
|
|
300
|
-
}
|
|
301
|
-
createStreamFromChunks(stream) {
|
|
302
|
-
return new ReadableStream({ async start(controller) {
|
|
303
|
-
controller.enqueue({
|
|
304
|
-
type: "stream-start",
|
|
305
|
-
warnings: []
|
|
306
|
-
});
|
|
307
|
-
const textId = crypto.randomUUID();
|
|
308
|
-
let hasText = false;
|
|
309
|
-
try {
|
|
310
|
-
for await (const event of stream) if (event.type === "text") {
|
|
311
|
-
if (!hasText) {
|
|
312
|
-
controller.enqueue({
|
|
313
|
-
type: "text-start",
|
|
314
|
-
id: textId
|
|
315
|
-
});
|
|
316
|
-
hasText = true;
|
|
317
|
-
}
|
|
318
|
-
controller.enqueue({
|
|
319
|
-
type: "text-delta",
|
|
320
|
-
delta: event.text,
|
|
321
|
-
id: textId
|
|
322
|
-
});
|
|
323
|
-
} else if (event.type === "error") {
|
|
324
|
-
controller.error(new Error(event.message));
|
|
325
|
-
return;
|
|
326
|
-
} else if (event.type === "done") break;
|
|
327
|
-
if (hasText) controller.enqueue({
|
|
328
|
-
type: "text-end",
|
|
329
|
-
id: textId
|
|
330
|
-
});
|
|
331
|
-
controller.enqueue({
|
|
332
|
-
type: "finish",
|
|
333
|
-
finishReason: {
|
|
334
|
-
unified: "stop",
|
|
335
|
-
raw: "stop"
|
|
336
|
-
},
|
|
337
|
-
usage: {
|
|
338
|
-
inputTokens: void 0,
|
|
339
|
-
outputTokens: void 0,
|
|
340
|
-
totalTokens: void 0
|
|
341
|
-
}
|
|
342
|
-
});
|
|
343
|
-
controller.close();
|
|
344
|
-
} catch (err) {
|
|
345
|
-
controller.error(err);
|
|
346
|
-
}
|
|
347
|
-
} });
|
|
348
|
-
}
|
|
349
|
-
emptyUsage() {
|
|
350
|
-
return {
|
|
351
|
-
inputTokens: void 0,
|
|
352
|
-
outputTokens: void 0,
|
|
353
|
-
totalTokens: void 0
|
|
354
|
-
};
|
|
355
|
-
}
|
|
356
|
-
};
|
|
357
|
-
|
|
358
|
-
//#endregion
|
|
359
|
-
//#region src/tauri.ts
|
|
360
|
-
function createTauriAppleIntelligenceTransport(options = {}) {
|
|
361
|
-
const prefix = options.commandPrefix ?? "apple_ai";
|
|
362
|
-
const command = (name) => `${prefix}_${name}`;
|
|
363
|
-
return {
|
|
364
|
-
async checkAvailability() {
|
|
365
|
-
return invoke(command("check_availability"));
|
|
366
|
-
},
|
|
367
|
-
async generate(request) {
|
|
368
|
-
return invoke(command("generate"), { request });
|
|
369
|
-
},
|
|
370
|
-
async *stream(request) {
|
|
371
|
-
const start = await invoke(command("stream"), { request });
|
|
372
|
-
const queue = [];
|
|
373
|
-
let done = false;
|
|
374
|
-
let pendingResolve = null;
|
|
375
|
-
const unlisten = await listen(start.eventName, (event) => {
|
|
376
|
-
const payload = event.payload;
|
|
377
|
-
if (pendingResolve) {
|
|
378
|
-
pendingResolve({
|
|
379
|
-
value: payload,
|
|
380
|
-
done: false
|
|
381
|
-
});
|
|
382
|
-
pendingResolve = null;
|
|
383
|
-
} else queue.push(payload);
|
|
384
|
-
if (payload.type === "done" || payload.type === "error") {
|
|
385
|
-
done = true;
|
|
386
|
-
unlisten();
|
|
387
|
-
}
|
|
388
|
-
});
|
|
389
|
-
try {
|
|
390
|
-
while (true) {
|
|
391
|
-
if (queue.length > 0) {
|
|
392
|
-
const value = queue.shift();
|
|
393
|
-
yield value;
|
|
394
|
-
if (value.type === "done" || value.type === "error") return;
|
|
395
|
-
continue;
|
|
396
|
-
}
|
|
397
|
-
if (done) return;
|
|
398
|
-
const value = await new Promise((resolve) => {
|
|
399
|
-
pendingResolve = resolve;
|
|
400
|
-
});
|
|
401
|
-
if (value.value) {
|
|
402
|
-
yield value.value;
|
|
403
|
-
if (value.value.type === "done" || value.value.type === "error") return;
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
} finally {
|
|
407
|
-
if (!done) unlisten();
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
};
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
//#endregion
|
|
414
|
-
export { AppleIntelligenceChatLanguageModel, createAppleIntelligenceProvider, createTauriAppleIntelligenceTransport };
|
|
415
|
-
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/provider.ts","../src/tauri.ts"],"sourcesContent":["import type {\n LanguageModelV3,\n LanguageModelV3CallOptions,\n LanguageModelV3Content,\n LanguageModelV3FinishReason,\n LanguageModelV3Message,\n LanguageModelV3ResponseMetadata,\n LanguageModelV3StreamPart,\n LanguageModelV3ToolResultOutput,\n LanguageModelV3Usage,\n SharedV3Headers,\n SharedV3ProviderMetadata,\n SharedV3Warning,\n} from \"@ai-sdk/provider\";\nimport { generateId } from \"@ai-sdk/provider-utils\";\nimport type { JSONSchema7 } from \"json-schema\";\nimport type {\n AppleIntelligenceAvailability,\n AppleIntelligenceMessage,\n AppleIntelligenceStreamEvent,\n AppleIntelligenceToolDefinition,\n AppleIntelligenceTransport,\n} from \"./transport\";\n\nexport type AppleIntelligenceModelId = \"apple-on-device\" | (string & {});\n\nexport type AppleIntelligenceSettings = {\n temperature?: number;\n maxTokens?: number;\n requireAvailability?: boolean;\n};\n\nexport type AppleIntelligenceProviderSettings = {\n transport: AppleIntelligenceTransport;\n generateId?: () => string;\n};\n\nexport interface AppleIntelligenceProvider {\n (\n modelId: AppleIntelligenceModelId,\n settings?: AppleIntelligenceSettings\n ): AppleIntelligenceChatLanguageModel;\n languageModel(\n modelId: AppleIntelligenceModelId,\n settings?: AppleIntelligenceSettings\n ): AppleIntelligenceChatLanguageModel;\n chat(\n modelId: AppleIntelligenceModelId,\n settings?: AppleIntelligenceSettings\n ): AppleIntelligenceChatLanguageModel;\n}\n\nexport function createAppleIntelligenceProvider(\n settings: AppleIntelligenceProviderSettings\n): AppleIntelligenceProvider {\n const createModel = (\n modelId: AppleIntelligenceModelId,\n modelSettings: AppleIntelligenceSettings = {}\n ) => new AppleIntelligenceChatLanguageModel(modelId, modelSettings, settings);\n\n const provider = function (\n modelId: AppleIntelligenceModelId,\n modelSettings?: AppleIntelligenceSettings\n ) {\n if (new.target) {\n throw new Error(\n \"The Apple Intelligence provider cannot be called with the new keyword.\"\n );\n }\n\n return createModel(modelId, modelSettings);\n } as AppleIntelligenceProvider;\n\n provider.chat = createModel;\n provider.languageModel = createModel;\n\n return provider;\n}\n\nexport class AppleIntelligenceChatLanguageModel implements LanguageModelV3 {\n readonly specificationVersion = \"v3\";\n readonly provider = \"apple-intelligence\";\n readonly modelId: string;\n readonly defaultObjectGenerationMode = \"json\";\n\n supportsImageUrls = false;\n supportsStructuredOutputs = true;\n\n private readonly settings: AppleIntelligenceSettings;\n private readonly transport: AppleIntelligenceTransport;\n private readonly generateId: () => string;\n\n constructor(\n modelId: AppleIntelligenceModelId,\n settings: AppleIntelligenceSettings,\n providerSettings: AppleIntelligenceProviderSettings\n ) {\n this.modelId = modelId;\n this.settings = settings;\n this.transport = providerSettings.transport;\n this.generateId = providerSettings.generateId ?? generateId;\n }\n\n supportedUrls:\n | Record<string, RegExp[]>\n | PromiseLike<Record<string, RegExp[]>> = {};\n\n async doGenerate(\n options: LanguageModelV3CallOptions\n ): Promise<{\n content: Array<LanguageModelV3Content>;\n finishReason: LanguageModelV3FinishReason;\n usage: LanguageModelV3Usage;\n providerMetadata?: SharedV3ProviderMetadata;\n request?: { body?: unknown };\n response?: LanguageModelV3ResponseMetadata & {\n headers?: SharedV3Headers;\n body?: unknown;\n };\n warnings: Array<SharedV3Warning>;\n }> {\n await this.assertAvailability();\n\n const isStructured =\n options.responseFormat?.type === \"json\" &&\n Boolean(options.responseFormat.schema);\n\n if (isStructured) {\n return this.handleStructuredGeneration(options);\n }\n\n return this.handleRegularGeneration(options);\n }\n\n async doStream(\n options: LanguageModelV3CallOptions\n ): Promise<{ stream: ReadableStream<LanguageModelV3StreamPart> }> {\n await this.assertAvailability();\n\n const messages = this.convertPromptToMessages(options.prompt);\n const tools = options.tools?.length\n ? this.convertTools(options.tools)\n : undefined;\n\n const stream = tools?.length\n ? this.createStreamFromEvents(\n this.transport.stream({\n messages,\n tools,\n temperature: this.settings.temperature,\n maxTokens: options.maxOutputTokens ?? this.settings.maxTokens,\n stopAfterToolCalls: true,\n })\n )\n : this.createStreamFromChunks(\n this.transport.stream({\n messages,\n temperature: this.settings.temperature,\n maxTokens: options.maxOutputTokens ?? this.settings.maxTokens,\n })\n );\n\n return { stream };\n }\n\n supportsUrl?(_url: typeof URL): boolean {\n return true;\n }\n\n private async assertAvailability(): Promise<AppleIntelligenceAvailability> {\n if (this.settings.requireAvailability === false) {\n return { available: true, reason: \"Skipped availability check\" };\n }\n\n const availability = await this.transport.checkAvailability();\n if (!availability.available) {\n throw new Error(\n `Apple Intelligence not available: ${availability.reason}`\n );\n }\n\n return availability;\n }\n\n private async handleStructuredGeneration(\n options: LanguageModelV3CallOptions\n ): Promise<{\n content: Array<LanguageModelV3Content>;\n finishReason: LanguageModelV3FinishReason;\n usage: LanguageModelV3Usage;\n warnings: Array<SharedV3Warning>;\n }> {\n const schema = options.responseFormat?.schema as JSONSchema7 | undefined;\n if (!schema) {\n throw new Error(\n \"Structured generation requires a JSON schema in responseFormat.\"\n );\n }\n\n const messages = this.convertPromptToMessages(options.prompt);\n const result = await this.transport.generate({\n messages,\n schema,\n temperature: this.settings.temperature,\n maxTokens: options.maxOutputTokens ?? this.settings.maxTokens,\n });\n\n if (result.object !== undefined) {\n return {\n content: [\n {\n type: \"text\",\n text: JSON.stringify(result.object),\n },\n ],\n finishReason: { unified: \"stop\", raw: \"stop\" },\n usage: this.emptyUsage(),\n warnings: [],\n };\n }\n\n return {\n content: [{ type: \"text\", text: result.text ?? \"\" }],\n finishReason: { unified: \"stop\", raw: \"stop\" },\n usage: this.emptyUsage(),\n warnings: [],\n };\n }\n\n private async handleRegularGeneration(\n options: LanguageModelV3CallOptions\n ): Promise<{\n content: Array<LanguageModelV3Content>;\n finishReason: LanguageModelV3FinishReason;\n usage: LanguageModelV3Usage;\n warnings: Array<SharedV3Warning>;\n }> {\n const messages = this.convertPromptToMessages(options.prompt);\n const tools = options.tools?.length\n ? this.convertTools(options.tools)\n : undefined;\n\n const result = await this.transport.generate({\n messages,\n tools,\n temperature: this.settings.temperature,\n maxTokens: options.maxOutputTokens ?? this.settings.maxTokens,\n stopAfterToolCalls: true,\n });\n\n if (result.toolCalls?.length) {\n const toolCallContent: LanguageModelV3Content[] = result.toolCalls.map(\n (call) => ({\n type: \"tool-call\",\n toolCallId: call.id,\n toolName: call.function.name,\n input: call.function.arguments,\n })\n );\n\n return {\n content: toolCallContent,\n finishReason: { unified: \"tool-calls\", raw: \"tool-calls\" },\n usage: this.emptyUsage(),\n warnings: [],\n };\n }\n\n return {\n content: [{ type: \"text\", text: result.text ?? \"\" }],\n finishReason: { unified: \"stop\", raw: \"stop\" },\n usage: this.emptyUsage(),\n warnings: [],\n };\n }\n\n private convertTools(\n tools: LanguageModelV3CallOptions[\"tools\"]\n ): AppleIntelligenceToolDefinition[] {\n return tools\n ? tools.map((tool) => {\n if (tool.type !== \"function\") {\n throw new Error(`Unsupported tool type: ${tool.type}`);\n }\n\n return {\n name: tool.name,\n description: tool.description,\n parameters: tool.inputSchema,\n };\n })\n : [];\n }\n\n private convertPromptToMessages(\n prompt: Parameters<LanguageModelV3[\"doGenerate\"]>[0][\"prompt\"]\n ): AppleIntelligenceMessage[] {\n return prompt.map((message) => {\n switch (message.role) {\n case \"system\":\n return {\n role: \"system\",\n content: message.content,\n };\n case \"user\":\n return {\n role: \"user\",\n content: Array.isArray(message.content)\n ? message.content\n .map((part) =>\n part.type === \"text\" ? part.text : \"[unsupported content]\"\n )\n .join(\"\\n\")\n : message.content,\n };\n case \"assistant\":\n return this.convertAssistantMessage(message);\n case \"tool\":\n return this.convertToolMessage(message);\n default:\n return {\n role: \"user\",\n content: String(message.content ?? \"\"),\n };\n }\n });\n }\n\n private convertAssistantMessage(\n message: Extract<LanguageModelV3Message, { role: \"assistant\" }>\n ): AppleIntelligenceMessage {\n if (Array.isArray(message.content)) {\n const toolCalls = message.content.filter(\n (part) => part.type === \"tool-call\"\n );\n const textParts = message.content.filter((part) => part.type === \"text\");\n\n if (toolCalls.length > 0) {\n return {\n role: \"assistant\",\n content: textParts.map((part) => part.text).join(\"\\n\") || \"\",\n toolCalls: toolCalls.map((part) => ({\n id: part.toolCallId,\n type: \"function\",\n function: {\n name: part.toolName,\n arguments:\n typeof part.input === \"string\"\n ? part.input\n : JSON.stringify(part.input),\n },\n })),\n };\n }\n\n return {\n role: \"assistant\",\n content: message.content\n .map((part) => {\n switch (part.type) {\n case \"text\":\n case \"reasoning\":\n return part.text;\n default:\n return `[unsupported content - ${part.type}]`;\n }\n })\n .join(\"\\n\"),\n };\n }\n\n return {\n role: \"assistant\",\n content: message.content || \"\",\n };\n }\n\n private convertToolMessage(\n message: Extract<LanguageModelV3Message, { role: \"tool\" }>\n ): AppleIntelligenceMessage {\n const toolCalls = message.content\n .map((part) => {\n if (part.type === \"tool-result\") {\n return {\n id: part.toolCallId,\n toolName: part.toolName,\n segments: [\n {\n type: \"text\",\n text: this.formatToolResultOutput(part.output),\n },\n ],\n };\n }\n if (part.type === \"tool-approval-response\") {\n return {\n id: part.approvalId,\n toolName: \"tool-approval\",\n segments: [\n {\n type: \"text\",\n text: part.approved\n ? `Tool approval granted${\n part.reason ? `: ${part.reason}` : \"\"\n }`\n : `Tool approval denied${\n part.reason ? `: ${part.reason}` : \"\"\n }`,\n },\n ],\n };\n }\n return null;\n })\n .filter(Boolean);\n\n return {\n role: \"tool\",\n content: JSON.stringify({ tool_calls: toolCalls }),\n };\n }\n\n private formatToolResultOutput(\n output: LanguageModelV3ToolResultOutput\n ): string {\n switch (output.type) {\n case \"text\":\n case \"error-text\":\n return output.value;\n case \"json\":\n case \"error-json\":\n return JSON.stringify(output.value);\n case \"execution-denied\":\n return output.reason\n ? `Tool execution denied: ${output.reason}`\n : \"Tool execution denied\";\n case \"content\":\n return output.value\n .map((part) => {\n if (part.type === \"text\") {\n return part.text;\n }\n if (part.type === \"file-data\") {\n return `[file-data:${part.mediaType}]`;\n }\n if (part.type === \"file-url\") {\n return `[file-url:${part.url}]`;\n }\n return \"[file]\";\n })\n .join(\"\\n\");\n default:\n return \"[unsupported tool output]\";\n }\n }\n\n private createStreamFromEvents(\n nativeStream: AsyncIterable<AppleIntelligenceStreamEvent>\n ): ReadableStream<LanguageModelV3StreamPart> {\n return new ReadableStream<LanguageModelV3StreamPart>({\n async start(controller) {\n controller.enqueue({ type: \"stream-start\", warnings: [] });\n const textId = crypto.randomUUID();\n let hasText = false;\n let hasToolCalls = false;\n\n try {\n for await (const event of nativeStream) {\n if (event.type === \"text\") {\n if (!hasText) {\n controller.enqueue({ type: \"text-start\", id: textId });\n hasText = true;\n }\n controller.enqueue({\n type: \"text-delta\",\n delta: event.text,\n id: textId,\n });\n } else if (event.type === \"tool-call\") {\n hasToolCalls = true;\n controller.enqueue({\n type: \"tool-call\",\n toolCallId: event.toolCallId,\n toolName: event.toolName,\n input: JSON.stringify(event.args),\n });\n } else if (event.type === \"error\") {\n controller.error(new Error(event.message));\n return;\n } else if (event.type === \"done\") {\n break;\n }\n }\n\n if (hasText) {\n controller.enqueue({ type: \"text-end\", id: textId });\n }\n\n controller.enqueue({\n type: \"finish\",\n finishReason: hasToolCalls\n ? { unified: \"tool-calls\", raw: \"tool-calls\" }\n : { unified: \"stop\", raw: \"stop\" },\n usage: {\n inputTokens: undefined,\n outputTokens: undefined,\n totalTokens: undefined,\n },\n });\n controller.close();\n } catch (err) {\n controller.error(err);\n }\n },\n });\n }\n\n private createStreamFromChunks(\n stream: AsyncIterable<AppleIntelligenceStreamEvent>\n ): ReadableStream<LanguageModelV3StreamPart> {\n return new ReadableStream<LanguageModelV3StreamPart>({\n async start(controller) {\n controller.enqueue({ type: \"stream-start\", warnings: [] });\n const textId = crypto.randomUUID();\n let hasText = false;\n\n try {\n for await (const event of stream) {\n if (event.type === \"text\") {\n if (!hasText) {\n controller.enqueue({ type: \"text-start\", id: textId });\n hasText = true;\n }\n controller.enqueue({\n type: \"text-delta\",\n delta: event.text,\n id: textId,\n });\n } else if (event.type === \"error\") {\n controller.error(new Error(event.message));\n return;\n } else if (event.type === \"done\") {\n break;\n }\n }\n\n if (hasText) {\n controller.enqueue({ type: \"text-end\", id: textId });\n }\n\n controller.enqueue({\n type: \"finish\",\n finishReason: { unified: \"stop\", raw: \"stop\" },\n usage: {\n inputTokens: undefined,\n outputTokens: undefined,\n totalTokens: undefined,\n },\n });\n controller.close();\n } catch (err) {\n controller.error(err);\n }\n },\n });\n }\n\n private emptyUsage(): LanguageModelV3Usage {\n return {\n inputTokens: undefined,\n outputTokens: undefined,\n totalTokens: undefined,\n };\n }\n}","import { invoke } from \"@tauri-apps/api/core\";\nimport { listen } from \"@tauri-apps/api/event\";\nimport type {\n AppleIntelligenceGenerateOptions,\n AppleIntelligenceGenerateResult,\n AppleIntelligenceStreamEvent,\n AppleIntelligenceStreamOptions,\n AppleIntelligenceTransport,\n AppleIntelligenceAvailability,\n} from \"./transport\";\n\ntype StreamStart = {\n streamId: string;\n eventName: string;\n};\n\nexport type TauriAppleIntelligenceTransportOptions = {\n commandPrefix?: string;\n};\n\nexport function createTauriAppleIntelligenceTransport(\n options: TauriAppleIntelligenceTransportOptions = {}\n): AppleIntelligenceTransport {\n const prefix = options.commandPrefix ?? \"apple_ai\";\n\n const command = (name: string) => `${prefix}_${name}`;\n\n return {\n async checkAvailability(): Promise<AppleIntelligenceAvailability> {\n return invoke(command(\"check_availability\"));\n },\n\n async generate(\n request: AppleIntelligenceGenerateOptions\n ): Promise<AppleIntelligenceGenerateResult> {\n return invoke(command(\"generate\"), { request });\n },\n\n async *stream(\n request: AppleIntelligenceStreamOptions\n ): AsyncIterable<AppleIntelligenceStreamEvent> {\n const start = await invoke<StreamStart>(command(\"stream\"), { request });\n\n const queue: AppleIntelligenceStreamEvent[] = [];\n let done = false;\n let pendingResolve:\n | ((value: IteratorResult<AppleIntelligenceStreamEvent>) => void)\n | null = null;\n\n const unlisten = await listen<AppleIntelligenceStreamEvent>(\n start.eventName,\n (event) => {\n const payload = event.payload;\n if (pendingResolve) {\n pendingResolve({ value: payload, done: false });\n pendingResolve = null;\n } else {\n queue.push(payload);\n }\n\n if (payload.type === \"done\" || payload.type === \"error\") {\n done = true;\n unlisten();\n }\n }\n );\n\n try {\n while (true) {\n if (queue.length > 0) {\n const value = queue.shift()!;\n yield value;\n if (value.type === \"done\" || value.type === \"error\") {\n return;\n }\n continue;\n }\n\n if (done) {\n return;\n }\n\n const value = await new Promise<\n IteratorResult<AppleIntelligenceStreamEvent>\n >((resolve) => {\n pendingResolve = resolve;\n });\n\n if (value.value) {\n yield value.value;\n if (value.value.type === \"done\" || value.value.type === \"error\") {\n return;\n }\n }\n }\n } finally {\n if (!done) {\n unlisten();\n }\n }\n },\n } satisfies AppleIntelligenceTransport;\n}"],"mappings":";;;;;AAoDA,SAAgB,gCACd,UAC2B;CAC3B,MAAM,eACJ,SACA,gBAA2C,EAAE,KAC1C,IAAI,mCAAmC,SAAS,eAAe,SAAS;CAE7E,MAAM,WAAW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