@surfishs/dsh-prompt-enhance 0.1.0 → 0.1.1

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/lib/client.js CHANGED
@@ -742,7 +742,7 @@ function totalTokensOf(usage) {
742
742
  return usage.totalTokens ?? usage.inputTokens + usage.outputTokens + (usage.cacheReadTokens ?? 0) + (usage.cacheWriteTokens ?? 0);
743
743
  }
744
744
  function ResultPanel(props) {
745
- const { state, t, onApply, onCancel, onRetry, applied = false, onUndo, onRegenerate, undone = false, regenerated = false } = props;
745
+ const { state, t, onApply, onCancel, onRetry, applied = false, onUndo, onRegenerate, regenerated = false } = props;
746
746
  const [copied, setCopied] = (0, import_react3.useState)("idle");
747
747
  const copy = (0, import_react3.useCallback)(() => {
748
748
  if (state.result === void 0) return;
@@ -771,6 +771,7 @@ function ResultPanel(props) {
771
771
  }
772
772
  return parts.join(" \xB7 ");
773
773
  };
774
+ const swapLabel = (active, text) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: active ? "on" : void 0, "aria-hidden": active ? void 0 : true, children: text });
774
775
  return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("section", { className: "dsh-pe-panel", role: "region", "aria-label": t("panel.title"), children: [
775
776
  /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("header", { className: "dsh-pe-head", children: [
776
777
  /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "dsh-pe-title", children: [
@@ -787,7 +788,6 @@ function ResultPanel(props) {
787
788
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { title: tokenDetail(state.result.usage), children: t("panel.tokens", { total: formatTokens(totalTokensOf(state.result.usage)) }) })
788
789
  ] })
789
790
  ] }),
790
- copied === "ok" ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "dsh-pe-applied", children: t("panel.copiedShort") }) : regenerated ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "dsh-pe-applied", children: t("panel.regeneratedShort") }) : applied ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "dsh-pe-applied", children: t("panel.appliedShort") }) : undone ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "dsh-pe-applied", children: t("panel.undoneShort") }) : null,
791
791
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { type: "button", className: "dsh-pe-close", "aria-label": t("panel.close"), onClick: onCancel, children: "\u2715" })
792
792
  ] })
793
793
  ] }),
@@ -817,23 +817,36 @@ function ResultPanel(props) {
817
817
  ] }),
818
818
  /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("footer", { className: "dsh-pe-foot", children: [
819
819
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "dsh-pe-grow" }),
820
- state.phase === "result" && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("button", { type: "button", className: "dsh-pe-btn-action plain", onClick: onRegenerate, disabled: onRegenerate === void 0, children: [
820
+ state.phase === "result" && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("button", { type: "button", className: "dsh-pe-btn-action plain dsh-pe-btn-swap", onClick: onRegenerate, disabled: onRegenerate === void 0, children: [
821
821
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(RegenerateIcon, {}),
822
- t("panel.regenerate")
822
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "dsh-pe-swap", children: [
823
+ swapLabel(!regenerated, t("panel.regenerate")),
824
+ swapLabel(regenerated, t("panel.regenerated"))
825
+ ] })
823
826
  ] }),
824
827
  state.phase === "error" && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_jsx_runtime4.Fragment, { children: retryable(state.error?.code) && onRetry !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { type: "button", className: "dsh-pe-btn-action plain", onClick: onRetry, children: t("panel.retry") }) }),
825
828
  state.phase === "loading" && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { type: "button", className: "dsh-pe-btn-action plain", onClick: onCancel, children: t("panel.cancel") }),
826
829
  state.phase === "result" && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
827
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("button", { type: "button", className: "dsh-pe-btn-action plain dsh-pe-copy", onClick: copy, children: [
830
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("button", { type: "button", className: "dsh-pe-btn-action plain dsh-pe-btn-swap", onClick: copy, children: [
828
831
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CopyIcon, {}),
829
- copied === "ok" ? t("panel.copied") : copied === "failed" ? t("panel.copyFailed") : t("panel.copy")
832
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "dsh-pe-swap", children: [
833
+ swapLabel(copied === "idle", t("panel.copy")),
834
+ swapLabel(copied === "ok", t("panel.copied")),
835
+ swapLabel(copied === "failed", t("panel.copyFailed"))
836
+ ] })
830
837
  ] }),
