@surfishs/dsh-prompt-enhance 0.0.4 → 0.0.5
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/README.en.md +24 -2
- package/README.md +24 -2
- package/docs/images/panel.png +0 -0
- package/lib/client.js +179 -130
- package/package.json +1 -1
- package/src/client/ResultDock.tsx +3 -93
- package/src/client/ResultPanel.tsx +27 -25
- package/src/client/UndoBar.tsx +14 -7
- package/src/client/locales.ts +2 -2
- package/src/client/styles.ts +47 -10
- package/src/client/useDockAlignment.ts +103 -0
package/README.en.md
CHANGED
|
@@ -35,6 +35,20 @@
|
|
|
35
35
|
|
|
36
36
|
## Install
|
|
37
37
|
|
|
38
|
+
### Let an agent install it
|
|
39
|
+
|
|
40
|
+
No command line needed. Send the block below to an agent that can run commands on your machine (DSH desktop or web):
|
|
41
|
+
|
|
42
|
+
```text
|
|
43
|
+
Install the DeepSeek Harness plugin @surfishs/dsh-prompt-enhance.
|
|
44
|
+
|
|
45
|
+
1. First confirm my DSH profile name: usually desktop for the desktop app and web for the web build; ask me if unsure.
|
|
46
|
+
2. Run: dsh plugin --profile <profile> add @surfishs/dsh-prompt-enhance
|
|
47
|
+
3. If the npm install fails, use: dsh plugin --profile <profile> add github:surfishs/dsh-prompt-enhance
|
|
48
|
+
4. After installing, ask me to restart DSH and confirm the plugin appears in the plugin list.
|
|
49
|
+
5. Do not change my other plugins or DSH configuration.
|
|
50
|
+
```
|
|
51
|
+
|
|
38
52
|
From npm:
|
|
39
53
|
|
|
40
54
|
```bash
|
|
@@ -66,9 +80,17 @@ dsh plugin --profile <profile> remove @surfishs/dsh-prompt-enhance
|
|
|
66
80
|
|
|
67
81
|
## Usage
|
|
68
82
|
|
|
69
|
-
|
|
83
|
+
1. **Start**: leave a draft in the composer and click the enhance button in the toolbar (or your configured shortcut).
|
|
84
|
+
2. **Review**: the result appears in a card docked above the composer. You can:
|
|
85
|
+
- **Apply**: write it back; the card stays open with a Replaced chip;
|
|
86
|
+
- **Copy**: copy the result;
|
|
87
|
+
- **Regenerate**: run the current draft again.
|
|
88
|
+
3. **Undo**: after applying, click Undo to restore; after closing the card, the undo bar remains above the composer.
|
|
89
|
+
4. **Close**: sending the draft closes the card automatically; Escape also closes it.
|
|
90
|
+
|
|
91
|
+
An empty or attachment-only draft dims the button and makes it unclickable; over-length or reference-chip drafts are rejected locally. A result that hits the token cap is marked as possibly incomplete.
|
|
70
92
|
|
|
71
|
-
`/enhance <text
|
|
93
|
+
`/enhance <text>`: rewrite any text from the slash menu; the result is copyable and never enters model history.
|
|
72
94
|
|
|
73
95
|
## Configuration
|
|
74
96
|
|
package/README.md
CHANGED
|
@@ -35,6 +35,20 @@
|
|
|
35
35
|
|
|
36
36
|
## 安装
|
|
37
37
|
|
|
38
|
+
### 让 Agent 帮你安装
|
|
39
|
+
|
|
40
|
+
不用自己敲命令。把下面整段发给能操作本机终端的 Agent(DSH 桌面版、Web 版都可以):
|
|
41
|
+
|
|
42
|
+
```text
|
|
43
|
+
帮我安装 DeepSeek Harness 插件 @surfishs/dsh-prompt-enhance。
|
|
44
|
+
|
|
45
|
+
1. 先确认我的 DSH profile 名:桌面版通常是 desktop,Web 版通常是 web;不确定就问我。
|
|
46
|
+
2. 执行:dsh plugin --profile <profile> add @surfishs/dsh-prompt-enhance
|
|
47
|
+
3. 如果 npm 安装失败,改用:dsh plugin --profile <profile> add github:surfishs/dsh-prompt-enhance
|
|
48
|
+
4. 安装完成后提示我重启 DSH,并让我确认插件出现在插件列表中。
|
|
49
|
+
5. 不要修改我的其他插件或 DSH 配置。
|
|
50
|
+
```
|
|
51
|
+
|
|
38
52
|
从 npm 安装:
|
|
39
53
|
|
|
40
54
|
```bash
|
|
@@ -66,9 +80,17 @@ dsh plugin --profile <profile> remove @surfishs/dsh-prompt-enhance
|
|
|
66
80
|
|
|
67
81
|
## 使用
|
|
68
82
|
|
|
69
|
-
|
|
83
|
+
1. **开始**:在输入框写下草稿,点工具栏的增强按钮(或你设置的快捷键)。
|
|
84
|
+
2. **查看结果**:结果出现在输入框上方的停靠卡里,可以:
|
|
85
|
+
- **回填**:写回输入框,卡片保持打开并显示「已替换」;
|
|
86
|
+
- **复制**:复制结果;
|
|
87
|
+
- **重新生成**:按当前输入再生成一版。
|
|
88
|
+
3. **撤销**:回填后点「撤销」恢复;关闭卡片后,输入框上方仍保留撤销条。
|
|
89
|
+
4. **关闭**:发送消息时卡片自动收起,按 `Esc` 也可以关闭。
|
|
90
|
+
|
|
91
|
+
输入为空或只有附件时,按钮会变灰、不可点;超长或含引用块会被本地拒绝。输出达到 Token 上限时,会提示结果可能不完整。
|
|
70
92
|
|
|
71
|
-
`/enhance
|
|
93
|
+
`/enhance <文本>`:从斜杠面板改写任意文本,结果可复制,不进入模型历史。
|
|
72
94
|
|
|
73
95
|
## 配置
|
|
74
96
|
|
package/docs/images/panel.png
CHANGED
|
Binary file
|
package/lib/client.js
CHANGED
|
@@ -610,7 +610,7 @@ function EnhanceButton(props) {
|
|
|
610
610
|
}
|
|
611
611
|
|
|
612
612
|
// src/client/ResultDock.tsx
|
|
613
|
-
var
|
|
613
|
+
var import_react5 = require("react");
|
|
614
614
|
|
|
615
615
|
// src/client/ResultPanel.tsx
|
|
616
616
|
var import_react3 = require("react");
|
|
@@ -761,17 +761,19 @@ function ResultPanel(props) {
|
|
|
761
761
|
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(SparkleFishIcon, { size: 15 }),
|
|
762
762
|
t("panel.title")
|
|
763
763
|
] }),
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
t("panel.elapsed", { ms: formatMs(state.result.elapsedMs) }),
|
|
768
|
-
state.result.usage === void 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
|
|
764
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "dsh-pe-head-actions", children: [
|
|
765
|
+
state.phase === "result" && state.result !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "dsh-pe-badge", children: [
|
|
766
|
+
t("panel.model", { provider: state.result.provider, model: state.result.model }),
|
|
769
767
|
" \xB7 ",
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
768
|
+
t("panel.elapsed", { ms: formatMs(state.result.elapsedMs) }),
|
|
769
|
+
state.result.usage === void 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
|
|
770
|
+
" \xB7 ",
|
|
771
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { title: tokenDetail(state.result.usage), children: t("panel.tokens", { total: formatTokens(totalTokensOf(state.result.usage)) }) })
|
|
772
|
+
] })
|
|
773
|
+
] }),
|
|
774
|
+
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,
|
|
775
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { type: "button", className: "dsh-pe-close", "aria-label": t("panel.close"), onClick: onCancel, children: "\u2715" })
|
|
776
|
+
] })
|
|
775
777
|
] }),
|
|
776
778
|
state.phase === "loading" && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "dsh-pe-loading", children: state.streaming === void 0 || state.streaming === "" ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
|
|
777
779
|
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "dsh-pe-spin", "aria-hidden": true }),
|
|
@@ -822,17 +824,83 @@ function ResultPanel(props) {
|
|
|
822
824
|
] });
|
|
823
825
|
}
|
|
824
826
|
|
|
827
|
+
// src/client/useDockAlignment.ts
|
|
828
|
+
var import_react4 = require("react");
|
|
829
|
+
function useDockAlignment(active) {
|
|
830
|
+
const rootRef = (0, import_react4.useRef)(null);
|
|
831
|
+
(0, import_react4.useEffect)(() => {
|
|
832
|
+
if (!active) return;
|
|
833
|
+
const root = rootRef.current;
|
|
834
|
+
if (root === null) return;
|
|
835
|
+
let frame = 0;
|
|
836
|
+
const align = () => {
|
|
837
|
+
const parent = root.parentElement;
|
|
838
|
+
if (parent === null) return;
|
|
839
|
+
root.style.transform = "";
|
|
840
|
+
const previousMargin = parseFloat(root.style.marginLeft) || 0;
|
|
841
|
+
const rootRect = root.getBoundingClientRect();
|
|
842
|
+
const editors = Array.from(document.querySelectorAll('textarea, [contenteditable="true"], [role="textbox"]'));
|
|
843
|
+
const editor = editors.find((node2) => {
|
|
844
|
+
const rect = node2.getBoundingClientRect();
|
|
845
|
+
return rect.width > 0 && rect.height > 0 && rect.top >= rootRect.bottom - 4;
|
|
846
|
+
});
|
|
847
|
+
if (editor === void 0) {
|
|
848
|
+
root.style.width = "";
|
|
849
|
+
root.style.marginLeft = "";
|
|
850
|
+
root.style.transform = "";
|
|
851
|
+
return;
|
|
852
|
+
}
|
|
853
|
+
const editorRect = editor.getBoundingClientRect();
|
|
854
|
+
const candidates = [];
|
|
855
|
+
let node = editor;
|
|
856
|
+
for (let depth = 0; depth < 12 && node !== null; depth++) {
|
|
857
|
+
const rect = node.getBoundingClientRect();
|
|
858
|
+
const style = getComputedStyle(node);
|
|
859
|
+
if (rect.width >= editorRect.width && rect.width > 360 && rect.height > 48 && (parseFloat(style.borderTopLeftRadius) || 0) >= 4 && style.backgroundColor !== "rgba(0, 0, 0, 0)") {
|
|
860
|
+
candidates.push({ node, rect });
|
|
861
|
+
}
|
|
862
|
+
node = node.parentElement;
|
|
863
|
+
}
|
|
864
|
+
const editorCenter = editorRect.left + editorRect.width / 2;
|
|
865
|
+
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];
|
|
866
|
+
if (cardEntry === void 0) return;
|
|
867
|
+
const cardRect = cardEntry.rect;
|
|
868
|
+
const width = `${cardRect.width}px`;
|
|
869
|
+
if (root.style.width !== width) root.style.width = width;
|
|
870
|
+
const afterWidth = root.getBoundingClientRect();
|
|
871
|
+
const currentMargin = parseFloat(root.style.marginLeft) || 0;
|
|
872
|
+
const marginLeft = `${cardRect.left - (afterWidth.left - currentMargin)}px`;
|
|
873
|
+
if (root.style.marginLeft !== marginLeft) root.style.marginLeft = marginLeft;
|
|
874
|
+
};
|
|
875
|
+
const schedule = () => {
|
|
876
|
+
cancelAnimationFrame(frame);
|
|
877
|
+
frame = requestAnimationFrame(align);
|
|
878
|
+
};
|
|
879
|
+
schedule();
|
|
880
|
+
schedule();
|
|
881
|
+
window.addEventListener("resize", schedule);
|
|
882
|
+
const observer = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(schedule);
|
|
883
|
+
observer?.observe(document.documentElement);
|
|
884
|
+
return () => {
|
|
885
|
+
cancelAnimationFrame(frame);
|
|
886
|
+
window.removeEventListener("resize", schedule);
|
|
887
|
+
observer?.disconnect();
|
|
888
|
+
};
|
|
889
|
+
}, [active]);
|
|
890
|
+
return rootRef;
|
|
891
|
+
}
|
|
892
|
+
|
|
825
893
|
// src/client/ResultDock.tsx
|
|
826
894
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
827
895
|
function ResultDock(props) {
|
|
828
896
|
const { t, sessionId, useInput, inputActions } = props;
|
|
829
897
|
const uiKey = useSessionKey(sessionId, inputActions);
|
|
830
|
-
const
|
|
831
|
-
const
|
|
832
|
-
const [
|
|
833
|
-
const [
|
|
834
|
-
const
|
|
835
|
-
const
|
|
898
|
+
const panel = (0, import_react5.useSyncExternalStore)(subscribe, getPanel);
|
|
899
|
+
const rootRef = useDockAlignment(panel !== void 0 && panel.sessionId === uiKey);
|
|
900
|
+
const [undone, setUndone] = (0, import_react5.useState)(false);
|
|
901
|
+
const [regenerated, setRegenerated] = (0, import_react5.useState)(false);
|
|
902
|
+
const [pendingRegenerate, setPendingRegenerate] = (0, import_react5.useState)(false);
|
|
903
|
+
const previousResultRef = (0, import_react5.useRef)(void 0);
|
|
836
904
|
const draft = useInput((state) => {
|
|
837
905
|
const value = state.draft;
|
|
838
906
|
return typeof value === "string" ? value : "";
|
|
@@ -846,8 +914,8 @@ function ResultDock(props) {
|
|
|
846
914
|
const sessionQueued = useSession === void 0 ? 0 : Number(useSession((state) => state.queue?.length ?? 0));
|
|
847
915
|
const entry = peekUndo(uiKey);
|
|
848
916
|
const applied = entry !== void 0 && entry.applied === draft;
|
|
849
|
-
const prevSession = (0,
|
|
850
|
-
(0,
|
|
917
|
+
const prevSession = (0, import_react5.useRef)({ running: sessionRunning, queued: sessionQueued });
|
|
918
|
+
(0, import_react5.useEffect)(() => {
|
|
851
919
|
const prev = prevSession.current;
|
|
852
920
|
prevSession.current = { running: sessionRunning, queued: sessionQueued };
|
|
853
921
|
if (panel === void 0 || panel.sessionId !== uiKey) return;
|
|
@@ -855,7 +923,7 @@ function ResultDock(props) {
|
|
|
855
923
|
closePanel();
|
|
856
924
|
}
|
|
857
925
|
}, [phase, sessionRunning, sessionQueued, panel, uiKey]);
|
|
858
|
-
(0,
|
|
926
|
+
(0, import_react5.useEffect)(() => {
|
|
859
927
|
if (panel === void 0 || panel.sessionId !== uiKey) return;
|
|
860
928
|
const onKeyDown = (event) => {
|
|
861
929
|
if (event.defaultPrevented || event.isComposing || event.key !== "Escape") return;
|
|
@@ -865,12 +933,12 @@ function ResultDock(props) {
|
|
|
865
933
|
document.addEventListener("keydown", onKeyDown);
|
|
866
934
|
return () => document.removeEventListener("keydown", onKeyDown);
|
|
867
935
|
}, [panel, uiKey]);
|
|
868
|
-
(0,
|
|
936
|
+
(0, import_react5.useEffect)(() => {
|
|
869
937
|
if (!undone) return;
|
|
870
938
|
const timer = setTimeout(() => setUndone(false), 2500);
|
|
871
939
|
return () => clearTimeout(timer);
|
|
872
940
|
}, [undone]);
|
|
873
|
-
(0,
|
|
941
|
+
(0, import_react5.useEffect)(() => {
|
|
874
942
|
if (!pendingRegenerate) return;
|
|
875
943
|
if (panel === void 0 || panel.sessionId !== uiKey) {
|
|
876
944
|
setPendingRegenerate(false);
|
|
@@ -885,76 +953,16 @@ function ResultDock(props) {
|
|
|
885
953
|
setRegenerated(true);
|
|
886
954
|
}
|
|
887
955
|
}, [panel, pendingRegenerate, uiKey]);
|
|
888
|
-
(0,
|
|
956
|
+
(0, import_react5.useEffect)(() => {
|
|
889
957
|
if (!regenerated) return;
|
|
890
958
|
const timer = setTimeout(() => setRegenerated(false), 2500);
|
|
891
959
|
return () => clearTimeout(timer);
|
|
892
960
|
}, [regenerated]);
|
|
893
|
-
(0,
|
|
961
|
+
(0, import_react5.useEffect)(() => {
|
|
894
962
|
if (!pendingRegenerate) return;
|
|
895
963
|
const timer = setTimeout(() => setPendingRegenerate(false), 15e3);
|
|
896
964
|
return () => clearTimeout(timer);
|
|
897
965
|
}, [pendingRegenerate]);
|
|
898
|
-
(0, import_react4.useEffect)(() => {
|
|
899
|
-
if (panel === void 0 || panel.sessionId !== uiKey) return;
|
|
900
|
-
const root = rootRef.current;
|
|
901
|
-
if (root === null) return;
|
|
902
|
-
let frame = 0;
|
|
903
|
-
const align = () => {
|
|
904
|
-
const parent = root.parentElement;
|
|
905
|
-
if (parent === null) return;
|
|
906
|
-
root.style.transform = "";
|
|
907
|
-
const previousMargin = parseFloat(root.style.marginLeft) || 0;
|
|
908
|
-
const rootRect = root.getBoundingClientRect();
|
|
909
|
-
const baseLeft = rootRect.left - previousMargin;
|
|
910
|
-
const editors = Array.from(document.querySelectorAll('textarea, [contenteditable="true"], [role="textbox"]'));
|
|
911
|
-
const editor = editors.find((node2) => {
|
|
912
|
-
const rect = node2.getBoundingClientRect();
|
|
913
|
-
return rect.width > 0 && rect.height > 0 && rect.top >= rootRect.bottom - 4;
|
|
914
|
-
});
|
|
915
|
-
if (editor === void 0) {
|
|
916
|
-
root.style.width = "";
|
|
917
|
-
root.style.marginLeft = "";
|
|
918
|
-
root.style.transform = "";
|
|
919
|
-
return;
|
|
920
|
-
}
|
|
921
|
-
const editorRect = editor.getBoundingClientRect();
|
|
922
|
-
const candidates = [];
|
|
923
|
-
let node = editor;
|
|
924
|
-
for (let depth = 0; depth < 12 && node !== null; depth++) {
|
|
925
|
-
const rect = node.getBoundingClientRect();
|
|
926
|
-
const style = getComputedStyle(node);
|
|
927
|
-
if (rect.width >= editorRect.width && rect.width > 360 && rect.height > 48 && (parseFloat(style.borderTopLeftRadius) || 0) >= 4 && style.backgroundColor !== "rgba(0, 0, 0, 0)") {
|
|
928
|
-
candidates.push({ node, rect });
|
|
929
|
-
}
|
|
930
|
-
node = node.parentElement;
|
|
931
|
-
}
|
|
932
|
-
const editorCenter = editorRect.left + editorRect.width / 2;
|
|
933
|
-
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];
|
|
934
|
-
if (cardEntry === void 0) return;
|
|
935
|
-
const cardRect = cardEntry.rect;
|
|
936
|
-
const width = `${cardRect.width}px`;
|
|
937
|
-
if (root.style.width !== width) root.style.width = width;
|
|
938
|
-
const afterWidth = root.getBoundingClientRect();
|
|
939
|
-
const currentMargin = parseFloat(root.style.marginLeft) || 0;
|
|
940
|
-
const marginLeft = `${cardRect.left - (afterWidth.left - currentMargin)}px`;
|
|
941
|
-
if (root.style.marginLeft !== marginLeft) root.style.marginLeft = marginLeft;
|
|
942
|
-
};
|
|
943
|
-
const schedule = () => {
|
|
944
|
-
cancelAnimationFrame(frame);
|
|
945
|
-
frame = requestAnimationFrame(align);
|
|
946
|
-
};
|
|
947
|
-
schedule();
|
|
948
|
-
schedule();
|
|
949
|
-
window.addEventListener("resize", schedule);
|
|
950
|
-
const observer = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(schedule);
|
|
951
|
-
observer?.observe(document.documentElement);
|
|
952
|
-
return () => {
|
|
953
|
-
cancelAnimationFrame(frame);
|
|
954
|
-
window.removeEventListener("resize", schedule);
|
|
955
|
-
observer?.disconnect();
|
|
956
|
-
};
|
|
957
|
-
}, [panel, uiKey]);
|
|
958
966
|
if (panel === void 0 || panel.sessionId !== uiKey) return null;
|
|
959
967
|
const apply2 = () => {
|
|
960
968
|
if (panel.phase !== "result" || panel.result === void 0) return;
|
|
@@ -995,7 +1003,7 @@ function ResultDock(props) {
|
|
|
995
1003
|
}
|
|
996
1004
|
|
|
997
1005
|
// src/client/UndoBar.tsx
|
|
998
|
-
var
|
|
1006
|
+
var import_react6 = require("react");
|
|
999
1007
|
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
1000
1008
|
function UndoBar(props) {
|
|
1001
1009
|
const { t, sessionId, useInput, inputActions } = props;
|
|
@@ -1004,14 +1012,15 @@ function UndoBar(props) {
|
|
|
1004
1012
|
const value = state.draft;
|
|
1005
1013
|
return typeof value === "string" ? value : "";
|
|
1006
1014
|
});
|
|
1007
|
-
(0,
|
|
1015
|
+
(0, import_react6.useSyncExternalStore)(subscribe, getVersion);
|
|
1008
1016
|
const entry = peekUndo(uiKey);
|
|
1009
|
-
(0,
|
|
1017
|
+
(0, import_react6.useEffect)(() => {
|
|
1010
1018
|
if (entry !== void 0 && entry.applied !== draft) popUndo(uiKey);
|
|
1011
1019
|
}, [draft, entry, uiKey]);
|
|
1012
1020
|
const panel = getPanel();
|
|
1013
|
-
|
|
1014
|
-
|
|
1021
|
+
const visible = (panel === void 0 || panel.sessionId !== uiKey) && entry !== void 0 && entry.applied === draft;
|
|
1022
|
+
const rootRef = useDockAlignment(visible);
|
|
1023
|
+
if (!visible) return null;
|
|
1015
1024
|
const undo = () => {
|
|
1016
1025
|
inputActions.setDraft(entry.original);
|
|
1017
1026
|
popUndo(uiKey);
|
|
@@ -1019,12 +1028,15 @@ function UndoBar(props) {
|
|
|
1019
1028
|
const dismiss = () => {
|
|
1020
1029
|
popUndo(uiKey);
|
|
1021
1030
|
};
|
|
1022
|
-
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "dsh-pe-undo", children: [
|
|
1031
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { ref: rootRef, className: "dsh-pe-dock", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "dsh-pe-undo", children: [
|
|
1023
1032
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "dsh-pe-undo-check", "aria-hidden": true, children: "\u2713" }),
|
|
1024
1033
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: t("undo.applied") }),
|
|
1025
|
-
/* @__PURE__ */ (0, import_jsx_runtime6.
|
|
1034
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("button", { type: "button", className: "dsh-pe-undo-link", onClick: undo, children: [
|
|
1035
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(UndoIcon, {}),
|
|
1036
|
+
t("undo.undo")
|
|
1037
|
+
] }),
|
|
1026
1038
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { type: "button", className: "dsh-pe-undo-x", "aria-label": t("undo.dismiss"), onClick: dismiss, children: "\u2715" })
|
|
1027
|
-
] });
|
|
1039
|
+
] }) });
|
|
1028
1040
|
}
|
|
1029
1041
|
|
|
1030
1042
|
// src/client/locales.ts
|
|
@@ -1060,7 +1072,7 @@ var zh = {
|
|
|
1060
1072
|
"panel.tokens.output": "\u8F93\u51FA {count}",
|
|
1061
1073
|
"panel.tokens.cacheRead": "\u7F13\u5B58\u8BFB\u53D6 {count}",
|
|
1062
1074
|
"panel.tokens.cacheWrite": "\u7F13\u5B58\u5199\u5165 {count}",
|
|
1063
|
-
"undo.applied": "\u5DF2\
|
|
1075
|
+
"undo.applied": "\u5DF2\u66FF\u6362\u539F\u63D0\u793A\u8BCD",
|
|
1064
1076
|
"undo.undo": "\u64A4\u9500",
|
|
1065
1077
|
"undo.dismiss": "\u5173\u95ED\u63D0\u793A",
|
|
1066
1078
|
"error.empty": "\u8F93\u5165\u6846\u4E3A\u7A7A\uFF0C\u8BF7\u5148\u8F93\u5165\u8981\u589E\u5F3A\u7684\u63D0\u793A\u8BCD\u3002",
|
|
@@ -1198,7 +1210,7 @@ var en = {
|
|
|
1198
1210
|
"panel.tokens.output": "Output {count}",
|
|
1199
1211
|
"panel.tokens.cacheRead": "Cache read {count}",
|
|
1200
1212
|
"panel.tokens.cacheWrite": "Cache write {count}",
|
|
1201
|
-
"undo.applied": "Original
|
|
1213
|
+
"undo.applied": "Original draft replaced",
|
|
1202
1214
|
"undo.undo": "Undo",
|
|
1203
1215
|
"undo.dismiss": "Dismiss",
|
|
1204
1216
|
"error.empty": "The input box is empty \u2014 type a prompt to enhance first.",
|
|
@@ -1358,8 +1370,15 @@ var CSS = `
|
|
|
1358
1370
|
font-weight: 600;
|
|
1359
1371
|
}
|
|
1360
1372
|
.dsh-pe-head .dsh-pe-title { display: inline-flex; align-items: center; gap: 6px; }
|
|
1361
|
-
.dsh-pe-head .dsh-pe-
|
|
1373
|
+
.dsh-pe-head .dsh-pe-head-actions {
|
|
1374
|
+
display: flex;
|
|
1375
|
+
align-items: center;
|
|
1376
|
+
gap: 8px;
|
|
1362
1377
|
margin-left: auto;
|
|
1378
|
+
min-width: 0;
|
|
1379
|
+
}
|
|
1380
|
+
.dsh-pe-head .dsh-pe-badge {
|
|
1381
|
+
margin-left: 0;
|
|
1363
1382
|
border: 1px solid var(--pe-border);
|
|
1364
1383
|
border-radius: 999px;
|
|
1365
1384
|
padding: 1px 8px;
|
|
@@ -1510,22 +1529,52 @@ var CSS = `
|
|
|
1510
1529
|
display: flex;
|
|
1511
1530
|
align-items: center;
|
|
1512
1531
|
gap: 8px;
|
|
1513
|
-
|
|
1532
|
+
width: fit-content;
|
|
1533
|
+
margin-left: auto;
|
|
1534
|
+
padding: 3px 6px 3px 10px;
|
|
1535
|
+
border: 1px solid var(--dsw-alias-border-l2, rgba(128, 128, 128, 0.32));
|
|
1536
|
+
border-radius: 12px;
|
|
1537
|
+
background: var(--dsw-alias-bg-layer-1, transparent);
|
|
1514
1538
|
font-size: 12px;
|
|
1515
1539
|
color: inherit;
|
|
1516
|
-
opacity: 0.85;
|
|
1517
1540
|
}
|
|
1518
|
-
.dsh-pe-undo .dsh-pe-undo-check {
|
|
1541
|
+
.dsh-pe-undo .dsh-pe-undo-check {
|
|
1542
|
+
color: var(--dsw-alias-state-success-primary, #2da44e);
|
|
1543
|
+
font-weight: 600;
|
|
1544
|
+
}
|
|
1519
1545
|
.dsh-pe-undo-link {
|
|
1520
|
-
|
|
1521
|
-
|
|
1546
|
+
display: inline-flex;
|
|
1547
|
+
align-items: center;
|
|
1548
|
+
justify-content: center;
|
|
1549
|
+
gap: 6px;
|
|
1550
|
+
height: 28px;
|
|
1551
|
+
padding: 0 10px;
|
|
1552
|
+
border: 1px solid var(--dsw-alias-border-l2, rgba(128, 128, 128, 0.32));
|
|
1553
|
+
border-radius: 6px;
|
|
1554
|
+
background: transparent;
|
|
1555
|
+
color: inherit;
|
|
1556
|
+
font-size: 12px;
|
|
1557
|
+
cursor: pointer;
|
|
1558
|
+
transition: background-color 120ms ease;
|
|
1522
1559
|
}
|
|
1523
|
-
.dsh-pe-undo-link:hover { background: rgba(127,127,127,0.
|
|
1560
|
+
.dsh-pe-undo-link:hover { background: rgba(127, 127, 127, 0.16); }
|
|
1561
|
+
.dsh-pe-undo-link:active { background: rgba(127, 127, 127, 0.22); }
|
|
1524
1562
|
.dsh-pe-undo-x {
|
|
1525
|
-
|
|
1526
|
-
|
|
1563
|
+
display: inline-flex;
|
|
1564
|
+
align-items: center;
|
|
1565
|
+
justify-content: center;
|
|
1566
|
+
width: 28px;
|
|
1567
|
+
height: 28px;
|
|
1568
|
+
border: none;
|
|
1569
|
+
border-radius: 6px;
|
|
1570
|
+
background: transparent;
|
|
1571
|
+
color: inherit;
|
|
1572
|
+
opacity: 0.55;
|
|
1573
|
+
cursor: pointer;
|
|
1574
|
+
padding: 0;
|
|
1575
|
+
font-size: 12px;
|
|
1527
1576
|
}
|
|
1528
|
-
.dsh-pe-undo-x:hover { opacity: 1; }
|
|
1577
|
+
.dsh-pe-undo-x:hover { opacity: 1; background: var(--dsw-alias-bg-layer-2, rgba(128, 128, 128, 0.12)); }
|
|
1529
1578
|
`;
|
|
1530
1579
|
function ensureStyles() {
|
|
1531
1580
|
if (document.getElementById(STYLE_ID) !== null) return false;
|
|
@@ -1716,7 +1765,7 @@ function installClientSettingsSource(ctx, options) {
|
|
|
1716
1765
|
}
|
|
1717
1766
|
|
|
1718
1767
|
// src/client/settings-page.tsx
|
|
1719
|
-
var
|
|
1768
|
+
var import_react8 = require("react");
|
|
1720
1769
|
|
|
1721
1770
|
// src/shared/defaults.ts
|
|
1722
1771
|
var DEFAULT_VALUES = {
|
|
@@ -1790,7 +1839,7 @@ async function fetchReasoningCapabilities(provider, model, options = {}) {
|
|
|
1790
1839
|
}
|
|
1791
1840
|
|
|
1792
1841
|
// src/client/llm-catalog.ts
|
|
1793
|
-
var
|
|
1842
|
+
var import_react7 = require("react");
|
|
1794
1843
|
|
|
1795
1844
|
// src/shared/catalog.ts
|
|
1796
1845
|
var LLM_PROVIDERS_ENDPOINT = "/dsh-prompt-enhance/llm-providers";
|
|
@@ -1836,17 +1885,17 @@ async function fetchRouteCheck(provider, model, signal) {
|
|
|
1836
1885
|
return value;
|
|
1837
1886
|
}
|
|
1838
1887
|
function useLlmRouting(provider, model) {
|
|
1839
|
-
const [providers, setProviders] = (0,
|
|
1840
|
-
const [providersLoading, setProvidersLoading] = (0,
|
|
1841
|
-
const [providersFailed, setProvidersFailed] = (0,
|
|
1842
|
-
const [providersToken, setProvidersToken] = (0,
|
|
1843
|
-
const [models, setModels] = (0,
|
|
1844
|
-
const [modelsLoading, setModelsLoading] = (0,
|
|
1845
|
-
const [modelsFailed, setModelsFailed] = (0,
|
|
1846
|
-
const [modelsToken, setModelsToken] = (0,
|
|
1847
|
-
const [routeChecking, setRouteChecking] = (0,
|
|
1848
|
-
const [routeAvailable, setRouteAvailable] = (0,
|
|
1849
|
-
(0,
|
|
1888
|
+
const [providers, setProviders] = (0, import_react7.useState)([]);
|
|
1889
|
+
const [providersLoading, setProvidersLoading] = (0, import_react7.useState)(true);
|
|
1890
|
+
const [providersFailed, setProvidersFailed] = (0, import_react7.useState)(false);
|
|
1891
|
+
const [providersToken, setProvidersToken] = (0, import_react7.useState)(0);
|
|
1892
|
+
const [models, setModels] = (0, import_react7.useState)([]);
|
|
1893
|
+
const [modelsLoading, setModelsLoading] = (0, import_react7.useState)(false);
|
|
1894
|
+
const [modelsFailed, setModelsFailed] = (0, import_react7.useState)(false);
|
|
1895
|
+
const [modelsToken, setModelsToken] = (0, import_react7.useState)(0);
|
|
1896
|
+
const [routeChecking, setRouteChecking] = (0, import_react7.useState)(false);
|
|
1897
|
+
const [routeAvailable, setRouteAvailable] = (0, import_react7.useState)(void 0);
|
|
1898
|
+
(0, import_react7.useEffect)(() => {
|
|
1850
1899
|
const controller = new AbortController();
|
|
1851
1900
|
setProvidersLoading(true);
|
|
1852
1901
|
setProvidersFailed(false);
|
|
@@ -1862,7 +1911,7 @@ function useLlmRouting(provider, model) {
|
|
|
1862
1911
|
});
|
|
1863
1912
|
return () => controller.abort();
|
|
1864
1913
|
}, [providersToken]);
|
|
1865
|
-
(0,
|
|
1914
|
+
(0, import_react7.useEffect)(() => {
|
|
1866
1915
|
if (provider === "") {
|
|
1867
1916
|
setModels([]);
|
|
1868
1917
|
setModelsLoading(false);
|
|
@@ -1885,7 +1934,7 @@ function useLlmRouting(provider, model) {
|
|
|
1885
1934
|
});
|
|
1886
1935
|
return () => controller.abort();
|
|
1887
1936
|
}, [provider, modelsToken]);
|
|
1888
|
-
(0,
|
|
1937
|
+
(0, import_react7.useEffect)(() => {
|
|
1889
1938
|
if (provider === "" || model === "") {
|
|
1890
1939
|
setRouteChecking(false);
|
|
1891
1940
|
setRouteAvailable(void 0);
|
|
@@ -2133,7 +2182,7 @@ var REPOSITORY_URL = "https://github.com/surfishs/dsh-prompt-enhance";
|
|
|
2133
2182
|
var NPM_URL = "https://www.npmjs.com/package/@surfishs/dsh-prompt-enhance";
|
|
2134
2183
|
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";
|
|
2135
2184
|
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";
|
|
2136
|
-
var PLUGIN_VERSION = true ? "0.0.
|
|
2185
|
+
var PLUGIN_VERSION = true ? "0.0.5" : "0.0.0";
|
|
2137
2186
|
var HEADER_STYLE = { display: "flex", flexDirection: "column", gap: 12, padding: "2px 0" };
|
|
2138
2187
|
var HEADER_ROW_STYLE = { display: "flex", alignItems: "center", gap: 10, flexWrap: "wrap" };
|
|
2139
2188
|
var HEADER_TITLE_STYLE = {
|
|
@@ -2270,13 +2319,13 @@ function ChoiceRow(props) {
|
|
|
2270
2319
|
}
|
|
2271
2320
|
function ReasoningRow(props) {
|
|
2272
2321
|
const pair = props.provider !== "" && props.model !== "" ? `${props.provider}/${props.model}` : "";
|
|
2273
|
-
const [phase, setPhase] = (0,
|
|
2274
|
-
const [capabilities, setCapabilities] = (0,
|
|
2275
|
-
const [refreshToken, setRefreshToken] = (0,
|
|
2276
|
-
const [feedback, setFeedback] = (0,
|
|
2277
|
-
const forceRef = (0,
|
|
2278
|
-
const feedbackTimer = (0,
|
|
2279
|
-
(0,
|
|
2322
|
+
const [phase, setPhase] = (0, import_react8.useState)("loading");
|
|
2323
|
+
const [capabilities, setCapabilities] = (0, import_react8.useState)(void 0);
|
|
2324
|
+
const [refreshToken, setRefreshToken] = (0, import_react8.useState)(0);
|
|
2325
|
+
const [feedback, setFeedback] = (0, import_react8.useState)("idle");
|
|
2326
|
+
const forceRef = (0, import_react8.useRef)(false);
|
|
2327
|
+
const feedbackTimer = (0, import_react8.useRef)(void 0);
|
|
2328
|
+
(0, import_react8.useEffect)(() => {
|
|
2280
2329
|
const controller = new AbortController();
|
|
2281
2330
|
const force = forceRef.current;
|
|
2282
2331
|
forceRef.current = false;
|
|
@@ -2380,7 +2429,7 @@ function ReasoningRow(props) {
|
|
|
2380
2429
|
] });
|
|
2381
2430
|
}
|
|
2382
2431
|
function SelectControl(props) {
|
|
2383
|
-
const [focused, setFocused] = (0,
|
|
2432
|
+
const [focused, setFocused] = (0, import_react8.useState)(false);
|
|
2384
2433
|
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
2385
2434
|
"select",
|
|
2386
2435
|
{
|
|
@@ -2425,7 +2474,7 @@ function ProviderRow(props) {
|
|
|
2425
2474
|
function ModelRow(props) {
|
|
2426
2475
|
const current2 = props.view.text;
|
|
2427
2476
|
const provider = props.providerValue;
|
|
2428
|
-
const [customMode, setCustomMode] = (0,
|
|
2477
|
+
const [customMode, setCustomMode] = (0, import_react8.useState)(false);
|
|
2429
2478
|
const known = props.routing.models.entries.some((entry) => entry.id === current2);
|
|
2430
2479
|
const showCustom = provider !== "" && (customMode || current2 !== "" && !known);
|
|
2431
2480
|
const pairIncomplete = provider !== "" && current2 === "";
|
|
@@ -2474,7 +2523,7 @@ function ModelRow(props) {
|
|
|
2474
2523
|
] });
|
|
2475
2524
|
}
|
|
2476
2525
|
function TextControl(props) {
|
|
2477
|
-
const [focused, setFocused] = (0,
|
|
2526
|
+
const [focused, setFocused] = (0, import_react8.useState)(false);
|
|
2478
2527
|
const borderColor = props.invalid === true ? "var(--dsw-alias-state-error-primary, #f85149)" : focused ? "var(--dsw-alias-state-business-primary, #4f8cff)" : void 0;
|
|
2479
2528
|
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
2480
2529
|
"input",
|
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.0.
|
|
4
|
+
"version": "0.0.5",
|
|
5
5
|
"author": "surfishs",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"engines": {
|
|
@@ -13,6 +13,7 @@ import type {} from '@deepseek-ai/dsh-client-ui-conversation/client'
|
|
|
13
13
|
import { ResultPanel } from './ResultPanel'
|
|
14
14
|
import * as ui from './ui-state'
|
|
15
15
|
import { useSessionKey } from './session-key'
|
|
16
|
+
import { useDockAlignment } from './useDockAlignment'
|
|
16
17
|
|
|
17
18
|
/** Props of the input.dock entry: the InputZone owner share + session kit + locale seat. */
|
|
18
19
|
export type ResultDockProps = PropsRuntime<'conversation.input.dock'> & PropsLocale<'dsh-prompt-enhance'>
|
|
@@ -23,12 +24,12 @@ export function ResultDock(props: ResultDockProps): ReactNode {
|
|
|
23
24
|
// 0.1.1-rc.2 carries sessionId on the props; 0.1.2-rc.1 dropped it. Use the
|
|
24
25
|
// host id for UI keying when present, else a stable per-mount fallback.
|
|
25
26
|
const uiKey = useSessionKey(sessionId, inputActions)
|
|
26
|
-
const
|
|
27
|
+
const panel = useSyncExternalStore(ui.subscribe, ui.getPanel)
|
|
28
|
+
const rootRef = useDockAlignment(panel !== undefined && panel.sessionId === uiKey)
|
|
27
29
|
const [undone, setUndone] = useState(false)
|
|
28
30
|
const [regenerated, setRegenerated] = useState(false)
|
|
29
31
|
const [pendingRegenerate, setPendingRegenerate] = useState(false)
|
|
30
32
|
const previousResultRef = useRef<unknown>(undefined)
|
|
31
|
-
const panel = useSyncExternalStore(ui.subscribe, ui.getPanel)
|
|
32
33
|
const draft = useInput((state) => {
|
|
33
34
|
const value = (state as { draft?: unknown }).draft
|
|
34
35
|
return typeof value === 'string' ? value : ''
|
|
@@ -121,97 +122,6 @@ export function ResultDock(props: ResultDockProps): ReactNode {
|
|
|
121
122
|
return () => clearTimeout(timer)
|
|
122
123
|
}, [pendingRegenerate])
|
|
123
124
|
|
|
124
|
-
// The dock row is wider than the composer card in some host layouts (the
|
|
125
|
-
// conversation column spans the pane while the card is centered). Align the
|
|
126
|
-
// card to the composer by measuring the composer's rounded card: find the
|
|
127
|
-
// nearest editor below the dock, walk up to the rounded surface, and reuse
|
|
128
|
-
// its width and left offset. The measurement is re-run on resize; when no
|
|
129
|
-
// editor exists the dock keeps the host's full width.
|
|
130
|
-
useEffect(() => {
|
|
131
|
-
if (panel === undefined || panel.sessionId !== uiKey) return
|
|
132
|
-
const root = rootRef.current
|
|
133
|
-
if (root === null) return
|
|
134
|
-
let frame = 0
|
|
135
|
-
const align = (): void => {
|
|
136
|
-
const parent = root.parentElement
|
|
137
|
-
if (parent === null) return
|
|
138
|
-
// A transform-only offset is applied to the wrong base when the host
|
|
139
|
-
// already centers this entry, and a translated box can be clipped by its
|
|
140
|
-
// parent; use a layout margin instead. The previous margin is subtracted
|
|
141
|
-
// from the measured left so repeated runs do not accumulate drift.
|
|
142
|
-
root.style.transform = ''
|
|
143
|
-
const previousMargin = parseFloat(root.style.marginLeft) || 0
|
|
144
|
-
const rootRect = root.getBoundingClientRect()
|
|
145
|
-
const baseLeft = rootRect.left - previousMargin
|
|
146
|
-
const editors = Array.from(document.querySelectorAll<HTMLElement>('textarea, [contenteditable="true"], [role="textbox"]'))
|
|
147
|
-
const editor = editors.find((node) => {
|
|
148
|
-
const rect = node.getBoundingClientRect()
|
|
149
|
-
return rect.width > 0 && rect.height > 0 && rect.top >= rootRect.bottom - 4
|
|
150
|
-
})
|
|
151
|
-
if (editor === undefined) {
|
|
152
|
-
root.style.width = ''
|
|
153
|
-
root.style.marginLeft = ''
|
|
154
|
-
root.style.transform = ''
|
|
155
|
-
return
|
|
156
|
-
}
|
|
157
|
-
const editorRect = editor.getBoundingClientRect()
|
|
158
|
-
// Collect every rounded, opaque ancestor of the editor, then take the
|
|
159
|
-
// widest one that is still plausibly the composer card. The first match
|
|
160
|
-
// is often an inner wrapper a few pixels narrower than the card; the
|
|
161
|
-
// conversation pane above it is too wide. Center proximity rejects the
|
|
162
|
-
// pane when the composer is off-center, and the width cap rejects it
|
|
163
|
-
// when both are centered.
|
|
164
|
-
const candidates: { node: HTMLElement; rect: DOMRect }[] = []
|
|
165
|
-
let node: HTMLElement | null = editor
|
|
166
|
-
for (let depth = 0; depth < 12 && node !== null; depth++) {
|
|
167
|
-
const rect = node.getBoundingClientRect()
|
|
168
|
-
const style = getComputedStyle(node)
|
|
169
|
-
if (
|
|
170
|
-
rect.width >= editorRect.width
|
|
171
|
-
&& rect.width > 360
|
|
172
|
-
&& rect.height > 48
|
|
173
|
-
&& (parseFloat(style.borderTopLeftRadius) || 0) >= 4
|
|
174
|
-
&& style.backgroundColor !== 'rgba(0, 0, 0, 0)'
|
|
175
|
-
) {
|
|
176
|
-
candidates.push({ node, rect })
|
|
177
|
-
}
|
|
178
|
-
node = node.parentElement
|
|
179
|
-
}
|
|
180
|
-
const editorCenter = editorRect.left + editorRect.width / 2
|
|
181
|
-
const cardEntry = candidates
|
|
182
|
-
.filter((candidate) => (
|
|
183
|
-
candidate.rect.width <= window.innerWidth * 0.8
|
|
184
|
-
&& Math.abs(candidate.rect.left + candidate.rect.width / 2 - editorCenter) < 40
|
|
185
|
-
))
|
|
186
|
-
.sort((a, b) => b.rect.width - a.rect.width)[0]
|
|
187
|
-
?? candidates.sort((a, b) => b.rect.width - a.rect.width)[0]
|
|
188
|
-
if (cardEntry === undefined) return
|
|
189
|
-
const cardRect = cardEntry.rect
|
|
190
|
-
const width = `${cardRect.width}px`
|
|
191
|
-
if (root.style.width !== width) root.style.width = width
|
|
192
|
-
// Width can shift a centered entry; measure again before deriving the
|
|
193
|
-
// margin so the final left edge matches the composer card.
|
|
194
|
-
const afterWidth = root.getBoundingClientRect()
|
|
195
|
-
const currentMargin = parseFloat(root.style.marginLeft) || 0
|
|
196
|
-
const marginLeft = `${cardRect.left - (afterWidth.left - currentMargin)}px`
|
|
197
|
-
if (root.style.marginLeft !== marginLeft) root.style.marginLeft = marginLeft
|
|
198
|
-
}
|
|
199
|
-
const schedule = (): void => {
|
|
200
|
-
cancelAnimationFrame(frame)
|
|
201
|
-
frame = requestAnimationFrame(align)
|
|
202
|
-
}
|
|
203
|
-
schedule()
|
|
204
|
-
schedule()
|
|
205
|
-
window.addEventListener('resize', schedule)
|
|
206
|
-
const observer = typeof ResizeObserver === 'undefined' ? null : new ResizeObserver(schedule)
|
|
207
|
-
observer?.observe(document.documentElement)
|
|
208
|
-
return () => {
|
|
209
|
-
cancelAnimationFrame(frame)
|
|
210
|
-
window.removeEventListener('resize', schedule)
|
|
211
|
-
observer?.disconnect()
|
|
212
|
-
}
|
|
213
|
-
}, [panel, uiKey])
|
|
214
|
-
|
|
215
125
|
if (panel === undefined || panel.sessionId !== uiKey) return null
|
|
216
126
|
|
|
217
127
|
const apply = (): void => {
|
|
@@ -180,31 +180,33 @@ export function ResultPanel(props: ResultPanelProps): ReactNode {
|
|
|
180
180
|
<SparkleFishIcon size={15} />
|
|
181
181
|
{t('panel.title')}
|
|
182
182
|
</span>
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
183
|
+
<div className="dsh-pe-head-actions">
|
|
184
|
+
{state.phase === 'result' && state.result !== undefined && (
|
|
185
|
+
<span className="dsh-pe-badge">
|
|
186
|
+
{t('panel.model', { provider: state.result.provider, model: state.result.model })} · {t('panel.elapsed', { ms: formatMs(state.result.elapsedMs) })}
|
|
187
|
+
{state.result.usage === undefined
|
|
188
|
+
? null
|
|
189
|
+
: (
|
|
190
|
+
<>
|
|
191
|
+
{' · '}
|
|
192
|
+
<span title={tokenDetail(state.result.usage)}>
|
|
193
|
+
{t('panel.tokens', { total: formatTokens(totalTokensOf(state.result.usage)) })}
|
|
194
|
+
</span>
|
|
195
|
+
</>
|
|
196
|
+
)}
|
|
197
|
+
</span>
|
|
198
|
+
)}
|
|
199
|
+
{copied === 'ok'
|
|
200
|
+
? <span className="dsh-pe-applied">{t('panel.copiedShort')}</span>
|
|
201
|
+
: regenerated
|
|
202
|
+
? <span className="dsh-pe-applied">{t('panel.regeneratedShort')}</span>
|
|
203
|
+
: applied
|
|
204
|
+
? <span className="dsh-pe-applied">{t('panel.appliedShort')}</span>
|
|
205
|
+
: undone
|
|
206
|
+
? <span className="dsh-pe-applied">{t('panel.undoneShort')}</span>
|
|
207
|
+
: null}
|
|
208
|
+
<button type="button" className="dsh-pe-close" aria-label={t('panel.close')} onClick={onCancel}>✕</button>
|
|
209
|
+
</div>
|
|
208
210
|
</header>
|
|
209
211
|
|
|
210
212
|
{state.phase === 'loading' && (
|
package/src/client/UndoBar.tsx
CHANGED
|
@@ -12,6 +12,8 @@ import type { PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots
|
|
|
12
12
|
import type {} from '@deepseek-ai/dsh-client-ui-conversation/client'
|
|
13
13
|
import * as ui from './ui-state'
|
|
14
14
|
import { useSessionKey } from './session-key'
|
|
15
|
+
import { UndoIcon } from './ActionIcons'
|
|
16
|
+
import { useDockAlignment } from './useDockAlignment'
|
|
15
17
|
|
|
16
18
|
/** Props of the input.dock entry: the InputZone owner share + session kit + locale seat. */
|
|
17
19
|
export type UndoBarProps = PropsRuntime<'conversation.input.dock'> & PropsLocale<'dsh-prompt-enhance'>
|
|
@@ -40,8 +42,11 @@ export function UndoBar(props: UndoBarProps): ReactNode {
|
|
|
40
42
|
// The result card owns the undo affordance while it is open; the standalone
|
|
41
43
|
// row takes over only after the card is closed.
|
|
42
44
|
const panel = ui.getPanel()
|
|
43
|
-
|
|
44
|
-
|
|
45
|
+
const visible = (panel === undefined || panel.sessionId !== uiKey)
|
|
46
|
+
&& entry !== undefined
|
|
47
|
+
&& entry.applied === draft
|
|
48
|
+
const rootRef = useDockAlignment(visible)
|
|
49
|
+
if (!visible) return null
|
|
45
50
|
|
|
46
51
|
const undo = (): void => {
|
|
47
52
|
inputActions.setDraft(entry.original)
|
|
@@ -52,11 +57,13 @@ export function UndoBar(props: UndoBarProps): ReactNode {
|
|
|
52
57
|
}
|
|
53
58
|
|
|
54
59
|
return (
|
|
55
|
-
<div className="dsh-pe-
|
|
56
|
-
<
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
+
<div ref={rootRef} className="dsh-pe-dock">
|
|
61
|
+
<div className="dsh-pe-undo">
|
|
62
|
+
<span className="dsh-pe-undo-check" aria-hidden>✓</span>
|
|
63
|
+
<span>{t('undo.applied')}</span>
|
|
64
|
+
<button type="button" className="dsh-pe-undo-link" onClick={undo}><UndoIcon />{t('undo.undo')}</button>
|
|
65
|
+
<button type="button" className="dsh-pe-undo-x" aria-label={t('undo.dismiss')} onClick={dismiss}>✕</button>
|
|
66
|
+
</div>
|
|
60
67
|
</div>
|
|
61
68
|
)
|
|
62
69
|
}
|
package/src/client/locales.ts
CHANGED
|
@@ -37,7 +37,7 @@ export const zh = {
|
|
|
37
37
|
'panel.tokens.output': '输出 {count}',
|
|
38
38
|
'panel.tokens.cacheRead': '缓存读取 {count}',
|
|
39
39
|
'panel.tokens.cacheWrite': '缓存写入 {count}',
|
|
40
|
-
'undo.applied': '
|
|
40
|
+
'undo.applied': '已替换原提示词',
|
|
41
41
|
'undo.undo': '撤销',
|
|
42
42
|
'undo.dismiss': '关闭提示',
|
|
43
43
|
'error.empty': '输入框为空,请先输入要增强的提示词。',
|
|
@@ -180,7 +180,7 @@ export const en: Record<PromptEnhanceKey, string> = {
|
|
|
180
180
|
'panel.tokens.output': 'Output {count}',
|
|
181
181
|
'panel.tokens.cacheRead': 'Cache read {count}',
|
|
182
182
|
'panel.tokens.cacheWrite': 'Cache write {count}',
|
|
183
|
-
'undo.applied': 'Original
|
|
183
|
+
'undo.applied': 'Original draft replaced',
|
|
184
184
|
'undo.undo': 'Undo',
|
|
185
185
|
'undo.dismiss': 'Dismiss',
|
|
186
186
|
'error.empty': 'The input box is empty — type a prompt to enhance first.',
|
package/src/client/styles.ts
CHANGED
|
@@ -59,8 +59,15 @@ export const CSS = `
|
|
|
59
59
|
font-weight: 600;
|
|
60
60
|
}
|
|
61
61
|
.dsh-pe-head .dsh-pe-title { display: inline-flex; align-items: center; gap: 6px; }
|
|
62
|
-
.dsh-pe-head .dsh-pe-
|
|
62
|
+
.dsh-pe-head .dsh-pe-head-actions {
|
|
63
|
+
display: flex;
|
|
64
|
+
align-items: center;
|
|
65
|
+
gap: 8px;
|
|
63
66
|
margin-left: auto;
|
|
67
|
+
min-width: 0;
|
|
68
|
+
}
|
|
69
|
+
.dsh-pe-head .dsh-pe-badge {
|
|
70
|
+
margin-left: 0;
|
|
64
71
|
border: 1px solid var(--pe-border);
|
|
65
72
|
border-radius: 999px;
|
|
66
73
|
padding: 1px 8px;
|
|
@@ -211,22 +218,52 @@ export const CSS = `
|
|
|
211
218
|
display: flex;
|
|
212
219
|
align-items: center;
|
|
213
220
|
gap: 8px;
|
|
214
|
-
|
|
221
|
+
width: fit-content;
|
|
222
|
+
margin-left: auto;
|
|
223
|
+
padding: 3px 6px 3px 10px;
|
|
224
|
+
border: 1px solid var(--dsw-alias-border-l2, rgba(128, 128, 128, 0.32));
|
|
225
|
+
border-radius: 12px;
|
|
226
|
+
background: var(--dsw-alias-bg-layer-1, transparent);
|
|
215
227
|
font-size: 12px;
|
|
216
228
|
color: inherit;
|
|
217
|
-
opacity: 0.85;
|
|
218
229
|
}
|
|
219
|
-
.dsh-pe-undo .dsh-pe-undo-check {
|
|
230
|
+
.dsh-pe-undo .dsh-pe-undo-check {
|
|
231
|
+
color: var(--dsw-alias-state-success-primary, #2da44e);
|
|
232
|
+
font-weight: 600;
|
|
233
|
+
}
|
|
220
234
|
.dsh-pe-undo-link {
|
|
221
|
-
|
|
222
|
-
|
|
235
|
+
display: inline-flex;
|
|
236
|
+
align-items: center;
|
|
237
|
+
justify-content: center;
|
|
238
|
+
gap: 6px;
|
|
239
|
+
height: 28px;
|
|
240
|
+
padding: 0 10px;
|
|
241
|
+
border: 1px solid var(--dsw-alias-border-l2, rgba(128, 128, 128, 0.32));
|
|
242
|
+
border-radius: 6px;
|
|
243
|
+
background: transparent;
|
|
244
|
+
color: inherit;
|
|
245
|
+
font-size: 12px;
|
|
246
|
+
cursor: pointer;
|
|
247
|
+
transition: background-color 120ms ease;
|
|
223
248
|
}
|
|
224
|
-
.dsh-pe-undo-link:hover { background: rgba(127,127,127,0.
|
|
249
|
+
.dsh-pe-undo-link:hover { background: rgba(127, 127, 127, 0.16); }
|
|
250
|
+
.dsh-pe-undo-link:active { background: rgba(127, 127, 127, 0.22); }
|
|
225
251
|
.dsh-pe-undo-x {
|
|
226
|
-
|
|
227
|
-
|
|
252
|
+
display: inline-flex;
|
|
253
|
+
align-items: center;
|
|
254
|
+
justify-content: center;
|
|
255
|
+
width: 28px;
|
|
256
|
+
height: 28px;
|
|
257
|
+
border: none;
|
|
258
|
+
border-radius: 6px;
|
|
259
|
+
background: transparent;
|
|
260
|
+
color: inherit;
|
|
261
|
+
opacity: 0.55;
|
|
262
|
+
cursor: pointer;
|
|
263
|
+
padding: 0;
|
|
264
|
+
font-size: 12px;
|
|
228
265
|
}
|
|
229
|
-
.dsh-pe-undo-x:hover { opacity: 1; }
|
|
266
|
+
.dsh-pe-undo-x:hover { opacity: 1; background: var(--dsw-alias-bg-layer-2, rgba(128, 128, 128, 0.12)); }
|
|
230
267
|
`
|
|
231
268
|
|
|
232
269
|
/**
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Align a dock entry to the composer card below it.
|
|
3
|
+
*
|
|
4
|
+
* The host renders conversation.input.dock entries full-width, while the
|
|
5
|
+
* composer card is narrower and may be centered or offset. This hook measures
|
|
6
|
+
* the nearest editor below the dock, walks up to the composer's rounded
|
|
7
|
+
* surface, and copies its width and left margin onto the returned wrapper.
|
|
8
|
+
* When no editor is found, the host's full width is left untouched.
|
|
9
|
+
* @module dsh-prompt-enhance/client/useDockAlignment
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { useEffect, useRef, type RefObject } from 'react'
|
|
13
|
+
|
|
14
|
+
/** Measure the composer below the dock and align the returned wrapper to it. */
|
|
15
|
+
export function useDockAlignment(active: boolean): RefObject<HTMLDivElement> {
|
|
16
|
+
const rootRef = useRef<HTMLDivElement>(null)
|
|
17
|
+
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (!active) return
|
|
20
|
+
const root = rootRef.current
|
|
21
|
+
if (root === null) return
|
|
22
|
+
let frame = 0
|
|
23
|
+
const align = (): void => {
|
|
24
|
+
const parent = root.parentElement
|
|
25
|
+
if (parent === null) return
|
|
26
|
+
// A transform-only offset is applied to the wrong base when the host
|
|
27
|
+
// already centers this entry, and a translated box can be clipped by its
|
|
28
|
+
// parent; use a layout margin instead. The previous margin is subtracted
|
|
29
|
+
// from the measured left so repeated runs do not accumulate drift.
|
|
30
|
+
root.style.transform = ''
|
|
31
|
+
const previousMargin = parseFloat(root.style.marginLeft) || 0
|
|
32
|
+
const rootRect = root.getBoundingClientRect()
|
|
33
|
+
const editors = Array.from(document.querySelectorAll<HTMLElement>('textarea, [contenteditable="true"], [role="textbox"]'))
|
|
34
|
+
const editor = editors.find((node) => {
|
|
35
|
+
const rect = node.getBoundingClientRect()
|
|
36
|
+
return rect.width > 0 && rect.height > 0 && rect.top >= rootRect.bottom - 4
|
|
37
|
+
})
|
|
38
|
+
if (editor === undefined) {
|
|
39
|
+
root.style.width = ''
|
|
40
|
+
root.style.marginLeft = ''
|
|
41
|
+
root.style.transform = ''
|
|
42
|
+
return
|
|
43
|
+
}
|
|
44
|
+
const editorRect = editor.getBoundingClientRect()
|
|
45
|
+
// Collect every rounded, opaque ancestor of the editor, then take the
|
|
46
|
+
// widest one that is still plausibly the composer card. The first match
|
|
47
|
+
// is often an inner wrapper a few pixels narrower than the card; the
|
|
48
|
+
// conversation pane above it is too wide. Center proximity rejects the
|
|
49
|
+
// pane when the composer is off-center, and the width cap rejects it
|
|
50
|
+
// when both are centered.
|
|
51
|
+
const candidates: { node: HTMLElement; rect: DOMRect }[] = []
|
|
52
|
+
let node: HTMLElement | null = editor
|
|
53
|
+
for (let depth = 0; depth < 12 && node !== null; depth++) {
|
|
54
|
+
const rect = node.getBoundingClientRect()
|
|
55
|
+
const style = getComputedStyle(node)
|
|
56
|
+
if (
|
|
57
|
+
rect.width >= editorRect.width
|
|
58
|
+
&& rect.width > 360
|
|
59
|
+
&& rect.height > 48
|
|
60
|
+
&& (parseFloat(style.borderTopLeftRadius) || 0) >= 4
|
|
61
|
+
&& style.backgroundColor !== 'rgba(0, 0, 0, 0)'
|
|
62
|
+
) {
|
|
63
|
+
candidates.push({ node, rect })
|
|
64
|
+
}
|
|
65
|
+
node = node.parentElement
|
|
66
|
+
}
|
|
67
|
+
const editorCenter = editorRect.left + editorRect.width / 2
|
|
68
|
+
const cardEntry = candidates
|
|
69
|
+
.filter((candidate) => (
|
|
70
|
+
candidate.rect.width <= window.innerWidth * 0.8
|
|
71
|
+
&& Math.abs(candidate.rect.left + candidate.rect.width / 2 - editorCenter) < 40
|
|
72
|
+
))
|
|
73
|
+
.sort((a, b) => b.rect.width - a.rect.width)[0]
|
|
74
|
+
?? candidates.sort((a, b) => b.rect.width - a.rect.width)[0]
|
|
75
|
+
if (cardEntry === undefined) return
|
|
76
|
+
const cardRect = cardEntry.rect
|
|
77
|
+
const width = `${cardRect.width}px`
|
|
78
|
+
if (root.style.width !== width) root.style.width = width
|
|
79
|
+
// Width can shift a centered entry; measure again before deriving the
|
|
80
|
+
// margin so the final left edge matches the composer card.
|
|
81
|
+
const afterWidth = root.getBoundingClientRect()
|
|
82
|
+
const currentMargin = parseFloat(root.style.marginLeft) || 0
|
|
83
|
+
const marginLeft = `${cardRect.left - (afterWidth.left - currentMargin)}px`
|
|
84
|
+
if (root.style.marginLeft !== marginLeft) root.style.marginLeft = marginLeft
|
|
85
|
+
}
|
|
86
|
+
const schedule = (): void => {
|
|
87
|
+
cancelAnimationFrame(frame)
|
|
88
|
+
frame = requestAnimationFrame(align)
|
|
89
|
+
}
|
|
90
|
+
schedule()
|
|
91
|
+
schedule()
|
|
92
|
+
window.addEventListener('resize', schedule)
|
|
93
|
+
const observer = typeof ResizeObserver === 'undefined' ? null : new ResizeObserver(schedule)
|
|
94
|
+
observer?.observe(document.documentElement)
|
|
95
|
+
return () => {
|
|
96
|
+
cancelAnimationFrame(frame)
|
|
97
|
+
window.removeEventListener('resize', schedule)
|
|
98
|
+
observer?.disconnect()
|
|
99
|
+
}
|
|
100
|
+
}, [active])
|
|
101
|
+
|
|
102
|
+
return rootRef
|
|
103
|
+
}
|