dsh-coding-subscription-oauth 0.5.7 → 0.6.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 (141) hide show
  1. package/CHANGELOG.md +211 -182
  2. package/CONTRIBUTING.md +120 -109
  3. package/INSTALL.md +240 -209
  4. package/LICENSE +19 -19
  5. package/NOTICE +11 -11
  6. package/README.de.md +298 -293
  7. package/README.es.md +299 -294
  8. package/README.fr.md +299 -294
  9. package/README.ja.md +299 -294
  10. package/README.ko.md +299 -294
  11. package/README.md +313 -306
  12. package/README.pt-BR.md +299 -294
  13. package/README.ru.md +299 -294
  14. package/README.zh-CN.md +311 -304
  15. package/compatibility/dsh-bom.json +43 -0
  16. package/cordis.patch.yml +13 -13
  17. package/docs/00-project-rules.md +195 -195
  18. package/docs/02-architecture.md +134 -129
  19. package/docs/02-architecture.zh-CN.md +134 -129
  20. package/lib/auth-routes.d.ts +8 -15
  21. package/lib/auth-routes.d.ts.map +1 -1
  22. package/lib/bin.js +746 -1402
  23. package/lib/bin.js.map +4 -4
  24. package/lib/capability-routes.d.ts +3 -3
  25. package/lib/capability-routes.d.ts.map +1 -1
  26. package/lib/capability-settings.d.ts +5 -4
  27. package/lib/capability-settings.d.ts.map +1 -1
  28. package/lib/client.js +27 -8
  29. package/lib/client.js.map +4 -4
  30. package/lib/compatibility.d.ts +46 -0
  31. package/lib/compatibility.d.ts.map +1 -0
  32. package/lib/dsh-host-adapter.d.ts +18 -0
  33. package/lib/dsh-host-adapter.d.ts.map +1 -0
  34. package/lib/gateway-auth.d.ts +1 -2
  35. package/lib/gateway-auth.d.ts.map +1 -1
  36. package/lib/gateway-routes.d.ts +3 -4
  37. package/lib/gateway-routes.d.ts.map +1 -1
  38. package/lib/gateway.d.ts +4 -0
  39. package/lib/gateway.d.ts.map +1 -1
  40. package/lib/ids.d.ts +3 -32
  41. package/lib/ids.d.ts.map +1 -1
  42. package/lib/imagine-routes.d.ts +2 -0
  43. package/lib/imagine-routes.d.ts.map +1 -1
  44. package/lib/index.d.ts +19 -4
  45. package/lib/index.d.ts.map +1 -1
  46. package/lib/index.js +26573 -1023
  47. package/lib/index.js.map +4 -4
  48. package/lib/invariant.js.map +1 -1
  49. package/lib/oauth-import-routes.d.ts +3 -4
  50. package/lib/oauth-import-routes.d.ts.map +1 -1
  51. package/lib/proxy.d.ts +3 -16
  52. package/lib/proxy.d.ts.map +1 -1
  53. package/lib/web-origin.d.ts +28 -4
  54. package/lib/web-origin.d.ts.map +1 -1
  55. package/lib/web-routes.d.ts.map +1 -1
  56. package/media/en/settings_accounts.png +0 -0
  57. package/media/en/settings_capabilities.png +0 -0
  58. package/media/en/settings_gateway.png +0 -0
  59. package/media/zh-CN/settings_accounts.png +0 -0
  60. package/media/zh-CN/settings_capabilities.png +0 -0
  61. package/media/zh-CN/settings_gateway.png +0 -0
  62. package/package.json +209 -172
  63. package/patches/dsh-agy@0.1.2.patch +25 -25
  64. package/scripts/release.mjs +186 -166
  65. package/scripts/smoke-deployed-routes.mjs +146 -146
  66. package/scripts/verify-deployed-catalog.mjs +87 -87
  67. package/src/adapter.ts +287 -287
  68. package/src/alias-adapter.ts +153 -153
  69. package/src/auth-routes.ts +921 -871
  70. package/src/auth.ts +67 -67
  71. package/src/bin.ts +350 -350
  72. package/src/capability-routes.ts +279 -275
  73. package/src/capability-runtime.ts +313 -313
  74. package/src/capability-settings.ts +658 -657
  75. package/src/capability-tools.ts +666 -666
  76. package/src/catalog.ts +271 -271
  77. package/src/client/GrokBuildSettings.tsx +770 -718
  78. package/src/client/api.ts +88 -88
  79. package/src/client/components/AboutTab.tsx +30 -20
  80. package/src/client/components/AccountsTab.tsx +241 -224
  81. package/src/client/components/Badge.tsx +33 -33
  82. package/src/client/components/CapabilitiesTab.tsx +265 -227
  83. package/src/client/components/CliPullPreview.tsx +116 -107
  84. package/src/client/components/CopyButton.tsx +57 -57
  85. package/src/client/components/GatewayTab.tsx +469 -364
  86. package/src/client/components/NoticeBanner.tsx +46 -46
  87. package/src/client/components/ProgressBar.tsx +53 -52
  88. package/src/client/components/ProviderCard.tsx +606 -502
  89. package/src/client/components/SettingsTabs.tsx +75 -75
  90. package/src/client/components/ToggleSwitch.tsx +71 -62
  91. package/src/client/constants.ts +224 -206
  92. package/src/client/display.ts +61 -61
  93. package/src/client/dshClientAdapter.ts +109 -0
  94. package/src/client/gatewaySnippets.ts +37 -36
  95. package/src/client/index.tsx +156 -37
  96. package/src/client/locales.ts +535 -487
  97. package/src/client/microStyles.ts +52 -33
  98. package/src/client/parsers.ts +396 -386
  99. package/src/client/styles.ts +325 -312
  100. package/src/client/types.ts +197 -185
  101. package/src/codex-http.ts +447 -447
  102. package/src/codex-images.ts +485 -485
  103. package/src/codex-model-capabilities.ts +320 -320
  104. package/src/codex-search.ts +245 -245
  105. package/src/codex-usage.ts +263 -263
  106. package/src/compatibility.ts +55 -0
  107. package/src/dsh-host-adapter.ts +171 -0
  108. package/src/gateway-anthropic-messages.ts +84 -84
  109. package/src/gateway-auth.ts +102 -100
  110. package/src/gateway-backend.ts +274 -274
  111. package/src/gateway-body.ts +49 -49
  112. package/src/gateway-config.ts +76 -76
  113. package/src/gateway-http.ts +104 -104
  114. package/src/gateway-openai-chat.ts +124 -124
  115. package/src/gateway-openai-responses.ts +53 -53
  116. package/src/gateway-parse.ts +224 -224
  117. package/src/gateway-protocol.ts +52 -52
  118. package/src/gateway-routes.ts +158 -152
  119. package/src/gateway.ts +258 -242
  120. package/src/grok-errors.ts +24 -24
  121. package/src/grok-imagine.ts +1627 -1627
  122. package/src/grok-import.ts +151 -151
  123. package/src/http-json.ts +82 -82
  124. package/src/ids.ts +59 -45
  125. package/src/imagine-routes.ts +463 -461
  126. package/src/index.ts +748 -598
  127. package/src/invariant.ts +17 -17
  128. package/src/kimi-errors.ts +26 -26
  129. package/src/media-store.ts +927 -927
  130. package/src/oauth-import-routes.ts +324 -314
  131. package/src/oauth-providers.ts +152 -152
  132. package/src/oauth-session.ts +183 -183
  133. package/src/oauth-sources.ts +1104 -1104
  134. package/src/oauth.ts +620 -620
  135. package/src/provider.ts +128 -128
  136. package/src/proxy.ts +11 -99
  137. package/src/redact.ts +72 -72
  138. package/src/session.ts +218 -218
  139. package/src/store.ts +217 -217
  140. package/src/web-origin.ts +296 -60
  141. package/src/web-routes.ts +38 -75
