@yhong91/cpac 0.1.28 → 0.1.29
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 +2 -2
- package/dist/agents.js +2 -2
- package/dist/pi-extension.template +6 -6
- package/dist/targets/pi.js +24 -6
- package/package.json +1 -2
package/README.md
CHANGED
|
@@ -285,7 +285,7 @@ cpac opencode [--] [opencode args...]
|
|
|
285
285
|
cpac pi install
|
|
286
286
|
```
|
|
287
287
|
|
|
288
|
-
它将生成 `cpac.ts` 写入 `~/.pi/agent/extensions/`,Pi 启动时自动加载并从 CPA 动态注册模型目录。卸载:
|
|
288
|
+
它将生成 `pi-cpac.ts` 写入 `~/.pi/agent/extensions/`,Pi 启动时自动加载并从 CPA 动态注册模型目录。卸载:
|
|
289
289
|
|
|
290
290
|
```bash
|
|
291
291
|
cpac restore --target pi
|
|
@@ -326,7 +326,7 @@ CPAC CLI 可临时覆盖 CPA 地址:
|
|
|
326
326
|
CPA_BASE_URL='https://cpa.example.com' cpac claude
|
|
327
327
|
```
|
|
328
328
|
|
|
329
|
-
`pi-
|
|
329
|
+
`pi-cpac.ts` 插件固定连接配置指定的 CPA 地址,并且只从 Pi 进程环境读取 `CPA_API_KEY`;不读取用户 home 中的私有文件。
|
|
330
330
|
|
|
331
331
|
## 可选 JSON 配置
|
|
332
332
|
|
package/dist/agents.js
CHANGED
|
@@ -209,14 +209,14 @@ const TARGETS = [
|
|
|
209
209
|
version: () => detectClientVersion("pi"),
|
|
210
210
|
install: async (config, dryRun) => {
|
|
211
211
|
if (dryRun) {
|
|
212
|
-
console.log(`would write Pi extension: ${join(piExtensionsDir(), "cpac.ts")}`);
|
|
212
|
+
console.log(`would write Pi extension: ${join(piExtensionsDir(), "pi-cpac.ts")}`);
|
|
213
213
|
return;
|
|
214
214
|
}
|
|
215
215
|
await installPiExtension(config);
|
|
216
216
|
},
|
|
217
217
|
uninstall: async (_config, dryRun) => {
|
|
218
218
|
if (dryRun) {
|
|
219
|
-
console.log(`would remove Pi extension: ${join(piExtensionsDir(), "cpac.ts")}`);
|
|
219
|
+
console.log(`would remove Pi extension: ${join(piExtensionsDir(), "pi-cpac.ts")}`);
|
|
220
220
|
return;
|
|
221
221
|
}
|
|
222
222
|
await uninstallPiExtension();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// CPAC
|
|
1
|
+
// Pi CPAC extension: register CPA models as Pi providers
|
|
2
2
|
// Installed by: cpac pi install
|
|
3
3
|
|
|
4
4
|
const CPA = "__CPA_URL__";
|
|
@@ -71,7 +71,7 @@ function intField(value) {
|
|
|
71
71
|
export default async function (pi) {
|
|
72
72
|
const apiKey = (process.env.CPA_API_KEY || "").trim();
|
|
73
73
|
if (!apiKey) {
|
|
74
|
-
console.error("[cpac] CPA_API_KEY not set; skipping CPA providers");
|
|
74
|
+
console.error("[pi-cpac] CPA_API_KEY not set; skipping CPA providers");
|
|
75
75
|
return;
|
|
76
76
|
}
|
|
77
77
|
let payload;
|
|
@@ -81,19 +81,19 @@ export default async function (pi) {
|
|
|
81
81
|
signal: AbortSignal.timeout(10000),
|
|
82
82
|
});
|
|
83
83
|
if (!res.ok) {
|
|
84
|
-
console.error("[cpac] CPA models request failed: HTTP " + res.status);
|
|
84
|
+
console.error("[pi-cpac] CPA models request failed: HTTP " + res.status);
|
|
85
85
|
return;
|
|
86
86
|
}
|
|
87
87
|
payload = await res.json();
|
|
88
88
|
} catch (error) {
|
|
89
|
-
console.error("[cpac] CPA models request failed: " + (error && error.message || error));
|
|
89
|
+
console.error("[pi-cpac] CPA models request failed: " + (error && error.message || error));
|
|
90
90
|
return;
|
|
91
91
|
}
|
|
92
92
|
const source = payload && Array.isArray(payload.models)
|
|
93
93
|
? payload.models
|
|
94
94
|
: payload && Array.isArray(payload.data) ? payload.data : null;
|
|
95
95
|
if (!source) {
|
|
96
|
-
console.error("[cpac] CPA models response has no models list");
|
|
96
|
+
console.error("[pi-cpac] CPA models response has no models list");
|
|
97
97
|
return;
|
|
98
98
|
}
|
|
99
99
|
const rows = [];
|
|
@@ -110,7 +110,7 @@ export default async function (pi) {
|
|
|
110
110
|
});
|
|
111
111
|
}
|
|
112
112
|
if (rows.length === 0) {
|
|
113
|
-
console.error("[cpac] CPA models response has no usable models");
|
|
113
|
+
console.error("[pi-cpac] CPA models response has no usable models");
|
|
114
114
|
return;
|
|
115
115
|
}
|
|
116
116
|
const groups = new Map();
|
package/dist/targets/pi.js
CHANGED
|
@@ -7,7 +7,8 @@ export function piExtensionsDir() {
|
|
|
7
7
|
return join(expandUserPath(process.env.PI_CODING_AGENT_DIR?.trim() || join(homedir(), ".pi", "agent")), "extensions");
|
|
8
8
|
}
|
|
9
9
|
export function isPiExtensionInstalled() {
|
|
10
|
-
|
|
10
|
+
const dir = piExtensionsDir();
|
|
11
|
+
return existsSync(join(dir, "pi-cpac.ts")) || existsSync(join(dir, "cpac.ts"));
|
|
11
12
|
}
|
|
12
13
|
function piTemplatePath() {
|
|
13
14
|
return join(dirname(fileURLToPath(import.meta.url)), "..", "pi-extension.template");
|
|
@@ -18,15 +19,32 @@ function piExtensionContent(cpaUrl) {
|
|
|
18
19
|
export async function installPiExtension(config) {
|
|
19
20
|
const dir = piExtensionsDir();
|
|
20
21
|
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
21
|
-
const target = join(dir, "cpac.ts");
|
|
22
|
+
const target = join(dir, "pi-cpac.ts");
|
|
22
23
|
ensureCpacBackup(target);
|
|
23
24
|
atomicWrite(target, Buffer.from(piExtensionContent(config.cpa_url)), 0o644);
|
|
25
|
+
for (const legacy of ["cpac.ts", "pi-cpa.ts"]) {
|
|
26
|
+
const legacyPath = join(dir, legacy);
|
|
27
|
+
if (existsSync(legacyPath) && legacyPath !== target) {
|
|
28
|
+
try {
|
|
29
|
+
unlinkSync(legacyPath);
|
|
30
|
+
}
|
|
31
|
+
catch { }
|
|
32
|
+
}
|
|
33
|
+
}
|
|
24
34
|
console.log(`Installed Pi extension: ${target}`);
|
|
25
35
|
}
|
|
26
36
|
export async function uninstallPiExtension() {
|
|
27
|
-
const
|
|
28
|
-
|
|
37
|
+
const dir = piExtensionsDir();
|
|
38
|
+
const target = join(dir, "pi-cpac.ts");
|
|
39
|
+
const legacyTargets = [join(dir, "cpac.ts"), join(dir, "pi-cpa.ts")];
|
|
40
|
+
let removed = false;
|
|
41
|
+
for (const file of [target, ...legacyTargets]) {
|
|
42
|
+
if (existsSync(file)) {
|
|
43
|
+
unlinkSync(file);
|
|
44
|
+
console.log(`Removed Pi extension: ${file}`);
|
|
45
|
+
removed = true;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (!removed)
|
|
29
49
|
throw new CPACError("Pi extension is not installed");
|
|
30
|
-
unlinkSync(target);
|
|
31
|
-
console.log(`Removed Pi extension: ${target}`);
|
|
32
50
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yhong91/cpac",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.29",
|
|
4
4
|
"description": "Connect Codex and Claude Code to a remote CLIProxyAPI gateway",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -30,7 +30,6 @@
|
|
|
30
30
|
"clean": "node -e \"for (const d of ['dist','dist-test']) require('fs').rmSync(d,{recursive:true,force:true})\"",
|
|
31
31
|
"build": "npm run clean --if-present && tsc -p tsconfig.build.json && cp src/pi-extension.template dist/ && node -e \"const fs=require('fs');const p='dist/cpac.js';const s=fs.readFileSync(p,'utf8');if(!s.startsWith('#!'))fs.writeFileSync(p,'#!/usr/bin/env node\\n'+s);try{fs.chmodSync(p,0o755)}catch{}\"",
|
|
32
32
|
"check": "tsc -p tsconfig.json --noEmit",
|
|
33
|
-
"check:pi": "tsc -p tsconfig.pi.json --noEmit",
|
|
34
33
|
"test": "npm run clean && tsc -p tsconfig.test.json && cp src/pi-extension.template dist-test/src/ && node --test --test-reporter=spec dist-test/cpac.test.js",
|
|
35
34
|
"pack:check": "npm pack --dry-run"
|
|
36
35
|
},
|