llm-api-purity-check 0.0.0-stage → 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/LICENSE +27 -0
- package/README.md +161 -2
- package/README_CN.md +122 -0
- package/bin/cli.mjs +415 -0
- package/data/bank.generated.json +1 -0
- package/package.json +39 -4
- package/scripts/sync-bank.mjs +333 -0
- package/skills/aiapipk-check/SKILL.md +134 -0
- package/src/checks.mjs +1273 -0
- package/src/client.mjs +1240 -0
- package/src/fingerprint.mjs +665 -0
- package/src/links.mjs +135 -0
- package/src/modelIdNormalize.mjs +94 -0
package/src/links.mjs
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contextual, restrained AIAPIPK links emitted at the end of a CLI audit.
|
|
3
|
+
* Strictly capped at 1-2 high-signal lines (never spam):
|
|
4
|
+
* - Line 1 (always): site archive, pricing & live status lookup for the audited domain
|
|
5
|
+
* - Line 2 (only when actionable):
|
|
6
|
+
* - If an issue was detected -> verified alternative leaderboard for that model family
|
|
7
|
+
* - Else if model is outside the local 38-model bank -> online 38-model live bank
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { normalizeModelSlug } from './modelIdNormalize.mjs';
|
|
11
|
+
|
|
12
|
+
const TWO_PART_TLDS = new Set([
|
|
13
|
+
'com.cn',
|
|
14
|
+
'net.cn',
|
|
15
|
+
'org.cn',
|
|
16
|
+
'gov.cn',
|
|
17
|
+
'co.uk',
|
|
18
|
+
'org.uk',
|
|
19
|
+
'co.jp',
|
|
20
|
+
'ne.jp',
|
|
21
|
+
'com.hk',
|
|
22
|
+
'com.tw',
|
|
23
|
+
'com.sg',
|
|
24
|
+
'com.au',
|
|
25
|
+
'co.kr',
|
|
26
|
+
]);
|
|
27
|
+
|
|
28
|
+
const PROXY_SUBDOMAIN_PREFIXES = new Set([
|
|
29
|
+
'api',
|
|
30
|
+
'www',
|
|
31
|
+
'v1',
|
|
32
|
+
'v2',
|
|
33
|
+
'proxy',
|
|
34
|
+
'gateway',
|
|
35
|
+
'gw',
|
|
36
|
+
'relay',
|
|
37
|
+
'openai',
|
|
38
|
+
'claude',
|
|
39
|
+
'anthropic',
|
|
40
|
+
'ai',
|
|
41
|
+
'llm',
|
|
42
|
+
'chat',
|
|
43
|
+
'router',
|
|
44
|
+
]);
|
|
45
|
+
|
|
46
|
+
export function extractRootDomain(baseUrl) {
|
|
47
|
+
const raw = String(baseUrl || '').trim();
|
|
48
|
+
if (!raw) return null;
|
|
49
|
+
let hostname = '';
|
|
50
|
+
try {
|
|
51
|
+
hostname = new URL(/^https?:\/\//i.test(raw) ? raw : `https://${raw}`).hostname.toLowerCase();
|
|
52
|
+
} catch {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
if (!hostname || hostname === 'localhost' || /^(\d{1,3}\.){3}\d{1,3}$/.test(hostname) || hostname.includes(':')) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
const parts = hostname.split('.').filter(Boolean);
|
|
59
|
+
if (parts.length <= 2) return hostname;
|
|
60
|
+
|
|
61
|
+
const lastTwo = `${parts[parts.length - 2]}.${parts[parts.length - 1]}`;
|
|
62
|
+
if (TWO_PART_TLDS.has(lastTwo) && parts.length >= 3) {
|
|
63
|
+
return `${parts[parts.length - 3]}.${lastTwo}`;
|
|
64
|
+
}
|
|
65
|
+
if (parts.length === 3 && PROXY_SUBDOMAIN_PREFIXES.has(parts[0])) {
|
|
66
|
+
return lastTwo;
|
|
67
|
+
}
|
|
68
|
+
return lastTwo;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function inferModelTagSlug(modelName) {
|
|
72
|
+
const m = normalizeModelSlug(modelName);
|
|
73
|
+
if (/claude|sonnet|opus|haiku|fable/.test(m)) return 'claude';
|
|
74
|
+
if (/^(?:gpt|codex|o[134](?:-|$)|chatgpt)/.test(m)) return 'openai';
|
|
75
|
+
if (/gemini/.test(m)) return 'gemini';
|
|
76
|
+
if (/deepseek/.test(m)) return 'deepseek';
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function hasAuditIssue(results = {}) {
|
|
81
|
+
if (!results || typeof results !== 'object') return false;
|
|
82
|
+
if (results.inject && results.inject.status === 'fail') return true;
|
|
83
|
+
if (results.stream && results.stream.status === 'fail') return true;
|
|
84
|
+
if (results.cache && results.cache.status === 'fail') return true;
|
|
85
|
+
if (
|
|
86
|
+
results.cache &&
|
|
87
|
+
results.cache.status !== 'error' &&
|
|
88
|
+
typeof results.cache.cacheHitRate === 'number' &&
|
|
89
|
+
results.cache.cacheHitRate === 0
|
|
90
|
+
) {
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
if (results.logic && (results.logic.status === 'fail' || results.logic.hitTrap)) return true;
|
|
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;
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function buildContextualFooter({ baseUrl, model, results }) {
|
|
101
|
+
const rootDomain = extractRootDomain(baseUrl);
|
|
102
|
+
const lines = [];
|
|
103
|
+
|
|
104
|
+
if (rootDomain) {
|
|
105
|
+
lines.push({
|
|
106
|
+
label: 'Site archive & pricing',
|
|
107
|
+
url: `https://www.aiapipk.com/directory/?q=${encodeURIComponent(rootDomain)}&from=cli`,
|
|
108
|
+
});
|
|
109
|
+
} else {
|
|
110
|
+
lines.push({
|
|
111
|
+
label: 'Live 370+ relay radar',
|
|
112
|
+
url: 'https://www.aiapipk.com/directory/?from=cli',
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (hasAuditIssue(results)) {
|
|
117
|
+
const slug = inferModelTagSlug(model);
|
|
118
|
+
lines.push({
|
|
119
|
+
label: slug ? `Verified ${slug} relays` : 'Verified online relays',
|
|
120
|
+
url: slug
|
|
121
|
+
? `https://www.aiapipk.com/tag/${slug}/?from=cli`
|
|
122
|
+
: 'https://www.aiapipk.com/directory/?from=cli',
|
|
123
|
+
});
|
|
124
|
+
} else if (
|
|
125
|
+
results?.fingerprint?.claimedMatchStatus === 'not_in_bank' ||
|
|
126
|
+
results?.fingerprint?.claimedMatchStatus === 'out_of_bank'
|
|
127
|
+
) {
|
|
128
|
+
lines.push({
|
|
129
|
+
label: '38-model live bank',
|
|
130
|
+
url: 'https://www.aiapipk.com/detect/?tab=fingerprint&from=cli',
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return lines;
|
|
135
|
+
}
|
|
@@ -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
|
+
}
|