@@ -1,133 +1,138 @@
1
- # Architecture
2
-
3
- > [**中文版**](02-architecture.zh-CN.md) · English
4
-
5
- This document describes the internal architecture of `dsh-coding-subscription-oauth`. It is the source for the technical notes in `README.md` and is intended for contributors and maintainers.
6
-
7
- ## 1. Routes and native providers
8
-
9
- ```text
10
- Harness route pi-ai provider request authentication
11
- ────────────────────────────────────────────────────────────
12
- grok-build grok-build xAI access token + Grok CLI headers
13
- codex-oauth openai-codex OAuth token → apiKey override
14
- kimi-code-oauth kimi-coding OAuth token → Authorization: Bearer
15
- claude-code-oauth anthropic sk-ant-oat token → Claude Code headers
16
- agy dsh-agy external dsh-agy own account pool
17
- ```
18
-
19
- External routes and the pi-ai native ids are separated by `AliasLlmAdapter`. `PiAiAdapter` always sees the native provider id, so Codex tool-calls, Claude compatibility checks and the Kimi Anthropic transport do not break when a route is renamed.
20
-
21
- "Authenticated" in model discovery is defined as an existing, structurally valid, refreshable OAuth credential; the selector does not probe upstream on every open. Credentials that upstream has revoked but are still locally valid are recognized during token refresh or inference, avoiding extra network requests on catalog load.
22
-
23
- ## 2. Host data flow
24
-
25
- ```text
26
- Settings / CLI
27
-
28
- ├─ GrokBuildWebAuth ── Grok custom PKCE/device
29
- │ └─ .grok-build-auth.json
30
-
31
- ├─ SubscriptionWebAuth ── pi-ai OAuth login/refresh
32
- │ ├─ Codex ── .codex-oauth-auth.json
33
- │ ├─ Kimi ── .kimi-code-oauth-auth.json
34
- │ └─ Claude ── .claude-code-oauth-auth.json
35
-
36
- └─ OAuthImportSession ── read-only allowlisted CLI discovery
37
- └─ explicit one-way Pull (preview ticket → dest store)
38
- official CLI files are never written
39
-
40
- OAuthProviderSession.resolveAccessToken()
41
- └─ Models.getAuth(native id) # refresh-under-lock
42
- └─ OAuthCredentialFileStore # 0600 + atomic write + cross-process lock
43
-
44
- CapabilitySettingsController (default-off, applies: live)
45
- └─ CapabilityRuntimeState
46
- ├─ Codex search / usage / gpt-image-2 images
47
- ├─ codex-oauth-fast (only after a fresh priority catalog)
48
- └─ Grok Imagine (api.x.ai + XAI_API_KEY via DSH credentials)
49
-
50
- ctx.llm route
51
- └─ AliasLlmAdapter
52
- └─ PiAiAdapter
53
- └─ native pi-ai Provider.streamSimple()
54
- ```
55
-
56
- ## 3. Module responsibilities
57
-
58
- - `store.ts`: one file owns one provider credential; keeps the legacy Grok store API; `invalidate()` backdates `expires` after an upstream AUTH rejection.
59
- - `oauth-providers.ts`: Codex/Kimi/Claude definitions, route metadata, request token bridge.
60
- - `oauth-session.ts`: login, refresh, static model catalog and model-selection cache.
61
- - `oauth-sources.ts`: allowlisted official Grok/Codex/Kimi/Claude CLI discovery; hardened lstat/`O_NOFOLLOW`/owner/mode/regular-file/size reads; one-use preview tickets (five minutes, max 32); never writes official CLI files.
62
- - `oauth-import-routes.ts`: same-origin Pull HTTP API (discover → preview → commit/cancel) into the destination store lock.
63
- - `alias-adapter.ts`: translates Harness routes, does not modify pi-ai `model.provider`, and runs a credential gate before `listModels()`; unauthenticated or unreadable credentials return an empty catalog, and the provider group name is `(OAuth)`. On an AUTH finish it invalidates the stored token so the harness retry can refresh first. The finish pipeline also remaps Kimi misclassified AUTH context overflow and xAI capacity wording → `RATE_LIMIT`.
64
- - `grok-errors.ts`: detects xAI “at capacity / high demand / priority processing / overloaded” messages and rewrites them to `RATE_LIMIT` so they are not skipped as `PI_AI_ERROR`.
65
- - `adapter.ts`: composes Grok with the three subscription profiles; asks pi-ai for a 60 s remaining-validity floor and registers a retry policy that includes AUTH plus transient codes (default 5 retries, 5 s → 80 s stacked exponential). Optionally wraps `codex-oauth-fast` as **Fast requested**.
66
- - `auth-routes.ts`: legacy Grok API + the unified `/plugins/dsh-grok-build/oauth/*`; JSON writes use a 64 KiB bounded reader and return 400/413 for malformed/oversized bodies.
67
- - `capability-settings.ts`: default-off live flags and limits (search 1–20, image count 1–4, artifact TTL 1 h–7 d).
68
- - `capability-routes.ts`: secret-free capability snapshot plus optional Codex usage and Imagine credential-status routes.
69
- - `capability-runtime.ts`: live bind/unbind of search, tools, and the Fast route after a fresh priority catalog.
70
- - `capability-tools.ts`: optional Codex / Grok Imagine tool definitions; flags re-read at execute time.
71
- - `codex-http.ts`: opt-in private `chatgpt.com/backend-api` client (HTTPS-only, first-party host).
72
- - `codex-search.ts` / `codex-usage.ts` / `codex-images.ts`: opt-in search, quota, and fixed `gpt-image-2` generate/edit (edits require current-session top-level attachment ownership).
73
- - `codex-model-capabilities.ts`: live Codex service-tier cache; fail-closed Fast eligibility; injects `service_tier: priority` and the routing hint.
74
- - `grok-imagine.ts`: official `api.x.ai` Imagine client (`grok-imagine-image-2.0` / `grok-imagine-video-1.5`); `XAI_API_KEY` via DSH credentials only; MIME/size/time/redirect/DNS download controls; frozen hosts `imgen.x.ai`, `videogen.x.ai`, `vidgen.x.ai`.
75
- - `imagine-routes.ts`: same-origin loopback GET routes for generated images and video artifacts.
76
- - `media-store.ts`: owner-private artifact store (256 MiB per-object and aggregate unique-byte hard caps, seven days).
77
- - `client/`: four native account cards, CLI Pull, capability switches, gateway controls, and the external Antigravity status card.
78
- - `proxy.ts`: process-wide undici dispatcher, but proxies only a reviewed domain whitelist.
1
+ # Architecture
2
+
3
+ > [**中文版**](02-architecture.zh-CN.md) · English
4
+
5
+ This document describes the internal architecture of `dsh-coding-subscription-oauth`. It is the source for the technical notes in `README.md` and is intended for contributors and maintainers.
6
+
7
+ ## 1. Routes and native providers
8
+
9
+ ```text
10
+ Harness route pi-ai provider request authentication
11
+ ────────────────────────────────────────────────────────────
12
+ grok-build grok-build xAI access token + Grok CLI headers
13
+ codex-oauth openai-codex OAuth token → apiKey override
14
+ kimi-code-oauth kimi-coding OAuth token → Authorization: Bearer
15
+ claude-code-oauth anthropic sk-ant-oat token → Claude Code headers
16
+ agy dsh-agy external dsh-agy own account pool
17
+ ```
18
+
19
+ External routes and the pi-ai native ids are separated by `AliasLlmAdapter`. `PiAiAdapter` always sees the native provider id, so Codex tool-calls, Claude compatibility checks and the Kimi Anthropic transport do not break when a route is renamed.
20
+
21
+ "Authenticated" in model discovery is defined as an existing, structurally valid, refreshable OAuth credential; the selector does not probe upstream on every open. Credentials that upstream has revoked but are still locally valid are recognized during token refresh or inference, avoiding extra network requests on catalog load.
22
+
23
+ ## 2. Host data flow
24
+
25
+ ```text
26
+ Settings / CLI
27
+
28
+ ├─ GrokBuildWebAuth ── Grok custom PKCE/device
29
+ │ └─ .grok-build-auth.json
30
+
31
+ ├─ SubscriptionWebAuth ── pi-ai OAuth login/refresh
32
+ │ ├─ Codex ── .codex-oauth-auth.json
33
+ │ ├─ Kimi ── .kimi-code-oauth-auth.json
34
+ │ └─ Claude ── .claude-code-oauth-auth.json
35
+
36
+ └─ OAuthImportSession ── read-only allowlisted CLI discovery
37
+ └─ explicit one-way Pull (preview ticket → dest store)
38
+ official CLI files are never written
39
+
40
+ OAuthProviderSession.resolveAccessToken()
41
+ └─ Models.getAuth(native id) # refresh-under-lock
42
+ └─ OAuthCredentialFileStore # 0600 + atomic write + cross-process lock
43
+
44
+ CapabilitySettingsController (default-off, applies: live)
45
+ └─ CapabilityRuntimeState
46
+ ├─ Codex search / usage / gpt-image-2 images
47
+ ├─ codex-oauth-fast (only after a fresh priority catalog)
48
+ └─ Grok Imagine (api.x.ai + XAI_API_KEY via DSH credentials)
49
+
50
+ ctx.llm route
51
+ └─ AliasLlmAdapter
52
+ └─ PiAiAdapter
53
+ └─ native pi-ai Provider.streamSimple()
54
+ ```
55
+
56
+ ## 3. Module responsibilities
57
+
58
+ - `store.ts`: one file owns one provider credential; keeps the legacy Grok store API; `invalidate()` backdates `expires` after an upstream AUTH rejection.
59
+ - `oauth-providers.ts`: Codex/Kimi/Claude definitions, route metadata, request token bridge.
60
+ - `oauth-session.ts`: login, refresh, static model catalog and model-selection cache.
61
+ - `oauth-sources.ts`: allowlisted official Grok/Codex/Kimi/Claude CLI discovery; hardened lstat/`O_NOFOLLOW`/owner/mode/regular-file/size reads; one-use preview tickets (five minutes, max 32); never writes official CLI files.
62
+ - `oauth-import-routes.ts`: same-origin Pull HTTP API (discover → preview → commit/cancel) into the destination store lock.
63
+ - `alias-adapter.ts`: translates Harness routes, does not modify pi-ai `model.provider`, and runs a credential gate before `listModels()`; unauthenticated or unreadable credentials return an empty catalog, and the provider group name is `(OAuth)`. On an AUTH finish it invalidates the stored token so the harness retry can refresh first. The finish pipeline also remaps Kimi misclassified AUTH context overflow and xAI capacity wording → `RATE_LIMIT`.
64
+ - `grok-errors.ts`: detects xAI “at capacity / high demand / priority processing / overloaded” messages and rewrites them to `RATE_LIMIT` so they are not skipped as `PI_AI_ERROR`.
65
+ - `adapter.ts`: composes Grok with the three subscription profiles; asks pi-ai for a 60 s remaining-validity floor and registers a retry policy that includes AUTH plus transient codes (default 5 retries, 5 s → 80 s stacked exponential). Optionally wraps `codex-oauth-fast` as **Fast requested**.
66
+ - `auth-routes.ts`: legacy Grok API + the unified `/plugins/dsh-grok-build/oauth/*`; JSON writes use a 64 KiB bounded reader and return 400/413 for malformed/oversized bodies.
67
+ - `capability-settings.ts`: default-off live flags and limits (search 1–20, image count 1–4, artifact TTL 1 h–7 d).
68
+ - `capability-routes.ts`: secret-free capability snapshot plus optional Codex usage and Imagine credential-status routes.
69
+ - `capability-runtime.ts`: live bind/unbind of search, tools, and the Fast route after a fresh priority catalog.
70
+ - `capability-tools.ts`: optional Codex / Grok Imagine tool definitions; flags re-read at execute time.
71
+ - `codex-http.ts`: opt-in private `chatgpt.com/backend-api` client (HTTPS-only, first-party host).
72
+ - `codex-search.ts` / `codex-usage.ts` / `codex-images.ts`: opt-in search, quota, and fixed `gpt-image-2` generate/edit (edits require current-session top-level attachment ownership).
73
+ - `codex-model-capabilities.ts`: live Codex service-tier cache; fail-closed Fast eligibility; injects `service_tier: priority` and the routing hint.
74
+ - `grok-imagine.ts`: official `api.x.ai` Imagine client (`grok-imagine-image-2.0` / `grok-imagine-video-1.5`); `XAI_API_KEY` via DSH credentials only; MIME/size/time/redirect/DNS download controls; frozen hosts `imgen.x.ai`, `videogen.x.ai`, `vidgen.x.ai`.
75
+ - `imagine-routes.ts`: same-origin loopback GET routes for generated images and video artifacts.
76
+ - `media-store.ts`: owner-private artifact store (256 MiB per-object and aggregate unique-byte hard caps, seven days).
77
+ - `client/`: four native account cards, CLI Pull, capability switches, gateway controls, and the external Antigravity status card.
78
+ - `proxy.ts`: process-wide undici dispatcher, but proxies only a reviewed domain whitelist.
79
79
  - `gateway*.ts`: opt-in isolated loopback OpenAI/Anthropic-compatible HTTP server (default off; independent of the DSH web port).
