dsh-coding-subscription-oauth 0.7.1 → 0.8.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 (42) hide show
  1. package/CHANGELOG.md +312 -302
  2. package/CONTRIBUTING.md +138 -138
  3. package/INSTALL.md +267 -262
  4. package/LICENSE +19 -19
  5. package/NOTICE +11 -11
  6. package/README.de.md +309 -303
  7. package/README.es.md +310 -304
  8. package/README.fr.md +310 -304
  9. package/README.ja.md +310 -304
  10. package/README.ko.md +310 -304
  11. package/README.md +327 -321
  12. package/README.pt-BR.md +310 -304
  13. package/README.ru.md +310 -304
  14. package/README.zh-CN.md +325 -319
  15. package/compatibility/dsh-bom.json +36 -36
  16. package/cordis.patch.yml +13 -13
  17. package/docs/00-project-rules.md +213 -213
  18. package/docs/02-architecture.md +143 -142
  19. package/docs/02-architecture.zh-CN.md +143 -142
  20. package/lib/bin.js +13 -6
  21. package/lib/bin.js.map +3 -3
  22. package/lib/client.js +3 -3
  23. package/lib/client.js.map +4 -4
  24. package/lib/gateway-auth.d.ts +1 -0
  25. package/lib/gateway-auth.d.ts.map +1 -1
  26. package/lib/gateway-config.d.ts +4 -0
  27. package/lib/gateway-config.d.ts.map +1 -1
  28. package/lib/gateway-http.d.ts +5 -0
  29. package/lib/gateway-http.d.ts.map +1 -1
  30. package/lib/gateway-opencode-go.d.ts +22 -0
  31. package/lib/gateway-opencode-go.d.ts.map +1 -0
  32. package/lib/gateway.d.ts +2 -0
  33. package/lib/gateway.d.ts.map +1 -1
  34. package/lib/index.js +276 -63
  35. package/lib/index.js.map +4 -4
  36. package/lib/invariant.js.map +1 -1
  37. package/package.json +229 -229
  38. package/patches/dsh-agy@0.1.2.patch +25 -25
  39. package/scripts/release.mjs +187 -187
  40. package/scripts/smoke-deployed-routes.mjs +146 -146
  41. package/scripts/verify-adapter-host.mjs +70 -70
  42. package/scripts/verify-deployed-catalog.mjs +87 -87
