u1s1-cli 1.4.2 → 1.4.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/dist/config.d.ts CHANGED
@@ -170,6 +170,13 @@ export declare function loadConfig(): CliConfig;
170
170
  * (umask 下常是 0644)存在过哪怕一瞬;rename 在 POSIX 上原子替换。
171
171
  */
172
172
  export declare function writePrivateFile(path: string, content: string): void;
173
+ /**
174
+ * 环境变量只是本进程的临时覆盖,不能随保存写死进文件:曾经在
175
+ * U1S1_BASE_URL 指向本地调试网关的 shell 里切了一次模型,config.json 就
176
+ * 永久记住了 127.0.0.1:8899,之后每次启动都连不上。凡是当前值与环境变量
177
+ * 一致的字段,一律写回文件里原来的值(或不写)。
178
+ */
179
+ export declare function stripEnvOverrides(cfg: CliConfig, file: Partial<CliConfig>, env?: NodeJS.ProcessEnv): Partial<CliConfig>;
173
180
  export declare function saveConfig(cfg: CliConfig): void;
174
181
  /** Persist the user's preferred model to both stores. */
175
182
  export declare function persistPreferredModel(cfg: CliConfig, provider: string, modelId: string): CliConfig;
package/dist/config.js CHANGED
@@ -314,8 +314,50 @@ export function writePrivateFile(path, content) {
314
314
  throw e;
315
315
  }
316
316
  }
317
+ /** loadConfig 里允许环境变量临时覆盖的字段 → 对应变量名。 */
318
+ const ENV_OVERRIDES = [
319
+ ["apiKey", "U1S1_API_KEY"],
320
+ ["deviceToken", "U1S1_DEVICE_TOKEN"],
321
+ ["baseUrl", "U1S1_BASE_URL"],
322
+ ["devicePrivateJwk", "U1S1_DEVICE_PRIVATE_JWK"],
323
+ ["devicePublicJwk", "U1S1_DEVICE_PUBLIC_JWK"],
324
+ ];
325
+ function sameValue(a, b) {
326
+ if (a === b)
327
+ return true;
328
+ if (typeof a === "object" && typeof b === "object" && a && b)
329
+ return JSON.stringify(a) === JSON.stringify(b);
330
+ return false;
331
+ }
332
+ /**
333
+ * 环境变量只是本进程的临时覆盖,不能随保存写死进文件:曾经在
334
+ * U1S1_BASE_URL 指向本地调试网关的 shell 里切了一次模型,config.json 就
335
+ * 永久记住了 127.0.0.1:8899,之后每次启动都连不上。凡是当前值与环境变量
336
+ * 一致的字段,一律写回文件里原来的值(或不写)。
337
+ */
338
+ export function stripEnvOverrides(cfg, file, env = process.env) {
339
+ const next = { ...cfg };
340
+ for (const [key, name] of ENV_OVERRIDES) {
341
+ const raw = env[name];
342
+ if (!raw)
343
+ continue;
344
+ let envValue = raw;
345
+ if (key === "devicePrivateJwk" || key === "devicePublicJwk") {
346
+ try {
347
+ envValue = JSON.parse(raw);
348
+ }
349
+ catch {
350
+ continue;
351
+ }
352
+ }
353
+ if (sameValue(cfg[key], envValue))
354
+ next[key] = file[key];
355
+ }
356
+ return next;
357
+ }
317
358
  export function saveConfig(cfg) {
318
- writePrivateFile(configFile, JSON.stringify(cfg, null, 2) + "\n");
359
+ const file = (readJsonFile(configFile) ?? {});
360
+ writePrivateFile(configFile, JSON.stringify(stripEnvOverrides(cfg, file), null, 2) + "\n");
319
361
  }
320
362
  /** Persist the user's preferred model to both stores. */
321
363
  export function persistPreferredModel(cfg, provider, modelId) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "u1s1-cli",
3
- "version": "1.4.2",
3
+ "version": "1.4.3",
4
4
  "description": "u1s1 — 有一说一,最省心的 AI 编程搭子。终端里用中文说需求,AI 帮你读文件、改代码、跑命令。",
5
5
  "type": "module",
6
6
  "bin": {