@walkhi/code-relax 0.1.0-beta.10 → 0.1.0-beta.11
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 +44 -54
- package/dist/bin/codex-remote.mjs +22 -58
- package/dist/shared/app-server-events.cjs +15 -3
- package/dist/shared/file-mentions.cjs +35 -0
- package/dist/skills/code-relax/SKILL.md +1 -1
- package/dist/src/desktop-launcher.mjs +6 -11
- package/dist/src/file-upload-session.mjs +124 -0
- package/dist/src/lan-socket-server.mjs +51 -8
- package/dist/src/managed-app-server.mjs +9 -7
- package/dist/src/onboarding.mjs +3 -3
- package/dist/src/platform/windows/desktop-host.mjs +1 -2
- package/dist/src/platform/windows/desktop-shortcuts.ps1 +6 -13
- package/dist/src/platform/windows/service-host.mjs +0 -9
- package/dist/src/self-relay/admin-page.mjs +1 -1
- package/dist/src/self-relay/connector.mjs +84 -12
- package/dist/src/self-relay/lifecycle.mjs +8 -24
- package/dist/src/self-relay/p2p-probe.mjs +1 -1
- package/dist/src/self-relay/server.mjs +67 -12
- package/dist/src/server.mjs +141 -34
- package/dist/src/service-doctor.mjs +1 -1
- package/dist/src/service-install.mjs +1 -4
- package/dist/src/shared-app-server.mjs +30 -28
- package/dist/src/shared-catalog.mjs +1 -11
- package/dist/src/shared-recovery.mjs +5 -5
- package/dist/src/skill-install.mjs +0 -13
- package/package.json +1 -1
- package/dist/src/debug-ui.mjs +0 -131
- package/dist/src/platform/windows/desktop-shortcut-run.ps1 +0 -5
- package/dist/web/activity-view.js +0 -283
- package/dist/web/approval-ui.js +0 -188
- package/dist/web/capabilities.js +0 -50
- package/dist/web/chat-transport.js +0 -196
- package/dist/web/chat.css +0 -778
- package/dist/web/chat.js +0 -3815
- package/dist/web/client-platform.js +0 -11
- package/dist/web/community.css +0 -82
- package/dist/web/community.html +0 -36
- package/dist/web/composer-controller.js +0 -97
- package/dist/web/conversation-controller.js +0 -99
- package/dist/web/disclosure-state-controller.js +0 -95
- package/dist/web/draft-controller.js +0 -103
- package/dist/web/harmony-platform.js +0 -52
- package/dist/web/highlight-powershell.min.js +0 -39
- package/dist/web/highlight.min.js +0 -1262
- package/dist/web/history-cache.js +0 -240
- package/dist/web/history-controller.js +0 -167
- package/dist/web/index.html +0 -288
- package/dist/web/lan-session.js +0 -122
- package/dist/web/link-action-controller.js +0 -212
- package/dist/web/message-send-controller.js +0 -177
- package/dist/web/message-view.js +0 -98
- package/dist/web/p2p-data-channel.js +0 -50
- package/dist/web/p2p-diagnostics.js +0 -28
- package/dist/web/p2p-probe.js +0 -123
- package/dist/web/page-resume.js +0 -28
- package/dist/web/pending-message-store.js +0 -108
- package/dist/web/queue-controller.js +0 -82
- package/dist/web/resources.json +0 -1
- package/dist/web/self-relay-session.js +0 -129
- package/dist/web/server-requests.js +0 -67
- package/dist/web/station-connection-controller.js +0 -75
- package/dist/web/task-list-view.js +0 -289
- package/dist/web/thread-attention-controller.js +0 -124
- package/dist/web/thread-context-controller.js +0 -30
- package/dist/web/thread-list-controller.js +0 -61
- package/dist/web/thread-list-sync.js +0 -86
- package/dist/web/thread-title-controller.js +0 -57
- package/dist/web/timeline-formatters.js +0 -249
- package/dist/web/timeline-reducer.js +0 -77
- package/dist/web/timeline-renderer.js +0 -161
- package/dist/web/timeline-scroll-controller.js +0 -50
- package/dist/web/timeline-sync.js +0 -67
- package/dist/web/usage-controller.js +0 -258
- package/dist/web/vendor/README.md +0 -14
- package/dist/web/vendor/highlight-powershell.min.js +0 -39
- package/dist/web/vendor/highlight.LICENSE.txt +0 -29
- package/dist/web/vendor/highlight.min.js +0 -1262
- package/dist/web/vendor/lucide.LICENSE.txt +0 -17
package/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
# Code Relax Bridge(Windows 私测包)
|
|
2
|
-
|
|
3
|
-
Bridge 让 HarmonyOS 客户端控制 Windows
|
|
4
|
-
|
|
5
|
-
## 安装
|
|
6
|
-
|
|
1
|
+
# Code Relax Bridge(Windows 私测包)
|
|
2
|
+
|
|
3
|
+
Bridge 让 HarmonyOS 客户端控制 Windows 上的受管 Codex 内核。当前要求 Windows x64、Node >=22.12,以及已登录的 Codex Desktop 配套内核或独立 Codex CLI;npm 包不包含 Node,也不修改官方程序文件。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
7
|
公开 beta 已发布到 npm,安装或更新使用:
|
|
8
8
|
|
|
9
9
|
```powershell
|
|
@@ -11,72 +11,62 @@ npm i -g @walkhi/code-relax@beta --allow-scripts=@walkhi/code-relax --foreground
|
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
首次安装前先保存工作,并从 Codex 菜单或 Windows 托盘完全退出 Codex。更新无需先停止正在运行的 Bridge;安装器会短暂停止、替换并恢复服务。npm 全局安装会自动执行 `setup` 和 Skill 安装。`setup` 将完整服务部署到 `%LOCALAPPDATA%\Programs\CodexRemote\service`,记录安装所用 Node 的绝对路径,不复制 Node。配置、日志和二维码以 `installation.json.stateRoot` 为准,通常位于 `%LOCALAPPDATA%\CodexRemote`,MSIX 环境可能解析到包缓存目录;附件位于 `%ProgramData%\CodexRemote\attachments`。
|
|
14
|
-
|
|
15
|
-
`setup` 立即启动 Bridge 和固定 45839 受管 app-server,并启用当前用户登录自启;自启不打开 Codex。受管实例健康后配置当前用户 `CODEX_APP_SERVER_WS_URL`,之后正常启动的 Desktop 自动接入。若安装时 Desktop
|
|
16
|
-
|
|
14
|
+
|
|
15
|
+
`setup` 立即启动 Bridge 和固定 45839 受管 app-server,并启用当前用户登录自启;自启不打开 Codex。受管实例健康后配置当前用户 `CODEX_APP_SERVER_WS_URL`,之后正常启动的 Desktop 自动接入。若安装时 Desktop 仍未接入,安装器会关闭并重新打开 Desktop;安装前应保存工作。普通更新无接入或启动链迁移需求时复用现有内核。
|
|
16
|
+
|
|
17
17
|
## Codex 内核
|
|
18
|
-
|
|
19
|
-
```powershell
|
|
20
|
-
relax
|
|
21
|
-
relax shared-start # Codex 内核、Desktop、Bridge
|
|
22
|
-
relax start # 启动/复用常驻 Bridge 和已配置中继
|
|
18
|
+
|
|
19
|
+
```powershell
|
|
20
|
+
relax start # 启动/复用 Bridge、受管 Codex 内核和已配置中继
|
|
23
21
|
relax pair # 启动/复用服务并打开配对二维码
|
|
24
22
|
relax status
|
|
25
23
|
relax stop
|
|
26
|
-
```
|
|
27
|
-
|
|
24
|
+
```
|
|
25
|
+
|
|
28
26
|
Codex 内核由官方 `codex app-server --listen ws://127.0.0.1:45839` 提供执行服务,Desktop 和 Bridge 均可连接;它只监听回环地址。Bridge 独立报告内核健康、Desktop 接入和手机可写状态;Desktop 退出后,手机仍可操作内核中的任务。同一 thread 已被另一个实例持有时,手机只读且可重新检测。
|
|
29
|
-
|
|
30
|
-
手机工作站详情可确认让 Desktop 接入 Codex 内核,独立进程逐步执行并保留 Bridge/中继连接,见[启用流程](../docs/shared-recovery.md)
|
|
31
|
-
|
|
27
|
+
|
|
28
|
+
手机工作站详情可确认让 Desktop 接入 Codex 内核,独立进程逐步执行并保留 Bridge/中继连接,见[启用流程](../docs/shared-recovery.md)。本机恢复命令为 `relax shared-recover --confirm`,查看恢复结果用 `relax shared-recovery-status`。Bridge 状态匹配且健康时直接复用;未知进程占用 45831/45839 时拒绝接管。`stop` 只停止 Bridge,不停止 Desktop 或受管 app-server。
|
|
29
|
+
|
|
32
30
|
受管 app-server 通过隐藏控制台启动,使后续控制台子进程继承隐藏窗口。手机的项目、任务列表和新建任务均使用受管内核,不依赖 Desktop 工具管道;项目和任务 ID 保持原生值。
|
|
33
|
-
|
|
31
|
+
|
|
34
32
|
受管 app-server 未就绪时,手机停留在连接界面并显示“Codex 内核未就绪”;Bridge 保留健康和恢复接口,聊天请求返回错误。
|
|
35
|
-
|
|
36
|
-
## Code Relax 中继
|
|
37
|
-
|
|
38
|
-
私有中继仍需要本机 Bridge:
|
|
39
|
-
|
|
40
|
-
```powershell
|
|
41
|
-
relax
|
|
33
|
+
|
|
34
|
+
## Code Relax 中继
|
|
35
|
+
|
|
36
|
+
私有中继仍需要本机 Bridge:
|
|
37
|
+
|
|
38
|
+
```powershell
|
|
39
|
+
relax start --json
|
|
42
40
|
relax relay-start --json
|
|
43
41
|
relax relay-status --json
|
|
44
42
|
relax pair --json
|
|
45
43
|
relax relay-stop --json
|
|
46
44
|
relax relay-revoke --json
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
`relay-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
调试页面与 Bridge 共用进程和端口(默认 45831),只额外提供白名单静态资源,用于局域网页面调试。`dev-stop` 只关闭静态页面,不影响 Bridge WebSocket。Code Relax 中继和 OpenAI 中继均使用 HAP 内置页面。
|
|
60
|
-
|
|
61
|
-
## 更新与卸载
|
|
62
|
-
|
|
63
|
-
更新固定服务:
|
|
64
|
-
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
`start` 启动内核和 Bridge,并恢复已配置中继;`relay-start` 单独管理中继连接器。每台移动设备通过 `pair` 配对一次;新增设备不替换已有设备。连接器把 Windows hostname 和当前 Wi-Fi/有线网络候选经已认证 WebSocket 临时发送给手机,手机本地保存电脑名,只在设备身份验证通过后保存可达地址;服务器不持久化这些 Code Relax 中继 hostname、IP 或网络名。OpenAI 官方认证和设备配对仍直接访问 OpenAI;完成后,手机使用统一配对产生的设备凭据,通过独立元数据 WebSocket 把官方环境 ID、名称和 hostname 写入设备记录,不上传 OpenAI access token、配对码或登录态。停止连接器不撤销授权。
|
|
48
|
+
|
|
49
|
+
Bridge 的局域网端口仅提供鉴权 WebSocket,普通 HTTP 请求返回 404;手机聊天页面随 HAP 安装。
|
|
50
|
+
|
|
51
|
+
## 更新与卸载
|
|
52
|
+
|
|
53
|
+
更新固定服务:
|
|
54
|
+
|
|
65
55
|
```powershell
|
|
66
56
|
npm i -g @walkhi/code-relax@beta --allow-scripts=@walkhi/code-relax --foreground-scripts
|
|
67
57
|
```
|
|
68
58
|
|
|
69
59
|
`setup` 先暂存并校验新版本,再短暂停止 Bridge/中继完成切换;原服务此前正在运行时会自动恢复,新版本启动失败则回滚并启动旧版本。无需提前执行 `stop`。Node 路径变化或原 Node 被删除后需重新 setup。升级可能因 Node 可执行文件路径变化而再次触发 Windows 防火墙授权。
|
|
70
|
-
|
|
71
|
-
卸载:
|
|
72
|
-
|
|
73
|
-
```powershell
|
|
60
|
+
|
|
61
|
+
卸载:
|
|
62
|
+
|
|
63
|
+
```powershell
|
|
74
64
|
relax uninstall
|
|
75
65
|
npm uninstall -g @walkhi/code-relax
|
|
76
|
-
```
|
|
77
|
-
|
|
66
|
+
```
|
|
67
|
+
|
|
78
68
|
`uninstall` 停止 Bridge 后先核对并清理 Code Relax 所有的当前用户 `CODEX_APP_SERVER_WS_URL`;用户后来修改或不归属 Code Relax 的值会保留。随后删除固定程序和本包管理且未修改的 Skill;保留其他配置、Token、日志、长期设备凭据、附件和自定义 Skill。它不卸载 Node、Codex Desktop,也不强制结束完整控制的执行进程。
|
|
79
|
-
|
|
80
|
-
## 发布边界
|
|
81
|
-
|
|
69
|
+
|
|
70
|
+
## 发布边界
|
|
71
|
+
|
|
82
72
|
registry 测试包使用 `@walkhi/code-relax@beta`,主 CLI 为 `relax`,并保留 `code-relax` 兼容入口。安装摘要通过 `--foreground-scripts` 显示,首次安装或启动链迁移时干净重启 Desktop,分别报告已安装与实际运行版本;登录启动使用当前用户任务计划。通信协议仍为 7。详细规则见 [npm 分发](../docs/npm-distribution.md)。
|
|
@@ -7,8 +7,7 @@ import { installService, uninstallService, packageRoot } from '../src/service-in
|
|
|
7
7
|
import { installSkill, removeSkill, inspectSkill } from '../src/skill-install.mjs';
|
|
8
8
|
import { doctor } from '../src/service-doctor.mjs';
|
|
9
9
|
import { launchDesktop } from '../src/desktop-launcher.mjs';
|
|
10
|
-
import { desktopHost,
|
|
11
|
-
import { debugUi } from '../src/debug-ui.mjs';
|
|
10
|
+
import { desktopHost, removeDesktopShortcut, residentStartup, resolveStateRoot } from '../src/platform/windows/desktop-host.mjs';
|
|
12
11
|
import { selfRelay } from '../src/self-relay/lifecycle.mjs';
|
|
13
12
|
import { fileURLToPath } from 'node:url';
|
|
14
13
|
import path from 'node:path';
|
|
@@ -20,30 +19,24 @@ import { configureManagedEnvironment, clearManagedEnvironment } from '../src/pla
|
|
|
20
19
|
import { resolveCodexRuntime } from '../src/platform/windows/codex-runtime.mjs';
|
|
21
20
|
|
|
22
21
|
const help = `Code Relax(Windows)
|
|
23
|
-
用法:relax <setup|doctor|skill-install|skill-remove|uninstall|start|
|
|
22
|
+
用法:relax <setup|doctor|skill-install|skill-remove|uninstall|start|pair|status|stop> [--json]
|
|
24
23
|
setup 部署并启动固定目录服务、受管 app-server 和登录自启动;安全配置 Desktop 后续接入
|
|
25
|
-
start 启动或复用 Bridge
|
|
26
|
-
shared-start 启动或复用 Codex 内核,再启动 Desktop、Bridge 和已配置的私有中继
|
|
24
|
+
start 启动或复用 Bridge 和 Codex 内核,并恢复已配置的私有中继
|
|
27
25
|
shared-recover --confirm 重新打开 Desktop 并接入 Codex 内核;不强制重启已有内核
|
|
28
26
|
shared-recovery-status 查看最近一次恢复的实际阶段和结果
|
|
29
27
|
autostart-enable / autostart-disable / autostart-status 管理当前用户登录时启动 Bridge
|
|
30
|
-
shortcuts 创建 Codex 内核桌面快捷方式
|
|
31
28
|
pair 启动或复用工作站服务,并打开一次性配对二维码
|
|
32
29
|
status 查看服务健康状态
|
|
33
30
|
stop 停止服务
|
|
34
|
-
dev 在 Bridge 端口开启调试页面(实时读取当前源码/包资源)
|
|
35
|
-
dev-status 查看 Bridge 调试页面状态
|
|
36
|
-
dev-stop 关闭调试页面,不停止 Bridge
|
|
37
31
|
relay-start 启动或复用私有中继,已有授权直接恢复,首次授权生成二维码
|
|
38
|
-
relay-
|
|
39
|
-
relay-status 查看私有中继连接器及手机连接状态
|
|
32
|
+
relay-status 查看私有中继连接器及移动端连接状态
|
|
40
33
|
relay-stop 停止私有中继连接器,不停止 Bridge 或 Codex
|
|
41
34
|
relay-revoke 撤销这台电脑的全部移动设备授权(停止连接器不会撤销授权)
|
|
42
35
|
doctor 检查安装、Node、Codex 内核、网络和 Skill,提示防火墙处理方式
|
|
43
36
|
skill-install 安装/更新当前用户的 Codex Skill,不覆盖自定义文件
|
|
44
37
|
skill-remove 移除本包安装且未修改的 Skill
|
|
45
38
|
uninstall 停止并移除固定目录服务和本包 Skill,清理自有 Desktop 环境变量,保留其他配置与附件
|
|
46
|
-
默认监听 0.0.0.0
|
|
39
|
+
默认监听 0.0.0.0,移动端与电脑需在同一受信任局域网。
|
|
47
40
|
--json 输出机器可读结果;统一二维码不含 LAN 地址、Bridge Token 或中继地址。`;
|
|
48
41
|
|
|
49
42
|
async function main() {
|
|
@@ -52,7 +45,7 @@ async function main() {
|
|
|
52
45
|
console.log(help);
|
|
53
46
|
return;
|
|
54
47
|
}
|
|
55
|
-
if (!['autostart-enable', 'autostart-disable', 'autostart-status', 'shared-recover', 'shared-recovery-status', 'relay-
|
|
48
|
+
if (!['autostart-enable', 'autostart-disable', 'autostart-status', 'shared-recover', 'shared-recovery-status', 'relay-revoke', 'relay-start', 'relay-status', 'relay-stop', 'setup', 'doctor', 'skill-install', 'skill-remove', 'uninstall', 'start', 'pair', 'status', 'stop'].includes(command)
|
|
56
49
|
|| flags.some(flag => flag !== '--json' && !(command === 'shared-recover' && flag === '--confirm'))) {
|
|
57
50
|
throw new Error('无效命令或参数。使用 --help 查看用法。');
|
|
58
51
|
}
|
|
@@ -60,30 +53,13 @@ async function main() {
|
|
|
60
53
|
const json = flags.includes('--json');
|
|
61
54
|
const paths = runtimePaths();
|
|
62
55
|
const { stateRoot, serviceRoot } = paths;
|
|
63
|
-
if (['relay-
|
|
64
|
-
|
|
65
|
-
const existing = await selfRelay('relay-status', stateRoot);
|
|
66
|
-
if (existing.running && existing.transportMode !== 'lan-shared') throw new Error('旧连接器仍在运行,请先执行 relay-stop;不会自动中断手机连接。');
|
|
67
|
-
const result = await new Promise((resolve, reject) => {
|
|
68
|
-
const child = spawn(process.execPath, [fileURLToPath(import.meta.url), 'shared-start', '--json'], { windowsHide: true, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
69
|
-
let output = '', errors = '';
|
|
70
|
-
child.stdout.on('data', chunk => { output += chunk; }); child.stderr.on('data', chunk => { errors += chunk; });
|
|
71
|
-
child.once('error', reject);
|
|
72
|
-
child.once('exit', code => { if (code) reject(new Error(errors.trim().replace(/^(?:Code Relax:)+/u, '') || 'Codex 内核启动失败')); else { try { resolve(JSON.parse(output)); } catch { reject(new Error('Codex 内核启动结果无法确认,未启动中继')); } } });
|
|
73
|
-
});
|
|
74
|
-
if (!result.bridgeReady) { console.log(json ? JSON.stringify(result) : result.displayText); return; }
|
|
75
|
-
}
|
|
76
|
-
const result = await selfRelay(command === 'relay-shared-start' ? 'relay-start' : command, stateRoot, command === 'relay-shared-start' ? 'lan-shared' : '');
|
|
56
|
+
if (['relay-revoke', 'relay-start', 'relay-status', 'relay-stop'].includes(command)) {
|
|
57
|
+
const result = await selfRelay(command, stateRoot);
|
|
77
58
|
console.log(json ? JSON.stringify(result) : `${result.displayText}${result.qrPath ? '\n二维码:' + result.qrPath : ''}`);
|
|
78
59
|
return;
|
|
79
60
|
}
|
|
80
|
-
if (['dev', 'dev-status', 'dev-stop'].includes(command)) {
|
|
81
|
-
const result = await debugUi(command, stateRoot);
|
|
82
|
-
console.log(json ? JSON.stringify(result) : result.message || JSON.stringify(result));
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
61
|
const installedEntry = path.join(serviceRoot, 'dist/bin/codex-remote.mjs');
|
|
86
|
-
if (['autostart-enable', 'autostart-disable', 'autostart-status', 'shared-recover', 'shared-recovery-status', '
|
|
62
|
+
if (['autostart-enable', 'autostart-disable', 'autostart-status', 'shared-recover', 'shared-recovery-status', 'start', 'pair', 'status', 'stop'].includes(command) && path.resolve(fileURLToPath(import.meta.url)).toLowerCase() !== installedEntry.toLowerCase()) {
|
|
87
63
|
if (!fs.existsSync(installedEntry)) throw new Error('尚未部署服务,请先执行 relax setup。');
|
|
88
64
|
const executable = readRecord(path.join(serviceRoot, 'installation.json'))?.nodeExecutable;
|
|
89
65
|
if (!executable || !fs.existsSync(executable)) throw new Error('安装时选用的 Node 不存在,请重新执行 relax setup。');
|
|
@@ -92,7 +68,6 @@ async function main() {
|
|
|
92
68
|
process.exitCode = code ?? 1;
|
|
93
69
|
return;
|
|
94
70
|
}
|
|
95
|
-
host.migrateState(stateRoot);
|
|
96
71
|
const service = lifecycle({ stateRoot, host });
|
|
97
72
|
if (command.startsWith('autostart-')) {
|
|
98
73
|
const installation = readRecord(path.join(serviceRoot, 'installation.json'));
|
|
@@ -122,13 +97,6 @@ async function main() {
|
|
|
122
97
|
console.log(json ? JSON.stringify(result) : `${result.displayText}\n二维码:${result.qrPath}`);
|
|
123
98
|
return;
|
|
124
99
|
}
|
|
125
|
-
if (command === 'shortcuts') {
|
|
126
|
-
const installation = readRecord(path.join(serviceRoot, 'installation.json'));
|
|
127
|
-
if (!installation?.nodeExecutable) throw new Error('请先执行 relax setup。');
|
|
128
|
-
const shortcuts = await desktopShortcuts({ serviceRoot, nodeExecutable: installation.nodeExecutable });
|
|
129
|
-
console.log(json ? JSON.stringify({ shortcuts }) : `桌面快捷方式已创建:\n${shortcuts.join('\n')}`);
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
100
|
if (command === 'doctor') {
|
|
133
101
|
const result = await doctor({ paths, host, service });
|
|
134
102
|
console.log(json ? JSON.stringify(result) : result.checks.map(item => `[${item.status}] ${item.message}`).join('\n'));
|
|
@@ -148,7 +116,7 @@ async function main() {
|
|
|
148
116
|
const result = await uninstallService(paths, service, async () => {
|
|
149
117
|
environment = await clearManagedEnvironment(stateRoot);
|
|
150
118
|
const installation = readRecord(path.join(serviceRoot, 'installation.json'));
|
|
151
|
-
if (installation?.nodeExecutable) await
|
|
119
|
+
if (installation?.nodeExecutable) await removeDesktopShortcut({ serviceRoot, nodeExecutable: installation.nodeExecutable });
|
|
152
120
|
if (installation?.nodeExecutable) await residentStartup({ serviceRoot, nodeExecutable: installation.nodeExecutable }, 'disable');
|
|
153
121
|
});
|
|
154
122
|
result.environment = environment;
|
|
@@ -164,13 +132,15 @@ async function main() {
|
|
|
164
132
|
if (major < 22 || (major === 22 && minor < 12)) throw new Error('需要 Node >=22.12。');
|
|
165
133
|
const physicalStateRoot = await resolveStateRoot(stateRoot);
|
|
166
134
|
// Preserve the effective package view; never replace a newer file already in it.
|
|
167
|
-
for (const name of ['bridge-config.json', 'bridge-session.json', 'bridge-startup-context.json',
|
|
168
|
-
'self-relay-config.json', 'self-relay-session.json', 'lan-device-authorizations.json',
|
|
169
|
-
'managed-app-server.json', 'managed-environment.json', 'shared-recovery.json', 'shared-recovery.lock'
|
|
135
|
+
for (const name of ['bridge-config.json', 'bridge-session.json', 'bridge-startup-context.json',
|
|
136
|
+
'self-relay-config.json', 'self-relay-session.json', 'lan-device-authorizations.json',
|
|
137
|
+
'managed-app-server.json', 'managed-environment.json', 'shared-recovery.json', 'shared-recovery.lock']) {
|
|
170
138
|
const source = path.join(stateRoot, name), target = path.join(physicalStateRoot, name);
|
|
171
139
|
if (fs.existsSync(source) && !fs.existsSync(target)) fs.copyFileSync(source, target, fs.constants.COPYFILE_EXCL);
|
|
172
140
|
}
|
|
173
141
|
const hadInstalledService = fs.existsSync(path.join(serviceRoot, 'installation.json'));
|
|
142
|
+
const previousInstallation = readRecord(path.join(serviceRoot, 'installation.json'));
|
|
143
|
+
if (previousInstallation?.nodeExecutable) await removeDesktopShortcut({ serviceRoot, nodeExecutable: previousInstallation.nodeExecutable });
|
|
174
144
|
const desktopBeforeSetup = await desktopHost.inspect();
|
|
175
145
|
const runtime = await resolveCodexRuntime(physicalStateRoot, { refresh: true });
|
|
176
146
|
const desktopNeedsAttach = desktopBeforeSetup.running && !await host.sharedServiceUrl();
|
|
@@ -240,7 +210,7 @@ async function main() {
|
|
|
240
210
|
managedAppServerMigrated = true;
|
|
241
211
|
managedAppServerMigration.restarted = true;
|
|
242
212
|
if (desktopAttached) {
|
|
243
|
-
await launchDesktop(
|
|
213
|
+
await launchDesktop({ stateRoot: physicalStateRoot, host: desktopHost });
|
|
244
214
|
desktopRestarted = true;
|
|
245
215
|
desktopRestartReason = 'app-server-migration';
|
|
246
216
|
bridge = await service.status();
|
|
@@ -250,7 +220,7 @@ async function main() {
|
|
|
250
220
|
if (desktopNeedsAttach && !desktopRestarted) {
|
|
251
221
|
const currentDesktop = await desktopHost.inspect();
|
|
252
222
|
if (currentDesktop.running) await desktopHost.closeDesktop(currentDesktop.desktop);
|
|
253
|
-
await launchDesktop(
|
|
223
|
+
await launchDesktop({ stateRoot: physicalStateRoot, host: desktopHost });
|
|
254
224
|
desktopRestarted = true;
|
|
255
225
|
desktopRestartReason = 'attach-managed-server';
|
|
256
226
|
bridge = await service.status();
|
|
@@ -269,7 +239,7 @@ async function main() {
|
|
|
269
239
|
const migrationText = managedAppServerMigrated ? '已自动重建旧启动链的 app-server;安装前尚未完成的任务可能已中断。\n' : '';
|
|
270
240
|
const restartText = desktopRestarted
|
|
271
241
|
? 'Codex Desktop 已干净重启并重新接入受管 app-server。'
|
|
272
|
-
: desktopBeforeSetup.desktop ? 'Codex Desktop 使用同一受管 app-server
|
|
242
|
+
: desktopBeforeSetup.desktop ? 'Codex Desktop 使用同一受管 app-server;移动端控制不依赖 Desktop 是否打开。'
|
|
273
243
|
: '使用独立 Codex CLI;无需安装 Codex Desktop。';
|
|
274
244
|
console.log(json ? JSON.stringify({ ...installed, nextSteps: desktopSetupSteps, displayText: `${migrationText}${desktopSetupSteps.join('\n')}\n${restartText}` }) : `服务已安装:${installed.serviceRoot}\n使用已安装的 Node:${installed.nodeExecutable}\n受管 app-server 已就绪;首次联网可能需要 Windows 防火墙授权。\n${migrationText}${desktopSetupSteps.join('\n')}\n${restartText}`);
|
|
275
245
|
return;
|
|
@@ -279,26 +249,20 @@ async function main() {
|
|
|
279
249
|
console.log(json ? JSON.stringify(result) : result.message);
|
|
280
250
|
return;
|
|
281
251
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
if (!json) console.log('正在检查 Codex 的启动模式…');
|
|
285
|
-
desktop = await launchDesktop('shared', { stateRoot, host: desktopHost });
|
|
286
|
-
delete process.env.CODEX_APP_TOOLS_PIPE_PATH;
|
|
287
|
-
}
|
|
288
|
-
if (!json && (desktop || command === 'start')) console.log('正在检查电脑连接并准备 Bridge…');
|
|
289
|
-
const result = await service[desktop ? 'start' : command]();
|
|
252
|
+
if (!json && command === 'start') console.log('正在检查电脑连接并准备 Bridge…');
|
|
253
|
+
const result = await service[command]();
|
|
290
254
|
if (command === 'status') {
|
|
291
255
|
console.log(json ? JSON.stringify(result) : result.running
|
|
292
256
|
? `服务正常:${result.mode},版本 ${result.version || '未知'},端口 ${result.port},PID ${result.pid}` : '服务未就绪。');
|
|
293
257
|
return;
|
|
294
258
|
}
|
|
295
259
|
const { accessUrl, qrPath: _legacyQrPath, ...metadata } = result;
|
|
296
|
-
const notice = '
|
|
260
|
+
const notice = '本机服务检查通过,移动端连通性尚未验证。若电脑弹出 Node 网络访问提示,请先处理 Windows 防火墙授权,再用移动端连接。';
|
|
297
261
|
let relay;
|
|
298
262
|
if (fs.existsSync(path.join(stateRoot, 'self-relay-config.json'))) relay = await selfRelay('relay-start', stateRoot);
|
|
299
263
|
const nextSteps = phonePairingSteps(metadata.transportMode, relay?.paired === true);
|
|
300
264
|
const displayText = pairingDisplayText(nextSteps, notice);
|
|
301
|
-
const output = { ...metadata, ...(
|
|
265
|
+
const output = { ...metadata, ...(relay ? { relayConnected: relay.relayConnected,
|
|
302
266
|
paired: relay.paired, clientCount: relay.clientCount, ...(relay.qrPath ? { qrPath: relay.qrPath, expiresAt: relay.expiresAt } : {}) } : {}),
|
|
303
267
|
nextSteps, displayText, mode: 'lan', listenAddress: '0.0.0.0', address: new URL(accessUrl).host,
|
|
304
268
|
lanAccess: 'unverified', notice };
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
(function (root, factory) {
|
|
2
2
|
if (typeof module === 'object' && module.exports) module.exports = factory();
|
|
3
3
|
else root.CodexAppServerEvents = factory();
|
|
4
|
-
})(globalThis, function () {
|
|
4
|
+
})(globalThis, function () {
|
|
5
5
|
function mergeItems(existing, incoming = []) {
|
|
6
6
|
for (const source of incoming) {
|
|
7
7
|
const item = compactItem(source);
|
|
8
8
|
const index = existing.findIndex(current => current.id === item.id);
|
|
9
9
|
if (index < 0) existing.push(item);
|
|
10
10
|
else existing[index] = { ...existing[index], ...item };
|
|
11
|
-
}
|
|
11
|
+
}
|
|
12
12
|
return existing;
|
|
13
13
|
}
|
|
14
14
|
|
|
@@ -137,6 +137,18 @@
|
|
|
137
137
|
}
|
|
138
138
|
return match;
|
|
139
139
|
}
|
|
140
|
+
function catalogThreadProjectId(thread, projects) {
|
|
141
|
+
if (thread.projectId) return thread.projectId;
|
|
142
|
+
const local = thread.environments?.find(environment => environment.environmentId === 'local');
|
|
143
|
+
if (local && Array.isArray(local.runtimeWorkspaceRoots)) {
|
|
144
|
+
for (const root of local.runtimeWorkspaceRoots) {
|
|
145
|
+
const projectId = threadProjectId({ cwd: root }, projects);
|
|
146
|
+
if (projectId) return projectId;
|
|
147
|
+
}
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
return threadProjectId({ cwd: thread.cwd }, projects);
|
|
151
|
+
}
|
|
140
152
|
function projectlessThreadTarget(cwd = '') {
|
|
141
153
|
return { projectId: null, runtimeWorkspaceRoots: [], ...(cwd ? { cwd } : {}) };
|
|
142
154
|
}
|
|
@@ -289,6 +301,6 @@
|
|
|
289
301
|
}
|
|
290
302
|
return readQueue(request, threadId);
|
|
291
303
|
}
|
|
292
|
-
return { createThread, readQueue, addQueue, changeQueue, compactItem, compactTurn, mergeItems, applyNotification, mergeUsage, UsageCache, readProjects, orderDesktopProjects, threadProjectId, projectlessThreadTarget, updateSettings,
|
|
304
|
+
return { createThread, readQueue, addQueue, changeQueue, compactItem, compactTurn, mergeItems, applyNotification, mergeUsage, UsageCache, readProjects, orderDesktopProjects, threadProjectId, catalogThreadProjectId, projectlessThreadTarget, updateSettings,
|
|
293
305
|
permissionState, availablePermissionModes, PermissionOptionsCache, updatePermissions };
|
|
294
306
|
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
(function (root, factory) {
|
|
2
|
+
const api = factory();
|
|
3
|
+
if (typeof module === 'object' && module.exports) module.exports = api;
|
|
4
|
+
else root.CodexFileMentions = api;
|
|
5
|
+
})(globalThis, function () {
|
|
6
|
+
const heading = '# Files mentioned by the user:';
|
|
7
|
+
const request = '## My request:';
|
|
8
|
+
|
|
9
|
+
function parse(value) {
|
|
10
|
+
const source = typeof value === 'string' ? value : '';
|
|
11
|
+
if (!source.startsWith(heading)) return { text: source, files: [] };
|
|
12
|
+
const marker = source.indexOf(`\n${request}`, heading.length);
|
|
13
|
+
if (marker < 0) return { text: source, files: [] };
|
|
14
|
+
const files = [];
|
|
15
|
+
for (const line of source.slice(heading.length, marker).split(/\r?\n/)) {
|
|
16
|
+
const match = /^## (.+): ((?:[A-Za-z]:[\\/]|\/)[^\r\n]+)$/.exec(line);
|
|
17
|
+
if (!match) continue;
|
|
18
|
+
let name = match[1];
|
|
19
|
+
if (name.startsWith('"')) {
|
|
20
|
+
try { name = JSON.parse(name); } catch { continue; }
|
|
21
|
+
}
|
|
22
|
+
if (typeof name !== 'string' || !name) continue;
|
|
23
|
+
files.push({ type: 'file', name, path: match[2] });
|
|
24
|
+
}
|
|
25
|
+
if (!files.length) return { text: source, files: [] };
|
|
26
|
+
return { text: source.slice(marker + request.length + 1).trim(), files };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function wrap(prompt, files) {
|
|
30
|
+
if (!files?.length) return prompt;
|
|
31
|
+
return `${heading}\n${files.map(file => `\n## ${JSON.stringify(file.name)}: ${file.path}\n`).join('')}\n${request}\n${prompt || '请查看上述文件。'}`;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return Object.freeze({ parse, wrap });
|
|
35
|
+
});
|
|
@@ -5,7 +5,7 @@ description: 启动、检查或停止 Code Relax 工作站服务,生成并展
|
|
|
5
5
|
|
|
6
6
|
# Code Relax
|
|
7
7
|
|
|
8
|
-
- `relax start --json` 启动 Bridge 和受管 Codex 内核,无需打开 Desktop;支持纯 CLI
|
|
8
|
+
- `relax start --json` 启动 Bridge 和受管 Codex 内核,无需打开 Desktop;支持纯 CLI 安装。Desktop 正常打开后接入已配置内核;需要重新接入时使用 App 的“重启 Codex Desktop”或经确认的 `relax shared-recover --confirm`。已配置 Code Relax 中继时,启动命令同时恢复中继连接器和已有设备授权。
|
|
9
9
|
- npm 全局安装会自动执行服务部署和 Skill 安装;只有修复安装时才单独运行 `relax setup --json` 或 `relax skill-install --json`。
|
|
10
10
|
- `setup` 默认启用当前用户登录启动工作站服务,不自动打开 Codex;用 `autostart-status / autostart-disable / autostart-enable` 管理。恢复完整控制会保留 Bridge 和中继,但仍须明确确认可能中断全部完整控制任务。
|
|
11
11
|
- 用户要求启动 Code Relax 时,执行一次 `relax start --json`。用户要求二维码或当前启动结果包含二维码时,展示 CLI 返回的 `qrPath` 和 `displayText`;没有设备授权时可用 `relax pair --json` 生成新的配对二维码。
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
4
|
-
import { readRecord
|
|
4
|
+
import { readRecord } from './service-lifecycle.mjs';
|
|
5
5
|
import { ManagedAppServer, managedAppServerUrl as sharedUrl, managedPortAvailable as portAvailable } from './managed-app-server.mjs';
|
|
6
6
|
export { portAvailable };
|
|
7
|
-
export async function launchDesktop(
|
|
8
|
-
if (mode !== 'shared') throw new Error('只支持接入 Code Relax 管理的 Codex 内核。');
|
|
7
|
+
export async function launchDesktop({ stateRoot, host, environment = process.env, available = portAvailable, wait = delay, timeout = 30000, recoveryId, progress = () => {} }) {
|
|
9
8
|
fs.mkdirSync(stateRoot, { recursive: true });
|
|
10
9
|
const recovery = readRecord(path.join(stateRoot, 'shared-recovery.lock'));
|
|
11
10
|
if (recovery && recovery.operationId !== recoveryId) throw new Error('Codex 内核正在启动,请先查看 shared-recovery-status。');
|
|
@@ -22,11 +21,8 @@ export async function launchDesktop(mode, { stateRoot, host, environment = proce
|
|
|
22
21
|
if (!info.desktop) throw new Error('未安装 Codex Desktop,请使用 relax start 启动工作站。');
|
|
23
22
|
const connected = await host.sharedServiceUrl();
|
|
24
23
|
if (info.running) {
|
|
25
|
-
if (
|
|
26
|
-
|
|
27
|
-
return { reused: true, mode };
|
|
28
|
-
}
|
|
29
|
-
throw new Error('请先保存任务并完全退出 Codex Desktop,再切换模式;不会自动结束正在运行的任务。');
|
|
24
|
+
if (connected) return { reused: true };
|
|
25
|
+
throw new Error('请先保存任务并完全退出 Codex Desktop,再接入 Codex 内核;不会自动结束正在运行的任务。');
|
|
30
26
|
}
|
|
31
27
|
const childEnv = { ...environment };
|
|
32
28
|
for (const key of ['CODEX_APP_SERVER_WS_URL', 'CODEX_APP_SERVER_FORCE_CLI', 'CODEX_APP_TOOLS_PIPE_PATH']) delete childEnv[key];
|
|
@@ -42,10 +38,9 @@ export async function launchDesktop(mode, { stateRoot, host, environment = proce
|
|
|
42
38
|
while (true) {
|
|
43
39
|
const ready = await host.sharedServiceUrl();
|
|
44
40
|
if (ready) break;
|
|
45
|
-
if (Date.now() >= deadline) throw new Error('Desktop
|
|
41
|
+
if (Date.now() >= deadline) throw new Error('Desktop 尚未接入 Codex 内核。请查看 Desktop 窗口后重试。');
|
|
46
42
|
await wait(500);
|
|
47
43
|
}
|
|
48
|
-
|
|
49
|
-
return { reused: false, mode };
|
|
44
|
+
return { reused: false };
|
|
50
45
|
} finally { managed?.close(); fs.closeSync(descriptor); fs.rmSync(lock, { force: true }); }
|
|
51
46
|
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import fs from 'node:fs/promises';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
|
|
5
|
+
export const MAX_FILE_BYTES = 20 * 1024 * 1024;
|
|
6
|
+
export const MAX_FILE_COUNT = 4;
|
|
7
|
+
export const MAX_TOTAL_BYTES = 40 * 1024 * 1024;
|
|
8
|
+
export const FILE_CHUNK_BYTES = 256 * 1024;
|
|
9
|
+
|
|
10
|
+
function validName(value) {
|
|
11
|
+
return typeof value === 'string' && value.length > 0 && value.length <= 180 &&
|
|
12
|
+
value !== '.' && value !== '..' && !/[\\/:*?"<>|\x00-\x1f]/.test(value) && !/[. ]$/.test(value) &&
|
|
13
|
+
!/^(?:CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])(?:\.|$)/i.test(value);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async function uniqueDestination(directory, name, partial) {
|
|
17
|
+
const dot = name.lastIndexOf('.');
|
|
18
|
+
const stem = dot > 0 ? name.slice(0, dot) : name;
|
|
19
|
+
const extension = dot > 0 ? name.slice(dot) : '';
|
|
20
|
+
for (let index = 0; ; index++) {
|
|
21
|
+
const suffix = index ? ` (${index})` : '';
|
|
22
|
+
const candidate = index ? `${stem.slice(0, 180 - extension.length - suffix.length)}${suffix}${extension}` : name;
|
|
23
|
+
if (!candidate || candidate.length > 180) throw new Error('同名文件过多,文件名无法继续编号');
|
|
24
|
+
const destination = path.join(directory, candidate);
|
|
25
|
+
try {
|
|
26
|
+
await fs.link(partial, destination);
|
|
27
|
+
await fs.unlink(partial);
|
|
28
|
+
return { name: candidate, path: destination };
|
|
29
|
+
} catch (error) {
|
|
30
|
+
if (error.code !== 'EEXIST') throw error;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function createFileUploadSession(root) {
|
|
36
|
+
let upload;
|
|
37
|
+
const completed = new Map();
|
|
38
|
+
let completedBytes = 0;
|
|
39
|
+
const directory = path.join(root, 'incoming');
|
|
40
|
+
const clearActive = async () => {
|
|
41
|
+
const current = upload;
|
|
42
|
+
upload = undefined;
|
|
43
|
+
if (!current) return;
|
|
44
|
+
await current.handle.close().catch(() => {});
|
|
45
|
+
await fs.unlink(current.partial).catch(() => {});
|
|
46
|
+
};
|
|
47
|
+
const clear = async () => {
|
|
48
|
+
await clearActive();
|
|
49
|
+
for (const file of completed.values()) await fs.unlink(file.path).catch(() => {});
|
|
50
|
+
completed.clear(); completedBytes = 0;
|
|
51
|
+
};
|
|
52
|
+
return {
|
|
53
|
+
async receive(message) {
|
|
54
|
+
if (!message || typeof message !== 'object') throw new Error('无效的文件上传请求');
|
|
55
|
+
if (message.type === 'cancel') { await clear(); return { type: 'cancelled' }; }
|
|
56
|
+
if (message.type === 'commit') {
|
|
57
|
+
if (upload) throw new Error('文件尚未上传完成');
|
|
58
|
+
completed.clear(); completedBytes = 0;
|
|
59
|
+
return { type: 'committed' };
|
|
60
|
+
}
|
|
61
|
+
if (message.type === 'remove') {
|
|
62
|
+
if (upload) throw new Error('请等待当前文件上传完成');
|
|
63
|
+
const file = completed.get(message.id);
|
|
64
|
+
if (!file) throw new Error('文件上传会话已失效');
|
|
65
|
+
await fs.unlink(file.path);
|
|
66
|
+
completed.delete(message.id); completedBytes -= file.size;
|
|
67
|
+
return { type: 'removed', id: message.id };
|
|
68
|
+
}
|
|
69
|
+
if (message.type === 'start') {
|
|
70
|
+
if (upload) throw new Error('已有文件正在上传');
|
|
71
|
+
if (!validName(message.name)) throw new Error('文件名无效');
|
|
72
|
+
if (!Number.isSafeInteger(message.size) || message.size < 1 || message.size > MAX_FILE_BYTES) {
|
|
73
|
+
throw new Error('单个文件不得超过 20 MiB');
|
|
74
|
+
}
|
|
75
|
+
if (completed.size >= MAX_FILE_COUNT || completedBytes + message.size > MAX_TOTAL_BYTES) {
|
|
76
|
+
throw new Error('每条消息最多 4 个文件,合计不超过 40 MiB');
|
|
77
|
+
}
|
|
78
|
+
if (!/^[a-f0-9]{64}$/i.test(message.sha256 || '')) throw new Error('文件校验值无效');
|
|
79
|
+
const id = crypto.randomUUID();
|
|
80
|
+
await fs.mkdir(directory, { recursive: true });
|
|
81
|
+
const partial = path.join(directory, `.upload-${id}`);
|
|
82
|
+
const handle = await fs.open(partial, 'wx');
|
|
83
|
+
upload = { id, partial, handle, name: message.name, size: message.size,
|
|
84
|
+
expected: message.sha256.toLowerCase(), hash: crypto.createHash('sha256'), offset: 0 };
|
|
85
|
+
return { type: 'started', id, offset: 0, chunkBytes: FILE_CHUNK_BYTES };
|
|
86
|
+
}
|
|
87
|
+
const current = upload;
|
|
88
|
+
if (!current || message.id !== current.id) throw new Error('文件上传会话已失效');
|
|
89
|
+
if (message.type === 'chunk') {
|
|
90
|
+
if (!Number.isSafeInteger(message.offset) || message.offset !== current.offset) {
|
|
91
|
+
return { type: 'offset', id: current.id, offset: current.offset };
|
|
92
|
+
}
|
|
93
|
+
if (typeof message.data !== 'string' || message.data.length > Math.ceil(FILE_CHUNK_BYTES / 3) * 4 + 4 ||
|
|
94
|
+
!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(message.data)) {
|
|
95
|
+
throw new Error('文件分片格式无效');
|
|
96
|
+
}
|
|
97
|
+
const bytes = Buffer.from(message.data, 'base64');
|
|
98
|
+
if (!bytes.length || bytes.length > FILE_CHUNK_BYTES || current.offset + bytes.length > current.size) {
|
|
99
|
+
throw new Error('文件分片大小无效');
|
|
100
|
+
}
|
|
101
|
+
await current.handle.writeFile(bytes);
|
|
102
|
+
current.hash.update(bytes);
|
|
103
|
+
current.offset += bytes.length;
|
|
104
|
+
return { type: 'offset', id: current.id, offset: current.offset };
|
|
105
|
+
}
|
|
106
|
+
if (message.type === 'finish') {
|
|
107
|
+
if (current.offset !== current.size || current.hash.digest('hex') !== current.expected) {
|
|
108
|
+
await clear(); throw new Error('文件大小或 SHA-256 校验失败');
|
|
109
|
+
}
|
|
110
|
+
await current.handle.sync();
|
|
111
|
+
await current.handle.close();
|
|
112
|
+
upload = undefined;
|
|
113
|
+
let saved;
|
|
114
|
+
try { saved = await uniqueDestination(directory, current.name, current.partial); }
|
|
115
|
+
catch (error) { await fs.unlink(current.partial).catch(() => {}); throw error; }
|
|
116
|
+
const result = { type: 'completed', id: current.id, ...saved, size: current.size };
|
|
117
|
+
completed.set(current.id, result); completedBytes += current.size;
|
|
118
|
+
return result;
|
|
119
|
+
}
|
|
120
|
+
throw new Error('不支持的文件上传操作');
|
|
121
|
+
},
|
|
122
|
+
close: clear,
|
|
123
|
+
};
|
|
124
|
+
}
|