dsh-coding-subscription-oauth 0.6.4 → 0.6.5

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 (144) hide show
  1. package/CHANGELOG.md +280 -255
  2. package/CONTRIBUTING.md +138 -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 +141 -137
  19. package/docs/02-architecture.zh-CN.md +141 -137
  20. package/lib/bin.js.map +1 -1
  21. package/lib/client.js +1 -1
  22. package/lib/client.js.map +1 -1
  23. package/lib/gateway-protocol.d.ts +3 -46
  24. package/lib/gateway-protocol.d.ts.map +1 -1
  25. package/lib/gateway-routes.d.ts.map +1 -1
  26. package/lib/grok-errors.d.ts +2 -12
  27. package/lib/grok-errors.d.ts.map +1 -1
  28. package/lib/grok-imagine/client.d.ts +73 -0
  29. package/lib/grok-imagine/client.d.ts.map +1 -0
  30. package/lib/grok-imagine/index.d.ts +8 -0
  31. package/lib/grok-imagine/index.d.ts.map +1 -0
  32. package/lib/grok-imagine/net.d.ts +10 -0
  33. package/lib/grok-imagine/net.d.ts.map +1 -0
  34. package/lib/grok-imagine/parse.d.ts +20 -0
  35. package/lib/grok-imagine/parse.d.ts.map +1 -0
  36. package/lib/grok-imagine/types.d.ts +191 -0
  37. package/lib/grok-imagine/types.d.ts.map +1 -0
  38. package/lib/grok-imagine.d.ts +3 -263
  39. package/lib/grok-imagine.d.ts.map +1 -1
  40. package/lib/http-json.d.ts +2 -9
  41. package/lib/http-json.d.ts.map +1 -1
  42. package/lib/index.js +57 -37
  43. package/lib/index.js.map +4 -4
  44. package/lib/invariant.js.map +1 -1
  45. package/lib/kimi-errors.d.ts +2 -12
  46. package/lib/kimi-errors.d.ts.map +1 -1
  47. package/lib/runtime/gateway-protocol.d.ts +47 -0
  48. package/lib/runtime/gateway-protocol.d.ts.map +1 -0
  49. package/lib/runtime/grok-errors.d.ts +13 -0
  50. package/lib/runtime/grok-errors.d.ts.map +1 -0
  51. package/lib/runtime/http-json.d.ts +10 -0
  52. package/lib/runtime/http-json.d.ts.map +1 -0
  53. package/lib/runtime/kimi-errors.d.ts +13 -0
  54. package/lib/runtime/kimi-errors.d.ts.map +1 -0
  55. package/media/en/settings_accounts.png +0 -0
  56. package/media/en/settings_capabilities.png +0 -0
  57. package/media/en/settings_gateway.png +0 -0
  58. package/media/settings_accounts.png +0 -0
  59. package/media/settings_capabilities.png +0 -0
  60. package/media/settings_gateway.png +0 -0
  61. package/media/settings_overview.png +0 -0
  62. package/media/zh-CN/settings_accounts.png +0 -0
  63. package/media/zh-CN/settings_capabilities.png +0 -0
  64. package/media/zh-CN/settings_gateway.png +0 -0
  65. package/package.json +225 -220
  66. package/patches/dsh-agy@0.1.2.patch +25 -25
  67. package/scripts/release.mjs +187 -186
  68. package/scripts/smoke-deployed-routes.mjs +146 -146
  69. package/scripts/verify-deployed-catalog.mjs +87 -87
  70. package/src/adapter.ts +0 -348
  71. package/src/alias-adapter.ts +0 -147
  72. package/src/auth-routes.ts +0 -921
  73. package/src/auth.ts +0 -67
  74. package/src/bin.ts +0 -350
  75. package/src/capability-routes.ts +0 -279
  76. package/src/capability-runtime.ts +0 -314
  77. package/src/capability-settings.ts +0 -671
  78. package/src/capability-tools.ts +0 -685
  79. package/src/catalog.ts +0 -271
  80. package/src/client/GrokBuildSettings.tsx +0 -771
  81. package/src/client/api.ts +0 -88
  82. package/src/client/components/AboutTab.tsx +0 -30
  83. package/src/client/components/AccountsTab.tsx +0 -241
  84. package/src/client/components/Badge.tsx +0 -33
  85. package/src/client/components/CapabilitiesTab.tsx +0 -265
  86. package/src/client/components/CliPullPreview.tsx +0 -116
  87. package/src/client/components/CopyButton.tsx +0 -57
  88. package/src/client/components/GatewayTab.tsx +0 -469
  89. package/src/client/components/NoticeBanner.tsx +0 -46
  90. package/src/client/components/ProgressBar.tsx +0 -53
  91. package/src/client/components/ProviderCard.tsx +0 -606
  92. package/src/client/components/SettingsTabs.tsx +0 -75
  93. package/src/client/components/ToggleSwitch.tsx +0 -71
  94. package/src/client/constants.ts +0 -230
  95. package/src/client/display.ts +0 -61
  96. package/src/client/dshClientAdapter.ts +0 -127
  97. package/src/client/gatewaySnippets.ts +0 -37
  98. package/src/client/index.tsx +0 -156
  99. package/src/client/locales.ts +0 -540
  100. package/src/client/microStyles.ts +0 -52
  101. package/src/client/parsers.ts +0 -398
  102. package/src/client/styles.ts +0 -325
  103. package/src/client/types.ts +0 -199
  104. package/src/codex-http.ts +0 -447
  105. package/src/codex-images.ts +0 -503
  106. package/src/codex-model-capabilities.ts +0 -320
  107. package/src/codex-search.ts +0 -245
  108. package/src/codex-usage.ts +0 -263
  109. package/src/compatibility.ts +0 -55
  110. package/src/dsh-host-adapter.ts +0 -173
  111. package/src/gateway-anthropic-messages.ts +0 -84
  112. package/src/gateway-auth.ts +0 -102
  113. package/src/gateway-backend.ts +0 -274
  114. package/src/gateway-body.ts +0 -49
  115. package/src/gateway-config.ts +0 -76
  116. package/src/gateway-http.ts +0 -104
  117. package/src/gateway-openai-chat.ts +0 -124
  118. package/src/gateway-openai-responses.ts +0 -53
  119. package/src/gateway-parse.ts +0 -224
  120. package/src/gateway-protocol.ts +0 -52
  121. package/src/gateway-routes.ts +0 -158
  122. package/src/gateway.ts +0 -258
  123. package/src/grok-errors.ts +0 -24
  124. package/src/grok-imagine.ts +0 -1627
  125. package/src/grok-import.ts +0 -151
  126. package/src/http-json.ts +0 -82
  127. package/src/ids.ts +0 -59
  128. package/src/imagine-routes.ts +0 -463
  129. package/src/index.ts +0 -735
  130. package/src/invariant.ts +0 -17
  131. package/src/kimi-errors.ts +0 -26
  132. package/src/media-store.ts +0 -927
  133. package/src/oauth-import-routes.ts +0 -324
  134. package/src/oauth-providers.ts +0 -152
  135. package/src/oauth-session.ts +0 -183
  136. package/src/oauth-sources.ts +0 -1104
  137. package/src/oauth.ts +0 -620
  138. package/src/provider.ts +0 -128
  139. package/src/proxy.ts +0 -11
  140. package/src/redact.ts +0 -72
  141. package/src/session.ts +0 -218
  142. package/src/store.ts +0 -217
  143. package/src/web-origin.ts +0 -296
  144. package/src/web-routes.ts +0 -38
