Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

Merge remote-tracking branch 'upstream/main' into bot-group-single-speaker

zqchris5c1242c37a43
diff --cc apps/desktop/src/main/maker-ipc/chatServer.ts
index bb628c7e4d,7c98d838e6..7b1c2abb32
--- a/apps/desktop/src/main/maker-ipc/chatServer.ts
+++ b/apps/desktop/src/main/maker-ipc/chatServer.ts
@@@ -1425,11 -1416,9 +1454,11 @@@ function createChatServer(local: BotGro
if (failureCodes.size > 1000) failureCodes.delete(failureCodes.keys().next().value!);
}
pending.payload = terminal.outcome === 'error' ? { detail: botGroupRuntimeFailureDetail(terminal.failureCode ?? 'RUNTIME_ERROR') }
- : { ...(isBotGroupNoReplyText(text) && !files.length ? {} : { content: [{ type: 'text', text: text.slice(0, 16000) || '已完成' }, ...files] }), continueDiscussion: run.context?.kind !== 'member.joined' && !run.plan && !isBotGroupNoReplyText(text) };
+ : { ...(isBotGroupNoReplyText(text) && !files.length ? {} : { content: [{ type: 'text', text: text.slice(0, 16000) || '已完成' }, ...files] }),
+ // A single-speaker server never chains rounds, so there is nothing to continue.
+ ...(singleSpeaker ? {} : { continueDiscussion: run.context?.kind !== 'member.joined' && !run.plan && !isBotGroupNoReplyText(text) }) };
}
- if (!current() || running.get(run.execution.bot_id) !== run) return;
+ if (!current() || running.get(run.execution.id) !== run) return;
await updateExecution(run, pending.terminal.outcome === 'error' ? 'fail' : 'complete', pending.payload);
if (run.plan && deps.onStepSettled) {
const s = await snapshot(run.execution.conversation_id);
@@@ -2342,45 -2407,16 +2461,45 @@@
if (projectDir !== undefined) workspaces().save(i.groupId, { ...workspaces().read(i.groupId) ?? { plans: {} }, projectDir });
changed(i.groupId); return { ok: true as const };
}),
- stopRound: roomId => safe(async () => {
+ // Stop stops what is yours: your requests and arrangements, and your teammates' work for
+ // others. An owner or admin may stop everything (`all`). Work you may not stop is left running.
+ stopRound: (roomId, scopeInput) => safe(async () => {
const room = await groupRoom(id.parse(roomId));
await replacePlanIntent(room);
+ // Older servers keep the whole-round stop; the narrower scope belongs to single-speaker groups (§4.0).
+ if (!singleSpeaker) {
+ const plans = await api<ServerPlan[]>(`/conversations/${room}/plans`);
+ for (const plan of plans.filter(p => ['proposed','running','waiting'].includes(p.status))) await actPlan({ groupId: room, planId: plan.id }, 'stop');
+ const executions = await api<Execution[]>(`/conversations/${room}/executions`);
+ for (const e of executions.filter(e => ['queued', 'running', 'needs_input'].includes(e.status) && !e.plan_id)) {
+ await api(`/conversations/${room}/executions/${e.id}/control`, 'POST', { operationId: randomUUID(), action: 'stop' });
- const run = running.get(e.bot_id);
- if (run?.execution.id === e.id) { running.delete(e.bot_id); if (run.sessionId) await deps.abortLane(run.sessionId); }
++ const run = running.get(e.id);
++ if (run) { forgetRun(run); if (run.sessionId) await deps.abortLane(run.sessionId); }
+ }
+ changed(room); return { ok: true as const };
+ }
+ const s = await recentSnapshot(room);
+ // Owners and admins may be the account's own teammate; that member acts for everyone's work.
+ const manager = managementActor(s);
+ const everything = scopeInput === 'all' && !!manager;
+ const asManager = manager === selfId ? undefined : manager;
+ const ownBot = (botId: string) => !!localBot(botId) || s.members.some(m => m.id === botId && m.ownerActorId === selfId);
+ const refused = (error: unknown) => error instanceof ChatResponseError && [403, 404, 409].includes(error.status);
const plans = await api<ServerPlan[]>(`/conversations/${room}/plans`);
- for (const plan of plans.filter(p => ['proposed','running','waiting'].includes(p.status))) await actPlan({ groupId: room, planId: plan.id }, 'stop');
+ const stoppedPlans = new Set<string>();
+ for (const plan of plans.filter(p => ['proposed','running','waiting'].includes(p.status) && (everything || p.creator_id === selfId))) {
+ try { await actPlan({ groupId: room, planId: plan.id }, 'stop'); stoppedPlans.add(plan.id); }
+ catch (error) { if (!refused(error)) throw error; }
+ }
const executions = await api<Execution[]>(`/conversations/${room}/executions`);
- for (const e of executions.filter(e => ['queued', 'running', 'needs_input'].includes(e.status) && !e.plan_id)) {
- await api(`/conversations/${room}/executions/${e.id}/control`, 'POST', { operationId: randomUUID(), action: 'stop' });
+ for (const e of executions.filter(e => ['queued', 'running', 'needs_input'].includes(e.status) && !(e.plan_id && stoppedPlans.has(e.plan_id)))) {
+ // Your own teammate stops its work for others as itself; a request you made, as you.
+ const asBot = !everything && e.requester_id !== selfId && ownBot(e.bot_id);
+ if (!everything && !asBot && e.requester_id !== selfId) continue;
+ try { await api(`/conversations/${room}/executions/${e.id}/control`, 'POST', { operationId: randomUUID(), action: 'stop' }, asBot ? e.bot_id : everything && e.requester_id !== selfId ? asManager : undefined); }
+ catch (error) { if (refused(error)) continue; throw error; }
- const run = running.get(e.bot_id);
- if (run?.execution.id === e.id) { running.delete(e.bot_id); if (run.sessionId) await deps.abortLane(run.sessionId); }
+ const run = running.get(e.id);
+ if (run) { forgetRun(run); if (run.sessionId) await deps.abortLane(run.sessionId); }
}
changed(room); return { ok: true as const };
}),