@yhong91/cpac 0.1.39 → 0.1.40

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 CHANGED
@@ -113,6 +113,7 @@ Commands:
113
113
  cpac <agent> [args...] Launch an agent through CPA
114
114
  cpac setup Show current Codex/Claude setup
115
115
  cpac status Show agent support status
116
+ cpac models List remote CPA catalog models
116
117
  cpac restore <codex|pi|kimi|grok|zed> | --all Detach injected agents
117
118
  cpac --help Show command usage
118
119
  ```
@@ -165,6 +166,7 @@ cpac --help
165
166
 
166
167
  ```bash
167
168
  cpac detect [--json]
169
+ cpac models [--json]
168
170
  cpac install [codex|pi|kimi|grok|zed...] [--all] [--dry-run] [--force] [--v2_off] [--v2_models] [--max_context]
169
171
  cpac sync [codex|pi|kimi|grok|zed...] [--all] [--dry-run] [--v2_off] [--v2_models] [--max_context]
170
172
  cpac restore <codex|pi|kimi|grok|zed...> | --all [--dry-run]
@@ -173,6 +175,7 @@ cpac upgrade [--check]
173
175
  cpac -v | --version
174
176
  ```
175
177
 
178
+ - `models` 从远端 CPA 拉取 rich catalog,默认一行一个 slug;`--json` 输出 `cpa_url` 和模型字段(`slug` / `display_name` / `context_window`)。用来核对 catalog 里有没有某个模型(例如 `*-fast`),不写本地配置。
176
179
  - `detect` 列出每个目标是否被检测到、是否已接入 CPAC;`--json` 输出机器可读结果。
177
180
  - `install` 默认作用于检测到的目标;后面直接写 agent 名(`cpac install codex pi`),`--all` 全部。`codex` 写入 catalog 并拉起 loopback 代理;`pi`/`kimi`/`grok`/`zed` 写入各自配置。`--dry-run` 只打印将要做的事,`--force` 允许重装已安装目标。
178
181
  - `sync` 按当前 `cpa_url` 和 CPA 目录强制刷新**已经接入**的目标(Codex 重新注入、Pi 按 CLI 版本决定写入 packages / `pi update` / 跳过,并清理旧的 `extensions/pi-cpac.ts`、Kimi / Grok / Zed 配置重写),用来在 CPA 地址或模型目录变化后一次对齐本地配置。不带参数只动已安装目标;`--all` 会对检测到的目标做同样的强制刷新(尚未安装的会装上)。`--max_context` 仍只对 `cpac install codex` 有效。
package/dist/cpac.js CHANGED
@@ -10,7 +10,7 @@ import { isGrokConfigInstalled } from "./targets/grok.js";
10
10
  import { isKimiConfigInstalled } from "./targets/kimi.js";
11
11
  import { isPiExtensionInstalled } from "./targets/pi.js";
12
12
  import { isZedConfigInstalled } from "./targets/zed.js";
13
- import { defaultConfigPath, loadConfig, originalBytes, pickSpawnModels, readState, saveSpawnModels, stateProxy, catalogMaxContextLive, } from "./config.js";
13
+ import { defaultConfigPath, loadConfig, originalBytes, pickSpawnModels, readState, saveSpawnModels, stateProxy, catalogMaxContextLive, catalogModelId, catalogModelRows, catalogSlugs, fetchCatalog, } from "./config.js";
14
14
  import { proxyIsHealthy, runProxyChild } from "./proxy.js";
15
15
  import { CPACError, expandUserPath, promptSecret, saveApiKeyExport, shellProfile, } from "./util.js";
16
16
  export { PROVIDER, loadConfig, saveSpawnModels, saveCodexSetup, liftContextWindows, reorderCatalog, sanitizeCatalogModalities, stampMultiAgentVersion, catalogMaxContextLive, readState, stateProxy, } from "./config.js";
@@ -83,12 +83,42 @@ export async function status(config) {
83
83
  return 2;
84
84
  return 0;
85
85
  }
86
+ async function listModels(config, json) {
87
+ const apiKey = process.env[config.api_key_env]?.trim();
88
+ if (!apiKey)
89
+ throw new CPACError(`environment variable ${config.api_key_env} is not set`);
90
+ const catalog = await fetchCatalog(config.cpa_url, apiKey);
91
+ if (!json) {
92
+ for (const slug of catalogSlugs(catalog.bytes))
93
+ console.log(slug);
94
+ return 0;
95
+ }
96
+ const document = JSON.parse(new TextDecoder().decode(catalog.bytes));
97
+ const models = (catalogModelRows(document) ?? []).flatMap((row) => {
98
+ const slug = catalogModelId(row);
99
+ if (!slug)
100
+ return [];
101
+ const display = typeof row.display_name === "string" && row.display_name.trim()
102
+ ? row.display_name.trim()
103
+ : slug;
104
+ const context = typeof row.context_window === "number" && row.context_window > 0
105
+ ? Math.floor(row.context_window)
106
+ : undefined;
107
+ return [
108
+ context !== undefined
109
+ ? { slug, display_name: display, context_window: context }
110
+ : { slug, display_name: display },
111
+ ];
112
+ });
113
+ console.log(JSON.stringify({ cpa_url: config.cpa_url, count: models.length, models }, null, 2));
114
+ return 0;
115
+ }
86
116
  async function guide(config) {
87
117
  console.log(`CPA Companion\n\nCPA: ${config.cpa_url}\nCPA_API_KEY: ${process.env[config.api_key_env]?.trim() ? "configured" : "not configured"}\n\nCommands:\n cpac <agent> [args...] Launch an agent (codex, kimi, grok, pi, zed, claude) through CPA\n cpac setup Show current Codex/Claude setup; cpac setup <codex|claude> to change\n cpac status Show agent support status (Codex, Claude, Pi, Kimi, Grok, Zed)\n cpac restore <codex|pi|kimi|grok|zed> | --all Detach injected agents
