dsh-coding-subscription-oauth 0.6.3 → 0.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/CHANGELOG.md +258 -250
  2. package/CONTRIBUTING.md +129 -129
  3. package/INSTALL.md +256 -255
  4. package/LICENSE +19 -19
  5. package/NOTICE +11 -11
  6. package/README.de.md +303 -303
  7. package/README.es.md +304 -304
  8. package/README.fr.md +304 -304
  9. package/README.ja.md +304 -304
  10. package/README.ko.md +304 -304
  11. package/README.md +320 -320
  12. package/README.pt-BR.md +304 -304
  13. package/README.ru.md +304 -304
  14. package/README.zh-CN.md +318 -318
  15. package/compatibility/dsh-bom.json +30 -30
  16. package/cordis.patch.yml +13 -13
  17. package/docs/00-project-rules.md +212 -212
  18. package/docs/02-architecture.md +138 -138
  19. package/docs/02-architecture.zh-CN.md +138 -138
  20. package/lib/bin.js +1333 -569
  21. package/lib/bin.js.map +4 -4
  22. package/lib/client.js +1 -1
  23. package/lib/client.js.map +2 -2
  24. package/lib/index.js +689 -25492
  25. package/lib/index.js.map +4 -4
  26. package/lib/invariant.js.map +1 -1
  27. package/media/en/settings_accounts.png +0 -0
  28. package/media/en/settings_capabilities.png +0 -0
  29. package/media/en/settings_gateway.png +0 -0
  30. package/media/settings_accounts.png +0 -0
  31. package/media/settings_capabilities.png +0 -0
  32. package/media/settings_gateway.png +0 -0
  33. package/media/settings_overview.png +0 -0
  34. package/media/zh-CN/settings_accounts.png +0 -0
  35. package/media/zh-CN/settings_capabilities.png +0 -0
  36. package/media/zh-CN/settings_gateway.png +0 -0
  37. package/package.json +223 -223
  38. package/patches/dsh-agy@0.1.2.patch +25 -25
  39. package/scripts/release.mjs +186 -186
  40. package/scripts/smoke-deployed-routes.mjs +146 -146
  41. package/scripts/verify-deployed-catalog.mjs +87 -87
  42. package/src/adapter.ts +348 -348
  43. package/src/alias-adapter.ts +147 -147
  44. package/src/auth-routes.ts +921 -921
  45. package/src/auth.ts +67 -67
  46. package/src/bin.ts +350 -350
  47. package/src/capability-routes.ts +279 -279
  48. package/src/capability-runtime.ts +314 -314
  49. package/src/capability-settings.ts +671 -671
  50. package/src/capability-tools.ts +685 -685
  51. package/src/catalog.ts +271 -271
  52. package/src/client/GrokBuildSettings.tsx +771 -771
  53. package/src/client/api.ts +88 -88
  54. package/src/client/components/AboutTab.tsx +30 -30
  55. package/src/client/components/AccountsTab.tsx +241 -241
  56. package/src/client/components/Badge.tsx +33 -33
  57. package/src/client/components/CapabilitiesTab.tsx +265 -265
  58. package/src/client/components/CliPullPreview.tsx +116 -116
  59. package/src/client/components/CopyButton.tsx +57 -57
  60. package/src/client/components/GatewayTab.tsx +469 -469
  61. package/src/client/components/NoticeBanner.tsx +46 -46
  62. package/src/client/components/ProgressBar.tsx +53 -53
  63. package/src/client/components/ProviderCard.tsx +606 -606
  64. package/src/client/components/SettingsTabs.tsx +75 -75
  65. package/src/client/components/ToggleSwitch.tsx +71 -71
  66. package/src/client/constants.ts +230 -230
  67. package/src/client/display.ts +61 -61
  68. package/src/client/dshClientAdapter.ts +127 -127
  69. package/src/client/gatewaySnippets.ts +37 -37
  70. package/src/client/index.tsx +156 -156
  71. package/src/client/locales.ts +540 -540
  72. package/src/client/microStyles.ts +52 -52
  73. package/src/client/parsers.ts +398 -398
  74. package/src/client/styles.ts +325 -325
  75. package/src/client/types.ts +199 -199
  76. package/src/codex-http.ts +447 -447
  77. package/src/codex-images.ts +503 -503
  78. package/src/codex-model-capabilities.ts +320 -320
  79. package/src/codex-search.ts +245 -245
  80. package/src/codex-usage.ts +263 -263
  81. package/src/compatibility.ts +55 -55
  82. package/src/dsh-host-adapter.ts +173 -173
  83. package/src/gateway-anthropic-messages.ts +84 -84
  84. package/src/gateway-auth.ts +102 -102
  85. package/src/gateway-backend.ts +274 -274
  86. package/src/gateway-body.ts +49 -49
  87. package/src/gateway-config.ts +76 -76
  88. package/src/gateway-http.ts +104 -104
  89. package/src/gateway-openai-chat.ts +124 -124
  90. package/src/gateway-openai-responses.ts +53 -53
  91. package/src/gateway-parse.ts +224 -224
  92. package/src/gateway-protocol.ts +52 -52
  93. package/src/gateway-routes.ts +158 -158
  94. package/src/gateway.ts +258 -258
  95. package/src/grok-errors.ts +24 -24
  96. package/src/grok-imagine.ts +1627 -1627
  97. package/src/grok-import.ts +151 -151
  98. package/src/http-json.ts +82 -82
  99. package/src/ids.ts +59 -59
  100. package/src/imagine-routes.ts +463 -463
  101. package/src/index.ts +735 -735
  102. package/src/invariant.ts +17 -17
  103. package/src/kimi-errors.ts +26 -26
  104. package/src/media-store.ts +927 -927
  105. package/src/oauth-import-routes.ts +324 -324
  106. package/src/oauth-providers.ts +152 -152
  107. package/src/oauth-session.ts +183 -183
  108. package/src/oauth-sources.ts +1104 -1104
  109. package/src/oauth.ts +620 -620
  110. package/src/provider.ts +128 -128
  111. package/src/proxy.ts +11 -11
  112. package/src/redact.ts +72 -72
  113. package/src/session.ts +218 -218
  114. package/src/store.ts +217 -217
  115. package/src/web-origin.ts +296 -296
  116. package/src/web-routes.ts +38 -38
