vanspod 0.4.15 → 0.5.1
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 +5 -5
- package/dist/classroomApp.js +185 -56
- package/dist/classroomKeyRejection.js +1 -1
- package/dist/codexWebSearch.js +1 -1
- package/dist/desktop.js +13 -3
- package/dist/deviceConnection.js +13 -2
- package/dist/html.js +12 -0
- package/dist/legacyMigration.js +10 -44
- package/dist/localCommands.js +82 -119
- package/dist/localToolApproval.js +81 -4
- package/dist/localTools.js +31 -8
- package/dist/modelStatus.js +14 -12
- package/dist/page.js +322 -132
- package/dist/platformStorage.js +1 -1
- package/dist/remoteAgentLog.js +126 -0
- package/dist/remoteAgentLogView.js +421 -0
- package/dist/saveImage.js +26 -0
- package/dist/secureStorage.js +17 -5
- package/dist/settingsActions.js +2 -10
- package/dist/start.js +86 -49
- package/dist/storageErrors.js +4 -5
- package/dist/trayChannel.js +25 -6
- package/dist/version.js +1 -1
- package/package.json +2 -2
- package/scripts/tray.ps1 +141 -11
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.
|
|
41
|
+
exe 產物為 `dist/VansPod.exe`,本機套件為 `dist/vanspod-0.5.1.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`。Release 另附 brotli 壓縮的 `VansPod.exe.br`(約三分之一大小),程式內更新只下載這份,解壓後再比對 `VansPod.exe` 的 SHA-256;SHA256SUMS 沒列出它的舊版 Release 則下載完整 exe。
|
|
48
48
|
|
|
49
|
-
發版前同步 `package.json`、`package-lock.json` 與 `src/version.ts` 的版本;tag 必須等於 `v` 加版本號,否則流程失敗。以 `0.
|
|
49
|
+
發版前同步 `package.json`、`package-lock.json` 與 `src/version.ts` 的版本;tag 必須等於 `v` 加版本號,否則流程失敗。以 `0.5.1` 為例:
|
|
50
50
|
|
|
51
51
|
```powershell
|
|
52
52
|
git push origin master
|
|
53
|
-
git tag -a v0.
|
|
54
|
-
git push origin v0.
|
|
53
|
+
git tag -a v0.5.1 -m "VansPod 0.5.1"
|
|
54
|
+
git push origin v0.5.1
|
|
55
55
|
```
|
|
56
56
|
|
|
57
57
|
新版本使用新的版本號與 tag。相同 tag 的 Actions 重跑會更新該 Release 的產物。
|
|
@@ -70,7 +70,7 @@ GitHub Release 建立後,同一流程以 npm Trusted Publishing(OIDC)發
|
|
|
70
70
|
|
|
71
71
|
## Classroom 上游 API
|
|
72
72
|
|
|
73
|
-
模型區提供各客戶端的上游 API 選項:Codex 可選 Responses/Chat,Claude Code 可選 Responses/Chat/Messages,兩者均預設 Responses。選擇保存在使用者目錄的 `.vanspod/settings.json
|
|
73
|
+
模型區提供各客戶端的上游 API 選項:Codex 可選 Responses/Chat,Claude Code 可選 Responses/Chat/Messages,兩者均預設 Responses。選擇保存在使用者目錄的 `.vanspod/settings.json`,與課堂憑證分開;重啟、切換模型、清除或重新連線課堂不會移除偏好。此選項只影響 Classroom 模式的下一個請求。
|
|
74
74
|
|
|
75
75
|
共用 Adapter 介面下的三個實作負責請求、上游呼叫與回應轉換;所有程式都在 VansPod 內,不需要 opencodex 專案。支援多輪文字、圖片輸入、函式工具往返與串流/非串流;Chat 路徑沿用 Codex 自訂工具的文字包裝及 `apply_patch` 修復。
|
|
76
76
|
|
package/dist/classroomApp.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ClassroomApp = exports.COPIED_KEY_NOTICE = exports.ENVIRONMENT_LABEL = exports.ENVIRONMENT_TOOLS = void 0;
|
|
3
|
+
exports.ClassroomApp = exports.COPIED_KEY_NOTICE = exports.AUTO_APPROVAL_NEEDS_ACCESS = exports.AUTO_APPROVAL_DURATIONS = exports.ENVIRONMENT_LABEL = exports.ENVIRONMENT_TOOLS = exports.CONNECTION_CANCELLED = exports.CONNECT_TIMEOUT_MS = exports.OAUTH_CLIENT_ID = void 0;
|
|
4
|
+
const node_crypto_1 = require("node:crypto");
|
|
4
5
|
const secureStorage_1 = require("./secureStorage");
|
|
5
6
|
const storageErrors_1 = require("./storageErrors");
|
|
6
7
|
const adapterSettings_1 = require("./adapterSettings");
|
|
@@ -9,6 +10,13 @@ const node_util_1 = require("node:util");
|
|
|
9
10
|
const courseCatalog_1 = require("./courseCatalog");
|
|
10
11
|
const modelProxy_1 = require("./modelProxy");
|
|
11
12
|
const classroomKeyRejection_1 = require("./classroomKeyRejection");
|
|
13
|
+
const localToolApproval_1 = require("./localToolApproval");
|
|
14
|
+
/** The public OAuth Client of VansPod on the Router. */
|
|
15
|
+
exports.OAUTH_CLIENT_ID = "vanspod";
|
|
16
|
+
/** After this long without a callback, the connection attempt ends by itself. */
|
|
17
|
+
exports.CONNECT_TIMEOUT_MS = 10 * 60_000;
|
|
18
|
+
exports.CONNECTION_CANCELLED = "連線已取消";
|
|
19
|
+
const CONNECTION_FAILED = "連線失敗,請再按一次「連線」。";
|
|
12
20
|
const CLIENT_ROUTE_OF = { codex: "codex", claude: "claudeCode", vscode: "vsCodeChat" };
|
|
13
21
|
// 新工具加在最後,不改既有 id。
|
|
14
22
|
exports.ENVIRONMENT_TOOLS = ["uv", "git", "node", "pwsh", "vscode"];
|
|
@@ -19,12 +27,18 @@ exports.ENVIRONMENT_LABEL = {
|
|
|
19
27
|
pwsh: "PowerShell 7",
|
|
20
28
|
vscode: "VS Code",
|
|
21
29
|
};
|
|
22
|
-
|
|
30
|
+
exports.AUTO_APPROVAL_DURATIONS = {
|
|
31
|
+
"10": { label: "10 分鐘", ms: 10 * 60_000 },
|
|
32
|
+
"30": { label: "30 分鐘", ms: 30 * 60_000 },
|
|
33
|
+
until_off: { label: "直到關閉開關" },
|
|
34
|
+
};
|
|
35
|
+
const LOCAL_TOOLS_NEED_CONNECTION = "請先在「教室設定」按「連線」,才能讓 Agent 使用這台電腦。";
|
|
36
|
+
exports.AUTO_APPROVAL_NEEDS_ACCESS = "請先打開「允許 Agent 使用這台電腦」,才能自動允許。";
|
|
23
37
|
const LOCAL_LIST_NOTE = "這是本機清單。";
|
|
24
38
|
exports.COPIED_KEY_NOTICE = "已複製 Classroom API Key。請勿分享給不信任的人。";
|
|
25
39
|
const KEY_REJECTED_NOTICE = {
|
|
26
|
-
expired: "Classroom API Key
|
|
27
|
-
invalid: "Classroom API Key
|
|
40
|
+
expired: "Classroom API Key 已過期,請按「清除連線」,再按「連線」,用老師給的新邀請碼登入。",
|
|
41
|
+
invalid: "Classroom API Key 已失效,請按「清除連線」,再按「連線」,用老師給的新邀請碼登入。",
|
|
28
42
|
};
|
|
29
43
|
const MODELS_UNLOADED_NOTICE = "無法載入課堂模型,請按「↻ 更新」再試。";
|
|
30
44
|
const VS_CODE_KEPT_NOTICE = "VS Code 的 VCRouter 已被修改,不再指向 VansPod,VansPod 沒有移除它。";
|
|
@@ -44,13 +58,15 @@ class ClassroomApp {
|
|
|
44
58
|
connectionOperations = Promise.resolve();
|
|
45
59
|
connected = false;
|
|
46
60
|
classLabel;
|
|
47
|
-
|
|
61
|
+
displayName;
|
|
62
|
+
loginMethod;
|
|
48
63
|
courseTitle;
|
|
49
64
|
sessionTitle;
|
|
50
65
|
detail = "";
|
|
51
66
|
connectionError;
|
|
52
67
|
connectionNotice;
|
|
53
|
-
|
|
68
|
+
// The connection attempt that waits for the browser to come back.
|
|
69
|
+
pendingConnection;
|
|
54
70
|
notice;
|
|
55
71
|
projectFolder;
|
|
56
72
|
folderError;
|
|
@@ -91,7 +107,7 @@ class ClassroomApp {
|
|
|
91
107
|
mustRestart = [];
|
|
92
108
|
modelRestart = [];
|
|
93
109
|
allowlistError;
|
|
94
|
-
// Router refused this Classroom API Key; only a new
|
|
110
|
+
// Router refused this Classroom API Key; only a new connection or Clear resets it.
|
|
95
111
|
keyRejection;
|
|
96
112
|
// 啟動時抓不到 Session Model Allowlist 而暫時退回 Native 的 Client Route;設定檔仍保留 Classroom,
|
|
97
113
|
// 「更新」抓到模型後切回去。學生自己切換或換堂後就不再代為恢復。
|
|
@@ -102,8 +118,15 @@ class ClassroomApp {
|
|
|
102
118
|
vsCodeOrigin;
|
|
103
119
|
sending = new Map();
|
|
104
120
|
localToolsNotice;
|
|
121
|
+
autoApprovalLabel;
|
|
105
122
|
constructor(deps) {
|
|
106
123
|
this.deps = deps;
|
|
124
|
+
// Every way that Local Tool Access turns off (the switch, or the relay by itself) ends Auto Approval
|
|
125
|
+
// and denies the waiting approvals (ADR 0014).
|
|
126
|
+
const { device, approvals } = deps;
|
|
127
|
+
if (device && approvals)
|
|
128
|
+
device.subscribe(status => { if (!status.on)
|
|
129
|
+
approvals.denyAll(); });
|
|
107
130
|
}
|
|
108
131
|
serialConnectionOperation(operation) {
|
|
109
132
|
const next = this.connectionOperations.then(operation, operation);
|
|
@@ -139,9 +162,12 @@ class ClassroomApp {
|
|
|
139
162
|
if (this.deps.device) {
|
|
140
163
|
const status = this.deps.device.status();
|
|
141
164
|
const local = { on: status.on, state: status.state, device: status.device };
|
|
142
|
-
if (this.
|
|
143
|
-
local.
|
|
144
|
-
|
|
165
|
+
if (this.displayName)
|
|
166
|
+
local.displayName = this.displayName;
|
|
167
|
+
if (this.loginMethod)
|
|
168
|
+
local.loginMethod = this.loginMethod;
|
|
169
|
+
// While it is off, the newest notice (from the student's last action) comes before the relay's reason.
|
|
170
|
+
const message = status.on ? status.message : this.localToolsNotice ?? status.message;
|
|
145
171
|
if (message)
|
|
146
172
|
local.message = message;
|
|
147
173
|
if (status.retryInMs !== undefined)
|
|
@@ -157,22 +183,32 @@ class ClassroomApp {
|
|
|
157
183
|
device: status.device,
|
|
158
184
|
secondsLeft: Math.max(0, Math.ceil((shown.expiresAt - Date.now()) / 1000)),
|
|
159
185
|
waiting: shown.waiting,
|
|
186
|
+
...(shown.exception ? { exception: localToolApproval_1.AUTO_APPROVAL_EXCEPTION_LABELS[shown.exception] } : {}),
|
|
160
187
|
};
|
|
161
188
|
}
|
|
162
|
-
|
|
163
|
-
|
|
189
|
+
const auto = this.deps.approvals?.autoApproval();
|
|
190
|
+
if (auto) {
|
|
191
|
+
local.autoApproval = auto.endsAt === undefined
|
|
192
|
+
? { label: this.autoApprovalLabel ?? exports.AUTO_APPROVAL_DURATIONS.until_off.label }
|
|
193
|
+
: { label: this.autoApprovalLabel ?? "", endsAt: auto.endsAt, secondsLeft: Math.max(0, Math.ceil((auto.endsAt - Date.now()) / 1000)) };
|
|
194
|
+
}
|
|
195
|
+
if (this.deps.remoteAgentLog)
|
|
196
|
+
local.log = { entries: this.deps.remoteAgentLog.list(), dropped: this.deps.remoteAgentLog.dropped() };
|
|
164
197
|
view.localTools = local;
|
|
165
198
|
}
|
|
166
199
|
if (this.notice && this.notice === this.connectionNotice)
|
|
167
200
|
view.connectionNotice = this.connectionNotice;
|
|
168
|
-
if (this.
|
|
169
|
-
view.
|
|
201
|
+
if (this.pendingConnection) {
|
|
202
|
+
view.connecting = true;
|
|
203
|
+
view.authorizeUrl = this.pendingConnection.authorizeUrl;
|
|
204
|
+
}
|
|
170
205
|
if (this.classLabel) {
|
|
171
206
|
view.classLabel = this.classLabel;
|
|
172
207
|
}
|
|
173
|
-
if (this.
|
|
174
|
-
view.
|
|
175
|
-
|
|
208
|
+
if (this.displayName)
|
|
209
|
+
view.displayName = this.displayName;
|
|
210
|
+
if (this.loginMethod)
|
|
211
|
+
view.loginMethod = this.loginMethod;
|
|
176
212
|
if (this.courseTitle) {
|
|
177
213
|
view.courseTitle = this.courseTitle;
|
|
178
214
|
}
|
|
@@ -777,39 +813,74 @@ class ClassroomApp {
|
|
|
777
813
|
this.pendingCommand = undefined;
|
|
778
814
|
this.pendingActionId = undefined;
|
|
779
815
|
}
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
const
|
|
785
|
-
const
|
|
816
|
+
/** 連線: opens the Router's Authorization Page in the system browser and waits for the callback. */
|
|
817
|
+
async startConnection() {
|
|
818
|
+
this.endPendingConnection();
|
|
819
|
+
const verifier = (0, node_crypto_1.randomBytes)(32).toString("base64url");
|
|
820
|
+
const state = (0, node_crypto_1.randomBytes)(24).toString("base64url");
|
|
821
|
+
const redirectUri = `${this.deps.proxyBaseUrl}/oauth/callback`;
|
|
822
|
+
const timer = setTimeout(() => {
|
|
823
|
+
if (this.pendingConnection?.state === state)
|
|
824
|
+
this.pendingConnection = undefined;
|
|
825
|
+
}, exports.CONNECT_TIMEOUT_MS);
|
|
826
|
+
timer.unref?.();
|
|
786
827
|
this.connectionError = undefined;
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
828
|
+
const url = new URL(this.deps.router.authorizeUrl);
|
|
829
|
+
url.search = new URLSearchParams({
|
|
830
|
+
response_type: "code",
|
|
831
|
+
client_id: exports.OAUTH_CLIENT_ID,
|
|
832
|
+
redirect_uri: redirectUri,
|
|
833
|
+
scope: "openid classroom",
|
|
834
|
+
state,
|
|
835
|
+
code_challenge: (0, node_crypto_1.createHash)("sha256").update(verifier).digest("base64url"),
|
|
836
|
+
code_challenge_method: "S256",
|
|
837
|
+
}).toString();
|
|
838
|
+
this.pendingConnection = { state, verifier, redirectUri, authorizeUrl: url.toString(), timer };
|
|
839
|
+
this.deps.openBrowser(url.toString());
|
|
840
|
+
}
|
|
841
|
+
/** 取消: stops waiting for the browser. A late callback is then ignored. */
|
|
842
|
+
cancelConnection() {
|
|
843
|
+
this.endPendingConnection();
|
|
844
|
+
}
|
|
845
|
+
endPendingConnection() {
|
|
846
|
+
if (this.pendingConnection)
|
|
847
|
+
clearTimeout(this.pendingConnection.timer);
|
|
848
|
+
this.pendingConnection = undefined;
|
|
849
|
+
}
|
|
850
|
+
/** The browser came back to `/oauth/callback`. A callback whose `state` does not match is ignored. */
|
|
851
|
+
async finishConnection(callback) {
|
|
852
|
+
const pending = this.pendingConnection;
|
|
853
|
+
if (!pending || !callback.state || callback.state !== pending.state)
|
|
854
|
+
return;
|
|
855
|
+
this.endPendingConnection();
|
|
856
|
+
if (callback.error || !callback.code) {
|
|
857
|
+
this.connectionError = exports.CONNECTION_CANCELLED;
|
|
858
|
+
return;
|
|
859
|
+
}
|
|
860
|
+
const code = callback.code;
|
|
861
|
+
return this.serialConnectionOperation(() => this.exchangeNow({ code, code_verifier: pending.verifier, redirect_uri: pending.redirectUri }));
|
|
862
|
+
}
|
|
863
|
+
async exchangeNow(exchange) {
|
|
864
|
+
this.connectionError = undefined;
|
|
865
|
+
let response;
|
|
796
866
|
try {
|
|
797
|
-
|
|
798
|
-
invite_code: invite,
|
|
799
|
-
nickname: name,
|
|
800
|
-
});
|
|
867
|
+
response = await this.deps.router.exchangeCode(exchange);
|
|
801
868
|
}
|
|
802
869
|
catch {
|
|
870
|
+
response = undefined;
|
|
871
|
+
}
|
|
872
|
+
const connection = response === undefined ? undefined : connectionFromTokens(response);
|
|
873
|
+
if (!connection) {
|
|
803
874
|
if (!this.connected) {
|
|
804
|
-
this.connectionError =
|
|
875
|
+
this.connectionError = CONNECTION_FAILED;
|
|
805
876
|
this.detail = "";
|
|
806
877
|
this.notice = undefined;
|
|
807
878
|
}
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
879
|
+
else {
|
|
880
|
+
this.notice = this.connectionNotice = response === undefined
|
|
881
|
+
? "連線失敗,已保留原有課堂連線。請稍後再試。"
|
|
882
|
+
: "連線回應資料格式不正確,已保留原有課堂連線。請稍後再試。";
|
|
883
|
+
}
|
|
813
884
|
return;
|
|
814
885
|
}
|
|
815
886
|
this.hiddenKeys.add(connection.apiKey);
|
|
@@ -842,7 +913,6 @@ class ClassroomApp {
|
|
|
842
913
|
this.pendingCommand = undefined;
|
|
843
914
|
this.pendingActionId = undefined;
|
|
844
915
|
this.applyConnectionIdentity(connection);
|
|
845
|
-
this.connectionDraft = undefined;
|
|
846
916
|
this.notice = undefined;
|
|
847
917
|
// Storage is committed: publish its identity before any client-file operation can fail.
|
|
848
918
|
if (desiredVsCodeMode === "classroom") {
|
|
@@ -867,7 +937,7 @@ class ClassroomApp {
|
|
|
867
937
|
return;
|
|
868
938
|
}
|
|
869
939
|
await this.loadCatalog();
|
|
870
|
-
await this.loadModels(
|
|
940
|
+
await this.loadModels(connection.apiKey);
|
|
871
941
|
if (desiredMode === "classroom" && this.modelIds.length > 0) {
|
|
872
942
|
this.mode = "classroom";
|
|
873
943
|
this.clientModes = desiredClientModes;
|
|
@@ -1204,7 +1274,7 @@ class ClassroomApp {
|
|
|
1204
1274
|
this.showKeyRejection(this.keyRejection);
|
|
1205
1275
|
});
|
|
1206
1276
|
}
|
|
1207
|
-
/** A refused Classroom API Key replaces any reload warning: the student has to
|
|
1277
|
+
/** A refused Classroom API Key replaces any reload warning: the student has to connect again. */
|
|
1208
1278
|
showKeyRejection(rejection) {
|
|
1209
1279
|
this.allowlistError = KEY_REJECTED_NOTICE[rejection];
|
|
1210
1280
|
}
|
|
@@ -1723,7 +1793,7 @@ class ClassroomApp {
|
|
|
1723
1793
|
return false;
|
|
1724
1794
|
}
|
|
1725
1795
|
}
|
|
1726
|
-
/** Turns Local Tool Access (
|
|
1796
|
+
/** Turns Local Tool Access (允許 Agent 使用這台電腦) on or off. It needs a Classroom Connection. */
|
|
1727
1797
|
async setLocalToolAccess(on) {
|
|
1728
1798
|
return this.serialConnectionOperation(async () => {
|
|
1729
1799
|
const device = this.deps.device;
|
|
@@ -1752,21 +1822,43 @@ class ClassroomApp {
|
|
|
1752
1822
|
decideLocalToolApproval(id, decision) {
|
|
1753
1823
|
return this.deps.approvals?.decide(id, decision) ?? false;
|
|
1754
1824
|
}
|
|
1825
|
+
/**
|
|
1826
|
+
* Starts Auto Approval (ADR 0014) from the page or the Approval Popup. The waiting approvals that are not
|
|
1827
|
+
* Auto Approval Exceptions are approved now. False when Local Tool Access is off: the page then tells the student.
|
|
1828
|
+
*/
|
|
1829
|
+
startAutoApproval(duration) {
|
|
1830
|
+
const approvals = this.deps.approvals;
|
|
1831
|
+
if (!approvals || !Object.hasOwn(exports.AUTO_APPROVAL_DURATIONS, duration))
|
|
1832
|
+
return false;
|
|
1833
|
+
if (!this.deps.device?.status().on) {
|
|
1834
|
+
this.localToolsNotice = exports.AUTO_APPROVAL_NEEDS_ACCESS;
|
|
1835
|
+
return false;
|
|
1836
|
+
}
|
|
1837
|
+
const { label, ms } = exports.AUTO_APPROVAL_DURATIONS[duration];
|
|
1838
|
+
this.autoApprovalLabel = label;
|
|
1839
|
+
approvals.startAutoApproval(ms);
|
|
1840
|
+
return true;
|
|
1841
|
+
}
|
|
1842
|
+
/** Stops Auto Approval from the page or the tray menu. */
|
|
1843
|
+
stopAutoApproval() {
|
|
1844
|
+
this.deps.approvals?.stopAutoApproval();
|
|
1845
|
+
}
|
|
1755
1846
|
/** The full body of the shown Local Tool Approval, or undefined when `id` is not the shown one. The page cuts a long body. */
|
|
1756
1847
|
localToolApprovalBody(id) {
|
|
1757
1848
|
const shown = this.deps.approvals?.shown();
|
|
1758
1849
|
return shown && shown.id === id ? shown.request.body : undefined;
|
|
1759
1850
|
}
|
|
1760
1851
|
/** Stops a running `bash` command from the page. False when it is not running. */
|
|
1761
|
-
|
|
1762
|
-
return this.deps.
|
|
1852
|
+
stopRemoteAgentCommand(id) {
|
|
1853
|
+
return this.deps.remoteAgentLog?.stop(id) ?? false;
|
|
1763
1854
|
}
|
|
1764
1855
|
// Denies every waiting approval, lets the denials reach the relay, then disconnects.
|
|
1765
1856
|
async turnLocalToolAccessOff() {
|
|
1766
|
-
|
|
1767
|
-
|
|
1857
|
+
const approvals = this.deps.approvals;
|
|
1858
|
+
const waiting = approvals?.shown() !== undefined;
|
|
1859
|
+
approvals?.denyAll();
|
|
1860
|
+
if (waiting)
|
|
1768
1861
|
await new Promise(resolve => setImmediate(resolve));
|
|
1769
|
-
}
|
|
1770
1862
|
this.deps.device?.stop();
|
|
1771
1863
|
}
|
|
1772
1864
|
async clearConnection() {
|
|
@@ -1784,7 +1876,7 @@ class ClassroomApp {
|
|
|
1784
1876
|
this.localToolsNotice = undefined;
|
|
1785
1877
|
this.applyConnectionIdentity(undefined);
|
|
1786
1878
|
this.connectionError = undefined;
|
|
1787
|
-
this.
|
|
1879
|
+
this.endPendingConnection();
|
|
1788
1880
|
this.notice = undefined;
|
|
1789
1881
|
this.allowlistError = undefined;
|
|
1790
1882
|
this.keyRejection = undefined;
|
|
@@ -1922,10 +2014,11 @@ class ClassroomApp {
|
|
|
1922
2014
|
}
|
|
1923
2015
|
applyConnectionIdentity(connection) {
|
|
1924
2016
|
this.connected = connection !== undefined;
|
|
1925
|
-
this.classLabel = connection && ([connection.
|
|
1926
|
-
this.courseTitle = connection?.
|
|
1927
|
-
this.sessionTitle = connection?.
|
|
1928
|
-
this.
|
|
2017
|
+
this.classLabel = connection && ([connection.className, connection.sessionName].filter(Boolean).join(" · ") || undefined);
|
|
2018
|
+
this.courseTitle = connection?.className || undefined;
|
|
2019
|
+
this.sessionTitle = connection?.sessionName || undefined;
|
|
2020
|
+
this.displayName = connection?.displayName || undefined;
|
|
2021
|
+
this.loginMethod = connection?.loginMethod;
|
|
1929
2022
|
this.detail = connection ? "Classroom API Key 已設定。" : "";
|
|
1930
2023
|
}
|
|
1931
2024
|
async restoreConnection() {
|
|
@@ -2164,3 +2257,39 @@ function catalogView(actions, snippets, source) {
|
|
|
2164
2257
|
}
|
|
2165
2258
|
return view;
|
|
2166
2259
|
}
|
|
2260
|
+
/**
|
|
2261
|
+
* Reads the token response into a Classroom Connection. The Student ID Token payload is read without a
|
|
2262
|
+
* signature check: VansPod got it straight from the Router over HTTPS and uses it only for display (ADR 0015).
|
|
2263
|
+
* Returns undefined when the response has no usable Classroom API Key or Student ID Token.
|
|
2264
|
+
*/
|
|
2265
|
+
function connectionFromTokens(response) {
|
|
2266
|
+
if (!response || typeof response !== "object")
|
|
2267
|
+
return undefined;
|
|
2268
|
+
const tokens = response;
|
|
2269
|
+
if (typeof tokens.access_token !== "string" || !tokens.access_token || typeof tokens.id_token !== "string")
|
|
2270
|
+
return undefined;
|
|
2271
|
+
let claims;
|
|
2272
|
+
try {
|
|
2273
|
+
const payload = JSON.parse(Buffer.from(tokens.id_token.split(".")[1] ?? "", "base64url").toString("utf8"));
|
|
2274
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
2275
|
+
return undefined;
|
|
2276
|
+
claims = payload;
|
|
2277
|
+
}
|
|
2278
|
+
catch {
|
|
2279
|
+
return undefined;
|
|
2280
|
+
}
|
|
2281
|
+
const fromClaims = {
|
|
2282
|
+
displayName: claims.name,
|
|
2283
|
+
className: claims.class_name,
|
|
2284
|
+
sessionName: claims.session_name,
|
|
2285
|
+
classSessionId: claims.class_session_id,
|
|
2286
|
+
loginMethod: claims.login_method,
|
|
2287
|
+
};
|
|
2288
|
+
const connection = {
|
|
2289
|
+
version: 2,
|
|
2290
|
+
apiKey: tokens.access_token,
|
|
2291
|
+
...Object.fromEntries(Object.entries(fromClaims).filter(([, value]) => value !== undefined && value !== "")),
|
|
2292
|
+
};
|
|
2293
|
+
// A claim of the wrong type means a malformed Student ID Token: refuse it rather than guess.
|
|
2294
|
+
return (0, secureStorage_1.isClassroomConnection)(connection) ? connection : undefined;
|
|
2295
|
+
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ClassroomKeyRejectedError = void 0;
|
|
4
4
|
exports.assertClassroomKeyAccepted = assertClassroomKeyAccepted;
|
|
5
|
-
/** Router refused this Classroom API Key: the student has to
|
|
5
|
+
/** Router refused this Classroom API Key: the student has to connect again with a new invite code. */
|
|
6
6
|
class ClassroomKeyRejectedError extends Error {
|
|
7
7
|
reason;
|
|
8
8
|
constructor(reason) {
|
package/dist/codexWebSearch.js
CHANGED
|
@@ -16,7 +16,7 @@ function unsupported(commands) {
|
|
|
16
16
|
return `課堂模式沒有這些網路指令。${commands.length ? `These web commands are not supported in this classroom session and were not run: ${commands.join(", ")}.` : "This request named no web command that this classroom session runs."} Searching is done with search_query (searching by query text); its results already include a text snippet of each page. Do not retry the unsupported commands. Do not use shell commands (curl, wget, scripts) to get that information some other way. If that is not enough, tell the user this classroom session cannot do it.`;
|
|
17
17
|
}
|
|
18
18
|
// open, click and find read a page Codex already knows the address of. That is not Web
|
|
19
|
-
// Search (
|
|
19
|
+
// Search (GLOSSARY.md): Router is not called, so whether the Class Session allows Web
|
|
20
20
|
// Search is never asked, and the Coding Agent fetches the page itself.
|
|
21
21
|
const READ_COMMANDS = ["open", "click", "find"];
|
|
22
22
|
// What is written back to the model; a longer ref_id is still answered, just not quoted.
|
package/dist/desktop.js
CHANGED
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.browserCommand = browserCommand;
|
|
6
7
|
exports.openBrowser = openBrowser;
|
|
7
8
|
exports.asset = asset;
|
|
8
9
|
exports.writeTool = writeTool;
|
|
@@ -13,12 +14,21 @@ const node_child_process_1 = require("node:child_process");
|
|
|
13
14
|
const node_sea_1 = require("node:sea");
|
|
14
15
|
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
15
16
|
const node_path_1 = __importDefault(require("node:path"));
|
|
17
|
+
/**
|
|
18
|
+
* The program that opens a URL in the system browser. On Windows it is not `cmd.exe /c start`:
|
|
19
|
+
* cmd reads `&`, `%` and `^` in the URL as its own syntax and cuts the Authorization Page URL.
|
|
20
|
+
* The URL handler of url.dll gets the URL as one unchanged argument.
|
|
21
|
+
*/
|
|
22
|
+
function browserCommand(url, platform = process.platform) {
|
|
23
|
+
return platform === "win32"
|
|
24
|
+
? { file: "rundll32.exe", args: ["url.dll,FileProtocolHandler", url] }
|
|
25
|
+
: { file: "open", args: [url] };
|
|
26
|
+
}
|
|
16
27
|
function openBrowser(url) {
|
|
17
28
|
if (process.env.CLASSROOM_APP_HEADLESS === "1")
|
|
18
29
|
return;
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
: (0, node_child_process_1.spawn)("open", [url], { detached: true, stdio: "ignore" });
|
|
30
|
+
const { file, args } = browserCommand(url);
|
|
31
|
+
const child = (0, node_child_process_1.spawn)(file, args, { detached: true, stdio: "ignore", windowsHide: true });
|
|
22
32
|
child.on("error", () => process.stderr.write("請用瀏覽器開啟顯示的本機網址。\n"));
|
|
23
33
|
child.unref();
|
|
24
34
|
}
|
package/dist/deviceConnection.js
CHANGED
|
@@ -24,9 +24,16 @@ function createDeviceConnection(options) {
|
|
|
24
24
|
// Each attempt has its own number; events from an older socket are ignored.
|
|
25
25
|
let attempt = 0;
|
|
26
26
|
const calls = new Map();
|
|
27
|
+
const listeners = new Set();
|
|
27
28
|
const set = (next) => {
|
|
28
29
|
current = { ...next, device };
|
|
29
30
|
options.onChange?.({ ...current });
|
|
31
|
+
for (const listener of [...listeners]) {
|
|
32
|
+
try {
|
|
33
|
+
listener({ ...current });
|
|
34
|
+
}
|
|
35
|
+
catch { /* one listener must not stop the others */ }
|
|
36
|
+
}
|
|
30
37
|
};
|
|
31
38
|
const abortCalls = () => {
|
|
32
39
|
for (const control of calls.values())
|
|
@@ -137,11 +144,11 @@ function createDeviceConnection(options) {
|
|
|
137
144
|
if (mine !== attempt)
|
|
138
145
|
return;
|
|
139
146
|
if (event.code === REFUSED) {
|
|
140
|
-
off(refusal ?? "
|
|
147
|
+
off(refusal ?? "課堂連線被拒絕,已關閉「允許 Agent 使用這台電腦」。");
|
|
141
148
|
return;
|
|
142
149
|
}
|
|
143
150
|
if (event.code === BAD_HELLO) {
|
|
144
|
-
off("VansPod
|
|
151
|
+
off("VansPod 無法連上遠端 Agent 的轉送站(連線資料不正確),請更新 VansPod。");
|
|
145
152
|
return;
|
|
146
153
|
}
|
|
147
154
|
if (event.code === REPLACED) {
|
|
@@ -162,5 +169,9 @@ function createDeviceConnection(options) {
|
|
|
162
169
|
},
|
|
163
170
|
stop() { off(); },
|
|
164
171
|
status() { return { ...current }; },
|
|
172
|
+
subscribe(listener) {
|
|
173
|
+
listeners.add(listener);
|
|
174
|
+
return () => { listeners.delete(listener); };
|
|
175
|
+
},
|
|
165
176
|
};
|
|
166
177
|
}
|
package/dist/html.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.escapeHtml = escapeHtml;
|
|
4
|
+
/** Escapes text for HTML text and attribute values. */
|
|
5
|
+
function escapeHtml(value) {
|
|
6
|
+
return value
|
|
7
|
+
.replaceAll("&", "&")
|
|
8
|
+
.replaceAll("<", "<")
|
|
9
|
+
.replaceAll(">", ">")
|
|
10
|
+
.replaceAll('"', """)
|
|
11
|
+
.replaceAll("'", "'");
|
|
12
|
+
}
|
package/dist/legacyMigration.js
CHANGED
|
@@ -2,33 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createMigratingConnectionStorage = createMigratingConnectionStorage;
|
|
4
4
|
const storageErrors_1 = require("./storageErrors");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
catch {
|
|
11
|
-
return undefined;
|
|
12
|
-
}
|
|
13
|
-
if (!value || typeof value !== "object")
|
|
14
|
-
return undefined;
|
|
15
|
-
const legacy = value;
|
|
16
|
-
if (legacy.secureStorage !== undefined || typeof legacy.apiKey !== "string" || !legacy.apiKey)
|
|
17
|
-
return undefined;
|
|
18
|
-
const session = {};
|
|
19
|
-
if (legacy.session && typeof legacy.session === "object") {
|
|
20
|
-
const oldSession = legacy.session;
|
|
21
|
-
for (const field of ["class_name", "name", "invite_code", "expires_at"]) {
|
|
22
|
-
if (typeof oldSession[field] === "string")
|
|
23
|
-
session[field] = oldSession[field];
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
const connection = { version: 1, apiKey: legacy.apiKey, session, mode: legacy.mode === "classroom" ? "classroom" : "native" };
|
|
27
|
-
if (typeof legacy.nickname === "string")
|
|
28
|
-
connection.nickname = legacy.nickname;
|
|
29
|
-
return connection;
|
|
30
|
-
}
|
|
31
|
-
/** Startup migration is shared by all reads and settles before later mutations. */
|
|
5
|
+
/**
|
|
6
|
+
* The legacy extension saved its classroom connection as plaintext. VansPod does not convert it (ADR 0015):
|
|
7
|
+
* startup removes the plaintext file, so no key stays readable on disk, and VansPod starts not connected.
|
|
8
|
+
* The removal is shared by all reads and settles before later mutations.
|
|
9
|
+
*/
|
|
32
10
|
function createMigratingConnectionStorage(storage, filePath, files) {
|
|
33
11
|
let loaded;
|
|
34
12
|
async function migrate() {
|
|
@@ -40,25 +18,13 @@ function createMigratingConnectionStorage(storage, filePath, files) {
|
|
|
40
18
|
throw error;
|
|
41
19
|
}
|
|
42
20
|
try {
|
|
43
|
-
|
|
44
|
-
if (!legacy)
|
|
45
|
-
throw new storageErrors_1.StorageError("unavailable");
|
|
46
|
-
// A strict save performs protect, decrypt verification, protected temp write and replacement.
|
|
47
|
-
const result = await storage.setConnection(legacy);
|
|
48
|
-
if (result.persistence !== "persistent")
|
|
49
|
-
throw new storageErrors_1.StorageError("unavailable");
|
|
50
|
-
return legacy;
|
|
21
|
+
await files.remove(filePath);
|
|
51
22
|
}
|
|
52
|
-
catch {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
catch (error) {
|
|
57
|
-
if (error?.code !== "ENOENT")
|
|
58
|
-
throw new storageErrors_1.StorageError("legacy-cleanup-failed");
|
|
59
|
-
}
|
|
60
|
-
throw new storageErrors_1.StorageError("migration-failed");
|
|
23
|
+
catch (error) {
|
|
24
|
+
if (error?.code !== "ENOENT")
|
|
25
|
+
throw new storageErrors_1.StorageError("legacy-cleanup-failed");
|
|
61
26
|
}
|
|
27
|
+
return undefined;
|
|
62
28
|
}
|
|
63
29
|
function initialize() {
|
|
64
30
|
if (!loaded) {
|