dsh-mobile-plugin 0.5.95 → 0.5.96

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.
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: dsh-mobile-kb
3
- description: DSH 手机版(移动端插件)连不上电脑、配对失败、设备离线/失联、中转与局域网不通、自建公网入口(IPv4 公网/端口映射、IPv6、frp、DDNS、Nginx 反代、域名)等常见问题的排查知识库。用户说「帮我部署一个网络」「不知道该用什么网络」「你帮我看看我能怎么连」「隧道是不是关的」「怎么开内置隧道」时也用。「配对没成功」「扫二维码没反应」「显示离线」「连不上」「中转连不上」「局域网不通」「IPv6 直连连不上」「家里光猫/路由器 IPv6 没开」「IPv6 防火墙」「有公网 IPv4 / 端口映射 / 路由器映射」「frp / frps / frpc / 自建 TCP 隧道」「dsh-relay / 自建中转服务器 / 部署中转 / 中转体检口」「ddns / 域名绑定 / 动态解析」「nginx 反代 / NAS 部署」「外网拨不进来」「海外 IPv6 / 运营商不给 IPv6 / 网关锁死」「路由器后台密码/超级管理」「apiProxy 未注入 / 电脑插件没加载 / 加载会话或工作区失败 / 电脑服务处理失败」「归档或改名成功却弹加载失败 / 动作成功却报请求超时(GET /sessions)」「HTTP 522 / 注册超时」「stage: auth」「怎么回这条反馈」时也用。先按这里分好类,再读对应参考,别从头猜。
3
+ description: DSH 手机版(电脑上装的「移动端插件」,手机 App 靠它连回这台电脑)的网络搭建与排查知识库。用户要给「移动端插件 / DSH 手机版 / 手机 App 连电脑」搭建、部署、开通一条能连回电脑的网络线路(比如「我想给移动端插件搭建一个网络线路」「给当前 DSH 装的这个移动端插件弄条能连的网络」),或用「帮我部署一个网络」「不知道该用什么网络」「你帮我看看我能怎么连」「隧道是不是关的」「怎么开内置隧道」这类说法时用它;遇到连不上电脑、配对失败、设备离线/失联、中转与局域网不通、自建公网入口(IPv4 公网/端口映射、IPv6、frp、DDNS、Nginx 反代、域名)等问题也用它。「配对没成功」「扫二维码没反应」「显示离线」「连不上」「中转连不上」「局域网不通」「IPv6 直连连不上」「家里光猫/路由器 IPv6 没开」「IPv6 防火墙」「有公网 IPv4 / 端口映射 / 路由器映射」「frp / frps / frpc / 自建 TCP 隧道」「dsh-relay / 自建中转服务器 / 部署中转 / 中转体检口」「ddns / 域名绑定 / 动态解析」「nginx 反代 / NAS 部署」「外网拨不进来」「海外 IPv6 / 运营商不给 IPv6 / 网关锁死」「路由器后台密码/超级管理」「apiProxy 未注入 / 电脑插件没加载 / 加载会话或工作区失败 / 电脑服务处理失败」「归档或改名成功却弹加载失败 / 动作成功却报请求超时(GET /sessions)」「HTTP 522 / 注册超时」「stage: auth」「怎么回这条反馈」时也用。先按这里分好类,再读对应参考,别从头猜。
4
4
  ---
5
5
 
6
6
  # DSH 手机版常见问题(dsh-mobile-kb)
@@ -10,6 +10,7 @@ description: DSH 手机版(移动端插件)连不上电脑、配对失败、
10
10
  ## 入口
11
11
 
12
12
  - 用户问 DSH 手机版「连不上、配不对、设备离线、中转不通、局域网不通」这类问题,或反馈里带 `stage: xxx`、设备与版本信息时,走这里。
13
+ - 先把一个词对上:用户说的「移动端插件」「手机版」「DSH 手机版」,指的都是电脑上那个让手机 App 连回 DSH 的插件(AI-HUB 移动端插件)。所以「给移动端插件搭建网络线路」= 让手机能连回这台电脑,不是去布网线、拉专线或搭别的 VPN。
13
14
  - 先按下面的分类选一篇 references 读,再回答;没读参考前不凭印象给结论。
14
15
  - 这是排查知识,不是修复记录:问题已经被修好的,不必往下面加。
15
16
 
@@ -48,6 +48,7 @@ const {
48
48
  toolStepState,
49
49
  } = require('./step-index.js');
