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 { useMessages } from "gt-react"; |
| 2 | import { AuthEnvironmentMaintainScope } from "@t3tools/contracts"; |
| 3 | |
| 4 | import { usePrimaryCloudLinkState } from "~/cloud/cloudLinkState"; |
| 5 | import { hasCloudPublicConfig } from "~/cloud/publicConfig"; |
| 6 | import { isElectron } from "~/env"; |
| 7 | import { isLocalEnvironmentDisabled } from "~/localEnvironment"; |
| 8 | import { desktopWslStateAtom } from "~/state/desktopWslState"; |
| 9 | import { useEnvironments, usePrimaryEnvironmentId } from "~/state/environments"; |
| 10 | import { usePeerLinkHosts } from "~/state/peerLinks"; |
| 11 | import { useEnvironmentQuery } from "~/state/query"; |
| 12 | import { useEnvironmentScope } from "~/state/session"; |
| 13 | import { isWslSettingsRowVisible } from "./ConnectionsSettings.logic"; |
| 14 | import { isProviderSettingsEnvironmentAvailable } from "./ProviderSettingsPanel.logic"; |
| 15 | import { |
| 16 | filterAvailableSettingsSearchItems, |
| 17 | getThreadAutoSettlementSearchAvailability, |
| 18 | } from "./settingsSearch"; |
| 19 | |
| 20 | export function useAvailableSettingsSearchItems() { |
| 21 | const { environments } = useEnvironments(); |
| 22 | // Explicit booleans keep flags out of the filter cache so environment updates do not rebuild the list. |
| 23 | const hasEnvironment = |
| 24 | environments.some((environment) => environment.serverConfig !== null) === true; |
| 25 | const hasProviderSettingsEnvironment = |
| 26 | environments.some((environment) => |
| 27 | isProviderSettingsEnvironmentAvailable({ |
| 28 | connectionPhase: environment.connection.phase, |
| 29 | hasServerConfig: environment.serverConfig !== null, |
| 30 | }), |
| 31 | ) === true; |
| 32 | // Any machine that offers it; the row then shows for a settings scope where all selected ones do. |
| 33 | const hasFastWorktreeCheckoutEnvironment = |
| 34 | environments.some( |
| 35 | (environment) => |
| 36 | environment.connection.phase === "connected" && |
| 37 | environment.serverConfig?.environment.capabilities.fastWorktreeCheckout === true, |
| 38 | ) === true; |
| 39 | const hasTextGeneratorsEnvironment = |
| 40 | environments.some( |
| 41 | (environment) => |
| 42 | environment.serverConfig !== null && |
| 43 | environment.serverConfig.managedPolicy?.limits?.providers?.allowedDrivers === undefined, |
| 44 | ) === true; |
| 45 | const hasThreadAutoSettlement = |
| 46 | getThreadAutoSettlementSearchAvailability(environments).eligibleEnvironmentIds.length > 0; |
| 47 | const primaryEnvironmentId = usePrimaryEnvironmentId(); |
| 48 | const canMaintain = useEnvironmentScope(primaryEnvironmentId, AuthEnvironmentMaintainScope); |
| 49 | const hasPeerLinkHost = usePeerLinkHosts().length > 0; |
| 50 | const cloudLinkState = usePrimaryCloudLinkState().data; |
| 51 | // Same fallback as the Connections row: older servers imply a tunnel from `linked`. |
| 52 | const managedTunnelActive = |
| 53 | cloudLinkState?.linkRevoked !== true && |
| 54 | (cloudLinkState?.managedTunnelActive ?? cloudLinkState?.linked ?? false) === true; |
| 55 | const localEnvironmentDisabled = isLocalEnvironmentDisabled() === true; |
| 56 | const canManageLocalBackend = !localEnvironmentDisabled && canMaintain; |
| 57 | const desktopWsl = useEnvironmentQuery( |
| 58 | isElectron && canManageLocalBackend ? desktopWslStateAtom : null, |
| 59 | useMessages(), |
| 60 | ); |
| 61 | const cloudPublicConfig = hasCloudPublicConfig() === true; |
| 62 | const wslSettingsRowVisible = |
| 63 | isWslSettingsRowVisible({ state: desktopWsl.data, error: desktopWsl.error }) === true; |
| 64 | |
| 65 | return filterAvailableSettingsSearchItems({ |
| 66 | localEnvironmentDisabled, |
| 67 | hasCloudPublicConfig: cloudPublicConfig, |
| 68 | hasEnvironment, |
| 69 | hasProviderSettingsEnvironment, |
| 70 | canManageLocalBackend, |
| 71 | isWslSettingsRowVisible: wslSettingsRowVisible, |
| 72 | hasThreadAutoSettlement, |
| 73 | managedTunnelActive, |
| 74 | hasPeerLinkHost, |
| 75 | hasFastWorktreeCheckoutEnvironment, |
| 76 | hasTextGeneratorsEnvironment, |
| 77 | hasPrimaryEnvironment: primaryEnvironmentId !== null, |
| 78 | }); |
| 79 | } |