Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): GET 兜底与 push 共用带 emittedAt 的词典投影
Dash1e52b7acd67e
diff --git a/apps/desktop/src/main/device-link/dispatch.ts b/apps/desktop/src/main/device-link/dispatch.tsindex ed3a46135c..20cb429dc5 100644--- a/apps/desktop/src/main/device-link/dispatch.ts+++ b/apps/desktop/src/main/device-link/dispatch.ts@@ -73,7 +73,7 @@ import { fetchLocalMediaToOss } from './mediaFetch';import { transcribeRemoteVoiceInput } from './voiceTranscribe';import { readTelegramRemoteStatus, setTelegramRemoteOnline } from './telegramRemoteControl';import { adviseAndRecordVoiceInputDictionaryLearning } from '../voice-input/index.js';-import { readDictionaryProjectionForMobile } from '../voice-input/dictionarySyncDriver.js';+import { buildMobileDictionarySnapshot } from '../voice-input/dictionarySyncDriver.js';import {setBroadcastTapListener,} from './broadcast-tap';@@ -2808,7 +2808,7 @@ export async function runInvoke(// 不参与合并,避免移动端维护一份会分叉的词典。if (payload.channel === DL_VOICE_DICTIONARY_GET_CHANNEL) {try {- return { ok: true, result: { ok: true, ...readDictionaryProjectionForMobile() } };+ return { ok: true, result: buildMobileDictionarySnapshot() };} catch (err) {const message = err instanceof Error ? err.message : String(err);log.warn(`voice:dictionary:get failed from ${shortId(src)}: ${message}`);diff --git a/apps/desktop/src/main/voice-input/__tests__/dictionarySyncDriver.test.ts b/apps/desktop/src/main/voice-input/__tests__/dictionarySyncDriver.test.tsindex 8ce41b57bb..a1cb5c1a3b 100644--- a/apps/desktop/src/main/voice-input/__tests__/dictionarySyncDriver.test.ts+++ b/apps/desktop/src/main/voice-input/__tests__/dictionarySyncDriver.test.ts@@ -64,6 +64,7 @@ const {initVoiceDictionarySync,isDesktopPlatform,notifyLocalDictionaryChanged,+ buildMobileDictionarySnapshot,readDictionaryProjectionForMobile,shouldExchangeDictionaryWith,stopVoiceDictionarySync,@@ -328,4 +329,10 @@ describe('手机只读投影', () => {expect(projection.entries).toEqual([]);expect(projection.stateVector && Object.keys(projection.stateVector)).toEqual(['node-a']);});++ it('主动 GET 与 push 共用带 emittedAt 的投影', () => {+ const snapshot = buildMobileDictionarySnapshot();+ expect(snapshot.ok).toBe(true);+ if (snapshot.ok) expect(snapshot.emittedAt).toEqual(expect.any(Number));+ });});diff --git a/apps/desktop/src/main/voice-input/dictionarySyncDriver.ts b/apps/desktop/src/main/voice-input/dictionarySyncDriver.tsindex 1084d578c8..c37724d328 100644--- a/apps/desktop/src/main/voice-input/dictionarySyncDriver.ts+++ b/apps/desktop/src/main/voice-input/dictionarySyncDriver.ts@@ -244,12 +244,17 @@ function sendMobileSnapshotTo(}}-function buildMobileSnapshot(): MobileVoiceDictionarySnapshotResult | null {- const payload: MobileVoiceDictionarySnapshotResult = {+/** push 与主动 GET 共用:同一份投影必须带上发出时间,否则同代向量的兜底拉取盖不掉已有 push。 */+export function buildMobileDictionarySnapshot(): MobileVoiceDictionarySnapshotResult {+ return {ok: true,emittedAt: Date.now(),...readDictionaryProjectionForMobile(),};+}++function buildMobileSnapshot(): MobileVoiceDictionarySnapshotResult | null {+ const payload = buildMobileDictionarySnapshot();const bytes = Buffer.byteLength(JSON.stringify(payload), 'utf8');if (bytes <= MAX_STATE_FRAME_BYTES) return payload;// 与桌面 CRDT 同一条上限:超限帧会被 relay 拒绝。这里不另造分片协议,diff --git a/apps/mobile/src/__tests__/mobileVoiceDictionaryCache.test.ts b/apps/mobile/src/__tests__/mobileVoiceDictionaryCache.test.tsindex 179a180ebb..de6fc226f3 100644--- a/apps/mobile/src/__tests__/mobileVoiceDictionaryCache.test.ts+++ b/apps/mobile/src/__tests__/mobileVoiceDictionaryCache.test.ts@@ -435,6 +435,21 @@ describe('版本向量的入站校验', () => {expect(readCachedMobileVoiceDictionary(HOST)[0].text).toBe('新词');});+ it('不带 emittedAt 的同代拉取不能盖掉已有 push', async () => {+ await applyMobileVoiceDictionarySnapshot(HOST, {+ ok: true,+ entries: [{ text: '推送词' }],+ stateVector: { 'node-a': STAMP_A },+ emittedAt: 1_000,+ });+ await applyMobileVoiceDictionarySnapshot(HOST, {+ ok: true,+ entries: [{ text: '拉取词' }],+ stateVector: { 'node-a': STAMP_A },+ });+ expect(readCachedMobileVoiceDictionary(HOST)[0].text).toBe('推送词');+ });+it('后到的无向量空投影不能清掉已有的更新快照', async () => {await applyMobileVoiceDictionarySnapshot(HOST, {ok: true,