@surfishs/dsh-prompt-enhance 0.0.9 → 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
@@ -118,7 +118,13 @@ function parseResult(value) {
118
118
  provider: record.provider,
119
119
  model: record.model,
120
120
  elapsedMs: record.elapsedMs,
121
- ...usage === void 0 ? {} : { usage }
121
+ ...usage === void 0 ? {} : { usage },
122
+ // Carried explicitly, not optional-by-accident: the panel's "output hit
123
+ // the token cap" warning is driven by this flag alone, so rebuilding the
124
+ // object without it left the host setting it, the wire carrying it, and
125
+ // the UI never seeing it. Only `true` is ever normalized in, matching the
126
+ // host, which sets the field solely on a capped finish.
127
+ ...record.truncated === true ? { truncated: true } : {}
122
128
  };
123
129
  }
124
130
  throw new EnhanceClientError({ code: "internal", params: { reason: "malformed" } });
@@ -514,8 +520,9 @@ function serverSessionId(maybeSessionId) {
514
520
 
515
521
  // src/client/EnhanceButton.tsx
516
522
  var import_jsx_runtime2 = require("react/jsx-runtime");
517
- function countOf(value) {
518
- return Array.isArray(value) ? value.length : 0;
523
+ var OCCURRENCES_UNKNOWN = -1;
524
+ function occurrenceCountOf(value) {
525
+ return Array.isArray(value) ? value.length : OCCURRENCES_UNKNOWN;
519
526
  }
520
527
  function stringOf(value) {
521
528
  return typeof value === "string" ? value : "";
@@ -526,7 +533,7 @@ function EnhanceButton(props) {
526
533
  const wireId = serverSessionId(sessionId);
527
534
  const draft = useInput((state) => stringOf(state.draft));
528
535
  const phase = useInput((state) => state.phase);
529
- const occurrenceCount = useInput((state) => countOf(state.occurrences));
536
+ const occurrenceCount = useInput((state) => occurrenceCountOf(state.occurrences));
530
537
  const settings = (0, import_react2.useSyncExternalStore)(subscribeClientSettings, getClientSettings);
531
538
  const panel = (0, import_react2.useSyncExternalStore)(subscribe, getPanel);
532
539
  const rootRef = (0, import_react2.useRef)(null);
@@ -549,6 +556,11 @@ function EnhanceButton(props) {
549
556
  openError(uiKey, source, { code: "rejected", localized: message });
550
557
  return;
551
558
  }
559
+ if (occurrenceCount === OCCURRENCES_UNKNOWN) {
560
+ const unknown = t("error.chipsUnknown");
561
+ openError(uiKey, source, { code: "rejected", localized: unknown });
562
+ return;
563
+ }
552
564
  if (occurrenceCount > 0) {
553
565
  const occurrences = t("error.occurrences");
554
566
  openError(uiKey, source, { code: "rejected", localized: occurrences });
@@ -602,6 +614,7 @@ function EnhanceButton(props) {
602
614
  {
603
615
  ref: rootRef,
604
616
  type: "button",
617
+ "data-dsh-pe-key": uiKey,
605
618
  className: `dsh-pe-btn${busy ? " is-busy" : ""}${otherBusy && !empty ? " is-blocked" : ""}${empty && !busy ? " is-empty" : ""}`,
606
619
  title: busy ? t("button.busy") : otherBusy ? t("button.otherBusy") : empty ? t("button.emptyTitle") : t("button.title"),
607
620
  "aria-label": busy ? t("button.busy") : otherBusy ? t("button.otherBusy") : empty ? t("button.emptyTitle") : t("button.title"),
@@ -729,7 +742,7 @@ function totalTokensOf(usage) {
729
742
  return usage.totalTokens ?? usage.inputTokens + usage.outputTokens + (usage.cacheReadTokens ?? 0) + (usage.cacheWriteTokens ?? 0);
730
743
  }
731
744
  function ResultPanel(props) {
732
- 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;
733
746
  const [copied, setCopied] = (0, import_react3.useState)("idle");
734
747
  const copy = (0, import_react3.useCallback)(() => {
735
748
  if (state.result === void 0) return;
@@ -758,6 +771,7 @@ function ResultPanel(props) {
758
771
  }
759
772
  return parts.join(" \xB7 ");
760
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 });
761
775
  return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("section", { className: "dsh-pe-panel", role: "region", "aria-label": t("panel.title"), children: [
762
776
  /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("header", { className: "dsh-pe-head", children: [
763
777
  /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "dsh-pe-title", children: [
@@ -774,7 +788,6 @@ function ResultPanel(props) {
774
788
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { title: tokenDetail(state.result.usage), children: t("panel.tokens", { total: formatTokens(totalTokensOf(state.result.usage)) }) })
775
789
  ] })
776
790
  ] }),
777
- 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,
778
791
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { type: "button", className: "dsh-pe-close", "aria-label": t("panel.close"), onClick: onCancel, children: "\u2715" })
779
792
  ] })
780
793
  ] }),
@@ -804,23 +817,36 @@ function ResultPanel(props) {
804
817
  ] }),
