Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

fix(ensu): clean up defaults and iOS settings flows

Prateek Sunal4ea43ec7ea40
diff --git a/mobile/native/darwin/Apps/ensu/ensu/Chat/ChatViewModel.swift b/mobile/native/darwin/Apps/ensu/ensu/Chat/ChatViewModel.swift
index b893707e50..3bab90cbec 100644
--- a/mobile/native/darwin/Apps/ensu/ensu/Chat/ChatViewModel.swift
+++ b/mobile/native/darwin/Apps/ensu/ensu/Chat/ChatViewModel.swift
@@ -1787,18 +1787,24 @@ final class ChatViewModel: ObservableObject {
if let progress {
emptyPollCount = 0
- self.handleProgress(progress)
+ await MainActor.run {
+ self.handleProgress(progress)
+ }
} else {
emptyPollCount += 1
}
if isDownloaded {
- self.refreshModelDownloadInfo()
+ await MainActor.run {
+ self.refreshModelDownloadInfo()
+ }
return
}
if emptyPollCount >= 6 {
- self.refreshModelDownloadInfo()
+ await MainActor.run {
+ self.refreshModelDownloadInfo()
+ }
return
}
@@ -2213,7 +2219,7 @@ final class ChatViewModel: ObservableObject {
let isLastAndGenerating = i == messages.count - 1 && isGenerating
if next?.role != .assistant && !isLastAndGenerating {
augmented.append(ChatMessage(
- id: UUID(),
+ id: deterministicSyntheticMessageId(parentId: msg.id),
role: .assistant,
text: "Response was interrupted",
timestamp: msg.timestamp,
@@ -2226,6 +2232,13 @@ final class ChatViewModel: ObservableObject {
messages = augmented
}
+ private func deterministicSyntheticMessageId(parentId: UUID) -> UUID {
+ var uuid = parentId.uuid
+ uuid.0 ^= 0xA5
+ uuid.15 ^= 0x5A
+ return UUID(uuid: uuid)
+ }
+
private func buildSelectedPath(for sessionId: UUID, childrenMap: [UUID: [MessageNode]]) -> [MessageNode] {
guard let nodes = messageStore[sessionId], !nodes.isEmpty else { return [] }
let byId = Dictionary(uniqueKeysWithValues: nodes.map { ($0.id, $0) })
diff --git a/mobile/native/darwin/Apps/ensu/ensu/Components/EnsuComponents.swift b/mobile/native/darwin/Apps/ensu/ensu/Components/EnsuComponents.swift
index 0eda641725..84c42c1807 100644
--- a/mobile/native/darwin/Apps/ensu/ensu/Components/EnsuComponents.swift
+++ b/mobile/native/darwin/Apps/ensu/ensu/Components/EnsuComponents.swift
@@ -191,6 +191,28 @@ struct ToastView: View {
}
}
+@MainActor
+func presentToast(
+ _ message: String,
+ setToastMessage: @escaping (String?) -> Void,
+ duration: TimeInterval = 1.5
+) -> Task<Void, Never> {
+ withAnimation(.easeOut(duration: 0.2)) {
+ setToastMessage(message)
+ }
+ let nanoseconds = UInt64(max(0, duration) * 1_000_000_000)
+ return Task { @MainActor in
+ do {
+ try await Task.sleep(nanoseconds: nanoseconds)
+ } catch {
+ return
+ }
+ withAnimation(.easeIn(duration: 0.2)) {
+ setToastMessage(nil)
+ }
+ }
+}
+
struct MacSheetHeader<Leading: View, Center: View, Trailing: View>: View {
let leading: Leading
let center: Center
diff --git a/mobile/native/darwin/Apps/ensu/ensu/Info.plist b/mobile/native/darwin/Apps/ensu/ensu/Info.plist
index d3cedb63d9..4df95f9162 100644
--- a/mobile/native/darwin/Apps/ensu/ensu/Info.plist
+++ b/mobile/native/darwin/Apps/ensu/ensu/Info.plist
@@ -24,7 +24,7 @@
<string>0.1.10</string>
<key>CFBundleVersion</key>
- <string>25</string>
+ <string>26</string>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
diff --git a/mobile/native/darwin/Apps/ensu/ensu/ModelSettings/ModelSettingsView.swift b/mobile/native/darwin/Apps/ensu/ensu/ModelSettings/ModelSettingsView.swift
index 3e7d316698..59d02a027d 100644
--- a/mobile/native/darwin/Apps/ensu/ensu/ModelSettings/ModelSettingsView.swift
+++ b/mobile/native/darwin/Apps/ensu/ensu/ModelSettings/ModelSettingsView.swift
@@ -336,7 +336,8 @@ struct ModelSettingsView: View {
guard validate() else { return }
isSaving = true
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
+ Task { @MainActor in
+ try? await Task.sleep(nanoseconds: 200_000_000)
if selectedModel.isDefault {
settings.useCustomModel = false
settings.modelUrl = ""
@@ -362,7 +363,10 @@ struct ModelSettingsView: View {
)
}
isSaving = false
- showToast("Model settings saved")
+ toastTask?.cancel()
+ toastTask = presentToast("Model settings saved") { message in
+ toastMessage = message
+ }
}
}
@@ -374,22 +378,10 @@ struct ModelSettingsView: View {
contextLength = ""
maxTokens = ""
temperature = ""
- showToast("Model settings reset")
- }
-
- private func showToast(_ message: String) {
toastTask?.cancel()
- withAnimation(.easeOut(duration: 0.2)) {
+ toastTask = presentToast("Model settings reset") { message in
toastMessage = message
}
- toastTask = Task { @MainActor in
- try? await Task.sleep(nanoseconds: 1_500_000_000)
- guard !Task.isCancelled else { return }
- withAnimation(.easeIn(duration: 0.2)) {
- toastMessage = nil
- }
- toastTask = nil
- }
}
private func validate() -> Bool {
diff --git a/mobile/native/darwin/Apps/ensu/ensu/Services/ModelDownloadManager.swift b/mobile/native/darwin/Apps/ensu/ensu/Services/ModelDownloadManager.swift
index a4c0496b54..eb505a49be 100644
--- a/mobile/native/darwin/Apps/ensu/ensu/Services/ModelDownloadManager.swift
+++ b/mobile/native/darwin/Apps/ensu/ensu/Services/ModelDownloadManager.swift
@@ -28,6 +28,12 @@ final class ModelDownloadManager: NSObject {
private let recordsKey = "ensu.model.download.records"
private let syncQueue = DispatchQueue(label: "io.ente.ensu.model-download-manager")
+ private let delegateQueue: OperationQueue = {
+ let queue = OperationQueue()
+ queue.name = "io.ente.ensu.model-download-manager.delegate"
+ queue.maxConcurrentOperationCount = 1
+ return queue
+ }()
private lazy var session: URLSession = {
let configuration: URLSessionConfiguration
configuration = URLSessionConfiguration.background(withIdentifier: "io.ente.ensu.model-downloads")
@@ -35,8 +41,8 @@ final class ModelDownloadManager: NSObject {
configuration.sessionSendsLaunchEvents = true
#endif
configuration.isDiscretionary = false
- configuration.waitsForConnectivity = true
- return URLSession(configuration: configuration, delegate: self, delegateQueue: nil)
+ configuration.waitsForConnectivity = true
+ return URLSession(configuration: configuration, delegate: self, delegateQueue: delegateQueue)
}()
private var backgroundCompletionHandler: (() -> Void)?
diff --git a/mobile/native/darwin/Apps/ensu/ensu/Settings/SettingsView.swift b/mobile/native/darwin/Apps/ensu/ensu/Settings/SettingsView.swift
index e774a3b409..7041231344 100644
--- a/mobile/native/darwin/Apps/ensu/ensu/Settings/SettingsView.swift
+++ b/mobile/native/darwin/Apps/ensu/ensu/Settings/SettingsView.swift
@@ -296,22 +296,10 @@ struct SettingsView: View {
EnsuAdvancedSettings.unlock()
isAdvancedUnlocked = true
buildVersionTapCount = 0
- showToast("Advanced settings unlocked")
- }
-
- private func showToast(_ message: String) {
toastTask?.cancel()
- withAnimation(.easeOut(duration: 0.2)) {
+ toastTask = presentToast("Advanced settings unlocked") { message in
toastMessage = message
}
- toastTask = Task { @MainActor in
- try? await Task.sleep(nanoseconds: 1_500_000_000)
- guard !Task.isCancelled else { return }
- withAnimation(.easeIn(duration: 0.2)) {
- toastMessage = nil
- }
- toastTask = nil
- }
}
private func openExternalLink(_ urlString: String) {
@@ -370,6 +358,8 @@ private struct SystemPromptSettingsView: View {
@ObservedObject private var settings = ModelSettingsStore.shared
@State private var promptBody: String = ""
@State private var isSaving = false
+ @State private var toastMessage: String?
+ @State private var toastTask: Task<Void, Never>?
init(embeddedInNavigation: Bool = false) {
self.embeddedInNavigation = embeddedInNavigation
@@ -413,6 +403,13 @@ private struct SystemPromptSettingsView: View {
.onAppear {
promptBody = ModelSettingsStore.resolveSystemPromptBody(settings.systemPromptBody)
}
+ .overlay(alignment: .bottom) {
+ if let toastMessage {
+ ToastView(message: toastMessage)
+ .padding(.bottom, EnsuSpacing.xl)
+ .transition(.move(edge: .bottom).combined(with: .opacity))
+ }
+ }
#if os(macOS)
.safeAreaInset(edge: .top) {
if embeddedInNavigation {
@@ -491,18 +488,27 @@ private struct SystemPromptSettingsView: View {
private func saveTapped() {
isSaving = true
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
+ Task { @MainActor in
+ try? await Task.sleep(nanoseconds: 200_000_000)
let trimmedPrompt = promptBody.trimmingCharacters(in: .whitespacesAndNewlines)
let defaultPrompt = ModelSettingsStore.defaultSystemPromptBody.trimmingCharacters(in: .whitespacesAndNewlines)
settings.systemPromptBody = trimmedPrompt == defaultPrompt ? "" : trimmedPrompt
promptBody = ModelSettingsStore.resolveSystemPromptBody(settings.systemPromptBody)
isSaving = false
+ toastTask?.cancel()
+ toastTask = presentToast("Prompt saved") { message in
+ toastMessage = message
+ }
}
}
private func resetTapped() {
settings.systemPromptBody = ""
promptBody = ModelSettingsStore.defaultSystemPromptBody
+ toastTask?.cancel()
+ toastTask = presentToast("Prompt reset") { message in
+ toastMessage = message
+ }
}
}
diff --git a/rust/ensu/inference/src/defaults.rs b/rust/ensu/inference/src/defaults.rs
index 43a51178d4..f678908ff0 100644
--- a/rust/ensu/inference/src/defaults.rs
+++ b/rust/ensu/inference/src/defaults.rs
@@ -29,7 +29,7 @@ fn lfm_vl_1_6b() -> EnsuModelPreset {
EnsuModelPreset {
id: "lfm-vl-1.6b".to_string(),
title: "LFM 2.5 VL 1.6B (Q4_0)".to_string(),
- url: "https://huggingface.co/LiquidAI/LFM2.5-VL-1.6B-GGUF/resolve/main/LFM2.5-VL-1.6B-Q4_0.gguf".to_string(),
+ url: "https://huggingface.co/LiquidAI/LFM2.5-VL-1.6B-GGUF/resolve/main/LFM2.5-VL-1.6B-Q4_0.gguf?download=true".to_string(),
mmproj_url: Some(
"https://huggingface.co/LiquidAI/LFM2.5-VL-1.6B-GGUF/resolve/main/mmproj-LFM2.5-VL-1.6b-Q8_0.gguf"
.to_string(),
@@ -41,7 +41,7 @@ fn lfm_1_2b() -> EnsuModelPreset {
EnsuModelPreset {
id: "lfm-1.2b".to_string(),
title: "LFM 2.5 1.2B Instruct (Q4_0)".to_string(),
- url: "https://huggingface.co/LiquidAI/LFM2.5-1.2B-GGUF/resolve/main/LFM2.5-1.2B-Q4_0.gguf".to_string(),
+ url: "https://huggingface.co/LiquidAI/LFM2.5-1.2B-GGUF/resolve/main/LFM2.5-1.2B-Q4_0.gguf?download=true".to_string(),
mmproj_url: None,
}
}
diff --git a/web/apps/ensu/src/components/chat/ChatMessageList.tsx b/web/apps/ensu/src/components/chat/ChatMessageList.tsx
index f0c5203321..1050357386 100644
--- a/web/apps/ensu/src/components/chat/ChatMessageList.tsx
+++ b/web/apps/ensu/src/components/chat/ChatMessageList.tsx
@@ -178,8 +178,9 @@ const MessageRow = memo(
}: MessageRowProps) => {
const isSelf = message.sender === "self";
const isStreaming = message.messageUuid === STREAMING_SELECTION_KEY;
+ const isSynthetic = !!message.isSynthetic;
const switcher = branchSwitchers[message.messageUuid];
- const showSwitcher = !!switcher && switcher.total > 1;
+ const showSwitcher = !isSynthetic && !!switcher && switcher.total > 1;
const timestamp = formatTime(message.createdAt);
const attachments = message.attachments ?? [];
const assistantMessagePaddingX = "8px";
@@ -335,7 +336,7 @@ const MessageRow = memo(
alignSelf: isSelf ? "flex-end" : "flex-start",
}}
>
- {isStreaming ? null : isSelf ? (
+ {isStreaming || isSynthetic ? null : isSelf ? (
<>
<IconButton
aria-label="Edit"
@@ -384,7 +385,7 @@ const MessageRow = memo(
)}
</Stack>
- {isStreaming ? null : (
+ {isStreaming || isSynthetic ? null : (
<Stack
direction="row"
sx={{
diff --git a/web/apps/ensu/src/pages/chat.tsx b/web/apps/ensu/src/pages/chat.tsx
index dba835fca3..8f9e9594c1 100644
--- a/web/apps/ensu/src/pages/chat.tsx
+++ b/web/apps/ensu/src/pages/chat.tsx
@@ -1900,6 +1900,7 @@ const Page: React.FC = () => {
sender: "assistant",
text: "Response was interrupted",
createdAt: msg.createdAt,
+ isSynthetic: true,
});
}
}
diff --git a/web/apps/ensu/src/services/chat/store.ts b/web/apps/ensu/src/services/chat/store.ts
index e730631656..7d1d0f5cba 100644
--- a/web/apps/ensu/src/services/chat/store.ts
+++ b/web/apps/ensu/src/services/chat/store.ts
@@ -139,6 +139,7 @@ export interface ChatMessage {
text: string;
createdAt: number;
attachments?: ChatAttachment[];
+ isSynthetic?: boolean;
}
export interface LocalSessionRecord {
diff --git a/web/apps/ensu/src/services/llm/provider.ts b/web/apps/ensu/src/services/llm/provider.ts
index 2902f67bce..47feeb525f 100644
--- a/web/apps/ensu/src/services/llm/provider.ts
+++ b/web/apps/ensu/src/services/llm/provider.ts
@@ -19,7 +19,7 @@ const MIN_HIGH_RAM_MAC_BYTES = 16 * 1024 * 1024 * 1024;
export const DEFAULT_MODEL: ModelInfo = {
id: "lfm-2.5-vl-1.6b",
name: "LFM 2.5 VL 1.6B (Q4_0)",
- url: "https://huggingface.co/LiquidAI/LFM2.5-VL-1.6B-GGUF/resolve/main/LFM2.5-VL-1.6B-Q4_0.gguf",
+ url: "https://huggingface.co/LiquidAI/LFM2.5-VL-1.6B-GGUF/resolve/main/LFM2.5-VL-1.6B-Q4_0.gguf?download=true",
mmprojUrl:
"https://huggingface.co/LiquidAI/LFM2.5-VL-1.6B-GGUF/resolve/main/mmproj-LFM2.5-VL-1.6b-Q8_0.gguf",
sizeBytes: 695_752_160,
@@ -27,8 +27,6 @@ export const DEFAULT_MODEL: ModelInfo = {
sizeHuman: "~664 MB",
};
-const TAURI_DEFAULT_MODEL: ModelInfo = DEFAULT_MODEL;
-
const DESKTOP_DEFAULT_MODEL: ModelInfo = {
id: "qwen-3.5-4b-q4km",
name: "Qwen 3.5 4B (Q4_K_M)",
@@ -354,8 +352,7 @@ export class LlmProvider {
}
private async resolveDefaultModelForDevice() {
- this.defaultModel =
- this.backend.kind === "tauri" ? TAURI_DEFAULT_MODEL : DEFAULT_MODEL;
+ this.defaultModel = DEFAULT_MODEL;
if (this.backend.kind !== "tauri") {
return;