Open History to see the last commit
1import type { ProviderOptionDescriptor, RuntimeMode } from "@t3tools/contracts";
2
3/**
4 * Prompt-injected values (ultrathink and friends) are filtered from the
5 * descriptor metadata; ultracode is a real option but a workflow trigger, not a
6 * reasoning level.
7 */
8const HIDDEN_EFFORT_OPTION_IDS: ReadonlySet<string> = new Set(["ultracode"]);
9
10export const RUNTIME_MODE_CHOICES: ReadonlyArray<{
11 readonly mode: RuntimeMode;
12 readonly label: string;
13 readonly description: string;
14}> = [
15 {
16 mode: "approval-required",
17 label: "Supervised",
18 description: "Ask before commands and file changes.",
19 },
20 {
21 mode: "auto-accept-edits",
22 label: "Auto-accept edits",
23 description: "Auto-approve edits, ask before other actions.",
24 },
25 {
26 mode: "auto",
27 label: "Auto",
28 description: "Supported providers approve routine actions; others still ask.",
29 },
30 {
31 mode: "full-access",
32 label: "Full access",
33 description: "Allow commands and edits without prompts.",
34 },
35];
36
37export function runtimeModeChoicesForSupportedModes(
38 supportedRuntimeModes: ReadonlyArray<RuntimeMode> | undefined,
39) {
40 return supportedRuntimeModes && supportedRuntimeModes.length > 0
41 ? RUNTIME_MODE_CHOICES.filter((choice) => supportedRuntimeModes.includes(choice.mode))
42 : RUNTIME_MODE_CHOICES;
43}
44
45export function compatibleRuntimeModeForChoices(
46 runtimeMode: RuntimeMode,
47 choices: ReadonlyArray<{ readonly mode: RuntimeMode }>,
48): RuntimeMode {
49 return choices.some((choice) => choice.mode === runtimeMode)
50 ? runtimeMode
51 : (choices[0]?.mode ?? runtimeMode);
52}
53
54export function selectableChoices(
55 descriptor: Extract<ProviderOptionDescriptor, { type: "select" }>,
56) {
57 const injected = new Set(descriptor.promptInjectedValues ?? []);
58 return descriptor.options.filter(
59 (option) => !injected.has(option.id) && !HIDDEN_EFFORT_OPTION_IDS.has(option.id),
60 );
61}