dsh-mobile-plugin 0.5.88 → 0.5.90
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/config/agent-presets/standard/agent.cordis.yml +5 -0
- package/config/agent-presets/standard/skills/dsh-mobile-kb/SKILL.md +43 -0
- package/config/agent-presets/standard/skills/dsh-mobile-kb/references/network.md +27 -0
- package/config/agent-presets/standard/skills/dsh-mobile-kb/references/offline.md +30 -0
- package/config/agent-presets/standard/skills/dsh-mobile-kb/references/pairing.md +27 -0
- package/config/agent-presets/standard/skills/dsh-mobile-kb/references/relay.md +23 -0
- package/docs/extension-authoring.md +24 -8
- package/extension-registry/index.json +15 -1
- package/lib/client.js +131 -28
- package/lib/impl.js +9 -13
- package/lib/mobile/ai-recipient.cjs +61 -0
- package/lib/mobile/approval-facts.js +26 -3
- package/lib/mobile/approvals.js +42 -11
- package/lib/mobile/extension-catalog.js +29 -3
- package/lib/mobile/extension-dev.js +7 -0
- package/lib/mobile/extension-metadata.cjs +40 -0
- package/lib/mobile/feedback-read.cjs +59 -0
- package/lib/mobile/feedback.js +24 -16
- package/lib/mobile/mux.js +30 -3
- package/lib/mobile/permissions.js +30 -0
- package/lib/mobile/plugin-catalog.js +5 -0
- package/lib/mobile/questions.js +21 -2
- package/lib/mobile/relay-control.js +4 -3
- package/lib/mobile/session-models.js +2 -1
- package/lib/mobile/session-send.js +16 -2
- package/lib/mobile/stream-registry.js +29 -4
- package/lib/mobile/subagents.js +6 -1
- package/lib/mobile/third-party-extensions.js +6 -1
- package/lib/panel/index.html +17 -15
- package/lib/relay/identity-rotate.cjs +4 -1
- package/lib/relay/preview.js +10 -1
- package/lib/relay/protocol.js +2 -2
- package/lib/relay/tunnel.js +7 -2
- package/lib/remote/controller.cjs +4 -1
- package/lib/remote/tunnel-helper.cjs +2 -2
- package/lib/routes/control-plane.js +21 -11
- package/lib/routes/feedback.cjs +20 -0
- package/lib/shared/route-order.cjs +6 -0
- package/lib/sidecar-facade-worker.cjs +8 -2
- package/lib/sidecar-lifecycle.cjs +94 -14
- package/package.json +2 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// 升级权限优先使用本次已认证记录,身份轮换后不回查过期实例快照。
|
|
1
2
|
'use strict';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -113,6 +114,33 @@ function hasPermission(record, permission) {
|
|
|
113
114
|
return granted.includes(permission);
|
|
114
115
|
}
|
|
115
116
|
|
|
117
|
+
/**
|
|
118
|
+
* 这台实例里还有没有「能答审批」的设备(approve 位)。
|
|
119
|
+
*
|
|
120
|
+
* 只读档设备收到的审批 / 提问卡点了必然 403(respond 两条路由归 approve)。审批桥与提问桥
|
|
121
|
+
* 据此决定要不要建卡、推卡:一台能答的设备都没有时不推。`store` 是设备凭据库
|
|
122
|
+
* (`credentialsEntry()`),由调用方传进来 —— 本文件不反向依赖凭据包。
|
|
123
|
+
*
|
|
124
|
+
* 口径与 `hasPermission` 一致:记录里缺 `permissions` = 全权(算能答);活动设备一台都没有时
|
|
125
|
+
* 也返回 true —— 老凭据 / 测试环境按全权处理,不能因为读不到清单就把提醒静默掐掉。
|
|
126
|
+
*/
|
|
127
|
+
function anyApprover(store) {
|
|
128
|
+
try {
|
|
129
|
+
if (!store || typeof store.listActive !== 'function' || typeof store.listDevices !== 'function') return true;
|
|
130
|
+
const instanceIds = new Set();
|
|
131
|
+
for (const row of store.listActive()) if (row && row.instanceId) instanceIds.add(row.instanceId);
|
|
132
|
+
if (instanceIds.size === 0) return true;
|
|
133
|
+
for (const instanceId of instanceIds) {
|
|
134
|
+
for (const device of store.listDevices(instanceId)) {
|
|
135
|
+
if (!device || !Array.isArray(device.permissions) || device.permissions.includes(PERMISSIONS.APPROVE)) return true;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return false;
|
|
139
|
+
} catch {
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
116
144
|
/**
|
|
117
145
|
* 移动路由 → 所需权限位。`null` 表示 BASE(鉴权通过即放行,不查权限位)。
|
|
118
146
|
* 值是字符串,或 `{ GET, POST, DELETE, ... }` 形状(同路径按方法分读写)。
|
|
@@ -456,6 +484,7 @@ function createUpgradePermission({ credentials, instanceId, presentedCredential
|
|
|
456
484
|
resolve: resolvePermission,
|
|
457
485
|
has: hasPermission,
|
|
458
486
|
recordOf: (req) => {
|
|
487
|
+
if (req && req.__dshRecord && typeof req.__dshRecord === 'object') return req.__dshRecord;
|
|
459
488
|
if (!credentials || typeof credentials.lookup !== 'function') return null;
|
|
460
489
|
let presented = null;
|
|
461
490
|
try { presented = presentedCredential ? presentedCredential(req) : null; } catch { presented = null; }
|
|
@@ -482,6 +511,7 @@ module.exports = {
|
|
|
482
511
|
missingDependencies,
|
|
483
512
|
normalizePermissionsInput,
|
|
484
513
|
hasPermission,
|
|
514
|
+
anyApprover,
|
|
485
515
|
resolvePermission,
|
|
486
516
|
createUpgradePermission,
|
|
487
517
|
isClassified,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// 插件市场透传目录用途、年龄声明与公开详情,缺失数据不作评级结论。
|
|
1
2
|
'use strict';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -36,6 +37,7 @@
|
|
|
36
37
|
const { sendJson } = require('../shared/http-util');
|
|
37
38
|
const fs = require('node:fs');
|
|
38
39
|
const path = require('node:path');
|
|
40
|
+
const { ageRatingOf } = require('./extension-metadata.cjs');
|
|
39
41
|
|
|
40
42
|
/**
|
|
41
43
|
* 数据源,按顺序试,前一个失败才试下一个。两份清单是社区同一批数据的两条腿:
|
|
@@ -249,6 +251,9 @@ function normalizeItem(raw, sourceId) {
|
|
|
249
251
|
category: firstString(rawCategory) || FALLBACK_CATEGORY,
|
|
250
252
|
title: localizedOf(raw.title),
|
|
251
253
|
description: localizedOf(raw.description),
|
|
254
|
+
purpose: textOrNull(raw.purpose, TEXT_MAX_CHARS),
|
|
255
|
+
ageRating: ageRatingOf(raw.ageRating),
|
|
256
|
+
publicUrl: httpsOrNull(raw.publicUrl),
|
|
252
257
|
npm: npmValid,
|
|
253
258
|
version,
|
|
254
259
|
stars: stars === null ? 0 : stars,
|
package/lib/mobile/questions.js
CHANGED
|
@@ -17,6 +17,20 @@
|
|
|
17
17
|
const { randomUUID } = require('node:crypto');
|
|
18
18
|
const { sendJson, readJsonBody } = require('../shared/http-util');
|
|
19
19
|
const { cancelForwardedRequests } = require('./host-bridge/transport.js');
|
|
20
|
+
const { anyApprover } = require('./permissions.js');
|
|
21
|
+
const { credentialsEntry } = require('../shared/credentials-entry.js');
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 这台电脑上还有没有能答提问的设备(approve 位)。只读档设备收到的提问卡点了必然 403,所以
|
|
25
|
+
* 一台能答的都没有时桥不建卡也不推送。读凭据出错时按「有」处理,见 permissions.anyApprover。
|
|
26
|
+
*/
|
|
27
|
+
function canShowCards() {
|
|
28
|
+
try {
|
|
29
|
+
return anyApprover(credentialsEntry());
|
|
30
|
+
} catch {
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
20
34
|
|
|
21
35
|
/** sessionId → Set<sink>:正在看这个会话的手机连接(每条 SSE 一个 sink)。 */
|
|
22
36
|
const watchers = new Map();
|
|
@@ -106,6 +120,8 @@ function broadcast(sessionId, frame) {
|
|
|
106
120
|
|
|
107
121
|
function pushCard(entry) {
|
|
108
122
|
if (entry.settled) return;
|
|
123
|
+
// 没有能答提问的设备时不建卡也不推送(点下去必然 403),见 `canShowCards`。
|
|
124
|
+
if (!canShowCards()) return;
|
|
109
125
|
if (watcherCount(entry.sessionId) > 0) broadcast(entry.sessionId, cardFrame(entry));
|
|
110
126
|
// 没人看也要推:手机在后台 / 被杀时这张卡到不了,只能靠系统通知把人叫回来。
|
|
111
127
|
// 只推「已绑上钩子 = 答得动」的卡,避免用户点进来是一条必然 409 的死卡。
|
|
@@ -162,8 +178,10 @@ function attachSession(sessionId, sink) {
|
|
|
162
178
|
let set = watchers.get(sessionId);
|
|
163
179
|
if (!set) { set = new Set(); watchers.set(sessionId, set); }
|
|
164
180
|
set.add(sink);
|
|
165
|
-
|
|
166
|
-
|
|
181
|
+
if (canShowCards()) {
|
|
182
|
+
for (const entry of openEntries(sessionId)) {
|
|
183
|
+
if (entry.bound) { try { sink(cardFrame(entry)); } catch { /* ignore */ } }
|
|
184
|
+
}
|
|
167
185
|
}
|
|
168
186
|
return () => {
|
|
169
187
|
set.delete(sink);
|
|
@@ -179,6 +197,7 @@ function attachSession(sessionId, sink) {
|
|
|
179
197
|
* 让后台轮询顺手把卡的内容带回去,这条缺口才补得上。
|
|
180
198
|
*/
|
|
181
199
|
function pendingCardOf(sessionId) {
|
|
200
|
+
if (!canShowCards()) return undefined;
|
|
182
201
|
for (const entry of openEntries(sessionId)) {
|
|
183
202
|
if (entry.bound) return cardFrame(entry);
|
|
184
203
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//
|
|
1
|
+
// 手机主动重连在回执发出后调用独立隧道动作,普通配置同步保持幂等。
|
|
2
2
|
// 既有中转配置复用有界健康判据与出网诊断,保留本实例吊销回执收尾。
|
|
3
3
|
// 2026-11-21:「立即同步」只上报不等查询 —— 查询归手机,宿主没有比自己更新的上游可查。
|
|
4
4
|
'use strict';
|
|
@@ -200,6 +200,7 @@ function createRelayControlHandlers(deps) {
|
|
|
200
200
|
state,
|
|
201
201
|
settings,
|
|
202
202
|
syncSidecar,
|
|
203
|
+
reconnectTunnel = null,
|
|
203
204
|
status,
|
|
204
205
|
resolveLanPort,
|
|
205
206
|
lanPortInUse,
|
|
@@ -604,9 +605,9 @@ function createRelayControlHandlers(deps) {
|
|
|
604
605
|
|
|
605
606
|
/** `POST /api/mobile/v1/relay/reconnect` —— 让旁路重读配置并重建隧道。 */
|
|
606
607
|
async function handleRelayReconnect(_ctx, _req, res) {
|
|
607
|
-
if (!wired) return unavailable(res);
|
|
608
|
+
if (!wired || typeof reconnectTunnel !== 'function') return unavailable(res);
|
|
608
609
|
sendJson(res, 200, { ok: true, started: true });
|
|
609
|
-
afterResponse(() =>
|
|
610
|
+
afterResponse(() => Promise.resolve().then(reconnectTunnel).catch(() => undefined));
|
|
610
611
|
}
|
|
611
612
|
|
|
612
613
|
/**
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// 模型响应声明显式接收方校验能力,客户端不能依赖旧插件忽略新增字段。
|
|
1
2
|
'use strict';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -108,7 +109,7 @@ function safeModelsValue(value, language = 'en') {
|
|
|
108
109
|
}
|
|
109
110
|
|
|
110
111
|
function modelsBody(value, fetchedAt, language = 'en') {
|
|
111
|
-
const result = { ok: true, ...safeModelsValue(value, language) };
|
|
112
|
+
const result = { ok: true, ...safeModelsValue(value, language), capabilities: { expectedAiRecipient: true } };
|
|
112
113
|
const revision = result.revision;
|
|
113
114
|
result.meta = {
|
|
114
115
|
...(result.meta && typeof result.meta === 'object' ? result.meta : {}),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** 发送前核对显式同意的模型接收方;旧宿主无切换能力时仍验证真实当前路由。 */
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -12,6 +12,9 @@
|
|
|
12
12
|
*
|
|
13
13
|
* 文本块恰好一个且以 / 开头时派发为 slash 命令(commands.execute,不发给模型);
|
|
14
14
|
* 未知命令或网关未组合时回退普通消息,与桌面 miss 落入默认 sink 的行为一致。
|
|
15
|
+
*
|
|
16
|
+
* slash 命令也按 clientMessageId 去重:传输内核换通道重投同一次发送时,命令不能跑第二遍
|
|
17
|
+
* (压缩两次 / 导出两份 / 清两遍)。口径与普通消息的 promptOnceFor 一致,见命令分支。
|
|
15
18
|
*/
|
|
16
19
|
|
|
17
20
|
const { Readable } = require('node:stream');
|
|
@@ -28,6 +31,7 @@ const { promptErrorObject, MODEL_UNAVAILABLE_ERROR } = require('./history-derive
|
|
|
28
31
|
const { withIdempotency, requestIdOf } = require('./idempotency.js');
|
|
29
32
|
const { invoke, UNAVAILABLE: GATEWAY_UNAVAILABLE } = require('./host-bridge/transport.js');
|
|
30
33
|
const { selectSessionModel } = require('./host-bridge/session-model.js');
|
|
34
|
+
const { expectedAiRecipientError } = require('./ai-recipient.cjs');
|
|
31
35
|
const { recordSessionRead } = require('./session-last-turn.js');
|
|
32
36
|
const { imageSizeOf } = require('./local-images.js');
|
|
33
37
|
const attachmentStore = require('./attachment-store.js');
|
|
@@ -161,7 +165,14 @@ async function handleSend(ctx, req, res) {
|
|
|
161
165
|
// 与网关未组合时回退普通消息(对齐桌面 miss 落入默认 sink,`/foo` 仍按文本发送)。
|
|
162
166
|
const singleText = singleTextOf(content);
|
|
163
167
|
if (singleText !== null && singleText.trim().startsWith('/')) {
|
|
164
|
-
const
|
|
168
|
+
const line = singleText.trim();
|
|
169
|
+
const clientMessageId = typeof body.clientMessageId === 'string' ? body.clientMessageId : '';
|
|
170
|
+
// 命令同样按 clientMessageId 去重:传输内核换通道重投同一次发送时,命令绝不能执行第二遍。
|
|
171
|
+
// 口径与普通消息的 promptOnceFor 一致 —— 只有真正派发成功才留下去重记录;未知命令 / 网关
|
|
172
|
+
// 未组合 / 派发失败都释放,允许重投真的再试一次。
|
|
173
|
+
const runCommand = () => executeCommand(ctx, body.sessionId, line).then((outcome) => ({ outcome, result: { ok: outcome.execution !== undefined } }));
|
|
174
|
+
const dispatched = clientMessageId ? await promptOnceFor(ctx, `${body.sessionId}:command:${clientMessageId}`, runCommand) : await runCommand();
|
|
175
|
+
const outcome = dispatched.outcome;
|
|
165
176
|
if (outcome.error) {
|
|
166
177
|
const failure = outcome.error.failure
|
|
167
178
|
|| { code: 'command-error', message: outcome.error.message || String(outcome.error), details: {} };
|
|
@@ -188,6 +199,9 @@ async function handleSend(ctx, req, res) {
|
|
|
188
199
|
}
|
|
189
200
|
}
|
|
190
201
|
|
|
202
|
+
const recipientError = await expectedAiRecipientError(ctx, { sessionId: body.sessionId, expected: body.expectedAiRecipient, selection: modelSelection });
|
|
203
|
+
if (recipientError) return sendJson(res, 400, { ok: false, error: recipientError });
|
|
204
|
+
|
|
191
205
|
let promptResponse;
|
|
192
206
|
try {
|
|
193
207
|
promptResponse = await promptOnce(ctx, typeof body.clientMessageId === 'string' ? body.clientMessageId : '', {
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
//
|
|
1
|
+
// SSE 登记随本机换号迁移,清理回调与吊销始终使用当前实例归属。
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
const streams = new Map();
|
|
5
|
+
// 每条响应挂本轮归属的 scope;用 Symbol 直接挂到响应对象上,随之一起回收,不再另立模块级登记表。
|
|
6
|
+
const SCOPE_STATE = Symbol('dsh.streamScope');
|
|
5
7
|
|
|
6
8
|
/** 无实例参数保留旧调用口径;业务入口显式传当前实例。 */
|
|
7
9
|
function track(deviceId, res, instanceId = '') {
|
|
@@ -12,16 +14,39 @@ function track(deviceId, res, instanceId = '') {
|
|
|
12
14
|
let set = devices.get(deviceId);
|
|
13
15
|
if (!set) { set = new Set(); devices.set(deviceId, set); }
|
|
14
16
|
set.add(res);
|
|
17
|
+
const registration = { scope };
|
|
18
|
+
res[SCOPE_STATE] = registration;
|
|
15
19
|
return () => {
|
|
16
|
-
const
|
|
20
|
+
const currentScope = registration.scope;
|
|
21
|
+
const current = streams.get(currentScope);
|
|
17
22
|
const active = current?.get(deviceId);
|
|
18
23
|
if (!active) return;
|
|
19
24
|
active.delete(res);
|
|
20
25
|
if (active.size === 0) current.delete(deviceId);
|
|
21
|
-
if (current.size === 0) streams.delete(
|
|
26
|
+
if (current.size === 0) streams.delete(currentScope);
|
|
22
27
|
};
|
|
23
28
|
}
|
|
24
29
|
|
|
30
|
+
function reassignInstance(fromInstanceId, toInstanceId) {
|
|
31
|
+
const from = String(fromInstanceId || '');
|
|
32
|
+
const to = String(toInstanceId || '');
|
|
33
|
+
if (from === to) return;
|
|
34
|
+
const source = streams.get(from);
|
|
35
|
+
if (!source) return;
|
|
36
|
+
streams.delete(from);
|
|
37
|
+
let target = streams.get(to);
|
|
38
|
+
if (!target) { target = new Map(); streams.set(to, target); }
|
|
39
|
+
for (const [deviceId, responses] of source) {
|
|
40
|
+
let active = target.get(deviceId);
|
|
41
|
+
if (!active) { active = new Set(); target.set(deviceId, active); }
|
|
42
|
+
for (const res of responses) {
|
|
43
|
+
const registration = res[SCOPE_STATE];
|
|
44
|
+
if (registration) registration.scope = to;
|
|
45
|
+
active.add(res);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
25
50
|
function closeSet(set, deferClose) {
|
|
26
51
|
const active = [...set].filter(res => !res.destroyed && !res.writableEnded);
|
|
27
52
|
const close = () => {
|
|
@@ -65,4 +90,4 @@ function size() {
|
|
|
65
90
|
}
|
|
66
91
|
function reset() { streams.clear(); }
|
|
67
92
|
|
|
68
|
-
module.exports = { track, drop, dropAll, size, reset };
|
|
93
|
+
module.exports = { track, reassignInstance, drop, dropAll, size, reset };
|
package/lib/mobile/subagents.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//
|
|
1
|
+
// 子代理续话核对自身当前模型接收方,external 只展示,投递能力由宿主探测决定。
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -18,6 +18,7 @@ const { unwrap } = require('./sessions.js');
|
|
|
18
18
|
const { promptOnceFor } = require('./session-cache.js');
|
|
19
19
|
const { inlineUploadedImageBlocks } = require('./uploads.js');
|
|
20
20
|
const { subagentPromptCapabilities } = require('./host-bridge/endpoints.js');
|
|
21
|
+
const { expectedAiRecipientError } = require('./ai-recipient.cjs');
|
|
21
22
|
|
|
22
23
|
// 子代理条数上限。长程会话实测能派到两百多个(反馈 #19 / #20),早先的 100 会把后面的整段
|
|
23
24
|
// 静默截掉、手机上看不见也点不进。现在按实际数量取,只留一个防异常宿主的兜底量级。
|
|
@@ -254,6 +255,10 @@ async function handleSubagentPrompt(ctx, req, res) {
|
|
|
254
255
|
// 续话与主会话发送走同一条重试链路(乐观行 + 超时后自动 / 手点重发),所以同样按
|
|
255
256
|
// `clientMessageId` 去重:没有它,超时的那一发多半已经在子会话里说过了,重试会说第二遍
|
|
256
257
|
// (口径见 session-cache 的 `promptOnceFor`)。
|
|
258
|
+
const recipientError = await expectedAiRecipientError(ctx, {
|
|
259
|
+
sessionId: childSessionId, expected: body.expectedAiRecipient, selection: body.modelSelection, child: true,
|
|
260
|
+
});
|
|
261
|
+
if (recipientError) return sendJson(res, 400, { ok: false, error: recipientError });
|
|
257
262
|
const response = clientMessageId
|
|
258
263
|
? await promptOnceFor(ctx, `subagent:${parentSessionId}:${childSessionId}:${clientMessageId}`, call)
|
|
259
264
|
: await call();
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// 第三方扩展发现同时保留所属插件与公开来源,不把本机目录当公开索引。
|
|
1
2
|
'use strict';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -20,6 +21,7 @@
|
|
|
20
21
|
|
|
21
22
|
const fs = require('node:fs');
|
|
22
23
|
const path = require('node:path');
|
|
24
|
+
const { packageSourceUrl } = require('./extension-metadata.cjs');
|
|
23
25
|
|
|
24
26
|
/** 插件 `package.json` 里声明「我带了给手机用的扩展」的那一格。 */
|
|
25
27
|
const DECL_FIELD = 'dshMobileExtensions';
|
|
@@ -229,7 +231,10 @@ function discoverPackages(pluginsRoot) {
|
|
|
229
231
|
const slug = slugOf(ownerSlug, child.name);
|
|
230
232
|
if (!SLUG_PATTERN.test(slug) || seen.has(slug)) continue;
|
|
231
233
|
seen.add(slug);
|
|
232
|
-
found.push({
|
|
234
|
+
found.push({
|
|
235
|
+
slug, directory: path.join(declaredRoot, child.name), packageName: name,
|
|
236
|
+
sourceUrl: packageSourceUrl(manifest),
|
|
237
|
+
});
|
|
233
238
|
}
|
|
234
239
|
}
|
|
235
240
|
return found;
|