Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
fix(web-app): copy Cowork sandboxes during the migration instead of skipping them
thinhlpg9f4944879e12
diff --git a/web-app/src/lib/__tests__/agentTools.test.ts b/web-app/src/lib/__tests__/agentTools.test.tsindex c42309c6a..9943e1e51 100644--- a/web-app/src/lib/__tests__/agentTools.test.ts+++ b/web-app/src/lib/__tests__/agentTools.test.ts@@ -13,6 +13,7 @@ const subagentResultFill = vi.fn()const attachmentImport = vi.fn()const startMonitor = vi.fn()const getJanDataFolder = vi.fn()+const coreInvoke = vi.fn()vi.mock('@janhq/tauri-plugin-agent-tools-api', () => ({toolSchemas: () => toolSchemas(),@@ -31,7 +32,10 @@ vi.mock('@janhq/tauri-plugin-agent-tools-api', () => ({}))vi.mock('@/hooks/useServiceHub', () => ({- getServiceHub: () => ({ app: () => ({ getJanDataFolder }) }),+ getServiceHub: () => ({+ app: () => ({ getJanDataFolder }),+ core: () => ({ invoke: coreInvoke }),+ }),}))const schemaFor = (name: string) => ({@@ -59,6 +63,9 @@ describe('agentTools', () => {attachmentImport.mockReset()startMonitor.mockReset()getJanDataFolder.mockReset().mockResolvedValue('/data')+ coreInvoke.mockReset().mockImplementation(async (cmd: string) =>+ cmd === 'get_jan_data_folder_path' ? '/data' : undefined+ )})// The chat surface offers the sandboxed shell alone; everything else is@@ -546,14 +553,11 @@ describe('agentTools', () => {})})- it('copies nothing when there is no data folder', async () => {- getJanDataFolder.mockResolvedValue('')+ // Skipping the copy would commit the thread without its files.+ it('rejects when the data folder is not known, so the session is retried', async () => {+ coreInvoke.mockResolvedValue('')const { copySessionWorkspaceToThread } = await import('../agentTools')- await expect(copySessionWorkspaceToThread('s1')).resolves.toEqual({- copied: false,- files: 0,- skipped: 0,- })+ await expect(copySessionWorkspaceToThread('s1')).rejects.toThrow()expect(sessionWorkspaceCopyToThread).not.toHaveBeenCalled()})diff --git a/web-app/src/lib/agentTools.ts b/web-app/src/lib/agentTools.tsindex f26bc1da5..5a67ad34b 100644--- a/web-app/src/lib/agentTools.ts+++ b/web-app/src/lib/agentTools.ts@@ -522,14 +522,20 @@ export async function cleanupThreadWorkspace(threadId: string): Promise<void> {/*** Copy a Cowork session's sandbox into the thread workspace of the same id* (Cowork migration). Unlike the cleanup helpers this THROWS: the migration- * must not commit a thread whose files did not arrive. With no data folder- * there is nothing to copy.+ * must not commit a thread whose files did not arrive.+ *+ * The data folder comes from the backend command, not `window.core.api`: the+ * migration starts before the extension API is installed, and reading the+ * folder there returned nothing, which skipped the copy and committed threads+ * without their files.*/export async function copySessionWorkspaceToThread(sessionId: string): Promise<WorkspaceCopy> {- const dataFolder = await getServiceHub().app().getJanDataFolder()- if (!dataFolder) return { copied: false, files: 0, skipped: 0 }+ const dataFolder = await getServiceHub()+ .core()+ .invoke<string>('get_jan_data_folder_path')+ if (!dataFolder) throw new Error('the Jan data folder is not known yet')return await sessionWorkspaceCopyToThread(dataFolder, sessionId)}