@@ -1,146 +1,146 @@
1
- #!/usr/bin/env node
2
-
3
- import { randomUUID } from "node:crypto";
4
-
5
- const base = new URL(process.env.DSH_WEB_URL ?? "http://127.0.0.1:3080");
6
- const origin = base.origin;
7
- const timeoutMs = Number.parseInt(process.env.DSH_SMOKE_TIMEOUT_MS ?? "180000", 10);
8
- const restoreProvider = process.env.DSH_RESTORE_PROVIDER;
9
- const restoreModel = process.env.DSH_RESTORE_MODEL;
10
- if (restoreProvider === undefined || restoreModel === undefined) {
11
- throw new Error(
12
- "Set DSH_RESTORE_PROVIDER and DSH_RESTORE_MODEL before running; smoke selection updates the saved default temporarily",
13
- );
14
- }
15
- const restoreSelection = {
16
- provider: restoreProvider,
17
- model: restoreModel,
18
- ...(process.env.DSH_RESTORE_REASONING === undefined ? {} : { reasoningEffort: process.env.DSH_RESTORE_REASONING }),
19
- };
20
- const cases = [
21
- {
22
- route: "codex-oauth",
23
- model: process.env.DSH_CODEX_SMOKE_MODEL ?? "gpt-5.6-sol",
24
- marker: "DSH_CODEX_OAUTH_SMOKE_OK",
25
- },
26
- { route: "kimi-code-oauth", model: process.env.DSH_KIMI_SMOKE_MODEL ?? "k3", marker: "DSH_KIMI_OAUTH_SMOKE_OK" },
27
- ];
28
-
29
- async function rpc(method, payload) {
30
- const rpcId = randomUUID();
31
- const response = await fetch(new URL(`/api/${method}`, base), {
32
- method: "POST",
33
- headers: { accept: "application/json", "content-type": "application/json", origin },
34
- body: JSON.stringify({ type: "client-request", rpcId, method, payload }),
35
- signal: AbortSignal.timeout(30_000),
36
- });
37
- const envelope = await response.json().catch(() => undefined);
38
- if (!response.ok) throw new Error(`${method}: HTTP ${response.status}`);
39
- if (envelope?.rpcId !== rpcId || envelope?.result?.ok !== true) {
40
- throw new Error(`${method}: ${envelope?.result?.error?.message ?? "invalid response"}`);
41
- }
42
- return envelope.result.value;
43
- }
44
-
45
- async function waitForIdle(sessionId) {
46
- const deadline = Date.now() + timeoutMs;
47
- while (Date.now() < deadline) {
48
- const { items } = await rpc("session.list", {});
49
- const session = items.find((item) => item.sessionId === sessionId);
50
- if (session === undefined) throw new Error(`session ${sessionId} disappeared`);
51
- if (!session.blank && !session.running) return;
52
- await new Promise((resolve) => setTimeout(resolve, 1_000));
53
- }
54
- throw new Error(`session ${sessionId} did not finish within ${timeoutMs}ms`);
55
- }
56
-
57
- function contentBlocks(value, output = []) {
58
- if (Array.isArray(value)) {
59
- for (const item of value) contentBlocks(item, output);
60
- } else if (value !== null && typeof value === "object") {
61
- if (typeof value.type === "string" && ["tool-call", "tool-result"].includes(value.type)) output.push(value);
62
- for (const child of Object.values(value)) contentBlocks(child, output);
63
- }
64
- return output;
65
- }
66
-
67
- async function runSmoke(testCase) {
68
- const created = await rpc("session.create", { cwd: process.cwd() });
69
- const sessionId = created.sessionId;
70
- let selected = false;
71
- let failure;
72
- try {
73
- await rpc("session.selectModel", {
74
- sessionId,
75
- provider: testCase.route,
76
- model: testCase.model,
77
- reasoningEffort: "low",
78
- });
79
- selected = true;
80
- await rpc("session.prompt", {
81
- sessionId,
82
- mode: "queue",
83
- clientTimeZone: "UTC",
84
- content: [
85
- {
86
- type: "text",
87
- text: `Automated OAuth smoke test. You MUST call the glob tool exactly once with pattern "package.json" in the current workspace. After receiving the tool result, reply with exactly ${testCase.marker} and no other text.`,
88
- },
89
- ],
90
- });
91
- await waitForIdle(sessionId);
92
- const history = await rpc("session.history", { sessionId, maxMessages: 200 });
93
- const serialized = JSON.stringify(history.events);
94
- const blocks = contentBlocks(history.events);
95
- const toolCalls = blocks.filter((block) => block.type === "tool-call").length;
96
- const toolResults = blocks.filter((block) => block.type === "tool-result").length;
97
- const eventTypes = [...new Set(history.events.map((entry) => entry.event.type))];
98
- const turnErrors = eventTypes.filter((type) => type.includes("error"));
99
- if (!serialized.includes(testCase.marker)) throw new Error(`${testCase.route}: response marker missing`);
100
- if (toolCalls === 0 || toolResults === 0) throw new Error(`${testCase.route}: tool-call round trip missing`);
101
- if (turnErrors.length > 0) throw new Error(`${testCase.route}: error events: ${turnErrors.join(", ")}`);
102
-
103
- const secondMarker = `${testCase.marker}_TURN2`;
104
- await rpc("session.prompt", {
105
- sessionId,
106
- mode: "queue",
107
- clientTimeZone: "UTC",
108
- content: [
109
- { type: "text", text: `Second-turn replay test. Reply with exactly ${secondMarker} and no other text.` },
110
- ],
111
- });
112
- await waitForIdle(sessionId);
113
- const secondHistory = await rpc("session.history", { sessionId, maxMessages: 200 });
114
- const secondSerialized = JSON.stringify(secondHistory.events);
115
- const secondEventTypes = [...new Set(secondHistory.events.map((entry) => entry.event.type))];
116
- const secondTurnErrors = secondEventTypes.filter((type) => type.includes("error"));
117
- if (!secondSerialized.includes(secondMarker))
118
- throw new Error(`${testCase.route}: second-turn response marker missing`);
119
- if (secondTurnErrors.length > 0)
120
- throw new Error(`${testCase.route}: second-turn error events: ${secondTurnErrors.join(", ")}`);
121
- console.log(`${testCase.route}/${testCase.model}: twoTurns=yes toolCalls=${toolCalls} toolResults=${toolResults}`);
122
- } catch (error) {
123
- failure = error;
124
- } finally {
125
- if (selected) {
126
- try {
127
- await rpc("session.selectModel", { sessionId, ...restoreSelection });
128
- } catch (error) {
129
- failure ??= new Error(
130
- `${testCase.route}: failed to restore default model: ${error instanceof Error ? error.message : String(error)}`,
131
- );
132
- }
133
- }
134
- try {
135
- await rpc("workspace.archiveSession", { sessionId });
136
- } catch (error) {
137
- failure ??= new Error(
138
- `${testCase.route}: failed to archive smoke session: ${error instanceof Error ? error.message : String(error)}`,
139
- );
140
- }
141
- }
142
- if (failure !== undefined) throw failure;
143
- }
144
-
145
- for (const testCase of cases) await runSmoke(testCase);
146
- console.log("Deployed Codex/Kimi OAuth inference and tool-call smoke passed.");
1
+ #!/usr/bin/env node
2
+
3
+ import { randomUUID } from "node:crypto";
4
+
5
+ const base = new URL(process.env.DSH_WEB_URL ?? "http://127.0.0.1:3080");
6
+ const origin = base.origin;
7
+ const timeoutMs = Number.parseInt(process.env.DSH_SMOKE_TIMEOUT_MS ?? "180000", 10);
8
+ const restoreProvider = process.env.DSH_RESTORE_PROVIDER;
9
+ const restoreModel = process.env.DSH_RESTORE_MODEL;
10
+ if (restoreProvider === undefined || restoreModel === undefined) {
11
+ throw new Error(
12
+ "Set DSH_RESTORE_PROVIDER and DSH_RESTORE_MODEL before running; smoke selection updates the saved default temporarily",
13
+ );
14
+ }
15
+ const restoreSelection = {
16
+ provider: restoreProvider,
17
+ model: restoreModel,
18
+ ...(process.env.DSH_RESTORE_REASONING === undefined ? {} : { reasoningEffort: process.env.DSH_RESTORE_REASONING }),
19
+ };
20
+ const cases = [
21
+ {
22
+ route: "codex-oauth",
23
+ model: process.env.DSH_CODEX_SMOKE_MODEL ?? "gpt-5.6-sol",
24
+ marker: "DSH_CODEX_OAUTH_SMOKE_OK",
25
+ },
26
+ { route: "kimi-code-oauth", model: process.env.DSH_KIMI_SMOKE_MODEL ?? "k3", marker: "DSH_KIMI_OAUTH_SMOKE_OK" },
27
+ ];
28
+
29
+ async function rpc(method, payload) {
30
+ const rpcId = randomUUID();
31
+ const response = await fetch(new URL(`/api/${method}`, base), {
32
+ method: "POST",
33
+ headers: { accept: "application/json", "content-type": "application/json", origin },
34
+ body: JSON.stringify({ type: "client-request", rpcId, method, payload }),
35
+ signal: AbortSignal.timeout(30_000),
36
+ });
37
+ const envelope = await response.json().catch(() => undefined);
38
+ if (!response.ok) throw new Error(`${method}: HTTP ${response.status}`);
39
+ if (envelope?.rpcId !== rpcId || envelope?.result?.ok !== true) {
40
+ throw new Error(`${method}: ${envelope?.result?.error?.message ?? "invalid response"}`);
41
+ }
42
+ return envelope.result.value;
43
+ }
44
+
45
+ async function waitForIdle(sessionId) {
46
+ const deadline = Date.now() + timeoutMs;
47
+ while (Date.now() < deadline) {
48
+ const { items } = await rpc("session.list", {});
49
+ const session = items.find((item) => item.sessionId === sessionId);
50
+ if (session === undefined) throw new Error(`session ${sessionId} disappeared`);
51
+ if (!session.blank && !session.running) return;
52
+ await new Promise((resolve) => setTimeout(resolve, 1_000));
53
+ }
54
+ throw new Error(`session ${sessionId} did not finish within ${timeoutMs}ms`);
55
+ }
56
+
57
+ function contentBlocks(value, output = []) {
58
+ if (Array.isArray(value)) {
59
+ for (const item of value) contentBlocks(item, output);
60
+ } else if (value !== null && typeof value === "object") {
61
+ if (typeof value.type === "string" && ["tool-call", "tool-result"].includes(value.type)) output.push(value);
62
+ for (const child of Object.values(value)) contentBlocks(child, output);
63
+ }
64
+ return output;
65
+ }
66
+
67
+ async function runSmoke(testCase) {
68
+ const created = await rpc("session.create", { cwd: process.cwd() });
69
+ const sessionId = created.sessionId;
70
+ let selected = false;
71
+ let failure;
72
+ try {
73
+ await rpc("session.selectModel", {
74
+ sessionId,
75
+ provider: testCase.route,
76
+ model: testCase.model,
77
+ reasoningEffort: "low",
78
+ });
79
+ selected = true;
80
+ await rpc("session.prompt", {
81
+ sessionId,
82
+ mode: "queue",
83
+ clientTimeZone: "UTC",
84
+ content: [
85
+ {
86
+ type: "text",
87
+ text: `Automated OAuth smoke test. You MUST call the glob tool exactly once with pattern "package.json" in the current workspace. After receiving the tool result, reply with exactly ${testCase.marker} and no other text.`,
88
+ },
89
+ ],
90
+ });
91
+ await waitForIdle(sessionId);
92
+ const history = await rpc("session.history", { sessionId, maxMessages: 200 });
93
+ const serialized = JSON.stringify(history.events);
94
+ const blocks = contentBlocks(history.events);
95
+ const toolCalls = blocks.filter((block) => block.type === "tool-call").length;
96
+ const toolResults = blocks.filter((block) => block.type === "tool-result").length;
97
+ const eventTypes = [...new Set(history.events.map((entry) => entry.event.type))];
98
+ const turnErrors = eventTypes.filter((type) => type.includes("error"));
99
+ if (!serialized.includes(testCase.marker)) throw new Error(`${testCase.route}: response marker missing`);
100
+ if (toolCalls === 0 || toolResults === 0) throw new Error(`${testCase.route}: tool-call round trip missing`);
101
+ if (turnErrors.length > 0) throw new Error(`${testCase.route}: error events: ${turnErrors.join(", ")}`);
102
+
103
+ const secondMarker = `${testCase.marker}_TURN2`;
104
+ await rpc("session.prompt", {
105
+ sessionId,
106
+ mode: "queue",
107
+ clientTimeZone: "UTC",
108
+ content: [
109
+ { type: "text", text: `Second-turn replay test. Reply with exactly ${secondMarker} and no other text.` },
110
+ ],
111
+ });
112
+ await waitForIdle(sessionId);
113
+ const secondHistory = await rpc("session.history", { sessionId, maxMessages: 200 });
114
+ const secondSerialized = JSON.stringify(secondHistory.events);
115
+ const secondEventTypes = [...new Set(secondHistory.events.map((entry) => entry.event.type))];
116
+ const secondTurnErrors = secondEventTypes.filter((type) => type.includes("error"));
117
+ if (!secondSerialized.includes(secondMarker))
118
+ throw new Error(`${testCase.route}: second-turn response marker missing`);
119
+ if (secondTurnErrors.length > 0)
120
+ throw new Error(`${testCase.route}: second-turn error events: ${secondTurnErrors.join(", ")}`);
121
+ console.log(`${testCase.route}/${testCase.model}: twoTurns=yes toolCalls=${toolCalls} toolResults=${toolResults}`);
122
+ } catch (error) {
123
+ failure = error;
124
+ } finally {
125
+ if (selected) {
126
+ try {
127
+ await rpc("session.selectModel", { sessionId, ...restoreSelection });
128
+ } catch (error) {
129
+ failure ??= new Error(
130
+ `${testCase.route}: failed to restore default model: ${error instanceof Error ? error.message : String(error)}`,
131
+ );
132
+ }
133
+ }
134
+ try {
135
+ await rpc("workspace.archiveSession", { sessionId });
136
+ } catch (error) {
137
+ failure ??= new Error(
138
+ `${testCase.route}: failed to archive smoke session: ${error instanceof Error ? error.message : String(error)}`,
139
+ );
140
+ }
141
+ }
142
+ if (failure !== undefined) throw failure;
143
+ }
144
+
145
+ for (const testCase of cases) await runSmoke(testCase);
146
+ console.log("Deployed Codex/Kimi OAuth inference and tool-call smoke passed.");
@@ -1,70 +1,70 @@
1
- #!/usr/bin/env node
2
-
3
- // Run against a plugin installed in an isolated host, not this checkout's peers.
4
- // Metadata resolution is offline and uses disposable example credentials.
5
- import assert from "node:assert/strict";
6
- import { mkdtemp, rm } from "node:fs/promises";
7
- import { tmpdir } from "node:os";
8
- import { join, resolve } from "node:path";
9
- import { pathToFileURL } from "node:url";
10
-
11
- const entry = process.argv[2];
12
- if (!entry) throw new Error("Usage: node scripts/verify-adapter-host.mjs <installed-plugin>/lib/index.js");
13
- const scratch = await mkdtemp(join(tmpdir(), "dsh-adapter-host-"));
14
- const previousHome = process.env.DSH_HOME;
15
- const previousFetch = globalThis.fetch;
16
- process.env.DSH_HOME = scratch;
17
- globalThis.fetch = async () => {
18
- throw new Error("Model metadata checks must not make network requests");
19
- };
20
- try {
21
- const plugin = await import(pathToFileURL(resolve(entry)).href);
22
- const grok = new plugin.GrokBuildSession(new plugin.GrokBuildCredentialStore(join(scratch, "grok.json")));
23
- const subscriptions = plugin.OAUTH_PROVIDER_DEFINITIONS.map(
24
- (definition) =>
25
- new plugin.OAuthProviderSession(
26
- definition,
27
- undefined,
28
- new plugin.OAuthCredentialFileStore(
29
- definition.nativeProviderId,
30
- join(scratch, `${definition.slug}.json`),
31
- definition.route,
32
- ),
33
- join(scratch, `${definition.slug}-models.json`),
34
- ),
35
- );
36
- const exampleCredential = () => ({
37
- type: "oauth",
38
- access: "EXAMPLE_ACCESS_TOKEN",
39
- refresh: "EXAMPLE_REFRESH_TOKEN",
40
- expires: Date.now() + 3_600_000,
41
- });
42
- await grok.store.modify("xai", async () => exampleCredential());
43
- for (const session of subscriptions) {
44
- await session.store.modify(session.definition.nativeProviderId, async () => exampleCredential());
45
- }
46
- const adapter = plugin.createCodingOAuthAdapter(grok, subscriptions, () => undefined, {
47
- codexFast: { isEligible: () => true },
48
- });
49
- for (const route of [...plugin.CODING_OAUTH_ROUTES, "codex-oauth-fast"]) {
50
- const models = await adapter.listModels(route);
51
- assert.ok(models.length > 0, `${route}: expected catalog entries`);
52
- const model = route === "grok-build" ? models.find((item) => item.id === "grok-4.6") : models[0];
53
- assert.ok(model, `${route}: expected model`);
54
- const resolved = await adapter.resolveModel(route, model.id);
55
- assert.equal(resolved.provider, route);
56
- assert.equal(resolved.id, model.id);
57
- const prepared = await adapter.prepareCall(route, model.id);
58
- assert.equal(prepared.model.id, model.id);
59
- await assert.rejects(adapter.resolveModel(route, "missing-example-model"), { code: "UNKNOWN_MODEL" });
60
- console.log(`PASS ${route}: catalog, model resolution, request preparation, unknown-model error`);
61
- }
62
- const standalone = plugin.createGrokBuildAdapter(grok, () => undefined);
63
- assert.equal((await standalone.resolveModel("grok-build", "grok-4.6")).id, "grok-4.6");
64
- console.log("PASS standalone Grok adapter");
65
- } finally {
66
- globalThis.fetch = previousFetch;
67
- if (previousHome === undefined) delete process.env.DSH_HOME;
68
- else process.env.DSH_HOME = previousHome;
69
- await rm(scratch, { recursive: true, force: true });
70
- }
1
+ #!/usr/bin/env node
2
+
3
+ // Run against a plugin installed in an isolated host, not this checkout's peers.
4
+ // Metadata resolution is offline and uses disposable example credentials.
5
+ import assert from "node:assert/strict";
6
+ import { mkdtemp, rm } from "node:fs/promises";
7
+ import { tmpdir } from "node:os";
8
+ import { join, resolve } from "node:path";
9
+ import { pathToFileURL } from "node:url";
10
+
11
+ const entry = process.argv[2];
12
+ if (!entry) throw new Error("Usage: node scripts/verify-adapter-host.mjs <installed-plugin>/lib/index.js");
13
+ const scratch = await mkdtemp(join(tmpdir(), "dsh-adapter-host-"));
14
+ const previousHome = process.env.DSH_HOME;
15
+ const previousFetch = globalThis.fetch;
16
+ process.env.DSH_HOME = scratch;
17
+ globalThis.fetch = async () => {
18
+ throw new Error("Model metadata checks must not make network requests");
19
+ };
20
+ try {
21
+ const plugin = await import(pathToFileURL(resolve(entry)).href);
22
+ const grok = new plugin.GrokBuildSession(new plugin.GrokBuildCredentialStore(join(scratch, "grok.json")));
23
+ const subscriptions = plugin.OAUTH_PROVIDER_DEFINITIONS.map(
24
+ (definition) =>
25
+ new plugin.OAuthProviderSession(
26
+ definition,
27
+ undefined,
28
+ new plugin.OAuthCredentialFileStore(
29
+ definition.nativeProviderId,
30
+ join(scratch, `${definition.slug}.json`),
31
+ definition.route,
32
+ ),
33
+ join(scratch, `${definition.slug}-models.json`),
34
+ ),
35
+ );
36
+ const exampleCredential = () => ({
37
+ type: "oauth",
38
+ access: "EXAMPLE_ACCESS_TOKEN",
39
+ refresh: "EXAMPLE_REFRESH_TOKEN",
40
+ expires: Date.now() + 3_600_000,
41
+ });
42
+ await grok.store.modify("xai", async () => exampleCredential());
43
+ for (const session of subscriptions) {
44
+ await session.store.modify(session.definition.nativeProviderId, async () => exampleCredential());
45
+ }
46
+ const adapter = plugin.createCodingOAuthAdapter(grok, subscriptions, () => undefined, {
47
+ codexFast: { isEligible: () => true },
48
+ });
49
+ for (const route of [...plugin.CODING_OAUTH_ROUTES, "codex-oauth-fast"]) {
50
+ const models = await adapter.listModels(route);
51
+ assert.ok(models.length > 0, `${route}: expected catalog entries`);
52
+ const model = route === "grok-build" ? models.find((item) => item.id === "grok-4.6") : models[0];
53
+ assert.ok(model, `${route}: expected model`);
54
+ const resolved = await adapter.resolveModel(route, model.id);
55
+ assert.equal(resolved.provider, route);
56
+ assert.equal(resolved.id, model.id);
57
+ const prepared = await adapter.prepareCall(route, model.id);
58
+ assert.equal(prepared.model.id, model.id);
59
+ await assert.rejects(adapter.resolveModel(route, "missing-example-model"), { code: "UNKNOWN_MODEL" });
60
+ console.log(`PASS ${route}: catalog, model resolution, request preparation, unknown-model error`);
61
+ }
62
+ const standalone = plugin.createGrokBuildAdapter(grok, () => undefined);
63
+ assert.equal((await standalone.resolveModel("grok-build", "grok-4.6")).id, "grok-4.6");
64
+ console.log("PASS standalone Grok adapter");
65
+ } finally {
66
+ globalThis.fetch = previousFetch;
67
+ if (previousHome === undefined) delete process.env.DSH_HOME;
68
+ else process.env.DSH_HOME = previousHome;
69
+ await rm(scratch, { recursive: true, force: true });
70
+ }
@@ -1,87 +1,87 @@
1
- #!/usr/bin/env node
2
-
3
- import { randomUUID } from "node:crypto";
4
-
5
- const base = new URL(process.env.DSH_WEB_URL ?? "http://127.0.0.1:3080");
6
- const origin = base.origin;
7
-
8
- async function jsonFetch(path, init = {}) {
9
- const response = await fetch(new URL(path, base), {
10
- ...init,
11
- headers: {
12
- accept: "application/json",
13
- origin,
14
- ...init.headers,
15
- },
16
- });
17
- const value = await response.json().catch(() => undefined);
18
- if (!response.ok) throw new Error(`${path}: HTTP ${response.status}`);
19
- return value;
20
- }
21
-
22
- async function rpc(method, payload = {}) {
23
- const rpcId = randomUUID();
24
- const envelope = await jsonFetch(`/api/${method}`, {
25
- method: "POST",
26
- headers: { "content-type": "application/json" },
27
- body: JSON.stringify({ type: "client-request", rpcId, method, payload }),
28
- });
29
- if (envelope?.rpcId !== rpcId || envelope?.result?.ok !== true) {
30
- throw new Error(`${method} failed: ${JSON.stringify(envelope?.result?.error ?? envelope)}`);
31
- }
32
- return envelope.result.value;
33
- }
34
-
35
- const status = await jsonFetch("/plugins/dsh-grok-build/oauth/status");
36
- const catalog = await rpc("llm.models");
37
- const registered = await rpc("llm.providers");
38
- const groups = new Map(catalog.groups.map((group) => [group.id, group]));
39
- const routes = [
40
- ["grok", "grok-build"],
41
- ["codex", "codex-oauth"],
42
- ["kimi", "kimi-code-oauth"],
43
- ["claude", "claude-code-oauth"],
44
- ];
45
- const failures = [];
46
- const report = [];
47
- for (const [slug, route] of routes) {
48
- const authenticated = status?.providers?.[slug]?.status === "signed-in";
49
- const group = groups.get(route);
50
- if (authenticated && group === undefined) failures.push(`${route}: authenticated but absent from model catalog`);
51
- if (!authenticated && group !== undefined)
52
- failures.push(`${route}: unauthenticated but still advertises ${group.models.length} model(s)`);
53
- if (group !== undefined && !/\(OAuth\)$/u.test(group.name))
54
- failures.push(`${route}: provider name lacks (OAuth): ${group.name}`);
55
- report.push(
56
- `${route}: ${authenticated ? "authenticated" : "unauthenticated"} → ${group === undefined ? "hidden" : `${group.models.length} model(s), ${group.name}`}`,
57
- );
58
- }
59
-
60
- const providerIds = new Set(registered.providers.map((provider) => provider.provider));
61
- const preservedRoutes = ["openai", "xai", "kimi-coding"];
62
- for (const route of preservedRoutes) {
63
- if (!providerIds.has(route)) failures.push(`${route}: legacy API-key route is no longer registered`);
64
- }
65
- report.push(`preserved API-key routes: ${preservedRoutes.filter((route) => providerIds.has(route)).join(", ")}`);
66
-
67
- const agyExpectation = process.env.DSH_EXPECT_AGY_AUTH ?? "signed-out";
68
- if (!["signed-out", "signed-in", "auto"].includes(agyExpectation)) {
69
- throw new Error("DSH_EXPECT_AGY_AUTH must be signed-out, signed-in, or auto");
70
- }
71
- const agy = groups.get("agy");
72
- if (agyExpectation === "signed-out" && agy !== undefined)
73
- failures.push(`agy: expected signed-out but advertises ${agy.models.length} model(s)`);
74
- if (agyExpectation === "signed-in" && agy === undefined)
75
- failures.push("agy: expected signed-in but absent from model catalog");
76
- if (agy !== undefined && agy.name !== "Google Antigravity (OAuth)")
77
- failures.push(`agy: provider name lacks OAuth label: ${agy.name}`);
78
- report.push(`agy: ${agy === undefined ? "hidden" : `${agy.models.length} model(s), ${agy.name}`}`);
79
-
80
- console.log(report.join("\n"));
81
- if (failures.length > 0) {
82
- console.error("\nDeployment verification failed:");
83
- for (const failure of failures) console.error(`- ${failure}`);
84
- process.exitCode = 1;
85
- } else {
86
- console.log("\nOAuth model catalog verification passed.");
87
- }
1
+ #!/usr/bin/env node
2
+
3
+ import { randomUUID } from "node:crypto";
4
+
5
+ const base = new URL(process.env.DSH_WEB_URL ?? "http://127.0.0.1:3080");
6
+ const origin = base.origin;
7
+
8
+ async function jsonFetch(path, init = {}) {
9
+ const response = await fetch(new URL(path, base), {
10
+ ...init,
11
+ headers: {
12
+ accept: "application/json",
13
+ origin,
14
+ ...init.headers,
15
+ },
16
+ });
17
+ const value = await response.json().catch(() => undefined);
18
+ if (!response.ok) throw new Error(`${path}: HTTP ${response.status}`);
19
+ return value;
20
+ }
21
+
22
+ async function rpc(method, payload = {}) {
23
+ const rpcId = randomUUID();
24
+ const envelope = await jsonFetch(`/api/${method}`, {
25
+ method: "POST",
26
+ headers: { "content-type": "application/json" },
27
+ body: JSON.stringify({ type: "client-request", rpcId, method, payload }),
28
+ });
29
+ if (envelope?.rpcId !== rpcId || envelope?.result?.ok !== true) {
30
+ throw new Error(`${method} failed: ${JSON.stringify(envelope?.result?.error ?? envelope)}`);
31
+ }
32
+ return envelope.result.value;
33
+ }
34
+
35
+ const status = await jsonFetch("/plugins/dsh-grok-build/oauth/status");
36
+ const catalog = await rpc("llm.models");
37
+ const registered = await rpc("llm.providers");
38
+ const groups = new Map(catalog.groups.map((group) => [group.id, group]));
39
+ const routes = [
40
+ ["grok", "grok-build"],
41
+ ["codex", "codex-oauth"],
42
+ ["kimi", "kimi-code-oauth"],
43
+ ["claude", "claude-code-oauth"],
44
+ ];
45
+ const failures = [];
46
+ const report = [];
47
+ for (const [slug, route] of routes) {
48
+ const authenticated = status?.providers?.[slug]?.status === "signed-in";
49
+ const group = groups.get(route);
50
+ if (authenticated && group === undefined) failures.push(`${route}: authenticated but absent from model catalog`);
51
+ if (!authenticated && group !== undefined)
52
+ failures.push(`${route}: unauthenticated but still advertises ${group.models.length} model(s)`);
53
+ if (group !== undefined && !/\(OAuth\)$/u.test(group.name))
54
+ failures.push(`${route}: provider name lacks (OAuth): ${group.name}`);
55
+ report.push(
56
+ `${route}: ${authenticated ? "authenticated" : "unauthenticated"} → ${group === undefined ? "hidden" : `${group.models.length} model(s), ${group.name}`}`,
57
+ );
58
+ }
59
+
60
+ const providerIds = new Set(registered.providers.map((provider) => provider.provider));
61
+ const preservedRoutes = ["openai", "xai", "kimi-coding"];
62
+ for (const route of preservedRoutes) {
63
+ if (!providerIds.has(route)) failures.push(`${route}: legacy API-key route is no longer registered`);
64
+ }
65
+ report.push(`preserved API-key routes: ${preservedRoutes.filter((route) => providerIds.has(route)).join(", ")}`);
66
+
67
+ const agyExpectation = process.env.DSH_EXPECT_AGY_AUTH ?? "signed-out";
68
+ if (!["signed-out", "signed-in", "auto"].includes(agyExpectation)) {
69
+ throw new Error("DSH_EXPECT_AGY_AUTH must be signed-out, signed-in, or auto");
70
+ }
71
+ const agy = groups.get("agy");
72
+ if (agyExpectation === "signed-out" && agy !== undefined)
73
+ failures.push(`agy: expected signed-out but advertises ${agy.models.length} model(s)`);
74
+ if (agyExpectation === "signed-in" && agy === undefined)
75
+ failures.push("agy: expected signed-in but absent from model catalog");
76
+ if (agy !== undefined && agy.name !== "Google Antigravity (OAuth)")
77
+ failures.push(`agy: provider name lacks OAuth label: ${agy.name}`);
78
+ report.push(`agy: ${agy === undefined ? "hidden" : `${agy.models.length} model(s), ${agy.name}`}`);
79
+
80
+ console.log(report.join("\n"));
81
+ if (failures.length > 0) {
82
+ console.error("\nDeployment verification failed:");
83
+ for (const failure of failures) console.error(`- ${failure}`);
84
+ process.exitCode = 1;
85
+ } else {
86
+ console.log("\nOAuth model catalog verification passed.");
87
+ }