dsh-textru-unique 1.0.0 → 1.0.2

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.
Files changed (3) hide show
  1. package/README.md +9 -0
  2. package/lib/client.js +191 -0
  3. package/package.json +16 -1
package/README.md CHANGED
@@ -46,6 +46,15 @@ Agent: textru_unique({ text: "..." })
46
46
  → 43.51% · 2 sources · 4 fragments
47
47
  ```
48
48
 
49
+ ## API-ключ
50
+
51
+ В карточке «Настройки → text.ru» есть поле «Ключ text.ru». Значение сохраняется в защищённом
52
+ хранилище креденшелов профиля (`DSH_HOME/.credentials.yaml`), а не в `cordis.patch.yml`
53
+ плагина, поэтому в контекст модели ключ не попадает. Хостовые инструменты читают его по имени
54
+ `TEXT_RU_KEY` (или из переменной окружения с этим именем; имя можно изменить полем
55
+ `apiKeyEnv` в конфиге плагина). Подсказка «?» рядом с полем предупреждает, что хранилище — файл
56
+ на диске, и перечисляет альтернативные способы передачи ключа.
57
+
49
58
  ## License
50
59
 
51
60
  MIT.
package/lib/client.js ADDED
@@ -0,0 +1,191 @@
1
+ /**
2
+ * dsh-textru-unique — browser half.
3
+ *
4
+ * Карточка «Настройки → text.ru»: поле API-ключа, который сохраняется в
5
+ * защищённое хранилище креденшелов профиля (DSH_HOME/.credentials.yaml),
6
+ * а не в конфиг плагина. Хост читает ключ из того же хранилища по имени
7
+ * TEXT_RU_KEY (или из переменной окружения с этим именем).
8
+ */
9
+ window.__ModuleLoader__.load({
10
+ id: "dsh-textru-unique",
11
+ factory: (require) => {
12
+ var module = { exports: {} };
13
+ var exports = module.exports;
14
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
15
+ let react = require("react");
16
+
17
+ const ENV = "TEXT_RU_KEY";
18
+ const KEY_URL = "https://text.ru";
19
+
20
+ const wrap = { display: "flex", flexDirection: "column", gap: "12px", padding: "16px", maxWidth: "760px", lineHeight: 1.5 };
21
+ const heading = { fontSize: "15px", fontWeight: 600, margin: 0 };
22
+ const paragraph = { margin: 0, fontSize: "13px", opacity: 0.85 };
23
+ const note = { margin: 0, fontSize: "12px", opacity: 0.65 };
24
+ const row = { display: "flex", alignItems: "center", gap: "8px", flexWrap: "wrap" };
25
+ const label = { fontSize: "12px", opacity: 0.75, minWidth: "120px" };
26
+ const input = { fontSize: "12px", padding: "4px 8px", borderRadius: "6px", border: "1px solid currentColor", background: "transparent", color: "inherit", minWidth: "260px" };
27
+ const chip = { fontSize: "11px", opacity: 0.7, border: "1px solid currentColor", borderRadius: "999px", padding: "1px 8px" };
28
+ const button = { fontSize: "12px", padding: "5px 12px", borderRadius: "6px", border: "1px solid currentColor", background: "transparent", color: "inherit", cursor: "pointer" };
29
+ const buttonDanger = { ...button, opacity: 0.8 };
30
+ const error = { margin: 0, fontSize: "12px", color: "#e5484d" };
31
+ const ok = { margin: 0, fontSize: "12px", color: "#30a46c" };
32
+ const divider = { height: "1px", background: "currentColor", opacity: 0.15 };
33
+ const link = { color: "inherit", textDecoration: "underline", textUnderlineOffset: "2px" };
34
+
35
+ const KEY_WARNING = "Ключ сохраняется в защищённом хранилище креденшелов профиля (DSH_HOME/.credentials.yaml), а не в cordis.patch.yml этого плагина, поэтому в контекст модели он не попадает. Но это файл на диске: при полном доступе к файловой системе агент теоретически может его прочитать — не вставляйте ключи в чат. Альтернативы: 1) переменная окружения " + ENV + " перед запуском DSH; 2) вручную в DSH_HOME/.credentials.yaml, раздел refs; 3) имя переменной можно изменить полем apiKeyEnv в конфиге плагина.";
36
+
37
+ /** Кастомная подсказка: title в webview не всплывает. */
38
+ function Tooltip(props) {
39
+ const [open, setOpen] = react.useState(false);
40
+ return react.createElement("span", {
41
+ style: { position: "relative", display: "inline-flex" },
42
+ onMouseEnter: () => setOpen(true),
43
+ onMouseLeave: () => setOpen(false),
44
+ onFocus: () => setOpen(true),
45
+ onBlur: () => setOpen(false),
46
+ tabIndex: 0,
47
+ "aria-label": props.text,
48
+ },
49
+ props.children,
50
+ open && react.createElement("span", {
51
+ role: "tooltip",
52
+ style: {
53
+ position: "absolute", top: "100%", left: 0, marginTop: "6px",
54
+ width: "340px", maxWidth: "70vw", zIndex: 1000,
55
+ padding: "8px 10px", borderRadius: "8px",
56
+ border: "1px solid color-mix(in srgb, currentColor 25%, transparent)",
57
+ background: "var(--dsw-specific-menu, rgba(24,24,28,0.97))",
58
+ color: "inherit", fontSize: "12px", lineHeight: 1.45,
59
+ whiteSpace: "normal", boxShadow: "0 8px 28px rgba(0,0,0,0.28)",
60
+ }
61
+ }, props.text)
62
+ );
63
+ }
64
+
65
+ async function callRemote(rpcCall) {
66
+ return rpcCall;
67
+ }
68
+
69
+ function TextruSettings(props) {
70
+ const ctx = props.ctx;
71
+ const [info, setInfo] = react.useState({});
72
+ const [draft, setDraft] = react.useState("");
73
+ const [busy, setBusy] = react.useState(false);
74
+ const [message, setMessage] = react.useState("");
75
+ const [failure, setFailure] = react.useState("");
76
+
77
+ const load = react.useCallback(async () => {
78
+ try {
79
+ const response = await ctx.remote.credentials.describe([ENV]);
80
+ if (response && response.ok === true) {
81
+ setInfo((response.value && response.value[ENV]) || {});
82
+ setFailure("");
83
+ } else {
84
+ setFailure(response && response.error ? response.error.message : "не удалось получить статус ключа");
85
+ }
86
+ } catch (cause) {
87
+ setFailure(String(cause));
88
+ }
89
+ }, [ctx]);
90
+
91
+ react.useEffect(() => { load(); }, [load]);
92
+
93
+ const save = async () => {
94
+ const value = draft.trim();
95
+ if (value.length === 0) return;
96
+ setBusy(true);
97
+ setMessage("");
98
+ setFailure("");
99
+ try {
100
+ const response = await ctx.remote.credentials.set(ENV, value);
101
+ if (response && response.ok === true) {
102
+ setDraft("");
103
+ setMessage("Ключ сохранён: " + ENV);
104
+ await load();
105
+ } else {
106
+ setFailure(response && response.error ? response.error.message : "не удалось сохранить");
107
+ }
108
+ } catch (cause) {
109
+ setFailure(String(cause));
110
+ } finally {
111
+ setBusy(false);
112
+ }
113
+ };
114
+
115
+ const remove = async () => {
116
+ setBusy(true);
117
+ setMessage("");
118
+ setFailure("");
119
+ try {
120
+ const response = await ctx.remote.credentials.unset(ENV);
121
+ if (response && response.ok === true) {
122
+ setMessage("Ключ удалён: " + ENV);
123
+ await load();
124
+ } else {
125
+ setFailure(response && response.error ? response.error.message : "не удалось удалить");
126
+ }
127
+ } catch (cause) {
128
+ setFailure(String(cause));
129
+ } finally {
130
+ setBusy(false);
131
+ }
132
+ };
133
+
134
+ const configured = info.configured === true;
135
+ return react.createElement("div", { style: wrap },
136
+ react.createElement("h2", { style: heading }, "text.ru: проверка уникальности"),
137
+ react.createElement("p", { style: paragraph },
138
+ "Ключ text.ru нужен для инструментов textru_unique и textru_balance. Он хранится в хранилище креденшелов профиля, а не в конфиге плагина."
139
+ ),
140
+ react.createElement("h3", { style: heading, fontSize: "13px" }, "API-ключ"),
141
+ react.createElement("div", { style: row },
142
+ react.createElement("span", { style: label }, "Ключ text.ru"),
143
+ react.createElement("span", { style: chip }, ENV),
144
+ react.createElement("input", {
145
+ style: input,
146
+ type: "password",
147
+ autoComplete: "new-password",
148
+ placeholder: configured ? (info.masked || "ключ сохранён") : "API-ключ text.ru",
149
+ value: draft,
150
+ onChange: (event) => setDraft(event.target.value),
151
+ onKeyDown: (event) => { if (event.key === "Enter") save(); },
152
+ }),
153
+ react.createElement("button", { style: button, disabled: busy || draft.trim().length === 0, onClick: save }, "Сохранить"),
154
+ configured && react.createElement("button", { style: buttonDanger, disabled: busy, onClick: remove }, "Удалить"),
155
+ react.createElement("span", { style: chip }, configured ? "задан" : "не задан"),
156
+ react.createElement(Tooltip, { text: KEY_WARNING }, "?"),
157
+ react.createElement("a", { style: link, href: KEY_URL, target: "_blank", rel: "noopener noreferrer" }, "где взять ключ")
158
+ ),
159
+ message.length > 0 && react.createElement("p", { style: ok }, message),
160
+ failure.length > 0 && react.createElement("p", { style: error }, failure),
161
+ react.createElement("div", { style: divider }),
162
+ react.createElement("p", { style: note },
163
+ "Альтернатива: переменная окружения " + ENV + " перед запуском DSH, либо вручную в DSH_HOME/.credentials.yaml (раздел refs). По умолчанию хост читает имя " + ENV + "; изменить имя можно полем apiKeyEnv в конфиге плагина."
164
+ )
165
+ );
166
+ }
167
+
168
+ const name = "textru-unique";
169
+ const inject = ["slots", "remote", "remote.credentials"];
170
+
171
+ function apply(ctx) {
172
+ try {
173
+ ctx.slots.inject("settings.section", () => ctx.slots.register({
174
+ name: "settings.section",
175
+ id: "textru-unique",
176
+ order: 47,
177
+ label: () => "text.ru",
178
+ inject: () => ({ ctx })
179
+ }, TextruSettings));
180
+ } catch (cause) {
181
+ console.error("[textru-unique] не удалось смонтировать карточку:", cause);
182
+ }
183
+ }
184
+
185
+ exports.TextruSettings = TextruSettings;
186
+ exports.apply = apply;
187
+ exports.inject = inject;
188
+ exports.name = name;
189
+ return module.exports;
190
+ }
191
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-textru-unique",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Text.ru uniqueness checks for DeepSeek Harness: submits text through the text.ru API, reports the score, sources and non-unique fragments",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -13,11 +13,13 @@
13
13
  ],
14
14
  "exports": {
15
15
  ".": "./index.js",
16
+ "./client": "./lib/client.js",
16
17
  "./locale/*.json": "./locale/*.json",
17
18
  "./icon": "./icon.svg"
18
19
  },
19
20
  "files": [
20
21
  "index.js",
22
+ "lib/client.js",
21
23
  "cordis.patch.yml",
22
24
  "locale/*.json",
23
25
  "icon.svg",
@@ -27,6 +29,13 @@
27
29
  "dsh": {
28
30
  "bundle": {
29
31
  "patch": "./cordis.patch.yml"
32
+ },
33
+ "client": {
34
+ "platform": "web",
35
+ "inject": [
36
+ "@deepseek-ai/dsh-client-ui-settings",
37
+ "@deepseek-ai/dsh-api-remotes"
38
+ ]
30
39
  }
31
40
  },
32
41
  "homepage": "https://seofortuna.ru",
@@ -37,5 +46,11 @@
37
46
  },
38
47
  "bugs": {
39
48
  "url": "https://github.com/maburykh-gif/dsh-plugins/issues"
49
+ },
50
+ "peerDependencies": {
51
+ "@deepseek-ai/dsh": "^0.2.2-rc.1",
52
+ "@deepseek-ai/dsh-api-remotes": "^0.2.2-rc.1",
53
+ "@deepseek-ai/dsh-client-ui-settings": "^0.2.2-rc.1",
54
+ "react": "^18.2.0"
40
55
  }
41
56
  }