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

runtimeModeConfig.ts

43 lines1.5 KB

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