chatccc 0.2.246 → 0.2.248

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.
@@ -1,194 +1,194 @@
1
- import { mkdtemp } from "node:fs/promises";
2
- import { tmpdir } from "node:os";
3
- import { join } from "node:path";
4
-
5
- import { afterEach, describe, expect, it, vi } from "vitest";
6
-
7
- const streamTextMock = vi.fn();
8
- const generateTextMock = vi.fn();
9
-
10
- vi.mock("@ai-sdk/openai-compatible", () => ({
11
- createOpenAICompatible: vi.fn(() => (modelId: string) => ({ modelId })),
12
- }));
13
-
14
- vi.mock("@ai-sdk/anthropic", () => ({
15
- createAnthropic: vi.fn(() => (modelId: string) => ({ modelId })),
16
- }));
17
-
18
- vi.mock("ai", () => ({
19
- streamText: streamTextMock,
20
- generateText: generateTextMock,
21
- isLoopFinished: vi.fn(() => ({ loopFinished: true })),
22
- stepCountIs: vi.fn((count: number) => ({ count })),
23
- jsonSchema: vi.fn((schema: unknown) => schema),
24
- tool: vi.fn((definition: unknown) => definition),
25
- }));
26
-
27
- async function* textStream(...chunks: string[]): AsyncIterable<string> {
28
- for (const chunk of chunks) yield chunk;
29
- }
30
-
31
- async function* fullStream(...parts: unknown[]): AsyncIterable<unknown> {
32
- for (const part of parts) yield part;
33
- }
34
-
35
- afterEach(() => {
36
- streamTextMock.mockReset();
37
- generateTextMock.mockReset();
38
- });
39
-
40
- describe("createCccAdapter", () => {
41
- it("disables response-stall detection when DeepCCC streaming is disabled", async () => {
42
- const { config: deepCccConfig } = await import("../../deepccc-agent/src/config.ts");
43
- const previousStreaming = deepCccConfig.streaming;
44
- deepCccConfig.streaming = false;
45
-
46
- try {
47
- const { createCccAdapter } = await import("../adapters/ccc-adapter.ts");
48
- const adapter = createCccAdapter({ apiKey: "sk-test" });
49
-
50
- expect(adapter.responseStallDetectionEnabled).toBe(false);
51
- } finally {
52
- deepCccConfig.streaming = previousStreaming;
53
- }
54
- });
55
-
56
- it("creates a persisted ccc session and exposes model/cwd metadata", async () => {
57
- const { createCccAdapter } = await import("../adapters/ccc-adapter.ts");
58
- const contextDir = await mkdtemp(join(tmpdir(), "chatccc-ccc-adapter-meta-"));
59
- const adapter = createCccAdapter({
60
- apiKey: "sk-test",
61
- provider: "openai",
62
- contextDir,
63
- model: "deepseek-v4-pro",
64
- });
65
-
66
- const created = await adapter.createSession("F:\\repo");
67
- const info = await adapter.getSessionInfo(created.sessionId);
68
-
69
- expect(created.sessionId).toMatch(/^session-\d{8}-\d{6}-[a-f0-9]{6}$/);
70
- expect(info).toEqual(expect.objectContaining({
71
- sessionId: created.sessionId,
72
- cwd: "F:\\repo",
73
- model: "deepseek-v4-pro",
74
- }));
75
- });
76
-
77
- it("maps ChatSession text chunks to unified assistant text blocks", async () => {
78
- const { createCccAdapter } = await import("../adapters/ccc-adapter.ts");
79
- const contextDir = await mkdtemp(join(tmpdir(), "chatccc-ccc-adapter-stream-"));
80
- const adapter = createCccAdapter({
81
- apiKey: "sk-test",
82
- provider: "openai",
83
- contextDir,
84
- model: "deepseek-v4-flash",
85
- });
86
- const { sessionId } = await adapter.createSession("F:\\repo");
87
- streamTextMock.mockReturnValueOnce({ textStream: textStream("hello", " world") });
88
-
89
- const messages = [];
90
- for await (const message of adapter.prompt(sessionId, "hi", "F:\\repo")) {
91
- messages.push(message);
92
- }
93
-
94
- expect(messages).toEqual([
95
- { type: "assistant", blocks: [{ type: "agent_status", status: "responding" }] },
96
- { type: "assistant", blocks: [{ type: "text", text: "hello" }] },
97
- { type: "assistant", blocks: [{ type: "text", text: " world" }] },
98
- { type: "assistant", blocks: [], isFinalResponse: true },
99
- ]);
100
- expect(streamTextMock).toHaveBeenCalledWith(expect.objectContaining({
101
- model: { modelId: "deepseek-v4-flash" },
102
- }));
103
- });
104
-
105
- it("maps ChatSession tool events to unified tool blocks", async () => {
106
- const { createCccAdapter } = await import("../adapters/ccc-adapter.ts");
107
- const contextDir = await mkdtemp(join(tmpdir(), "chatccc-ccc-adapter-tools-"));
108
- const adapter = createCccAdapter({
109
- apiKey: "sk-test",
110
- provider: "openai",
111
- contextDir,
112
- model: "deepseek-v4-flash",
113
- });
114
- const { sessionId } = await adapter.createSession("F:\\repo");
115
- streamTextMock.mockReturnValueOnce({
116
- fullStream: fullStream(
117
- { type: "tool-call", toolCallId: "call-1", toolName: "read_file", input: { path: "README.md" } },
118
- { type: "tool-result", toolCallId: "call-1", toolName: "read_file", output: { content: "hello" } },
119
- ),
120
- });
121
-
122
- const messages = [];
123
- for await (const message of adapter.prompt(sessionId, "read", "F:\\repo")) {
124
- messages.push(message);
125
- }
126
-
127
- expect(messages).toEqual([
128
- { type: "assistant", blocks: [{ type: "agent_status", status: "responding" }] },
129
- {
130
- type: "assistant",
131
- blocks: [{ type: "tool_use", id: "call-1", name: "read_file", input: { path: "README.md" } }],
132
- },
133
- {
134
- type: "assistant",
135
- blocks: [{ type: "tool_result", tool_use_id: "call-1", content: { content: "hello" }, is_error: false }],
136
- },
137
- { type: "assistant", blocks: [], isFinalResponse: true },
138
- ]);
139
- });
140
-
141
- it("maps DeepCCC compaction and generation phases to unified activity blocks", async () => {
142
- const { createCccAdapter } = await import("../adapters/ccc-adapter.ts");
143
- const contextDir = await mkdtemp(join(tmpdir(), "chatccc-ccc-adapter-status-"));
144
- const adapter = createCccAdapter({
145
- apiKey: "sk-test",
146
- provider: "openai",
147
- contextDir,
148
- compactAtTokens: 1,
149
- keepRecentMessages: 1,
150
- });
151
- const { sessionId } = await adapter.createSession("F:\\repo");
152
- streamTextMock.mockReturnValueOnce({ textStream: textStream("old") });
153
- for await (const _message of adapter.prompt(sessionId, "old question", "F:\\repo")) {
154
- // drain
155
- }
156
-
157
- generateTextMock.mockResolvedValueOnce({ text: "summary" });
158
- streamTextMock.mockReturnValueOnce({ textStream: textStream("new") });
159
- const messages = [];
160
- for await (const message of adapter.prompt(sessionId, "new question", "F:\\repo")) {
161
- messages.push(message);
162
- }
163
-
164
- expect(messages[0]).toEqual({
165
- type: "assistant",
166
- blocks: [{ type: "agent_status", status: "compacting" }],
167
- });
168
- expect(messages).toContainEqual({
169
- type: "assistant",
170
- blocks: [{ type: "agent_status", status: "responding" }],
171
- });
172
- });
173
-
174
- it("passes effort into ChatSession so streamText receives reasoningEffort", async () => {
175
- const { createCccAdapter } = await import("../adapters/ccc-adapter.ts");
176
- const contextDir = await mkdtemp(join(tmpdir(), "chatccc-ccc-adapter-effort-"));
177
- const adapter = createCccAdapter({
178
- apiKey: "sk-test",
179
- provider: "openai",
180
- contextDir,
181
- effort: "xhigh",
182
- });
183
- const { sessionId } = await adapter.createSession("F:\\repo");
184
- streamTextMock.mockReturnValueOnce({ textStream: textStream("ok") });
185
-
186
- for await (const _message of adapter.prompt(sessionId, "hi", "F:\\repo")) {
187
- // drain
188
- }
189
-
190
- expect(streamTextMock).toHaveBeenLastCalledWith(expect.objectContaining({
191
- providerOptions: { deepseek: { reasoningEffort: "xhigh" } },
192
- }));
193
- });
194
- });
1
+ import { mkdtemp } from "node:fs/promises";
2
+ import { tmpdir } from "node:os";
3
+ import { join } from "node:path";
4
+
5
+ import { afterEach, describe, expect, it, vi } from "vitest";
6
+
7
+ const streamTextMock = vi.fn();
8
+ const generateTextMock = vi.fn();
9
+
10
+ vi.mock("@ai-sdk/openai-compatible", () => ({
11
+ createOpenAICompatible: vi.fn(() => (modelId: string) => ({ modelId })),
12
+ }));
13
+
14
+ vi.mock("@ai-sdk/anthropic", () => ({
15
+ createAnthropic: vi.fn(() => (modelId: string) => ({ modelId })),
16
+ }));
17
+
18
+ vi.mock("ai", () => ({
19
+ streamText: streamTextMock,
20
+ generateText: generateTextMock,
21
+ isLoopFinished: vi.fn(() => ({ loopFinished: true })),
22
+ stepCountIs: vi.fn((count: number) => ({ count })),
23
+ jsonSchema: vi.fn((schema: unknown) => schema),
24
+ tool: vi.fn((definition: unknown) => definition),
25
+ }));
26
+
27
+ async function* textStream(...chunks: string[]): AsyncIterable<string> {
28
+ for (const chunk of chunks) yield chunk;
29
+ }
30
+
31
+ async function* fullStream(...parts: unknown[]): AsyncIterable<unknown> {
32
+ for (const part of parts) yield part;
33
+ }
34
+
35
+ afterEach(() => {
36
+ streamTextMock.mockReset();
37
+ generateTextMock.mockReset();
38
+ });
39
+
40
+ describe("createCccAdapter", () => {
41
+ it("disables response-stall detection when DeepCCC streaming is disabled", async () => {
42
+ const { config: deepCccConfig } = await import("../../deepccc-agent/src/config.ts");
43
+ const previousStreaming = deepCccConfig.streaming;
44
+ deepCccConfig.streaming = false;
45
+
46
+ try {
47
+ const { createCccAdapter } = await import("../adapters/ccc-adapter.ts");
48
+ const adapter = createCccAdapter({ apiKey: "sk-test" });
49
+
50
+ expect(adapter.responseStallDetectionEnabled).toBe(false);
51
+ } finally {
52
+ deepCccConfig.streaming = previousStreaming;
53
+ }
54
+ });
55
+
56
+ it("creates a persisted ccc session and exposes model/cwd metadata", async () => {
57
+ const { createCccAdapter } = await import("../adapters/ccc-adapter.ts");
58
+ const contextDir = await mkdtemp(join(tmpdir(), "chatccc-ccc-adapter-meta-"));
59
+ const adapter = createCccAdapter({
60
+ apiKey: "sk-test",
61
+ provider: "openai",
62
+ contextDir,
63
+ model: "deepseek-v4-pro",
64
+ });
65
+
66
+ const created = await adapter.createSession("F:\\repo");
67
+ const info = await adapter.getSessionInfo(created.sessionId);
68
+
69
+ expect(created.sessionId).toMatch(/^session-\d{8}-\d{6}-[a-f0-9]{6}$/);
70
+ expect(info).toEqual(expect.objectContaining({
71
+ sessionId: created.sessionId,
72
+ cwd: "F:\\repo",
73
+ model: "deepseek-v4-pro",
74
+ }));
75
+ });
76
+
77
+ it("maps ChatSession text chunks to unified assistant text blocks", async () => {
78
+ const { createCccAdapter } = await import("../adapters/ccc-adapter.ts");
79
+ const contextDir = await mkdtemp(join(tmpdir(), "chatccc-ccc-adapter-stream-"));
80
+ const adapter = createCccAdapter({
81
+ apiKey: "sk-test",
82
+ provider: "openai",
83
+ contextDir,
84
+ model: "deepseek-v4-flash",
85
+ });
86
+ const { sessionId } = await adapter.createSession("F:\\repo");
87
+ streamTextMock.mockReturnValueOnce({ textStream: textStream("hello", " world") });
88
+
89
+ const messages = [];
90
+ for await (const message of adapter.prompt(sessionId, "hi", "F:\\repo")) {
91
+ messages.push(message);
92
+ }
93
+
94
+ expect(messages).toEqual([
95
+ { type: "assistant", blocks: [{ type: "agent_status", status: "responding" }] },
96
+ { type: "assistant", blocks: [{ type: "text", text: "hello" }] },
97
+ { type: "assistant", blocks: [{ type: "text", text: " world" }] },
98
+ { type: "assistant", blocks: [], isFinalResponse: true },
99
+ ]);
100
+ expect(streamTextMock).toHaveBeenCalledWith(expect.objectContaining({
101
+ model: { modelId: "deepseek-v4-flash" },
102
+ }));
103
+ });
104
+
105
+ it("maps ChatSession tool events to unified tool blocks", async () => {
106
+ const { createCccAdapter } = await import("../adapters/ccc-adapter.ts");
107
+ const contextDir = await mkdtemp(join(tmpdir(), "chatccc-ccc-adapter-tools-"));
108
+ const adapter = createCccAdapter({
109
+ apiKey: "sk-test",
110
+ provider: "openai",
111
+ contextDir,
112
+ model: "deepseek-v4-flash",
113
+ });
114
+ const { sessionId } = await adapter.createSession("F:\\repo");
115
+ streamTextMock.mockReturnValueOnce({
116
+ fullStream: fullStream(
117
+ { type: "tool-call", toolCallId: "call-1", toolName: "read_file", input: { path: "README.md" } },
118
+ { type: "tool-result", toolCallId: "call-1", toolName: "read_file", output: { content: "hello" } },
119
+ ),
120
+ });
121
+
122
+ const messages = [];
123
+ for await (const message of adapter.prompt(sessionId, "read", "F:\\repo")) {
124
+ messages.push(message);
125
+ }
126
+
127
+ expect(messages).toEqual([
128
+ { type: "assistant", blocks: [{ type: "agent_status", status: "responding" }] },
129
+ {
130
+ type: "assistant",
131
+ blocks: [{ type: "tool_use", id: "call-1", name: "read_file", input: { path: "README.md" } }],
132
+ },
133
+ {
134
+ type: "assistant",
135
+ blocks: [{ type: "tool_result", tool_use_id: "call-1", content: { content: "hello" }, is_error: false }],
136
+ },
137
+ { type: "assistant", blocks: [], isFinalResponse: true },
138
+ ]);
139
+ });
140
+
141
+ it("maps DeepCCC compaction and generation phases to unified activity blocks", async () => {
142
+ const { createCccAdapter } = await import("../adapters/ccc-adapter.ts");
143
+ const contextDir = await mkdtemp(join(tmpdir(), "chatccc-ccc-adapter-status-"));
144
+ const adapter = createCccAdapter({
145
+ apiKey: "sk-test",
146
+ provider: "openai",
147
+ contextDir,
148
+ compactAtTokens: 1,
149
+ keepRecentMessages: 1,
150
+ });
151
+ const { sessionId } = await adapter.createSession("F:\\repo");
152
+ streamTextMock.mockReturnValueOnce({ textStream: textStream("old") });
153
+ for await (const _message of adapter.prompt(sessionId, "old question", "F:\\repo")) {
154
+ // drain
155
+ }
156
+
157
+ generateTextMock.mockResolvedValueOnce({ text: "summary" });
158
+ streamTextMock.mockReturnValueOnce({ textStream: textStream("new") });
159
+ const messages = [];
160
+ for await (const message of adapter.prompt(sessionId, "new question", "F:\\repo")) {
161
+ messages.push(message);
162
+ }
163
+
164
+ expect(messages[0]).toEqual({
165
+ type: "assistant",
166
+ blocks: [{ type: "agent_status", status: "compacting" }],
167
+ });
168
+ expect(messages).toContainEqual({
169
+ type: "assistant",
170
+ blocks: [{ type: "agent_status", status: "responding" }],
171
+ });
172
+ });
173
+
174
+ it("passes effort into ChatSession so streamText receives reasoningEffort", async () => {
175
+ const { createCccAdapter } = await import("../adapters/ccc-adapter.ts");
176
+ const contextDir = await mkdtemp(join(tmpdir(), "chatccc-ccc-adapter-effort-"));
177
+ const adapter = createCccAdapter({
178
+ apiKey: "sk-test",
179
+ provider: "openai",
180
+ contextDir,
181
+ effort: "xhigh",
182
+ });
183
+ const { sessionId } = await adapter.createSession("F:\\repo");
184
+ streamTextMock.mockReturnValueOnce({ textStream: textStream("ok") });
185
+
186
+ for await (const _message of adapter.prompt(sessionId, "hi", "F:\\repo")) {
187
+ // drain
188
+ }
189
+
190
+ expect(streamTextMock).toHaveBeenLastCalledWith(expect.objectContaining({
191
+ providerOptions: { deepseek: { reasoningEffort: "xhigh" } },
192
+ }));
193
+ });
194
+ });
@@ -72,7 +72,7 @@ const baseAppConfig: AppConfig = {
72
72
  onDemandMonthlyBudget: 1000,
73
73
  },
