The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import type { EnvironmentId, RuntimeMode } from "@t3tools/contracts"; |
| 2 | import { useAtomValue } from "@effect/atom-react"; |
| 3 | import { T, useGT, useMessages } from "gt-react"; |
| 4 | |
| 5 | import { shortcutLabelForCommand } from "../keybindings"; |
| 6 | import { useManagedPolicy } from "../state/managedPolicy"; |
| 7 | import { primaryServerKeybindingsAtom } from "../state/server"; |
| 8 | import { ComposerControl } from "./chat/ComposerControl"; |
| 9 | import { ComposerPermissionsSection } from "./chat/ComposerFooterControls"; |
| 10 | import { useComposerMenuProps } from "./chat/composerEventScope"; |
| 11 | import { |
| 12 | resolveCompatibleRuntimeMode, |
| 13 | resolveRuntimeModeOptions, |
| 14 | runtimeModeConfig, |
| 15 | } from "./chat/runtimeModeConfig"; |
| 16 | import { ComposerContextLabel } from "./ComposerContextLabel"; |
| 17 | import { Menu, MenuPopup, MenuTrigger } from "./ui/menu"; |
| 18 | import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip"; |
| 19 | |
| 20 | export function ComposerContextPermissions(props: { |
| 21 | environmentId: EnvironmentId | null; |
| 22 | runtimeMode: RuntimeMode; |
| 23 | supportedRuntimeModes: ReadonlyArray<RuntimeMode> | undefined; |
| 24 | onRuntimeModeChange: (mode: RuntimeMode) => void; |
| 25 | }) { |
| 26 | const gt = useGT(); |
| 27 | const messages = useMessages(); |
| 28 | const shortcutLabel = shortcutLabelForCommand( |
| 29 | useAtomValue(primaryServerKeybindingsAtom), |
| 30 | "composer.mode", |
| 31 | ); |
| 32 | const { mode, modes } = resolveCompatibleRuntimeMode( |
| 33 | props.runtimeMode, |
| 34 | props.supportedRuntimeModes, |
| 35 | ); |
| 36 | const options = resolveRuntimeModeOptions(modes, useManagedPolicy(props.environmentId), messages); |
| 37 | const composerMenuProps = useComposerMenuProps(); |
| 38 | const { icon: Icon } = runtimeModeConfig[mode]; |
| 39 | const label = messages(runtimeModeConfig[mode].label); |
| 40 | return ( |
| 41 | <Menu> |
| 42 | <Tooltip> |
| 43 | <TooltipTrigger |
| 44 | render={ |
| 45 | <MenuTrigger |
| 46 | render={ |
| 47 | <ComposerControl |
| 48 | size="xs" |
| 49 | className="ms-auto min-w-0 shrink-0" |
| 50 | aria-label={gt("Permissions: {label}", { label })} |
| 51 | data-composer-context-control |
| 52 | /> |
| 53 | } |
| 54 | /> |
| 55 | } |
| 56 | > |
| 57 | <Icon aria-hidden="true" className="size-3" /> |
| 58 | <ComposerContextLabel>{label}</ComposerContextLabel> |
| 59 | </TooltipTrigger> |
| 60 | <TooltipPopup> |
| 61 | <T>Permissions</T> |
| 62 | {shortcutLabel ? ` · ${shortcutLabel}` : null} |
| 63 | </TooltipPopup> |
| 64 | </Tooltip> |
| 65 | <MenuPopup side="top" align="end" {...composerMenuProps}> |
| 66 | <ComposerPermissionsSection |
| 67 | runtimeMode={mode} |
| 68 | runtimeModeOptions={options} |
| 69 | onRuntimeModeChange={props.onRuntimeModeChange} |
| 70 | /> |
| 71 | </MenuPopup> |
| 72 | </Menu> |
| 73 | ); |
| 74 | } |