Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
fix(web-app): explain a Cowork row that cannot open instead of bouncing home
Akarshan Biswasdc44f97451a6
diff --git a/web-app/src/components/left-sidebar/NavHistory.tsx b/web-app/src/components/left-sidebar/NavHistory.tsxindex d6ce1d10e..f182b6563 100644--- a/web-app/src/components/left-sidebar/NavHistory.tsx+++ b/web-app/src/components/left-sidebar/NavHistory.tsx@@ -38,6 +38,8 @@ import { ThreadItem } from '@/containers/ThreadList'import { RenameThreadDialog } from '@/containers/dialogs/RenameThreadDialog'import { DeleteAllThreadsDialog } from '@/containers/dialogs/DeleteAllThreadsDialog'import { mergeHistory } from '@/lib/mergeHistory'+import { canOpenCoworkSession } from '@/lib/coworkOpenable'+import { toast } from 'sonner'/*** One history for every conversation, newest first. It replaces the Home/Cowork@@ -77,12 +79,17 @@ const CoworkRow = memo(function CoworkRow({isActive={isCurrent}className="data-[active=true]:bg-sidebar-foreground/10 dark:data-[active=true]:bg-sidebar-accent"data-testid={`history-cowork-${id}`}- onClick={() =>+ onClick={() => {+ // The route would redirect home for these; say why instead.+ if (!canOpenCoworkSession(id)) {+ toast.error(t('common:coworkSessionUnavailable'))+ return+ }navigate({to: route.coworkSession,params: { sessionId: id },})- }+ }}>{isRunning && (<Loader2 className="size-3 shrink-0 animate-spin text-muted-foreground" />diff --git a/web-app/src/components/left-sidebar/__tests__/navHistory.test.tsx b/web-app/src/components/left-sidebar/__tests__/navHistory.test.tsxindex 9b0f451c1..f3d61935b 100644--- a/web-app/src/components/left-sidebar/__tests__/navHistory.test.tsx+++ b/web-app/src/components/left-sidebar/__tests__/navHistory.test.tsx@@ -52,7 +52,8 @@ const projects = vi.hoisted(() => ({vi.mock('@/hooks/useThreadManagement', () => ({useThreadManagement: () => projects,}))-vi.mock('sonner', () => ({ toast: { success: vi.fn(), error: vi.fn() } }))+const toast = vi.hoisted(() => ({ success: vi.fn(), error: vi.fn() }))+vi.mock('sonner', () => ({ toast }))vi.mock('@/containers/dialogs/DeleteAllThreadsDialog', () => ({DeleteAllThreadsDialog: () => <div data-testid="delete-all" />,}))@@ -121,6 +122,7 @@ beforeEach(() => {projects.foldersLoaded = trueuseThreads.setState({ threads: {} })router.navigate.mockClear()+ toast.error.mockClear()router.sessionId = undefineduseCoworkSessions.setState({ sessions: [session('open', 'Open one'), session('other', 'Other one')] })})@@ -296,6 +298,26 @@ describe('NavHistory one row per conversation (write-through mirror)', () => {expect(screen.getByTestId('history-cowork-solo')).toHaveTextContent('Solo')})+ it('tells the user instead of bouncing home when the session behind a row is missing', () => {+ useCoworkSessions.setState({ sessions: [] })+ useThreads.setState({ threads: { solo: mirror('solo', 'Solo') } })+ render(<NavHistory />)+ fireEvent.click(screen.getByTestId('history-cowork-solo'))+ expect(router.navigate).not.toHaveBeenCalled()+ expect(toast.error).toHaveBeenCalledWith('common:coworkSessionUnavailable')+ })++ it('tells the user instead of bouncing home when the session is untouched', () => {+ useCoworkSessions.setState({+ sessions: [{ ...session('blank', 'Blank'), turns: [] }],+ })+ useThreads.setState({ threads: { blank: mirror('blank', 'Blank') } })+ render(<NavHistory />)+ fireEvent.click(screen.getByTestId('history-cowork-blank'))+ expect(router.navigate).not.toHaveBeenCalled()+ expect(toast.error).toHaveBeenCalledWith('common:coworkSessionUnavailable')+ })+it('deletes a mirrored session through the session store', () => {useThreads.setState({ threads: { open: mirror('open', 'Open one'), other: mirror('other', 'Other one') } })render(<NavHistory />)diff --git a/web-app/src/lib/coworkOpenable.ts b/web-app/src/lib/coworkOpenable.tsnew file mode 100644index 000000000..887c2cd69--- /dev/null+++ b/web-app/src/lib/coworkOpenable.ts@@ -0,0 +1,25 @@+import { useCoworkRun } from '@/hooks/useCoworkRun'+import { useCoworkSessions } from '@/hooks/useCoworkSessions'+import { peekCoworkHandoff } from '@/lib/coworkHandoff'++/**+ * Whether `/cowork/$sessionId` shows this session rather than redirecting home.+ * The route guard and the sidebar row share it, so a row can explain a refusal+ * instead of navigating to a redirect that looks like a dead click.+ *+ * An untouched session is not a different start surface: the unified composer+ * stays home unless its first prompt is being handed off or a run is active.+ */+export function canOpenCoworkSession(sessionId: string): boolean {+ const session = useCoworkSessions+ .getState()+ .sessions.find((s) => s.id === sessionId)+ if (!session) return false+ if (session.unavailable || session.cleared) return true+ return (+ session.turns.length > 0 ||+ session.messages.length > 0 ||+ !!useCoworkRun.getState().runId[sessionId] ||+ !!peekCoworkHandoff(sessionId)+ )+}diff --git a/web-app/src/locales/de-DE/common.json b/web-app/src/locales/de-DE/common.jsonindex 80a29eae8..41e5a977b 100644--- a/web-app/src/locales/de-DE/common.json+++ b/web-app/src/locales/de-DE/common.json@@ -433,6 +433,7 @@"artifacts": "Artefakte","skills": "Skills","deleteSession": "Sitzung löschen",+ "coworkSessionUnavailable": "Diese Unterhaltung hat noch nichts anzuzeigen.","deleteSessionTitle": "Sitzung löschen?","deleteSessionBody": "„{{title}}“ und das zugehörige Protokoll werden endgültig gelöscht. Das lässt sich nicht rückgängig machen.","sidebar": {diff --git a/web-app/src/locales/en/common.json b/web-app/src/locales/en/common.jsonindex 49e83f285..edb8385d7 100644--- a/web-app/src/locales/en/common.json+++ b/web-app/src/locales/en/common.json@@ -88,6 +88,7 @@"skillImported": "Imported {{name}}","sessions": "Sessions","deleteSession": "Delete session",+ "coworkSessionUnavailable": "This conversation has nothing to show yet.","deleteSessionTitle": "Delete session?","deleteSessionBody": "\"{{title}}\" and its transcript will be permanently deleted. This can't be undone.","newChat": "New Chat",@@ -830,7 +831,7 @@"triggerLabel": "Select model: {{name}}","dialogLabel": "Choose a model","searchLabel": "Search models or providers",- "searchPlaceholder": "Search models or providers…",+ "searchPlaceholder": "Search models or providers...","listLabel": "Models","noMatches": "No matching models","noModels": "No models configured",diff --git a/web-app/src/locales/fr/common.json b/web-app/src/locales/fr/common.jsonindex 7df3e02b0..96cfaac3f 100644--- a/web-app/src/locales/fr/common.json+++ b/web-app/src/locales/fr/common.json@@ -436,6 +436,7 @@"artifacts": "Artefacts","skills": "Compétences","deleteSession": "Supprimer la session",+ "coworkSessionUnavailable": "Cette conversation n'a encore rien à afficher.","deleteSessionTitle": "Supprimer la session ?","deleteSessionBody": "« {{title}} » et sa transcription seront supprimées définitivement. Cette action est irréversible.","sidebar": {diff --git a/web-app/src/locales/ja/common.json b/web-app/src/locales/ja/common.jsonindex dae317ba8..97ca04387 100644--- a/web-app/src/locales/ja/common.json+++ b/web-app/src/locales/ja/common.json@@ -550,6 +550,7 @@"artifacts": "アーティファクト","skills": "スキル","deleteSession": "セッションを削除",+ "coworkSessionUnavailable": "この会話にはまだ表示できる内容がありません。","deleteSessionTitle": "セッションを削除しますか?","deleteSessionBody": "「{{title}}」とそのトランスクリプトは完全に削除されます。この操作は元に戻せません。","sidebar": {diff --git a/web-app/src/locales/zh-CN/common.json b/web-app/src/locales/zh-CN/common.jsonindex 0052f3a9c..45c335f77 100644--- a/web-app/src/locales/zh-CN/common.json+++ b/web-app/src/locales/zh-CN/common.json@@ -612,6 +612,7 @@"artifacts": "产物","skills": "技能","deleteSession": "删除会话",+ "coworkSessionUnavailable": "此对话暂无可显示的内容。","deleteSessionTitle": "删除会话?","deleteSessionBody": "“{{title}}”及其记录将被永久删除,此操作无法撤销。","sidebar": {diff --git a/web-app/src/routes/cowork/$sessionId.tsx b/web-app/src/routes/cowork/$sessionId.tsxindex 53c435c18..8727afad6 100644--- a/web-app/src/routes/cowork/$sessionId.tsx+++ b/web-app/src/routes/cowork/$sessionId.tsx@@ -1,7 +1,6 @@import { createFileRoute, redirect, useParams } from '@tanstack/react-router'import { useEffect } from 'react'-import { useCoworkRun } from '@/hooks/useCoworkRun'-import { peekCoworkHandoff } from '@/lib/coworkHandoff'+import { canOpenCoworkSession } from '@/lib/coworkOpenable'import { route } from '@/constants/routes'import { useCoworkSessions } from '@/hooks/useCoworkSessions'import { CoworkPage } from '@/containers/CoworkPage'@@ -11,14 +10,7 @@ export const Route = createFileRoute('/cowork/$sessionId')({const { sessionId } = params as { sessionId: string }// Sessions are hydrated before routes render, so an id that is not in the// store is unknown, not "not loaded yet".- const session = useCoworkSessions.getState().sessions.find((s) => s.id === sessionId)- if (!session) throw redirect({ to: route.home, replace: true })- // An untouched session is not a different start surface. Keep the unified- // composer unless its first prompt is being handed off or a run is active.- if (!session.unavailable && !session.cleared && !session.turns.length && !session.messages.length &&- !useCoworkRun.getState().runId[sessionId] && !peekCoworkHandoff(sessionId)) {- throw redirect({ to: route.home, replace: true })- }+ if (!canOpenCoworkSession(sessionId)) throw redirect({ to: route.home, replace: true })// Select here, not while rendering: a render-phase store write warns on// every switch and re-selects a session deleted under the mounted route.useCoworkSessions.getState().selectSession(sessionId)