74
74
  codex: { enabled: true, defaultAgent: false, path: "/initial/codex", model: "initial-codex-model", alternativeModel: "initial-codex-alt-model", effort: "initial-codex-effort", fastMode: false },
75
- ccc: { enabled: true, defaultAgent: false, DEEPSEEK_API_KEY: "initial-ccc-key", DEEPSEEK_BASE_URL: "https://initial.deepseek.test/v1", model: "initial-ccc-model", alternativeModel: "initial-ccc-alt-model", effort: "initial-ccc-effort" },
75
+ ccc: { enabled: true, defaultAgent: false, DEEPSEEK_API_KEY: "initial-ccc-key", DEEPSEEK_BASE_URL: "https://initial.deepseek.test/v1", model: "initial-ccc-model", alternativeModel: "initial-ccc-alt-model", effort: "initial-ccc-effort", provider: "" },
76
76
  };
77
77
 
78
78
  // 把 module 状态抢救快照:每个 it 跑前重置回这个状态,避免污染相邻测试。
@@ -0,0 +1,40 @@
1
+ import { afterEach, describe, expect, it, vi } from "vitest";
2
+ import { normalizeCccProviderOverride } from "../config-utils.ts";
3
+
4
+ describe("normalizeCccProviderOverride", () => {
5
+ const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
6
+
7
+ afterEach(() => {
8
+ warnSpy.mockClear();
9
+ });
10
+
11
+ it("returns empty string for missing / non-string values (no override)", () => {
12
+ expect(normalizeCccProviderOverride(undefined)).toBe("");
13
+ expect(normalizeCccProviderOverride(null)).toBe("");
14
+ expect(normalizeCccProviderOverride(42)).toBe("");
15
+ expect(normalizeCccProviderOverride({})).toBe("");
16
+ expect(warnSpy).not.toHaveBeenCalled();
17
+ });
18
+
19
+ it("treats empty/whitespace and legacy 'default' as no override", () => {
20
+ expect(normalizeCccProviderOverride("")).toBe("");
21
+ expect(normalizeCccProviderOverride(" ")).toBe("");
22
+ expect(normalizeCccProviderOverride("default")).toBe("");
23
+ expect(normalizeCccProviderOverride("DEFAULT")).toBe("");
24
+ expect(warnSpy).not.toHaveBeenCalled();
25
+ });
26
+
27
+ it("normalizes openai / anthropic case-insensitively", () => {
28
+ expect(normalizeCccProviderOverride("openai")).toBe("openai");
29
+ expect(normalizeCccProviderOverride("OPENAI")).toBe("openai");
30
+ expect(normalizeCccProviderOverride(" anthropic ")).toBe("anthropic");
31
+ expect(normalizeCccProviderOverride("Anthropic")).toBe("anthropic");
32
+ expect(warnSpy).not.toHaveBeenCalled();
33
+ });
34
+
35
+ it("ignores invalid values with a warning", () => {
36
+ expect(normalizeCccProviderOverride("gemini")).toBe("");
37
+ expect(normalizeCccProviderOverride("oai")).toBe("");
38
+ expect(warnSpy).toHaveBeenCalledTimes(2);
39
+ });
40
+ });
@@ -31,10 +31,12 @@ describe("CCC Agent ChatCCC configuration", () => {
31
31
  DEEPSEEK_BASE_URL: "https://chatccc.example.com/v1",
32
32
  model: "chatccc-model",
33
33
  effort: "high",
34
+ provider: "",
34
35
  });