88
118
  cpac detect Show supported targets and install status
89
119
  cpac install [codex|pi|kimi|grok|zed...] Install CPA into detected targets, or named agents
90
120
  cpac sync Refresh installed Codex/Pi/Kimi/Grok/Zed injections from CPA
91
- cpac uninstall Detach all agents, then remove the cpac package (confirms first)\n cpac upgrade Update cpac from npm and sync installed agents\n cpac --help Show command usage`);
121
+ cpac uninstall Detach all agents, then remove the cpac package (confirms first)\n cpac upgrade Update cpac from npm and sync installed agents\n cpac models List remote CPA catalog models\n cpac --help Show command usage`);
92
122
  if (process.env[config.api_key_env]?.trim())
93
123
  return 0;
94
124
  const apiKey = await promptSecret(config.api_key_env);
@@ -109,6 +139,7 @@ function usage() {
109
139
  " codex [--v2_off] [--v2_models] [--max_context]",
110
140
  " cpac restore <codex|pi|kimi|grok|zed...> | --all [--dry-run]",
111
141
  " cpac status",
142
+ " cpac models [--json]",
112
143
  " cpac detect [--json]",
113
144
  " cpac install [codex|pi|kimi|grok|zed...] [--all] [--dry-run] [--force] [--v2_off] [--v2_models] [--max_context]",
114
145
  " cpac sync [codex|pi|kimi|grok|zed...] [--all] [--dry-run] [--v2_off] [--v2_models] [--max_context]",
@@ -157,7 +188,8 @@ function parseArgs(args) {
157
188
  args[0] === "sync" ||
158
189
  args[0] === "uninstall" ||
159
190
  args[0] === "restore" ||
160
- args[0] === "upgrade") {
191
+ args[0] === "upgrade" ||
192
+ args[0] === "models") {
161
193
  const parsed = {
162
194
  command: args[0],
163
195
  configPath: defaultConfigPath(),
@@ -531,6 +563,8 @@ export async function main(args = process.argv.slice(2)) {
531
563
  const config = loadConfig(parsed.configPath, true);
532
564
  if (parsed.command === "guide")
533
565
  return await guide(config);
566
+ if (parsed.command === "models")
567
+ return await listModels(config, parsed.json);
534
568
  if (parsed.command === "detect")
535
569
  return await runDetect(config, parsed.json);
536
570
  if (parsed.command === "install") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yhong91/cpac",
3
- "version": "0.1.39",
3
+ "version": "0.1.40",
4
4
  "description": "Connect Codex and Claude Code to a remote CLIProxyAPI gateway",
5
5
  "type": "module",
6
6
  "bin": {