dsh-mobile-plugin 0.5.59 → 0.5.61
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 +2 -0
- package/docs/chat-embed.md +123 -0
- package/docs/extension-authoring.md +235 -47
- package/docs/extension-sample/README.md +16 -10
- package/extensions/README.md +1 -1
- package/lib/client.js +31 -0
- package/lib/mobile/approval-memory.js +9 -2
- package/lib/mobile/approvals.js +12 -1
- package/lib/mobile/session-send.js +37 -2
- package/lib/panel/index.html +1 -1
- package/lib/relay/lan-proxy.js +55 -1
- package/lib/remote/host.cjs +27 -0
- package/lib/remote/instance-hint.cjs +66 -0
- package/lib/routes/mobile-api.js +4 -0
- package/package.json +2 -1
package/lib/client.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 移动端插件提供电脑插件页面目录;标准页面保留宿主上下文并支持直接导航。
|
|
3
|
+
* 聊天嵌入服务合并顶部栏显示声明,随提供方与消费方生命周期释放。
|
|
3
4
|
* 本机和局域网入口直接访问管理页,公网入口保留两小时窗口。
|
|
4
5
|
*
|
|
5
6
|
* 五件事:桌面侧边栏的展开态与「读过了」报给宿主;手机端的已读回执应用回桌面绿点;
|
|
@@ -2304,6 +2305,35 @@ window.__ModuleLoader__.load({
|
|
|
2304
2305
|
};
|
|
2305
2306
|
}
|
|
2306
2307
|
|
|
2308
|
+
/** 每个提供方独立持有声明;旧撤销函数不能碰到重载后的新声明。 */
|
|
2309
|
+
function provideMobileChatEmbed(ctx) {
|
|
2310
|
+
const candidate = globalThis.__DSH_MOBILE_CHAT_EMBED__;
|
|
2311
|
+
const bridge = candidate && candidate.version === 1 && candidate.surface === 'chat'
|
|
2312
|
+
&& typeof candidate.setTopBarVisible === 'function' ? candidate : null;
|
|
2313
|
+
const claims = new Set();
|
|
2314
|
+
let disposed = false;
|
|
2315
|
+
const service = {
|
|
2316
|
+
isEmbedded: () => Boolean(bridge && !disposed),
|
|
2317
|
+
keepTopBar() {
|
|
2318
|
+
if (!bridge || disposed) return () => {};
|
|
2319
|
+
const claim = {};
|
|
2320
|
+
claims.add(claim);
|
|
2321
|
+
if (claims.size === 1) bridge.setTopBarVisible(true);
|
|
2322
|
+
return () => {
|
|
2323
|
+
if (disposed || !claims.delete(claim)) return;
|
|
2324
|
+
if (claims.size === 0) bridge.setTopBarVisible(false);
|
|
2325
|
+
};
|
|
2326
|
+
},
|
|
2327
|
+
};
|
|
2328
|
+
ctx.effect(() => () => {
|
|
2329
|
+
disposed = true;
|
|
2330
|
+
const hadClaims = claims.size > 0;
|
|
2331
|
+
claims.clear();
|
|
2332
|
+
if (bridge && hadClaims) bridge.setTopBarVisible(false);
|
|
2333
|
+
}, 'mobile-plugin: chat embed top bar');
|
|
2334
|
+
ctx.provide('mobileChatEmbed', service);
|
|
2335
|
+
}
|
|
2336
|
+
|
|
2307
2337
|
return {
|
|
2308
2338
|
// slots:注册设置项与侧边栏那颗图标,由 @deepseek-ai/dsh-client-runtime 提供(它 require
|
|
2309
2339
|
// dsh-client-ui-slots 的 SlotCore 再以 `super(ctx, "slots")` 暴露服务)。
|
|
@@ -2311,6 +2341,7 @@ window.__ModuleLoader__.load({
|
|
|
2311
2341
|
// 这两个服务名对应 package.json 里 dsh.client.inject 注入的两个包。
|
|
2312
2342
|
inject: ['slots', 'locale'],
|
|
2313
2343
|
apply(ctx) {
|
|
2344
|
+
provideMobileChatEmbed(ctx);
|
|
2314
2345
|
ctx.effect(() => ctx.locale.register(NS, DICT), 'mobile-plugin: settings dictionaries');
|
|
2315
2346
|
const t = ctx.locale.bind(NS);
|
|
2316
2347
|
installPluginPages(ctx, t);
|
|
@@ -18,6 +18,8 @@
|
|
|
18
18
|
* 落盘位置 `<DSH_HOME>/storages/mobile-plugin/approval-rules.json`,照移动端那几份账本的
|
|
19
19
|
* 同一套「原子写 + 读坏当空」的边界:账本读不动不能把审批拦在门外,写失败也只影响「重启后
|
|
20
20
|
* 还在不在」。`DSH_MOBILE_APPROVAL_RULES` 只给测试注入路径用。
|
|
21
|
+
*
|
|
22
|
+
* 撤销走的是真删除:写盘失败时 `removeRule` 抛错而非报成功,免得界面划掉后重启规则又回来。
|
|
21
23
|
*/
|
|
22
24
|
|
|
23
25
|
const fs = require('node:fs');
|
|
@@ -181,7 +183,12 @@ function addRule({ classKey, label }) {
|
|
|
181
183
|
return saveStore(store);
|
|
182
184
|
}
|
|
183
185
|
|
|
184
|
-
/**
|
|
186
|
+
/**
|
|
187
|
+
* 撤一条。true = 真删掉并落盘;false = 本来就不在(算成功,结果一样)。
|
|
188
|
+
*
|
|
189
|
+
* 写盘失败**抛错**,不报「已删掉」:否则界面把这一行划掉、插件一重启规则又回来,用户以为撤销
|
|
190
|
+
* 成了。调用方据此回非 ok,手机才保留那一行并提示重试。
|
|
191
|
+
*/
|
|
185
192
|
function removeRule(classKey) {
|
|
186
193
|
const key = textOf(classKey, 200);
|
|
187
194
|
if (!key) return false;
|
|
@@ -189,7 +196,7 @@ function removeRule(classKey) {
|
|
|
189
196
|
const next = store.rules.filter((rule) => rule.classKey !== key);
|
|
190
197
|
if (next.length === store.rules.length) return false;
|
|
191
198
|
store.rules = next;
|
|
192
|
-
saveStore(store);
|
|
199
|
+
if (!saveStore(store)) throw new Error('审批规则写盘失败');
|
|
193
200
|
return true;
|
|
194
201
|
}
|
|
195
202
|
|
package/lib/mobile/approvals.js
CHANGED
|
@@ -27,6 +27,9 @@
|
|
|
27
27
|
* 记录 —— 只写在挂起项上会随结算一起消失,用户事后无从回看。
|
|
28
28
|
* 另有「同一轮里相同请求再次出现直接 auto-reject」(`turnState` 记本轮签名)。这套逻辑整体
|
|
29
29
|
* 叠在可关的自动审阅档(`auto-review.js`)之后,两者互不影响。
|
|
30
|
+
*
|
|
31
|
+
* `classLabel`(类别人话)在推卡时随卡下发,供第三颗按钮旁那行说明;撤销接口在写盘失败时
|
|
32
|
+
* 回非 ok,手机据此保留那一行并提示重试,不把没删成的规则当成已撤销。
|
|
30
33
|
*/
|
|
31
34
|
|
|
32
35
|
const { randomUUID } = require('node:crypto');
|
|
@@ -954,7 +957,15 @@ async function handleApprovalRuleRevoke(ctx, req, res) {
|
|
|
954
957
|
return sendJson(res, 400, { ok: false, error: { code: 'bad-request', message: '需要 { classKey }' } });
|
|
955
958
|
}
|
|
956
959
|
let removed = false;
|
|
957
|
-
try {
|
|
960
|
+
try {
|
|
961
|
+
removed = approvalMemory.removeRule(classKey);
|
|
962
|
+
} catch {
|
|
963
|
+
// 写盘失败:如实报错,手机那一行才不会被划掉(否则重启后规则又冒回来,用户白撤销一场)。
|
|
964
|
+
return sendJson(res, 500, {
|
|
965
|
+
ok: false,
|
|
966
|
+
error: { code: 'rule-persist-failed', message: '电脑上没能删掉这条规则,请稍后再试' },
|
|
967
|
+
});
|
|
968
|
+
}
|
|
958
969
|
sendJson(res, 200, { ok: true, removed });
|
|
959
970
|
}
|
|
960
971
|
|
|
@@ -26,6 +26,7 @@ const {
|
|
|
26
26
|
const { promptErrorObject, MODEL_UNAVAILABLE_ERROR } = require('./history-derive.js');
|
|
27
27
|
const { withIdempotency, requestIdOf } = require('./idempotency.js');
|
|
28
28
|
const { invoke, UNAVAILABLE: GATEWAY_UNAVAILABLE } = require('./host-bridge/transport.js');
|
|
29
|
+
const { selectSessionModel } = require('./host-bridge/session-model.js');
|
|
29
30
|
const { recordSessionRead } = require('./session-last-turn.js');
|
|
30
31
|
const { imageSizeOf } = require('./local-images.js');
|
|
31
32
|
const attachmentStore = require('./attachment-store.js');
|
|
@@ -47,6 +48,22 @@ function singleTextOf(content) {
|
|
|
47
48
|
return block.text;
|
|
48
49
|
}
|
|
49
50
|
|
|
51
|
+
/**
|
|
52
|
+
* 本次发送要临时使用的模型(`{provider, model, reasoningEffort?}`):App 选完模型不再单独
|
|
53
|
+
* 发切换请求,而是随这一条消息带过来,由这里在**真正提交 prompt 之前**落到会话上。
|
|
54
|
+
*
|
|
55
|
+
* 形状不认识(缺 provider / model)就当没带:老 App 不带这一格,行为与以前完全一致。
|
|
56
|
+
*/
|
|
57
|
+
function modelSelectionOf(body) {
|
|
58
|
+
const value = body && body.modelSelection;
|
|
59
|
+
if (!value || typeof value !== 'object') return null;
|
|
60
|
+
const provider = typeof value.provider === 'string' ? value.provider.trim() : '';
|
|
61
|
+
const model = typeof value.model === 'string' ? value.model.trim() : '';
|
|
62
|
+
if (!provider || !model) return null;
|
|
63
|
+
const reasoningEffort = typeof value.reasoningEffort === 'string' && value.reasoningEffort ? value.reasoningEffort : undefined;
|
|
64
|
+
return { provider, model, ...(reasoningEffort ? { reasoningEffort } : {}) };
|
|
65
|
+
}
|
|
66
|
+
|
|
50
67
|
/**
|
|
51
68
|
* 经网关执行 slash 命令(commands.execute,桌面 Web 端同一条派发路径:命令注册表命中才执行,
|
|
52
69
|
* 绝不经 session.prompt 发给模型;agent 由 agentId 经同一查找器解析,支持冷会话自动 resume)。
|
|
@@ -72,8 +89,10 @@ async function executeCommand(ctx, sessionId, line) {
|
|
|
72
89
|
* POST /api/mobile/v1/session/send(token)
|
|
73
90
|
* 兼容两种格式:
|
|
74
91
|
* 旧:{sessionId, text}
|
|
75
|
-
* 新:{sessionId, content:[{type:'text',text} | {type:'image',mediaType,data(base64),name?}], mode?:'queue'|'steer'
|
|
76
|
-
*
|
|
92
|
+
* 新:{sessionId, content:[{type:'text',text} | {type:'image',mediaType,data(base64),name?}], mode?:'queue'|'steer',
|
|
93
|
+
* modelSelection?:{provider,model,reasoningEffort?}}
|
|
94
|
+
* `modelSelection` 是本次发送要用的模型(App 侧选模型不再单独发切换请求);提交 prompt 之前先
|
|
95
|
+
* 落到会话上。恰为单个文本块且以 / 开头时派发为 slash 命令(commands.execute,不发给模型,也不应用模型);
|
|
77
96
|
* 其余原样透传给 harness 的 session.prompt(图片块需模型支持,不支持时错误原样返回)。
|
|
78
97
|
*/
|
|
79
98
|
function promptOnce(ctx, clientMessageId, payload) {
|
|
@@ -151,6 +170,22 @@ async function handleSend(ctx, req, res) {
|
|
|
151
170
|
return sendJson(res, 200, { ok: true, accepted: true, handledAs: 'command' });
|
|
152
171
|
}
|
|
153
172
|
}
|
|
173
|
+
// ── 本次发送携带的模型 ─────────────────────────────────────────
|
|
174
|
+
// App 侧选模型只改本地,切换请求随这一条消息一起到。**必须在 prompt 之前**落到会话上,
|
|
175
|
+
// 这样这一轮的第一步用的就是用户刚选的模型(`agent.model.select` 只作用于尚未准备的那一步)。
|
|
176
|
+
// 模型不可用 / 无该能力时明确回 400,让 App 报出来 —— 不静默沿用会话里原来的模型。
|
|
177
|
+
const modelSelection = modelSelectionOf(body);
|
|
178
|
+
if (modelSelection) {
|
|
179
|
+
const applied = await selectSessionModel(ctx, { sessionId: body.sessionId, ...modelSelection });
|
|
180
|
+
const result = applied && applied.result ? applied.result : null;
|
|
181
|
+
if (!result || result.ok !== true) {
|
|
182
|
+
const failure = result && result.error
|
|
183
|
+
? result.error
|
|
184
|
+
: { code: 'session/model-unavailable', message: '所选模型当前不可用', details: modelSelection };
|
|
185
|
+
return sendJson(res, 400, { ok: false, error: continuation ? continuationError(failure) : failure });
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
154
189
|
let promptResponse;
|
|
155
190
|
try {
|
|
156
191
|
promptResponse = await promptOnce(ctx, typeof body.clientMessageId === 'string' ? body.clientMessageId : '', {
|