Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

fix(web-app): run the Cowork migration on desktop only

Akarshan Biswas38a6009f6e4b
diff --git a/web-app/src/lib/__tests__/migrateCoworkSessionsStartup.test.ts b/web-app/src/lib/__tests__/migrateCoworkSessionsStartup.test.ts
index a553da2d6..aa765c48e 100644
--- a/web-app/src/lib/__tests__/migrateCoworkSessionsStartup.test.ts
+++ b/web-app/src/lib/__tests__/migrateCoworkSessionsStartup.test.ts
@@ -2,12 +2,16 @@ import { describe, it, expect, vi, beforeEach } from 'vitest'
const h = vi.hoisted(() => ({
isTauri: true,
+ isIOS: false,
+ isAndroid: false,
invoke: vi.fn(),
getServiceHub: vi.fn(),
}))
vi.mock('@/lib/platform/utils', () => ({
isPlatformTauri: () => h.isTauri,
+ isPlatformIOS: () => h.isIOS,
+ isPlatformAndroid: () => h.isAndroid,
}))
vi.mock('@/hooks/useServiceHub', () => ({
getServiceHub: h.getServiceHub,
@@ -22,6 +26,8 @@ import {
describe('migrateCoworkSessionsOnStartup', () => {
beforeEach(() => {
h.isTauri = true
+ h.isIOS = false
+ h.isAndroid = false
h.invoke.mockReset()
h.getServiceHub.mockReset()
h.getServiceHub.mockReturnValue({ core: () => ({ invoke: h.invoke }) })
@@ -34,6 +40,17 @@ describe('migrateCoworkSessionsOnStartup', () => {
expect(h.invoke).not.toHaveBeenCalled()
})
+ it.each([['iOS'], ['Android']])(
+ 'does nothing on %s: sidecars and message replacement are desktop-only',
+ async (platform) => {
+ h.isIOS = platform === 'iOS'
+ h.isAndroid = platform === 'Android'
+ await expect(migrateCoworkSessionsOnStartup()).resolves.toBeNull()
+ expect(h.getServiceHub).not.toHaveBeenCalled()
+ expect(h.invoke).not.toHaveBeenCalled()
+ }
+ )
+
it('runs the migration through the service hub invoke', async () => {
h.invoke.mockImplementation(async (_cmd: string, args?: { key?: string }) =>
args?.key === COWORK_MIGRATION_FLAG_KEY ? 'true' : null
diff --git a/web-app/src/lib/migrateCoworkSessions.ts b/web-app/src/lib/migrateCoworkSessions.ts
index d397c8b29..4e94b9ccc 100644
--- a/web-app/src/lib/migrateCoworkSessions.ts
+++ b/web-app/src/lib/migrateCoworkSessions.ts
@@ -2,7 +2,11 @@ import { coworkTurnsToUIMessages } from '@/lib/coworkTurns'
import { coworkSessionToThreadMessages } from '@/lib/coworkThreadMessages'
import type { CoworkSession } from '@/hooks/useCoworkSessions'
import { getServiceHub } from '@/hooks/useServiceHub'
-import { isPlatformTauri } from '@/lib/platform/utils'
+import {
+ isPlatformAndroid,
+ isPlatformIOS,
+ isPlatformTauri,
+} from '@/lib/platform/utils'
/**
* One-time copy of Cowork sessions (`code-sessions` in settings.json) into
@@ -254,12 +258,16 @@ export async function migrateCoworkSessionsToThreads(
/**
* Startup entry point: runs the migration through the service hub's backend
* `invoke`, the same seam `migrateLocalStorageToBackend` uses. On web there is
- * no backend and no `code-sessions` blob in it, so nothing runs. It never
+ * no backend and no `code-sessions` blob in it, so nothing runs; mobile is
+ * skipped too. It never
* throws: a failed migration stays unflagged and is retried next launch, and
* must not stop the app from rendering. Returns `null` when it did not run.
*/
export async function migrateCoworkSessionsOnStartup(): Promise<CoworkMigrationResult | null> {
if (!isPlatformTauri()) return null
+ // Sidecars and message replacement are file-backed and desktop-only; mobile
+ // stores threads in SQLite and Cowork does not exist there.
+ if (isPlatformIOS() || isPlatformAndroid()) return null
try {
const core = getServiceHub().core()
return await migrateCoworkSessionsToThreads(core.invoke.bind(core) as Invoke)