@@ -8,10 +8,11 @@ import type { ServerConnection } from "@/runtime/server/registry"
88import { sessionHref } from "@/shell/routes/session"
99import { useData } from "@/runtime/server/current"
1010import { useServerSDK } from "@/runtime/server/client"
11- import { useTabs } from "@/shell/tabs/tabs"
11+ import { useTabs , type Tab } from "@/shell/tabs/tabs"
1212import { readLocalImage } from "@/runtime/server/image"
1313import { useLanguage } from "@/runtime/i18n/language"
1414import { showToast } from "@/shell/notifications/toast"
15+ import { createTurnDiffCache } from "@/session/timeline/turn-diffs"
1516
1617export function SessionUIProvider (
1718 props : ParentProps < {
@@ -65,6 +66,23 @@ export function SessionUIProvider(
6566
6667 const providers = useProviders ( directory )
6768
69+ // Turn diffs live in the tab's in-memory state, so they outlast timeline remounts and go when the tab closes.
70+ const turnDiffs = ( ) => {
71+ const id = params . id
72+
73+ if ( ! id ) return
74+
75+ const tab =
76+ tabs . store . find (
77+ ( item ) =>
78+ item . type === "session" &&
79+ item . server === props . server &&
80+ ( item . sessionId === id || item . routeSessionId === id ) ,
81+ ) ?? ( { type : "session" , server : props . server , sessionId : id } satisfies Tab )
82+
83+ return tabs . state ( tab , "turnDiffs" , createTurnDiffCache )
84+ }
85+
6886 const sessionUIData = createMemo ( ( ) => ( {
6987 provider : providers . ready ( )
7088 ? { all : providers . all ( ) , default : providers . default ( ) , connected : providers . connected ( ) . map ( ( item ) => item . id ) }
@@ -88,6 +106,10 @@ export function SessionUIProvider(
88106 sessionID = { params . id }
89107 shellRunning = { ( id ) => ! ! data . shell . get ( id ) }
90108 shellOutput = { ( input ) => serverSDK . api . shell . output ( input ) }
109+ turnDiff = { {
110+ get : ( input ) => turnDiffs ( ) ?. get ( input ) ,
111+ load : ( input ) => turnDiffs ( ) ?. load ( input , ( ) => serverSDK . api . session . diff ( input ) ) ,
112+ } }
91113 onNavigateToSession = { navigateToSession }
92114 onSessionHref = { href }
93115 >
0 commit comments