vanspod 0.4.1 → 0.4.4

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.
package/README.md CHANGED
@@ -38,7 +38,7 @@ npm run dist
38
38
  npm pack --pack-destination dist
39
39
  ```
40
40
 
41
- exe 產物為 `dist/VansPod.exe`,本機套件為 `dist/vanspod-0.4.1.tgz`;可在 Windows 用 `npm install -g <套件路徑>` 安裝測試。圖片、favicon、系統匣與移除腳本均包含在發佈產物中。更新 logo 後執行 `powershell.exe -NoProfile -File scripts/build-icon.ps1` 重建多尺寸 Windows icon。
41
+ exe 產物為 `dist/VansPod.exe`,本機套件為 `dist/vanspod-0.4.4.tgz`;可在 Windows 用 `npm install -g <套件路徑>` 安裝測試。圖片、favicon、系統匣與移除腳本均包含在發佈產物中。更新 logo 後執行 `powershell.exe -NoProfile -File scripts/build-icon.ps1` 重建多尺寸 Windows icon。
42
42
 
43
43
  exe 發佈管道為本專案 GitHub Releases,npm 為公開 registry 的 [`vanspod`](https://www.npmjs.com/package/vanspod) 套件。更新時不要執行完整移除,否則會清除課堂資料。
44
44
 
@@ -46,12 +46,12 @@ exe 發佈管道為本專案 GitHub Releases,npm 為公開 registry 的 [`vans
46
46
 
47
47
  一般 push 不發佈;推送 `v*` tag 會在 Windows runner 安裝 Node.js 24、檢查型別、執行測試、打包並驗證 exe/npm 生命週期,全部通過後才建立 GitHub Release,最後發佈 npm 套件。學生從 Release 下載 `VansPod.exe`,同頁提供 `SHA256SUMS.txt`。
48
48
 
49
- 發版前同步 `package.json`、`package-lock.json` 與 `src/version.ts` 的版本;tag 必須等於 `v` 加版本號,否則流程失敗。以 `0.4.1` 為例:
49
+ 發版前同步 `package.json`、`package-lock.json` 與 `src/version.ts` 的版本;tag 必須等於 `v` 加版本號,否則流程失敗。以 `0.4.4` 為例:
50
50
 
51
51
  ```powershell
52
52
  git push origin master
53
- git tag -a v0.4.1 -m "VansPod 0.4.1"
54
- git push origin v0.4.1
53
+ git tag -a v0.4.4 -m "VansPod 0.4.4"
54
+ git push origin v0.4.4
55
55
  ```
56
56
 
57
57
  新版本使用新的版本號與 tag。相同 tag 的 Actions 重跑會更新該 Release 的產物。
@@ -8,6 +8,7 @@ const clientRoutes_1 = require("./clientRoutes");
8
8
  const node_util_1 = require("node:util");
9
9
  const courseCatalog_1 = require("./courseCatalog");
10
10
  const modelProxy_1 = require("./modelProxy");
11
+ const classroomKeyRejection_1 = require("./classroomKeyRejection");
11
12
  // 新工具加在最後,不改既有 id。
12
13
  exports.ENVIRONMENT_TOOLS = ["uv", "git", "node", "pwsh", "vscode"];
