Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(group-chat): 服务端声明 directRoomClaim 能力时领取请求带 directRoomVersion
Dashd7366e03b026
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/chatServerCompanion.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/chatServerCompanion.test.tsindex de551ada55..df10fc53e4 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/chatServerCompanion.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/chatServerCompanion.test.ts@@ -83,7 +83,7 @@ describe('Chat Server cloud companions', () => {vi.stubEnv('XDT_ISOLATED', '1');fixture.profiles = [{ id: 'local-bot', displayName: 'Mia', avatar: null, status: 'active' }];fixture.sockets = [];- me = { actor: { id: selfId }, deviceId: 'desk-1', capabilities: { companionHome: true } };+ me = { actor: { id: selfId }, deviceId: 'desk-1', capabilities: { companionHome: true, directRoomClaim: true } };home = null; claimed = false;directMembers = [{ id: selfId, state: 'joined' }, { id: botActor, state: 'joined' }];patch = () => { home = 'desk-1'; return { body: { id: botActor, homeDeviceId: 'desk-1' } }; };@@ -250,6 +250,8 @@ describe('Chat Server cloud companions', () => {it('delivers a 1:1 room message to the canonical Session and completes without content', async () => {await vi.advanceTimersByTimeAsync(2000);await vi.advanceTimersByTimeAsync(0);+ // The server only hands 1:1 room work to a claim that declares it can run it.+ expect(calls('/executions/claim')[0]![2]).toMatchObject({ directRoomVersion: 1, accessPolicyVersion: 1, planVersion: 1 });expect(host.deliverToCanonical).toHaveBeenCalledWith('local-bot', 'hi\n[附件: a.png]', `chat-direct:${execution.id}:${sourceId}`);expect(deps.ensureLane).not.toHaveBeenCalled();expect(deps.dispatch).not.toHaveBeenCalled();@@ -261,6 +263,22 @@ describe('Chat Server cloud companions', () => {expect(results[0]![3]).toBe(botActor);});+ it('claims without directRoomVersion from a server that does not offer the capability', async () => {+ me = { ...me, capabilities: { companionHome: true } };+ await vi.advanceTimersByTimeAsync(2000);+ await vi.advanceTimersByTimeAsync(0);+ expect(calls('/executions/claim').length).toBeGreaterThan(0);+ for (const call of calls('/executions/claim')) expect(call[2]).not.toHaveProperty('directRoomVersion');+ });++ it('never declares 1:1 room work from a copy that cannot hand it to the main task', async () => {+ me = { ...me, capabilities: { directRoomClaim: true } };+ await vi.advanceTimersByTimeAsync(2000);+ await vi.advanceTimersByTimeAsync(0);+ expect(calls('/executions/claim').length).toBeGreaterThan(0);+ for (const call of calls('/executions/claim')) expect(call[2]).not.toHaveProperty('directRoomVersion');+ });+it('never treats someone else\'s 1:1 room as the companion\'s own room', async () => {directMembers = [{ id: selfId, state: 'joined' }, { id: '60000000-0000-4000-8000-000000000009', state: 'joined' }];await vi.advanceTimersByTimeAsync(2000);diff --git a/apps/desktop/src/main/maker-ipc/chatServer.ts b/apps/desktop/src/main/maker-ipc/chatServer.tsindex 52d19dfc72..bdfe324616 100644--- a/apps/desktop/src/main/maker-ipc/chatServer.ts+++ b/apps/desktop/src/main/maker-ipc/chatServer.ts@@ -214,6 +214,7 @@ function createChatServer(local: BotGroupChatService, deps: BotGroupChatServiceD// Cloud companions (cloud-companions.md): inert unless the server announces homes.let selfDeviceId: string | null = null;let companionHome = false;+ let directRoomClaims = false;let companion: CompanionCloudRuntime | undefined;let companionSelf: string | null = null;let actorsStale = false;@@ -504,12 +505,15 @@ function createChatServer(local: BotGroupChatService, deps: BotGroupChatServiceDrefreshActors = (async () => {actorsStale = false;profiles = await getDbClient().drizzle.select().from(botProfiles).where(undefined);- const me = await api<{ actor: Actor; deviceId?: string | null; capabilities?: { groupDiscussionParity?: number; companionHome?: boolean; groupLifecycleVersion?: number; conversationListStateVersion?: number } }>('/me'); selfId = me.actor.id;+ const me = await api<{ actor: Actor; deviceId?: string | null; capabilities?: { groupDiscussionParity?: number; companionHome?: boolean; directRoomClaim?: boolean; groupLifecycleVersion?: number; conversationListStateVersion?: number } }>('/me'); selfId = me.actor.id;supportsDissolve = me.capabilities?.groupLifecycleVersion === 1;supportsListRemoval = me.capabilities?.conversationListStateVersion === 1;groupDiscussionParity = me.capabilities?.groupDiscussionParity === 1;selfDeviceId = typeof me.deviceId === 'string' && me.deviceId ? me.deviceId : null;companionHome = !!deps.companionCloud && me.capabilities?.companionHome === true && !!selfDeviceId;+ // Work in a 1:1 room is only claimed by a copy that hands it to the companion's main task;+ // a server without the capability never sees the field (its strict contract would reject it).+ directRoomClaims = companionHome && me.capabilities?.directRoomClaim === true;// Refresh from the issuing auth server, never overwrite with a stale device cache.if (Date.now() - profileRefreshedAt > 60000) {await api('/profile/refresh', 'POST').then(() => { profileRefreshedAt = Date.now(); }).catch(() => undefined);@@ -1365,7 +1369,7 @@ function createChatServer(local: BotGroupChatService, deps: BotGroupChatServiceD// installation is not yet confirmed to run it (the server only tells devices apart): never claim.if (companionHome && (companion?.isShadowed(actor.externalId) || !companion?.installConfirmed(actor.externalId))) continue;let claim: { execution: Execution | null };- const payload = { operationId: randomUUID(), executorId, accessPolicyVersion: 1, planVersion: 1 };+ const payload = { operationId: randomUUID(), executorId, accessPolicyVersion: 1, planVersion: 1, ...(directRoomClaims ? { directRoomVersion: 1 } : {}) };try {claim = await api('/executions/claim', 'POST', { ...payload, ...(memberJoinedClaims ? { memberJoinedVersion: 1 } : {}) }, actor.id);} catch (error) {