dsh-question-timeout-protection 0.1.3 → 0.2.0

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/client.js CHANGED
@@ -39,6 +39,22 @@ const QUESTION_CARD_SELECTOR = "[data-question-key]";
39
39
  const QUESTION_CARD_KEY_PREFIX = "question:";
40
40
  /** 宿主提问卡片右上角操作区(类名带构建哈希,按后缀匹配) */
41
41
  const HEADER_ACTIONS_SELECTOR = "[class*=\"_headerActions\"]";
42
+ /** 宿主单选题的自定义回答行(类名带构建哈希, 按后缀匹配) */
43
+ const CUSTOM_ROW_SELECTOR = "[class*=\"_customRow\"]";
44
+ /** 插件自绘「自定义回答」单选按钮的类名 */
45
+ const CUSTOM_RADIO_CLASS = "dqtp-custom-radio";
46
+ /** 插件自绘「已保留自定义内容」提示按钮的类名 */
47
+ const CUSTOM_HINT_CLASS = "dqtp-custom-hint";
48
+ /** 选中自定义回答时挂在卡片上的类名: 用它压掉宿主预设选项的选中底色 */
49
+ const CUSTOM_CHOICE_CLASS = "dqtp-custom-choice";
50
+ /** 单选题自定义回答的输入内容与选中状态在 localStorage 里的键 */
51
+ const CUSTOM_STATE_STORAGE_KEY = "dqtp-custom-choice.v1";
52
+ /** 「自定义回答」单选按钮的文案(中文/英文) */
53
+ const CUSTOM_RADIO_LABEL_ZH = "自定义回答";
54
+ const CUSTOM_RADIO_LABEL_EN = "Custom answer";
55
+ /** 自定义内容已保留但当前未选中时的提示(中文/英文), {text} 替换为内容 */
56
+ const CUSTOM_HINT_ZH = "已保留自定义内容: {text}(点这里选用)";
57
+ const CUSTOM_HINT_EN = "Custom answer kept: {text} (click to use it)";
42
58
  /** 卡片输入框选择器 */
43
59
  const CARD_INPUT_SELECTOR = "textarea, input";
44
60
  /** 卡片内可点击的控件 */
@@ -69,6 +85,12 @@ const COUNTDOWN_PATTERNS = [
69
85
  ];
70
86
  /** 判定宿主是否停在暂停态的文案特征: 暂停态下的剩余秒数不是真实到期时间 */
71
87
  const PAUSED_TEXT_PATTERNS = [/已暂停/, /Paused/];
88
+ /**
89
+ * 宿主「已经停表」的等待文案: 用户点过「慢慢回答」或开始编辑回答后,
90
+ * 宿主自己的定时器已经停下, 卡片只显示这句提示, 不再渲染倒计时与暂停控件。
91
+ * 与 HOST_WAIT_PATTERNS 分开: 后者还含「已继续工作」这类已结算文案。
92
+ */
93
+ const HOST_HELD_PATTERNS = ["会一直等你回答", "Waiting until you answer"];
72
94
  /** 「问答自动无限等待」常开开关的文案(中文与英文): 中文侧带「自动」, 与英文的 Auto 对齐 */
73
95
  const AUTO_INFINITE_LABEL_ZH = "问答自动无限等待";
74
96
  const AUTO_INFINITE_LABEL_EN = "Auto wait indefinitely";
@@ -188,6 +210,10 @@ const DRAFT_PANEL_EMPTY_EN = "No option was selected and no text had been entere
188
210
  const DRAFT_PANEL_UNANSWERED_ZH = "未作答";
189
211
  /** 只读草稿面板里某题没有作答时的提示(英文) */
190
212
  const DRAFT_PANEL_UNANSWERED_EN = "Not answered";
213
+ /** 工具行根节点的状态属性(宿主 ToolRow 的 data-state) */
214
+ const TOOL_ROW_STATE_ATTRIBUTE = "data-state";
215
+ /** 视为提问已被中断的宿主工具行状态: 失败与中止都不再有可作答的卡片 */
216
+ const TOOL_ROW_FAILED_STATES = ["error", "stopped"];
191
217
  // src/locale-core.ts
