jbc-dssi 1.1.15 → 1.1.16
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/package.json
CHANGED
|
@@ -123,6 +123,8 @@ export function createDeliver({
|
|
|
123
123
|
return function deliver(group, member, prompt, attachments = {}, opts = {}) {
|
|
124
124
|
const budgetMs = typeof opts.budgetMs === 'number' ? opts.budgetMs : timing.defaultBudgetMs;
|
|
125
125
|
const roundNo = opts.round?.rounds ?? 0;
|
|
126
|
+
/** 外部中止(用户点停止):由 engine 传入 round.abort.signal。 */
|
|
127
|
+
const external = opts.signal ?? null;
|
|
126
128
|
return new Promise((resolve) => {
|
|
127
129
|
let settled = false;
|
|
128
130
|
let stillRunning = false;
|
|
@@ -183,8 +185,14 @@ export function createDeliver({
|
|
|
183
185
|
settled = true;
|
|
184
186
|
if (budgetTimer) { clearTimeout(budgetTimer); budgetTimer = null; }
|
|
185
187
|
clearIdle();
|
|
188
|
+
try { external?.removeEventListener?.('abort', onExternalAbort); } catch { /* 忽略 */ }
|
|
186
189
|
resolve(result);
|
|
187
190
|
};
|
|
191
|
+
/** 用户点停止:立刻收口(不落"未回应",由 engine 统一写停止行 + round_end)。 */
|
|
192
|
+
const onExternalAbort = () => {
|
|
193
|
+
if (settled) return;
|
|
194
|
+
settle({ failed: 'stopped' });
|
|
195
|
+
};
|
|
188
196
|
/*
|
|
189
197
|
* 静默看门狗:任意帧到达就重置;静默只记日志,**绝不结算**。
|
|
190
198
|
* (长命令执行期间可能长时间没有事件,那不等于失联。)
|
|
@@ -196,6 +204,10 @@ export function createDeliver({
|
|
|
196
204
|
log?.(`[groups] ${member.name} 静默 ${timing.idleMs}ms,任务可能仍在执行(不结算、不判未回应)`);
|
|
197
205
|
}, timing.idleMs);
|
|
198
206
|
};
|
|
207
|
+
if (external) {
|
|
208
|
+
if (external.aborted) onExternalAbort();
|
|
209
|
+
else external.addEventListener?.('abort', onExternalAbort, { once: true });
|
|
210
|
+
}
|
|
199
211
|
let sessionId = null;
|
|
200
212
|
(async () => {
|
|
201
213
|
try {
|
|
@@ -40,6 +40,8 @@ export function createRoundRunner({ deliver, emitLine, emitReplyLine, now, budge
|
|
|
40
40
|
*/
|
|
41
41
|
async function runDirect(group, round, targets, members, text, attachments, onProgress) {
|
|
42
42
|
for (const member of targets) {
|
|
43
|
+
if (round.stopped) return;
|
|
44
|
+
round.currentMemberId = member.id;
|
|
43
45
|
onProgress?.({ breakpoint: `已分派给 ${member.name},等待反馈` });
|
|
44
46
|
const prompt = buildMemberPrompt({
|
|
45
47
|
group,
|
|
@@ -49,7 +51,13 @@ export function createRoundRunner({ deliver, emitLine, emitReplyLine, now, budge
|
|
|
49
51
|
task: text,
|
|
50
52
|
mode: 'user-direct',
|
|
51
53
|
});
|
|
52
|
-
const result = await deliver(group, member, prompt, attachments, {
|
|
54
|
+
const result = await deliver(group, member, prompt, attachments, {
|
|
55
|
+
budgetMs: budgetFor(text),
|
|
56
|
+
round,
|
|
57
|
+
signal: round.abort?.signal,
|
|
58
|
+
});
|
|
59
|
+
// 用户点了停止:不写"回应失败",交由 handleUserMessage 统一收尾
|
|
60
|
+
if (round.stopped) return;
|
|
53
61
|
if (result.failed) {
|
|
54
62
|
emitLine(group.id, {
|
|
55
63
|
at: now(), role: 'system', name: member.name,
|
|
@@ -75,6 +83,7 @@ export function createRoundRunner({ deliver, emitLine, emitReplyLine, now, budge
|
|
|
75
83
|
let refusals = 0;
|
|
76
84
|
|
|
77
85
|
while (true) {
|
|
86
|
+
if (round.stopped) return;
|
|
78
87
|
const prompt = buildManagerPrompt({
|
|
79
88
|
group,
|
|
80
89
|
members,
|
|
@@ -88,7 +97,12 @@ export function createRoundRunner({ deliver, emitLine, emitReplyLine, now, budge
|
|
|
88
97
|
});
|
|
89
98
|
// 用户附件只在第一轮(计划阶段)带给主管;后续复查阶段不再重复投递。
|
|
90
99
|
const managerAttachments = roundIndex === 0 && feedbacks.length === 0 ? attachments : {};
|
|
91
|
-
|
|
100
|
+
round.currentMemberId = manager.id;
|
|
101
|
+
const result = await deliver(group, manager, prompt, managerAttachments, {
|
|
102
|
+
round,
|
|
103
|
+
signal: round.abort?.signal,
|
|
104
|
+
});
|
|
105
|
+
if (round.stopped) return;
|
|
92
106
|
if (result.failed) {
|
|
93
107
|
emitLine(group.id, {
|
|
94
108
|
at: now(), role: 'system', name: manager.name,
|
|
@@ -155,6 +169,8 @@ export function createRoundRunner({ deliver, emitLine, emitReplyLine, now, budge
|
|
|
155
169
|
round.rounds = roundIndex;
|
|
156
170
|
feedbacks = [];
|
|
157
171
|
for (const target of targets) {
|
|
172
|
+
if (round.stopped) return;
|
|
173
|
+
round.currentMemberId = target.id;
|
|
158
174
|
onProgress?.({ breakpoint: `第 ${roundIndex} 轮:已分派给 ${target.name},等待反馈` });
|
|
159
175
|
const memberPrompt = buildMemberPrompt({
|
|
160
176
|
group,
|
|
@@ -167,7 +183,9 @@ export function createRoundRunner({ deliver, emitLine, emitReplyLine, now, budge
|
|
|
167
183
|
const memberResult = await deliver(group, target, memberPrompt, attachments, {
|
|
168
184
|
budgetMs: budgetFor(managerText),
|
|
169
185
|
round,
|
|
186
|
+
signal: round.abort?.signal,
|
|
170
187
|
});
|
|
188
|
+
if (round.stopped) return;
|
|
171
189
|
if (memberResult.failed) {
|
|
172
190
|
emitLine(group.id, {
|
|
173
191
|
at: now(), role: 'system', name: target.name,
|
|
@@ -153,7 +153,18 @@ export function createRoundEngine({ ctx, state, dssAgent, log, save, broadcast,
|
|
|
153
153
|
attachments: attachmentMeta,
|
|
154
154
|
});
|
|
155
155
|
|
|
156
|
-
const round = {
|
|
156
|
+
const round = {
|
|
157
|
+
groupId: group.id,
|
|
158
|
+
rounds: 0,
|
|
159
|
+
totalTurns: 0,
|
|
160
|
+
fused: false,
|
|
161
|
+
/** 用户点停止:置 true 后轮次循环立即退出(不再分发/不再写失败行)。 */
|
|
162
|
+
stopped: false,
|
|
163
|
+
/** 中止正在进行的投递(deliver 会立刻收口)。 */
|
|
164
|
+
abort: new AbortController(),
|
|
165
|
+
/** 当前正在执行的成员(停止时用它取消 DSH 会话里的 turn)。 */
|
|
166
|
+
currentMemberId: null,
|
|
167
|
+
};
|
|
157
168
|
activeRound = round;
|
|
158
169
|
try {
|
|
159
170
|
/*
|
|
@@ -170,16 +181,57 @@ export function createRoundEngine({ ctx, state, dssAgent, log, save, broadcast,
|
|
|
170
181
|
}
|
|
171
182
|
} finally {
|
|
172
183
|
if (activeRound === round) activeRound = null;
|
|
184
|
+
// 用户停止:按正常收尾流程落一条系统行(手机侧收到即进入"已结束")
|
|
185
|
+
if (round.stopped) {
|
|
186
|
+
emitLine(group.id, {
|
|
187
|
+
at: now(),
|
|
188
|
+
role: 'system',
|
|
189
|
+
name: '',
|
|
190
|
+
text: '本轮任务已被用户停止',
|
|
191
|
+
});
|
|
192
|
+
}
|
|
173
193
|
broadcast?.({
|
|
174
194
|
type: 'round_end',
|
|
175
195
|
groupId: group.id,
|
|
176
196
|
totalTurns: round.totalTurns,
|
|
177
197
|
rounds: round.rounds,
|
|
178
198
|
fused: round.fused === true,
|
|
199
|
+
stopped: round.stopped === true,
|
|
179
200
|
});
|
|
180
201
|
}
|
|
181
202
|
}
|
|
182
203
|
|
|
204
|
+
/**
|
|
205
|
+
* 停止当前群的本轮执行(2026-11-02)。
|
|
206
|
+
*
|
|
207
|
+
* 幂等:本轮已在停止中 → `{stopped:true, reason:'already'}`;
|
|
208
|
+
* 当前没有执行中的轮次 → `{stopped:false, reason:'idle'}`。
|
|
209
|
+
* 真正中止:置 stopped + abort(deliver 立刻收口)+ 取消当前成员会话的 DSH turn;
|
|
210
|
+
* 收尾统一在 handleUserMessage 的 finally 里(系统行 + round_end(stopped:true))。
|
|
211
|
+
*
|
|
212
|
+
* @param {string} groupId
|
|
213
|
+
*/
|
|
214
|
+
function stopRound(groupId) {
|
|
215
|
+
const round = activeRound;
|
|
216
|
+
if (round === null || round.groupId !== groupId) return { stopped: false, reason: 'idle' };
|
|
217
|
+
if (round.stopped) return { stopped: true, reason: 'already' };
|
|
218
|
+
round.stopped = true;
|
|
219
|
+
try {
|
|
220
|
+
round.abort?.abort();
|
|
221
|
+
} catch (err) {
|
|
222
|
+
log?.(`[groups] 停止轮次时 abort 失败(忽略):${err?.message ?? err}`);
|
|
223
|
+
}
|
|
224
|
+
// 取消当前正在跑的成员会话 turn(DSH 公开方法;失败只记日志)
|
|
225
|
+
try {
|
|
226
|
+
const memberId = round.currentMemberId;
|
|
227
|
+
const sessionId = memberId ? state.groupSessions?.[round.groupId]?.[memberId] : null;
|
|
228
|
+
if (sessionId) ctx.sessionController.cancel({ sessionId });
|
|
229
|
+
} catch (err) {
|
|
230
|
+
log?.(`[groups] 停止轮次时取消会话失败(忽略):${err?.message ?? err}`);
|
|
231
|
+
}
|
|
232
|
+
return { stopped: true, reason: 'stopped' };
|
|
233
|
+
}
|
|
234
|
+
|
|
183
235
|
/**
|
|
184
236
|
* 以调用方指定的身份落一行房间日志(自动接续等**插件侧系统消息**用)。
|
|
185
237
|
* 不触发任务;走既有 emitLine:分配单调 seq + **随既有 save() 持久化到 groups.json** + 广播
|
|
@@ -189,5 +241,5 @@ export function createRoundEngine({ ctx, state, dssAgent, log, save, broadcast,
|
|
|
189
241
|
emitLine(groupId, line);
|
|
190
242
|
}
|
|
191
243
|
|
|
192
|
-
return { handleUserMessage, roomSnapshot, ensureGroupSession, postSystemLine };
|
|
244
|
+
return { handleUserMessage, roomSnapshot, ensureGroupSession, postSystemLine, stopRound };
|
|
193
245
|
}
|
|
@@ -313,6 +313,20 @@ export function createGroupsEngine({
|
|
|
313
313
|
return { id: group.id };
|
|
314
314
|
}
|
|
315
315
|
|
|
316
|
+
/**
|
|
317
|
+
* 停止本轮执行(2026-11-02,插件侧新增指令,见 options 说明)。
|
|
318
|
+
*
|
|
319
|
+
* 幂等:空闲 → `{stopped:false, reason:'idle'}`;已在停止 → `{stopped:true, reason:'already'}`。
|
|
320
|
+
* 协议兼容:只给现有 GROUPS_CMD 增加一个 op 值 `stopRound`,无新帧类型;
|
|
321
|
+
* 老 App 不会发;老插件收到会抛"未知群命令"(手机侧按失败处理,不卡死)。
|
|
322
|
+
*/
|
|
323
|
+
async function stopRound(payload) {
|
|
324
|
+
await ensure();
|
|
325
|
+
const id = String(payload?.id ?? '');
|
|
326
|
+
if (!id) throw new Error('停止任务缺少群 id');
|
|
327
|
+
return engine.stopRound(id);
|
|
328
|
+
}
|
|
329
|
+
|
|
316
330
|
async function command(payload) {
|
|
317
331
|
await ensure();
|
|
318
332
|
const op = String(payload?.op ?? '');
|
|
@@ -324,6 +338,7 @@ export function createGroupsEngine({
|
|
|
324
338
|
case 'addMembers': return addMembers(payload);
|
|
325
339
|
case 'removeMembers': return removeMembers(payload);
|
|
326
340
|
case 'sendMessage': return userMessage(payload);
|
|
341
|
+
case 'stopRound': return stopRound(payload);
|
|
327
342
|
default: throw new Error(`未知群命令:${op}`);
|
|
328
343
|
}
|
|
329
344
|
}
|