@michengai/dsh-agency-agents 1.2.13 → 1.2.15
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 +22 -0
- package/CHANGELOG.zh-CN.md +22 -0
- package/README.md +1 -1
- package/README.zh-CN.md +1 -1
- package/lib/client.js +26 -23
- package/lib/index.js +1 -1
- package/lib/remote.d.ts +111 -1
- package/lib/remote.js +53 -1
- package/lib/{src-9NxK49RV.js → src-D3NK414L.js} +585 -3
- package/package.json +1 -1
|
@@ -255,7 +255,19 @@ const TEAM_EN = {
|
|
|
255
255
|
"示例追加失败,草稿已保留。": "Could not append the example. Your draft is preserved.",
|
|
256
256
|
"已移除团队(请重新选择)": "Removed team (select again)",
|
|
257
257
|
"团队已停用或成员失效,请修复后再发送。": "The team is disabled or has unavailable members. Fix it before sending.",
|
|
258
|
-
"建议在插件页开启 Agent Team 的 Host 与 Web 层,并重新加载会话;未开启也可继续使用普通专家团。": "Enable the Host and Web layers of Agent Team in Plugins, then reload the conversation. Standard expert teams also work without it."
|
|
258
|
+
"建议在插件页开启 Agent Team 的 Host 与 Web 层,并重新加载会话;未开启也可继续使用普通专家团。": "Enable the Host and Web layers of Agent Team in Plugins, then reload the conversation. Standard expert teams also work without it.",
|
|
259
|
+
"人工创建": "Manual",
|
|
260
|
+
"通过对话创建": "Create with AI",
|
|
261
|
+
"通过对话创建专家团": "Create Team with AI",
|
|
262
|
+
"描述你的任务目标、关注重点或期望的专业搭配……": "Describe your mission, focus areas, or desired team roles…",
|
|
263
|
+
"生成草案": "Generate draft",
|
|
264
|
+
"正在构思草案…": "Thinking…",
|
|
265
|
+
"使用草稿并编辑": "Use draft and edit",
|
|
266
|
+
"生成过程由宿主大模型驱动,确认草案前不会写入任何配置或创建子代理。": "Generation is powered by host LLM. No settings are saved or subagents spawned until you explicitly save in the editor.",
|
|
267
|
+
"重新生成": "Regenerate",
|
|
268
|
+
"入选理由": "Selection Reason",
|
|
269
|
+
"覆盖成员": "Team Roster",
|
|
270
|
+
"帮我组建一个专家团队,任务目标是 ": "Assemble an expert team for this mission: "
|
|
259
271
|
};
|
|
260
272
|
function teamText(locale, key, values = []) {
|
|
261
273
|
const canonical = Object.hasOwn(TEAM_EN, key) ? key : Object.entries(TEAM_EN).find(([, value]) => value === key)?.[0] ?? key;
|
|
@@ -2165,6 +2177,243 @@ async function executeTeam(args) {
|
|
|
2165
2177
|
};
|
|
2166
2178
|
}
|
|
2167
2179
|
//#endregion
|
|
2180
|
+
//#region src/creation-tools.ts
|
|
2181
|
+
function generateProposalId() {
|
|
2182
|
+
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") return `prop-${crypto.randomUUID()}`;
|
|
2183
|
+
return `prop-${Math.random().toString(36).slice(2, 10)}-${Date.now().toString(36)}`;
|
|
2184
|
+
}
|
|
2185
|
+
const storedProposalItemSchema = z.union([z.object({
|
|
2186
|
+
kind: z.literal("expert"),
|
|
2187
|
+
data: customExpertInputSchema,
|
|
2188
|
+
confirmed: z.boolean().optional(),
|
|
2189
|
+
sessionId: z.string().optional()
|
|
2190
|
+
}), z.object({
|
|
2191
|
+
kind: z.literal("team"),
|
|
2192
|
+
data: teamInputSchema,
|
|
2193
|
+
memberReasons: z.record(z.string(), z.string()).optional(),
|
|
2194
|
+
confirmed: z.boolean().optional(),
|
|
2195
|
+
sessionId: z.string().optional()
|
|
2196
|
+
})]);
|
|
2197
|
+
const storedProposalSchema = storedProposalItemSchema.nullable();
|
|
2198
|
+
const latestProposalSchema = z.object({
|
|
2199
|
+
id: z.string(),
|
|
2200
|
+
proposal: storedProposalItemSchema,
|
|
2201
|
+
timestamp: z.number()
|
|
2202
|
+
}).nullable();
|
|
2203
|
+
function createProposalRegistry() {
|
|
2204
|
+
const store = /* @__PURE__ */ new Map();
|
|
2205
|
+
const TTL_MS = 9e5;
|
|
2206
|
+
const cleanup = () => {
|
|
2207
|
+
const now = Date.now();
|
|
2208
|
+
for (const [id, item] of store.entries()) if (now > item.expiresAt) store.delete(id);
|
|
2209
|
+
};
|
|
2210
|
+
const matchSession = (entry, sessionId) => {
|
|
2211
|
+
if (!sessionId) return true;
|
|
2212
|
+
if (!entry.proposal.sessionId) return true;
|
|
2213
|
+
return entry.proposal.sessionId === sessionId;
|
|
2214
|
+
};
|
|
2215
|
+
return {
|
|
2216
|
+
save(proposal, sessionId) {
|
|
2217
|
+
cleanup();
|
|
2218
|
+
const id = generateProposalId();
|
|
2219
|
+
const now = Date.now();
|
|
2220
|
+
if (sessionId && !proposal.sessionId) proposal.sessionId = sessionId;
|
|
2221
|
+
store.set(id, {
|
|
2222
|
+
id,
|
|
2223
|
+
proposal,
|
|
2224
|
+
timestamp: now,
|
|
2225
|
+
expiresAt: now + TTL_MS
|
|
2226
|
+
});
|
|
2227
|
+
return id;
|
|
2228
|
+
},
|
|
2229
|
+
get(id) {
|
|
2230
|
+
cleanup();
|
|
2231
|
+
return store.get(id)?.proposal;
|
|
2232
|
+
},
|
|
2233
|
+
delete(id) {
|
|
2234
|
+
return store.delete(id);
|
|
2235
|
+
},
|
|
2236
|
+
getLatest(afterTimestamp, sessionId) {
|
|
2237
|
+
cleanup();
|
|
2238
|
+
let best = null;
|
|
2239
|
+
for (const entry of store.values()) if (entry.timestamp > afterTimestamp && matchSession(entry, sessionId)) {
|
|
2240
|
+
if (!best || entry.timestamp >= best.timestamp) best = entry;
|
|
2241
|
+
}
|
|
2242
|
+
return best ? {
|
|
2243
|
+
id: best.id,
|
|
2244
|
+
proposal: best.proposal,
|
|
2245
|
+
timestamp: best.timestamp
|
|
2246
|
+
} : null;
|
|
2247
|
+
},
|
|
2248
|
+
getLatestConfirmed(afterTimestamp, sessionId) {
|
|
2249
|
+
cleanup();
|
|
2250
|
+
let best = null;
|
|
2251
|
+
for (const entry of store.values()) if (entry.proposal.confirmed === true && entry.timestamp > afterTimestamp && matchSession(entry, sessionId)) {
|
|
2252
|
+
if (!best || entry.timestamp >= best.timestamp) best = entry;
|
|
2253
|
+
}
|
|
2254
|
+
return best ? {
|
|
2255
|
+
id: best.id,
|
|
2256
|
+
proposal: best.proposal,
|
|
2257
|
+
timestamp: best.timestamp
|
|
2258
|
+
} : null;
|
|
2259
|
+
},
|
|
2260
|
+
confirmLatest(sessionId) {
|
|
2261
|
+
cleanup();
|
|
2262
|
+
let best = null;
|
|
2263
|
+
for (const entry of store.values()) if (matchSession(entry, sessionId)) {
|
|
2264
|
+
if (!best || entry.timestamp >= best.timestamp) best = entry;
|
|
2265
|
+
}
|
|
2266
|
+
if (!best) return null;
|
|
2267
|
+
best.proposal.confirmed = true;
|
|
2268
|
+
best.timestamp = Date.now();
|
|
2269
|
+
best.expiresAt = best.timestamp + TTL_MS;
|
|
2270
|
+
return {
|
|
2271
|
+
id: best.id,
|
|
2272
|
+
proposal: best.proposal,
|
|
2273
|
+
timestamp: best.timestamp
|
|
2274
|
+
};
|
|
2275
|
+
}
|
|
2276
|
+
};
|
|
2277
|
+
}
|
|
2278
|
+
function renderExpertProposalMarkdown(id, expert) {
|
|
2279
|
+
const divisionName = ZH_DIVISION[expert.division] ?? expert.division;
|
|
2280
|
+
return [
|
|
2281
|
+
`### 🧩 专家草案预览:${expert.emoji} ${expert.name}`,
|
|
2282
|
+
`* **所属分类**:${divisionName}`,
|
|
2283
|
+
`* **一句话简介**:${expert.description}`,
|
|
2284
|
+
"",
|
|
2285
|
+
"<details>",
|
|
2286
|
+
"<summary>查看完整系统提示词(点击展开)</summary>",
|
|
2287
|
+
"",
|
|
2288
|
+
"```markdown",
|
|
2289
|
+
expert.prompt,
|
|
2290
|
+
"```",
|
|
2291
|
+
"</details>",
|
|
2292
|
+
"",
|
|
2293
|
+
`👉 **[点击直接在弹窗中核对并保存草案](#dsh-agency:apply-draft?id=${id})**`,
|
|
2294
|
+
"",
|
|
2295
|
+
"> 💬 **这是专家草案预览**。你可以仔细阅读核对:如果需要修改(如调整名字、增删提示词规则),请直接在对话中告诉我;如果你觉得满意,请对我说「**确认**」,我将弹出确认卡片并为您唤起全量填好的编辑抽屉!"
|
|
2296
|
+
].join("\n");
|
|
2297
|
+
}
|
|
2298
|
+
function renderTeamProposalMarkdown(id, team, reasons = {}, expertMap = {}) {
|
|
2299
|
+
const tagsStr = team.tags.length > 0 ? ` [${team.tags.join(" / ")}]` : "";
|
|
2300
|
+
const membersList = team.members.map((m) => {
|
|
2301
|
+
const info = expertMap[m.expertSlug];
|
|
2302
|
+
const name = typeof info === "object" ? info.name : typeof info === "string" ? info : m.expertSlug;
|
|
2303
|
+
const emoji = typeof info === "object" && info.emoji ? `${info.emoji} ` : "";
|
|
2304
|
+
const reason = reasons[m.expertSlug] ? `(*入选理由*:${reasons[m.expertSlug]})` : "";
|
|
2305
|
+
return `* ${emoji}**${name}**(\`${m.expertSlug}\`):${m.duty}${reason}\n *分工*:${m.instructions}`;
|
|
2306
|
+
}).join("\n");
|
|
2307
|
+
return [
|
|
2308
|
+
`### 👥 专家团队草案预览:${team.name}${tagsStr}`,
|
|
2309
|
+
`* **定位简介**:${team.description}`,
|
|
2310
|
+
`* **团队目标**:${team.goal}`,
|
|
2311
|
+
`* **交付要求**:${team.deliveryRequirements}`,
|
|
2312
|
+
...team.constraints ? [`* **通用约束**:${team.constraints}`] : [],
|
|
2313
|
+
"",
|
|
2314
|
+
"**团队成员阵容**:",
|
|
2315
|
+
membersList,
|
|
2316
|
+
"",
|
|
2317
|
+
`👉 **[点击直接在弹窗中核对并保存草案](#dsh-agency:apply-draft?id=${id})**`,
|
|
2318
|
+
"",
|
|
2319
|
+
"> 💬 **这是专家团队草案预览**。你可以仔细阅读核对成员分工与目标:如果需要修改(如增减成员、调整分工),请直接在对话中告诉我;如果你觉得满意,请对我说「**确认**」,我将弹出确认卡片并为您唤起全量填好的编辑弹窗!"
|
|
2320
|
+
].join("\n");
|
|
2321
|
+
}
|
|
2322
|
+
//#endregion
|
|
2323
|
+
//#region src/creation-contract.ts
|
|
2324
|
+
/**
|
|
2325
|
+
* 校验模型生成的专家草案并规范化。
|
|
2326
|
+
* 剥离任何尝试伪造的 slug,返回纯净的新建草案。
|
|
2327
|
+
*/
|
|
2328
|
+
function validateExpertProposal(input) {
|
|
2329
|
+
if (typeof input !== "object" || input === null) return {
|
|
2330
|
+
ok: false,
|
|
2331
|
+
error: "专家草案必须是对象结构。"
|
|
2332
|
+
};
|
|
2333
|
+
const raw = { ...input };
|
|
2334
|
+
delete raw.slug;
|
|
2335
|
+
if (typeof raw.division === "string" && !Object.hasOwn(ZH_DIVISION, raw.division)) return {
|
|
2336
|
+
ok: false,
|
|
2337
|
+
error: `专家分类「${raw.division}」不存在。`
|
|
2338
|
+
};
|
|
2339
|
+
const parsed = customExpertInputSchema.safeParse(raw);
|
|
2340
|
+
if (!parsed.success) {
|
|
2341
|
+
const issue = parsed.error.issues[0];
|
|
2342
|
+
return {
|
|
2343
|
+
ok: false,
|
|
2344
|
+
error: `专家草案字段「${issue?.path.join(".") ?? ""}」不合法: ${issue?.message ?? "校验未通过"}`
|
|
2345
|
+
};
|
|
2346
|
+
}
|
|
2347
|
+
return {
|
|
2348
|
+
ok: true,
|
|
2349
|
+
value: parsed.data
|
|
2350
|
+
};
|
|
2351
|
+
}
|
|
2352
|
+
function matchExpertSlug(query, candidates) {
|
|
2353
|
+
const q = query.trim().toLowerCase();
|
|
2354
|
+
if (!q) return void 0;
|
|
2355
|
+
const exactSlug = candidates.find((c) => c.slug.toLowerCase() === q);
|
|
2356
|
+
if (exactSlug) return exactSlug.slug;
|
|
2357
|
+
const exactZh = candidates.find((c) => c.name && c.name.trim() === query.trim());
|
|
2358
|
+
if (exactZh) return exactZh.slug;
|
|
2359
|
+
const exactEn = candidates.find((c) => c.nameEn && c.nameEn.trim().toLowerCase() === q);
|
|
2360
|
+
if (exactEn) return exactEn.slug;
|
|
2361
|
+
const suffixMatch = candidates.find((c) => c.slug.toLowerCase().endsWith(`-${q}`) || c.slug.toLowerCase().endsWith(`_${q}`));
|
|
2362
|
+
if (suffixMatch) return suffixMatch.slug;
|
|
2363
|
+
const zhContains = candidates.find((c) => c.name && (c.name.includes(query.trim()) || query.trim().includes(c.name)));
|
|
2364
|
+
if (zhContains) return zhContains.slug;
|
|
2365
|
+
}
|
|
2366
|
+
/**
|
|
2367
|
+
* 校验模型生成的专家团草案。
|
|
2368
|
+
* 剥离任何尝试伪造的 id 和 builtin,提取成员入选理由,并校验候选专家合法性。
|
|
2369
|
+
*/
|
|
2370
|
+
function validateTeamProposal(input, availableExperts) {
|
|
2371
|
+
if (typeof input !== "object" || input === null) return {
|
|
2372
|
+
ok: false,
|
|
2373
|
+
error: "专家团草案必须是对象结构。"
|
|
2374
|
+
};
|
|
2375
|
+
const raw = { ...input };
|
|
2376
|
+
delete raw.id;
|
|
2377
|
+
delete raw.builtin;
|
|
2378
|
+
const candidates = Array.isArray(availableExperts) ? availableExperts : availableExperts instanceof Set ? [...availableExperts].map((slug) => ({ slug })) : [];
|
|
2379
|
+
const memberReasons = {};
|
|
2380
|
+
if (Array.isArray(raw.members)) raw.members = raw.members.map((item) => {
|
|
2381
|
+
if (typeof item === "object" && item !== null) {
|
|
2382
|
+
const m = { ...item };
|
|
2383
|
+
const rawSlug = typeof m.expertSlug === "string" ? m.expertSlug.trim() : "";
|
|
2384
|
+
const effectiveSlug = (candidates.length > 0 ? matchExpertSlug(rawSlug, candidates) : void 0) ?? rawSlug;
|
|
2385
|
+
if (typeof m.reason === "string") memberReasons[effectiveSlug] = m.reason;
|
|
2386
|
+
delete m.reason;
|
|
2387
|
+
return {
|
|
2388
|
+
...m,
|
|
2389
|
+
expertSlug: effectiveSlug
|
|
2390
|
+
};
|
|
2391
|
+
}
|
|
2392
|
+
return item;
|
|
2393
|
+
});
|
|
2394
|
+
const parsed = teamInputSchema.safeParse(raw);
|
|
2395
|
+
if (!parsed.success) {
|
|
2396
|
+
const issue = parsed.error.issues[0];
|
|
2397
|
+
return {
|
|
2398
|
+
ok: false,
|
|
2399
|
+
error: `专家团草案字段「${issue?.path.join(".") ?? ""}」不合法: ${issue?.message ?? "校验未通过"}`
|
|
2400
|
+
};
|
|
2401
|
+
}
|
|
2402
|
+
const team = parsed.data;
|
|
2403
|
+
if (candidates.length > 0) {
|
|
2404
|
+
const validSlugs = new Set(candidates.map((c) => c.slug));
|
|
2405
|
+
for (const member of team.members) if (!validSlugs.has(member.expertSlug)) return {
|
|
2406
|
+
ok: false,
|
|
2407
|
+
error: `专家成员「${member.expertSlug}」不存在于当前专家库中。`
|
|
2408
|
+
};
|
|
2409
|
+
}
|
|
2410
|
+
return {
|
|
2411
|
+
ok: true,
|
|
2412
|
+
value: team,
|
|
2413
|
+
memberReasons
|
|
2414
|
+
};
|
|
2415
|
+
}
|
|
2416
|
+
//#endregion
|
|
2168
2417
|
//#region src/team-engine.ts
|
|
2169
2418
|
const methods = [
|
|
2170
2419
|
"tryMembership",
|
|
@@ -3289,6 +3538,8 @@ function apply(ctx, config) {
|
|
|
3289
3538
|
}, activeLocale);
|
|
3290
3539
|
ctx.reflect.provide(AGENCY_TEAM_SERVICE, teamLibrary);
|
|
3291
3540
|
ctx.reflect.provide("agencyAgentsTeamEngine", () => resolveTeamEngine(ctx, void 0, maxDepth).status);
|
|
3541
|
+
const proposalRegistry = createProposalRegistry();
|
|
3542
|
+
ctx.reflect.provide("agencyProposalRegistry", proposalRegistry);
|
|
3292
3543
|
ctx.on?.("tools/pre-execute", async (exec, next) => {
|
|
3293
3544
|
if (blocksNativeDelegation(ctx.get("agentTeams"), exec.agent, exec.name)) return {
|
|
3294
3545
|
kind: "deny",
|
|
@@ -3918,6 +4169,337 @@ function apply(ctx, config) {
|
|
|
3918
4169
|
}) };
|
|
3919
4170
|
}
|
|
3920
4171
|
}), activeLocale, [TEAM_TASK_MAX_CHARS]));
|
|
4172
|
+
ctx.tools.register(defineTool({
|
|
4173
|
+
name: "propose_custom_expert",
|
|
4174
|
+
description: "Design or update a custom expert draft. ALWAYS call this tool during ideation and iterative revisions in chat. This tool generates a full preview in chat and stores the draft WITHOUT opening any UI modal.",
|
|
4175
|
+
parameters: {
|
|
4176
|
+
name: {
|
|
4177
|
+
type: "string",
|
|
4178
|
+
required: true,
|
|
4179
|
+
description: "Expert name (1-40 chars), e.g. \"Rust 并发安全专家\"."
|
|
4180
|
+
},
|
|
4181
|
+
division: {
|
|
4182
|
+
type: "string",
|
|
4183
|
+
required: true,
|
|
4184
|
+
description: "Division category. Must be one of the valid divisions: " + Object.keys(ZH_DIVISION).join(", ") + "."
|
|
4185
|
+
},
|
|
4186
|
+
description: {
|
|
4187
|
+
type: "string",
|
|
4188
|
+
required: true,
|
|
4189
|
+
description: "Short summary (1-160 chars) of expertise and scope."
|
|
4190
|
+
},
|
|
4191
|
+
prompt: {
|
|
4192
|
+
type: "string",
|
|
4193
|
+
required: true,
|
|
4194
|
+
description: "Complete system prompt (at least 100 chars)."
|
|
4195
|
+
},
|
|
4196
|
+
emoji: {
|
|
4197
|
+
type: "string",
|
|
4198
|
+
description: "Single emoji representing the expert (default: 🧩)."
|
|
4199
|
+
}
|
|
4200
|
+
},
|
|
4201
|
+
output: {
|
|
4202
|
+
schema: {
|
|
4203
|
+
type: "object",
|
|
4204
|
+
additionalProperties: false,
|
|
4205
|
+
properties: {
|
|
4206
|
+
proposalId: {
|
|
4207
|
+
type: "string",
|
|
4208
|
+
required: true
|
|
4209
|
+
},
|
|
4210
|
+
actionLink: {
|
|
4211
|
+
type: "string",
|
|
4212
|
+
required: true
|
|
4213
|
+
},
|
|
4214
|
+
markdown: {
|
|
4215
|
+
type: "string",
|
|
4216
|
+
required: true
|
|
4217
|
+
}
|
|
4218
|
+
}
|
|
4219
|
+
},
|
|
4220
|
+
render: (_args, value) => [{
|
|
4221
|
+
type: "text",
|
|
4222
|
+
text: value.markdown
|
|
4223
|
+
}]
|
|
4224
|
+
},
|
|
4225
|
+
async execute(args, exec) {
|
|
4226
|
+
const sessionId = exec?.agent?.session?.id ?? exec?.agent?.session?.header?.id;
|
|
4227
|
+
const validation = validateExpertProposal({
|
|
4228
|
+
name: String(args.name ?? "").trim(),
|
|
4229
|
+
description: String(args.description ?? "").trim(),
|
|
4230
|
+
division: String(args.division ?? "").trim(),
|
|
4231
|
+
prompt: String(args.prompt ?? "").trim(),
|
|
4232
|
+
emoji: args.emoji ? String(args.emoji).trim() : "🧩",
|
|
4233
|
+
avatar: 0
|
|
4234
|
+
});
|
|
4235
|
+
if (!validation.ok) throw new Error(`专家草案校验失败:${validation.error}`);
|
|
4236
|
+
const proposalId = proposalRegistry.save({
|
|
4237
|
+
kind: "expert",
|
|
4238
|
+
data: validation.value,
|
|
4239
|
+
confirmed: false
|
|
4240
|
+
}, sessionId);
|
|
4241
|
+
return {
|
|
4242
|
+
proposalId,
|
|
4243
|
+
actionLink: `#dsh-agency:apply-draft?id=${proposalId}`,
|
|
4244
|
+
markdown: renderExpertProposalMarkdown(proposalId, validation.value)
|
|
4245
|
+
};
|
|
4246
|
+
}
|
|
4247
|
+
}));
|
|
4248
|
+
ctx.tools.register(defineTool({
|
|
4249
|
+
name: "open_custom_expert_editor",
|
|
4250
|
+
description: "Open the custom expert editor modal. Call this tool ONLY after the user has reviewed the draft preview in chat AND explicitly confirms (e.g. says \"确认\", \"就按这个\", \"打开弹窗\", \"满意\").",
|
|
4251
|
+
parameters: {},
|
|
4252
|
+
output: {
|
|
4253
|
+
schema: {
|
|
4254
|
+
type: "object",
|
|
4255
|
+
additionalProperties: false,
|
|
4256
|
+
properties: {
|
|
4257
|
+
success: {
|
|
4258
|
+
type: "boolean",
|
|
4259
|
+
required: true
|
|
4260
|
+
},
|
|
4261
|
+
message: {
|
|
4262
|
+
type: "string",
|
|
4263
|
+
required: true
|
|
4264
|
+
}
|
|
4265
|
+
}
|
|
4266
|
+
},
|
|
4267
|
+
render: (_args, value) => [{
|
|
4268
|
+
type: "text",
|
|
4269
|
+
text: value.message
|
|
4270
|
+
}]
|
|
4271
|
+
},
|
|
4272
|
+
async execute(_args, exec) {
|
|
4273
|
+
const userQuestions = ctx.get?.("userQuestions", false) ?? ctx.userQuestions;
|
|
4274
|
+
const sessionId = exec?.agent?.session?.id ?? exec?.agent?.session?.header?.id;
|
|
4275
|
+
const latest = proposalRegistry.getLatest(0, sessionId);
|
|
4276
|
+
if (!latest || latest.proposal.kind !== "expert") return {
|
|
4277
|
+
success: false,
|
|
4278
|
+
message: "当前没有待保存的专家草案,请先告诉我您想创建什么样的专家。"
|
|
4279
|
+
};
|
|
4280
|
+
const expert = latest.proposal.data;
|
|
4281
|
+
if (userQuestions && typeof userQuestions.ask === "function" && exec?.agent) try {
|
|
4282
|
+
if (((await userQuestions.ask({
|
|
4283
|
+
agent: exec.agent,
|
|
4284
|
+
signal: exec.signal,
|
|
4285
|
+
questions: [{
|
|
4286
|
+
id: "confirm-open-expert-dialog",
|
|
4287
|
+
header: "🧩 专家草案确认",
|
|
4288
|
+
question: `您已审阅专家「${expert.emoji} ${expert.name}」的草案。是否现在打开编辑窗口进行最终核对并保存?`,
|
|
4289
|
+
options: [{
|
|
4290
|
+
label: "✅ 立即打开编辑窗口反显写入",
|
|
4291
|
+
description: "在右侧弹窗中全自动回填所有字段,供你审查并保存"
|
|
4292
|
+
}, {
|
|
4293
|
+
label: "✏️ 留在当前对话继续修改调整",
|
|
4294
|
+
description: "不打开窗口,继续在对话中补充或修改要求"
|
|
4295
|
+
}]
|
|
4296
|
+
}]
|
|
4297
|
+
}))?.answers?.find((a) => a.id === "confirm-open-expert-dialog"))?.selected?.[0] !== "✅ 立即打开编辑窗口反显写入") return {
|
|
4298
|
+
success: false,
|
|
4299
|
+
message: `已收到您的反馈:继续在对话中调整。当前不会打开弹窗,请继续告诉我修改要求。`
|
|
4300
|
+
};
|
|
4301
|
+
} catch {
|
|
4302
|
+
return {
|
|
4303
|
+
success: false,
|
|
4304
|
+
message: "已取消打开编辑窗口,您可以继续在对话中调整草案。"
|
|
4305
|
+
};
|
|
4306
|
+
}
|
|
4307
|
+
if (!proposalRegistry.confirmLatest(sessionId)) return {
|
|
4308
|
+
success: false,
|
|
4309
|
+
message: "当前没有待保存的专家草案,请先告诉我您想创建什么样的专家。"
|
|
4310
|
+
};
|
|
4311
|
+
return {
|
|
4312
|
+
success: true,
|
|
4313
|
+
message: `✅ 已为您打开专家「${expert.name}」的编辑窗口,所有字段已全自动回填,请在右侧抽屉中核对后点击「保存并启用」。`
|
|
4314
|
+
};
|
|
4315
|
+
}
|
|
4316
|
+
}));
|
|
4317
|
+
ctx.tools.register(defineTool({
|
|
4318
|
+
name: "propose_expert_team",
|
|
4319
|
+
description: "Assemble or update an expert team draft. ALWAYS call this tool during ideation and iterative revisions in chat. This tool generates a full preview in chat and stores the draft WITHOUT opening any UI modal.",
|
|
4320
|
+
parameters: {
|
|
4321
|
+
name: {
|
|
4322
|
+
type: "string",
|
|
4323
|
+
required: true,
|
|
4324
|
+
description: "Team name (1-40 chars)."
|
|
4325
|
+
},
|
|
4326
|
+
description: {
|
|
4327
|
+
type: "string",
|
|
4328
|
+
required: true,
|
|
4329
|
+
description: "Team description (1-160 chars)."
|
|
4330
|
+
},
|
|
4331
|
+
tags: {
|
|
4332
|
+
type: "array",
|
|
4333
|
+
description: "Tags (max 3).",
|
|
4334
|
+
items: { type: "string" }
|
|
4335
|
+
},
|
|
4336
|
+
goal: {
|
|
4337
|
+
type: "string",
|
|
4338
|
+
required: true,
|
|
4339
|
+
description: "Core mission goal."
|
|
4340
|
+
},
|
|
4341
|
+
deliveryRequirements: {
|
|
4342
|
+
type: "string",
|
|
4343
|
+
required: true,
|
|
4344
|
+
description: "Delivery and output criteria."
|
|
4345
|
+
},
|
|
4346
|
+
constraints: {
|
|
4347
|
+
type: "string",
|
|
4348
|
+
description: "General constraints."
|
|
4349
|
+
},
|
|
4350
|
+
examples: {
|
|
4351
|
+
type: "array",
|
|
4352
|
+
required: true,
|
|
4353
|
+
items: { type: "string" },
|
|
4354
|
+
description: "1-3 trigger examples."
|
|
4355
|
+
},
|
|
4356
|
+
coordinatorTemplateId: {
|
|
4357
|
+
type: "string",
|
|
4358
|
+
description: "Coordinator template: \"general\" | \"product\" | \"technical\" | \"content\" | \"data\" | \"research\"."
|
|
4359
|
+
},
|
|
4360
|
+
members: {
|
|
4361
|
+
type: "array",
|
|
4362
|
+
required: true,
|
|
4363
|
+
description: "Team members (2-8 experts). Each item is an object with { expertSlug, duty, instructions, reason }.",
|
|
4364
|
+
items: { type: "json" }
|
|
4365
|
+
}
|
|
4366
|
+
},
|
|
4367
|
+
output: {
|
|
4368
|
+
schema: {
|
|
4369
|
+
type: "object",
|
|
4370
|
+
additionalProperties: false,
|
|
4371
|
+
properties: {
|
|
4372
|
+
proposalId: {
|
|
4373
|
+
type: "string",
|
|
4374
|
+
required: true
|
|
4375
|
+
},
|
|
4376
|
+
actionLink: {
|
|
4377
|
+
type: "string",
|
|
4378
|
+
required: true
|
|
4379
|
+
},
|
|
4380
|
+
markdown: {
|
|
4381
|
+
type: "string",
|
|
4382
|
+
required: true
|
|
4383
|
+
}
|
|
4384
|
+
}
|
|
4385
|
+
},
|
|
4386
|
+
render: (_args, value) => [{
|
|
4387
|
+
type: "text",
|
|
4388
|
+
text: value.markdown
|
|
4389
|
+
}]
|
|
4390
|
+
},
|
|
4391
|
+
async execute(args, exec) {
|
|
4392
|
+
const sessionId = exec?.agent?.session?.id ?? exec?.agent?.session?.header?.id;
|
|
4393
|
+
const catalog = await library.catalog();
|
|
4394
|
+
new Set(catalog.experts.map((e) => e.slug));
|
|
4395
|
+
const members = (Array.isArray(args.members) ? args.members : []).map((m) => ({
|
|
4396
|
+
expertSlug: String(m?.expertSlug ?? "").trim(),
|
|
4397
|
+
duty: String(m?.duty ?? "").trim(),
|
|
4398
|
+
instructions: String(m?.instructions ?? "").trim(),
|
|
4399
|
+
...m?.reason ? { reason: String(m.reason).trim() } : {}
|
|
4400
|
+
}));
|
|
4401
|
+
const validation = validateTeamProposal({
|
|
4402
|
+
name: String(args.name ?? "").trim(),
|
|
4403
|
+
description: String(args.description ?? "").trim(),
|
|
4404
|
+
tags: Array.isArray(args.tags) ? args.tags.map(String).filter(Boolean).slice(0, 3) : [],
|
|
4405
|
+
goal: String(args.goal ?? "").trim(),
|
|
4406
|
+
constraints: args.constraints ? String(args.constraints).trim() : void 0,
|
|
4407
|
+
deliveryRequirements: String(args.deliveryRequirements ?? "").trim(),
|
|
4408
|
+
members,
|
|
4409
|
+
examples: Array.isArray(args.examples) ? args.examples.map(String).filter(Boolean).slice(0, 3) : ["任务示例"],
|
|
4410
|
+
coordinatorMode: "template",
|
|
4411
|
+
coordinatorTemplateId: args.coordinatorTemplateId ?? "general",
|
|
4412
|
+
coordinatorTemplateVersion: 1,
|
|
4413
|
+
coordinatorPrompt: ""
|
|
4414
|
+
}, catalog.experts);
|
|
4415
|
+
if (!validation.ok) throw new Error(`专家团队方案校验失败:${validation.error}`);
|
|
4416
|
+
const expertMap = {};
|
|
4417
|
+
for (const e of catalog.experts) expertMap[e.slug] = {
|
|
4418
|
+
name: localizedExpertName(e, activeLocale()),
|
|
4419
|
+
emoji: e.emoji
|
|
4420
|
+
};
|
|
4421
|
+
const proposalId = proposalRegistry.save({
|
|
4422
|
+
kind: "team",
|
|
4423
|
+
data: validation.value,
|
|
4424
|
+
memberReasons: validation.memberReasons,
|
|
4425
|
+
confirmed: false
|
|
4426
|
+
}, sessionId);
|
|
4427
|
+
return {
|
|
4428
|
+
proposalId,
|
|
4429
|
+
actionLink: `#dsh-agency:apply-draft?id=${proposalId}`,
|
|
4430
|
+
markdown: renderTeamProposalMarkdown(proposalId, validation.value, validation.memberReasons, expertMap)
|
|
4431
|
+
};
|
|
4432
|
+
}
|
|
4433
|
+
}));
|
|
4434
|
+
ctx.tools.register(defineTool({
|
|
4435
|
+
name: "open_expert_team_editor",
|
|
4436
|
+
description: "Open the expert team editor modal. Call this tool ONLY after the user has reviewed the team draft preview in chat AND explicitly confirms (e.g. says \"确认\", \"就按这个\", \"打开弹窗\", \"满意\").",
|
|
4437
|
+
parameters: {},
|
|
4438
|
+
output: {
|
|
4439
|
+
schema: {
|
|
4440
|
+
type: "object",
|
|
4441
|
+
additionalProperties: false,
|
|
4442
|
+
properties: {
|
|
4443
|
+
success: {
|
|
4444
|
+
type: "boolean",
|
|
4445
|
+
required: true
|
|
4446
|
+
},
|
|
4447
|
+
message: {
|
|
4448
|
+
type: "string",
|
|
4449
|
+
required: true
|
|
4450
|
+
}
|
|
4451
|
+
}
|
|
4452
|
+
},
|
|
4453
|
+
render: (_args, value) => [{
|
|
4454
|
+
type: "text",
|
|
4455
|
+
text: value.message
|
|
4456
|
+
}]
|
|
4457
|
+
},
|
|
4458
|
+
async execute(_args, exec) {
|
|
4459
|
+
const userQuestions = ctx.get?.("userQuestions", false) ?? ctx.userQuestions;
|
|
4460
|
+
const sessionId = exec?.agent?.session?.id ?? exec?.agent?.session?.header?.id;
|
|
4461
|
+
const latest = proposalRegistry.getLatest(0, sessionId);
|
|
4462
|
+
if (!latest || latest.proposal.kind !== "team") return {
|
|
4463
|
+
success: false,
|
|
4464
|
+
message: "当前没有待保存的专家团队草案,请先告诉我您想组建什么样的专家团队。"
|
|
4465
|
+
};
|
|
4466
|
+
const team = latest.proposal.data;
|
|
4467
|
+
if (userQuestions && typeof userQuestions.ask === "function" && exec?.agent) try {
|
|
4468
|
+
if (((await userQuestions.ask({
|
|
4469
|
+
agent: exec.agent,
|
|
4470
|
+
signal: exec.signal,
|
|
4471
|
+
questions: [{
|
|
4472
|
+
id: "confirm-open-team-dialog",
|
|
4473
|
+
header: "👥 专家团队配置确认",
|
|
4474
|
+
question: `您已审阅专家团队「${team.name}」(共 ${team.members.length} 位专家)的配置方案。是否现在打开编辑窗口进行最终核对并保存?`,
|
|
4475
|
+
options: [{
|
|
4476
|
+
label: "✅ 立即打开编辑窗口反显写入",
|
|
4477
|
+
description: "在弹窗中全自动回填团队配置与成员阵容,供你审查并保存"
|
|
4478
|
+
}, {
|
|
4479
|
+
label: "✏️ 留在当前对话继续修改调整",
|
|
4480
|
+
description: "不打开窗口,继续在对话中微调成员分工或目标"
|
|
4481
|
+
}]
|
|
4482
|
+
}]
|
|
4483
|
+
}))?.answers?.find((a) => a.id === "confirm-open-team-dialog"))?.selected?.[0] !== "✅ 立即打开编辑窗口反显写入") return {
|
|
4484
|
+
success: false,
|
|
4485
|
+
message: `已收到您的反馈:继续在对话中调整。当前不会打开弹窗,请继续告诉我修改要求。`
|
|
4486
|
+
};
|
|
4487
|
+
} catch {
|
|
4488
|
+
return {
|
|
4489
|
+
success: false,
|
|
4490
|
+
message: "已取消打开编辑窗口,您可以继续在对话中调整配置。"
|
|
4491
|
+
};
|
|
4492
|
+
}
|
|
4493
|
+
if (!proposalRegistry.confirmLatest(sessionId)) return {
|
|
4494
|
+
success: false,
|
|
4495
|
+
message: "当前没有待保存的专家团队草案,请先告诉我您想组建什么样的专家团队。"
|
|
4496
|
+
};
|
|
4497
|
+
return {
|
|
4498
|
+
success: true,
|
|
4499
|
+
message: `✅ 已为您打开专家团队「${team.name}」的编辑窗口,成员阵容与分工已全自动回填,请在弹窗中核对后点击「保存并启用」。`
|
|
4500
|
+
};
|
|
4501
|
+
}
|
|
4502
|
+
}));
|
|
3921
4503
|
ctx.systemPrompt.section({
|
|
3922
4504
|
name: "agency:teams",
|
|
3923
4505
|
order: 118,
|
|
@@ -3930,9 +4512,9 @@ function apply(ctx, config) {
|
|
|
3930
4512
|
order: 117,
|
|
3931
4513
|
text: (context) => {
|
|
3932
4514
|
if (context.agent?.session?.header?.parentSession !== void 0) return "";
|
|
3933
|
-
return "## Agency expert mode\nThe parent session has a roster of domain experts from The Agency (specialists across 22 divisions, individually enable/disable; ALL are disabled by default, and the user enables some in the Agency settings tab). A composer selection inserts one enabled expert as a native reference chip; all remaining draft text is that expert's task. When the user message already names experts, call summon_expert or summon_experts immediately. Summarize that message into the user goal, constraints, and file paths; do not pass the raw text when it is long. Do not call list_experts, read the project, or do the analysis yourself. Experts read the files and produce the analysis; the parent only synthesizes their results. Call list_experts only when the user did not name an expert. summon_experts runs at most 8 experts; partial results are returned if some fail. A disabled expert cannot be summoned. When calling either tool, pass only a short brief: the user goal, constraints, and file paths. Do not paste source, CSS, HTML, or quoted code into the tool argument; an unescaped quote makes the JSON invalid and no expert starts. Each task must stay within 2000 characters. Experts read the files themselves.";
|
|
4515
|
+
return "## Agency expert mode\nThe parent session has a roster of domain experts from The Agency (specialists across 22 divisions, individually enable/disable; ALL are disabled by default, and the user enables some in the Agency settings tab). A composer selection inserts one enabled expert as a native reference chip; all remaining draft text is that expert's task. When the user message already names experts, call summon_expert or summon_experts immediately. Summarize that message into the user goal, constraints, and file paths; do not pass the raw text when it is long. Do not call list_experts, read the project, or do the analysis yourself. Experts read the files and produce the analysis; the parent only synthesizes their results. Call list_experts only when the user did not name an expert. summon_experts runs at most 8 experts; partial results are returned if some fail. A disabled expert cannot be summoned. When calling either tool, pass only a short brief: the user goal, constraints, and file paths. Do not paste source, CSS, HTML, or quoted code into the tool argument; an unescaped quote makes the JSON invalid and no expert starts. Each task must stay within 2000 characters. Experts read the files themselves.\nWhen the user asks to create, design, or customize an expert persona (e.g. \"我想创建一个专家...\", \"创建小红书运营专家\", \"新建专家\"), call propose_custom_expert. You MUST ALWAYS present a full, polished preview in your response text (name, division, description, and detailed system prompt breakdown) so the user can read and review it first. Invite the user to suggest modifications in chat. Only when the user explicitly confirms (e.g. says \"确认\", \"就按这个\", \"打开弹窗\", \"满意\"), call open_custom_expert_editor to open the modal. Do NOT tell the user to manually copy-paste, and do NOT write markdown files to docs/. When the user asks to assemble, design, or create an expert team (e.g. \"帮我组建一个专家团队...\", \"创建专家团\"), call propose_expert_team. Always present team members using their localized names (e.g. 中文名如「产品经理」、「代码审查工程师」) alongside their slug, duties, and reasons in your chat preview. Do NOT tell the user to click non-existent links; instead, inform them that they can review the draft and say \"确认\" when satisfied. When the user explicitly confirms (e.g. says \"确认\", \"就按这个\", \"满意\", \"打开弹窗\"), call open_expert_team_editor (or open_custom_expert_editor), which will present an interactive confirmation card before popping up the full editor dialog.";
|
|
3934
4516
|
}
|
|
3935
4517
|
});
|
|
3936
4518
|
}
|
|
3937
4519
|
//#endregion
|
|
3938
|
-
export {
|
|
4520
|
+
export { settingsNamespaceCompat as A, teamText as B, unquote as C, storedProposalSchema as D, latestProposalSchema as E, expertEditSchema as F, ZH_NAME as I, AGENCY_TEAM_SERVICE as L, CUSTOM_EXPERT_SLUG as M, catalogSnapshotSchema as N, formatHost as O, customExpertInputSchema as P, teamInputSchema as R, truncate as S, nativeTeamMemberName as T, resolveCatalogRoot as _, SUMMON_EXPERTS_MAX as a, stripBom as b, createAgencyPersonaSource as c, loadCatalog as d, mapPool as f, readLocalizedExpertPrompt as g, readExpertPrompt as h, SUMMON_EXPERTS_CONCURRENCY as i, AGENCY_LIBRARY_SERVICE as j, readHostLocale as k, inject as l, parseFrontmatter as m, Config as n, SUMMON_TASK_MAX_CHARS as o, name as p, DEFAULT_DIVISIONS as r, apply as s, AGENCY_PERSONA_SERVICE as t, liveSchemaField as u, resolveExpert as v, validateSummonSpecs as w, toSummonItemResult as x, sanitize as y, teamSnapshotSchema as z };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@michengai/dsh-agency-agents",
|
|
3
3
|
"description": "DSH Agency Agents — 为 DeepSeek Harness 提供 331 名可召唤的专业智能体 · 331 summonable domain experts for DeepSeek Harness",
|
|
4
|
-
"version": "1.2.
|
|
4
|
+
"version": "1.2.15",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"packageManager": "pnpm@11.22.0",
|
|
7
7
|
"engines": {
|