805
818
  /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("footer", { className: "dsh-pe-foot", children: [
806
819
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "dsh-pe-grow" }),
807
- 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: [
808
821
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(RegenerateIcon, {}),
809
- 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
+ ] })
810
826
  ] }),
811
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") }) }),
812
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") }),
813
829
  state.phase === "result" && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
814
- /* @__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: [
815
831
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CopyIcon, {}),
816
- 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
+ ] })
817
837
  ] }),
818
- 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: [
819
839
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(UndoIcon, {}),
820
- t("undo.undo")
821
- ] }) : /* @__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: [
822
845
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(FillIcon, {}),
823
- 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
+ ] })
824
850
  ] })
825
851
  ] })
826
852
  ] })
@@ -829,44 +855,81 @@ function ResultPanel(props) {
829
855
 
830
856
  // src/client/useDockAlignment.ts
831
857
  var import_react4 = require("react");
832
- function useDockAlignment(active) {
858
+ var EDITOR_SELECTOR = 'textarea, [contenteditable="true"], [role="textbox"]';
859
+ var SESSION_ANCHOR_ATTRIBUTE = "data-dsh-pe-key";
860
+ var CARD_MIN_WIDTH = 360;
861
+ var CARD_MIN_HEIGHT = 48;
862
+ var CARD_MIN_RADIUS = 4;
863
+ var CARD_MAX_DEPTH = 12;
864
+ var CARD_MAX_VIEWPORT_SHARE = 0.8;
865
+ var CARD_CENTER_TOLERANCE = 40;
866
+ var EDITOR_BELOW_SLACK = 4;
867
+ function isCardSurface(node, minWidth) {
868
+ const rect = node.getBoundingClientRect();
869
+ if (rect.width < minWidth || rect.width <= CARD_MIN_WIDTH || rect.height <= CARD_MIN_HEIGHT) return false;
870
+ const style = getComputedStyle(node);
871
+ return (parseFloat(style.borderTopLeftRadius) || 0) >= CARD_MIN_RADIUS && style.backgroundColor !== "rgba(0, 0, 0, 0)";
872
+ }
873
+ function cardAround(start) {
874
+ let node = start.parentElement;
875
+ for (let depth = 0; depth < CARD_MAX_DEPTH && node !== null; depth++) {
876
+ if (isCardSurface(node, 0)) return node.getBoundingClientRect();
877
+ node = node.parentElement;
878
+ }
879
+ return void 0;
880
+ }
881
+ function editorsIn(scope) {
882
+ return Array.from(scope.querySelectorAll(EDITOR_SELECTOR));
883
+ }
884
+ function useDockAlignment(active, uiKey) {
833
885
  const rootRef = (0, import_react4.useRef)(null);
834
886
  (0, import_react4.useEffect)(() => {
835
887
  if (!active) return;
836
888
  const root = rootRef.current;
837
889
  if (root === null) return;
838
890
  let frame = 0;
839
- const align = () => {
840
- const parent = root.parentElement;
841
- if (parent === null) return;
842
- root.style.transform = "";
843
- const rootRect = root.getBoundingClientRect();
844
- const editors = Array.from(document.querySelectorAll('textarea, [contenteditable="true"], [role="textbox"]'));
845
- const editor = editors.find((node2) => {
846
- const rect = node2.getBoundingClientRect();
847
- return rect.width > 0 && rect.height > 0 && rect.top >= rootRect.bottom - 4;
848
- });
849
- if (editor === void 0) {
850
- root.style.width = "";
851
- root.style.marginLeft = "";
852
- root.style.transform = "";
853
- return;
854
- }
891
+ const cardFromEditor = (editor) => {
855
892
  const editorRect = editor.getBoundingClientRect();
856
893
  const candidates = [];
857
894
  let node = editor;
858
- for (let depth = 0; depth < 12 && node !== null; depth++) {
859
- const rect = node.getBoundingClientRect();
860
- const style = getComputedStyle(node);
861
- if (rect.width >= editorRect.width && rect.width > 360 && rect.height > 48 && (parseFloat(style.borderTopLeftRadius) || 0) >= 4 && style.backgroundColor !== "rgba(0, 0, 0, 0)") {
862
- candidates.push({ node, rect });
863
- }
895
+ for (let depth = 0; depth < CARD_MAX_DEPTH && node !== null; depth++) {
896
+ if (isCardSurface(node, editorRect.width)) candidates.push(node.getBoundingClientRect());
864
897
  node = node.parentElement;
865
898
  }
899
+ const widest = (list) => list.sort((a, b) => b.width - a.width)[0];
900
+ if (candidates.length === 0) return void 0;
866
901
  const editorCenter = editorRect.left + editorRect.width / 2;
867
- const cardEntry = candidates.filter((candidate) => candidate.rect.width <= window.innerWidth * 0.8 && Math.abs(candidate.rect.left + candidate.rect.width / 2 - editorCenter) < 40).sort((a, b) => b.rect.width - a.rect.width)[0] ?? candidates.sort((a, b) => b.rect.width - a.rect.width)[0];
868
- if (cardEntry === void 0) return;
869
- const cardRect = cardEntry.rect;
902
+ const centered = candidates.filter((rect) => rect.width <= window.innerWidth * CARD_MAX_VIEWPORT_SHARE && Math.abs(rect.left + rect.width / 2 - editorCenter) < CARD_CENTER_TOLERANCE);
903
+ return widest(centered) ?? widest(candidates);
904
+ };
905
+ const editorBelow = (scope, rootRect) => editorsIn(scope).find((node) => {
906
+ const rect = node.getBoundingClientRect();
907
+ return rect.width > 0 && rect.height > 0 && rect.top >= rootRect.bottom - EDITOR_BELOW_SLACK;
908
+ });
909
+ const cardForThisEntry = () => {
910
+ if (uiKey !== void 0) {
911
+ const anchor = Array.from(document.querySelectorAll(`[${SESSION_ANCHOR_ATTRIBUTE}]`)).find((node) => node.getAttribute(SESSION_ANCHOR_ATTRIBUTE) === uiKey);
912
+ if (anchor !== void 0) {
913
+ const anchored = cardAround(anchor);
914
+ if (anchored !== void 0) return anchored;
915
+ }
916
+ }
917
+ const rootRect = root.getBoundingClientRect();
918
+ const parent = root.parentElement;
919
+ const scoped = parent === null ? void 0 : editorBelow(parent, rootRect);
920
+ if (scoped !== void 0) {
921
+ const rect = cardFromEditor(scoped);
922
+ if (rect !== void 0) return rect;
923
+ }
924
+ const anywhere = editorBelow(document, rootRect);
925
+ return anywhere === void 0 ? void 0 : cardFromEditor(anywhere);
926
+ };
927
+ const apply2 = (cardRect) => {
928
+ if (cardRect === void 0) {
929
+ root.style.width = "";
930
+ root.style.marginLeft = "";
931
+ return;
932
+ }
870
933
  const width = `${cardRect.width}px`;
871
934
  if (root.style.width !== width) root.style.width = width;
872
935
  const afterWidth = root.getBoundingClientRect();
@@ -874,6 +937,10 @@ function useDockAlignment(active) {
874
937
  const marginLeft = `${cardRect.left - (afterWidth.left - currentMargin)}px`;
875
938
  if (root.style.marginLeft !== marginLeft) root.style.marginLeft = marginLeft;
876
939
  };
940
+ const align = () => {
941
+ root.style.transform = "";
942
+ apply2(cardForThisEntry());
943
+ };
877
944
  const schedule = () => {
878
945
  cancelAnimationFrame(frame);
879
946
  frame = requestAnimationFrame(align);
@@ -888,21 +955,18 @@ function useDockAlignment(active) {
888
955
  window.removeEventListener("resize", schedule);
889
956
  observer?.disconnect();
890
957
  };
891
- }, [active]);
958
+ }, [active, uiKey]);
892
959
  return rootRef;
893
960
  }
894
961
 
895
962
  // src/client/ResultDock.tsx
896
963
  var import_jsx_runtime5 = require("react/jsx-runtime");
964
+ var REGENERATED_NOTICE_MS = 2500;
897
965
  function ResultDock(props) {
898
966
  const { t, sessionId, useInput, inputActions } = props;
899
967
  const uiKey = useSessionKey(sessionId, inputActions);
900
968
  const panel = (0, import_react5.useSyncExternalStore)(subscribe, getPanel);
901
- const rootRef = useDockAlignment(panel !== void 0 && panel.sessionId === uiKey);
902
- const [undone, setUndone] = (0, import_react5.useState)(false);
903
- const [regenerated, setRegenerated] = (0, import_react5.useState)(false);
904
- const [pendingRegenerate, setPendingRegenerate] = (0, import_react5.useState)(false);
905
- const previousResultRef = (0, import_react5.useRef)(void 0);
969
+ const rootRef = useDockAlignment(panel !== void 0 && panel.sessionId === uiKey, uiKey);
906
970
  const draft = useInput((state) => {
907
971
  const value = state.draft;
908
972
  return typeof value === "string" ? value : "";
@@ -922,6 +986,9 @@ function ResultDock(props) {
922
986
  );
923
987
  const entry = peekUndo(uiKey);
924
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);
925
992
  const prevSession = (0, import_react5.useRef)({ running: sessionRunning, queued: sessionQueued });
926
993
  (0, import_react5.useEffect)(() => {
927
994
  const prev = prevSession.current;
@@ -942,55 +1009,37 @@ function ResultDock(props) {
942
1009
  return () => document.removeEventListener("keydown", onKeyDown);
943
1010
  }, [panel, uiKey]);
944
1011
  (0, import_react5.useEffect)(() => {
945
- if (!undone) return;
946
- const timer = setTimeout(() => setUndone(false), 2500);
947
- return () => clearTimeout(timer);
948
- }, [undone]);
949
- (0, import_react5.useEffect)(() => {
950
- if (!pendingRegenerate) return;
951
- if (panel === void 0 || panel.sessionId !== uiKey) {
952
- setPendingRegenerate(false);
953
- return;
954
- }
955
- if (panel.phase === "error") {
956
- setPendingRegenerate(false);
1012
+ if (!pendingRegenerate.current) return;
1013
+ if (panel === void 0 || panel.sessionId !== uiKey || panel.phase === "error") {
1014
+ pendingRegenerate.current = false;
957
1015
  return;
958
1016
  }
959
1017
  if (panel.phase === "result" && panel.result !== previousResultRef.current) {
960
- setPendingRegenerate(false);
961
- setRegenerated(true);
1018
+ pendingRegenerate.current = false;
1019
+ setRegeneratedNotice(true);
962
1020
  }
963
- }, [panel, pendingRegenerate, uiKey]);
964
- (0, import_react5.useEffect)(() => {
965
- if (!regenerated) return;
966
- const timer = setTimeout(() => setRegenerated(false), 2500);
967
- return () => clearTimeout(timer);
968
- }, [regenerated]);
1021
+ }, [panel, uiKey]);
969
1022
  (0, import_react5.useEffect)(() => {
970
- if (!pendingRegenerate) return;
971
- const timer = setTimeout(() => setPendingRegenerate(false), 15e3);
1023
+ if (!regeneratedNotice) return;
1024
+ const timer = setTimeout(() => setRegeneratedNotice(false), REGENERATED_NOTICE_MS);
972
1025
  return () => clearTimeout(timer);
973
- }, [pendingRegenerate]);
1026
+ }, [regeneratedNotice]);
974
1027
  if (panel === void 0 || panel.sessionId !== uiKey) return null;
975
1028
  const apply2 = () => {
976
1029
  if (panel.phase !== "result" || panel.result === void 0) return;
977
1030
  pushUndo(uiKey, { original: draft, applied: panel.result.text });
978
1031
  inputActions.setDraft(panel.result.text);
979
- setUndone(false);
980
- setRegenerated(false);
981
1032
  };
982
1033
  const undo = () => {
983
1034
  if (entry === void 0) return;
984
1035
  inputActions.setDraft(entry.original);
985
1036
  popUndo(uiKey);
986
- setUndone(true);
987
- setRegenerated(false);
988
1037
  };
989
1038
  const regenerate = () => {
990
1039
  if (panel.phase !== "result") return;
1040
+ setRegeneratedNotice(false);
991
1041
  previousResultRef.current = panel.result;
992
- setRegenerated(false);
993
- setPendingRegenerate(true);
1042
+ pendingRegenerate.current = true;
994
1043
  runSession(uiKey);
995
1044
  };
996
1045
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { ref: rootRef, className: "dsh-pe-dock", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
@@ -999,8 +1048,7 @@ function ResultDock(props) {
999
1048
  state: panel,
1000
1049
  t,
1001
1050
  applied,
1002
- undone,
1003
- regenerated,
1051
+ regenerated: regeneratedNotice,
1004
1052
  onApply: apply2,
1005
1053
  onUndo: undo,
1006
1054
  onRegenerate: regenerate,
@@ -1027,7 +1075,7 @@ function UndoBar(props) {
1027
1075
  }, [draft, entry, uiKey]);
1028
1076
  const panel = getPanel();
1029
1077
  const visible = (panel === void 0 || panel.sessionId !== uiKey) && entry !== void 0 && entry.applied === draft;
1030
- const rootRef = useDockAlignment(visible);
1078
+ const rootRef = useDockAlignment(visible, uiKey);
1031
1079
  if (!visible) return null;
1032
1080
  const undo = () => {
1033
1081
  inputActions.setDraft(entry.original);
@@ -1062,10 +1110,7 @@ var zh = {
1062
1110
  "panel.enhanced": "\u589E\u5F3A\u7ED3\u679C",
1063
1111
  "panel.apply": "\u56DE\u586B\u5230\u8F93\u5165\u6846",
1064
1112
  "panel.regenerate": "\u91CD\u65B0\u751F\u6210",
1065
- "panel.appliedShort": "\u5DF2\u66FF\u6362 \u2713",
1066
- "panel.undoneShort": "\u5DF2\u64A4\u9500 \u2713",
1067
- "panel.regeneratedShort": "\u5DF2\u91CD\u65B0\u751F\u6210 \u2713",
1068
- "panel.copiedShort": "\u5DF2\u590D\u5236 \u2713",
1113
+ "panel.regenerated": "\u5DF2\u91CD\u65B0\u751F\u6210",
1069
1114
  "panel.copy": "\u590D\u5236\u7ED3\u679C",
1070
1115
  "panel.copied": "\u5DF2\u590D\u5236",
1071
1116
  "panel.copyFailed": "\u590D\u5236\u5931\u8D25",
@@ -1085,8 +1130,8 @@ var zh = {
1085
1130
  "undo.dismiss": "\u5173\u95ED\u63D0\u793A",
1086
1131
  "error.empty": "\u8F93\u5165\u6846\u4E3A\u7A7A\uFF0C\u8BF7\u5148\u8F93\u5165\u8981\u589E\u5F3A\u7684\u63D0\u793A\u8BCD\u3002",
1087
1132
  "error.tooLong": "\u5185\u5BB9\u5171 {count} \u4E2A\u5B57\u7B26\uFF0C\u8D85\u8FC7 {max} \u4E2A\u5B57\u7B26\u4E0A\u9650\uFF08\u6309 Unicode \u5B57\u7B26\u6570\u7EDF\u8BA1\uFF0C\u4E0D\u662F token \u6570\uFF09\u3002\u4E3A\u907F\u514D\u6539\u53D8\u539F\u610F\u4E0D\u4F1A\u81EA\u52A8\u622A\u65AD\uFF0C\u8BF7\u7CBE\u7B80\u540E\u518D\u8BD5\u3002",
1088
- "error.attachmentsOnly": "\u8F93\u5165\u6846\u53EA\u9644\u52A0\u4E86\u9644\u4EF6\uFF08\u56FE\u7247\u6216\u6587\u4EF6\uFF09\uFF0C\u8BF7\u8865\u5145\u8981\u589E\u5F3A\u7684\u6587\u672C\u3002",
1089
1133
  "error.occurrences": "\u8F93\u5165\u5185\u5BB9\u5305\u542B\u547D\u4EE4\u6216\u6587\u4EF6\u5F15\u7528\uFF0C\u6682\u4E0D\u652F\u6301\u589E\u5F3A\uFF1B\u8BF7\u5148\u79FB\u9664\u540E\u518D\u8BD5\u3002",
1134
+ "error.chipsUnknown": "\u65E0\u6CD5\u8BFB\u53D6\u8F93\u5165\u6846\u7684\u5F15\u7528\u72B6\u6001\uFF08\u5BBF\u4E3B\u672A\u63D0\u4F9B\u5F15\u7528\u4FE1\u606F\uFF09\u3002\u4E3A\u907F\u514D\u8986\u76D6\u5DF2\u6DFB\u52A0\u7684\u547D\u4EE4\u6216\u6587\u4EF6\u5F15\u7528\uFF0C\u672C\u6B21\u589E\u5F3A\u5DF2\u963B\u6B62\uFF1B\u8BF7\u6E05\u7A7A\u8F93\u5165\u6846\u540E\u8F93\u5165\u7EAF\u6587\u672C\u8349\u7A3F\uFF0C\u6216\u5347\u7EA7 DSH \u540E\u91CD\u8BD5\u3002",
1090
1135
  "error.phase": "\u5F53\u524D\u8F93\u5165\u6B63\u88AB\u5360\u7528\uFF08\u63D0\u4EA4\u4E2D\uFF09\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5\u3002",
1091
1136
  "error.disabled": "\u63D0\u793A\u8BCD\u589E\u5F3A\u5DF2\u5728\u63D2\u4EF6\u8BBE\u7F6E\u4E2D\u5173\u95ED\u3002",
1092
1137
  "error.rejected": "\u589E\u5F3A\u8BF7\u6C42\u88AB\u62D2\u7EDD\u3002",
@@ -1184,7 +1229,7 @@ var zh = {
1184
1229
  "settings.strategy.extend": "\u8FFD\u52A0\u5728\u5185\u7F6E\u7B56\u7565\u540E",
1185
1230
  "settings.reasoning.inherit": "\u63D0\u4F9B\u65B9\u9ED8\u8BA4",
1186
1231
  "settings.reasoning.loading": "\u6B63\u5728\u8BFB\u53D6\u8BE5\u6A21\u578B\u7684\u6863\u4F4D\u2026",
1187
- "settings.reasoning.unavailable": "\u65E0\u6CD5\u8BFB\u53D6\u8BE5\u6A21\u578B\u7684\u6863\u4F4D\uFF0C\u4EC5\u53EF\u8DDF\u968F\u63D0\u4F9B\u65B9\u9ED8\u8BA4\u3002",
1232
+ "settings.reasoning.unavailable": "\u65E0\u6CD5\u8BFB\u53D6\u8BE5\u6A21\u578B\u7684\u6863\u4F4D\u5217\u8868\uFF1B\u5DF2\u4FDD\u5B58\u7684\u6863\u4F4D\u4ECD\u4F1A\u7167\u5E38\u53D1\u9001\u3002",
1188
1233
  "settings.reasoning.noTiers": "\u8BE5\u6A21\u578B\u672A\u58F0\u660E\u63A8\u7406\u6863\u4F4D\uFF0C\u8C03\u7528\u65F6\u5C06\u8DDF\u968F\u63D0\u4F9B\u65B9\u9ED8\u8BA4\u3002",
1189
1234
  "settings.reasoning.unsupported": "\u5F53\u524D\u503C\u300C{effort}\u300D\u4E0D\u5728\u8BE5\u6A21\u578B\u652F\u6301\u7684\u6863\u4F4D\u4E2D\u3002",
1190
1235
  "settings.reasoning.current": "\u5F53\u524D\u503C\uFF1A{value}",
@@ -1208,10 +1253,7 @@ var en = {
1208
1253
  "panel.enhanced": "Enhanced result",
1209
1254
  "panel.apply": "Fill into input box",
1210
1255
  "panel.regenerate": "Regenerate",
1211
- "panel.appliedShort": "Replaced \u2713",
1212
- "panel.undoneShort": "Undone \u2713",
1213
- "panel.regeneratedShort": "Regenerated \u2713",
1214
- "panel.copiedShort": "Copied \u2713",
1256
+ "panel.regenerated": "Regenerated",
1215
1257
  "panel.copy": "Copy result",
1216
1258
  "panel.copied": "Copied",
1217
1259
  "panel.copyFailed": "Copy failed",
@@ -1231,8 +1273,8 @@ var en = {
1231
1273
  "undo.dismiss": "Dismiss",
1232
1274
  "error.empty": "The input box is empty \u2014 type a prompt to enhance first.",
1233
1275
  "error.tooLong": "The draft is {count} characters, above the {max} cap (Unicode characters, not tokens). It is never auto-truncated (that would change your meaning) \u2014 please shorten it.",
1234
- "error.attachmentsOnly": "The composer only has attachments; add the text you want enhanced.",
1235
1276
  "error.occurrences": "The draft contains commands or file references, which are not supported yet \u2014 remove them first.",
1277
+ "error.chipsUnknown": "The composer reference state could not be read on this host, so the enhancement was blocked to avoid overwriting a command or file reference. Clear the input box and type plain text, or update DSH, then retry.",
1236
1278
  "error.phase": "The input box is busy (submitting) \u2014 try again in a moment.",
1237
1279
  "error.disabled": "Prompt enhance is disabled in the plugin settings.",
1238
1280
  "error.rejected": "The enhance request was rejected.",
@@ -1330,7 +1372,7 @@ var en = {
1330
1372
  "settings.strategy.extend": "Append after the built-in strategy",
1331
1373
  "settings.reasoning.inherit": "Provider default",
1332
1374
  "settings.reasoning.loading": "Reading this model\u2019s tiers\u2026",
1333
- "settings.reasoning.unavailable": "Could not read this model\u2019s tiers; only \u201Cfollow provider default\u201D is available.",
1375
+ "settings.reasoning.unavailable": "Could not read this model\u2019s tier list; your saved tier is still sent.",
1334
1376
  "settings.reasoning.noTiers": "This model declares no reasoning tiers; calls follow the provider default.",
1335
1377
  "settings.reasoning.unsupported": "The current value \u201C{effort}\u201D is not one of this model\u2019s tiers.",
1336
1378
  "settings.reasoning.current": "Current value: {value}",
@@ -1349,16 +1391,19 @@ var CSS = `
1349
1391
  .dsh-pe-dock { width: 100%; }
1350
1392
  .dsh-pe-panel {
1351
1393
  box-sizing: border-box;
1352
- --pe-bg: #1f2127;
1353
- --pe-fg: #e6e8ee;
1354
- --pe-fg-dim: rgba(230, 232, 238, 0.55);
1355
- --pe-border: rgba(127, 127, 127, 0.35);
1356
- --pe-separator: rgba(127, 127, 127, 0.25);
1394
+ --pe-bg: var(--dsw-alias-bg-layer-1, #1f2127);
1395
+ --pe-fg: var(--dsw-alias-label-primary, #e6e8ee);
1396
+ --pe-fg-dim: var(--dsw-alias-label-secondary, rgba(230, 232, 238, 0.55));
1397
+ --pe-border: var(--dsw-alias-border-l2, rgba(127, 127, 127, 0.35));
1398
+ --pe-separator: var(--dsw-alias-border-l1, rgba(127, 127, 127, 0.25));
1399
+ /* No hover token exists: a neutral grey alpha is already theme-agnostic. */
1357
1400
  --pe-hover: rgba(127, 127, 127, 0.18);
