dsh-coding-subscription-oauth 0.5.8 → 0.6.2

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 (148) hide show
  1. package/CHANGELOG.md +217 -188
  2. package/CONTRIBUTING.md +120 -120
  3. package/INSTALL.md +241 -209
  4. package/LICENSE +19 -19
  5. package/NOTICE +11 -11
  6. package/README.de.md +298 -294
  7. package/README.es.md +299 -295
  8. package/README.fr.md +299 -295
  9. package/README.ja.md +299 -295
  10. package/README.ko.md +299 -295
  11. package/README.md +313 -307
  12. package/README.pt-BR.md +299 -295
  13. package/README.ru.md +299 -295
  14. package/README.zh-CN.md +311 -305
  15. package/compatibility/dsh-bom.json +30 -0
  16. package/cordis.patch.yml +13 -13
  17. package/docs/00-project-rules.md +195 -195
  18. package/docs/02-architecture.md +134 -129
  19. package/docs/02-architecture.zh-CN.md +134 -129
  20. package/lib/adapter.d.ts.map +1 -1
  21. package/lib/alias-adapter.d.ts +3 -1
  22. package/lib/alias-adapter.d.ts.map +1 -1
  23. package/lib/auth-routes.d.ts +8 -15
  24. package/lib/auth-routes.d.ts.map +1 -1
  25. package/lib/bin.js +746 -1402
  26. package/lib/bin.js.map +4 -4
  27. package/lib/capability-routes.d.ts +3 -3
  28. package/lib/capability-routes.d.ts.map +1 -1
  29. package/lib/capability-settings.d.ts +5 -4
  30. package/lib/capability-settings.d.ts.map +1 -1
  31. package/lib/client.js +27 -8
  32. package/lib/client.js.map +4 -4
  33. package/lib/compatibility.d.ts +46 -0
  34. package/lib/compatibility.d.ts.map +1 -0
  35. package/lib/dsh-host-adapter.d.ts +18 -0
  36. package/lib/dsh-host-adapter.d.ts.map +1 -0
  37. package/lib/gateway-auth.d.ts +1 -2
  38. package/lib/gateway-auth.d.ts.map +1 -1
  39. package/lib/gateway-routes.d.ts +3 -4
  40. package/lib/gateway-routes.d.ts.map +1 -1
  41. package/lib/gateway.d.ts +4 -0
  42. package/lib/gateway.d.ts.map +1 -1
  43. package/lib/ids.d.ts +3 -32
  44. package/lib/ids.d.ts.map +1 -1
  45. package/lib/imagine-routes.d.ts +2 -0
  46. package/lib/imagine-routes.d.ts.map +1 -1
  47. package/lib/index.d.ts +19 -4
  48. package/lib/index.d.ts.map +1 -1
  49. package/lib/index.js +26627 -1047
  50. package/lib/index.js.map +4 -4
  51. package/lib/invariant.js.map +1 -1
  52. package/lib/oauth-import-routes.d.ts +3 -4
  53. package/lib/oauth-import-routes.d.ts.map +1 -1
  54. package/lib/proxy.d.ts +3 -16
  55. package/lib/proxy.d.ts.map +1 -1
  56. package/lib/web-origin.d.ts +28 -4
  57. package/lib/web-origin.d.ts.map +1 -1
  58. package/lib/web-routes.d.ts.map +1 -1
  59. package/media/en/settings_accounts.png +0 -0
  60. package/media/en/settings_capabilities.png +0 -0
  61. package/media/en/settings_gateway.png +0 -0
  62. package/media/settings_accounts.png +0 -0
  63. package/media/settings_capabilities.png +0 -0
  64. package/media/settings_gateway.png +0 -0
  65. package/media/settings_overview.png +0 -0
  66. package/media/zh-CN/settings_accounts.png +0 -0
  67. package/media/zh-CN/settings_capabilities.png +0 -0
  68. package/media/zh-CN/settings_gateway.png +0 -0
  69. package/package.json +211 -174
  70. package/patches/dsh-agy@0.1.2.patch +25 -25
  71. package/scripts/release.mjs +186 -170
  72. package/scripts/smoke-deployed-routes.mjs +146 -146
  73. package/scripts/verify-deployed-catalog.mjs +87 -87
  74. package/src/adapter.ts +329 -268
  75. package/src/alias-adapter.ts +141 -147
  76. package/src/auth-routes.ts +921 -871
  77. package/src/auth.ts +67 -67
  78. package/src/bin.ts +350 -350
  79. package/src/capability-routes.ts +279 -275
  80. package/src/capability-runtime.ts +313 -313
  81. package/src/capability-settings.ts +658 -657
  82. package/src/capability-tools.ts +666 -666
  83. package/src/catalog.ts +271 -271
  84. package/src/client/GrokBuildSettings.tsx +770 -718
  85. package/src/client/api.ts +88 -88
  86. package/src/client/components/AboutTab.tsx +30 -30
  87. package/src/client/components/AccountsTab.tsx +241 -224
  88. package/src/client/components/Badge.tsx +33 -33
  89. package/src/client/components/CapabilitiesTab.tsx +265 -227
  90. package/src/client/components/CliPullPreview.tsx +116 -107
  91. package/src/client/components/CopyButton.tsx +57 -57
  92. package/src/client/components/GatewayTab.tsx +469 -409
  93. package/src/client/components/NoticeBanner.tsx +46 -46
  94. package/src/client/components/ProgressBar.tsx +53 -53
  95. package/src/client/components/ProviderCard.tsx +606 -502
  96. package/src/client/components/SettingsTabs.tsx +75 -75
  97. package/src/client/components/ToggleSwitch.tsx +71 -62
  98. package/src/client/constants.ts +224 -206
  99. package/src/client/display.ts +61 -61
  100. package/src/client/dshClientAdapter.ts +127 -0
  101. package/src/client/gatewaySnippets.ts +37 -36
  102. package/src/client/index.tsx +156 -37
  103. package/src/client/locales.ts +535 -491
  104. package/src/client/microStyles.ts +52 -33
  105. package/src/client/parsers.ts +396 -386
  106. package/src/client/styles.ts +325 -307
  107. package/src/client/types.ts +197 -185
  108. package/src/codex-http.ts +447 -447
  109. package/src/codex-images.ts +485 -485
  110. package/src/codex-model-capabilities.ts +320 -320
  111. package/src/codex-search.ts +245 -245
  112. package/src/codex-usage.ts +263 -263
  113. package/src/compatibility.ts +55 -0
  114. package/src/dsh-host-adapter.ts +173 -0
  115. package/src/gateway-anthropic-messages.ts +84 -84
  116. package/src/gateway-auth.ts +102 -100
  117. package/src/gateway-backend.ts +274 -274
  118. package/src/gateway-body.ts +49 -49
  119. package/src/gateway-config.ts +76 -76
  120. package/src/gateway-http.ts +104 -104
  121. package/src/gateway-openai-chat.ts +124 -124
  122. package/src/gateway-openai-responses.ts +53 -53
  123. package/src/gateway-parse.ts +224 -224
  124. package/src/gateway-protocol.ts +52 -52
  125. package/src/gateway-routes.ts +158 -152
  126. package/src/gateway.ts +258 -242
  127. package/src/grok-errors.ts +24 -24
  128. package/src/grok-imagine.ts +1627 -1627
  129. package/src/grok-import.ts +151 -151
  130. package/src/http-json.ts +82 -82
  131. package/src/ids.ts +59 -45
  132. package/src/imagine-routes.ts +463 -461
  133. package/src/index.ts +729 -592
  134. package/src/invariant.ts +17 -17
  135. package/src/kimi-errors.ts +26 -26
  136. package/src/media-store.ts +927 -927
  137. package/src/oauth-import-routes.ts +324 -314
  138. package/src/oauth-providers.ts +152 -152
  139. package/src/oauth-session.ts +183 -183
  140. package/src/oauth-sources.ts +1104 -1104
  141. package/src/oauth.ts +620 -620
  142. package/src/provider.ts +128 -128
  143. package/src/proxy.ts +11 -99
  144. package/src/redact.ts +72 -72
  145. package/src/session.ts +218 -218
  146. package/src/store.ts +217 -217
  147. package/src/web-origin.ts +296 -60
  148. package/src/web-routes.ts +38 -75
