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 { useAtomRefresh, useAtomValue } from "@effect/atom-react"; |
| 2 | import { type EnvironmentId, type ProviderInstanceId } from "@t3tools/contracts"; |
| 3 | import { |
| 4 | createProviderWorkspaceSnapshotRefreshAtomFamily, |
| 5 | isProviderWorkspaceSnapshotScanning, |
| 6 | type ProviderWorkspaceSnapshotRefreshState, |
| 7 | } from "@t3tools/client-runtime/providerSkills"; |
| 8 | import { Atom } from "effect/reactivity"; |
| 9 | |
| 10 | import { serverEnvironment } from "../../state/server"; |
| 11 | |
| 12 | const providerWorkspaceSnapshotRefresh = createProviderWorkspaceSnapshotRefreshAtomFamily({ |
| 13 | providers: serverEnvironment.providersValueAtom, |
| 14 | refreshProviders: serverEnvironment.refreshProviders, |
| 15 | }); |
| 16 | |
| 17 | const idleRefreshAtom: Atom.Atom<ProviderWorkspaceSnapshotRefreshState | undefined> = Atom.make< |
| 18 | ProviderWorkspaceSnapshotRefreshState | undefined |
| 19 | >(undefined).pipe(Atom.withLabel("provider-workspace-snapshot-refresh:idle")); |
| 20 | |
| 21 | /** |
| 22 | * Keeps a provider's workspace snapshot fresh for the composer's cwd while |
| 23 | * mounted. Returns a check to run when the user types, and whether the cwd's |
| 24 | * skills are still being scanned. |
| 25 | */ |
| 26 | export function useProviderWorkspaceSnapshotRefresh(input: { |
| 27 | readonly environmentId: EnvironmentId | null; |
| 28 | readonly gitCwd: string | null; |
| 29 | readonly instanceId: ProviderInstanceId | undefined; |
| 30 | }): { readonly refresh: () => void; readonly scanning: boolean } { |
| 31 | const { environmentId, gitCwd, instanceId } = input; |
| 32 | const atom = |
| 33 | environmentId && gitCwd && instanceId |
| 34 | ? providerWorkspaceSnapshotRefresh({ environmentId, instanceId, cwd: gitCwd }) |
| 35 | : idleRefreshAtom; |
| 36 | return { |
| 37 | refresh: useAtomRefresh(atom), |
| 38 | scanning: isProviderWorkspaceSnapshotScanning(useAtomValue(atom)), |
| 39 | }; |
| 40 | } |