dsh-coding-subscription-oauth 0.6.4 → 0.7.0

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 (151) hide show
  1. package/CHANGELOG.md +291 -255
  2. package/CONTRIBUTING.md +138 -129
  3. package/INSTALL.md +261 -256
  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 +321 -320
  12. package/README.pt-BR.md +304 -304
  13. package/README.ru.md +304 -304
  14. package/README.zh-CN.md +319 -318
  15. package/compatibility/dsh-bom.json +36 -30
  16. package/cordis.patch.yml +13 -13
  17. package/docs/00-project-rules.md +213 -212
  18. package/docs/02-architecture.md +142 -138
  19. package/docs/02-architecture.zh-CN.md +142 -138
  20. package/lib/auth-routes.d.ts +10 -1
  21. package/lib/auth-routes.d.ts.map +1 -1
  22. package/lib/bin.js +483 -50
  23. package/lib/bin.js.map +4 -4
  24. package/lib/client.js +5 -5
  25. package/lib/client.js.map +4 -4
  26. package/lib/compatibility.d.ts +0 -1
  27. package/lib/compatibility.d.ts.map +1 -1
  28. package/lib/gateway-protocol.d.ts +3 -46
  29. package/lib/gateway-protocol.d.ts.map +1 -1
  30. package/lib/gateway-routes.d.ts.map +1 -1
  31. package/lib/grok-errors.d.ts +2 -12
  32. package/lib/grok-errors.d.ts.map +1 -1
  33. package/lib/grok-imagine/client.d.ts +73 -0
  34. package/lib/grok-imagine/client.d.ts.map +1 -0
  35. package/lib/grok-imagine/index.d.ts +8 -0
  36. package/lib/grok-imagine/index.d.ts.map +1 -0
  37. package/lib/grok-imagine/net.d.ts +10 -0
  38. package/lib/grok-imagine/net.d.ts.map +1 -0
  39. package/lib/grok-imagine/parse.d.ts +20 -0
  40. package/lib/grok-imagine/parse.d.ts.map +1 -0
  41. package/lib/grok-imagine/types.d.ts +191 -0
  42. package/lib/grok-imagine/types.d.ts.map +1 -0
  43. package/lib/grok-imagine.d.ts +3 -263
  44. package/lib/grok-imagine.d.ts.map +1 -1
  45. package/lib/http-json.d.ts +2 -9
  46. package/lib/http-json.d.ts.map +1 -1
  47. package/lib/ids.d.ts +4 -0
  48. package/lib/ids.d.ts.map +1 -1
  49. package/lib/index.d.ts +2 -1
  50. package/lib/index.d.ts.map +1 -1
  51. package/lib/index.js +730 -196
  52. package/lib/index.js.map +4 -4
  53. package/lib/invariant.js.map +1 -1
  54. package/lib/kimi-errors.d.ts +2 -12
  55. package/lib/kimi-errors.d.ts.map +1 -1
  56. package/lib/oauth-session.d.ts +2 -0
  57. package/lib/oauth-session.d.ts.map +1 -1
  58. package/lib/session.d.ts +2 -0
  59. package/lib/session.d.ts.map +1 -1
  60. package/lib/store.d.ts +73 -1
  61. package/lib/store.d.ts.map +1 -1
  62. package/media/en/settings_accounts.png +0 -0
  63. package/media/en/settings_capabilities.png +0 -0
  64. package/media/en/settings_gateway.png +0 -0
  65. package/media/settings_accounts.png +0 -0
  66. package/media/settings_capabilities.png +0 -0
  67. package/media/settings_gateway.png +0 -0
  68. package/media/settings_overview.png +0 -0
  69. package/media/zh-CN/settings_accounts.png +0 -0
  70. package/media/zh-CN/settings_capabilities.png +0 -0
  71. package/media/zh-CN/settings_gateway.png +0 -0
  72. package/package.json +224 -221
  73. package/patches/dsh-agy@0.1.2.patch +25 -25
  74. package/scripts/release.mjs +187 -186
  75. package/scripts/smoke-deployed-routes.mjs +146 -146
  76. package/scripts/verify-deployed-catalog.mjs +87 -87
  77. package/src/adapter.ts +0 -348
  78. package/src/alias-adapter.ts +0 -147
  79. package/src/auth-routes.ts +0 -921
  80. package/src/auth.ts +0 -67
  81. package/src/bin.ts +0 -350
  82. package/src/capability-routes.ts +0 -279
  83. package/src/capability-runtime.ts +0 -314
  84. package/src/capability-settings.ts +0 -671
  85. package/src/capability-tools.ts +0 -685
  86. package/src/catalog.ts +0 -271
  87. package/src/client/GrokBuildSettings.tsx +0 -771
  88. package/src/client/api.ts +0 -88
  89. package/src/client/components/AboutTab.tsx +0 -30
  90. package/src/client/components/AccountsTab.tsx +0 -241
  91. package/src/client/components/Badge.tsx +0 -33
  92. package/src/client/components/CapabilitiesTab.tsx +0 -265
  93. package/src/client/components/CliPullPreview.tsx +0 -116
  94. package/src/client/components/CopyButton.tsx +0 -57
  95. package/src/client/components/GatewayTab.tsx +0 -469
  96. package/src/client/components/NoticeBanner.tsx +0 -46
  97. package/src/client/components/ProgressBar.tsx +0 -53
  98. package/src/client/components/ProviderCard.tsx +0 -606
  99. package/src/client/components/SettingsTabs.tsx +0 -75
  100. package/src/client/components/ToggleSwitch.tsx +0 -71
  101. package/src/client/constants.ts +0 -230
  102. package/src/client/display.ts +0 -61
  103. package/src/client/dshClientAdapter.ts +0 -127
  104. package/src/client/gatewaySnippets.ts +0 -37
  105. package/src/client/index.tsx +0 -156
  106. package/src/client/locales.ts +0 -540
  107. package/src/client/microStyles.ts +0 -52
  108. package/src/client/parsers.ts +0 -398
  109. package/src/client/styles.ts +0 -325
  110. package/src/client/types.ts +0 -199
  111. package/src/codex-http.ts +0 -447
  112. package/src/codex-images.ts +0 -503
  113. package/src/codex-model-capabilities.ts +0 -320
  114. package/src/codex-search.ts +0 -245
  115. package/src/codex-usage.ts +0 -263
  116. package/src/compatibility.ts +0 -55
  117. package/src/dsh-host-adapter.ts +0 -173
  118. package/src/gateway-anthropic-messages.ts +0 -84
  119. package/src/gateway-auth.ts +0 -102
  120. package/src/gateway-backend.ts +0 -274
  121. package/src/gateway-body.ts +0 -49
  122. package/src/gateway-config.ts +0 -76
  123. package/src/gateway-http.ts +0 -104
  124. package/src/gateway-openai-chat.ts +0 -124
  125. package/src/gateway-openai-responses.ts +0 -53
  126. package/src/gateway-parse.ts +0 -224
  127. package/src/gateway-protocol.ts +0 -52
  128. package/src/gateway-routes.ts +0 -158
  129. package/src/gateway.ts +0 -258
  130. package/src/grok-errors.ts +0 -24
  131. package/src/grok-imagine.ts +0 -1627
  132. package/src/grok-import.ts +0 -151
  133. package/src/http-json.ts +0 -82
  134. package/src/ids.ts +0 -59
  135. package/src/imagine-routes.ts +0 -463
  136. package/src/index.ts +0 -735
  137. package/src/invariant.ts +0 -17
  138. package/src/kimi-errors.ts +0 -26
  139. package/src/media-store.ts +0 -927
  140. package/src/oauth-import-routes.ts +0 -324
  141. package/src/oauth-providers.ts +0 -152
  142. package/src/oauth-session.ts +0 -183
  143. package/src/oauth-sources.ts +0 -1104
  144. package/src/oauth.ts +0 -620
  145. package/src/provider.ts +0 -128
  146. package/src/proxy.ts +0 -11
  147. package/src/redact.ts +0 -72
  148. package/src/session.ts +0 -218
  149. package/src/store.ts +0 -217
  150. package/src/web-origin.ts +0 -296
  151. package/src/web-routes.ts +0 -38