80
-
81
- ## 4. Web API
82
-
83
- Unified interface:
84
-
85
- ```text
86
- GET /plugins/dsh-grok-build/oauth/status
87
- POST /plugins/dsh-grok-build/oauth/login
88
- POST /plugins/dsh-grok-build/oauth/code
89
- POST /plugins/dsh-grok-build/oauth/cancel
90
- POST /plugins/dsh-grok-build/oauth/logout
91
- POST /plugins/dsh-grok-build/oauth/models
92
-
93
- GET /plugins/dsh-grok-build/oauth/sources
94
- POST /plugins/dsh-grok-build/oauth/sources/preview
95
- POST /plugins/dsh-grok-build/oauth/sources/commit
96
- POST /plugins/dsh-grok-build/oauth/sources/cancel
97
-
98
- GET /plugins/dsh-grok-build/capabilities
99
- PATCH /plugins/dsh-grok-build/capabilities
100
- PUT /plugins/dsh-grok-build/capabilities
101
- GET /plugins/dsh-grok-build/codex/usage
102
- GET /plugins/dsh-grok-build/imagine/credential-status
103
- GET /plugins/dsh-grok-build/imagine/images/<id>
104
- GET /plugins/dsh-grok-build/imagine/media/<id>
105
- GET /plugins/dsh-grok-build/gateway
106
- PATCH /plugins/dsh-grok-build/gateway
107
- POST /plugins/dsh-grok-build/gateway/rotate
108
- ```
109
-
80
+ - `dsh-host-adapter.ts` / `web-origin.ts`: isolate the changing DSH service surface and prefer a host-native `ownerRequestPolicy`; the fallback constrains loopback/SSH Host and Origin, while HTTPS proxy access jointly verifies the real peer, exact Origin/Host, Fetch Metadata, owner proof, and independent CSRF. A throwing or malformed host policy is denied without escaping the route boundary.
81
+
82
+ ## 4. Web API
83
+
84
+ Unified interface:
85
+
86
+ ```text
87
+ GET /plugins/dsh-grok-build/oauth/status
88
+ POST /plugins/dsh-grok-build/oauth/login
89
+ POST /plugins/dsh-grok-build/oauth/code
90
+ POST /plugins/dsh-grok-build/oauth/cancel
91
+ POST /plugins/dsh-grok-build/oauth/logout
92
+ POST /plugins/dsh-grok-build/oauth/models
93
+
94
+ GET /plugins/dsh-grok-build/oauth/sources
95
+ POST /plugins/dsh-grok-build/oauth/sources/preview
96
+ POST /plugins/dsh-grok-build/oauth/sources/commit
97
+ POST /plugins/dsh-grok-build/oauth/sources/cancel
98
+
99
+ GET /plugins/dsh-grok-build/capabilities
100
+ PATCH /plugins/dsh-grok-build/capabilities
101
+ PUT /plugins/dsh-grok-build/capabilities
102
+ GET /plugins/dsh-grok-build/codex/usage
103
+ GET /plugins/dsh-grok-build/imagine/credential-status
104
+ GET /plugins/dsh-grok-build/imagine/images/<id>
105
+ GET /plugins/dsh-grok-build/imagine/media/<id>
106
+ GET /plugins/dsh-grok-build/gateway
107
+ PATCH /plugins/dsh-grok-build/gateway
108
+ POST /plugins/dsh-grok-build/gateway/rotate
109
+ ```
110
+
110
111
  Write endpoints take `provider: grok|codex|kimi|claude` in the body. Responses contain only status, authorization URL, device user code, model ids and a non-sensitive expiry; they never contain access/refresh tokens. JSON request bodies are capped at 64 KiB before parsing.
