@duke-dsh-plugins/dsh-remote-control 1.2.0 → 1.3.0

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.
@@ -2048,61 +2048,76 @@ export class HostBridge {
2048
2048
  const signal = this.#signal(30_000);
2049
2049
  try {
2050
2050
  const sc = this.#sc();
2051
- // v1.1.1(§5.10.2):交付物图片作为**独立**的历史消息(两条回包路径都要带上)
2052
- const delivered = await this.#deliveredHistoryMessages(sessionId);
2053
- const page = await this.#readHistoryPage(sc, sessionId, maxMessages, beforeSeq, signal);
2054
- const messages = [];
2055
- let oldestSeq = Number.MAX_SAFE_INTEGER;
2056
- let oldestEventSeq = Number.MAX_SAFE_INTEGER;
2057
- for (const record of page?.records ?? []) {
2058
- const rawSeq = Number(record?.event?.seq);
2059
- if (Number.isSafeInteger(rawSeq) && rawSeq >= 0 && rawSeq < oldestEventSeq) {
2060
- oldestEventSeq = rawSeq;
2051
+ while (true) {
2052
+ // 每轮都重建完整回包:fitReplyBudget 会就地剥缩略图 / 删 images[],
2053
+ // 尤其不能把上一轮已追加的交付物图片对象带进下一次重试。
2054
+ const delivered = await this.#deliveredHistoryMessages(sessionId);
2055
+ const page = await this.#readHistoryPage(sc, sessionId, maxMessages, beforeSeq, signal);
2056
+ const messages = [];
2057
+ let oldestSeq = Number.MAX_SAFE_INTEGER;
2058
+ let oldestEventSeq = Number.MAX_SAFE_INTEGER;
2059
+ for (const record of page?.records ?? []) {
2060
+ const rawSeq = Number(record?.event?.seq);
2061
+ if (Number.isSafeInteger(rawSeq) && rawSeq >= 0 && rawSeq < oldestEventSeq) {
2062
+ oldestEventSeq = rawSeq;
2063
+ }
2064
+ // v1.0.7:一条事件可能产出「思考 + 正文」两条(mapHistoryMessages)
2065
+ for (const mapped of mapHistoryMessages(sessionId, record)) {
2066
+ messages.push(mapped);
2067
+ // v1.0.9(§5.10):记下 imageId → 附件引用(image.fetch 要用原始字节)
2068
+ this.#rememberImages(mapped.images);
2069
+ if (mapped.seq < oldestSeq) oldestSeq = mapped.seq;
2070
+ }
2061
2071
  }
2062
- // v1.0.7:一条事件可能产出「思考 + 正文」两条(mapHistoryMessages)
2063
- for (const mapped of mapHistoryMessages(sessionId, record)) {
2064
- messages.push(mapped);
2065
- // v1.0.9(§5.10):记下 imageId → 附件引用(image.fetch 要用原始字节)
2066
- this.#rememberImages(mapped.images);
2067
- if (mapped.seq < oldestSeq) oldestSeq = mapped.seq;
2072
+ if (oldestSeq === Number.MAX_SAFE_INTEGER) {
2073
+ // 本页无可聊消息(全被过滤)→ 用页内最老事件 seq 续翻,避免卡页
2074
+ oldestSeq = oldestEventSeq === Number.MAX_SAFE_INTEGER ? 0 : oldestEventSeq;
2068
2075
  }
2069
- }
2070
- if (oldestSeq === Number.MAX_SAFE_INTEGER) {
2071
- // 本页无可聊消息(全被过滤)→ 用页内最老事件 seq 续翻,避免卡页
2072
- oldestSeq = oldestEventSeq === Number.MAX_SAFE_INTEGER ? 0 : oldestEventSeq;
2073
- }
2074
- // v1.0.9(§5.10):缩略图必须内联(客户端立刻显示)——这里补齐
2075
- await attachThumbs(messages, this.#ctx);
2076
- // v1.1.1(§5.10.2):交付物图片作为**独立**的历史消息追加进去
2077
- // (宿主的持久副本里没有它们 → 不补的话图片「一闪而过然后消失」)。
2078
- messages.push(...delivered);
2079
- // v1.0.6(§5.7):工作步骤(工具调用)——旧客户端只读 messages,不受影响
2080
- const steps = mapHistorySteps(page?.records ?? []);
2081
- // v1.0.9:帧预算守卫——中继的 1MiB 是 **ws 单帧**上限,超了 ws 直接断链
2082
- //(不是丢一帧)。先剥缩略图、再丢 images[];实在装不下(只剩文字就超了)
2083
- // → 回 error,宁可这一页失败也不能把整条链路顶爆。
2084
- const value = { messages, steps, hasMore: page?.hasMore === true, oldestSeq };
2085
- const fit = fitReplyBudget(value);
2086
- if (fit.strippedThumbs > 0 || fit.strippedImages > 0) {
2087
- this.#log("warn", "history reply trimmed to fit the relay frame budget", {
2076
+ // v1.0.9(§5.10):缩略图必须内联(客户端立刻显示)——这里补齐
2077
+ await attachThumbs(messages, this.#ctx);
2078
+ // v1.1.1(§5.10.2):交付物图片作为**独立**的历史消息追加进去
2079
+ // (宿主的持久副本里没有它们 → 不补的话图片「一闪而过然后消失」)。
2080
+ messages.push(...delivered);
2081
+ // v1.0.6(§5.7):工作步骤(工具调用)——旧客户端只读 messages,不受影响
2082
+ const steps = mapHistorySteps(page?.records ?? []);
2083
+ // v1.0.9:帧预算守卫——中继的 1MiB 是 **ws 单帧**上限,超了 ws 直接断链
2084
+ // (不是丢一帧)。先剥缩略图、再丢 images[];只剩文字仍超限时自动减半
2085
+ // 页大小并重读。只有单条消息仍装不下时才回 history-too-large。
2086
+ const value = { messages, steps, hasMore: page?.hasMore === true, oldestSeq };
2087
+ const fit = fitReplyBudget(value);
2088
+ if (fit.strippedThumbs > 0 || fit.strippedImages > 0) {
2089
+ this.#log("warn", "history reply trimmed to fit the relay frame budget", {
2090
+ sessionId,
2091
+ strippedThumbs: fit.strippedThumbs,
2092
+ strippedImages: fit.strippedImages,
2093
+ bytes: fit.bytes,
2094
+ });
2095
+ }
2096
+ if (!fit.overflow) {
2097
+ // 游标必须属于实际成功的这一页,而不是首次超限的大页。
2098
+ this.#reply(m, resultOf(m, fit.value));
2099
+ return;
2100
+ }
2101
+ if (maxMessages <= 1) {
2102
+ this.#reply(
2103
+ m,
2104
+ errorOf(
2105
+ m,
2106
+ "history-too-large",
2107
+ "这一页会话内容过大,无法在一帧内传输(请缩小每页条数后重试)。",
2108
+ ),
2109
+ );
2110
+ return;
2111
+ }
2112
+ const retryMaxMessages = Math.max(1, Math.floor(maxMessages / 2));
2113
+ this.#log("warn", "history reply still too large; retrying with fewer messages", {
2088
2114
  sessionId,
2089
- strippedThumbs: fit.strippedThumbs,
2090
- strippedImages: fit.strippedImages,
2115
+ maxMessages,
2116
+ retryMaxMessages,
2091
2117
  bytes: fit.bytes,
2092
2118
  });
2119
+ maxMessages = retryMaxMessages;
2093
2120
  }
2094
- if (fit.overflow) {
2095
- this.#reply(
2096
- m,
2097
- errorOf(
2098
- m,
2099
- "history-too-large",
2100
- "这一页会话内容过大,无法在一帧内传输(请缩小每页条数后重试)。",
2101
- ),
2102
- );
2103
- return;
2104
- }
2105
- this.#reply(m, resultOf(m, fit.value));
2106
2121
  } catch (e) {
2107
2122
  this.#reply(m, errorOf(m, "session-history-failed", errText(e)));
2108
2123
  }
