@wendongfly/myhi 1.3.104 → 1.3.105

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.
Files changed (2) hide show
  1. package/dist/chat.html +33 -5
  2. package/package.json +1 -1
package/dist/chat.html CHANGED
@@ -2622,15 +2622,43 @@
2622
2622
  let _askQuestions = [];
2623
2623
  let askMultiState = null; // { answers: [{question,label}|null] },下标与 _askQuestions 对齐
2624
2624
 
2625
+ // 解 \uXXXX / \n / \t 转义:有些网关把 AskUserQuestion input 用 ensure_ascii 序列化下发,
2626
+ // 文本里就是字面的反斜杠-u,直接 textContent 会显示成 优化...,这里解回真字符。
2627
+ function _decodeU(s) {
2628
+ if (typeof s !== 'string') return s;
2629
+ if (s.indexOf('\\u') < 0 && s.indexOf('\\n') < 0 && s.indexOf('\\t') < 0) return s;
2630
+ return s.replace(/\\u([0-9a-fA-F]{4})/g, (_, h) => String.fromCharCode(parseInt(h, 16)))
2631
+ .replace(/\\n/g, '\n').replace(/\\t/g, '\t');
2632
+ }
2633
+ // input 可能是对象,也可能是被整段序列化的 JSON 字符串(网关双重编码)→ 尽力还原成对象
2634
+ function _coerceAsk(v) {
2635
+ if (typeof v === 'string') {
2636
+ const t = v.trim();
2637
+ if (t[0] === '{' || t[0] === '[') { try { return JSON.parse(t); } catch {} }
2638
+ try { return JSON.parse(_decodeU(t)); } catch {}
2639
+ return { question: v };
2640
+ }
2641
+ return v || {};
2642
+ }
2625
2643
  function _normalizeAsk(input) {
2626
- const q = input?.questions || input?.question;
2644
+ input = _coerceAsk(input);
2645
+ let q = input.questions || input.question;
2646
+ // question/questions 本身又是序列化 JSON 字符串时,再解一层
2647
+ if (typeof q === 'string' && (q.trim()[0] === '{' || q.trim()[0] === '[' || q.indexOf('\\u') >= 0)) {
2648
+ const p = _coerceAsk(q);
2649
+ if (p && (p.questions || p.options || Array.isArray(p))) q = p.questions || p;
2650
+ }
2627
2651
  const list = Array.isArray(q)
2628
2652
  ? q
2629
- : [{ question: (typeof q === 'string' ? q : '') || input?.question || '请选择', options: input?.options, header: input?.header }];
2653
+ : [{ question: (typeof q === 'string' ? q : '') || '请选择', options: input.options, header: input.header }];
2630
2654
  return list.map((x) => ({
2631
- question: x.question || x.text || '',
2632
- options: x.options || x.choices || [],
2633
- header: x.header,
2655
+ question: _decodeU(x.question || x.text || ''),
2656
+ options: (x.options || x.choices || []).map((o) =>
2657
+ (typeof o === 'string' || typeof o === 'number')
2658
+ ? { label: _decodeU(String(o)) }
2659
+ : { ...o, label: _decodeU(o.label || o.value || ''), description: _decodeU(o.description || '') }
2660
+ ),
2661
+ header: _decodeU(x.header),
2634
2662
  }));
2635
2663
  }
2636
2664
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wendongfly/myhi",
3
- "version": "1.3.104",
3
+ "version": "1.3.105",
4
4
  "description": "Web-based terminal sharing with chat UI — control your terminal from phone via LAN/Tailscale",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",