@@ -1,227 +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
- cardStyle,
8
- dotStyle,
9
- errorStyle,
10
- hintStyle,
11
- inputStyle,
12
- listStyle,
13
- nestedStyle,
14
- rowStyle,
15
- skeletonStyle,
16
- statusStyle,
17
- titleStyle,
18
- } from "../styles.ts";
19
- import type {
20
- CapabilitySettingKey,
21
- CapabilitySnapshot,
22
- GrokBuildSettingsInjected,
23
- ImagineCredentialView,
24
- } from "../types.ts";
25
- import { Badge } from "./Badge.tsx";
26
- import { ToggleSwitch } from "./ToggleSwitch.tsx";
27
-
28
- export interface CapabilitiesTabProps {
29
- t: GrokBuildSettingsInjected["t"];
30
- capabilities: CapabilitySnapshot | undefined;
31
- capabilitiesError: string | undefined;
32
- capabilitiesBusy: boolean;
33
- imagine: ImagineCredentialView | undefined;
34
- imagineError: string | undefined;
35
- onPatchCapability: (key: CapabilitySettingKey, value: boolean | number) => Promise<boolean | undefined> | undefined;
36
- }
37
-
38
- export function CapabilitiesTab({
39
- t,
40
- capabilities,
41
- capabilitiesError,
42
- capabilitiesBusy,
43
- imagine,
44
- imagineError,
45
- onPatchCapability,
46
- }: CapabilitiesTabProps) {
47
- const codexToggles = CAPABILITY_TOGGLES.filter((item) => !item.key.startsWith("grokImagine"));
48
- const imagineToggles = CAPABILITY_TOGGLES.filter((item) => item.key.startsWith("grokImagine"));
49
-
50
- return (
51
- <section style={cardStyle} aria-labelledby="coding-oauth-capabilities-title">
52
- <div>
53
- <h3 id="coding-oauth-capabilities-title" style={{ ...titleStyle, fontSize: 16 }}>
54
- {t("capabilitiesTitle")}
55
- </h3>
56
- <p style={{ ...bodyStyle, marginTop: 4 }}>{t("capabilitiesIntro")}</p>
57
- </div>
58
- {imagineError === undefined ? null : (
59
- <p style={errorStyle} role="alert">
60
- {imagineError}
61
- </p>
62
- )}
63
- {imagine === undefined && imagineError === undefined ? (
64
- <div style={skeletonStyle} role="status" aria-busy="true">
65
- <div style={statusStyle}>
66
- <span aria-hidden="true" style={dotStyle("loading")} />
67
- {t("imagineLoading")}
68
- </div>
69
- </div>
70
- ) : imagine === undefined ? null : (
71
- <div style={nestedStyle}>
72
- <Badge
73
- label={imagine.configured ? t("imagineConfigured") : t("imagineNotConfigured")}
74
- tone={imagine.configured ? "success" : "neutral"}
75
- />
76
- <p style={hintStyle}>{t("imagineSource", { source: imagineSourceLabel(imagine.source, t) })}</p>
77
- </div>
78
- )}
79
- {capabilitiesError === undefined ? null : (
80
- <p style={errorStyle} role="alert">
81
- {capabilitiesError}
82
- </p>
83
- )}
84
- {capabilities === undefined ? (
85
- <div style={skeletonStyle} role="status" aria-busy="true">
86
- <div style={statusStyle}>
87
- <span aria-hidden="true" style={dotStyle("loading")} />
88
- {t("capabilitiesLoading")}
89
- </div>
90
- </div>
91
- ) : (
92
- <fieldset style={{ border: 0, margin: 0, padding: 0, minWidth: 0 }}>
93
- <legend style={{ ...bodyStyle, position: "absolute", width: 1, height: 1, overflow: "hidden" }}>
94
- {t("capabilitiesTitle")}
95
- </legend>
96
- {capabilities.writable ? null : <p style={hintStyle}>{t("capabilitiesReadOnly")}</p>}
97
- <ul style={listStyle}>
98
- {codexToggles.map((item) => {
99
- const checked = capabilities.value[item.key];
100
- const imagesOff = item.requiresImages === true && !capabilities.value.codexImages;
101
- const disabled = capabilitiesBusy || !capabilities.writable || imagesOff;
102
- const switchId = `cap-switch-${item.key}`;
103
- return (
104
- <li
105
- key={item.key}
106
- style={{
107
- opacity: imagesOff ? 0.5 : 1,
108
- transition: "opacity 0.15s ease",
109
- }}
110
- >
111
- <div style={{ ...rowStyle, alignItems: "flex-start" }}>
112
- <label htmlFor={switchId} style={{ flex: "1 1 360px", cursor: disabled ? "default" : "pointer" }}>
113
- <span style={{ display: "block", fontSize: 14, color: "var(--dsw-alias-label-primary)" }}>
114
- {t(item.label)}
115
- </span>
116
- <span id={`cap-hint-${item.key}`} style={{ display: "block", ...hintStyle }}>
117
- {imagesOff ? t("requiresCodexImages") : t(item.hint)}
118
- </span>
119
- </label>
120
- <ToggleSwitch
121
- id={switchId}
122
- checked={checked}
123
- disabled={disabled}
124
- ariaLabel={t(item.label)}
125
- onChange={(next) => {
126
- void onPatchCapability(item.key, next);
127
- }}
128
- />
129
- </div>
130
- </li>
131
- );
132
- })}
133
- </ul>
134
- <h4 style={{ ...titleStyle, fontSize: 14 }}>{t("imagineTitle")}</h4>
135
- <ul style={listStyle}>
136
- {imagineToggles.map((item) => {
137
- const checked = capabilities.value[item.key];
138
- const disabled = capabilitiesBusy || !capabilities.writable;
139
- const switchId = `cap-switch-${item.key}`;
140
- return (
141
- <li key={item.key}>
142
- <div style={{ ...rowStyle, alignItems: "flex-start" }}>
143
- <label htmlFor={switchId} style={{ flex: "1 1 360px", cursor: disabled ? "default" : "pointer" }}>
144
- <span style={{ display: "block", fontSize: 14, color: "var(--dsw-alias-label-primary)" }}>
145
- {t(item.label)}
146
- </span>
147
- <span id={`cap-hint-${item.key}`} style={{ display: "block", ...hintStyle }}>
148
- {t(item.hint)}
149
- </span>
150
- </label>
151
- <ToggleSwitch
152
- id={switchId}
153
- checked={checked}
154
- disabled={disabled}
155
- ariaLabel={t(item.label)}
156
- onChange={(next) => {
157
- void onPatchCapability(item.key, next);
158
- }}
159
- />
160
- </div>
161
- </li>
162
- );
163
- })}
164
- </ul>
165
- <div style={nestedStyle}>
166
- <h4 style={{ ...titleStyle, fontSize: 14 }}>{t("capabilityLimitsTitle")}</h4>
167
- <p style={hintStyle}>{t("capabilityLimitsHint")}</p>
168
- <ul style={listStyle}>
169
- {CAPABILITY_LIMITS.map((item) => {
170
- const displayValue = capabilities.value[item.key] / item.scale;
171
- const inputId = `cap-limit-${item.key}`;
172
- return (
173
- <li key={item.key} style={rowStyle}>
174
- <label htmlFor={inputId} style={{ ...bodyStyle, flex: "1 1 360px" }}>
175
- <span style={{ display: "block", color: "var(--dsw-alias-label-primary)" }}>{t(item.label)}</span>
176
- <span id={`${inputId}-hint`} style={{ display: "block", ...hintStyle }}>
177
- {t(item.hint)}
178
- </span>
179
- </label>
180
- <input
181
- key={`${item.key}-${String(capabilities.revision)}-${String(displayValue)}`}
182
- id={inputId}
183
- type="number"
184
- inputMode="numeric"
185
- min={item.min}
186
- max={item.max}
187
- step={1}
188
- defaultValue={displayValue}
189
- disabled={capabilitiesBusy || !capabilities.writable}
190
- aria-describedby={`${inputId}-hint`}
191
- style={{ ...inputStyle, width: 112, flex: "0 0 112px" }}
192
- onInput={(event) => {
193
- event.currentTarget.setCustomValidity("");
194
- }}
195
- onKeyDown={(event) => {
196
- if (event.key === "Enter") event.currentTarget.blur();
197
- if (event.key === "Escape") {
198
- event.currentTarget.value = String(displayValue);
199
- event.currentTarget.setCustomValidity("");
200
- }
201
- }}
202
- onBlur={(event) => {
203
- const target = event.currentTarget;
204
- const next = Number(target.value);
205
- if (!Number.isInteger(next) || next < item.min || next > item.max) {
206
- target.setCustomValidity(t("capabilityLimitInvalid", { min: item.min, max: item.max }));
207
- target.reportValidity();
208
- return;
209
- }
210
- target.setCustomValidity("");
211
- const apiValue = next * item.scale;
212
- if (apiValue === capabilities.value[item.key]) return;
213
- void Promise.resolve(onPatchCapability(item.key, apiValue)).then((saved) => {
214
- if (saved === false && target.isConnected) target.value = String(displayValue);
215
- });
216
- }}
217
- />
218
- </li>
219
- );
220
- })}
221
- </ul>
222
- </div>
223
- </fieldset>
224
- )}
225
- </section>
226
- );
227
- }
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
+ }