@@ -1,75 +0,0 @@
1
- /** Accessible segmented tablist for Coding OAuth settings. */
2
-
3
- import type { KeyboardEvent } from "react";
4
- import { SETTINGS_TABS } from "../constants.ts";
5
- import { segmentedNavStyle, segmentedTabActiveStyle, segmentedTabStyle } from "../styles.ts";
6
- import type { GrokBuildSettingsInjected, SettingsTabId } from "../types.ts";
7
-
8
- export interface SettingsTabHint {
9
- id: SettingsTabId;
10
- suffix?: string;
11
- }
12
-
13
- export interface SettingsTabsProps {
14
- t: GrokBuildSettingsInjected["t"];
15
- activeTab: SettingsTabId;
16
- onChange: (tab: SettingsTabId) => void;
17
- hints?: readonly SettingsTabHint[];
18
- }
19
-
20
- export function SettingsTabs({ t, activeTab, onChange, hints }: SettingsTabsProps) {
21
- const hintFor = (id: SettingsTabId): string | undefined => hints?.find((entry) => entry.id === id)?.suffix;
22
-
23
- const focusTab = (index: number): void => {
24
- const tab = SETTINGS_TABS[index];
25
- if (tab === undefined) return;
26
- onChange(tab.id);
27
- const button = document.getElementById(`coding-oauth-tab-${tab.id}`);
28
- button?.focus();
29
- };
30
-
31
- const onKeyDown = (event: KeyboardEvent<HTMLDivElement>): void => {
32
- const current = SETTINGS_TABS.findIndex((tab) => tab.id === activeTab);
33
- if (current < 0) return;
34
- if (event.key === "ArrowRight" || event.key === "ArrowDown") {
35
- event.preventDefault();
36
- focusTab((current + 1) % SETTINGS_TABS.length);
37
- } else if (event.key === "ArrowLeft" || event.key === "ArrowUp") {
38
- event.preventDefault();
39
- focusTab((current - 1 + SETTINGS_TABS.length) % SETTINGS_TABS.length);
40
- } else if (event.key === "Home") {
41
- event.preventDefault();
42
- focusTab(0);
43
- } else if (event.key === "End") {
44
- event.preventDefault();
45
- focusTab(SETTINGS_TABS.length - 1);
46
- }
47
- };
48
-
49
- return (
50
- <div role="tablist" aria-label={t("title")} style={segmentedNavStyle} onKeyDown={onKeyDown}>
51
- {SETTINGS_TABS.map((tab) => {
52
- const selected = activeTab === tab.id;
53
- const suffix = hintFor(tab.id);
54
- const label = suffix === undefined ? t(tab.label) : `${t(tab.label)} (${suffix})`;
55
- return (
56
- <button
57
- key={tab.id}
58
- id={`coding-oauth-tab-${tab.id}`}
59
- type="button"
60
- role="tab"
61
- aria-selected={selected}
62
- aria-controls={selected ? `coding-oauth-panel-${tab.id}` : undefined}
63
- tabIndex={selected ? 0 : -1}
64
- style={selected ? segmentedTabActiveStyle : segmentedTabStyle}
65
- onClick={() => {
66
- onChange(tab.id);
67
- }}
68
- >
69
- {label}
70
- </button>
71
- );
72
- })}
73
- </div>
74
- );
75
- }
@@ -1,71 +0,0 @@
1
- /** Accessible toggle switch replacing native checkboxes for capability settings. */
2
-
3
- import type { CSSProperties } from "react";
4
- import { TRANSITION } from "../styles.ts";
5
-
6
- export interface ToggleSwitchProps {
7
- checked: boolean;
8
- disabled?: boolean;
9
- onChange: (checked: boolean) => void;
10
- /** Accessible label (visually hidden when label prop is rendered externally). */
11
- ariaLabel?: string;
12
- ariaDescribedBy?: string;
13
- id?: string;
14
- }
15
-
16
- const trackStyle = (checked: boolean, disabled: boolean): CSSProperties => ({
17
- position: "relative",
18
- width: 40,
19
- height: 22,
20
- borderRadius: 11,
21
- flex: "0 0 auto",
22
- background: checked
23
- ? "var(--dsw-alias-button-primary-fill)"
24
- : "var(--dsw-alias-border-l4, rgba(127, 127, 127, 0.45))",
25
- opacity: disabled ? 0.5 : 1,
26
- cursor: disabled ? "not-allowed" : "pointer",
27
- transition: TRANSITION,
28
- border: "none",
29
- padding: 0,
30
- });
31
-
32
- const thumbStyle = (checked: boolean): CSSProperties => ({
33
- position: "absolute",
34
- top: 2,
35
- left: checked ? 20 : 2,
36
- width: 18,
37
- height: 18,
38
- borderRadius: "50%",
39
- // Match DSH primary fill/foreground pairing so the thumb stays visible when
40
- // dark theme inverts brand-primary to near-white.
41
- background: checked ? "var(--dsw-alias-label-primary-foreground)" : "var(--dsw-alias-button-elevated-fill)",
42
- boxShadow: "0 1px 3px rgba(0, 0, 0, 0.25)",
43
- transition: TRANSITION,
44
- });
45
-
46
- export function ToggleSwitch({
47
- checked,
48
- disabled = false,
49
- onChange,
50
- ariaLabel,
51
- ariaDescribedBy,
52
- id,
53
- }: ToggleSwitchProps) {
54
- return (
55
- <button
56
- id={id}
57
- type="button"
58
- role="switch"
59
- aria-checked={checked}
60
- aria-label={ariaLabel}
61
- aria-describedby={ariaDescribedBy}
62
- disabled={disabled}
63
- style={trackStyle(checked, disabled)}
64
- onClick={() => {
65
- if (!disabled) onChange(!checked);
66
- }}
67
- >
68
- <span aria-hidden="true" style={thumbStyle(checked)} />
69
- </button>
70
- );
71
- }
@@ -1,230 +0,0 @@
1
- /** Static tables for the Coding OAuth settings UI. */
2
-
3
- import {
4
- CAPABILITY_SETTINGS_PATH,
5
- CODING_OAUTH_LOGIN_CANCEL_PATH,
6
- CODING_OAUTH_LOGIN_CODE_PATH,
7
- CODING_OAUTH_LOGIN_PATH,
8
- CODING_OAUTH_LOGOUT_PATH,
9
- CODING_OAUTH_MODELS_PATH,
10
- CODING_OAUTH_STATUS_PATH,
11
- CODEX_USAGE_PATH as CORE_CODEX_USAGE_PATH,
12
- GATEWAY_REVEAL_PATH as CORE_GATEWAY_REVEAL_PATH,
13
- GATEWAY_ROTATE_PATH as CORE_GATEWAY_ROTATE_PATH,
14
- GATEWAY_SETTINGS_PATH,
15
- IMAGINE_CREDENTIAL_STATUS_PATH,
16
- OAUTH_IMPORT_CANCEL_PATH,
17
- OAUTH_IMPORT_COMMIT_PATH,
18
- OAUTH_IMPORT_PREVIEW_PATH,
19
- OAUTH_IMPORT_SOURCES_PATH,
20
- } from "dsh-coding-oauth-core/contracts";
21
- import type { GrokBuildSettingsKey } from "./locales.ts";
22
- import type {
23
- CapabilityFlagKey,
24
- CapabilityLimitKey,
25
- ProviderCardDefinition,
26
- SettingsTabId,
27
- SourceCommitAction,
28
- SourceConflict,
29
- SourceKind,
30
- SourcePreviewAction,
31
- SourceReason,
32
- } from "./types.ts";
33
-
34
- export const STATUS_PATH = CODING_OAUTH_STATUS_PATH;
35
- export const LOGIN_PATH = CODING_OAUTH_LOGIN_PATH;
36
- export const LOGIN_CODE_PATH = CODING_OAUTH_LOGIN_CODE_PATH;
37
- export const LOGIN_CANCEL_PATH = CODING_OAUTH_LOGIN_CANCEL_PATH;
38
- export const LOGOUT_PATH = CODING_OAUTH_LOGOUT_PATH;
39
- export const MODELS_PATH = CODING_OAUTH_MODELS_PATH;
40
- export const SOURCES_PATH = OAUTH_IMPORT_SOURCES_PATH;
41
- export const SOURCES_PREVIEW_PATH = OAUTH_IMPORT_PREVIEW_PATH;
42
- export const SOURCES_COMMIT_PATH = OAUTH_IMPORT_COMMIT_PATH;
43
- export const SOURCES_CANCEL_PATH = OAUTH_IMPORT_CANCEL_PATH;
44
- export const CAPABILITIES_PATH = CAPABILITY_SETTINGS_PATH;
45
- export const CODEX_USAGE_PATH = CORE_CODEX_USAGE_PATH;
46
- export const IMAGINE_CREDENTIAL_PATH = IMAGINE_CREDENTIAL_STATUS_PATH;
47
- export const GATEWAY_PATH = GATEWAY_SETTINGS_PATH;
48
- export const GATEWAY_REVEAL_PATH = CORE_GATEWAY_REVEAL_PATH;
49
- export const GATEWAY_ROTATE_PATH = CORE_GATEWAY_ROTATE_PATH;
50
- export const POLL_INTERVAL_MS = 1_000;
51
- export const HOUR_MS = 60 * 60 * 1000;
52
-
53
- export const SOURCE_KINDS: readonly SourceKind[] = ["grok", "codex", "kimi", "claude"];
54
- export const SOURCE_REASONS: readonly SourceReason[] = ["missing", "unsafe", "invalid", "too_large"];
55
- export const SOURCE_CONFLICTS: readonly SourceConflict[] = [
56
- "none",
57
- "same_credential",
58
- "same_account",
59
- "different_account",
60
- "unknown_account",
61
- "unreadable_destination",
62
- "unsafe_destination",
63
- ];
64
- export const SOURCE_PREVIEW_ACTIONS: readonly SourcePreviewAction[] = ["import", "reuse", "overwrite", "blocked"];
65
- export const SOURCE_COMMIT_ACTIONS: readonly SourceCommitAction[] = ["imported", "unchanged", "overwritten"];
66
-
67
- export const SOURCE_DEFAULT_PATH: { readonly [K in SourceKind]: string } = {
68
- grok: "~/.grok/auth.json",
69
- codex: "~/.codex/auth.json",
70
- kimi: "~/.kimi/credentials/kimi-code.json",
71
- claude: "~/.claude/.credentials.json",
72
- };
73
-
74
- export const SOURCE_KIND_KEY: { readonly [K in SourceKind]: GrokBuildSettingsKey } = {
75
- grok: "sourceKindGrok",
76
- codex: "sourceKindCodex",
77
- kimi: "sourceKindKimi",
78
- claude: "sourceKindClaude",
79
- };
80
-
81
- export const SOURCE_REASON_KEY: { readonly [K in SourceReason]: GrokBuildSettingsKey } = {
82
- missing: "sourceReasonMissing",
83
- unsafe: "sourceReasonUnsafe",
84
- invalid: "sourceReasonInvalid",
85
- too_large: "sourceReasonTooLarge",
86
- };
87
-
88
- export const SOURCE_CONFLICT_KEY: { readonly [K in SourceConflict]: GrokBuildSettingsKey } = {
89
- none: "sourceConflictNone",
90
- same_credential: "sourceConflictSameCredential",
91
- same_account: "sourceConflictSameAccount",
92
- different_account: "sourceConflictDifferentAccount",
93
- unknown_account: "sourceConflictUnknownAccount",
94
- unreadable_destination: "sourceConflictUnreadableDestination",
95
- unsafe_destination: "sourceConflictUnsafeDestination",
96
- };
97
-
98
- export const SOURCE_PREVIEW_ACTION_KEY: { readonly [K in SourcePreviewAction]: GrokBuildSettingsKey } = {
99
- import: "sourceActionImport",
100
- reuse: "sourceActionReuse",
101
- overwrite: "sourceActionOverwrite",
102
- blocked: "sourceActionBlocked",
103
- };
104
-
105
- export const SOURCE_COMMIT_ACTION_KEY: { readonly [K in SourceCommitAction]: GrokBuildSettingsKey } = {
106
- imported: "sourceCommitImported",
107
- unchanged: "sourceCommitUnchanged",
108
- overwritten: "sourceCommitOverwritten",
109
- };
110
-
111
- export const CAPABILITY_TOGGLES: readonly {
112
- key: CapabilityFlagKey;
113
- label: GrokBuildSettingsKey;
114
- hint: GrokBuildSettingsKey;
115
- requiresImages?: true;
116
- }[] = [
117
- { key: "codexSearch", label: "capCodexSearch", hint: "capCodexSearchHint" },
118
- { key: "codexImages", label: "capCodexImages", hint: "capCodexImagesHint" },
119
- { key: "codexImageEdits", label: "capCodexImageEdits", hint: "capCodexImageEditsHint", requiresImages: true },
120
- {
121
- key: "codexImagesAnyModel",
122
- label: "capCodexImagesAnyModel",
123
- hint: "capCodexImagesAnyModelHint",
124
- requiresImages: true,
125
- },
126
- { key: "codexUsage", label: "capCodexUsage", hint: "capCodexUsageHint" },
127
- { key: "codexFast", label: "capCodexFast", hint: "capCodexFastHint" },
128
- { key: "grokImagineImage", label: "capGrokImagineImage", hint: "capGrokImagineImageHint" },
129
- { key: "grokImagineVideo", label: "capGrokImagineVideo", hint: "capGrokImagineVideoHint" },
130
- ];
131
-
132
- export const CAPABILITY_LIMITS: readonly {
133
- key: CapabilityLimitKey;
134
- label: GrokBuildSettingsKey;
135
- hint: GrokBuildSettingsKey;
136
- min: number;
137
- max: number;
138
- scale: number;
139
- }[] = [
140
- { key: "searchResults", label: "capSearchResults", hint: "capSearchResultsHint", min: 1, max: 20, scale: 1 },
141
- { key: "imageCount", label: "capImageCount", hint: "capImageCountHint", min: 1, max: 4, scale: 1 },
142
- {
143
- key: "videoArtifactTtlMs",
144
- label: "capVideoTtlHours",
145
- hint: "capVideoTtlHoursHint",
146
- min: 1,
147
- max: 168,
148
- scale: HOUR_MS,
149
- },
150
- ];
151
-
152
- export const IMAGINE_SOURCE_KEY: { readonly [source: string]: GrokBuildSettingsKey } = {
153
- none: "imagineSourceNone",
154
- env: "imagineSourceEnv",
155
- environment: "imagineSourceEnv",
156
- "xai-api-key": "imagineSourceEnv",
157
- xai_api_key: "imagineSourceEnv",
158
- "api-key": "imagineSourceApiKey",
159
- api_key: "imagineSourceApiKey",
160
- apikey: "imagineSourceApiKey",
161
- key: "imagineSourceApiKey",
162
- settings: "imagineSourceApiKey",
163
- oauth: "imagineSourceOAuth",
164
- "oauth-access": "imagineSourceOAuth",
165
- "grok-cli-key": "imagineSourceCliKey",
166
- "cli-key": "imagineSourceCliKey",
167
- };
168
-
169
- export const PROVIDERS: readonly ProviderCardDefinition[] = [
170
- {
171
- slug: "grok",
172
- route: "grok-build",
173
- titleKey: "grokTitle",
174
- descriptionKey: "grokDescription",
175
- methods: ["pkce", "device"],
176
- recommended: "pkce",
177
- remoteRecommended: "device",
178
- },
179
- {
180
- slug: "codex",
181
- route: "codex-oauth",
182
- titleKey: "codexTitle",
183
- descriptionKey: "codexDescription",
184
- methods: ["device", "browser"],
185
- recommended: "device",
186
- remoteRecommended: "device",
187
- },
188
- {
189
- slug: "kimi",
190
- route: "kimi-code-oauth",
191
- titleKey: "kimiTitle",
192
- descriptionKey: "kimiDescription",
193
- methods: ["device"],
194
- recommended: "device",
195
- remoteRecommended: "device",
196
- },
197
- {
198
- slug: "claude",
199
- route: "claude-code-oauth",
200
- titleKey: "claudeTitle",
201
- descriptionKey: "claudeDescription",
202
- methods: ["browser"],
203
- recommended: "browser",
204
- remoteRecommended: "browser",
205
- },
206
- ];
207
-
208
- export const SETTINGS_TABS: readonly { id: SettingsTabId; label: GrokBuildSettingsKey }[] = [
209
- { id: "accounts", label: "tabAccounts" },
210
- { id: "gateway", label: "tabGateway" },
211
- { id: "capabilities", label: "tabCapabilities" },
212
- { id: "about", label: "tabAbout" },
213
- ];
214
-
215
- export const GATEWAY_PORT_MIN = 1024;
216
- export const GATEWAY_PORT_MAX = 65_535;
217
- export const GATEWAY_RANDOM_PORT_MIN = 18_100;
218
- export const GATEWAY_RANDOM_PORT_MAX = 18_999;
219
- export const GATEWAY_RANDOM_RESERVED = new Set([22, 53, 3080, 7890, 9090, 18_080]);
220
-
221
- export const CONSUMED_PREVIEW_CODES = new Set([
222
- "preview_invalid",
223
- "preview_expired",
224
- "source_changed",
225
- "destination_changed",
226
- "confirm_required",
227
- "unsafe_destination",
228
- ]);
229
-
230
- export const PLUGIN_VERSION = "0.6.4";
@@ -1,61 +0,0 @@
1
- /** Pure display helpers for remote UX and CLI pull noise control. */
2
-
3
- import type { GrokBuildSettingsInjected, LoginMethod, ProviderCardDefinition, SourceStatus } from "./types.ts";
4
-
5
- const LOOPBACK_HOSTS = new Set(["localhost", "127.0.0.1", "[::1]", "::1"]);
6
-
7
- /** True when the Settings page is served from a non-loopback host (typical remote DSH). */
8
- export function isLikelyRemoteHost(hostname: string): boolean {
9
- const normalized = hostname.trim().toLowerCase();
10
- if (normalized.length === 0) return false;
11
- if (LOOPBACK_HOSTS.has(normalized)) return false;
12
- if (normalized.endsWith(".localhost")) return false;
13
- return true;
14
- }
15
-
16
- export function preferredLoginMethod(definition: ProviderCardDefinition, remote: boolean): LoginMethod {
17
- if (
18
- remote &&
19
- definition.remoteRecommended !== undefined &&
20
- definition.methods.includes(definition.remoteRecommended)
21
- ) {
22
- return definition.remoteRecommended;
23
- }
24
- return definition.recommended;
25
- }
26
-
27
- /** Put the recommended method first so the primary CTA is unambiguous. */
28
- export function orderedLoginMethods(definition: ProviderCardDefinition, remote: boolean): LoginMethod[] {
29
- const preferred = preferredLoginMethod(definition, remote);
30
- const rest = definition.methods.filter((method) => method !== preferred);
31
- return definition.methods.includes(preferred) ? [preferred, ...rest] : [...definition.methods];
32
- }
33
-
34
- /** Per-card CLI “missing” copy is noisy on remote hosts; keep only actionable reasons. */
35
- export function shouldShowPerCardSourceReason(source: SourceStatus | undefined): boolean {
36
- if (source === undefined || source.available) return false;
37
- if (source.reason === undefined) return false;
38
- return source.reason !== "missing";
39
- }
40
-
41
- export function allOfficialCliMissing(sources: readonly SourceStatus[] | undefined): boolean {
42
- if (sources === undefined || sources.length === 0) return false;
43
- return sources.every((source) => !source.available && (source.reason === undefined || source.reason === "missing"));
44
- }
45
-
46
- export function anyOfficialCliAvailable(sources: readonly SourceStatus[] | undefined): boolean {
47
- return sources?.some((source) => source.available) === true;
48
- }
49
-
50
- export function methodLabel(
51
- method: LoginMethod,
52
- t: GrokBuildSettingsInjected["t"],
53
- options?: { remote?: boolean; primary?: boolean },
54
- ): string {
55
- if (method === "device") {
56
- if (options?.remote === true && options.primary === true) return t("deviceLoginRemote");
57
- return t("deviceLogin");
58
- }
59
- if (method === "browser") return t("browserLogin");
60
- return t("pkceLogin");
61
- }
@@ -1,127 +0,0 @@
1
- /** Capability adapter for the unstable DSH browser client surface. */
2
-
3
- import type {} from "@deepseek-ai/dsh-client-locale/client";
4
- import type { ClientContext } from "@deepseek-ai/dsh-client-runtime/client";
5
- import type {} from "@deepseek-ai/dsh-client-ui-slots";
6
-
7
- export interface DshClientCompatibilityDiagnostic {
8
- readonly id: string;
9
- readonly level: "warning" | "error";
10
- readonly message: string;
11
- readonly expected: "function";
12
- readonly actual: string;
13
- }
14
-
15
- type SlotsApi = ClientContext["slots"];
16
-
17
- function slotsOf(context: unknown): SlotsApi | undefined {
18
- if (typeof context !== "object" || context === null) return undefined;
19
- let slots: unknown;
20
- try {
21
- const get = (context as { readonly get?: unknown }).get;
22
- if (typeof get === "function") slots = get.call(context, "slots");
23
- } catch {
24
- // Older client runtimes may not expose the Cordis reflection helper.
25
- }
26
- if (slots === undefined) {
27
- try {
28
- slots = (context as { readonly slots?: unknown }).slots;
29
- } catch {
30
- // Strict Cordis rejects optional service reads outside an inject scope.
31
- }
32
- }
33
- if (
34
- typeof slots === "object" &&
35
- slots !== null &&
36
- typeof (slots as { readonly inject?: unknown }).inject === "function" &&
37
- typeof (slots as { readonly register?: unknown }).register === "function"
38
- )
39
- return slots as SlotsApi;
40
- return undefined;
41
- }
42
-
43
- export interface DshClientAdapter {
44
- readonly context: ClientContext;
45
- readonly locale: ClientContext["locale"];
46
- readonly effect: ClientContext["effect"];
47
- diagnostics(): readonly DshClientCompatibilityDiagnostic[];
48
- assertCompatible(): void;
49
- installSlots(options: {
50
- readonly register: (slots: SlotsApi) => () => void;
51
- readonly mountFallback: () => () => void;
52
- }): void;
53
- }
54
-
55
- type InstallSlotsOptions = Parameters<DshClientAdapter["installSlots"]>[0];
56
-
57
- export function createDshClientAdapter(context: ClientContext): DshClientAdapter {
58
- const candidate = context as unknown as Record<string, unknown>;
59
- const locale = candidate["locale"] as Record<string, unknown> | undefined;
60
- const slots = slotsOf(context);
61
- const checks: Array<[string, unknown, DshClientCompatibilityDiagnostic["level"]]> = [
62
- ["client.effect", candidate["effect"], "error"],
63
- ["client.locale.register", locale?.["register"], "error"],
64
- ["client.locale.bind", locale?.["bind"], "error"],
65
- ["client.slots.inject", slots?.inject, "warning"],
66
- ];
67
- const diagnostics = checks.flatMap(([id, value, level]): DshClientCompatibilityDiagnostic[] =>
68
- typeof value === "function"
69
- ? []
70
- : [
71
- {
72
- id,
73
- level,
74
- message:
75
- level === "warning"
76
- ? `${id} is unavailable; the independent settings entry remains active`
77
- : `${id} is unavailable in the DSH client runtime`,
78
- expected: "function",
79
- actual: typeof value,
80
- },
81
- ],
82
- );
83
- const frozenDiagnostics = Object.freeze([...diagnostics]);
84
- return Object.freeze({
85
- context,
86
- locale: context.locale,
87
- effect: context.effect,
88
- diagnostics: () => frozenDiagnostics,
89
- assertCompatible() {
90
- const errors = diagnostics.filter((item) => item.level === "error");
91
- if (errors.length > 0) {
92
- throw new Error(`incompatible DSH client API: ${errors.map((item) => item.id).join(", ")}`);
93
- }
94
- },
95
- installSlots(options: InstallSlotsOptions) {
96
- let disposed = false;
97
- let installed = false;
98
- let disposeCurrent: () => void = () => undefined;
99
- const install = (slotContext: ClientContext): boolean => {
100
- const slots = slotsOf(slotContext);
101
- if (disposed || installed || slots === undefined) return false;
102
- installed = true;
103
- disposeCurrent();
104
- disposeCurrent = options.register(slots);
105
- return true;
106
- };
107
-
108
- if (!install(context)) {
109
- disposeCurrent = options.mountFallback();
110
- const inject = candidate["inject"];
111
- if (typeof inject === "function") {
112
- (inject as ClientContext["inject"]).call(context, ["slots"], (slotContext) => {
113
- install(slotContext);
114
- });
115
- }
116
- }
117
-
118
- context.effect(
119
- () => () => {
120
- disposed = true;
121
- disposeCurrent();
122
- },
123
- "dsh-coding-subscription-oauth: independent settings entry",
124
- );
125
- },
126
- });
127
- }
@@ -1,37 +0,0 @@
1
- /** Quick-setup code snippets for the local API gateway. */
2
-
3
- export type GatewaySnippetId = "curl" | "python" | "ide";
4
-
5
- export function buildGatewaySnippets(
6
- openAiBaseUrl: string,
7
- anthropicBaseUrl: string,
8
- apiKeyPlaceholder: string,
9
- model = "<gateway-model>",
10
- ): Record<GatewaySnippetId, string> {
11
- const key = apiKeyPlaceholder.length > 0 ? apiKeyPlaceholder : "<your-gateway-key>";
12
- return {
13
- curl: `curl ${openAiBaseUrl}/chat/completions \\
14
- -H "Authorization: Bearer ${key}" \\
15
- -H "Content-Type: application/json" \\
16
- -d '{"model":"${model}","messages":[{"role":"user","content":"Hello"}]}'`,
17
- python: `from openai import OpenAI
18
-
19
- client = OpenAI(
20
- base_url="${openAiBaseUrl}",
21
- api_key="${key}",
22
- )
23
-
24
- response = client.chat.completions.create(
25
- model="${model}",
26
- messages=[{"role": "user", "content": "Hello"}],
27
- )
28
- print(response.choices[0].message.content)`,
29
- ide: `# OpenAI-compatible client
30
- base_url: ${openAiBaseUrl}
31
- api_key: ${key}
32
-
33
- # Anthropic-compatible client
34
- base_url: ${anthropicBaseUrl}
35
- api_key: ${key}`,
36
- };
37
- }