The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { managedRuntimeModeDenial } from "@t3tools/client-runtime/contract-labels"; |
| 2 | import { |
| 3 | clampManagedRuntimeMode, |
| 4 | type ManagedPolicySummary, |
| 5 | type RuntimeMode, |
| 6 | } from "@t3tools/contracts"; |
| 7 | import { useGT, useMessages } from "gt-react-native"; |
| 8 | import { View } from "react-native"; |
| 9 | |
| 10 | import { AppText } from "../../components/ui/AppText"; |
| 11 | import { Button } from "../../components/ui/Button"; |
| 12 | import { |
| 13 | updateComposerDraftSettings, |
| 14 | useComposerDraftSettings, |
| 15 | } from "../../state/use-composer-drafts"; |
| 16 | import { runtimeModeChoicesForSupportedModes } from "./thread-settings-options"; |
| 17 | |
| 18 | /** |
| 19 | * Shown while a thread's mode is above its environment's managed ceiling, where the server |
| 20 | * refuses every turn. Switching sets the draft's mode, which the next send applies first. |
| 21 | */ |
| 22 | export function ManagedRuntimeModeNotice(props: { |
| 23 | readonly threadKey: string; |
| 24 | readonly threadRuntimeMode: RuntimeMode; |
| 25 | readonly supportedRuntimeModes: ReadonlyArray<RuntimeMode> | undefined; |
| 26 | readonly policy: ManagedPolicySummary | undefined; |
| 27 | }) { |
| 28 | const gt = useGT(); |
| 29 | const messages = useMessages(); |
| 30 | const draftSettings = useComposerDraftSettings(props.threadKey); |
| 31 | const runtimeMode = draftSettings.runtimeMode ?? props.threadRuntimeMode; |
| 32 | const denial = managedRuntimeModeDenial(props.policy, runtimeMode, messages); |
| 33 | if (denial === undefined) return null; |
| 34 | const choices = runtimeModeChoicesForSupportedModes(props.supportedRuntimeModes); |
| 35 | const target = clampManagedRuntimeMode( |
| 36 | props.policy, |
| 37 | runtimeMode, |
| 38 | choices.map((choice) => choice.mode), |
| 39 | ); |
| 40 | const targetLabel = choices.find((choice) => choice.mode === target)?.label; |
| 41 | return ( |
| 42 | <View className="gap-2 px-4 pb-3"> |
| 43 | <AppText textRole="footnote" className="text-foreground-muted"> |
| 44 | {gt("{denial} Switch this thread's mode to continue.", { denial })} |
| 45 | </AppText> |
| 46 | {target === undefined || targetLabel === undefined ? null : ( |
| 47 | <Button |
| 48 | label={gt("Switch to {mode}", { mode: messages(targetLabel) })} |
| 49 | onPress={() => updateComposerDraftSettings(props.threadKey, { runtimeMode: target })} |
| 50 | /> |
| 51 | )} |
| 52 | </View> |
| 53 | ); |
| 54 | } |