@@ -1,265 +1,265 @@
1
- /** Capabilities tab: Codex toggles, Grok Imagine, and limits. */
2
-
3
- import { CAPABILITY_LIMITS, CAPABILITY_TOGGLES } from "../constants.ts";
4
- import { imagineSourceLabel } from "../parsers.ts";
5
- import {
6
- bodyStyle,
7
- buttonStyle,
8
- cardStyle,
9
- dotStyle,
10
- errorStyle,
11
- hintStyle,
12
- inputStyle,
13
- listStyle,
14
- nestedStyle,
15
- rowStyle,
16
- skeletonStyle,
17
- statusStyle,
18
- titleStyle,
19
- } from "../styles.ts";
20
- import type {
21
- CapabilitySettingKey,
22
- CapabilitySnapshot,
23
- GrokBuildSettingsInjected,
24
- ImagineCredentialView,
25
- } from "../types.ts";
26
- import { Badge } from "./Badge.tsx";
27
- import { ToggleSwitch } from "./ToggleSwitch.tsx";
28
-
29
- export interface CapabilitiesTabProps {
30
- t: GrokBuildSettingsInjected["t"];
31
- capabilities: CapabilitySnapshot | undefined;
32
- capabilitiesError: string | undefined;
33
- capabilitiesBusy: boolean;
34
- imagine: ImagineCredentialView | undefined;
35
- imagineError: string | undefined;
36
- codexSignedIn: boolean;
37
- onRetry: () => void;
38
- onOpenAccounts: (provider: "codex") => void;
39
- onFocusDependency: (target: "codexImages" | "imagineCredential") => void;
40
- onPatchCapability: (key: CapabilitySettingKey, value: boolean | number) => Promise<boolean | undefined> | undefined;
41
- }
42
-
43
- export function CapabilitiesTab({
44
- t,
45
- capabilities,
46
- capabilitiesError,
47
- capabilitiesBusy,
48
- imagine,
49
- imagineError,
50
- codexSignedIn,
51
- onRetry,
52
- onOpenAccounts,
53
- onFocusDependency,
54
- onPatchCapability,
55
- }: CapabilitiesTabProps) {
56
- const codexToggles = CAPABILITY_TOGGLES.filter((item) => !item.key.startsWith("grokImagine"));
57
- const imagineToggles = CAPABILITY_TOGGLES.filter((item) => item.key.startsWith("grokImagine"));
58
-
59
- return (
60
- <section style={cardStyle} aria-labelledby="coding-oauth-capabilities-title">
61
- <div>
62
- <h3 id="coding-oauth-capabilities-title" style={{ ...titleStyle, fontSize: 16 }}>
63
- {t("capabilitiesTitle")}
64
- </h3>
65
- <p style={{ ...bodyStyle, marginTop: 4 }}>{t("capabilitiesIntro")}</p>
66
- </div>
67
- {imagineError === undefined ? null : (
68
- <div style={nestedStyle} role="alert">
69
- <p style={errorStyle}>{imagineError}</p>
70
- <button type="button" style={buttonStyle} onClick={onRetry}>
71
- {t("retry")}
72
- </button>
73
- </div>
74
- )}
75
- {imagine === undefined && imagineError === undefined ? (
76
- <div style={skeletonStyle} role="status" aria-busy="true">
77
- <div style={statusStyle}>
78
- <span aria-hidden="true" style={dotStyle("loading")} />
79
- {t("imagineLoading")}
80
- </div>
81
- </div>
82
- ) : imagine === undefined ? null : (
83
- <div id="coding-oauth-imagine-credential" style={nestedStyle} tabIndex={-1}>
84
- <Badge
85
- label={imagine.configured ? t("imagineConfigured") : t("imagineNotConfigured")}
86
- tone={imagine.configured ? "success" : "neutral"}
87
- />
88
- <p style={hintStyle}>{t("imagineSource", { source: imagineSourceLabel(imagine.source, t) })}</p>
89
- </div>
90
- )}
91
- {capabilitiesError === undefined ? null : (
92
- <div style={nestedStyle} role="alert">
93
- <p style={errorStyle}>{capabilitiesError}</p>
94
- <button type="button" style={buttonStyle} onClick={onRetry}>
95
- {t("retry")}
96
- </button>
97
- </div>
98
- )}
99
- {capabilities === undefined && capabilitiesError === undefined ? (
100
- <div style={skeletonStyle} role="status" aria-busy="true">
101
- <div style={statusStyle}>
102
- <span aria-hidden="true" style={dotStyle("loading")} />
103
- {t("capabilitiesLoading")}
104
- </div>
105
- </div>
106
- ) : capabilities === undefined ? null : (
107
- <fieldset style={{ border: 0, margin: 0, padding: 0, minWidth: 0 }}>
108
- <legend style={{ ...bodyStyle, position: "absolute", width: 1, height: 1, overflow: "hidden" }}>
109
- {t("capabilitiesTitle")}
110
- </legend>
111
- {capabilities.writable ? null : <p style={hintStyle}>{t("capabilitiesReadOnly")}</p>}
112
- <ul style={listStyle}>
113
- {codexToggles.map((item) => {
114
- const checked = capabilities.value[item.key];
115
- const imagesOff = item.requiresImages === true && !capabilities.value.codexImages;
116
- const dependencyReason = !codexSignedIn
117
- ? t("requiresCodexSignIn")
118
- : imagesOff
119
- ? t("requiresCodexImages")
120
- : undefined;
121
- const disabled = capabilitiesBusy || !capabilities.writable || dependencyReason !== undefined;
122
- const switchId = `cap-switch-${item.key}`;
123
- const repairAction = !codexSignedIn
124
- ? { label: t("openCodexAccount"), action: () => onOpenAccounts("codex") }
125
- : imagesOff
126
- ? { label: t("focusCodexImages"), action: () => onFocusDependency("codexImages") }
127
- : undefined;
128
- return (
129
- <li
130
- key={item.key}
131
- style={{
132
- opacity: dependencyReason === undefined ? 1 : 0.65,
133
- transition: "opacity 0.15s ease",
134
- }}
135
- >
136
- <div style={{ ...rowStyle, alignItems: "flex-start" }}>
137
- <label htmlFor={switchId} style={{ flex: "1 1 360px", cursor: disabled ? "default" : "pointer" }}>
138
- <span style={{ display: "block", fontSize: 14, color: "var(--dsw-alias-label-primary)" }}>
139
- {t(item.label)}
140
- </span>
141
- <span id={`cap-hint-${item.key}`} style={{ display: "block", ...hintStyle }}>
142
- {dependencyReason ?? t(item.hint)}
143
- </span>
144
- </label>
145
- {repairAction === undefined ? null : (
146
- <button type="button" style={buttonStyle} onClick={repairAction.action}>
147
- {repairAction.label}
148
- </button>
149
- )}
150
- <ToggleSwitch
151
- id={switchId}
152
- checked={checked}
153
- disabled={disabled}
154
- ariaLabel={t(item.label)}
155
- ariaDescribedBy={`cap-hint-${item.key}`}
156
- onChange={(next) => {
157
- void onPatchCapability(item.key, next);
158
- }}
159
- />
160
- </div>
161
- </li>
162
- );
163
- })}
164
- </ul>
165
- <h4 style={{ ...titleStyle, fontSize: 14 }}>{t("imagineTitle")}</h4>
166
- <ul style={listStyle}>
167
- {imagineToggles.map((item) => {
168
- const checked = capabilities.value[item.key];
169
- const dependencyReason = imagine?.configured === true ? undefined : t("requiresImagineCredential");
170
- const disabled = capabilitiesBusy || !capabilities.writable || dependencyReason !== undefined;
171
- const switchId = `cap-switch-${item.key}`;
172
- return (
173
- <li key={item.key}>
174
- <div style={{ ...rowStyle, alignItems: "flex-start" }}>
175
- <label htmlFor={switchId} style={{ flex: "1 1 360px", cursor: disabled ? "default" : "pointer" }}>
176
- <span style={{ display: "block", fontSize: 14, color: "var(--dsw-alias-label-primary)" }}>
177
- {t(item.label)}
178
- </span>
179
- <span id={`cap-hint-${item.key}`} style={{ display: "block", ...hintStyle }}>
180
- {dependencyReason ?? t(item.hint)}
181
- </span>
182
- </label>
183
- {dependencyReason === undefined ? null : (
184
- <button type="button" style={buttonStyle} onClick={() => onFocusDependency("imagineCredential")}>
185
- {t("focusImagineCredential")}
186
- </button>
187
- )}
188
- <ToggleSwitch
189
- id={switchId}
190
- checked={checked}
191
- disabled={disabled}
192
- ariaLabel={t(item.label)}
193
- ariaDescribedBy={`cap-hint-${item.key}`}
194
- onChange={(next) => {
195
- void onPatchCapability(item.key, next);
196
- }}
197
- />
198
- </div>
199
- </li>
200
- );
201
- })}
202
- </ul>
203
- <div style={nestedStyle}>
204
- <h4 style={{ ...titleStyle, fontSize: 14 }}>{t("capabilityLimitsTitle")}</h4>
205
- <p style={hintStyle}>{t("capabilityLimitsHint")}</p>
206
- <ul style={listStyle}>
207
- {CAPABILITY_LIMITS.map((item) => {
208
- const displayValue = capabilities.value[item.key] / item.scale;
209
- const inputId = `cap-limit-${item.key}`;
210
- return (
211
- <li key={item.key} style={rowStyle}>
212
- <label htmlFor={inputId} style={{ ...bodyStyle, flex: "1 1 360px" }}>
213
- <span style={{ display: "block", color: "var(--dsw-alias-label-primary)" }}>{t(item.label)}</span>
214
- <span id={`${inputId}-hint`} style={{ display: "block", ...hintStyle }}>
215
- {t(item.hint)}
216
- </span>
217
- </label>
218
- <input
219
- key={`${item.key}-${String(capabilities.revision)}-${String(displayValue)}`}
220
- id={inputId}
221
- type="number"
222
- inputMode="numeric"
223
- min={item.min}
224
- max={item.max}
225
- step={1}
226
- defaultValue={displayValue}
227
- disabled={capabilitiesBusy || !capabilities.writable}
228
- aria-describedby={`${inputId}-hint`}
229
- style={{ ...inputStyle, width: 112, flex: "0 0 112px" }}
230
- onInput={(event) => {
231
- event.currentTarget.setCustomValidity("");
232
- }}
233
- onKeyDown={(event) => {
234
- if (event.key === "Enter") event.currentTarget.blur();
235
- if (event.key === "Escape") {
236
- event.currentTarget.value = String(displayValue);
237
- event.currentTarget.setCustomValidity("");
238
- }
239
- }}
240
- onBlur={(event) => {
241
- const target = event.currentTarget;
242
- const next = Number(target.value);
243
- if (!Number.isInteger(next) || next < item.min || next > item.max) {
244
- target.setCustomValidity(t("capabilityLimitInvalid", { min: item.min, max: item.max }));
245
- target.reportValidity();
246
- return;
247
- }
248
- target.setCustomValidity("");
249
- const apiValue = next * item.scale;
250
- if (apiValue === capabilities.value[item.key]) return;
251
- void Promise.resolve(onPatchCapability(item.key, apiValue)).then((saved) => {
252
- if (saved === false && target.isConnected) target.value = String(displayValue);
253
- });
254
- }}
255
- />
256
- </li>
257
- );
258
- })}
259
- </ul>
260
- </div>
261
- </fieldset>
262
- )}
263
- </section>
264
- );
265
- }
1
+ /** Capabilities tab: Codex toggles, Grok Imagine, and limits. */
2
+
3
+ import { CAPABILITY_LIMITS, CAPABILITY_TOGGLES } from "../constants.ts";
4
+ import { imagineSourceLabel } from "../parsers.ts";
5
+ import {
6
+ bodyStyle,
7
+ buttonStyle,
8
+ cardStyle,
9
+ dotStyle,
10
+ errorStyle,
11
+ hintStyle,
12
+ inputStyle,
13
+ listStyle,
14
+ nestedStyle,
15
+ rowStyle,
16
+ skeletonStyle,
17
+ statusStyle,
18
+ titleStyle,
19
+ } from "../styles.ts";
20
+ import type {
21
+ CapabilitySettingKey,
22
+ CapabilitySnapshot,
23
+ GrokBuildSettingsInjected,
24
+ ImagineCredentialView,
25
+ } from "../types.ts";
26
+ import { Badge } from "./Badge.tsx";
27
+ import { ToggleSwitch } from "./ToggleSwitch.tsx";
28
+
29
+ export interface CapabilitiesTabProps {
30
+ t: GrokBuildSettingsInjected["t"];
31
+ capabilities: CapabilitySnapshot | undefined;
32
+ capabilitiesError: string | undefined;
33
+ capabilitiesBusy: boolean;
34
+ imagine: ImagineCredentialView | undefined;
35
+ imagineError: string | undefined;
36
+ codexSignedIn: boolean;
37
+ onRetry: () => void;
38
+ onOpenAccounts: (provider: "codex") => void;
39
+ onFocusDependency: (target: "codexImages" | "imagineCredential") => void;
40
+ onPatchCapability: (key: CapabilitySettingKey, value: boolean | number) => Promise<boolean | undefined> | undefined;
41
+ }
42
+
43
+ export function CapabilitiesTab({
44
+ t,
45
+ capabilities,
46
+ capabilitiesError,
47
+ capabilitiesBusy,
48
+ imagine,
49
+ imagineError,
50
+ codexSignedIn,
51
+ onRetry,
52
+ onOpenAccounts,
53
+ onFocusDependency,
54
+ onPatchCapability,
55
+ }: CapabilitiesTabProps) {
56
+ const codexToggles = CAPABILITY_TOGGLES.filter((item) => !item.key.startsWith("grokImagine"));
57
+ const imagineToggles = CAPABILITY_TOGGLES.filter((item) => item.key.startsWith("grokImagine"));
58
+
59
+ return (
60
+ <section style={cardStyle} aria-labelledby="coding-oauth-capabilities-title">
61
+ <div>
62
+ <h3 id="coding-oauth-capabilities-title" style={{ ...titleStyle, fontSize: 16 }}>
63
+ {t("capabilitiesTitle")}
64
+ </h3>
65
+ <p style={{ ...bodyStyle, marginTop: 4 }}>{t("capabilitiesIntro")}</p>
66
+ </div>
67
+ {imagineError === undefined ? null : (
68
+ <div style={nestedStyle} role="alert">
69
+ <p style={errorStyle}>{imagineError}</p>
70
+ <button type="button" style={buttonStyle} onClick={onRetry}>
71
+ {t("retry")}
72
+ </button>
73
+ </div>
74
+ )}
75
+ {imagine === undefined && imagineError === undefined ? (
76
+ <div style={skeletonStyle} role="status" aria-busy="true">
77
+ <div style={statusStyle}>
78
+ <span aria-hidden="true" style={dotStyle("loading")} />
79
+ {t("imagineLoading")}
80
+ </div>
81
+ </div>
82
+ ) : imagine === undefined ? null : (
83
+ <div id="coding-oauth-imagine-credential" style={nestedStyle} tabIndex={-1}>
84
+ <Badge
85
+ label={imagine.configured ? t("imagineConfigured") : t("imagineNotConfigured")}
86
+ tone={imagine.configured ? "success" : "neutral"}
87
+ />
88
+ <p style={hintStyle}>{t("imagineSource", { source: imagineSourceLabel(imagine.source, t) })}</p>
89
+ </div>
90
+ )}
91
+ {capabilitiesError === undefined ? null : (
92
+ <div style={nestedStyle} role="alert">
93
+ <p style={errorStyle}>{capabilitiesError}</p>
94
+ <button type="button" style={buttonStyle} onClick={onRetry}>
95
+ {t("retry")}
96
+ </button>
97
+ </div>
98
+ )}
99
+ {capabilities === undefined && capabilitiesError === undefined ? (
100
+ <div style={skeletonStyle} role="status" aria-busy="true">
101
+ <div style={statusStyle}>
102
+ <span aria-hidden="true" style={dotStyle("loading")} />
103
+ {t("capabilitiesLoading")}
104
+ </div>
105
+ </div>
106
+ ) : capabilities === undefined ? null : (
107
+ <fieldset style={{ border: 0, margin: 0, padding: 0, minWidth: 0 }}>
108
+ <legend style={{ ...bodyStyle, position: "absolute", width: 1, height: 1, overflow: "hidden" }}>
109
+ {t("capabilitiesTitle")}
110
+ </legend>
111
+ {capabilities.writable ? null : <p style={hintStyle}>{t("capabilitiesReadOnly")}</p>}
112
+ <ul style={listStyle}>
113
+ {codexToggles.map((item) => {
114
+ const checked = capabilities.value[item.key];
115
+ const imagesOff = item.requiresImages === true && !capabilities.value.codexImages;
116
+ const dependencyReason = !codexSignedIn
117
+ ? t("requiresCodexSignIn")
118
+ : imagesOff
119
+ ? t("requiresCodexImages")
120
+ : undefined;
121
+ const disabled = capabilitiesBusy || !capabilities.writable || dependencyReason !== undefined;
122
+ const switchId = `cap-switch-${item.key}`;
123
+ const repairAction = !codexSignedIn
124
+ ? { label: t("openCodexAccount"), action: () => onOpenAccounts("codex") }
125
+ : imagesOff
126
+ ? { label: t("focusCodexImages"), action: () => onFocusDependency("codexImages") }
127
+ : undefined;
128
+ return (
129
+ <li
130
+ key={item.key}
131
+ style={{
132
+ opacity: dependencyReason === undefined ? 1 : 0.65,
133
+ transition: "opacity 0.15s ease",
134
+ }}
135
+ >
136
+ <div style={{ ...rowStyle, alignItems: "flex-start" }}>
137
+ <label htmlFor={switchId} style={{ flex: "1 1 360px", cursor: disabled ? "default" : "pointer" }}>
138
+ <span style={{ display: "block", fontSize: 14, color: "var(--dsw-alias-label-primary)" }}>
139
+ {t(item.label)}
140
+ </span>
141
+ <span id={`cap-hint-${item.key}`} style={{ display: "block", ...hintStyle }}>
142
+ {dependencyReason ?? t(item.hint)}
143
+ </span>
144
+ </label>
145
+ {repairAction === undefined ? null : (
146
+ <button type="button" style={buttonStyle} onClick={repairAction.action}>
147
+ {repairAction.label}
148
+ </button>
149
+ )}
150
+ <ToggleSwitch
151
+ id={switchId}
152
+ checked={checked}
153
+ disabled={disabled}
154
+ ariaLabel={t(item.label)}
155
+ ariaDescribedBy={`cap-hint-${item.key}`}
156
+ onChange={(next) => {
157
+ void onPatchCapability(item.key, next);
158
+ }}
159
+ />
160
+ </div>
161
+ </li>
162
+ );
163
+ })}
164
+ </ul>
165
+ <h4 style={{ ...titleStyle, fontSize: 14 }}>{t("imagineTitle")}</h4>
166
+ <ul style={listStyle}>
167
+ {imagineToggles.map((item) => {
168
+ const checked = capabilities.value[item.key];
169
+ const dependencyReason = imagine?.configured === true ? undefined : t("requiresImagineCredential");
170
+ const disabled = capabilitiesBusy || !capabilities.writable || dependencyReason !== undefined;
171
+ const switchId = `cap-switch-${item.key}`;
172
+ return (
173
+ <li key={item.key}>
174
+ <div style={{ ...rowStyle, alignItems: "flex-start" }}>
175
+ <label htmlFor={switchId} style={{ flex: "1 1 360px", cursor: disabled ? "default" : "pointer" }}>
176
+ <span style={{ display: "block", fontSize: 14, color: "var(--dsw-alias-label-primary)" }}>
177
+ {t(item.label)}
178
+ </span>
179
+ <span id={`cap-hint-${item.key}`} style={{ display: "block", ...hintStyle }}>
180
+ {dependencyReason ?? t(item.hint)}
181
+ </span>
182
+ </label>
183
+ {dependencyReason === undefined ? null : (
184
+ <button type="button" style={buttonStyle} onClick={() => onFocusDependency("imagineCredential")}>
185
+ {t("focusImagineCredential")}
186
+ </button>
187
+ )}
188
+ <ToggleSwitch
189
+ id={switchId}
190
+ checked={checked}
191
+ disabled={disabled}
192
+ ariaLabel={t(item.label)}
193
+ ariaDescribedBy={`cap-hint-${item.key}`}
194
+ onChange={(next) => {
195
+ void onPatchCapability(item.key, next);
196
+ }}
197
+ />
198
+ </div>
199
+ </li>
200
+ );
201
+ })}
202
+ </ul>
203
+ <div style={nestedStyle}>
204
+ <h4 style={{ ...titleStyle, fontSize: 14 }}>{t("capabilityLimitsTitle")}</h4>
205
+ <p style={hintStyle}>{t("capabilityLimitsHint")}</p>
206
+ <ul style={listStyle}>
207
+ {CAPABILITY_LIMITS.map((item) => {
208
+ const displayValue = capabilities.value[item.key] / item.scale;
209
+ const inputId = `cap-limit-${item.key}`;
210
+ return (
211
+ <li key={item.key} style={rowStyle}>
212
+ <label htmlFor={inputId} style={{ ...bodyStyle, flex: "1 1 360px" }}>
213
+ <span style={{ display: "block", color: "var(--dsw-alias-label-primary)" }}>{t(item.label)}</span>
214
+ <span id={`${inputId}-hint`} style={{ display: "block", ...hintStyle }}>
215
+ {t(item.hint)}
216
+ </span>
217
+ </label>
218
+ <input
219
+ key={`${item.key}-${String(capabilities.revision)}-${String(displayValue)}`}
220
+ id={inputId}
221
+ type="number"
222
+ inputMode="numeric"
223
+ min={item.min}
224
+ max={item.max}
225
+ step={1}
226
+ defaultValue={displayValue}
227
+ disabled={capabilitiesBusy || !capabilities.writable}
228
+ aria-describedby={`${inputId}-hint`}
229
+ style={{ ...inputStyle, width: 112, flex: "0 0 112px" }}
230
+ onInput={(event) => {
231
+ event.currentTarget.setCustomValidity("");
232
+ }}
233
+ onKeyDown={(event) => {
234
+ if (event.key === "Enter") event.currentTarget.blur();
235
+ if (event.key === "Escape") {
236
+ event.currentTarget.value = String(displayValue);
237
+ event.currentTarget.setCustomValidity("");
238
+ }
239
+ }}
240
+ onBlur={(event) => {
241
+ const target = event.currentTarget;
242
+ const next = Number(target.value);
243
+ if (!Number.isInteger(next) || next < item.min || next > item.max) {
244
+ target.setCustomValidity(t("capabilityLimitInvalid", { min: item.min, max: item.max }));
245
+ target.reportValidity();
246
+ return;
247
+ }
248
+ target.setCustomValidity("");
249
+ const apiValue = next * item.scale;
250
+ if (apiValue === capabilities.value[item.key]) return;
251
+ void Promise.resolve(onPatchCapability(item.key, apiValue)).then((saved) => {
252
+ if (saved === false && target.isConnected) target.value = String(displayValue);
253
+ });
254
+ }}
255
+ />
256
+ </li>
257
+ );
258
+ })}
259
+ </ul>
260
+ </div>
261
+ </fieldset>
262
+ )}
263
+ </section>
264
+ );
265
+ }