vanspod 0.4.3 → 0.4.5
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 +4 -4
- package/dist/classroomApp.js +49 -13
- package/dist/classroomKeyRejection.js +31 -0
- package/dist/entry.js +2 -0
- package/dist/networkPreference.js +14 -0
- package/dist/routerCourseCatalog.js +25 -0
- package/dist/routerSessionModels.js +2 -0
- package/dist/start.js +15 -17
- package/dist/version.js +1 -1
- package/package.json +1 -1
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.
|
|
41
|
+
exe 產物為 `dist/VansPod.exe`,本機套件為 `dist/vanspod-0.4.5.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.
|
|
49
|
+
發版前同步 `package.json`、`package-lock.json` 與 `src/version.ts` 的版本;tag 必須等於 `v` 加版本號,否則流程失敗。以 `0.4.5` 為例:
|
|
50
50
|
|
|
51
51
|
```powershell
|
|
52
52
|
git push origin master
|
|
53
|
-
git tag -a v0.4.
|
|
54
|
-
git push origin v0.4.
|
|
53
|
+
git tag -a v0.4.5 -m "VansPod 0.4.5"
|
|
54
|
+
git push origin v0.4.5
|
|
55
55
|
```
|
|
56
56
|
|
|
57
57
|
新版本使用新的版本號與 tag。相同 tag 的 Actions 重跑會更新該 Release 的產物。
|
package/dist/classroomApp.js
CHANGED
|
@@ -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,12 @@ 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
|
+
};
|
|
27
|
+
const RESTORE_CATALOG_ATTEMPTS = 3;
|
|
28
|
+
const RESTORE_CATALOG_RETRY_MS = 1_000;
|
|
22
29
|
const INSTALL_UNAVAILABLE = "尚未指定專案資料夾,安裝不可用。";
|
|
23
30
|
const ENVIRONMENT_ABORTED = "已中止安裝。系統安裝程式可能仍在執行,請等待結束或稍後重新安裝。";
|
|
24
31
|
const PROXY_CLIENTS = ["codex", "claude", "copilot"];
|
|
@@ -80,6 +87,8 @@ class ClassroomApp {
|
|
|
80
87
|
mustRestart = [];
|
|
81
88
|
modelRestart = [];
|
|
82
89
|
allowlistError;
|
|
90
|
+
// Router refused this Classroom API Key; only a new redeem or Clear resets it.
|
|
91
|
+
keyRejection;
|
|
83
92
|
routeRestartNoted = false;
|
|
84
93
|
vsCodeOrigin;
|
|
85
94
|
sending = new Map();
|
|
@@ -784,6 +793,7 @@ class ClassroomApp {
|
|
|
784
793
|
this.modelIds = [];
|
|
785
794
|
this.modelProviders = [];
|
|
786
795
|
this.allowlistError = undefined;
|
|
796
|
+
this.keyRejection = undefined;
|
|
787
797
|
this.forgetModelChoices();
|
|
788
798
|
this.catalog = undefined;
|
|
789
799
|
this.catalogError = undefined;
|
|
@@ -1135,7 +1145,15 @@ class ClassroomApp {
|
|
|
1135
1145
|
}
|
|
1136
1146
|
}
|
|
1137
1147
|
async reloadCatalog() {
|
|
1138
|
-
return this.serialConnectionOperation(() =>
|
|
1148
|
+
return this.serialConnectionOperation(async () => {
|
|
1149
|
+
await this.loadCatalog();
|
|
1150
|
+
if (this.keyRejection)
|
|
1151
|
+
this.showKeyRejection(this.keyRejection);
|
|
1152
|
+
});
|
|
1153
|
+
}
|
|
1154
|
+
/** A refused Classroom API Key replaces any reload warning: the student has to redeem again. */
|
|
1155
|
+
showKeyRejection(rejection) {
|
|
1156
|
+
this.allowlistError = KEY_REJECTED_NOTICE[rejection];
|
|
1139
1157
|
}
|
|
1140
1158
|
async reloadAllowlist() {
|
|
1141
1159
|
await this.detectClients();
|
|
@@ -1419,9 +1437,10 @@ class ClassroomApp {
|
|
|
1419
1437
|
}
|
|
1420
1438
|
const previous = this.mode === "classroom" ? this.modelIds.join("\0") : "";
|
|
1421
1439
|
const refreshed = await this.loadModels(apiKey);
|
|
1422
|
-
this.
|
|
1423
|
-
|
|
1424
|
-
|
|
1440
|
+
if (this.keyRejection)
|
|
1441
|
+
this.showKeyRejection(this.keyRejection);
|
|
1442
|
+
else
|
|
1443
|
+
this.allowlistError = refreshed ? undefined : "重新載入課堂模型失敗,已保留上次成功的模型清單。";
|
|
1425
1444
|
const current = this.mode === "classroom" ? this.modelIds.join("\0") : "";
|
|
1426
1445
|
if (previous !== current) {
|
|
1427
1446
|
this.modelRestart = ["codex", "claude"].filter(client => this.clientModes[client] === "classroom");
|
|
@@ -1442,7 +1461,9 @@ class ClassroomApp {
|
|
|
1442
1461
|
try {
|
|
1443
1462
|
payload = await this.deps.router.fetchSessionModels(apiKey);
|
|
1444
1463
|
}
|
|
1445
|
-
catch {
|
|
1464
|
+
catch (error) {
|
|
1465
|
+
if (error instanceof classroomKeyRejection_1.ClassroomKeyRejectedError)
|
|
1466
|
+
this.keyRejection = error.reason;
|
|
1446
1467
|
return false;
|
|
1447
1468
|
}
|
|
1448
1469
|
if (!Array.isArray(payload))
|
|
@@ -1618,6 +1639,7 @@ class ClassroomApp {
|
|
|
1618
1639
|
this.connectionDraft = undefined;
|
|
1619
1640
|
this.notice = undefined;
|
|
1620
1641
|
this.allowlistError = undefined;
|
|
1642
|
+
this.keyRejection = undefined;
|
|
1621
1643
|
this.catalog = undefined;
|
|
1622
1644
|
this.catalogError = undefined;
|
|
1623
1645
|
this.remoteCatalogHeld = false;
|
|
@@ -1772,8 +1794,11 @@ class ClassroomApp {
|
|
|
1772
1794
|
this.hiddenKeys.add(connection.apiKey);
|
|
1773
1795
|
this.applyConnectionIdentity(connection);
|
|
1774
1796
|
this.mode = "native";
|
|
1775
|
-
|
|
1797
|
+
// 版本更新後重新啟動時網路可能還沒穩;恢復 Classroom Connection 時抓不到 Course Catalog 就稍候再試,才退回本機的 classroom-installs.yaml。
|
|
1798
|
+
await this.loadCatalog(RESTORE_CATALOG_ATTEMPTS);
|
|
1776
1799
|
await this.loadModels(connection.apiKey);
|
|
1800
|
+
if (this.keyRejection)
|
|
1801
|
+
this.showKeyRejection(this.keyRejection);
|
|
1777
1802
|
if (connection.mode === "classroom" && this.modelIds.length > 0) {
|
|
1778
1803
|
this.mode = "classroom";
|
|
1779
1804
|
this.clientModes = connection.clientModes ?? { codex: "classroom", claude: "classroom" };
|
|
@@ -1851,7 +1876,7 @@ class ClassroomApp {
|
|
|
1851
1876
|
closeWindow() {
|
|
1852
1877
|
// 關分頁不停止代理,也不改路由。
|
|
1853
1878
|
}
|
|
1854
|
-
async loadCatalog() {
|
|
1879
|
+
async loadCatalog(attempts = 1) {
|
|
1855
1880
|
if (!this.connected) {
|
|
1856
1881
|
return;
|
|
1857
1882
|
}
|
|
@@ -1863,12 +1888,23 @@ class ClassroomApp {
|
|
|
1863
1888
|
return;
|
|
1864
1889
|
}
|
|
1865
1890
|
let body;
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1891
|
+
for (let attempt = 1;; attempt++) {
|
|
1892
|
+
try {
|
|
1893
|
+
body = await this.deps.catalog.fetchCourseCatalog(apiKey);
|
|
1894
|
+
break;
|
|
1895
|
+
}
|
|
1896
|
+
catch (error) {
|
|
1897
|
+
// The refused key is reported with the allowlist; the last catalog stays on screen.
|
|
1898
|
+
if (error instanceof classroomKeyRejection_1.ClassroomKeyRejectedError) {
|
|
1899
|
+
this.keyRejection = error.reason;
|
|
1900
|
+
return;
|
|
1901
|
+
}
|
|
1902
|
+
if (attempt >= attempts) {
|
|
1903
|
+
await this.loadLocalCatalog();
|
|
1904
|
+
return;
|
|
1905
|
+
}
|
|
1906
|
+
await new Promise(resolve => setTimeout(resolve, RESTORE_CATALOG_RETRY_MS));
|
|
1907
|
+
}
|
|
1872
1908
|
}
|
|
1873
1909
|
const yaml = usableCatalogYaml(body?.course_catalog_yaml);
|
|
1874
1910
|
if (yaml === undefined) {
|
|
@@ -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) {
|
|
@@ -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
|
+
}
|
|
@@ -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
|
-
|
|
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 {
|
|
@@ -181,6 +166,8 @@ function isEnvironmentTool(value) {
|
|
|
181
166
|
const MAC_PWSH_PAGE = "https://learn.microsoft.com/powershell/scripting/install/installing-powershell-on-macos";
|
|
182
167
|
// VS Code 的直接下載安裝只做 Windows;macOS 開啟官方下載頁,由學生自己安裝。
|
|
183
168
|
const MAC_VSCODE_PAGE = "https://code.visualstudio.com/download";
|
|
169
|
+
/** 首頁最多等啟動這麼久;涵蓋 Course Catalog 重試與 Session Model Allowlist 的抓取。 */
|
|
170
|
+
const PAGE_STARTUP_WAIT_MS = 30_000;
|
|
184
171
|
/** macOS 維持原本的偵測:找得到且有輸出版本就算已就緒(ADR-0008:第一版只完整支援 Windows)。 */
|
|
185
172
|
function probeMacEnvironment(tool) {
|
|
186
173
|
return (0, commandRunner_1.collectOutput)(tool === "vscode" ? "code" : tool, ["--version"]).then((result) => {
|
|
@@ -386,6 +373,9 @@ async function main(instance) {
|
|
|
386
373
|
},
|
|
387
374
|
});
|
|
388
375
|
let ready = false;
|
|
376
|
+
// 和 ready 不同:啟動失敗但服務保留時也會放行,頁面才能顯示 startupError。
|
|
377
|
+
let settleStartup;
|
|
378
|
+
const startupSettled = new Promise(resolve => { settleStartup = resolve; });
|
|
389
379
|
let startupError;
|
|
390
380
|
let tray;
|
|
391
381
|
let trayError;
|
|
@@ -580,6 +570,9 @@ async function main(instance) {
|
|
|
580
570
|
return;
|
|
581
571
|
}
|
|
582
572
|
if (req.method === "GET" && (pathname === "/" || pathname === "/index.html")) {
|
|
573
|
+
// 版本更新後重新啟動時,舊分頁一拿到首頁就重新整理頁面;
|
|
574
|
+
// 等 Classroom Connection 恢復、Course Catalog 載入後才給頁面,免得課程安裝停在尚未載入的狀態。
|
|
575
|
+
await startupSettled;
|
|
583
576
|
const variant = parsed.searchParams.get("variant") ?? "";
|
|
584
577
|
const html = process.env.NODE_ENV !== "production" && (0, pagePrototype_1.isPrototypeVariant)(variant)
|
|
585
578
|
? (0, pagePrototype_1.renderPrototypePage)(app.pageView(), variant)
|
|
@@ -846,6 +839,8 @@ async function main(instance) {
|
|
|
846
839
|
await clientRouteRuntime.stop();
|
|
847
840
|
throw error;
|
|
848
841
|
}
|
|
842
|
+
// 啟動卡住時不讓首頁無限等待;顯示未完成的頁面總比一直轉圈好。
|
|
843
|
+
setTimeout(settleStartup, PAGE_STARTUP_WAIT_MS).unref();
|
|
849
844
|
try {
|
|
850
845
|
await app.start();
|
|
851
846
|
ready = true;
|
|
@@ -867,6 +862,9 @@ async function main(instance) {
|
|
|
867
862
|
}
|
|
868
863
|
startupError += " 設定恢復未完成,服務已保留;修復後請重試 vanspod stop。";
|
|
869
864
|
}
|
|
865
|
+
finally {
|
|
866
|
+
settleStartup();
|
|
867
|
+
}
|
|
870
868
|
versionUpdate.start();
|
|
871
869
|
// 系統匣起不來時 VansPod 仍要繼續;頁面會提示改用頁面上的「結束 VansPod」。
|
|
872
870
|
if (runtimeOptions.desktop && process.platform === "win32" && instance) {
|
package/dist/version.js
CHANGED