@a9i5k4/dsh-literature 0.3.3 → 0.3.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.
Files changed (2) hide show
  1. package/lib/index.js +17 -14
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -757,7 +757,7 @@ var UA, FetchFailure;
757
757
  var init_net = __esm({
758
758
  "src/node/net.js"() {
759
759
  init_log();
760
- UA = "dsh-literature/0.3.3 (+https://github.com/deepseek-ai/deepseek-harness)";
760
+ UA = "dsh-literature/0.3.5 (+https://github.com/deepseek-ai/deepseek-harness)";
761
761
  FetchFailure = class extends Error {
762
762
  constructor(message, { code = "network", status = 0, retryable = true, cause } = {}) {
763
763
  super(message, { cause });
@@ -1672,12 +1672,15 @@ async function postJson(path, payload, options) {
1672
1672
  }
1673
1673
  return { status: res.status, body: text };
1674
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
+ }
1675
1678
  async function postBuffer(path, buffer, { metadata, contentType, timeoutMs }) {
1676
1679
  const headers = {
1677
1680
  "Content-Type": contentType,
1678
1681
  "Content-Length": String(buffer.length)
1679
1682
  };
1680
- if (metadata) headers["X-Metadata"] = JSON.stringify(metadata);
1683
+ if (metadata) headers["X-Metadata"] = asciiJson(metadata);
1681
1684
  const res = await request(path, { body: buffer, headers, timeoutMs });
1682
1685
  const text = await res.text().catch(() => "");
1683
1686
  if (res.status >= 400) {
@@ -36403,7 +36406,7 @@ async function readJsonBody2(req) {
36403
36406
  const { readJsonBody: read } = await Promise.resolve().then(() => (init_http(), http_exports));
36404
36407
  return read(req);
36405
36408
  }
36406
- async function handler(req, res, ctx2) {
36409
+ async function handler(req, res, ctx2, { activation } = {}) {
36407
36410
  if (!isLoopbackRequest(req)) {
36408
36411
  writeJson(res, 403, { error: "forbidden: loopback-only", code: "forbidden" });
36409
36412
  return;
@@ -36684,8 +36687,8 @@ async function handler(req, res, ctx2) {
36684
36687
  else res.end();
36685
36688
  }
36686
36689
  }
36687
- function registerRoutes(ctx2, { activation: activation2 } = {}) {
36688
- const disposers = [ctx2.webServer.register({ kind: "prefix", path: PREFIX2, handler: (req, res) => handler(req, res, ctx2) })];
36690
+ function registerRoutes(ctx2, { activation } = {}) {
36691
+ const disposers = [ctx2.webServer.register({ kind: "prefix", path: PREFIX2, handler: (req, res) => handler(req, res, ctx2, { activation }) })];
36689
36692
  if (typeof ctx2.on === "function") {
36690
36693
  disposers.push(
36691
36694
  ctx2.on("session/event", (session) => {
@@ -37304,14 +37307,14 @@ function textFromSessionEvent(event) {
37304
37307
  }
37305
37308
  return "";
37306
37309
  }
37307
- function registerSessionHook(ctx2, { activation: activation2, detectIntent: detectIntent2 } = {}) {
37310
+ function registerSessionHook(ctx2, { activation, detectIntent: detectIntent2 } = {}) {
37308
37311
  const disposers = [];
37309
37312
  disposers.push(
37310
37313
  ctx2.on("session/event", (session, event) => {
37311
37314
  const text = textFromSessionEvent(event);
37312
- if (activation2 && detectIntent2 && event?.type === "user/message") {
37315
+ if (activation && detectIntent2 && event?.type === "user/message") {
37313
37316
  const verdict = detectIntent2(textFromSessionEvent(event));
37314
- if (verdict.active) activation2.activate(verdict.reason);
37317
+ if (verdict.active) activation.activate(verdict.reason);
37315
37318
  }
37316
37319
  if (!text || text.length < 20) return;
37317
37320
  if (!extractIdentifiers(text).length) return;
@@ -37505,12 +37508,12 @@ function apply(ctx2, config) {
37505
37508
  const ready = (async () => {
37506
37509
  await ensureDirs();
37507
37510
  await init();
37508
- const activation2 = createActivation();
37509
- activation2.activate("always-on");
37511
+ const activation = createActivation();
37512
+ activation.activate("always-on");
37510
37513
  const toolsCtl = registerTools(ctx2);
37511
37514
  toolsCtl.mount();
37512
- disposers.push(activation2.onTransition(({ active }) => active ? toolsCtl.mount() : toolsCtl.unmount()));
37513
- disposers.push(() => activation2.dispose());
37515
+ disposers.push(activation.onTransition(({ active }) => active ? toolsCtl.mount() : toolsCtl.unmount()));
37516
+ disposers.push(() => activation.dispose());
37514
37517
  try {
37515
37518
  disposers.push(
37516
37519
  ctx2.systemPrompt.section({
@@ -37530,9 +37533,9 @@ function apply(ctx2, config) {
37530
37533
  } catch (e) {
37531
37534
  error("systemPrompt unavailable:", e.message);
37532
37535
  }
37533
- disposers.push(...registerRoutes(ctx2, { activation: activation2 }));
37536
+ disposers.push(...registerRoutes(ctx2, { activation }));
37534
37537
  try {
37535
- disposers.push(...registerSessionHook(ctx2, { activation: activation2, detectIntent }));
37538
+ disposers.push(...registerSessionHook(ctx2, { activation, detectIntent }));
37536
37539
  } catch (e) {
37537
37540
  error("session hook unavailable:", e.message);
37538
37541
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@a9i5k4/dsh-literature",
3
- "version": "0.3.3",
3
+ "version": "0.3.5",
4
4
  "description": "DSH Literature 文献侧窗:在 DeepSeek Harness 侧边栏识别 DOI/arXiv/标题、抓取元数据与全文、写入本地文献库或导出目录,并提供内置 PDF 阅读器(缩放/翻页/目录/搜索/高亮/笔记)。",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",