From 88e07e82e6a35658d97586eda967150ce87b1235 Mon Sep 17 00:00:00 2001 From: wgqqqqq Date: Mon, 23 Nov 2026 19:56:23 +0800 Subject: [PATCH 1/4] fix(harmony): keep local genui turns alive in background --- .../main/ets/pages/runtime/AppRootRuntime.ets | 1 + .../runtime/AppRootRuntimeComposition.ets | 3 ++ .../pages/viewmodel/LocalGenUIViewModel.ets | 15 ++++++ .../HarmonyTaskCompletionNotificationPort.ets | 3 +- .../LocalGenUIBackgroundKeepAlive.ets | 5 ++ .../LocalGenUISessionController.ets | 50 ++++++++++++++++++- 6 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIBackgroundKeepAlive.ets diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/runtime/AppRootRuntime.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/runtime/AppRootRuntime.ets index eb39e1c..33a768b 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/runtime/AppRootRuntime.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/runtime/AppRootRuntime.ets @@ -40,6 +40,7 @@ export class AppRootRuntime extends AppRootRuntimeComposition { constructor(host: AppRootHostPort) { super(host); + this.localGenUIViewModel.setBackgroundKeepAlive(this.localGenUIBackgroundPort); } subscribeToDesktopLaunch(onLaunch: () => void): void { diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/runtime/AppRootRuntimeComposition.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/runtime/AppRootRuntimeComposition.ets index 85b60d1..c958896 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/runtime/AppRootRuntimeComposition.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/runtime/AppRootRuntimeComposition.ets @@ -162,6 +162,9 @@ export abstract class AppRootRuntimeComposition { readonly localGenUIViewModel: LocalGenUIViewModel = new LocalGenUIViewModel((): Context => this.host.context()); readonly taskCompletionNotificationPort: HarmonyTaskCompletionNotificationPort = new HarmonyTaskCompletionNotificationPort((): Context => this.host.context()); + /** Separate suspend-delay lease so local GenUI never cancels remote task observation. */ + readonly localGenUIBackgroundPort: HarmonyTaskCompletionNotificationPort = + new HarmonyTaskCompletionNotificationPort((): Context => this.host.context()); readonly taskCompletionNotificationController: TaskCompletionNotificationController = new TaskCompletionNotificationController( this.taskCompletionNotificationPort, diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/viewmodel/LocalGenUIViewModel.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/viewmodel/LocalGenUIViewModel.ets index 76f4931..8282715 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/viewmodel/LocalGenUIViewModel.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/viewmodel/LocalGenUIViewModel.ets @@ -34,6 +34,7 @@ import { LocalGenUIPresentationSource, LocalGenUISessionController } from '../../services/local-genui/LocalGenUISessionController'; +import { LocalGenUIBackgroundKeepAlive } from '../../services/local-genui/LocalGenUIBackgroundKeepAlive'; import { LocalGenUIActions, LocalGenUIModelEditorInput, LocalGenUIState } from '../state/LocalGenUIState'; import { ConversationIntent, ConversationIntentType, MessageCopyScope } from '../actions/ConversationIntent'; import { ConversationViewModel } from './ConversationViewModel'; @@ -70,6 +71,7 @@ export class LocalGenUIViewModel implements LocalGenUIControllerListener, LocalG private showActiveTurn: boolean = true; private readonly orientation: LocalGenUIOrientation; private preferredOrientation: string = 'auto'; + private backgroundKeepAlive?: LocalGenUIBackgroundKeepAlive; readonly actions: LocalGenUIActions = { open: (): void => { @@ -229,9 +231,19 @@ export class LocalGenUIViewModel implements LocalGenUIControllerListener, LocalG /** The phone app went to the background or came back. */ setForeground(foreground: boolean): void { this.foreground = foreground; + if (foreground) { + this.controller?.onForeground(); + } else { + this.controller?.onBackground(); + } this.syncDeviceVisibility(); } + setBackgroundKeepAlive(backgroundKeepAlive: LocalGenUIBackgroundKeepAlive): void { + this.backgroundKeepAlive = backgroundKeepAlive; + this.controller?.setBackgroundKeepAlive(backgroundKeepAlive); + } + /** Camera surface from the preview leaf; recognition starts once it exists. */ attachCameraSurface(surfaceId: string): void { if (this.devices) this.devices.attachSurface(surfaceId); @@ -604,6 +616,9 @@ export class LocalGenUIViewModel implements LocalGenUIControllerListener, LocalG this.devices = devices; this.syncDeviceVisibility(); this.controller = new LocalGenUISessionController(repository, provider, contract, this.bridge, this, this, models, thumbnails, devices, desktopCards, calendar, collaboration, photos); + if (this.backgroundKeepAlive) { + this.controller.setBackgroundKeepAlive(this.backgroundKeepAlive); + } await this.controller.refreshModels(); RemoteLogger.info(`local genui ready renderer=${contract.manifest.rendererRevision} models=${models.list().length}`); } finally { diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/services/HarmonyTaskCompletionNotificationPort.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/services/HarmonyTaskCompletionNotificationPort.ets index 5466dcb..e48bf23 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/services/HarmonyTaskCompletionNotificationPort.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/services/HarmonyTaskCompletionNotificationPort.ets @@ -4,6 +4,7 @@ import { backgroundTaskManager } from '@kit.BackgroundTasksKit'; import { notificationManager } from '@kit.NotificationKit'; import { RemoteI18n } from '../i18n/RemoteI18n'; import { RemoteLogger } from './RemoteLogger'; +import { LocalGenUIBackgroundKeepAlive } from './local-genui/LocalGenUIBackgroundKeepAlive'; import { TaskCompletionNotificationPort, TaskCompletionObservation @@ -12,7 +13,7 @@ import { const BACKGROUND_REASON: string = 'Waiting for an active OpenBitFun task to finish'; /** HarmonyOS platform leaf for task-completion notifications. */ -export class HarmonyTaskCompletionNotificationPort implements TaskCompletionNotificationPort { +export class HarmonyTaskCompletionNotificationPort implements TaskCompletionNotificationPort, LocalGenUIBackgroundKeepAlive { private readonly contextProvider: () => Context; private permissionPrepared: boolean = false; private suspendRequestId: number = 0; diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIBackgroundKeepAlive.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIBackgroundKeepAlive.ets new file mode 100644 index 0000000..2cea49c --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIBackgroundKeepAlive.ets @@ -0,0 +1,5 @@ +/** Platform-neutral lease used to keep a local provider request alive in background. */ +export interface LocalGenUIBackgroundKeepAlive { + keepAlive(onExpired: () => void): boolean; + releaseKeepAlive(): void; +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUISessionController.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUISessionController.ets index 25194b3..a147d16 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUISessionController.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUISessionController.ets @@ -38,6 +38,7 @@ import { LocalProviderFrame } from './LocalProviderSseParser'; import { LocalGenUIModelStore, LocalGenUIModelUpdate } from './LocalGenUIModelStore'; import { LocalGenUIImageSearch } from './LocalGenUIImageSearch'; import { LocalGenUIModelCatalog, LocalGenUIModelChoice, LocalGenUIModelProfile } from './LocalGenUIModelCatalog'; +import { LocalGenUIBackgroundKeepAlive } from './LocalGenUIBackgroundKeepAlive'; /** Projection of one app for the presentation layer. */ export interface LocalGenUIAppView { @@ -137,6 +138,9 @@ export class LocalGenUISessionController { private readonly collaboration: LocalGenUICollaborationHost; private readonly calendarActions: LocalGenUICalendarActions; private readonly desktopCards: LocalGenUIDesktopCardStore; + private backgroundKeepAlive?: LocalGenUIBackgroundKeepAlive; + private backgrounded: boolean = false; + private backgroundKeepAliveActive: boolean = false; private activeSessionId: string = ''; private activeSession?: LocalGenUISession; /** Model for the next new session; follows the last explicit choice. */ @@ -162,9 +166,11 @@ export class LocalGenUISessionController { desktopCards: LocalGenUIDesktopCardStore, calendar: HarmonyCalendarService, collaboration: LocalGenUICollaborationHost, - imageSearch?: LocalGenUIImageSearch + imageSearch?: LocalGenUIImageSearch, + backgroundKeepAlive?: LocalGenUIBackgroundKeepAlive ) { this.imageSearch = imageSearch; + this.backgroundKeepAlive = backgroundKeepAlive; this.devices = devices; this.calendar = calendar; this.collaboration = collaboration; @@ -236,6 +242,46 @@ export class LocalGenUISessionController { return this.turnActive; } + setBackgroundKeepAlive(backgroundKeepAlive: LocalGenUIBackgroundKeepAlive): void { + this.backgroundKeepAlive = backgroundKeepAlive; + } + + /** Preserve the direct provider stream while Harmony suspends the UI ability. */ + onBackground(): void { + this.backgrounded = true; + this.ensureBackgroundKeepAlive(); + } + + /** Release the temporary background lease after the page is visible again. */ + onForeground(): void { + this.backgrounded = false; + this.releaseBackgroundKeepAlive(); + } + + private ensureBackgroundKeepAlive(): void { + if (!this.backgrounded || !this.turnActive || this.backgroundKeepAliveActive || !this.backgroundKeepAlive) { + return; + } + const keptAlive = this.backgroundKeepAlive.keepAlive((): void => { + this.backgroundKeepAliveActive = false; + if (this.backgrounded && this.turnActive) { + RemoteLogger.warn('local genui background keep-alive expired; cancelling provider turn'); + this.cancel(); + } + }); + this.backgroundKeepAliveActive = keptAlive; + RemoteLogger.info(`local genui background keep-alive ${keptAlive ? 'started' : 'unavailable'}`); + } + + private releaseBackgroundKeepAlive(): void { + if (!this.backgroundKeepAliveActive || !this.backgroundKeepAlive) { + return; + } + this.backgroundKeepAliveActive = false; + this.backgroundKeepAlive.releaseKeepAlive(); + RemoteLogger.info('local genui background keep-alive released'); + } + async refreshSessions(): Promise { this.listener.sessionsChanged(await this.repository.listSessions(), this.activeSessionId); } @@ -602,6 +648,7 @@ export class LocalGenUISessionController { const modelId = choice.model.id; this.turnActive = true; const serial = ++this.turnSerial; + this.ensureBackgroundKeepAlive(); const internalRepair = repairMessageId.length > 0; this.listener.busyChanged(true, serial, !internalRepair); composer?.onAccepted(); @@ -639,6 +686,7 @@ export class LocalGenUISessionController { this.listener.notice(String(err instanceof Error ? err.message : err)); } finally { this.turnActive = false; + this.releaseBackgroundKeepAlive(); this.listener.busyChanged(false, serial, !internalRepair); } const repair = this.pendingRepair; From b1011c62a7cb006fefd3193d27228678b8bc0143 Mon Sep 17 00:00:00 2001 From: wgqqqqq Date: Mon, 23 Nov 2026 20:07:56 +0800 Subject: [PATCH 2/4] fix(ios): improve mobile control hit targets --- .../Account/AccountSettingsView.swift | 1 + .../Features/Chat/ChatTimelineView.swift | 3 +++ .../Features/Chat/ComposerBar.swift | 1 + .../Features/Chat/ConversationHeader.swift | 1 + .../Features/Chat/MessageQueuePanel.swift | 4 +-- .../AdaptiveModalComponents.swift | 3 +++ .../Features/Remote/RemoteHomeViews.swift | 1 + .../Features/Shell/LocalGenUiModels.swift | 3 ++- .../Features/Shell/OpenBitFunTheme.swift | 1 + .../Shell/RemoteCreateSessionView.swift | 9 ++++--- .../Shell/RemoteFilePreviewView.swift | 3 +++ .../Shell/SessionActionComponents.swift | 2 ++ .../Features/Shell/SidebarToolsFooter.swift | 1 + .../Features/Shell/SidebarView.swift | 26 ++++++++++++++----- src/apps/mobile/ios/OpenBitFun/Info.plist | 2 +- 15 files changed, 47 insertions(+), 14 deletions(-) diff --git a/src/apps/mobile/ios/OpenBitFun/Features/Account/AccountSettingsView.swift b/src/apps/mobile/ios/OpenBitFun/Features/Account/AccountSettingsView.swift index c7d996a..0f58c32 100644 --- a/src/apps/mobile/ios/OpenBitFun/Features/Account/AccountSettingsView.swift +++ b/src/apps/mobile/ios/OpenBitFun/Features/Account/AccountSettingsView.swift @@ -112,6 +112,7 @@ struct AccountLoginView: View { .font(.system(size: 19, weight: .medium)) .foregroundStyle(OpenBitFunTheme.ink) .frame(width: 44, height: 44) + .contentShape(Rectangle()) } .buttonStyle(.plain) .accessibilityLabel(model.localized("返回")) diff --git a/src/apps/mobile/ios/OpenBitFun/Features/Chat/ChatTimelineView.swift b/src/apps/mobile/ios/OpenBitFun/Features/Chat/ChatTimelineView.swift index 980ea79..2cb0ddb 100644 --- a/src/apps/mobile/ios/OpenBitFun/Features/Chat/ChatTimelineView.swift +++ b/src/apps/mobile/ios/OpenBitFun/Features/Chat/ChatTimelineView.swift @@ -131,6 +131,7 @@ struct ChatTimelineView: View { .clipShape(Circle()) .overlay(Circle().stroke(OpenBitFunTheme.line, lineWidth: 1)) .shadow(color: OpenBitFunTheme.shadowMedium, radius: 8, y: 3) + .contentShape(Rectangle()) } .buttonStyle(.plain) .padding(18) @@ -1124,6 +1125,7 @@ private struct FileReferenceCard: View { } .font(.system(size: 18, weight: .medium)) .foregroundStyle(OpenBitFunTheme.muted).frame(width: 40, height: 40) + .contentShape(Rectangle()) } .buttonStyle(.plain) .accessibilityLabel(model.localizedFormat("下载 %@", reference.label)) @@ -1165,6 +1167,7 @@ private struct FullScreenTimelineImage: View { Button { dismiss() } label: { Image(systemName: "xmark").font(.system(size: 15, weight: .semibold)).foregroundStyle(OpenBitFunTheme.contentOnAction) .frame(width: 44, height: 44).background(OpenBitFunTheme.mediaControlBackground).clipShape(Circle()) + .contentShape(Rectangle()) } .buttonStyle(.plain).padding(20) } diff --git a/src/apps/mobile/ios/OpenBitFun/Features/Chat/ComposerBar.swift b/src/apps/mobile/ios/OpenBitFun/Features/Chat/ComposerBar.swift index fee7872..dfc11eb 100644 --- a/src/apps/mobile/ios/OpenBitFun/Features/Chat/ComposerBar.swift +++ b/src/apps/mobile/ios/OpenBitFun/Features/Chat/ComposerBar.swift @@ -549,6 +549,7 @@ struct ComposerBar: View { width: MobileDesignGeometry.selectionCloseSize, height: MobileDesignGeometry.selectionCloseSize ) + .contentShape(Rectangle()) } .buttonStyle(.plain) .accessibilityLabel(Text(model.localized("关闭"))) diff --git a/src/apps/mobile/ios/OpenBitFun/Features/Chat/ConversationHeader.swift b/src/apps/mobile/ios/OpenBitFun/Features/Chat/ConversationHeader.swift index eb576e6..33711be 100644 --- a/src/apps/mobile/ios/OpenBitFun/Features/Chat/ConversationHeader.swift +++ b/src/apps/mobile/ios/OpenBitFun/Features/Chat/ConversationHeader.swift @@ -51,6 +51,7 @@ struct ConversationHeader: View { ) } .buttonStyle(.plain) + .contentShape(Rectangle()) .accessibilityLabel(MobileLocalization.text(sidebarActionLabel)) } else { OpenBitFunTheme.transparent diff --git a/src/apps/mobile/ios/OpenBitFun/Features/Chat/MessageQueuePanel.swift b/src/apps/mobile/ios/OpenBitFun/Features/Chat/MessageQueuePanel.swift index 17f3f73..53b3379 100644 --- a/src/apps/mobile/ios/OpenBitFun/Features/Chat/MessageQueuePanel.swift +++ b/src/apps/mobile/ios/OpenBitFun/Features/Chat/MessageQueuePanel.swift @@ -89,7 +89,7 @@ struct MessageQueuePanel: View { if item.status != "queued" { Text(model.localized("等待执行端处理")).font(MobileDesignTypography.bodySmall.font).foregroundStyle(OpenBitFunTheme.muted) } }.font(MobileDesignTypography.bodyMedium.font).frame(maxWidth: .infinity, minHeight: 48, alignment: .leading) Button { model.promoteQueuedMessage(item.id) } label: { - Image(systemName: "arrow.turn.down.right").frame(width: 44, height: 48) + Image(systemName: "arrow.turn.down.right").frame(width: 44, height: 48).contentShape(Rectangle()) }.disabled(queue.busy || queue.failure != nil || !["queued", "blocked"].contains(item.status)) .accessibilityLabel(model.localized("立即发送")) Menu { @@ -99,7 +99,7 @@ struct MessageQueuePanel: View { Button(model.localized("下移")) { if let index { model.moveQueuedMessage(item.id, before: ids.dropFirst(index + 2).first) } }.disabled(!enabled || index == ids.count - 1) Button(model.localized("从队列移除"), role: .destructive) { model.cancelQueuedMessage(item.id) } .disabled(queue.busy || queue.failure != nil || !["queued", "blocked"].contains(item.status)) - } label: { Image(systemName: "ellipsis").frame(width: 44, height: 48) } + } label: { Image(systemName: "ellipsis").frame(width: 44, height: 48).contentShape(Rectangle()) } .accessibilityLabel(model.localized("消息操作")) }.buttonStyle(.plain).foregroundStyle(OpenBitFunTheme.ink) } diff --git a/src/apps/mobile/ios/OpenBitFun/Features/DesignSystem/AdaptiveModalComponents.swift b/src/apps/mobile/ios/OpenBitFun/Features/DesignSystem/AdaptiveModalComponents.swift index b22b5e9..0fb6bdc 100644 --- a/src/apps/mobile/ios/OpenBitFun/Features/DesignSystem/AdaptiveModalComponents.swift +++ b/src/apps/mobile/ios/OpenBitFun/Features/DesignSystem/AdaptiveModalComponents.swift @@ -31,6 +31,7 @@ struct OpenBitFunModalHeader: View { width: MobileDesignGeometry.controlTouchSize, height: MobileDesignGeometry.controlTouchSize ) + .contentShape(Rectangle()) } .buttonStyle(.plain) .accessibilityLabel(MobileLocalization.text("关闭")) @@ -61,6 +62,7 @@ struct OpenBitFunSelectionHeader: View { width: MobileDesignGeometry.selectionCloseSize, height: MobileDesignGeometry.selectionCloseSize ) + .contentShape(Rectangle()) } .buttonStyle(.plain) .accessibilityLabel(MobileLocalization.text("关闭")) @@ -370,6 +372,7 @@ struct ConnectionSheetHeader: View { } } .frame(width: MobileDesignGeometry.controlTouchSize, height: MobileDesignGeometry.controlTouchSize) + .contentShape(Rectangle()) } .buttonStyle(.plain) .accessibilityLabel(MobileLocalization.text("关闭")) diff --git a/src/apps/mobile/ios/OpenBitFun/Features/Remote/RemoteHomeViews.swift b/src/apps/mobile/ios/OpenBitFun/Features/Remote/RemoteHomeViews.swift index 9aeadca..c81396f 100644 --- a/src/apps/mobile/ios/OpenBitFun/Features/Remote/RemoteHomeViews.swift +++ b/src/apps/mobile/ios/OpenBitFun/Features/Remote/RemoteHomeViews.swift @@ -129,6 +129,7 @@ struct RemoteConnectedHomeView: View { height: MobileDesignGeometry.controlTouchSize) } .buttonStyle(.plain) + .contentShape(Rectangle()) .accessibilityLabel(model.localized("打开侧栏")) .padding(.leading, 8) .padding(.top, 8) diff --git a/src/apps/mobile/ios/OpenBitFun/Features/Shell/LocalGenUiModels.swift b/src/apps/mobile/ios/OpenBitFun/Features/Shell/LocalGenUiModels.swift index daaaf63..83e6a9e 100644 --- a/src/apps/mobile/ios/OpenBitFun/Features/Shell/LocalGenUiModels.swift +++ b/src/apps/mobile/ios/OpenBitFun/Features/Shell/LocalGenUiModels.swift @@ -103,6 +103,7 @@ struct LocalGenUiModelSheet: View { } label: { Image(systemName: "xmark").font(.system(size: 18, weight: .medium)) .frame(width: MobileDesignGeometry.controlTouchSize, height: MobileDesignGeometry.controlTouchSize) + .contentShape(Rectangle()) } .buttonStyle(.plain) .accessibilityLabel(model.localized("关闭")) @@ -206,7 +207,7 @@ private struct LocalGenUiModelFields: View { if wasFocused { Task { @MainActor in keyFocused = true } } } label: { Image(systemName: draft.showTypedKey ? "eye" : "eye.slash") - .font(.system(size: 18)).frame(width: 32, height: 32) + .font(.system(size: 18)).frame(width: 32, height: 32).contentShape(Rectangle()) } .buttonStyle(.plain) .accessibilityLabel(model.localized(draft.showTypedKey ? "隐藏密钥" : "显示密钥")) diff --git a/src/apps/mobile/ios/OpenBitFun/Features/Shell/OpenBitFunTheme.swift b/src/apps/mobile/ios/OpenBitFun/Features/Shell/OpenBitFunTheme.swift index 763cc09..b0a6282 100644 --- a/src/apps/mobile/ios/OpenBitFun/Features/Shell/OpenBitFunTheme.swift +++ b/src/apps/mobile/ios/OpenBitFun/Features/Shell/OpenBitFunTheme.swift @@ -58,6 +58,7 @@ struct CircleControl: View { .overlay(Circle().stroke(OpenBitFunTheme.line, lineWidth: 1)) .clipShape(Circle()) .shadow(color: OpenBitFunTheme.shadowMedium, radius: 8, y: 3) + .contentShape(Rectangle()) } .buttonStyle(.plain) .accessibilityLabel(systemName) diff --git a/src/apps/mobile/ios/OpenBitFun/Features/Shell/RemoteCreateSessionView.swift b/src/apps/mobile/ios/OpenBitFun/Features/Shell/RemoteCreateSessionView.swift index f2acd98..23f2a7d 100644 --- a/src/apps/mobile/ios/OpenBitFun/Features/Shell/RemoteCreateSessionView.swift +++ b/src/apps/mobile/ios/OpenBitFun/Features/Shell/RemoteCreateSessionView.swift @@ -36,6 +36,7 @@ struct RemoteCreateSessionView: View { .frame(width: 44, height: 44) .background(OpenBitFunTheme.card) .clipShape(Circle()) + .contentShape(Rectangle()) } .buttonStyle(.plain) .accessibilityLabel(model.localized("返回")) @@ -1033,8 +1034,8 @@ private struct NativeRuntimeFileBrowser: View { VStack(alignment: .leading, spacing: 8) { Text(files.directory).font(.caption).foregroundStyle(OpenBitFunTheme.muted).lineLimit(2) HStack { - Button { model.browseRuntimeFiles((files.directory as NSString).deletingLastPathComponent.isEmpty ? "/" : (files.directory as NSString).deletingLastPathComponent) } label: { Image(systemName: "arrow.up").frame(width: 44, height: 44) }.accessibilityLabel(model.localized("Parent folder")).disabled(files.directory == "/") - Button { model.browseRuntimeFiles(files.directory) } label: { Image(systemName: "arrow.clockwise").frame(width: 44, height: 44) }.accessibilityLabel(model.localized("刷新")) + Button { model.browseRuntimeFiles((files.directory as NSString).deletingLastPathComponent.isEmpty ? "/" : (files.directory as NSString).deletingLastPathComponent) } label: { Image(systemName: "arrow.up").frame(width: 44, height: 44).contentShape(Rectangle()) }.accessibilityLabel(model.localized("Parent folder")).disabled(files.directory == "/") + Button { model.browseRuntimeFiles(files.directory) } label: { Image(systemName: "arrow.clockwise").frame(width: 44, height: 44).contentShape(Rectangle()) }.accessibilityLabel(model.localized("刷新")) Menu { Button(model.localized("Name: A–Z")) { model.sortRuntimeFiles(.nameAsc) } Button(model.localized("Name: Z–A")) { model.sortRuntimeFiles(.nameDesc) } @@ -1047,7 +1048,7 @@ private struct NativeRuntimeFileBrowser: View { Button(model.localized("新建文件")) { begin(.file) } Button(model.localized("创建文件夹")) { begin(.directory) } Button(model.localized("Upload file")) { begin(.upload) } - } label: { Image(systemName: "plus").frame(width: 44, height: 44) }.accessibilityIdentifier("file.browser.create") + } label: { Image(systemName: "plus").frame(width: 44, height: 44).contentShape(Rectangle()) }.accessibilityIdentifier("file.browser.create") } }.padding(.horizontal, 16).disabled(busy) @@ -1070,7 +1071,7 @@ private struct NativeRuntimeFileBrowser: View { if !entry.directory { Button(model.localized("下载")) { model.downloadWorkspaceFile(path: entry.path, label: entry.name) } } Button(model.localized("重命名")) { begin(.rename, path: entry.path, name: entry.name) } Button(model.localized("删除"), role: .destructive) { begin(.delete, path: entry.path, name: entry.name) } - } label: { Image(systemName: "ellipsis").frame(width: 44, height: 44) } + } label: { Image(systemName: "ellipsis").frame(width: 44, height: 44).contentShape(Rectangle()) } .accessibilityIdentifier("file.browser.actions.\(entry.path)") }.disabled(busy) Divider() diff --git a/src/apps/mobile/ios/OpenBitFun/Features/Shell/RemoteFilePreviewView.swift b/src/apps/mobile/ios/OpenBitFun/Features/Shell/RemoteFilePreviewView.swift index 0ffc76f..62d93a3 100644 --- a/src/apps/mobile/ios/OpenBitFun/Features/Shell/RemoteFilePreviewView.swift +++ b/src/apps/mobile/ios/OpenBitFun/Features/Shell/RemoteFilePreviewView.swift @@ -116,6 +116,7 @@ struct RemoteFilePreviewSheet: View { .font(.system(size: 18, weight: .medium)) .foregroundStyle(OpenBitFunTheme.ink) .frame(width: 44, height: 44) + .contentShape(Rectangle()) } .buttonStyle(.plain) .accessibilityLabel(Text(model.localized("返回"))) @@ -139,6 +140,7 @@ struct RemoteFilePreviewSheet: View { .font(.system(size: 18, weight: .medium)) .foregroundStyle(OpenBitFunTheme.ink) .frame(width: 44, height: 44) + .contentShape(Rectangle()) } .buttonStyle(.plain) .disabled(model.filePreviewLoading || model.connectionPhase == .disconnected) @@ -154,6 +156,7 @@ struct RemoteFilePreviewSheet: View { .font(.system(size: 18, weight: .medium)) .foregroundStyle(OpenBitFunTheme.ink) .frame(width: 44, height: 44) + .contentShape(Rectangle()) } .buttonStyle(.plain) .disabled([.preparing, .downloading, .saving].contains(model.downloadPhase)) diff --git a/src/apps/mobile/ios/OpenBitFun/Features/Shell/SessionActionComponents.swift b/src/apps/mobile/ios/OpenBitFun/Features/Shell/SessionActionComponents.swift index f86979f..9705d7f 100644 --- a/src/apps/mobile/ios/OpenBitFun/Features/Shell/SessionActionComponents.swift +++ b/src/apps/mobile/ios/OpenBitFun/Features/Shell/SessionActionComponents.swift @@ -42,6 +42,7 @@ struct SessionActionSurface: View { .font(.system(size: 16, weight: .regular)) .foregroundStyle(OpenBitFunTheme.muted) .frame(width: 40, height: 40) + .contentShape(Rectangle()) } .buttonStyle(.plain) .accessibilityLabel(model.localized("关闭")) @@ -212,6 +213,7 @@ struct SessionDetailsView: View { .frame(width: 44, height: 44) .background(OpenBitFunTheme.soft) .clipShape(Circle()) + .contentShape(Rectangle()) } .buttonStyle(.plain) .accessibilityLabel(model.localized("关闭")) diff --git a/src/apps/mobile/ios/OpenBitFun/Features/Shell/SidebarToolsFooter.swift b/src/apps/mobile/ios/OpenBitFun/Features/Shell/SidebarToolsFooter.swift index b485427..c7ae43a 100644 --- a/src/apps/mobile/ios/OpenBitFun/Features/Shell/SidebarToolsFooter.swift +++ b/src/apps/mobile/ios/OpenBitFun/Features/Shell/SidebarToolsFooter.swift @@ -30,6 +30,7 @@ struct SidebarToolsFooter: View { .font(.system(size: 20)) .frame(width: 48, height: 48) .background(OpenBitFunTheme.sidebarRaised, in: Circle()) + .contentShape(Rectangle()) } .buttonStyle(.plain) .foregroundStyle(OpenBitFunTheme.sidebarInk) diff --git a/src/apps/mobile/ios/OpenBitFun/Features/Shell/SidebarView.swift b/src/apps/mobile/ios/OpenBitFun/Features/Shell/SidebarView.swift index d4e27b0..2411668 100644 --- a/src/apps/mobile/ios/OpenBitFun/Features/Shell/SidebarView.swift +++ b/src/apps/mobile/ios/OpenBitFun/Features/Shell/SidebarView.swift @@ -201,6 +201,7 @@ struct SidebarView: View { .background(OpenBitFunTheme.sidebarRaised) .overlay(Circle().stroke(OpenBitFunTheme.sidebarLine, lineWidth: 1)) .clipShape(Circle()) + .contentShape(Rectangle()) } .buttonStyle(.plain) .accessibilityLabel(Text(model.localized("收起侧栏"))) @@ -216,6 +217,7 @@ struct SidebarView: View { .background(OpenBitFunTheme.sidebarRaised) .overlay(Circle().stroke(OpenBitFunTheme.sidebarLine, lineWidth: 0.5)) .clipShape(Circle()) + .contentShape(Rectangle()) .shadow(color: MobileDesignColors.shadowFaint, radius: 9, y: 3) } .buttonStyle(.plain) @@ -247,6 +249,7 @@ struct SidebarView: View { .background(OpenBitFunTheme.sidebarRaised) .overlay(Circle().stroke(OpenBitFunTheme.sidebarLine, lineWidth: 1)) .clipShape(Circle()) + .contentShape(Rectangle()) } .buttonStyle(.plain) .accessibilityLabel(Text(model.localized("收起侧栏"))) @@ -285,13 +288,17 @@ struct SidebarView: View { Spacer() if model.accountUser != nil { Button { model.refreshRemoteDevices() } label: { - if model.accountRefreshing { - ProgressView().controlSize(.small) - } else { - Image(systemName: "arrow.clockwise") - .font(.system(size: 14, weight: .medium)) - .foregroundStyle(OpenBitFunTheme.sidebarMuted) + Group { + if model.accountRefreshing { + ProgressView().controlSize(.small) + } else { + Image(systemName: "arrow.clockwise") + .font(.system(size: 14, weight: .medium)) + .foregroundStyle(OpenBitFunTheme.sidebarMuted) + } } + .frame(width: 40, height: 38) + .contentShape(Rectangle()) } .buttonStyle(.plain) .accessibilityLabel(Text(model.localized("刷新设备"))) @@ -341,6 +348,7 @@ struct SidebarView: View { .font(.system(size: 18, weight: .regular)) .foregroundStyle(selectedDirectoryEntry.online ? OpenBitFunTheme.sidebarInk : OpenBitFunTheme.sidebarSubtle) .frame(width: 34, height: 34) + .contentShape(Rectangle()) } .buttonStyle(.plain) .disabled(!selectedDirectoryEntry.online) @@ -668,6 +676,7 @@ struct SidebarView: View { .font(.system(size: 16, weight: .medium)) .foregroundStyle(OpenBitFunTheme.sidebarMuted) .frame(width: 40, height: 40) + .contentShape(Rectangle()) } .buttonStyle(.plain) .disabled(model.busy) @@ -836,6 +845,7 @@ struct SidebarView: View { .font(.system(size: 17, weight: .regular)) .foregroundStyle(OpenBitFunTheme.sidebarInk) .frame(width: 30, height: 40) + .contentShape(Rectangle()) }) } @@ -987,6 +997,7 @@ private struct SidebarWorkspaceRow: View { .rotationEffect(.degrees(expanded ? 90 : 0)) .opacity(0.62) .frame(width: 24, height: 46) + .contentShape(Rectangle()) } .buttonStyle(.plain) .accessibilityLabel( @@ -1019,6 +1030,7 @@ private struct SidebarWorkspaceRow: View { .font(.system(size: 17, weight: .regular)) .foregroundStyle(OpenBitFunTheme.sidebarInk) .frame(width: 30, height: 40) + .contentShape(Rectangle()) } } } @@ -1107,6 +1119,7 @@ private struct SidebarWorkspaceRow: View { Image(systemName: "ellipsis") .font(.system(size: 13, weight: .medium)).foregroundStyle(OpenBitFunTheme.sidebarMuted) .frame(width: 36, height: 40) + .contentShape(Rectangle()) } .buttonStyle(.plain) .accessibilityLabel(MobileLocalization.text("会话操作")) @@ -1174,6 +1187,7 @@ private struct SidebarWorkspacePickerSheet: View { .frame(width: 40, height: 40) .background(OpenBitFunTheme.soft) .clipShape(Circle()) + .contentShape(Rectangle()) } .buttonStyle(.plain) .accessibilityLabel(Text(MobileLocalization.text("关闭"))) diff --git a/src/apps/mobile/ios/OpenBitFun/Info.plist b/src/apps/mobile/ios/OpenBitFun/Info.plist index 0d103f4..c03c7aa 100644 --- a/src/apps/mobile/ios/OpenBitFun/Info.plist +++ b/src/apps/mobile/ios/OpenBitFun/Info.plist @@ -15,7 +15,7 @@ CFBundleShortVersionString 1.0.0 CFBundleVersion - 2 + 3 CFBundleURLTypes From 5e00a6beaf2028c9b9b115384a37002633509fe6 Mon Sep 17 00:00:00 2001 From: wgqqqqq Date: Mon, 23 Nov 2026 20:46:02 +0800 Subject: [PATCH 3/4] fix(mobile): align remote streaming behavior --- .../mobile/app/ui/chat/ChatMessageBubble.kt | 24 ++++--- .../mobile/app/ui/chat/MarkdownContent.kt | 66 ++++++++++++++++++- .../app/ui/chat/message/MessageBlockList.kt | 1 + .../src/main/ets/model/ChatTimelineModels.ets | 5 +- .../pages/components/ChatMessageBubble.ets | 2 +- .../ets/services/ChatSessionController.ets | 8 ++- .../ets/services/ChatTimelineProjector.ets | 12 +++- .../main/ets/services/ChatTimelineStore.ets | 3 +- .../core/domain/ChatSessionController.kt | 5 +- .../core/domain/ChatTimelineProjector.kt | 15 ++++- .../mobile/core/domain/StatusSemantics.kt | 15 ++++- .../session/ConversationPresentation.kt | 2 +- .../session/ConversationPresentationTest.kt | 26 ++++++++ 13 files changed, 160 insertions(+), 24 deletions(-) diff --git a/src/apps/mobile/android/app/src/main/kotlin/com/openbitfun/mobile/app/ui/chat/ChatMessageBubble.kt b/src/apps/mobile/android/app/src/main/kotlin/com/openbitfun/mobile/app/ui/chat/ChatMessageBubble.kt index 9ca092f..f6b7300 100644 --- a/src/apps/mobile/android/app/src/main/kotlin/com/openbitfun/mobile/app/ui/chat/ChatMessageBubble.kt +++ b/src/apps/mobile/android/app/src/main/kotlin/com/openbitfun/mobile/app/ui/chat/ChatMessageBubble.kt @@ -117,9 +117,19 @@ internal fun ChatMessageBubble( downloadEnabled = downloadEnabled, ), ) + if (row.typing) ChatTypingDots(Modifier) MessageImageGallery(images = row.images, userStyle = false) } + if (row.showRetry) { + ChatMessageRetryAction( + fromUser = fromUser, + enabled = enabled, + onRetry = { onRetry(row) }, + modifier = Modifier, + ) + } + row.timestampMs?.let { timestamp -> val locale = LocalConfiguration.current.locales[0] Text( @@ -131,19 +141,6 @@ internal fun ChatMessageBubble( modifier = Modifier.testTag("chat-message-timestamp"), ) } - - // Two mutually exclusive footnotes about delivery: nothing has arrived - // yet, or the send was refused. - when { - row.showRetry -> ChatMessageRetryAction( - fromUser = fromUser, - enabled = enabled, - onRetry = { onRetry(row) }, - modifier = Modifier, - ) - - row.typing -> ChatTypingDots(Modifier) - } } } @@ -172,6 +169,7 @@ private fun AssistantContent(row: ConversationRow, callbacks: MessageBlockCallba onOpenLink = callbacks.onOpenLink, modifier = Modifier, streaming = row.streaming, + streamKey = row.id, ) FileReferenceCards( text = row.text, diff --git a/src/apps/mobile/android/app/src/main/kotlin/com/openbitfun/mobile/app/ui/chat/MarkdownContent.kt b/src/apps/mobile/android/app/src/main/kotlin/com/openbitfun/mobile/app/ui/chat/MarkdownContent.kt index b2a1981..4477ec4 100644 --- a/src/apps/mobile/android/app/src/main/kotlin/com/openbitfun/mobile/app/ui/chat/MarkdownContent.kt +++ b/src/apps/mobile/android/app/src/main/kotlin/com/openbitfun/mobile/app/ui/chat/MarkdownContent.kt @@ -23,8 +23,12 @@ import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Surface import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope +import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color @@ -54,7 +58,10 @@ import com.openbitfun.mobile.core.feature.markdown.MarkdownBlock import com.openbitfun.mobile.core.feature.markdown.MarkdownInline import com.openbitfun.mobile.core.feature.markdown.MarkdownListItem import com.openbitfun.mobile.core.feature.markdown.MarkdownParser +import kotlinx.coroutines.delay import kotlinx.coroutines.launch +import kotlin.math.ceil +import kotlin.math.min internal const val MARKDOWN_TEST_TAG: String = "markdown" @@ -80,6 +87,63 @@ internal fun MarkdownContent( onOpenLink: (String, String) -> Unit, modifier: Modifier, streaming: Boolean = false, + streamKey: String = "", +) { + if (streaming) { + StreamingMarkdownContent(text, onOpenLink, modifier, streamKey) + return + } + MarkdownContentBody(text, onOpenLink, modifier, copyFullText = null) +} + +private val streamingMarkdownCache = mutableMapOf() + +@Composable +private fun StreamingMarkdownContent( + text: String, + onOpenLink: (String, String) -> Unit, + modifier: Modifier, + streamKey: String, +) { + val key = streamKey.ifBlank { "default" } + var visible by remember(key) { mutableStateOf(streamingMarkdownCache[key].orEmpty()) } + var target by remember(key) { mutableStateOf(visible) } + + LaunchedEffect(key, text) { + if (!text.startsWith(visible) || !text.startsWith(target)) { + visible = text + target = text + streamingMarkdownCache[key] = text + return@LaunchedEffect + } + target = text + while (visible != target) { + delay(40) + if (!text.startsWith(visible)) { + visible = text + target = text + break + } + val visiblePoints = visible.codePointCount(0, visible.length) + val targetPoints = target.codePointCount(0, target.length) + val remaining = targetPoints - visiblePoints + val step = maxOf(1, ceil(remaining.toDouble() / 35.0).toInt()) + val nextPoints = min(targetPoints, visiblePoints + step) + visible = target.substring(0, target.offsetByCodePoints(0, nextPoints)) + streamingMarkdownCache[key] = visible + } + streamingMarkdownCache[key] = visible + } + + MarkdownContentBody(visible, onOpenLink, modifier, copyFullText = target) +} + +@Composable +private fun MarkdownContentBody( + text: String, + onOpenLink: (String, String) -> Unit, + modifier: Modifier, + copyFullText: String?, ) { val blocks = remember(text) { MarkdownParser.parse(text) } Column( @@ -90,7 +154,7 @@ internal fun MarkdownContent( MarkdownBlockView( block = block, onOpenLink = onOpenLink, - copyFullText = if (streaming) text else null, + copyFullText = copyFullText, ) } } diff --git a/src/apps/mobile/android/app/src/main/kotlin/com/openbitfun/mobile/app/ui/chat/message/MessageBlockList.kt b/src/apps/mobile/android/app/src/main/kotlin/com/openbitfun/mobile/app/ui/chat/message/MessageBlockList.kt index 8328ffd..4de9077 100644 --- a/src/apps/mobile/android/app/src/main/kotlin/com/openbitfun/mobile/app/ui/chat/message/MessageBlockList.kt +++ b/src/apps/mobile/android/app/src/main/kotlin/com/openbitfun/mobile/app/ui/chat/message/MessageBlockList.kt @@ -127,6 +127,7 @@ private fun MessageBlockView(block: MessageBlock, callbacks: MessageBlockCallbac onOpenLink = callbacks.onOpenLink, modifier = Modifier, streaming = block.streaming, + streamKey = block.id, ) FileReferenceCards( text = block.text, diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/model/ChatTimelineModels.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/model/ChatTimelineModels.ets index a414fc3..ba39030 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/model/ChatTimelineModels.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/model/ChatTimelineModels.ets @@ -138,8 +138,11 @@ export class ChatTimelineRevisionTracker { `${message ? ChatTimelineRevisionTracker.textSignature(message.text) : ''}:` + `${message && message.error ? ChatTimelineRevisionTracker.textSignature(message.error) : ''}:` + `${message && message.thinking ? ChatTimelineRevisionTracker.textSignature(message.thinking) : ''}:` + + `${message && message.detail ? ChatTimelineRevisionTracker.textSignature(message.detail) : ''}:` + `${message && message.appCard ? JSON.stringify(message.appCard) : ''}:` + - `${message && message.items ? message.items.length : 0}:${message && message.tools ? message.tools.length : 0}`; + `${message && message.items ? JSON.stringify(message.items) : ''}:` + + `${message && message.tools ? JSON.stringify(message.tools) : ''}:` + + `${message && message.images ? JSON.stringify(message.images) : ''}`; } update(items: ChatTimelineItem[]): number { diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/ChatMessageBubble.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/ChatMessageBubble.ets index 35c9f1b..0dc57b9 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/ChatMessageBubble.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/ChatMessageBubble.ets @@ -549,7 +549,7 @@ export struct ChatMessageBubble { } private shouldShowTypingDots(item: ConversationUiMessage): boolean { - if (item.role === 'user' || (item.status || '').toLowerCase() !== 'active') { + if (item.role === 'user' || (!this.isStreaming && (item.status || '').toLowerCase() !== 'active')) { return false; } return this.visibleMessageText(item).length === 0 && diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/services/ChatSessionController.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/services/ChatSessionController.ets index 76a7f11..1d6c587 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/services/ChatSessionController.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/services/ChatSessionController.ets @@ -224,7 +224,7 @@ export class ChatSessionController { let active: ChatMessage | undefined = undefined; this.completedTurnId = ''; this.subagents.decorate(transcript).forEach((message: ChatMessage) => { - if (message.role === 'assistant' && (message.status === 'active' || message.status === 'running')) active = message; + if (message.role === 'assistant' && ChatSessionController.isActiveTurnStatus(message.status)) active = message; else { persisted.push(message); if (message.role === 'assistant') { @@ -246,4 +246,10 @@ export class ChatSessionController { promptSuggestion: active ? '' : suggestion }); } + + private static isActiveTurnStatus(status: string): boolean { + return ['active', 'inprogress', 'starting', 'running', 'streaming', 'thinking', + 'tool_calling', 'pending_confirmation', 'capability_required', 'finishing'] + .indexOf((status || '').toLowerCase()) >= 0; + } } diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/services/ChatTimelineProjector.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/services/ChatTimelineProjector.ets index 6aff7f3..50c2a7d 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/services/ChatTimelineProjector.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/services/ChatTimelineProjector.ets @@ -91,17 +91,25 @@ export class ChatTimelineProjector { private static activeTurnItem(activeTurn: ChatMessage): ChatTimelineItem { const turnKey = ChatTimelineProjector.activeTurnKey(activeTurn); + const status = (activeTurn.status || '').toLowerCase(); const item: ChatTimelineItem = { id: `active-${turnKey}`, type: 'assistant_live_turn', message: activeTurn, - isStreaming: (activeTurn.status || '').toLowerCase() === 'active', - isFinalizing: (activeTurn.status || '').toLowerCase() === 'completed', + isStreaming: ChatTimelineProjector.isStreamingStatus(status), + isFinalizing: status === 'completed', showRetryAction: false }; return item; } + private static isStreamingStatus(status: string): boolean { + return [ + 'active', 'inprogress', 'starting', 'running', 'streaming', 'thinking', + 'tool_calling', 'pending_confirmation', 'capability_required', 'finishing' + ].indexOf(status) >= 0; + } + private static markLatestFailedMessageRetryable(items: ChatTimelineItem[]): void { for (let index = items.length - 1; index >= 0; index--) { const message = items[index].message; diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/services/ChatTimelineStore.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/services/ChatTimelineStore.ets index ca620b6..5597d81 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/services/ChatTimelineStore.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/services/ChatTimelineStore.ets @@ -759,7 +759,8 @@ export class ChatTimelineStore { return fallback === 'sending' ? 'sending' : 'idle'; } const status = (activeTurn.status || '').toLowerCase(); - if (status === 'active') { + if (['active', 'inprogress', 'starting', 'running', 'streaming', 'thinking', + 'tool_calling', 'pending_confirmation', 'capability_required', 'finishing'].indexOf(status) >= 0) { return 'streaming'; } if (status === 'completed') { diff --git a/src/apps/mobile/shared/core-domain/src/commonMain/kotlin/com/openbitfun/mobile/core/domain/ChatSessionController.kt b/src/apps/mobile/shared/core-domain/src/commonMain/kotlin/com/openbitfun/mobile/core/domain/ChatSessionController.kt index 025a615..6d8c313 100644 --- a/src/apps/mobile/shared/core-domain/src/commonMain/kotlin/com/openbitfun/mobile/core/domain/ChatSessionController.kt +++ b/src/apps/mobile/shared/core-domain/src/commonMain/kotlin/com/openbitfun/mobile/core/domain/ChatSessionController.kt @@ -209,7 +209,10 @@ public class ChatSessionController internal constructor( } private fun isRunningTurn(turn: ChatMessage?): Boolean = - turn != null && turn.id.isNotEmpty() && turn.status.lowercase() == "active" + turn != null && turn.id.isNotEmpty() && turn.status.lowercase() in setOf( + "active", "inprogress", "starting", "running", "streaming", "thinking", + "tool_calling", "pending_confirmation", "capability_required", "finishing", + ) private fun nowMs(): Long = Clock.System.now().toEpochMilliseconds() diff --git a/src/apps/mobile/shared/core-domain/src/commonMain/kotlin/com/openbitfun/mobile/core/domain/ChatTimelineProjector.kt b/src/apps/mobile/shared/core-domain/src/commonMain/kotlin/com/openbitfun/mobile/core/domain/ChatTimelineProjector.kt index f3c6d64..3acb85e 100644 --- a/src/apps/mobile/shared/core-domain/src/commonMain/kotlin/com/openbitfun/mobile/core/domain/ChatTimelineProjector.kt +++ b/src/apps/mobile/shared/core-domain/src/commonMain/kotlin/com/openbitfun/mobile/core/domain/ChatTimelineProjector.kt @@ -63,8 +63,13 @@ public object ChatTimelineProjector { val timelineMessages = realMessages(messages) val pendingItems = pendingMessagesNotPersisted(pendingMessages, timelineMessages) val renderActiveTurn = activeTurn?.takeIf { shouldRenderActiveTurn(timelineMessages, it) } + val renderedMessages = if (renderActiveTurn != null) { + timelineMessages.filterNot { message -> isMatchingAssistantTurn(renderActiveTurn, message) } + } else { + timelineMessages + } val anchorIndex = anchorIndex(pendingItems, activeTurnAnchorId) - val items = timelineMessages.map { message -> + val items = renderedMessages.map { message -> ChatTimelineItem( id = "message-${message.id}", type = messageItemType(message), @@ -168,6 +173,14 @@ public object ChatTimelineProjector { activeTurn.turnId == message.turnId } + private fun isMatchingAssistantTurn(activeTurn: ChatMessage, message: ChatMessage): Boolean { + if (message.role != "assistant") return false + if (message.id == activeTurn.id) return true + if (!activeTurn.turnId.isNullOrEmpty() && message.id == "${activeTurn.turnId}_assistant") return true + return !activeTurn.turnId.isNullOrEmpty() && !message.turnId.isNullOrEmpty() && + activeTurn.turnId == message.turnId + } + private fun hasDisplayableAssistantFinal(message: ChatMessage): Boolean { val text = message.text.trim() if (text.isNotEmpty() && text != message.thinking.orEmpty().trim()) return true diff --git a/src/apps/mobile/shared/core-domain/src/commonMain/kotlin/com/openbitfun/mobile/core/domain/StatusSemantics.kt b/src/apps/mobile/shared/core-domain/src/commonMain/kotlin/com/openbitfun/mobile/core/domain/StatusSemantics.kt index 9054cb2..8b53548 100644 --- a/src/apps/mobile/shared/core-domain/src/commonMain/kotlin/com/openbitfun/mobile/core/domain/StatusSemantics.kt +++ b/src/apps/mobile/shared/core-domain/src/commonMain/kotlin/com/openbitfun/mobile/core/domain/StatusSemantics.kt @@ -2,7 +2,7 @@ package com.openbitfun.mobile.core.domain /** Message-only interpretations of the relay's raw status value. */ internal object MessageStatusSemantics { - fun isStreaming(status: String): Boolean = status.normalized() == "active" + fun isStreaming(status: String): Boolean = status.normalized() in STREAMING_STATUSES fun isFinalizing(status: String): Boolean = status.normalized() == "completed" @@ -10,6 +10,19 @@ internal object MessageStatusSemantics { fun shouldHoldCompletedTurn(status: String): Boolean = status.normalized() in setOf("completed", "done", "success") + + private val STREAMING_STATUSES = setOf( + "active", + "inprogress", + "starting", + "running", + "streaming", + "thinking", + "tool_calling", + "pending_confirmation", + "capability_required", + "finishing", + ) } /** Tool-only ordering used to reject stale snapshots. */ diff --git a/src/apps/mobile/shared/core-feature/src/commonMain/kotlin/com/openbitfun/mobile/core/feature/session/ConversationPresentation.kt b/src/apps/mobile/shared/core-feature/src/commonMain/kotlin/com/openbitfun/mobile/core/feature/session/ConversationPresentation.kt index 6c84357..8dc03f5 100644 --- a/src/apps/mobile/shared/core-feature/src/commonMain/kotlin/com/openbitfun/mobile/core/feature/session/ConversationPresentation.kt +++ b/src/apps/mobile/shared/core-feature/src/commonMain/kotlin/com/openbitfun/mobile/core/feature/session/ConversationPresentation.kt @@ -354,4 +354,4 @@ private fun toolPhase(tool: RemoteToolStatusResponse): ToolPhase = when { else -> ToolPhase.WAITING } -private val NON_TEXT_ITEM_TYPES = setOf("thinking", "tool", "subagent", "agent") +private val NON_TEXT_ITEM_TYPES = setOf("thinking", "tool", "subagent", "agent", "user-steering") diff --git a/src/apps/mobile/shared/core-feature/src/commonTest/kotlin/com/openbitfun/mobile/core/feature/session/ConversationPresentationTest.kt b/src/apps/mobile/shared/core-feature/src/commonTest/kotlin/com/openbitfun/mobile/core/feature/session/ConversationPresentationTest.kt index 3cb6ef8..45715e6 100644 --- a/src/apps/mobile/shared/core-feature/src/commonTest/kotlin/com/openbitfun/mobile/core/feature/session/ConversationPresentationTest.kt +++ b/src/apps/mobile/shared/core-feature/src/commonTest/kotlin/com/openbitfun/mobile/core/feature/session/ConversationPresentationTest.kt @@ -60,6 +60,32 @@ class ConversationPresentationTest { ) } + @Test + fun aStreamingStatusKeepsTheLiveRowAndTypingIndicatorActive() { + val row = timeline( + activeTurn = message("turn-streaming", "assistant", "").copy(status = "streaming"), + ).conversationRows().single() + + assertTrue(row.live) + assertTrue(row.streaming) + assertTrue(row.typing) + } + + @Test + fun anActiveTurnReplacesItsPersistedAssistantStub() { + val rows = timeline( + persisted = listOf( + message("user-1", "user", "Please check"), + message("turn-1_assistant", "assistant", "", thinking = "Still checking") + .copy(turnId = "turn-1"), + ), + activeTurn = message("active-turn-1", "assistant", "", thinking = "Still checking") + .copy(status = "streaming", turnId = "turn-1"), + ).conversationRows() + + assertEquals(listOf("message-user-1", "active-turn-1"), rows.map { it.id }) + } + @Test fun aMessageStillInFlightIsShownOnceUntilItsTwinArrives() { val optimistic = timeline(optimistic = listOf(message("local-1", "user", "ship it"))) From 75aabd5a4e541bae222ae61e52d27e4c259971ad Mon Sep 17 00:00:00 2001 From: wgqqqqq Date: Mon, 23 Nov 2026 20:51:57 +0800 Subject: [PATCH 4/4] fix(mobile): preserve finalizing transcript stubs --- .../entry/src/main/ets/services/ChatTimelineProjector.ets | 4 +++- .../openbitfun/mobile/core/domain/ChatTimelineProjector.kt | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/services/ChatTimelineProjector.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/services/ChatTimelineProjector.ets index 50c2a7d..23fcfa9 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/services/ChatTimelineProjector.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/services/ChatTimelineProjector.ets @@ -24,7 +24,9 @@ export class ChatTimelineProjector { // one visual row and share one stable turn key, so retaining both would // violate the uniqueness contract required by Repeat.virtualScroll(). const timelineMessages = shouldRenderActiveTurn ? persistedMessages.filter((message: ChatMessage) => { - return !ChatTimelineProjector.isMatchingAssistantTurn(activeTurn, message); + if (!ChatTimelineProjector.isMatchingAssistantTurn(activeTurn, message)) return true; + return !(ChatTimelineProjector.isStreamingStatus((activeTurn.status || '').toLowerCase()) || + ChatTimelineProjector.hasDisplayableAssistantFinal(message)); }) : persistedMessages; const pendingItems = ChatTimelineProjector.pendingMessagesNotPersisted(pendingMessages, timelineMessages); const anchorIndex = ChatTimelineProjector.anchorIndex(pendingItems, activeTurnAnchorId); diff --git a/src/apps/mobile/shared/core-domain/src/commonMain/kotlin/com/openbitfun/mobile/core/domain/ChatTimelineProjector.kt b/src/apps/mobile/shared/core-domain/src/commonMain/kotlin/com/openbitfun/mobile/core/domain/ChatTimelineProjector.kt index 3acb85e..b9a4a83 100644 --- a/src/apps/mobile/shared/core-domain/src/commonMain/kotlin/com/openbitfun/mobile/core/domain/ChatTimelineProjector.kt +++ b/src/apps/mobile/shared/core-domain/src/commonMain/kotlin/com/openbitfun/mobile/core/domain/ChatTimelineProjector.kt @@ -64,7 +64,10 @@ public object ChatTimelineProjector { val pendingItems = pendingMessagesNotPersisted(pendingMessages, timelineMessages) val renderActiveTurn = activeTurn?.takeIf { shouldRenderActiveTurn(timelineMessages, it) } val renderedMessages = if (renderActiveTurn != null) { - timelineMessages.filterNot { message -> isMatchingAssistantTurn(renderActiveTurn, message) } + timelineMessages.filterNot { message -> + isMatchingAssistantTurn(renderActiveTurn, message) && + (MessageStatusSemantics.isStreaming(renderActiveTurn.status) || hasDisplayableAssistantFinal(message)) + } } else { timelineMessages }