dsh-coding-subscription-oauth 0.6.2 → 0.6.3

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 (121) hide show
  1. package/CHANGELOG.md +222 -206
  2. package/CONTRIBUTING.md +129 -120
  3. package/INSTALL.md +218 -218
  4. package/LICENSE +19 -19
  5. package/NOTICE +11 -11
  6. package/README.de.md +289 -289
  7. package/README.es.md +290 -290
  8. package/README.fr.md +290 -290
  9. package/README.ja.md +290 -290
  10. package/README.ko.md +290 -290
  11. package/README.md +304 -304
  12. package/README.pt-BR.md +290 -290
  13. package/README.ru.md +290 -290
  14. package/README.zh-CN.md +302 -302
  15. package/compatibility/dsh-bom.json +0 -0
  16. package/cordis.patch.yml +13 -13
  17. package/docs/00-project-rules.md +212 -195
  18. package/docs/02-architecture.md +130 -130
  19. package/docs/02-architecture.zh-CN.md +130 -130
  20. package/lib/bin.js.map +1 -1
  21. package/lib/capability-settings.d.ts +8 -2
  22. package/lib/capability-settings.d.ts.map +1 -1
  23. package/lib/capability-tools.d.ts +7 -2
  24. package/lib/capability-tools.d.ts.map +1 -1
  25. package/lib/client.js +3 -3
  26. package/lib/client.js.map +2 -2
  27. package/lib/codex-images.d.ts +8 -0
  28. package/lib/codex-images.d.ts.map +1 -1
  29. package/lib/index.js +32 -7
  30. package/lib/index.js.map +2 -2
  31. package/lib/invariant.js.map +1 -1
  32. package/media/en/settings_accounts.png +0 -0
  33. package/media/en/settings_capabilities.png +0 -0
  34. package/media/en/settings_gateway.png +0 -0
  35. package/media/settings_accounts.png +0 -0
  36. package/media/settings_capabilities.png +0 -0
  37. package/media/settings_gateway.png +0 -0
  38. package/media/settings_overview.png +0 -0
  39. package/media/zh-CN/settings_accounts.png +0 -0
  40. package/media/zh-CN/settings_capabilities.png +0 -0
  41. package/media/zh-CN/settings_gateway.png +0 -0
  42. package/package.json +148 -148
  43. package/patches/dsh-agy@0.1.2.patch +25 -25
  44. package/scripts/release.mjs +186 -186
  45. package/scripts/smoke-deployed-routes.mjs +146 -146
  46. package/scripts/verify-deployed-catalog.mjs +87 -87
  47. package/src/adapter.ts +273 -273
  48. package/src/alias-adapter.ts +130 -130
  49. package/src/auth-routes.ts +921 -921
  50. package/src/auth.ts +67 -67
  51. package/src/bin.ts +350 -350
  52. package/src/capability-routes.ts +279 -279
  53. package/src/capability-runtime.ts +314 -313
  54. package/src/capability-settings.ts +671 -658
  55. package/src/capability-tools.ts +685 -666
  56. package/src/catalog.ts +271 -271
  57. package/src/client/GrokBuildSettings.tsx +771 -770
  58. package/src/client/api.ts +88 -88
  59. package/src/client/components/AboutTab.tsx +30 -30
  60. package/src/client/components/AccountsTab.tsx +241 -241
  61. package/src/client/components/Badge.tsx +33 -33
  62. package/src/client/components/CapabilitiesTab.tsx +265 -265
  63. package/src/client/components/CliPullPreview.tsx +116 -116
  64. package/src/client/components/CopyButton.tsx +57 -57
  65. package/src/client/components/GatewayTab.tsx +469 -469
  66. package/src/client/components/NoticeBanner.tsx +46 -46
  67. package/src/client/components/ProgressBar.tsx +53 -53
  68. package/src/client/components/ProviderCard.tsx +606 -606
  69. package/src/client/components/SettingsTabs.tsx +75 -75
  70. package/src/client/components/ToggleSwitch.tsx +71 -71
  71. package/src/client/constants.ts +230 -224
  72. package/src/client/display.ts +61 -61
  73. package/src/client/dshClientAdapter.ts +127 -127
  74. package/src/client/gatewaySnippets.ts +37 -37
  75. package/src/client/index.tsx +156 -156
  76. package/src/client/locales.ts +540 -535
  77. package/src/client/microStyles.ts +52 -52
  78. package/src/client/parsers.ts +398 -396
  79. package/src/client/styles.ts +325 -325
  80. package/src/client/types.ts +199 -197
  81. package/src/codex-http.ts +447 -447
  82. package/src/codex-images.ts +503 -485
  83. package/src/codex-model-capabilities.ts +320 -320
  84. package/src/codex-search.ts +245 -245
  85. package/src/codex-usage.ts +263 -263
  86. package/src/compatibility.ts +41 -41
  87. package/src/dsh-host-adapter.ts +173 -173
  88. package/src/gateway-anthropic-messages.ts +84 -84
  89. package/src/gateway-auth.ts +102 -102
  90. package/src/gateway-backend.ts +274 -274
  91. package/src/gateway-body.ts +49 -49
  92. package/src/gateway-config.ts +76 -76
  93. package/src/gateway-http.ts +104 -104
  94. package/src/gateway-openai-chat.ts +124 -124
  95. package/src/gateway-openai-responses.ts +53 -53
  96. package/src/gateway-parse.ts +224 -224
  97. package/src/gateway-protocol.ts +52 -52
  98. package/src/gateway-routes.ts +158 -158
  99. package/src/gateway.ts +258 -258
  100. package/src/grok-errors.ts +24 -24
  101. package/src/grok-imagine.ts +1627 -1627
  102. package/src/grok-import.ts +151 -151
  103. package/src/http-json.ts +82 -82
  104. package/src/ids.ts +59 -59
  105. package/src/imagine-routes.ts +463 -463
  106. package/src/index.ts +709 -709
  107. package/src/invariant.ts +17 -17
  108. package/src/kimi-errors.ts +26 -26
  109. package/src/media-store.ts +927 -927
  110. package/src/oauth-import-routes.ts +324 -324
  111. package/src/oauth-providers.ts +152 -152
  112. package/src/oauth-session.ts +183 -183
  113. package/src/oauth-sources.ts +1104 -1104
  114. package/src/oauth.ts +620 -620
  115. package/src/provider.ts +128 -128
  116. package/src/proxy.ts +11 -11
  117. package/src/redact.ts +72 -72
  118. package/src/session.ts +218 -218
  119. package/src/store.ts +217 -217
  120. package/src/web-origin.ts +296 -296
  121. package/src/web-routes.ts +38 -38
@@ -1,158 +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 { 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
- }
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
+ }