dsh-plugin-zotero 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/client.js +175 -32
- package/package.json +1 -1
package/client/client.js
CHANGED
|
@@ -411,8 +411,8 @@ const dicts = {
|
|
|
411
411
|
"toast.insertedItems": "已把 {n} 条加入会话草稿",
|
|
412
412
|
"toast.copied": "已复制",
|
|
413
413
|
"toast.copyFailed": "复制失败",
|
|
414
|
-
"settings.nav": "Zotero",
|
|
415
|
-
"settings.hint": "这些参数决定面板与模型工具如何连上 Zotero
|
|
414
|
+
"settings.nav": "Zotero 插件",
|
|
415
|
+
"settings.hint": "这些参数决定面板与模型工具如何连上 Zotero;改完自动保存、即时生效,无需重启。",
|
|
416
416
|
"group.api": "API 设置",
|
|
417
417
|
"group.mcp": "MCP 设置",
|
|
418
418
|
"tools.title": "MCP 工具",
|
|
@@ -491,7 +491,7 @@ const dicts = {
|
|
|
491
491
|
"write.reauthorize": "重新授权",
|
|
492
492
|
"write.authorizeHint": "Zotero 会弹出一次确认框,选「始终允许」后长期有效",
|
|
493
493
|
"write.pending": "等待 Zotero 弹窗…",
|
|
494
|
-
"write.needSave": "
|
|
494
|
+
"write.needSave": "请先打开上面的开关,再授权",
|
|
495
495
|
"write.granted": "已取得写权限并保存到本机:以后重启不用再授权。",
|
|
496
496
|
"write.grantedOnce": "这次拿到的是一次性授权:只对下一次写入有效,重启后还要再授权。",
|
|
497
497
|
"write.alwaysAllow": "弹窗里选「始终允许」:授权会保存到本机,点一次长期有效;选「允许」只用一次。",
|
|
@@ -514,9 +514,8 @@ const dicts = {
|
|
|
514
514
|
"field.defaultLimitHint": "面板条目列表默认拉取条数,默认 50",
|
|
515
515
|
"form.unavailable": "该插件当前未加载,暂时无法配置。",
|
|
516
516
|
"form.readOnly": "本部署的设置为只读。",
|
|
517
|
-
"form.
|
|
518
|
-
"form.
|
|
519
|
-
"form.saving": "保存中…",
|
|
517
|
+
"form.autosaving": "正在自动保存…",
|
|
518
|
+
"form.autosaveFailed": "自动保存失败:这些值还没写进配置,改动任意字段会再试一次。",
|
|
520
519
|
"form.overridden": "已覆盖",
|
|
521
520
|
"form.reset": "恢复默认",
|
|
522
521
|
"form.invalidNumber": "请填数字;留空表示使用默认值。",
|
|
@@ -733,8 +732,8 @@ const dicts = {
|
|
|
733
732
|
"toast.insertedItems": "Added {n} to the conversation draft",
|
|
734
733
|
"toast.copied": "Copied",
|
|
735
734
|
"toast.copyFailed": "Copy failed",
|
|
736
|
-
"settings.nav": "Zotero",
|
|
737
|
-
"settings.hint": "These parameters decide how the panel and the model tools reach Zotero;
|
|
735
|
+
"settings.nav": "Zotero Plugin",
|
|
736
|
+
"settings.hint": "These parameters decide how the panel and the model tools reach Zotero; edits save automatically and take effect immediately, no restart needed.",
|
|
738
737
|
"group.api": "API settings",
|
|
739
738
|
"group.mcp": "MCP settings",
|
|
740
739
|
"tools.title": "MCP tools",
|
|
@@ -813,7 +812,7 @@ const dicts = {
|
|
|
813
812
|
"write.reauthorize": "Authorize again",
|
|
814
813
|
"write.authorizeHint": "Zotero asks once; pick \"Always allow\" to keep the grant",
|
|
815
814
|
"write.pending": "Waiting for the Zotero dialog…",
|
|
816
|
-
"write.needSave": "Turn the switch on
|
|
815
|
+
"write.needSave": "Turn the switch on first, then authorize",
|
|
817
816
|
"write.granted": "Write access granted and saved on this machine: no re-authorizing after restarts.",
|
|
818
817
|
"write.grantedOnce": "That grant works once: only the next write is covered, and a restart needs authorizing again.",
|
|
819
818
|
"write.alwaysAllow": "Pick \"Always allow\": the grant is saved on this machine and covers future runs. \"Allow\" only covers one write.",
|
|
@@ -836,9 +835,8 @@ const dicts = {
|
|
|
836
835
|
"field.defaultLimitHint": "Default number of items a page loads, default 50",
|
|
837
836
|
"form.unavailable": "This plugin is not loaded, so it cannot be configured right now.",
|
|
838
837
|
"form.readOnly": "This deployment stores settings read-only.",
|
|
839
|
-
"form.
|
|
840
|
-
"form.
|
|
841
|
-
"form.saving": "Saving…",
|
|
838
|
+
"form.autosaving": "Saving automatically…",
|
|
839
|
+
"form.autosaveFailed": "Auto-save failed: these values are not in the config yet. Edit any field to retry.",
|
|
842
840
|
"form.overridden": "Overridden",
|
|
843
841
|
"form.reset": "Reset to default",
|
|
844
842
|
"form.invalidNumber": "Enter a number; leave blank to use the default.",
|
|
@@ -1844,10 +1842,15 @@ function insertChip(sessions, sessionId, reference, span) {
|
|
|
1844
1842
|
* 设置页(浏览器半)。
|
|
1845
1843
|
*
|
|
1846
1844
|
* 把 Host 导出的 volatile `Config` 表单渲染进「设置」对话框的
|
|
1847
|
-
* `settings.section` 席位(左侧导航里独立一页「Zotero
|
|
1848
|
-
*
|
|
1845
|
+
* `settings.section` 席位(左侧导航里独立一页「Zotero 插件」)—— 表单模型照抄官方
|
|
1846
|
+
* 参考实现 `@deepseek-ai/dsh-client-ui-settings-shell` 的 `ShellCard`:
|
|
1849
1847
|
* 控制器持 `SettingsFormModel`,组件经注入的 hook 读快照。
|
|
1850
1848
|
*
|
|
1849
|
+
* **没有保存按钮**:字段改完停手 {@link AUTOSAVE_DELAY_MS} 就自动落盘(今天大家
|
|
1850
|
+
* 已经不习惯点保存),失败不自动重试、等下一次编辑;离开页面时把合法草稿立刻冲掉、
|
|
1851
|
+
* 非法草稿直接丢弃。因此这里用普通 `<div>` 容器而不是框架的 `SettingsForm`——
|
|
1852
|
+
* 后者的页脚写死了一个「保存」按钮,没有关掉的开关。
|
|
1853
|
+
*
|
|
1851
1854
|
* 顺序:**Zotero 写权限**(置顶 —— 写入开关 + 授权/重读按钮,写成显眼的操作卡)、
|
|
1852
1855
|
* **API 设置**(本地 API 与面板行为)、**MCP 设置**(集成 MCP 连接 + 工具清单)。
|
|
1853
1856
|
* 写权限放最前是因为「没点授权按钮 → 写操作全失败」是最常见的踩坑点,不能让用户
|
|
@@ -1894,6 +1897,13 @@ const MCP_FIELDS = [{
|
|
|
1894
1897
|
}];
|
|
1895
1898
|
const ALL_FIELDS = [...API_FIELDS, ...MCP_FIELDS];
|
|
1896
1899
|
/**
|
|
1900
|
+
* 自动保存的静默窗口(毫秒):最后一次改动后停手这么久才落盘。
|
|
1901
|
+
*
|
|
1902
|
+
* 太短会把「边打字边写盘」变成一串写请求(每个字符都要 patch 一次配置),
|
|
1903
|
+
* 太长又让关窗前的改动容易丢。600ms 大致等于「打完一个词、手指离开键盘」。
|
|
1904
|
+
*/
|
|
1905
|
+
const AUTOSAVE_DELAY_MS = 600;
|
|
1906
|
+
/**
|
|
1897
1907
|
* 禁用集的字段规格:表单只认文本/数字,因此把字符串数组序列化成 JSON 文本。
|
|
1898
1908
|
* 非 JSON 数组的输入视为非法,阻止保存。
|
|
1899
1909
|
*/
|
|
@@ -1945,7 +1955,7 @@ function booleanField(field) {
|
|
|
1945
1955
|
};
|
|
1946
1956
|
}
|
|
1947
1957
|
/**
|
|
1948
|
-
*
|
|
1958
|
+
* 一张卡片的暂存表单模型:改动先进暂存,由组件的防抖自动保存落盘(没有保存按钮)。
|
|
1949
1959
|
* `scope` 由 `configForms.get(ROW_ID)` 提供(本条的共享配置表单)。
|
|
1950
1960
|
*/
|
|
1951
1961
|
var ZoteroCardController = class {
|
|
@@ -2053,6 +2063,35 @@ const SECTION_HINT_STYLE = {
|
|
|
2053
2063
|
opacity: .72,
|
|
2054
2064
|
marginBottom: 10
|
|
2055
2065
|
};
|
|
2066
|
+
/**
|
|
2067
|
+
* 表单容器:等价于框架 `SettingsForm` 的 `._form_*`(`display:flex;
|
|
2068
|
+
* flex-direction:column`),只是不带那个写死的「保存」页脚。
|
|
2069
|
+
* 页脚没了就等于少了 16px 的底部留白,这里补一点,免得最后一行贴着对话框边缘。
|
|
2070
|
+
*/
|
|
2071
|
+
const FORM_STYLE = {
|
|
2072
|
+
display: "flex",
|
|
2073
|
+
flexDirection: "column",
|
|
2074
|
+
paddingBottom: 8
|
|
2075
|
+
};
|
|
2076
|
+
/** 不可用 / 只读提示,对齐框架 `._readOnly_*` 的字号与颜色。 */
|
|
2077
|
+
const NOTICE_STYLE = {
|
|
2078
|
+
margin: "0 0 12px",
|
|
2079
|
+
fontSize: 12,
|
|
2080
|
+
lineHeight: 1.5,
|
|
2081
|
+
color: "var(--dsw-alias-label-tertiary, rgba(128, 128, 128, 0.9))"
|
|
2082
|
+
};
|
|
2083
|
+
/** 自动保存的状态行(保存中 / 保存失败)。 */
|
|
2084
|
+
const SAVE_STATUS_STYLE = {
|
|
2085
|
+
margin: "0 0 8px",
|
|
2086
|
+
fontSize: 12,
|
|
2087
|
+
lineHeight: 1.5,
|
|
2088
|
+
opacity: .72
|
|
2089
|
+
};
|
|
2090
|
+
const SAVE_FAILED_STYLE = {
|
|
2091
|
+
...SAVE_STATUS_STYLE,
|
|
2092
|
+
opacity: 1,
|
|
2093
|
+
color: "var(--dsw-alias-state-error-primary, var(--dsw-alias-label-error, #b3261e))"
|
|
2094
|
+
};
|
|
2056
2095
|
const GROUP_STYLE = { marginTop: 4 };
|
|
2057
2096
|
const GROUP_HEAD_STYLE = {
|
|
2058
2097
|
fontSize: 12,
|
|
@@ -2148,6 +2187,101 @@ function ZoteroSettingsSection(props) {
|
|
|
2148
2187
|
const [authNotice, setAuthNotice] = (0, react.useState)(null);
|
|
2149
2188
|
const locked = !state.writable;
|
|
2150
2189
|
const disabledSet = readDisabled(state.disabledMcpTools.text);
|
|
2190
|
+
/**
|
|
2191
|
+
* 草稿指纹:任何字段改动都会换一个字符串。
|
|
2192
|
+
*
|
|
2193
|
+
* `dirty` 只是布尔,连着改两次仍是 `true`,靠它做 effect 依赖会让防抖计时器
|
|
2194
|
+
* 不重启(第二次改动落在第一次的旧计时器上)。指纹进依赖才能真正「最后一次改完
|
|
2195
|
+
* 再等 600ms」。
|
|
2196
|
+
*/
|
|
2197
|
+
const draftKey = [
|
|
2198
|
+
state.zoteroBaseUrl.text,
|
|
2199
|
+
state.mcpUrl.text,
|
|
2200
|
+
state.requestTimeoutMs.text,
|
|
2201
|
+
state.mcpProbeTimeoutMs.text,
|
|
2202
|
+
state.fulltextMaxBytes.text,
|
|
2203
|
+
state.defaultLimit.text,
|
|
2204
|
+
state.disabledMcpTools.text,
|
|
2205
|
+
state.writeEnabled.text
|
|
2206
|
+
].join("\0");
|
|
2207
|
+
/**
|
|
2208
|
+
* 自动保存:改完停手 {@link AUTOSAVE_DELAY_MS} 落盘。
|
|
2209
|
+
*
|
|
2210
|
+
* 三种情况明确不排队:
|
|
2211
|
+
* - `invalid`:有字段填得解析不出来(比如数字框里打了字母),存下去会写坏配置,
|
|
2212
|
+
* 字段自己会亮红提示,用户改对了自然会重新排队;
|
|
2213
|
+
* - `saving`:上一次写还在飞。等它落地后 `saving` 变 false,这条 effect 会重跑,
|
|
2214
|
+
* 仍在 dirty 就继续排 —— 所以连续快速改动不会被 `save()` 的 `saving` 早退吞掉;
|
|
2215
|
+
* - `failed`:写盘失败(被更高优先级 patch 层覆盖、网络断等)。**不自动重试**,
|
|
2216
|
+
* 否则每 600ms 打一次后端;`stage()` 会把 `failed` 清掉,用户再改一次即可重来。
|
|
2217
|
+
*/
|
|
2218
|
+
(0, react.useEffect)(() => {
|
|
2219
|
+
if (!state.dirty || state.invalid || state.saving || state.failed) return;
|
|
2220
|
+
const timer = setTimeout(() => {
|
|
2221
|
+
props.save();
|
|
2222
|
+
}, AUTOSAVE_DELAY_MS);
|
|
2223
|
+
return () => {
|
|
2224
|
+
clearTimeout(timer);
|
|
2225
|
+
};
|
|
2226
|
+
}, [
|
|
2227
|
+
draftKey,
|
|
2228
|
+
state.dirty,
|
|
2229
|
+
state.invalid,
|
|
2230
|
+
state.saving,
|
|
2231
|
+
state.failed
|
|
2232
|
+
]);
|
|
2233
|
+
/**
|
|
2234
|
+
* 一次写入落地后,重取工具清单与写权限状态。
|
|
2235
|
+
*
|
|
2236
|
+
* 这两处的「事实」在 Host 侧:保存会按新开关重建工具注册,写通道状态也要重读
|
|
2237
|
+
* 才会从「未开启」翻成「待授权」(原来靠 `onSave` 里那个 400ms 定时器猜落盘时间,
|
|
2238
|
+
* 现在 `saving` 由模型自己翻转,时机是准的)。
|
|
2239
|
+
*/
|
|
2240
|
+
const wasSaving = (0, react.useRef)(false);
|
|
2241
|
+
(0, react.useEffect)(() => {
|
|
2242
|
+
if (state.saving) {
|
|
2243
|
+
wasSaving.current = true;
|
|
2244
|
+
return;
|
|
2245
|
+
}
|
|
2246
|
+
if (!wasSaving.current) return;
|
|
2247
|
+
wasSaving.current = false;
|
|
2248
|
+
reloadTools();
|
|
2249
|
+
reloadWrite();
|
|
2250
|
+
}, [state.saving]);
|
|
2251
|
+
/**
|
|
2252
|
+
* 离开页面时处理残留草稿:合法的立刻冲掉(不然这 600ms 内的改动会悄悄丢),
|
|
2253
|
+
* 非法的直接丢弃(旧 `SettingsForm` 的 unmount 语义,避免下次打开还挂着一片红)。
|
|
2254
|
+
*
|
|
2255
|
+
* 用 ref 而不是把 effect 依赖铺开:这个 effect 只该在卸载时跑一次。
|
|
2256
|
+
*/
|
|
2257
|
+
const pendingRef = (0, react.useRef)({
|
|
2258
|
+
dirty: false,
|
|
2259
|
+
invalid: false,
|
|
2260
|
+
save: () => {},
|
|
2261
|
+
discard: () => {}
|
|
2262
|
+
});
|
|
2263
|
+
(0, react.useEffect)(() => {
|
|
2264
|
+
pendingRef.current = {
|
|
2265
|
+
dirty: state.dirty,
|
|
2266
|
+
invalid: state.invalid,
|
|
2267
|
+
save: () => {
|
|
2268
|
+
props.save();
|
|
2269
|
+
},
|
|
2270
|
+
discard: () => {
|
|
2271
|
+
props.discard();
|
|
2272
|
+
}
|
|
2273
|
+
};
|
|
2274
|
+
}, [
|
|
2275
|
+
draftKey,
|
|
2276
|
+
state.dirty,
|
|
2277
|
+
state.invalid
|
|
2278
|
+
]);
|
|
2279
|
+
(0, react.useEffect)(() => () => {
|
|
2280
|
+
const pending = pendingRef.current;
|
|
2281
|
+
if (!pending.dirty) return;
|
|
2282
|
+
if (pending.invalid) pending.discard();
|
|
2283
|
+
else pending.save();
|
|
2284
|
+
}, []);
|
|
2151
2285
|
const toggle = (name, enabled) => {
|
|
2152
2286
|
const next = new Set(disabledSet);
|
|
2153
2287
|
if (enabled) next.delete(name);
|
|
@@ -2347,28 +2481,37 @@ function ZoteroSettingsSection(props) {
|
|
|
2347
2481
|
})]
|
|
2348
2482
|
}), renderWriteBody()]
|
|
2349
2483
|
});
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2484
|
+
const renderStatus = () => {
|
|
2485
|
+
if (state.failed) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
2486
|
+
style: SAVE_FAILED_STYLE,
|
|
2487
|
+
role: "status",
|
|
2488
|
+
children: t("form.autosaveFailed")
|
|
2489
|
+
});
|
|
2490
|
+
if (state.saving) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
2491
|
+
style: SAVE_STATUS_STYLE,
|
|
2492
|
+
role: "status",
|
|
2493
|
+
children: t("form.autosaving")
|
|
2494
|
+
});
|
|
2495
|
+
return null;
|
|
2496
|
+
};
|
|
2497
|
+
if (!state.available) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
2498
|
+
style: NOTICE_STYLE,
|
|
2499
|
+
role: "status",
|
|
2500
|
+
children: t("form.unavailable")
|
|
2501
|
+
});
|
|
2502
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2503
|
+
style: FORM_STYLE,
|
|
2367
2504
|
children: [
|
|
2505
|
+
state.writable ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
2506
|
+
style: NOTICE_STYLE,
|
|
2507
|
+
role: "status",
|
|
2508
|
+
children: t("form.readOnly")
|
|
2509
|
+
}),
|
|
2368
2510
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2369
2511
|
style: SECTION_HINT_STYLE,
|
|
2370
2512
|
children: t("settings.hint")
|
|
2371
2513
|
}),
|
|
2514
|
+
renderStatus(),
|
|
2372
2515
|
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
2373
2516
|
style: GROUP_STYLE,
|
|
2374
2517
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h4", {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-plugin-zotero",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Map your Zotero library into DSH: let AI operate Zotero for you and help you read papers. Browse collections and tags in the sidebar, read PDFs with highlights in place, and cite excerpts, annotations, notes or whole items into the chat. The model works from the source text for reviews, comparisons and data extraction, and can also search and organize the library, import papers and attach translations back to items; first use needs the Zotero MCP plugin and the local API enabled.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dsh",
|