50
50
  const { deriveWorkflowRuns } = require('./workflow-runs.js');
51
+ const { createQuestionReplyTracker } = require('./question-reply.js');
51
52
 
52
53
  /**
53
54
  * 从 session.list 摘要行取会话标题(与桌面端侧栏同源,不再从 history 窗口猜):
@@ -533,6 +534,9 @@ function deriveMessages(events, sessionId, lookbackEvents) {
533
534
  if (hit !== undefined) return hit;
534
535
  }
535
536
  const out = [];
537
+ // 问答累积器:`ask_user_question` 的调用先记题目、结果到达时折成一条 `question-reply` 行。
538
+ // 与直播(stream.js)各持一份,两边游标互不相干。
539
+ const questionReplies = createQuestionReplyTracker();
536
540
  // 预扫描 tool/result 事件(同批次事件内,结果可能在调用块之前/之后出现)。
537
541
  // `lookbackEvents` 是这一页**再往前**的一小段:倒着分页时工具结果常常落在比消息更早的位置
538
542
  // (一轮里先跑工具、最后才写正文),只看这一页就看不出这一轮出过哪些图。
@@ -719,6 +723,9 @@ function deriveMessages(events, sessionId, lookbackEvents) {
719
723
  return;
720
724
  }
721
725
  if (raw.type !== 'tool-call') return;
726
+ // `ask_user_question` 不进球过程:它答完会落成一条「问 + 答」气泡(见 question-reply.js),
727
+ // 再留一行空摘要的工具步骤只是同一次提问被画两遍。
728
+ if (raw.name === 'ask_user_question') return;
722
729
  const callId = raw.id != null ? String(raw.id) : undefined;
723
730
  const result = callId ? toolResults.get(callId) : undefined;
724
731
  const rawArgs = typeof raw.arguments === 'string'
@@ -864,6 +871,17 @@ function deriveMessages(events, sessionId, lookbackEvents) {
864
871
  const e = entry.event || entry;
865
872
  const seq = e.seq;
866
873
  const time = e.time;
874
+ // 问答派生:`ask_user_question` 的调用先记题目、结果到达时吐一条 `question-reply` 行。
875
+ // `tool/call` / `tool/result` 其余情况此前整条忽略,`assistant/message` 还要继续走下面的
876
+ // 消息折叠,所以只有前两种吃 `continue`。
877
+ if (e.type === 'tool/call' || e.type === 'tool/result') {
878
+ const reply = questionReplies.note(e);
879
+ if (reply) out.push(reply);
880
+ continue;
881
+ }
882
+ if (e.type === 'assistant/message' && e.data && e.data.message) {
883
+ questionReplies.note(e);
884
+ }
867
885
  // 工作流那四类事件不在这里就地折:攒起来整窗看(见 `workflowEntries`)。
868
886
  if (typeof e.type === 'string' && e.type.startsWith('tool-workflow/')) {
869
887
  workflowEntries.push(entry.event ? entry : { event: e });
@@ -0,0 +1,159 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * `ask_user_question` 的问答派生(历史与直播共用这一份)。
5
+ *
6
+ * 桌面那边由 `dsh-client-ui-user-questions` 的 `answeredQuestionDefinition` 把「问 + 答」
7
+ * 折成一条右对齐的用户气泡(`QuestionReplyView`):每道题在上、用户给的答案在下,跳过显示
8
+ * 「已跳过」。手机此前只把提问卡收掉,对话记录里看不到用户选了什么 —— 这里补上同一件事。
9
+ *
10
+ * 只认 `ask_user_question` 的调用与其结果**成对**出现:
11
+ * - 计划评审(`intent.kind === 'plan-review'`)不是普通选择题,走它自己的接管卡,这里不出气泡;
12
+ * - pending(限时提问还没答)/ 失败 / 题数对不上 / 畸形的结果都不算,交回通用工具行;
13
+ * - 题里任一题带 plan-review、或没有题,整批都不出(与桌面 `callQuestions` 同口径)。
14
+ *
15
+ * 状态按 callId 记:调用先到、结果后到时才能把题目和答案配起来。历史与直播各持一份,
16
+ * 因为两边的游标互不相干(见 `history-derive.js` 与 `stream.js`)。
17
+ */
18
+
19
+ /** 计划评审的 intent.kind,出现在任一题里就不当普通提问。 */
20
+ const PLAN_REVIEW = 'plan-review';
21
+
22
+ function isRecord(value) {
23
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
24
+ }
25
+
26
+ function parseJsonRecord(text) {
27
+ try {
28
+ const value = JSON.parse(text);
29
+ return isRecord(value) ? value : null;
30
+ } catch {
31
+ return null;
32
+ }
33
+ }
34
+
35
+ /**
36
+ * 从调用参数解析题目;解析失败 / 无题 / 有题带 plan-review intent 时返回 null。
37
+ *
38
+ * `arguments` 既可能是 JSON 原文,也可能是已解析对象(PTC / 合成事件两种形状都见过)。
39
+ */
40
+ function questionsOf(args) {
41
+ const value = typeof args === 'string' ? parseJsonRecord(args) : (isRecord(args) ? args : null);
42
+ if (!value || !Array.isArray(value.questions) || value.questions.length === 0) return null;
43
+ const ids = new Set();
44
+ const questions = [];
45
+ for (const question of value.questions) {
46
+ if (!isRecord(question) || typeof question.id !== 'string' || typeof question.question !== 'string') return null;
47
+ if (ids.has(question.id)) return null;
48
+ if (isRecord(question.intent) && question.intent.kind === PLAN_REVIEW) return null;
49
+ ids.add(question.id);
50
+ questions.push({
51
+ id: question.id,
52
+ question: question.question,
53
+ ...(typeof question.header === 'string' && question.header ? { header: question.header } : {}),
54
+ });
55
+ }
56
+ return questions;
57
+ }
58
+
59
+ /**
60
+ * 从工具结果解析答案批次;pending / 失败 / 题数对不上 / 畸形返回 null。
61
+ *
62
+ * 结果正文是宿主塞给模型的那段 JSON:`{"answers":[{"id","selected","custom"?}]}`。
63
+ */
64
+ function answersOf(resultMessage, questions) {
65
+ if (!isRecord(resultMessage) || resultMessage.isError === true) return null;
66
+ const content = resultMessage.content;
67
+ if (!Array.isArray(content) || content.length !== 1) return null;
68
+ const block = content[0];
69
+ if (!isRecord(block) || block.type !== 'text' || typeof block.text !== 'string') return null;
70
+ const value = parseJsonRecord(block.text);
71
+ if (!value || value.pending === true || !Array.isArray(value.answers)) return null;
72
+ if (value.answers.length !== questions.length) return null;
73
+ const ids = new Set(questions.map((question) => question.id));
74
+ const answers = [];
75
+ for (const answer of value.answers) {
76
+ if (!isRecord(answer) || typeof answer.id !== 'string' || !ids.delete(answer.id)) return null;
77
+ if (!Array.isArray(answer.selected) || !answer.selected.every((label) => typeof label === 'string')) return null;
78
+ if (answer.custom !== undefined && typeof answer.custom !== 'string') return null;
79
+ answers.push({
80
+ id: answer.id,
81
+ selected: [...answer.selected],
82
+ ...(answer.custom === undefined ? {} : { custom: answer.custom }),
83
+ });
84
+ }
85
+ return answers;
86
+ }
87
+
88
+ /** 从工具结果事件取 callId(两种宿主形状:`message.source.callId` / `message.toolCallId`)。 */
89
+ function callIdOfResult(data) {
90
+ const message = data && data.message;
91
+ if (!isRecord(message)) return '';
92
+ const source = message.source;
93
+ if (isRecord(source) && source.callId != null) return String(source.callId);
94
+ return message.toolCallId != null ? String(message.toolCallId) : '';
95
+ }
96
+
97
+ /**
98
+ * 建一份问答累积器。`note(event)` 喂原始会话事件:
99
+ * - `tool/call` / `assistant/message` 里的 `ask_user_question` 调用 → 记下题目,返回 null;
100
+ * - 对应的 `tool/result` 且答案合法 → 吐出结构化行(`kind:'question-reply'`),否则 null。
101
+ *
102
+ * 返回的行形状对齐 App 的 `ChatMessage`(`text` 空串、内容全在 `questionReply` 上)。
103
+ */
104
+ function createQuestionReplyTracker() {
105
+ /** callId → 题目数组。 */
106
+ const questionsByCall = new Map();
107
+
108
+ const rememberCall = (callId, args) => {
109
+ if (!callId) return;
110
+ const questions = questionsOf(args);
111
+ if (questions) questionsByCall.set(callId, questions);
112
+ };
113
+
114
+ function note(event) {
115
+ if (!event || typeof event.type !== 'string') return null;
116
+
117
+ if (event.type === 'tool/call') {
118
+ const data = event.data;
119
+ if (!isRecord(data) || data.name !== 'ask_user_question') return null;
120
+ rememberCall(data.callId != null ? String(data.callId) : '', data.arguments);
121
+ return null;
122
+ }
123
+
124
+ if (event.type === 'assistant/message') {
125
+ const message = event.data && event.data.message;
126
+ if (!isRecord(message) || !Array.isArray(message.content)) return null;
127
+ for (const block of message.content) {
128
+ if (!isRecord(block) || block.type !== 'tool-call' || block.name !== 'ask_user_question') continue;
129
+ rememberCall(block.id != null ? String(block.id) : '', block.arguments);
130
+ }
131
+ return null;
132
+ }
133
+
134
+ if (event.type !== 'tool/result') return null;
135
+ const data = event.data;
136
+ const callId = callIdOfResult(data);
137
+ const questions = callId ? questionsByCall.get(callId) : undefined;
138
+ if (!questions) return null;
139
+ const answers = answersOf(data.message, questions);
140
+ if (!answers) return null;
141
+ questionsByCall.delete(callId);
142
+ return {
143
+ id: `question-reply-${callId}`,
144
+ kind: 'question-reply',
145
+ text: '',
146
+ questionReply: { callId, questions, answers },
147
+ seq: Number.isSafeInteger(event.seq) ? event.seq : 0,
148
+ time: typeof event.time === 'number' ? event.time : 0,
149
+ };
150
+ }
151
+
152
+ return { note };
153
+ }
154
+
155
+ module.exports = {
156
+ createQuestionReplyTracker,
157
+ questionsOf,
158
+ answersOf,
159
+ };
@@ -43,6 +43,7 @@ const { callSessions } = require('./rpc.js');
43
43
  const { unwrap } = require('./envelope.js');
