@duke-dsh-plugins/dsh-remote-control 1.1.4 → 1.1.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.
- package/lib/host-bridge.mjs +86 -42
- package/market/index.json +11 -1
- package/package.json +1 -1
package/lib/host-bridge.mjs
CHANGED
|
@@ -492,33 +492,6 @@ export function mapToolResultEvent(sessionId, event) {
|
|
|
492
492
|
};
|
|
493
493
|
}
|
|
494
494
|
|
|
495
|
-
/**
|
|
496
|
-
* 契约 §5.2 `system.message` 事件映射(宿主 session/event 的
|
|
497
|
-
* system/message 与 developer/message;两者共用一个 topic,用 kind 区分)。
|
|
498
|
-
* message 可能是 {content:[blocks]},也可能是字符串——两种都兜住。
|
|
499
|
-
* @returns {{sessionId:string,kind:"system"|"developer",text:string,ts:number}|null}
|
|
500
|
-
*/
|
|
501
|
-
export function mapSystemMessageEvent(sessionId, event, kind) {
|
|
502
|
-
if (!event || typeof event !== "object") return null;
|
|
503
|
-
if (event.type !== "system/message" && event.type !== "developer/message") return null;
|
|
504
|
-
const data = event.data;
|
|
505
|
-
if (!data || typeof data !== "object") return null;
|
|
506
|
-
const message = data.message !== undefined ? data.message : data;
|
|
507
|
-
let text = "";
|
|
508
|
-
if (typeof message === "string") {
|
|
509
|
-
text = message;
|
|
510
|
-
} else if (message && typeof message === "object") {
|
|
511
|
-
text = contentText(message.content);
|
|
512
|
-
}
|
|
513
|
-
if (text.trim() === "") return null;
|
|
514
|
-
return {
|
|
515
|
-
sessionId: String(sessionId ?? ""),
|
|
516
|
-
kind: kind === "developer" ? "developer" : "system",
|
|
517
|
-
text,
|
|
518
|
-
ts: eventTime(event),
|
|
519
|
-
};
|
|
520
|
-
}
|
|
521
|
-
|
|
522
495
|
/**
|
|
523
496
|
* 契约 §5.7 StepRecord 提取:session.history 的 page.records → steps[]。
|
|
524
497
|
*
|
|
@@ -967,10 +940,14 @@ export class HostBridge {
|
|
|
967
940
|
}
|
|
968
941
|
});
|
|
969
942
|
|
|
970
|
-
// --- v1.0.6(§5.7
|
|
943
|
+
// --- v1.0.6(§5.7)→ v1.1.4:会话事件总闸 → tool.call / tool.result ---
|
|
971
944
|
// 宿主每写入一条会话日志事件就触发(覆盖所有会话,含 subagent)。
|
|
972
945
|
// 按 session.id 寻址即可,**不过滤**子代理;不认识的事件类型直接忽略,
|
|
973
946
|
// 绝不因为形状不认识而抛错(#on 包装器已兜底)。
|
|
947
|
+
// v1.1.4:**不再桥接 system/message / developer/message**——宿主里它们是
|
|
948
|
+
// 系统提示词节点与工具注册表变更(提示词组装记录,不是对话内容),
|
|
949
|
+
// DSH 桌面端的聊天视图从不展示;手机端曾把它们当「系统消息」显示,
|
|
950
|
+
// 造成时间线里出现大段多余的系统提示文本(用户反馈)。
|
|
974
951
|
this.#on("session/event", (session, event) => {
|
|
975
952
|
const sessionId = String(session?.id ?? "");
|
|
976
953
|
if (sessionId === "") return;
|
|
@@ -985,12 +962,6 @@ export class HostBridge {
|
|
|
985
962
|
if (mapped !== null) this.#sendEvent("tool.result", mapped);
|
|
986
963
|
return;
|
|
987
964
|
}
|
|
988
|
-
if (type === "system/message" || type === "developer/message") {
|
|
989
|
-
const kind = type === "developer/message" ? "developer" : "system";
|
|
990
|
-
const mapped = mapSystemMessageEvent(sessionId, event, kind);
|
|
991
|
-
if (mapped !== null) this.#sendEvent("system.message", mapped);
|
|
992
|
-
return;
|
|
993
|
-
}
|
|
994
965
|
if (type === "model/selection") {
|
|
995
966
|
// v1.0.8:会话模型/思考强度变化(桌面端或手机端 selectModel 都会追加)
|
|
996
967
|
const selection = mapModelSelection(event.data);
|
|
@@ -1189,6 +1160,36 @@ export class HostBridge {
|
|
|
1189
1160
|
return this.#service("workspaceRegistry");
|
|
1190
1161
|
}
|
|
1191
1162
|
|
|
1163
|
+
/**
|
|
1164
|
+
* v1.1.4:按 cwd 反查它是否属于某个**已注册工作区**的目录。
|
|
1165
|
+
* 命中返回该工作区的 id(供 `session.create` 传 `workspaceId` 归组),
|
|
1166
|
+
* 否则返回 null(调用方退回传 cwd,与 PC 在普通目录新建一样 = 未分组)。
|
|
1167
|
+
*
|
|
1168
|
+
* 用宿主 `workspaceRegistry.resolveByPath`:按 canonical path 匹配,
|
|
1169
|
+
* **不创建**工作区、不改写注册表;目录不存在会 reject。
|
|
1170
|
+
* 任何异常(服务缺失 / 方法不存在 / 路径解析失败)都兜底回 null——
|
|
1171
|
+
* 归组是增强,绝不能因此让 session.create 失败。
|
|
1172
|
+
* @param {string} cwd
|
|
1173
|
+
* @returns {Promise<string|null>}
|
|
1174
|
+
*/
|
|
1175
|
+
async #resolveWorkspaceByCwd(cwd) {
|
|
1176
|
+
try {
|
|
1177
|
+
const reg = this.#workspaceRegistry();
|
|
1178
|
+
if (!reg || typeof reg.resolveByPath !== "function") return null;
|
|
1179
|
+
const ws = await reg.resolveByPath(cwd);
|
|
1180
|
+
const id = typeof ws?.id === "string" && ws.id !== "" ? ws.id : null;
|
|
1181
|
+
if (id !== null) {
|
|
1182
|
+
this.#log("info", "session.create cwd matches a workspace; attaching to it", {
|
|
1183
|
+
workspaceId: id,
|
|
1184
|
+
});
|
|
1185
|
+
}
|
|
1186
|
+
return id;
|
|
1187
|
+
} catch (e) {
|
|
1188
|
+
this.#log("warn", "resolveByPath failed; session stays ungrouped", { error: errText(e) });
|
|
1189
|
+
return null;
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1192
1193
|
/** 事件监听包装:emit 监听必须永不抛出。 */
|
|
1193
1194
|
#on(name, handler) {
|
|
1194
1195
|
const wrapped = (...args) => {
|
|
@@ -1689,7 +1690,7 @@ export class HostBridge {
|
|
|
1689
1690
|
case "session.selectModel":
|
|
1690
1691
|
return await this.#rSessionSelectModel(m);
|
|
1691
1692
|
case "session.model":
|
|
1692
|
-
return this.#rSessionModel(m);
|
|
1693
|
+
return await this.#rSessionModel(m);
|
|
1693
1694
|
case "session.queue":
|
|
1694
1695
|
return this.#rSessionQueue(m);
|
|
1695
1696
|
case "session.archive":
|
|
@@ -2072,7 +2073,20 @@ export class HostBridge {
|
|
|
2072
2073
|
try {
|
|
2073
2074
|
const sc = this.#sc();
|
|
2074
2075
|
const req = {};
|
|
2075
|
-
if (typeof p.cwd === "string" && p.cwd !== "")
|
|
2076
|
+
if (typeof p.cwd === "string" && p.cwd !== "") {
|
|
2077
|
+
// v1.1.4:cwd 若命中某个**已注册工作区**的目录,改传 `workspaceId`
|
|
2078
|
+
// 让会话自动归到该工作区下面(与 PC 端「在工作区里新建」一致——
|
|
2079
|
+
// PC 走 createInWorkspace → createNamed({workspaceId}))。
|
|
2080
|
+
// 旧实现只传 cwd,宿主不会 attach 到任何工作区 → PC 上显示「未分组」。
|
|
2081
|
+
// 未命中(普通目录)保持传 cwd,与 PC 在任意目录新建一样 = 未分组。
|
|
2082
|
+
// resolveByPath 不创建工作区、不改写注册表;路径不存在会 reject → 兜底回 cwd。
|
|
2083
|
+
const ws = await this.#resolveWorkspaceByCwd(p.cwd);
|
|
2084
|
+
if (ws !== null) {
|
|
2085
|
+
req.workspaceId = ws;
|
|
2086
|
+
} else {
|
|
2087
|
+
req.cwd = p.cwd;
|
|
2088
|
+
}
|
|
2089
|
+
}
|
|
2076
2090
|
if (agentPreset !== "") req.agentPreset = agentPreset;
|
|
2077
2091
|
let value;
|
|
2078
2092
|
try {
|
|
@@ -2267,18 +2281,48 @@ export class HostBridge {
|
|
|
2267
2281
|
}
|
|
2268
2282
|
}
|
|
2269
2283
|
|
|
2270
|
-
/** 契约 §5.1/§5.8
|
|
2271
|
-
*
|
|
2272
|
-
*
|
|
2273
|
-
|
|
2284
|
+
/** 契约 §5.1/§5.8 session.model:查询会话当前模型/思考强度(v1.0.8 引入,
|
|
2285
|
+
* v1.1.4 数据源升级)。
|
|
2286
|
+
*
|
|
2287
|
+
* 权威数据源 = 宿主 **modelSelection 持久投影**(`sessionController.projections`
|
|
2288
|
+
* 的 `values.modelSelection`,视图形状 `{lastUsed, next}`,`next = pending ?? lastUsed`)。
|
|
2289
|
+
* 这与 DSH 桌面端 composer 显示的是**同一份**(dsh-client-ui-model-selection 的
|
|
2290
|
+
* syncInputs:`selection = projected.next ?? catalog.default`):
|
|
2291
|
+
* - `pending`:用户在会话里显式切换过、还没被请求消费的模型;
|
|
2292
|
+
* - `lastUsed`:上一个 `request/header` 实际使用的模型(旧实现完全漏掉它——
|
|
2293
|
+
* 从没显式切换过的会话在旧实现里永远回 null,手机端就总显示目录默认,
|
|
2294
|
+
* 与 PC 对不上,用户实测反馈);
|
|
2295
|
+
* - 两者都空(从未跑过也没选过的空白会话)→ null,客户端回退目录默认
|
|
2296
|
+
* (= PC 的 catalog.default 回退,天然一致)。
|
|
2297
|
+
*
|
|
2298
|
+
* 投影不可用(旧宿主没注册)/读取失败 → 退回 `model/selection` 直播事件维护的
|
|
2299
|
+
* 内存态(v1.0.8 行为);再没有 → null。**不得臆造**。 */
|
|
2300
|
+
async #rSessionModel(m) {
|
|
2274
2301
|
const p = m.payload ?? {};
|
|
2275
2302
|
const sessionId = typeof p.sessionId === "string" ? p.sessionId : "";
|
|
2276
2303
|
if (sessionId === "") {
|
|
2277
2304
|
this.#reply(m, errorOf(m, "bad-params", "sessionId required"));
|
|
2278
2305
|
return;
|
|
2279
2306
|
}
|
|
2280
|
-
|
|
2281
|
-
|
|
2307
|
+
try {
|
|
2308
|
+
const sc = this.#sc();
|
|
2309
|
+
if (typeof sc.projections === "function") {
|
|
2310
|
+
const projections = await sc.projections({ sessionId }, this.#signal(10_000));
|
|
2311
|
+
const view = projections?.values?.modelSelection;
|
|
2312
|
+
if (view !== undefined && view !== null) {
|
|
2313
|
+
const model = mapModelSelection(view.next ?? view.lastUsed ?? null);
|
|
2314
|
+
this.#reply(m, resultOf(m, { model }));
|
|
2315
|
+
return;
|
|
2316
|
+
}
|
|
2317
|
+
}
|
|
2318
|
+
} catch (e) {
|
|
2319
|
+
// 投影缺失/读取失败 → 退回直播事件内存态(不报错,静默降级)
|
|
2320
|
+
this.#log("warn", "modelSelection projection unavailable; falling back to live tracking", {
|
|
2321
|
+
sessionId,
|
|
2322
|
+
error: errText(e),
|
|
2323
|
+
});
|
|
2324
|
+
}
|
|
2325
|
+
this.#reply(m, resultOf(m, { model: this.#modelSelections.get(sessionId) ?? null }));
|
|
2282
2326
|
}
|
|
2283
2327
|
|
|
2284
2328
|
/** 模式目录(宿主 Agent preset 目录)。服务缺失/抛错 → 空目录。 */
|
package/market/index.json
CHANGED
|
@@ -69,9 +69,19 @@
|
|
|
69
69
|
"sortKeys": {}
|
|
70
70
|
},
|
|
71
71
|
"versions": [
|
|
72
|
+
{
|
|
73
|
+
"version": "1.1.5",
|
|
74
|
+
"publishTimestamp": 1793149102,
|
|
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.4",
|
|
74
|
-
"publishTimestamp":
|
|
84
|
+
"publishTimestamp": 1793036707,
|
|
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.5",
|
|
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",
|