dsh-coding-subscription-oauth 0.6.2 → 0.6.3
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.
- package/CHANGELOG.md +222 -206
- package/CONTRIBUTING.md +129 -120
- package/INSTALL.md +218 -218
- package/LICENSE +19 -19
- package/NOTICE +11 -11
- package/README.de.md +289 -289
- package/README.es.md +290 -290
- package/README.fr.md +290 -290
- package/README.ja.md +290 -290
- package/README.ko.md +290 -290
- package/README.md +304 -304
- package/README.pt-BR.md +290 -290
- package/README.ru.md +290 -290
- package/README.zh-CN.md +302 -302
- package/compatibility/dsh-bom.json +0 -0
- package/cordis.patch.yml +13 -13
- package/docs/00-project-rules.md +212 -195
- package/docs/02-architecture.md +130 -130
- package/docs/02-architecture.zh-CN.md +130 -130
- package/lib/bin.js.map +1 -1
- package/lib/capability-settings.d.ts +8 -2
- package/lib/capability-settings.d.ts.map +1 -1
- package/lib/capability-tools.d.ts +7 -2
- package/lib/capability-tools.d.ts.map +1 -1
- package/lib/client.js +3 -3
- package/lib/client.js.map +2 -2
- package/lib/codex-images.d.ts +8 -0
- package/lib/codex-images.d.ts.map +1 -1
- package/lib/index.js +32 -7
- package/lib/index.js.map +2 -2
- package/lib/invariant.js.map +1 -1
- package/media/en/settings_accounts.png +0 -0
- package/media/en/settings_capabilities.png +0 -0
- package/media/en/settings_gateway.png +0 -0
- package/media/settings_accounts.png +0 -0
- package/media/settings_capabilities.png +0 -0
- package/media/settings_gateway.png +0 -0
- package/media/settings_overview.png +0 -0
- package/media/zh-CN/settings_accounts.png +0 -0
- package/media/zh-CN/settings_capabilities.png +0 -0
- package/media/zh-CN/settings_gateway.png +0 -0
- package/package.json +148 -148
- package/patches/dsh-agy@0.1.2.patch +25 -25
- package/scripts/release.mjs +186 -186
- package/scripts/smoke-deployed-routes.mjs +146 -146
- package/scripts/verify-deployed-catalog.mjs +87 -87
- package/src/adapter.ts +273 -273
- package/src/alias-adapter.ts +130 -130
- package/src/auth-routes.ts +921 -921
- package/src/auth.ts +67 -67
- package/src/bin.ts +350 -350
- package/src/capability-routes.ts +279 -279
- package/src/capability-runtime.ts +314 -313
- package/src/capability-settings.ts +671 -658
- package/src/capability-tools.ts +685 -666
- package/src/catalog.ts +271 -271
- package/src/client/GrokBuildSettings.tsx +771 -770
- package/src/client/api.ts +88 -88
- package/src/client/components/AboutTab.tsx +30 -30
- package/src/client/components/AccountsTab.tsx +241 -241
- package/src/client/components/Badge.tsx +33 -33
- package/src/client/components/CapabilitiesTab.tsx +265 -265
- package/src/client/components/CliPullPreview.tsx +116 -116
- package/src/client/components/CopyButton.tsx +57 -57
- package/src/client/components/GatewayTab.tsx +469 -469
- package/src/client/components/NoticeBanner.tsx +46 -46
- package/src/client/components/ProgressBar.tsx +53 -53
- package/src/client/components/ProviderCard.tsx +606 -606
- package/src/client/components/SettingsTabs.tsx +75 -75
- package/src/client/components/ToggleSwitch.tsx +71 -71
- package/src/client/constants.ts +230 -224
- package/src/client/display.ts +61 -61
- package/src/client/dshClientAdapter.ts +127 -127
- package/src/client/gatewaySnippets.ts +37 -37
- package/src/client/index.tsx +156 -156
- package/src/client/locales.ts +540 -535
- package/src/client/microStyles.ts +52 -52
- package/src/client/parsers.ts +398 -396
- package/src/client/styles.ts +325 -325
- package/src/client/types.ts +199 -197
- package/src/codex-http.ts +447 -447
- package/src/codex-images.ts +503 -485
- package/src/codex-model-capabilities.ts +320 -320
- package/src/codex-search.ts +245 -245
- package/src/codex-usage.ts +263 -263
- package/src/compatibility.ts +41 -41
- package/src/dsh-host-adapter.ts +173 -173
- package/src/gateway-anthropic-messages.ts +84 -84
- package/src/gateway-auth.ts +102 -102
- package/src/gateway-backend.ts +274 -274
- package/src/gateway-body.ts +49 -49
- package/src/gateway-config.ts +76 -76
- package/src/gateway-http.ts +104 -104
- package/src/gateway-openai-chat.ts +124 -124
- package/src/gateway-openai-responses.ts +53 -53
- package/src/gateway-parse.ts +224 -224
- package/src/gateway-protocol.ts +52 -52
- package/src/gateway-routes.ts +158 -158
- package/src/gateway.ts +258 -258
- package/src/grok-errors.ts +24 -24
- package/src/grok-imagine.ts +1627 -1627
- package/src/grok-import.ts +151 -151
- package/src/http-json.ts +82 -82
- package/src/ids.ts +59 -59
- package/src/imagine-routes.ts +463 -463
- package/src/index.ts +709 -709
- package/src/invariant.ts +17 -17
- package/src/kimi-errors.ts +26 -26
- package/src/media-store.ts +927 -927
- package/src/oauth-import-routes.ts +324 -324
- package/src/oauth-providers.ts +152 -152
- package/src/oauth-session.ts +183 -183
- package/src/oauth-sources.ts +1104 -1104
- package/src/oauth.ts +620 -620
- package/src/provider.ts +128 -128
- package/src/proxy.ts +11 -11
- package/src/redact.ts +72 -72
- package/src/session.ts +218 -218
- package/src/store.ts +217 -217
- package/src/web-origin.ts +296 -296
- 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
|
+
}
|