Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

runtimeModeConfig.ts

58 lines1.9 KB

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