831
- applied ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("button", { type: "button", className: "dsh-pe-btn-action primary", onClick: onUndo, disabled: onUndo === void 0, children: [
838
+ applied ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("button", { type: "button", className: "dsh-pe-btn-action primary dsh-pe-btn-swap", onClick: onUndo, disabled: onUndo === void 0, children: [
832
839
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(UndoIcon, {}),
833
- t("undo.undo")
834
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("button", { type: "button", className: "dsh-pe-btn-action primary", onClick: onApply, children: [
840
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "dsh-pe-swap", children: [
841
+ swapLabel(true, t("undo.undo")),
842
+ swapLabel(false, t("panel.apply"))
843
+ ] })
844
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("button", { type: "button", className: "dsh-pe-btn-action primary dsh-pe-btn-swap", onClick: onApply, children: [
835
845
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(FillIcon, {}),
836
- t("panel.apply")
846
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "dsh-pe-swap", children: [
847
+ swapLabel(true, t("panel.apply")),
848
+ swapLabel(false, t("undo.undo"))
849
+ ] })
837
850
  ] })
838
851
  ] })
839
852
  ] })
@@ -948,15 +961,12 @@ function useDockAlignment(active, uiKey) {
948
961
 
949
962
  // src/client/ResultDock.tsx
950
963
  var import_jsx_runtime5 = require("react/jsx-runtime");
964
+ var REGENERATED_NOTICE_MS = 2500;
951
965
  function ResultDock(props) {
952
966
  const { t, sessionId, useInput, inputActions } = props;
953
967
  const uiKey = useSessionKey(sessionId, inputActions);
954
968
  const panel = (0, import_react5.useSyncExternalStore)(subscribe, getPanel);
955
969
  const rootRef = useDockAlignment(panel !== void 0 && panel.sessionId === uiKey, uiKey);
956
- const [undone, setUndone] = (0, import_react5.useState)(false);
957
- const [regenerated, setRegenerated] = (0, import_react5.useState)(false);
958
- const [pendingRegenerate, setPendingRegenerate] = (0, import_react5.useState)(false);
959
- const previousResultRef = (0, import_react5.useRef)(void 0);
960
970
  const draft = useInput((state) => {
961
971
  const value = state.draft;
962
972
  return typeof value === "string" ? value : "";
@@ -976,6 +986,9 @@ function ResultDock(props) {
976
986
  );
977
987
  const entry = peekUndo(uiKey);
978
988
  const applied = entry !== void 0 && entry.applied === draft;
989
+ const [regeneratedNotice, setRegeneratedNotice] = (0, import_react5.useState)(false);
990
+ const pendingRegenerate = (0, import_react5.useRef)(false);
991
+ const previousResultRef = (0, import_react5.useRef)(void 0);
979
992
  const prevSession = (0, import_react5.useRef)({ running: sessionRunning, queued: sessionQueued });
980
993
  (0, import_react5.useEffect)(() => {
981
994
  const prev = prevSession.current;
@@ -996,55 +1009,37 @@ function ResultDock(props) {
996
1009
  return () => document.removeEventListener("keydown", onKeyDown);
997
1010
  }, [panel, uiKey]);
998
1011
  (0, import_react5.useEffect)(() => {
999
- if (!undone) return;
1000
- const timer = setTimeout(() => setUndone(false), 2500);
1001
- return () => clearTimeout(timer);
1002
- }, [undone]);
1003
- (0, import_react5.useEffect)(() => {
1004
- if (!pendingRegenerate) return;
1005
- if (panel === void 0 || panel.sessionId !== uiKey) {
1006
- setPendingRegenerate(false);
1007
- return;
1008
- }
1009
- if (panel.phase === "error") {
1010
- setPendingRegenerate(false);
1012
+ if (!pendingRegenerate.current) return;
1013
+ if (panel === void 0 || panel.sessionId !== uiKey || panel.phase === "error") {
1014
+ pendingRegenerate.current = false;
1011
1015
  return;
1012
1016
  }
1013
1017
  if (panel.phase === "result" && panel.result !== previousResultRef.current) {
1014
- setPendingRegenerate(false);
1015
- setRegenerated(true);
1018
+ pendingRegenerate.current = false;
1019
+ setRegeneratedNotice(true);
1016
1020
  }
1017
- }, [panel, pendingRegenerate, uiKey]);
1018
- (0, import_react5.useEffect)(() => {
1019
- if (!regenerated) return;
1020
- const timer = setTimeout(() => setRegenerated(false), 2500);
1021
- return () => clearTimeout(timer);
1022
- }, [regenerated]);
1021
+ }, [panel, uiKey]);
1023
1022
  (0, import_react5.useEffect)(() => {
1024
- if (!pendingRegenerate) return;
1025
- const timer = setTimeout(() => setPendingRegenerate(false), 15e3);
1023
+ if (!regeneratedNotice) return;
1024
+ const timer = setTimeout(() => setRegeneratedNotice(false), REGENERATED_NOTICE_MS);
1026
1025
  return () => clearTimeout(timer);
1027
- }, [pendingRegenerate]);
1026
+ }, [regeneratedNotice]);
1028
1027
  if (panel === void 0 || panel.sessionId !== uiKey) return null;
1029
1028
  const apply2 = () => {
1030
1029
  if (panel.phase !== "result" || panel.result === void 0) return;
1031
1030
  pushUndo(uiKey, { original: draft, applied: panel.result.text });
1032
1031
  inputActions.setDraft(panel.result.text);
1033
- setUndone(false);
1034
- setRegenerated(false);
1035
1032
  };
1036
1033
  const undo = () => {
1037
1034
  if (entry === void 0) return;
1038
1035
  inputActions.setDraft(entry.original);
1039
1036
  popUndo(uiKey);
1040
- setUndone(true);
1041
- setRegenerated(false);
1042
1037
  };
1043
1038
  const regenerate = () => {
1044
1039
  if (panel.phase !== "result") return;
1040
+ setRegeneratedNotice(false);
1045
1041
  previousResultRef.current = panel.result;
1046
- setRegenerated(false);
1047
- setPendingRegenerate(true);
1042
+ pendingRegenerate.current = true;
1048
1043
  runSession(uiKey);
1049
1044
  };
1050
1045
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { ref: rootRef, className: "dsh-pe-dock", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
@@ -1053,8 +1048,7 @@ function ResultDock(props) {
1053
1048
  state: panel,
1054
1049
  t,
1055
1050
  applied,
1056
- undone,
1057
- regenerated,
1051
+ regenerated: regeneratedNotice,
1058
1052
  onApply: apply2,
1059
1053
  onUndo: undo,
1060
1054
  onRegenerate: regenerate,
@@ -1116,10 +1110,7 @@ var zh = {
1116
1110
  "panel.enhanced": "\u589E\u5F3A\u7ED3\u679C",
1117
1111
  "panel.apply": "\u56DE\u586B\u5230\u8F93\u5165\u6846",
1118
1112
  "panel.regenerate": "\u91CD\u65B0\u751F\u6210",
1119
- "panel.appliedShort": "\u5DF2\u66FF\u6362 \u2713",
1120
- "panel.undoneShort": "\u5DF2\u64A4\u9500 \u2713",
1121
- "panel.regeneratedShort": "\u5DF2\u91CD\u65B0\u751F\u6210 \u2713",
1122
- "panel.copiedShort": "\u5DF2\u590D\u5236 \u2713",
1113
+ "panel.regenerated": "\u5DF2\u91CD\u65B0\u751F\u6210",
1123
1114
  "panel.copy": "\u590D\u5236\u7ED3\u679C",
1124
1115
  "panel.copied": "\u5DF2\u590D\u5236",
1125
1116
  "panel.copyFailed": "\u590D\u5236\u5931\u8D25",
@@ -1262,10 +1253,7 @@ var en = {
1262
1253
  "panel.enhanced": "Enhanced result",
1263
1254
  "panel.apply": "Fill into input box",
1264
1255
  "panel.regenerate": "Regenerate",
1265
- "panel.appliedShort": "Replaced \u2713",
1266
- "panel.undoneShort": "Undone \u2713",
1267
- "panel.regeneratedShort": "Regenerated \u2713",
1268
- "panel.copiedShort": "Copied \u2713",
1256
+ "panel.regenerated": "Regenerated",
1269
1257
  "panel.copy": "Copy result",
1270
1258
  "panel.copied": "Copied",
1271
1259
  "panel.copyFailed": "Copy failed",
@@ -1454,16 +1442,6 @@ var CSS = `
1454
1442
  opacity: 0.72;
1455
1443
  white-space: nowrap;
1456
1444
  }
1457
- .dsh-pe-applied {
1458
- font-size: 10.5px;
1459
- font-weight: 500;
1460
- line-height: 1;
1461
- padding: 3px 7px;
1462
- border-radius: 999px;
1463
- color: var(--dsw-alias-state-success-primary, #2da44e);
1464
- border: 1px solid currentColor;
1465
- white-space: nowrap;
1466
- }
1467
1445
  .dsh-pe-close {
1468
1446
  border: none; background: transparent; color: inherit; opacity: 0.6;
1469
1447
  font-size: 15px; cursor: pointer; padding: 2px 6px; border-radius: 4px;
@@ -1547,7 +1525,6 @@ var CSS = `
1547
1525
  cursor: pointer;
1548
1526
  }
1549
1527
  .dsh-pe-btn-action.primary {
1550
- min-width: 112px;
1551
1528
  border-color: transparent;
1552
1529
  /* Fill and label are a PAIR: the alias layer flips brand-primary from
1553
1530
  near-black (light theme) to near-white (dark theme), so the label has to
@@ -1565,9 +1542,24 @@ var CSS = `
1565
1542
  }
1566
1543
  .dsh-pe-btn-action.plain { background: transparent; color: inherit; }
1567
1544
  .dsh-pe-btn-action.plain:hover { background: var(--pe-hover); }
1568
- .dsh-pe-btn-action.dsh-pe-copy { min-width: 96px; }
1545
+ /* A floor for the buttons whose label swaps (see .dsh-pe-swap), not a sizing
1546
+ mechanism: the swap group already makes the button as wide as its longest
1547
+ label, so the longest label wins in every shipped language and this only
1548
+ matters if all labels ever collapse to nothing \u2014 the button keeps a visible,
1549
+ clickable width instead of shrinking to the icon. 96px is below every real
1550
+ content width here (the shortest swap group already reserves about 102px in
1551
+ Chinese and about 114px in English). */
1552
+ .dsh-pe-btn-swap { min-width: 96px; }
1569
1553
  .dsh-pe-btn-action:disabled { opacity: 0.45; cursor: default; }
1570
1554
 
1555
+ /* Both labels of the regenerate button share one cell, so the button is as wide
1556
+ as the longer label of the active language and a label swap can never move
1557
+ the footer. visibility:hidden keeps the inert label out of the accessibility
1558
+ tree, leaving the visible text as the button's name. */
1559
+ .dsh-pe-swap { display: inline-grid; }
1560
+ .dsh-pe-swap > * { grid-area: 1 / 1; visibility: hidden; }
1561
+ .dsh-pe-swap > .on { visibility: visible; }
1562
+
1571
1563
  .dsh-pe-stale {
1572
1564
  padding: 6px 10px;
1573
1565
  font-size: 12px;
@@ -2393,7 +2385,7 @@ var REPOSITORY_URL = "https://github.com/surfishs/dsh-prompt-enhance";
2393
2385
  var NPM_URL = "https://www.npmjs.com/package/@surfishs/dsh-prompt-enhance";
2394
2386
  var GITHUB_MARK = "M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82a7.6 7.6 0 0 1 2-.27c.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.01 8.01 0 0 0 16 8c0-4.42-3.58-8-8-8z";
2395
2387
  var NPM_MARK = "M1.763 0C.786 0 0 .786 0 1.763v20.474C0 23.214.786 24 1.763 24h20.474c.977 0 1.763-.786 1.763-1.763V1.763C24 .786 23.214 0 22.237 0zM5.13 5.323l13.837.019-.009 13.836h-3.464l.01-10.382h-3.456L12.04 19.17H5.113z";
2396
- var PLUGIN_VERSION = true ? "0.1.0" : "0.0.0";
2388
+ var PLUGIN_VERSION = true ? "0.1.1" : "0.0.0";
2397
2389
  var HEADER_STYLE = { display: "flex", flexDirection: "column", gap: 12, padding: "2px 0" };
2398
2390
  var HEADER_ROW_STYLE = { display: "flex", alignItems: "center", gap: 10, flexWrap: "wrap" };
2399
2391
  var HEADER_TITLE_STYLE = {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@surfishs/dsh-prompt-enhance",
3
3
  "description": "Prompt enhancement for the dsh web GUI: rewrite the composer draft into a well-structured prompt through the harness LLM service, preview the before/after, then fill back, copy, or undo. Original draft is always preserved.",
4
- "version": "0.1.0",
4
+ "version": "0.1.1",
5
5
  "author": "surfishs",
6
6
  "type": "module",
7
7
  "engines": {
@@ -18,6 +18,14 @@ import { useDockAlignment } from './useDockAlignment'
18
18
  /** Props of the input.dock entry: the InputZone owner share + session kit + locale seat. */
19
19
  export type ResultDockProps = PropsRuntime<'conversation.input.dock'> & PropsLocale<'dsh-prompt-enhance'>
20
20
 
21
+ /**
22
+ * How long the regenerate button keeps the "regenerated" label.
23
+ *
24
+ * Matches the copy confirmation's window (`ResultPanel`'s copy handler uses the
25
+ * same 2500ms) so both transient confirmations feel like one system.
26
+ */
27
+ const REGENERATED_NOTICE_MS = 2500
28
+
21
29
  /** One session's enhancement card, docked above its composer. */
22
30
  export function ResultDock(props: ResultDockProps): ReactNode {
23
31
  const { t, sessionId, useInput, inputActions } = props
@@ -26,10 +34,6 @@ export function ResultDock(props: ResultDockProps): ReactNode {
26
34
  const uiKey = useSessionKey(sessionId, inputActions)
27
35
  const panel = useSyncExternalStore(ui.subscribe, ui.getPanel)
28
36
  const rootRef = useDockAlignment(panel !== undefined && panel.sessionId === uiKey, uiKey)
29
- const [undone, setUndone] = useState(false)
30
- const [regenerated, setRegenerated] = useState(false)
31
- const [pendingRegenerate, setPendingRegenerate] = useState(false)
32
- const previousResultRef = useRef<unknown>(undefined)
33
37
  const draft = useInput((state) => {
34
38
  const value = (state as { draft?: unknown }).draft
35
39
  return typeof value === 'string' ? value : ''
@@ -63,12 +67,22 @@ export function ResultDock(props: ResultDockProps): ReactNode {
63
67
  : // eslint-disable-next-line react-hooks/rules-of-hooks
64
68
  Number(useSession((state) => (state as { queue?: unknown[] }).queue?.length ?? 0))
65
69
 
66
- // The applied chip is derived from the undo stack: it is true exactly while
70
+ // The applied state is derived from the undo stack: it is true exactly while
67
71
  // the composer still holds the applied text, and drops itself when the user
68
- // edits (the UndoBar drops the stale entry in the same situation).
72
+ // edits (the UndoBar drops the stale entry in the same situation). It drives
73
+ // the footer button (fill vs undo); the header shows no status chip.
69
74
  const entry = ui.peekUndo(uiKey)
70
75
  const applied = entry !== undefined && entry.applied === draft
71
76
 
77
+ // The regenerate button is HIDDEN while the next round streams, so its
78
+ // confirmation has to be a completion signal: it turns on only after a result
79
+ // that differs from the one the click captured arrives, and clears itself
80
+ // after REGENERATED_NOTICE_MS. A failure or a closed panel only drops the
81
+ // pending flag — there is no button to relabel in those states.
82
+ const [regeneratedNotice, setRegeneratedNotice] = useState(false)
83
+ const pendingRegenerate = useRef(false)
84
+ const previousResultRef = useRef<unknown>(undefined)
85
+
72
86
  // Sending the draft dismisses the card; the undo row can still take over.
73
87
  // The phase is checked where the host provides it; the session transition
74
88
  // (running false→true, or a new queued turn) is the fallback for hosts that
@@ -95,45 +109,27 @@ export function ResultDock(props: ResultDockProps): ReactNode {
95
109
  return () => document.removeEventListener('keydown', onKeyDown)
96
110
  }, [panel, uiKey])
97
111
 
98
- // The "undone" chip is transient: it confirms the undo for a moment, then
99
- // clears without needing another state change.
112
+ // Turn the completion signal into the transient label, and clear it on time.
113
+ // The two effects are separate on purpose: the first only watches the panel
114
+ // settling, the second only owns the timer, so a re-render of the panel cannot
115
+ // restart the countdown.
100
116
  useEffect(() => {
101
- if (!undone) return
102
- const timer = setTimeout(() => setUndone(false), 2500)
103
- return () => clearTimeout(timer)
104
- }, [undone])
105
-
106
- // "Regenerated" is a completion signal, not a click signal: wait until the
107
- // panel settles with a different result object, then show the chip briefly.
108
- useEffect(() => {
109
- if (!pendingRegenerate) return
110
- if (panel === undefined || panel.sessionId !== uiKey) {
111
- setPendingRegenerate(false)
112
- return
113
- }
114
- if (panel.phase === 'error') {
115
- setPendingRegenerate(false)
117
+ if (!pendingRegenerate.current) return
118
+ if (panel === undefined || panel.sessionId !== uiKey || panel.phase === 'error') {
119
+ pendingRegenerate.current = false
116
120
  return
117
121
  }
118
122
  if (panel.phase === 'result' && panel.result !== previousResultRef.current) {
119
- setPendingRegenerate(false)
120
- setRegenerated(true)
123
+ pendingRegenerate.current = false
124
+ setRegeneratedNotice(true)
121
125
  }
122
- }, [panel, pendingRegenerate, uiKey])
123
-
124
- useEffect(() => {
125
- if (!regenerated) return
126
- const timer = setTimeout(() => setRegenerated(false), 2500)
127
- return () => clearTimeout(timer)
128
- }, [regenerated])
126
+ }, [panel, uiKey])
129
127
 
130
- // A regenerate click on an empty draft is a no-op; do not leave the pending
131
- // flag stuck forever in that case.
132
128
  useEffect(() => {
133
- if (!pendingRegenerate) return
134
- const timer = setTimeout(() => setPendingRegenerate(false), 15000)
129
+ if (!regeneratedNotice) return
130
+ const timer = setTimeout(() => setRegeneratedNotice(false), REGENERATED_NOTICE_MS)
135
131
  return () => clearTimeout(timer)
136
- }, [pendingRegenerate])
132
+ }, [regeneratedNotice])
137
133
 
138
134
  if (panel === undefined || panel.sessionId !== uiKey) return null
139
135
 
@@ -145,23 +141,22 @@ export function ResultDock(props: ResultDockProps): ReactNode {
145
141
  // closing it falls back to the standalone undo row.
146
142
  ui.pushUndo(uiKey, { original: draft, applied: panel.result.text })
147
143
  inputActions.setDraft(panel.result.text)
148
- setUndone(false)
149
- setRegenerated(false)
150
144
  }
151
145
 
152
146
  const undo = (): void => {
153
147
  if (entry === undefined) return
154
148
  inputActions.setDraft(entry.original)
155
149
  ui.popUndo(uiKey)
156
- setUndone(true)
157
- setRegenerated(false)
158
150
  }
159
151
 
160
152
  const regenerate = (): void => {
161
153
  if (panel.phase !== 'result') return
154
+ // A click during the notice window starts a fresh round: drop the label now
155
+ // so the button shows its normal text before it disappears, and remember
156
+ // which result this round has to replace.
157
+ setRegeneratedNotice(false)
162
158
  previousResultRef.current = panel.result
163
- setRegenerated(false)
164
- setPendingRegenerate(true)
159
+ pendingRegenerate.current = true
165
160
  ui.runSession(uiKey)
166
161
  }
167
162
 
@@ -171,8 +166,7 @@ export function ResultDock(props: ResultDockProps): ReactNode {
171
166
  state={panel}
172
167
  t={t}
173
168
  applied={applied}
174
- undone={undone}
175
- regenerated={regenerated}
169
+ regenerated={regeneratedNotice}
176
170
  onApply={apply}
177
171
  onUndo={undo}
178
172
  onRegenerate={regenerate}
@@ -30,9 +30,7 @@ export interface ResultPanelProps {
30
30
  onUndo?: () => void
31
31
  /** Run the same source prompt through the model again. */
32
32
  onRegenerate?: () => void
33
- /** Show the transient 'undone' chip after an undo. */
34
- undone?: boolean
35
- /** Show the transient 'regenerated' chip after a regenerate request settles. */
33
+ /** Show the transient "regenerated" label on that button instead of its normal text. */
36
34
  regenerated?: boolean
37
35
  }
38
36
 
@@ -165,7 +163,7 @@ function totalTokensOf(usage: EnhanceUsage): number {
165
163
 
166
164
  /** One enhancement result card. */
167
165
  export function ResultPanel(props: ResultPanelProps): ReactNode {
168
- const { state, t, onApply, onCancel, onRetry, applied = false, onUndo, onRegenerate, undone = false, regenerated = false } = props
166
+ const { state, t, onApply, onCancel, onRetry, applied = false, onUndo, onRegenerate, regenerated = false } = props
169
167
  const [copied, setCopied] = useState<'idle' | 'ok' | 'failed'>('idle')
170
168
 
171
169
  const copy = useCallback((): void => {
@@ -205,6 +203,24 @@ export function ResultPanel(props: ResultPanelProps): ReactNode {
205
203
  return parts.join(' · ')
206
204
  }
207
205
 
206
+ /**
207
+ * One label of a swap group.
208
+ *
209
+ * Every label of the group sits in the same `.dsh-pe-swap` grid cell, so the
210
+ * widest label of the active language defines the button width and swapping
211
+ * the visible one cannot resize the button or shift the footer. Only the
212
+ * active label is painted; `aria-hidden` keeps the inert ones out of the
213
+ * accessibility tree even before the stylesheet applies.
214
+ * @param active - whether this label is the one currently shown.
215
+ * @param text - the label text.
216
+ * @returns the label element.
217
+ */
218
+ const swapLabel = (active: boolean, text: string): ReactNode => (
219
+ <span className={active ? 'on' : undefined} aria-hidden={active ? undefined : true}>
220
+ {text}
221
+ </span>
222
+ )
223
+
208
224
  return (
209
225
  <section className="dsh-pe-panel" role="region" aria-label={t('panel.title')}>
210
226
  <header className="dsh-pe-head">
@@ -224,15 +240,6 @@ export function ResultPanel(props: ResultPanelProps): ReactNode {
224
240
  )}
225
241
  </span>
226
242
  )}
227
- {copied === 'ok' ? (
228
- <span className="dsh-pe-applied">{t('panel.copiedShort')}</span>
229
- ) : regenerated ? (
230
- <span className="dsh-pe-applied">{t('panel.regeneratedShort')}</span>
231
- ) : applied ? (
232
- <span className="dsh-pe-applied">{t('panel.appliedShort')}</span>
233
- ) : undone ? (
234
- <span className="dsh-pe-applied">{t('panel.undoneShort')}</span>
235
- ) : null}
236
243
  <button type="button" className="dsh-pe-close" aria-label={t('panel.close')} onClick={onCancel}>
237
244
  ✕
238
245
  </button>
@@ -285,9 +292,12 @@ export function ResultPanel(props: ResultPanelProps): ReactNode {
285
292
  <footer className="dsh-pe-foot">
286
293
  <span className="dsh-pe-grow" />
287
294
  {state.phase === 'result' && (
288
- <button type="button" className="dsh-pe-btn-action plain" onClick={onRegenerate} disabled={onRegenerate === undefined}>
295
+ <button type="button" className="dsh-pe-btn-action plain dsh-pe-btn-swap" onClick={onRegenerate} disabled={onRegenerate === undefined}>
289
296
  <RegenerateIcon />
290
- {t('panel.regenerate')}
297
+ <span className="dsh-pe-swap">
298
+ {swapLabel(!regenerated, t('panel.regenerate'))}
299
+ {swapLabel(regenerated, t('panel.regenerated'))}
300
+ </span>
291
301
  </button>
292
302
  )}
293
303
  {state.phase === 'error' && (
@@ -306,19 +316,31 @@ export function ResultPanel(props: ResultPanelProps): ReactNode {
306
316
  )}
307
317
  {state.phase === 'result' && (
308
318
  <>
309
- <button type="button" className="dsh-pe-btn-action plain dsh-pe-copy" onClick={copy}>
319
+ <button type="button" className="dsh-pe-btn-action plain dsh-pe-btn-swap" onClick={copy}>
310
320
  <CopyIcon />
311
- {copied === 'ok' ? t('panel.copied') : copied === 'failed' ? t('panel.copyFailed') : t('panel.copy')}
321
+ <span className="dsh-pe-swap">
322
+ {swapLabel(copied === 'idle', t('panel.copy'))}
323
+ {swapLabel(copied === 'ok', t('panel.copied'))}
324
+ {swapLabel(copied === 'failed', t('panel.copyFailed'))}
325
+ </span>
312
326
  </button>
313
327
  {applied ? (
314
- <button type="button" className="dsh-pe-btn-action primary" onClick={onUndo} disabled={onUndo === undefined}>
328
+ <button type="button" className="dsh-pe-btn-action primary dsh-pe-btn-swap" onClick={onUndo} disabled={onUndo === undefined}>
315
329
  <UndoIcon />
316
- {t('undo.undo')}
330
+ {/* The undo label reserves the width of the fill label it replaces,
331
+ so switching between the two does not resize the footer. */}
332
+ <span className="dsh-pe-swap">
333
+ {swapLabel(true, t('undo.undo'))}
334
+ {swapLabel(false, t('panel.apply'))}
335
+ </span>
317
336
  </button>
318
337
  ) : (
319
- <button type="button" className="dsh-pe-btn-action primary" onClick={onApply}>
338
+ <button type="button" className="dsh-pe-btn-action primary dsh-pe-btn-swap" onClick={onApply}>
320
339
  <FillIcon />
321
- {t('panel.apply')}
340
+ <span className="dsh-pe-swap">
341
+ {swapLabel(true, t('panel.apply'))}
342
+ {swapLabel(false, t('undo.undo'))}
343
+ </span>
322
344
  </button>
323
345
  )}
324
346
  </>
@@ -19,10 +19,7 @@ export const zh = {
19
19
  'panel.enhanced': '增强结果',
20
20
  'panel.apply': '回填到输入框',
21
21
  'panel.regenerate': '重新生成',
22
- 'panel.appliedShort': '已替换 ✓',
23
- 'panel.undoneShort': '已撤销 ✓',
24
- 'panel.regeneratedShort': '已重新生成 ✓',
25
- 'panel.copiedShort': '已复制 ✓',
22
+ 'panel.regenerated': '已重新生成',
26
23
  'panel.copy': '复制结果',
27
24
  'panel.copied': '已复制',
28
25
  'panel.copyFailed': '复制失败',
@@ -170,10 +167,7 @@ export const en: Record<PromptEnhanceKey, string> = {
170
167
  'panel.enhanced': 'Enhanced result',
171
168
  'panel.apply': 'Fill into input box',
172
169
  'panel.regenerate': 'Regenerate',
173
- 'panel.appliedShort': 'Replaced ✓',
174
- 'panel.undoneShort': 'Undone ✓',
175
- 'panel.regeneratedShort': 'Regenerated ✓',
176
- 'panel.copiedShort': 'Copied ✓',
170
+ 'panel.regenerated': 'Regenerated',
177
171
  'panel.copy': 'Copy result',
178
172
  'panel.copied': 'Copied',
179
173
  'panel.copyFailed': 'Copy failed',
@@ -70,16 +70,6 @@ export const CSS = `
70
70
  opacity: 0.72;
71
71
  white-space: nowrap;
72
72
  }
73
- .dsh-pe-applied {
74
- font-size: 10.5px;
75
- font-weight: 500;
76
- line-height: 1;
77
- padding: 3px 7px;
78
- border-radius: 999px;
79
- color: var(--dsw-alias-state-success-primary, #2da44e);
80
- border: 1px solid currentColor;
81
- white-space: nowrap;
82
- }
83
73
  .dsh-pe-close {
84
74
  border: none; background: transparent; color: inherit; opacity: 0.6;
85
75
  font-size: 15px; cursor: pointer; padding: 2px 6px; border-radius: 4px;
@@ -163,7 +153,6 @@ export const CSS = `
163
153
  cursor: pointer;
164
154
  }
165
155
  .dsh-pe-btn-action.primary {
166
- min-width: 112px;
167
156
  border-color: transparent;
168
157
  /* Fill and label are a PAIR: the alias layer flips brand-primary from
169
158
  near-black (light theme) to near-white (dark theme), so the label has to
@@ -181,9 +170,24 @@ export const CSS = `
181
170
  }
182
171
  .dsh-pe-btn-action.plain { background: transparent; color: inherit; }
183
172
  .dsh-pe-btn-action.plain:hover { background: var(--pe-hover); }
184
- .dsh-pe-btn-action.dsh-pe-copy { min-width: 96px; }
173
+ /* A floor for the buttons whose label swaps (see .dsh-pe-swap), not a sizing
174
+ mechanism: the swap group already makes the button as wide as its longest
175
+ label, so the longest label wins in every shipped language and this only
176
+ matters if all labels ever collapse to nothing — the button keeps a visible,
177
+ clickable width instead of shrinking to the icon. 96px is below every real
178
+ content width here (the shortest swap group already reserves about 102px in
179
+ Chinese and about 114px in English). */
180
+ .dsh-pe-btn-swap { min-width: 96px; }
185
181
  .dsh-pe-btn-action:disabled { opacity: 0.45; cursor: default; }
186
182
 
183
+ /* Both labels of the regenerate button share one cell, so the button is as wide
184
+ as the longer label of the active language and a label swap can never move
185
+ the footer. visibility:hidden keeps the inert label out of the accessibility
186
+ tree, leaving the visible text as the button's name. */
187
+ .dsh-pe-swap { display: inline-grid; }
188
+ .dsh-pe-swap > * { grid-area: 1 / 1; visibility: hidden; }
189
+ .dsh-pe-swap > .on { visibility: visible; }
190
+
187
191
  .dsh-pe-stale {
188
192
  padding: 6px 10px;
189
193
  font-size: 12px;