dsh-coding-subscription-oauth 0.5.2 → 0.5.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 (44) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/INSTALL.md +11 -11
  3. package/README.de.md +34 -9
  4. package/README.es.md +35 -9
  5. package/README.fr.md +35 -9
  6. package/README.ja.md +35 -9
  7. package/README.ko.md +35 -9
  8. package/README.md +34 -13
  9. package/README.pt-BR.md +35 -9
  10. package/README.ru.md +35 -9
  11. package/README.zh-CN.md +34 -13
  12. package/docs/02-architecture.md +4 -3
  13. package/docs/02-architecture.zh-CN.md +8 -3
  14. package/lib/adapter.d.ts.map +1 -1
  15. package/lib/alias-adapter.d.ts.map +1 -1
  16. package/lib/client.js +1 -1
  17. package/lib/client.js.map +4 -4
  18. package/lib/grok-errors.d.ts +13 -0
  19. package/lib/grok-errors.d.ts.map +1 -0
  20. package/lib/index.js +13 -3
  21. package/lib/index.js.map +3 -3
  22. package/media/settings_accounts.png +0 -0
  23. package/media/settings_capabilities.png +0 -0
  24. package/media/settings_gateway.png +0 -0
  25. package/media/settings_overview.png +0 -0
  26. package/package.json +2 -1
  27. package/src/adapter.ts +7 -2
  28. package/src/alias-adapter.ts +2 -1
  29. package/src/client/GrokBuildSettings.tsx +247 -1772
  30. package/src/client/api.ts +88 -0
  31. package/src/client/components/AboutTab.tsx +20 -0
  32. package/src/client/components/AccountsTab.tsx +224 -0
  33. package/src/client/components/CapabilitiesTab.tsx +214 -0
  34. package/src/client/components/CliPullPreview.tsx +107 -0
  35. package/src/client/components/GatewayTab.tsx +287 -0
  36. package/src/client/components/ProviderCard.tsx +322 -0
  37. package/src/client/components/SettingsTabs.tsx +65 -0
  38. package/src/client/constants.ts +206 -0
  39. package/src/client/display.ts +61 -0
  40. package/src/client/locales.ts +47 -15
  41. package/src/client/parsers.ts +386 -0
  42. package/src/client/styles.ts +180 -0
  43. package/src/client/types.ts +185 -0
  44. package/src/grok-errors.ts +24 -0
