Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(bots): 交接消息按实际完成的步骤标第几步
Chrisdca309947cc8
diff --git a/apps/desktop/src/main/maker-ipc/botGroupChatService.ts b/apps/desktop/src/main/maker-ipc/botGroupChatService.tsindex 4c766395da..36231ae3fa 100644--- a/apps/desktop/src/main/maker-ipc/botGroupChatService.ts+++ b/apps/desktop/src/main/maker-ipc/botGroupChatService.ts@@ -689,6 +689,7 @@ export function createBotGroupChatService(deps: BotGroupChatServiceDeps) {botName: step.botName,task: step.task,status: stepStatus(step.status),+ resultMessageId: step.resultMessageId ?? null,})),currentStep: plan.currentStep ?? null,workDir: plan.workDir ?? null,diff --git a/apps/desktop/src/renderer/features/bots/BotGroupTimelineModel.ts b/apps/desktop/src/renderer/features/bots/BotGroupTimelineModel.tsindex 5aec6f12bf..f84a5a1d90 100644--- a/apps/desktop/src/renderer/features/bots/BotGroupTimelineModel.ts+++ b/apps/desktop/src/renderer/features/bots/BotGroupTimelineModel.ts@@ -312,19 +312,41 @@ export function runningBotGroupPlanStep(plan: BotGroupPlanView | null): BotGroup}/**- * 「第 k 步」 on a step's hand-off message: the plan step done by the message's author. When the- * author has several steps in the plan, the hand-offs are matched to them in order.+ * 「第 k 步」 on a step's hand-off message. Where the plan names each step's latest hand-off, that+ * message gets its step exactly, and a hand-off a redo replaced gets the step of the same+ * author's next hand-off (a redo follows the step it redoes); one that matches nothing stays+ * unnumbered rather than numbered wrong. Without those ids (Chat Server plans, older hosts) the+ * author's hand-offs are matched to the author's steps in order.*/export function botGroupHandoffStepNumbers(messages: readonly BotGroupMessageView[],plans: ReadonlyMap<string, BotGroupPlanView>,): ReadonlyMap<string, number> {const numbers = new Map<string, number>();+ const handoffs = messages.filter((message) => message.kind === 'message' && message.authorKind === 'bot'+ && message.planId && message.authorBotId && plans.has(message.planId));+ const exact = new Map<string, number>();+ const exactPlans = new Set<string>();+ for (const plan of plans.values()) {+ plan.steps.forEach((step, index) => {+ if (step.resultMessageId === undefined) return;+ exactPlans.add(plan.id);+ if (step.resultMessageId) exact.set(step.resultMessageId, index + 1);+ });+ }+ const next = new Map<string, number>();+ for (const message of [...handoffs].reverse()) {+ if (!exactPlans.has(message.planId!)) continue;+ const key = `${message.planId}:${message.authorBotId}`;+ const number = exact.get(message.id) ?? next.get(key);+ if (number === undefined) continue;+ numbers.set(message.id, number);+ next.set(key, number);+ }const seen = new Map<string, number>();- for (const message of messages) {- if (message.kind !== 'message' || message.authorKind !== 'bot' || !message.planId || !message.authorBotId) continue;- const plan = plans.get(message.planId);- if (!plan) continue;+ for (const message of handoffs) {+ if (exactPlans.has(message.planId!)) continue;+ const plan = plans.get(message.planId!)!;const key = `${plan.id}:${message.authorBotId}`;const nth = seen.get(key) ?? 0;const positions = plan.steps.flatMap((step, index) => (step.botId === message.authorBotId ? [index + 1] : []));diff --git a/apps/desktop/src/renderer/features/bots/__tests__/BotGroupTimelineModel.test.ts b/apps/desktop/src/renderer/features/bots/__tests__/BotGroupTimelineModel.test.tsindex cf27213644..cc15cfe7c8 100644--- a/apps/desktop/src/renderer/features/bots/__tests__/BotGroupTimelineModel.test.ts+++ b/apps/desktop/src/renderer/features/bots/__tests__/BotGroupTimelineModel.test.ts@@ -184,4 +184,26 @@ describe('plan hand-offs', () => {], new Map([['p1', plan]]));expect([...numbers]).toEqual([['h1', 1], ['h2', 2], ['h3', 3]]);});++ it('numbers hand-offs by the step they finished, through a redo and with earlier pages not loaded', () => {+ const plan: BotGroupPlanView = {+ id: 'p1', status: 'running', organizerBotId: 'mimi', organizerName: '咪咪', currentStep: 2, workDir: null, branch: null, createdAt: 1, updatedAt: 1,+ steps: [+ { position: 0, botId: 'mimi', botName: '咪咪', task: 'a', status: 'done', resultMessageId: 'h1-redo' },+ { position: 1, botId: 'xiaoman', botName: '小满', task: 'b', status: 'done', resultMessageId: 'h2' },+ { position: 2, botId: 'mimi', botName: '咪咪', task: 'c', status: 'done', resultMessageId: 'h3' },+ ],+ };+ const plans = new Map([['p1', plan]]);+ // Step 1 was redone after the user asked: its first hand-off is replaced, still step 1.+ const numbers = botGroupHandoffStepNumbers([+ msg({ id: 'h1', planId: 'p1' }),+ msg({ id: 'h1-redo', planId: 'p1' }),+ msg({ id: 'h2', planId: 'p1', authorBotId: 'xiaoman' }),+ msg({ id: 'h3', planId: 'p1' }),+ ], plans);+ expect(Object.fromEntries(numbers)).toEqual({ h1: 1, 'h1-redo': 1, h2: 2, h3: 3 });+ // Only the newest page is loaded: the third step is still the third step.+ expect(Object.fromEntries(botGroupHandoffStepNumbers([msg({ id: 'h3', planId: 'p1' })], plans))).toEqual({ h3: 3 });+ });});diff --git a/packages/maker-shared/src/botGroupChat.ts b/packages/maker-shared/src/botGroupChat.tsindex 1e55b9a3c9..b4d314bb03 100644--- a/packages/maker-shared/src/botGroupChat.ts+++ b/packages/maker-shared/src/botGroupChat.ts@@ -229,6 +229,8 @@ export interface BotGroupPlanStepView {botName: string;task: string;status: BotGroupPlanStepStatus;+ /** The step's latest hand-off message (a redo replaces it); absent where the host does not report it. */+ resultMessageId?: string | null;}export interface BotGroupPlanView {