package/src/client/api.ts DELETED
@@ -1,88 +0,0 @@
1
- /** Same-origin JSON helpers for the Coding OAuth plugin HTTP API. */
2
-
3
- import { CONSUMED_PREVIEW_CODES, SOURCES_CANCEL_PATH } from "./constants.ts";
4
- import type { PluginRequestError } from "./types.ts";
5
-
6
- export function isRecord(value: unknown): value is Record<string, unknown> {
7
- return typeof value === "object" && value !== null && !Array.isArray(value);
8
- }
9
-
10
- export function isPluginRequestError(error: unknown): error is PluginRequestError {
11
- return error instanceof Error && error.name === "PluginRequestError" && "status" in error;
12
- }
13
-
14
- export function isConflictError(error: unknown): boolean {
15
- if (!isPluginRequestError(error)) {
16
- return (
17
- error instanceof Error && /SETTINGS_CONFLICT|settings-conflict|changed since it was read/iu.test(error.message)
18
- );
19
- }
20
- return error.status === 409 || error.code === "SETTINGS_CONFLICT" || /conflict/iu.test(error.message);
21
- }
22
-
23
- export function isConsumedPreviewError(error: unknown): boolean {
24
- if (!isPluginRequestError(error)) return false;
25
- if (error.code !== undefined && CONSUMED_PREVIEW_CODES.has(error.code)) return true;
26
- return error.status === 404 || error.status === 410;
27
- }
28
-
29
- export function cancelPreviewTicket(previewId: string, keepalive = false): void {
30
- void fetch(SOURCES_CANCEL_PATH, {
31
- method: "POST",
32
- headers: { accept: "application/json", "content-type": "application/json" },
33
- credentials: "same-origin",
34
- body: JSON.stringify({ previewId }),
35
- ...(keepalive ? { keepalive: true } : {}),
36
- }).catch(() => undefined);
37
- }
38
-
39
- export async function jsonRequest<T>(path: string, method = "GET", body?: unknown): Promise<T> {
40
- const response = await fetch(path, {
41
- method,
42
- headers: { accept: "application/json", ...(body === undefined ? {} : { "content-type": "application/json" }) },
43
- credentials: "same-origin",
44
- ...(body === undefined ? {} : { body: JSON.stringify(body) }),
45
- });
46
- const value: unknown = await response.json().catch(() => undefined);
47
- if (!response.ok) {
48
- const record = isRecord(value) ? value : undefined;
49
- const message =
50
- record !== undefined && typeof record["error"] === "string"
51
- ? record["error"]
52
- : record !== undefined && typeof record["message"] === "string"
53
- ? record["message"]
54
- : `HTTP ${response.status}`;
55
- const code = record !== undefined && typeof record["code"] === "string" ? record["code"] : undefined;
56
- const error = new Error(message) as PluginRequestError;
57
- error.name = "PluginRequestError";
58
- error.status = response.status;
59
- if (code !== undefined) error.code = code;
60
- throw error;
61
- }
62
- return value as T;
63
- }
64
-
65
- export async function copyText(text: string): Promise<boolean> {
66
- try {
67
- if (typeof navigator !== "undefined" && navigator.clipboard?.writeText !== undefined) {
68
- await navigator.clipboard.writeText(text);
69
- return true;
70
- }
71
- } catch {
72
- // fall through to execCommand
73
- }
74
- try {
75
- const area = document.createElement("textarea");
76
- area.value = text;
77
- area.setAttribute("readonly", "");
78
- area.style.position = "fixed";
79
- area.style.left = "-9999px";
80
- document.body.appendChild(area);
81
- area.select();
82
- const ok = document.execCommand("copy");
83
- document.body.removeChild(area);
84
- return ok;
85
- } catch {
86
- return false;
87
- }
88
- }
@@ -1,30 +0,0 @@
1
- /** About tab: terms, remote help, and plugin version. */
2
-
3
- import { PLUGIN_VERSION } from "../constants.ts";
4
- import { bodyStyle, cardStyle, hintStyle, linkStyle, titleStyle, warningStyle } from "../styles.ts";
5
- import type { GrokBuildSettingsInjected } from "../types.ts";
6
-
7
- const README_URL = "https://github.com/lninghaha/dsh-coding-subscription-oauth#readme";
8
-
9
- export interface AboutTabProps {
10
- t: GrokBuildSettingsInjected["t"];
11
- }
12
-
13
- export function AboutTab({ t }: AboutTabProps) {
14
- return (
15
- <section style={cardStyle} aria-labelledby="coding-oauth-about-title">
16
- <h3 id="coding-oauth-about-title" style={{ ...titleStyle, fontSize: 16 }}>
17
- {t("aboutTitle")}
18
- </h3>
19
- <p style={{ ...warningStyle, marginTop: 12 }}>{t("termsWarning")}</p>
20
- <p style={{ ...bodyStyle, marginTop: 12 }}>{t("remoteLoginHelp")}</p>
21
- <p style={{ ...hintStyle, marginTop: 12 }}>{t("pluginVersion", { version: PLUGIN_VERSION })}</p>
22
- <p style={{ ...hintStyle, marginTop: 8 }}>{t("aboutDocsHint")}</p>
23
- <p style={{ marginTop: 8 }}>
24
- <a href={README_URL} target="_blank" rel="noreferrer" style={linkStyle}>
25
- {t("aboutDocsLink")}
26
- </a>
27
- </p>
28
- </section>
29
- );
30
- }
@@ -1,241 +0,0 @@
1
- /** Accounts tab: provider cards, CLI tips, and pull preview. */
2
-
3
- import { Fragment, useEffect, useRef } from "react";
4
- import { PROVIDERS } from "../constants.ts";
5
- import { allOfficialCliMissing, anyOfficialCliAvailable } from "../display.ts";
6
- import {
7
- accountGridStyle,
8
- bodyStyle,
9
- cardStyle,
10
- dotStyle,
11
- hintStyle,
12
- monoStyle,
13
- rowStyle,
14
- skeletonStyle,
15
- statusStyle,
16
- titleStyle,
17
- } from "../styles.ts";
18
- import type {
19
- CodingOAuthStatus,
20
- GrokBuildSettingsInjected,
21
- LoginMethod,
22
- ProviderSlug,
23
- SourcePreview,
24
- SourceStatus,
25
- UsageView,
26
- } from "../types.ts";
27
- import { Badge } from "./Badge.tsx";
28
- import { CliPullPreview } from "./CliPullPreview.tsx";
29
- import { NoticeBanner } from "./NoticeBanner.tsx";
30
- import { ProviderCard } from "./ProviderCard.tsx";
31
-
32
- export interface AccountsTabProps {
33
- t: GrokBuildSettingsInjected["t"];
34
- status: CodingOAuthStatus | undefined;
35
- remote: boolean;
36
- remoteTipDismissed: boolean;
37
- onDismissRemoteTip: () => void;
38
- sources: readonly SourceStatus[] | undefined;
39
- sourcesError: string | undefined;
40
- sourcesNotice: string | undefined;
41
- sourcesBusy: boolean;
42
- preview: SourcePreview | undefined;
43
- confirmOverwrite: boolean;
44
- busyProvider: ProviderSlug | undefined;
45
- codeInputs: Partial<Record<ProviderSlug, string>>;
46
- popupBlocked: Partial<Record<ProviderSlug, boolean>>;
47
- expandedProviders: Partial<Record<ProviderSlug, boolean>>;
48
- showUsage: boolean;
49
- usage: UsageView | undefined;
50
- usageError: string | undefined;
51
- usageLoading: boolean;
52
- onSignIn: (slug: ProviderSlug, method: LoginMethod) => void;
53
- onSignOut: (slug: ProviderSlug) => void;
54
- onCancelLogin: (slug: ProviderSlug) => void;
55
- onSubmitCode: (slug: ProviderSlug) => void;
56
- onCodeChange: (slug: ProviderSlug, value: string) => void;
57
- onToggleExpanded: (slug: ProviderSlug) => void;
58
- onPreviewSource: (slug: ProviderSlug) => void;
59
- onSaveModels: (slug: ProviderSlug, selected: string[]) => void;
60
- onConfirmOverwriteChange: (checked: boolean) => void;
61
- onCommitSource: () => void;
62
- onCancelSourcePreview: () => void;
63
- onRefreshSources: () => void;
64
- onDismissSourcesNotice: () => void;
65
- }
66
-
67
- export function AccountsTab({
68
- t,
69
- status,
70
- remote,
71
- remoteTipDismissed,
72
- onDismissRemoteTip,
73
- sources,
74
- sourcesError,
75
- sourcesNotice,
76
- sourcesBusy,
77
- preview,
78
- confirmOverwrite,
79
- busyProvider,
80
- codeInputs,
81
- popupBlocked,
82
- expandedProviders,
83
- showUsage,
84
- usage,
85
- usageError,
86
- usageLoading,
87
- onSignIn,
88
- onSignOut,
89
- onCancelLogin,
90
- onSubmitCode,
91
- onCodeChange,
92
- onToggleExpanded,
93
- onPreviewSource,
94
- onSaveModels,
95
- onConfirmOverwriteChange,
96
- onCommitSource,
97
- onCancelSourcePreview,
98
- onRefreshSources,
99
- onDismissSourcesNotice,
100
- }: AccountsTabProps) {
101
- const previousPreviewKind = useRef<ProviderSlug | undefined>(undefined);
102
- useEffect(() => {
103
- if (preview !== undefined) {
104
- previousPreviewKind.current = preview.kind;
105
- document.getElementById(`coding-oauth-source-preview-${preview.kind}`)?.focus();
106
- return;
107
- }
108
- const trigger = previousPreviewKind.current;
109
- if (trigger === undefined || sourcesBusy) return;
110
- previousPreviewKind.current = undefined;
111
- document.getElementById(`coding-oauth-source-pull-${trigger}`)?.focus();
112
- }, [preview, sourcesBusy]);
113
-
114
- if (status === undefined) {
115
- return (
116
- <div style={skeletonStyle} role="status" aria-busy="true">
117
- <div style={statusStyle}>
118
- <span aria-hidden="true" style={dotStyle("loading")} />
119
- {t("loadingAccount")}
120
- </div>
121
- </div>
122
- );
123
- }
124
-
125
- return (
126
- <>
127
- {remote && !remoteTipDismissed ? (
128
- <NoticeBanner
129
- message={t("remoteAccountsTip")}
130
- dismissLabel={t("remoteTipDismiss")}
131
- onDismiss={onDismissRemoteTip}
132
- />
133
- ) : null}
134
- {allOfficialCliMissing(sources) ? (
135
- <NoticeBanner
136
- message={t("sourcesAllMissingHint")}
137
- dismissLabel={t("sourcesCheckAgain")}
138
- onDismiss={() => {
139
- onRefreshSources();
140
- }}
141
- />
142
- ) : null}
143
- {anyOfficialCliAvailable(sources) ? <p style={hintStyle}>{t("sourcesAvailableHint")}</p> : null}
144
- {sourcesError === undefined ? null : (
145
- <p style={{ ...bodyStyle, color: "var(--dsw-alias-state-error-primary)" }} role="alert">
146
- {sourcesError}
147
- </p>
148
- )}
149
- {sourcesNotice === undefined ? null : (
150
- <NoticeBanner
151
- key={sourcesNotice}
152
- message={sourcesNotice}
153
- tone="success"
154
- autoHideMs={5000}
155
- onDismiss={onDismissSourcesNotice}
156
- />
157
- )}
158
- <div style={accountGridStyle}>
159
- {PROVIDERS.map((definition) => {
160
- const providerStatus = status.providers[definition.slug];
161
- const expanded = providerStatus.status === "signing-in" || expandedProviders[definition.slug] === true;
162
- return (
163
- <Fragment key={definition.slug}>
164
- <ProviderCard
165
- t={t}
166
- definition={definition}
167
- providerStatus={providerStatus}
168
- busy={busyProvider === definition.slug}
169
- sourcesBusy={sourcesBusy}
170
- remote={remote}
171
- codeInput={codeInputs[definition.slug] ?? ""}
172
- popupBlocked={popupBlocked[definition.slug] === true}
173
- expanded={expanded}
174
- source={sources?.find((entry) => entry.kind === definition.slug)}
175
- showUsage={showUsage}
176
- usage={usage}
177
- usageError={usageError}
178
- usageLoading={usageLoading}
179
- onSignIn={(method) => {
180
- onSignIn(definition.slug, method);
181
- }}
182
- onSignOut={() => {
183
- onSignOut(definition.slug);
184
- }}
185
- onCancelLogin={() => {
186
- onCancelLogin(definition.slug);
187
- }}
188
- onSubmitCode={() => {
189
- onSubmitCode(definition.slug);
190
- }}
191
- onCodeChange={(value) => {
192
- onCodeChange(definition.slug, value);
193
- }}
194
- onToggleExpanded={() => {
195
- onToggleExpanded(definition.slug);
196
- }}
197
- onPreviewSource={() => {
198
- onPreviewSource(definition.slug);
199
- }}
200
- onSaveModels={(selected) => {
201
- onSaveModels(definition.slug, selected);
202
- }}
203
- />
204
- {preview?.kind === definition.slug ? (
205
- <div style={{ gridColumn: "1 / -1", minWidth: 0 }}>
206
- <CliPullPreview
207
- t={t}
208
- preview={preview}
209
- confirmOverwrite={confirmOverwrite}
210
- sourcesBusy={sourcesBusy}
211
- onConfirmOverwriteChange={onConfirmOverwriteChange}
212
- onCommit={onCommitSource}
213
- onCancel={onCancelSourcePreview}
214
- />
215
- </div>
216
- ) : null}
217
- </Fragment>
218
- );
219
- })}
220
- <div style={cardStyle}>
221
- <div style={rowStyle}>
222
- <div>
223
- <h3 style={{ ...titleStyle, fontSize: 16 }}>{t("antigravityTitle")}</h3>
224
- <p style={{ ...bodyStyle, marginTop: 4 }}>{t("antigravityDescription")}</p>
225
- <p style={{ ...bodyStyle, marginTop: 4 }}>
226
- <span style={monoStyle}>{status.antigravity.route}</span>
227
- </p>
228
- </div>
229
- <Badge
230
- label={status.antigravity.installed ? t("antigravityInstalled") : t("antigravityMissing")}
231
- tone={status.antigravity.installed ? "success" : "neutral"}
232
- installed={status.antigravity.installed}
233
- />
234
- </div>
235
- <p style={bodyStyle}>{t("antigravityCliHint")}</p>
236
- <code style={{ ...monoStyle, fontSize: 12, overflowWrap: "anywhere" }}>{t("antigravityCliCommand")}</code>
237
- </div>
238
- </div>
239
- </>
240
- );
241
- }
@@ -1,33 +0,0 @@
1
- /** Status capsule badge with semantic tone colors. */
2
-
3
- import { badgeStyle, dotStyle, providerStatusTone, type StatusTone } from "../styles.ts";
4
- import type { ProviderStatus } from "../types.ts";
5
-
6
- export interface BadgeProps {
7
- label: string;
8
- tone?: StatusTone;
9
- /** When set, derives tone from provider login status. */
10
- providerStatus?: ProviderStatus["status"];
11
- installed?: boolean;
12
- showDot?: boolean;
13
- }
14
-
15
- export function Badge({ label, tone, providerStatus, installed = true, showDot = true }: BadgeProps) {
16
- const resolvedTone =
17
- tone ?? (providerStatus !== undefined ? providerStatusTone(providerStatus, installed) : "neutral");
18
- return (
19
- <span style={badgeStyle(resolvedTone)} role="status">
20
- {showDot ? (
21
- <span
22
- aria-hidden="true"
23
- style={{
24
- ...dotStyle(providerStatus ?? (resolvedTone === "success" ? "signed-in" : "signed-out"), installed),
25
- width: 7,
26
- height: 7,
27
- }}
28
- />
29
- ) : null}
30
- <span>{label}</span>
31
- </span>
32
- );
33
- }
@@ -1,265 +0,0 @@
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
- }