@@ -0,0 +1,88 @@
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
+ }
@@ -0,0 +1,20 @@
1
+ /** About tab: terms, remote help, and plugin version. */
2
+
3
+ import { PLUGIN_VERSION } from "../constants.ts";
4
+ import { bodyStyle, cardStyle, hintStyle, warningStyle } from "../styles.ts";
5
+ import type { GrokBuildSettingsInjected } from "../types.ts";
6
+
7
+ export interface AboutTabProps {
8
+ t: GrokBuildSettingsInjected["t"];
9
+ }
10
+
11
+ export function AboutTab({ t }: AboutTabProps) {
12
+ return (
13
+ <section style={cardStyle} aria-labelledby="coding-oauth-about-title">
14
+ <p style={warningStyle}>{t("termsWarning")}</p>
15
+ <p style={{ ...bodyStyle, marginTop: 12 }}>{t("remoteLoginHelp")}</p>
16
+ <p style={{ ...hintStyle, marginTop: 12 }}>{t("pluginVersion", { version: PLUGIN_VERSION })}</p>
17
+ <p style={{ ...hintStyle, marginTop: 8 }}>{t("aboutDocsHint")}</p>
18
+ </section>
19
+ );
20
+ }
@@ -0,0 +1,224 @@
1
+ /** Accounts tab: provider cards, CLI tips, and pull preview. */
2
+
3
+ import { PROVIDERS } from "../constants.ts";
4
+ import { allOfficialCliMissing, anyOfficialCliAvailable } from "../display.ts";
5
+ import {
6
+ accountGridStyle,
7
+ bodyStyle,
8
+ buttonStyle,
9
+ cardStyle,
10
+ dotStyle,
11
+ errorStyle,
12
+ hintStyle,
13
+ monoStyle,
14
+ rowStyle,
15
+ skeletonStyle,
16
+ statusStyle,
17
+ tipStyle,
18
+ titleStyle,
19
+ } from "../styles.ts";
20
+ import type {
21
+ CodingOAuthStatus,
22
+ GrokBuildSettingsInjected,
23
+ LoginMethod,
24
+ ProviderSlug,
25
+ SourcePreview,
26
+ SourceStatus,
27
+ UsageView,
28
+ } from "../types.ts";
29
+ import { CliPullPreview } from "./CliPullPreview.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
+ }
65
+
66
+ export function AccountsTab({
67
+ t,
68
+ status,
69
+ remote,
70
+ remoteTipDismissed,
71
+ onDismissRemoteTip,
72
+ sources,
73
+ sourcesError,
74
+ sourcesNotice,
75
+ sourcesBusy,
76
+ preview,
77
+ confirmOverwrite,
78
+ busyProvider,
79
+ codeInputs,
80
+ popupBlocked,
81
+ expandedProviders,
82
+ showUsage,
83
+ usage,
84
+ usageError,
85
+ usageLoading,
86
+ onSignIn,
87
+ onSignOut,
88
+ onCancelLogin,
89
+ onSubmitCode,
90
+ onCodeChange,
91
+ onToggleExpanded,
92
+ onPreviewSource,
93
+ onSaveModels,
94
+ onConfirmOverwriteChange,
95
+ onCommitSource,
96
+ onCancelSourcePreview,
97
+ onRefreshSources,
98
+ }: AccountsTabProps) {
99
+ if (status === undefined) {
100
+ return (
101
+ <div style={skeletonStyle} role="status" aria-busy="true">
102
+ <div style={statusStyle}>
103
+ <span aria-hidden="true" style={dotStyle("loading")} />
104
+ {t("loadingAccount")}
105
+ </div>
106
+ </div>
107
+ );
108
+ }
109
+
110
+ return (
111
+ <>
112
+ {remote && !remoteTipDismissed ? (
113
+ <div
114
+ style={{ ...tipStyle, display: "flex", alignItems: "flex-start", justifyContent: "space-between", gap: 12 }}
115
+ >
116
+ <p style={{ ...bodyStyle, margin: 0, color: "var(--dsw-alias-label-primary)" }}>{t("remoteAccountsTip")}</p>
117
+ <button type="button" style={buttonStyle} onClick={onDismissRemoteTip}>
118
+ {t("remoteTipDismiss")}
119
+ </button>
120
+ </div>
121
+ ) : null}
122
+ {allOfficialCliMissing(sources) ? (
123
+ <div
124
+ style={{ ...tipStyle, display: "flex", alignItems: "flex-start", justifyContent: "space-between", gap: 12 }}
125
+ >
126
+ <p style={{ ...bodyStyle, margin: 0, color: "var(--dsw-alias-label-primary)" }}>
127
+ {t("sourcesAllMissingHint")}
128
+ </p>
129
+ <button type="button" style={buttonStyle} disabled={sourcesBusy} onClick={onRefreshSources}>
130
+ {t("sourcesCheckAgain")}
131
+ </button>
132
+ </div>
133
+ ) : null}
134
+ {anyOfficialCliAvailable(sources) ? <p style={hintStyle}>{t("sourcesAvailableHint")}</p> : null}
135
+ {sourcesError === undefined ? null : (
136
+ <p style={errorStyle} role="alert">
137
+ {sourcesError}
138
+ </p>
139
+ )}
140
+ {sourcesNotice === undefined ? null : (
141
+ <p style={bodyStyle} role="status">
142
+ {sourcesNotice}
143
+ </p>
144
+ )}
145
+ <div style={accountGridStyle}>
146
+ {PROVIDERS.map((definition) => {
147
+ const providerStatus = status.providers[definition.slug];
148
+ const expanded = providerStatus.status === "signing-in" || expandedProviders[definition.slug] === true;
149
+ return (
150
+ <ProviderCard
151
+ key={definition.slug}
152
+ t={t}
153
+ definition={definition}
154
+ providerStatus={providerStatus}
155
+ busy={busyProvider === definition.slug}
156
+ sourcesBusy={sourcesBusy}
157
+ remote={remote}
158
+ codeInput={codeInputs[definition.slug] ?? ""}
159
+ popupBlocked={popupBlocked[definition.slug] === true}
160
+ expanded={expanded}
161
+ source={sources?.find((entry) => entry.kind === definition.slug)}
162
+ showUsage={showUsage}
163
+ usage={usage}
164
+ usageError={usageError}
165
+ usageLoading={usageLoading}
166
+ onSignIn={(method) => {
167
+ onSignIn(definition.slug, method);
168
+ }}
169
+ onSignOut={() => {
170
+ onSignOut(definition.slug);
171
+ }}
172
+ onCancelLogin={() => {
173
+ onCancelLogin(definition.slug);
174
+ }}
175
+ onSubmitCode={() => {
176
+ onSubmitCode(definition.slug);
177
+ }}
178
+ onCodeChange={(value) => {
179
+ onCodeChange(definition.slug, value);
180
+ }}
181
+ onToggleExpanded={() => {
182
+ onToggleExpanded(definition.slug);
183
+ }}
184
+ onPreviewSource={() => {
185
+ onPreviewSource(definition.slug);
186
+ }}
187
+ onSaveModels={(selected) => {
188
+ onSaveModels(definition.slug, selected);
189
+ }}
190
+ />
191
+ );
192
+ })}
193
+ <div style={cardStyle}>
194
+ <div style={rowStyle}>
195
+ <div>
196
+ <h3 style={{ ...titleStyle, fontSize: 16 }}>{t("antigravityTitle")}</h3>
197
+ <p style={{ ...bodyStyle, marginTop: 4 }}>{t("antigravityDescription")}</p>
198
+ <p style={{ ...bodyStyle, marginTop: 4 }}>
199
+ <span style={monoStyle}>{status.antigravity.route}</span>
200
+ </p>
201
+ </div>
202
+ <div style={statusStyle} role="status">
203
+ <span aria-hidden="true" style={dotStyle("signed-out", status.antigravity.installed)} />
204
+ <span>{status.antigravity.installed ? t("antigravityInstalled") : t("antigravityMissing")}</span>
205
+ </div>
206
+ </div>
207
+ <p style={bodyStyle}>{t("antigravityCliHint")}</p>
208
+ <code style={{ ...monoStyle, fontSize: 12, overflowWrap: "anywhere" }}>{t("antigravityCliCommand")}</code>
209
+ </div>
210
+ </div>
211
+ {preview === undefined ? null : (
212
+ <CliPullPreview
213
+ t={t}
214
+ preview={preview}
215
+ confirmOverwrite={confirmOverwrite}
216
+ sourcesBusy={sourcesBusy}
217
+ onConfirmOverwriteChange={onConfirmOverwriteChange}
218
+ onCommit={onCommitSource}
219
+ onCancel={onCancelSourcePreview}
220
+ />
221
+ )}
222
+ </>
223
+ );
224
+ }
@@ -0,0 +1,214 @@
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
+ checkRowStyle,
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
+
27
+ export interface CapabilitiesTabProps {
28
+ t: GrokBuildSettingsInjected["t"];
29
+ capabilities: CapabilitySnapshot | undefined;
30
+ capabilitiesError: string | undefined;
31
+ capabilitiesBusy: boolean;
32
+ imagine: ImagineCredentialView | undefined;
33
+ imagineError: string | undefined;
34
+ onPatchCapability: (key: CapabilitySettingKey, value: boolean | number) => Promise<boolean | undefined> | undefined;
35
+ }
36
+
37
+ export function CapabilitiesTab({
38
+ t,
39
+ capabilities,
40
+ capabilitiesError,
41
+ capabilitiesBusy,
42
+ imagine,
43
+ imagineError,
44
+ onPatchCapability,
45
+ }: CapabilitiesTabProps) {
46
+ const codexToggles = CAPABILITY_TOGGLES.filter((item) => !item.key.startsWith("grokImagine"));
47
+ const imagineToggles = CAPABILITY_TOGGLES.filter((item) => item.key.startsWith("grokImagine"));
48
+
49
+ return (
50
+ <section style={cardStyle} aria-labelledby="coding-oauth-capabilities-title">
51
+ <div>
52
+ <h3 id="coding-oauth-capabilities-title" style={{ ...titleStyle, fontSize: 16 }}>
53
+ {t("capabilitiesTitle")}
54
+ </h3>
55
+ <p style={{ ...bodyStyle, marginTop: 4 }}>{t("capabilitiesIntro")}</p>
56
+ </div>
57
+ {imagineError === undefined ? null : (
58
+ <p style={errorStyle} role="alert">
59
+ {imagineError}
60
+ </p>
61
+ )}
62
+ {imagine === undefined && imagineError === undefined ? (
63
+ <div style={skeletonStyle} role="status" aria-busy="true">
64
+ <div style={statusStyle}>
65
+ <span aria-hidden="true" style={dotStyle("loading")} />
66
+ {t("imagineLoading")}
67
+ </div>
68
+ </div>
69
+ ) : imagine === undefined ? null : (
70
+ <div style={nestedStyle}>
71
+ <p style={statusStyle} role="status">
72
+ <span aria-hidden="true" style={dotStyle(imagine.configured ? "available" : "unavailable")} />
73
+ <span>{imagine.configured ? t("imagineConfigured") : t("imagineNotConfigured")}</span>
74
+ </p>
75
+ <p style={hintStyle}>{t("imagineSource", { source: imagineSourceLabel(imagine.source, t) })}</p>
76
+ </div>
77
+ )}
78
+ {capabilitiesError === undefined ? null : (
79
+ <p style={errorStyle} role="alert">
80
+ {capabilitiesError}
81
+ </p>
82
+ )}
83
+ {capabilities === undefined ? (
84
+ <div style={skeletonStyle} role="status" aria-busy="true">
85
+ <div style={statusStyle}>
86
+ <span aria-hidden="true" style={dotStyle("loading")} />
87
+ {t("capabilitiesLoading")}
88
+ </div>
89
+ </div>
90
+ ) : (
91
+ <fieldset style={{ border: 0, margin: 0, padding: 0, minWidth: 0 }}>
92
+ <legend style={{ ...bodyStyle, position: "absolute", width: 1, height: 1, overflow: "hidden" }}>
93
+ {t("capabilitiesTitle")}
94
+ </legend>
95
+ {capabilities.writable ? null : <p style={hintStyle}>{t("capabilitiesReadOnly")}</p>}
96
+ <ul style={listStyle}>
97
+ {codexToggles.map((item) => {
98
+ const checked = capabilities.value[item.key];
99
+ const imagesOff = item.requiresImages === true && !capabilities.value.codexImages;
100
+ const disabled = capabilitiesBusy || !capabilities.writable || imagesOff;
101
+ return (
102
+ <li key={item.key}>
103
+ <label style={checkRowStyle}>
104
+ <input
105
+ type="checkbox"
106
+ checked={checked}
107
+ disabled={disabled}
108
+ aria-describedby={`cap-hint-${item.key}`}
109
+ onChange={(event) => {
110
+ void onPatchCapability(item.key, event.target.checked);
111
+ }}
112
+ />
113
+ <span>
114
+ <span style={{ display: "block" }}>{t(item.label)}</span>
115
+ <span id={`cap-hint-${item.key}`} style={{ display: "block", ...hintStyle }}>
116
+ {t(item.hint)}
117
+ </span>
118
+ </span>
119
+ </label>
120
+ </li>
121
+ );
122
+ })}
123
+ </ul>
124
+ <h4 style={{ ...titleStyle, fontSize: 14 }}>{t("imagineTitle")}</h4>
125
+ <ul style={listStyle}>
126
+ {imagineToggles.map((item) => {
127
+ const checked = capabilities.value[item.key];
128
+ const disabled = capabilitiesBusy || !capabilities.writable;
129
+ return (
130
+ <li key={item.key}>
131
+ <label style={checkRowStyle}>
132
+ <input
133
+ type="checkbox"
134
+ checked={checked}
135
+ disabled={disabled}
136
+ aria-describedby={`cap-hint-${item.key}`}
137
+ onChange={(event) => {
138
+ void onPatchCapability(item.key, event.target.checked);
139
+ }}
140
+ />
141
+ <span>
142
+ <span style={{ display: "block" }}>{t(item.label)}</span>
143
+ <span id={`cap-hint-${item.key}`} style={{ display: "block", ...hintStyle }}>
144
+ {t(item.hint)}
145
+ </span>
146
+ </span>
147
+ </label>
148
+ </li>
149
+ );
150
+ })}
151
+ </ul>
152
+ <div style={nestedStyle}>
153
+ <h4 style={{ ...titleStyle, fontSize: 14 }}>{t("capabilityLimitsTitle")}</h4>
154
+ <p style={hintStyle}>{t("capabilityLimitsHint")}</p>
155
+ <ul style={listStyle}>
156
+ {CAPABILITY_LIMITS.map((item) => {
157
+ const displayValue = capabilities.value[item.key] / item.scale;
158
+ const inputId = `cap-limit-${item.key}`;
159
+ return (
160
+ <li key={item.key} style={rowStyle}>
161
+ <label htmlFor={inputId} style={{ ...bodyStyle, flex: "1 1 360px" }}>
162
+ <span style={{ display: "block", color: "var(--dsw-alias-label-primary)" }}>{t(item.label)}</span>
163
+ <span id={`${inputId}-hint`} style={{ display: "block", ...hintStyle }}>
164
+ {t(item.hint)}
165
+ </span>
166
+ </label>
167
+ <input
168
+ key={`${item.key}-${String(capabilities.revision)}-${String(displayValue)}`}
169
+ id={inputId}
170
+ type="number"
171
+ inputMode="numeric"
172
+ min={item.min}
173
+ max={item.max}
174
+ step={1}
175
+ defaultValue={displayValue}
176
+ disabled={capabilitiesBusy || !capabilities.writable}
177
+ aria-describedby={`${inputId}-hint`}
178
+ style={{ ...inputStyle, width: 112, flex: "0 0 112px" }}
179
+ onInput={(event) => {
180
+ event.currentTarget.setCustomValidity("");
181
+ }}
182
+ onKeyDown={(event) => {
183
+ if (event.key === "Enter") event.currentTarget.blur();
184
+ if (event.key === "Escape") {
185
+ event.currentTarget.value = String(displayValue);
186
+ event.currentTarget.setCustomValidity("");
187
+ }
188
+ }}
189
+ onBlur={(event) => {
190
+ const target = event.currentTarget;
191
+ const next = Number(target.value);
192
+ if (!Number.isInteger(next) || next < item.min || next > item.max) {
193
+ target.setCustomValidity(t("capabilityLimitInvalid", { min: item.min, max: item.max }));
194
+ target.reportValidity();
195
+ return;
196
+ }
197
+ target.setCustomValidity("");
198
+ const apiValue = next * item.scale;
199
+ if (apiValue === capabilities.value[item.key]) return;
200
+ void Promise.resolve(onPatchCapability(item.key, apiValue)).then((saved) => {
201
+ if (saved === false && target.isConnected) target.value = String(displayValue);
202
+ });
203
+ }}
204
+ />
205
+ </li>
206
+ );
207
+ })}
208
+ </ul>
209
+ </div>
210
+ </fieldset>
211
+ )}
212
+ </section>
213
+ );
214
+ }
@@ -0,0 +1,107 @@
1
+ /** CLI credential pull preview panel. */
2
+
3
+ import { SOURCE_CONFLICT_KEY, SOURCE_KIND_KEY, SOURCE_PREVIEW_ACTION_KEY } from "../constants.ts";
4
+ import { formatEpoch } from "../parsers.ts";
5
+ import {
6
+ bodyStyle,
7
+ buttonStyle,
8
+ cardStyle,
9
+ checkRowStyle,
10
+ hintStyle,
11
+ listStyle,
12
+ monoStyle,
13
+ primaryButtonStyle,
14
+ } from "../styles.ts";
15
+ import type { GrokBuildSettingsInjected, SourcePreview } from "../types.ts";
16
+
17
+ export interface CliPullPreviewProps {
18
+ t: GrokBuildSettingsInjected["t"];
19
+ preview: SourcePreview;
20
+ confirmOverwrite: boolean;
21
+ sourcesBusy: boolean;
22
+ onConfirmOverwriteChange: (checked: boolean) => void;
23
+ onCommit: () => void;
24
+ onCancel: () => void;
25
+ }
26
+
27
+ export function CliPullPreview({
28
+ t,
29
+ preview,
30
+ confirmOverwrite,
31
+ sourcesBusy,
32
+ onConfirmOverwriteChange,
33
+ onCommit,
34
+ onCancel,
35
+ }: CliPullPreviewProps) {
36
+ const expiresAt = formatEpoch(preview.expiresAt);
37
+ const ticketExpiresAt = formatEpoch(preview.ticketExpiresAt);
38
+
39
+ return (
40
+ <div style={cardStyle} aria-live="polite">
41
+ <p style={bodyStyle}>
42
+ {t("sourcesPreviewTitle")} · {t(SOURCE_KIND_KEY[preview.kind])}
43
+ </p>
44
+ <p style={hintStyle}>
45
+ <span style={monoStyle}>{preview.displayPath}</span>
46
+ </p>
47
+ <p style={bodyStyle}>
48
+ {t("sourcesConflict", {
49
+ detail: t(
50
+ preview.conflict === undefined ? "sourceConflictUnrecognized" : SOURCE_CONFLICT_KEY[preview.conflict],
51
+ ),
52
+ })}
53
+ </p>
54
+ <p style={bodyStyle}>
55
+ {t("sourcesAction", {
56
+ detail: t(
57
+ preview.action === undefined ? "sourceActionUnrecognized" : SOURCE_PREVIEW_ACTION_KEY[preview.action],
58
+ ),
59
+ })}
60
+ </p>
61
+ {expiresAt === undefined ? null : <p style={hintStyle}>{t("sourcesPreviewExpires", { time: expiresAt })}</p>}
62
+ {ticketExpiresAt === undefined ? null : (
63
+ <p style={hintStyle}>{t("sourcesTicketExpires", { time: ticketExpiresAt })}</p>
64
+ )}
65
+ {preview.warnings.length === 0 ? null : (
66
+ <ul style={{ ...listStyle, gap: 4 }} aria-label={t("sourcesWarnings")}>
67
+ {preview.warnings.map((warning) => (
68
+ <li key={warning} style={hintStyle}>
69
+ {warning}
70
+ </li>
71
+ ))}
72
+ </ul>
73
+ )}
74
+ {preview.confirmOverwriteRequired ? (
75
+ <label style={checkRowStyle}>
76
+ <input
77
+ type="checkbox"
78
+ checked={confirmOverwrite}
79
+ disabled={sourcesBusy || preview.action === "blocked"}
80
+ onChange={(event) => {
81
+ onConfirmOverwriteChange(event.target.checked);
82
+ }}
83
+ />
84
+ <span>
85
+ {t("sourcesConfirmOverwrite")}
86
+ <span style={{ display: "block", ...hintStyle }}>{t("sourcesConfirmOverwriteHint")}</span>
87
+ </span>
88
+ </label>
89
+ ) : null}
90
+ <div style={{ display: "flex", flexWrap: "wrap", gap: 8 }}>
91
+ <button
92
+ type="button"
93
+ style={primaryButtonStyle}
94
+ disabled={
95
+ sourcesBusy || preview.action === "blocked" || (preview.confirmOverwriteRequired && !confirmOverwrite)
96
+ }
97
+ onClick={onCommit}
98
+ >
99
+ {t("sourcesCommit")}
100
+ </button>
101
+ <button type="button" style={buttonStyle} disabled={sourcesBusy} onClick={onCancel}>
102
+ {t("sourcesCancelPreview")}
103
+ </button>
104
+ </div>
105
+ </div>
106
+ );
107
+ }