The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 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 | import { useMemo } from "react"; |
| 9 | |
| 10 | import { appAtomRegistry } from "../../state/atom-registry"; |
| 11 | import { orchestrationEnvironment } from "../../state/orchestration"; |
| 12 | import { serverEnvironment } from "../../state/server"; |
| 13 | import { environmentThreadShells } from "../../state/threads"; |
| 14 | |
| 15 | function archivedSnapshotAtom(environmentId: EnvironmentId) { |
| 16 | return orchestrationEnvironment.archivedShellSnapshot({ |
| 17 | environmentId, |
| 18 | input: {}, |
| 19 | }); |
| 20 | } |
| 21 | |
| 22 | const archivedSnapshotsAtom = createArchivedThreadSnapshotsAtomFamily({ |
| 23 | getSnapshotAtom: archivedSnapshotAtom, |
| 24 | hiddenThreadTagsAtom: serverEnvironment.hiddenThreadTagsAtom, |
| 25 | hiddenThreadKeysAtom: environmentThreadShells.hiddenThreadKeysAtom, |
| 26 | liveThreadRefsAtom: environmentThreadShells.threadRefsAtom, |
| 27 | anyEnvironmentHidingAtom: environmentThreadShells.anyEnvironmentHidingAtom, |
| 28 | labelPrefix: "mobile:archived-thread-snapshots", |
| 29 | }); |
| 30 | |
| 31 | export function refreshArchivedThreadsForEnvironment(environmentId: EnvironmentId): void { |
| 32 | appAtomRegistry.refresh(archivedSnapshotAtom(environmentId)); |
| 33 | } |
| 34 | |
| 35 | export function useArchivedThreadSnapshots(environmentIds: ReadonlyArray<EnvironmentId>): { |
| 36 | readonly snapshots: ReadonlyArray<ArchivedSnapshotEntry>; |
| 37 | readonly error: string | null; |
| 38 | readonly isLoading: boolean; |
| 39 | readonly refresh: () => void; |
| 40 | } { |
| 41 | const environmentKey = useMemo( |
| 42 | () => makeArchivedThreadsEnvironmentKey(environmentIds), |
| 43 | [environmentIds], |
| 44 | ); |
| 45 | const result = useAtomValue(archivedSnapshotsAtom(environmentKey)); |
| 46 | const refresh = () => { |
| 47 | for (const environmentId of environmentIds) { |
| 48 | appAtomRegistry.refresh(archivedSnapshotAtom(environmentId)); |
| 49 | } |
| 50 | }; |
| 51 | |
| 52 | return { ...result, refresh }; |
| 53 | } |