chatccc 0.2.103 → 0.2.106

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.
@@ -48,8 +48,8 @@ const baseAppConfig: AppConfig = {
48
48
  model: "initial-model",
49
49
  subagentModel: "initial-subagent-model",
50
50
  effort: "initial-effort",
51
- apiKey: "sk-initial",
52
- baseUrl: "https://initial.gw/anthropic",
51
+ apiKey: "",
52
+ baseUrl: "",
53
53
  },
54
54
  cursor: { enabled: true, defaultAgent: false, path: "/initial/cursor", model: "initial-cursor-model" },
55
55
  codex: { enabled: true, defaultAgent: false, path: "/initial/codex", model: "initial-codex-model", effort: "initial-codex-effort" },
@@ -89,16 +89,16 @@ describe("applyLoadedConfig — 刷新 export let 常量", () => {
89
89
  model: "claude-sonnet-4-6",
90
90
  subagentModel: "claude-haiku-4-5-20251001",
91
91
  effort: "high",
92
- apiKey: "sk-newkey",
93
- baseUrl: "https://gw2.example/anthropic",
92
+ apiKey: "sk-test",
93
+ baseUrl: "https://api.example.com",
94
94
  },
95
95
  });
96
96
 
97
97
  expect(CLAUDE_MODEL).toBe("claude-sonnet-4-6");
98
98
  expect(CLAUDE_SUBAGENT_MODEL).toBe("claude-haiku-4-5-20251001");
99
99
  expect(CLAUDE_EFFORT).toBe("high");
100
- expect(CLAUDE_API_KEY).toBe("sk-newkey");
101
- expect(CLAUDE_BASE_URL).toBe("https://gw2.example/anthropic");
100
+ expect(CLAUDE_API_KEY).toBe("sk-test");
101
+ expect(CLAUDE_BASE_URL).toBe("https://api.example.com");
102
102
  });
103
103
 
