dsh-mobile-plugin 0.5.127 → 0.5.128
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/lib/mirror/pusher.cjs +24 -14
- package/lib/mobile/feedback.js +43 -0
- package/lib/panel/index.html +15 -15
- package/lib/remote/runtime.cjs +6 -1
- package/lib/remote/store.cjs +64 -1
- package/lib/routes/control-plane.js +7 -0
- package/package.json +15 -15
package/lib/mirror/pusher.cjs
CHANGED
|
@@ -110,6 +110,8 @@ const BG_LIST_REBUILD_FALLBACK_MS = 5000;
|
|
|
110
110
|
const MIRROR_FULL_PUSH_MIN_INTERVAL_MS = 30_000;
|
|
111
111
|
const MAX_CONCURRENT_SESSION_BUILDS = 2;
|
|
112
112
|
const MAX_CONSECUTIVE_EVENT_BUILDS = 3;
|
|
113
|
+
/** 隧道没连时短路记账的那句话。只有它可以被「隧道已恢复」清掉,别的错误是真故障。 */
|
|
114
|
+
const TUNNEL_OFFLINE_ERROR = '隧道未连接,镜像未推送';
|
|
113
115
|
|
|
114
116
|
function createMirrorPusher(deps) {
|
|
115
117
|
const { ctx, tunnelConnected, getSidecar, listSignal = sharedListSignal, sessionSignal = sharedSessionSignal } = deps;
|
|
@@ -582,7 +584,7 @@ function createMirrorPusher(deps) {
|
|
|
582
584
|
// 每一次推上去的清单都顺手记一下规模(含短路那两条路径:手机侧栏看的就是这份清单)。
|
|
583
585
|
noteMirrorList(payload && payload.sessions);
|
|
584
586
|
if (!tunnelConnected()) {
|
|
585
|
-
recordMirrorPush(false,
|
|
587
|
+
recordMirrorPush(false, TUNNEL_OFFLINE_ERROR);
|
|
586
588
|
// 没推成镜像,但「正文长到哪儿了」这件事仍然要说给手机听(见 announceSessionActivity)。
|
|
587
589
|
announceSessionActivity(payload.messages);
|
|
588
590
|
return false
|
|
@@ -1254,25 +1256,33 @@ function createMirrorPusher(deps) {
|
|
|
1254
1256
|
};
|
|
1255
1257
|
};
|
|
1256
1258
|
|
|
1259
|
+
/**
|
|
1260
|
+
* 把「上次推送的记账」投影成面板该显示的当前状态。
|
|
1261
|
+
*
|
|
1262
|
+
* 「隧道未连接」是断线那一刻记下的结果,它不会自动撤销:隧道恢复后 onTunnelUp 的补推
|
|
1263
|
+
* 可能被 30 秒全量间隔挡掉,面板于是挂着一句已经不成立的故障,还让人一键反馈假问题。
|
|
1264
|
+
* 只清这一条、只在隧道确实已连时清——别的错误是真故障,必须原样保留。
|
|
1265
|
+
* 内部记账(pushedAt / ok / error)不动:它仍是「上次尝试」的忠实记录。
|
|
1266
|
+
*/
|
|
1267
|
+
const mirrorPushView = () => {
|
|
1268
|
+
const stale = tunnelConnected() && mirrorPushError === TUNNEL_OFFLINE_ERROR
|
|
1269
|
+
return {
|
|
1270
|
+
pushedAt: mirrorPushAt, ok: stale ? null : mirrorPushOk, error: stale ? null : mirrorPushError,
|
|
1271
|
+
skippedBodies: mirrorBodySkipCount, skipReason: mirrorBodySkipReason,
|
|
1272
|
+
listSessions: mirrorListSessions,
|
|
1273
|
+
listActiveSessions: mirrorListActiveSessions,
|
|
1274
|
+
listSubagents: mirrorListSubagents,
|
|
1275
|
+
listAt: mirrorListAt,
|
|
1276
|
+
}
|
|
1277
|
+
};
|
|
1278
|
+
|
|
1257
1279
|
return {
|
|
1258
1280
|
start,
|
|
1259
1281
|
pushMirror,
|
|
1260
1282
|
pushSessionImmediately,
|
|
1261
1283
|
/** 会话名(取不到就空串):装配层拿它当系统通知的标题。 */
|
|
1262
1284
|
sessionTitleOf,
|
|
1263
|
-
getMirrorPush:
|
|
1264
|
-
pushedAt: mirrorPushAt, ok: mirrorPushOk, error: mirrorPushError,
|
|
1265
|
-
// 正文缺失而清单照推的次数与最近原因:与 ok/pushedAt 分开,避免再把
|
|
1266
|
-
// 「某会话正文读不到」误读成「镜像死了」(见 recordMirrorPushSkipped)。
|
|
1267
|
-
skippedBodies: mirrorBodySkipCount, skipReason: mirrorBodySkipReason,
|
|
1268
|
-
// 清单规模(自检台账读它):会话总数 / 其中活跃 / 其中子会话 / 这份读数的时间。
|
|
1269
|
-
// 这是「手机侧栏那份清单有多大」,**不是**「宿主内存里挂着多少会话、正文占多少」——
|
|
1270
|
-
// 后者插件看不到(见 lib/mobile/self-check.cjs 的口径段)。
|
|
1271
|
-
listSessions: mirrorListSessions,
|
|
1272
|
-
listActiveSessions: mirrorListActiveSessions,
|
|
1273
|
-
listSubagents: mirrorListSubagents,
|
|
1274
|
-
listAt: mirrorListAt,
|
|
1275
|
-
}),
|
|
1285
|
+
getMirrorPush: mirrorPushView,
|
|
1276
1286
|
/** 失败会话的定向重试账(诊断 + 守卫用):失败几次、下次什么时候补推。 */
|
|
1277
1287
|
getPushFailures: () => [...sessionPushFailures.entries()].map(([sessionId, entry]) => ({
|
|
1278
1288
|
sessionId, attempts: entry.attempts, dueAt: entry.dueAt, error: entry.lastError,
|
package/lib/mobile/feedback.js
CHANGED
|
@@ -408,6 +408,48 @@ function renderSummary(value) {
|
|
|
408
408
|
}
|
|
409
409
|
}
|
|
410
410
|
|
|
411
|
+
/**
|
|
412
|
+
* 面板「发送问题」的入口:表单在这里(Node 侧)拼、在这里发,面板只走同源本地接口。
|
|
413
|
+
*
|
|
414
|
+
* 面板在浏览器里直连平台时,来源是 `http://127.0.0.1:<端口>`,平台只对自己的站点回
|
|
415
|
+
* `access-control-allow-origin`,浏览器读不到响应就抛 `Failed to fetch` —— 请求其实已经
|
|
416
|
+
* 到平台了,用户却看到发送失败、还会重发。字段必须与面板原先逐字一致(尤其不带
|
|
417
|
+
* submit_kind,保持「插件自报」的归类),所以这里复用同一套 buildFeedbackForm。
|
|
418
|
+
*/
|
|
419
|
+
async function submitPanelFeedback({ summary, detail, context, version, deviceId, submissionId }) {
|
|
420
|
+
const form = buildFeedbackForm(null, String(summary || ''), '', {
|
|
421
|
+
localDeviceId: String(deviceId || ''),
|
|
422
|
+
submissionId,
|
|
423
|
+
componentVersion: version,
|
|
424
|
+
diagnosis: String(detail || ''),
|
|
425
|
+
context: context && typeof context === 'object' ? context : {},
|
|
426
|
+
});
|
|
427
|
+
const data = await postMultipart(form);
|
|
428
|
+
const key = data && typeof data.thread_key === 'string' ? data.thread_key : '';
|
|
429
|
+
if (!key) throw new Error('反馈接口没有返回线程编号');
|
|
430
|
+
return { threadKey: key, submissionId };
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* 面板「发送问题」的本机转发路由:只在本机来源上收面板草稿,Node 侧发出去。
|
|
435
|
+
*/
|
|
436
|
+
async function handlePanelFeedback({ req, res, readJson, sendJson }) {
|
|
437
|
+
try {
|
|
438
|
+
const body = await readJson(req);
|
|
439
|
+
const submitted = await submitPanelFeedback({
|
|
440
|
+
summary: body.summary,
|
|
441
|
+
detail: body.detail,
|
|
442
|
+
context: body.context,
|
|
443
|
+
version: body.version,
|
|
444
|
+
deviceId: body.deviceId,
|
|
445
|
+
submissionId: body.submissionId,
|
|
446
|
+
});
|
|
447
|
+
return sendJson(res, 200, submitted);
|
|
448
|
+
} catch (error) {
|
|
449
|
+
return sendJson(res, error.status || 502, { ok: false, error: { code: 'feedback_failed', message: String(error?.message || error) } });
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
|
|
411
453
|
/** 装配层入口:挂 `dsh_feedback` 工具;宿主没有 tools 服务时只少这个工具。 */
|
|
412
454
|
function installFeedback(ctx, deps) {
|
|
413
455
|
return registerFeedbackTool(ctx, deps);
|
|
@@ -425,6 +467,7 @@ module.exports = {
|
|
|
425
467
|
SOURCE,
|
|
426
468
|
buildFeedbackForm,
|
|
427
469
|
diagnosisTextOf,
|
|
470
|
+
handlePanelFeedback,
|
|
428
471
|
feedbackChannels,
|
|
429
472
|
installFeedback,
|
|
430
473
|
localDeviceId,
|