dsh-coding-subscription-oauth 0.5.8 → 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 -196
  2. package/CONTRIBUTING.md +120 -120
  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 -170
  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 -30
  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 -409
  86. package/src/client/components/NoticeBanner.tsx +46 -46
  87. package/src/client/components/ProgressBar.tsx +53 -53
  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 -491
  97. package/src/client/microStyles.ts +52 -33
  98. package/src/client/parsers.ts +396 -386
  99. package/src/client/styles.ts +325 -307
  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,152 +1,158 @@
1
- /**
2
- * Settings-facing routes for the opt-in local API gateway.
3
- * @module dsh-coding-subscription-oauth/gateway-routes
4
- */
5
-
6
- import type { IncomingMessage, ServerResponse } from "node:http";
7
- import type { CodingOAuthGatewayController } from "./gateway.ts";
8
- import { assertGatewayPort } from "./gateway-config.ts";
9
- import { readJsonRequest, requestErrorStatus } from "./http-json.ts";
10
- import { safeMessage } from "./redact.ts";
11
- import { isTrustedLoopbackWebRequest } from "./web-origin.ts";
12
- import { registerWebRouteSetupAtomically } from "./web-routes.ts";
13
-
14
- export const GATEWAY_SETTINGS_PATH = "/plugins/dsh-grok-build/gateway";
15
- export const GATEWAY_REVEAL_PATH = "/plugins/dsh-grok-build/gateway/reveal";
16
- export const GATEWAY_ROTATE_PATH = "/plugins/dsh-grok-build/gateway/rotate";
17
-
18
- export interface GatewayRouteContext {
19
- readonly webServer: {
20
- register(route: {
21
- kind: "exact" | "prefix";
22
- path: string;
23
- handler: (req: IncomingMessage, res: ServerResponse) => void | Promise<void>;
24
- }): () => void;
25
- };
26
- effect(callback: () => () => void | Promise<void>, label?: string): unknown;
27
- }
28
-
29
- export function registerGatewayRoutes(ctx: GatewayRouteContext, controller: CodingOAuthGatewayController): () => void {
30
- let dispose = (): void => undefined;
31
- ctx.effect(() => {
32
- dispose = registerWebRouteSetupAtomically(ctx.webServer, (webServer) => {
33
- webServer.register({
34
- kind: "exact",
35
- path: GATEWAY_SETTINGS_PATH,
36
- handler: (req, res) => handleGatewaySettings(req, res, controller),
37
- });
38
- webServer.register({
39
- kind: "exact",
40
- path: GATEWAY_REVEAL_PATH,
41
- handler: (req, res) => handleGatewayReveal(req, res, controller),
42
- });
43
- webServer.register({
44
- kind: "exact",
45
- path: GATEWAY_ROTATE_PATH,
46
- handler: (req, res) => handleGatewayRotate(req, res, controller),
47
- });
48
- });
49
- return dispose;
50
- }, "dsh-coding-subscription-oauth: gateway settings routes");
51
- return () => dispose();
52
- }
53
-
54
- async function handleGatewaySettings(
55
- req: IncomingMessage,
56
- res: ServerResponse,
57
- controller: CodingOAuthGatewayController,
58
- ): Promise<void> {
59
- if (!isTrustedLoopbackWebRequest(req)) {
60
- json(res, 403, { error: "forbidden" });
61
- return;
62
- }
63
- try {
64
- if (req.method === "GET") {
65
- json(res, 200, await controller.status());
66
- return;
67
- }
68
- if (req.method === "PATCH") {
69
- const raw = await readJsonRequest(req);
70
- const payload = typeof raw === "object" && raw !== null ? (raw as { enabled?: unknown; port?: unknown }) : {};
71
- const enabled = payload.enabled;
72
- const port = payload.port;
73
- if (enabled === undefined && port === undefined) {
74
- json(res, 400, { error: "enabled or port is required" });
75
- return;
76
- }
77
- if (enabled !== undefined && typeof enabled !== "boolean") {
78
- json(res, 400, { error: "enabled must be a boolean" });
79
- return;
80
- }
81
- if (port !== undefined) {
82
- if (typeof port !== "number" || !Number.isSafeInteger(port)) {
83
- json(res, 400, { error: "port must be an integer" });
84
- return;
85
- }
86
- try {
87
- assertGatewayPort(port);
88
- } catch (error) {
89
- json(res, 400, { error: safeMessage(error) });
90
- return;
91
- }
92
- await controller.setPort(port);
93
- }
94
- const status = typeof enabled === "boolean" ? await controller.setEnabled(enabled) : await controller.status();
95
- json(res, 200, status);
96
- return;
97
- }
98
- json(res, 405, { error: "method not allowed" });
99
- } catch (error) {
100
- json(res, requestErrorStatus(error, 500), { error: safeMessage(error) });
101
- }
102
- }
103
-
104
- async function handleGatewayReveal(
105
- req: IncomingMessage,
106
- res: ServerResponse,
107
- controller: CodingOAuthGatewayController,
108
- ): Promise<void> {
109
- if (!isTrustedLoopbackWebRequest(req)) {
110
- json(res, 403, { error: "forbidden" });
111
- return;
112
- }
113
- if (req.method !== "POST") {
114
- json(res, 405, { error: "method not allowed" });
115
- return;
116
- }
117
- try {
118
- json(res, 200, await controller.revealKey());
119
- } catch (error) {
120
- json(res, requestErrorStatus(error, 500), { error: safeMessage(error) });
121
- }
122
- }
123
-
124
- async function handleGatewayRotate(
125
- req: IncomingMessage,
126
- res: ServerResponse,
127
- controller: CodingOAuthGatewayController,
128
- ): Promise<void> {
129
- if (!isTrustedLoopbackWebRequest(req)) {
130
- json(res, 403, { error: "forbidden" });
131
- return;
132
- }
133
- if (req.method !== "POST") {
134
- json(res, 405, { error: "method not allowed" });
135
- return;
136
- }
137
- try {
138
- json(res, 200, await controller.rotateKey());
139
- } catch (error) {
140
- json(res, requestErrorStatus(error, 500), { error: safeMessage(error) });
141
- }
142
- }
143
-
144
- function json(res: ServerResponse, status: number, value: unknown): void {
145
- const body = Buffer.from(`${JSON.stringify(value)}\n`);
146
- res.writeHead(status, {
147
- "content-type": "application/json; charset=utf-8",
148
- "content-length": body.byteLength,
149
- "cache-control": "no-store",
150
- });
151
- res.end(body);
152
- }
1
+ /**
2
+ * Settings-facing routes for the opt-in local API gateway.
3
+ * @module dsh-coding-subscription-oauth/gateway-routes
4
+ */
5
+
6
+ import type { IncomingMessage, ServerResponse } from "node:http";
7
+ import type { CodingOAuthGatewayController } from "./gateway.ts";
8
+ import { assertGatewayPort } from "./gateway-config.ts";
9
+ import { readJsonRequest, requestErrorStatus } from "./http-json.ts";
10
+ import { GATEWAY_REVEAL_PATH, GATEWAY_ROTATE_PATH, GATEWAY_SETTINGS_PATH } from "./ids.ts";
11
+ import { safeMessage } from "./redact.ts";
12
+ import { LOOPBACK_OWNER_REQUEST_POLICY, type OwnerRequestPolicy } from "./web-origin.ts";
13
+ import { registerWebRouteSetupAtomically } from "./web-routes.ts";
14
+
15
+ export { GATEWAY_REVEAL_PATH, GATEWAY_ROTATE_PATH, GATEWAY_SETTINGS_PATH } from "./ids.ts";
16
+
17
+ export interface GatewayRouteContext {
18
+ readonly webServer: {
19
+ register(route: {
20
+ kind: "exact" | "prefix";
21
+ path: string;
22
+ handler: (req: IncomingMessage, res: ServerResponse) => void | Promise<void>;
23
+ }): () => void;
24
+ };
25
+ effect(callback: () => () => void | Promise<void>, label?: string): unknown;
26
+ }
27
+
28
+ export function registerGatewayRoutes(
29
+ ctx: GatewayRouteContext,
30
+ controller: CodingOAuthGatewayController,
31
+ ownerRequestPolicy: OwnerRequestPolicy = LOOPBACK_OWNER_REQUEST_POLICY,
32
+ ): () => void {
33
+ let dispose = (): void => undefined;
34
+ ctx.effect(() => {
35
+ dispose = registerWebRouteSetupAtomically(ctx.webServer, (webServer) => {
36
+ webServer.register({
37
+ kind: "exact",
38
+ path: GATEWAY_SETTINGS_PATH,
39
+ handler: (req, res) => handleGatewaySettings(req, res, controller, ownerRequestPolicy),
40
+ });
41
+ webServer.register({
42
+ kind: "exact",
43
+ path: GATEWAY_REVEAL_PATH,
44
+ handler: (req, res) => handleGatewayReveal(req, res, controller, ownerRequestPolicy),
45
+ });
46
+ webServer.register({
47
+ kind: "exact",
48
+ path: GATEWAY_ROTATE_PATH,
49
+ handler: (req, res) => handleGatewayRotate(req, res, controller, ownerRequestPolicy),
50
+ });
51
+ });
52
+ return dispose;
53
+ }, "dsh-coding-subscription-oauth: gateway settings routes");
54
+ return () => dispose();
55
+ }
56
+
57
+ async function handleGatewaySettings(
58
+ req: IncomingMessage,
59
+ res: ServerResponse,
60
+ controller: CodingOAuthGatewayController,
61
+ ownerRequestPolicy: OwnerRequestPolicy,
62
+ ): Promise<void> {
63
+ if (!ownerRequestPolicy.authorize(req).authorized) {
64
+ json(res, 403, { error: "forbidden" });
65
+ return;
66
+ }
67
+ try {
68
+ if (req.method === "GET") {
69
+ json(res, 200, await controller.status());
70
+ return;
71
+ }
72
+ if (req.method === "PATCH") {
73
+ const raw = await readJsonRequest(req);
74
+ const payload = typeof raw === "object" && raw !== null ? (raw as { enabled?: unknown; port?: unknown }) : {};
75
+ const enabled = payload.enabled;
76
+ const port = payload.port;
77
+ if (enabled === undefined && port === undefined) {
78
+ json(res, 400, { error: "enabled or port is required" });
79
+ return;
80
+ }
81
+ if (enabled !== undefined && typeof enabled !== "boolean") {
82
+ json(res, 400, { error: "enabled must be a boolean" });
83
+ return;
84
+ }
85
+ if (port !== undefined) {
86
+ if (typeof port !== "number" || !Number.isSafeInteger(port)) {
87
+ json(res, 400, { error: "port must be an integer" });
88
+ return;
89
+ }
90
+ try {
91
+ assertGatewayPort(port);
92
+ } catch (error) {
93
+ json(res, 400, { error: safeMessage(error) });
94
+ return;
95
+ }
96
+ await controller.setPort(port);
97
+ }
98
+ const status = typeof enabled === "boolean" ? await controller.setEnabled(enabled) : await controller.status();
99
+ json(res, 200, status);
100
+ return;
101
+ }
102
+ json(res, 405, { error: "method not allowed" });
103
+ } catch (error) {
104
+ json(res, requestErrorStatus(error, 500), { error: safeMessage(error) });
105
+ }
106
+ }
107
+
108
+ async function handleGatewayReveal(
109
+ req: IncomingMessage,
110
+ res: ServerResponse,
111
+ controller: CodingOAuthGatewayController,
112
+ ownerRequestPolicy: OwnerRequestPolicy,
113
+ ): Promise<void> {
114
+ if (!ownerRequestPolicy.authorize(req).authorized) {
115
+ json(res, 403, { error: "forbidden" });
116
+ return;
117
+ }
118
+ if (req.method !== "POST") {
119
+ json(res, 405, { error: "method not allowed" });
120
+ return;
121
+ }
122
+ try {
123
+ json(res, 200, await controller.revealKey());
124
+ } catch (error) {
125
+ json(res, requestErrorStatus(error, 500), { error: safeMessage(error) });
126
+ }
127
+ }
128
+
129
+ async function handleGatewayRotate(
130
+ req: IncomingMessage,
131
+ res: ServerResponse,
132
+ controller: CodingOAuthGatewayController,
133
+ ownerRequestPolicy: OwnerRequestPolicy,
134
+ ): Promise<void> {
135
+ if (!ownerRequestPolicy.authorize(req).authorized) {
136
+ json(res, 403, { error: "forbidden" });
137
+ return;
138
+ }
139
+ if (req.method !== "POST") {
140
+ json(res, 405, { error: "method not allowed" });
141
+ return;
142
+ }
143
+ try {
144
+ json(res, 200, await controller.rotateKey());
145
+ } catch (error) {
146
+ json(res, requestErrorStatus(error, 500), { error: safeMessage(error) });
147
+ }
148
+ }
149
+
150
+ function json(res: ServerResponse, status: number, value: unknown): void {
151
+ const body = Buffer.from(`${JSON.stringify(value)}\n`);
152
+ res.writeHead(status, {
153
+ "content-type": "application/json; charset=utf-8",
154
+ "content-length": body.byteLength,
155
+ "cache-control": "no-store",
156
+ });
157
+ res.end(body);
158
+ }