@duke-dsh-plugins/dsh-remote-control 1.1.5 → 1.1.6
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/README.md +1 -1
- package/lib/host-bridge.mjs +210 -68
- package/market/index.json +11 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -75,7 +75,7 @@ scripts/verify-pairing.mjs /remote-pairing 命令逻辑自检(mock ctx;devD
|
|
|
75
75
|
|
|
76
76
|
```bash
|
|
77
77
|
# DSH 插件市场(推荐):在「设置 → 插件市场」添加索引 URL 后搜「DSH Pocket」安装
|
|
78
|
-
# https://unpkg.com/@duke-dsh-plugins/dsh-remote-control
|
|
78
|
+
# https://unpkg.com/@duke-dsh-plugins/dsh-remote-control@latest/market/index.json
|
|
79
79
|
#
|
|
80
80
|
# 或直接用插件管理器:会解析 peerDependencies 并做兼容性 gate
|
|
81
81
|
plugin_manager install @duke-dsh-plugins/dsh-remote-control
|
package/lib/host-bridge.mjs
CHANGED
|
@@ -24,8 +24,9 @@
|
|
|
24
24
|
// 生成缩略图,按 §5.10 的 assistant.image / image.fetch 通道发给手机。
|
|
25
25
|
import { randomUUID, createHash } from "node:crypto";
|
|
26
26
|
import { readFileSync } from "node:fs";
|
|
27
|
-
import { readFile } from "node:fs/promises";
|
|
28
|
-
import { hostname } from "node:os";
|
|
27
|
+
import { mkdir, readFile } from "node:fs/promises";
|
|
28
|
+
import { homedir, hostname } from "node:os";
|
|
29
|
+
import { join } from "node:path";
|
|
29
30
|
import { createRequire } from "node:module";
|
|
30
31
|
import { msg, sanitizeEnvelope } from "./protocol.mjs";
|
|
31
32
|
import { ASSISTANT_THROTTLE_PER_SEC } from "./config.mjs";
|
|
@@ -51,6 +52,23 @@ import {
|
|
|
51
52
|
*/
|
|
52
53
|
const DELIVERED_MAX_BYTES = 20 * 1024 * 1024;
|
|
53
54
|
|
|
55
|
+
/**
|
|
56
|
+
* 单会话待发流式文本的字符上限(正文 + 思考合计)。
|
|
57
|
+
*
|
|
58
|
+
* 流式缓冲按「保序队列」实现:同一 125ms 窗口内的块都受这个上限约束,
|
|
59
|
+
* 超了从**最旧**的内容开始丢(保留顺序,不丢新内容),
|
|
60
|
+
* 避免长时间运行 / 异常事件流把内存吃满。
|
|
61
|
+
*/
|
|
62
|
+
const STREAM_BUFFER_MAX_CHARS = 65_536;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* 单会话待发流式**块**数的上限。
|
|
66
|
+
*
|
|
67
|
+
* 块只在「类型切换」时新增,125ms 窗口内正常也就几条;但异常事件流
|
|
68
|
+
* (重连回放 / 高频交替)不该让块数无界增长——超了从最旧的块开始丢。
|
|
69
|
+
*/
|
|
70
|
+
const STREAM_BUFFER_MAX_BLOCKS = 256;
|
|
71
|
+
|
|
54
72
|
/**
|
|
55
73
|
* 单会话待执行消息的条数上限(契约 §5.2 session.queue)。
|
|
56
74
|
*
|
|
@@ -783,6 +801,34 @@ export function hostErrorOf(e, fallbackCode) {
|
|
|
783
801
|
return { code, message: errText(e) };
|
|
784
802
|
}
|
|
785
803
|
|
|
804
|
+
/**
|
|
805
|
+
* 契约 §5.1 session.create:**默认工作目录**。
|
|
806
|
+
*
|
|
807
|
+
* 手机端不传 cwd(或传空串)时,不再让宿主回退到 DSH 后端的 process.cwd(),
|
|
808
|
+
* 而是解析为 Host 用户主目录下的 `.dsh/remote`(用 node:path.join 拼,
|
|
809
|
+
* Windows / POSIX 都对)。
|
|
810
|
+
* @param {string} [home] 用户主目录(默认 os.homedir())
|
|
811
|
+
* @returns {string} 绝对路径
|
|
812
|
+
*/
|
|
813
|
+
export function defaultSessionCwd(home = homedir()) {
|
|
814
|
+
return join(home, ".dsh", "remote");
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
/**
|
|
818
|
+
* 契约 §5.1 session.create:解析手机端传来的 cwd。
|
|
819
|
+
*
|
|
820
|
+
* 缺省 / undefined / 空串 / trim 后空串 → 默认目录(`~/.dsh/remote`);
|
|
821
|
+
* 其余按既有行为 trim 后返回;显式 cwd 不自动创建目录。
|
|
822
|
+
* @param {unknown} raw payload.cwd
|
|
823
|
+
* @param {string} [home] 用户主目录(默认 os.homedir())
|
|
824
|
+
* @returns {{cwd:string, isDefault:boolean}}
|
|
825
|
+
*/
|
|
826
|
+
export function resolveSessionCwd(raw, home = homedir()) {
|
|
827
|
+
const explicit = typeof raw === "string" ? raw : "";
|
|
828
|
+
if (explicit.trim() !== "") return { cwd: explicit.trim(), isDefault: false };
|
|
829
|
+
return { cwd: defaultSessionCwd(home), isDefault: true };
|
|
830
|
+
}
|
|
831
|
+
|
|
786
832
|
/** result / error 信封(契约 §5)。 */
|
|
787
833
|
function resultOf(m, value) {
|
|
788
834
|
return msg("result", { id: m.id, ok: true, value });
|
|
@@ -802,9 +848,16 @@ export class HostBridge {
|
|
|
802
848
|
#cfg;
|
|
803
849
|
#log;
|
|
804
850
|
#pluginVersion;
|
|
851
|
+
// v1.1.4:session.create 的默认工作目录基准(用户主目录)+ 建目录实现
|
|
852
|
+
// —— 二者都可注入,生产用 homedir() / fs.mkdir,测试用临时目录(不写真实 home)。
|
|
853
|
+
#homeDir;
|
|
854
|
+
#mkdir;
|
|
805
855
|
#disposed = false; // dispose() 后禁止一切出站与拦截
|
|
806
|
-
|
|
807
|
-
|
|
856
|
+
// v1.1.x:每个 session 一个**统一保序**的流式缓冲(正文 + 思考共用一条队列)
|
|
857
|
+
// sessionId -> { blocks: [{kind:"text"|"reasoning", text}], timer }
|
|
858
|
+
// 同一 125ms 窗口内只合并**相邻同类**块;不同类各占一块 → 冲刷时严格按
|
|
859
|
+
// 原始 chunk 顺序发 assistant.delta / assistant.reasoningDelta(跨类型也保序)。
|
|
860
|
+
#streamBuf = new Map();
|
|
808
861
|
#modelSelections = new Map(); // sessionId -> {provider, model, reasoningEffort?}(v1.0.8 内存态)
|
|
809
862
|
#pending = new Map(); // askId -> { resolve, kind, sessionId, timer, abortHandler, signal }
|
|
810
863
|
#titles = new Map(); // sessionId -> title(turn.end 推送文案用)
|
|
@@ -836,6 +889,8 @@ export class HostBridge {
|
|
|
836
889
|
* push: { notify:(req:object)=>Promise<{ok:boolean,reason?:string}>, configured:boolean, unavailableReason?:()=>string },
|
|
837
890
|
* config: any,
|
|
838
891
|
* log: (level:"info"|"warn"|"error", message:string, extra?:object)=>void,
|
|
892
|
+
* homeDir?: string, // v1.1.4:默认 cwd 的基准目录(默认 os.homedir())
|
|
893
|
+
* mkdir?: (p:string)=>Promise<unknown>, // v1.1.4:建默认目录(默认 fs.mkdir recursive)
|
|
839
894
|
* }} deps
|
|
840
895
|
*/
|
|
841
896
|
constructor(deps) {
|
|
@@ -844,6 +899,12 @@ export class HostBridge {
|
|
|
844
899
|
this.#push = deps.push;
|
|
845
900
|
this.#cfg = deps.config;
|
|
846
901
|
this.#log = deps.log;
|
|
902
|
+
this.#homeDir =
|
|
903
|
+
typeof deps.homeDir === "string" && deps.homeDir !== "" ? deps.homeDir : homedir();
|
|
904
|
+
this.#mkdir =
|
|
905
|
+
typeof deps.mkdir === "function"
|
|
906
|
+
? deps.mkdir
|
|
907
|
+
: (p) => mkdir(p, { recursive: true });
|
|
847
908
|
this.#pluginVersion = pluginVersion();
|
|
848
909
|
this.#hostName = hostname();
|
|
849
910
|
this.#dshVersion = dshVersion();
|
|
@@ -872,6 +933,8 @@ export class HostBridge {
|
|
|
872
933
|
this.#queues.delete(key);
|
|
873
934
|
this.#deliveredEntries.delete(key);
|
|
874
935
|
this.#runningSessions.delete(key);
|
|
936
|
+
// 待发的流式增量也没意义了(定时器一并清掉,别在会话没了之后还出站)
|
|
937
|
+
this.#dropStream(key);
|
|
875
938
|
this.#sendEvent("session.removed", { sessionId: key });
|
|
876
939
|
});
|
|
877
940
|
this.#on("api-session/status", (sessionId, running) => {
|
|
@@ -890,20 +953,27 @@ export class HostBridge {
|
|
|
890
953
|
|
|
891
954
|
// agent/assistant-stream:文本增量与**思考增量分流**,按 sessionId 合并节流(≤8 条/秒)
|
|
892
955
|
// v1.0.7:chunk.type==='reasoning-delta' → assistant.reasoningDelta(§5.2)
|
|
956
|
+
// v1.1.x:两者进**同一条保序队列**——原先两个独立缓冲 + 固定「先正文后思考」
|
|
957
|
+
// 的冲刷顺序会把 reasoning→text 的 wire 顺序倒过来(手机端按到达顺序渲染,
|
|
958
|
+
// 与冷启动历史「思考在前」不一致,用户看到正文跑到思考前面)。
|
|
893
959
|
this.#on("agent/assistant-stream", (payload) => {
|
|
894
960
|
try {
|
|
895
961
|
const frame = payload?.frame;
|
|
896
|
-
if (!frame
|
|
897
|
-
const chunk = frame.chunk;
|
|
898
|
-
if (!chunk || typeof chunk.text !== "string" || chunk.text === "") return;
|
|
899
|
-
if (chunk.type !== "text-delta" && chunk.type !== "reasoning-delta") return;
|
|
962
|
+
if (!frame) return;
|
|
900
963
|
const sessionId = payload?.agent?.session?.id;
|
|
901
964
|
if (!sessionId) return;
|
|
902
|
-
|
|
903
|
-
|
|
965
|
+
// 一条 assistant 流结束时立即冲刷,后续 tool.call/result、图片等持久事件
|
|
966
|
+
// 不得越过尚未上屏的正文/思考。
|
|
967
|
+
if (frame.type === "end") {
|
|
968
|
+
this.#flushStream(String(sessionId));
|
|
904
969
|
return;
|
|
905
970
|
}
|
|
906
|
-
|
|
971
|
+
if (frame.type !== "chunk") return;
|
|
972
|
+
const chunk = frame.chunk;
|
|
973
|
+
if (!chunk || typeof chunk.text !== "string" || chunk.text === "") return;
|
|
974
|
+
if (chunk.type !== "text-delta" && chunk.type !== "reasoning-delta") return;
|
|
975
|
+
// 正文与思考进**同一条保序队列**(v1.1.x):跨类型的先后关系必须保住
|
|
976
|
+
this.#queueStream(String(sessionId), chunk.type === "reasoning-delta" ? "reasoning" : "text", chunk.text);
|
|
907
977
|
} catch (e) {
|
|
908
978
|
this.#log("warn", "assistant-stream bridge error", { error: errText(e) });
|
|
909
979
|
}
|
|
@@ -915,8 +985,8 @@ export class HostBridge {
|
|
|
915
985
|
const sessionId = payload?.agent?.session?.id;
|
|
916
986
|
if (!sessionId) return;
|
|
917
987
|
if (payload.status === "idle") {
|
|
918
|
-
|
|
919
|
-
this.#
|
|
988
|
+
// 先统一冲刷全部待发块(正文 + 思考,**保持原始顺序**),再发 turn.end
|
|
989
|
+
this.#flushStream(String(sessionId));
|
|
920
990
|
this.#sendEvent("turn.end", { sessionId: String(sessionId), status: "idle" });
|
|
921
991
|
this.#maybeNotifyTurnEnd(String(sessionId));
|
|
922
992
|
}
|
|
@@ -931,8 +1001,8 @@ export class HostBridge {
|
|
|
931
1001
|
if (!sessionId) return;
|
|
932
1002
|
const err = payload.error;
|
|
933
1003
|
const message = err && typeof err.message === "string" ? err.message : String(err);
|
|
934
|
-
|
|
935
|
-
this.#
|
|
1004
|
+
// 与 idle 同口径:先统一冲刷(保序),再发 turn.end
|
|
1005
|
+
this.#flushStream(String(sessionId));
|
|
936
1006
|
this.#sendEvent("turn.end", { sessionId: String(sessionId), status: "error", error: message });
|
|
937
1007
|
this.#maybeNotifyTurnEnd(String(sessionId), message);
|
|
938
1008
|
} catch (e) {
|
|
@@ -954,12 +1024,18 @@ export class HostBridge {
|
|
|
954
1024
|
const type = event?.type;
|
|
955
1025
|
if (type === "tool/call") {
|
|
956
1026
|
const mapped = mapToolCallEvent(sessionId, event);
|
|
957
|
-
if (mapped !== null)
|
|
1027
|
+
if (mapped !== null) {
|
|
1028
|
+
this.#flushStream(sessionId);
|
|
1029
|
+
this.#sendEvent("tool.call", mapped);
|
|
1030
|
+
}
|
|
958
1031
|
return;
|
|
959
1032
|
}
|
|
960
1033
|
if (type === "tool/result") {
|
|
961
1034
|
const mapped = mapToolResultEvent(sessionId, event);
|
|
962
|
-
if (mapped !== null)
|
|
1035
|
+
if (mapped !== null) {
|
|
1036
|
+
this.#flushStream(sessionId);
|
|
1037
|
+
this.#sendEvent("tool.result", mapped);
|
|
1038
|
+
}
|
|
963
1039
|
return;
|
|
964
1040
|
}
|
|
965
1041
|
if (type === "model/selection") {
|
|
@@ -971,13 +1047,16 @@ export class HostBridge {
|
|
|
971
1047
|
return;
|
|
972
1048
|
}
|
|
973
1049
|
if (type === "assistant/message") {
|
|
974
|
-
// v1.0.9(§5.10):助手消息里的图片 → 广播 assistant.image
|
|
1050
|
+
// v1.0.9(§5.10):助手消息里的图片 → 广播 assistant.image(带内联缩略图)。
|
|
1051
|
+
// 即便本条没有图片,也先把之前的流式文本/思考冲出去,保持时间线顺序。
|
|
1052
|
+
this.#flushStream(sessionId);
|
|
975
1053
|
this.#emitAssistantImages(sessionId, event);
|
|
976
1054
|
return;
|
|
977
1055
|
}
|
|
978
1056
|
if (type === "deliverables/presented") {
|
|
979
1057
|
// present 工具投递的文件:宿主记的是**路径**,不是图片附件块 →
|
|
980
1058
|
// 不桥接的话手机端永远看不到这些图(用户反馈:桌面有、手机没有)。
|
|
1059
|
+
this.#flushStream(sessionId);
|
|
981
1060
|
void this.#emitDeliveredImages(sessionId, event);
|
|
982
1061
|
return;
|
|
983
1062
|
}
|
|
@@ -1212,14 +1291,10 @@ export class HostBridge {
|
|
|
1212
1291
|
/** 释放全部资源(定时器/待答项/监听)。 */
|
|
1213
1292
|
dispose() {
|
|
1214
1293
|
this.#disposed = true;
|
|
1215
|
-
for (const b of this.#
|
|
1216
|
-
if (b.timer !== null) clearTimeout(b.timer);
|
|
1217
|
-
}
|
|
1218
|
-
this.#deltaBuf.clear();
|
|
1219
|
-
for (const b of this.#reasoningBuf.values()) {
|
|
1294
|
+
for (const b of this.#streamBuf.values()) {
|
|
1220
1295
|
if (b.timer !== null) clearTimeout(b.timer);
|
|
1221
1296
|
}
|
|
1222
|
-
this.#
|
|
1297
|
+
this.#streamBuf.clear();
|
|
1223
1298
|
for (const entry of this.#pending.values()) {
|
|
1224
1299
|
if (entry.timer !== null) clearTimeout(entry.timer);
|
|
1225
1300
|
if (entry.signal && entry.abortHandler) {
|
|
@@ -1606,58 +1681,101 @@ export class HostBridge {
|
|
|
1606
1681
|
}
|
|
1607
1682
|
}
|
|
1608
1683
|
|
|
1609
|
-
// ---- assistant
|
|
1684
|
+
// ---- assistant 流式增量:统一保序缓冲(正文 + 思考,v1.1.x)---------------
|
|
1610
1685
|
|
|
1611
|
-
|
|
1612
|
-
|
|
1686
|
+
/**
|
|
1687
|
+
* 入队一个流式增量块。
|
|
1688
|
+
*
|
|
1689
|
+
* 规则:
|
|
1690
|
+
* - 正文(text)与思考(reasoning)进**同一条队列**,块按到达顺序排;
|
|
1691
|
+
* - 同一窗口内**只合并相邻同类**块(尾块同类就并进去);
|
|
1692
|
+
* - 不同类**不跨块合并**——否则 reasoning 与 text 会糊成一条,
|
|
1693
|
+
* 冲刷时无法还原原始先后顺序。
|
|
1694
|
+
*
|
|
1695
|
+
* @param {string} sessionId
|
|
1696
|
+
* @param {"text"|"reasoning"} kind
|
|
1697
|
+
* @param {string} text
|
|
1698
|
+
*/
|
|
1699
|
+
#queueStream(sessionId, kind, text) {
|
|
1700
|
+
if (this.#disposed) return; // dispose() 后不再产生任何出站
|
|
1701
|
+
let b = this.#streamBuf.get(sessionId);
|
|
1613
1702
|
if (b === undefined) {
|
|
1614
|
-
b = {
|
|
1615
|
-
this.#
|
|
1703
|
+
b = { blocks: [], timer: null };
|
|
1704
|
+
this.#streamBuf.set(sessionId, b);
|
|
1616
1705
|
}
|
|
1617
|
-
b.
|
|
1618
|
-
if (
|
|
1706
|
+
const last = b.blocks[b.blocks.length - 1];
|
|
1707
|
+
if (last !== undefined && last.kind === kind) {
|
|
1708
|
+
last.text += text;
|
|
1709
|
+
} else {
|
|
1710
|
+
b.blocks.push({ kind, text });
|
|
1711
|
+
}
|
|
1712
|
+
this.#trimStreamBuffer(b);
|
|
1619
1713
|
if (b.timer === null) {
|
|
1620
|
-
b.timer = setTimeout(() => this.#
|
|
1714
|
+
b.timer = setTimeout(() => this.#flushStream(sessionId), Math.ceil(1000 / ASSISTANT_THROTTLE_PER_SEC));
|
|
1715
|
+
}
|
|
1716
|
+
}
|
|
1717
|
+
|
|
1718
|
+
/**
|
|
1719
|
+
* 内存上限:单会话待发文本(正文 + 思考合计)不超过 STREAM_BUFFER_MAX_CHARS。
|
|
1720
|
+
*
|
|
1721
|
+
* 超了从**最旧**的内容开始丢(保序:只丢头,不动类型顺序,也不丢新内容)。
|
|
1722
|
+
* 块数另有 STREAM_BUFFER_MAX_BLOCKS 上限(类型频繁切换时的兜底)。
|
|
1723
|
+
* @param {{blocks:{kind:string,text:string}[]}} b
|
|
1724
|
+
*/
|
|
1725
|
+
#trimStreamBuffer(b) {
|
|
1726
|
+
let total = 0;
|
|
1727
|
+
for (const blk of b.blocks) total += blk.text.length;
|
|
1728
|
+
let excess = total - STREAM_BUFFER_MAX_CHARS;
|
|
1729
|
+
while (excess > 0 && b.blocks.length > 0) {
|
|
1730
|
+
const first = b.blocks[0];
|
|
1731
|
+
if (first.text.length <= excess) {
|
|
1732
|
+
excess -= first.text.length;
|
|
1733
|
+
b.blocks.shift();
|
|
1734
|
+
} else {
|
|
1735
|
+
first.text = first.text.slice(excess);
|
|
1736
|
+
excess = 0;
|
|
1737
|
+
}
|
|
1621
1738
|
}
|
|
1739
|
+
while (b.blocks.length > STREAM_BUFFER_MAX_BLOCKS) b.blocks.shift();
|
|
1622
1740
|
}
|
|
1623
1741
|
|
|
1624
|
-
|
|
1625
|
-
|
|
1742
|
+
/**
|
|
1743
|
+
* 冲刷一个会话的全部待发块:**严格按原始 chunk 顺序**逐块发
|
|
1744
|
+
* (assistant.delta / assistant.reasoningDelta),跨类型也保序。
|
|
1745
|
+
* @param {string} sessionId
|
|
1746
|
+
*/
|
|
1747
|
+
#flushStream(sessionId) {
|
|
1748
|
+
const b = this.#streamBuf.get(sessionId);
|
|
1626
1749
|
if (b === undefined) return;
|
|
1627
1750
|
if (b.timer !== null) {
|
|
1628
1751
|
clearTimeout(b.timer);
|
|
1629
1752
|
b.timer = null;
|
|
1630
1753
|
}
|
|
1631
|
-
const
|
|
1632
|
-
b.
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
}
|
|
1644
|
-
b.text += text;
|
|
1645
|
-
if (b.text.length > 65_536) b.text = b.text.slice(-65_536); // 内存上限
|
|
1646
|
-
if (b.timer === null) {
|
|
1647
|
-
b.timer = setTimeout(() => this.#flushReasoning(sessionId), Math.ceil(1000 / ASSISTANT_THROTTLE_PER_SEC));
|
|
1754
|
+
const blocks = b.blocks;
|
|
1755
|
+
b.blocks = [];
|
|
1756
|
+
// 空了就别占着 map(会话很多时避免无界增长)
|
|
1757
|
+
if (this.#streamBuf.get(sessionId) === b) this.#streamBuf.delete(sessionId);
|
|
1758
|
+
if (this.#disposed) return; // dispose() 后不再产生任何出站
|
|
1759
|
+
for (const blk of blocks) {
|
|
1760
|
+
if (blk.text === "") continue;
|
|
1761
|
+
if (blk.kind === "reasoning") {
|
|
1762
|
+
this.#sendEvent("assistant.reasoningDelta", { sessionId, text: blk.text });
|
|
1763
|
+
} else {
|
|
1764
|
+
this.#sendEvent("assistant.delta", { sessionId, text: blk.text });
|
|
1765
|
+
}
|
|
1648
1766
|
}
|
|
1649
1767
|
}
|
|
1650
1768
|
|
|
1651
|
-
|
|
1652
|
-
|
|
1769
|
+
/** 丢弃某会话的待发块(会话没了)——清定时器 + 清队列。 */
|
|
1770
|
+
#dropStream(sessionId) {
|
|
1771
|
+
const b = this.#streamBuf.get(sessionId);
|
|
1653
1772
|
if (b === undefined) return;
|
|
1654
1773
|
if (b.timer !== null) {
|
|
1655
1774
|
clearTimeout(b.timer);
|
|
1656
1775
|
b.timer = null;
|
|
1657
1776
|
}
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
if (text !== "") this.#sendEvent("assistant.reasoningDelta", { sessionId, text });
|
|
1777
|
+
b.blocks = [];
|
|
1778
|
+
this.#streamBuf.delete(sessionId);
|
|
1661
1779
|
}
|
|
1662
1780
|
|
|
1663
1781
|
// ---- 业务请求分发(§5.1)---------------------------------------------------
|
|
@@ -2073,19 +2191,43 @@ export class HostBridge {
|
|
|
2073
2191
|
try {
|
|
2074
2192
|
const sc = this.#sc();
|
|
2075
2193
|
const req = {};
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
} else {
|
|
2087
|
-
req.cwd = p.cwd;
|
|
2194
|
+
// v1.1.4:cwd 缺省 / undefined / 空串 / trim 后空串时,**不再**交给宿主
|
|
2195
|
+
// 回退到 DSH 后端的 process.cwd()——解析为 Host 用户主目录下的
|
|
2196
|
+
// `~/.dsh/remote`,并**先确保目录存在**(失败直接回错,不静默回退)。
|
|
2197
|
+
// 显式非空 cwd 保持原行为(不自动建目录)。
|
|
2198
|
+
const { cwd, isDefault } = resolveSessionCwd(p.cwd, this.#homeDir);
|
|
2199
|
+
if (isDefault) {
|
|
2200
|
+
if (p.cwd !== undefined && p.cwd !== null && typeof p.cwd !== "string") {
|
|
2201
|
+
this.#log("warn", "session.create got a non-string cwd; using the default directory", {
|
|
2202
|
+
type: typeof p.cwd,
|
|
2203
|
+
});
|
|
2088
2204
|
}
|
|
2205
|
+
try {
|
|
2206
|
+
await this.#mkdir(cwd);
|
|
2207
|
+
} catch (e) {
|
|
2208
|
+
this.#log("error", "failed to create the default session directory", {
|
|
2209
|
+
error: errText(e),
|
|
2210
|
+
});
|
|
2211
|
+
this.#reply(
|
|
2212
|
+
m,
|
|
2213
|
+
errorOf(m, "session-create-failed", "cannot create session directory: " + errText(e)),
|
|
2214
|
+
);
|
|
2215
|
+
return;
|
|
2216
|
+
}
|
|
2217
|
+
}
|
|
2218
|
+
// v1.1.4:cwd 若命中某个**已注册工作区**的目录,改传 `workspaceId`
|
|
2219
|
+
// 让会话自动归到该工作区下面(与 PC 端「在工作区里新建」一致——
|
|
2220
|
+
// PC 走 createInWorkspace → createNamed({workspaceId}))。
|
|
2221
|
+
// 旧实现只传 cwd,宿主不会 attach 到任何工作区 → PC 上显示「未分组」。
|
|
2222
|
+
// 未命中(普通目录)保持传 cwd,与 PC 在任意目录新建一样 = 未分组。
|
|
2223
|
+
// resolveByPath 不创建工作区、不改写注册表;路径不存在会 reject → 兜底回 cwd。
|
|
2224
|
+
// 默认目录(~/.dsh/remote)同样走这条反查:已注册 → 传 workspaceId,
|
|
2225
|
+
// 未注册 → 传该 cwd(**不自动注册工作区**)。
|
|
2226
|
+
const ws = await this.#resolveWorkspaceByCwd(cwd);
|
|
2227
|
+
if (ws !== null) {
|
|
2228
|
+
req.workspaceId = ws;
|
|
2229
|
+
} else {
|
|
2230
|
+
req.cwd = cwd;
|
|
2089
2231
|
}
|
|
2090
2232
|
if (agentPreset !== "") req.agentPreset = agentPreset;
|
|
2091
2233
|
let value;
|
package/market/index.json
CHANGED
|
@@ -69,9 +69,19 @@
|
|
|
69
69
|
"sortKeys": {}
|
|
70
70
|
},
|
|
71
71
|
"versions": [
|
|
72
|
+
{
|
|
73
|
+
"version": "1.1.6",
|
|
74
|
+
"publishTimestamp": 1793202911,
|
|
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
|
+
},
|
|
72
82
|
{
|
|
73
83
|
"version": "1.1.5",
|
|
74
|
-
"publishTimestamp":
|
|
84
|
+
"publishTimestamp": 1793149134,
|
|
75
85
|
"source": {
|
|
76
86
|
"type": "npm"
|
|
77
87
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@duke-dsh-plugins/dsh-remote-control",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.6",
|
|
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",
|