13
14
  exports.ENVIRONMENT_LABEL = {
@@ -19,6 +20,10 @@ exports.ENVIRONMENT_LABEL = {
19
20
  };
20
21
  const LOCAL_LIST_NOTE = "這是本機清單。";
21
22
  exports.COPIED_KEY_NOTICE = "已複製 Classroom API Key。請勿分享給不信任的人。";
23
+ const KEY_REJECTED_NOTICE = {
24
+ expired: "Classroom API Key 已過期,請按「清除連線」,再用老師給的新邀請碼重新兌換。",
25
+ invalid: "Classroom API Key 已失效,請按「清除連線」,再用老師給的新邀請碼重新兌換。",
26
+ };
22
27
  const INSTALL_UNAVAILABLE = "尚未指定專案資料夾,安裝不可用。";
23
28
  const ENVIRONMENT_ABORTED = "已中止安裝。系統安裝程式可能仍在執行,請等待結束或稍後重新安裝。";
24
29
  const PROXY_CLIENTS = ["codex", "claude", "copilot"];
@@ -80,6 +85,8 @@ class ClassroomApp {
80
85
  mustRestart = [];
81
86
  modelRestart = [];
82
87
  allowlistError;
88
+ // Router refused this Classroom API Key; only a new redeem or Clear resets it.
89
+ keyRejection;
83
90
  routeRestartNoted = false;
84
91
  vsCodeOrigin;
85
92
  sending = new Map();
@@ -784,6 +791,7 @@ class ClassroomApp {
784
791
  this.modelIds = [];
785
792
  this.modelProviders = [];
786
793
  this.allowlistError = undefined;
794
+ this.keyRejection = undefined;
787
795
  this.forgetModelChoices();
788
796
  this.catalog = undefined;
789
797
  this.catalogError = undefined;
@@ -1135,7 +1143,15 @@ class ClassroomApp {
1135
1143
  }
1136
1144
  }
1137
1145
  async reloadCatalog() {
1138
- return this.serialConnectionOperation(() => this.loadCatalog());
1146
+ return this.serialConnectionOperation(async () => {
1147
+ await this.loadCatalog();
1148
+ if (this.keyRejection)
1149
+ this.showKeyRejection(this.keyRejection);
1150
+ });
1151
+ }
1152
+ /** A refused Classroom API Key replaces any reload warning: the student has to redeem again. */
1153
+ showKeyRejection(rejection) {
1154
+ this.allowlistError = KEY_REJECTED_NOTICE[rejection];
1139
1155
  }
1140
1156
  async reloadAllowlist() {
1141
1157
  await this.detectClients();
@@ -1419,9 +1435,10 @@ class ClassroomApp {
1419
1435
  }
1420
1436
  const previous = this.mode === "classroom" ? this.modelIds.join("\0") : "";
1421
1437
  const refreshed = await this.loadModels(apiKey);
1422
- this.allowlistError = refreshed
1423
- ? undefined
1424
- : "重新載入課堂模型失敗,已保留上次成功的模型清單。";
1438
+ if (this.keyRejection)
1439
+ this.showKeyRejection(this.keyRejection);
1440
+ else
1441
+ this.allowlistError = refreshed ? undefined : "重新載入課堂模型失敗,已保留上次成功的模型清單。";
1425
1442
  const current = this.mode === "classroom" ? this.modelIds.join("\0") : "";
1426
1443
  if (previous !== current) {
1427
1444
  this.modelRestart = ["codex", "claude"].filter(client => this.clientModes[client] === "classroom");
@@ -1442,7 +1459,9 @@ class ClassroomApp {
1442
1459
  try {
1443
1460
  payload = await this.deps.router.fetchSessionModels(apiKey);
1444
1461
  }
1445
- catch {
1462
+ catch (error) {
1463
+ if (error instanceof classroomKeyRejection_1.ClassroomKeyRejectedError)
1464
+ this.keyRejection = error.reason;
1446
1465
  return false;
1447
1466
  }
1448
1467
  if (!Array.isArray(payload))
@@ -1618,6 +1637,7 @@ class ClassroomApp {
1618
1637
  this.connectionDraft = undefined;
1619
1638
  this.notice = undefined;
1620
1639
  this.allowlistError = undefined;
1640
+ this.keyRejection = undefined;
1621
1641
  this.catalog = undefined;
1622
1642
  this.catalogError = undefined;
1623
1643
  this.remoteCatalogHeld = false;
@@ -1774,6 +1794,8 @@ class ClassroomApp {
1774
1794
  this.mode = "native";
1775
1795
  await this.loadCatalog();
1776
1796
  await this.loadModels(connection.apiKey);
1797
+ if (this.keyRejection)
1798
+ this.showKeyRejection(this.keyRejection);
1777
1799
  if (connection.mode === "classroom" && this.modelIds.length > 0) {
1778
1800
  this.mode = "classroom";
1779
1801
  this.clientModes = connection.clientModes ?? { codex: "classroom", claude: "classroom" };
@@ -1866,7 +1888,12 @@ class ClassroomApp {
1866
1888
  try {
1867
1889
  body = await this.deps.catalog.fetchCourseCatalog(apiKey);
1868
1890
  }
1869
- catch {
1891
+ catch (error) {
1892
+ // The refused key is reported with the allowlist; the last catalog stays on screen.
1893
+ if (error instanceof classroomKeyRejection_1.ClassroomKeyRejectedError) {
1894
+ this.keyRejection = error.reason;
1895
+ return;
1896
+ }
1870
1897
  await this.loadLocalCatalog();
1871
1898
  return;
1872
1899
  }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ClassroomKeyRejectedError = void 0;
4
+ exports.assertClassroomKeyAccepted = assertClassroomKeyAccepted;
5
+ /** Router refused this Classroom API Key: the student has to redeem a new invite code. */
6
+ class ClassroomKeyRejectedError extends Error {
7
+ reason;
8
+ constructor(reason) {
9
+ super(`Classroom API Key ${reason}`);
10
+ this.reason = reason;
11
+ }
12
+ }
13
+ exports.ClassroomKeyRejectedError = ClassroomKeyRejectedError;
14
+ /** Throws when a Router reply to a request made with a Classroom API Key refuses that key. */
15
+ async function assertClassroomKeyAccepted(response) {
16
+ if (response.status === 401)
17
+ throw new ClassroomKeyRejectedError("expired");
18
+ // A school filter or proxy in front of Router also answers 403, with its own block page;
19
+ // only Router's own JSON reply means the key itself was refused.
20
+ if (response.status === 403 && await isRouterReply(response))
21
+ throw new ClassroomKeyRejectedError("invalid");
22
+ }
23
+ async function isRouterReply(response) {
24
+ try {
25
+ const body = await response.clone().json();
26
+ return !!body && typeof body === "object" && typeof body.detail === "string";
27
+ }
28
+ catch {
29
+ return false;
30
+ }
31
+ }
package/dist/entry.js CHANGED
@@ -7,6 +7,8 @@ const launcher_1 = require("./launcher");
7
7
  const promises_1 = __importDefault(require("node:fs/promises"));
8
8
  const node_path_1 = __importDefault(require("node:path"));
9
9
  const instance_1 = require("./instance");
10
+ const networkPreference_1 = require("./networkPreference");
11
+ (0, networkPreference_1.preferIpv4)();
10
12
  void (0, launcher_1.runCli)().catch(async (error) => {
11
13
  const message = error instanceof Error ? error.message : "VansPod 操作失敗。";
12
14
  if (process.env.VANSPOD_WORKER_TOKEN) {
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.environmentProgressScript = void 0;
4
4
  /**
5
- * 背景 Environment Install 的進度輪詢:頁面帶 data-environment-progress 時,每 500ms 讀 /environment-status
6
- * 更新每個工具的階段文字;安裝結束就重新整理頁面顯示結果。狀態在伺服器上,重新整理頁面後照樣接著輪詢。
5
+ * 背景 Environment Install 與第一次檢查的輪詢:頁面帶 data-environment-progress 時,每 500ms 讀 /environment-status
6
+ * 更新每個工具的階段文字;安裝或檢查結束就重新整理頁面顯示結果。狀態在伺服器上,重新整理頁面後照樣接著輪詢。
7
7
  */
8
8
  exports.environmentProgressScript = `
9
9
  (function () {
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.preferIpv4 = preferIpv4;
7
+ const node_dns_1 = __importDefault(require("node:dns"));
8
+ /**
9
+ * Some networks (an iPhone hotspot on a mobile carrier) connect to Router over IPv6 and then never
10
+ * answer, so a request hangs until it times out. IPv4 goes first; IPv6 is only the fallback.
11
+ */
12
+ function preferIpv4() {
13
+ node_dns_1.default.setDefaultResultOrder("ipv4first");
14
+ }
package/dist/page.js CHANGED
@@ -192,10 +192,14 @@ function environmentStageText(progress) {
192
192
  const percent = Math.min(100, Math.floor((progress.downloaded / progress.total) * 100));
193
193
  return `${text} ${megabytes(progress.downloaded)} / ${megabytes(progress.total)} MB(${percent}%)`;
194
194
  }
195
- /** GET /environment-status:背景 Environment Install 是否還在跑,以及這次安裝裡每個工具的階段文字。 */
195
+ /** 背景安裝或第一次檢查還沒結束時,頁面要輪詢,結束後重新整理顯示結果。 */
196
+ function environmentPolling(view) {
197
+ return view.environmentInstalling || environmentChecking(view);
198
+ }
199
+ /** GET /environment-status:背景 Environment Install 或第一次檢查是否還在跑,以及這次安裝裡每個工具的階段文字。 */
196
200
  function environmentStatus(view) {
197
201
  return {
198
- running: view.environmentInstalling,
202
+ running: environmentPolling(view),
199
203
  tools: view.tools.flatMap((tool) => (tool.progress ? [{ id: tool.id, stage: environmentStageText(tool.progress) }] : [])),
200
204
  };
201
205
  }
@@ -214,7 +218,7 @@ function environmentInner(view) {
214
218
  return `<label class="tool"><input type="checkbox" name="tool" value="${escapeHtml(tool.id)}"${checked}${off}> ${environmentIcons_1.environmentIcons[tool.id]}<span${title}>${escapeHtml(tool.label)}</span> ${mark}</label>`;
215
219
  })
216
220
  .join("");
217
- const polling = view.environmentInstalling ? " data-environment-progress" : "";
221
+ const polling = environmentPolling(view) ? " data-environment-progress" : "";
218
222
  const note = view.environmentNotice
219
223
  ? `<p class="hint">${escapeHtml(view.environmentNotice)}</p>`
220
224
  : "";
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fetchCourseCatalog = fetchCourseCatalog;
4
+ const classroomKeyRejection_1 = require("./classroomKeyRejection");
5
+ async function fetchCourseCatalog(options) {
6
+ const request = options.request ?? fetch;
7
+ const root = options.root.replace(/\/+$/, "");
8
+ const response = await request(`${root}/extension/course-catalog`, {
9
+ signal: AbortSignal.timeout(5_000),
10
+ method: "GET",
11
+ headers: {
12
+ Accept: "application/json",
13
+ Authorization: `Bearer ${options.apiKey}`,
14
+ },
15
+ });
16
+ await (0, classroomKeyRejection_1.assertClassroomKeyAccepted)(response);
17
+ if (!response.ok) {
18
+ throw new Error("course catalog failed");
19
+ }
20
+ const json = await response.json();
21
+ if (!json || typeof json !== "object") {
22
+ throw new Error("course catalog failed");
23
+ }
24
+ return json;
25
+ }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.fetchSessionModelProviders = fetchSessionModelProviders;
4
+ const classroomKeyRejection_1 = require("./classroomKeyRejection");
4
5
  function isProviderRecord(value) {
5
6
  if (!value || typeof value !== "object" || Array.isArray(value))
6
7
  return false;
@@ -22,6 +23,7 @@ async function fetchSessionModelProviders(options) {
22
23
  Authorization: `Bearer ${options.apiKey}`,
23
24
  },
24
25
  });
26
+ await (0, classroomKeyRejection_1.assertClassroomKeyAccepted)(response);
25
27
  if (!response.ok)
26
28
  throw new Error("session models failed");
27
29
  const payload = await response.json();
package/dist/start.js CHANGED
@@ -29,6 +29,7 @@ const clientRoutes_1 = require("./clientRoutes");
29
29
  const clientRouteRuntime_1 = require("./clientRouteRuntime");
30
30
  const vsCodeRouteSettings_1 = require("./vsCodeRouteSettings");
31
31
  const modelProxy_1 = require("./modelProxy");
32
+ const routerCourseCatalog_1 = require("./routerCourseCatalog");
32
33
  const routerSessionModels_1 = require("./routerSessionModels");
33
34
  const clientTraffic_1 = require("./clientTraffic");
34
35
  const instance_1 = require("./instance");
@@ -126,23 +127,7 @@ function isRedeemResult(value) {
126
127
  }));
127
128
  }
128
129
  async function fetchCourseCatalog(apiKey) {
129
- const root = routerBaseUrl();
130
- const response = await fetch(`${root}/extension/course-catalog`, {
131
- signal: AbortSignal.timeout(5_000),
132
- method: "GET",
133
- headers: {
134
- Accept: "application/json",
135
- Authorization: `Bearer ${apiKey}`,
136
- },
137
- });
138
- if (!response.ok) {
139
- throw new Error("course catalog failed");
140
- }
141
- const json = await response.json();
142
- if (!json || typeof json !== "object") {
143
- throw new Error("course catalog failed");
144
- }
145
- return json;
130
+ return (0, routerCourseCatalog_1.fetchCourseCatalog)({ root: routerBaseUrl(), apiKey });
146
131
  }
147
132
  async function readClassroomInstalls(folder) {
148
133
  try {
package/dist/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
- exports.VERSION = "0.4.1";
4
+ exports.VERSION = "0.4.4";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vanspod",
3
- "version": "0.4.1",
3
+ "version": "0.4.4",
4
4
  "bin": { "vanspod": "bin/vanspod.cjs" },
5
5
  "engines": { "node": ">=24" },
6
6
  "os": ["win32"],