111
112
 
112
- `/oauth/sources` is read-only discovery. Preview/commit is the explicit one-way Pull (tickets one-use, five minutes, max 32). Capability writes are secret-free compare-and-swap snapshots in the `coding-subscription-oauth` settings section and apply live. Seven flags default off; `searchResults` is 1–20 (default 5), `imageCount` is 1–4 (default 1), and `videoArtifactTtlMs` is 1 hour–7 days (default 7 days; UI 1–168 hours); decreases rewrite/clean existing expiries immediately, while increases affect only new artifacts. Imagine download routes are same-origin loopback GETs; they never return a signed upstream URL.
113
-
114
- The legacy `/plugins/dsh-grok-build/auth/*` endpoints remain registered and reuse the same Grok controller.
115
-
116
- ## 5. Antigravity
117
-
118
- This project does not replicate the private Google Antigravity protocol. The profile separately installs `dsh-agy@0.1.2`, which provides the `agy` route. Because the `/agy` dashboard in that version includes an export API with no authentication of its own, trusted-host deployments should disable `dsh-agy-web` in the profile's final `cordis.patch.yml` (see `INSTALL.md`) and keep only the host adapter and CLI. The profile uses a pnpm patch with a lockfile hash: with no Google session, `listModels()` returns empty; after authentication the provider group name is `Google Antigravity (OAuth)`.
119
-
120
- ## 6. Compatibility
121
-
122
- The canonical package and repository name is **`dsh-coding-subscription-oauth`**. The previous GitHub URL still resolves to the same `main`, so old `dsh plugin add github:lninghaha/dsh-grok-build` commands continue to install the renamed package. The first public npm/GitHub Release was **`0.4.1`**. The current release is **`0.5.7`** (`dsh plugin --profile web add dsh-coding-subscription-oauth@0.5.7`). GitHub and local tarball installs remain valid.
123
-
124
- Stable on-disk / in-process identifiers (do not rename without a migration):
125
-
126
- - Cordis id: `llm-grok-build-oauth`
127
- - Settings HTTP API: `/plugins/dsh-grok-build/oauth/*`, `/plugins/dsh-grok-build/capabilities`, `/plugins/dsh-grok-build/codex/usage`, `/plugins/dsh-grok-build/imagine/*`, and legacy `/plugins/dsh-grok-build/auth/*`
128
- - Credential files: `$DSH_HOME/.grok-build-auth.json` and the other `*-oauth-auth.json` files
129
- - Imagine credential: DSH credentials reference `XAI_API_KEY` (never Grok OAuth, never process-env fallback)
130
- - CLI: `dsh-coding-oauth` (primary) and `dsh-grok-build` (alias)
131
- - LLM routes: `grok-build`, `codex-oauth`, `kimi-code-oauth`, `claude-code-oauth`; optional `codex-oauth-fast` (v0.4.0, advertised only when a fresh live catalog lists `priority`)
132
-
113
+ Every Settings route shares `OwnerRequestPolicy`. `X-Forwarded-*` is forwarding metadata, never owner proof; a fallback policy missing any independent signal rejects remote requests. Status responses carry the server-derived `accessMode`, so the client does not infer SSH or proxy access from the hostname.
114
+
115
+ `/oauth/sources` is read-only discovery. Preview/commit is the explicit one-way Pull (tickets one-use, five minutes, max 32). Capability writes are secret-free compare-and-swap snapshots in the `coding-subscription-oauth` settings section and apply live. Seven flags default off; `searchResults` is 1–20 (default 5), `imageCount` is 1–4 (default 1), and `videoArtifactTtlMs` is 1 hour–7 days (default 7 days; UI 1–168 hours); decreases rewrite/clean existing expiries immediately, while increases affect only new artifacts. Imagine download routes are same-origin loopback GETs; they never return a signed upstream URL.
116
+
117
+ The legacy `/plugins/dsh-grok-build/auth/*` endpoints remain registered and reuse the same Grok controller.
118
+
119
+ ## 5. Antigravity
120
+
121
+ This project does not replicate the private Google Antigravity protocol. The profile separately installs `dsh-agy@0.1.2`, which provides the `agy` route. Because the `/agy` dashboard in that version includes an export API with no authentication of its own, trusted-host deployments should disable `dsh-agy-web` in the profile's final `cordis.patch.yml` (see `INSTALL.md`) and keep only the host adapter and CLI. The profile uses a pnpm patch with a lockfile hash: with no Google session, `listModels()` returns empty; after authentication the provider group name is `Google Antigravity (OAuth)`.
122
+
123
+ ## 6. Compatibility
124
+
125
+ The canonical package and repository name is **`dsh-coding-subscription-oauth`**. The previous GitHub URL still resolves to the same `main`, so old `dsh plugin add github:lninghaha/dsh-grok-build` commands continue to install the renamed package. The first public npm/GitHub Release was **`0.4.1`**. The current release is **`0.6.0`** (`dsh plugin --profile web add dsh-coding-subscription-oauth@0.6.0`). GitHub and local tarball installs remain valid.
126
+
127
+ Stable on-disk / in-process identifiers (do not rename without a migration):
128
+
129
+ - Cordis id: `llm-grok-build-oauth`
130
+ - Settings HTTP API: `/plugins/dsh-grok-build/oauth/*`, `/plugins/dsh-grok-build/capabilities`, `/plugins/dsh-grok-build/codex/usage`, `/plugins/dsh-grok-build/imagine/*`, and legacy `/plugins/dsh-grok-build/auth/*`
131
+ - Credential files: `$DSH_HOME/.grok-build-auth.json` and the other `*-oauth-auth.json` files
132
+ - Imagine credential: DSH credentials reference `XAI_API_KEY` (never Grok OAuth, never process-env fallback)
133
+ - CLI: `dsh-coding-oauth` (primary) and `dsh-grok-build` (alias)
134
+ - LLM routes: `grok-build`, `codex-oauth`, `kimi-code-oauth`, `claude-code-oauth`; optional `codex-oauth-fast` (v0.4.0, advertised only when a fresh live catalog lists `priority`)
135
+
133
136
  New routes use the `*-oauth` alias and do not occupy `openai`, `xai` or `kimi-coding`. In v0.3.0 the `grok-build` fallback/default advances to `grok-4.6`; saved user defaults still win.
