@keyou007/agent-bot 0.1.25-alpha.0 → 0.1.25-alpha.2
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/CHANGELOG.md +27 -0
- package/README.md +60 -5
- package/README.zh.md +60 -5
- package/config.example.yaml +1 -3
- package/dist/cli/controlProtocol.js.map +1 -1
- package/dist/cli/help.js +14 -0
- package/dist/cli/help.js.map +1 -1
- package/dist/cli.js +32 -0
- package/dist/cli.js.map +1 -1
- package/dist/codex/CodexRuntime.js +15 -5
- package/dist/codex/CodexRuntime.js.map +1 -1
- package/dist/commands/CommandRouter.js +7 -0
- package/dist/commands/CommandRouter.js.map +1 -1
- package/dist/config/SettingsStore.js +341 -0
- package/dist/config/SettingsStore.js.map +1 -0
- package/dist/config/loadConfig.js +1 -2
- package/dist/config/loadConfig.js.map +1 -1
- package/dist/config/schema.js +0 -1
- package/dist/config/schema.js.map +1 -1
- package/dist/console/ConsoleTurnPresenter.js +3 -0
- package/dist/console/ConsoleTurnPresenter.js.map +1 -1
- package/dist/feishu/CardRenderer.js +32 -96
- package/dist/feishu/CardRenderer.js.map +1 -1
- package/dist/feishu/FeishuConnector.js +9 -0
- package/dist/feishu/FeishuConnector.js.map +1 -1
- package/dist/feishu/FeishuMessageClient.js +35 -14
- package/dist/feishu/FeishuMessageClient.js.map +1 -1
- package/dist/feishu/FeishuTurnPresenter.js +36 -23
- package/dist/feishu/FeishuTurnPresenter.js.map +1 -1
- package/dist/feishu/LocalCardImage.js.map +1 -1
- package/dist/feishu/LocalImageMarkdown.js +59 -3
- package/dist/feishu/LocalImageMarkdown.js.map +1 -1
- package/dist/feishu/SettingsCard.js +199 -0
- package/dist/feishu/SettingsCard.js.map +1 -0
- package/dist/index.js +17 -6
- package/dist/index.js.map +1 -1
- package/dist/local-files/TurnPreviewPage.js +8 -4
- package/dist/local-files/TurnPreviewPage.js.map +1 -1
- package/dist/presentation/TurnStateReducer.js +21 -2
- package/dist/presentation/TurnStateReducer.js.map +1 -1
- package/dist/presentation/turnStatus.js +34 -0
- package/dist/presentation/turnStatus.js.map +1 -0
- package/dist/proxy/ProxySessionController.js +688 -153
- package/dist/proxy/ProxySessionController.js.map +1 -1
- package/dist/runtime/submissionErrors.js +15 -0
- package/dist/runtime/submissionErrors.js.map +1 -0
- package/dist/scheduling/ScheduleCards.js +240 -0
- package/dist/scheduling/ScheduleCards.js.map +1 -0
- package/dist/scheduling/ScheduleCommand.js +67 -0
- package/dist/scheduling/ScheduleCommand.js.map +1 -0
- package/dist/scheduling/ScheduledTaskStore.js +226 -0
- package/dist/scheduling/ScheduledTaskStore.js.map +1 -0
- package/dist/scheduling/TaskScheduler.js +132 -0
- package/dist/scheduling/TaskScheduler.js.map +1 -0
- package/dist/scheduling/types.js +89 -0
- package/dist/scheduling/types.js.map +1 -0
- package/dist/state/ExecutionProvenanceStore.js +58 -0
- package/dist/state/ExecutionProvenanceStore.js.map +1 -0
- package/dist/state/StateStore.js +145 -45
- package/dist/state/StateStore.js.map +1 -1
- package/dist/state/migrations.js +37 -0
- package/dist/state/migrations.js.map +1 -1
- package/dist/supervision/SafeRestartNotifier.js +1 -1
- package/dist/supervision/SafeRestartNotifier.js.map +1 -1
- package/docs/technical-reference.md +11 -8
- package/docs/technical-reference.zh.md +11 -8
- package/npm-shrinkwrap.json +24 -2
- package/package.json +2 -1
- package/skills/agent-bot/SKILL.md +33 -3
- package/src/cli/controlProtocol.ts +1 -0
- package/src/cli/help.ts +14 -0
- package/src/cli.ts +25 -0
- package/src/codex/CodexRuntime.ts +14 -5
- package/src/commands/CommandRouter.ts +7 -0
- package/src/commands/commandTypes.ts +2 -0
- package/src/config/SettingsStore.ts +588 -0
- package/src/config/loadConfig.ts +1 -2
- package/src/config/schema.ts +0 -1
- package/src/console/ConsoleTurnPresenter.ts +2 -0
- package/src/feishu/CardRenderer.ts +33 -110
- package/src/feishu/FeishuConnector.ts +9 -0
- package/src/feishu/FeishuMessageClient.ts +39 -17
- package/src/feishu/FeishuTurnPresenter.ts +33 -22
- package/src/feishu/LocalCardImage.ts +0 -1
- package/src/feishu/LocalImageMarkdown.ts +54 -3
- package/src/feishu/SettingsCard.ts +231 -0
- package/src/index.ts +17 -6
- package/src/local-files/TurnPreviewPage.ts +8 -4
- package/src/presentation/TurnStateReducer.ts +21 -2
- package/src/presentation/turnStatus.ts +38 -0
- package/src/presentation/turnViewTypes.ts +3 -0
- package/src/proxy/ProxySessionController.ts +628 -152
- package/src/runtime/submissionErrors.ts +15 -0
- package/src/runtime/types.ts +1 -0
- package/src/scheduling/ScheduleCards.ts +317 -0
- package/src/scheduling/ScheduleCommand.ts +76 -0
- package/src/scheduling/ScheduledTaskStore.ts +332 -0
- package/src/scheduling/TaskScheduler.ts +171 -0
- package/src/scheduling/types.ts +151 -0
- package/src/state/ExecutionProvenanceStore.ts +100 -0
- package/src/state/StateStore.ts +167 -44
- package/src/state/migrations.ts +37 -0
- package/src/supervision/SafeRestartNotifier.ts +1 -1
|
@@ -0,0 +1,588 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
3
|
+
import { isMap, parseDocument } from "yaml";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { appConfigSchema, type AppConfig } from "./schema.js";
|
|
6
|
+
import type { ModelListResult, ModelProviderOption } from "../runtime/types.js";
|
|
7
|
+
|
|
8
|
+
export interface SettingsCatalog extends ModelListResult {
|
|
9
|
+
providers?: ModelProviderOption[];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const SETTINGS_SECTIONS = {
|
|
13
|
+
general: "常用",
|
|
14
|
+
agents: "Agent",
|
|
15
|
+
naming: "群名",
|
|
16
|
+
services: "高级",
|
|
17
|
+
} as const;
|
|
18
|
+
export type SettingsSection = keyof typeof SETTINGS_SECTIONS;
|
|
19
|
+
export interface SettingsField {
|
|
20
|
+
name: string;
|
|
21
|
+
label: string;
|
|
22
|
+
path: string[];
|
|
23
|
+
kind: "text" | "boolean" | "select" | "number";
|
|
24
|
+
fallback: string | boolean | number;
|
|
25
|
+
optional?: boolean;
|
|
26
|
+
options?: Array<{ value: string; label: string }>;
|
|
27
|
+
schema: z.ZodType;
|
|
28
|
+
}
|
|
29
|
+
export interface SettingsSnapshot {
|
|
30
|
+
section: SettingsSection;
|
|
31
|
+
agentName?: string;
|
|
32
|
+
agents: Array<{ name: string; title: string }>;
|
|
33
|
+
revision: string;
|
|
34
|
+
fieldRevisions: Record<string, string>;
|
|
35
|
+
fields: SettingsField[];
|
|
36
|
+
values: Record<string, string | boolean | number>;
|
|
37
|
+
pendingRestart: boolean;
|
|
38
|
+
modelProvider?: string;
|
|
39
|
+
model?: string;
|
|
40
|
+
reasoningEffort?: string;
|
|
41
|
+
warning?: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const text = z
|
|
45
|
+
.string()
|
|
46
|
+
.trim()
|
|
47
|
+
.max(1000)
|
|
48
|
+
.refine((value) => !/[\r\n\0]/u.test(value), "不能包含换行或空字符");
|
|
49
|
+
const option = (value: string, label = value) => ({ value, label });
|
|
50
|
+
const field = (
|
|
51
|
+
name: string,
|
|
52
|
+
label: string,
|
|
53
|
+
path: string[],
|
|
54
|
+
kind: SettingsField["kind"],
|
|
55
|
+
fallback: SettingsField["fallback"],
|
|
56
|
+
schema: z.ZodType,
|
|
57
|
+
extra: Partial<SettingsField> = {},
|
|
58
|
+
): SettingsField => ({ name, label, path, kind, fallback, schema, ...extra });
|
|
59
|
+
|
|
60
|
+
export function settingsSection(value: unknown): SettingsSection {
|
|
61
|
+
if (typeof value !== "string" || !Object.hasOwn(SETTINGS_SECTIONS, value))
|
|
62
|
+
throw new Error("无效的配置分组。");
|
|
63
|
+
return value as SettingsSection;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function fieldsFor(
|
|
67
|
+
section: SettingsSection,
|
|
68
|
+
config: AppConfig,
|
|
69
|
+
agentName?: string,
|
|
70
|
+
catalog?: SettingsCatalog,
|
|
71
|
+
allAgentFields = false,
|
|
72
|
+
): SettingsField[] {
|
|
73
|
+
const bool = (name: string, label: string, path: string[], fallback = true) =>
|
|
74
|
+
field(name, label, path, "boolean", fallback, z.boolean());
|
|
75
|
+
switch (section) {
|
|
76
|
+
case "general":
|
|
77
|
+
return [
|
|
78
|
+
...(Object.keys(config.agents).length === 1
|
|
79
|
+
? fieldsFor(
|
|
80
|
+
"agents",
|
|
81
|
+
config,
|
|
82
|
+
Object.keys(config.agents)[0],
|
|
83
|
+
catalog,
|
|
84
|
+
true,
|
|
85
|
+
).filter((entry) => ["modelProvider", "model"].includes(entry.name))
|
|
86
|
+
: [
|
|
87
|
+
field(
|
|
88
|
+
"agent",
|
|
89
|
+
"默认 Agent",
|
|
90
|
+
["defaults", "agent"],
|
|
91
|
+
"select",
|
|
92
|
+
Object.keys(config.agents)[0]!,
|
|
93
|
+
text.refine(
|
|
94
|
+
(value) => Object.hasOwn(config.agents, value),
|
|
95
|
+
"Agent 未配置",
|
|
96
|
+
),
|
|
97
|
+
{
|
|
98
|
+
options: Object.entries(config.agents).map(([name, agent]) =>
|
|
99
|
+
option(name, `${agent.title} (${name})`),
|
|
100
|
+
),
|
|
101
|
+
},
|
|
102
|
+
),
|
|
103
|
+
]),
|
|
104
|
+
bool("ownerOnly", "仅响应所有者", ["feishu", "respondToOwnerOnly"]),
|
|
105
|
+
bool("allGroupMessages", "响应群内所有消息", [
|
|
106
|
+
"feishu",
|
|
107
|
+
"respondToAllGroupMessages",
|
|
108
|
+
]),
|
|
109
|
+
bool("updates", "自动检查并安装正式版更新", ["updates", "enabled"]),
|
|
110
|
+
];
|
|
111
|
+
case "agents": {
|
|
112
|
+
if (!agentName || !Object.hasOwn(config.agents, agentName))
|
|
113
|
+
throw new Error("请选择已配置的 Agent。");
|
|
114
|
+
const prefix = ["agents", agentName, "defaults"];
|
|
115
|
+
const defaults = config.agents[agentName]!.defaults;
|
|
116
|
+
const models = catalog?.models ?? [];
|
|
117
|
+
const choices = (
|
|
118
|
+
entries: Array<{ value: string; label: string }>,
|
|
119
|
+
current?: string,
|
|
120
|
+
) => {
|
|
121
|
+
const unique = new Map(entries.map((entry) => [entry.value, entry]));
|
|
122
|
+
unique.delete("");
|
|
123
|
+
if (current && !unique.has(current))
|
|
124
|
+
unique.set(current, option(current, `${current}(当前配置)`));
|
|
125
|
+
return [option("", "使用 Agent 默认"), ...unique.values()];
|
|
126
|
+
};
|
|
127
|
+
const modelChoices = choices(
|
|
128
|
+
models.map((model) =>
|
|
129
|
+
option(
|
|
130
|
+
model.id,
|
|
131
|
+
model.displayName && model.displayName !== model.id
|
|
132
|
+
? `${model.displayName} (${model.id})`
|
|
133
|
+
: model.id,
|
|
134
|
+
),
|
|
135
|
+
),
|
|
136
|
+
defaults.model,
|
|
137
|
+
);
|
|
138
|
+
const providerChoices = choices(
|
|
139
|
+
(catalog?.providers ?? []).map((provider) =>
|
|
140
|
+
option(
|
|
141
|
+
provider.id,
|
|
142
|
+
provider.displayName && provider.displayName !== provider.id
|
|
143
|
+
? `${provider.displayName} (${provider.id})`
|
|
144
|
+
: provider.id,
|
|
145
|
+
),
|
|
146
|
+
),
|
|
147
|
+
defaults.modelProvider,
|
|
148
|
+
);
|
|
149
|
+
const effortChoices = choices(
|
|
150
|
+
models.flatMap((model) =>
|
|
151
|
+
model.supportedReasoningEfforts.map((effort) => option(effort.value)),
|
|
152
|
+
),
|
|
153
|
+
defaults.reasoningEffort,
|
|
154
|
+
);
|
|
155
|
+
const selection = (options: typeof modelChoices) =>
|
|
156
|
+
z
|
|
157
|
+
.string()
|
|
158
|
+
.refine((value) => options.some((entry) => entry.value === value));
|
|
159
|
+
const fields = [
|
|
160
|
+
field(
|
|
161
|
+
"modelProvider",
|
|
162
|
+
"默认 Provider",
|
|
163
|
+
[...prefix, "modelProvider"],
|
|
164
|
+
"select",
|
|
165
|
+
"",
|
|
166
|
+
selection(providerChoices),
|
|
167
|
+
{ optional: true, options: providerChoices },
|
|
168
|
+
),
|
|
169
|
+
field(
|
|
170
|
+
"model",
|
|
171
|
+
"默认模型",
|
|
172
|
+
[...prefix, "model"],
|
|
173
|
+
"select",
|
|
174
|
+
"",
|
|
175
|
+
selection(modelChoices),
|
|
176
|
+
{ optional: true, options: modelChoices },
|
|
177
|
+
),
|
|
178
|
+
field(
|
|
179
|
+
"reasoningEffort",
|
|
180
|
+
"默认思考强度",
|
|
181
|
+
[...prefix, "reasoningEffort"],
|
|
182
|
+
"select",
|
|
183
|
+
"",
|
|
184
|
+
selection(effortChoices),
|
|
185
|
+
{ optional: true, options: effortChoices },
|
|
186
|
+
),
|
|
187
|
+
field(
|
|
188
|
+
"permissionMode",
|
|
189
|
+
"默认权限",
|
|
190
|
+
[...prefix, "permissionMode"],
|
|
191
|
+
"select",
|
|
192
|
+
"",
|
|
193
|
+
z.enum(["", "auto", "confirm"]),
|
|
194
|
+
{
|
|
195
|
+
optional: true,
|
|
196
|
+
options: [
|
|
197
|
+
option("", "使用 Agent 默认"),
|
|
198
|
+
option("confirm", "操作前确认"),
|
|
199
|
+
option("auto", "自动执行"),
|
|
200
|
+
],
|
|
201
|
+
},
|
|
202
|
+
),
|
|
203
|
+
];
|
|
204
|
+
return allAgentFields
|
|
205
|
+
? fields
|
|
206
|
+
: fields.filter((entry) =>
|
|
207
|
+
Object.keys(config.agents).length === 1
|
|
208
|
+
? ["reasoningEffort", "permissionMode"].includes(entry.name)
|
|
209
|
+
: entry.name !== "modelProvider",
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
case "naming":
|
|
213
|
+
return [
|
|
214
|
+
field(
|
|
215
|
+
"project",
|
|
216
|
+
"项目群命名格式",
|
|
217
|
+
["feishu", "groupNameFormat", "project"],
|
|
218
|
+
"text",
|
|
219
|
+
"[{agent}] [{project}] {taskname}",
|
|
220
|
+
text.min(1).max(240),
|
|
221
|
+
),
|
|
222
|
+
field(
|
|
223
|
+
"projectless",
|
|
224
|
+
"无项目群命名格式",
|
|
225
|
+
["feishu", "groupNameFormat", "projectless"],
|
|
226
|
+
"text",
|
|
227
|
+
"[{agent}] {taskname}",
|
|
228
|
+
text.min(1).max(240),
|
|
229
|
+
),
|
|
230
|
+
field(
|
|
231
|
+
"dateFormat",
|
|
232
|
+
"日期格式",
|
|
233
|
+
["feishu", "groupNameFormat", "dateFormat"],
|
|
234
|
+
"text",
|
|
235
|
+
"MM-dd",
|
|
236
|
+
text.min(1).max(80),
|
|
237
|
+
),
|
|
238
|
+
];
|
|
239
|
+
case "services":
|
|
240
|
+
return [
|
|
241
|
+
bool("console", "本地控制台", ["console", "enabled"]),
|
|
242
|
+
bool("terminal", "网页终端", ["terminal", "enabled"]),
|
|
243
|
+
bool("preview", "文件与 Turn 预览", ["fileViewer", "enabled"]),
|
|
244
|
+
field(
|
|
245
|
+
"host",
|
|
246
|
+
"监听地址",
|
|
247
|
+
["fileViewer", "host"],
|
|
248
|
+
"text",
|
|
249
|
+
"127.0.0.1",
|
|
250
|
+
text
|
|
251
|
+
.min(1)
|
|
252
|
+
.refine(
|
|
253
|
+
(value) => !/[\s/\\?#@]/u.test(value),
|
|
254
|
+
"请输入主机名或 IP 地址",
|
|
255
|
+
),
|
|
256
|
+
),
|
|
257
|
+
field(
|
|
258
|
+
"port",
|
|
259
|
+
"端口",
|
|
260
|
+
["fileViewer", "port"],
|
|
261
|
+
"number",
|
|
262
|
+
0,
|
|
263
|
+
z.number().int().min(0).max(65535),
|
|
264
|
+
),
|
|
265
|
+
field(
|
|
266
|
+
"logLevel",
|
|
267
|
+
"日志级别",
|
|
268
|
+
["logging", "level"],
|
|
269
|
+
"select",
|
|
270
|
+
"info",
|
|
271
|
+
z.enum(["trace", "debug", "info", "warn", "error", "fatal"]),
|
|
272
|
+
{
|
|
273
|
+
options: ["trace", "debug", "info", "warn", "error", "fatal"].map(
|
|
274
|
+
(value) => option(value),
|
|
275
|
+
),
|
|
276
|
+
},
|
|
277
|
+
),
|
|
278
|
+
];
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function getValue(root: unknown, keys: string[]): unknown {
|
|
283
|
+
let value = root;
|
|
284
|
+
for (const key of keys) {
|
|
285
|
+
if (!value || typeof value !== "object" || !Object.hasOwn(value, key))
|
|
286
|
+
return undefined;
|
|
287
|
+
value = (value as Record<string, unknown>)[key];
|
|
288
|
+
}
|
|
289
|
+
return value;
|
|
290
|
+
}
|
|
291
|
+
const revisionOf = (contents: string) =>
|
|
292
|
+
createHash("sha256").update(contents).digest("hex");
|
|
293
|
+
|
|
294
|
+
export class SettingsStore {
|
|
295
|
+
constructor(
|
|
296
|
+
private readonly configPath: string,
|
|
297
|
+
private readonly activeConfig: AppConfig,
|
|
298
|
+
) {}
|
|
299
|
+
|
|
300
|
+
private readDocument() {
|
|
301
|
+
const original = fs.readFileSync(this.configPath, "utf8");
|
|
302
|
+
const document = parseDocument(original);
|
|
303
|
+
if (document.errors.length || !isMap(document.contents))
|
|
304
|
+
throw new Error("配置文件不是有效的 YAML 对象,请先在本机修复。");
|
|
305
|
+
// Validate without including YAML source, environment values or secrets in errors/cards.
|
|
306
|
+
const expanded = parseDocument(
|
|
307
|
+
original.replace(
|
|
308
|
+
/\$\{([A-Z0-9_]+)\}/gi,
|
|
309
|
+
(_match, name: string) => process.env[name] ?? "",
|
|
310
|
+
),
|
|
311
|
+
);
|
|
312
|
+
let data: unknown;
|
|
313
|
+
try {
|
|
314
|
+
data = expanded.toJS();
|
|
315
|
+
} catch {
|
|
316
|
+
throw new Error("配置文件无法解析,请先在本机修复。");
|
|
317
|
+
}
|
|
318
|
+
const result = appConfigSchema.safeParse(data);
|
|
319
|
+
if (expanded.errors.length || !result.success)
|
|
320
|
+
throw new Error("配置文件校验失败,请先在本机修复。");
|
|
321
|
+
return { original, document, config: result.data };
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
read(
|
|
325
|
+
sectionValue: unknown = "general",
|
|
326
|
+
requestedAgent?: string,
|
|
327
|
+
catalog?: SettingsCatalog,
|
|
328
|
+
): SettingsSnapshot {
|
|
329
|
+
return this.readSnapshot(sectionValue, requestedAgent, catalog);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
private readSnapshot(
|
|
333
|
+
sectionValue: unknown,
|
|
334
|
+
requestedAgent?: string,
|
|
335
|
+
catalog?: SettingsCatalog,
|
|
336
|
+
allAgentFields = false,
|
|
337
|
+
): SettingsSnapshot {
|
|
338
|
+
const section = settingsSection(sectionValue);
|
|
339
|
+
const { original, document, config } = this.readDocument();
|
|
340
|
+
const agentName =
|
|
341
|
+
section === "agents"
|
|
342
|
+
? (requestedAgent ??
|
|
343
|
+
config.defaults.agent ??
|
|
344
|
+
Object.keys(config.agents)[0])
|
|
345
|
+
: section === "general" && Object.keys(config.agents).length === 1
|
|
346
|
+
? Object.keys(config.agents)[0]
|
|
347
|
+
: undefined;
|
|
348
|
+
const fields = fieldsFor(
|
|
349
|
+
section,
|
|
350
|
+
config,
|
|
351
|
+
agentName,
|
|
352
|
+
catalog,
|
|
353
|
+
allAgentFields,
|
|
354
|
+
);
|
|
355
|
+
const values: SettingsSnapshot["values"] = {};
|
|
356
|
+
const fieldRevisions: Record<string, string> = {};
|
|
357
|
+
let pendingRestart = false;
|
|
358
|
+
for (const entry of fields) {
|
|
359
|
+
const raw = document.getIn(entry.path);
|
|
360
|
+
const effective = getValue(config, entry.path) ?? entry.fallback;
|
|
361
|
+
values[entry.name] =
|
|
362
|
+
entry.kind === "text" && typeof raw === "string"
|
|
363
|
+
? raw
|
|
364
|
+
: typeof effective === "string" ||
|
|
365
|
+
typeof effective === "boolean" ||
|
|
366
|
+
typeof effective === "number"
|
|
367
|
+
? effective
|
|
368
|
+
: entry.fallback;
|
|
369
|
+
const active = getValue(this.activeConfig, entry.path) ?? entry.fallback;
|
|
370
|
+
pendingRestart ||= effective !== active;
|
|
371
|
+
fieldRevisions[entry.name] = revisionOf(
|
|
372
|
+
JSON.stringify([
|
|
373
|
+
entry.path,
|
|
374
|
+
raw,
|
|
375
|
+
effective,
|
|
376
|
+
agentName &&
|
|
377
|
+
["modelProvider", "model", "reasoningEffort"].includes(entry.name)
|
|
378
|
+
? {
|
|
379
|
+
provider: config.agents[agentName]!.defaults.modelProvider,
|
|
380
|
+
dependentValue:
|
|
381
|
+
entry.name === "modelProvider"
|
|
382
|
+
? config.agents[agentName]!.defaults
|
|
383
|
+
: entry.name === "model"
|
|
384
|
+
? config.agents[agentName]!.defaults.reasoningEffort
|
|
385
|
+
: config.agents[agentName]!.defaults.model,
|
|
386
|
+
}
|
|
387
|
+
: undefined,
|
|
388
|
+
]),
|
|
389
|
+
);
|
|
390
|
+
}
|
|
391
|
+
return {
|
|
392
|
+
section,
|
|
393
|
+
agentName,
|
|
394
|
+
fields,
|
|
395
|
+
values,
|
|
396
|
+
fieldRevisions,
|
|
397
|
+
pendingRestart,
|
|
398
|
+
...(agentName
|
|
399
|
+
? {
|
|
400
|
+
modelProvider: config.agents[agentName]!.defaults.modelProvider,
|
|
401
|
+
model: config.agents[agentName]!.defaults.model,
|
|
402
|
+
reasoningEffort: config.agents[agentName]!.defaults.reasoningEffort,
|
|
403
|
+
warning: catalog?.warning,
|
|
404
|
+
}
|
|
405
|
+
: {}),
|
|
406
|
+
revision: revisionOf(original),
|
|
407
|
+
agents: Object.entries(config.agents).map(([name, agent]) => ({
|
|
408
|
+
name,
|
|
409
|
+
title: agent.title,
|
|
410
|
+
})),
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
saveField(
|
|
415
|
+
sectionValue: unknown,
|
|
416
|
+
agentName: string | undefined,
|
|
417
|
+
name: unknown,
|
|
418
|
+
revision: unknown,
|
|
419
|
+
value: unknown,
|
|
420
|
+
catalog?: SettingsCatalog,
|
|
421
|
+
): SettingsSnapshot {
|
|
422
|
+
const view = this.read(sectionValue, agentName, catalog);
|
|
423
|
+
if (
|
|
424
|
+
typeof name !== "string" ||
|
|
425
|
+
!view.fields.some((entry) => entry.name === name)
|
|
426
|
+
)
|
|
427
|
+
throw new Error("不允许修改此配置项。");
|
|
428
|
+
if (typeof revision !== "string" || revision !== view.fieldRevisions[name])
|
|
429
|
+
throw new Error("此配置项已变化,请刷新后重新选择。");
|
|
430
|
+
const snapshot =
|
|
431
|
+
view.agentName &&
|
|
432
|
+
["modelProvider", "model", "reasoningEffort", "permissionMode"].includes(
|
|
433
|
+
name,
|
|
434
|
+
)
|
|
435
|
+
? this.readSnapshot("agents", view.agentName, catalog, true)
|
|
436
|
+
: view;
|
|
437
|
+
if (revision !== snapshot.fieldRevisions[name])
|
|
438
|
+
throw new Error("此配置项已变化,请刷新后重新选择。");
|
|
439
|
+
const next: Record<string, unknown> = { ...snapshot.values, [name]: value };
|
|
440
|
+
const normalized = value === "__agent_default__" ? "" : value;
|
|
441
|
+
if (
|
|
442
|
+
name === "modelProvider" &&
|
|
443
|
+
normalized !== snapshot.values.modelProvider
|
|
444
|
+
) {
|
|
445
|
+
next.model =
|
|
446
|
+
catalog?.models.find((model) => model.id === snapshot.values.model)
|
|
447
|
+
?.id ??
|
|
448
|
+
catalog?.models.find((model) => model.isDefault)?.id ??
|
|
449
|
+
catalog?.models[0]?.id ??
|
|
450
|
+
"";
|
|
451
|
+
}
|
|
452
|
+
if (
|
|
453
|
+
snapshot.agentName &&
|
|
454
|
+
["modelProvider", "model"].includes(name) &&
|
|
455
|
+
normalized !== snapshot.values[name]
|
|
456
|
+
) {
|
|
457
|
+
const selected =
|
|
458
|
+
next.model === "__agent_default__" || next.model === ""
|
|
459
|
+
? catalog?.models.find((model) => model.isDefault)
|
|
460
|
+
: catalog?.models.find((model) => model.id === next.model);
|
|
461
|
+
if (
|
|
462
|
+
next.reasoningEffort &&
|
|
463
|
+
!selected?.supportedReasoningEfforts.some(
|
|
464
|
+
(effort) => effort.value === next.reasoningEffort,
|
|
465
|
+
)
|
|
466
|
+
)
|
|
467
|
+
next.reasoningEffort = "";
|
|
468
|
+
}
|
|
469
|
+
this.saveSnapshot(snapshot, snapshot.revision, next, catalog);
|
|
470
|
+
return this.read(view.section, view.agentName, catalog);
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
save(
|
|
474
|
+
sectionValue: unknown,
|
|
475
|
+
agentName: string | undefined,
|
|
476
|
+
revision: unknown,
|
|
477
|
+
form: unknown,
|
|
478
|
+
catalog?: SettingsCatalog,
|
|
479
|
+
): SettingsSnapshot {
|
|
480
|
+
const snapshot = this.read(sectionValue, agentName, catalog);
|
|
481
|
+
return this.saveSnapshot(snapshot, revision, form, catalog);
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
private saveSnapshot(
|
|
485
|
+
snapshot: SettingsSnapshot,
|
|
486
|
+
revision: unknown,
|
|
487
|
+
form: unknown,
|
|
488
|
+
catalog?: SettingsCatalog,
|
|
489
|
+
): SettingsSnapshot {
|
|
490
|
+
if (typeof revision !== "string" || revision !== snapshot.revision)
|
|
491
|
+
throw new Error("配置已变化,请刷新面板后重新编辑。");
|
|
492
|
+
if (!form || typeof form !== "object" || Array.isArray(form))
|
|
493
|
+
throw new Error("缺少配置表单。");
|
|
494
|
+
const input = form as Record<string, unknown>;
|
|
495
|
+
const allowed = new Set(snapshot.fields.map((entry) => entry.name));
|
|
496
|
+
if (Object.keys(input).some((name) => !allowed.has(name)))
|
|
497
|
+
throw new Error("表单包含不允许修改的配置项。");
|
|
498
|
+
const { original, document } = this.readDocument();
|
|
499
|
+
if (revisionOf(original) !== revision)
|
|
500
|
+
throw new Error("配置已变化,请刷新面板后重新编辑。");
|
|
501
|
+
let changed = false;
|
|
502
|
+
const next = { ...snapshot.values };
|
|
503
|
+
for (const entry of snapshot.fields) {
|
|
504
|
+
if (!Object.hasOwn(input, entry.name))
|
|
505
|
+
throw new Error(`缺少配置项:${entry.label}。`);
|
|
506
|
+
let value = input[entry.name];
|
|
507
|
+
if (entry.kind === "select" && value === "__agent_default__") value = "";
|
|
508
|
+
// Do not materialize defaults or replace existing environment references on a no-op save.
|
|
509
|
+
if (value === snapshot.values[entry.name]) continue;
|
|
510
|
+
if (
|
|
511
|
+
entry.kind === "number" &&
|
|
512
|
+
typeof value === "string" &&
|
|
513
|
+
/^\d+$/u.test(value.trim())
|
|
514
|
+
)
|
|
515
|
+
value = Number(value);
|
|
516
|
+
const parsed = entry.schema.safeParse(value);
|
|
517
|
+
if (!parsed.success) throw new Error(`配置项无效:${entry.label}。`);
|
|
518
|
+
if (parsed.data === snapshot.values[entry.name]) continue;
|
|
519
|
+
changed = true;
|
|
520
|
+
next[entry.name] = parsed.data as string | number | boolean;
|
|
521
|
+
if (entry.optional && parsed.data === "") document.deleteIn(entry.path);
|
|
522
|
+
else document.setIn(entry.path, parsed.data);
|
|
523
|
+
}
|
|
524
|
+
if (
|
|
525
|
+
snapshot.section === "agents" &&
|
|
526
|
+
next.reasoningEffort &&
|
|
527
|
+
(next.model !== snapshot.values.model ||
|
|
528
|
+
next.reasoningEffort !== snapshot.values.reasoningEffort)
|
|
529
|
+
) {
|
|
530
|
+
const selected = next.model
|
|
531
|
+
? catalog?.models.find((model) => model.id === next.model)
|
|
532
|
+
: catalog?.models.find((model) => model.isDefault);
|
|
533
|
+
if (!selected)
|
|
534
|
+
throw new Error(
|
|
535
|
+
"无法确认此模型支持的思考强度,请选择已列出的模型或将思考强度设为使用 Agent 默认。",
|
|
536
|
+
);
|
|
537
|
+
if (
|
|
538
|
+
!selected.supportedReasoningEfforts.some(
|
|
539
|
+
(effort) => effort.value === next.reasoningEffort,
|
|
540
|
+
)
|
|
541
|
+
)
|
|
542
|
+
throw new Error(
|
|
543
|
+
`所选模型不支持此思考强度;请选择 ${selected.supportedReasoningEfforts.map((effort) => effort.value).join("、") || "使用 Agent 默认"},或使用 Agent 默认。`,
|
|
544
|
+
);
|
|
545
|
+
}
|
|
546
|
+
if (!changed) return snapshot;
|
|
547
|
+
const updated = document.toString();
|
|
548
|
+
const candidate = parseDocument(
|
|
549
|
+
updated.replace(
|
|
550
|
+
/\$\{([A-Z0-9_]+)\}/gi,
|
|
551
|
+
(_match, name: string) => process.env[name] ?? "",
|
|
552
|
+
),
|
|
553
|
+
);
|
|
554
|
+
let candidateData: unknown;
|
|
555
|
+
try {
|
|
556
|
+
candidateData = candidate.toJS();
|
|
557
|
+
} catch {
|
|
558
|
+
throw new Error("修改后的配置无法解析。");
|
|
559
|
+
}
|
|
560
|
+
if (
|
|
561
|
+
candidate.errors.length ||
|
|
562
|
+
!appConfigSchema.safeParse(candidateData).success
|
|
563
|
+
)
|
|
564
|
+
throw new Error(
|
|
565
|
+
"配置校验失败:请检查群名格式等字段,群名必须包含且仅包含一个 {taskname}。",
|
|
566
|
+
);
|
|
567
|
+
if (updated !== original) this.write(original, updated);
|
|
568
|
+
return this.read(snapshot.section, snapshot.agentName, catalog);
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
private write(original: string, updated: string): void {
|
|
572
|
+
const temporary = `${this.configPath}.${randomUUID()}.tmp`;
|
|
573
|
+
let handle: number | undefined;
|
|
574
|
+
try {
|
|
575
|
+
handle = fs.openSync(temporary, "wx", fs.statSync(this.configPath).mode);
|
|
576
|
+
fs.writeFileSync(handle, updated, "utf8");
|
|
577
|
+
fs.fsyncSync(handle);
|
|
578
|
+
fs.closeSync(handle);
|
|
579
|
+
handle = undefined;
|
|
580
|
+
if (fs.readFileSync(this.configPath, "utf8") !== original)
|
|
581
|
+
throw new Error("配置已变化,请刷新面板后重新编辑。");
|
|
582
|
+
fs.renameSync(temporary, this.configPath);
|
|
583
|
+
} finally {
|
|
584
|
+
if (handle !== undefined) fs.closeSync(handle);
|
|
585
|
+
fs.rmSync(temporary, { force: true });
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
}
|
package/src/config/loadConfig.ts
CHANGED
|
@@ -21,7 +21,6 @@ const DEFAULT_CONFIG = `feishu:
|
|
|
21
21
|
project: "[{agent}] [{project}] {taskname}"
|
|
22
22
|
projectless: "[{agent}] {taskname}"
|
|
23
23
|
dateFormat: "MM-dd"
|
|
24
|
-
thinkingCardLayout: "grouped"
|
|
25
24
|
|
|
26
25
|
console:
|
|
27
26
|
enabled: true
|
|
@@ -56,7 +55,7 @@ agents:
|
|
|
56
55
|
- "--listen"
|
|
57
56
|
- "stdio://"
|
|
58
57
|
env: {}
|
|
59
|
-
#
|
|
58
|
+
# Configure explicitly here or through /settings; task settings stay task-local.
|
|
60
59
|
defaults:
|
|
61
60
|
# modelProvider: "openai"
|
|
62
61
|
# model: "gpt-5"
|
package/src/config/schema.ts
CHANGED
|
@@ -83,7 +83,6 @@ export const appConfigSchema = z.object({
|
|
|
83
83
|
respondToOwnerOnly: z.boolean().default(true),
|
|
84
84
|
respondToAllGroupMessages: z.boolean().default(true),
|
|
85
85
|
groupNameFormat: groupNameFormatSchema,
|
|
86
|
-
thinkingCardLayout: z.enum(["grouped", "timeline"]).default("grouped"),
|
|
87
86
|
useConsoleWhenMissingCredentials: z.boolean().default(false),
|
|
88
87
|
}),
|
|
89
88
|
agents: z.record(z.string().min(1), agentConfigSchema).refine(
|
|
@@ -61,6 +61,8 @@ export class ConsoleTurnPresenter implements TurnPresenter {
|
|
|
61
61
|
await this.outbound.sendMarkdown(contextKey, event.finalResponse || "(completed without text)");
|
|
62
62
|
} else if (event.type === "turn_failed") {
|
|
63
63
|
await this.outbound.sendText(contextKey, `${this.agentLabel(event.sessionId)} failed: ${event.message}`);
|
|
64
|
+
} else if (event.type === "turn_status_unknown") {
|
|
65
|
+
await this.outbound.sendText(contextKey, `${this.agentLabel(event.sessionId)} execution unverified: ${event.message}`);
|
|
64
66
|
} else if (event.type === "turn_cancelled") {
|
|
65
67
|
await this.outbound.sendText(contextKey, `${this.agentLabel(event.sessionId)} stopped.`);
|
|
66
68
|
}
|