Files
plugins/packages/fingerprint/src/config.ts
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

48 lines
1.5 KiB
TypeScript

import { homedir } from 'node:os';
import { join } from 'node:path';
export interface Options {
port?: number;
gateway?: string;
apiKey?: string;
dataDir?: string;
bankSource?: string;
demo?: boolean;
uiDir?: string;
}
export function options(
input: Options = {},
): Required<Omit<Options, 'bankSource' | 'uiDir'>> & Pick<Options, 'bankSource' | 'uiDir'> {
const addr = process.env.MAGPIE_ADDR?.replace(/^(0\.0\.0\.0|\[::\]):/, '127.0.0.1:');
const gateway = (
input.gateway ||
process.env.MAGPIE_FINGERPRINT_GATEWAY ||
(addr ? `http://${addr}` : 'http://127.0.0.1:3425')
).replace(/\/+$/, '');
const url = new URL(gateway);
if (
!['http:', 'https:'].includes(url.protocol) ||
url.username ||
url.password ||
url.search ||
url.hash ||
(url.pathname !== '/' && url.pathname !== '')
)
throw new Error(
'Gateway must be an HTTP(S) origin without credentials, path, query or fragment.',
);
const port = input.port ?? Number(process.env.MAGPIE_FINGERPRINT_PORT || 3488);
if (!Number.isInteger(port) || port < 0 || port > 65535) throw new Error('Invalid service port.');
return {
port,
gateway,
apiKey: input.apiKey || process.env.MAGPIE_FINGERPRINT_API_KEY || '',
dataDir:
input.dataDir ||
process.env.MAGPIE_FINGERPRINT_DATA_DIR ||
join(process.env.XDG_CONFIG_HOME || join(homedir(), '.config'), 'magpie', 'fingerprint'),
bankSource: input.bankSource || process.env.MAGPIE_FINGERPRINT_BANK_SOURCE,
demo: input.demo ?? false,
uiDir: input.uiDir,
};
}