vanspod 0.4.10 → 0.4.13
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/start.js +1 -0
- package/dist/version.js +1 -1
- package/dist/versionUpdate.js +45 -27
- package/dist/vsCodeDefaultModel.js +197 -0
- package/dist/vsCodeRouteSettings.js +55 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -38,20 +38,20 @@ 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.13.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
|
|
|
45
45
|
## GitHub Actions 發佈
|
|
46
46
|
|
|
47
|
-
一般 push 不發佈;推送 `v*` tag 會在 Windows runner 安裝 Node.js 24、檢查型別、執行測試、打包並驗證 exe/npm 生命週期,全部通過後才建立 GitHub Release,最後發佈 npm 套件。學生從 Release 下載 `VansPod.exe`,同頁提供 `SHA256SUMS.txt`。
|
|
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.4.
|
|
49
|
+
發版前同步 `package.json`、`package-lock.json` 與 `src/version.ts` 的版本;tag 必須等於 `v` 加版本號,否則流程失敗。以 `0.4.13` 為例:
|
|
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.13 -m "VansPod 0.4.13"
|
|
54
|
+
git push origin v0.4.13
|
|
55
55
|
```
|
|
56
56
|
|
|
57
57
|
新版本使用新的版本號與 tag。相同 tag 的 Actions 重跑會更新該 Release 的產物。
|
package/dist/start.js
CHANGED
|
@@ -409,6 +409,7 @@ async function main(instance) {
|
|
|
409
409
|
settingsFile: copilotModelsFile(),
|
|
410
410
|
journalFile: node_path_1.default.join(node_os_1.default.homedir(), ".vanspod", "vscode-route-journal.json"),
|
|
411
411
|
legacyOrigins: [pageUrl.replace(/\/$/, ""), "http://127.0.0.1:47821"],
|
|
412
|
+
userSettingsFile: routePaths().vsCode,
|
|
412
413
|
}),
|
|
413
414
|
router: { redeemNickname, fetchSessionModels },
|
|
414
415
|
catalog: { fetchCourseCatalog },
|
package/dist/version.js
CHANGED
package/dist/versionUpdate.js
CHANGED
|
@@ -8,8 +8,12 @@ exports.compareVersions = compareVersions;
|
|
|
8
8
|
exports.downloadExe = downloadExe;
|
|
9
9
|
exports.createVersionUpdate = createVersionUpdate;
|
|
10
10
|
const node_crypto_1 = require("node:crypto");
|
|
11
|
+
const node_fs_1 = require("node:fs");
|
|
11
12
|
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
12
13
|
const node_path_1 = __importDefault(require("node:path"));
|
|
14
|
+
const node_stream_1 = require("node:stream");
|
|
15
|
+
const promises_2 = require("node:stream/promises");
|
|
16
|
+
const node_zlib_1 = require("node:zlib");
|
|
13
17
|
const desktop_1 = require("./desktop");
|
|
14
18
|
const exitGuard_1 = require("./exitGuard");
|
|
15
19
|
const instance_1 = require("./instance");
|
|
@@ -83,14 +87,18 @@ function createUpdateChecker() {
|
|
|
83
87
|
},
|
|
84
88
|
};
|
|
85
89
|
}
|
|
86
|
-
function
|
|
90
|
+
function listedChecksum(sums, name) {
|
|
87
91
|
for (const line of sums.split(/\r?\n/)) {
|
|
88
92
|
const match = /^([a-f0-9]{64})\s+\*?(.+)$/i.exec(line.trim());
|
|
89
93
|
if (match && match[2] === name)
|
|
90
94
|
return match[1].toLowerCase();
|
|
91
95
|
}
|
|
92
|
-
|
|
96
|
+
return undefined;
|
|
93
97
|
}
|
|
98
|
+
const EXE = "VansPod.exe";
|
|
99
|
+
const COMPRESSED_EXE = "VansPod.exe.br";
|
|
100
|
+
/** 讓每段資料經過時順手做一件事(算進度、算雜湊),資料原樣往下傳。 */
|
|
101
|
+
const tap = (each) => new node_stream_1.Transform({ transform(chunk, _encoding, done) { each(chunk); done(null, chunk); } });
|
|
94
102
|
/** 從 GitHub Release 下載新版 exe 到原檔旁的 `.new`;SHA-256 不符就刪掉並失敗。 */
|
|
95
103
|
async function downloadExe(version, file, onProgress, fetcher = fetch) {
|
|
96
104
|
const get = async (name) => {
|
|
@@ -99,34 +107,44 @@ async function downloadExe(version, file, onProgress, fetcher = fetch) {
|
|
|
99
107
|
throw new Error(`下載 ${name} 失敗(${response.status})`);
|
|
100
108
|
return response;
|
|
101
109
|
};
|
|
102
|
-
const
|
|
103
|
-
const
|
|
104
|
-
|
|
110
|
+
const sums = await (await get("SHA256SUMS.txt")).text();
|
|
111
|
+
const expected = listedChecksum(sums, EXE);
|
|
112
|
+
if (!expected)
|
|
113
|
+
throw new Error(`SHA256SUMS.txt 沒有 ${EXE}`);
|
|
105
114
|
const target = `${file}.new`;
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
115
|
+
const save = async (name, compressed) => {
|
|
116
|
+
const response = await get(name);
|
|
117
|
+
const total = Number(response.headers.get("content-length")) || 0;
|
|
118
|
+
const hash = (0, node_crypto_1.createHash)("sha256");
|
|
119
|
+
let received = 0;
|
|
120
|
+
try {
|
|
121
|
+
await (0, promises_2.pipeline)([
|
|
122
|
+
node_stream_1.Readable.fromWeb(response.body),
|
|
123
|
+
tap(chunk => { received += chunk.length; if (total)
|
|
124
|
+
onProgress(Math.min(100, Math.floor(received * 100 / total))); }),
|
|
125
|
+
...(compressed ? [(0, node_zlib_1.createBrotliDecompress)()] : []),
|
|
126
|
+
tap(chunk => hash.update(chunk)),
|
|
127
|
+
(0, node_fs_1.createWriteStream)(target),
|
|
128
|
+
]);
|
|
120
129
|
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
await promises_1.default.rm(target, { force: true });
|
|
132
|
+
throw error;
|
|
133
|
+
}
|
|
134
|
+
if (hash.digest("hex") !== expected) {
|
|
135
|
+
await promises_1.default.rm(target, { force: true });
|
|
136
|
+
throw new Error(`下載的 ${EXE} 驗證失敗,已刪除。`);
|
|
137
|
+
}
|
|
138
|
+
return target;
|
|
139
|
+
};
|
|
140
|
+
// 壓縮版只有完整 exe 的三分之一左右,驗證一律比對解壓後的 exe;舊 Release 沒列出它,或它下載、解壓、驗證任一步失敗,就改下載完整 exe。
|
|
141
|
+
if (listedChecksum(sums, COMPRESSED_EXE)) {
|
|
142
|
+
try {
|
|
143
|
+
return await save(COMPRESSED_EXE, true);
|
|
144
|
+
}
|
|
145
|
+
catch { }
|
|
121
146
|
}
|
|
122
|
-
|
|
123
|
-
await handle.close();
|
|
124
|
-
}
|
|
125
|
-
if (hash.digest("hex") !== expected) {
|
|
126
|
-
await promises_1.default.rm(target, { force: true });
|
|
127
|
-
throw new Error("下載的 VansPod.exe 驗證失敗,已刪除。");
|
|
128
|
-
}
|
|
129
|
-
return target;
|
|
147
|
+
return save(EXE, false);
|
|
130
148
|
}
|
|
131
149
|
async function folderWritable(file) {
|
|
132
150
|
const probe = node_path_1.default.join(node_path_1.default.dirname(file), `.vanspod-write-${process.pid}.tmp`);
|
|
@@ -0,0 +1,197 @@
|
|
|
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.planClassroomDefaultModel = planClassroomDefaultModel;
|
|
7
|
+
exports.applyClassroomDefaultModel = applyClassroomDefaultModel;
|
|
8
|
+
exports.restoreClassroomDefaultModel = restoreClassroomDefaultModel;
|
|
9
|
+
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
10
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
11
|
+
// Classroom Default Model: same rules as the classroom-one-click-install extension
|
|
12
|
+
// (its ADR 0018). While Classroom, VS Code's user `chat.defaultModel` points at the
|
|
13
|
+
// first VCRouter model so new Chat conversations use it; Native puts back the
|
|
14
|
+
// student's own value, but only if the setting still holds the one VansPod wrote.
|
|
15
|
+
const CHAT_DEFAULT_MODEL = "chat.defaultModel";
|
|
16
|
+
// Comment- and string-aware tokens of a JSONC document. `depth` is the nesting level
|
|
17
|
+
// the token sits at (the root object's own braces are depth 0, its members depth 1).
|
|
18
|
+
function tokenize(text) {
|
|
19
|
+
const tokens = [];
|
|
20
|
+
let depth = 0;
|
|
21
|
+
let i = 0;
|
|
22
|
+
while (i < text.length) {
|
|
23
|
+
const c = text[i];
|
|
24
|
+
if (/\s|/.test(c)) {
|
|
25
|
+
i += 1;
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (c === "/" && text[i + 1] === "/") {
|
|
29
|
+
while (i < text.length && text[i] !== "\n")
|
|
30
|
+
i += 1;
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
if (c === "/" && text[i + 1] === "*") {
|
|
34
|
+
const close = text.indexOf("*/", i + 2);
|
|
35
|
+
i = close < 0 ? text.length : close + 2;
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
if (c === '"') {
|
|
39
|
+
let j = i + 1;
|
|
40
|
+
while (j < text.length && text[j] !== '"')
|
|
41
|
+
j += text[j] === "\\" ? 2 : 1;
|
|
42
|
+
tokens.push({ kind: "string", start: i, end: Math.min(j + 1, text.length), depth });
|
|
43
|
+
i = j + 1;
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if ("{[".includes(c)) {
|
|
47
|
+
tokens.push({ kind: "punct", char: c, start: i, end: i + 1, depth });
|
|
48
|
+
depth += 1;
|
|
49
|
+
i += 1;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if ("}]".includes(c)) {
|
|
53
|
+
depth -= 1;
|
|
54
|
+
tokens.push({ kind: "punct", char: c, start: i, end: i + 1, depth });
|
|
55
|
+
i += 1;
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (":,".includes(c)) {
|
|
59
|
+
tokens.push({ kind: "punct", char: c, start: i, end: i + 1, depth });
|
|
60
|
+
i += 1;
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
let j = i;
|
|
64
|
+
while (j < text.length && !/[\s{}[\]:,"/]/.test(text[j]))
|
|
65
|
+
j += 1;
|
|
66
|
+
tokens.push({ kind: "literal", start: i, end: Math.max(j, i + 1), depth });
|
|
67
|
+
i = Math.max(j, i + 1);
|
|
68
|
+
}
|
|
69
|
+
return tokens;
|
|
70
|
+
}
|
|
71
|
+
function inspect(text) {
|
|
72
|
+
const tokens = tokenize(text);
|
|
73
|
+
if (tokens.length === 0)
|
|
74
|
+
return { tokens, members: 0 };
|
|
75
|
+
const root = tokens[0];
|
|
76
|
+
if (root.char !== "{")
|
|
77
|
+
return undefined;
|
|
78
|
+
let entry;
|
|
79
|
+
let members = 0;
|
|
80
|
+
for (let i = 1; i + 2 < tokens.length; i += 1) {
|
|
81
|
+
const key = tokens[i];
|
|
82
|
+
if (key.depth !== 1 || key.kind !== "string" || tokens[i + 1].char !== ":")
|
|
83
|
+
continue;
|
|
84
|
+
members += 1;
|
|
85
|
+
if (JSON.parse(text.slice(key.start, key.end)) !== CHAT_DEFAULT_MODEL)
|
|
86
|
+
continue;
|
|
87
|
+
const value = tokens[i + 2];
|
|
88
|
+
// VS Code uses the last duplicate key, so the last one wins here too.
|
|
89
|
+
entry = { index: i, key, value, text: value.kind === "string" ? JSON.parse(text.slice(value.start, value.end)) : undefined };
|
|
90
|
+
}
|
|
91
|
+
return { tokens, root, entry, members };
|
|
92
|
+
}
|
|
93
|
+
async function readText(file) {
|
|
94
|
+
try {
|
|
95
|
+
return await promises_1.default.readFile(file, "utf8");
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
if (error.code === "ENOENT")
|
|
99
|
+
return null;
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
async function readDefaultModel(file) {
|
|
104
|
+
const text = await readText(file);
|
|
105
|
+
return text === null ? undefined : inspect(text)?.entry?.text;
|
|
106
|
+
}
|
|
107
|
+
function lineStart(text, index) {
|
|
108
|
+
const start = text.lastIndexOf("\n", index - 1) + 1;
|
|
109
|
+
return text.slice(start, index).trim() === "" ? start : index;
|
|
110
|
+
}
|
|
111
|
+
function lineEnd(text, index) {
|
|
112
|
+
const rest = text.slice(index).match(/^[ \t]*(\r?\n)?/)[0];
|
|
113
|
+
return rest.endsWith("\n") ? index + rest.length : index;
|
|
114
|
+
}
|
|
115
|
+
/** The edited text, or undefined when the file cannot be edited safely. */
|
|
116
|
+
function edit(text, value) {
|
|
117
|
+
const line = `"${CHAT_DEFAULT_MODEL}": ${JSON.stringify(value)}`;
|
|
118
|
+
if (text === null)
|
|
119
|
+
return value === undefined ? undefined : `{\n ${line}\n}\n`;
|
|
120
|
+
const doc = inspect(text);
|
|
121
|
+
if (!doc)
|
|
122
|
+
return undefined;
|
|
123
|
+
const eol = text.includes("\r\n") ? "\r\n" : "\n";
|
|
124
|
+
if (!doc.root) {
|
|
125
|
+
// Only comments or nothing: keep them and add the object after.
|
|
126
|
+
if (value === undefined)
|
|
127
|
+
return undefined;
|
|
128
|
+
const sep = text === "" || text.endsWith("\n") ? "" : eol;
|
|
129
|
+
return `${text}${sep}{${eol} ${line}${eol}}${eol}`;
|
|
130
|
+
}
|
|
131
|
+
const { entry, tokens } = doc;
|
|
132
|
+
if (entry && value !== undefined) {
|
|
133
|
+
// A non-string value we can't place safely (object, array) is left alone.
|
|
134
|
+
if (entry.value.kind === "punct")
|
|
135
|
+
return undefined;
|
|
136
|
+
return text.slice(0, entry.value.start) + JSON.stringify(value) + text.slice(entry.value.end);
|
|
137
|
+
}
|
|
138
|
+
if (entry) {
|
|
139
|
+
if (entry.value.kind === "punct")
|
|
140
|
+
return undefined;
|
|
141
|
+
const next = tokens[entry.index + 3];
|
|
142
|
+
const before = tokens[entry.index - 1];
|
|
143
|
+
if (next?.char === ",") {
|
|
144
|
+
const from = lineStart(text, entry.key.start);
|
|
145
|
+
return text.slice(0, from) + text.slice(lineEnd(text, next.end));
|
|
146
|
+
}
|
|
147
|
+
if (before.char === ",")
|
|
148
|
+
return text.slice(0, before.start) + text.slice(entry.value.end);
|
|
149
|
+
const from = lineStart(text, entry.key.start);
|
|
150
|
+
return text.slice(0, from) + text.slice(lineEnd(text, entry.value.end));
|
|
151
|
+
}
|
|
152
|
+
if (value === undefined)
|
|
153
|
+
return undefined;
|
|
154
|
+
const at = doc.root.end;
|
|
155
|
+
const rest = text.slice(at);
|
|
156
|
+
const comma = doc.members > 0 ? "," : "";
|
|
157
|
+
// Match the file's layout so removing the entry later gives back the exact bytes:
|
|
158
|
+
// its own line in a multi-line object, inline right after `{` in a compact one.
|
|
159
|
+
return /^[ \t]*\r?\n/.test(rest)
|
|
160
|
+
? `${text.slice(0, at)}${eol} ${line}${comma}${rest}`
|
|
161
|
+
: `${text.slice(0, at)}${line}${comma}${rest}`;
|
|
162
|
+
}
|
|
163
|
+
async function writeDefaultModel(file, value) {
|
|
164
|
+
const next = edit(await readText(file), value);
|
|
165
|
+
if (next === undefined)
|
|
166
|
+
return;
|
|
167
|
+
await promises_1.default.mkdir(node_path_1.default.dirname(file), { recursive: true });
|
|
168
|
+
const temporary = `${file}.vanspod.tmp`;
|
|
169
|
+
try {
|
|
170
|
+
await promises_1.default.writeFile(temporary, next, "utf8");
|
|
171
|
+
await promises_1.default.rename(temporary, file);
|
|
172
|
+
}
|
|
173
|
+
finally {
|
|
174
|
+
await promises_1.default.rm(temporary, { force: true });
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* What the journal should hold after this publish, or undefined to write nothing.
|
|
179
|
+
* Same model as last time → leave whatever the student has now, never re-override it.
|
|
180
|
+
*/
|
|
181
|
+
async function planClassroomDefaultModel(file, modelId, record) {
|
|
182
|
+
if (record?.written === modelId)
|
|
183
|
+
return undefined;
|
|
184
|
+
const current = await readDefaultModel(file);
|
|
185
|
+
const previous = record && current === record.written ? record.previous : current;
|
|
186
|
+
return previous === undefined ? { written: modelId } : { previous, written: modelId };
|
|
187
|
+
}
|
|
188
|
+
async function applyClassroomDefaultModel(file, record) {
|
|
189
|
+
if (await readDefaultModel(file) !== record.written)
|
|
190
|
+
await writeDefaultModel(file, record.written);
|
|
191
|
+
}
|
|
192
|
+
async function restoreClassroomDefaultModel(file, record) {
|
|
193
|
+
if (!record)
|
|
194
|
+
return;
|
|
195
|
+
if (await readDefaultModel(file) === record.written)
|
|
196
|
+
await writeDefaultModel(file, record.previous);
|
|
197
|
+
}
|
|
@@ -7,6 +7,7 @@ exports.createVsCodeRouteSettings = createVsCodeRouteSettings;
|
|
|
7
7
|
const node_util_1 = require("node:util");
|
|
8
8
|
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
9
9
|
const node_path_1 = __importDefault(require("node:path"));
|
|
10
|
+
const vsCodeDefaultModel_1 = require("./vsCodeDefaultModel");
|
|
10
11
|
function isJournal(value) {
|
|
11
12
|
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
12
13
|
return false;
|
|
@@ -144,7 +145,36 @@ function intendedProvider(template, adapter, origin) {
|
|
|
144
145
|
});
|
|
145
146
|
return provider;
|
|
146
147
|
}
|
|
148
|
+
function firstModelId(provider) {
|
|
149
|
+
for (const model of provider.models ?? []) {
|
|
150
|
+
const id = model?.id;
|
|
151
|
+
if (typeof id === "string" && id)
|
|
152
|
+
return id;
|
|
153
|
+
}
|
|
154
|
+
return undefined;
|
|
155
|
+
}
|
|
147
156
|
function createVsCodeRouteSettings(options) {
|
|
157
|
+
// 課堂預設模型是附加功能:讀寫失敗不擋連線或切回 Native,殘留的設定在 VCRouter 消失後也無作用。
|
|
158
|
+
// undefined = 不需要寫(同一個模型已寫過,或讀不到設定);journal 裡原有的紀錄要保留。
|
|
159
|
+
const planDefault = async (intended, journal) => {
|
|
160
|
+
const modelId = firstModelId(intended);
|
|
161
|
+
if (!options.userSettingsFile || !modelId)
|
|
162
|
+
return undefined;
|
|
163
|
+
try {
|
|
164
|
+
return await (0, vsCodeDefaultModel_1.planClassroomDefaultModel)(options.userSettingsFile, modelId, journal?.defaultModel);
|
|
165
|
+
}
|
|
166
|
+
catch {
|
|
167
|
+
return undefined;
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
const writeDefault = async (record) => {
|
|
171
|
+
if (!options.userSettingsFile || !record)
|
|
172
|
+
return;
|
|
173
|
+
try {
|
|
174
|
+
await (0, vsCodeDefaultModel_1.applyClassroomDefaultModel)(options.userSettingsFile, record);
|
|
175
|
+
}
|
|
176
|
+
catch { /* best effort */ }
|
|
177
|
+
};
|
|
148
178
|
// 只移除仍指向 VansPod 代理的 VCRouter;已被移除或改成別的網址的,視為不再由 VansPod 接管。
|
|
149
179
|
const restore = async () => {
|
|
150
180
|
const journal = await readJournal(options.journalFile);
|
|
@@ -156,6 +186,12 @@ function createVsCodeRouteSettings(options) {
|
|
|
156
186
|
const changed = next.length !== current.length;
|
|
157
187
|
if (changed)
|
|
158
188
|
await atomicJson(options.settingsFile, next);
|
|
189
|
+
if (options.userSettingsFile) {
|
|
190
|
+
try {
|
|
191
|
+
await (0, vsCodeDefaultModel_1.restoreClassroomDefaultModel)(options.userSettingsFile, journal.defaultModel);
|
|
192
|
+
}
|
|
193
|
+
catch { /* best effort */ }
|
|
194
|
+
}
|
|
159
195
|
await promises_1.default.rm(options.journalFile, { force: true });
|
|
160
196
|
return namedIndexes(next).length ? { changed, kept: true } : { changed };
|
|
161
197
|
};
|
|
@@ -182,18 +218,25 @@ function createVsCodeRouteSettings(options) {
|
|
|
182
218
|
}
|
|
183
219
|
next = [...current, intended];
|
|
184
220
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
const
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
221
|
+
const planned = await planDefault(intended, journal);
|
|
222
|
+
const defaultModel = planned ?? journal?.defaultModel;
|
|
223
|
+
const changed = !(0, node_util_1.isDeepStrictEqual)(next, current);
|
|
224
|
+
if (changed || planned) {
|
|
225
|
+
const nextJournal = {
|
|
226
|
+
version: 1,
|
|
227
|
+
route: "vsCodeChat",
|
|
228
|
+
original,
|
|
229
|
+
intended,
|
|
230
|
+
owned: { name: "VCRouter", vendor: "customendpoint" },
|
|
231
|
+
...(defaultModel ? { defaultModel } : {}),
|
|
232
|
+
};
|
|
233
|
+
await atomicJson(options.journalFile, nextJournal);
|
|
234
|
+
if (changed)
|
|
235
|
+
await atomicJson(options.settingsFile, next);
|
|
236
|
+
}
|
|
237
|
+
// chat.defaultModel 不需要重啟 VS Code,所以不算進 changed。
|
|
238
|
+
await writeDefault(planned);
|
|
239
|
+
return { changed };
|
|
197
240
|
},
|
|
198
241
|
restore,
|
|
199
242
|
async initializeNative() {
|