44
44
  const { normalizeJobs } = require('./jobs.js');
45
45
  const { cutEvent, createToolNameIndex } = require('./wire-cut.js');
46
+ const { createQuestionReplyTracker } = require('./question-reply.js');
46
47
  const { createPresentedStats } = require('./presented-file-stats.js');
47
48
  const { noteLiveEvent, drainLiveSteps, liveStepsOf, liveStepsTurnOf, liveTurnFactsOf, drainLiveTurnFacts, seedLiveTurnFacts, claimLiveWriter, releaseLiveWriter, attachLiveSteps, broadcastLiveSteps } = require('./live-steps.js');
48
49
  const { readTurnEvents } = require('./session-changes.js');
@@ -519,6 +520,9 @@ async function handleStream(ctx, req, res) {
519
520
  const imageBudget = createTextImageBudget();
520
521
  // 过程明细的减法(wire-cut.js)与它要的工具名索引:整条流共用一份,回放与实时帧都往里吸。
521
522
  const toolNames = createToolNameIndex();
523
+ // 问答派生:`ask_user_question` 的调用与结果在减法之前先过一遍,折出「问 + 答」行推给手机
524
+ // (见 question-reply.js)。回放与实时帧共用同一份,断线续传也能把这一行补回来。
525
+ const questionReplies = createQuestionReplyTracker();
522
526
  /**
523
527
  * 跑着那一轮的过程清单一发(`session/live-steps`)。
524
528
  *
@@ -564,7 +568,7 @@ async function handleStream(ctx, req, res) {
564
568
 
565
569
  // 断线续传:回放 history 中 seq > resumeSeq 的事件(收敛状态)。
566
570
  if (resumeSeq != null && resumeSeq > 0) {
567
- const replay = await replaySince(ctx, sessionId, resumeSeq, res, ac.signal, (seq) => { lastDeliveredSeq = Math.max(lastDeliveredSeq, seq); }, streamAddress, sealFrame, imageBudget, toolNames, presentedStats, liveWriterId);
571
+ const replay = await replaySince(ctx, sessionId, resumeSeq, res, ac.signal, (seq) => { lastDeliveredSeq = Math.max(lastDeliveredSeq, seq); }, streamAddress, sealFrame, imageBudget, toolNames, presentedStats, liveWriterId, questionReplies);
568
572
  if (replay.gap && !ac.signal.aborted) {
569
573
  const value = { type: 'session/resync-required', sessionId, resumeSeq, oldestSeq: replay.oldestSeq };
570
574
  // 旧实现在这里直接 `return`:既不清 keepAlive 也不 end,漏出一条永不收尾的连接。
@@ -644,6 +648,15 @@ async function handleStream(ctx, req, res) {
644
648
  // 过程副本:推理正文与工具参数不上线路,但用户点开「正在读取文件」那一步时要
645
649
  // 就地答得出来(落盘之前宿主的历史里还没有这一份,见 live-steps.js)。
646
650
  noteLiveEvent(ctx, sessionId, event, liveWriterId);
651
+ // 问答派生要在 `cutEvent` 之前:工具参数与结果正文都不上线路,只能在电脑侧折成
652
+ // 一条 `question-reply` 行推给手机(见 question-reply.js)。
653
+ {
654
+ const replyItem = questionReplies.note(event);
655
+ if (replyItem) {
656
+ const value = { type: 'session/question-reply', sessionId, item: replyItem };
657
+ if (await pushOrdered(value, null) === 'closed') { clientGone = true; break; }
658
+ }
659
+ }
647
660
  const facts = event.type === 'turn/start' ? null : drainLiveTurnFacts(ctx, sessionId, liveWriterId);
648
661
  if (facts) {
649
662
  const value = { type: 'session/turn-facts', sessionId, ...facts };
@@ -780,7 +793,7 @@ async function handleStream(ctx, req, res) {
780
793
  * 从会话 history 回放 seq > sinceSeq 的事件(升序),逐个经附件解析后写 SSE。
781
794
  * 通过 onDelivered(seq) 回报已交付的最大 seq,供上层去重。
782
795
  */
783
- async function replaySince(ctx, sessionId, sinceSeq, res, signal, onDelivered, address, sealFrame = null, imageBudget = null, toolNames = null, presentedStats = null, liveWriterId) {
796
+ async function replaySince(ctx, sessionId, sinceSeq, res, signal, onDelivered, address, sealFrame = null, imageBudget = null, toolNames = null, presentedStats = null, liveWriterId, questionReplies = null) {
784
797
  try {
785
798
  // 子会话的重放也要带父会话(同 historyAddress 的口径),否则宿主回 agent-busy,
786
799
  // 这条断线续传静默退化成「后面缺一段」。
@@ -828,6 +841,8 @@ async function replaySince(ctx, sessionId, sinceSeq, res, signal, onDelivered, a
828
841
  // 漏掉的事件重走一遍,顺手折回去最省事(turn/start 的重置也照直播的口径生效)。
829
842
  if (typeof e.type === 'string' && e.type.startsWith('tool-workflow/')) noteWorkflowEvent(ctx, sessionId, e);
830
843
  const resolved = await resolveEventAttachments(ctx, sessionId, e, { referencesOnly: true });
844
+ // 问答派生要在减之前喂原始事件(参数与结果正文不上线路,见 question-reply.js)。
845
+ const replyItem = questionReplies ? questionReplies.note(resolved) : null;
831
846
  let event = cutEvent(resolved, toolNames);
832
847
  // 回放与直播同一副眼镜:整条不上线路的事件这里也跳过(见 wire-cut.js)。
833
848
  if (!event) continue;
@@ -844,6 +859,14 @@ async function replaySince(ctx, sessionId, sinceSeq, res, signal, onDelivered, a
844
859
  // 回放是「一次性灌几千条」,最容易把写队列撑爆:写不动就在这里等,别一口气塞完。
845
860
  if (sent.needDrain && !(await waitForDrain(res, signal))) break;
846
861
  if (Number.isFinite(event.seq)) onDelivered(event.seq);
862
+ // 这一事件折出的问答行单独补一帧:手机端把它并进消息列表(同 id 幂等去重)。
863
+ if (replyItem) {
864
+ const value = { type: 'session/question-reply', sessionId, item: replyItem };
865
+ const replySent = writeSse(res, value, { payload: value }, { burst: true, sealFrame });
866
+ if (!replySent.ok) break;
867
+ written += (replySent.bytes ?? 0);
868
+ if (replySent.needDrain && !(await waitForDrain(res, signal))) break;
869
+ }
847
870
  // 字节到顶也一样:剩下的交给分页历史,别再灌。**但必须把缺口报出去** —— 只发前缀
848
871
  // 而不说话,客户端会以为这一段就是全部,接着实时流往下走(它只按 seq 去重、不查跳跃),
849
872
  // 缺掉的那一截永远不会被补。与 `gap` 同一个出口,上层据此发 resync。