@yhong91/cpac 0.1.5 → 0.1.7

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
@@ -132,6 +132,8 @@ CLAUDE_CODE_PROVIDER_MANAGED_BY_HOST=1
132
132
 
133
133
  代理开启 Claude Code 的 gateway model discovery:`/model` 选择器会列出 CPA 目录里的全部模型。claude 系模型直接使用原 id;其它模型以 `claude-cpac--<模型名>` 别名出现(例如 `claude-cpac--gpt-5.6-sol`),请求发出时由代理还原为真实模型名。
134
134
 
135
+ Claude Code 的发现协议不携带 context 信息,未知模型默认按 200K 处理。`cpac claude` 启动时会从 CPA 目录取最大 `context_window`,通过 `CLAUDE_CODE_MAX_CONTEXT_TOKENS` 告知 Claude Code(对非 claude 名称的模型生效);你自己 export 该变量时以你为准。claude 系模型如需 1M 窗口,在模型名后加 `[1m]`(如 `cpac claude --model claude-sonnet-4-6[1m]`)。
136
+
135
137
  > CPA 服务端必须支持 Claude Code 使用的 Anthropic Messages API(`/v1/messages`)。
136
138
 
137
139
  ### Codex
package/dist/cpac.js CHANGED
@@ -1097,6 +1097,22 @@ export async function runClaude(config, args, executable = "claude") {
1097
1097
  proxy.server.closeAllConnections?.();
1098
1098
  proxy.server.close();
1099
1099
  };
1100
+ // Gateway discovery only carries {id, display_name}; Claude Code defaults
1101
+ // unknown models to 200K. CLAUDE_CODE_MAX_CONTEXT_TOKENS applies to
1102
+ // non-claude model names, so feed it the largest catalog window.
1103
+ let maxContext = 0;
1104
+ try {
1105
+ const catalog = await fetchCatalog(config.cpa_url, apiKey);
1106
+ const rows = catalogModelRows(JSON.parse(new TextDecoder("utf-8").decode(catalog.bytes))) ?? [];
1107
+ for (const row of rows) {
1108
+ if (typeof row.context_window === "number" && row.context_window > maxContext) {
1109
+ maxContext = row.context_window;
1110
+ }
1111
+ }
1112
+ }
1113
+ catch {
1114
+ // keep the default window when the catalog is unreachable
1115
+ }
1100
1116
  const env = {
1101
1117
  ...process.env,
1102
1118
  ANTHROPIC_BASE_URL: `http://127.0.0.1:${proxy.port}`,
@@ -1104,6 +1120,9 @@ export async function runClaude(config, args, executable = "claude") {
1104
1120
  CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY: "1",
1105
1121
  CLAUDE_CODE_PROVIDER_MANAGED_BY_HOST: "1",
1106
1122
  };
1123
+ if (maxContext > 0 && !(Number(process.env.CLAUDE_CODE_MAX_CONTEXT_TOKENS) > 0)) {
1124
+ env.CLAUDE_CODE_MAX_CONTEXT_TOKENS = String(maxContext);
1125
+ }
1107
1126
  delete env.ANTHROPIC_API_KEY;
1108
1127
  delete env.CLAUDE_CODE_USE_ANTHROPIC_AWS;
1109
1128
  delete env.CLAUDE_CODE_USE_BEDROCK;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yhong91/cpac",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "Connect Codex and Claude Code to a remote CLIProxyAPI gateway",
5
5
  "type": "module",
6
6
  "bin": {