Files
plugins/packages/fingerprint/page/boot.js
T
KaranocaVe 00f4d84b8f fingerprint 0.1.0: a page that checks whether a model answers like the one it claims to be (#516)
Adds the Fingerprint page plugin (packages/fingerprint): it checks whether a model behind the local magpie gateway answers like the model it claims to be.

Reviewed at 531ca11f4 (KaranocaVe). Run at that head merged with main 848497c, through mote-run on the Mac mini with Bun 1.4.2:
- bun run rebuild from the committed bun.lock (frozen, --ignore-scripts): typecheck, 30/30 tests, build; diff -r against the committed dist/ is empty.
- HOME=$(mktemp -d) bun test: 3838 pass, 0 fail. bun scripts/check.mjs: exit 0.
- Offline preload refusing every non-loopback fetch/socket: 30/30, nothing refused.
- Broken by hand, each red: ensureDetector() in bootstrap, dropping ttl: Infinity, validating the job after the download.

Maintainer decision: the reference data comes from two third-party hosts (lm.ikale.io, cdn.jsdmirror.com), only on an explicit Download or a valid job, and both are named on the page, in registry.json and the READMEs. It is data used locally to rank candidates and is sent nowhere; the @latest fallback has no pinned hash, so a bad snapshot would rank wrongly, which the page states.

Not on npm yet (E404): magpie installs it from the dist branch until an owner publishes the first version.
2026-10-31 02:00:33 +08:00

99 lines
3.9 KiB
JavaScript

(() => {
const messages = {
en: {
title: 'Fingerprint',
connecting: 'Connecting to Fingerprint…',
remote:
'Upgrade Magpie for remote plugin services, or forward the service port to this computer over SSH.',
invalidPort: 'Invalid Fingerprint service port.',
failed: 'Could not connect',
},
'zh-Hans': {
title: '模型指纹',
connecting: '正在连接模型指纹服务…',
remote: '请升级 Magpie 以支持远程插件服务,或将服务器的服务端口通过 SSH 转发到本机。',
invalidPort: '模型指纹服务端口无效。',
failed: '连接失败',
},
'zh-Hant': {
title: '模型指紋',
connecting: '正在連線至模型指紋服務…',
remote: '請升級 Magpie 以支援遠端外掛服務,或透過 SSH 將伺服器的服務連接埠轉送至本機。',
invalidPort: '模型指紋服務連接埠無效。',
failed: '連線失敗',
},
ja: {
title: 'モデル指紋',
connecting: 'モデル指紋サービスに接続中…',
remote:
'リモートプラグインサービスを利用するには、Magpie を更新するか、SSH でサービスポートをこのコンピューターに転送してください。',
invalidPort: 'モデル指紋サービスのポートが無効です。',
failed: '接続できませんでした',
},
de: {
title: 'Modell-Fingerabdruck',
connecting: 'Verbindung zum Fingerabdruck-Dienst wird hergestellt…',
remote:
'Aktualisieren Sie Magpie für entfernte Plugin-Dienste oder leiten Sie den Dienstport per SSH an diesen Computer weiter.',
invalidPort: 'Ungültiger Port für den Fingerabdruck-Dienst.',
failed: 'Verbindung fehlgeschlagen',
},
};
let text = messages.en;
const status = document.getElementById('status');
function followLanguage(theme) {
const language = String(theme?.lang || 'en')
.toLowerCase()
.replaceAll('_', '-');
const parts = language.split('-');
const key =
parts[0] === 'zh'
? parts.includes('hant') ||
(!parts.includes('hans') && parts.some((part) => ['tw', 'hk', 'mo'].includes(part)))
? 'zh-Hant'
: 'zh-Hans'
: parts[0];
text = messages[key] || messages.en;
document.documentElement.lang = messages[key] ? key : 'en';
document.title = text.title;
document.getElementById('title').textContent = text.title;
status.textContent = text.connecting;
}
return (async () => {
const theme = await window.magpie?.ready;
followLanguage(theme);
window.magpie?.onTheme?.(followLanguage);
const config = (await window.magpie?.options?.get?.()) || {};
const port = Number(config.port ?? 3488);
if (!Number.isInteger(port) || port < 1 || port > 65535) throw new Error(text.invalidPort);
let service = window.magpie?.service;
if (!service) {
const local =
!location.hostname || ['localhost', '127.0.0.1', '::1'].includes(location.hostname);
if (!local) {
status.textContent = text.remote;
return;
}
service = `http://127.0.0.1:${port}/`;
}
const url = new URL(service, location.href);
// Opaque Magpie web frames need the concrete proxy origin in connect-src.
url.searchParams.set('uiOrigin', url.origin);
if (theme) {
url.searchParams.set('theme', theme.dark ? 'dark' : 'light');
if (theme.lang) url.searchParams.set('lang', theme.lang);
}
const context = window.magpie?.context?.provider;
if (context?.id) url.searchParams.set('provider', context.id);
window.magpie?.onAction((action) => {
if (action?.provider?.id) {
url.searchParams.set('provider', action.provider.id);
location.replace(url.href);
}
});
location.replace(url.href);
})().catch((error) => {
status.textContent = `${text.failed}: ${String(error?.message || error)}`;
});
})();