1358
- --pe-danger: #ffb4a8;
1359
- --pe-warn-fg: #e8c07d;
1360
- --pe-warn-border: rgba(230, 158, 60, 0.35);
1361
- --pe-warn-bg: rgba(230, 158, 60, 0.12);
1401
+ --pe-danger: var(--dsw-alias-state-error-primary, #ffb4a8);
1402
+ --pe-warn-fg: var(--dsw-alias-state-warn-primary, #e8c07d);
1403
+ /* Tints of the themed warning color, so the banner cannot keep an amber cast
1404
+ from the other scheme. */
1405
+ --pe-warn-border: color-mix(in srgb, var(--dsw-alias-state-warn-primary, #e8c07d) 35%, transparent);
1406
+ --pe-warn-bg: color-mix(in srgb, var(--dsw-alias-state-warn-primary, #e8c07d) 12%, transparent);
1362
1407
  display: flex;
1363
1408
  flex-direction: column;
1364
1409
  width: 100%;
@@ -1370,20 +1415,6 @@ var CSS = `
1370
1415
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03), 0 4px 14px rgba(0, 0, 0, 0.05);
1371
1416
  overflow: hidden;
1372
1417
  }
1373
- @media (prefers-color-scheme: light) {
1374
- .dsh-pe-panel {
1375
- --pe-bg: #ffffff;
1376
- --pe-fg: #1c1e24;
1377
- --pe-fg-dim: rgba(28, 30, 36, 0.55);
1378
- --pe-border: rgba(0, 0, 0, 0.18);
1379
- --pe-separator: rgba(0, 0, 0, 0.12);
1380
- --pe-hover: rgba(0, 0, 0, 0.08);
1381
- --pe-danger: #a63a2e;
1382
- --pe-warn-fg: #8a5a00;
1383
- --pe-warn-border: rgba(176, 122, 0, 0.4);
1384
- --pe-warn-bg: rgba(230, 158, 60, 0.15);
1385
- }
1386
- }
1387
1418
  .dsh-pe-head {
1388
1419
  display: flex;
1389
1420
  align-items: center;
@@ -1411,16 +1442,6 @@ var CSS = `
1411
1442
  opacity: 0.72;
1412
1443
  white-space: nowrap;
1413
1444
  }
1414
- .dsh-pe-applied {
1415
- font-size: 10.5px;
1416
- font-weight: 500;
1417
- line-height: 1;
1418
- padding: 3px 7px;
1419
- border-radius: 999px;
1420
- color: var(--dsw-alias-state-success-primary, #2da44e);
1421
- border: 1px solid currentColor;
1422
- white-space: nowrap;
1423
- }
1424
1445
  .dsh-pe-close {
1425
1446
  border: none; background: transparent; color: inherit; opacity: 0.6;
1426
1447
  font-size: 15px; cursor: pointer; padding: 2px 6px; border-radius: 4px;
@@ -1475,7 +1496,7 @@ var CSS = `
1475
1496
  .dsh-pe-spin.small { width: 11px; height: 11px; border-width: 1px; }
1476
1497
  .dsh-pe-spin {
1477
1498
  width: 22px; height: 22px; border-radius: 50%;
1478
- border: 2px solid var(--pe-separator); border-top-color: #6ea8ff;
1499
+ border: 2px solid var(--pe-separator); border-top-color: var(--dsw-alias-brand-primary, #6ea8ff);
1479
1500
  animation: dsh-pe-spin 0.9s linear infinite;
1480
1501
  }
1481
1502
  .dsh-pe-foot {
@@ -1504,17 +1525,41 @@ var CSS = `
1504
1525
  cursor: pointer;
1505
1526
  }
1506
1527
  .dsh-pe-btn-action.primary {
1507
- min-width: 112px;
1508
1528
  border-color: transparent;
1509
- background: #3f76e1;
1510
- color: #fff;
1529
+ /* Fill and label are a PAIR: the alias layer flips brand-primary from
1530
+ near-black (light theme) to near-white (dark theme), so the label has to
1531
+ flip with it \u2014 a hardcoded foreground turns the dark theme into
1532
+ white-on-white. label-primary-inverted is the color the shell itself
1533
+ paints onto an inverted surface; the fallback chain keeps an inverted label
1534
+ on hosts that predate that token. */
1535
+ background: var(--dsw-alias-brand-primary, #3f76e1);
1536
+ color: var(--dsw-alias-label-primary-inverted, var(--dsw-alias-bg-base, #ffffff));
1537
+ }
1538
+ .dsh-pe-btn-action.primary:hover {
1539
+ /* Blend toward the panel surface, not toward white: in the dark theme white
1540
+ IS the fill, so a white-ward blend would show no hover change at all. */
1541
+ background: color-mix(in srgb, var(--dsw-alias-brand-primary, #3f76e1) 88%, var(--dsw-alias-bg-layer-1, #1f2127));
1511
1542
  }
1512
- .dsh-pe-btn-action.primary:hover { background: #4d82ec; }
1513
1543
  .dsh-pe-btn-action.plain { background: transparent; color: inherit; }
1514
1544
  .dsh-pe-btn-action.plain:hover { background: var(--pe-hover); }
1515
- .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; }
1516
1553
  .dsh-pe-btn-action:disabled { opacity: 0.45; cursor: default; }
1517
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
+
1518
1563
  .dsh-pe-stale {
1519
1564
  padding: 6px 10px;
1520
1565
  font-size: 12px;
@@ -2048,7 +2093,7 @@ var SETTINGS_SECTION_ORDER = 70;
2048
2093
  var SETTINGS_SECTION_LABEL = "\u63D0\u793A\u8BCD\u589E\u5F3A";
2049
2094
  var SETTINGS_ROW_CONFIG_SLOT = "plugins.row.config";
2050
2095
  var SETTINGS_NAMESPACE = "dsh-prompt-enhance";
2051
- var SETTINGS_BUNDLE = "@surfishs/dsh-prompt-enhance";
2096
+ var SETTINGS_BUNDLE = true ? "@surfishs/dsh-prompt-enhance" : "@surfishs/dsh-prompt-enhance";
2052
2097
  var SETTINGS_ROW_ID = "dsh-prompt-enhance";
2053
2098
  var SETTINGS_ROW_CONFIG_KEY = `${SETTINGS_BUNDLE}#${SETTINGS_ROW_ID}`;
2054
2099
  function settingsBooleanField(key) {
@@ -2340,7 +2385,7 @@ var REPOSITORY_URL = "https://github.com/surfishs/dsh-prompt-enhance";
2340
2385
  var NPM_URL = "https://www.npmjs.com/package/@surfishs/dsh-prompt-enhance";
2341
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";
2342
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";
2343
- var PLUGIN_VERSION = true ? "0.0.9" : "0.0.0";
2388
+ var PLUGIN_VERSION = true ? "0.1.1" : "0.0.0";
2344
2389
  var HEADER_STYLE = { display: "flex", flexDirection: "column", gap: 12, padding: "2px 0" };
2345
2390
  var HEADER_ROW_STYLE = { display: "flex", alignItems: "center", gap: 10, flexWrap: "wrap" };
2346
2391
  var HEADER_TITLE_STYLE = {