@iamsamyiok/agents-chat 3.18.0

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.
@@ -0,0 +1,125 @@
1
+ // 演示模式 agent(仅 AGENTS_CHAT_MOCK=1 时启用,输出均为模拟结果)
2
+ // 行为由 MOCK_BEHAVIOR 环境变量控制,prompt 为 argv[2]
3
+ const stdout = process.stdout;
4
+ const behavior = process.env.MOCK_BEHAVIOR || 'echo';
5
+ const prompt = process.argv.slice(2).join(' ');
6
+ const DEMO_TAG = '(演示模式:模拟输出,未调用真实智能体。去掉 .env 中 AGENTS_CHAT_MOCK=1 并安装 OpenCode 后为真实执行)';
7
+
8
+ function output(text) {
9
+ stdout.write(text + '\n');
10
+ setTimeout(() => process.exit(0), 20);
11
+ }
12
+
13
+ function streamOutput(lines) {
14
+ let i = 0;
15
+ const tick = () => {
16
+ if (i < lines.length) {
17
+ stdout.write(lines[i] + '\n');
18
+ i++;
19
+ setTimeout(tick, 30);
20
+ } else {
21
+ process.exit(0);
22
+ }
23
+ };
24
+ tick();
25
+ }
26
+
27
+ if (behavior === 'solo-chat') {
28
+ // 单聊工作台演示:流式输出模拟回复(含模拟工具调用行,验证过程事件渲染)
29
+ streamOutput([
30
+ '[工具] read(demo/notes.md) 读取参考资料',
31
+ `[单聊] 收到:${prompt.slice(0, 120)}`,
32
+ '思考中:正在组织回答…(演示)',
33
+ `已处理完成 ${DEMO_TAG}`
34
+ ]);
35
+ } else if (behavior === 'solo-task') {
36
+ // 单聊任务执行演示:输出任务结果(作为 result 持久化)
37
+ streamOutput([
38
+ `[单聊任务] 开始处理:${prompt.slice(0, 120)}`,
39
+ `任务完成:产出模拟结果 ${DEMO_TAG}`
40
+ ]);
41
+ } else if (behavior === 'echo') {
42
+ if (prompt.includes('【委派背景】')) {
43
+ // 中途委派演示:接手方正常完成,并附一条看板更新(验证共享看板的主动写入通道)
44
+ output(`完成:已接手委派任务并解决,供后续协作者参考 ${DEMO_TAG}\n\n【看板更新】\n1. 已确认该任务由我接手,前一位智能体的参考内容已消化`);
45
+ } else if (prompt.includes('委派测试')) {
46
+ // 中途委派演示:自认职责错配,输出委派 JSON 转交研究员
47
+ output(`这个任务需要数据调研能力,我无法胜任,转交更合适的人 ${DEMO_TAG}\n\n\`\`\`json\n{"handoff":"研究员","reason":"该任务核心是数据调研,我缺少相应能力"}\n\`\`\``);
48
+ } else if (prompt.includes('【文件产出要求】')) {
49
+ // 演示「成果文件」闭环:真实写入工作目录一个文件,输出末尾报告完整绝对路径
50
+ const fs = require('fs');
51
+ const path = require('path');
52
+ const file = path.join(process.cwd(), 'demo-deliverable.md');
53
+ fs.writeFileSync(file, '# 演示成果\n\n这是演示模式下智能体写入工作目录的成果文件。\n');
54
+ output(`完成:任务已解决,成果文件已写入工作目录 ${DEMO_TAG}\n\n【产出文件】\n- ${file}`);
55
+ } else {
56
+ streamOutput([`[演示] 收到:${prompt.slice(0, 200)}`, '正在处理…', `完成 ${DEMO_TAG}`]);
57
+ }
58
+ } else if (behavior === 'worker-good') {
59
+ output(`完成:任务已解决,产出可用结果 ${DEMO_TAG}`);
60
+ } else if (behavior === 'worker-bad-then-good') {
61
+ output(`改进:已根据反馈修复缺陷,现在结果合格 ${DEMO_TAG}`);
62
+ } else if (behavior === 'lead') {
63
+ if (prompt.includes('规划')) {
64
+ output(`[PLAN] 作为主智能体,我将拆解任务并分配给工作智能体,并制定验收标准 ${DEMO_TAG}`);
65
+ } else if (prompt.includes('汇总')) {
66
+ output(`[REPORT] 汇总报告:全部工作已完成 ${DEMO_TAG}`);
67
+ } else if (prompt.includes('验收')) {
68
+ output(`[ACCEPT] 验收通过:工作成果合格 ${DEMO_TAG}`);
69
+ } else {
70
+ output(`[PLAN] 收到任务,开始规划 ${DEMO_TAG}`);
71
+ }
72
+ } else if (behavior === 'butler') {
73
+ // 管家演示:规划时输出可解析的 JSON 调度方案;验收第1轮拒绝、第2轮通过;汇总时输出最终报告
74
+ if (prompt.includes('圆桌讨论总结')) {
75
+ output(`[圆桌总结] 共识:方案整体可行;分歧:实现优先级尚未定;建议行动:先做核心功能 ${DEMO_TAG}`);
76
+ } else if (prompt.includes('主持人') && prompt.includes('CONVERGED')) {
77
+ const rm = prompt.match(/第 (\d+) 轮发言结束/);
78
+ const round = rm ? Number(rm[1]) : 1;
79
+ if (round < 2) {
80
+ output(`判定:存在信息缺口,需要继续 ${DEMO_TAG}\n\`\`\`json\n${JSON.stringify({ verdict: 'CONTINUE', question: '请重点讨论实现成本与风险' }, null, 2)}\n\`\`\``);
81
+ } else {
82
+ output(`判定:观点已充分交锋 ${DEMO_TAG}\n\`\`\`json\n{"verdict":"CONVERGED"}\n\`\`\``);
83
+ }
84
+ } else if (prompt.includes('最终正式回答') || prompt.includes('【各智能体产出】')) {
85
+ // 汇总演示:照抄上游注入的成果文件完整路径(模拟管家按清单交付)
86
+ const fm = prompt.match(/【成果文件完整路径[^\n]*】\n([\s\S]*?)(?=\n\s*\n|$)/);
87
+ if (fm) {
88
+ output(`[汇总] 已综合各子智能体的产出,任务完成。\n\n成果文件:\n${fm[1].trim()}\n\n以上为最终交付 ${DEMO_TAG}`);
89
+ } else {
90
+ output(`[汇总] 已综合各子智能体的产出,任务完成(本次无成果文件) ${DEMO_TAG}`);
91
+ }
92
+ } else if (prompt.includes('轮验收')) {
93
+ const names = [...prompt.matchAll(/^【([^\s】]+) 的任务】/gm)].map(m => m[1]).filter(Boolean);
94
+ if (prompt.includes('第 1 轮验收') && names.length > 0) {
95
+ const issues = [{ agent: names[0], requirement: '补充关键细节与依据', suggestion: '请在结论中补充数据来源与具体步骤' }];
96
+ output(`验收意见:部分成果还缺少细节,需要返工完善 ${DEMO_TAG}\n\`\`\`json\n${JSON.stringify({ verdict: 'REJECT', issues }, null, 2)}\n\`\`\``);
97
+ } else {
98
+ output(`验收意见:成果已满足用户需求,验收通过 ${DEMO_TAG}\n\`\`\`json\n{"verdict":"ACCEPT"}\n\`\`\``);
99
+ }
100
+ } else {
101
+ const names = [...prompt.matchAll(/^- ([^(::]+)[(::]/gm)].map(m => m[1].trim()).filter(Boolean);
102
+ if (names.length === 0) {
103
+ output(`我是管家,这个需求我直接回答即可 ${DEMO_TAG}`);
104
+ } else if (names.length === 1) {
105
+ const steps = [[{ agent: names[0], instruction: '完成该任务的主要部分' }]];
106
+ output(`我来安排「${names[0]}」完成这个任务 ${DEMO_TAG}\n\`\`\`json\n${JSON.stringify({ steps }, null, 2)}\n\`\`\``);
107
+ } else {
108
+ const steps = [
109
+ [{ agent: names[0], instruction: '完成第一部分:调研与资料准备' }, { agent: names[1], instruction: '并行完成第二部分:独立子任务' }],
110
+ [{ agent: names[0], instruction: '汇总前序成果,完成收尾' }]
111
+ ];
112
+ output(`我拆成两个阶段:先让「${names[0]}」「${names[1]}」并行工作,再由「${names[0]}」收尾 ${DEMO_TAG}\n\`\`\`json\n${JSON.stringify({ steps }, null, 2)}\n\`\`\``);
113
+ }
114
+ }
115
+ } else if (behavior === 'lead-always-reject') {
116
+ if (prompt.includes('汇总')) {
117
+ output(`[REPORT] 汇总报告:多轮验收后交付 ${DEMO_TAG}`);
118
+ } else if (prompt.includes('验收')) {
119
+ output(`[REJECT] 验收不通过:请改进后重做 ${DEMO_TAG}`);
120
+ } else {
121
+ output(`[PLAN] 收到任务 ${DEMO_TAG}`);
122
+ }
123
+ } else {
124
+ output(`完成:默认输出(${behavior})${DEMO_TAG}`);
125
+ }