137
+
138
+ Hub and this standalone participant pin the same `dsh-coding-oauth-core@0.1.0`. The core owns root-scoped owner election, reference-counted proxy policy, atomic registration helpers, provider/route/credential identifiers, the capability namespace, Gateway state filename, and all legacy/current management paths. Hub has priority while installed; this participant remains standby and resumes without renaming routes or resetting credentials after Hub unloads.
@@ -1,133 +1,138 @@
1
- # 02 · 架构设计
2
-
3
- > 中文版 · [**English**](02-architecture.md)
4
-
5
- 本文描述 `dsh-coding-subscription-oauth` 的内部架构,是 `README.md` 技术说明的来源,面向贡献者与维护者。
6
-
7
- ## 1. 路由与原生 provider
8
-
9
- ```text
10
- Harness route pi-ai provider 请求认证
11
- ────────────────────────────────────────────────────────────
12
- grok-build grok-build xAI access token + Grok CLI headers
13
- codex-oauth openai-codex OAuth token → apiKey override
14
- kimi-code-oauth kimi-coding OAuth token → Authorization: Bearer
15
- claude-code-oauth anthropic sk-ant-oat token → Claude Code headers
16
- agy dsh-agy external dsh-agy 自有账号池
17
- ```
18
-
19
- 外部 route 和 pi-ai 原生 id 由 `AliasLlmAdapter` 分隔。`PiAiAdapter` 始终看到原生 provider id,因此 Codex 工具调用、Claude compatibility 判断和 Kimi Anthropic transport 不因 route 改名而失效。
20
-
21
- 模型发现里的“已认证”定义为存在可读、结构有效且可刷新的 OAuth credential;不会在每次打开选择器时向上游做在线探测。已被上游撤销但本地仍有效的 credential 会在 token refresh 或推理时被识别,避免目录加载产生额外网络请求。
22
-
23
- ## 2. 主机数据流
24
-
25
- ```text
26
- Settings / CLI
27
-
28
- ├─ GrokBuildWebAuth ── Grok custom PKCE/device
29
- │ └─ .grok-build-auth.json
30
-
31
- ├─ SubscriptionWebAuth ── pi-ai OAuth login/refresh
32
- │ ├─ Codex ── .codex-oauth-auth.json
33
- │ ├─ Kimi ── .kimi-code-oauth-auth.json
34
- │ └─ Claude ── .claude-code-oauth-auth.json
35
-
36
- └─ OAuthImportSession ── 白名单 CLI 只读发现
37
- └─ 显式单向拉取(预览票据 → 目标 store)
38
- 从不写入官方 CLI 文件
39
-
40
- OAuthProviderSession.resolveAccessToken()
41
- └─ Models.getAuth(native id) # refresh-under-lock
42
- └─ OAuthCredentialFileStore # 0600 + atomic write + cross-process lock
43
-
44
- CapabilitySettingsController(默认关闭,applies: live)
45
- └─ CapabilityRuntimeState
46
- ├─ Codex 搜索 / 用量 / gpt-image-2 图像
47
- ├─ codex-oauth-fast(仅在最新 priority catalog 之后)
48
- └─ Grok Imagine(api.x.ai + DSH 凭据 XAI_API_KEY)
49
-
50
- ctx.llm route
51
- └─ AliasLlmAdapter
52
- └─ PiAiAdapter
53
- └─ native pi-ai Provider.streamSimple()
54
- ```
55
-
56
- ## 3. 模块职责
57
-
58
- - `store.ts`:一个文件只拥有一个 provider credential;保留旧 Grok store API;`invalidate()` 在上游 AUTH 拒绝后把 `expires` 回写到过去。
59
- - `oauth-providers.ts`:Codex/Kimi/Claude 定义、route metadata、请求 token bridge。
60
- - `oauth-session.ts`:登录、刷新、静态模型目录和模型选择缓存。
61
- - `oauth-sources.ts`:白名单官方 Grok/Codex/Kimi/Claude CLI 发现;加固的 lstat/`O_NOFOLLOW`/属主/权限/普通文件/大小读取;一次性预览票据(五分钟、最多 32 张);从不写入官方 CLI 文件。
62
- - `oauth-import-routes.ts`:同源拉取 HTTP API(发现 → 预览 → 提交/取消),写入发生在目标 store 锁内。
63
- - `alias-adapter.ts`:转换 Harness route、不修改 pi-ai model.provider,并在 `listModels()` 前执行 credential gate;未认证或凭据读取失败返回空目录,provider group 名使用 `(OAuth)`。AUTH finish 时作废本地令牌,让 harness 重试先刷新。finish 管道还会重映射 Kimi 误标 AUTH 的上下文溢出,以及 xAI capacity 文案 → `RATE_LIMIT`。
64
- - `grok-errors.ts`:识别 xAI「at capacity / high demand / priority processing / overloaded」并改为 `RATE_LIMIT`,避免 `PI_AI_ERROR` 跳过退避。
65
- - `adapter.ts`:组合 Grok 与三个 subscription profile;向 pi-ai 要求至少 60 秒剩余有效期,并注册包含 AUTH 与瞬时故障码的 retryPolicy(默认 5 次,5 s → 80 s 指数叠加)。可选包装 `codex-oauth-fast`,显示为 **已请求 Fast**。
66
- - `auth-routes.ts`:旧 Grok API + 新统一 `/plugins/dsh-grok-build/oauth/*`;JSON 写请求使用 64 KiB 有界读取器,无效/超限 body 分别返回 400/413。
67
- - `capability-settings.ts`:默认关闭、立即生效的开关与限制(搜索 1–20、图像 1–4、产物 TTL 1 小时–7 天)。
68
- - `capability-routes.ts`:无密钥的能力快照,以及可选的 Codex 用量和 Imagine 凭据状态路由。
69
- - `capability-runtime.ts`:按 live 开关绑定/解绑搜索、工具,以及仅在最新 priority catalog 后发布 Fast 路由。
70
- - `capability-tools.ts`:可选 Codex / Grok Imagine 工具定义;执行时重新读取开关。
71
- - `codex-http.ts`:需打开的私有 `chatgpt.com/backend-api` 客户端(仅 HTTPS、仅第一方主机)。
72
- - `codex-search.ts` / `codex-usage.ts` / `codex-images.ts`:可选搜索、配额,以及固定 `gpt-image-2` 生成/编辑(编辑要求当前会话顶层附件所有权)。
73
- - `codex-model-capabilities.ts`:live Codex service-tier 缓存;Fast 资格失败关闭;注入 `service_tier: priority` 与路由提示。
74
- - `grok-imagine.ts`:官方 `api.x.ai` Imagine 客户端(`grok-imagine-image-2.0` / `grok-imagine-video-1.5`);`XAI_API_KEY` 只通过 DSH 凭据;MIME/大小/超时/重定向/DNS 下载控制;冻结主机 `imgen.x.ai`、`videogen.x.ai`、`vidgen.x.ai`。
75
- - `imagine-routes.ts`:生成图像与视频产物的同源 loopback GET 路由。
76
- - `media-store.ts`:属主私有产物库(单件与唯一对象总量均硬限 256 MiB,最长七天)。
77
- - `client/`:四个原生账号卡片、CLI 拉取、能力开关、网关控制,以及外部 Antigravity 状态卡片。
78
- - `proxy.ts`:process-wide undici dispatcher,但只代理审核过的域名白名单。
1
+ # 02 · 架构设计
2
+
3
+ > 中文版 · [**English**](02-architecture.md)
4
+
5
+ 本文描述 `dsh-coding-subscription-oauth` 的内部架构,是 `README.md` 技术说明的来源,面向贡献者与维护者。
6
+
7
+ ## 1. 路由与原生 provider
8
+
9
+ ```text
10
+ Harness route pi-ai provider 请求认证
11
+ ────────────────────────────────────────────────────────────
12
+ grok-build grok-build xAI access token + Grok CLI headers
13
+ codex-oauth openai-codex OAuth token → apiKey override
14
+ kimi-code-oauth kimi-coding OAuth token → Authorization: Bearer
15
+ claude-code-oauth anthropic sk-ant-oat token → Claude Code headers
16
+ agy dsh-agy external dsh-agy 自有账号池
17
+ ```
18
+
19
+ 外部 route 和 pi-ai 原生 id 由 `AliasLlmAdapter` 分隔。`PiAiAdapter` 始终看到原生 provider id,因此 Codex 工具调用、Claude compatibility 判断和 Kimi Anthropic transport 不因 route 改名而失效。
20
+
21
+ 模型发现里的“已认证”定义为存在可读、结构有效且可刷新的 OAuth credential;不会在每次打开选择器时向上游做在线探测。已被上游撤销但本地仍有效的 credential 会在 token refresh 或推理时被识别,避免目录加载产生额外网络请求。
22
+
23
+ ## 2. 主机数据流
24
+
25
+ ```text
26
+ Settings / CLI
27
+
28
+ ├─ GrokBuildWebAuth ── Grok custom PKCE/device
29
+ │ └─ .grok-build-auth.json
30
+
31
+ ├─ SubscriptionWebAuth ── pi-ai OAuth login/refresh
32
+ │ ├─ Codex ── .codex-oauth-auth.json
33
+ │ ├─ Kimi ── .kimi-code-oauth-auth.json
34
+ │ └─ Claude ── .claude-code-oauth-auth.json
35
+
36
+ └─ OAuthImportSession ── 白名单 CLI 只读发现
37
+ └─ 显式单向拉取(预览票据 → 目标 store)
38
+ 从不写入官方 CLI 文件
39
+
40
+ OAuthProviderSession.resolveAccessToken()
41
+ └─ Models.getAuth(native id) # refresh-under-lock
42
+ └─ OAuthCredentialFileStore # 0600 + atomic write + cross-process lock
43
+
44
+ CapabilitySettingsController(默认关闭,applies: live)
45
+ └─ CapabilityRuntimeState
46
+ ├─ Codex 搜索 / 用量 / gpt-image-2 图像
47
+ ├─ codex-oauth-fast(仅在最新 priority catalog 之后)
48
+ └─ Grok Imagine(api.x.ai + DSH 凭据 XAI_API_KEY)
49
+
50
+ ctx.llm route
51
+ └─ AliasLlmAdapter
52
+ └─ PiAiAdapter
53
+ └─ native pi-ai Provider.streamSimple()
54
+ ```
55
+
56
+ ## 3. 模块职责
57
+
58
+ - `store.ts`:一个文件只拥有一个 provider credential;保留旧 Grok store API;`invalidate()` 在上游 AUTH 拒绝后把 `expires` 回写到过去。
59
+ - `oauth-providers.ts`:Codex/Kimi/Claude 定义、route metadata、请求 token bridge。
60
+ - `oauth-session.ts`:登录、刷新、静态模型目录和模型选择缓存。
61
+ - `oauth-sources.ts`:白名单官方 Grok/Codex/Kimi/Claude CLI 发现;加固的 lstat/`O_NOFOLLOW`/属主/权限/普通文件/大小读取;一次性预览票据(五分钟、最多 32 张);从不写入官方 CLI 文件。
62
+ - `oauth-import-routes.ts`:同源拉取 HTTP API(发现 → 预览 → 提交/取消),写入发生在目标 store 锁内。
63
+ - `alias-adapter.ts`:转换 Harness route、不修改 pi-ai model.provider,并在 `listModels()` 前执行 credential gate;未认证或凭据读取失败返回空目录,provider group 名使用 `(OAuth)`。AUTH finish 时作废本地令牌,让 harness 重试先刷新。finish 管道还会重映射 Kimi 误标 AUTH 的上下文溢出,以及 xAI capacity 文案 → `RATE_LIMIT`。
64
+ - `grok-errors.ts`:识别 xAI「at capacity / high demand / priority processing / overloaded」并改为 `RATE_LIMIT`,避免 `PI_AI_ERROR` 跳过退避。
65
+ - `adapter.ts`:组合 Grok 与三个 subscription profile;向 pi-ai 要求至少 60 秒剩余有效期,并注册包含 AUTH 与瞬时故障码的 retryPolicy(默认 5 次,5 s → 80 s 指数叠加)。可选包装 `codex-oauth-fast`,显示为 **已请求 Fast**。
66
+ - `auth-routes.ts`:旧 Grok API + 新统一 `/plugins/dsh-grok-build/oauth/*`;JSON 写请求使用 64 KiB 有界读取器,无效/超限 body 分别返回 400/413。
67
+ - `capability-settings.ts`:默认关闭、立即生效的开关与限制(搜索 1–20、图像 1–4、产物 TTL 1 小时–7 天)。
68
+ - `capability-routes.ts`:无密钥的能力快照,以及可选的 Codex 用量和 Imagine 凭据状态路由。
69
+ - `capability-runtime.ts`:按 live 开关绑定/解绑搜索、工具,以及仅在最新 priority catalog 后发布 Fast 路由。
70
+ - `capability-tools.ts`:可选 Codex / Grok Imagine 工具定义;执行时重新读取开关。
71
+ - `codex-http.ts`:需打开的私有 `chatgpt.com/backend-api` 客户端(仅 HTTPS、仅第一方主机)。
72
+ - `codex-search.ts` / `codex-usage.ts` / `codex-images.ts`:可选搜索、配额,以及固定 `gpt-image-2` 生成/编辑(编辑要求当前会话顶层附件所有权)。
73
+ - `codex-model-capabilities.ts`:live Codex service-tier 缓存;Fast 资格失败关闭;注入 `service_tier: priority` 与路由提示。
74
+ - `grok-imagine.ts`:官方 `api.x.ai` Imagine 客户端(`grok-imagine-image-2.0` / `grok-imagine-video-1.5`);`XAI_API_KEY` 只通过 DSH 凭据;MIME/大小/超时/重定向/DNS 下载控制;冻结主机 `imgen.x.ai`、`videogen.x.ai`、`vidgen.x.ai`。
75
+ - `imagine-routes.ts`:生成图像与视频产物的同源 loopback GET 路由。
76
+ - `media-store.ts`:属主私有产物库(单件与唯一对象总量均硬限 256 MiB,最长七天)。
77
+ - `client/`:四个原生账号卡片、CLI 拉取、能力开关、网关控制,以及外部 Antigravity 状态卡片。
78
+ - `proxy.ts`:process-wide undici dispatcher,但只代理审核过的域名白名单。
79
79
  - `gateway*.ts`:可选的隔离 loopback OpenAI/Anthropic 兼容 HTTP 服务(默认关;独立于 DSH web 端口)。