104
104
  it("更新 GIT_TIMEOUT_SECONDS 与 GIT_TIMEOUT_MS(毫秒派生值同步刷新)", () => {
@@ -1,135 +1,9 @@
1
1
  import { describe, it, expect } from "vitest";
2
2
  import {
3
- applyClaudeApiMode,
4
3
  chooseStartPath,
5
- detectClaudeApiMode,
6
4
  unflattenConfig,
7
5
  } from "../web-ui.ts";
8
6
 
9
- // ---------------------------------------------------------------------------
10
- // detectClaudeApiMode — 加载已有 config 时如何判定 UI 初始模式
11
- // 契约:apiKey 或 baseUrl 任一非空(trim 后) → "thirdparty",否则 "official"。
12
- // ---------------------------------------------------------------------------
13
-
14
- describe("detectClaudeApiMode", () => {
15
- it("两者都缺失 → official", () => {
16
- expect(detectClaudeApiMode(undefined)).toBe("official");
17
- expect(detectClaudeApiMode({})).toBe("official");
18
- });
19
-
20
- it("两者都为空字符串 → official", () => {
21
- expect(detectClaudeApiMode({ apiKey: "", baseUrl: "" })).toBe("official");
22
- });
23
-
24
- it("两者都全空白 → official", () => {
25
- expect(detectClaudeApiMode({ apiKey: " ", baseUrl: "\t\n" })).toBe(
26
- "official",
27
- );
28
- });
29
-
30
- it("apiKey 非空 → thirdparty(即使 baseUrl 为空)", () => {
31
- expect(detectClaudeApiMode({ apiKey: "sk-x", baseUrl: "" })).toBe(
32
- "thirdparty",
33
- );
34
- });
35
-
36
- it("baseUrl 非空 → thirdparty(即使 apiKey 为空)", () => {
37
- expect(
38
- detectClaudeApiMode({ apiKey: "", baseUrl: "https://gw/anthropic" }),
39
- ).toBe("thirdparty");
40
- });
41
-
42
- it("两者都非空 → thirdparty", () => {
43
- expect(
44
- detectClaudeApiMode({
45
- apiKey: "sk-x",
46
- baseUrl: "https://gw/anthropic",
47
- }),
48
- ).toBe("thirdparty");
49
- });
50
- });
51
-
52
- // ---------------------------------------------------------------------------
53
- // applyClaudeApiMode — 服务端写入前归一化扁平 vars
54
- // 关键契约:
55
- // - mode=official 时即使 vars 不含这两个键,也要写入 ""(覆盖原 config.json)
56
- // - mode=thirdparty 时原样保留(包括前端传 "")
57
- // - mode 未传 默认按 official 兌底(不保留可能误填的密钥)
58
- // ---------------------------------------------------------------------------
59
-
60
- describe("applyClaudeApiMode", () => {
61
- it("mode=official 时清空 CLAUDE_API_KEY / CLAUDE_BASE_URL(即使 vars 没传)", () => {
62
- const out = applyClaudeApiMode({ CHATCCC_APP_ID: "x" }, "official");
63
- expect(out).toEqual({
64
- CHATCCC_APP_ID: "x",
65
- CLAUDE_API_KEY: "",
66
- CLAUDE_BASE_URL: "",
67
- });
68
- });
69
-
70
- it("mode=official 时覆盖前端误传的非空 apiKey / baseUrl", () => {
71
- const out = applyClaudeApiMode(
72
- {
73
- CLAUDE_API_KEY: "sk-leftover",
74
- CLAUDE_BASE_URL: "https://leftover/anthropic",
75
- CHATCCC_APP_ID: "x",
76
- },
77
- "official",
78
- );
79
- expect(out.CLAUDE_API_KEY).toBe("");
80
- expect(out.CLAUDE_BASE_URL).toBe("");
81
- expect(out.CHATCCC_APP_ID).toBe("x");
82
- });
83
-
84
- it("mode=thirdparty 时原样保留前端值", () => {
85
- const out = applyClaudeApiMode(
86
- {
87
- CLAUDE_API_KEY: "sk-test",
88
- CLAUDE_BASE_URL: "https://gw/anthropic",
89
- },
90
- "thirdparty",
91
- );
92
- expect(out).toEqual({
93
- CLAUDE_API_KEY: "sk-test",
94
- CLAUDE_BASE_URL: "https://gw/anthropic",
95
- });
96
- });
97
-
98
- it("mode=thirdparty 时保留前端主动提交的 ''(允许局部清空)", () => {
99
- const out = applyClaudeApiMode(
100
- { CLAUDE_API_KEY: "", CLAUDE_BASE_URL: "https://gw/anthropic" },
101
- "thirdparty",
102
- );
103
- expect(out.CLAUDE_API_KEY).toBe("");
104
- expect(out.CLAUDE_BASE_URL).toBe("https://gw/anthropic");
105
- });
106
-
107
- it("mode 未传(undefined) → 按 official 兌底清空", () => {
108
- const out = applyClaudeApiMode(
109
- { CLAUDE_API_KEY: "sk-x" },
110
- undefined,
111
- );
112
- expect(out.CLAUDE_API_KEY).toBe("");
113
- expect(out.CLAUDE_BASE_URL).toBe("");
114
- });
115
-
116
- it("mode 是未知字符串 → 按 official 兌底清空", () => {
117
- const out = applyClaudeApiMode(
118
- { CLAUDE_API_KEY: "sk-x" },
119
- "garbage-mode",
120
- );
121
- expect(out.CLAUDE_API_KEY).toBe("");
122
- expect(out.CLAUDE_BASE_URL).toBe("");
123
- });
124
-
125
- it("不修改入参对象(返回新对象)", () => {
126
- const input = { CLAUDE_API_KEY: "sk-x" };
127
- const out = applyClaudeApiMode(input, "official");
128
- expect(input).toEqual({ CLAUDE_API_KEY: "sk-x" }); // 原对象未变
129
- expect(out).not.toBe(input);
130
- });
131
- });
132
-
133
7
  describe("unflattenConfig", () => {
134
8
  it("maps Claude subagent model into claude.subagentModel", () => {
135
9
  expect(
@@ -144,6 +18,20 @@ describe("unflattenConfig", () => {
144
18
  },
145
19
  });
146
20
  });
21
+
22
+ it("maps Claude apiKey and baseUrl into claude config", () => {
23
+ expect(
24
+ unflattenConfig({
25
+ CHATCCC_ANTHROPIC_API_KEY: "sk-test-key",
26
+ CHATCCC_ANTHROPIC_BASE_URL: "https://api.example.com",
27
+ }),
28
+ ).toEqual({
29
+ claude: {
30
+ apiKey: "sk-test-key",
31
+ baseUrl: "https://api.example.com",
32
+ },
33
+ });
34
+ });
147
35
  });
148
36
 
149
37
  // ---------------------------------------------------------------------------
@@ -192,4 +80,4 @@ describe("chooseStartPath", () => {
192
80
  }),
193
81
  ).toBe("spawn");
194
82
  });
195
- });
83
+ });