chatccc 0.2.190 → 0.2.192
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/agent-prompts/claude_specific.md +45 -45
- package/agent-prompts/codex_specific.md +2 -2
- package/agent-prompts/cursor_specific.md +13 -13
- package/config.sample.json +14 -14
- package/im-skills/feishu-skill/receive-send-file.md +63 -63
- package/im-skills/feishu-skill/receive-send-image.md +24 -24
- package/im-skills/feishu-skill/skill.md +3 -3
- package/im-skills/wechat-file-skill/receive-send-file.md +38 -38
- package/im-skills/wechat-file-skill/send-file.mjs +83 -83
- package/im-skills/wechat-file-skill/skill.md +10 -10
- package/im-skills/wechat-image-skill/skill.md +10 -10
- package/im-skills/wechat-video-skill/receive-send-video.md +38 -38
- package/im-skills/wechat-video-skill/send-video.mjs +79 -79
- package/im-skills/wechat-video-skill/skill.md +10 -10
- package/package.json +1 -1
- package/scripts/postinstall-sharp-check.mjs +58 -58
- package/src/__tests__/agent-delegate-task-rpc.test.ts +165 -165
- package/src/__tests__/builtin-chat-session.test.ts +76 -0
- package/src/__tests__/builtin-config.test.ts +33 -33
- package/src/__tests__/builtin-context.test.ts +126 -0
- package/src/__tests__/builtin-sigint.test.ts +56 -0
- package/src/__tests__/card-plain-text.test.ts +5 -5
- package/src/__tests__/cardkit.test.ts +60 -60
- package/src/__tests__/cards.test.ts +77 -77
- package/src/__tests__/chatgpt-subscription-rpc.test.ts +89 -89
- package/src/__tests__/chatgpt-subscription.test.ts +135 -135
- package/src/__tests__/chrome-devtools-guard.test.ts +165 -165
- package/src/__tests__/claude-adapter.test.ts +592 -592
- package/src/__tests__/codex-reset-actions.test.ts +146 -146
- package/src/__tests__/config-reload.test.ts +4 -4
- package/src/__tests__/config-sample.test.ts +17 -17
- package/src/__tests__/feishu-api.test.ts +60 -60
- package/src/__tests__/feishu-platform.test.ts +22 -22
- package/src/__tests__/format-message.test.ts +47 -47
- package/src/__tests__/orchestrator.test.ts +120 -120
- package/src/__tests__/privacy.test.ts +198 -198
- package/src/__tests__/raw-stream-log.test.ts +106 -106
- package/src/__tests__/session.test.ts +17 -17
- package/src/__tests__/shared-prefix.test.ts +36 -36
- package/src/__tests__/stream-state.test.ts +42 -42
- package/src/__tests__/web-ui.test.ts +209 -209
- package/src/adapters/claude-adapter.ts +566 -566
- package/src/adapters/claude-session-meta-store.ts +120 -120
- package/src/adapters/codex-adapter.ts +30 -30
- package/src/adapters/cursor-adapter.ts +46 -46
- package/src/adapters/raw-stream-log.ts +124 -124
- package/src/adapters/resource-monitor.ts +140 -140
- package/src/agent-delegate-task-rpc.ts +153 -153
- package/src/agent-delegate-task.ts +81 -81
- package/src/agent-stop-stuck.ts +129 -129
- package/src/builtin/cli.ts +211 -189
- package/src/builtin/context.ts +225 -0
- package/src/builtin/index.ts +232 -170
- package/src/builtin/sigint.ts +50 -0
- package/src/cards.ts +137 -137
- package/src/chatgpt-subscription-rpc.ts +27 -27
- package/src/chatgpt-subscription.ts +299 -299
- package/src/chrome-devtools-guard.ts +318 -318
- package/src/codex-reset-actions.ts +184 -184
- package/src/config.ts +86 -86
- package/src/feishu-platform.ts +20 -20
- package/src/format-message.ts +293 -293
- package/src/litellm-proxy.ts +374 -374
- package/src/orchestrator.ts +143 -143
- package/src/privacy.ts +118 -118
- package/src/session-chat-binding.ts +6 -6
- package/src/session-name.ts +8 -8
- package/src/session.ts +98 -98
- package/src/shared-prefix.ts +29 -29
- package/src/sim-platform.ts +20 -20
- package/src/turn-cards.ts +117 -117
- package/src/web-ui.ts +205 -205
|
@@ -1,184 +1,184 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
2
|
-
|
|
3
|
-
import { buildCodexResetConfirmCard } from "./cards.ts";
|
|
4
|
-
import type { CodexResetConsumeResult } from "./feishu-api.ts";
|
|
5
|
-
|
|
6
|
-
type CodexResetDecision = "yes" | "no";
|
|
7
|
-
|
|
8
|
-
interface PendingCodexResetRequest {
|
|
9
|
-
chatId: string;
|
|
10
|
-
parentMessageId: string;
|
|
11
|
-
status: "pending" | "handled";
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface CodexResetActionDeps {
|
|
15
|
-
getTenantAccessToken(): Promise<string>;
|
|
16
|
-
sendRawCard(token: string, chatId: string, cardJson: string): Promise<boolean>;
|
|
17
|
-
sendTextReply(token: string, chatId: string, text: string): Promise<boolean>;
|
|
18
|
-
sendCardReply(token: string, chatId: string, title: string, content: string, template?: string): Promise<boolean>;
|
|
19
|
-
updateCardMessage(token: string, messageId: string, content: string): Promise<boolean>;
|
|
20
|
-
recallMessage(token: string, messageId: string): Promise<boolean>;
|
|
21
|
-
consumeCodexRateLimitResetCredit(redeemRequestId: string): Promise<CodexResetConsumeResult>;
|
|
22
|
-
createRequestId?: () => string;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const pendingCodexResetRequests = new Map<string, PendingCodexResetRequest>();
|
|
26
|
-
|
|
27
|
-
function rawEvent(data: unknown): Record<string, unknown> {
|
|
28
|
-
return ((data as Record<string, unknown>)?.event ?? data) as Record<string, unknown>;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function actionValue(raw: Record<string, unknown>): Record<string, unknown> | null {
|
|
32
|
-
const action = raw.action as { value?: unknown } | undefined;
|
|
33
|
-
const value = action?.value;
|
|
34
|
-
if (!value || typeof value !== "object") return null;
|
|
35
|
-
return value as Record<string, unknown>;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function eventMessageId(raw: Record<string, unknown>): string {
|
|
39
|
-
return typeof raw.open_message_id === "string"
|
|
40
|
-
? raw.open_message_id
|
|
41
|
-
: typeof (raw.context as Record<string, unknown> | undefined)?.open_message_id === "string"
|
|
42
|
-
? (raw.context as Record<string, string>).open_message_id
|
|
43
|
-
: typeof raw.message_id === "string"
|
|
44
|
-
? raw.message_id
|
|
45
|
-
: typeof (raw.context as Record<string, unknown> | undefined)?.message_id === "string"
|
|
46
|
-
? (raw.context as Record<string, string>).message_id
|
|
47
|
-
: typeof (raw.message as Record<string, unknown> | undefined)?.message_id === "string"
|
|
48
|
-
? (raw.message as Record<string, string>).message_id
|
|
49
|
-
: "";
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function eventChatId(raw: Record<string, unknown>): string {
|
|
53
|
-
return typeof raw.open_chat_id === "string"
|
|
54
|
-
? raw.open_chat_id
|
|
55
|
-
: typeof (raw.context as Record<string, unknown> | undefined)?.open_chat_id === "string"
|
|
56
|
-
? (raw.context as Record<string, string>).open_chat_id
|
|
57
|
-
: typeof (raw.message as Record<string, unknown> | undefined)?.chat_id === "string"
|
|
58
|
-
? (raw.message as Record<string, string>).chat_id
|
|
59
|
-
: "";
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function collapsedCard(): string {
|
|
63
|
-
return JSON.stringify({
|
|
64
|
-
config: { wide_screen_mode: true },
|
|
65
|
-
elements: [{ tag: "markdown", content: " " }],
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function resetResultMessage(result: CodexResetConsumeResult): { content: string; template: string } {
|
|
70
|
-
if (result.code === "reset") {
|
|
71
|
-
return {
|
|
72
|
-
content: `重置成功。已重置 ${result.windowsReset} 个 Codex 用量窗口。`,
|
|
73
|
-
template: "green",
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
if (result.code === "nothing_to_reset") {
|
|
77
|
-
return {
|
|
78
|
-
content: "没有需要重置的 Codex 用量窗口。",
|
|
79
|
-
template: "yellow",
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
if (result.code === "no_credit") {
|
|
83
|
-
return {
|
|
84
|
-
content: "没有可用的 Codex 主动重置次数。",
|
|
85
|
-
template: "red",
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
return {
|
|
89
|
-
content: "这次 Codex 主动重置请求已经处理过。",
|
|
90
|
-
template: "yellow",
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
async function sendResetRequestConfirmation(
|
|
95
|
-
raw: Record<string, unknown>,
|
|
96
|
-
value: Record<string, unknown>,
|
|
97
|
-
deps: CodexResetActionDeps,
|
|
98
|
-
): Promise<boolean> {
|
|
99
|
-
const parentMessageId = eventMessageId(raw);
|
|
100
|
-
const chatId = eventChatId(raw);
|
|
101
|
-
if (!parentMessageId || !chatId) return true;
|
|
102
|
-
const availableCount = Number(value.availableCount);
|
|
103
|
-
|
|
104
|
-
const requestId = (deps.createRequestId ?? randomUUID)();
|
|
105
|
-
pendingCodexResetRequests.set(requestId, {
|
|
106
|
-
chatId,
|
|
107
|
-
parentMessageId,
|
|
108
|
-
status: "pending",
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
const token = await deps.getTenantAccessToken();
|
|
112
|
-
await deps.sendRawCard(token, chatId, buildCodexResetConfirmCard({
|
|
113
|
-
availableCount: Number.isFinite(availableCount) ? Math.max(1, Math.trunc(availableCount)) : 1,
|
|
114
|
-
parentMessageId,
|
|
115
|
-
requestId,
|
|
116
|
-
}));
|
|
117
|
-
return true;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
async function handleResetConfirmation(
|
|
121
|
-
raw: Record<string, unknown>,
|
|
122
|
-
value: Record<string, unknown>,
|
|
123
|
-
deps: CodexResetActionDeps,
|
|
124
|
-
): Promise<boolean> {
|
|
125
|
-
const decision = value.decision;
|
|
126
|
-
const requestId = value.requestId;
|
|
127
|
-
const parentMessageId = value.parentMessageId;
|
|
128
|
-
if ((decision !== "yes" && decision !== "no") || typeof requestId !== "string" || typeof parentMessageId !== "string") {
|
|
129
|
-
return true;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
const token = await deps.getTenantAccessToken();
|
|
133
|
-
const confirmMessageId = eventMessageId(raw);
|
|
134
|
-
if (confirmMessageId) {
|
|
135
|
-
const collapsed = await deps.updateCardMessage(token, confirmMessageId, collapsedCard());
|
|
136
|
-
console.log(`[Codex Reset] collapse confirmation card ${collapsed ? "OK" : "FAILED"}: messageId=${confirmMessageId}`);
|
|
137
|
-
const recalled = await deps.recallMessage(token, confirmMessageId);
|
|
138
|
-
console.log(`[Codex Reset] recall confirmation card ${recalled ? "OK" : "FAILED"}: messageId=${confirmMessageId}`);
|
|
139
|
-
} else {
|
|
140
|
-
console.error("[Codex Reset] missing confirmation card message id; cannot collapse");
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
const pending = pendingCodexResetRequests.get(requestId);
|
|
144
|
-
const chatId = pending?.chatId ?? eventChatId(raw);
|
|
145
|
-
if (!chatId) return true;
|
|
146
|
-
|
|
147
|
-
if (!pending || pending.status !== "pending" || pending.parentMessageId !== parentMessageId) {
|
|
148
|
-
await deps.sendTextReply(token, chatId, "Codex 主动重置:这张确认卡片已经失效或已处理。");
|
|
149
|
-
return true;
|
|
150
|
-
}
|
|
151
|
-
pending.status = "handled";
|
|
152
|
-
|
|
153
|
-
if (decision === "no") {
|
|
154
|
-
await deps.sendTextReply(token, chatId, "Codex 主动重置:用户取消了重置。");
|
|
155
|
-
return true;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
try {
|
|
159
|
-
const result = await deps.consumeCodexRateLimitResetCredit(requestId);
|
|
160
|
-
const message = resetResultMessage(result);
|
|
161
|
-
await deps.sendTextReply(token, chatId, `Codex 主动重置:${message.content}`);
|
|
162
|
-
} catch (err) {
|
|
163
|
-
await deps.sendTextReply(token, chatId, `Codex 主动重置失败:${(err as Error).message}`);
|
|
164
|
-
}
|
|
165
|
-
return true;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
export async function handleCodexResetCardAction(data: unknown, deps: CodexResetActionDeps): Promise<boolean> {
|
|
169
|
-
const raw = rawEvent(data);
|
|
170
|
-
const value = actionValue(raw);
|
|
171
|
-
if (!value) return false;
|
|
172
|
-
const action = value?.action;
|
|
173
|
-
if (action === "codex_reset_request") {
|
|
174
|
-
return sendResetRequestConfirmation(raw, value, deps);
|
|
175
|
-
}
|
|
176
|
-
if (action === "codex_reset_confirm") {
|
|
177
|
-
return handleResetConfirmation(raw, value, deps);
|
|
178
|
-
}
|
|
179
|
-
return false;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
export function _resetCodexResetRequestsForTest(): void {
|
|
183
|
-
pendingCodexResetRequests.clear();
|
|
184
|
-
}
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
|
|
3
|
+
import { buildCodexResetConfirmCard } from "./cards.ts";
|
|
4
|
+
import type { CodexResetConsumeResult } from "./feishu-api.ts";
|
|
5
|
+
|
|
6
|
+
type CodexResetDecision = "yes" | "no";
|
|
7
|
+
|
|
8
|
+
interface PendingCodexResetRequest {
|
|
9
|
+
chatId: string;
|
|
10
|
+
parentMessageId: string;
|
|
11
|
+
status: "pending" | "handled";
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface CodexResetActionDeps {
|
|
15
|
+
getTenantAccessToken(): Promise<string>;
|
|
16
|
+
sendRawCard(token: string, chatId: string, cardJson: string): Promise<boolean>;
|
|
17
|
+
sendTextReply(token: string, chatId: string, text: string): Promise<boolean>;
|
|
18
|
+
sendCardReply(token: string, chatId: string, title: string, content: string, template?: string): Promise<boolean>;
|
|
19
|
+
updateCardMessage(token: string, messageId: string, content: string): Promise<boolean>;
|
|
20
|
+
recallMessage(token: string, messageId: string): Promise<boolean>;
|
|
21
|
+
consumeCodexRateLimitResetCredit(redeemRequestId: string): Promise<CodexResetConsumeResult>;
|
|
22
|
+
createRequestId?: () => string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const pendingCodexResetRequests = new Map<string, PendingCodexResetRequest>();
|
|
26
|
+
|
|
27
|
+
function rawEvent(data: unknown): Record<string, unknown> {
|
|
28
|
+
return ((data as Record<string, unknown>)?.event ?? data) as Record<string, unknown>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function actionValue(raw: Record<string, unknown>): Record<string, unknown> | null {
|
|
32
|
+
const action = raw.action as { value?: unknown } | undefined;
|
|
33
|
+
const value = action?.value;
|
|
34
|
+
if (!value || typeof value !== "object") return null;
|
|
35
|
+
return value as Record<string, unknown>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function eventMessageId(raw: Record<string, unknown>): string {
|
|
39
|
+
return typeof raw.open_message_id === "string"
|
|
40
|
+
? raw.open_message_id
|
|
41
|
+
: typeof (raw.context as Record<string, unknown> | undefined)?.open_message_id === "string"
|
|
42
|
+
? (raw.context as Record<string, string>).open_message_id
|
|
43
|
+
: typeof raw.message_id === "string"
|
|
44
|
+
? raw.message_id
|
|
45
|
+
: typeof (raw.context as Record<string, unknown> | undefined)?.message_id === "string"
|
|
46
|
+
? (raw.context as Record<string, string>).message_id
|
|
47
|
+
: typeof (raw.message as Record<string, unknown> | undefined)?.message_id === "string"
|
|
48
|
+
? (raw.message as Record<string, string>).message_id
|
|
49
|
+
: "";
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function eventChatId(raw: Record<string, unknown>): string {
|
|
53
|
+
return typeof raw.open_chat_id === "string"
|
|
54
|
+
? raw.open_chat_id
|
|
55
|
+
: typeof (raw.context as Record<string, unknown> | undefined)?.open_chat_id === "string"
|
|
56
|
+
? (raw.context as Record<string, string>).open_chat_id
|
|
57
|
+
: typeof (raw.message as Record<string, unknown> | undefined)?.chat_id === "string"
|
|
58
|
+
? (raw.message as Record<string, string>).chat_id
|
|
59
|
+
: "";
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function collapsedCard(): string {
|
|
63
|
+
return JSON.stringify({
|
|
64
|
+
config: { wide_screen_mode: true },
|
|
65
|
+
elements: [{ tag: "markdown", content: " " }],
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function resetResultMessage(result: CodexResetConsumeResult): { content: string; template: string } {
|
|
70
|
+
if (result.code === "reset") {
|
|
71
|
+
return {
|
|
72
|
+
content: `重置成功。已重置 ${result.windowsReset} 个 Codex 用量窗口。`,
|
|
73
|
+
template: "green",
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
if (result.code === "nothing_to_reset") {
|
|
77
|
+
return {
|
|
78
|
+
content: "没有需要重置的 Codex 用量窗口。",
|
|
79
|
+
template: "yellow",
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
if (result.code === "no_credit") {
|
|
83
|
+
return {
|
|
84
|
+
content: "没有可用的 Codex 主动重置次数。",
|
|
85
|
+
template: "red",
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
content: "这次 Codex 主动重置请求已经处理过。",
|
|
90
|
+
template: "yellow",
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async function sendResetRequestConfirmation(
|
|
95
|
+
raw: Record<string, unknown>,
|
|
96
|
+
value: Record<string, unknown>,
|
|
97
|
+
deps: CodexResetActionDeps,
|
|
98
|
+
): Promise<boolean> {
|
|
99
|
+
const parentMessageId = eventMessageId(raw);
|
|
100
|
+
const chatId = eventChatId(raw);
|
|
101
|
+
if (!parentMessageId || !chatId) return true;
|
|
102
|
+
const availableCount = Number(value.availableCount);
|
|
103
|
+
|
|
104
|
+
const requestId = (deps.createRequestId ?? randomUUID)();
|
|
105
|
+
pendingCodexResetRequests.set(requestId, {
|
|
106
|
+
chatId,
|
|
107
|
+
parentMessageId,
|
|
108
|
+
status: "pending",
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
const token = await deps.getTenantAccessToken();
|
|
112
|
+
await deps.sendRawCard(token, chatId, buildCodexResetConfirmCard({
|
|
113
|
+
availableCount: Number.isFinite(availableCount) ? Math.max(1, Math.trunc(availableCount)) : 1,
|
|
114
|
+
parentMessageId,
|
|
115
|
+
requestId,
|
|
116
|
+
}));
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
async function handleResetConfirmation(
|
|
121
|
+
raw: Record<string, unknown>,
|
|
122
|
+
value: Record<string, unknown>,
|
|
123
|
+
deps: CodexResetActionDeps,
|
|
124
|
+
): Promise<boolean> {
|
|
125
|
+
const decision = value.decision;
|
|
126
|
+
const requestId = value.requestId;
|
|
127
|
+
const parentMessageId = value.parentMessageId;
|
|
128
|
+
if ((decision !== "yes" && decision !== "no") || typeof requestId !== "string" || typeof parentMessageId !== "string") {
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const token = await deps.getTenantAccessToken();
|
|
133
|
+
const confirmMessageId = eventMessageId(raw);
|
|
134
|
+
if (confirmMessageId) {
|
|
135
|
+
const collapsed = await deps.updateCardMessage(token, confirmMessageId, collapsedCard());
|
|
136
|
+
console.log(`[Codex Reset] collapse confirmation card ${collapsed ? "OK" : "FAILED"}: messageId=${confirmMessageId}`);
|
|
137
|
+
const recalled = await deps.recallMessage(token, confirmMessageId);
|
|
138
|
+
console.log(`[Codex Reset] recall confirmation card ${recalled ? "OK" : "FAILED"}: messageId=${confirmMessageId}`);
|
|
139
|
+
} else {
|
|
140
|
+
console.error("[Codex Reset] missing confirmation card message id; cannot collapse");
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const pending = pendingCodexResetRequests.get(requestId);
|
|
144
|
+
const chatId = pending?.chatId ?? eventChatId(raw);
|
|
145
|
+
if (!chatId) return true;
|
|
146
|
+
|
|
147
|
+
if (!pending || pending.status !== "pending" || pending.parentMessageId !== parentMessageId) {
|
|
148
|
+
await deps.sendTextReply(token, chatId, "Codex 主动重置:这张确认卡片已经失效或已处理。");
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
pending.status = "handled";
|
|
152
|
+
|
|
153
|
+
if (decision === "no") {
|
|
154
|
+
await deps.sendTextReply(token, chatId, "Codex 主动重置:用户取消了重置。");
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
try {
|
|
159
|
+
const result = await deps.consumeCodexRateLimitResetCredit(requestId);
|
|
160
|
+
const message = resetResultMessage(result);
|
|
161
|
+
await deps.sendTextReply(token, chatId, `Codex 主动重置:${message.content}`);
|
|
162
|
+
} catch (err) {
|
|
163
|
+
await deps.sendTextReply(token, chatId, `Codex 主动重置失败:${(err as Error).message}`);
|
|
164
|
+
}
|
|
165
|
+
return true;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export async function handleCodexResetCardAction(data: unknown, deps: CodexResetActionDeps): Promise<boolean> {
|
|
169
|
+
const raw = rawEvent(data);
|
|
170
|
+
const value = actionValue(raw);
|
|
171
|
+
if (!value) return false;
|
|
172
|
+
const action = value?.action;
|
|
173
|
+
if (action === "codex_reset_request") {
|
|
174
|
+
return sendResetRequestConfirmation(raw, value, deps);
|
|
175
|
+
}
|
|
176
|
+
if (action === "codex_reset_confirm") {
|
|
177
|
+
return handleResetConfirmation(raw, value, deps);
|
|
178
|
+
}
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export function _resetCodexResetRequestsForTest(): void {
|
|
183
|
+
pendingCodexResetRequests.clear();
|
|
184
|
+
}
|
package/src/config.ts
CHANGED
|
@@ -88,9 +88,9 @@ export interface CursorConfig {
|
|
|
88
88
|
onDemandMonthlyBudget: number;
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
export interface CodexConfig {
|
|
92
|
-
/** 是否启用 Codex Agent;缺省时按"有任意字段非空"自动判定(向后兼容) */
|
|
93
|
-
enabled: boolean;
|
|
91
|
+
export interface CodexConfig {
|
|
92
|
+
/** 是否启用 Codex Agent;缺省时按"有任意字段非空"自动判定(向后兼容) */
|
|
93
|
+
enabled: boolean;
|
|
94
94
|
/** 是否作为 /new 未指定工具时使用的默认 Agent */
|
|
95
95
|
defaultAgent: boolean;
|
|
96
96
|
/** Codex CLI 可执行文件绝对路径;留空时退回到 PATH 中的 `codex` */
|
|
@@ -98,22 +98,22 @@ export interface CodexConfig {
|
|
|
98
98
|
model: string;
|
|
99
99
|
/** /model 可切换的单个备选模型;留空则不加入候选列表 */
|
|
100
100
|
alternativeModel: string;
|
|
101
|
-
effort: string;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export interface CccConfig {
|
|
105
|
-
/** DeepSeek API Key for the ChatCCC self-developed agent. */
|
|
106
|
-
DEEPSEEK_API_KEY: string;
|
|
107
|
-
/** DeepSeek-compatible API Base URL for the ChatCCC self-developed agent. */
|
|
108
|
-
DEEPSEEK_BASE_URL: string;
|
|
109
|
-
/** Model used by the ChatCCC self-developed agent. */
|
|
110
|
-
model: string;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export interface FeishuConfig {
|
|
114
|
-
appId: string;
|
|
115
|
-
appSecret: string;
|
|
116
|
-
}
|
|
101
|
+
effort: string;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export interface CccConfig {
|
|
105
|
+
/** DeepSeek API Key for the ChatCCC self-developed agent. */
|
|
106
|
+
DEEPSEEK_API_KEY: string;
|
|
107
|
+
/** DeepSeek-compatible API Base URL for the ChatCCC self-developed agent. */
|
|
108
|
+
DEEPSEEK_BASE_URL: string;
|
|
109
|
+
/** Model used by the ChatCCC self-developed agent. */
|
|
110
|
+
model: string;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export interface FeishuConfig {
|
|
114
|
+
appId: string;
|
|
115
|
+
appSecret: string;
|
|
116
|
+
}
|
|
117
117
|
|
|
118
118
|
export interface PlatformConfig {
|
|
119
119
|
enabled: boolean;
|
|
@@ -158,22 +158,22 @@ export interface AppConfig {
|
|
|
158
158
|
/** 若为 false,AI 生成过程中用户发送消息不会打断,须先点「停止」再发送新消息 */
|
|
159
159
|
allowInterrupt: boolean;
|
|
160
160
|
rawStreamLogs: RawStreamLogsConfig;
|
|
161
|
-
claude: ClaudeConfig;
|
|
162
|
-
cursor: CursorConfig;
|
|
163
|
-
codex: CodexConfig;
|
|
164
|
-
ccc: CccConfig;
|
|
165
|
-
}
|
|
161
|
+
claude: ClaudeConfig;
|
|
162
|
+
cursor: CursorConfig;
|
|
163
|
+
codex: CodexConfig;
|
|
164
|
+
ccc: CccConfig;
|
|
165
|
+
}
|
|
166
166
|
|
|
167
167
|
export type AgentTool = "claude" | "cursor" | "codex";
|
|
168
168
|
export const AGENT_TOOLS: AgentTool[] = ["claude", "cursor", "codex"];
|
|
169
169
|
export type CursorAvatarBatteryMode = "apiPercent" | "onDemandUse";
|
|
170
170
|
|
|
171
171
|
/** 获取指定 agent 配置中所有模型相关的值(最多 100 个,去重) */
|
|
172
|
-
export function getAllModelsForTool(tool: AgentTool, cfg: AppConfig = config): string[] {
|
|
173
|
-
const seen = new Set<string>();
|
|
174
|
-
const collect = (v: unknown) => {
|
|
175
|
-
if (typeof v === "string" && v.trim()) seen.add(v.trim());
|
|
176
|
-
};
|
|
172
|
+
export function getAllModelsForTool(tool: AgentTool, cfg: AppConfig = config): string[] {
|
|
173
|
+
const seen = new Set<string>();
|
|
174
|
+
const collect = (v: unknown) => {
|
|
175
|
+
if (typeof v === "string" && v.trim()) seen.add(v.trim());
|
|
176
|
+
};
|
|
177
177
|
|
|
178
178
|
if (tool === "claude") {
|
|
179
179
|
collect(cfg.claude.model);
|
|
@@ -185,29 +185,29 @@ export function getAllModelsForTool(tool: AgentTool, cfg: AppConfig = config): s
|
|
|
185
185
|
collect(cfg.codex.model);
|
|
186
186
|
collect(cfg.codex.alternativeModel);
|
|
187
187
|
}
|
|
188
|
-
|
|
189
|
-
return Array.from(seen).slice(0, 100);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
export const CLAUDE_EFFORT_LEVELS = ["low", "medium", "high", "xhigh", "max"] as const;
|
|
193
|
-
export const CODEX_EFFORT_LEVELS = ["minimal", "low", "medium", "high", "xhigh"] as const;
|
|
194
|
-
|
|
195
|
-
export function getAllEffortsForTool(tool: AgentTool): string[] {
|
|
196
|
-
if (tool === "claude") return [...CLAUDE_EFFORT_LEVELS];
|
|
197
|
-
if (tool === "codex") return [...CODEX_EFFORT_LEVELS];
|
|
198
|
-
return [];
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
export function getDefaultEffortForTool(tool: AgentTool, cfg: AppConfig = config): string {
|
|
202
|
-
if (tool === "claude") return cfg.claude.effort;
|
|
203
|
-
if (tool === "codex") return cfg.codex.effort;
|
|
204
|
-
return "";
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
const CONFIG_FILE = join(USER_DATA_DIR, "config.json");
|
|
208
|
-
const CONFIG_SAMPLE_FILE = join(PROJECT_ROOT, "config.sample.json");
|
|
209
|
-
export const DEFAULT_CCC_DEEPSEEK_BASE_URL = "https://api.deepseek.com/v1";
|
|
210
|
-
export const DEFAULT_CCC_MODEL = "deepseek-v4-pro";
|
|
188
|
+
|
|
189
|
+
return Array.from(seen).slice(0, 100);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export const CLAUDE_EFFORT_LEVELS = ["low", "medium", "high", "xhigh", "max"] as const;
|
|
193
|
+
export const CODEX_EFFORT_LEVELS = ["minimal", "low", "medium", "high", "xhigh"] as const;
|
|
194
|
+
|
|
195
|
+
export function getAllEffortsForTool(tool: AgentTool): string[] {
|
|
196
|
+
if (tool === "claude") return [...CLAUDE_EFFORT_LEVELS];
|
|
197
|
+
if (tool === "codex") return [...CODEX_EFFORT_LEVELS];
|
|
198
|
+
return [];
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export function getDefaultEffortForTool(tool: AgentTool, cfg: AppConfig = config): string {
|
|
202
|
+
if (tool === "claude") return cfg.claude.effort;
|
|
203
|
+
if (tool === "codex") return cfg.codex.effort;
|
|
204
|
+
return "";
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const CONFIG_FILE = join(USER_DATA_DIR, "config.json");
|
|
208
|
+
const CONFIG_SAMPLE_FILE = join(PROJECT_ROOT, "config.sample.json");
|
|
209
|
+
export const DEFAULT_CCC_DEEPSEEK_BASE_URL = "https://api.deepseek.com/v1";
|
|
210
|
+
export const DEFAULT_CCC_MODEL = "deepseek-v4-pro";
|
|
211
211
|
|
|
212
212
|
/**
|
|
213
213
|
* 将旧位置(PROJECT_ROOT)的持久化数据一次性迁移到 USER_DATA_DIR。
|
|
@@ -425,8 +425,8 @@ function loadConfig(): AppConfig {
|
|
|
425
425
|
claude: { enabled: false, maxBytesPerTurn: 50 * 1024 * 1024, retentionDays: 7, keepCompleted: false },
|
|
426
426
|
cursor: { enabled: false, maxBytesPerTurn: 50 * 1024 * 1024, retentionDays: 7, keepCompleted: false },
|
|
427
427
|
codex: { enabled: false, maxBytesPerTurn: 50 * 1024 * 1024, retentionDays: 7, keepCompleted: false },
|
|
428
|
-
},
|
|
429
|
-
claude: { enabled: false, defaultAgent: true, model: "", subagentModel: "", effort: "", apiKey: "", baseUrl: "", maxTurn: 0 },
|
|
428
|
+
},
|
|
429
|
+
claude: { enabled: false, defaultAgent: true, model: "", subagentModel: "", effort: "", apiKey: "", baseUrl: "", maxTurn: 0 },
|
|
430
430
|
cursor: {
|
|
431
431
|
enabled: false,
|
|
432
432
|
defaultAgent: false,
|
|
@@ -435,10 +435,10 @@ function loadConfig(): AppConfig {
|
|
|
435
435
|
alternativeModel: "",
|
|
436
436
|
avatarBatteryMode: "apiPercent",
|
|
437
437
|
onDemandMonthlyBudget: 1000,
|
|
438
|
-
},
|
|
439
|
-
codex: { enabled: false, defaultAgent: false, path: "", model: "", alternativeModel: "", effort: "" },
|
|
440
|
-
ccc: { DEEPSEEK_API_KEY: "", DEEPSEEK_BASE_URL: DEFAULT_CCC_DEEPSEEK_BASE_URL, model: DEFAULT_CCC_MODEL },
|
|
441
|
-
};
|
|
438
|
+
},
|
|
439
|
+
codex: { enabled: false, defaultAgent: false, path: "", model: "", alternativeModel: "", effort: "" },
|
|
440
|
+
ccc: { DEEPSEEK_API_KEY: "", DEEPSEEK_BASE_URL: DEFAULT_CCC_DEEPSEEK_BASE_URL, model: DEFAULT_CCC_MODEL },
|
|
441
|
+
};
|
|
442
442
|
|
|
443
443
|
if (!IS_TEST_ENV) {
|
|
444
444
|
migrateLegacyData();
|
|
@@ -488,12 +488,12 @@ function loadConfig(): AppConfig {
|
|
|
488
488
|
alternativeModel?: unknown;
|
|
489
489
|
avatarBatteryMode?: unknown;
|
|
490
490
|
onDemandMonthlyBudget?: unknown;
|
|
491
|
-
};
|
|
492
|
-
codex?: { enabled?: unknown; defaultAgent?: unknown; path?: unknown; command?: unknown; model?: unknown; alternativeModel?: unknown; effort?: unknown };
|
|
493
|
-
ccc?: { DEEPSEEK_API_KEY?: unknown; DEEPSEEK_BASE_URL?: unknown; model?: unknown };
|
|
494
|
-
chromeDevtools?: { enabled?: unknown; port?: unknown; chromePath?: unknown };
|
|
495
|
-
rawStreamLogs?: unknown;
|
|
496
|
-
};
|
|
491
|
+
};
|
|
492
|
+
codex?: { enabled?: unknown; defaultAgent?: unknown; path?: unknown; command?: unknown; model?: unknown; alternativeModel?: unknown; effort?: unknown };
|
|
493
|
+
ccc?: { DEEPSEEK_API_KEY?: unknown; DEEPSEEK_BASE_URL?: unknown; model?: unknown };
|
|
494
|
+
chromeDevtools?: { enabled?: unknown; port?: unknown; chromePath?: unknown };
|
|
495
|
+
rawStreamLogs?: unknown;
|
|
496
|
+
};
|
|
497
497
|
try {
|
|
498
498
|
parsed = JSON.parse(raw);
|
|
499
499
|
} catch (err) {
|
|
@@ -503,10 +503,10 @@ function loadConfig(): AppConfig {
|
|
|
503
503
|
|
|
504
504
|
const feishu = parsed.feishu ?? { appId: "", appSecret: "" };
|
|
505
505
|
const claude = parsed.claude ?? {} as Partial<ClaudeConfig>;
|
|
506
|
-
const cursorRaw = (parsed.cursor ?? {}) as NonNullable<typeof parsed.cursor>;
|
|
507
|
-
const codexRaw = (parsed.codex ?? {}) as NonNullable<typeof parsed.codex>;
|
|
508
|
-
const cccRaw = (parsed.ccc ?? {}) as NonNullable<typeof parsed.ccc>;
|
|
509
|
-
const chromeDevtoolsRaw = (parsed.chromeDevtools ?? {}) as NonNullable<typeof parsed.chromeDevtools>;
|
|
506
|
+
const cursorRaw = (parsed.cursor ?? {}) as NonNullable<typeof parsed.cursor>;
|
|
507
|
+
const codexRaw = (parsed.codex ?? {}) as NonNullable<typeof parsed.codex>;
|
|
508
|
+
const cccRaw = (parsed.ccc ?? {}) as NonNullable<typeof parsed.ccc>;
|
|
509
|
+
const chromeDevtoolsRaw = (parsed.chromeDevtools ?? {}) as NonNullable<typeof parsed.chromeDevtools>;
|
|
510
510
|
const rawStreamLogsRaw = typeof parsed.rawStreamLogs === "object" && parsed.rawStreamLogs !== null
|
|
511
511
|
? parsed.rawStreamLogs as unknown as Record<string, unknown>
|
|
512
512
|
: {};
|
|
@@ -629,24 +629,24 @@ function loadConfig(): AppConfig {
|
|
|
629
629
|
avatarBatteryMode: normalizeCursorAvatarBatteryMode(cursorRaw.avatarBatteryMode),
|
|
630
630
|
onDemandMonthlyBudget: normalizeCursorOnDemandMonthlyBudget(cursorRaw.onDemandMonthlyBudget),
|
|
631
631
|
},
|
|
632
|
-
codex: {
|
|
633
|
-
enabled: codexEnabled,
|
|
634
|
-
defaultAgent: defaultTool === "codex",
|
|
635
|
-
path: readToolCliPath(codexRaw, { label: "codex", onLegacyField }),
|
|
636
|
-
model: normalizeOptionalConfigField(codexRaw.model, { label: "codex.model" }),
|
|
637
|
-
alternativeModel: normalizeOptionalConfigField(codexRaw.alternativeModel, { label: "codex.alternativeModel" }),
|
|
638
|
-
effort: normalizeOptionalConfigField(codexRaw.effort, { label: "codex.effort" }),
|
|
639
|
-
},
|
|
640
|
-
ccc: {
|
|
641
|
-
DEEPSEEK_API_KEY: normalizeOptionalConfigField(cccRaw.DEEPSEEK_API_KEY, { label: "ccc.DEEPSEEK_API_KEY" }),
|
|
642
|
-
DEEPSEEK_BASE_URL: normalizeOptionalConfigField(cccRaw.DEEPSEEK_BASE_URL, {
|
|
643
|
-
label: "ccc.DEEPSEEK_BASE_URL",
|
|
644
|
-
fallback: DEFAULT_CCC_DEEPSEEK_BASE_URL,
|
|
645
|
-
}),
|
|
646
|
-
model: normalizeOptionalConfigField(cccRaw.model, { label: "ccc.model", fallback: DEFAULT_CCC_MODEL }),
|
|
647
|
-
},
|
|
648
|
-
};
|
|
649
|
-
}
|
|
632
|
+
codex: {
|
|
633
|
+
enabled: codexEnabled,
|
|
634
|
+
defaultAgent: defaultTool === "codex",
|
|
635
|
+
path: readToolCliPath(codexRaw, { label: "codex", onLegacyField }),
|
|
636
|
+
model: normalizeOptionalConfigField(codexRaw.model, { label: "codex.model" }),
|
|
637
|
+
alternativeModel: normalizeOptionalConfigField(codexRaw.alternativeModel, { label: "codex.alternativeModel" }),
|
|
638
|
+
effort: normalizeOptionalConfigField(codexRaw.effort, { label: "codex.effort" }),
|
|
639
|
+
},
|
|
640
|
+
ccc: {
|
|
641
|
+
DEEPSEEK_API_KEY: normalizeOptionalConfigField(cccRaw.DEEPSEEK_API_KEY, { label: "ccc.DEEPSEEK_API_KEY" }),
|
|
642
|
+
DEEPSEEK_BASE_URL: normalizeOptionalConfigField(cccRaw.DEEPSEEK_BASE_URL, {
|
|
643
|
+
label: "ccc.DEEPSEEK_BASE_URL",
|
|
644
|
+
fallback: DEFAULT_CCC_DEEPSEEK_BASE_URL,
|
|
645
|
+
}),
|
|
646
|
+
model: normalizeOptionalConfigField(cccRaw.model, { label: "ccc.model", fallback: DEFAULT_CCC_MODEL }),
|
|
647
|
+
},
|
|
648
|
+
};
|
|
649
|
+
}
|
|
650
650
|
|
|
651
651
|
/**
|
|
652
652
|
* 全局可变 config 对象。
|