35
36
 
36
37
  getAdapterForTool("ccc");
37
38
 
39
+ // provider 留空时不传 → ChatSession 跟随 DeepCCC 内核配置(~/.deepccc/config.json 或 DEEPCCC_PROVIDER)
38
40
  expect(createCccAdapterMock).toHaveBeenCalledWith({
39
41
  apiKey: "chatccc-api-key",
40
42
  baseURL: "https://chatccc.example.com/v1",
@@ -42,4 +44,23 @@ describe("CCC Agent ChatCCC configuration", () => {
42
44
  effort: "high",
43
45
  });
44
46
  });
47
+
48
+ it("forwards ccc.provider override to createCccAdapter", () => {
49
+ Object.assign(config.ccc, {
50
+ DEEPSEEK_API_KEY: "chatccc-api-key",
51
+ DEEPSEEK_BASE_URL: "https://chatccc.example.com/v1",
52
+ model: "chatccc-model",
53
+ effort: "",
54
+ provider: "anthropic",
55
+ });
56
+
57
+ getAdapterForTool("ccc");
58
+
59
+ expect(createCccAdapterMock).toHaveBeenCalledWith({
60
+ apiKey: "chatccc-api-key",
61
+ baseURL: "https://chatccc.example.com/v1",
62
+ model: "chatccc-model",
63
+ provider: "anthropic",
64
+ });
65
+ });
45
66
  });