@wendongfly/myhi 1.3.39 → 1.3.41

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 +10 -6
  2. package/package.json +1 -1
package/dist/chat.html CHANGED
@@ -800,6 +800,7 @@
800
800
  // ── 消息渲染 ──────────────────────────────────
801
801
  function addInputMessage(text) {
802
802
  endStream(); endToolGroup();
803
+ _streamedTextThisMessage = false; // 新一轮用户提问开始,重置流式渲染标志
803
804
  const msg = document.createElement('div');
804
805
  msg.className = 'msg msg-input';
805
806
  msg.innerHTML = `<div><div class="bubble">${escHtml(text)}</div><div class="meta">${formatTime(new Date())}</div></div>`;
@@ -820,6 +821,7 @@
820
821
 
821
822
  let _streamEl = null; // 当前流式输出的 assistant 元素
822
823
  let _streamText = ''; // 累积的原始文本
824
+ let _streamedTextThisMessage = false; // 当前轮(自上次用户提问起)是否已通过 content_block_delta 流式渲染过 text;用于在末尾 assistant / result 事件中跳过重复渲染
823
825
 
824
826
  function addAssistantMessage(raw) {
825
827
  removeThinking(); endToolGroup();
@@ -1318,7 +1320,7 @@
1318
1320
  if (block.type === 'thinking' && block.thinking) {
1319
1321
  showThinking(block.thinking);
1320
1322
  } else if (block.type === 'text' && block.text) {
1321
- addAssistantMessage(block.text);
1323
+ if (!_streamedTextThisMessage) addAssistantMessage(block.text);
1322
1324
  } else if (block.type === 'tool_use') {
1323
1325
  if (block.name === 'AskUserQuestion' && block.input) {
1324
1326
  openAskSheet(block.input);
@@ -1335,17 +1337,18 @@
1335
1337
  case 'result':
1336
1338
  removeThinking();
1337
1339
  setWorkState('idle');
1338
- if (msg.result) {
1340
+ // msg.result 是整轮的最终答复文本,纯文字回答时与流式 delta 内容相同;
1341
+ // 已通过 content_block_delta 渲染过就跳过,避免生成第二个独立气泡
1342
+ if (msg.result && !_streamedTextThisMessage) {
1339
1343
  addAssistantMessage(typeof msg.result === 'string' ? msg.result : JSON.stringify(msg.result));
1340
1344
  }
1341
1345
  const cost = msg.total_cost_usd ? ` ($${msg.total_cost_usd.toFixed(4)})` : '';
1342
1346
  addStatusMessage(`完成${cost}`);
1343
1347
  break;
1344
1348
  case 'content_block_start':
1345
- // 流式内容块开始(tool_use 时显示工具名)
1346
- if (msg.content_block?.type === 'tool_use') {
1347
- addToolMessage('', msg.content_block.name || '工具');
1348
- } else if (msg.content_block?.type === 'thinking') {
1349
+ // 流式内容块开始:thinking 时创建占位,由 thinking_delta 增量填充;
1350
+ // tool_use 不创建占位卡,待末尾 assistant 事件用完整入参渲染,避免重复
1351
+ if (msg.content_block?.type === 'thinking') {
1349
1352
  showThinking('');
1350
1353
  }
1351
1354
  setWorkState('working');
@@ -1354,6 +1357,7 @@
1354
1357
  // 流式内容增量
1355
1358
  if (msg.delta?.type === 'text_delta' && msg.delta.text) {
1356
1359
  appendStream(msg.delta.text);
1360
+ _streamedTextThisMessage = true;
1357
1361
  } else if (msg.delta?.type === 'thinking_delta' && msg.delta.thinking) {
1358
1362
  appendThinking(msg.delta.thinking);
1359
1363
  } else if (msg.delta?.type === 'input_json_delta' && msg.delta.partial_json) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wendongfly/myhi",
3
- "version": "1.3.39",
3
+ "version": "1.3.41",
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",