80
-
81
- ## 4. Web API
82
-
83
- 统一接口:
84
-
85
- ```text
86
- GET /plugins/dsh-grok-build/oauth/status
87
- POST /plugins/dsh-grok-build/oauth/login
88
- POST /plugins/dsh-grok-build/oauth/code
89
- POST /plugins/dsh-grok-build/oauth/cancel
90
- POST /plugins/dsh-grok-build/oauth/logout
91
- POST /plugins/dsh-grok-build/oauth/models
92
-
93
- GET /plugins/dsh-grok-build/oauth/sources
94
- POST /plugins/dsh-grok-build/oauth/sources/preview
95
- POST /plugins/dsh-grok-build/oauth/sources/commit
96
- POST /plugins/dsh-grok-build/oauth/sources/cancel
97
-
98
- GET /plugins/dsh-grok-build/capabilities
99
- PATCH /plugins/dsh-grok-build/capabilities
100
- PUT /plugins/dsh-grok-build/capabilities
101
- GET /plugins/dsh-grok-build/codex/usage
102
- GET /plugins/dsh-grok-build/imagine/credential-status
103
- GET /plugins/dsh-grok-build/imagine/images/<id>
104
- GET /plugins/dsh-grok-build/imagine/media/<id>
105
- GET /plugins/dsh-grok-build/gateway
106
- PATCH /plugins/dsh-grok-build/gateway
107
- POST /plugins/dsh-grok-build/gateway/rotate
108
- ```
109
-
80
+ - `dsh-host-adapter.ts` / `web-origin.ts`:隔离可变 DSH 服务,并优先使用宿主 `ownerRequestPolicy`;fallback 对 loopback/SSH 做 Host/Origin 约束,对 HTTPS 反代同时核验真实 peer、精确 Origin/Host、Fetch Metadata、owner proof 与独立 CSRF。宿主策略抛错或返回畸形结果时安全拒绝,不让异常越过路由边界。
81
+
82
+ ## 4. Web API
83
+
84
+ 统一接口:
85
+
86
+ ```text
87
+ GET /plugins/dsh-grok-build/oauth/status
88
+ POST /plugins/dsh-grok-build/oauth/login
89
+ POST /plugins/dsh-grok-build/oauth/code
90
+ POST /plugins/dsh-grok-build/oauth/cancel
91
+ POST /plugins/dsh-grok-build/oauth/logout
92
+ POST /plugins/dsh-grok-build/oauth/models
93
+
94
+ GET /plugins/dsh-grok-build/oauth/sources
95
+ POST /plugins/dsh-grok-build/oauth/sources/preview
96
+ POST /plugins/dsh-grok-build/oauth/sources/commit
97
+ POST /plugins/dsh-grok-build/oauth/sources/cancel
98
+
99
+ GET /plugins/dsh-grok-build/capabilities
100
+ PATCH /plugins/dsh-grok-build/capabilities
101
+ PUT /plugins/dsh-grok-build/capabilities
102
+ GET /plugins/dsh-grok-build/codex/usage
103
+ GET /plugins/dsh-grok-build/imagine/credential-status
104
+ GET /plugins/dsh-grok-build/imagine/images/<id>
105
+ GET /plugins/dsh-grok-build/imagine/media/<id>
106
+ GET /plugins/dsh-grok-build/gateway
107
+ PATCH /plugins/dsh-grok-build/gateway
108
+ POST /plugins/dsh-grok-build/gateway/rotate
109
+ ```
110
+
110
111
  写接口请求体带 `provider: grok|codex|kimi|claude`。响应只包含状态、授权 URL、device user code、模型 id 和非敏感 expiry;绝不包含 access/refresh token。JSON 请求体在解析前限制为 64 KiB。
