@wendongfly/myhi 1.3.166 → 1.3.167

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/dist/chat.html CHANGED
@@ -3205,16 +3205,12 @@
3205
3205
  if (workState !== 'idle') {
3206
3206
  (async () => {
3207
3207
  try {
3208
- const r = await fetch('/api/inbox', {
3209
- method: 'POST', headers: { 'Content-Type': 'application/json' },
3210
- body: JSON.stringify({ text: prompt, sessionId: SESSION_ID, source: 'busy' }),
3211
- });
3212
- const d = await r.json();
3208
+ const d = await postDraft({ text: prompt, sessionId: SESSION_ID, source: 'busy' });
3213
3209
  if (d.error) { addStatusMessage('存草稿失败: ' + d.error); return; }
3214
3210
  _draftTipDismissed = false;
3215
3211
  await refreshInbox();
3216
3212
  addStatusMessage('📥 AI 正在跑,已把「重读 ' + p + '」存进草稿,干完自动接上');
3217
- } catch (e) { addStatusMessage('存草稿失败: ' + e.message); }
3213
+ } catch (e) { addStatusMessage('存草稿失败: ' + draftErrMsg(e)); }
3218
3214
  })();
3219
3215
  return;
3220
3216
  }
@@ -4034,6 +4030,29 @@
4034
4030
  let _inboxCache = { drafts: [], counts: {} };
4035
4031
  let _draftTipDismissed = false;
4036
4032
 
4033
+ // 存草稿统一走这里:网络层失败(Failed to fetch,多为连接被复用竞争/瞬时断连)
4034
+ // 自动重试一次;clientKey 让服务端去重,重试不会记两条。
4035
+ async function postDraft(body) {
4036
+ body.clientKey = (crypto.randomUUID ? crypto.randomUUID() : `${Date.now()}-${Math.random()}`);
4037
+ let lastErr;
4038
+ for (let i = 0; i < 2; i++) {
4039
+ try {
4040
+ const r = await fetch('/api/inbox', {
4041
+ method: 'POST', headers: { 'Content-Type': 'application/json' },
4042
+ body: JSON.stringify(body),
4043
+ });
4044
+ return await r.json();
4045
+ } catch (e) {
4046
+ lastErr = e;
4047
+ if (!i) await new Promise((res) => setTimeout(res, 400));
4048
+ }
4049
+ }
4050
+ throw lastErr;
4051
+ }
4052
+ function draftErrMsg(e) {
4053
+ return e.message === 'Failed to fetch' ? '网络连接中断(重试仍失败)' : e.message;
4054
+ }
4055
+
4037
4056
  async function refreshInbox(silent = true) {
4038
4057
  try {
4039
4058
  const r = await fetch('/api/inbox');
@@ -4187,15 +4206,11 @@
4187
4206
  const text = ta.value.trim();
4188
4207
  if (!text && !_inboxNewImage) { addStatusMessage('写点什么或加张图再记'); return; }
4189
4208
  try {
4190
- const r = await fetch('/api/inbox', {
4191
- method: 'POST', headers: { 'Content-Type': 'application/json' },
4192
- body: JSON.stringify({
4193
- text, sessionId: SESSION_ID, source: 'manual',
4194
- autoSend: document.getElementById('inbox-new-autosend').checked,
4195
- images: _inboxNewImage ? [_inboxNewImage] : [],
4196
- }),
4209
+ const d = await postDraft({
4210
+ text, sessionId: SESSION_ID, source: 'manual',
4211
+ autoSend: document.getElementById('inbox-new-autosend').checked,
4212
+ images: _inboxNewImage ? [_inboxNewImage] : [],
4197
4213
  });
4198
- const d = await r.json();
4199
4214
  if (d.error) { addStatusMessage('存草稿失败: ' + d.error); return; }
4200
4215
  ta.value = '';
4201
4216
  clearInboxNewImage();
@@ -4203,7 +4218,7 @@
4203
4218
  await refreshInbox();
4204
4219
  renderInbox();
4205
4220
  } catch (e) {
4206
- addStatusMessage('存草稿失败: ' + e.message);
4221
+ addStatusMessage('存草稿失败: ' + draftErrMsg(e));
4207
4222
  }
4208
4223
  };
4209
4224
 
@@ -4219,10 +4234,7 @@
4219
4234
  files: _pendingFile ? [{ path: _pendingFile.path, name: _pendingFile.name }] : [],
4220
4235
  };
4221
4236
  try {
4222
- const r = await fetch('/api/inbox', {
4223
- method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body),
4224
- });
4225
- const d = await r.json();
4237
+ const d = await postDraft(body);
4226
4238
  if (d.error) { addStatusMessage('存草稿失败: ' + d.error); return false; }
4227
4239
  cmdInput.value = '';
4228
4240
  cmdInput.style.height = 'auto';
@@ -4236,7 +4248,7 @@
4236
4248
  : '📥 已存进草稿');
4237
4249
  return true;
4238
4250
  } catch (e) {
4239
- addStatusMessage('存草稿失败: ' + e.message);
4251
+ addStatusMessage('存草稿失败: ' + draftErrMsg(e));
4240
4252
  return false;
4241
4253
  }
4242
4254
  };
package/dist/index.html CHANGED
@@ -1158,20 +1158,31 @@
1158
1158
  if (!sid) { alert('请选择归属任务'); return; }
1159
1159
  if (!text && !_notePendingImage) { alert('写点什么或传张图'); return; }
1160
1160
  try {
1161
- const r = await fetch('/api/inbox', {
1162
- method: 'POST', headers: { 'Content-Type': 'application/json' },
1163
- body: JSON.stringify({
1164
- text, sessionId: sid, source: 'home',
1165
- autoSend: document.getElementById('note-autosend').checked,
1166
- images: _notePendingImage ? [{ path: _notePendingImage.path, name: '图片' }] : [],
1167
- }),
1168
- });
1169
- const d = await r.json();
1161
+ // 网络层失败自动重试一次;clientKey 让服务端去重,重试不会记两条
1162
+ const clientKey = (crypto.randomUUID ? crypto.randomUUID() : `${Date.now()}-${Math.random()}`);
1163
+ let d;
1164
+ for (let i = 0; i < 2; i++) {
1165
+ try {
1166
+ const r = await fetch('/api/inbox', {
1167
+ method: 'POST', headers: { 'Content-Type': 'application/json' },
1168
+ body: JSON.stringify({
1169
+ text, sessionId: sid, source: 'home', clientKey,
1170
+ autoSend: document.getElementById('note-autosend').checked,
1171
+ images: _notePendingImage ? [{ path: _notePendingImage.path, name: '图片' }] : [],
1172
+ }),
1173
+ });
1174
+ d = await r.json();
1175
+ break;
1176
+ } catch (e) {
1177
+ if (i) throw e;
1178
+ await new Promise((res) => setTimeout(res, 400));
1179
+ }
1180
+ }
1170
1181
  if (d.error) { alert('存草稿失败:' + d.error); return; }
1171
1182
  closeNoteSheet();
1172
1183
  refreshDraftCounts();
1173
1184
  } catch (e) {
1174
- alert('存草稿失败:' + e.message);
1185
+ alert('存草稿失败:' + (e.message === 'Failed to fetch' ? '网络连接中断(重试仍失败)' : e.message));
1175
1186
  }
1176
1187
  };
1177
1188