192
218
  function normalizeLocale(locale) {
193
219
  const raw = locale.trim().toLowerCase().replace(/_/g, "-");
@@ -306,6 +332,46 @@ const CARD_STYLE = `
306
332
  .dqtp-card-locked {
307
333
  cursor: default;
308
334
  }
335
+ .dqtp-custom-radio {
336
+ flex: 0 0 20px;
337
+ width: 20px;
338
+ height: 20px;
339
+ /* 与宿主 .number 标号座对齐: 行内 gap 提供水平间距, 这里只补垂直偏移 */
340
+ margin: 2px 0 0;
341
+ padding: 0;
342
+ border-radius: 50%;
343
+ border: 1px solid var(--dsw-alias-border-secondary, rgba(0, 0, 0, 0.24));
344
+ background: transparent;
345
+ cursor: pointer;
346
+ }
347
+ .dqtp-custom-radio[aria-checked="true"] {
348
+ border-color: var(--dsw-alias-label-primary, #111);
349
+ background: var(--dsw-alias-label-primary, #111);
350
+ box-shadow: inset 0 0 0 3px var(--dsw-alias-bg-primary, #fff);
351
+ }
352
+ /* 选中自定义回答时压掉宿主预设项的选中底色, 避免界面上出现两个"已选" */
353
+ .dqtp-custom-choice[data-question-key] button[role="radio"][aria-checked="true"] > span:first-child {
354
+ background: transparent;
355
+ color: var(--dsw-alias-label-secondary, #666);
356
+ }
357
+ /* 宿主把选中底色加在整行上, 只清标号底色仍会出现两个"已选" */
358
+ .dqtp-custom-choice[data-question-key] [class*="_optionSelected"] {
359
+ background: transparent;
360
+ border-color: var(--dsw-alias-border-secondary, rgba(0, 0, 0, 0.16));
361
+ }
362
+ .dqtp-custom-hint {
363
+ display: block;
364
+ margin: 6px 0 0;
365
+ padding: 0;
366
+ border: 0;
367
+ background: transparent;
368
+ color: var(--dsw-alias-label-secondary, #666);
369
+ font-size: 12px;
370
+ line-height: 18px;
371
+ text-align: left;
372
+ cursor: pointer;
373
+ word-break: break-word;
374
+ }
309
375
  #dqtp-draft-panel {
310
376
  position: fixed;
311
377
  z-index: 2147483000;
@@ -356,7 +422,7 @@ function parseCardKey(key) {
356
422
  if (!key.startsWith("question:")) return void 0;
357
423
  const rest = key.slice(9);
358
424
  const split = rest.indexOf(":");
359
- if (split <= 0) return void 0;
425
+ if (split <= 0 || split + 1 >= rest.length) return void 0;
360
426
  return {
361
427
  sessionId: rest.slice(0, split),
362
428
  callId: rest.slice(split + 1)
@@ -427,14 +493,18 @@ function recommendedOptionLabels(question) {
427
493
  if (question?.multiSelect === true) return marked;
428
494
  return labels.length > 0 && stripRecommendedSuffix(labels[0]) !== labels[0] ? [labels[0]] : [];
429
495
  }
430
- function dropRecommended(selected, question) {
431
- const recommended = new Set(recommendedOptionLabels(question));
432
- return selected.filter((label) => !recommended.has(label));
496
+ function dropPreselected(selected, question) {
497
+ const recommended = recommendedOptionLabels(question);
498
+ if (recommended.length === 0) return [...selected];
499
+ if (selected.length !== recommended.length) return [...selected];
500
+ const expected = new Set(recommended);
501
+ return selected.every((label) => expected.has(label)) ? [] : [...selected];
433
502
  }
434
503
  function readSelected(card, question) {
435
504
  const selected = [];
436
505
  const originals = (question?.options ?? []).map((option) => typeof option.label === "string" ? option.label : "").filter((label) => label !== "");
437
506
  for (const button of Array.from(card.querySelectorAll("button[aria-checked=\"true\"]"))) {
507
+ if (button.classList.contains("dqtp-custom-radio")) continue;
438
508
  const display = (button.getAttribute("aria-label") ?? "").trim();
439
509
  if (display === "") continue;
440
510
  const label = originals.find((original) => stripRecommendedSuffix(original) === display) ?? display;
@@ -712,16 +782,23 @@ function installQuestionTimeoutAdapter(ctx, source) {
712
782
  const draftSyncFailures = /* @__PURE__ */ new Map();
713
783
  const drafts = /* @__PURE__ */ new Map();
714
784
  const lastDrafts = /* @__PURE__ */ new Map();
785
+ const typedCustom = /* @__PURE__ */ new Map();
786
+ const customChoice = /* @__PURE__ */ new Map();
715
787
  const subscriptions = /* @__PURE__ */ new Map();
716
788
  const lockedCards = /* @__PURE__ */ new WeakSet();
717
- const dismissedCallIds = /* @__PURE__ */ new Set();
789
+ const dismissFailures = /* @__PURE__ */ new WeakMap();
790
+ const dismissAttemptedAt = /* @__PURE__ */ new WeakMap();
791
+ const dismissFailedWarned = /* @__PURE__ */ new Set();
718
792
  const deferred = /* @__PURE__ */ new Map();
719
793
  const projectedCounts = /* @__PURE__ */ new Map();
720
794
  const projectedQuestions = /* @__PURE__ */ new Map();
721
795
  const optionInteractions = /* @__PURE__ */ new Map();
722
796
  const callActive = /* @__PURE__ */ new Set();
797
+ const seenLive = /* @__PURE__ */ new Set();
723
798
  const callTouchedAt = /* @__PURE__ */ new Map();
724
799
  const draftTooLarge = /* @__PURE__ */ new Set();
800
+ const badCallIdWarned = /* @__PURE__ */ new Set();
801
+ const interrupted = /* @__PURE__ */ new Set();
725
802
  const draftTooLargeAt = /* @__PURE__ */ new Map();
726
803
  const callSessions = /* @__PURE__ */ new Map();
727
804
  const readLiveSelected = (card, callId) => {
@@ -729,17 +806,211 @@ function installQuestionTimeoutAdapter(ctx, source) {
729
806
  const question = projectedQuestions.get(callId)?.[index];
730
807
  const selected = readSelected(card, question);
731
808
  if (optionInteractions.get(callId)?.has(index) === true) return selected;
732
- return dropRecommended(selected, question);
809
+ return dropPreselected(selected, question);
733
810
  };
734
811
  const gateDraftSelections = (items, callId) => {
735
812
  if (items === void 0) return void 0;
736
813
  const touched = optionInteractions.get(callId);
737
814
  return items.map((item, index) => touched?.has(index) === true ? item : {
738
- selected: dropRecommended(item.selected, projectedQuestions.get(callId)?.[index]),
815
+ selected: dropPreselected(item.selected, projectedQuestions.get(callId)?.[index]),
739
816
  custom: item.custom,
740
817
  skipped: item.skipped
741
818
  });
742
819
  };
820
+ const rememberTypedCustom = (callId, index, text) => {
821
+ let entries = typedCustom.get(callId);
822
+ if (text === "") {
823
+ if (entries === void 0) return;
824
+ entries.delete(index);
825
+ if (entries.size === 0) typedCustom.delete(callId);
826
+ saveCustomState();
827
+ return;
828
+ }
829
+ if (entries === void 0) {
830
+ entries = /* @__PURE__ */ new Map();
831
+ typedCustom.set(callId, entries);
832
+ }
833
+ entries.set(index, text);
834
+ saveCustomState();
835
+ };
836
+ const typedCustomAt = (callId, index) => typedCustom.get(callId)?.get(index);
837
+ const setCustomChoice = (callId, index, custom) => {
838
+ let entries = customChoice.get(callId);
839
+ if (entries === void 0) {
840
+ entries = /* @__PURE__ */ new Map();
841
+ customChoice.set(callId, entries);
842
+ }
843
+ entries.set(index, custom);
844
+ saveCustomState();
845
+ };
846
+ const clearCustomState = (callId) => {
847
+ typedCustom.delete(callId);
848
+ customChoice.delete(callId);
849
+ saveCustomState();
850
+ };
851
+ const loadCustomState = () => {
852
+ try {
853
+ const raw = window.localStorage.getItem(CUSTOM_STATE_STORAGE_KEY);
854
+ if (raw === null) return;
855
+ const parsed = JSON.parse(raw);
856
+ if (parsed === null || typeof parsed !== "object") return;
857
+ for (const [callId, entry] of Object.entries(parsed)) {
858
+ if (entry === null || typeof entry !== "object") continue;
859
+ if (entry.text !== void 0 && entry.text !== null) {
860
+ const map = /* @__PURE__ */ new Map();
861
+ for (const [key, value] of Object.entries(entry.text)) {
862
+ const index = Number(key);
863
+ if (Number.isInteger(index) && index >= 0 && typeof value === "string" && value !== "") map.set(index, value);
864
+ }
865
+ if (map.size > 0) typedCustom.set(callId, map);
866
+ }
867
+ if (entry.choice !== void 0 && entry.choice !== null) {
868
+ const map = /* @__PURE__ */ new Map();
869
+ for (const [key, value] of Object.entries(entry.choice)) {
870
+ const index = Number(key);
871
+ if (Number.isInteger(index) && index >= 0 && typeof value === "boolean") map.set(index, value);
872
+ }
873
+ if (map.size > 0) customChoice.set(callId, map);
874
+ }
875
+ }
876
+ } catch {}
877
+ };
878
+ const saveCustomState = () => {
879
+ try {
880
+ const out = {};
881
+ const ids = /* @__PURE__ */ new Set([...typedCustom.keys(), ...customChoice.keys()]);
882
+ let kept = 0;
883
+ for (const callId of ids) {
884
+ if (kept >= 64) break;
885
+ kept += 1;
886
+ const text = {};
887
+ for (const [index, value] of typedCustom.get(callId) ?? []) text[String(index)] = value;
888
+ const choice = {};
889
+ for (const [index, value] of customChoice.get(callId) ?? []) choice[String(index)] = value;
890
+ out[callId] = {
891
+ text,
892
+ choice
893
+ };
894
+ }
895
+ window.localStorage.setItem(CUSTOM_STATE_STORAGE_KEY, JSON.stringify(out));
896
+ } catch {}
897
+ };
898
+ loadCustomState();
899
+ const resolveCustomChoice = (callId, index, card) => {
900
+ const explicit = customChoice.get(callId)?.get(index);
901
+ if (explicit !== void 0) return explicit ? "custom" : "option";
902
+ if (card === void 0) return "option";
903
+ const question = projectedQuestions.get(callId)?.[index];
904
+ const selected = readSelected(card, question);
905
+ const custom = readCustom(card);
906
+ return selected.length === 0 && custom.trim() !== "" ? "custom" : "option";
907
+ };
908
+ const applyCustomChoice = (items, callId) => {
909
+ const choices = customChoice.get(callId);
910
+ const typed = typedCustom.get(callId);
911
+ if (choices === void 0 && typed === void 0) return items;
912
+ return items.map((item, index) => {
913
+ const question = projectedQuestions.get(callId)?.[index];
914
+ if (question?.multiSelect === true) return item;
915
+ const explicit = choices?.get(index);
916
+ if (explicit === void 0 && question === void 0) return item;
917
+ if (item.skipped) return {
918
+ ...item,
919
+ custom: ""
920
+ };
921
+ const typedText = typed?.get(index);
922
+ if (explicit ?? (item.selected.length === 0 && (typedText ?? item.custom).trim() !== "")) return {
923
+ ...item,
924
+ selected: [],
925
+ custom: typedText ?? item.custom
926
+ };
927
+ return {
928
+ ...item,
929
+ custom: ""
930
+ };
931
+ });
932
+ };
933
+ const writeField = (field, value) => {
934
+ const prototype = field instanceof HTMLTextAreaElement ? HTMLTextAreaElement.prototype : HTMLInputElement.prototype;
935
+ const setter = Object.getOwnPropertyDescriptor(prototype, "value")?.set;
936
+ if (setter === void 0) field.value = value;
937
+ else setter.call(field, value);
938
+ field.dispatchEvent(new Event("input", { bubbles: true }));
939
+ };
940
+ const writeFieldWithChange = (field, value) => {
941
+ const sentinel = field.value === " " ? "" : " ";
942
+ writeField(field, sentinel);
943
+ writeField(field, value);
944
+ };
945
+ const hostHasCheckedOption = (card) => Array.from(card.querySelectorAll("button[role=\"radio\"][aria-checked=\"true\"]")).some((button) => !button.classList.contains(CUSTOM_RADIO_CLASS));
946
+ const customFieldOf = (card) => {
947
+ const row = card.querySelector(CUSTOM_ROW_SELECTOR);
948
+ if (!(row instanceof HTMLElement)) return void 0;
949
+ const field = row.querySelector(CARD_INPUT_SELECTOR);
950
+ return field instanceof HTMLTextAreaElement || field instanceof HTMLInputElement ? field : void 0;
951
+ };
952
+ const isReadOnlyCard = (card) => {
953
+ const fields = Array.from(card.querySelectorAll(CARD_INPUT_SELECTOR));
954
+ return fields.length > 0 && fields.every((field) => field.disabled);
955
+ };
956
+ const removeCustomChoiceUI = (card) => {
957
+ const row = card.querySelector(CUSTOM_ROW_SELECTOR);
958
+ for (const element of Array.from(card.querySelectorAll("button.dqtp-custom-radio, button.dqtp-custom-hint"))) element.remove();
959
+ if (row instanceof HTMLElement) {
960
+ for (const marker of Array.from(row.querySelectorAll("span[aria-hidden=\"true\"]"))) if (marker instanceof HTMLElement) marker.classList.remove(HIDDEN_CONTROL_CLASS);
961
+ }
962
+ card.classList.remove(CUSTOM_CHOICE_CLASS);
963
+ };
964
+ const ensureCustomChoiceUI = (card, identity) => {
965
+ if (!(options().cardEnhancements !== false && !card.classList.contains("dqtp-card-locked") && card.querySelector("[role=\"radiogroup\"]") !== null && card.querySelector("[class*=\"_customRow\"]") instanceof HTMLElement && !passive.has(identity.callId) && !isReadOnlyCard(card))) {
966
+ removeCustomChoiceUI(card);
967
+ return;
968
+ }
969
+ const row = card.querySelector(CUSTOM_ROW_SELECTOR);
970
+ const field = customFieldOf(card);
971
+ if (!(row instanceof HTMLElement) || field === void 0) {
972
+ removeCustomChoiceUI(card);
973
+ return;
974
+ }
975
+ let radio = row.querySelector("button.dqtp-custom-radio");
976
+ if (!(radio instanceof HTMLButtonElement)) {
977
+ radio = document.createElement("button");
978
+ radio.type = "button";
979
+ radio.className = CUSTOM_RADIO_CLASS;
980
+ radio.setAttribute("role", "radio");
981
+ const anchor = field.parentElement !== null && field.parentElement !== row ? field.parentElement : field;
982
+ if (anchor.parentElement === row) row.insertBefore(radio, anchor);
983
+ else row.appendChild(radio);
984
+ }
985
+ for (const marker of Array.from(row.querySelectorAll("span[aria-hidden=\"true\"]"))) if (marker instanceof HTMLElement) marker.classList.add(HIDDEN_CONTROL_CLASS);
986
+ const index = readProgress(card)?.index ?? 0;
987
+ const mode = resolveCustomChoice(identity.callId, index, card);
988
+ radio.setAttribute("aria-checked", mode === "custom" ? "true" : "false");
989
+ const label = pick(CUSTOM_RADIO_LABEL_ZH, CUSTOM_RADIO_LABEL_EN);
990
+ if (radio.title !== label) radio.title = label;
991
+ if (radio.getAttribute("aria-label") !== label) radio.setAttribute("aria-label", label);
992
+ card.classList.toggle(CUSTOM_CHOICE_CLASS, mode === "custom");
993
+ const typed = typedCustomAt(identity.callId, index);
994
+ const showHint = mode === "option" && typed !== void 0 && typed.trim() !== "";
995
+ let hint = null;
996
+ const sibling = row.nextElementSibling;
997
+ if (sibling instanceof HTMLButtonElement && sibling.classList.contains("dqtp-custom-hint")) hint = sibling;
998
+ if (!showHint) {
999
+ if (hint !== null) hint.remove();
1000
+ return;
1001
+ }
1002
+ if (!(hint instanceof HTMLButtonElement)) {
1003
+ hint = document.createElement("button");
1004
+ hint.type = "button";
1005
+ hint.className = CUSTOM_HINT_CLASS;
1006
+ row.insertAdjacentElement("afterend", hint);
1007
+ }
1008
+ const customText = typed ?? "";
1009
+ const customShown = customText.length > 80 ? customText.slice(0, 80) + "…" : customText;
1010
+ const text = pick(CUSTOM_HINT_ZH, CUSTOM_HINT_EN).replace("{text}", () => customShown);
1011
+ if (hint.textContent !== text) hint.textContent = text;
1012
+ if (hint.title !== customText) hint.title = customText;
1013
+ };
743
1014
  const rememberCallSession = (identity) => {
744
1015
  callTouchedAt.set(identity.callId, Date.now());
745
1016
  if (callSessions.get(identity.callId) === identity.sessionId) return;
@@ -765,8 +1036,11 @@ function installQuestionTimeoutAdapter(ctx, source) {
765
1036
  for (const id of draftSyncFailures.keys()) ids.add(id);
766
1037
  for (const id of draftTooLarge.keys()) ids.add(id);
767
1038
  for (const id of draftTooLargeAt.keys()) ids.add(id);
768
- for (const id of dismissedCallIds.keys()) ids.add(id);
1039
+ for (const id of interrupted.keys()) ids.add(id);
1040
+ for (const id of badCallIdWarned.keys()) ids.add(id);
769
1041
  for (const id of optionInteractions.keys()) ids.add(id);
1042
+ for (const id of typedCustom.keys()) ids.add(id);
1043
+ for (const id of customChoice.keys()) ids.add(id);
770
1044
  return [...ids];
771
1045
  };
772
1046
  const forgetCall = (callId) => {
@@ -787,11 +1061,14 @@ function installQuestionTimeoutAdapter(ctx, source) {
787
1061
  projectedQuestions.delete(callId);
788
1062
  optionInteractions.delete(callId);
789
1063
  callActive.delete(callId);
1064
+ seenLive.delete(callId);
790
1065
  callTouchedAt.delete(callId);
791
1066
  draftTooLarge.delete(callId);
792
1067
  draftTooLargeAt.delete(callId);
793
- dismissedCallIds.delete(callId);
794
- lastDrafts.delete(callId);
1068
+ dismissFailedWarned.delete(callId);
1069
+ interrupted.delete(callId);
1070
+ badCallIdWarned.delete(callId);
1071
+ clearCustomState(callId);
795
1072
  };
796
1073
  const pruneCallStates = () => {
797
1074
  const now = Date.now();
@@ -810,6 +1087,11 @@ function installQuestionTimeoutAdapter(ctx, source) {
810
1087
  if (oldestId === void 0) break;
811
1088
  forgetCall(oldestId);
812
1089
  }
1090
+ for (const warned of [subscribeWarned, evaluateWarned]) while (warned.size > 64) {
1091
+ const oldest = warned.keys().next();
1092
+ if (oldest.done) break;
1093
+ warned.delete(oldest.value);
1094
+ }
813
1095
  };
814
1096
  const pruneDrafts = () => {
815
1097
  while (drafts.size > 200) {
@@ -1002,28 +1284,61 @@ function installQuestionTimeoutAdapter(ctx, source) {
1002
1284
  if (SUBMIT_TEXTS.includes(text) || NEXT_QUESTION_TEXTS.includes(text) || SKIP_QUESTION_TEXTS.includes(text)) disableControl(button);
1003
1285
  }
1004
1286
  };
1287
+ const dismissCard = (card) => {
1288
+ for (const button of Array.from(card.querySelectorAll(CARD_BUTTON_SELECTOR))) {
1289
+ const label = (button.getAttribute("aria-label") ?? button.getAttribute("title") ?? "").trim();
1290
+ if (!CLOSE_PANEL_LABELS.includes(label)) continue;
1291
+ if (button instanceof HTMLButtonElement && button.disabled) return false;
1292
+ button.click();
1293
+ return true;
1294
+ }
1295
+ return false;
1296
+ };
1297
+ const handBackCard = (card) => {
1298
+ card.classList.remove(HIDDEN_CONTROL_CLASS);
1299
+ card.removeAttribute(CARD_DISMISSED_ATTRIBUTE);
1300
+ const identity = parseCardKey(card.getAttribute("data-question-key"));
1301
+ if (identity === void 0) return;
1302
+ passive.add(identity.callId);
1303
+ timedOut.delete(identity.callId);
1304
+ drafts.delete(identity.callId);
1305
+ restoreCard(card);
1306
+ if (dismissFailedWarned.has(identity.callId)) return;
1307
+ dismissFailedWarned.add(identity.callId);
1308
+ console.warn("[question-timeout-protection] 无法让宿主收起问答卡片, 这一轮改由宿主原版处理, 卡片保持可作答");
1309
+ };
1005
1310
  const hideCard = (card) => {
1006
1311
  const key = card.getAttribute("data-question-key") ?? "";
1007
- const callId = parseCardKey(key)?.callId ?? key;
1008
- const marked = card.getAttribute(CARD_DISMISSED_ATTRIBUTE) === key;
1009
- if (!marked) card.setAttribute(CARD_DISMISSED_ATTRIBUTE, key);
1010
- if (!marked && !dismissedCallIds.has(callId)) {
1011
- dismissedCallIds.add(callId);
1012
- for (const button of Array.from(card.querySelectorAll(CARD_BUTTON_SELECTOR))) {
1013
- const label = (button.getAttribute("aria-label") ?? button.getAttribute("title") ?? "").trim();
1014
- if (!CLOSE_PANEL_LABELS.includes(label)) continue;
1015
- button.click();
1016
- break;
1017
- }
1312
+ if (Date.now() - (dismissAttemptedAt.get(card) ?? 0) < 500) return;
1313
+ let failures = dismissFailures.get(card) ?? 0;
1314
+ if (card.getAttribute(CARD_DISMISSED_ATTRIBUTE) === key) {
1315
+ card.removeAttribute(CARD_DISMISSED_ATTRIBUTE);
1316
+ card.classList.remove(HIDDEN_CONTROL_CLASS);
1317
+ failures += 1;
1318
+ }
1319
+ dismissAttemptedAt.set(card, Date.now());
1320
+ if (failures >= 5) {
1321
+ dismissFailures.set(card, failures);
1322
+ handBackCard(card);
1323
+ return;
1324
+ }
1325
+ if (dismissCard(card)) {
1326
+ dismissFailures.set(card, failures);
1327
+ card.setAttribute(CARD_DISMISSED_ATTRIBUTE, key);
1328
+ card.classList.add(HIDDEN_CONTROL_CLASS);
1329
+ return;
1018
1330
  }
1019
- card.classList.add(HIDDEN_CONTROL_CLASS);
1331
+ dismissFailures.set(card, failures + 1);
1020
1332
  };
1021
1333
  const restoreCard = (card) => {
1022
- if (card.getAttribute(CARD_DISMISSED_ATTRIBUTE) !== null) return;
1334
+ const markedKey = card.getAttribute(CARD_DISMISSED_ATTRIBUTE);
1335
+ if (markedKey !== null && markedKey === (card.getAttribute("data-question-key") ?? "")) return;
1336
+ if (markedKey !== null) card.removeAttribute(CARD_DISMISSED_ATTRIBUTE);
1023
1337
  card.classList.remove(HIDDEN_CONTROL_CLASS);
1024
1338
  for (const element of Array.from(card.querySelectorAll("." + HIDDEN_CONTROL_CLASS))) element.classList.remove(HIDDEN_CONTROL_CLASS);
1025
1339
  for (const element of Array.from(card.querySelectorAll("[data-dqtp-host-wait]"))) element.removeAttribute(HIDDEN_WAIT_ATTRIBUTE);
1026
1340
  for (const element of Array.from(card.querySelectorAll("[data-dqtp-countdown], button.dqtp-infinite-wait"))) element.remove();
1341
+ removeCustomChoiceUI(card);
1027
1342
  restoreDisabled(card);
1028
1343
  card.classList.remove(CARD_LOCKED_CLASS);
1029
1344
  lockedCards.delete(card);
@@ -1137,15 +1452,24 @@ function installQuestionTimeoutAdapter(ctx, source) {
1137
1452
  hideCard(card);
1138
1453
  }
1139
1454
  };
1455
+ const hostTimerStopped = (card) => {
1456
+ for (const element of Array.from(card.querySelectorAll(WAIT_STATUS_SELECTOR))) {
1457
+ const text = (element.textContent ?? "").trim();
1458
+ if (text === "") continue;
1459
+ if (HOST_HELD_PATTERNS.some((pattern) => text.includes(pattern))) return true;
1460
+ }
1461
+ return false;
1462
+ };
1140
1463
  const clickHostTakeTime = (identity) => {
1141
1464
  const card = findCard(identity);
1142
- if (card === void 0) return false;
1465
+ if (card === void 0) return "missing";
1143
1466
  for (const element of Array.from(card.querySelectorAll(CARD_BUTTON_SELECTOR))) {
1144
1467
  if (!TAKE_TIME_TEXTS.includes(element.textContent?.trim() ?? "")) continue;
1468
+ if (element instanceof HTMLButtonElement && element.disabled) continue;
1145
1469
  element.click();
1146
- return true;
1470
+ return "clicked";
1147
1471
  }
1148
- return false;
1472
+ return hostTimerStopped(card) ? "already-stopped" : "missing";
1149
1473
  };
1150
1474
  const pauseCountdown = (card, identity) => {
1151
1475
  if (paused.has(identity.callId)) return;
@@ -1156,7 +1480,7 @@ function installQuestionTimeoutAdapter(ctx, source) {
1156
1480
  if (disposed) return;
1157
1481
  if (reply.ok) {
1158
1482
  if (timedOut.has(identity.callId)) return;
1159
- if (clickHostTakeTime(identity)) return;
1483
+ if (clickHostTakeTime(identity) !== "missing") return;
1160
1484
  paused.delete(identity.callId);
1161
1485
  syncUnavailable.add(identity.callId);
1162
1486
  reportInfiniteWait(identity, void 0, false);
@@ -1172,6 +1496,16 @@ function installQuestionTimeoutAdapter(ctx, source) {
1172
1496
  if (current !== void 0) decorateCard(current, identity);
1173
1497
  return;
1174
1498
  }
1499
+ if (reply.reason === "bad-call-id") {
1500
+ paused.delete(identity.callId);
1501
+ if (!badCallIdWarned.has(identity.callId)) {
1502
+ badCallIdWarned.add(identity.callId);
1503
+ console.warn("[question-timeout-protection] 调用标识不符合通道格式, 「无限等待」无法登记");
1504
+ }
1505
+ const badIdCard = findCard(identity);
1506
+ if (badIdCard !== void 0) decorateCard(badIdCard, identity);
1507
+ return;
1508
+ }
1175
1509
  paused.delete(identity.callId);
1176
1510
  syncUnavailable.add(identity.callId);
1177
1511
  console.warn("[question-timeout-protection] 「无限等待」状态上报失败, 本次问答改由宿主原版处理");
@@ -1246,9 +1580,11 @@ function installQuestionTimeoutAdapter(ctx, source) {
1246
1580
  note.textContent = pick(DRAFT_PANEL_NOTE_ZH, DRAFT_PANEL_NOTE_EN);
1247
1581
  const body = document.createElement("div");
1248
1582
  body.className = "dqtp-draft-body";
1249
- const blocks = draft.questions.map((question, index) => {
1583
+ const blockCount = Math.max(draft.questions.length, draft.items.length);
1584
+ const blocks = Array.from({ length: blockCount }, (_, index) => {
1585
+ const question = draft.questions[index];
1250
1586
  const item = draft.items[index] ?? emptyItem();
1251
- const heading = (question.header ?? question.question ?? "").trim();
1587
+ const heading = (question?.header ?? question?.question ?? "").trim();
1252
1588
  const content = hasItemContent(item) ? composeItem(item) : pick(DRAFT_PANEL_UNANSWERED_ZH, DRAFT_PANEL_UNANSWERED_EN);
1253
1589
  return (heading === "" ? "" : heading + "\n") + content;
1254
1590
  });
@@ -1307,13 +1643,36 @@ function installQuestionTimeoutAdapter(ctx, source) {
1307
1643
  }
1308
1644
  };
1309
1645
  const decoratedRows = /* @__PURE__ */ new WeakMap();
1646
+ const failedRowState = (row) => {
1647
+ const state = row.getAttribute(TOOL_ROW_STATE_ATTRIBUTE);
1648
+ return state !== null && TOOL_ROW_FAILED_STATES.includes(state);
1649
+ };
1650
+ const promoteInterruptedDraft = (row, callId) => {
1651
+ if (timedOut.has(callId) || passive.has(callId)) return;
1652
+ const items = lastDrafts.get(callId);
1653
+ if (items === void 0 || !items.some(hasItemContent)) return;
1654
+ if (!drafts.has(callId)) {
1655
+ const container = row.closest(SESSION_CONTAINER_SELECTOR);
1656
+ const sessionId = container instanceof HTMLElement ? container.getAttribute("data-conversation-session") ?? void 0 : callSessionOf(callId);
1657
+ if (sessionId === void 0 || sessionId === "") return;
1658
+ drafts.set(callId, {
1659
+ sessionId,
1660
+ callId,
1661
+ questions: projectedQuestions.get(callId) ?? [],
1662
+ items
1663
+ });
1664
+ pruneDrafts();
1665
+ }
1666
+ interrupted.add(callId);
1667
+ };
1310
1668
  const decorateRow = (row) => {
1311
1669
  const callId = resolveCallId(row);
1312
1670
  if (callId === void 0) return;
1313
- const plain = !timedOut.has(callId) && !passive.has(callId) && !drafts.has(callId);
1314
- const signature = callId + (row.querySelector("button.dqtp-question-bubble") !== null ? "1" : "0") + (timedOut.has(callId) ? "T" : "-") + (passive.has(callId) ? "P" : "-");
1671
+ if (failedRowState(row)) promoteInterruptedDraft(row, callId);
1672
+ const plain = !timedOut.has(callId) && !passive.has(callId) && !interrupted.has(callId) && !drafts.has(callId);
1673
+ const signature = callId + (row.querySelector("button.dqtp-question-bubble") !== null ? "1" : "0") + (timedOut.has(callId) ? "T" : "-") + (passive.has(callId) ? "P" : "-") + (interrupted.has(callId) ? "I" : "-");
1315
1674
  if (plain && decoratedRows.get(row) === signature) return;
1316
- if (!timedOut.has(callId)) {
1675
+ if (!timedOut.has(callId) && !interrupted.has(callId)) {
1317
1676
  showHostReopen(row);
1318
1677
  showHostWaitText(row);
1319
1678
  }
@@ -1338,7 +1697,7 @@ function installQuestionTimeoutAdapter(ctx, source) {
1338
1697
  const label = pick(BUBBLE_DRAFT_LABEL_ZH, BUBBLE_DRAFT_LABEL_EN);
1339
1698
  if (button.textContent !== label) button.textContent = label;
1340
1699
  if (button.getAttribute("data-dqtp-bubble") !== "draft") button.setAttribute(BUBBLE_STATE_ATTRIBUTE, BUBBLE_STATE_DRAFT);
1341
- if (timedOut.has(callId)) {
1700
+ if (timedOut.has(callId) || interrupted.has(callId)) {
1342
1701
  hideHostReopen(row);
1343
1702
  hideHostWaitText(row);
1344
1703
  }
@@ -1373,12 +1732,13 @@ function installQuestionTimeoutAdapter(ctx, source) {
1373
1732
  draftTooLargeAt.delete(identity.callId);
1374
1733
  }
1375
1734
  if (timedOut.has(identity.callId) || passive.has(identity.callId)) return;
1376
- if (!callActive.has(identity.callId) && !hostStillWaiting(card)) return;
1735
+ const waitingByStatus = !card.classList.contains("dqtp-card-locked") && Array.from(card.querySelectorAll("[class*=\"_waitStatus\"]")).some((element) => (element.textContent ?? "").trim() !== "");
1736
+ if (!callActive.has(identity.callId) && !hostStillWaiting(card) && !waitingByStatus) return;
1377
1737
  rememberCallSession(identity);
1378
1738
  const progress = readProgress(card);
1379
1739
  const projected = projectedCounts.get(identity.callId) ?? 1;
1380
1740
  const count = Math.max(progress?.count ?? 1, projected);
1381
- const items = mergeDrafts(gateDraftSelections(readHostDrafts(identity, count), identity.callId), readLiveDrafts(card, count, readLiveSelected(card, identity.callId)), lastDrafts.get(identity.callId), count, progress?.index);
1741
+ const items = applyCustomChoice(mergeDrafts(gateDraftSelections(readHostDrafts(identity, count), identity.callId), readLiveDrafts(card, count, readLiveSelected(card, identity.callId)), lastDrafts.get(identity.callId), count, progress?.index), identity.callId);
1382
1742
  const last = draftReportedAt.get(identity.callId);
1383
1743
  const now = Date.now();
1384
1744
  if (last !== void 0 && now - last < DRAFT_REPORT_INTERVAL_MS) return;
@@ -1410,6 +1770,16 @@ function installQuestionTimeoutAdapter(ctx, source) {
1410
1770
  return;
1411
1771
  }
1412
1772
  if (settled) return;
1773
+ if (reply.reason === "bad-call-id") {
1774
+ if (!badCallIdWarned.has(callId)) {
1775
+ badCallIdWarned.add(callId);
1776
+ console.warn("[question-timeout-protection] 调用标识不符合通道格式, 这一轮的草稿无法送达");
1777
+ }
1778
+ syncUnavailable.add(callId);
1779
+ const badIdCard = findCard(identity);
1780
+ if (badIdCard !== void 0) decorateCard(badIdCard, identity);
1781
+ return;
1782
+ }
1413
1783
  if (reply.reason === "too-large") {
1414
1784
  draftTooLargeAt.set(identity.callId, Date.now());
1415
1785
  if (!draftTooLarge.has(identity.callId)) {
@@ -1441,9 +1811,10 @@ function installQuestionTimeoutAdapter(ctx, source) {
1441
1811
  }
1442
1812
  handled.add(row.callId);
1443
1813
  deferred.delete(row.callId);
1444
- const count = row.questions.length;
1445
- const liveIndex = card === void 0 ? void 0 : readProgress(card)?.index;
1446
- const items = mergeDrafts(gateDraftSelections(readHostDrafts(identity, count), identity.callId), readLiveDrafts(card, count, card === void 0 ? [] : readLiveSelected(card, row.callId)), stored, count, liveIndex);
1814
+ const progress = card === void 0 ? void 0 : readProgress(card);
1815
+ const count = Math.max(progress?.count ?? 1, projectedCounts.get(row.callId) ?? 1, row.questions.length);
1816
+ const liveIndex = progress?.index;
1817
+ const items = applyCustomChoice(mergeDrafts(gateDraftSelections(readHostDrafts(identity, count), identity.callId), readLiveDrafts(card, count, card === void 0 ? [] : readLiveSelected(card, row.callId)), stored, count, liveIndex), row.callId);
1447
1818
  lastDrafts.set(row.callId, items);
1448
1819
  const current = options();
1449
1820
  if (!(current.draftFallback && !syncUnavailable.has(row.callId) && !draftSyncFailed.has(row.callId) && items.some(hasItemContent))) {
@@ -1487,6 +1858,7 @@ function installQuestionTimeoutAdapter(ctx, source) {
1487
1858
  for (const row of active) {
1488
1859
  if (typeof row.callId !== "string") continue;
1489
1860
  live.add(row.callId);
1861
+ seenLive.add(row.callId);
1490
1862
  callActive.add(row.callId);
1491
1863
  callTouchedAt.set(row.callId, Date.now());
1492
1864
  if (!Array.isArray(row.questions)) continue;
@@ -1501,6 +1873,7 @@ function installQuestionTimeoutAdapter(ctx, source) {
1501
1873
  for (const callId of knownCallIds()) {
1502
1874
  if (live.has(callId)) continue;
1503
1875
  if (callSessionOf(callId) !== sessionId) continue;
1876
+ if (!seenLive.has(callId)) continue;
1504
1877
  forgetCall(callId);
1505
1878
  }
1506
1879
  };
@@ -1529,10 +1902,8 @@ function installQuestionTimeoutAdapter(ctx, source) {
1529
1902
  };
1530
1903
  const ensureSubscription = (sessionId) => {
1531
1904
  if (subscriptions.has(sessionId)) return;
1532
- if (polledSessions.has(sessionId)) {
1533
- if (subscriptions.size >= 8) return;
1534
- polledSessions.delete(sessionId);
1535
- }
1905
+ const wasPolled = polledSessions.has(sessionId);
1906
+ if (wasPolled && subscriptions.size >= 8) return;
1536
1907
  const face = resolveProjectionFace(ctx, sessionId);
1537
1908
  if (face === void 0) {
1538
1909
  if (!subscribeWarned.has(sessionId)) {
@@ -1541,6 +1912,7 @@ function installQuestionTimeoutAdapter(ctx, source) {
1541
1912
  }
1542
1913
  return;
1543
1914
  }
1915
+ if (wasPolled) polledSessions.delete(sessionId);
1544
1916
  const evaluate = () => {
1545
1917
  if (disposed) return;
1546
1918
  try {
@@ -1602,7 +1974,7 @@ function installQuestionTimeoutAdapter(ctx, source) {
1602
1974
  const target = event.target;
1603
1975
  if (!(target instanceof Element)) return;
1604
1976
  const option = target.closest("button[role=\"radio\"], button[role=\"checkbox\"]");
1605
- if (option instanceof HTMLElement) {
1977
+ if (option instanceof HTMLElement && !option.classList.contains("dqtp-custom-radio")) {
1606
1978
  const card = option.closest(QUESTION_CARD_SELECTOR);
1607
1979
  if (card instanceof HTMLElement) {
1608
1980
  const identity = parseCardKey(card.getAttribute("data-question-key"));
@@ -1612,11 +1984,35 @@ function installQuestionTimeoutAdapter(ctx, source) {
1612
1984
  const touched = optionInteractions.get(identity.callId) ?? /* @__PURE__ */ new Set();
1613
1985
  touched.add(index);
1614
1986
  optionInteractions.set(identity.callId, touched);
1987
+ if (card.querySelector("[role=\"group\"]") === null) {
1988
+ setCustomChoice(identity.callId, index, false);
1989
+ ensureCustomChoiceUI(card, identity);
1990
+ }
1615
1991
  }
1616
1992
  }
1617
1993
  }
1618
1994
  const button = target.closest(CARD_BUTTON_SELECTOR);
1619
1995
  if (!(button instanceof HTMLElement)) return;
1996
+ if (button.classList.contains("dqtp-custom-radio") || button.classList.contains("dqtp-custom-hint")) {
1997
+ event.preventDefault();
1998
+ event.stopPropagation();
1999
+ const card = button.closest(QUESTION_CARD_SELECTOR);
2000
+ const identity = parseCardKey(card instanceof HTMLElement ? card.getAttribute("data-question-key") : null);
2001
+ if (!(card instanceof HTMLElement) || identity === void 0) return;
2002
+ const index = readProgress(card)?.index ?? 0;
2003
+ setCustomChoice(identity.callId, index, true);
2004
+ rememberCallSession(identity);
2005
+ const field = customFieldOf(card);
2006
+ if (field !== void 0) {
2007
+ const intended = typedCustomAt(identity.callId, index) ?? field.value;
2008
+ if (intended !== "") rememberTypedCustom(identity.callId, index, intended);
2009
+ writeFieldWithChange(field, intended);
2010
+ if (hostHasCheckedOption(card)) writeFieldWithChange(field, intended);
2011
+ }
2012
+ ensureCustomChoiceUI(card, identity);
2013
+ field?.focus();
2014
+ return;
2015
+ }
1620
2016
  if (button.classList.contains("dqtp-auto-infinite")) {
1621
2017
  event.preventDefault();
1622
2018
  event.stopPropagation();
@@ -1652,6 +2048,7 @@ function installQuestionTimeoutAdapter(ctx, source) {
1652
2048
  paused.delete(identity.callId);
1653
2049
  deadlines.delete(identity.callId);
1654
2050
  lastDrafts.delete(identity.callId);
2051
+ clearCustomState(identity.callId);
1655
2052
  };
1656
2053
  document.addEventListener("click", onDocumentClick, true);
1657
2054
  const visibleSessionIds = (containers) => {
@@ -1677,15 +2074,28 @@ function installQuestionTimeoutAdapter(ctx, source) {
1677
2074
  subscriptionMissing.delete(sessionId);
1678
2075
  continue;
1679
2076
  }
1680
- const misses = (subscriptionMissing.get(sessionId) ?? 0) + 1;
1681
- if (misses < 600) {
1682
- subscriptionMissing.set(sessionId, misses);
2077
+ const missingSince = subscriptionMissing.get(sessionId);
2078
+ if (missingSince === void 0) {
2079
+ subscriptionMissing.set(sessionId, Date.now());
1683
2080
  continue;
1684
2081
  }
2082
+ if (Date.now() - missingSince < 6e5) continue;
1685
2083
  off();
1686
2084
  subscriptions.delete(sessionId);
1687
2085
  subscriptionMissing.delete(sessionId);
1688
- subscriptionSeen.delete(sessionId);
2086
+ polledSessions.set(sessionId, () => {
2087
+ try {
2088
+ const face = resolveProjectionFace(ctx, sessionId);
2089
+ if (face === void 0) return;
2090
+ evaluateProjection(sessionId, face.getSnapshot?.());
2091
+ } catch (error) {
2092
+ if (evaluateWarned.has(sessionId)) return;
2093
+ evaluateWarned.add(sessionId);
2094
+ console.warn("[question-timeout-protection] 评估提问投影时出错, 该会话的兜底可能受影响", error);
2095
+ }
2096
+ });
2097
+ subscriptionSeen.set(sessionId, Date.now());
2098
+ enforcePolledLimit();
1689
2099
  subscribeWarned.delete(sessionId);
1690
2100
  evaluateWarned.delete(sessionId);
1691
2101
  }
@@ -1702,11 +2112,13 @@ function installQuestionTimeoutAdapter(ctx, source) {
1702
2112
  }
1703
2113
  subscriptionSeen.set(identity.sessionId, Date.now());
1704
2114
  ensureSubscription(identity.sessionId);
2115
+ if (enhancementOn && !passive.has(identity.callId) && (callActive.has(identity.callId) || hostStillWaiting(element))) ensureCustomChoiceUI(element, identity);
2116
+ else removeCustomChoiceUI(element);
1705
2117
  if (enhancementOn && (callActive.has(identity.callId) || hostStillWaiting(element))) {
1706
2118
  const previous = lastDrafts.get(identity.callId);
1707
2119
  const progress = readProgress(element);
1708
2120
  const count = Math.max(progress?.count ?? 1, previous?.length ?? 1);
1709
- lastDrafts.set(identity.callId, mergeDrafts(gateDraftSelections(readHostDrafts(identity, count), identity.callId), readLiveDrafts(element, count, readLiveSelected(element, identity.callId)), previous, count, progress?.index));
2121
+ lastDrafts.set(identity.callId, applyCustomChoice(mergeDrafts(gateDraftSelections(readHostDrafts(identity, count), identity.callId), readLiveDrafts(element, count, readLiveSelected(element, identity.callId)), previous, count, progress?.index), identity.callId));
1710
2122
  }
1711
2123
  if (enhancementOn) decorateCard(element, identity);
1712
2124
  else restoreCardOnce(element, QUESTION_CARD_KEY_PREFIX + identity.sessionId + ":" + identity.callId);
@@ -1744,6 +2156,11 @@ function installQuestionTimeoutAdapter(ctx, source) {
1744
2156
  };
1745
2157
  const onDraftStorageChange = (event) => {
1746
2158
  const key = event.key;
2159
+ if (key === "dsh.question-timeout-protection.auto-infinite") {
2160
+ autoInfinite = readAutoInfinite();
2161
+ scheduleScan();
2162
+ return;
2163
+ }
1747
2164
  if (typeof key === "string" && !key.startsWith("dsh.user-questions.drafts.v1")) return;
1748
2165
  invalidateHostDraftCache();
1749
2166
  scheduleScan();
@@ -1753,6 +2170,18 @@ function installQuestionTimeoutAdapter(ctx, source) {
1753
2170
  if (!(target instanceof Element) || target.closest("[data-question-key]") === null) return;
1754
2171
  invalidateHostDraftCache();
1755
2172
  scheduleScan();
2173
+ if (!event.isTrusted) return;
2174
+ const card = target.closest(QUESTION_CARD_SELECTOR);
2175
+ if (!(card instanceof HTMLElement)) return;
2176
+ const identity = parseCardKey(card.getAttribute("data-question-key"));
2177
+ const index = readProgress(card)?.index;
2178
+ if (identity === void 0 || index === void 0) return;
2179
+ const field = customFieldOf(card);
2180
+ if (field === void 0 || field !== target) return;
2181
+ if (card.querySelector("[role=\"radiogroup\"]") === null) return;
2182
+ rememberTypedCustom(identity.callId, index, field.value);
2183
+ setCustomChoice(identity.callId, index, true);
2184
+ ensureCustomChoiceUI(card, identity);
1756
2185
  };
1757
2186
  window.addEventListener("storage", onDraftStorageChange);
1758
2187
  document.addEventListener("input", onDraftContentChange, true);
@@ -1779,19 +2208,22 @@ function installQuestionTimeoutAdapter(ctx, source) {
1779
2208
  closeDraftPanel();
1780
2209
  for (const off of subscriptions.values()) off();
1781
2210
  subscriptions.clear();
1782
- for (const element of Array.from(document.querySelectorAll(QUESTION_CARD_SELECTOR))) if (element instanceof HTMLElement) {
1783
- restoreCard(element);
2211
+ for (const element of Array.from(document.querySelectorAll(QUESTION_CARD_SELECTOR))) {
2212
+ if (!(element instanceof HTMLElement)) continue;
1784
2213
  element.removeAttribute(CARD_DISMISSED_ATTRIBUTE);
2214
+ restoreCard(element);
1785
2215
  }
1786
- for (const element of Array.from(document.querySelectorAll("[data-dqtp-countdown], button.dqtp-infinite-wait, button.dqtp-question-bubble"))) element.remove();
2216
+ for (const element of Array.from(document.querySelectorAll("[data-dqtp-countdown], button.dqtp-infinite-wait, button.dqtp-question-bubble, button.dqtp-custom-radio, button.dqtp-custom-hint"))) element.remove();
1787
2217
  for (const element of Array.from(document.querySelectorAll("." + HIDDEN_CONTROL_CLASS))) element.classList.remove(HIDDEN_CONTROL_CLASS);
2218
+ for (const element of Array.from(document.querySelectorAll("[data-dqtp-host-wait]"))) element.removeAttribute(HIDDEN_WAIT_ATTRIBUTE);
1788
2219
  for (const element of Array.from(document.querySelectorAll("button.dqtp-auto-infinite"))) element.remove();
2220
+ for (const element of Array.from(document.querySelectorAll(".dqtp-custom-choice"))) element.classList.remove(CUSTOM_CHOICE_CLASS);
1789
2221
  releaseStyle();
1790
2222
  enhancementUsers -= 1;
1791
2223
  if (enhancementUsers <= 0) document.documentElement.classList.remove(CARD_ENHANCEMENTS_CLASS);
1792
2224
  syncUnavailable.clear();
1793
2225
  autoInfiniteAttempted.clear();
1794
- dismissedCallIds.clear();
2226
+ dismissFailedWarned.clear();
1795
2227
  subscribeWarned.clear();
1796
2228
  evaluateWarned.clear();
1797
2229
  };
@@ -1804,7 +2236,7 @@ const ZH = {
1804
2236
  injectLabel: "注入到上下文",
1805
2237
  injectDesc: "超时前把草稿快照交给服务端, 到期时随工具结果按题带回模型上下文, 由模型自行决定是否重新提问",
1806
2238
  fixedSection: "固定特性",
1807
- fixedNote: "随插件启用状态生效, 不可单独关闭",
2239
+ fixedNote: "随插件启用状态生效, 本页不提供开关",
1808
2240
  fixedKeepLabel: "界面保留草稿",
1809
2241
  fixedKeepDesc: "超时后把已选选项与已输入内容记入提问气泡, 可在气泡里只读查看",
1810
2242
  cardEnhancementsLabel: "卡片增强",
@@ -1824,7 +2256,7 @@ const EN = {
1824
2256
  injectLabel: "Inject into context",
1825
2257
  injectDesc: "The draft snapshot is sent to the server before the timeout; on expiry it comes back with the tool result per question and enters the model context, so the model can decide whether to ask again",
1826
2258
  fixedSection: "Fixed features",
1827
- fixedNote: "Follows the plugin's enabled state and cannot be turned off separately",
2259
+ fixedNote: "Follows the plugin's enabled state; this page offers no switch",
1828
2260
  fixedKeepLabel: "Keep the draft in the UI",
1829
2261
  fixedKeepDesc: "At timeout, records the selected options and typed text into the question bubble, where they can be viewed read-only",
1830
2262
  cardEnhancementsLabel: "Card enhancements",