@ia-ccun/code-agent-cli 0.0.57-beta.2 → 0.0.57-beta.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/bin/cli.js CHANGED
@@ -224,12 +224,16 @@ const piAgentPath = fileURLToPath(piAgentPathUrl); // 解码中文路径
224
224
  const versionCachePath = getVersionCachePath();
225
225
 
226
226
  // 设置环境变量
227
+ /** @type {Record<string, string | undefined>} */
227
228
  const env = {
228
229
  ...process.env,
229
230
  AICODE_CLI_CONFIG_DIR: config.configDir,
230
231
  AICODE_CLI_NAME: config.name,
231
232
  AICODE_CLI_VERSION: localVersion || "",
232
233
  AICODE_CLI_VERSION_CACHE: versionCachePath,
234
+ // pi 的 ${VAR} 占位符解析器读 process.env.VERSION,
235
+ // 扩展里的 headers.User-Agent="${VERSION}" 依赖它(缺失会直接抛错)
236
+ VERSION: `aicode-cli/${localVersion || "0.0.0"}`,
233
237
  PI_SKIP_VERSION_CHECK: "1",
234
238
  PI_OFFLINE: "1", // 禁用包更新检查
235
239
  };
@@ -3,8 +3,8 @@
3
3
  * AICode 内网 LLM Provider — 动态模型列表
4
4
  *
5
5
  * 内网网关每次上下线模型,用户不该手改 models.json。
6
- * 这里用 pi.registerProvider + refreshModels 钩子,在会话启动和打开 /model 时
7
- * 自动从 GET {baseUrl}/models 拉取真实模型列表,用户零操作。
6
+ * 这里用 pi.registerProvider + refreshModels 钩子,在会话启动时从
7
+ * GET {baseUrl}/models 拉取真实模型列表,用户零操作。
8
8
  *
9
9
  * ponytail:
10
10
  * - 内网不返回 maxTokens,统一用 DEFAULT_MAX_TOKENS;个别模型要改走
@@ -13,17 +13,26 @@
13
13
  * 按 lowercase 去重,优先保留全小写的那个
14
14
  * - embedding / rerank 不是 chat 模型,pi 用不了,直接过滤
15
15
  * - 静态兜底列表放在扩展里,网关不可达时至少还有一个可选模型
16
+ * - 故意忽略 ctx.allowNetwork:aicode-cli 以 PI_OFFLINE=1 启动(内网环境),
17
+ * pi 自己的目录刷新被禁用,只能扩展自己拉内网网关
16
18
  */
17
19
 
18
- import { type ExtensionAPI, type ProviderModelConfig } from "@earendil-works/pi-coding-agent";
20
+ import {
21
+ type ExtensionAPI,
22
+ type ProviderModelConfig,
23
+ } from "@earendil-works/pi-coding-agent";
19
24
  import { type RefreshModelsContext } from "@earendil-works/pi-ai";
20
25
 
21
26
  const PROVIDER_ID = "aicode";
22
27
  const DEFAULT_BASE_URL = "https://ai-llm.nucc.com/v1";
23
28
  const DEFAULT_MAX_TOKENS = 8192;
29
+ const FETCH_TIMEOUT_MS = 3000;
24
30
 
25
31
  const BASE_URL = process.env.AICODE_BASE_URL ?? DEFAULT_BASE_URL;
26
32
 
33
+ // ${VERSION} 由 bin/cli.js 注入子进程;直接用 pi 跑时兜底,避免 header 解析抛错
34
+ process.env.VERSION ??= `aicode-cli/${process.env.AICODE_CLI_VERSION ?? "0.0.0"}`;
35
+
27
36
  /** chat 模型的配置形状(ProviderModelConfig 联合类型里的 chat 分支) */
28
37
  type ChatModelConfig = Extract<ProviderModelConfig, { type?: "chat" }>;
29
38
 
@@ -131,19 +140,29 @@ export default function (pi: ExtensionAPI) {
131
140
  api: "openai-completions",
132
141
  // 环境变量没设时回落 /login 的 API key 输入框,凭据存 auth.json
133
142
  apiKey: "$AICODE_API_KEY",
134
- headers: { "User-Agent": "aicode-cli" },
143
+ headers: { "User-Agent": "${VERSION}" },
135
144
  models: FALLBACK_MODELS,
136
145
  async refreshModels(
137
146
  ctx: RefreshModelsContext,
138
147
  ): Promise<ProviderModelConfig[]> {
139
- // 离线阶段(allowNetwork=false)不发请求,沿用静态兜底列表
140
- if (!ctx.allowNetwork) return FALLBACK_MODELS;
141
-
142
148
  const credential = ctx.credential;
143
- const apiKey = credential?.type === "api_key" ? credential.key : undefined;
144
- const models = await fetchInternalModels(apiKey, ctx.signal);
145
- // 空列表会清空 /model 里的模型,宁可用兜底也不清空
146
- return models.length > 0 ? models : FALLBACK_MODELS;
149
+ const apiKey =
150
+ (credential?.type === "api_key" ? credential.key : undefined) ??
151
+ process.env.AICODE_API_KEY;
152
+
153
+ try {
154
+ const signal = AbortSignal.any([
155
+ ctx.signal,
156
+ AbortSignal.timeout(FETCH_TIMEOUT_MS),
157
+ ]);
158
+ const models = await fetchInternalModels(apiKey, signal);
159
+ // 空列表会清空 /model 里的模型,宁可用兜底也不清空
160
+ if (models.length > 0) return models;
161
+ } catch {
162
+ // 网关不可达(超时/断网):沿用静态兜底列表,不影响启动
163
+ }
164
+
165
+ return FALLBACK_MODELS;
147
166
  },
148
167
  });
149
168
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ia-ccun/code-agent-cli",
3
- "version": "0.0.57-beta.2",
3
+ "version": "0.0.57-beta.3",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -1 +1 @@
1
- 5531
1
+ 7895
@@ -1 +1 @@
1
- /Users/jianjiang/.aicode-regression-5502-6601000
1
+ /Users/jianjiang/.aicode-regression-7873-4949000