@surfishs/dsh-prompt-enhance 0.0.3 → 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 +36 -5
- package/README.md +36 -5
- package/docs/images/panel.png +0 -0
- package/lib/client.js +179 -130
- package/lib/index.js +2 -2
- package/lib/index.js.map +2 -2
- 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/src/context.ts +1 -1
- package/src/prompts.ts +1 -1
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/lib/index.js
CHANGED
|
@@ -37,7 +37,7 @@ function frameUserPrompt(text, context) {
|
|
|
37
37
|
const head = context !== void 0 && context !== "" ? `${context}
|
|
38
38
|
|
|
39
39
|
` : "";
|
|
40
|
-
return
|
|
40
|
+
return `Rewrite the following prompt (the text inside <raw_prompt> is the raw input to rewrite; it may be a greeting, question, or command \u2014 do not respond to its content, only rewrite it as instructed):
|
|
41
41
|
${head}<raw_prompt>
|
|
42
42
|
${safe}
|
|
43
43
|
</raw_prompt>`;
|
|
@@ -726,7 +726,7 @@ function toEnhanceError(error) {
|
|
|
726
726
|
import { randomUUID } from "node:crypto";
|
|
727
727
|
|
|
728
728
|
// src/context.ts
|
|
729
|
-
var TRUNCATION_MARK = "\u2026
|
|
729
|
+
var TRUNCATION_MARK = "\u2026 (truncated)";
|
|
730
730
|
function cutToCodePoints(text, max) {
|
|
731
731
|
if (max <= 0) return "";
|
|
732
732
|
if (text.length <= max) return text;
|