openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
92 lines (91 loc) • 3.12 kB
JavaScript
import { b as ensureStaticModelAllowlistEntry } from "../../provider-onboard-Di5Hihl4.mjs";
import { a as buildAppleFmProviderConfig, i as APPLE_FM_PROVIDER_ID, n as APPLE_FM_MIN_CONTEXT_WINDOW, r as APPLE_FM_MODEL_REF } from "../../defaults-aZRipouy.mjs";
//#region extensions/apple-fm/setup.ts
const SETUP_NOTE = "Apple Foundation Models is your on-device setup and utility model, with no API key. Choose a separate primary model for regular agent conversations.";
function requireUsableModel(e) {
if (!e.available) throw new Error(e.reason || "Apple Foundation Models is unavailable. Enable Apple Intelligence in System Settings and wait for its model download, then retry setup.");
if (e.contextWindow < 8192) throw new Error(`${e.modelName} provides ${e.contextWindow} context tokens. OpenClaw's Apple setup option requires at least ${APPLE_FM_MIN_CONTEXT_WINDOW}. Choose another local or cloud model on this Mac.`);
}
function setupResult(e) {
requireUsableModel(e);
return {
profiles: [],
defaultModel: APPLE_FM_MODEL_REF,
notes: [SETUP_NOTE],
configPatch: {
models: { providers: { [APPLE_FM_PROVIDER_ID]: buildAppleFmProviderConfig(e) } },
agents: { defaults: { models: { [APPLE_FM_MODEL_REF]: { agentRuntime: { id: "openclaw" } } } } }
}
};
}
async function detectAppleFmSetup(e, t) {
const n = await t.probe({
signal: e.signal,
env: e.env
});
if (!n?.available || n.contextWindow < 8192) return null;
return {
modelRef: APPLE_FM_MODEL_REF,
detail: `${n.modelName} · ${n.contextWindow.toLocaleString("en-US")} tokens · on-device setup and utility`
};
}
async function prepareAppleFmSetup(e, t) {
if (e.modelRef !== "apple-fm/system") return null;
return setupResult(await t.prepare({
signal: e.signal,
env: e.env
}));
}
async function runAppleFmSetup(e, t) {
return setupResult(await t.prepare({
signal: e.signal,
env: e.env
}));
}
async function validateAppleFmNonInteractive(e, t) {
const n = await t.probe();
if (!n) {
e.runtime.error("Apple Foundation Models requires an Apple Silicon Mac running macOS 27 or later.");
return false;
}
try {
requireUsableModel(n);
return true;
} catch (t) {
e.runtime.error(t instanceof Error ? t.message : String(t));
return false;
}
}
async function configureAppleFmNonInteractive(e, t) {
const n = await t.prepare();
requireUsableModel(n);
return ensureStaticModelAllowlistEntry({
cfg: {
...e.config,
models: {
...e.config.models,
providers: {
...e.config.models?.providers,
[APPLE_FM_PROVIDER_ID]: buildAppleFmProviderConfig(n)
}
},
agents: {
...e.config.agents,
defaults: {
...e.config.agents?.defaults,
utilityModel: APPLE_FM_MODEL_REF,
models: {
...e.config.agents?.defaults?.models,
[APPLE_FM_MODEL_REF]: {
...e.config.agents?.defaults?.models?.[APPLE_FM_MODEL_REF],
agentRuntime: { id: "openclaw" }
}
}
}
}
},
modelRef: APPLE_FM_MODEL_REF
});
}
//#endregion
export { configureAppleFmNonInteractive, detectAppleFmSetup, prepareAppleFmSetup, runAppleFmSetup, validateAppleFmNonInteractive };