dsh-mobile-plugin 0.5.83 → 0.5.85
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/client.js +218 -6
- package/lib/http/routing.js +7 -0
- package/lib/impl.js +7 -1
- package/lib/mobile/channels.js +41 -18
- package/lib/mobile/feedback.js +142 -69
- package/lib/mobile/forge-contract.js +186 -0
- package/lib/mobile/forge-worktree.js +117 -0
- package/lib/mobile/forge.js +197 -0
- package/lib/mobile/host-bridge/endpoints.js +77 -8
- package/lib/mobile/host-bridge/event-synthesis.js +6 -7
- package/lib/mobile/host-bridge/shims.js +50 -29
- package/lib/mobile/host-settings.js +32 -0
- package/lib/mobile/model-caps.js +10 -6
- package/lib/mobile/pairing.js +10 -2
- package/lib/mobile/permissions.js +32 -0
- package/lib/mobile/plugin-market.js +94 -50
- package/lib/mobile/plugin-update.js +5 -0
- package/lib/mobile/relay-control.js +87 -0
- package/lib/mobile/schedule-edit.js +30 -55
- package/lib/mobile/schedule.js +98 -24
- package/lib/mobile/session-new.js +11 -1
- package/lib/mobile/subagents.js +63 -25
- package/lib/mobile/worktree-isolation.js +12 -4
- package/lib/mobile/worktree-lifecycle.js +2 -0
- package/lib/p2p/wiring.cjs +32 -14
- package/lib/panel/index.html +22 -21
- package/lib/relay/control.js +25 -8
- package/lib/relay/core.js +21 -18
- package/lib/relay/pairing-payload.cjs +7 -0
- package/lib/relay/status.js +2 -1
- package/lib/relay/tunnel-forwarder.cjs +5 -3
- package/lib/relay/tunnel.js +7 -2
- package/lib/remote/host-control.cjs +1 -1
- package/lib/routes/control-plane.js +4 -3
- package/lib/routes/mobile-api.js +59 -1
- package/lib/sidecar-facade-worker.cjs +9 -2
- package/lib/sidecar-facade.cjs +50 -22
- package/lib/sidecar-lifecycle.cjs +4 -3
- package/lib/tailcat/ingress.cjs +5 -3
- package/lib/tailcat/wiring.cjs +54 -30
- package/package.json +1 -1
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
// Forge 评审移动后端:固定 Session 绑定、head 校验和宿主 Remote 动作。
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const { sendJson, readJsonBody } = require('../shared/http-util');
|
|
5
|
+
const { requestSignal } = require('../shared/fresh-request.js');
|
|
6
|
+
const { callPanel, readPanelState, capabilitiesOf, sendError } = require('./forge-worktree.js');
|
|
7
|
+
const { requiredId, requiredUrl, baseBody, commit, diffCommits, reviewRequest, reviewWrite, reviewers, queryString, text } = require('./forge-contract.js');
|
|
8
|
+
|
|
9
|
+
function bodyLimit() { return 512 * 1024; }
|
|
10
|
+
|
|
11
|
+
function sendValidation(res, result) {
|
|
12
|
+
if (!result || !result.error) return false;
|
|
13
|
+
sendJson(res, 400, { ok: false, error: result.error });
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async function readBody(req) {
|
|
18
|
+
if (req.method === 'GET' || !req.method) {
|
|
19
|
+
const params = new URL(req.url, 'http://x').searchParams;
|
|
20
|
+
const body = Object.fromEntries(params.entries());
|
|
21
|
+
if (body.fresh !== undefined) body.fresh = body.fresh === '1' || body.fresh === 'true';
|
|
22
|
+
return body;
|
|
23
|
+
}
|
|
24
|
+
return (await readJsonBody(req, bodyLimit())) || {};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function sendValue(res, value, options = {}) {
|
|
28
|
+
if (options.result) return sendJson(res, 200, { ok: true, result: value });
|
|
29
|
+
if (value === undefined) return sendJson(res, 200, { ok: true, applied: true });
|
|
30
|
+
if (value === null) return sendJson(res, 200, { ok: true, supported: false });
|
|
31
|
+
if (Array.isArray(value)) return sendJson(res, 200, { ok: true, reviewers: value });
|
|
32
|
+
sendJson(res, 200, { ok: true, ...value });
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async function invokeWithBody(ctx, req, res, method, makeArgs) {
|
|
36
|
+
const body = await readBody(req);
|
|
37
|
+
let args;
|
|
38
|
+
try { args = makeArgs(body); }
|
|
39
|
+
catch (error) { sendError(res, error); return; }
|
|
40
|
+
if (args && args.error) { sendJson(res, 400, { ok: false, error: args.error }); return; }
|
|
41
|
+
try {
|
|
42
|
+
const value = await callPanel(ctx, method, args.value, requestSignal(res));
|
|
43
|
+
sendValue(res, value);
|
|
44
|
+
} catch (error) { sendError(res, error); }
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function stateEntry(state, url) {
|
|
48
|
+
return Array.isArray(state?.changeRequests) ? state.changeRequests.find(item => item && item.url === url) : null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function checkHead(state, url, expected) {
|
|
52
|
+
const entry = stateEntry(state, url);
|
|
53
|
+
if (!entry || !entry.ref) return Object.assign(new Error('变更请求没有绑定到此会话,或提供方未加载'), { code: 'forgePanel/not-bound' });
|
|
54
|
+
const failure = entry.update && entry.update.failure;
|
|
55
|
+
if (failure) return Object.assign(new Error(failure.message || '读取变更请求状态失败'), { code: failure.code });
|
|
56
|
+
const actual = entry.snapshot?.headSha || entry.update?.snapshot?.headSha || null;
|
|
57
|
+
if (!actual) return Object.assign(new Error('变更请求状态尚未读取,请刷新后再试'), { code: 'forgePanel/diff-failed' });
|
|
58
|
+
if (actual !== expected) return Object.assign(new Error(`变更请求 head 已从 ${expected} 变为 ${actual}`), { code: 'forgePanel/stale-head' });
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async function panelRead(ctx, req, res, method, args, options = {}) {
|
|
63
|
+
try {
|
|
64
|
+
if (options.headSha) {
|
|
65
|
+
const state = await readPanelState(ctx, args.sessionId, requestSignal(res), { url: args.url });
|
|
66
|
+
const mismatch = checkHead(state, args.url, options.headSha);
|
|
67
|
+
if (mismatch) throw mismatch;
|
|
68
|
+
}
|
|
69
|
+
const value = await callPanel(ctx, method, args, requestSignal(res));
|
|
70
|
+
if (value === null && options.nullSupported) return sendValue(res, null);
|
|
71
|
+
const expectedResultHead = options.resultHead || options.headSha;
|
|
72
|
+
if (expectedResultHead && value && typeof value === 'object' && 'headSha' in value && value.headSha !== expectedResultHead) {
|
|
73
|
+
throw Object.assign(new Error('变更请求 head 已变化,请刷新后重新读取'), { code: 'forgePanel/stale-head' });
|
|
74
|
+
}
|
|
75
|
+
sendValue(res, value, options);
|
|
76
|
+
} catch (error) { sendError(res, error); }
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async function handleForgeCapabilities(ctx, req, res) {
|
|
80
|
+
sendJson(res, 200, { ok: true, ...capabilitiesOf(ctx) });
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async function handleForgeState(ctx, req, res) {
|
|
84
|
+
const session = requiredId(queryString(req, 'sessionId'));
|
|
85
|
+
if (session.error) return sendJson(res, 400, { ok: false, error: session.error });
|
|
86
|
+
try { sendValue(res, await readPanelState(ctx, session.value, requestSignal(res))); }
|
|
87
|
+
catch (error) { sendError(res, error); }
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async function handleForgeTrack(ctx, req, res) {
|
|
91
|
+
return invokeWithBody(ctx, req, res, 'track', body => {
|
|
92
|
+
const base = baseBody(body); if (base.error) return base;
|
|
93
|
+
return { value: { sessionId: base.value.sessionId, url: base.value.url } };
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async function handleForgeDismiss(ctx, req, res) {
|
|
98
|
+
return invokeWithBody(ctx, req, res, 'dismiss', body => {
|
|
99
|
+
const base = baseBody(body); if (base.error) return base;
|
|
100
|
+
return { value: { sessionId: base.value.sessionId, url: base.value.url } };
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async function handleForgeDiff(ctx, req, res) {
|
|
105
|
+
const body = await readBody(req); const base = baseBody(body); if (sendValidation(res, base)) return;
|
|
106
|
+
const head = commit(body.headSha); if (sendValidation(res, head)) return;
|
|
107
|
+
const commits = diffCommits(body.commits ?? (body.from || body.to ? { from: body.from, to: body.to } : null)); if (sendValidation(res, commits)) return;
|
|
108
|
+
return panelRead(ctx, req, res, 'changeRequestDiff', { ...base.value, commits: commits.value }, { headSha: head.value, resultHead: commits.value?.to || head.value });
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async function handleForgeChecks(ctx, req, res) {
|
|
112
|
+
const body = await readBody(req); const base = baseBody(body); if (sendValidation(res, base)) return;
|
|
113
|
+
const head = commit(body.headSha); if (sendValidation(res, head)) return;
|
|
114
|
+
return panelRead(ctx, req, res, 'changeRequestChecks', { ...base.value, headSha: head.value }, { headSha: head.value });
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
async function handleForgeCommits(ctx, req, res) {
|
|
118
|
+
const body = await readBody(req); const base = baseBody(body); if (sendValidation(res, base)) return;
|
|
119
|
+
const head = commit(body.headSha); if (sendValidation(res, head)) return;
|
|
120
|
+
return panelRead(ctx, req, res, 'changeRequestCommits', base.value, { headSha: head.value, nullSupported: true });
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
async function handleForgeReview(ctx, req, res) {
|
|
124
|
+
const body = await readBody(req); const base = baseBody(body); if (sendValidation(res, base)) return;
|
|
125
|
+
const head = commit(body.headSha); if (sendValidation(res, head)) return;
|
|
126
|
+
return panelRead(ctx, req, res, 'changeRequestReview', { ...base.value, headSha: head.value, fresh: body.fresh === true }, { headSha: head.value });
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async function handleForgeViewed(ctx, req, res) {
|
|
130
|
+
const body = await readBody(req); const base = baseBody(body); if (sendValidation(res, base)) return;
|
|
131
|
+
const head = commit(body.headSha); if (sendValidation(res, head)) return;
|
|
132
|
+
return panelRead(ctx, req, res, 'changeRequestViewed', { ...base.value, headSha: head.value }, { headSha: head.value, nullSupported: true });
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
async function handleForgeReviewers(ctx, req, res) {
|
|
136
|
+
const session = requiredId(queryString(req, 'sessionId')); if (session.error) return sendJson(res, 400, { ok: false, error: session.error });
|
|
137
|
+
const url = requiredUrl(queryString(req, 'url')); if (url.error) return sendJson(res, 400, { ok: false, error: url.error });
|
|
138
|
+
const query = text(queryString(req, 'query'), 300);
|
|
139
|
+
try { sendValue(res, await callPanel(ctx, 'reviewerCandidates', { sessionId: session.value, url: url.value, query }, requestSignal(res))); }
|
|
140
|
+
catch (error) { sendError(res, error); }
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
async function handleForgeReviewWrite(ctx, req, res) {
|
|
144
|
+
const body = await readBody(req); const parsed = reviewWrite(body); if (sendValidation(res, parsed)) return;
|
|
145
|
+
return panelRead(ctx, req, res, 'changeRequestReviewWrite', parsed.value, { result: true, headSha: parsed.value.write.headSha });
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
async function handleForgeSubmitReview(ctx, req, res) {
|
|
149
|
+
const body = await readBody(req); const parsed = reviewRequest(body); if (sendValidation(res, parsed)) return;
|
|
150
|
+
return panelRead(ctx, req, res, 'submitReview', parsed.value, { result: true, headSha: parsed.value.request.headSha });
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
async function handleForgeViewedWrite(ctx, req, res) {
|
|
154
|
+
const body = await readBody(req); const base = baseBody(body); if (sendValidation(res, base)) return;
|
|
155
|
+
const request = body.request; if (!request || typeof request !== 'object' || Array.isArray(request)) return sendJson(res, 400, { ok: false, error: { code: 'bad-request', message: '需要 viewed request' } });
|
|
156
|
+
const head = commit(request.headSha); if (sendValidation(res, head)) return;
|
|
157
|
+
const path = text(request.path, 2048); if (!path || typeof request.viewed !== 'boolean') return sendJson(res, 400, { ok: false, error: { code: 'bad-request', message: 'viewed request 不合法' } });
|
|
158
|
+
return panelRead(ctx, req, res, 'setFileViewed', { ...base.value, request: { path, viewed: request.viewed, headSha: head.value } }, { headSha: head.value });
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
async function handleForgeRerunChecks(ctx, req, res) {
|
|
162
|
+
const body = await readBody(req); const base = baseBody(body); if (sendValidation(res, base)) return;
|
|
163
|
+
const head = commit(body.headSha); if (sendValidation(res, head)) return;
|
|
164
|
+
return panelRead(ctx, req, res, 'rerunChecks', { ...base.value, request: { headSha: head.value } }, { headSha: head.value });
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
async function handleForgeRequestReviews(ctx, req, res) {
|
|
168
|
+
const body = await readBody(req); const parsed = reviewers(body); if (sendValidation(res, parsed)) return;
|
|
169
|
+
return panelRead(ctx, req, res, 'requestReviews', parsed.value);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
async function handleForgeUpdateBranch(ctx, req, res) {
|
|
173
|
+
const body = await readBody(req); const base = baseBody(body); if (sendValidation(res, base)) return;
|
|
174
|
+
const head = commit(body.headSha); if (sendValidation(res, head)) return;
|
|
175
|
+
if (body.method !== 'merge' && body.method !== 'rebase') return sendJson(res, 400, { ok: false, error: { code: 'bad-request', message: 'updateBranch method 不合法' } });
|
|
176
|
+
return panelRead(ctx, req, res, 'updateBranch', { ...base.value, method: body.method, headSha: head.value }, { headSha: head.value });
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
async function handleForgeReady(ctx, req, res) {
|
|
180
|
+
const body = await readBody(req); const base = baseBody(body); if (sendValidation(res, base)) return;
|
|
181
|
+
return panelRead(ctx, req, res, 'markReady', base.value);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
async function handleForgeMerge(ctx, req, res) {
|
|
185
|
+
const body = await readBody(req); const base = baseBody(body); if (sendValidation(res, base)) return;
|
|
186
|
+
const head = commit(body.headSha); if (sendValidation(res, head)) return;
|
|
187
|
+
if (body.method !== 'merge' && body.method !== 'squash' && body.method !== 'rebase') return sendJson(res, 400, { ok: false, error: { code: 'bad-request', message: 'merge method 不合法' } });
|
|
188
|
+
return panelRead(ctx, req, res, 'merge', { ...base.value, method: body.method, headSha: head.value }, { headSha: head.value });
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
module.exports = {
|
|
192
|
+
handleForgeCapabilities, handleForgeState, handleForgeTrack, handleForgeDismiss,
|
|
193
|
+
handleForgeDiff, handleForgeChecks, handleForgeCommits, handleForgeReview, handleForgeViewed,
|
|
194
|
+
handleForgeReviewers, handleForgeReviewWrite, handleForgeSubmitReview, handleForgeViewedWrite,
|
|
195
|
+
handleForgeRerunChecks, handleForgeRequestReviews, handleForgeUpdateBranch, handleForgeReady,
|
|
196
|
+
handleForgeMerge,
|
|
197
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// 手机切换模型只写当前会话,不触发电脑全局默认保存。
|
|
2
2
|
// 本地目录浏览与宿主网关一致,保留路径中的首尾空格。
|
|
3
|
+
// rc.5 子代理 prompt 以 descriptor 识别新 wire,旧宿主继续走 parent/mode 兼容形状。
|
|
3
4
|
'use strict';
|
|
4
5
|
|
|
5
6
|
/**
|
|
@@ -120,13 +121,7 @@ const ENDPOINTS = {
|
|
|
120
121
|
|
|
121
122
|
// skills / subagents
|
|
122
123
|
'skills.list': inv('skills', 'list'),
|
|
123
|
-
'subagents.prompt':
|
|
124
|
-
request: {
|
|
125
|
-
...pick(p, ['parentSessionId', 'childSessionId', 'mode', 'content', 'clientTimeZone']),
|
|
126
|
-
requestId: typeof (p && p.requestId) === 'string' && p.requestId ? p.requestId : requestId('mobile-subagent'),
|
|
127
|
-
delivery: (p && p.delivery) || 'queue',
|
|
128
|
-
},
|
|
129
|
-
})),
|
|
124
|
+
'subagents.prompt': (ctx, payload, signal) => subagentPrompt(ctx, payload, signal),
|
|
130
125
|
'subagents.interrupt': (ctx, payload, signal) => subagentInterrupt(ctx, payload, signal),
|
|
131
126
|
'subagents.list': (ctx, payload, signal) => subagentCatalog(ctx, payload, signal),
|
|
132
127
|
|
|
@@ -175,6 +170,80 @@ const ENDPOINTS = {
|
|
|
175
170
|
.then((r) => (r.error ? fail(r.error) : ok(r.value))),
|
|
176
171
|
};
|
|
177
172
|
|
|
173
|
+
function subagentPromptRequestOf(payload) {
|
|
174
|
+
const p = payload && typeof payload === 'object' ? payload : {};
|
|
175
|
+
const content = Array.isArray(p.content) ? p.content : [];
|
|
176
|
+
return {
|
|
177
|
+
requestId: typeof p.requestId === 'string' && p.requestId ? p.requestId : requestId('mobile-subagent'),
|
|
178
|
+
childSessionId: p.childSessionId,
|
|
179
|
+
delivery: p.delivery === 'steer' ? 'steer' : 'queue',
|
|
180
|
+
content,
|
|
181
|
+
...(typeof p.clientTimeZone === 'string' && p.clientTimeZone ? { clientTimeZone: p.clientTimeZone } : {}),
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function subagentPromptCapabilities(ctx) {
|
|
186
|
+
const unknown = { images: null, delivery: null, queue: true, steer: null };
|
|
187
|
+
try {
|
|
188
|
+
const registry = ctx && ctx.typert && ctx.typert.local;
|
|
189
|
+
const descriptor = registry && typeof registry.get === 'function' ? registry.get('subagents/prompt') : null;
|
|
190
|
+
const codec = descriptor && Array.isArray(descriptor.parameters) && descriptor.parameters.find(item => item.wire === 'request')?.codec;
|
|
191
|
+
if (!codec || codec.mode !== 'strict' || typeof codec.create !== 'function') return unknown;
|
|
192
|
+
const parser = codec.create();
|
|
193
|
+
const request = { requestId: 'mobile-capability-probe', childSessionId: 'mobile-capability-probe', delivery: 'queue', content: [{ type: 'text', text: 'probe' }] };
|
|
194
|
+
const accepts = value => {
|
|
195
|
+
try {
|
|
196
|
+
const parsed = parser.parse(value);
|
|
197
|
+
return parsed && parsed.childSessionId === value.childSessionId && parsed.delivery === value.delivery
|
|
198
|
+
&& Array.isArray(parsed.content) && parsed.content.length === value.content.length
|
|
199
|
+
&& parsed.content.every((part, index) => part && part.type === value.content[index].type);
|
|
200
|
+
} catch { return false; }
|
|
201
|
+
};
|
|
202
|
+
if (!accepts(request) || accepts({ ...request, delivery: 'unsupported' })) {
|
|
203
|
+
try {
|
|
204
|
+
const parsed = parser.parse({ ...request, parentSessionId: 'mobile-parent-probe', mode: 'continuable' });
|
|
205
|
+
if (parsed && parsed.parentSessionId === 'mobile-parent-probe' && parsed.mode === 'continuable') return { images: false, delivery: false, queue: true, steer: false };
|
|
206
|
+
} catch { /* 既不是已确认的新形状,也不是旧形状,维持未知 */ }
|
|
207
|
+
return unknown;
|
|
208
|
+
}
|
|
209
|
+
return {
|
|
210
|
+
images: accepts({ ...request, content: [{ type: 'image', mediaType: 'image/png', data: 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAusB9Wl6ZmcAAAAASUVORK5CYII=' }] }),
|
|
211
|
+
delivery: true,
|
|
212
|
+
queue: true,
|
|
213
|
+
steer: accepts({ ...request, delivery: 'steer' }),
|
|
214
|
+
};
|
|
215
|
+
} catch {
|
|
216
|
+
return unknown;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function legacyPromptBoundary(error) {
|
|
221
|
+
if (!error || !['gateway/arguments-invalid', 'gateway/input-invalid', 'gateway/bad-request'].includes(error.code)) return false;
|
|
222
|
+
const detail = `${error.message || ''} ${JSON.stringify(error.details || {})}`;
|
|
223
|
+
return /parentSessionId|\bmode\b/.test(detail) && /missing|required|undefined|invalid_type/i.test(detail);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
async function subagentPrompt(ctx, payload, signal) {
|
|
227
|
+
const request = subagentPromptRequestOf(payload);
|
|
228
|
+
const caps = subagentPromptCapabilities(ctx);
|
|
229
|
+
const hasImages = request.content.some(item => item && item.type === 'image');
|
|
230
|
+
if ((hasImages && caps.images !== true) || (request.delivery === 'steer' && caps.steer !== true)) {
|
|
231
|
+
return fail({ code: 'subagent-prompt-unsupported', message: '这台宿主未确认支持子代理图片或插话投递', details: { reason: hasImages ? 'SUBAGENT_IMAGE_UNSUPPORTED' : 'SUBAGENT_STEER_UNSUPPORTED' } });
|
|
232
|
+
}
|
|
233
|
+
const legacy = {
|
|
234
|
+
...pick(payload, ['parentSessionId', 'childSessionId', 'mode', 'clientTimeZone']),
|
|
235
|
+
mode: (payload && payload.mode) || 'continuable', content: request.content,
|
|
236
|
+
};
|
|
237
|
+
// 未能从严格 descriptor 证实新 wire 时保守走旧形状;旧宿主不可被猜成新宿主。
|
|
238
|
+
if (caps.delivery !== true) return invokeEnvelope(ctx, 'subagents', 'prompt', { request: legacy }, signal);
|
|
239
|
+
const result = await invoke(ctx, 'subagents', 'prompt', { request }, signal);
|
|
240
|
+
// Only a pre-dispatch boundary rejection permits the old pure-text queue request.
|
|
241
|
+
if (result.error && !hasImages && request.delivery === 'queue' && legacyPromptBoundary(result.error)) {
|
|
242
|
+
return invokeEnvelope(ctx, 'subagents', 'prompt', { request: legacy }, signal);
|
|
243
|
+
}
|
|
244
|
+
return result.error ? fail(result.error) : ok(result.value);
|
|
245
|
+
}
|
|
246
|
+
|
|
178
247
|
function goalAction(ctx, method, payload, signal) {
|
|
179
248
|
return invoke(ctx, 'goals', method, { agentId: payload.sessionId, ref: payload.ref }, signal)
|
|
180
249
|
.then((r) => (r.error ? fail(r.error) : ok(r.value)));
|
|
@@ -254,4 +323,4 @@ async function localCreateDirectory(ctx, payload, signal) {
|
|
|
254
323
|
}
|
|
255
324
|
}
|
|
256
325
|
|
|
257
|
-
module.exports = { ENDPOINTS, goalAction, localCreateDirectory, localListDirectory };
|
|
326
|
+
module.exports = { ENDPOINTS, goalAction, localCreateDirectory, localListDirectory, subagentPromptCapabilities };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// 单会话 follow 仅按明确 activate 请求恢复 Agent;历史和被动订阅保持不激活。
|
|
1
2
|
'use strict';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -61,12 +62,9 @@ function sessionAddress(payload) {
|
|
|
61
62
|
const sessionId = payload && payload.sessionId;
|
|
62
63
|
const parentSessionId = payload && payload.parentSessionId;
|
|
63
64
|
if (typeof parentSessionId === 'string' && parentSessionId) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
childSessionId: sessionId,
|
|
68
|
-
mode: (payload && payload.mode) || 'continuable',
|
|
69
|
-
};
|
|
65
|
+
const mode = (payload && payload.mode) || 'continuable';
|
|
66
|
+
if (mode === 'external') return null;
|
|
67
|
+
return { kind: 'subagent', parentSessionId, childSessionId: sessionId, mode };
|
|
70
68
|
}
|
|
71
69
|
return { kind: 'session', sessionId };
|
|
72
70
|
}
|
|
@@ -423,6 +421,7 @@ function muxFrames(ctx, request, signal) {
|
|
|
423
421
|
return;
|
|
424
422
|
}
|
|
425
423
|
const address = sessionAddress(payload);
|
|
424
|
+
if (!address) throw Object.assign(new Error('外部执行没有本地子会话流'), { code: 'subagent/not-resumable' });
|
|
426
425
|
const controller = new AbortController();
|
|
427
426
|
const abort = () => controller.abort();
|
|
428
427
|
signal?.addEventListener('abort', abort, { once: true });
|
|
@@ -432,7 +431,7 @@ function muxFrames(ctx, request, signal) {
|
|
|
432
431
|
const childSignal = controller.signal;
|
|
433
432
|
const control = openStream(ctx, 'session', 'control', {}, childSignal);
|
|
434
433
|
const follow = openStream(ctx, 'session', 'follow', {
|
|
435
|
-
request: { address, maxMessages: 1, assistantStream: true },
|
|
434
|
+
request: { address, maxMessages: 1, assistantStream: true, ...(payload && payload.activate === true && address.kind === 'session' ? { activate: true } : {}) },
|
|
436
435
|
}, childSignal);
|
|
437
436
|
const opening = [['control', control], ['follow', follow]];
|
|
438
437
|
if (address.kind === 'session') opening.push(['jobs', openStream(ctx, 'job', 'list', { request: { sessionId } }, childSignal)]);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// 子代理目录保留 rc.5 名字与关系,根可用性由已验证的 catalog 创建链决定。
|
|
1
2
|
'use strict';
|
|
2
3
|
/** 没有 1:1 端点、需要跨端点合成或翻译的几处(翻页游标、模型目录、跟随流、投影基线)。 */
|
|
3
4
|
|
|
@@ -25,12 +26,9 @@ function historyAddress(payload) {
|
|
|
25
26
|
const sessionId = payload && payload.sessionId;
|
|
26
27
|
const parentSessionId = payload && payload.parentSessionId;
|
|
27
28
|
if (typeof parentSessionId === 'string' && parentSessionId) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
childSessionId: sessionId,
|
|
32
|
-
mode: (payload && payload.mode) || 'continuable',
|
|
33
|
-
};
|
|
29
|
+
const mode = (payload && payload.mode) || 'continuable';
|
|
30
|
+
if (mode === 'external') return null;
|
|
31
|
+
return { kind: 'subagent', parentSessionId, childSessionId: sessionId, mode };
|
|
34
32
|
}
|
|
35
33
|
return { kind: 'session', sessionId };
|
|
36
34
|
}
|
|
@@ -39,6 +37,7 @@ async function historyViaPage(ctx, payload, signal) {
|
|
|
39
37
|
const sessionId = payload && payload.sessionId;
|
|
40
38
|
if (typeof sessionId !== 'string' || !sessionId) return fail({ code: 'bad-request', message: '缺少 sessionId' }, 'bad-request');
|
|
41
39
|
const address = historyAddress(payload);
|
|
40
|
+
if (!address) return fail({ code: 'subagent/not-resumable', message: '外部执行没有本地子会话历史' });
|
|
42
41
|
let throughSeq = -1;
|
|
43
42
|
try {
|
|
44
43
|
const frames = await openStream(ctx, 'session', 'follow', {
|
|
@@ -227,19 +226,6 @@ async function subagentCatalog(ctx, payload, signal) {
|
|
|
227
226
|
for (const item of items) {
|
|
228
227
|
if (item && typeof item.sessionId === 'string' && item.sessionId) byId.set(item.sessionId, item);
|
|
229
228
|
}
|
|
230
|
-
// 桌面端 ClientSessions.agentAvailable() 的口径:在会话列表里找父会话,读它的
|
|
231
|
-
// agentAvailable;列表已就绪还找不到就是 false(它那个 undefined 是「列表还没读完」,
|
|
232
|
-
// 这里 list 是刚 await 回来的,早就就绪了)。
|
|
233
|
-
//
|
|
234
|
-
// 这一条是整套里唯一没法离线证实的口径,所以留一级退路:宿主万一不填
|
|
235
|
-
// agentAvailable(schema 里有,但没实证它一定被赋值),就退成「父会话还在列表里 =
|
|
236
|
-
// 还在这台宿主上」。宁可偶尔多给一个输入框,也不要整片目录一律只读 —— 后者用户
|
|
237
|
-
// 点进去发现子代理明明能续话却打不了字,比误判严重得多。
|
|
238
|
-
const parent = byId.get(parentSessionId);
|
|
239
|
-
const parentAvailable = !parent
|
|
240
|
-
? false
|
|
241
|
-
: typeof parent.agentAvailable === 'boolean' ? parent.agentAvailable : true;
|
|
242
|
-
|
|
243
229
|
// 基线优先:它是桌面端渲染目录的同一份数据。基线里没有这个会话、或者它的
|
|
244
230
|
// subagentCatalog 还没算出来,就退回列表摘要内联的那份投影;两处都没有就当
|
|
245
231
|
// 它没有派出过子代理。
|
|
@@ -250,24 +236,59 @@ async function subagentCatalog(ctx, payload, signal) {
|
|
|
250
236
|
return Array.isArray(inline.subagentCatalog) ? inline.subagentCatalog : [];
|
|
251
237
|
};
|
|
252
238
|
|
|
239
|
+
// 由父级 catalog 的创建边追溯根;只有 summary 的父指针而无 catalog 证明时保持未知。
|
|
240
|
+
const creators = new Map();
|
|
241
|
+
for (const id of new Set([...byId.keys(), ...baseline.keys()])) {
|
|
242
|
+
for (const entry of catalogOf(id)) {
|
|
243
|
+
if (!entry || typeof entry.id !== 'string' || !['continuable', 'one-shot', 'unknown', 'external'].includes(entry.mode)) continue;
|
|
244
|
+
const previous = creators.get(entry.id);
|
|
245
|
+
creators.set(entry.id, previous && previous.parentId !== id ? { conflict: true } : { parentId: id, entry });
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
const ancestry = [];
|
|
249
|
+
const seen = new Set();
|
|
250
|
+
let rootSessionId = parentSessionId;
|
|
251
|
+
let verified = true;
|
|
252
|
+
while (creators.has(rootSessionId) && !seen.has(rootSessionId)) {
|
|
253
|
+
seen.add(rootSessionId);
|
|
254
|
+
const edge = creators.get(rootSessionId);
|
|
255
|
+
if (edge.conflict || edge.entry.mode === 'external') { verified = false; break; }
|
|
256
|
+
ancestry.unshift(edge.entry.name);
|
|
257
|
+
rootSessionId = edge.parentId;
|
|
258
|
+
}
|
|
259
|
+
const root = byId.get(rootSessionId);
|
|
260
|
+
if (seen.has(rootSessionId) || !root || root.origin === 'subagent') verified = false;
|
|
261
|
+
const rootAvailable = verified && typeof root.agentAvailable === 'boolean' ? root.agentAvailable : null;
|
|
262
|
+
const parentPath = ancestry.every(name => typeof name === 'string' && name) ? ancestry.join('/') : undefined;
|
|
253
263
|
const entries = [];
|
|
254
264
|
for (const item of catalogOf(parentSessionId)) {
|
|
255
265
|
if (!item || typeof item.id !== 'string' || !item.id) continue;
|
|
256
|
-
|
|
266
|
+
const name = typeof item.name === 'string' && item.name.trim() ? item.name.trim() : undefined;
|
|
267
|
+
const label = typeof item.label === 'string' && item.label.trim() ? item.label.trim() : undefined;
|
|
268
|
+
const path = parentPath !== undefined && name ? [parentPath, name].filter(Boolean).join('/') : undefined;
|
|
269
|
+
const relation = { parentId: parentSessionId, parentSessionId, depth: ancestry.length + 1, ...(path ? { path } : {}) };
|
|
270
|
+
if (item.kind === 'diagnostic') {
|
|
271
|
+
if (['corrupt', 'unsupported', 'unavailable'].includes(item.reason)) entries.push({ kind: 'diagnostic', id: item.id, reason: item.reason, ...relation, ...(name ? { name } : {}) });
|
|
272
|
+
continue;
|
|
273
|
+
}
|
|
274
|
+
if (!['one-shot', 'continuable', 'unknown', 'external'].includes(item.mode)) {
|
|
275
|
+
entries.push({ kind: 'diagnostic', id: item.id, reason: 'unsupported', ...relation });
|
|
276
|
+
continue;
|
|
277
|
+
}
|
|
257
278
|
const child = byId.get(item.id);
|
|
258
279
|
entries.push({
|
|
259
|
-
kind: 'child',
|
|
260
|
-
id: item.id,
|
|
261
|
-
mode: item.mode,
|
|
280
|
+
kind: 'child', id: item.id, mode: item.mode,
|
|
262
281
|
activity: child && child.running === true ? 'running' : 'inactive',
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
...
|
|
282
|
+
hasChildren: item.mode !== 'external' && catalogOf(item.id).length > 0,
|
|
283
|
+
...(name ? { name } : {}),
|
|
284
|
+
...(label ? { label, description: label } : {}),
|
|
285
|
+
...(typeof item.description === 'string' && item.description.trim() ? { description: item.description.trim() } : {}),
|
|
286
|
+
...relation,
|
|
287
|
+
// Cold continuable targets can be resumed under the live root; target residency is not admission.
|
|
288
|
+
targetAvailable: item.mode === 'continuable' ? rootAvailable : false,
|
|
268
289
|
});
|
|
269
290
|
}
|
|
270
|
-
return ok({ entries, parentAvailable });
|
|
291
|
+
return ok({ entries, ...(verified ? { rootSessionId } : {}), rootAvailable, parentAvailable: rootAvailable === true });
|
|
271
292
|
}
|
|
272
293
|
|
|
273
294
|
module.exports = { historyViaPage, modelCatalog, workspaceListViaFollow, projectionBaseline, subagentCatalog };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// 搜索提供方、独立端点与凭据槽跟随宿主现值下发。
|
|
1
2
|
'use strict';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -232,6 +233,23 @@ function normalizeNamespace(item) {
|
|
|
232
233
|
const credential = credentialRefOf(item.schema, item.value);
|
|
233
234
|
if (credential) out.credentialRef = credential.ref;
|
|
234
235
|
}
|
|
236
|
+
if (ns === 'web' || ns === 'web-deepseek-api' || ns === 'web-search-deepseek') {
|
|
237
|
+
const current = out.value && typeof out.value === 'object' && !Array.isArray(out.value) ? out.value : {};
|
|
238
|
+
const defaults = ns === 'web' ? { searchProvider: '', fetchProvider: '' }
|
|
239
|
+
: ns === 'web-deepseek-api' ? { searchBilling: 'auto', fetchBilling: 'auto', searchBaseURL: '', searchApiKeyEnv: '', fetchBaseURL: '', fetchApiKeyEnv: '' }
|
|
240
|
+
: { baseURL: '', apiKeyEnv: '' };
|
|
241
|
+
const shape = schemaDict(item.schema);
|
|
242
|
+
out.value = { ...current };
|
|
243
|
+
for (const [key, fallback] of Object.entries(defaults)) {
|
|
244
|
+
if (shape && Object.hasOwn(shape.dict, key) && out.value[key] === undefined) out.value[key] = fallback;
|
|
245
|
+
}
|
|
246
|
+
if (ns === 'web-deepseek-api' && shape) {
|
|
247
|
+
out.credentialRefs = ['search', 'fetch'].filter((kind) => Object.hasOwn(shape.dict, `${kind}ApiKeyEnv`)).map((kind) => ({
|
|
248
|
+
field: `${kind}ApiKeyEnv`,
|
|
249
|
+
ref: typeof out.value[`${kind}ApiKeyEnv`] === 'string' && out.value[`${kind}ApiKeyEnv`].trim() ? out.value[`${kind}ApiKeyEnv`].trim() : 'DEEPSEEK_API_KEY',
|
|
250
|
+
}));
|
|
251
|
+
}
|
|
252
|
+
}
|
|
235
253
|
return out;
|
|
236
254
|
}
|
|
237
255
|
|
|
@@ -260,11 +278,25 @@ async function handleHostSettings(ctx, req, res) {
|
|
|
260
278
|
.filter(Boolean)
|
|
261
279
|
.slice(0, HOST_SETTINGS_MAX_NAMESPACES);
|
|
262
280
|
|
|
281
|
+
let webProviders;
|
|
282
|
+
try {
|
|
283
|
+
const web = typeof ctx.get === 'function' ? ctx.get('web') : null;
|
|
284
|
+
if (web && typeof web.listProviders === 'function') {
|
|
285
|
+
const listed = await web.listProviders();
|
|
286
|
+
const entries = (rows) => (Array.isArray(rows) ? rows : []).filter((row) => row && typeof row.id === 'string' && row.id).slice(0, 60).map((row) => ({
|
|
287
|
+
id: row.id,
|
|
288
|
+
...(row.title ? { title: boundValue(row.title) } : {}),
|
|
289
|
+
...(row.description ? { description: boundValue(row.description) } : {}),
|
|
290
|
+
}));
|
|
291
|
+
webProviders = { search: entries(listed?.search), fetch: entries(listed?.fetch) };
|
|
292
|
+
}
|
|
293
|
+
} catch { /* 旧宿主未挂载网页服务时,设置本体仍可读取。 */ }
|
|
263
294
|
sendJson(res, 200, {
|
|
264
295
|
ok: true,
|
|
265
296
|
writable: value != null && value.writable === true,
|
|
266
297
|
hasDocument: value != null && value.hasDocument === true,
|
|
267
298
|
namespaces,
|
|
299
|
+
...(webProviders ? { webProviders } : {}),
|
|
268
300
|
});
|
|
269
301
|
}
|
|
270
302
|
|
package/lib/mobile/model-caps.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//
|
|
1
|
+
// 模型协议随现值下发,Gemini 原生仅保存它支持的推理档位。
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -76,8 +76,9 @@ function overridesOf(providers) {
|
|
|
76
76
|
for (const model of models) {
|
|
77
77
|
const id = model && typeof model.id === 'string' ? model.id : '';
|
|
78
78
|
if (id === '') continue;
|
|
79
|
-
const caps = capabilityOf(model);
|
|
80
|
-
if (
|
|
79
|
+
const caps = capabilityOf(model) || {};
|
|
80
|
+
if (typeof profile.api === 'string') caps.protocol = profile.api;
|
|
81
|
+
if (Object.keys(caps).length > 0) out[`${providerId}\u0001${id}`] = caps;
|
|
81
82
|
}
|
|
82
83
|
}
|
|
83
84
|
return out;
|
|
@@ -158,7 +159,7 @@ function normalizeApply(body) {
|
|
|
158
159
|
}
|
|
159
160
|
|
|
160
161
|
/** 把一份能力配置合进那条模型(其它字段原样保留)。 */
|
|
161
|
-
function mergeModel(model, patch) {
|
|
162
|
+
function mergeModel(model, patch, protocol) {
|
|
162
163
|
const merged = { ...model };
|
|
163
164
|
if (patch.contextWindow !== undefined) merged.contextWindow = patch.contextWindow;
|
|
164
165
|
if (patch.maxTokens !== undefined) merged.maxTokens = patch.maxTokens;
|
|
@@ -175,7 +176,7 @@ function mergeModel(model, patch) {
|
|
|
175
176
|
const wires = modelMeta.lookupModelMeta(model.id)?.reasoningWires ?? {};
|
|
176
177
|
merged.reasoningEfforts = patch.reasoning.length === 0
|
|
177
178
|
? false
|
|
178
|
-
: Object.fromEntries(patch.reasoning.map((level) => [level, Object.hasOwn(previous, level) ? previous[level] : (wires[level] ?? level)]));
|
|
179
|
+
: Object.fromEntries(patch.reasoning.map((level) => [level, protocol === 'google-generative-ai' ? level : Object.hasOwn(previous, level) ? previous[level] : (wires[level] ?? level)]));
|
|
179
180
|
}
|
|
180
181
|
return merged;
|
|
181
182
|
}
|
|
@@ -206,6 +207,9 @@ async function handleModelMetaApply(ctx, req, res) {
|
|
|
206
207
|
error: { code: 'model-meta-external', message: '这条渠道不归本机配置,改不了它的模型参数' },
|
|
207
208
|
});
|
|
208
209
|
}
|
|
210
|
+
if (profile.api === 'google-generative-ai' && normalized.patch.reasoning?.some((level) => !['minimal', 'low', 'medium', 'high'].includes(level))) {
|
|
211
|
+
return sendJson(res, 400, { ok: false, error: { code: 'bad-request', message: 'Gemini 原生仅支持 minimal、low、medium、high 推理档位' } });
|
|
212
|
+
}
|
|
209
213
|
const models = Array.isArray(profile.models) ? profile.models : [];
|
|
210
214
|
const index = models.findIndex((model) => model && model.id === normalized.model);
|
|
211
215
|
if (index < 0) {
|
|
@@ -219,7 +223,7 @@ async function handleModelMetaApply(ctx, req, res) {
|
|
|
219
223
|
}
|
|
220
224
|
|
|
221
225
|
const nextModels = models.slice();
|
|
222
|
-
nextModels[index] = mergeModel(current, normalized.patch);
|
|
226
|
+
nextModels[index] = mergeModel(current, normalized.patch, profile.api);
|
|
223
227
|
const write = unwrap(await ctx.apiProxy.settings.mutate({
|
|
224
228
|
rpcId: 'mobile',
|
|
225
229
|
method: 'settings.mutate',
|
package/lib/mobile/pairing.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//
|
|
1
|
+
// 签发成功后记录绑定时间,供二维码自动收起,并发布独立的 IPv6 直连候选。
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -27,7 +27,7 @@ const { openSealedPairRequest, sealPairResponse } = require('../shared/e2ee-pair
|
|
|
27
27
|
// 档位 → 权限位(唯一真源)。配对时电脑侧选定的档位落在 state.pairingTier,这里展开成数组
|
|
28
28
|
// 交给凭据库;缺省 full = 与今天单 token 全给一字不差。
|
|
29
29
|
const permissions = require('./permissions.js');
|
|
30
|
-
const { tcpDirectTarget } = require('../relay/lan-network.cjs');
|
|
30
|
+
const { tcpDirectTarget, manualCandidate } = require('../relay/lan-network.cjs');
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* 一条入口一份闸门(见 `shared/pair-throttle.js` 头部的取舍说明)。
|
|
@@ -264,6 +264,8 @@ function createPairHandler(deps) {
|
|
|
264
264
|
return;
|
|
265
265
|
}
|
|
266
266
|
|
|
267
|
+
state.lastPairingAt = Date.now();
|
|
268
|
+
|
|
267
269
|
// 成功签发之后立刻作废资格:
|
|
268
270
|
// · 用一次性券配的 → consume 那张券(同一张配不了第二台手机);面板的码与票据不动,
|
|
269
271
|
// 因为这次配对根本没用到它们、也不该让别人的面板二维码跟着失效。
|
|
@@ -342,6 +344,12 @@ function createPairHandler(deps) {
|
|
|
342
344
|
// 整块展开就变成 `platform` —— App 收不到,设备行退回通用图标(真机上少的就是企鹅)。
|
|
343
345
|
...(hostPlatform ? { hostPlatform } : {}),
|
|
344
346
|
...(directCandidates.length ? { lanUrls: directCandidates } : {}),
|
|
347
|
+
// 手填的直连地址单独一格:手机把它落到「直连」栏,不从 lanUrls 里猜(lanUrls 里仍
|
|
348
|
+
// 带着它是老手机兼容)。
|
|
349
|
+
...(() => {
|
|
350
|
+
const direct = state.lanEnabled ? manualCandidate(state.manualLanUrl) : null;
|
|
351
|
+
return direct ? { directUrl: direct.url } : {};
|
|
352
|
+
})(),
|
|
345
353
|
...(v6Candidates.length ? { ipv6Candidates: v6Candidates } : {}),
|
|
346
354
|
// 「TCP 直连」那一条:设置项 `manualTcpUrl` 里能当裸 TCP 目标的,只此一条(手输配对时手机
|
|
347
355
|
// 没有二维码,这是它拿到这条 TCP 地址的唯一机会)。**始终带这一格**(可为空串),
|