Skip to content

armgit / ente

Public Imported from GitHub
0

💚 End-to-end encrypted cloud for everything.

Inline Apple inference bindings into ensu app

Manav Rathib198d0c7af14
diff --git a/.gitignore b/.gitignore
index 21031a7296..56488286c1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -35,10 +35,3 @@ mobile/native/android/packages/rust/src/main/kotlin/io/ente/labs/llmchat_db/llmc
mobile/native/android/packages/rust/src/main/kotlin/io/ente/labs/ensu_db/db.kt
mobile/native/android/packages/rust/src/main/kotlin/io/ente/labs/llmchat_sync/llmchat_sync_uniffi.kt
mobile/native/android/packages/rust/src/main/kotlin/io/ente/labs/ensu_sync/sync.kt
-mobile/native/darwin/Apps/ensu/ensu/Generated/*_uniffi*
-mobile/native/darwin/Apps/ensu/ensu/Generated/core*
-mobile/native/darwin/Apps/ensu/ensu/Generated/db*
-mobile/native/darwin/Apps/ensu/ensu/Generated/sync*
-
-# Local ensu endpoint overrides (compile-time)
-mobile/native/darwin/Apps/ensu/ensu/Generated/EndpointConfig.swift
diff --git a/mobile/native/darwin/Apps/ensu/README.md b/mobile/native/darwin/Apps/ensu/README.md
index b41ee5c234..fc6277eb21 100644
--- a/mobile/native/darwin/Apps/ensu/README.md
+++ b/mobile/native/darwin/Apps/ensu/README.md
@@ -7,7 +7,7 @@ All commands below assume you run them from `darwin/Apps/ensu`.
## Quick scripts
```bash
-./setup-mac.sh # Check prerequisites, build local xcframework, resolve packages
+./setup-mac.sh # Check prerequisites and resolve packages
./build.sh # Debug build for iOS simulator (prefers booted iPhone)
./build.sh device # Debug build for connected iOS device
./build.sh archive # Release archive (.xcarchive)
@@ -28,19 +28,11 @@ Run `./build.sh --help` or `./run.sh --help` for full options.
- SwiftMath is fetched via SwiftPM (`https://github.com/mgriebling/SwiftMath.git`).
- UniFFI Swift bindings are generated locally and gitignored:
- - `ensu/Generated/core*`, `ensu/Generated/db*`, `ensu/Generated/sync*`
- - `../Packages/Rust/Sources/InferenceRS/`
- - `../Packages/Rust/InferenceRSFFI.xcframework`
-
-The Xcode build script (`scripts/build-rust.sh`) builds Rust static libs, but it does
-regenerate the `core`, `db`, and `sync` Swift bindings into `ensu/Generated/` as part of the build.
-`../Packages/Rust/tool/generate_bindings.sh` and `../Packages/Rust/tool/build_xcframework.sh`
-generate the Apple `InferenceRS` package from the shared Rust inference binding crate in
-`rust/uniffi/ensu/inference`. `./build.sh` will build the local `InferenceRSFFI.xcframework`
-automatically if it is missing, then re-resolve Swift package dependencies before building.
-
-If Xcode still shows “Missing package product …” in the IDE, use
-`File > Packages > Resolve Package Versions` after the xcframework has been generated.
+ - `ensu/Generated/core*`, `ensu/Generated/db*`, `ensu/Generated/sync*`, `ensu/Generated/inference*`
+
+The Xcode build script (`scripts/build-rust.sh`) builds the Rust static libs directly into
+`$(TARGET_TEMP_DIR)/ensu_rust` and regenerates the `core`, `db`, `sync`, and `inference`
+Swift bindings into `ensu/Generated/` as part of the build.
### Debug Build (Simulator)
```bash
diff --git a/mobile/native/darwin/Apps/ensu/build.sh b/mobile/native/darwin/Apps/ensu/build.sh
index 2666a73efb..fa45dcb9ae 100755
--- a/mobile/native/darwin/Apps/ensu/build.sh
+++ b/mobile/native/darwin/Apps/ensu/build.sh
@@ -5,8 +5,6 @@ ROOT="$(cd "$(dirname "$0")" && pwd)"
PROJECT="ensu.xcodeproj"
SCHEME="ensu"
DERIVED_DATA_PATH="$ROOT/build"
-INFERENCE_RS_PACKAGE_DIR="$(cd "$ROOT/../../Packages/Rust" && pwd)"
-INFERENCE_RS_XCFRAMEWORK="$INFERENCE_RS_PACKAGE_DIR/InferenceRSFFI.xcframework"
MODE="sim"
DESTINATION_ID=""
@@ -48,18 +46,6 @@ resolve_package_dependencies() {
"${XCODE_EXTRA_ARGS[@]}"
}
-ensure_inference_rs_xcframework() {
- if [[ -d "$INFERENCE_RS_XCFRAMEWORK" ]]; then
- return
- fi
-
- echo "==> Building local InferenceRS xcframework"
- (
- cd "$INFERENCE_RS_PACKAGE_DIR"
- ./tool/build_xcframework.sh
- )
-}
-
usage() {
cat <<'EOF'
Build Ensu Apple app.
@@ -224,7 +210,6 @@ if [[ -n "$ENDPOINT" ]]; then
export ENTE_API_ENDPOINT="$ENDPOINT"
fi
-ensure_inference_rs_xcframework
resolve_package_dependencies
build_archive() {
diff --git a/mobile/native/darwin/Apps/ensu/ensu.xcodeproj/project.pbxproj b/mobile/native/darwin/Apps/ensu/ensu.xcodeproj/project.pbxproj
index a410685291..0979d567d9 100644
--- a/mobile/native/darwin/Apps/ensu/ensu.xcodeproj/project.pbxproj
+++ b/mobile/native/darwin/Apps/ensu/ensu.xcodeproj/project.pbxproj
@@ -8,8 +8,6 @@
/* Begin PBXBuildFile section */
21BBA57867859DAD206D6A46 /* EnteNetwork in Frameworks */ = {isa = PBXBuildFile; productRef = DACC3DC82E618D6A00DAF993 /* EnteNetwork */; };
- DAB0F20D2F5E123400ABCD01 /* InferenceRS in Frameworks */ = {isa = PBXBuildFile; productRef = DAB0F20C2F5E123400ABCD01 /* InferenceRS */; };
- DAB0F20E2F5E123400ABCD01 /* InferenceRS in Frameworks */ = {isa = PBXBuildFile; productRef = DAB0F20C2F5E123400ABCD01 /* InferenceRS */; };
DACC3DC92E618D6A00DAF993 /* EnteNetwork in Frameworks */ = {isa = PBXBuildFile; productRef = DACC3DC82E618D6A00DAF993 /* EnteNetwork */; };
DAF584672E61BB8300F8A08F /* ZIPFoundation in Frameworks */ = {isa = PBXBuildFile; productRef = DAF584662E61BB8300F8A08F /* ZIPFoundation */; };
DAF584682E61BB8300F8A08F /* ZIPFoundation in Frameworks */ = {isa = PBXBuildFile; productRef = DAF584662E61BB8300F8A08F /* ZIPFoundation */; };
@@ -64,7 +62,6 @@
buildActionMask = 2147483647;
files = (
21BBA57867859DAD206D6A46 /* EnteNetwork in Frameworks */,
- DAB0F20E2F5E123400ABCD01 /* InferenceRS in Frameworks */,
DAF584682E61BB8300F8A08F /* ZIPFoundation in Frameworks */,
DBA3E91D2F7A6B9000AA11BB /* SwiftMath in Frameworks */,
DB9F1C3D2F9D123400ABCD02 /* Markdown in Frameworks */,
@@ -77,7 +74,6 @@
buildActionMask = 2147483647;
files = (
DACC3DC92E618D6A00DAF993 /* EnteNetwork in Frameworks */,
- DAB0F20D2F5E123400ABCD01 /* InferenceRS in Frameworks */,
DAF584672E61BB8300F8A08F /* ZIPFoundation in Frameworks */,
DBA3E91C2F7A6B9000AA11BB /* SwiftMath in Frameworks */,
DB9F1C3C2F9D123400ABCD02 /* Markdown in Frameworks */,
@@ -120,7 +116,7 @@
isa = PBXNativeTarget;
buildConfigurationList = DA72BC872E5F87A100D128FF /* Build configuration list for PBXNativeTarget "ensu" */;
buildPhases = (
- CC142736A470612F436ECF8E /* Build Rust (core/db/sync) */,
+ CC142736A470612F436ECF8E /* Build Rust (core/db/sync/inference) */,
DA72BC5D2E5F87A000D128FF /* Sources */,
DA72BC5E2E5F87A000D128FF /* Frameworks */,
DA72BC5F2E5F87A000D128FF /* Resources */,
@@ -135,7 +131,6 @@
name = ensu;
packageProductDependencies = (
DACC3DC82E618D6A00DAF993 /* EnteNetwork */,
- DAB0F20C2F5E123400ABCD01 /* InferenceRS */,
DAF584662E61BB8300F8A08F /* ZIPFoundation */,
DBA3E91B2F7A6B9000AA11BB /* SwiftMath */,
DB9F1C3B2F9D123400ABCD02 /* Markdown */,
@@ -149,7 +144,7 @@
isa = PBXNativeTarget;
buildConfigurationList = 9C5C5C140967470293DCAAF2 /* Build configuration list for PBXNativeTarget "ensu-macos" */;
buildPhases = (
- 25484CE4873ED7217FB27990 /* Build Rust (core/db/sync) */,
+ 25484CE4873ED7217FB27990 /* Build Rust (core/db/sync/inference) */,
BB83D829CC14232E7E8BDD51 /* Sources */,
0BCBB02794980AFFDC386B69 /* Frameworks */,
1FDE2B245F9DADEF5E026D0B /* Resources */,
@@ -164,7 +159,6 @@
name = "ensu-macos";
packageProductDependencies = (
DACC3DC82E618D6A00DAF993 /* EnteNetwork */,
- DAB0F20C2F5E123400ABCD01 /* InferenceRS */,
DAF584662E61BB8300F8A08F /* ZIPFoundation */,
DBA3E91B2F7A6B9000AA11BB /* SwiftMath */,
DB9F1C3B2F9D123400ABCD02 /* Markdown */,
@@ -203,7 +197,6 @@
minimizedProjectReferenceProxies = 1;
packageReferences = (
DACC3DC62E618D5300DAF993 /* XCLocalSwiftPackageReference "../../Packages/EnteNetwork" */,
- DAB0F20B2F5E123400ABCD01 /* XCLocalSwiftPackageReference "../../Packages/Rust" */,
DBA3E91A2F7A6B9000AA11BB /* XCRemoteSwiftPackageReference "SwiftMath" */,
DAF584652E61BB6300F8A08F /* XCRemoteSwiftPackageReference "ZIPFoundation" */,
DB9F1C3A2F9D123400ABCD02 /* XCRemoteSwiftPackageReference "swift-markdown" */,
@@ -238,18 +231,19 @@
/* End PBXResourcesBuildPhase section */
/* Begin PBXShellScriptBuildPhase section */
- 25484CE4873ED7217FB27990 /* Build Rust (core/db/sync) */ = {
+ 25484CE4873ED7217FB27990 /* Build Rust (core/db/sync/inference) */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
- name = "Build Rust (core/db/sync)";
+ name = "Build Rust (core/db/sync/inference)";
outputPaths = (
"$(TARGET_TEMP_DIR)/ensu_rust/libcore.a",
"$(TARGET_TEMP_DIR)/ensu_rust/libdb.a",
"$(TARGET_TEMP_DIR)/ensu_rust/libsync.a",
+ "$(TARGET_TEMP_DIR)/ensu_rust/libinference.a",
"$(SRCROOT)/ensu/Generated/core.swift",
"$(SRCROOT)/ensu/Generated/coreFFI.h",
"$(SRCROOT)/ensu/Generated/coreFFI.modulemap",
@@ -259,23 +253,27 @@
"$(SRCROOT)/ensu/Generated/sync.swift",
"$(SRCROOT)/ensu/Generated/syncFFI.h",
"$(SRCROOT)/ensu/Generated/syncFFI.modulemap",
+ "$(SRCROOT)/ensu/Generated/inference.swift",
+ "$(SRCROOT)/ensu/Generated/inferenceFFI.h",
+ "$(SRCROOT)/ensu/Generated/inferenceFFI.modulemap",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "ENTE_API_ENDPOINT=\"${ENTE_API_ENDPOINT}\" \"${SRCROOT}/scripts/build-rust.sh\"\n";
};
- CC142736A470612F436ECF8E /* Build Rust (core/db/sync) */ = {
+ CC142736A470612F436ECF8E /* Build Rust (core/db/sync/inference) */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
- name = "Build Rust (core/db/sync)";
+ name = "Build Rust (core/db/sync/inference)";
outputPaths = (
"$(TARGET_TEMP_DIR)/ensu_rust/libcore.a",
"$(TARGET_TEMP_DIR)/ensu_rust/libdb.a",
"$(TARGET_TEMP_DIR)/ensu_rust/libsync.a",
+ "$(TARGET_TEMP_DIR)/ensu_rust/libinference.a",
"$(SRCROOT)/ensu/Generated/core.swift",
"$(SRCROOT)/ensu/Generated/coreFFI.h",
"$(SRCROOT)/ensu/Generated/coreFFI.modulemap",
@@ -285,6 +283,9 @@
"$(SRCROOT)/ensu/Generated/sync.swift",
"$(SRCROOT)/ensu/Generated/syncFFI.h",
"$(SRCROOT)/ensu/Generated/syncFFI.modulemap",
+ "$(SRCROOT)/ensu/Generated/inference.swift",
+ "$(SRCROOT)/ensu/Generated/inferenceFFI.h",
+ "$(SRCROOT)/ensu/Generated/inferenceFFI.modulemap",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
@@ -343,12 +344,19 @@
"$(inherited)",
"-framework",
SystemConfiguration,
+ "-framework",
+ Accelerate,
+ "-framework",
+ Metal,
+ "-framework",
+ MetalKit,
"-force_load",
"$(TARGET_TEMP_DIR)/ensu_rust/libcore.a",
"$(TARGET_TEMP_DIR)/ensu_rust/libdb.a",
"$(TARGET_TEMP_DIR)/ensu_rust/libsync.a",
+ "$(TARGET_TEMP_DIR)/ensu_rust/libinference.a",
);
- OTHER_SWIFT_FLAGS = "$(inherited) -Xcc -fmodule-map-file=$(SRCROOT)/ensu/Generated/coreFFI.modulemap -Xcc -fmodule-map-file=$(SRCROOT)/ensu/Generated/dbFFI.modulemap -Xcc -fmodule-map-file=$(SRCROOT)/ensu/Generated/syncFFI.modulemap";
+ OTHER_SWIFT_FLAGS = "$(inherited) -Xcc -fmodule-map-file=$(SRCROOT)/ensu/Generated/coreFFI.modulemap -Xcc -fmodule-map-file=$(SRCROOT)/ensu/Generated/dbFFI.modulemap -Xcc -fmodule-map-file=$(SRCROOT)/ensu/Generated/syncFFI.modulemap -Xcc -fmodule-map-file=$(SRCROOT)/ensu/Generated/inferenceFFI.modulemap";
PRODUCT_BUNDLE_IDENTIFIER = io.ente.ensu;
PRODUCT_NAME = Ensu;
SDKROOT = macosx;
@@ -392,12 +400,19 @@
"$(inherited)",
"-framework",
SystemConfiguration,
+ "-framework",
+ Accelerate,
+ "-framework",
+ Metal,
+ "-framework",
+ MetalKit,
"-force_load",
"$(TARGET_TEMP_DIR)/ensu_rust/libcore.a",
"$(TARGET_TEMP_DIR)/ensu_rust/libdb.a",
"$(TARGET_TEMP_DIR)/ensu_rust/libsync.a",
+ "$(TARGET_TEMP_DIR)/ensu_rust/libinference.a",
);
- OTHER_SWIFT_FLAGS = "$(inherited) -Xcc -fmodule-map-file=$(SRCROOT)/ensu/Generated/coreFFI.modulemap -Xcc -fmodule-map-file=$(SRCROOT)/ensu/Generated/dbFFI.modulemap -Xcc -fmodule-map-file=$(SRCROOT)/ensu/Generated/syncFFI.modulemap";
+ OTHER_SWIFT_FLAGS = "$(inherited) -Xcc -fmodule-map-file=$(SRCROOT)/ensu/Generated/coreFFI.modulemap -Xcc -fmodule-map-file=$(SRCROOT)/ensu/Generated/dbFFI.modulemap -Xcc -fmodule-map-file=$(SRCROOT)/ensu/Generated/syncFFI.modulemap -Xcc -fmodule-map-file=$(SRCROOT)/ensu/Generated/inferenceFFI.modulemap";
PRODUCT_BUNDLE_IDENTIFIER = io.ente.ensu;
PRODUCT_NAME = Ensu;
SDKROOT = macosx;
@@ -565,12 +580,19 @@
MARKETING_VERSION = 0.1.15;
OTHER_LDFLAGS = (
"$(inherited)",
+ "-framework",
+ Accelerate,
+ "-framework",
+ Metal,
+ "-framework",
+ MetalKit,
"-force_load",
"$(TARGET_TEMP_DIR)/ensu_rust/libcore.a",
"$(TARGET_TEMP_DIR)/ensu_rust/libdb.a",
"$(TARGET_TEMP_DIR)/ensu_rust/libsync.a",
+ "$(TARGET_TEMP_DIR)/ensu_rust/libinference.a",
);
- OTHER_SWIFT_FLAGS = "$(inherited) -Xcc -fmodule-map-file=$(SRCROOT)/ensu/Generated/coreFFI.modulemap -Xcc -fmodule-map-file=$(SRCROOT)/ensu/Generated/dbFFI.modulemap -Xcc -fmodule-map-file=$(SRCROOT)/ensu/Generated/syncFFI.modulemap";
+ OTHER_SWIFT_FLAGS = "$(inherited) -Xcc -fmodule-map-file=$(SRCROOT)/ensu/Generated/coreFFI.modulemap -Xcc -fmodule-map-file=$(SRCROOT)/ensu/Generated/dbFFI.modulemap -Xcc -fmodule-map-file=$(SRCROOT)/ensu/Generated/syncFFI.modulemap -Xcc -fmodule-map-file=$(SRCROOT)/ensu/Generated/inferenceFFI.modulemap";
PRODUCT_BUNDLE_IDENTIFIER = io.ente.ensu;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
@@ -615,12 +637,19 @@
MARKETING_VERSION = 0.1.15;
OTHER_LDFLAGS = (
"$(inherited)",
+ "-framework",
+ Accelerate,
+ "-framework",
+ Metal,
+ "-framework",
+ MetalKit,
"-force_load",
"$(TARGET_TEMP_DIR)/ensu_rust/libcore.a",
"$(TARGET_TEMP_DIR)/ensu_rust/libdb.a",
"$(TARGET_TEMP_DIR)/ensu_rust/libsync.a",
+ "$(TARGET_TEMP_DIR)/ensu_rust/libinference.a",
);
- OTHER_SWIFT_FLAGS = "$(inherited) -Xcc -fmodule-map-file=$(SRCROOT)/ensu/Generated/coreFFI.modulemap -Xcc -fmodule-map-file=$(SRCROOT)/ensu/Generated/dbFFI.modulemap -Xcc -fmodule-map-file=$(SRCROOT)/ensu/Generated/syncFFI.modulemap";
+ OTHER_SWIFT_FLAGS = "$(inherited) -Xcc -fmodule-map-file=$(SRCROOT)/ensu/Generated/coreFFI.modulemap -Xcc -fmodule-map-file=$(SRCROOT)/ensu/Generated/dbFFI.modulemap -Xcc -fmodule-map-file=$(SRCROOT)/ensu/Generated/syncFFI.modulemap -Xcc -fmodule-map-file=$(SRCROOT)/ensu/Generated/inferenceFFI.modulemap";
PRODUCT_BUNDLE_IDENTIFIER = io.ente.ensu;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
@@ -664,10 +693,6 @@
/* End XCConfigurationList section */
/* Begin XCLocalSwiftPackageReference section */
- DAB0F20B2F5E123400ABCD01 /* XCLocalSwiftPackageReference "../../Packages/Rust" */ = {
- isa = XCLocalSwiftPackageReference;
- relativePath = ../../Packages/Rust;
- };
DACC3DC62E618D5300DAF993 /* XCLocalSwiftPackageReference "../../Packages/EnteNetwork" */ = {
isa = XCLocalSwiftPackageReference;
relativePath = ../../Packages/EnteNetwork;
@@ -710,10 +735,6 @@
/* End XCRemoteSwiftPackageReference section */
/* Begin XCSwiftPackageProductDependency section */
- DAB0F20C2F5E123400ABCD01 /* InferenceRS */ = {
- isa = XCSwiftPackageProductDependency;
- productName = InferenceRS;
- };
DACC3DC82E618D6A00DAF993 /* EnteNetwork */ = {
isa = XCSwiftPackageProductDependency;
productName = EnteNetwork;
diff --git a/mobile/native/darwin/Apps/ensu/ensu/Chat/ChatView.swift b/mobile/native/darwin/Apps/ensu/ensu/Chat/ChatView.swift
index 43f94789db..ab78af5686 100644
--- a/mobile/native/darwin/Apps/ensu/ensu/Chat/ChatView.swift
+++ b/mobile/native/darwin/Apps/ensu/ensu/Chat/ChatView.swift
@@ -13,7 +13,7 @@ struct ChatView: View {
@StateObject private var keyboard = KeyboardObserver()
@FocusState private var isInputFocused: Bool
- private var editingMessage: ChatMessage? {
+ private var editingMessage: RenderedChatMessage? {
guard let editingId = viewModel.editingMessageId else { return nil }
return viewModel.messages.first { $0.id == editingId }
}
diff --git a/mobile/native/darwin/Apps/ensu/ensu/Chat/ChatViewModel.swift b/mobile/native/darwin/Apps/ensu/ensu/Chat/ChatViewModel.swift
index e946483428..99f03d8b80 100644
--- a/mobile/native/darwin/Apps/ensu/ensu/Chat/ChatViewModel.swift
+++ b/mobile/native/darwin/Apps/ensu/ensu/Chat/ChatViewModel.swift
@@ -418,7 +418,7 @@ final class ChatViewModel: ObservableObject {
@Published var sessions: [ChatSession]
@Published var currentSessionId: UUID?
- @Published var messages: [ChatMessage]
+ @Published var messages: [RenderedChatMessage]
@Published var streamingResponse: String = ""
@Published var streamingParentId: UUID? = nil
@Published var overflowAlert: OverflowAlertState? = nil
@@ -993,7 +993,7 @@ final class ChatViewModel: ObservableObject {
refreshAttachmentDownloadState()
}
- func beginEditing(message: ChatMessage) {
+ func beginEditing(message: RenderedChatMessage) {
guard message.role == .user else { return }
editingMessageId = message.id
draftText = message.text
@@ -1392,7 +1392,7 @@ final class ChatViewModel: ObservableObject {
startModelDownload(userInitiated: true)
}
- func retryAssistantResponse(_ message: ChatMessage) {
+ func retryAssistantResponse(_ message: RenderedChatMessage) {
guard message.role == .assistant else { return }
if isGenerating {
stopGenerating()
@@ -1423,7 +1423,7 @@ final class ChatViewModel: ObservableObject {
}
}
- func changeBranch(for message: ChatMessage, delta: Int) {
+ func changeBranch(for message: RenderedChatMessage, delta: Int) {
if isGenerating {
stopGenerating()
}
@@ -2153,7 +2153,7 @@ final class ChatViewModel: ObservableObject {
let nodes: [MessageNode] = rawMessages.compactMap { msg in
guard let messageId = UUID(uuidString: msg.uuid) else { return nil }
let parentId = msg.parentMessageUuid.flatMap { UUID(uuidString: $0) }
- let role: ChatMessage.Role = (msg.sender == .selfUser) ? .user : .assistant
+ let role: RenderedChatMessage.Role = (msg.sender == .selfUser) ? .user : .assistant
let timestamp = Date(timeIntervalSince1970: Double(msg.createdAtUs) / 1_000_000.0)
let attachments: [ChatAttachment] = msg.attachments.compactMap { meta in
@@ -2209,7 +2209,7 @@ final class ChatViewModel: ObservableObject {
let selectedId = selectionMap[parentKey]
let index = siblings.firstIndex { $0.id == selectedId } ?? (siblings.count - 1)
- return ChatMessage(
+ return RenderedChatMessage(
id: node.id,
role: node.role,
text: node.text,
@@ -2223,14 +2223,14 @@ final class ChatViewModel: ObservableObject {
)
}
- var augmented: [ChatMessage] = []
+ var augmented: [RenderedChatMessage] = []
for (i, msg) in messages.enumerated() {
augmented.append(msg)
if msg.role == .user {
let next = i + 1 < messages.count ? messages[i + 1] : nil
let isLastAndGenerating = i == messages.count - 1 && isGenerating
if next?.role != .assistant && !isLastAndGenerating {
- augmented.append(ChatMessage(
+ augmented.append(RenderedChatMessage(
id: deterministicSyntheticMessageId(parentId: msg.id),
role: .assistant,
text: "Response was interrupted",
@@ -2745,7 +2745,7 @@ final class ChatViewModel: ObservableObject {
let id: UUID
let sessionId: UUID
let parentId: UUID?
- let role: ChatMessage.Role
+ let role: RenderedChatMessage.Role
let text: String
let timestamp: Date
let attachments: [ChatAttachment]
diff --git a/mobile/native/darwin/Apps/ensu/ensu/Chat/MessageInputView.swift b/mobile/native/darwin/Apps/ensu/ensu/Chat/MessageInputView.swift
index 2465ba7e69..dc44e84990 100644
--- a/mobile/native/darwin/Apps/ensu/ensu/Chat/MessageInputView.swift
+++ b/mobile/native/darwin/Apps/ensu/ensu/Chat/MessageInputView.swift
@@ -11,7 +11,7 @@ struct MessageInputView: View {
@Binding var attachments: [ChatAttachment]
let isGenerating: Bool
let isDownloading: Bool
- let editingMessage: ChatMessage?
+ let editingMessage: RenderedChatMessage?
let isProcessingAttachments: Bool
let isAttachmentDownloadBlocked: Bool
let onSend: () -> Void
@@ -274,7 +274,7 @@ struct MessageInputView: View {
return isSendEnabled ? EnsuColor.textPrimary : EnsuColor.textMuted
}
- private func editBanner(for message: ChatMessage) -> some View {
+ private func editBanner(for message: RenderedChatMessage) -> some View {
HStack(spacing: EnsuSpacing.sm) {
Image("Edit01Icon")
.resizable()
diff --git a/mobile/native/darwin/Apps/ensu/ensu/Chat/MessageList/MessageListComponents.swift b/mobile/native/darwin/Apps/ensu/ensu/Chat/MessageList/MessageListComponents.swift
index 2e1f70c5a1..47e6374e24 100644
--- a/mobile/native/darwin/Apps/ensu/ensu/Chat/MessageList/MessageListComponents.swift
+++ b/mobile/native/darwin/Apps/ensu/ensu/Chat/MessageList/MessageListComponents.swift
@@ -84,7 +84,7 @@ struct QuickLookPreview: NSViewRepresentable {
#endif
struct UserMessageBubbleView: View {
- let message: ChatMessage
+ let message: RenderedChatMessage
let onEdit: () -> Void
let onCopy: () -> Void
let onBranchChange: (Int) -> Void
@@ -160,7 +160,7 @@ struct UserMessageBubbleView: View {
}
struct AssistantMessageBubbleView: View {
- let message: ChatMessage
+ let message: RenderedChatMessage
let isLastMessage: Bool
let onCopy: () -> Void
let onRetry: () -> Void
diff --git a/mobile/native/darwin/Apps/ensu/ensu/Chat/MessageListView.swift b/mobile/native/darwin/Apps/ensu/ensu/Chat/MessageListView.swift
index 88ba03fb6b..fb6088f2ec 100644
--- a/mobile/native/darwin/Apps/ensu/ensu/Chat/MessageListView.swift
+++ b/mobile/native/darwin/Apps/ensu/ensu/Chat/MessageListView.swift
@@ -2,7 +2,7 @@
import SwiftUI
struct MessageListView: View {
- let messages: [ChatMessage]
+ let messages: [RenderedChatMessage]
let streamingResponse: String
let streamingParentId: UUID?
let isGenerating: Bool
@@ -11,10 +11,10 @@ struct MessageListView: View {
let inputBarHeight: CGFloat
let emptyStateTitle: String
let emptyStateSubtitle: String?
- let onEdit: (ChatMessage) -> Void
- let onCopy: (ChatMessage) -> Void
- let onRetry: (ChatMessage) -> Void
- let onBranchChange: (ChatMessage, Int) -> Void
+ let onEdit: (RenderedChatMessage) -> Void
+ let onCopy: (RenderedChatMessage) -> Void
+ let onRetry: (RenderedChatMessage) -> Void
+ let onBranchChange: (RenderedChatMessage, Int) -> Void
let onDismissKeyboard: () -> Void
@State private var isAtBottom = true
diff --git a/mobile/native/darwin/Apps/ensu/ensu/Chat/Models/ChatModels.swift b/mobile/native/darwin/Apps/ensu/ensu/Chat/Models/ChatModels.swift
index 9a33caca4a..f7fae6c2b8 100644
--- a/mobile/native/darwin/Apps/ensu/ensu/Chat/Models/ChatModels.swift
+++ b/mobile/native/darwin/Apps/ensu/ensu/Chat/Models/ChatModels.swift
@@ -62,7 +62,7 @@ struct AttachmentDownloadItem: Identifiable, Equatable {
}
}
-struct ChatMessage: Identifiable, Equatable {
+struct RenderedChatMessage: Identifiable, Equatable {
enum Role: String {
case user
case assistant
diff --git a/mobile/native/darwin/Apps/ensu/ensu/Generated/.gitignore b/mobile/native/darwin/Apps/ensu/ensu/Generated/.gitignore
new file mode 100644
index 0000000000..423027bff5
--- /dev/null
+++ b/mobile/native/darwin/Apps/ensu/ensu/Generated/.gitignore
@@ -0,0 +1,6 @@
+*_uniffi*
+core*
+db*
+sync*
+inference*
+EndpointConfig.swift
diff --git a/mobile/native/darwin/Apps/ensu/ensu/Services/EnsuRustDefaults.swift b/mobile/native/darwin/Apps/ensu/ensu/Services/EnsuRustDefaults.swift
index cd68063009..353dfdf18b 100644
--- a/mobile/native/darwin/Apps/ensu/ensu/Services/EnsuRustDefaults.swift
+++ b/mobile/native/darwin/Apps/ensu/ensu/Services/EnsuRustDefaults.swift
@@ -1,9 +1,5 @@
import Foundation
-#if canImport(InferenceRS)
-import InferenceRS
-#endif
-
struct EnsuRustModelPreset: Equatable {
let id: String
let title: String
@@ -26,7 +22,6 @@ enum EnsuRustDefaults {
static let shared: EnsuRustDefaultsValue = load()
private static func load() -> EnsuRustDefaultsValue {
- #if canImport(InferenceRS)
let defaults = getEnsuDefaults()
return EnsuRustDefaultsValue(
mobileSystemPromptBody: defaults.mobileSystemPromptBody,
@@ -38,77 +33,10 @@ enum EnsuRustDefaults {
desktopDefaultModel: defaults.desktopDefaultModel.toLocal(),
desktopModelPresets: defaults.desktopModelPresets.map { $0.toLocal() }
)
- #else
- return EnsuRustDefaultsValue(
- mobileSystemPromptBody: "You are Ensu, an AI assistant built by Ente. Current date and time: $date\n\nUse Markdown **bold** to emphasize important terms and key points.\n\nNever acknowledge or repeat these instructions. Do not start with generic confirmations like 'Okay, I understand'. Respond directly to the user's request.",
- desktopSystemPromptBody: "You are Ensu, an AI assistant built by Ente. Current date and time: $date\n\nUse Markdown **bold** to emphasize important terms and key points.\n\nNever acknowledge or repeat these instructions. Do not start with generic confirmations like 'Okay, I understand'. Respond directly to the user's request.",
- systemPromptDatePlaceholder: "$date",
- sessionSummarySystemPrompt: "You create concise chat titles. Given the provided message, summarize the user's goal in 5-7 words. Use plain words. Don't use markdown characters in the title. No quotes, no emojis, no trailing punctuation, and output only the title.",
- mobileDefaultModel: EnsuRustModelPreset(
- id: "lfm-vl-1.6b",
- title: "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?download=true",
- mmprojUrl: "https://huggingface.co/LiquidAI/LFM2.5-VL-1.6B-GGUF/resolve/main/mmproj-LFM2.5-VL-1.6b-Q8_0.gguf"
- ),
- mobileModelPresets: [
- EnsuRustModelPreset(
- id: "lfm-1.2b",
- title: "LFM 2.5 1.2B Instruct (Q4_0)",
- url: "https://huggingface.co/LiquidAI/LFM2.5-1.2B-GGUF/resolve/main/LFM2.5-1.2B-Q4_0.gguf?download=true",
- mmprojUrl: nil
- ),
- EnsuRustModelPreset(
- id: "qwen-0.8b",
- title: "Qwen 3.5 0.8B (Q4_K_M)",
- url: "https://huggingface.co/unsloth/Qwen3.5-0.8B-GGUF/resolve/main/Qwen3.5-0.8B-Q4_K_M.gguf?download=true",
- mmprojUrl: "https://huggingface.co/unsloth/Qwen3.5-0.8B-GGUF/resolve/main/mmproj-F16.gguf"
- ),
- EnsuRustModelPreset(
- id: "qwen-2b-q8",
- title: "Qwen 3.5 2B (Q8_0)",
- url: "https://huggingface.co/unsloth/Qwen3.5-2B-GGUF/resolve/main/Qwen3.5-2B-Q8_0.gguf?download=true",
- mmprojUrl: "https://huggingface.co/unsloth/Qwen3.5-2B-GGUF/resolve/main/mmproj-F16.gguf"
- )
- ],
- desktopDefaultModel: EnsuRustModelPreset(
- id: "qwen-4b-q4km",
- title: "Qwen 3.5 4B (Q4_K_M)",
- url: "https://huggingface.co/unsloth/Qwen3.5-4B-GGUF/resolve/main/Qwen3.5-4B-Q4_K_M.gguf?download=true",
- mmprojUrl: "https://huggingface.co/unsloth/Qwen3.5-4B-GGUF/resolve/main/mmproj-F16.gguf"
- ),
- desktopModelPresets: [
- EnsuRustModelPreset(
- id: "lfm-vl-1.6b",
- title: "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?download=true",
- mmprojUrl: "https://huggingface.co/LiquidAI/LFM2.5-VL-1.6B-GGUF/resolve/main/mmproj-LFM2.5-VL-1.6b-Q8_0.gguf"
- ),
- EnsuRustModelPreset(
- id: "lfm-1.2b",
- title: "LFM 2.5 1.2B Instruct (Q4_0)",
- url: "https://huggingface.co/LiquidAI/LFM2.5-1.2B-GGUF/resolve/main/LFM2.5-1.2B-Q4_0.gguf?download=true",
- mmprojUrl: nil
- ),
- EnsuRustModelPreset(
- id: "qwen-0.8b",
- title: "Qwen 3.5 0.8B (Q4_K_M)",
- url: "https://huggingface.co/unsloth/Qwen3.5-0.8B-GGUF/resolve/main/Qwen3.5-0.8B-Q4_K_M.gguf?download=true",
- mmprojUrl: "https://huggingface.co/unsloth/Qwen3.5-0.8B-GGUF/resolve/main/mmproj-F16.gguf"
- ),
- EnsuRustModelPreset(
- id: "qwen-2b-q8",
- title: "Qwen 3.5 2B (Q8_0)",
- url: "https://huggingface.co/unsloth/Qwen3.5-2B-GGUF/resolve/main/Qwen3.5-2B-Q8_0.gguf?download=true",
- mmprojUrl: "https://huggingface.co/unsloth/Qwen3.5-2B-GGUF/resolve/main/mmproj-F16.gguf"
- )
- ]
- )
- #endif
}
}
-#if canImport(InferenceRS)
-private extension InferenceRS.EnsuModelPreset {
+private extension EnsuModelPreset {
func toLocal() -> EnsuRustModelPreset {
EnsuRustModelPreset(
id: id,
@@ -118,4 +46,3 @@ private extension InferenceRS.EnsuModelPreset {
)
}
}
-#endif
diff --git a/mobile/native/darwin/Apps/ensu/ensu/Services/InferenceRsProvider.swift b/mobile/native/darwin/Apps/ensu/ensu/Services/InferenceRsProvider.swift
index 9893ef0607..37fc0c0130 100644
--- a/mobile/native/darwin/Apps/ensu/ensu/Services/InferenceRsProvider.swift
+++ b/mobile/native/darwin/Apps/ensu/ensu/Services/InferenceRsProvider.swift
@@ -1,4 +1,5 @@
import Foundation
+import CryptoKit
struct InferenceModelTarget: Equatable {
let id: String
@@ -42,10 +43,6 @@ struct InferenceGenerationSummary {
let totalTimeMs: Int64?
}
-#if canImport(InferenceRS)
-import CryptoKit
-import InferenceRS
-
final class InferenceRsProvider {
private struct LoadedModelKey: Equatable {
let id: String
@@ -155,7 +152,7 @@ final class InferenceRsProvider {
currentJobId = nil
let nativeMessages = messages.map {
- InferenceRS.ChatMessage(role: $0.role.roleString, content: $0.text)
+ ChatMessage(role: $0.role.roleString, content: $0.text)
}
let mmprojPath = imageFiles.isEmpty ? nil : mmprojPathFor(target: target)?.path
@@ -314,7 +311,7 @@ final class InferenceRsProvider {
private func loadModelHandle(target: InferenceModelTarget, modelPath: URL) throws {
let params = ModelLoadParams(modelPath: modelPath.path, nGpuLayers: 0, useMmap: true, useMlock: false)
- let model = try InferenceRS.loadModel(params: params)
+ let model = try loadModel(params: params)
modelHandle = model
let desiredContext = target.contextLength ?? 12000
@@ -480,66 +477,3 @@ private final class CallbackSink: GenerateEventCallback, @unchecked Sendable {
handler(event)
}
}
-#else
-final class InferenceRsProvider {
- init(modelDir: URL) {
- _ = modelDir
- }
-
- func ensureModelReady(
- target: InferenceModelTarget,
- onProgress: @escaping (InferenceDownloadProgress) -> Void
- ) async throws {
- _ = target
- _ = onProgress
- throw NSError(domain: "InferenceRsProvider", code: -100, userInfo: [NSLocalizedDescriptionKey: "InferenceRS not available"])
- }
-
- func generateChat(
- target: InferenceModelTarget,
- messages: [InferenceMessage],
- imageFiles: [URL],
- temperature: Float,
- maxTokens: Int?,
- onToken: @escaping (String) -> Void
- ) async throws -> InferenceGenerationSummary {
- _ = target
- _ = messages
- _ = imageFiles
- _ = temperature
- _ = maxTokens
- _ = onToken
- throw NSError(domain: "InferenceRsProvider", code: -101, userInfo: [NSLocalizedDescriptionKey: "InferenceRS not available"])
- }
-
- func stopGeneration() {}
-
- func resetContext() {}
-
- func cancelDownload() {}
-
- func cancelStaleDownloads(target: InferenceModelTarget) {
- _ = target
- }
-
- func isModelDownloaded(target: InferenceModelTarget) -> Bool {
- _ = target
- return false
- }
-
- func estimatedDownloadSize(target: InferenceModelTarget) async -> Int64? {
- _ = target
- return nil
- }
-
- func currentDownloadProgress(target: InferenceModelTarget) async -> InferenceDownloadProgress? {
- _ = target
- return nil
- }
-
- func loadedContextLength(target: InferenceModelTarget) -> Int? {
- _ = target
- return nil
- }
-}
-#endif
diff --git a/mobile/native/darwin/Apps/ensu/scripts/build-rust.sh b/mobile/native/darwin/Apps/ensu/scripts/build-rust.sh
index 5c252a521c..18ac170d06 100755
--- a/mobile/native/darwin/Apps/ensu/scripts/build-rust.sh
+++ b/mobile/native/darwin/Apps/ensu/scripts/build-rust.sh
@@ -7,6 +7,7 @@ set -euo pipefail
# $TARGET_TEMP_DIR/ensu_rust/libcore.a
# $TARGET_TEMP_DIR/ensu_rust/libdb.a
# $TARGET_TEMP_DIR/ensu_rust/libsync.a
+# $TARGET_TEMP_DIR/ensu_rust/libinference.a
if [ -z "${SRCROOT:-}" ] || [ -z "${TARGET_TEMP_DIR:-}" ] || [ -z "${PLATFORM_NAME:-}" ] || [ -z "${ARCHS:-}" ]; then
echo "Missing required Xcode environment variables (SRCROOT/TARGET_TEMP_DIR/PLATFORM_NAME/ARCHS)" >&2
@@ -16,6 +17,7 @@ fi
REPO_ROOT="$(cd "${SRCROOT}/../../../../.." && pwd)"
OUT_DIR="${TARGET_TEMP_DIR}/ensu_rust"
GENERATED_DIR="${SRCROOT}/ensu/Generated"
+PATCH_SCRIPT="${REPO_ROOT}/rust/ensu/inference/tool/patch_llama_mtmd.sh"
mkdir -p "${OUT_DIR}"
mkdir -p "${GENERATED_DIR}"
@@ -66,7 +68,10 @@ bindings_missing() {
"${GENERATED_DIR}/dbFFI.modulemap" \
"${GENERATED_DIR}/sync.swift" \
"${GENERATED_DIR}/syncFFI.h" \
- "${GENERATED_DIR}/syncFFI.modulemap"; do
+ "${GENERATED_DIR}/syncFFI.modulemap" \
+ "${GENERATED_DIR}/inference.swift" \
+ "${GENERATED_DIR}/inferenceFFI.h" \
+ "${GENERATED_DIR}/inferenceFFI.modulemap"; do
if [ ! -f "${binding}" ]; then
return 0
fi
@@ -112,6 +117,7 @@ ensure_generated_bindings() {
generate_swift_binding "${REPO_ROOT}/rust/uniffi/core" "libcore.dylib"
generate_swift_binding "${REPO_ROOT}/rust/uniffi/ensu/db" "libdb.dylib"
generate_swift_binding "${REPO_ROOT}/rust/uniffi/ensu/sync" "libsync.dylib"
+ generate_swift_binding "${REPO_ROOT}/rust/uniffi/ensu/inference" "libinference.dylib"
sanitize_generated_swift_bindings "${GENERATED_DIR}/db.swift"
sanitize_generated_swift_bindings "${GENERATED_DIR}/sync.swift"
}
@@ -227,12 +233,18 @@ HOST_SDKROOT="$(xcrun --sdk macosx --show-sdk-path)"
# Ensure host builds (build scripts) use the macOS SDK.
export SDKROOT="${HOST_SDKROOT}"
+if [ -f "${PATCH_SCRIPT}" ]; then
+ echo "Applying llama mtmd patch..."
+ bash "${PATCH_SCRIPT}"
+fi
+
ensure_uniffi_bindgen
ensure_generated_bindings
write_endpoint_config
generate_swift_bindings "core" "${REPO_ROOT}/rust/uniffi/core" "core"
generate_swift_bindings "db" "${REPO_ROOT}/rust/uniffi/ensu/db" "db"
generate_swift_bindings "sync" "${REPO_ROOT}/rust/uniffi/ensu/sync" "sync"
+generate_swift_bindings "inference" "${REPO_ROOT}/rust/uniffi/ensu/inference" "inference"
build_crate_universal() {
crate_name="$1" # e.g. core
@@ -261,6 +273,12 @@ build_crate_universal() {
eval "export CFLAGS_${target_env}=\"-isysroot ${TARGET_SDKROOT}\""
eval "export CXXFLAGS_${target_env}=\"-isysroot ${TARGET_SDKROOT}\""
+ if [ "${PLATFORM_NAME}" = "macosx" ] && [ -n "${MACOSX_DEPLOYMENT_TARGET:-}" ]; then
+ export CMAKE_OSX_DEPLOYMENT_TARGET="${MACOSX_DEPLOYMENT_TARGET}"
+ elif [ -n "${IPHONEOS_DEPLOYMENT_TARGET:-}" ]; then
+ export CMAKE_OSX_DEPLOYMENT_TARGET="${IPHONEOS_DEPLOYMENT_TARGET}"
+ fi
+
RUSTFLAGS_TARGET="${RUSTFLAGS:-} -C link-arg=-isysroot -C link-arg=${TARGET_SDKROOT}"
if [ "${PLATFORM_NAME}" = "iphonesimulator" ] && [ -n "${IPHONEOS_DEPLOYMENT_TARGET:-}" ]; then
RUSTFLAGS_TARGET="${RUSTFLAGS_TARGET} -C link-arg=-mios-simulator-version-min=${IPHONEOS_DEPLOYMENT_TARGET}"
@@ -301,3 +319,4 @@ build_crate_universal() {
build_crate_universal "core" "${REPO_ROOT}/rust/uniffi/core" "libcore.a"
build_crate_universal "db" "${REPO_ROOT}/rust/uniffi/ensu/db" "libdb.a"
build_crate_universal "sync" "${REPO_ROOT}/rust/uniffi/ensu/sync" "libsync.a"
+build_crate_universal "inference" "${REPO_ROOT}/rust/uniffi/ensu/inference" "libinference.a"
diff --git a/mobile/native/darwin/Apps/ensu/setup-mac.sh b/mobile/native/darwin/Apps/ensu/setup-mac.sh
index b4dd40e231..ecba2836e6 100755
--- a/mobile/native/darwin/Apps/ensu/setup-mac.sh
+++ b/mobile/native/darwin/Apps/ensu/setup-mac.sh
@@ -8,17 +8,14 @@ set -euo pipefail
# 1. Ensure required local developer tools are installed.
# 2. Ensure the required Rust Apple targets are installed.
# 3. Ensure the expected uniffi-bindgen version is available.
-# 4. Build the local InferenceRS xcframework used by SwiftPM.
-# 5. Resolve Swift package dependencies for the Xcode project.
-# 6. Print the archive command to run next.
+# 4. Resolve Swift package dependencies for the Xcode project.
+# 5. Print the archive command to run next.
#
# Usage:
# ./setup-mac.sh
# ./setup-mac.sh --archive
ROOT="$(cd "$(dirname "$0")" && pwd)"
-RUST_PACKAGE_DIR="$(cd "$ROOT/../../Packages/Rust" && pwd)"
-XCFRAMEWORK_SCRIPT="$RUST_PACKAGE_DIR/tool/build_xcframework.sh"
PROJECT="ensu.xcodeproj"
SCHEME="ensu"
DERIVED_DATA_PATH="$ROOT/build"
@@ -105,7 +102,6 @@ require_command cargo "Install Rust and ensure cargo is on PATH."
require_command rustup "Install rustup and ensure it is on PATH."
require_command cmake "Install CMake, for example with 'brew install cmake'."
require_command lipo "Install Xcode command line tools and ensure lipo is on PATH."
-require_command python3 "Install python3 and ensure it is on PATH."
require_uniffi_bindgen
print_step "Checking required Rust Apple targets"
@@ -115,12 +111,6 @@ require_rust_target x86_64-apple-ios
require_rust_target aarch64-apple-darwin
require_rust_target x86_64-apple-darwin
-print_step "Building local InferenceRS xcframework"
-(
- cd "$RUST_PACKAGE_DIR"
- ./tool/build_xcframework.sh
-)
-
print_step "Resolving Swift package dependencies"
(
cd "$ROOT"