package/market/index.json CHANGED
@@ -69,6 +69,26 @@
69
69
  "sortKeys": {}
70
70
  },
71
71
  "versions": [
72
+ {
73
+ "version": "1.3.0",
74
+ "publishTimestamp": 1794185521,
75
+ "source": {
76
+ "type": "npm"
77
+ },
78
+ "engines": {
79
+ "dsh": "^0.1.5-rc.3 || ^0.2.0-rc.1 || ^0.2.1-rc.0"
80
+ }
81
+ },
82
+ {
83
+ "version": "1.2.1",
84
+ "publishTimestamp": 1794128655,
85
+ "source": {
86
+ "type": "npm"
87
+ },
88
+ "engines": {
89
+ "dsh": "^0.1.5-rc.3 || ^0.2.0-rc.1 || ^0.2.1-rc.0"
90
+ }
91
+ },
72
92
  {
73
93
  "version": "1.2.0",
74
94
  "publishTimestamp": 1793981953,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duke-dsh-plugins/dsh-remote-control",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Remote-control bridge for DeepSeek Harness: pairs a HarmonyOS phone app with the desktop Host over an end-to-end-encrypted public relay (WebSocket). Lets the phone list/create/switch sessions, send prompts, watch streamed replies, cancel turns, and answer approval and ask-user-question requests from anywhere; pushes Huawei Push Kit notifications (gracefully disabled when AGC is unconfigured) for approvals, questions, and turn completion. The pairing QR lives in the DSH settings panel (\"DSH Pocket\"). Fail-open by design: any relay timeout or fault hands the request back to the desktop answerer.",
5
5
  "type": "module",
6
6
  "main": "index.js",