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。

fix(mobile): 保留历史磁盘缓存中的业务字段

Dashe6c7429a2a6b
diff --git a/apps/mobile/src/__tests__/remoteHistoryDiskCache.test.ts b/apps/mobile/src/__tests__/remoteHistoryDiskCache.test.ts
index e54f294dc4..8c97ca1947 100644
--- a/apps/mobile/src/__tests__/remoteHistoryDiskCache.test.ts
+++ b/apps/mobile/src/__tests__/remoteHistoryDiskCache.test.ts
@@ -1,5 +1,5 @@
import { afterEach, describe, expect, it, vi } from 'vitest';
-import { HistoryViewController, projectHistoryView, type HistoryViewSnapshot } from '@cindy/maker-shared/message-window';
+import { HistoryViewController, projectHistoryView, type HistoryViewSnapshot, type HistoryWorkSummary } from '@cindy/maker-shared/message-window';
import { setMobileAuthOwner } from '@/auth/authOwnerGeneration';
import { clearHistoryDisk, historyDiskAuthority, readHistoryDisk, writeHistoryDisk } from '@/session/remoteHistoryDiskCache';
import type { RemoteMessage } from '@/session/types';
@@ -65,6 +65,38 @@ describe('persistent history integration', () => {
await writeHistoryDisk(auth, value);
expect(JSON.stringify(await readHistoryDisk(auth))).not.toContain('"isStreaming":true');
});
+ it('clears only view streaming metadata while preserving nested message and card content', async () => {
+ setMobileAuthOwner('a');
+ const auth = historyDiskAuthority('d', 's');
+ const value = snapshot('saved');
+ const row: RemoteMessage = { id: 'a', clientId: 'a', sessionId: 's', role: 'tool_use', toolUseId: 'tool',
+ createdAt: '2026-09-08T00:00:00Z', agentMeta: { isStreaming: true, streaming: true, custom: { isStreaming: 'business', streaming: true } },
+ content: { isStreaming: true, input: { isStreaming: 'literal', nested: [{ isStreaming: true }] } },
+ systemCardData: { isStreaming: true },
+ };
+ const summary: HistoryWorkSummary = { key: 'w', firstMessageId: 'a', lastMessageId: 'a', revision: 'r',
+ startedAtMs: 1, endedAtMs: 2, messageCount: 1, toolCount: 1, isStreaming: true };
+ value.items = [{ type: 'work', key: 'outer', summary: { ...summary, preview: summary }, children: [
+ { type: 'messages', key: 'narration', messages: [row] },
+ { type: 'work', key: 'inner', summary, children: [{ type: 'messages', key: 'nested', messages: [row] }] },
+ ] }];
+ value.details = new Map([['w', { messages: [row], revision: 'r', lastMessageId: 'a',
+ complete: true, loading: false, error: null }]]);
+ const original = JSON.stringify(value.items);
+ await writeHistoryDisk(auth, value);
+ const restored = (await readHistoryDisk(auth))!;
+ const cachedRow = { ...row, agentMeta: { ...row.agentMeta, isStreaming: false, streaming: false } };
+ expect(restored.items).toEqual([{ type: 'work', key: 'outer',
+ summary: { ...summary, isStreaming: false, preview: { ...summary, isStreaming: false } }, children: [
+ { type: 'messages', key: 'narration', messages: [cachedRow] },
+ { type: 'work', key: 'inner', summary: { ...summary, isStreaming: false }, children: [
+ { type: 'messages', key: 'nested', messages: [cachedRow] },
+ ] },
+ ] }]);
+ expect(restored.details.get('w')!.messages).toEqual([cachedRow]);
+ expect(JSON.stringify(value.items)).toBe(original);
+ expect(row.agentMeta!.isStreaming).toBe(true);
+ });
function controller() {
return new HistoryViewController<RemoteMessage>({
page: async () => ({ version: 1, items: [...snapshot('network').items], hasMore: false, nextCursor: null }),
diff --git a/apps/mobile/src/session/remoteHistoryDiskCache.ts b/apps/mobile/src/session/remoteHistoryDiskCache.ts
index 21ee9b8676..8dfe652df3 100644
--- a/apps/mobile/src/session/remoteHistoryDiskCache.ts
+++ b/apps/mobile/src/session/remoteHistoryDiskCache.ts
@@ -1,4 +1,4 @@
-import type { HistoryViewSnapshot } from '@cindy/maker-shared/message-window';
+import type { HistoryViewItem, HistoryViewSnapshot, HistoryWorkSummary } from '@cindy/maker-shared/message-window';
import { getMobileAuthOwner, isMobileAuthOwnerCurrent } from '@/auth/authOwnerGeneration';
import { getActiveMobileSessionRealm } from '@/config/env';
import { HistoryDiskStore, HISTORY_DISK_ITEM_BYTES, historyValueBytes } from './historyDiskStore';
@@ -68,10 +68,23 @@ export async function writeHistoryDisk(authority: Authority, snapshot: HistoryVi
if (!authority.current() || !snapshot.ready || snapshot.loading || snapshot.error) return;
if (historyValueBytes([snapshot.items, snapshot.details, snapshot.expanded, snapshot.nextCursor], HISTORY_DISK_ITEM_BYTES - 1024) > HISTORY_DISK_ITEM_BYTES - 1024) return;
try {
- const text = JSON.stringify({ version: 1, items: snapshot.items,
- details: [...snapshot.details].filter(([, detail]) => detail.complete && !detail.loading && !detail.error),
+ const messages = (rows: readonly RemoteMessage[]) => rows.map(row =>
+ row.agentMeta?.isStreaming === true || row.agentMeta?.streaming === true
+ ? { ...row, agentMeta: { ...row.agentMeta,
+ ...(row.agentMeta.isStreaming === true ? { isStreaming: false } : {}),
+ ...(row.agentMeta.streaming === true ? { streaming: false } : {}),
+ } } : row);
+ const summary = (value: HistoryWorkSummary): HistoryWorkSummary => ({ ...value, isStreaming: false,
+ ...(value.preview ? { preview: summary(value.preview) } : {}),
+ });
+ const items = (values: readonly HistoryViewItem<RemoteMessage>[]): HistoryViewItem<RemoteMessage>[] => values.map(item =>
+ item.type === 'messages' ? { ...item, messages: messages(item.messages) }
+ : { ...item, summary: summary(item.summary), ...(item.children ? { children: items(item.children) } : {}) });
+ const text = JSON.stringify({ version: 1, items: items(snapshot.items),
+ details: [...snapshot.details].filter(([, detail]) => detail.complete && !detail.loading && !detail.error)
+ .map(([key, detail]) => [key, { ...detail, messages: messages(detail.messages) }]),
expanded: [...snapshot.expanded], nextCursor: snapshot.nextCursor, hasMore: snapshot.hasMore,
- }, (key, value) => key === 'isStreaming' ? false : value);
+ });
await (await disk()).write(authority.key, text, authority.current);
} catch { /* Cache failure must not affect reading or synchronizing. */ }
}