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): a connector search reads on past empty pages, and pictures load once online

leepokai776abc230d2a
diff --git a/apps/android/app/src/main/kotlin/com/codync/android/ConnectorCatalog.kt b/apps/android/app/src/main/kotlin/com/codync/android/ConnectorCatalog.kt
index 07111e54..de813f09 100644
--- a/apps/android/app/src/main/kotlin/com/codync/android/ConnectorCatalog.kt
+++ b/apps/android/app/src/main/kotlin/com/codync/android/ConnectorCatalog.kt
@@ -35,8 +35,18 @@ internal class ConnectorCatalog<T>(
val mine = ++request
query = search; loading = true; loadingMore = false
try {
- val (rows, next) = fetch(search, null)
+ var (rows, next) = fetch(search, null)
if (request != mine) return
+ // The host reads past registry pages with nothing to install only while the app waits for its
+ // answer. An empty first page that still has a cursor gets a few more asks before it reads as
+ // no results: a phone has no other way to reach the rows after it.
+ var asks = 0
+ while (rows.isEmpty() && !next.isNullOrBlank() && asks < EMPTY_PAGE_ASKS) {
+ asks++
+ val more = fetch(search, next)
+ if (request != mine) return
+ rows = more.first; next = more.second
+ }
items = CatalogPage<T>().append(rows, id); cursor = next?.takeIf(String::isNotBlank); page = 0; error = null
} catch (cancelled: CancellationException) { throw cancelled }
catch (failure: Exception) {
@@ -75,3 +85,6 @@ internal class ConnectorCatalog<T>(
} finally { if (request == mine) loadingMore = false }
}
}
+
+/** Further registry pages a search reads when its first answer is empty but continues (iOS `emptyPageAsks`). */
+internal const val EMPTY_PAGE_ASKS = 3
diff --git a/apps/android/app/src/test/kotlin/com/codync/android/ConnectorCatalogTest.kt b/apps/android/app/src/test/kotlin/com/codync/android/ConnectorCatalogTest.kt
index 7d05f0c8..281e1f57 100644
--- a/apps/android/app/src/test/kotlin/com/codync/android/ConnectorCatalogTest.kt
+++ b/apps/android/app/src/test/kotlin/com/codync/android/ConnectorCatalogTest.kt
@@ -37,4 +37,23 @@ class ConnectorCatalogTest {
assertEquals("offline", catalog.error)
assertFalse(catalog.loadingMore)
}
+
+ @Test fun anEmptyFirstPageThatContinuesReadsOnToRows() = runBlocking {
+ val catalog = ConnectorCatalog<Int>({ it.toString() }) { _, cursor ->
+ when (cursor) {
+ null -> emptyList<Int>() to "a"
+ "a" -> emptyList<Int>() to "b"
+ else -> listOf(1, 2) to "c"
+ }
+ }
+ catalog.load("search")
+ assertEquals(2, catalog.items.items.size)
+ assertEquals("c", catalog.cursor)
+
+ // Past the asks it allows, an empty answer reads as no results, cursor and all.
+ val endless = ConnectorCatalog<Int>({ it.toString() }) { _, cursor -> emptyList<Int>() to "${cursor.orEmpty()}x" }
+ endless.load("none")
+ assertEquals(0, endless.items.items.size)
+ assertEquals("xxxx", endless.cursor)
+ }
}
diff --git a/apps/desktop/src/renderer/views/thread/Attachments.tsx b/apps/desktop/src/renderer/views/thread/Attachments.tsx
index d07145e7..96ded067 100644
--- a/apps/desktop/src/renderer/views/thread/Attachments.tsx
+++ b/apps/desktop/src/renderer/views/thread/Attachments.tsx
@@ -81,14 +81,25 @@ export function AttachmentImage({ source, fit }: { source: ImageSource; fit: 'ic
useEffect(() => {
let revoked = false
let made: string | null = null
- const data = 'entryId' in source ? store.sharedFileData(source.file, source.entryId) : store.attachmentData(source.file.id, source.botId)
- void data.then((data) => {
- if (!data || revoked) return
- made = URL.createObjectURL(new Blob([data as BlobPart]))
- setUrl(made)
+ const read = () => {
+ const data = 'entryId' in source ? store.sharedFileData(source.file, source.entryId) : store.attachmentData(source.file.id, source.botId)
+ void data.then((data) => {
+ if (!data || revoked || made) return
+ made = URL.createObjectURL(new Blob([data as BlobPart]))
+ setUrl(made)
+ })
+ }
+ // A chat shown before the computer connects reads its pictures again once it comes online.
+ let online = store.connection.kind === 'online'
+ const stop = store.subscribe(() => {
+ const now = store.connection.kind === 'online'
+ if (now && !online && !made) read()
+ online = now
})
+ read()
return () => {
revoked = true
+ stop()
if (made) URL.revokeObjectURL(made)
}
// A file's id names its bytes for good; `source` is a new object every render.
diff --git a/apps/ios/Kit/Sources/CodyncUI/Marketplace/MarketplacePage.swift b/apps/ios/Kit/Sources/CodyncUI/Marketplace/MarketplacePage.swift
index 838b3b36..b8557399 100644
--- a/apps/ios/Kit/Sources/CodyncUI/Marketplace/MarketplacePage.swift
+++ b/apps/ios/Kit/Sources/CodyncUI/Marketplace/MarketplacePage.swift
@@ -23,6 +23,8 @@ enum CatalogPaging {
/// Two agent tiles across, three rows: a page has no leftover card.
static let phonePageSize = 6
static let pageSizes = [6, 10, 20, 50]
+ /// Further registry pages a search reads when its first answer is empty but continues.
+ static let emptyPageAsks = 3
/// Loaded rows split into pages. While the registry still has a cursor, one more page is offered so the bar is never 1 / 1 for a list that continues.
static func pageCount(_ count: Int, size: Int = pageSize, hasMore: Bool = false) -> Int {
@@ -79,8 +81,17 @@ final class ConnectorCatalog<Item: Identifiable> {
loadingMore = false
defer { if self.request == request { loading = false } }
do {
- let first = try await fetch(search, nil)
+ var first = try await fetch(search, nil)
guard !Task.isCancelled, self.request == request else { return }
+ // The host reads past registry pages with nothing to install only while the app waits for its
+ // answer. An empty first page that still has a cursor gets a few more asks before it reads
+ // as no results: a phone has no other way to reach the rows after it.
+ var asks = 0
+ while first.items.isEmpty, let next = first.next, asks < CatalogPaging.emptyPageAsks {
+ asks += 1
+ first = try await fetch(search, next)
+ guard !Task.isCancelled, self.request == request else { return }
+ }
items.replace(with: first.items)
cursor = first.next
page = 0
diff --git a/apps/ios/Kit/Sources/CodyncUI/Thread/Attachments.swift b/apps/ios/Kit/Sources/CodyncUI/Thread/Attachments.swift
index df104856..b6c7cd73 100644
--- a/apps/ios/Kit/Sources/CodyncUI/Thread/Attachments.swift
+++ b/apps/ios/Kit/Sources/CodyncUI/Thread/Attachments.swift
@@ -196,8 +196,10 @@ struct AttachmentImage: View {
.overlay { Image(systemName: "photo").foregroundStyle(Palette.tertiary) }
}
}
- .task(id: id) {
- guard let data = await load(model) else { return }
+ // Asked again when the computer comes online: a chat shown from the cache before it connects
+ // gets its pictures once it does. A loaded picture is never fetched again.
+ .task(id: [id, model.connection == .online ? "online" : "waiting"]) {
+ guard image == nil, let data = await load(model) else { return }
let size = maxPixels
image = await Task.detached { ImageData.thumbnail(data, maxPixels: size) }.value
}
diff --git a/apps/ios/Kit/Tests/CodyncUITests/MarketplacePageTests.swift b/apps/ios/Kit/Tests/CodyncUITests/MarketplacePageTests.swift
index 1303e34d..c18a6e57 100644
--- a/apps/ios/Kit/Tests/CodyncUITests/MarketplacePageTests.swift
+++ b/apps/ios/Kit/Tests/CodyncUITests/MarketplacePageTests.swift
@@ -63,3 +63,20 @@ private struct Offline: Error {}
await catalog.fill(size: 10) { _, _ in throw Offline() }
#expect(catalog.page == 2 && catalog.error != nil)
}
+
+@Test @MainActor func anEmptyFirstPageThatContinuesReadsOnToRows() async {
+ let catalog = ConnectorCatalog<CatalogItem>()
+ await catalog.load(search: "search") { _, cursor in
+ switch cursor {
+ case nil: ([], "a")
+ case "a": ([], "b")
+ default: ([CatalogItem(id: 1), CatalogItem(id: 2)], "c")
+ }
+ }
+ #expect(catalog.items.items.count == 2 && catalog.cursor == "c")
+
+ // Past the asks it allows, an empty answer reads as no results, cursor and all.
+ let endless = ConnectorCatalog<CatalogItem>()
+ await endless.load(search: "none") { _, cursor in ([], (cursor ?? "") + "x") }
+ #expect(endless.items.isEmpty && endless.cursor == "xxxx")
+}