111
112
 
112
- `/oauth/sources` 是只读发现。预览/提交是显式单向拉取(票据一次性、五分钟、最多 32 张)。能力写入位于 `coding-subscription-oauth` 设置区,是无密钥的 compare-and-swap 快照并立即生效。七项开关默认关闭;`searchResults` 1–20(默认 5),`imageCount` 为 1–4(默认 1),`videoArtifactTtlMs` 为 1 小时–7 天(默认 7 天;界面显示 1–168 小时);降低时立即改写/清理已有 expiry,提高只影响新产物。Imagine 下载路由是同源 loopback GET,从不返回上游签名 URL。
113
-
114
- `/plugins/dsh-grok-build/auth/*` 继续注册并复用同一个 Grok 控制器。
115
-
116
- ## 5. Antigravity
117
-
118
- 本项目不复制 Google Antigravity 私有协议。profile 单独安装 `dsh-agy@0.1.2`,提供 `agy` route。由于该版本的 `/agy` dashboard 含无自身认证的 export API,trusted-host 部署应在 profile 最终 `cordis.patch.yml` 中禁用 `dsh-agy-web`(见 `INSTALL.md`),只保留 host adapter 和 CLI。profile 使用带 lockfile hash 的 pnpm patch:无 Google session 时 `listModels()` 返回空,认证后 provider group 名为 `Google Antigravity (OAuth)`。
119
-
120
- ## 6. 兼容性
121
-
122
- 正式包名与仓库名是 **`dsh-coding-subscription-oauth`**。旧 GitHub 地址仍指向同一条 `main`,因此旧的 `dsh plugin add github:lninghaha/dsh-grok-build` 仍会安装更名后的包。第一次公开 npm / GitHub Release 是 **`0.4.1`**。当前版本是 **`0.5.7`**(`dsh plugin --profile web add dsh-coding-subscription-oauth@0.5.7`)。GitHub 与本地 tarball 安装仍然有效。
123
-
124
- 以下标识保持稳定(无迁移方案前不要改名):
125
-
126
- - Cordis id:`llm-grok-build-oauth`
127
- - 设置页 HTTP API:`/plugins/dsh-grok-build/oauth/*`、`/plugins/dsh-grok-build/capabilities`、`/plugins/dsh-grok-build/codex/usage`、`/plugins/dsh-grok-build/imagine/*`,以及旧的 `/plugins/dsh-grok-build/auth/*`
128
- - 凭据文件:`$DSH_HOME/.grok-build-auth.json` 及其他 `*-oauth-auth.json`
129
- - Imagine 凭据:DSH 凭据引用 `XAI_API_KEY`(不用 Grok OAuth,不回退进程环境变量)
130
- - CLI:`dsh-coding-oauth`(主命令)与 `dsh-grok-build`(别名)
131
- - LLM 路由:`grok-build`、`codex-oauth`、`kimi-code-oauth`、`claude-code-oauth`;可选 `codex-oauth-fast`(v0.4.0,仅在最新 live catalog 列出 `priority` 后发布)
132
-
113
+ 所有 Settings 路由共用 `OwnerRequestPolicy`。`X-Forwarded-*` 只属于转发元数据,不能成为属主证明;fallback 配置缺少任一独立信号时拒绝远程请求。状态响应携带经服务端判定的 `accessMode`,客户端不根据 hostname 猜测 SSH 或反代环境。
114
+
115
+ `/oauth/sources` 是只读发现。预览/提交是显式单向拉取(票据一次性、五分钟、最多 32 张)。能力写入位于 `coding-subscription-oauth` 设置区,是无密钥的 compare-and-swap 快照并立即生效。七项开关默认关闭;`searchResults` 为 1–20(默认 5),`imageCount` 为 1–4(默认 1),`videoArtifactTtlMs` 为 1 小时–7 天(默认 7 天;界面显示 1–168 小时);降低时立即改写/清理已有 expiry,提高只影响新产物。Imagine 下载路由是同源 loopback GET,从不返回上游签名 URL。
116
+
117
+ `/plugins/dsh-grok-build/auth/*` 继续注册并复用同一个 Grok 控制器。
118
+
119
+ ## 5. Antigravity
120
+
121
+ 本项目不复制 Google Antigravity 私有协议。profile 单独安装 `dsh-agy@0.1.2`,提供 `agy` route。由于该版本的 `/agy` dashboard 含无自身认证的 export API,trusted-host 部署应在 profile 最终 `cordis.patch.yml` 中禁用 `dsh-agy-web`(见 `INSTALL.md`),只保留 host adapter 和 CLI。profile 使用带 lockfile hash 的 pnpm patch:无 Google session 时 `listModels()` 返回空,认证后 provider group 名为 `Google Antigravity (OAuth)`。
122
+
123
+ ## 6. 兼容性
124
+
125
+ 正式包名与仓库名是 **`dsh-coding-subscription-oauth`**。旧 GitHub 地址仍指向同一条 `main`,因此旧的 `dsh plugin add github:lninghaha/dsh-grok-build` 仍会安装更名后的包。第一次公开 npm / GitHub Release 是 **`0.4.1`**。当前版本是 **`0.6.0`**(`dsh plugin --profile web add dsh-coding-subscription-oauth@0.6.0`)。GitHub 与本地 tarball 安装仍然有效。
126
+
127
+ 以下标识保持稳定(无迁移方案前不要改名):
128
+
129
+ - Cordis id:`llm-grok-build-oauth`
130
+ - 设置页 HTTP API:`/plugins/dsh-grok-build/oauth/*`、`/plugins/dsh-grok-build/capabilities`、`/plugins/dsh-grok-build/codex/usage`、`/plugins/dsh-grok-build/imagine/*`,以及旧的 `/plugins/dsh-grok-build/auth/*`
131
+ - 凭据文件:`$DSH_HOME/.grok-build-auth.json` 及其他 `*-oauth-auth.json`
132
+ - Imagine 凭据:DSH 凭据引用 `XAI_API_KEY`(不用 Grok OAuth,不回退进程环境变量)
133
+ - CLI:`dsh-coding-oauth`(主命令)与 `dsh-grok-build`(别名)
134
+ - LLM 路由:`grok-build`、`codex-oauth`、`kimi-code-oauth`、`claude-code-oauth`;可选 `codex-oauth-fast`(v0.4.0,仅在最新 live catalog 列出 `priority` 后发布)
135
+
133
136
  新 route 使用 `*-oauth` alias,不占用 `openai`、`xai`、`kimi-coding`。v0.3.0 将 `grok-build` fallback/default 更新为 `grok-4.6`,已有用户默认设置仍优先。
