|
1 | 1 | import { useAtomValue } from "@effect/atom-react"; |
| 2 | +import { useEffect } from "react"; |
2 | 3 | import { deriveReportedModelSelection } from "@t3tools/client-runtime/state/thread-execution"; |
3 | 4 |
|
4 | 5 | import { appAtomRegistry } from "./atom-registry"; |
@@ -34,7 +35,7 @@ import { projectGlyphImageAtom, projectGlyphKey } from "../native/ProjectChipIco |
34 | 35 | import { projectFaviconUrlAtom } from "./assets"; |
35 | 36 | import { environmentProjects } from "./projects"; |
36 | 37 | import { environmentServerConfigsAtom, serverEnvironment } from "./server"; |
37 | | -import { environmentThreadDetails, environmentThreadShells } from "./threads"; |
| 38 | +import { environmentThreadDetails, environmentThreadShells, threadFamilies } from "./threads"; |
38 | 39 |
|
39 | 40 | const EMPTY_PROJECT_ATOM = Atom.make<EnvironmentProject | null>(null).pipe( |
40 | 41 | Atom.withLabel("mobile-project:empty"), |
@@ -208,11 +209,27 @@ export function useSideChats(ref: ScopedThreadRef) { |
208 | 209 | } |
209 | 210 |
|
210 | 211 | export function useLiveThreadLinkLabels(markdown: string, environmentId: EnvironmentId): string { |
| 212 | + const refs = hasThreadLinks(markdown) ? threadLinkRefs(markdown, environmentId) : []; |
211 | 213 | const titles = useAtomValue( |
212 | | - hasThreadLinks(markdown) |
213 | | - ? threadLinkTitlesAtom(JSON.stringify(threadLinkRefs(markdown, environmentId).map(threadKey))) |
214 | | - : EMPTY_THREAD_LINK_TITLES_ATOM, |
| 214 | + refs.length === 0 |
| 215 | + ? EMPTY_THREAD_LINK_TITLES_ATOM |
| 216 | + : threadLinkTitlesAtom(JSON.stringify(refs.map(threadKey))), |
215 | 217 | ); |
| 218 | + // Shells leave out idle subagent children and older settled threads, so a cited thread the |
| 219 | + // shell lacks is read with its family until it lands; only a settled empty read proves it gone. |
| 220 | + const missingKey = JSON.stringify( |
| 221 | + refs.filter((ref) => !titles.has(threadKey(ref))).map(threadKey), |
| 222 | + ); |
| 223 | + // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- mounts family reads for cited threads the shell omits while this message shows them |
| 224 | + useEffect(() => { |
| 225 | + const releases = (JSON.parse(missingKey) as ReadonlyArray<string>).map((key) => { |
| 226 | + const ref = scopeThreadRef(...decodeThreadKey(JSON.parse(key))); |
| 227 | + return threadFamilies.mount(appAtomRegistry, ref.environmentId, ref.threadId); |
| 228 | + }); |
| 229 | + return () => { |
| 230 | + for (const release of releases) release(); |
| 231 | + }; |
| 232 | + }, [missingKey]); |
216 | 233 | return relabelThreadLinks(markdown, environmentId, (ref) => titles.get(threadKey(ref))); |
217 | 234 | } |
218 | 235 |
|
|
0 commit comments