fix: 修复多项关键 Bug,与 openclaw 上游协议对齐

- main.js: wsClient.connect 传参格式错误(完整 ws:// URL → host:port)
- ws-client.js: request() 等待重连时不处理 onReady 握手失败
- gateway.js: bind 写入非法值 'all',改为 openclaw 合法值 'lan'
- device.rs: connect payload 从 v2 升级到 v3,补充 platform/deviceFamily
- config.rs: macOS reload_gateway 在 async fn 中用同步 Command 阻塞 tokio
- service.rs: Windows check_service_status 端口硬编码 18789,改为读配置
- extensions.rs: parse_cftunnel_status 全角冒号解析失败,添加 split_after_colon
- tauri-api.js: cachedInvoke miss 时 logRequest 被记录两次
- tauri-api.js: mock 补充 list_agents / restart_gateway
- chat.js: 附件对象冗余 data 字段(双倍内存)+ 缩进修复
- services.js: 服务操作缺少操作中 toast 反馈
This commit is contained in:
晴天
2026-03-04 12:16:58 +08:00
parent 05771ffa63
commit dab61ccd24
24 changed files with 882 additions and 209 deletions

View File

@@ -49,10 +49,7 @@ function cachedInvoke(cmd, args = {}, ttl = CACHE_TTL) {
logRequest(cmd, args, 0, true)
return Promise.resolve(cached.val)
}
const start = Date.now()
return invoke(cmd, args).then(val => {
const duration = Date.now() - start
logRequest(cmd, args, duration, false)
_cache.set(key, { val, ts: Date.now() })
return val
})
@@ -65,6 +62,9 @@ function invalidate(...cmds) {
}
}
// 导出 invalidate 供外部使用
export { invalidate }
async function invoke(cmd, args = {}) {
const start = Date.now()
if (_invokeReady) {
@@ -164,6 +164,10 @@ function mockInvoke(cmd, args) {
stop_service: () => true,
restart_service: () => true,
reload_gateway: () => 'Gateway 已重载',
restart_gateway: () => 'Gateway 已重启',
list_agents: () => [
{ id: 'main', isDefault: true, identityName: null, model: null, workspace: null },
],
upgrade_openclaw: () => '升级成功,当前版本: 2026.2.26-zh.3 (mock)',
install_gateway: () => 'Gateway 服务已安装 (mock)',
uninstall_gateway: () => 'Gateway 服务已卸载 (mock)',
@@ -211,6 +215,7 @@ export const api = {
readMcpConfig: () => cachedInvoke('read_mcp_config'),
writeMcpConfig: (config) => { invalidate('read_mcp_config'); return invoke('write_mcp_config', { config }) },
reloadGateway: () => invoke('reload_gateway'),
restartGateway: () => invoke('restart_gateway'),
upgradeOpenclaw: (source = 'chinese') => invoke('upgrade_openclaw', { source }),
installGateway: () => invoke('install_gateway'),
uninstallGateway: () => invoke('uninstall_gateway'),
@@ -224,6 +229,7 @@ export const api = {
addAgent: (name, model, workspace) => { invalidate('list_agents'); return invoke('add_agent', { name, model, workspace: workspace || null }) },
deleteAgent: (id) => { invalidate('list_agents'); return invoke('delete_agent', { id }) },
updateAgentIdentity: (id, name, emoji) => { invalidate('list_agents'); return invoke('update_agent_identity', { id, name, emoji }) },
updateAgentModel: (id, model) => { invalidate('list_agents'); return invoke('update_agent_model', { id, model }) },
backupAgent: (id) => invoke('backup_agent', { id }),
// 日志(短缓存)
@@ -255,6 +261,7 @@ export const api = {
getCftunnelLogs: (lines = 20) => cachedInvoke('get_cftunnel_logs', { lines }, 5000),
getClawappStatus: () => cachedInvoke('get_clawapp_status', {}, 5000),
installCftunnel: () => invoke('install_cftunnel'),
installClawapp: () => invoke('install_clawapp'),
// 设备密钥 + Gateway 握手
createConnectFrame: (nonce, gatewayToken) => invoke('create_connect_frame', { nonce, gatewayToken }),

View File

@@ -326,8 +326,9 @@ export class WsClient {
if (!this._ws || this._ws.readyState !== WebSocket.OPEN || !this._gatewayReady) {
if (!this._intentionalClose && (this._reconnectAttempts > 0 || !this._gatewayReady)) {
const waitTimeout = setTimeout(() => { unsub(); reject(new Error('等待重连超时')) }, 15000)
const unsub = this.onReady(() => {
const unsub = this.onReady((hello, sessionKey, err) => {
clearTimeout(waitTimeout); unsub()
if (err?.error) { reject(new Error(err.message || 'Gateway 握手失败')); return }
this.request(method, params).then(resolve, reject)
})
return
@@ -341,8 +342,14 @@ export class WsClient {
})
}
chatSend(sessionKey, message) {
return this.request('chat.send', { sessionKey, message, deliver: false, idempotencyKey: uuid() })
chatSend(sessionKey, message, attachments) {
const params = { sessionKey, message, deliver: false, idempotencyKey: uuid() }
if (attachments && attachments.length > 0) {
params.attachments = attachments
console.log('[ws] 发送附件:', attachments.length, '个')
console.log('[ws] 附件详情:', attachments.map(a => ({ type: a.type, mime: a.mimeType, name: a.fileName, size: a.content?.length })))
}
return this.request('chat.send', params)
}
chatHistory(sessionKey, limit = 200) {