@yhong91/cpac 0.2.1 → 0.2.3
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 +1 -1
- package/dist/ping.js +18 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -369,7 +369,7 @@ cpac restore cline
|
|
|
369
369
|
|
|
370
370
|
```bash
|
|
371
371
|
cpac ping codex # 目录里匹配 gpt-*-luna 的一条
|
|
372
|
-
cpac ping agy # gemini
|
|
372
|
+
cpac ping agy # 目录里匹配 gemini-*-flash* 的一条,以及 claude-sonnet-4-6
|
|
373
373
|
```
|
|
374
374
|
|
|
375
375
|
用 `CPA_API_KEY`。日志只打模型、HTTP 状态和不含 key 的 `x-cpa-*` trace。CPA 按账号轮询,一次只会落在一个账号上。
|
package/dist/ping.js
CHANGED
|
@@ -1,15 +1,26 @@
|
|
|
1
1
|
import { apiBase, catalogSlugs, fetchCatalog } from "./config.js";
|
|
2
2
|
import { CPACError } from "./util.js";
|
|
3
3
|
const LUNA = /^gpt-.+-luna$/;
|
|
4
|
+
const GEMINI_EXACT = /^gemini-.+-flash$/;
|
|
5
|
+
const GEMINI_SUFFIX = /^gemini-.+-flash.+$/;
|
|
4
6
|
export const PING_MODELS = {
|
|
5
|
-
agy: ["
|
|
7
|
+
agy: ["claude-sonnet-4-6"],
|
|
6
8
|
};
|
|
9
|
+
function lastMatch(slugs, pattern) {
|
|
10
|
+
return slugs.filter((slug) => pattern.test(slug)).sort().at(-1);
|
|
11
|
+
}
|
|
7
12
|
export function matchLuna(slugs) {
|
|
8
|
-
const model = slugs
|
|
13
|
+
const model = lastMatch(slugs, LUNA);
|
|
9
14
|
if (!model)
|
|
10
15
|
throw new CPACError("no catalog model matches gpt-*-luna");
|
|
11
16
|
return model;
|
|
12
17
|
}
|
|
18
|
+
export function matchGemini(slugs) {
|
|
19
|
+
const model = lastMatch(slugs, GEMINI_EXACT) ?? lastMatch(slugs, GEMINI_SUFFIX);
|
|
20
|
+
if (!model)
|
|
21
|
+
throw new CPACError("no catalog model matches gemini-*-flash*");
|
|
22
|
+
return model;
|
|
23
|
+
}
|
|
13
24
|
const EMAIL_RE = /[A-Za-z0-9._%+\-]+@/g;
|
|
14
25
|
function redact(value) {
|
|
15
26
|
return String(value).replace(EMAIL_RE, "*@");
|
|
@@ -22,9 +33,8 @@ export async function runPing(config, target, deps = {}) {
|
|
|
22
33
|
if (!apiKey)
|
|
23
34
|
throw new CPACError(`environment variable ${config.api_key_env} is not set`);
|
|
24
35
|
const url = `${apiBase(config.cpa_url)}/chat/completions`;
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
: PING_MODELS[target];
|
|
36
|
+
const slugs = catalogSlugs((await fetchCatalog(config.cpa_url, apiKey)).bytes);
|
|
37
|
+
const models = target === "codex" ? [matchLuna(slugs)] : [matchGemini(slugs), ...PING_MODELS.agy];
|
|
28
38
|
let failed = 0;
|
|
29
39
|
for (const model of models) {
|
|
30
40
|
let response;
|
|
@@ -51,14 +61,15 @@ export async function runPing(config, target, deps = {}) {
|
|
|
51
61
|
failed += 1;
|
|
52
62
|
continue;
|
|
53
63
|
}
|
|
54
|
-
await response.
|
|
64
|
+
const text = await response.text();
|
|
55
65
|
const trace = [];
|
|
56
66
|
response.headers.forEach((value, key) => {
|
|
57
67
|
const name = key.toLowerCase();
|
|
58
68
|
if (name.startsWith("x-cpa-") && !name.includes("key"))
|
|
59
69
|
trace.push(`${name}=${redact(value)}`);
|
|
60
70
|
});
|
|
61
|
-
|
|
71
|
+
const detail = response.status === 200 ? "" : ` ${redact(text).replaceAll(apiKey, "***").slice(0, 180)}`;
|
|
72
|
+
log(`${model} HTTP ${response.status}${trace.length ? ` ${trace.join(" ")}` : ""}${detail}`);
|
|
62
73
|
if (response.status !== 200)
|
|
63
74
|
failed += 1;
|
|
64
75
|
}
|