Skip to content

Open source Grok Bot alternative, Bring your own agent and subscription: message Claude Code, Codex, Gemini CLI, Cursor, Copilot and 40+ AI agents as bots on your own computer, from iPhone, Mac, Windows, Linux or terminal. Agent-agnostic and free. Also a Muse and Dots alternative. Built in Rust.

fix(apps): keep custom bot icons after saving settings

leepokaid4e4f6041aaf
diff --git a/apps/desktop/src/renderer/store/bot-mirror.ts b/apps/desktop/src/renderer/store/bot-mirror.ts
index 147d8281..2ddbf664 100644
--- a/apps/desktop/src/renderer/store/bot-mirror.ts
+++ b/apps/desktop/src/renderer/store/bot-mirror.ts
@@ -50,10 +50,22 @@ export class BotMirror extends Observable {
private restoreIcons(icons: import('@shared/custom-icons').CustomIcons) {
this.icons = icons
- for (const [id, bot] of this.bots) this.bots.set(id, { ...bot, customIcon: icons[`bot:${id}`] })
+ for (const [id, bot] of this.bots) this.bots.set(id, this.withIcon(bot))
this.onRosterChanged?.()
this.changed()
}
+
+ /** Icons sync apart from bots, so no bot the host sends carries its custom icon. */
+ private withIcon(bot: Bot): Bot {
+ return { ...bot, customIcon: this.icons[`bot:${bot.id}`] }
+ }
+
+ /** Stores a bot the host sent, with its custom icon. */
+ protected putHostBot(bot: Bot): Bot {
+ const stored = this.withIcon(bot)
+ this.bots.set(stored.id, stored)
+ return stored
+ }
computer: Computer
connection: Connection = { kind: 'connecting' }
hostRoute: HostRoute | null = null
diff --git a/apps/desktop/src/renderer/store/bot-store.ts b/apps/desktop/src/renderer/store/bot-store.ts
index dccd132d..b588fa00 100644
--- a/apps/desktop/src/renderer/store/bot-store.ts
+++ b/apps/desktop/src/renderer/store/bot-store.ts
@@ -354,8 +354,7 @@ export class BotStore extends BotSync {
async createGroup(name: string, description: string, members: string[]) {
const draft: GroupDraft = { kind: 'group', name, description, members }
const res = await (await this.ready()).call<{ bot: Bot }>('createBot', draft)
- const bot = normalizeBot(res.bot)
- this.bots.set(bot.id, bot)
+ const bot = this.putHostBot(normalizeBot(res.bot))
this.selection = bot.id
this.onRosterChanged?.()
this.changed()
@@ -364,7 +363,7 @@ export class BotStore extends BotSync {
async updateGroup(draft: GroupDraft) {
const res = await (await this.ready()).call<{ bot: Bot }>('updateBot', draft)
- this.bots.set(res.bot.id, normalizeBot(res.bot))
+ this.putHostBot(normalizeBot(res.bot))
this.changed()
}
@@ -402,8 +401,7 @@ export class BotStore extends BotSync {
const res = draft.id
? await client.call<{ bot: Bot }>('updateBot', { ...draft, model: draft.model ?? null })
: await client.call<{ bot: Bot }>('createBot', draft)
- const bot = normalizeBot(res.bot)
- this.bots.set(bot.id, bot)
+ const bot = this.putHostBot(normalizeBot(res.bot))
this.onRosterChanged?.()
this.changed()
return bot
diff --git a/apps/desktop/src/renderer/store/bot-sync.ts b/apps/desktop/src/renderer/store/bot-sync.ts
index fbdf2ad0..f18d671a 100644
--- a/apps/desktop/src/renderer/store/bot-sync.ts
+++ b/apps/desktop/src/renderer/store/bot-sync.ts
@@ -236,7 +236,7 @@ export class BotSync extends BotMirror {
this.floors = snapshotFloors(this.entries, this.rev === 0 ? 0 : this.requestedSince)
break
case 'bot':
- this.bots.set(event.bot.id, { ...event.bot, customIcon: this.icons[`bot:${event.bot.id}`] })
+ this.putHostBot(event.bot)
this.bump(event.bot.rev)
this.onRosterChanged?.()
if (event.bot.unread > 0) this.acknowledgeVisible(event.bot.id)
diff --git a/apps/ios/Kit/Sources/CodyncUI/Store/BotStore+Actions.swift b/apps/ios/Kit/Sources/CodyncUI/Store/BotStore+Actions.swift
index c1ad82a0..594b5a4b 100644
--- a/apps/ios/Kit/Sources/CodyncUI/Store/BotStore+Actions.swift
+++ b/apps/ios/Kit/Sources/CodyncUI/Store/BotStore+Actions.swift
@@ -334,15 +334,13 @@ extension BotStore {
/// Creates a group chat (or opens the one these bots already share) and selects it.
public func createGroup(name: String, description: String = "", members: [String]) async throws -> Bot {
- let group = try await ready().createGroup(GroupDraft(name: name, description: description, members: members))
- bots[group.id] = group
+ let group = putHostBot(try await ready().createGroup(GroupDraft(name: name, description: description, members: members)))
selection = group.id
return group
}
public func updateGroup(_ draft: GroupDraft) async throws {
- let group = try await ready().updateGroup(draft)
- bots[group.id] = group
+ putHostBot(try await ready().updateGroup(draft))
}
/// What a voice call carried, for its conversation. Never `upsert`ed, like `botConversation`.
@@ -358,9 +356,7 @@ extension BotStore {
public func save(_ draft: BotDraft) async throws -> Bot {
let client = try await ready()
- let bot = draft.id == nil ? try await client.createBot(draft) : try await client.updateBot(draft)
- bots[bot.id] = bot
- return bot
+ return putHostBot(draft.id == nil ? try await client.createBot(draft) : try await client.updateBot(draft))
}
public func selectWorkspace(_ path: String) async throws -> String {
diff --git a/apps/ios/Kit/Sources/CodyncUI/Store/BotStore+Icons.swift b/apps/ios/Kit/Sources/CodyncUI/Store/BotStore+Icons.swift
index 14ce83f3..27a65540 100644
--- a/apps/ios/Kit/Sources/CodyncUI/Store/BotStore+Icons.swift
+++ b/apps/ios/Kit/Sources/CodyncUI/Store/BotStore+Icons.swift
@@ -3,6 +3,21 @@ import Foundation
import os
extension BotStore {
+ /// Stores a bot the host sent, with its custom icon.
+ @discardableResult
+ func putHostBot(_ bot: Bot) -> Bot {
+ let bot = withIcon(bot)
+ bots[bot.id] = bot
+ return bot
+ }
+
+ /// Icons sync apart from bots, so no bot the host sends carries its custom icon.
+ private func withIcon(_ bot: Bot) -> Bot {
+ var bot = bot
+ bot.customIcon = icons["bot:\(bot.id)"]
+ return bot
+ }
+
func applyIcons(_ updated: [String: CustomIcon], revision: Int64 = 0) {
guard revision >= iconsRevision else { return }
iconsRevision = revision
@@ -15,11 +30,11 @@ extension BotStore {
do { try ActivityIconCache.prune(context: storage.id) }
catch { Logger(subsystem: "com.pokai.Codync", category: "CustomIcon").error("Cannot prune activity icons: \(error.localizedDescription)") }
icons = updated
- for (id, var bot) in bots {
- guard bot.customIcon != updated["bot:\(id)"] else { continue }
- bot.customIcon = updated["bot:\(id)"]
- bots[id] = bot
- onBotUpdated?(bot)
+ for (id, bot) in bots {
+ let next = withIcon(bot)
+ guard next.customIcon != bot.customIcon else { continue }
+ bots[id] = next
+ onBotUpdated?(next)
}
onRosterChanged?()
}
diff --git a/apps/ios/Kit/Sources/CodyncUI/Store/BotStore+Sync.swift b/apps/ios/Kit/Sources/CodyncUI/Store/BotStore+Sync.swift
index 669b65ac..262c89cb 100644
--- a/apps/ios/Kit/Sources/CodyncUI/Store/BotStore+Sync.swift
+++ b/apps/ios/Kit/Sources/CodyncUI/Store/BotStore+Sync.swift
@@ -100,9 +100,8 @@ extension BotStore {
windowFloors = requestedSince > 0 && !hostRewound ? loadedFloors() : [:]
catchUpRev = hostRev
bump(rev)
- case .bot(var bot):
- bot.customIcon = icons["bot:\(bot.id)"]
- bots[bot.id] = bot
+ case .bot(let received):
+ let bot = putHostBot(received)
bump(bot.rev)
onBotUpdated?(bot)
onRosterChanged?()
diff --git a/apps/ios/Kit/Tests/CodyncUITests/BotIconTests.swift b/apps/ios/Kit/Tests/CodyncUITests/BotIconTests.swift
new file mode 100644
index 00000000..538904f2
--- /dev/null
+++ b/apps/ios/Kit/Tests/CodyncUITests/BotIconTests.swift
@@ -0,0 +1,25 @@
+import Foundation
+import Testing
+@testable import CodyncKit
+@testable import CodyncUI
+
+@MainActor @Test func savedBotKeepsItsCustomIcon() async throws {
+ let suite = "BotIconTests.\(UUID().uuidString)"
+ defer { UserDefaults(suiteName: suite)?.removePersistentDomain(forName: suite) }
+ let remote = FakeRemote(.ready(.direct))
+ let computer = Computer(id: UUID().uuidString, name: "Mac", signKey: "unused", boxKey: "unused")
+ let store = BotStore(computer: computer, storage: SharedStore.Context(accountID: nil, suite: suite)) { _ in remote }
+ defer { store.retire() }
+ store.setActive(true)
+ #expect(await until { await remote.subscribed })
+ await remote.emit(#"{"type":"hello","hostId":"h1","rev":1}"#)
+ await remote.emit(#"{"type":"bot","bot":{"id":"b1","name":"Ada","rev":1}}"#)
+ #expect(await until { store.bots["b1"] != nil })
+ let icon = CustomIcon(dataUrl: "data:image/png;base64,AA==", tinted: false)
+ store.applyIcons(["bot:b1": icon])
+ #expect(store.bots["b1"]?.customIcon == icon)
+
+ let saved = try await store.save(BotDraft(try #require(store.bots["b1"])))
+ #expect(saved.customIcon == icon)
+ #expect(store.bots["b1"]?.customIcon == icon)
+}
diff --git a/apps/ios/Kit/Tests/CodyncUITests/StoreTestFixtures.swift b/apps/ios/Kit/Tests/CodyncUITests/StoreTestFixtures.swift
index 2995047c..b5c9d95e 100644
--- a/apps/ios/Kit/Tests/CodyncUITests/StoreTestFixtures.swift
+++ b/apps/ios/Kit/Tests/CodyncUITests/StoreTestFixtures.swift
@@ -100,6 +100,10 @@ actor FakeRemote: RemoteTransport {
// A fresh credential per provider session, so a test can tell a replaced session from the first.
let n = calls.filter { $0 == "startCall" }.count
return Data(#"{"instructions":"Be the relay.","tools":[],"credential":"token-\#(n)"}"#.utf8)
+ case "createBot", "updateBot":
+ // The host's reply bot, which never carries a custom icon (icons sync on their own).
+ let id = (try JSONSerialization.jsonObject(with: body) as? [String: Any])?["id"] as? String ?? "new"
+ return Data(#"{"bot":{"id":"\#(id)","name":"Saved","rev":2}}"#.utf8)
default:
return Data("{}".utf8)
}
diff --git a/apps/ios/WhatsNew.md b/apps/ios/WhatsNew.md
index 86e1cf9f..54b2dad4 100644
--- a/apps/ios/WhatsNew.md
+++ b/apps/ios/WhatsNew.md
@@ -9,6 +9,8 @@ a version without one gets a generic "Bug fixes and improvements" line. Delete o
## 2.33.3
### zh-Hant
- 可上下拖曳 section,連同其中的 bot 一起移動,也能放到「Bots」下方;此裝置會記住順序。
+- 儲存 bot 設定或編輯群組後,自訂圖示不會再消失。
### en-US
- Drag sections up or down with their bots, including below Bots. This device remembers the order.
+- Custom bot icons now stay after you save a bot's settings or edit a group.