llm-api-purity-check 1.2.0 → 1.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 +75 -32
- package/README_CN.md +64 -29
- package/bin/cli.mjs +147 -26
- package/data/bank.generated.json +1 -1
- package/package.json +3 -2
- package/scripts/sync-bank.mjs +333 -0
- package/skills/aiapipk-check/SKILL.md +134 -0
- package/src/checks.mjs +794 -58
- package/src/client.mjs +1000 -98
- package/src/fingerprint.mjs +326 -44
- package/src/links.mjs +12 -5
- package/src/modelIdNormalize.mjs +94 -0
- package/test/links.test.mjs +0 -60
- package/test/purity.test.mjs +0 -186
package/src/fingerprint.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* 1-355 Numerical Distribution Model Fingerprinting Engine
|
|
2
|
+
* 1-355 Numerical Distribution Model Fingerprinting Engine (38-model symmetric M2 engine)
|
|
3
3
|
*
|
|
4
|
-
* Statistical attribution (Hellinger + Ordered-block
|
|
4
|
+
* Statistical attribution (Hellinger + symmetric nuisance-projected Ordered-block + Jensen-Shannon similarity)
|
|
5
5
|
* built on MIT-licensed open-source methods from xqy2006/ModelTrace & kiss-kedaya/chanshui,
|
|
6
6
|
* packaged for standalone CLI use by AIAPIPK (https://www.aiapipk.com/detect/).
|
|
7
7
|
*/
|
|
@@ -10,17 +10,36 @@ import crypto from 'node:crypto';
|
|
|
10
10
|
import fs from 'node:fs';
|
|
11
11
|
import path from 'node:path';
|
|
12
12
|
import { fileURLToPath } from 'node:url';
|
|
13
|
+
import { inferCanonicalBankFamily, normalizeModelSlug } from './modelIdNormalize.mjs';
|
|
13
14
|
|
|
14
15
|
export const FP_VALUE_MIN = 1;
|
|
15
16
|
export const FP_VALUE_MAX = 355;
|
|
16
17
|
export const FP_DIMENSION = FP_VALUE_MAX - FP_VALUE_MIN + 1;
|
|
17
18
|
const FP_ALPHA = 0.5;
|
|
19
|
+
const SYMMETRIC_OB_WEIGHT = 0.4;
|
|
20
|
+
const MERGED_BETA_BY_ROUNDS = { 1: 3.5, 2: 4.5, 3: 5.0 };
|
|
21
|
+
const STALE_BASELINE_DAYS = 90;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Empirically verified same-family sibling clusters whose 1-355 priors overlap closely.
|
|
25
|
+
* Landing within the same sibling cluster with combined probability >= 0.60 counts as matched.
|
|
26
|
+
*/
|
|
27
|
+
export const SIBLING_MODEL_GROUPS = [
|
|
28
|
+
['gpt-6.1-sol', 'gpt-6-astra'],
|
|
29
|
+
['deepseek-v4-flash', 'deepseek-v4.1-flash-0910', 'deepseek-v4.1-flash-1017'],
|
|
30
|
+
['gemini-4-argon', 'gemini-4-carbon'],
|
|
31
|
+
['kimi-k3', 'kimi-k3.1-pro'],
|
|
32
|
+
];
|
|
18
33
|
|
|
19
34
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
20
35
|
const DEFAULT_BANK_PATH = path.resolve(__dirname, '../data/bank.generated.json');
|
|
21
36
|
|
|
22
37
|
let cachedNumericBank = null;
|
|
23
38
|
|
|
39
|
+
export function clearFingerprintBankCache() {
|
|
40
|
+
cachedNumericBank = null;
|
|
41
|
+
}
|
|
42
|
+
|
|
24
43
|
export function loadFingerprintBank(bankPath = DEFAULT_BANK_PATH) {
|
|
25
44
|
if (cachedNumericBank && bankPath === DEFAULT_BANK_PATH) return cachedNumericBank;
|
|
26
45
|
const raw = JSON.parse(fs.readFileSync(bankPath, 'utf-8'));
|
|
@@ -93,6 +112,66 @@ export function countNumbers355(nums) {
|
|
|
93
112
|
return counts;
|
|
94
113
|
}
|
|
95
114
|
|
|
115
|
+
/**
|
|
116
|
+
* Inspect whether a parsed 1..355 sequence is degenerate (e.g., counting 1..300,
|
|
117
|
+
* constant/stuck repetitions, or collapsed tiny value vocabulary).
|
|
118
|
+
*/
|
|
119
|
+
export function inspectSequenceDegeneracy(nums) {
|
|
120
|
+
if (!Array.isArray(nums) || nums.length < 2) {
|
|
121
|
+
return {
|
|
122
|
+
degenerate: true,
|
|
123
|
+
reason: 'too_short',
|
|
124
|
+
stepOneRatio: 0,
|
|
125
|
+
adjacentRepeatRatio: 0,
|
|
126
|
+
uniqueCount: Array.isArray(nums) ? nums.length : 0,
|
|
127
|
+
minUnique: 2,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
let stepOneCount = 0;
|
|
131
|
+
let adjacentRepeatCount = 0;
|
|
132
|
+
const unique = new Set();
|
|
133
|
+
unique.add(nums[0]);
|
|
134
|
+
for (let i = 1; i < nums.length; i += 1) {
|
|
135
|
+
unique.add(nums[i]);
|
|
136
|
+
if (nums[i] === nums[i - 1]) adjacentRepeatCount += 1;
|
|
137
|
+
else if (Math.abs(nums[i] - nums[i - 1]) === 1) stepOneCount += 1;
|
|
138
|
+
}
|
|
139
|
+
const transitions = nums.length - 1;
|
|
140
|
+
const stepOneRatio = Math.round((stepOneCount / transitions) * 10000) / 10000;
|
|
141
|
+
const adjacentRepeatRatio = Math.round((adjacentRepeatCount / transitions) * 10000) / 10000;
|
|
142
|
+
const uniqueCount = unique.size;
|
|
143
|
+
const minUnique = Math.min(30, nums.length * 0.15);
|
|
144
|
+
|
|
145
|
+
let reason = null;
|
|
146
|
+
if (stepOneRatio > 0.35) reason = 'monotonic_step_one';
|
|
147
|
+
else if (adjacentRepeatRatio > 0.35) reason = 'adjacent_repeat';
|
|
148
|
+
else if (uniqueCount < minUnique) reason = 'low_unique_diversity';
|
|
149
|
+
|
|
150
|
+
return {
|
|
151
|
+
degenerate: reason !== null,
|
|
152
|
+
reason,
|
|
153
|
+
stepOneRatio,
|
|
154
|
+
adjacentRepeatRatio,
|
|
155
|
+
uniqueCount,
|
|
156
|
+
minUnique,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export function isDegenerateSequence(nums) {
|
|
161
|
+
return inspectSequenceDegeneracy(nums).degenerate;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function computePositionalOverlap(a, b) {
|
|
165
|
+
const maxLen = Math.max(a.length, b.length);
|
|
166
|
+
if (maxLen === 0) return 0;
|
|
167
|
+
const minLen = Math.min(a.length, b.length);
|
|
168
|
+
let same = 0;
|
|
169
|
+
for (let i = 0; i < minLen; i += 1) {
|
|
170
|
+
if (a[i] === b[i]) same += 1;
|
|
171
|
+
}
|
|
172
|
+
return same / maxLen;
|
|
173
|
+
}
|
|
174
|
+
|
|
96
175
|
function hellingerFeature(counts) {
|
|
97
176
|
const total = counts.reduce((a, b) => a + b, 0) + FP_ALPHA * FP_DIMENSION;
|
|
98
177
|
return counts.map((v) => Math.sqrt((v + FP_ALPHA) / total));
|
|
@@ -153,21 +232,37 @@ function softmax(beta, scores) {
|
|
|
153
232
|
return weights.map((w) => w / sum);
|
|
154
233
|
}
|
|
155
234
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
.replace(/[._\s]+/g, '-');
|
|
235
|
+
/**
|
|
236
|
+
* Infer expected bank family for claimed model across the 7 covered families.
|
|
237
|
+
* Uncovered families (e.g. Grok, Llama, Mistral) return null so they do not trigger false family_mismatch.
|
|
238
|
+
*/
|
|
239
|
+
export function inferExpectedBankFamily(modelName) {
|
|
240
|
+
return inferCanonicalBankFamily(modelName);
|
|
163
241
|
}
|
|
164
242
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
if (
|
|
169
|
-
|
|
170
|
-
|
|
243
|
+
export { normalizeModelSlug };
|
|
244
|
+
|
|
245
|
+
export function classifyBaselineProvenance(modelDef, nowMs = Date.now()) {
|
|
246
|
+
if (!modelDef) return { tier: 'unknown', stale: false, ageDays: null };
|
|
247
|
+
const src = String(modelDef.reference_source || '').toLowerCase();
|
|
248
|
+
let tier = 'official_direct';
|
|
249
|
+
if (!src || src === 'modeltrace_base' || src.includes('official') || src.includes('openai-direct') || src.includes('api.deepseek.com')) {
|
|
250
|
+
tier = 'official_direct';
|
|
251
|
+
} else if (src.includes('langbase.netease.com') || src.includes('aigw-int') || src.includes('verified_gateway')) {
|
|
252
|
+
tier = 'verified_gateway';
|
|
253
|
+
} else {
|
|
254
|
+
tier = 'third_party_relay';
|
|
255
|
+
}
|
|
256
|
+
let stale = false;
|
|
257
|
+
let ageDays = null;
|
|
258
|
+
if (modelDef.captured_at) {
|
|
259
|
+
const ts = Date.parse(modelDef.captured_at);
|
|
260
|
+
if (Number.isFinite(ts)) {
|
|
261
|
+
ageDays = Math.floor((nowMs - ts) / (24 * 3600 * 1000));
|
|
262
|
+
stale = ageDays > STALE_BASELINE_DAYS;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return { tier, stale, ageDays };
|
|
171
266
|
}
|
|
172
267
|
|
|
173
268
|
export function generateFingerprintChallenges(count = 3) {
|
|
@@ -193,6 +288,14 @@ export function generateFingerprintChallenges(count = 3) {
|
|
|
193
288
|
}));
|
|
194
289
|
}
|
|
195
290
|
|
|
291
|
+
function usesSymmetricNuisanceOB(bank) {
|
|
292
|
+
const ob = bank.robust?.ordered_blocks;
|
|
293
|
+
if (bank.merged_symmetric || bank.robust?.symmetric_nuisance_ob) return true;
|
|
294
|
+
if (bank.models.length > 18) return true;
|
|
295
|
+
if (!Array.isArray(ob?.environment_centroids) || ob.environment_centroids.length === 0) return true;
|
|
296
|
+
return false;
|
|
297
|
+
}
|
|
298
|
+
|
|
196
299
|
function robustScoreNumbers(nums, bank) {
|
|
197
300
|
const h = bank.robust.hellinger;
|
|
198
301
|
const ob = bank.robust.ordered_blocks;
|
|
@@ -204,17 +307,29 @@ function robustScoreNumbers(nums, bank) {
|
|
|
204
307
|
h.nuisance_basis
|
|
205
308
|
)
|
|
206
309
|
);
|
|
207
|
-
const
|
|
310
|
+
const rawH = h.centroids.map((c) => dot(hp, c));
|
|
311
|
+
const hell = standardizeScalar(rawH);
|
|
208
312
|
|
|
209
|
-
|
|
210
|
-
|
|
313
|
+
if (!ob) {
|
|
314
|
+
return { scores: hell, rawH, rawOB: new Array(n).fill(0) };
|
|
315
|
+
}
|
|
211
316
|
|
|
212
317
|
const os = standardizeWithStats(orderedBlockFeature(nums), ob.feature_mean, ob.feature_scale);
|
|
213
|
-
const osUnit = unit(os);
|
|
214
318
|
const op = unit(projectOut(os, ob.nuisance_basis));
|
|
319
|
+
const rawOB = ob.centroids.map((c) => dot(op, c));
|
|
320
|
+
|
|
321
|
+
if (usesSymmetricNuisanceOB(bank)) {
|
|
322
|
+
const weight = SYMMETRIC_OB_WEIGHT;
|
|
323
|
+
const ordered = standardizeScalar(rawOB);
|
|
324
|
+
const scores = hell.map((hv, i) => (1 - weight) * hv + weight * ordered[i]);
|
|
325
|
+
return { scores, rawH, rawOB };
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
const weight = Number(ob.weight || 0);
|
|
329
|
+
if (weight === 0) return { scores: hell, rawH, rawOB };
|
|
215
330
|
|
|
331
|
+
const osUnit = unit(os);
|
|
216
332
|
const templateRaw = new Array(n);
|
|
217
|
-
const nuisanceRaw = new Array(n);
|
|
218
333
|
for (let c = 0; c < n; c += 1) {
|
|
219
334
|
let best = -Infinity;
|
|
220
335
|
for (const env of ob.environment_centroids) {
|
|
@@ -222,13 +337,12 @@ function robustScoreNumbers(nums, bank) {
|
|
|
222
337
|
if (val > best) best = val;
|
|
223
338
|
}
|
|
224
339
|
templateRaw[c] = Number.isFinite(best) ? best : 0;
|
|
225
|
-
nuisanceRaw[c] = dot(op, ob.centroids[c]);
|
|
226
340
|
}
|
|
227
341
|
const template = standardizeScalar(templateRaw);
|
|
228
|
-
const nuisance = standardizeScalar(
|
|
342
|
+
const nuisance = standardizeScalar(rawOB);
|
|
229
343
|
const ordered = standardizeScalar(template.map((t, i) => 0.5 * t + 0.5 * nuisance[i]));
|
|
230
|
-
|
|
231
|
-
return
|
|
344
|
+
const scores = hell.map((hv, i) => (1 - weight) * hv + weight * ordered[i]);
|
|
345
|
+
return { scores, rawH, rawOB };
|
|
232
346
|
}
|
|
233
347
|
|
|
234
348
|
function findClaimedModelInBank(claimedModel, bank) {
|
|
@@ -240,39 +354,99 @@ function findClaimedModelInBank(claimedModel, bank) {
|
|
|
240
354
|
if (normalizeModelSlug(al) === req) return m;
|
|
241
355
|
}
|
|
242
356
|
}
|
|
357
|
+
// Strict loose matching: only allow snapshot/version suffix tails (e.g. -20251001, -latest, -v1),
|
|
358
|
+
// never allow cross-tier prefix collisions like glm-5.3-flash matching glm-5.3 or gpt-5-mini matching gpt-5.
|
|
243
359
|
for (const m of bank.models) {
|
|
244
360
|
const normId = normalizeModelSlug(m.id);
|
|
245
361
|
if (normId.startsWith(req) || req.startsWith(normId)) {
|
|
246
362
|
const tail = req.length >= normId.length ? req.slice(normId.length) : normId.slice(req.length);
|
|
247
|
-
if (
|
|
248
|
-
|
|
363
|
+
if (/^-(?:202\d{5}|latest|v\d+(?:-\d+)?)$/i.test(tail)) {
|
|
364
|
+
return m;
|
|
365
|
+
}
|
|
249
366
|
}
|
|
250
367
|
}
|
|
251
368
|
return null;
|
|
252
369
|
}
|
|
253
370
|
|
|
254
|
-
export function attributeFingerprint(outputs, claimedModel,
|
|
255
|
-
const
|
|
371
|
+
export function attributeFingerprint(outputs, claimedModel, bankPathOrOptions = DEFAULT_BANK_PATH) {
|
|
372
|
+
const opts =
|
|
373
|
+
typeof bankPathOrOptions === 'string'
|
|
374
|
+
? { bankPath: bankPathOrOptions }
|
|
375
|
+
: { bankPath: DEFAULT_BANK_PATH, ...(bankPathOrOptions || {}) };
|
|
376
|
+
const bank = opts.bank || loadFingerprintBank(opts.bankPath || DEFAULT_BANK_PATH);
|
|
377
|
+
const nowMs = typeof opts.nowMs === 'number' ? opts.nowMs : Date.now();
|
|
256
378
|
const minValid = bank.minimum_valid_numbers || 80;
|
|
257
379
|
const valid = [];
|
|
258
380
|
const diagnostics = [];
|
|
381
|
+
let degenerateRejectedCount = 0;
|
|
382
|
+
let duplicateRejectedCount = 0;
|
|
259
383
|
|
|
260
384
|
outputs.forEach((o, index) => {
|
|
261
|
-
const nums = parseModelTraceNumbers(o
|
|
262
|
-
const minimum = o
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
385
|
+
const nums = parseModelTraceNumbers(o?.text);
|
|
386
|
+
const minimum = o?.expectedCount ? Math.max(minValid, Math.ceil(o.expectedCount * 0.55)) : minValid;
|
|
387
|
+
if (nums.length < minimum) {
|
|
388
|
+
diagnostics.push({
|
|
389
|
+
index,
|
|
390
|
+
parsedNumbers: nums.length,
|
|
391
|
+
minimumNumbers: minimum,
|
|
392
|
+
accepted: false,
|
|
393
|
+
rejectReason: 'too_short',
|
|
270
394
|
});
|
|
395
|
+
return;
|
|
271
396
|
}
|
|
397
|
+
|
|
398
|
+
const deg = inspectSequenceDegeneracy(nums);
|
|
399
|
+
if (deg.degenerate) {
|
|
400
|
+
degenerateRejectedCount += 1;
|
|
401
|
+
diagnostics.push({
|
|
402
|
+
index,
|
|
403
|
+
parsedNumbers: nums.length,
|
|
404
|
+
minimumNumbers: minimum,
|
|
405
|
+
accepted: false,
|
|
406
|
+
rejectReason: `degenerate:${deg.reason}`,
|
|
407
|
+
});
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
const isDuplicate = valid.some((prev) => computePositionalOverlap(nums, prev.nums) > 0.9);
|
|
412
|
+
if (isDuplicate) {
|
|
413
|
+
duplicateRejectedCount += 1;
|
|
414
|
+
diagnostics.push({
|
|
415
|
+
index,
|
|
416
|
+
parsedNumbers: nums.length,
|
|
417
|
+
minimumNumbers: minimum,
|
|
418
|
+
accepted: false,
|
|
419
|
+
rejectReason: 'duplicate_round',
|
|
420
|
+
});
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
const scored = robustScoreNumbers(nums, bank);
|
|
425
|
+
diagnostics.push({
|
|
426
|
+
index,
|
|
427
|
+
parsedNumbers: nums.length,
|
|
428
|
+
minimumNumbers: minimum,
|
|
429
|
+
accepted: true,
|
|
430
|
+
rejectReason: null,
|
|
431
|
+
});
|
|
432
|
+
valid.push({
|
|
433
|
+
nums,
|
|
434
|
+
counts: countNumbers355(nums),
|
|
435
|
+
scores: scored.scores,
|
|
436
|
+
rawH: scored.rawH,
|
|
437
|
+
rawOB: scored.rawOB,
|
|
438
|
+
});
|
|
272
439
|
});
|
|
273
440
|
|
|
274
441
|
const claimedDef = findClaimedModelInBank(claimedModel, bank);
|
|
442
|
+
const claimedExpectedFamily = claimedDef?.family || inferExpectedBankFamily(claimedModel);
|
|
443
|
+
const verdictPath = [];
|
|
444
|
+
|
|
275
445
|
if (valid.length === 0) {
|
|
446
|
+
verdictPath.push(
|
|
447
|
+
`valid_rounds=0/${outputs.length}(deg=${degenerateRejectedCount},dup=${duplicateRejectedCount})`,
|
|
448
|
+
'status=insufficient'
|
|
449
|
+
);
|
|
276
450
|
return {
|
|
277
451
|
bankModelCount: bank.models.length,
|
|
278
452
|
usedOutputs: 0,
|
|
@@ -280,25 +454,54 @@ export function attributeFingerprint(outputs, claimedModel, bankPath = DEFAULT_B
|
|
|
280
454
|
prediction: null,
|
|
281
455
|
predictionName: null,
|
|
282
456
|
probability: 0,
|
|
457
|
+
lowConfidence: true,
|
|
283
458
|
familyPrediction: null,
|
|
459
|
+
familyPredictionName: null,
|
|
284
460
|
familyProbability: 0,
|
|
461
|
+
familyProbabilities: [],
|
|
285
462
|
topCandidates: [],
|
|
286
463
|
claimedInBank: Boolean(claimedDef),
|
|
287
464
|
claimedCanonicalId: claimedDef?.id || null,
|
|
465
|
+
claimedExpectedFamily,
|
|
466
|
+
claimedModelRank: null,
|
|
467
|
+
claimedModelProb: null,
|
|
288
468
|
claimedMatchStatus: 'insufficient',
|
|
469
|
+
cvAccuracy: null,
|
|
470
|
+
topRawH: null,
|
|
471
|
+
topRawOB: null,
|
|
472
|
+
topJsSimilarity: null,
|
|
473
|
+
degenerateRejectedCount,
|
|
474
|
+
duplicateRejectedCount,
|
|
475
|
+
siblingClusterMatched: false,
|
|
476
|
+
verdictPath,
|
|
477
|
+
baselineProvenanceWarning: null,
|
|
289
478
|
};
|
|
290
479
|
}
|
|
291
480
|
|
|
292
481
|
const n = bank.models.length;
|
|
293
482
|
const combinedScores = new Array(n).fill(0);
|
|
483
|
+
const combinedRawH = new Array(n).fill(0);
|
|
484
|
+
const combinedRawOB = new Array(n).fill(0);
|
|
294
485
|
for (const v of valid) {
|
|
295
|
-
for (let c = 0; c < n; c += 1)
|
|
486
|
+
for (let c = 0; c < n; c += 1) {
|
|
487
|
+
combinedScores[c] += v.scores[c];
|
|
488
|
+
combinedRawH[c] += v.rawH[c];
|
|
489
|
+
combinedRawOB[c] += v.rawOB[c];
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
for (let c = 0; c < n; c += 1) {
|
|
493
|
+
combinedScores[c] /= valid.length;
|
|
494
|
+
combinedRawH[c] /= valid.length;
|
|
495
|
+
combinedRawOB[c] /= valid.length;
|
|
296
496
|
}
|
|
297
|
-
for (let c = 0; c < n; c += 1) combinedScores[c] /= valid.length;
|
|
298
497
|
|
|
299
|
-
const
|
|
300
|
-
const
|
|
301
|
-
const
|
|
498
|
+
const calibRound = Math.min(valid.length, 3);
|
|
499
|
+
const calibKey = String(calibRound);
|
|
500
|
+
const symmetricMode = usesSymmetricNuisanceOB(bank);
|
|
501
|
+
const defaultBeta = symmetricMode ? MERGED_BETA_BY_ROUNDS[calibRound] : 7.0;
|
|
502
|
+
const calib = bank.calibration?.[calibKey] || { beta: defaultBeta, cv_accuracy: null };
|
|
503
|
+
const beta = symmetricMode ? MERGED_BETA_BY_ROUNDS[calibRound] : calib.beta;
|
|
504
|
+
const probs = softmax(beta, combinedScores);
|
|
302
505
|
|
|
303
506
|
const pooledCounts = new Array(FP_DIMENSION).fill(0);
|
|
304
507
|
for (const v of valid) {
|
|
@@ -318,6 +521,8 @@ export function attributeFingerprint(outputs, claimedModel, bankPath = DEFAULT_B
|
|
|
318
521
|
familyName: m.family_name || m.family,
|
|
319
522
|
probability: Math.round(p * 10000) / 10000,
|
|
320
523
|
jsSimilarity: Math.round(jsSimilarity355(pooledCounts, m.counts) * 10000) / 10000,
|
|
524
|
+
rawH: Math.round(combinedRawH[idx] * 10000) / 10000,
|
|
525
|
+
rawOB: Math.round(combinedRawOB[idx] * 10000) / 10000,
|
|
321
526
|
score: Math.round(combinedScores[idx] * 1000) / 1000,
|
|
322
527
|
};
|
|
323
528
|
});
|
|
@@ -332,8 +537,12 @@ export function attributeFingerprint(outputs, claimedModel, bankPath = DEFAULT_B
|
|
|
332
537
|
.sort((a, b) => b.probability - a.probability);
|
|
333
538
|
|
|
334
539
|
const top = allResults[0];
|
|
540
|
+
const topModelDef = bank.models.find((m) => m.id === top.modelId) || null;
|
|
335
541
|
const winFam = familyProbabilities[0];
|
|
336
542
|
const lowConfidence = top.probability < 0.6;
|
|
543
|
+
const topRawH = top.rawH;
|
|
544
|
+
const topRawOB = top.rawOB;
|
|
545
|
+
const topJsSimilarity = top.jsSimilarity;
|
|
337
546
|
|
|
338
547
|
let claimedModelRank = null;
|
|
339
548
|
let claimedModelProb = null;
|
|
@@ -345,20 +554,83 @@ export function attributeFingerprint(outputs, claimedModel, bankPath = DEFAULT_B
|
|
|
345
554
|
}
|
|
346
555
|
}
|
|
347
556
|
|
|
348
|
-
const
|
|
557
|
+
const siblingGroup = claimedDef ? SIBLING_MODEL_GROUPS.find((g) => g.includes(claimedDef.id)) : null;
|
|
558
|
+
const siblingMatched = (() => {
|
|
559
|
+
if (!claimedDef || !siblingGroup || !siblingGroup.includes(top.modelId)) return false;
|
|
560
|
+
const combinedSiblingProb = allResults
|
|
561
|
+
.filter((r) => siblingGroup.includes(r.modelId))
|
|
562
|
+
.reduce((sum, r) => sum + r.probability, 0);
|
|
563
|
+
return combinedSiblingProb >= 0.6;
|
|
564
|
+
})();
|
|
565
|
+
const siblingClusterMatched = Boolean(siblingMatched && (top.modelId !== claimedDef.id || lowConfidence));
|
|
566
|
+
|
|
567
|
+
verdictPath.push(
|
|
568
|
+
`valid_rounds=${valid.length}/${outputs.length}`,
|
|
569
|
+
`top=${top.modelId}(p=${top.probability},rawH=${topRawH},rawOB=${topRawOB},js=${topJsSimilarity})`
|
|
570
|
+
);
|
|
571
|
+
|
|
349
572
|
let claimedMatchStatus = 'not_in_bank';
|
|
350
573
|
if (!claimedDef) {
|
|
351
|
-
|
|
574
|
+
const passesOodFitGate =
|
|
575
|
+
Boolean(claimedExpectedFamily) &&
|
|
576
|
+
Boolean(winFam) &&
|
|
577
|
+
winFam.family !== claimedExpectedFamily &&
|
|
578
|
+
winFam.probability >= 0.85 &&
|
|
579
|
+
topRawH >= 0.3 &&
|
|
580
|
+
topRawOB >= 0.3 &&
|
|
581
|
+
topJsSimilarity >= 0.78;
|
|
582
|
+
if (passesOodFitGate) {
|
|
352
583
|
claimedMatchStatus = 'family_mismatch';
|
|
584
|
+
verdictPath.push(`ood_gate=passed(fam=${winFam.family}:${winFam.probability})`, 'status=family_mismatch');
|
|
585
|
+
} else {
|
|
586
|
+
claimedMatchStatus = 'not_in_bank';
|
|
587
|
+
verdictPath.push('ood_gate=conservative_reject', 'status=not_in_bank');
|
|
353
588
|
}
|
|
589
|
+
} else if (siblingMatched) {
|
|
590
|
+
claimedMatchStatus = 'matched';
|
|
591
|
+
verdictPath.push(siblingClusterMatched ? 'sibling_cluster=matched' : 'exact_top1=matched', 'status=matched');
|
|
354
592
|
} else if (lowConfidence) {
|
|
355
593
|
claimedMatchStatus = 'low_confidence';
|
|
594
|
+
verdictPath.push(`low_conf(p=${top.probability}<0.6)`, 'status=low_confidence');
|
|
356
595
|
} else if (claimedModelRank === 1 || (claimedModelProb !== null && claimedModelProb >= 0.25)) {
|
|
357
596
|
claimedMatchStatus = 'matched';
|
|
597
|
+
verdictPath.push(`claimed_rank=${claimedModelRank}(p=${claimedModelProb})`, 'status=matched');
|
|
358
598
|
} else if (top.probability >= 0.72 && (claimedModelProb ?? 0) < 0.15) {
|
|
359
599
|
claimedMatchStatus = 'mismatch';
|
|
600
|
+
verdictPath.push(`claimed_rank=${claimedModelRank}(p=${claimedModelProb})`, 'candidate=mismatch');
|
|
360
601
|
} else {
|
|
361
602
|
claimedMatchStatus = 'low_confidence';
|
|
603
|
+
verdictPath.push('ambiguous_margin', 'status=low_confidence');
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
let baselineProvenanceWarning = null;
|
|
607
|
+
const claimedProv = classifyBaselineProvenance(claimedDef, nowMs);
|
|
608
|
+
const topProv = classifyBaselineProvenance(topModelDef, nowMs);
|
|
609
|
+
const nonDirectOrStaleClaimed = claimedDef && (claimedProv.tier === 'third_party_relay' || claimedProv.stale);
|
|
610
|
+
const nonDirectOrStaleTop = topModelDef && (topProv.tier === 'third_party_relay' || topProv.stale);
|
|
611
|
+
|
|
612
|
+
if (claimedMatchStatus === 'mismatch') {
|
|
613
|
+
const sameFamily = claimedDef && top.family === claimedDef.family;
|
|
614
|
+
if ((sameFamily && nonDirectOrStaleClaimed) || nonDirectOrStaleTop) {
|
|
615
|
+
const reasons = [];
|
|
616
|
+
if (nonDirectOrStaleClaimed) {
|
|
617
|
+
reasons.push(
|
|
618
|
+
`claimed baseline "${claimedDef.id}" is ${claimedProv.tier}${claimedProv.stale ? ` (${claimedProv.ageDays}d stale)` : ''}`
|
|
619
|
+
);
|
|
620
|
+
}
|
|
621
|
+
if (nonDirectOrStaleTop) {
|
|
622
|
+
reasons.push(
|
|
623
|
+
`winning baseline "${top.modelId}" is ${topProv.tier}${topProv.stale ? ` (${topProv.ageDays}d stale)` : ''}`
|
|
624
|
+
);
|
|
625
|
+
}
|
|
626
|
+
baselineProvenanceWarning = `Downgraded mismatch to low_confidence: ${reasons.join('; ')}`;
|
|
627
|
+
claimedMatchStatus = 'low_confidence';
|
|
628
|
+
verdictPath.push('provenance_guard=downgraded_to_low_confidence');
|
|
629
|
+
} else {
|
|
630
|
+
verdictPath.push('status=mismatch');
|
|
631
|
+
}
|
|
632
|
+
} else if (nonDirectOrStaleClaimed) {
|
|
633
|
+
baselineProvenanceWarning = `Reference baseline "${claimedDef.id}" sourced from ${claimedProv.tier}${claimedProv.stale ? ` (${claimedProv.ageDays}d old)` : ''}`;
|
|
362
634
|
}
|
|
363
635
|
|
|
364
636
|
return {
|
|
@@ -370,14 +642,24 @@ export function attributeFingerprint(outputs, claimedModel, bankPath = DEFAULT_B
|
|
|
370
642
|
probability: top.probability,
|
|
371
643
|
lowConfidence,
|
|
372
644
|
familyPrediction: winFam?.family || null,
|
|
645
|
+
familyPredictionName: winFam?.displayName || null,
|
|
373
646
|
familyProbability: winFam?.probability || 0,
|
|
374
647
|
familyProbabilities,
|
|
375
648
|
topCandidates: allResults.slice(0, 5),
|
|
376
649
|
claimedInBank: Boolean(claimedDef),
|
|
377
650
|
claimedCanonicalId: claimedDef?.id || null,
|
|
651
|
+
claimedExpectedFamily,
|
|
378
652
|
claimedModelRank,
|
|
379
653
|
claimedModelProb,
|
|
380
654
|
claimedMatchStatus,
|
|
381
655
|
cvAccuracy: calib.cv_accuracy ?? null,
|
|
656
|
+
topRawH,
|
|
657
|
+
topRawOB,
|
|
658
|
+
topJsSimilarity,
|
|
659
|
+
degenerateRejectedCount,
|
|
660
|
+
duplicateRejectedCount,
|
|
661
|
+
siblingClusterMatched,
|
|
662
|
+
verdictPath,
|
|
663
|
+
baselineProvenanceWarning,
|
|
382
664
|
};
|
|
383
665
|
}
|
package/src/links.mjs
CHANGED
|
@@ -4,9 +4,11 @@
|
|
|
4
4
|
* - Line 1 (always): site archive, pricing & live status lookup for the audited domain
|
|
5
5
|
* - Line 2 (only when actionable):
|
|
6
6
|
* - If an issue was detected -> verified alternative leaderboard for that model family
|
|
7
|
-
* - Else if model is outside the local
|
|
7
|
+
* - Else if model is outside the local 38-model bank -> online 38-model live bank
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
import { normalizeModelSlug } from './modelIdNormalize.mjs';
|
|
11
|
+
|
|
10
12
|
const TWO_PART_TLDS = new Set([
|
|
11
13
|
'com.cn',
|
|
12
14
|
'net.cn',
|
|
@@ -67,9 +69,9 @@ export function extractRootDomain(baseUrl) {
|
|
|
67
69
|
}
|
|
68
70
|
|
|
69
71
|
export function inferModelTagSlug(modelName) {
|
|
70
|
-
const m =
|
|
72
|
+
const m = normalizeModelSlug(modelName);
|
|
71
73
|
if (/claude|sonnet|opus|haiku|fable/.test(m)) return 'claude';
|
|
72
|
-
if (
|
|
74
|
+
if (/^(?:gpt|codex|o[134](?:-|$)|chatgpt)/.test(m)) return 'openai';
|
|
73
75
|
if (/gemini/.test(m)) return 'gemini';
|
|
74
76
|
if (/deepseek/.test(m)) return 'deepseek';
|
|
75
77
|
return null;
|
|
@@ -90,6 +92,8 @@ export function hasAuditIssue(results = {}) {
|
|
|
90
92
|
}
|
|
91
93
|
if (results.logic && (results.logic.status === 'fail' || results.logic.hitTrap)) return true;
|
|
92
94
|
if (results.fingerprint && results.fingerprint.status === 'fail') return true;
|
|
95
|
+
if (results.signature && results.signature.status === 'fail') return true;
|
|
96
|
+
if (results.multimodal && results.multimodal.status === 'fail') return true;
|
|
93
97
|
return false;
|
|
94
98
|
}
|
|
95
99
|
|
|
@@ -117,9 +121,12 @@ export function buildContextualFooter({ baseUrl, model, results }) {
|
|
|
117
121
|
? `https://www.aiapipk.com/tag/${slug}/?from=cli`
|
|
118
122
|
: 'https://www.aiapipk.com/directory/?from=cli',
|
|
119
123
|
});
|
|
120
|
-
} else if (
|
|
124
|
+
} else if (
|
|
125
|
+
results?.fingerprint?.claimedMatchStatus === 'not_in_bank' ||
|
|
126
|
+
results?.fingerprint?.claimedMatchStatus === 'out_of_bank'
|
|
127
|
+
) {
|
|
121
128
|
lines.push({
|
|
122
|
-
label: '
|
|
129
|
+
label: '38-model live bank',
|
|
123
130
|
url: 'https://www.aiapipk.com/detect/?tab=fingerprint&from=cli',
|
|
124
131
|
});
|
|
125
132
|
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified model ID normalization and canonical family inference.
|
|
3
|
+
*
|
|
4
|
+
* Strips common third-party relay / cloud prefixes and suffixes such as:
|
|
5
|
+
* - Bracketed relay tags: [官转], [逆向], [特价], 【官转】
|
|
6
|
+
* - Cloud/gateway prefixes: us.anthropic., eu.anthropic., global.anthropic.,
|
|
7
|
+
* bedrock/, vertex_ai/, openrouter/, azure/, dashscope/, openai/, anthropic/, etc.
|
|
8
|
+
* - Suffixes: -v1:0, :thinking, :free, :exacto, @20251001, -20251001, -latest, -thinking
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const LEADING_BRACKET_TAG_RE = /^\s*(?:\[[^\]]+\]|【[^】]+】|\([^)]+\))\s*/;
|
|
12
|
+
const TRAILING_BRACKET_TAG_RE = /\s*(?:\[[^\]]+\]|【[^】]+】)\s*$/;
|
|
13
|
+
|
|
14
|
+
const PATH_PREFIX_RE =
|
|
15
|
+
/^(?:openai|anthropic|moonshotai|moonshot|deepseek|xai|x-ai|google|qwen|alibaba|aliyun|dashscope|zhipu|z-ai|zai|bedrock|aws|aws-bedrock|vertex|vertex_ai|vertex-ai|gcp|openrouter|azure|azure-openai|groq|together|together_ai|fireworks|siliconflow|volcengine|ark|minimax|mistralai|meta-llama|perplexity|cohere|cloudflare|models|publishers\/[^/]+\/models)\//i;
|
|
16
|
+
|
|
17
|
+
const DOT_REGION_PREFIX_RE =
|
|
18
|
+
/^(?:(?:us|eu|ap|apac|global|au|ca|jp)\.)?(?:anthropic|amazon|meta|deepseek|mistral|cohere|google)\./i;
|
|
19
|
+
|
|
20
|
+
const SUFFIX_RE =
|
|
21
|
+
/(?:-v\d+:\d+|:(?:thinking|free|exacto|nitro|online|extended|beta|floor|latest|high|medium|low)|@202\d{5}|[-_](?:202\d{5}|20\d{2}[-_]\d{2}[-_]\d{2}|latest))$/i;
|
|
22
|
+
|
|
23
|
+
const TRAILING_THINKING_VARIANT_RE =
|
|
24
|
+
/^((?:claude|gpt|o[134]|gemini|qwen|kimi|glm|deepseek|opus|sonnet|haiku|fable).+?)[-_]thinking$/i;
|
|
25
|
+
|
|
26
|
+
export function normalizeModelSlug(rawName) {
|
|
27
|
+
let s = String(rawName || '').trim();
|
|
28
|
+
if (!s) return '';
|
|
29
|
+
|
|
30
|
+
// Strip leading/trailing relay tags like [官转], 【逆向】, etc.
|
|
31
|
+
for (let i = 0; i < 4; i += 1) {
|
|
32
|
+
const prev = s;
|
|
33
|
+
s = s.replace(LEADING_BRACKET_TAG_RE, '').replace(TRAILING_BRACKET_TAG_RE, '').trim();
|
|
34
|
+
if (s === prev) break;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
s = s.toLowerCase();
|
|
38
|
+
|
|
39
|
+
// Iteratively peel nested gateway/cloud path and region prefixes
|
|
40
|
+
for (let i = 0; i < 6; i += 1) {
|
|
41
|
+
const prev = s;
|
|
42
|
+
s = s.replace(PATH_PREFIX_RE, '').replace(DOT_REGION_PREFIX_RE, '');
|
|
43
|
+
if (s === prev) break;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Iteratively peel version/mode/date suffixes (e.g. -20260217-v1:0, :thinking, @20260205, -latest)
|
|
47
|
+
for (let i = 0; i < 6; i += 1) {
|
|
48
|
+
const prev = s;
|
|
49
|
+
s = s.replace(SUFFIX_RE, '');
|
|
50
|
+
const thinkingMatch = s.match(TRAILING_THINKING_VARIANT_RE);
|
|
51
|
+
if (thinkingMatch) s = thinkingMatch[1];
|
|
52
|
+
if (s === prev) break;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return s
|
|
56
|
+
.replace(/[._\s]+/g, '-')
|
|
57
|
+
.replace(/-{2,}/g, '-')
|
|
58
|
+
.replace(/^-+|-+$/g, '');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Infer canonical family among the 7 families enrolled in the 38-model fingerprint bank.
|
|
63
|
+
* Unenrolled families (Grok, Llama, Mistral, etc.) return null to avoid false cross-family alarms.
|
|
64
|
+
*/
|
|
65
|
+
export function inferCanonicalBankFamily(rawName) {
|
|
66
|
+
const s = normalizeModelSlug(rawName);
|
|
67
|
+
if (!s) return null;
|
|
68
|
+
if (/^(?:claude|opus|sonnet|haiku|fable)(?:-|$)/i.test(s)) return 'claude';
|
|
69
|
+
if (/^(?:gpt-\d|chatgpt|codex|o[134](?:-|$))/i.test(s)) return 'gpt';
|
|
70
|
+
if (/deepseek/i.test(s)) return 'deepseek';
|
|
71
|
+
if (/^gemini-\d/i.test(s)) return 'gemini';
|
|
72
|
+
if (/^qwen-?\d/i.test(s)) return 'qwen';
|
|
73
|
+
if (/^kimi-k\d/i.test(s)) return 'kimi';
|
|
74
|
+
if (/^glm-\d/i.test(s)) return 'zhipu';
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Infer broader canonical vendor family (includes non-banked vendors for informational use).
|
|
80
|
+
*/
|
|
81
|
+
export function inferCanonicalVendorFamily(rawName) {
|
|
82
|
+
const bankFam = inferCanonicalBankFamily(rawName);
|
|
83
|
+
if (bankFam) return bankFam;
|
|
84
|
+
const s = normalizeModelSlug(rawName);
|
|
85
|
+
if (!s) return null;
|
|
86
|
+
if (/^grok(?:-|$)/i.test(s)) return 'grok';
|
|
87
|
+
if (/^(?:llama|meta-llama)(?:-|$)/i.test(s)) return 'llama';
|
|
88
|
+
if (/^(?:mistral|mixtral|codestral|pixtral|ministral)(?:-|$)/i.test(s)) return 'mistral';
|
|
89
|
+
if (/^(?:minimax|abab)(?:-|$)/i.test(s)) return 'minimax';
|
|
90
|
+
if (/^(?:command|cohere)(?:-|$)/i.test(s)) return 'cohere';
|
|
91
|
+
if (/^(?:sonar|pplx)(?:-|$)/i.test(s)) return 'perplexity';
|
|
92
|
+
if (/^(?:doubao|seed)(?:-|$)/i.test(s)) return 'bytedance';
|
|
93
|
+
return null;
|
|
94
|
+
}
|