The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { useAtomValue } from "@effect/atom-react"; |
| 2 | import { |
| 3 | type ArchivedSnapshotEntry, |
| 4 | createArchivedThreadSnapshotsAtomFamily, |
| 5 | makeArchivedThreadsEnvironmentKey, |
| 6 | } from "@t3tools/client-runtime/state/threads"; |
| 7 | import type { EnvironmentId } from "@t3tools/contracts"; |
| 8 | |
| 9 | import { orchestrationEnvironment } from "../state/orchestration"; |
| 10 | import { serverEnvironment } from "../state/server"; |
| 11 | import { environmentThreadShells } from "../state/threads"; |
| 12 | import { appAtomRegistry } from "../rpc/atomRegistry"; |
| 13 | |
| 14 | function archivedSnapshotAtom(environmentId: EnvironmentId) { |
| 15 | return orchestrationEnvironment.archivedShellSnapshot({ |
| 16 | environmentId, |
| 17 | input: {}, |
| 18 | }); |
| 19 | } |
| 20 | |
| 21 | const archivedSnapshotsAtom = createArchivedThreadSnapshotsAtomFamily({ |
| 22 | getSnapshotAtom: archivedSnapshotAtom, |
| 23 | hiddenThreadTagsAtom: serverEnvironment.hiddenThreadTagsAtom, |
| 24 | hiddenThreadKeysAtom: environmentThreadShells.hiddenThreadKeysAtom, |
| 25 | liveThreadRefsAtom: environmentThreadShells.threadRefsAtom, |
| 26 | anyEnvironmentHidingAtom: environmentThreadShells.anyEnvironmentHidingAtom, |
| 27 | labelPrefix: "web:archived-thread-snapshots", |
| 28 | }); |
| 29 | |
| 30 | export function refreshArchivedThreadsForEnvironment(environmentId: EnvironmentId): void { |
| 31 | appAtomRegistry.refresh(archivedSnapshotAtom(environmentId)); |
| 32 | } |
| 33 | |
| 34 | export function useArchivedThreadSnapshots(environmentIds: ReadonlyArray<EnvironmentId>): { |
| 35 | readonly snapshots: ReadonlyArray<ArchivedSnapshotEntry>; |
| 36 | readonly error: string | null; |
| 37 | readonly isLoading: boolean; |
| 38 | readonly refresh: () => void; |
| 39 | } { |
| 40 | const environmentKey = makeArchivedThreadsEnvironmentKey(environmentIds); |
| 41 | const result = useAtomValue(archivedSnapshotsAtom(environmentKey)); |
| 42 | const refresh = () => { |
| 43 | for (const environmentId of environmentIds) { |
| 44 | appAtomRegistry.refresh(archivedSnapshotAtom(environmentId)); |
| 45 | } |
| 46 | }; |
| 47 | |
| 48 | return { |
| 49 | ...result, |
| 50 | refresh, |
| 51 | }; |
| 52 | } |