chatccc 0.2.244 → 0.2.246
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 +8 -8
- package/deepccc-agent/README.md +20 -0
- package/deepccc-agent/package-lock.json +70 -2
- package/deepccc-agent/package.json +4 -2
- package/deepccc-agent/src/__tests__/chat-session.test.ts +126 -2
- package/deepccc-agent/src/__tests__/config.test.ts +34 -26
- package/deepccc-agent/src/__tests__/permissions.test.ts +199 -195
- package/deepccc-agent/src/__tests__/privacy.test.ts +7 -0
- package/deepccc-agent/src/cli.ts +16 -4
- package/deepccc-agent/src/config.ts +101 -84
- package/deepccc-agent/src/index.ts +74 -12
- package/package.json +2 -1
- package/src/__tests__/builtin-chat-session.test.ts +532 -522
- package/src/__tests__/builtin-permissions.test.ts +219 -211
- package/src/__tests__/ccc-adapter.test.ts +194 -170
- package/src/__tests__/session.test.ts +362 -299
- package/src/adapters/adapter-interface.ts +39 -33
- package/src/adapters/ccc-adapter.ts +150 -145
- package/src/session.ts +321 -318
|
@@ -66,21 +66,21 @@ export interface UnifiedSearchResultBlock {
|
|
|
66
66
|
query: string;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
export interface UnifiedCompactBoundaryBlock {
|
|
70
|
-
type: "compact_boundary";
|
|
71
|
-
trigger: "manual" | "auto";
|
|
72
|
-
pre_tokens: number;
|
|
73
|
-
post_tokens?: number;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export interface UnifiedAgentStatusBlock {
|
|
77
|
-
type: "agent_status";
|
|
78
|
-
status: "compacting" | "responding";
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export type UnifiedBlock =
|
|
82
|
-
| UnifiedAgentStatusBlock
|
|
83
|
-
| UnifiedThinkingBlock
|
|
69
|
+
export interface UnifiedCompactBoundaryBlock {
|
|
70
|
+
type: "compact_boundary";
|
|
71
|
+
trigger: "manual" | "auto";
|
|
72
|
+
pre_tokens: number;
|
|
73
|
+
post_tokens?: number;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface UnifiedAgentStatusBlock {
|
|
77
|
+
type: "agent_status";
|
|
78
|
+
status: "compacting" | "responding";
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export type UnifiedBlock =
|
|
82
|
+
| UnifiedAgentStatusBlock
|
|
83
|
+
| UnifiedThinkingBlock
|
|
84
84
|
| UnifiedTextBlock
|
|
85
85
|
| UnifiedTextFinalBlock
|
|
86
86
|
| UnifiedToolUseBlock
|
|
@@ -93,17 +93,17 @@ export type UnifiedBlock =
|
|
|
93
93
|
// UnifiedStreamMessage — 一次 SDK/CLI 事件对应的归一化消息
|
|
94
94
|
// ---------------------------------------------------------------------------
|
|
95
95
|
|
|
96
|
-
export interface UnifiedStreamMessage {
|
|
97
|
-
type: "assistant" | "user" | "system";
|
|
98
|
-
blocks: UnifiedBlock[];
|
|
99
|
-
/**
|
|
100
|
-
* 适配器确认本事件代表一条完整、权威的最终回复,而不是流式文本片段。
|
|
101
|
-
*
|
|
102
|
-
* response-stall 终止与最终事件可能在同一事件循环边界竞态;只有该标记
|
|
103
|
-
* 为 true 时,上层才允许把已经触发的超时改判为正常完成。
|
|
104
|
-
*/
|
|
105
|
-
isFinalResponse?: boolean;
|
|
106
|
-
}
|
|
96
|
+
export interface UnifiedStreamMessage {
|
|
97
|
+
type: "assistant" | "user" | "system";
|
|
98
|
+
blocks: UnifiedBlock[];
|
|
99
|
+
/**
|
|
100
|
+
* 适配器确认本事件代表一条完整、权威的最终回复,而不是流式文本片段。
|
|
101
|
+
*
|
|
102
|
+
* response-stall 终止与最终事件可能在同一事件循环边界竞态;只有该标记
|
|
103
|
+
* 为 true 时,上层才允许把已经触发的超时改判为正常完成。
|
|
104
|
+
*/
|
|
105
|
+
isFinalResponse?: boolean;
|
|
106
|
+
}
|
|
107
107
|
|
|
108
108
|
// ---------------------------------------------------------------------------
|
|
109
109
|
// CreateSessionResult
|
|
@@ -158,12 +158,18 @@ export interface ToolAdapter {
|
|
|
158
158
|
/** 群描述中会话 ID 的前缀,如 "Claude Session:" */
|
|
159
159
|
readonly sessionDescPrefix: string;
|
|
160
160
|
|
|
161
|
-
/**
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
161
|
+
/**
|
|
162
|
+
* Whether ChatCCC may infer a stalled response from unchanged streamed output.
|
|
163
|
+
* Defaults to true. Adapters that only emit output after a request completes must disable it.
|
|
164
|
+
*/
|
|
165
|
+
readonly responseStallDetectionEnabled?: boolean;
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* 创建新会话,返回会话 ID。
|
|
169
|
+
* 适配器内部需处理后台流消费(静默消费 stream 中除 init 外的所有事件)。
|
|
170
|
+
* signal 用于上层在长期收不到 init 事件时终止底层 SDK/CLI。
|
|
171
|
+
*/
|
|
172
|
+
createSession(cwd: string, signal?: AbortSignal): Promise<CreateSessionResult>;
|
|
167
173
|
|
|
168
174
|
/**
|
|
169
175
|
* 向已有会话发送提示文本,返回归一化消息的异步迭代器。
|
|
@@ -208,4 +214,4 @@ export function parseUserCommand(userText: string): UserCommand {
|
|
|
208
214
|
if (original.startsWith("/plan")) return { original, mode: "plan" };
|
|
209
215
|
if (original.startsWith("/ask")) return { original, mode: "ask" };
|
|
210
216
|
return { original, mode: null };
|
|
211
|
-
}
|
|
217
|
+
}
|
|
@@ -1,145 +1,150 @@
|
|
|
1
|
-
import { ChatSession, type ChatSessionConfig, type ChatSessionOptions } from "../../deepccc-agent/src/index.ts";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
//
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
...(options.
|
|
53
|
-
...(options.
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
};
|
|
97
|
-
} else if (event.type === "
|
|
98
|
-
yield {
|
|
99
|
-
type: "assistant",
|
|
100
|
-
blocks: [{
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
1
|
+
import { ChatSession, type ChatSessionConfig, type ChatSessionOptions } from "../../deepccc-agent/src/index.ts";
|
|
2
|
+
import { config as deepCccConfig } from "../../deepccc-agent/src/config.ts";
|
|
3
|
+
import {
|
|
4
|
+
getBuiltinContextSession,
|
|
5
|
+
newBuiltinSessionId,
|
|
6
|
+
normalizeBuiltinSessionId,
|
|
7
|
+
} from "../../deepccc-agent/src/context.ts";
|
|
8
|
+
import { config, CCC_SESSION_PREFIX } from "../config.ts";
|
|
9
|
+
import type {
|
|
10
|
+
CreateSessionResult,
|
|
11
|
+
SessionInfo,
|
|
12
|
+
ToolAdapter,
|
|
13
|
+
ToolPromptOptions,
|
|
14
|
+
UnifiedStreamMessage,
|
|
15
|
+
} from "./adapter-interface.ts";
|
|
16
|
+
|
|
17
|
+
export interface CccAdapterOptions extends ChatSessionConfig {
|
|
18
|
+
contextDir?: string;
|
|
19
|
+
compactAtTokens?: number;
|
|
20
|
+
keepRecentMessages?: number;
|
|
21
|
+
compactionTimeoutMs?: number;
|
|
22
|
+
maxSteps?: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function toChatSessionOptions(
|
|
26
|
+
sessionId: string,
|
|
27
|
+
cwd: string,
|
|
28
|
+
options: CccAdapterOptions,
|
|
29
|
+
): ChatSessionOptions {
|
|
30
|
+
return {
|
|
31
|
+
cwd,
|
|
32
|
+
persist: true,
|
|
33
|
+
sessionId,
|
|
34
|
+
contextDir: options.contextDir,
|
|
35
|
+
compactAtTokens: options.compactAtTokens,
|
|
36
|
+
keepRecentMessages: options.keepRecentMessages,
|
|
37
|
+
compactionTimeoutMs: options.compactionTimeoutMs,
|
|
38
|
+
maxSteps: options.maxSteps,
|
|
39
|
+
// chatccc 无终端可交互,且对齐 claude/codex 适配器的 bypass 模式:
|
|
40
|
+
// 高危命令不询问,全部放行(与独立 deepccc CLI 的 ask 模式不同)
|
|
41
|
+
permissionMode: "bypass",
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function createCccAdapter(options: CccAdapterOptions = {}): ToolAdapter {
|
|
46
|
+
if (!options.apiKey?.trim()) {
|
|
47
|
+
throw new Error("ChatCCC 未配置 CCC Agent API Key。请先填写 ccc.DEEPSEEK_API_KEY 后再启用 CCC Agent。");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const chatConfig: ChatSessionConfig = {
|
|
51
|
+
apiKey: options.apiKey,
|
|
52
|
+
...(options.provider !== undefined ? { provider: options.provider } : {}),
|
|
53
|
+
...(options.baseURL !== undefined ? { baseURL: options.baseURL } : {}),
|
|
54
|
+
...(options.model !== undefined ? { model: options.model } : {}),
|
|
55
|
+
...(options.effort !== undefined ? { effort: options.effort } : {}),
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
displayName: "CCC Agent",
|
|
60
|
+
sessionDescPrefix: CCC_SESSION_PREFIX,
|
|
61
|
+
// Non-streaming DeepCCC emits its reply only after the provider request finishes,
|
|
62
|
+
// so unchanged output cannot distinguish a slow request from a stalled response.
|
|
63
|
+
responseStallDetectionEnabled: deepCccConfig.streaming,
|
|
64
|
+
|
|
65
|
+
async createSession(cwd: string): Promise<CreateSessionResult> {
|
|
66
|
+
const sessionId = newBuiltinSessionId();
|
|
67
|
+
const session = new ChatSession(
|
|
68
|
+
chatConfig,
|
|
69
|
+
toChatSessionOptions(sessionId, cwd, options),
|
|
70
|
+
);
|
|
71
|
+
session.reset();
|
|
72
|
+
return { sessionId };
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
async *prompt(
|
|
76
|
+
sessionId: string,
|
|
77
|
+
userText: string,
|
|
78
|
+
cwd: string,
|
|
79
|
+
signal?: AbortSignal,
|
|
80
|
+
_promptOptions?: ToolPromptOptions,
|
|
81
|
+
): AsyncIterable<UnifiedStreamMessage> {
|
|
82
|
+
const normalizedSessionId = normalizeBuiltinSessionId(sessionId);
|
|
83
|
+
const session = new ChatSession(
|
|
84
|
+
chatConfig,
|
|
85
|
+
toChatSessionOptions(normalizedSessionId, cwd, options),
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
for await (const event of session.chat(userText, signal)) {
|
|
89
|
+
if (event.type === "status") {
|
|
90
|
+
yield {
|
|
91
|
+
type: "assistant",
|
|
92
|
+
blocks: [{
|
|
93
|
+
type: "agent_status",
|
|
94
|
+
status: event.phase === "compacting" ? "compacting" : "responding",
|
|
95
|
+
}],
|
|
96
|
+
};
|
|
97
|
+
} else if (event.type === "text") {
|
|
98
|
+
yield {
|
|
99
|
+
type: "assistant",
|
|
100
|
+
blocks: [{ type: "text", text: event.text }],
|
|
101
|
+
};
|
|
102
|
+
} else if (event.type === "tool_use") {
|
|
103
|
+
yield {
|
|
104
|
+
type: "assistant",
|
|
105
|
+
blocks: [{
|
|
106
|
+
type: "tool_use",
|
|
107
|
+
id: event.id,
|
|
108
|
+
name: event.name,
|
|
109
|
+
input: event.input,
|
|
110
|
+
}],
|
|
111
|
+
};
|
|
112
|
+
} else if (event.type === "tool_result") {
|
|
113
|
+
yield {
|
|
114
|
+
type: "assistant",
|
|
115
|
+
blocks: [{
|
|
116
|
+
type: "tool_result",
|
|
117
|
+
tool_use_id: event.tool_use_id,
|
|
118
|
+
content: event.content,
|
|
119
|
+
is_error: event.is_error,
|
|
120
|
+
}],
|
|
121
|
+
};
|
|
122
|
+
} else if (event.type === "done" && !signal?.aborted) {
|
|
123
|
+
yield {
|
|
124
|
+
type: "assistant",
|
|
125
|
+
blocks: [],
|
|
126
|
+
isFinalResponse: true,
|
|
127
|
+
};
|
|
128
|
+
} else if (event.type === "error") {
|
|
129
|
+
throw new Error(event.message);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
|
|
134
|
+
async getSessionInfo(sessionId: string): Promise<SessionInfo | undefined> {
|
|
135
|
+
const normalizedSessionId = normalizeBuiltinSessionId(sessionId);
|
|
136
|
+
const info = getBuiltinContextSession(normalizedSessionId, options.contextDir);
|
|
137
|
+
if (!info) return undefined;
|
|
138
|
+
return {
|
|
139
|
+
sessionId: info.sessionId,
|
|
140
|
+
cwd: info.cwd,
|
|
141
|
+
lastModified: info.updatedAt,
|
|
142
|
+
model: options.model ?? config.ccc.model,
|
|
143
|
+
};
|
|
144
|
+
},
|
|
145
|
+
|
|
146
|
+
async closeSession(_sessionId: string): Promise<void> {
|
|
147
|
+
// ChatSession uses one request-scoped stream per prompt. AbortSignal handles cancellation.
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
}
|