wizards 0.2.48 → 0.2.50
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 -1
- package/apps/runtime/dist/apple/wizards-apple +0 -0
- package/apps/runtime/dist/cli/status.js +1 -1
- package/apps/runtime/dist/db/migrations/tenant/0013_run_origin.sql +1 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0013_snapshot.json +3139 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/_journal.json +7 -0
- package/apps/runtime/dist/db/schema.js +5 -0
- package/apps/runtime/dist/docs/user/meta.json +1 -0
- package/apps/runtime/dist/docs/user/models.md +25 -0
- package/apps/runtime/dist/docs/user/test-and-share.md +7 -1
- package/apps/runtime/dist/docs/user/wordpress.md +103 -0
- package/apps/runtime/dist/engine/device.js +182 -0
- package/apps/runtime/dist/engine/events.js +3 -0
- package/apps/runtime/dist/engine/input.js +3 -0
- package/apps/runtime/dist/engine/prepare.js +1 -0
- package/apps/runtime/dist/engine/requirements.js +6 -109
- package/apps/runtime/dist/engine/runner.js +1 -0
- package/apps/runtime/dist/engine/steps.js +2 -1
- package/apps/runtime/dist/env.js +1 -1
- package/apps/runtime/dist/harness/apple.js +258 -0
- package/apps/runtime/dist/harness/model.js +3 -1
- package/apps/runtime/dist/mcp/auth.js +3 -0
- package/apps/runtime/dist/mcp/scopes.js +11 -2
- package/apps/runtime/dist/media/transcribe.js +6 -1
- package/apps/runtime/dist/models.js +63 -9
- package/apps/runtime/dist/routes/api.js +232 -1
- package/apps/runtime/dist/routes/plugins.js +6 -2
- package/apps/runtime/dist/routes/runs.js +65 -3
- package/apps/runtime/dist/routes/studio.js +11 -1
- package/apps/runtime/dist/services/api.js +244 -0
- package/apps/runtime/dist/services/engenty-shapes.js +1 -1
- package/apps/runtime/dist/services/package.js +77 -9
- package/apps/runtime/dist/services/runs.js +4 -3
- package/apps/runtime/dist/services/site.js +262 -0
- package/apps/web/dist/assets/AboutDialog-BRjyFW7N.js +1 -0
- package/apps/web/dist/assets/ChangelogDialog-DU-fYMNG.js +1 -0
- package/apps/web/dist/assets/ChatView-Chv8rH9v.js +10 -0
- package/apps/web/dist/assets/EditorPage-BEEiRjpL.js +3 -0
- package/apps/web/dist/assets/FlowPreview-911P5v6v.js +1 -0
- package/apps/web/dist/assets/{Harness-DAR1u4Dk.js → Harness-DE9pS-ZP.js} +2 -2
- package/apps/web/dist/assets/Marketplace-DfoRgS49.js +2 -0
- package/apps/web/dist/assets/NewWizardPage-BwZ39he_.js +1 -0
- package/apps/web/dist/assets/ProjectPage-BB8feiW1.js +2 -0
- package/apps/web/dist/assets/PublicRunner-JsgGibnC.js +1 -0
- package/apps/web/dist/assets/ReadOnly-ClY8xMQS.js +1 -0
- package/apps/web/dist/assets/RunDrawer-CxJtIQlP.js +4 -0
- package/apps/web/dist/assets/RunnerView-DvIBDzr1.js +1 -0
- package/apps/web/dist/assets/SettingsPage-DJBQvyom.js +1 -0
- package/apps/web/dist/assets/SetupPage-BVqbshmT.js +1 -0
- package/apps/web/dist/assets/SharePage-ChQxeHFC.js +1 -0
- package/apps/web/dist/assets/brand-CNF5NxD9.js +2 -0
- package/apps/web/dist/assets/changelog-OdE5-SsX.js +1 -0
- package/apps/web/dist/assets/circle-alert-r2qc1Vej.js +1 -0
- package/apps/web/dist/assets/engenty-eXZ-EAwd.js +1 -0
- package/apps/web/dist/assets/esm-cYET-omK.js +7 -0
- package/apps/web/dist/assets/{fluffy-engenty-D7rFrNcJ.js → fluffy-engenty-ClRou7yu.js} +1 -1
- package/apps/web/dist/assets/index-CDgxPZY_.js +11 -0
- package/apps/web/dist/assets/jsx-runtime-BNakU3Ej.js +1 -0
- package/apps/web/dist/assets/lock-N-C6-ZeG.js +1 -0
- package/apps/web/dist/assets/logo-C4V2_3Ar.js +1 -0
- package/apps/web/dist/assets/oss-credits-BQQX0kvk.js +1 -0
- package/apps/web/dist/assets/pdfmake-Cx9scTbD.js +228 -0
- package/apps/web/dist/assets/rolldown-runtime-hePW80VL.js +1 -0
- package/apps/web/dist/assets/session-Cpg5S8B3.js +1 -0
- package/apps/web/dist/assets/settings-menu-B763_KXf.js +1 -0
- package/apps/web/dist/assets/ui-DKcggL84.js +133 -0
- package/apps/web/dist/assets/upload-D24SDj7W.js +1 -0
- package/apps/web/dist/assets/useMutation-DKyQXgyj.js +1 -0
- package/apps/web/dist/assets/vfs_fonts-DllDSYt1.js +1 -0
- package/apps/web/dist/assets/volume-2-C-Y7-S4b.js +1 -0
- package/apps/web/dist/embed.js +57 -8
- package/apps/web/dist/index.html +11 -15
- package/apps/web/dist/mcp/flow.html +434 -206
- package/modules/calls/dist/client.css +1 -1
- package/modules/sms/dist/client.css +1 -1
- package/modules/whatsapp/dist/client.css +1 -1
- package/node_modules/@engenty-wizards/shared/dist/definition.d.ts +2 -0
- package/node_modules/@engenty-wizards/shared/dist/fit.d.ts +71 -0
- package/node_modules/@engenty-wizards/shared/dist/fit.js +381 -0
- package/package.json +1 -1
- package/apps/web/dist/assets/AboutDialog-CuiVGknS.js +0 -1
- package/apps/web/dist/assets/ChangelogDialog-DCEQD3Jd.js +0 -1
- package/apps/web/dist/assets/ChatView-DFxrG2PD.js +0 -10
- package/apps/web/dist/assets/EditorPage-B5rzKNMy.js +0 -3
- package/apps/web/dist/assets/FlowPreview-CYoR5DRY.js +0 -1
- package/apps/web/dist/assets/HomePage-BnYdh_Nx.js +0 -1
- package/apps/web/dist/assets/Marketplace-BDQNwMDB.js +0 -2
- package/apps/web/dist/assets/NewWizardPage-DztTEUlG.js +0 -1
- package/apps/web/dist/assets/ProjectPage-B7-Lqx9a.js +0 -2
- package/apps/web/dist/assets/PublicRunner-CaH3bHHd.js +0 -1
- package/apps/web/dist/assets/ReadOnly-DnB47DQC.js +0 -1
- package/apps/web/dist/assets/RunDrawer-Dv0KRqGA.js +0 -4
- package/apps/web/dist/assets/RunnerView-Bzwv1u4j.js +0 -2
- package/apps/web/dist/assets/SettingsPage-oVO7CKvc.js +0 -1
- package/apps/web/dist/assets/SetupPage-D--8cWA0.js +0 -1
- package/apps/web/dist/assets/SharePage-DjU08q7T.js +0 -1
- package/apps/web/dist/assets/ThemeSwitch-C3EJRN06.js +0 -1
- package/apps/web/dist/assets/arrow-right-F7X_SjK9.js +0 -1
- package/apps/web/dist/assets/changelog-BRoVI_JJ.js +0 -1
- package/apps/web/dist/assets/circle-alert-DdpaAYgd.js +0 -1
- package/apps/web/dist/assets/definition-CHacJYmI.js +0 -56
- package/apps/web/dist/assets/engenty-Cm8yZLON.js +0 -1
- package/apps/web/dist/assets/esm-rJY59Ixx.js +0 -7
- package/apps/web/dist/assets/external-link-Dfc1VFvS.js +0 -1
- package/apps/web/dist/assets/index-CX_yxZVQ.js +0 -79
- package/apps/web/dist/assets/jsx-runtime-D3jfb0Ew.js +0 -1
- package/apps/web/dist/assets/lock-Bu1wDFs8.js +0 -1
- package/apps/web/dist/assets/logo-C80CWCDM.js +0 -1
- package/apps/web/dist/assets/oss-credits-CIxnNZor.js +0 -1
- package/apps/web/dist/assets/react-dom-DenslgJm.js +0 -1
- package/apps/web/dist/assets/refresh-cw-BUDPOT39.js +0 -1
- package/apps/web/dist/assets/session-Blj2os_v.js +0 -1
- package/apps/web/dist/assets/settings-menu-BvxRnNtf.js +0 -1
- package/apps/web/dist/assets/sparkles-DWGJluyV.js +0 -1
- package/apps/web/dist/assets/trash-D9UB6TtS.js +0 -1
- package/apps/web/dist/assets/ui-GsuU9WTj.js +0 -9
- package/apps/web/dist/assets/upload-BngimDBR.js +0 -1
- package/apps/web/dist/assets/useMutation-DKcIz55V.js +0 -1
- package/apps/web/dist/assets/volume-2-BZju_bOP.js +0 -1
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { release } from "node:os";
|
|
3
|
+
import { dirname, join, resolve } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { nanoid } from "nanoid";
|
|
6
|
+
import { env } from "../env.js";
|
|
7
|
+
import { ffmpeg, hasFfmpeg } from "../media/ffmpeg.js";
|
|
8
|
+
import { ModelUnavailableError } from "../model-errors.js";
|
|
9
|
+
import { HarnessModel, lastJson, runClient, } from "./model.js";
|
|
10
|
+
/**
|
|
11
|
+
* Apple Intelligence on this Mac as a model: the on-device foundation model of macOS 26, run
|
|
12
|
+
* through `wizards-apple` (apps/runtime/apple/main.swift) — one process per call, as every
|
|
13
|
+
* installed AI client is run. Nothing leaves the machine and nothing is signed in. It is offered
|
|
14
|
+
* where it can run: a Mac with Apple silicon on macOS 26 or later with the helper built, and it
|
|
15
|
+
* answers once Apple Intelligence is switched on. The model is small (about 3B parameters,
|
|
16
|
+
* 4,096 tokens for prompt and answer together): a way for the Classifier and Standard classes,
|
|
17
|
+
* not for research, long documents or code. `apple:default` is the model; `apple:tagging` is
|
|
18
|
+
* Apple's adapter for tagging and extraction.
|
|
19
|
+
*/
|
|
20
|
+
/** The helper: built into dist/apple by `scripts/build-apple.mjs`, or named by the environment. */
|
|
21
|
+
export const APPLE_BIN = process.env.WIZARDS_APPLE_BIN?.trim() ||
|
|
22
|
+
resolve(dirname(fileURLToPath(import.meta.url)), "../../dist/apple/wizards-apple");
|
|
23
|
+
export const APPLE = { id: "apple", name: "Apple Intelligence" };
|
|
24
|
+
/** Darwin 25 is macOS 26: the first system with the Foundation Models framework. */
|
|
25
|
+
const DARWIN_OF_MACOS_26 = 25;
|
|
26
|
+
/** What this machine is, before the helper is asked: a Mac with Apple silicon on macOS 26 or later. */
|
|
27
|
+
export function appleMachine(platform = process.platform, arch = process.arch, darwin = release()) {
|
|
28
|
+
if (platform !== "darwin" || arch !== "arm64") {
|
|
29
|
+
return "device";
|
|
30
|
+
}
|
|
31
|
+
return Number.parseInt(darwin, 10) >= DARWIN_OF_MACOS_26 ? null : "os";
|
|
32
|
+
}
|
|
33
|
+
/** The helper's reason, as the status names it. */
|
|
34
|
+
export function appleReasonOf(helper) {
|
|
35
|
+
switch (helper) {
|
|
36
|
+
case "appleIntelligenceNotEnabled":
|
|
37
|
+
return "off";
|
|
38
|
+
case "modelNotReady":
|
|
39
|
+
return "loading";
|
|
40
|
+
default:
|
|
41
|
+
return "device";
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Without instructions the model refuses guided calls as "likely unsafe" (seen on macOS 26.5
|
|
46
|
+
* with a billing complaint); any instruction settles it. A step always brings its own.
|
|
47
|
+
*/
|
|
48
|
+
const DEFAULT_INSTRUCTIONS = "Answer what the prompt asks, precisely and briefly.";
|
|
49
|
+
const helperEnv = () => ({
|
|
50
|
+
PATH: process.env.PATH ?? "/usr/bin:/bin",
|
|
51
|
+
HOME: process.env.HOME ?? "",
|
|
52
|
+
LANG: process.env.LANG ?? "en_US.UTF-8",
|
|
53
|
+
});
|
|
54
|
+
let detected = null;
|
|
55
|
+
/** Apple Intelligence as it is now; asked again after a minute — the person may switch it on meanwhile. */
|
|
56
|
+
export async function appleStatus(force = false) {
|
|
57
|
+
if (!force && detected && Date.now() - detected.at < 60_000) {
|
|
58
|
+
return detected.value;
|
|
59
|
+
}
|
|
60
|
+
const value = await detectApple();
|
|
61
|
+
detected = { at: Date.now(), value };
|
|
62
|
+
return value;
|
|
63
|
+
}
|
|
64
|
+
async function detectApple() {
|
|
65
|
+
const machine = appleMachine();
|
|
66
|
+
if (machine) {
|
|
67
|
+
return { supported: false, available: false, reason: machine };
|
|
68
|
+
}
|
|
69
|
+
if (!existsSync(APPLE_BIN)) {
|
|
70
|
+
return { supported: false, available: false, reason: "missing" };
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
const { stdout } = await runClient(APPLE_BIN, ["status"], {
|
|
74
|
+
cwd: process.cwd(),
|
|
75
|
+
env: helperEnv(),
|
|
76
|
+
signal: AbortSignal.timeout(15_000),
|
|
77
|
+
});
|
|
78
|
+
const status = lastJson(stdout);
|
|
79
|
+
if (!status) {
|
|
80
|
+
return { supported: true, available: false, reason: "missing" };
|
|
81
|
+
}
|
|
82
|
+
return status.available
|
|
83
|
+
? { supported: true, available: true, reason: null }
|
|
84
|
+
: { supported: true, available: false, reason: appleReasonOf(status.reason) };
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
return { supported: true, available: false, reason: "missing" };
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/** What to tell the person when Apple Intelligence cannot answer. */
|
|
91
|
+
export function appleUnavailable(status) {
|
|
92
|
+
switch (status.reason) {
|
|
93
|
+
case "off":
|
|
94
|
+
return "Apple Intelligence ist auf diesem Mac ausgeschaltet. Einschalten unter Systemeinstellungen → Apple Intelligence & Siri.";
|
|
95
|
+
case "loading":
|
|
96
|
+
return "Apple lädt das Modell für Apple Intelligence noch auf diesen Mac. Gleich noch einmal versuchen.";
|
|
97
|
+
case "missing":
|
|
98
|
+
return "Der Helfer für Apple Intelligence (wizards-apple) fehlt in dieser Installation.";
|
|
99
|
+
case "os":
|
|
100
|
+
return "Apple Intelligence braucht macOS 26 oder neuer.";
|
|
101
|
+
default:
|
|
102
|
+
return "Apple Intelligence gibt es nur auf einem Mac mit Apple Silicon.";
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/** The failure the helper reports, as the person should read it. */
|
|
106
|
+
export function appleFailure(error) {
|
|
107
|
+
switch (error.kind) {
|
|
108
|
+
case "unavailable":
|
|
109
|
+
return new ModelUnavailableError(appleUnavailable({
|
|
110
|
+
supported: true,
|
|
111
|
+
available: false,
|
|
112
|
+
reason: appleReasonOf(error.message),
|
|
113
|
+
}));
|
|
114
|
+
case "rateLimited":
|
|
115
|
+
return new ModelUnavailableError("Apple Intelligence nimmt gerade keine weiteren Anfragen an. Gleich noch einmal versuchen.");
|
|
116
|
+
case "contextWindow":
|
|
117
|
+
return new Error("Apple Intelligence: Der Text ist zu lang für das Modell auf diesem Mac (4.096 Tokens für Frage und Antwort). Diese Klasse in den Einstellungen unter „Modelle & Konto“ auf ein anderes Modell legen.");
|
|
118
|
+
case "guardrail":
|
|
119
|
+
case "refusal":
|
|
120
|
+
return new Error("Apple Intelligence hat die Anfrage abgelehnt: Apples Inhaltsregeln lassen sie nicht zu.");
|
|
121
|
+
case "language":
|
|
122
|
+
return new Error("Apple Intelligence versteht die Sprache dieser Anfrage nicht.");
|
|
123
|
+
case "schema":
|
|
124
|
+
return new Error(`Apple Intelligence kann dieses Antwortformat nicht liefern: ${error.message}`);
|
|
125
|
+
default:
|
|
126
|
+
return new Error(`Apple Intelligence: ${error.message}`.slice(0, 500));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
class AppleModel extends HarnessModel {
|
|
130
|
+
provider = "apple";
|
|
131
|
+
/** The model keeps to the schema itself (guided generation). */
|
|
132
|
+
nativeSchema = true;
|
|
133
|
+
/** The helper calls no tools: a call with tools answers from the prompt alone. */
|
|
134
|
+
usesTools = false;
|
|
135
|
+
async invoke(call) {
|
|
136
|
+
const { stdout, stderr, code } = await runClient(APPLE_BIN, ["generate"], {
|
|
137
|
+
cwd: call.dir,
|
|
138
|
+
env: helperEnv(),
|
|
139
|
+
signal: call.signal,
|
|
140
|
+
stdin: JSON.stringify({
|
|
141
|
+
system: call.system || DEFAULT_INSTRUCTIONS,
|
|
142
|
+
prompt: call.prompt,
|
|
143
|
+
schema: call.schema,
|
|
144
|
+
useCase: this.modelId === "tagging" ? "tagging" : "general",
|
|
145
|
+
}),
|
|
146
|
+
});
|
|
147
|
+
const answer = lastJson(stdout);
|
|
148
|
+
if (!answer) {
|
|
149
|
+
throw new Error(`Apple Intelligence: ${stderr.trim() || `exit ${code}`}`.slice(0, 500));
|
|
150
|
+
}
|
|
151
|
+
if (answer.error) {
|
|
152
|
+
throw appleFailure(answer.error);
|
|
153
|
+
}
|
|
154
|
+
return { text: answer.text ?? "" };
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/** `apple:default` or `apple:tagging` as a language model. */
|
|
158
|
+
export function appleModel(alias) {
|
|
159
|
+
return new AppleModel(APPLE, alias || "default");
|
|
160
|
+
}
|
|
161
|
+
/** The Mac's own language: what a voice note is most likely in, unless the call names one. */
|
|
162
|
+
function systemLocale() {
|
|
163
|
+
const locale = Intl.DateTimeFormat().resolvedOptions().locale;
|
|
164
|
+
return /^[a-z]{2}-[A-Z]{2}$/.test(locale) ? locale : locale.startsWith("de") ? "de-DE" : "en-US";
|
|
165
|
+
}
|
|
166
|
+
/** What AVAudioFile reads as it is; a browser's WebM or Ogg (Opus) is turned into WAV first. */
|
|
167
|
+
function audioExtension(mediaType) {
|
|
168
|
+
const type = mediaType.split(";")[0].trim().toLowerCase();
|
|
169
|
+
if (/mp4|m4a|aac/.test(type)) {
|
|
170
|
+
return { ext: "m4a", native: true };
|
|
171
|
+
}
|
|
172
|
+
if (/wav/.test(type)) {
|
|
173
|
+
return { ext: "wav", native: true };
|
|
174
|
+
}
|
|
175
|
+
if (/aiff/.test(type)) {
|
|
176
|
+
return { ext: "aiff", native: true };
|
|
177
|
+
}
|
|
178
|
+
if (/mpeg|mp3/.test(type)) {
|
|
179
|
+
return { ext: "mp3", native: true };
|
|
180
|
+
}
|
|
181
|
+
if (/ogg|opus/.test(type)) {
|
|
182
|
+
return { ext: "ogg", native: false };
|
|
183
|
+
}
|
|
184
|
+
return { ext: "webm", native: false };
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* `apple:transcribe`: a voice note written down on this Mac by SpeechAnalyzer (macOS 26). It
|
|
188
|
+
* needs no Apple Intelligence, only the language's assets, which the system installs on the
|
|
189
|
+
* first call. The recording goes through a file of its own, deleted afterwards; what the
|
|
190
|
+
* system cannot read (a browser's WebM) becomes WAV through ffmpeg on the way.
|
|
191
|
+
*/
|
|
192
|
+
class AppleTranscriptionModel {
|
|
193
|
+
specificationVersion = "v3";
|
|
194
|
+
provider = "apple";
|
|
195
|
+
modelId = "transcribe";
|
|
196
|
+
async doGenerate(options) {
|
|
197
|
+
const dir = join(env.dataDir, "harness", nanoid(10));
|
|
198
|
+
mkdirSync(dir, { recursive: true });
|
|
199
|
+
const { ext, native } = audioExtension(options.mediaType);
|
|
200
|
+
const given = join(dir, `note.${ext}`);
|
|
201
|
+
const locale = options.providerOptions?.apple?.locale ?? systemLocale();
|
|
202
|
+
try {
|
|
203
|
+
writeFileSync(given, typeof options.audio === "string" ? Buffer.from(options.audio, "base64") : options.audio);
|
|
204
|
+
let path = given;
|
|
205
|
+
if (!native) {
|
|
206
|
+
if (!(await hasFfmpeg())) {
|
|
207
|
+
throw new Error(`Apple Intelligence liest ${options.mediaType} nicht; ohne ffmpeg bleibt die Aufnahme so. ffmpeg installieren oder im Browser als MP4 aufnehmen.`);
|
|
208
|
+
}
|
|
209
|
+
path = join(dir, "note.wav");
|
|
210
|
+
const { code, stderr } = await ffmpeg([
|
|
211
|
+
"-y",
|
|
212
|
+
"-i",
|
|
213
|
+
given,
|
|
214
|
+
"-ac",
|
|
215
|
+
"1",
|
|
216
|
+
"-ar",
|
|
217
|
+
"16000",
|
|
218
|
+
path,
|
|
219
|
+
]);
|
|
220
|
+
if (code !== 0) {
|
|
221
|
+
throw new Error(`Apple Intelligence: die Aufnahme ließ sich nicht wandeln: ${stderr.slice(-300)}`);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
const { stdout, stderr, code } = await runClient(APPLE_BIN, ["transcribe", path, locale], {
|
|
225
|
+
cwd: dir,
|
|
226
|
+
env: helperEnv(),
|
|
227
|
+
signal: options.abortSignal,
|
|
228
|
+
});
|
|
229
|
+
const answer = lastJson(stdout);
|
|
230
|
+
if (!answer) {
|
|
231
|
+
throw new Error(`Apple Intelligence: ${stderr.trim() || `exit ${code}`}`.slice(0, 500));
|
|
232
|
+
}
|
|
233
|
+
if (answer.error) {
|
|
234
|
+
throw appleFailure(answer.error);
|
|
235
|
+
}
|
|
236
|
+
return {
|
|
237
|
+
text: answer.text ?? "",
|
|
238
|
+
segments: [],
|
|
239
|
+
language: locale.slice(0, 2),
|
|
240
|
+
durationInSeconds: undefined,
|
|
241
|
+
warnings: [],
|
|
242
|
+
response: { timestamp: new Date(), modelId: this.modelId, headers: undefined },
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
catch (err) {
|
|
246
|
+
if (err.code === "ENOENT") {
|
|
247
|
+
throw new ModelUnavailableError(appleUnavailable({ supported: false, available: false, reason: "missing" }));
|
|
248
|
+
}
|
|
249
|
+
throw err;
|
|
250
|
+
}
|
|
251
|
+
finally {
|
|
252
|
+
rmSync(dir, { recursive: true, force: true });
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
export function appleTranscriptionModel() {
|
|
257
|
+
return new AppleTranscriptionModel();
|
|
258
|
+
}
|
|
@@ -69,6 +69,8 @@ export class HarnessModel {
|
|
|
69
69
|
supportedUrls = {};
|
|
70
70
|
/** Whether the client validates structured output against the schema itself. */
|
|
71
71
|
nativeSchema = false;
|
|
72
|
+
/** Whether the client runs a call's tools (over the bridge); else they are left out, with a warning. */
|
|
73
|
+
usesTools = true;
|
|
72
74
|
effort;
|
|
73
75
|
harness;
|
|
74
76
|
executors = new Map();
|
|
@@ -96,7 +98,7 @@ export class HarnessModel {
|
|
|
96
98
|
const bridged = [];
|
|
97
99
|
let webSearch = false;
|
|
98
100
|
for (const tool of options.tools ?? []) {
|
|
99
|
-
if (tool.type !== "function") {
|
|
101
|
+
if (tool.type !== "function" || !this.usesTools) {
|
|
100
102
|
warnings.push({ type: "unsupported", feature: `tool ${tool.name}` });
|
|
101
103
|
continue;
|
|
102
104
|
}
|
|
@@ -68,6 +68,7 @@ async function apiKeyAuth(key) {
|
|
|
68
68
|
role: result.role ?? "member",
|
|
69
69
|
client: result.name || "MCP",
|
|
70
70
|
scopes: [...SCOPES],
|
|
71
|
+
name: result.userName ?? "",
|
|
71
72
|
};
|
|
72
73
|
keyCache.set(key, { at: Date.now(), who, keyId: result.keyId ?? "" });
|
|
73
74
|
return authInfoFor(who, key, result.keyId ?? "");
|
|
@@ -88,6 +89,8 @@ async function tokenAuth(token) {
|
|
|
88
89
|
role: claims.role,
|
|
89
90
|
client: claims.clientId || "MCP",
|
|
90
91
|
scopes: SCOPES.filter((s) => granted.has(s)),
|
|
92
|
+
name: claims.name,
|
|
93
|
+
email: claims.email,
|
|
91
94
|
};
|
|
92
95
|
return authInfoFor(who, token, claims.clientId);
|
|
93
96
|
}
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { env } from "../env.js";
|
|
2
|
-
/**
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* What an MCP or API client may do; the Manage-App's consent page lists them, tools register only
|
|
4
|
+
* when granted. `runs:read`: the results of the live runs, as the WordPress plugin lists them.
|
|
5
|
+
*/
|
|
6
|
+
export const SCOPES = [
|
|
7
|
+
"wizards:read",
|
|
8
|
+
"wizards:write",
|
|
9
|
+
"wizards:publish",
|
|
10
|
+
"runs:test",
|
|
11
|
+
"runs:read",
|
|
12
|
+
];
|
|
4
13
|
/** The protected resource OAuth tokens are bound to (RFC 8707 / RFC 9728). */
|
|
5
14
|
export const MCP_RESOURCE = `${env.appUrl}/api/mcp`;
|
|
@@ -17,10 +17,15 @@ export async function transcribeAudio(input) {
|
|
|
17
17
|
model: listener.resolved.model,
|
|
18
18
|
audio: input.bytes,
|
|
19
19
|
abortSignal: input.abortSignal,
|
|
20
|
+
...(input.language
|
|
21
|
+
? { providerOptions: { apple: { locale: input.language === "en" ? "en-US" : "de-DE" } } }
|
|
22
|
+
: {}),
|
|
20
23
|
});
|
|
21
24
|
return {
|
|
22
25
|
text: result.text.trim(),
|
|
23
|
-
costUsd:
|
|
26
|
+
costUsd: listener.resolved.vendor === "apple"
|
|
27
|
+
? 0
|
|
28
|
+
: transcriptionCostUsd(result.durationInSeconds ?? 60),
|
|
24
29
|
};
|
|
25
30
|
}
|
|
26
31
|
// Else the audio class is bound to a chat model that takes audio files.
|
|
@@ -10,7 +10,9 @@ import { MODEL_CLASSES, TEXT_CLASSES, } from "@engenty-wizards/shared/definition
|
|
|
10
10
|
import { creditsModelOf, isCreditsRef, PROVIDER_IDS, providerInfo, providerOfRef, } from "@engenty-wizards/shared/providers";
|
|
11
11
|
import { generateSpeech, generateText, } from "ai";
|
|
12
12
|
import { accountToken, linkedAccount } from "./auth/account.js";
|
|
13
|
+
import { DeviceModel, deviceThinks } from "./engine/device.js";
|
|
13
14
|
import { env } from "./env.js";
|
|
15
|
+
import { appleModel, appleStatus, appleTranscriptionModel, appleUnavailable, } from "./harness/apple.js";
|
|
14
16
|
import { detectHarness, HarnessModel, harness, isHarnessVendor, notInstalled, signedOut, } from "./harness/index.js";
|
|
15
17
|
import { managed } from "./manage.js";
|
|
16
18
|
import { ModelUnavailableError } from "./model-errors.js";
|
|
@@ -174,6 +176,8 @@ function parse(ref) {
|
|
|
174
176
|
return { provider: null, id: ref, vendor: ref.split("/")[0] };
|
|
175
177
|
}
|
|
176
178
|
const vendorOf = (ref) => parse(ref).vendor;
|
|
179
|
+
/** A model on this machine: Ollama, or Apple Intelligence on a Mac (harness/apple.ts). */
|
|
180
|
+
const isLocalProvider = (provider) => provider === "ollama" || provider === "apple";
|
|
177
181
|
/** The part of `codex/default` after the client. */
|
|
178
182
|
const aliasOf = (id) => id.split("/").slice(1).join("/");
|
|
179
183
|
/** Whether this configuration can reach a binding without credits. */
|
|
@@ -182,7 +186,7 @@ function reachable(cfg, ref) {
|
|
|
182
186
|
return false;
|
|
183
187
|
}
|
|
184
188
|
const { provider, vendor } = parse(ref);
|
|
185
|
-
if ((provider === null && isHarnessVendor(vendor)) || provider
|
|
189
|
+
if ((provider === null && isHarnessVendor(vendor)) || isLocalProvider(provider)) {
|
|
186
190
|
// An installed client and a local model are of this machine.
|
|
187
191
|
return !managed;
|
|
188
192
|
}
|
|
@@ -371,6 +375,13 @@ async function ownLanguageModel(cfg, ref, meta) {
|
|
|
371
375
|
}).chat(id),
|
|
372
376
|
gateway: false,
|
|
373
377
|
};
|
|
378
|
+
case "apple": {
|
|
379
|
+
const status = await appleStatus();
|
|
380
|
+
if (!status.available) {
|
|
381
|
+
throw new ModelUnavailableError(appleUnavailable(status));
|
|
382
|
+
}
|
|
383
|
+
return { model: appleModel(id), gateway: false };
|
|
384
|
+
}
|
|
374
385
|
case "openai":
|
|
375
386
|
return { model: createOpenAI({ apiKey: need(cfg, "openai") })(id), gateway: false };
|
|
376
387
|
case "anthropic":
|
|
@@ -394,8 +405,18 @@ async function ownLanguageModel(cfg, ref, meta) {
|
|
|
394
405
|
}
|
|
395
406
|
throw new ModelUnavailableError(`Für das Modell "${ref}" ist kein Zugang eingerichtet. Bitte in den Einstellungen einen API Key hinterlegen oder ein Konto anmelden.`);
|
|
396
407
|
}
|
|
397
|
-
/**
|
|
408
|
+
/**
|
|
409
|
+
* The language model a text class runs on. A run watched from a device that offers the class
|
|
410
|
+
* (the app's Apple Intelligence, engine/device.ts) asks the device first and falls back to this.
|
|
411
|
+
*/
|
|
398
412
|
export async function textModel(cls, meta = {}) {
|
|
413
|
+
const resolved = await ownTextModel(cls, meta);
|
|
414
|
+
const device = meta.runId && isText(cls) ? deviceThinks(meta.runId, cls) : null;
|
|
415
|
+
return device
|
|
416
|
+
? { ...resolved, model: new DeviceModel(meta.runId, resolved.model, device.maxChars) }
|
|
417
|
+
: resolved;
|
|
418
|
+
}
|
|
419
|
+
async function ownTextModel(cls, meta) {
|
|
399
420
|
const route = await routeOf(cls);
|
|
400
421
|
if (route.kind === "credits") {
|
|
401
422
|
return viaCredits(route, cls, meta, (client, id) => client(id));
|
|
@@ -403,11 +424,18 @@ export async function textModel(cls, meta = {}) {
|
|
|
403
424
|
const { model, gateway } = await ownLanguageModel(route.cfg, route.ref, meta);
|
|
404
425
|
return { model, ref: route.ref, vendor: vendorOf(route.ref), gateway, metered: false };
|
|
405
426
|
}
|
|
406
|
-
/**
|
|
407
|
-
|
|
427
|
+
/**
|
|
428
|
+
* Hands the tools an agent will call to a model that runs them itself (an installed AI client).
|
|
429
|
+
* `ignorable`: the step declared no tools and has no uploads — the run's device may answer
|
|
430
|
+
* without the generic ones (engine/device.ts).
|
|
431
|
+
*/
|
|
432
|
+
export function attachTools(resolved, tools, ignorable = false) {
|
|
408
433
|
if (resolved.model instanceof HarnessModel) {
|
|
409
434
|
resolved.model.attach(tools);
|
|
410
435
|
}
|
|
436
|
+
else if (resolved.model instanceof DeviceModel) {
|
|
437
|
+
resolved.model.attach(tools, ignorable);
|
|
438
|
+
}
|
|
411
439
|
}
|
|
412
440
|
/** Gemini image models of the gateway are chat models answering with image files. */
|
|
413
441
|
export function isChatImageModel(ref) {
|
|
@@ -547,6 +575,19 @@ export async function listenerModel(meta = {}) {
|
|
|
547
575
|
if (route.kind === "own") {
|
|
548
576
|
const { cfg, ref } = route;
|
|
549
577
|
const { provider, id, vendor } = parse(ref);
|
|
578
|
+
if (provider === "apple") {
|
|
579
|
+
// This Mac writes the note down itself (SpeechAnalyzer); nothing is paid.
|
|
580
|
+
return {
|
|
581
|
+
kind: "transcription",
|
|
582
|
+
resolved: {
|
|
583
|
+
model: appleTranscriptionModel(),
|
|
584
|
+
ref,
|
|
585
|
+
vendor,
|
|
586
|
+
gateway: false,
|
|
587
|
+
metered: false,
|
|
588
|
+
},
|
|
589
|
+
};
|
|
590
|
+
}
|
|
550
591
|
const transcriber = provider === "elevenlabs"
|
|
551
592
|
? createElevenLabs({ apiKey: need(cfg, "elevenlabs") }).transcription(id)
|
|
552
593
|
: provider === "fal"
|
|
@@ -815,14 +856,20 @@ export async function classWays() {
|
|
|
815
856
|
const { provider, vendor } = parse(ref);
|
|
816
857
|
const client = provider === null && isHarnessVendor(vendor);
|
|
817
858
|
ways[cls] = {
|
|
818
|
-
kind: client ? "client" : provider
|
|
859
|
+
kind: client ? "client" : isLocalProvider(provider) ? "local" : "key",
|
|
819
860
|
by: client
|
|
820
861
|
? vendor
|
|
821
|
-
:
|
|
822
|
-
?
|
|
823
|
-
: providerOfRef(ref)
|
|
862
|
+
: isLocalProvider(provider)
|
|
863
|
+
? provider
|
|
864
|
+
: providerOfRef(ref) === "gateway" && !cfg.keys.gateway
|
|
865
|
+
? vendor
|
|
866
|
+
: providerOfRef(ref),
|
|
824
867
|
ref,
|
|
825
|
-
problem: client
|
|
868
|
+
problem: client
|
|
869
|
+
? null
|
|
870
|
+
: provider === "apple"
|
|
871
|
+
? await appleProblem()
|
|
872
|
+
: await gatewayProblem(cls, ref),
|
|
826
873
|
};
|
|
827
874
|
continue;
|
|
828
875
|
}
|
|
@@ -844,6 +891,11 @@ export async function classWays() {
|
|
|
844
891
|
}
|
|
845
892
|
return ways;
|
|
846
893
|
}
|
|
894
|
+
/** Why Apple Intelligence does not answer right now; null while it does. */
|
|
895
|
+
async function appleProblem() {
|
|
896
|
+
const status = await appleStatus();
|
|
897
|
+
return status.available ? null : appleUnavailable(status);
|
|
898
|
+
}
|
|
847
899
|
/** At start the ways are asked once, so a model the key cannot reach shows before a run meets it. */
|
|
848
900
|
export async function checkModelsAtStart() {
|
|
849
901
|
for (const [cls, way] of Object.entries(await classWays())) {
|
|
@@ -862,6 +914,8 @@ export async function modelSettings() {
|
|
|
862
914
|
creditFallback: cfg.settings.creditFallback !== false,
|
|
863
915
|
keys: Object.fromEntries(LOCAL_KEYS.map((k) => [k, Boolean(cfg.keys[k])])),
|
|
864
916
|
ways: await classWays(),
|
|
917
|
+
/** Apple Intelligence on this Mac: shown where the machine can run it, picked once it answers. */
|
|
918
|
+
apple: managed ? null : await appleStatus(),
|
|
865
919
|
/** What a class costs on the credits, where they are at hand. */
|
|
866
920
|
prices: (await classCatalog())?.classes ?? null,
|
|
867
921
|
/** The media models the credits pay for, which a binding may name. */
|