The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { |
| 2 | AuthRelayReadScope, |
| 3 | AuthRelayWriteScope, |
| 4 | type EnvironmentId, |
| 5 | managedCapabilityDenial, |
| 6 | } from "@t3tools/contracts"; |
| 7 | |
| 8 | import { useManagedPolicy } from "../state/managedPolicy"; |
| 9 | import { useEnvironmentCanConfigureRelay, useEnvironmentScope } from "../state/session"; |
| 10 | import { useCloudLinkState } from "./cloudLinkState"; |
| 11 | import { hasCloudPublicConfig } from "./publicConfig"; |
| 12 | import { resolveT3ConnectTurnOn } from "./t3ConnectState"; |
| 13 | |
| 14 | /** Whether this client can turn on T3 Connect for `environmentId`, and if not, why. */ |
| 15 | export function useT3ConnectTurnOn(environmentId: EnvironmentId | null) { |
| 16 | const canReadRelay = useEnvironmentScope(environmentId, AuthRelayReadScope); |
| 17 | const canWriteRelay = useEnvironmentScope(environmentId, AuthRelayWriteScope); |
| 18 | const canConfigureRelay = useEnvironmentCanConfigureRelay(environmentId); |
| 19 | const connectDenial = managedCapabilityDenial(useManagedPolicy(environmentId), "connect"); |
| 20 | const linkState = useCloudLinkState(environmentId).data; |
| 21 | return resolveT3ConnectTurnOn({ |
| 22 | // Unknown while loading and on older servers, which keep today's switch in Settings. |
| 23 | linkableHere: linkState?.linkableHere ?? true, |
| 24 | cloudConfigured: hasCloudPublicConfig(), |
| 25 | canReadRelay, |
| 26 | canWriteRelay: canWriteRelay && canConfigureRelay, |
| 27 | connectDenial, |
| 28 | }); |
| 29 | } |