Open History to see the last commit
1import {
2 managedRuntimeModeDenial,
3 type ManagedPolicySummary,
4 type RuntimeMode,
5} from "@t3tools/contracts";
6import {
7 type LucideIcon,
8 LockIcon,
9 PenLineIcon,
10 ShieldCheckIcon,
11 ShieldOffIcon,
12} from "lucide-react";
13
14export const runtimeModeConfig: Record<
15 RuntimeMode,
16 { label: string; description: string; icon: LucideIcon }
17> = {
18 "approval-required": {
19 label: "Supervised",
20 description: "Ask before commands and file changes.",
21 icon: LockIcon,
22 },
23 "auto-accept-edits": {
24 label: "Auto-accept edits",
25 description: "Auto-approve edits, ask before other actions.",
26 icon: PenLineIcon,
27 },
28 auto: {
29 label: "Auto",
30 description: "Supported providers approve routine actions; others still ask.",
31 icon: ShieldCheckIcon,
32 },
33 "full-access": {
34 label: "Full access",
35 description: "Allow commands and edits without prompts.",
36 // An open lock reads like a closed one at small sizes; a crossed shield does not.
37 icon: ShieldOffIcon,
38 },
39};
40
41export const runtimeModeOptions = Object.keys(runtimeModeConfig) as RuntimeMode[];
42
43/** The modes a provider supports (all when it reports none) and the mode a thread really runs in. */
44export function resolveCompatibleRuntimeMode(
45 runtimeMode: RuntimeMode,
46 supportedRuntimeModes: ReadonlyArray<RuntimeMode> | undefined,
47) {
48 const modes =
49 supportedRuntimeModes && supportedRuntimeModes.length > 0
50 ? runtimeModeOptions.filter((mode) => supportedRuntimeModes.includes(mode))
51 : runtimeModeOptions;
52 return { modes, mode: modes.includes(runtimeMode) ? runtimeMode : (modes[0] ?? runtimeMode) };
53}
54
55export function resolveRuntimeModeOptions(
56 modes: ReadonlyArray<RuntimeMode>,
57 managedPolicy: ManagedPolicySummary | undefined,
58) {
59 return modes.map((mode) => {
60 const option = { mode, ...runtimeModeConfig[mode] };
61 const disabledReason = managedRuntimeModeDenial(managedPolicy, mode);
62 return disabledReason === undefined ? option : { ...option, disabledReason };
63 });
64}