@a9i5k4/dsh-literature 0.3.2 → 0.3.4

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 (2) hide show
  1. package/lib/index.js +17 -8
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -461,16 +461,21 @@ var init_sse = __esm({
461
461
  // src/node/extract/identifiers.js
462
462
  function trimRight(s) {
463
463
  let out = s;
464
- for (; ; ) {
464
+ while (out.length > 0) {
465
465
  const next = out.replace(TRIM_RIGHT, "");
466
- const last = next[next.length - 1];
467
- if ((last === ")" || last === "]" || last === "}" || last === "\uFF09" || last === "\u3011") && !next.slice(0, -1).includes(last === ")" ? "(" : last === "]" ? "[" : last === "}" ? "{" : last === "\uFF09" ? "\uFF08" : "\u3010")) {
466
+ if (next !== out) {
468
467
  out = next;
469
468
  continue;
470
469
  }
471
- if (next === out) return next;
472
- out = next;
470
+ const last = out[out.length - 1];
471
+ const openFor = CLOSE_TO_OPEN[last];
472
+ if (openFor && !out.slice(0, -1).includes(openFor)) {
473
+ out = out.slice(0, -1);
474
+ continue;
475
+ }
476
+ return out;
473
477
  }
478
+ return out;
474
479
  }
475
480
  function push(list, seen, entry) {
476
481
  const dedupeKey = `${entry.kind}:${entry.value.toLowerCase()}`;
@@ -582,11 +587,12 @@ function extractIdentifiers(text, options = {}) {
582
587
  }
583
588
  return out.sort((a, b) => a.index - b.index);
584
589
  }
585
- var TRIM_RIGHT, CJK_PUNCT, DOI_TAIL, DOI_CORE, DOI_HINT, DOI_LABEL, ARXIV_NEW, ARXIV_OLD, URL_RE, ARXIV_URL, PMID, ISBN, QUOTED, QUOTED_FALLBACK;
590
+ var TRIM_RIGHT, CJK_PUNCT, CLOSE_TO_OPEN, DOI_TAIL, DOI_CORE, DOI_HINT, DOI_LABEL, ARXIV_NEW, ARXIV_OLD, URL_RE, ARXIV_URL, PMID, ISBN, QUOTED, QUOTED_FALLBACK;
586
591
  var init_identifiers = __esm({
587
592
  "src/node/extract/identifiers.js"() {
588
593
  TRIM_RIGHT = /[.,;:!?。、,;:!?…—>'">)》\]]+$/;
589
594
  CJK_PUNCT = "\u3002\u3001\uFF0C\uFF1B\uFF1A\uFF01\uFF1F\uFF08\uFF09\u3010\u3011\u300A\u300B\u3008\u3009\u2026\u2014\uFF5E\xB7";
595
+ CLOSE_TO_OPEN = { ")": "(", "]": "[", "}": "{", "\uFF09": "\uFF08", "\u3011": "\u3010" };
590
596
  DOI_TAIL = `[^\\s"'<>\`|${CJK_PUNCT}]+`;
591
597
  DOI_CORE = new RegExp(`10\\.\\d{4,9}\\/${DOI_TAIL}`, "gi");
592
598
  DOI_HINT = new RegExp(`(?:https?:\\/\\/)?(?:dx\\.)?doi\\.org\\/(10\\.\\d{4,9}\\/${DOI_TAIL})`, "gi");
@@ -751,7 +757,7 @@ var UA, FetchFailure;
751
757
  var init_net = __esm({
752
758
  "src/node/net.js"() {
753
759
  init_log();
754
- UA = "dsh-literature/0.3.3 (+https://github.com/deepseek-ai/deepseek-harness)";
760
+ UA = "dsh-literature/0.3.4 (+https://github.com/deepseek-ai/deepseek-harness)";
755
761
  FetchFailure = class extends Error {
756
762
  constructor(message, { code = "network", status = 0, retryable = true, cause } = {}) {
757
763
  super(message, { cause });
@@ -1666,12 +1672,15 @@ async function postJson(path, payload, options) {
1666
1672
  }
1667
1673
  return { status: res.status, body: text };
1668
1674
  }
1675
+ function asciiJson(value) {
1676
+ return JSON.stringify(value).replace(/[^\x00-\xFF]/g, (ch) => "\\u" + ch.charCodeAt(0).toString(16).padStart(4, "0"));
1677
+ }
1669
1678
  async function postBuffer(path, buffer, { metadata, contentType, timeoutMs }) {
1670
1679
  const headers = {
1671
1680
  "Content-Type": contentType,
1672
1681
  "Content-Length": String(buffer.length)
1673
1682
  };
1674
- if (metadata) headers["X-Metadata"] = JSON.stringify(metadata);
1683
+ if (metadata) headers["X-Metadata"] = asciiJson(metadata);
1675
1684
  const res = await request(path, { body: buffer, headers, timeoutMs });
1676
1685
  const text = await res.text().catch(() => "");
1677
1686
  if (res.status >= 400) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@a9i5k4/dsh-literature",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "description": "DSH Literature 文献侧窗:在 DeepSeek Harness 侧边栏识别 DOI/arXiv/标题、抓取元数据与全文、写入本地文献库或导出目录,并提供内置 PDF 阅读器(缩放/翻页/目录/搜索/高亮/笔记)。",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",