vanspod 0.4.15 → 0.4.16
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 +55 -11
- package/dist/codexWebSearch.js +1 -1
- package/dist/deviceConnection.js +13 -2
- package/dist/html.js +12 -0
- package/dist/localCommands.js +82 -119
- package/dist/localToolApproval.js +81 -4
- package/dist/localTools.js +31 -8
- package/dist/modelStatus.js +8 -12
- package/dist/page.js +278 -124
- package/dist/remoteAgentLog.js +126 -0
- package/dist/remoteAgentLogView.js +421 -0
- package/dist/saveImage.js +26 -0
- package/dist/settingsActions.js +1 -1
- package/dist/start.js +59 -10
- package/dist/trayChannel.js +25 -6
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/scripts/tray.ps1 +141 -11
package/dist/page.js
CHANGED
|
@@ -3,11 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.modelStatus = modelStatus;
|
|
4
4
|
exports.localToolApprovalBodyResponse = localToolApprovalBodyResponse;
|
|
5
5
|
exports.localToolsStateText = localToolsStateText;
|
|
6
|
+
exports.remoteAgentLogEntryResponse = remoteAgentLogEntryResponse;
|
|
6
7
|
exports.environmentStageText = environmentStageText;
|
|
7
8
|
exports.environmentStatus = environmentStatus;
|
|
8
9
|
exports.renderPage = renderPage;
|
|
9
10
|
exports.renderInspectorPage = renderInspectorPage;
|
|
11
|
+
exports.renderRemoteAgentPage = renderRemoteAgentPage;
|
|
10
12
|
const version_1 = require("./version");
|
|
13
|
+
const html_1 = require("./html");
|
|
11
14
|
const appearance_1 = require("./appearance");
|
|
12
15
|
const installProgress_1 = require("./installProgress");
|
|
13
16
|
const environmentProgress_1 = require("./environmentProgress");
|
|
@@ -19,7 +22,8 @@ const clientIcons_1 = require("./clientIcons");
|
|
|
19
22
|
const environmentIcons_1 = require("./environmentIcons");
|
|
20
23
|
const classroomApp_1 = require("./classroomApp");
|
|
21
24
|
const promptCapture_1 = require("./promptCapture");
|
|
22
|
-
const
|
|
25
|
+
const localToolApproval_1 = require("./localToolApproval");
|
|
26
|
+
const remoteAgentLogView_1 = require("./remoteAgentLogView");
|
|
23
27
|
const inspectorView_1 = require("./inspectorView");
|
|
24
28
|
const versionUpdateView_1 = require("./versionUpdateView");
|
|
25
29
|
const powerMenuView_1 = require("./powerMenuView");
|
|
@@ -29,14 +33,6 @@ const VERSION = `v${version_1.VERSION}`;
|
|
|
29
33
|
const COPY_ICON = `<svg viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>`;
|
|
30
34
|
const MOON = `<svg viewBox="0 0 24 24" aria-hidden="true"><path fill="currentColor" d="M21 14.5A8.5 8.5 0 1 1 9.5 3a7 7 0 0 0 11.5 11.5z"/></svg>`;
|
|
31
35
|
const SUN = `<svg viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="12" r="4" fill="currentColor"/><path stroke="currentColor" stroke-width="2" stroke-linecap="round" d="M12 2.5v2M12 19.5v2M2.5 12h2M19.5 12h2M5 5l1.4 1.4M17.6 17.6 19 19M19 5l-1.4 1.4M6.4 17.6 5 19"/></svg>`;
|
|
32
|
-
function escapeHtml(value) {
|
|
33
|
-
return value
|
|
34
|
-
.replaceAll("&", "&")
|
|
35
|
-
.replaceAll("<", "<")
|
|
36
|
-
.replaceAll(">", ">")
|
|
37
|
-
.replaceAll('"', """)
|
|
38
|
-
.replaceAll("'", "'");
|
|
39
|
-
}
|
|
40
36
|
function locked(view) {
|
|
41
37
|
return view.commandRunning ? " disabled" : "";
|
|
42
38
|
}
|
|
@@ -56,7 +52,7 @@ function restartHtml(view) {
|
|
|
56
52
|
const joined = names.length === 1
|
|
57
53
|
? names[0]
|
|
58
54
|
: `${names.slice(0, -1).join("、")} 與 ${names[names.length - 1]}`;
|
|
59
|
-
parts.push(`<p>設定幫你更新好了,${escapeHtml(joined)} 還在裝睡。重新開啟 ${escapeHtml(joined)} 後生效,披風可不包叫醒服務。</p>`);
|
|
55
|
+
parts.push(`<p>設定幫你更新好了,${(0, html_1.escapeHtml)(joined)} 還在裝睡。重新開啟 ${(0, html_1.escapeHtml)(joined)} 後生效,披風可不包叫醒服務。</p>`);
|
|
60
56
|
}
|
|
61
57
|
if (clients.includes("vscode")) {
|
|
62
58
|
parts.push(`<p>設定幫你更新好了,VS Code 還在裝睡。請完全退出 VS Code 再打開,不要只重載視窗。別敷衍牠,牠真的會繼續睡。</p>`);
|
|
@@ -69,10 +65,10 @@ function statusWord(view) {
|
|
|
69
65
|
return view.mode === "classroom" ? "Classroom" : "Native";
|
|
70
66
|
}
|
|
71
67
|
function notices(view) {
|
|
72
|
-
const notice = view.notice && view.notice !== view.connectionNotice ? `<p class="notice">${escapeHtml(view.notice)}</p>` : "";
|
|
68
|
+
const notice = view.notice && view.notice !== view.connectionNotice ? `<p class="notice">${(0, html_1.escapeHtml)(view.notice)}</p>` : "";
|
|
73
69
|
const running = view.commandRunning ? `<p class="running">執行中</p>` : "";
|
|
74
70
|
const klass = view.classLabel
|
|
75
|
-
? `<p class="class-label">${escapeHtml(view.classLabel)}</p>`
|
|
71
|
+
? `<p class="class-label">${(0, html_1.escapeHtml)(view.classLabel)}</p>`
|
|
76
72
|
: "";
|
|
77
73
|
return `${klass}${notice}${running}`;
|
|
78
74
|
}
|
|
@@ -80,7 +76,7 @@ function connectionFeedback(view) {
|
|
|
80
76
|
const original = view.connectionError || view.connectionNotice || (view.detail !== "Classroom API Key 已設定。" ? view.detail : "");
|
|
81
77
|
const message = original === classroomApp_1.COPIED_KEY_NOTICE
|
|
82
78
|
? "複製好了!API Key 不是群組伴手禮,別發給不信任的人喔。" : original;
|
|
83
|
-
const feedback = `<div class="connection-feedback">${message ? `<div class="${view.connectionError ? "connection-error" : "connection-message"}" role="${view.connectionError ? "alert" : "status"}"><svg viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8"><circle cx="12" cy="12" r="9"/><path d="M12 7v6M12 15v2"/></svg><p>${escapeHtml(message)}</p></div>` : ""}</div>`;
|
|
79
|
+
const feedback = `<div class="connection-feedback">${message ? `<div class="${view.connectionError ? "connection-error" : "connection-message"}" role="${view.connectionError ? "alert" : "status"}"><svg viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8"><circle cx="12" cy="12" r="9"/><path d="M12 7v6M12 15v2"/></svg><p>${(0, html_1.escapeHtml)(message)}</p></div>` : ""}</div>`;
|
|
84
80
|
return feedback;
|
|
85
81
|
}
|
|
86
82
|
function connectInner(view) {
|
|
@@ -95,17 +91,17 @@ function connectInner(view) {
|
|
|
95
91
|
</form>${feedback}`;
|
|
96
92
|
}
|
|
97
93
|
return `<form class="stack" method="post" action="/redeem">
|
|
98
|
-
<label>邀請碼 <input name="invite_code" autocomplete="off" value="${escapeHtml(view.connectionDraft?.inviteCode ?? "")}"${locked(view)}></label>
|
|
99
|
-
<label>課堂暱稱 <input name="nickname" autocomplete="off" value="${escapeHtml(view.connectionDraft?.nickname ?? "")}"${locked(view)}></label>
|
|
94
|
+
<label>邀請碼 <input name="invite_code" autocomplete="off" value="${(0, html_1.escapeHtml)(view.connectionDraft?.inviteCode ?? "")}"${locked(view)}></label>
|
|
95
|
+
<label>課堂暱稱 <input name="nickname" autocomplete="off" value="${(0, html_1.escapeHtml)(view.connectionDraft?.nickname ?? "")}"${locked(view)}></label>
|
|
100
96
|
${feedback}
|
|
101
97
|
<button type="submit" class="go"${locked(view)}>連線</button>
|
|
102
98
|
</form>`;
|
|
103
99
|
}
|
|
104
100
|
function folderInner(view) {
|
|
105
|
-
const value = view.projectFolder ? ` value="${escapeHtml(view.projectFolder)}"` : "";
|
|
101
|
+
const value = view.projectFolder ? ` value="${(0, html_1.escapeHtml)(view.projectFolder)}"` : "";
|
|
106
102
|
const off = locked(view);
|
|
107
103
|
const note = view.installNotice
|
|
108
|
-
? `<p class="hint">${escapeHtml(view.installNotice)}</p>`
|
|
104
|
+
? `<p class="hint">${(0, html_1.escapeHtml)(view.installNotice)}</p>`
|
|
109
105
|
: "";
|
|
110
106
|
return `<form class="stack" method="post" action="/project-folder">
|
|
111
107
|
<label>專案資料夾 <input name="project_folder" autocomplete="off"${value}${off}></label>
|
|
@@ -117,7 +113,7 @@ function modelInner(view) {
|
|
|
117
113
|
const off = locked(view);
|
|
118
114
|
const models = view.allowedModels ?? (view.modelId ? [view.modelId] : []);
|
|
119
115
|
const list = models.length
|
|
120
|
-
? `<ul class="allowed-model-list">${models.map(id => `<li>${escapeHtml(id)}</li>`).join("")}</ul>`
|
|
116
|
+
? `<ul class="allowed-model-list">${models.map(id => `<li>${(0, html_1.escapeHtml)(id)}</li>`).join("")}</ul>`
|
|
121
117
|
: `<p class="hint">${view.connected ? "這堂課尚無可用模型。" : "連線課堂後可查看。"}</p>`;
|
|
122
118
|
return `
|
|
123
119
|
${restartHtml(view)}
|
|
@@ -143,15 +139,26 @@ function modelStatus(view) {
|
|
|
143
139
|
return {
|
|
144
140
|
lights: { codex: clientLight(view, "codex"), claude: clientLight(view, "claude"), vscode: clientLight(view, "vscode") },
|
|
145
141
|
restart: restartHtml(view),
|
|
146
|
-
...(view.localTools ? { localTools: { on: view.localTools.on,
|
|
142
|
+
...(view.localTools ? { localTools: { on: view.localTools.on, status: remoteStatus(view), approval: approvalStatus(view.localTools.approval, Boolean(view.localTools.autoApproval)), ...(view.localTools.log ? { log: (0, remoteAgentLogView_1.logListStatus)(view.localTools.log) } : {}) } } : {}),
|
|
147
143
|
};
|
|
148
144
|
}
|
|
149
|
-
// The poll redraws the
|
|
150
|
-
function approvalStatus(approval) {
|
|
151
|
-
return approval ? { key: approvalKey(approval), secondsLeft: approval.secondsLeft, html: approvalBlock(approval) } : null;
|
|
145
|
+
// The poll redraws the card only when the shown approval, the count or Auto Approval changes; the seconds and the bar change every poll.
|
|
146
|
+
function approvalStatus(approval, auto) {
|
|
147
|
+
return approval ? { key: approvalKey(approval, auto), secondsLeft: approval.secondsLeft, bar: approvalBarWidth(approval), html: approvalBlock(approval, auto) } : null;
|
|
148
|
+
}
|
|
149
|
+
function approvalBarWidth(approval) {
|
|
150
|
+
const total = localToolApproval_1.APPROVAL_TIMEOUT_MS / 1000;
|
|
151
|
+
return `${Math.round(Math.min(1, Math.max(0, approval.secondsLeft / total)) * 1000) / 10}%`;
|
|
152
|
+
}
|
|
153
|
+
function approvalKey(approval, auto) {
|
|
154
|
+
return `${approval.id}:${approval.waiting}${auto ? ":auto" : ""}`;
|
|
152
155
|
}
|
|
153
|
-
|
|
154
|
-
|
|
156
|
+
const BOLT = `<svg class="auto-bolt" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="M13 2 4 14h7l-1 8 9-12h-7z"/></svg>`;
|
|
157
|
+
/** The 自動允許 ▾ menu on the approval card. Each item opens the reminder dialog; only 確定打開 starts Auto Approval. */
|
|
158
|
+
function autoApprovalMenu() {
|
|
159
|
+
const items = Object.entries(classroomApp_1.AUTO_APPROVAL_DURATIONS)
|
|
160
|
+
.map(([duration, { label }]) => `<button type="button" role="menuitem" data-auto-approval="${duration}">${(0, html_1.escapeHtml)(label)}</button>`).join("");
|
|
161
|
+
return `<details class="auto-menu"><summary class="auto-menu-button">自動允許 ▾</summary><div class="auto-menu-list" role="menu">${items}</div></details>`;
|
|
155
162
|
}
|
|
156
163
|
const NO_APPROVAL = `<div data-local-approval hidden></div>`;
|
|
157
164
|
/**
|
|
@@ -174,82 +181,89 @@ function localToolApprovalBodyResponse(app, id) {
|
|
|
174
181
|
const body = app.localToolApprovalBody(id);
|
|
175
182
|
return body === undefined ? { status: 404, body: { error: "這個確認已經結束。" } } : { status: 200, body: { id, body } };
|
|
176
183
|
}
|
|
177
|
-
// The Command Log on the page: the `bash` commands of this VansPod run (ADR 0013).
|
|
178
|
-
const SHOWN_COMMANDS = 50;
|
|
179
|
-
const SHOWN_COMMAND_CHARS = 300;
|
|
180
|
-
function commandsKey(commands) {
|
|
181
|
-
return commands.slice(0, SHOWN_COMMANDS).map(command => `${command.id}:${command.state}`).join(",");
|
|
182
|
-
}
|
|
183
|
-
// The poll redraws the list only when a command starts or ends.
|
|
184
|
-
function commandsStatus(commands) {
|
|
185
|
-
return commands ? { key: commandsKey(commands), html: commandsBlock(commands) } : null;
|
|
186
|
-
}
|
|
187
|
-
function commandStateText(command) {
|
|
188
|
-
if (command.state === "running")
|
|
189
|
-
return "執行中";
|
|
190
|
-
if (command.state === "exited")
|
|
191
|
-
return `結束代碼 ${command.exitCode ?? "不明"}`;
|
|
192
|
-
if (command.state === "timed_out")
|
|
193
|
-
return `超過 ${localCommands_1.BASH_TIMEOUT_MS / 1000} 秒,已停止`;
|
|
194
|
-
if (command.state === "stopped")
|
|
195
|
-
return "已停止";
|
|
196
|
-
return "無法啟動";
|
|
197
|
-
}
|
|
198
|
-
function commandsBlock(commands) {
|
|
199
|
-
if (!commands || commands.length === 0)
|
|
200
|
-
return `<div class="local-commands" data-local-commands data-commands-key="" hidden></div>`;
|
|
201
|
-
const items = commands.slice(0, SHOWN_COMMANDS).map(command => {
|
|
202
|
-
const chars = Array.from(command.command);
|
|
203
|
-
const text = chars.length > SHOWN_COMMAND_CHARS ? `${chars.slice(0, SHOWN_COMMAND_CHARS).join("")}…(共 ${chars.length} 個字元)` : command.command;
|
|
204
|
-
const time = new Date(command.startedAt).toLocaleTimeString("zh-TW", { hour12: false });
|
|
205
|
-
const stop = command.state === "running"
|
|
206
|
-
? `<form method="post" action="/local-command-stop"><input type="hidden" name="id" value="${escapeHtml(command.id)}"><button type="submit" class="local-command-stop">停止</button></form>`
|
|
207
|
-
: "";
|
|
208
|
-
return `<li><code>${escapeHtml(text)}</code><span class="hint">${escapeHtml(time)}・${escapeHtml(commandStateText(command))}</span>${stop}</li>`;
|
|
209
|
-
}).join("");
|
|
210
|
-
const older = commands.length > SHOWN_COMMANDS ? `<p class="hint">較早的 ${commands.length - SHOWN_COMMANDS} 個指令沒有顯示。</p>` : "";
|
|
211
|
-
return `<div class="local-commands" data-local-commands data-commands-key="${escapeHtml(commandsKey(commands))}"><p class="hint">Agent Builder 這次執行過的指令(關掉 VansPod 就清除):</p>${older}<ol>${items}</ol></div>`;
|
|
212
|
-
}
|
|
213
184
|
// Local Tool Approval on the page (ADR 0013). No text field and no autofocus, so Enter cannot approve.
|
|
214
185
|
function approvalBodyHtml(approval) {
|
|
215
186
|
const { text, cut } = shownBody(approval.body);
|
|
216
|
-
const more = cut ? `<button type="button" class="local-approval-full" data-approval-full="${escapeHtml(approval.id)}">顯示全部</button>` : "";
|
|
217
|
-
return `<pre class="local-approval-body">${escapeHtml(text)}</pre>${more}`;
|
|
187
|
+
const more = cut ? `<button type="button" class="local-approval-full" data-approval-full="${(0, html_1.escapeHtml)(approval.id)}">顯示全部</button>` : "";
|
|
188
|
+
return `<pre class="local-approval-body">${(0, html_1.escapeHtml)(text)}</pre>${more}`;
|
|
218
189
|
}
|
|
219
|
-
|
|
190
|
+
// During Auto Approval only exceptions are shown: the card says why, and has no 自動允許 ▾ (ADR 0014).
|
|
191
|
+
function approvalBlock(approval, auto) {
|
|
220
192
|
if (!approval)
|
|
221
193
|
return NO_APPROVAL;
|
|
222
|
-
const waiting = approval.waiting > 0 ?
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
+ `<p class="
|
|
194
|
+
const waiting = approval.waiting > 0 ? `<span class="remote-chip local-approval-queue">還有 ${approval.waiting} 個在排隊</span>` : "";
|
|
195
|
+
const exception = auto && approval.exception;
|
|
196
|
+
return `<section class="tile local-approval${exception ? " is-exception" : ""}" role="group" aria-label="Local Tool 確認" data-local-approval data-approval-key="${(0, html_1.escapeHtml)(approvalKey(approval, auto))}">`
|
|
197
|
+
+ (exception ? `<p class="local-approval-exception">${BOLT}自動允許期間仍要確認:<b>${(0, html_1.escapeHtml)(exception)}</b></p>` : "")
|
|
198
|
+
+ `<div class="local-approval-head"><p class="local-approval-title">Agent 想要:<strong>${(0, html_1.escapeHtml)(approval.title)}</strong></p><code>${(0, html_1.escapeHtml)(approval.tool)}</code>${waiting}</div>`
|
|
199
|
+
+ `<p class="hint">電腦:${(0, html_1.escapeHtml)(approval.device)} 資料夾:${(0, html_1.escapeHtml)(approval.folder)}</p>`
|
|
226
200
|
+ approvalBodyHtml(approval)
|
|
227
|
-
+ `<
|
|
228
|
-
+ `<form class="local-approval-actions" method="post" action="/local-tool-approval"><input type="hidden" name="id" value="${escapeHtml(approval.id)}">`
|
|
229
|
-
+ `<
|
|
230
|
-
+ `<button type="submit" name="decision" value="deny" class="local-approval-deny">拒絕</button
|
|
201
|
+
+ `<div class="local-approval-timer"><span data-approval-bar style="width: ${approvalBarWidth(approval)}"></span></div>`
|
|
202
|
+
+ `<form class="local-approval-actions" method="post" action="/local-tool-approval"><input type="hidden" name="id" value="${(0, html_1.escapeHtml)(approval.id)}">`
|
|
203
|
+
+ `<span class="hint"><span data-approval-seconds>${approval.secondsLeft}</span> 秒後自動拒絕</span>`
|
|
204
|
+
+ `<button type="submit" name="decision" value="deny" class="local-approval-deny">拒絕</button><button type="submit" name="decision" value="approve" class="local-approval-approve">允許一次</button>${auto ? "" : autoApprovalMenu()}</form></section>`;
|
|
231
205
|
}
|
|
232
206
|
/** One line about Local Tool Access for the student: the relay's message, or the connection state. */
|
|
233
207
|
function localToolsStateText(local) {
|
|
234
208
|
if (local.message)
|
|
235
209
|
return local.message;
|
|
236
210
|
if (local.state === "connected")
|
|
237
|
-
return "已連上,Agent
|
|
211
|
+
return "已連上,Agent 可以使用這台電腦。";
|
|
238
212
|
if (local.state === "connecting")
|
|
239
213
|
return "正在連線…";
|
|
240
214
|
if (local.state === "retrying")
|
|
241
215
|
return `連線中斷,${Math.max(1, Math.round((local.retryInMs ?? 1000) / 1000))} 秒後重新連線。`;
|
|
242
|
-
return "已關閉,Agent
|
|
216
|
+
return "已關閉,Agent 不能使用這台電腦。";
|
|
243
217
|
}
|
|
244
|
-
|
|
245
|
-
|
|
218
|
+
const LOCAL_TOOL_ACCESS = "允許 Agent 使用這台電腦";
|
|
219
|
+
// The status bar of the 遠端 Agent page: the connection, the names to match, and the
|
|
220
|
+
// 允許 Agent 使用這台電腦 switch (Local Tool Access, ADR 0013). `key` changes only when the bar changes.
|
|
221
|
+
function remoteStatus(view) {
|
|
246
222
|
const local = view.localTools;
|
|
247
|
-
if (!local
|
|
248
|
-
return "";
|
|
249
|
-
const
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
223
|
+
if (!local)
|
|
224
|
+
return { key: "", html: `<section class="tile remote-status" data-remote-status data-status-key=""><p class="hint">這個 VansPod 不能讓 Agent 使用這台電腦。</p></section>` };
|
|
225
|
+
const chip = (label, value) => `<span class="remote-chip">${label} <b>${(0, html_1.escapeHtml)(value)}</b></span>`;
|
|
226
|
+
const chips = chip("電腦", local.device) + (local.nickname ? chip("暱稱", local.nickname) : "") + chip("資料夾", view.projectFolder ?? "還沒選");
|
|
227
|
+
const lit = local.on && local.state === "connected";
|
|
228
|
+
const guidance = !view.connected
|
|
229
|
+
? `<p class="remote-setup">請先到「教室設定」兌換課堂連線,才能讓 Agent 使用這台電腦。</p>`
|
|
230
|
+
: local.on ? ""
|
|
231
|
+
: `<p class="remote-setup">${local.nickname ? `在 Agent 的 MCP 授權頁選「暱稱」,輸入 <b>${(0, html_1.escapeHtml)(local.nickname)}</b>(大小寫要一樣)。` : ""}這台電腦會顯示為 <b>${(0, html_1.escapeHtml)(local.device)}</b>。每次啟動 VansPod,這個開關都會關閉。</p>`;
|
|
232
|
+
const auto = local.autoApproval;
|
|
233
|
+
const main = `<div class="remote-status-main"><span class="remote-dot${lit ? " on" : ""}${auto ? " auto" : ""}"></span><div><strong role="status">${(0, html_1.escapeHtml)(localToolsStateText(local))}</strong><div class="remote-chips">${chips}</div></div></div>`;
|
|
234
|
+
const toggle = `<form class="remote-switch-row" method="post" action="/local-tools"><span>${LOCAL_TOOL_ACCESS}</span><button type="submit" name="on" value="${local.on ? "0" : "1"}" role="switch" aria-checked="${local.on}" aria-label="${LOCAL_TOOL_ACCESS}" class="remote-switch" data-local-tools-switch></button></form>`;
|
|
235
|
+
// The key leaves out the time left, which the page counts down by itself.
|
|
236
|
+
const autoLine = (time) => auto
|
|
237
|
+
? `<div class="remote-auto-line">${BOLT}<b>自動允許中</b>${time}<span class="hint">Agent 的動作不會再問你。碰到機密檔案,或刪除專案資料夾以外的檔案,仍然會問。</span>`
|
|
238
|
+
+ `<form method="post" action="/auto-approval-stop"><button type="submit" class="remote-auto-stop">停止自動允許</button></form></div>`
|
|
239
|
+
: "";
|
|
240
|
+
const time = !auto ? "" : auto.endsAt === undefined
|
|
241
|
+
? `<span class="remote-auto-time">${(0, html_1.escapeHtml)(auto.label)}</span>`
|
|
242
|
+
: `<span class="remote-auto-time" data-auto-ends-at="${auto.endsAt}">剩 ${timeLeftText(auto.secondsLeft ?? 0)}</span>`;
|
|
243
|
+
const key = statusKey(`${main}${toggle}${autoLine(auto?.endsAt === undefined ? "" : String(auto.endsAt))}${guidance}`);
|
|
244
|
+
const body = `${main}${toggle}${autoLine(time)}${guidance}`;
|
|
245
|
+
return { key, html: `<section class="tile remote-status${auto ? " is-auto" : ""}" data-remote-status data-status-key="${(0, html_1.escapeHtml)(key)}">${body}</section>` };
|
|
246
|
+
}
|
|
247
|
+
/** The time left of Auto Approval, for example "9:41". */
|
|
248
|
+
function timeLeftText(seconds) {
|
|
249
|
+
const whole = Math.max(0, Math.ceil(seconds));
|
|
250
|
+
return `${Math.floor(whole / 60)}:${String(whole % 60).padStart(2, "0")}`;
|
|
251
|
+
}
|
|
252
|
+
// A short key of the status bar, so that the poll redraws it only when it changes.
|
|
253
|
+
function statusKey(html) {
|
|
254
|
+
let hash = 0;
|
|
255
|
+
for (let i = 0; i < html.length; i++)
|
|
256
|
+
hash = (hash * 31 + html.charCodeAt(i)) | 0;
|
|
257
|
+
return `${html.length}:${(hash >>> 0).toString(36)}`;
|
|
258
|
+
}
|
|
259
|
+
/** The 遠端 Agent page body that the poll and the page actions redraw: status bar, approval card, Remote Agent Log. */
|
|
260
|
+
function remoteAgentBody(view) {
|
|
261
|
+
const log = view.localTools?.log;
|
|
262
|
+
return `${remoteStatus(view).html}${approvalBlock(view.localTools?.approval, Boolean(view.localTools?.autoApproval))}${log ? (0, remoteAgentLogView_1.remoteAgentLogBlock)(log) : ""}`;
|
|
263
|
+
}
|
|
264
|
+
/** The answer of GET /remote-agent-log-entry?id=...: the details of one Remote Agent Log entry, or 404. */
|
|
265
|
+
function remoteAgentLogEntryResponse(view, id) {
|
|
266
|
+
return (0, remoteAgentLogView_1.logEntryResponse)(view.localTools?.log, id);
|
|
253
267
|
}
|
|
254
268
|
function adapterForms(view) {
|
|
255
269
|
const selected = view.adapters ?? { codex: "responses", claude: "responses" };
|
|
@@ -266,7 +280,7 @@ function adapterForms(view) {
|
|
|
266
280
|
return `<div class="model-client"><div class="client-head"><span class="adapter-label"><span class="${className}" tabindex="0" title="${status}" aria-label="${status}" data-client-light="${client}"></span>${clientIcons_1.clientIcons[client]}<span>${clientLabel(client)}</span></span><form class="modes client-modes" method="post" action="/switch"><input type="hidden" name="client" value="${client}"><button type="submit" name="mode" value="native" aria-pressed="${mode === "native"}" class="${mode === "native" ? "on" : ""}"${locked(view)}>個人</button><button type="submit" name="mode" value="classroom" aria-pressed="${mode === "classroom"}" class="${mode === "classroom" ? "on" : ""}"${!available || !routeHealthy || view.commandRunning ? " disabled" : ""}>課堂</button></form></div><form class="adapter-row" method="post" action="/adapter"><input type="hidden" name="client" value="${client}"><span class="adapter-select"><select name="adapter" aria-label="${clientLabel(client)} API 協定"${adapterDisabled ? " disabled" : ""}>${options}</select><svg viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="m7 10 5 5 5-5"/></svg></span></form><span class="client-flow" data-client-flow="${client}" aria-hidden="true"></span></div>`;
|
|
267
281
|
}).join("");
|
|
268
282
|
return forms +
|
|
269
|
-
(view.adapterNotice ? `<p class="hint">${escapeHtml(view.adapterNotice)}</p>` : "");
|
|
283
|
+
(view.adapterNotice ? `<p class="hint">${(0, html_1.escapeHtml)(view.adapterNotice)}</p>` : "");
|
|
270
284
|
}
|
|
271
285
|
/** Environment Tool Readiness 與按下「確認安裝」後對該工具做的事。 */
|
|
272
286
|
const READINESS_MARK = {
|
|
@@ -319,17 +333,17 @@ function environmentInner(view) {
|
|
|
319
333
|
const tools = view.tools
|
|
320
334
|
.map((tool) => {
|
|
321
335
|
const checked = tool.selected ? " checked" : "";
|
|
322
|
-
const title = tool.reason ? ` title="${escapeHtml(tool.reason)}"` : "";
|
|
336
|
+
const title = tool.reason ? ` title="${(0, html_1.escapeHtml)(tool.reason)}"` : "";
|
|
323
337
|
// 安裝中的工具顯示階段;頁面輪詢 /environment-status 更新這段文字。
|
|
324
338
|
const mark = view.environmentInstalling && tool.progress
|
|
325
|
-
? `<span class="tool-stage" data-environment-stage="${escapeHtml(tool.id)}">${escapeHtml(environmentStageText(tool.progress))}</span>`
|
|
339
|
+
? `<span class="tool-stage" data-environment-stage="${(0, html_1.escapeHtml)(tool.id)}">${(0, html_1.escapeHtml)(environmentStageText(tool.progress))}</span>`
|
|
326
340
|
: READINESS_MARK[tool.readiness];
|
|
327
|
-
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>`;
|
|
341
|
+
return `<label class="tool"><input type="checkbox" name="tool" value="${(0, html_1.escapeHtml)(tool.id)}"${checked}${off}> ${environmentIcons_1.environmentIcons[tool.id]}<span${title}>${(0, html_1.escapeHtml)(tool.label)}</span> ${mark}</label>`;
|
|
328
342
|
})
|
|
329
343
|
.join("");
|
|
330
344
|
const polling = environmentPolling(view) ? " data-environment-progress" : "";
|
|
331
345
|
const note = view.environmentNotice
|
|
332
|
-
? `<p class="hint">${escapeHtml(view.environmentNotice)}</p>`
|
|
346
|
+
? `<p class="hint">${(0, html_1.escapeHtml)(view.environmentNotice)}</p>`
|
|
333
347
|
: "";
|
|
334
348
|
// 紀錄資料夾的路徑不放進頁面;伺服器開啟 ClassroomApp 記得的最近一次。
|
|
335
349
|
const openLog = view.environmentLogFolder && !view.commandRunning
|
|
@@ -357,10 +371,10 @@ function catalogInner(view) {
|
|
|
357
371
|
return `<p class="empty">這台電腦還沒有課程清單。</p>`;
|
|
358
372
|
}
|
|
359
373
|
const error = view.catalogError
|
|
360
|
-
? `<p class="error">${escapeHtml(view.catalogError)}</p>`
|
|
374
|
+
? `<p class="error">${(0, html_1.escapeHtml)(view.catalogError)}</p>`
|
|
361
375
|
: "";
|
|
362
376
|
const note = view.catalog?.localNote
|
|
363
|
-
? `<p class="hint">${escapeHtml(view.catalog.localNote)}</p>`
|
|
377
|
+
? `<p class="hint">${(0, html_1.escapeHtml)(view.catalog.localNote)}</p>`
|
|
364
378
|
: "";
|
|
365
379
|
return `${note}${error}`;
|
|
366
380
|
}
|
|
@@ -370,7 +384,7 @@ function commandInner(view) {
|
|
|
370
384
|
return `<p class="empty">沒有待確認的指令。</p>`;
|
|
371
385
|
}
|
|
372
386
|
const command = view.pendingCommand
|
|
373
|
-
? `<pre class="pending">${escapeHtml(view.pendingCommand)}</pre>`
|
|
387
|
+
? `<pre class="pending">${(0, html_1.escapeHtml)(view.pendingCommand)}</pre>`
|
|
374
388
|
: "";
|
|
375
389
|
// 執行中保留「確認執行」的空間,讓「停止安裝」落在「取消」的位置,避免連點誤觸。
|
|
376
390
|
const running = view.commandRunning;
|
|
@@ -382,17 +396,17 @@ function commandInner(view) {
|
|
|
382
396
|
</div>`
|
|
383
397
|
: "";
|
|
384
398
|
const output = hasOutput
|
|
385
|
-
? `<h3>指令輸出</h3><pre>${escapeHtml(view.commandOutput ?? "")}</pre>`
|
|
399
|
+
? `<h3>指令輸出</h3><pre>${(0, html_1.escapeHtml)(view.commandOutput ?? "")}</pre>`
|
|
386
400
|
: "";
|
|
387
401
|
return `${command}${choices}${output}`;
|
|
388
402
|
}
|
|
389
403
|
function snippetInner(snippet) {
|
|
390
404
|
const hint = snippet.pasteHint
|
|
391
|
-
? `<p class="hint">${escapeHtml(snippet.pasteHint)}</p>`
|
|
405
|
+
? `<p class="hint">${(0, html_1.escapeHtml)(snippet.pasteHint)}</p>`
|
|
392
406
|
: "";
|
|
393
|
-
return `<h3>${escapeHtml(snippet.title)}</h3>
|
|
407
|
+
return `<h3>${(0, html_1.escapeHtml)(snippet.title)}</h3>
|
|
394
408
|
${hint}
|
|
395
|
-
<pre>${escapeHtml(snippet.body)}</pre>`;
|
|
409
|
+
<pre>${(0, html_1.escapeHtml)(snippet.body)}</pre>`;
|
|
396
410
|
}
|
|
397
411
|
function catalogTable(view) {
|
|
398
412
|
const head = catalogInner(view);
|
|
@@ -400,13 +414,13 @@ function catalogTable(view) {
|
|
|
400
414
|
.map((action) => {
|
|
401
415
|
const off = view.commandRunning ? " disabled" : "";
|
|
402
416
|
const description = action.description
|
|
403
|
-
? `<p class="hint">${escapeHtml(action.description)}</p>`
|
|
417
|
+
? `<p class="hint">${(0, html_1.escapeHtml)(action.description)}</p>`
|
|
404
418
|
: "";
|
|
405
419
|
return `<tr>
|
|
406
|
-
<td>${escapeHtml((0, courseCatalog_1.actionKindLabel)(action.kind))}</td>
|
|
407
|
-
<td><strong>${escapeHtml(action.title)}</strong>${description}<code>${escapeHtml(action.command)}</code></td>
|
|
420
|
+
<td>${(0, html_1.escapeHtml)((0, courseCatalog_1.actionKindLabel)(action.kind))}</td>
|
|
421
|
+
<td><strong>${(0, html_1.escapeHtml)(action.title)}</strong>${description}<code>${(0, html_1.escapeHtml)(action.command)}</code></td>
|
|
408
422
|
<td><form method="post" action="/prepare">
|
|
409
|
-
<input type="hidden" name="action_id" value="${escapeHtml(action.id)}">
|
|
423
|
+
<input type="hidden" name="action_id" value="${(0, html_1.escapeHtml)(action.id)}">
|
|
410
424
|
<button type="submit"${off}>查看完整指令</button>
|
|
411
425
|
</form></td>
|
|
412
426
|
</tr>`;
|
|
@@ -727,6 +741,12 @@ const SIDE_PAGES = [
|
|
|
727
741
|
label: "Prompt 觀察室",
|
|
728
742
|
icon: `<svg viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="6.5"/><path d="m20 20-4.4-4.4M8 9.5h6M8 12.5h4"/></svg>`,
|
|
729
743
|
},
|
|
744
|
+
{
|
|
745
|
+
id: "remote-agent",
|
|
746
|
+
href: "/remote-agent",
|
|
747
|
+
label: "遠端 Agent",
|
|
748
|
+
icon: `<svg viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="4" width="18" height="13" rx="2"/><path d="m7 9 2.5 2L7 13M12 13h4M8 21h8M12 17v4"/></svg>`,
|
|
749
|
+
},
|
|
730
750
|
];
|
|
731
751
|
const BRAND = `<div class="brand"><div class="logo-badge"><img src="/brand-logo.png" alt=""></div><h1 class="brand-title">${PRODUCT}</h1><span class="ver">${VERSION}</span></div>`;
|
|
732
752
|
/** 兩頁共用的側欄:行動版頂列、抽屜遮罩、選單與外觀切換。 */
|
|
@@ -803,7 +823,7 @@ function basePage(view) {
|
|
|
803
823
|
<button type="button" data-appearance-toggle aria-label="切換外觀"></button>
|
|
804
824
|
</header>
|
|
805
825
|
<main>
|
|
806
|
-
<p class="display">${escapeHtml(statusWord(view))}</p>
|
|
826
|
+
<p class="display">${(0, html_1.escapeHtml)(statusWord(view))}</p>
|
|
807
827
|
${notices(view)}
|
|
808
828
|
<div class="modules">
|
|
809
829
|
${tile("連線", connectInner(view))}
|
|
@@ -823,10 +843,10 @@ function installActionCards(view) {
|
|
|
823
843
|
.map((action, index) => {
|
|
824
844
|
const number = index + 1;
|
|
825
845
|
const description = action.description
|
|
826
|
-
? `<p class="hint">${escapeHtml(action.description)}</p>`
|
|
846
|
+
? `<p class="hint">${(0, html_1.escapeHtml)(action.description)}</p>`
|
|
827
847
|
: "";
|
|
828
848
|
const installed = view.installedActionIds?.includes(action.id) ?? false;
|
|
829
|
-
return `<article class="install-card${installed ? " installed" : ""}"><span class="install-number" aria-hidden="true">${number}</span><div class="install-main"><div class="install-line"><strong><span class="visually-hidden">安裝 ${number}:</span>${escapeHtml(action.title)}</strong><span data-kind="${escapeHtml(action.kind)}" class="kind-tag">${escapeHtml((0, courseCatalog_1.actionKindLabel)(action.kind))}</span></div>${description}</div><form method="post" action="/prepare"><input type="hidden" name="action_id" value="${escapeHtml(action.id)}"><button type="submit"${installed ? ' class="quiet"' : ""}${off}>${installed ? "重新安裝" : "安裝"}</button></form></article>`;
|
|
849
|
+
return `<article class="install-card${installed ? " installed" : ""}"><span class="install-number" aria-hidden="true">${number}</span><div class="install-main"><div class="install-line"><strong><span class="visually-hidden">安裝 ${number}:</span>${(0, html_1.escapeHtml)(action.title)}</strong><span data-kind="${(0, html_1.escapeHtml)(action.kind)}" class="kind-tag">${(0, html_1.escapeHtml)((0, courseCatalog_1.actionKindLabel)(action.kind))}</span></div>${description}</div><form method="post" action="/prepare"><input type="hidden" name="action_id" value="${(0, html_1.escapeHtml)(action.id)}"><button type="submit"${installed ? ' class="quiet"' : ""}${off}>${installed ? "重新安裝" : "安裝"}</button></form></article>`;
|
|
830
850
|
})
|
|
831
851
|
.join("");
|
|
832
852
|
}
|
|
@@ -845,7 +865,7 @@ function presentCommand(body, view) {
|
|
|
845
865
|
return { inline, dialog };
|
|
846
866
|
}
|
|
847
867
|
function projectFolderRow(view) {
|
|
848
|
-
return `<div class="project-folder-row"><div class="project-folder-info"><span class="hint">專案資料夾</span><p class="folder-path"${view.projectFolder ? ` title="${escapeHtml(view.projectFolder)}"` : ""}>${escapeHtml(view.projectFolder || "尚未選擇安裝位置")}</p></div><form method="post" action="/pick-folder"><button type="submit" class="quiet"${locked(view)}>${view.projectFolder ? "變更" : "選擇專案資料夾"}</button></form>${view.folderError ? `<p class="error" role="alert">${escapeHtml(view.folderError)}</p>` : ""}${view.installNotice ? `<p class="hint" role="status">${escapeHtml(view.installNotice)}</p>` : ""}</div>`;
|
|
868
|
+
return `<div class="project-folder-row"><div class="project-folder-info"><span class="hint">專案資料夾</span><p class="folder-path"${view.projectFolder ? ` title="${(0, html_1.escapeHtml)(view.projectFolder)}"` : ""}>${(0, html_1.escapeHtml)(view.projectFolder || "尚未選擇安裝位置")}</p></div><form method="post" action="/pick-folder"><button type="submit" class="quiet"${locked(view)}>${view.projectFolder ? "變更" : "選擇專案資料夾"}</button></form>${view.folderError ? `<p class="error" role="alert">${(0, html_1.escapeHtml)(view.folderError)}</p>` : ""}${view.installNotice ? `<p class="hint" role="status">${(0, html_1.escapeHtml)(view.installNotice)}</p>` : ""}</div>`;
|
|
849
869
|
}
|
|
850
870
|
function splitCourseCards(html, view) {
|
|
851
871
|
const commandMatch = html.match(/<section class="tile wide"><h2>指令<\/h2>([\s\S]*?)<\/section>/);
|
|
@@ -862,12 +882,12 @@ function splitCourseCards(html, view) {
|
|
|
862
882
|
const copied = new Set(view.copiedSnippetIds ?? []);
|
|
863
883
|
const snippetBody = (view.catalog?.snippets ?? []).map((snippet, index) => {
|
|
864
884
|
const number = index + 1;
|
|
865
|
-
const title = escapeHtml(snippet.title);
|
|
885
|
+
const title = (0, html_1.escapeHtml)(snippet.title);
|
|
866
886
|
const done = copied.has(snippet.id);
|
|
867
887
|
const hint = snippet.pasteHint
|
|
868
|
-
? `<span class="snippet-hint">${escapeHtml(snippet.pasteHint)}</span>`
|
|
888
|
+
? `<span class="snippet-hint">${(0, html_1.escapeHtml)(snippet.pasteHint)}</span>`
|
|
869
889
|
: "";
|
|
870
|
-
return `<article class="snippet-card${done ? " copied" : ""}"><span class="snippet-number" aria-hidden="true">${number}</span><div class="snippet-main"><div class="snippet-line"><strong><span class="visually-hidden">片段 ${number}:</span>${title}</strong>${hint}</div><details class="snippet-peek"><summary>查看內容</summary><pre class="snippet-code">${escapeHtml(snippet.body)}</pre></details></div><button type="button"${done ? ' class="quiet"' : ""} data-copy-snippet="${escapeHtml(snippet.id)}" aria-label="${done ? "再複製一次" : "複製"}「${title}」">${COPY_ICON}<span>${done ? "✓ 已複製" : "複製"}</span></button><span class="visually-hidden" data-snippet-copy-status role="status" aria-live="polite"></span></article>`;
|
|
890
|
+
return `<article class="snippet-card${done ? " copied" : ""}"><span class="snippet-number" aria-hidden="true">${number}</span><div class="snippet-main"><div class="snippet-line"><strong><span class="visually-hidden">片段 ${number}:</span>${title}</strong>${hint}</div><details class="snippet-peek"><summary>查看內容</summary><pre class="snippet-code">${(0, html_1.escapeHtml)(snippet.body)}</pre></details></div><button type="button"${done ? ' class="quiet"' : ""} data-copy-snippet="${(0, html_1.escapeHtml)(snippet.id)}" aria-label="${done ? "再複製一次" : "複製"}「${title}」">${COPY_ICON}<span>${done ? "✓ 已複製" : "複製"}</span></button><span class="visually-hidden" data-snippet-copy-status role="status" aria-live="polite"></span></article>`;
|
|
871
891
|
}).join("") || `<p class="empty">這堂課沒有片段。</p>`;
|
|
872
892
|
const chevron = `<svg class="course-chevron" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="2"><path d="m9 6 6 6-6 6"/></svg>`;
|
|
873
893
|
const install = `<section class="tile wide"><details class="course-section" data-course-section="install" open><summary class="tile-head"><h2>課程安裝</h2>${chevron}</summary><div class="course-content">${courseBody}${presented.inline}</div></details></section>${presented.dialog}`;
|
|
@@ -978,7 +998,7 @@ function organizeSettings(html, view) {
|
|
|
978
998
|
const quote = view.connectionError === "請先輸入邀請碼與課堂暱稱,再按「連線」。"
|
|
979
999
|
? "我披風都穿好了,你的邀請碼跟暱稱呢?"
|
|
980
1000
|
: "連線這關還沒過,披風倒是先上班了。照下面的提示再試一次!";
|
|
981
|
-
const speech = `<div class="mascot-speech"><p class="mascot-quote">${escapeHtml(quote)}</p>${feedback}</div>`;
|
|
1001
|
+
const speech = `<div class="mascot-speech"><p class="mascot-quote">${(0, html_1.escapeHtml)(quote)}</p>${feedback}</div>`;
|
|
982
1002
|
body += connectionMascot_1.connectionMascot.replace('class="connection-mascot"', 'class="connection-mascot mascot-waiting"').replace('<div class="mascot-traveler">', `${speech}<div class="mascot-traveler">`);
|
|
983
1003
|
}
|
|
984
1004
|
}
|
|
@@ -1048,17 +1068,17 @@ function renderPage(view) {
|
|
|
1048
1068
|
if (view.connected && view.canCopyKey) {
|
|
1049
1069
|
const off = view.commandRunning ? " disabled" : "";
|
|
1050
1070
|
const course = view.courseTitle
|
|
1051
|
-
? `<p class="course-title">${escapeHtml(view.courseTitle)}</p>`
|
|
1071
|
+
? `<p class="course-title">${(0, html_1.escapeHtml)(view.courseTitle)}</p>`
|
|
1052
1072
|
: "";
|
|
1053
1073
|
const meta = [view.sessionTitle, view.nickname]
|
|
1054
1074
|
.filter((value) => Boolean(value))
|
|
1055
|
-
.map((value) => `<span>${escapeHtml(value)}</span>`)
|
|
1075
|
+
.map((value) => `<span>${(0, html_1.escapeHtml)(value)}</span>`)
|
|
1056
1076
|
.join('<span class="connection-separator" aria-hidden="true">·</span>');
|
|
1057
1077
|
const identity = course || meta
|
|
1058
1078
|
? `<div class="connection-identity">${course}${meta ? `<p class="connection-meta">${meta}</p>` : ""}</div>`
|
|
1059
1079
|
: "";
|
|
1060
1080
|
const mascot = `<div class="classroom-update-home"><div class="classroom-update">${connectionMascot_1.connectionMascot}${(0, classroomUpdate_1.classroomUpdateControl)(view, restartHtml(view))}</div></div>`;
|
|
1061
|
-
const block = `${identity}<div class="key-row"><p>API Key 已設定</p><form method="post" action="/copy"><button type="submit" class="connection-copy" aria-label="複製 Classroom API Key"${off}>${COPY_ICON}<span>複製</span></button></form></div>${mascot}<form method="post" action="/clear"><button type="submit" class="connection-clear"${off}>清除連線</button></form
|
|
1081
|
+
const block = `${identity}<div class="key-row"><p>API Key 已設定</p><form method="post" action="/copy"><button type="submit" class="connection-copy" aria-label="複製 Classroom API Key"${off}>${COPY_ICON}<span>複製</span></button></form></div>${mascot}<form method="post" action="/clear"><button type="submit" class="connection-clear"${off}>清除連線</button></form>`;
|
|
1062
1082
|
html = html.replace(/<form method="post" action="\/copy">[\s\S]*?<\/form>\s*<form method="post" action="\/clear">[\s\S]*?<\/form>/, block);
|
|
1063
1083
|
html = html.replace(/<p class="class-label">[\s\S]*?<\/p>/, "");
|
|
1064
1084
|
html = html.replace(`<p class="detail">Classroom API Key 已設定。</p>`, "");
|
|
@@ -1090,21 +1110,6 @@ function renderPage(view) {
|
|
|
1090
1110
|
.connection-meta { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 8px; color: var(--muted); font-size: 13px; line-height: 1.6; }
|
|
1091
1111
|
.connection-meta > span { min-width: 0; overflow-wrap: anywhere; }
|
|
1092
1112
|
.connection-separator { opacity: 0.5; }
|
|
1093
|
-
.local-tools { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
|
|
1094
|
-
.local-tools-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
|
|
1095
|
-
.local-tools-switch { min-width: 3.5rem; background: var(--modes); color: var(--text); }
|
|
1096
|
-
.local-tools-switch.on { background: var(--accent); color: var(--on-accent); }
|
|
1097
|
-
.local-tools .hint { font-size: 13px; overflow-wrap: anywhere; }
|
|
1098
|
-
.local-approval { display: flex; flex-direction: column; gap: 6px; padding: 10px; border: 2px solid var(--accent); border-radius: 8px; }
|
|
1099
|
-
.local-approval-title { margin: 0; overflow-wrap: anywhere; }
|
|
1100
|
-
.local-approval-body { margin: 0; max-height: 16rem; overflow: auto; padding: 8px; background: var(--modes); border-radius: 6px; font-size: 13px; white-space: pre-wrap; overflow-wrap: anywhere; }
|
|
1101
|
-
.local-approval-full { align-self: flex-start; background: none; color: var(--accent); padding: 0; text-decoration: underline; }
|
|
1102
|
-
.local-approval-actions { display: flex; gap: 8px; }
|
|
1103
|
-
.local-commands ol { margin: 0; padding-left: 1.4rem; display: flex; flex-direction: column; gap: 4px; max-height: 14rem; overflow: auto; }
|
|
1104
|
-
.local-commands li code { white-space: pre-wrap; overflow-wrap: anywhere; margin-right: 6px; }
|
|
1105
|
-
.local-command-stop { margin-left: 6px; padding: 2px 10px; }
|
|
1106
|
-
.local-commands form { display: inline; }
|
|
1107
|
-
.local-approval-approve { background: var(--accent); color: var(--on-accent); }
|
|
1108
1113
|
.tool em { color: var(--text); }
|
|
1109
1114
|
.tool em.missing { color: var(--muted); }
|
|
1110
1115
|
.tool em.needs-repair { color: light-dark(#9a4a08, #fbbf24); }
|
|
@@ -1222,7 +1227,7 @@ function renderPage(view) {
|
|
|
1222
1227
|
main button.connection-clear:hover:not(:disabled) { color: light-dark(#b91c1c, #f87171); }
|
|
1223
1228
|
${classroomUpdate_1.classroomUpdateStyles}
|
|
1224
1229
|
</style>
|
|
1225
|
-
<script>${drawerScript()}${powerMenuView_1.powerMenuScript}${installProgress_1.installProgressScript}${environmentProgress_1.environmentProgressScript}${snippetCopyScript()}${courseSectionScript()}${connectionMascot_1.connectionMascotScript}${classroomUpdate_1.classroomUpdateScript}${settingsActions_1.settingsActionsScript}${modelStatus_1.modelStatusScript}
|
|
1230
|
+
<script>${drawerScript()}${powerMenuView_1.powerMenuScript}${installProgress_1.installProgressScript}${environmentProgress_1.environmentProgressScript}${snippetCopyScript()}${courseSectionScript()}${connectionMascot_1.connectionMascotScript}${classroomUpdate_1.classroomUpdateScript}${settingsActions_1.settingsActionsScript}${modelStatus_1.modelStatusScript}
|
|
1226
1231
|
</script>`;
|
|
1227
1232
|
return html.replace("</body>", `${extra}</body>`);
|
|
1228
1233
|
}
|
|
@@ -1298,3 +1303,152 @@ function renderInspectorPage(view) {
|
|
|
1298
1303
|
</body>
|
|
1299
1304
|
</html>`;
|
|
1300
1305
|
}
|
|
1306
|
+
// The page actions of 遠端 Agent: post without a reload, then redraw the page body from the answer.
|
|
1307
|
+
// settingsBusy is the name that modelStatusScript reads to hold the status poll while an action runs.
|
|
1308
|
+
const remoteAgentActionsScript = `
|
|
1309
|
+
var settingsBusy = false;
|
|
1310
|
+
document.addEventListener("submit", async function (event) {
|
|
1311
|
+
var form = event.target;
|
|
1312
|
+
if (!form?.matches?.('form[action="/local-tools"], form[action="/local-tool-approval"], form[action="/remote-agent-log-stop"], form[action="/auto-approval-start"], form[action="/auto-approval-stop"]')) return;
|
|
1313
|
+
event.preventDefault();
|
|
1314
|
+
if (settingsBusy) return;
|
|
1315
|
+
settingsBusy = true;
|
|
1316
|
+
var app = document.getElementById("remote-app");
|
|
1317
|
+
app.querySelector(".remote-action-error")?.remove();
|
|
1318
|
+
var body = new URLSearchParams(new FormData(form));
|
|
1319
|
+
if (event.submitter?.name) body.set(event.submitter.name, event.submitter.value);
|
|
1320
|
+
var buttons = app.querySelectorAll("button");
|
|
1321
|
+
buttons.forEach(function (button) { button.disabled = true; });
|
|
1322
|
+
try {
|
|
1323
|
+
var response = await fetch(form.action, { method: "POST", headers: { "X-Remote-Agent": "1" }, body: body });
|
|
1324
|
+
if (!response.ok) throw new Error("remote agent action failed");
|
|
1325
|
+
var next = new DOMParser().parseFromString(await response.text(), "text/html").getElementById("remote-app");
|
|
1326
|
+
if (!next) throw new Error("remote agent page unavailable");
|
|
1327
|
+
keepRemoteAgentLogPlace(function () { app.replaceChildren(...next.childNodes); });
|
|
1328
|
+
form.closest("dialog")?.close();
|
|
1329
|
+
} catch (error) {
|
|
1330
|
+
buttons.forEach(function (button) { button.disabled = false; });
|
|
1331
|
+
var message = document.createElement("p");
|
|
1332
|
+
message.className = "error remote-action-error";
|
|
1333
|
+
message.setAttribute("role", "alert");
|
|
1334
|
+
message.textContent = "操作未完成,請再試一次。";
|
|
1335
|
+
app.prepend(message);
|
|
1336
|
+
} finally {
|
|
1337
|
+
settingsBusy = false;
|
|
1338
|
+
}
|
|
1339
|
+
});
|
|
1340
|
+
`;
|
|
1341
|
+
// Auto Approval on the page: 自動允許 ▾ opens the reminder dialog (not a browser dialog), and the
|
|
1342
|
+
// status bar counts the time left down by itself between polls.
|
|
1343
|
+
const autoApprovalScript = `
|
|
1344
|
+
document.addEventListener("click", function (event) {
|
|
1345
|
+
var item = event.target.closest && event.target.closest("[data-auto-approval]");
|
|
1346
|
+
var dialog = document.querySelector("[data-auto-dialog]");
|
|
1347
|
+
if (item && dialog) {
|
|
1348
|
+
dialog.querySelector("[data-auto-dialog-duration]").value = item.getAttribute("data-auto-approval");
|
|
1349
|
+
dialog.querySelector("[data-auto-dialog-label]").textContent = item.textContent;
|
|
1350
|
+
item.closest("details")?.removeAttribute("open");
|
|
1351
|
+
dialog.showModal();
|
|
1352
|
+
return;
|
|
1353
|
+
}
|
|
1354
|
+
if (event.target.closest && event.target.closest("[data-auto-dialog-cancel]")) dialog?.close();
|
|
1355
|
+
});
|
|
1356
|
+
setInterval(function () {
|
|
1357
|
+
document.querySelectorAll("[data-auto-ends-at]").forEach(function (time) {
|
|
1358
|
+
var seconds = Math.max(0, Math.ceil((Number(time.getAttribute("data-auto-ends-at")) - Date.now()) / 1000));
|
|
1359
|
+
time.textContent = "剩 " + Math.floor(seconds / 60) + ":" + String(seconds % 60).padStart(2, "0");
|
|
1360
|
+
});
|
|
1361
|
+
}, 1000);
|
|
1362
|
+
`;
|
|
1363
|
+
/** The reminder before Auto Approval starts (ADR 0014). It stays outside #remote-app, so the poll does not redraw it. */
|
|
1364
|
+
const AUTO_APPROVAL_DIALOG = `<dialog class="auto-dialog" data-auto-dialog aria-label="打開自動允許"><form method="post" action="/auto-approval-start"><input type="hidden" name="duration" value="10" data-auto-dialog-duration>`
|
|
1365
|
+
+ `<h3>${BOLT}打開自動允許(<span data-auto-dialog-label>10 分鐘</span>)</h3>`
|
|
1366
|
+
+ `<p>自動允許期間,Agent 可以不經過你,直接執行指令、寫入檔案和儲存圖片。</p>`
|
|
1367
|
+
+ `<p class="auto-dialog-warn">如果你的 Agent 會讀網頁或電子郵件,那些內容可能藏著給 Agent 的指令。</p>`
|
|
1368
|
+
+ `<p class="hint">下面這兩種情況仍然會問你:</p><ul class="hint"><li>碰到機密檔案,例如 <code>.env</code>、私密金鑰</li><li>刪除專案資料夾以外的檔案</li></ul>`
|
|
1369
|
+
+ `<p class="hint">排隊中的確認也會一起允許。你隨時可以按「停止自動允許」。</p>`
|
|
1370
|
+
+ `<div class="auto-dialog-actions"><button type="button" data-auto-dialog-cancel>取消</button><button type="submit" class="auto-dialog-ok">確定打開</button></div></form></dialog>`;
|
|
1371
|
+
const REMOTE_AGENT_STYLES = `
|
|
1372
|
+
main.remote-main { width: min(72rem, 100%); }
|
|
1373
|
+
main.remote-main, .auto-dialog { --auto: light-dark(#7c3aed, #a78bfa); --auto-err: light-dark(#c0362c, #ff7b72); }
|
|
1374
|
+
#remote-app { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
|
|
1375
|
+
.remote-main .tile { gap: 10px; padding: 16px 18px; min-width: 0; }
|
|
1376
|
+
.remote-main .hint { color: var(--muted); font-size: 13px; line-height: 1.6; }
|
|
1377
|
+
.remote-status { flex-direction: row; align-items: center; flex-wrap: wrap; gap: 10px 16px; }
|
|
1378
|
+
.remote-status-main { display: flex; align-items: center; gap: 10px; flex: 1 1 20rem; min-width: 0; }
|
|
1379
|
+
.remote-status-main strong { font-size: 14px; overflow-wrap: anywhere; }
|
|
1380
|
+
.remote-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex-shrink: 0; }
|
|
1381
|
+
.remote-dot.on { background: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent); }
|
|
1382
|
+
.remote-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
|
|
1383
|
+
.remote-chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; background: var(--input); color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
|
|
1384
|
+
.remote-chip b { color: var(--text); font-weight: 600; }
|
|
1385
|
+
.remote-switch-row { display: flex; flex-direction: row; align-items: center; gap: 10px; font-size: 13px; white-space: nowrap; }
|
|
1386
|
+
/* 頁面的一般 button 樣式會改變開關大小,所以開關有自己的固定尺寸。 */
|
|
1387
|
+
main button.remote-switch { box-sizing: border-box; position: relative; width: 44px; height: 26px; min-width: 44px; min-height: 26px; max-height: 26px; padding: 0; line-height: 0; flex: 0 0 44px; border: 0; border-radius: 999px; background: var(--modes); }
|
|
1388
|
+
.remote-switch::after { content: ""; position: absolute; top: 50%; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); transform: translateY(-50%); transition: left 0.15s; }
|
|
1389
|
+
main button.remote-switch[aria-checked="true"] { background: var(--accent); }
|
|
1390
|
+
.remote-switch[aria-checked="true"]::after { left: calc(100% - 23px); }
|
|
1391
|
+
.remote-setup { flex-basis: 100%; margin: 0; padding: 10px 12px; border-radius: 8px; background: var(--input); color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
|
|
1392
|
+
.local-approval { border: 1px solid color-mix(in srgb, var(--accent) 60%, transparent); box-shadow: inset 4px 0 0 var(--accent); }
|
|
1393
|
+
.local-approval-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
|
|
1394
|
+
.local-approval-title { margin: 0; font-size: 15px; overflow-wrap: anywhere; }
|
|
1395
|
+
.local-approval-queue { margin-left: auto; }
|
|
1396
|
+
.local-approval-body { margin: 0; max-height: 16rem; overflow: auto; padding: 8px 10px; background: var(--input); border-radius: 6px; font-size: 13px; white-space: pre-wrap; overflow-wrap: anywhere; }
|
|
1397
|
+
main button.local-approval-full { align-self: flex-start; min-height: 0; background: none; color: var(--accent); padding: 0; text-decoration: underline; }
|
|
1398
|
+
.local-approval-timer { height: 4px; border-radius: 999px; background: var(--modes); overflow: hidden; }
|
|
1399
|
+
.local-approval-timer span { display: block; height: 100%; background: var(--accent); transition: width 1s linear; }
|
|
1400
|
+
.local-approval-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
|
|
1401
|
+
.local-approval-actions .hint { margin-right: auto; }
|
|
1402
|
+
main button.local-approval-deny { background: transparent; color: var(--text); border-color: var(--line); }
|
|
1403
|
+
.auto-bolt { width: 14px; height: 14px; flex-shrink: 0; }
|
|
1404
|
+
.remote-main .tile.remote-status.is-auto { border-color: color-mix(in srgb, var(--auto) 55%, transparent); box-shadow: inset 4px 0 0 var(--auto); }
|
|
1405
|
+
.remote-dot.auto { background: var(--auto); box-shadow: 0 0 0 4px color-mix(in srgb, var(--auto) 22%, transparent); }
|
|
1406
|
+
.remote-auto-line { flex-basis: 100%; display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; padding: 10px 12px; border-radius: 8px; background: color-mix(in srgb, var(--auto) 12%, transparent); color: var(--auto); font-size: 13px; }
|
|
1407
|
+
.remote-auto-line .hint { flex: 1 1 18rem; }
|
|
1408
|
+
.remote-auto-time { font-family: Consolas, "Cascadia Mono", monospace; font-variant-numeric: tabular-nums; font-weight: 700; }
|
|
1409
|
+
main button.remote-auto-stop { min-height: 0; padding: 4px 12px; background: transparent; color: var(--auto); border: 1px solid color-mix(in srgb, var(--auto) 55%, transparent); }
|
|
1410
|
+
.remote-main .tile.local-approval.is-exception { border-color: color-mix(in srgb, var(--auto-err) 55%, transparent); box-shadow: inset 4px 0 0 var(--auto-err); }
|
|
1411
|
+
.local-approval-exception { display: flex; align-items: center; gap: 6px; margin: 0; font-size: 13px; color: var(--auto-err); }
|
|
1412
|
+
.auto-menu { position: relative; }
|
|
1413
|
+
.auto-menu-button { list-style: none; cursor: pointer; padding: 6px 14px; border-radius: 999px; border: 1px solid color-mix(in srgb, var(--auto) 55%, transparent); color: var(--auto); font-size: 13px; }
|
|
1414
|
+
.auto-menu-button::-webkit-details-marker { display: none; }
|
|
1415
|
+
.auto-menu-list { position: absolute; right: 0; bottom: calc(100% + 6px); z-index: 30; display: flex; flex-direction: column; min-width: 10rem; padding: 4px; border-radius: 10px; background: var(--tile, var(--bg)); border: 1px solid var(--line); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3); }
|
|
1416
|
+
main .auto-menu-list button { min-height: 0; text-align: left; padding: 8px 12px; border: 0; border-radius: 6px; background: transparent; color: var(--text); font-size: 13px; }
|
|
1417
|
+
main .auto-menu-list button:hover { background: var(--modes); }
|
|
1418
|
+
.auto-dialog { width: min(30rem, calc(100% - 32px)); padding: 20px 22px; border-radius: 14px; border: 1px solid var(--line); background: var(--tile, var(--bg)); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4); font-size: 14px; line-height: 1.6; }
|
|
1419
|
+
.auto-dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
|
|
1420
|
+
.auto-dialog form { display: flex; flex-direction: column; gap: 8px; }
|
|
1421
|
+
.auto-dialog h3 { display: flex; align-items: center; gap: 6px; margin: 0 0 4px; font-size: 16px; color: var(--auto); }
|
|
1422
|
+
.auto-dialog p, .auto-dialog ul { margin: 0; }
|
|
1423
|
+
.auto-dialog ul { padding-left: 1.2rem; }
|
|
1424
|
+
.auto-dialog .hint { color: var(--muted); font-size: 13px; }
|
|
1425
|
+
.auto-dialog-warn { color: var(--auto-err); }
|
|
1426
|
+
.auto-dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
|
|
1427
|
+
.auto-dialog-actions button { padding: 7px 16px; border-radius: 999px; border: 1px solid var(--line); background: transparent; color: var(--text); font: inherit; font-size: 13px; cursor: pointer; }
|
|
1428
|
+
.auto-dialog-actions .auto-dialog-ok { background: var(--auto); color: #fff; border-color: transparent; font-weight: 600; }
|
|
1429
|
+
${remoteAgentLogView_1.REMOTE_AGENT_LOG_STYLES}`;
|
|
1430
|
+
/** 遠端 Agent:Local Tool Access 的開關、確認卡片和 Remote Agent Log,與其他頁共用頁殼、側欄、主題與法鬥超人頁首。 */
|
|
1431
|
+
function renderRemoteAgentPage(view) {
|
|
1432
|
+
return `${documentHead()}
|
|
1433
|
+
<body>
|
|
1434
|
+
${sideMenu("remote-agent")}
|
|
1435
|
+
<main class="remote-main">
|
|
1436
|
+
<header class="page-head pi-head"><div class="pi-head-text"><h2>遠端 Agent</h2><p>看看 Agent 透過 MCP 在這台電腦做了哪些事。</p></div>${connectionMascot_1.connectionMascot}</header>
|
|
1437
|
+
<div id="remote-app">${remoteAgentBody(view)}</div>
|
|
1438
|
+
</main>
|
|
1439
|
+
${AUTO_APPROVAL_DIALOG}
|
|
1440
|
+
<style>
|
|
1441
|
+
${SHELL_LAYOUT_STYLES}
|
|
1442
|
+
${SHELL_CONTROL_STYLES}
|
|
1443
|
+
.pi-head { display: flex; align-items: flex-end; flex-wrap: wrap; gap: 0 16px; }
|
|
1444
|
+
.pi-head-text { flex: 0 1 auto; padding-bottom: 12px; }
|
|
1445
|
+
.pi-head .connection-mascot { flex: 1 1 260px; height: 144px; }
|
|
1446
|
+
${connectionMascot_1.connectionMascotStyles}
|
|
1447
|
+
${headPatrol.styles}
|
|
1448
|
+
${REMOTE_AGENT_STYLES}
|
|
1449
|
+
</style>
|
|
1450
|
+
${headPatrol.sheet}
|
|
1451
|
+
<script>${drawerScript()}${powerMenuView_1.powerMenuScript}${connectionMascot_1.connectionMascotScript}${headPatrol.script}${remoteAgentActionsScript}${autoApprovalScript}${remoteAgentLogView_1.remoteAgentLogScript}${modelStatus_1.modelStatusScript}${modelStatus_1.approvalFullScript}</script>
|
|
1452
|
+
</body>
|
|
1453
|
+
</html>`;
|
|
1454
|
+
}
|