137
+
138
+ Hub 与本独立 participant 精确依赖同一个 `dsh-coding-oauth-core@0.1.0`。核心统一管理 root-scoped owner 选举、引用计数代理策略、原子注册、provider/route/credential 标识、能力设置命名空间、Gateway 状态文件名,以及全部新旧管理路径。Hub 安装时优先成为 owner;Hub 卸载后本插件从 standby 自动接管,不改路由名,也不重置凭据。
@@ -1,23 +1,13 @@
1
1
  /** Same-origin Web settings routes for Grok Build OAuth. */
2
2
  import type { Context } from "@deepseek-ai/cordis";
3
3
  import type { CatalogSource } from "./catalog.js";
4
+ import type { DshCompatibility } from "./compatibility.js";
4
5
  import { ANTIGRAVITY_ROUTE, type CodingOAuthProviderSlug } from "./ids.js";
5
6
  import type { SubscriptionLoginMethod } from "./oauth-providers.js";
6
7
  import type { OAuthProviderSession } from "./oauth-session.js";
7
8
  import type { GrokBuildSession } from "./session.js";
8
- export declare const GROK_BUILD_AUTH_STATUS_PATH = "/plugins/dsh-grok-build/auth/status";
9
- export declare const GROK_BUILD_AUTH_LOGIN_PATH = "/plugins/dsh-grok-build/auth/login";
10
- export declare const GROK_BUILD_AUTH_LOGIN_CODE_PATH = "/plugins/dsh-grok-build/auth/login/code";
11
- export declare const GROK_BUILD_AUTH_LOGIN_CANCEL_PATH = "/plugins/dsh-grok-build/auth/login/cancel";
12
- export declare const GROK_BUILD_AUTH_IMPORT_PATH = "/plugins/dsh-grok-build/auth/import";
13
- export declare const GROK_BUILD_AUTH_LOGOUT_PATH = "/plugins/dsh-grok-build/auth/logout";
14
- export declare const GROK_BUILD_AUTH_MODELS_PATH = "/plugins/dsh-grok-build/auth/models";
15
- export declare const CODING_OAUTH_STATUS_PATH = "/plugins/dsh-grok-build/oauth/status";
16
- export declare const CODING_OAUTH_LOGIN_PATH = "/plugins/dsh-grok-build/oauth/login";
17
- export declare const CODING_OAUTH_LOGIN_CODE_PATH = "/plugins/dsh-grok-build/oauth/code";
18
- export declare const CODING_OAUTH_LOGIN_CANCEL_PATH = "/plugins/dsh-grok-build/oauth/cancel";
19
- export declare const CODING_OAUTH_LOGOUT_PATH = "/plugins/dsh-grok-build/oauth/logout";
20
- export declare const CODING_OAUTH_MODELS_PATH = "/plugins/dsh-grok-build/oauth/models";
9
+ import { type OwnerAccessMode, type OwnerRequestPolicy } from "./web-origin.js";
10
+ export { CODING_OAUTH_LOGIN_CANCEL_PATH, CODING_OAUTH_LOGIN_CODE_PATH, CODING_OAUTH_LOGIN_PATH, CODING_OAUTH_LOGOUT_PATH, CODING_OAUTH_MODELS_PATH, CODING_OAUTH_STATUS_PATH, GROK_BUILD_AUTH_IMPORT_PATH, GROK_BUILD_AUTH_LOGIN_CANCEL_PATH, GROK_BUILD_AUTH_LOGIN_CODE_PATH, GROK_BUILD_AUTH_LOGIN_PATH, GROK_BUILD_AUTH_LOGOUT_PATH, GROK_BUILD_AUTH_MODELS_PATH, GROK_BUILD_AUTH_STATUS_PATH, } from "./ids.js";
21
11
  export type GrokBuildLoginMethod = "pkce" | "device";
22
12
  export type GrokBuildWebAuthStatus = {
23
13
  status: "signed-out";
@@ -136,8 +126,11 @@ export declare class SubscriptionWebAuth {
136
126
  private rejectChallenge;
137
127
  }
138
128
  /** Register the plugin-owned OAuth routes when the Web server is composed. */
139
- export declare function registerGrokBuildAuthRoutes(ctx: Context, session: GrokBuildSession, existingAuth?: GrokBuildWebAuth): void;
129
+ export declare function registerGrokBuildAuthRoutes(ctx: Context, session: GrokBuildSession, existingAuth?: GrokBuildWebAuth, ownerRequestPolicy?: OwnerRequestPolicy): void;
140
130
  export interface CodingOAuthWebStatus {
131
+ accessMode: OwnerAccessMode;
132
+ uiOwner: "standalone" | "hub";
133
+ compatibility: DshCompatibility;
141
134
  providers: {
142
135
  grok: GrokBuildWebAuthStatus;
143
136
  codex: SubscriptionWebAuthStatus;
@@ -151,5 +144,5 @@ export interface CodingOAuthWebStatus {
151
144
  };
152
145
  }
153
146
  /** Register the unified Coding OAuth API plus the compatibility Grok routes. */
154
- export declare function registerCodingOAuthRoutes(ctx: Context, grokSession: GrokBuildSession, subscriptionSessions: readonly OAuthProviderSession[]): void;
147
+ export declare function registerCodingOAuthRoutes(ctx: Context, grokSession: GrokBuildSession, subscriptionSessions: readonly OAuthProviderSession[], ownerRequestPolicy?: OwnerRequestPolicy, compatibility?: (accessMode: OwnerAccessMode) => DshCompatibility): void;
155
148
  //# sourceMappingURL=auth-routes.d.ts.map