vanspod 0.4.4 → 0.4.6

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.4.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.6.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.4` 為例:
49
+ 發版前同步 `package.json`、`package-lock.json` 與 `src/version.ts` 的版本;tag 必須等於 `v` 加版本號,否則流程失敗。以 `0.4.6` 為例:
50
50
 
51
51
  ```powershell
52
52
  git push origin master
53
- git tag -a v0.4.4 -m "VansPod 0.4.4"
54
- git push origin v0.4.4
53
+ git tag -a v0.4.6 -m "VansPod 0.4.6"
54
+ git push origin v0.4.6
55
55
  ```
56
56
 
57
57
  新版本使用新的版本號與 tag。相同 tag 的 Actions 重跑會更新該 Release 的產物。
@@ -9,6 +9,7 @@ const node_util_1 = require("node:util");
9
9
  const courseCatalog_1 = require("./courseCatalog");
10
10
  const modelProxy_1 = require("./modelProxy");
11
11
  const classroomKeyRejection_1 = require("./classroomKeyRejection");
12
+ const CLIENT_ROUTE_OF = { codex: "codex", claude: "claudeCode", vscode: "vsCodeChat" };
12
13
  // 新工具加在最後,不改既有 id。
13
14
  exports.ENVIRONMENT_TOOLS = ["uv", "git", "node", "pwsh", "vscode"];
14
15
  exports.ENVIRONMENT_LABEL = {
@@ -24,6 +25,9 @@ const KEY_REJECTED_NOTICE = {
24
25
  expired: "Classroom API Key 已過期,請按「清除連線」,再用老師給的新邀請碼重新兌換。",
25
26
  invalid: "Classroom API Key 已失效,請按「清除連線」,再用老師給的新邀請碼重新兌換。",
26
27
  };
28
+ const MODELS_UNLOADED_NOTICE = "無法載入課堂模型,請按「↻ 更新」再試。";
29
+ const RESTORE_FETCH_ATTEMPTS = 3;
30
+ const RESTORE_FETCH_RETRY_MS = 1_000;
27
31
  const INSTALL_UNAVAILABLE = "尚未指定專案資料夾,安裝不可用。";
28
32
  const ENVIRONMENT_ABORTED = "已中止安裝。系統安裝程式可能仍在執行,請等待結束或稍後重新安裝。";
29
33
  const PROXY_CLIENTS = ["codex", "claude", "copilot"];
@@ -87,6 +91,11 @@ class ClassroomApp {
87
91
  allowlistError;
88
92
  // Router refused this Classroom API Key; only a new redeem or Clear resets it.
89
93
  keyRejection;
94
+ // 啟動時抓不到 Session Model Allowlist 而暫時退回 Native 的 Client Route;設定檔仍保留 Classroom,
95
+ // 「更新」抓到模型後切回去。學生自己切換或換堂後就不再代為恢復。
96
+ classroomAwaitingModels = new Set();
97
+ // 恢復 Classroom Connection 時重試後仍抓不到 Session Model Allowlist;和老師沒開放任何模型不同。
98
+ allowlistUnloaded = false;
90
99
  routeRestartNoted = false;
91
100
  vsCodeOrigin;
92
101
  sending = new Map();
@@ -792,6 +801,8 @@ class ClassroomApp {
792
801
  this.modelProviders = [];
793
802
  this.allowlistError = undefined;
794
803
  this.keyRejection = undefined;
804
+ this.allowlistUnloaded = false;
805
+ this.classroomAwaitingModels.clear();
795
806
  this.forgetModelChoices();
796
807
  this.catalog = undefined;
797
808
  this.catalogError = undefined;
@@ -887,6 +898,18 @@ class ClassroomApp {
887
898
  return this.serialConnectionOperation(() => client ? this.setClientSwitch(mode, client) : this.setSwitchNow(mode));
888
899
  }
889
900
  async setClientSwitch(mode, client) {
901
+ // 學生自己選了 Native,就不再代為恢復啟動前的 Classroom;路由此時已是 Native,只差存檔。
902
+ // 選 Classroom 則照常切換,抓不到模型被拒時仍等「更新」恢復。
903
+ const route = CLIENT_ROUTE_OF[client];
904
+ if (mode === "native" && this.classroomAwaitingModels.delete(route)) {
905
+ try {
906
+ await this.saveClientRoutePreferences();
907
+ }
908
+ catch {
909
+ this.notice = "無法儲存 Native 模式,重新啟動仍可能恢復 Classroom;請重試。";
910
+ }
911
+ return;
912
+ }
890
913
  if (client === "vscode") {
891
914
  await this.setVsCodeClientRouteSwitch(mode);
892
915
  return;
@@ -1164,12 +1187,41 @@ class ClassroomApp {
1164
1187
  return this.serialConnectionOperation(() => this.reloadAllowlistNow());
1165
1188
  }
1166
1189
  async saveClientRoutePreferences() {
1190
+ const savedMode = (id) => this.classroomAwaitingModels.has(id) ? "classroom" : this.clientRoutes[id].mode;
1167
1191
  await this.deps.clientRouteSettings?.save({
1168
- codex: { mode: this.clientRoutes.codex.mode, adapter: this.clientRoutes.codex.adapter },
1169
- claudeCode: { mode: this.clientRoutes.claudeCode.mode, adapter: this.clientRoutes.claudeCode.adapter },
1170
- vsCodeChat: { mode: this.clientRoutes.vsCodeChat.mode, adapter: this.clientRoutes.vsCodeChat.adapter },
1192
+ codex: { mode: savedMode("codex"), adapter: this.clientRoutes.codex.adapter },
1193
+ claudeCode: { mode: savedMode("claudeCode"), adapter: this.clientRoutes.claudeCode.adapter },
1194
+ vsCodeChat: { mode: savedMode("vsCodeChat"), adapter: this.clientRoutes.vsCodeChat.adapter },
1171
1195
  });
1172
1196
  }
1197
+ noteClassroomAwaitingModels(route) {
1198
+ if (this.connected && this.allowlistUnloaded)
1199
+ this.classroomAwaitingModels.add(route);
1200
+ }
1201
+ /** 「更新」抓到 Session Model Allowlist 後,把啟動時暫時退回 Native 的 Client Route 切回 Classroom。 */
1202
+ // 老師沒開放任何模型、或路由已紅燈/灰燈時不切回;紅燈恢復後仍須學生自己切入 Classroom(ADR-0006)。
1203
+ async resumeClassroomAwaitingModels() {
1204
+ const waiting = [...this.classroomAwaitingModels];
1205
+ if (waiting.length === 0)
1206
+ return;
1207
+ this.classroomAwaitingModels.clear();
1208
+ for (const route of waiting) {
1209
+ const health = this.clientRoutes[route].health;
1210
+ if (this.modelIds.length === 0 || health === "red" || health === "gray")
1211
+ continue;
1212
+ if (route === "codex")
1213
+ await this.setCodexClientRouteSwitch("classroom");
1214
+ else if (route === "claudeCode")
1215
+ await this.setClaudeCodeClientRouteSwitch("classroom");
1216
+ else
1217
+ await this.setVsCodeClientRouteSwitch("classroom");
1218
+ }
1219
+ // 沒切回的路由此時才把 Native 寫進設定檔。
1220
+ try {
1221
+ await this.saveClientRoutePreferences();
1222
+ }
1223
+ catch { /* Route state stays visible; the next save retries. */ }
1224
+ }
1173
1225
  async startCodexRoute() {
1174
1226
  const runtime = this.deps.clientRouteRuntime;
1175
1227
  if (!runtime)
@@ -1206,6 +1258,7 @@ class ClassroomApp {
1206
1258
  }
1207
1259
  lifecycle = this.codexLifecycle(); // start() supplied the route's authoritative origin.
1208
1260
  if (this.clientRoutes.codex.mode === "classroom" && (!this.connected || this.modelIds.length === 0)) {
1261
+ this.noteClassroomAwaitingModels("codex");
1209
1262
  lifecycle.setMode("native");
1210
1263
  try {
1211
1264
  await this.saveClientRoutePreferences();
@@ -1291,6 +1344,8 @@ class ClassroomApp {
1291
1344
  this.settleVsCodePublish(result?.changed);
1292
1345
  }
1293
1346
  else {
1347
+ if (this.clientRoutes.vsCodeChat.mode === "classroom")
1348
+ this.noteClassroomAwaitingModels("vsCodeChat");
1294
1349
  this.clientRoutes.vsCodeChat.mode = "native";
1295
1350
  await this.deps.vsCodeRouteSettings?.initializeNative();
1296
1351
  this.clientRoutes.vsCodeChat.health = "green";
@@ -1359,6 +1414,7 @@ class ClassroomApp {
1359
1414
  return;
1360
1415
  }
1361
1416
  if (route.mode === "classroom" && (!this.connected || this.modelIds.length === 0)) {
1417
+ this.noteClassroomAwaitingModels("claudeCode");
1362
1418
  route.mode = "native";
1363
1419
  try {
1364
1420
  await this.saveClientRoutePreferences();
@@ -1437,8 +1493,14 @@ class ClassroomApp {
1437
1493
  const refreshed = await this.loadModels(apiKey);
1438
1494
  if (this.keyRejection)
1439
1495
  this.showKeyRejection(this.keyRejection);
1496
+ else if (refreshed)
1497
+ this.allowlistError = undefined;
1440
1498
  else
1441
- this.allowlistError = refreshed ? undefined : "重新載入課堂模型失敗,已保留上次成功的模型清單。";
1499
+ this.allowlistError = this.allowlistUnloaded ? MODELS_UNLOADED_NOTICE : "重新載入課堂模型失敗,已保留上次成功的模型清單。";
1500
+ if (refreshed) {
1501
+ this.allowlistUnloaded = false;
1502
+ await this.resumeClassroomAwaitingModels();
1503
+ }
1442
1504
  const current = this.mode === "classroom" ? this.modelIds.join("\0") : "";
1443
1505
  if (previous !== current) {
1444
1506
  this.modelRestart = ["codex", "claude"].filter(client => this.clientModes[client] === "classroom");
@@ -1454,10 +1516,10 @@ class ClassroomApp {
1454
1516
  }
1455
1517
  }
1456
1518
  }
1457
- async loadModels(apiKey) {
1519
+ async loadModels(apiKey, attempts = 1) {
1458
1520
  let payload;
1459
1521
  try {
1460
- payload = await this.deps.router.fetchSessionModels(apiKey);
1522
+ payload = await fetchWithRetries(attempts, () => this.deps.router.fetchSessionModels(apiKey));
1461
1523
  }
1462
1524
  catch (error) {
1463
1525
  if (error instanceof classroomKeyRejection_1.ClassroomKeyRejectedError)
@@ -1638,6 +1700,8 @@ class ClassroomApp {
1638
1700
  this.notice = undefined;
1639
1701
  this.allowlistError = undefined;
1640
1702
  this.keyRejection = undefined;
1703
+ this.allowlistUnloaded = false;
1704
+ this.classroomAwaitingModels.clear();
1641
1705
  this.catalog = undefined;
1642
1706
  this.catalogError = undefined;
1643
1707
  this.remoteCatalogHeld = false;
@@ -1792,10 +1856,16 @@ class ClassroomApp {
1792
1856
  this.hiddenKeys.add(connection.apiKey);
1793
1857
  this.applyConnectionIdentity(connection);
1794
1858
  this.mode = "native";
1795
- await this.loadCatalog();
1796
- await this.loadModels(connection.apiKey);
1859
+ // 版本更新後重新啟動時網路可能還沒穩;恢復 Classroom Connection 時抓不到 Course Catalog
1860
+ // 或 Session Model Allowlist 就稍候再試,才退回本機的 classroom-installs.yaml 或 Native。
1861
+ await this.loadCatalog(RESTORE_FETCH_ATTEMPTS);
1862
+ const modelsLoaded = await this.loadModels(connection.apiKey, RESTORE_FETCH_ATTEMPTS);
1797
1863
  if (this.keyRejection)
1798
1864
  this.showKeyRejection(this.keyRejection);
1865
+ else if (!modelsLoaded) {
1866
+ this.allowlistUnloaded = true;
1867
+ this.allowlistError = MODELS_UNLOADED_NOTICE;
1868
+ }
1799
1869
  if (connection.mode === "classroom" && this.modelIds.length > 0) {
1800
1870
  this.mode = "classroom";
1801
1871
  this.clientModes = connection.clientModes ?? { codex: "classroom", claude: "classroom" };
@@ -1873,7 +1943,7 @@ class ClassroomApp {
1873
1943
  closeWindow() {
1874
1944
  // 關分頁不停止代理,也不改路由。
1875
1945
  }
1876
- async loadCatalog() {
1946
+ async loadCatalog(attempts = 1) {
1877
1947
  if (!this.connected) {
1878
1948
  return;
1879
1949
  }
@@ -1886,7 +1956,7 @@ class ClassroomApp {
1886
1956
  }
1887
1957
  let body;
1888
1958
  try {
1889
- body = await this.deps.catalog.fetchCourseCatalog(apiKey);
1959
+ body = await fetchWithRetries(attempts, () => this.deps.catalog.fetchCourseCatalog(apiKey));
1890
1960
  }
1891
1961
  catch (error) {
1892
1962
  // The refused key is reported with the allowlist; the last catalog stays on screen.
@@ -1941,6 +2011,19 @@ class ClassroomApp {
1941
2011
  }
1942
2012
  }
1943
2013
  exports.ClassroomApp = ClassroomApp;
2014
+ /** 失敗時稍候再試,最多 attempts 次;Router 拒絕 Classroom API Key 時再試也沒用,立刻放棄。 */
2015
+ async function fetchWithRetries(attempts, fetch) {
2016
+ for (let attempt = 1;; attempt++) {
2017
+ try {
2018
+ return await fetch();
2019
+ }
2020
+ catch (error) {
2021
+ if (error instanceof classroomKeyRejection_1.ClassroomKeyRejectedError || attempt >= attempts)
2022
+ throw error;
2023
+ await new Promise(resolve => setTimeout(resolve, RESTORE_FETCH_RETRY_MS));
2024
+ }
2025
+ }
2026
+ }
1944
2027
  /** 安裝後驗證未通過時的提示;安裝程式要求重新開機時,請學生重開機後再檢查。 */
1945
2028
  function environmentInstallFailure(label, result, verified) {
1946
2029
  const rejected = result?.failure
package/dist/start.js CHANGED
@@ -166,6 +166,8 @@ function isEnvironmentTool(value) {
166
166
  const MAC_PWSH_PAGE = "https://learn.microsoft.com/powershell/scripting/install/installing-powershell-on-macos";
167
167
  // VS Code 的直接下載安裝只做 Windows;macOS 開啟官方下載頁,由學生自己安裝。
168
168
  const MAC_VSCODE_PAGE = "https://code.visualstudio.com/download";
169
+ /** 首頁最多等啟動這麼久;涵蓋 Course Catalog 重試與 Session Model Allowlist 的抓取。 */
170
+ const PAGE_STARTUP_WAIT_MS = 30_000;
169
171
  /** macOS 維持原本的偵測:找得到且有輸出版本就算已就緒(ADR-0008:第一版只完整支援 Windows)。 */
170
172
  function probeMacEnvironment(tool) {
171
173
  return (0, commandRunner_1.collectOutput)(tool === "vscode" ? "code" : tool, ["--version"]).then((result) => {
@@ -371,6 +373,9 @@ async function main(instance) {
371
373
  },
372
374
  });
373
375
  let ready = false;
376
+ // 和 ready 不同:啟動失敗但服務保留時也會放行,頁面才能顯示 startupError。
377
+ let settleStartup;
378
+ const startupSettled = new Promise(resolve => { settleStartup = resolve; });
374
379
  let startupError;
375
380
  let tray;
376
381
  let trayError;
@@ -565,6 +570,9 @@ async function main(instance) {
565
570
  return;
566
571
  }
567
572
  if (req.method === "GET" && (pathname === "/" || pathname === "/index.html")) {
573
+ // 版本更新後重新啟動時,舊分頁一拿到首頁就重新整理頁面;
574
+ // 等 Classroom Connection 恢復、Course Catalog 載入後才給頁面,免得課程安裝停在尚未載入的狀態。
575
+ await startupSettled;
568
576
  const variant = parsed.searchParams.get("variant") ?? "";
569
577
  const html = process.env.NODE_ENV !== "production" && (0, pagePrototype_1.isPrototypeVariant)(variant)
570
578
  ? (0, pagePrototype_1.renderPrototypePage)(app.pageView(), variant)
@@ -831,6 +839,8 @@ async function main(instance) {
831
839
  await clientRouteRuntime.stop();
832
840
  throw error;
833
841
  }
842
+ // 啟動卡住時不讓首頁無限等待;顯示未完成的頁面總比一直轉圈好。
843
+ setTimeout(settleStartup, PAGE_STARTUP_WAIT_MS).unref();
834
844
  try {
835
845
  await app.start();
836
846
  ready = true;
@@ -852,6 +862,9 @@ async function main(instance) {
852
862
  }
853
863
  startupError += " 設定恢復未完成,服務已保留;修復後請重試 vanspod stop。";
854
864
  }
865
+ finally {
866
+ settleStartup();
867
+ }
855
868
  versionUpdate.start();
856
869
  // 系統匣起不來時 VansPod 仍要繼續;頁面會提示改用頁面上的「結束 VansPod」。
857
870
  if (runtimeOptions.desktop && process.platform === "win32" && instance) {
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.4";
4
+ exports.VERSION = "0.4.6";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vanspod",
3
- "version": "0.4.4",
3
+ "version": "0.4.6",
4
4
  "bin": { "vanspod": "bin/vanspod.cjs" },
5
5
  "engines": { "node": ">=24" },
6
6
  "os": ["win32"],