dsh-mobile-plugin 0.5.124 → 0.5.126
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/impl.js +9 -6
- package/lib/mirror/pusher.cjs +1 -1
- package/lib/mobile/approvals.js +39 -47
- package/lib/mobile/channel-proxy.js +247 -38
- package/lib/mobile/channels.js +99 -4
- package/lib/mobile/feedback.js +17 -8
- package/lib/mobile/monitor.js +6 -1
- package/lib/mobile/push-notify.js +22 -4
- package/lib/mobile/relay-control.js +3 -2
- package/lib/mobile/workspace-id.js +40 -0
- package/lib/panel/index.html +3 -3
- package/lib/relay/control.js +5 -4
- package/package.json +14 -15
package/lib/mobile/channels.js
CHANGED
|
@@ -27,6 +27,28 @@ const { lanInterfaces } = require('../relay/lan-network.cjs');
|
|
|
27
27
|
/** 自建渠道写在这个命名空间里;桌面端 `src/custom-channels.js` 的 PI_AI_NS 同值。 */
|
|
28
28
|
const PI_AI_NS = 'llm-pi-ai';
|
|
29
29
|
|
|
30
|
+
/**
|
|
31
|
+
* 宿主自带的官方渠道里,手机「一键导入」能直接用的那几条。
|
|
32
|
+
*
|
|
33
|
+
* 它们不在 `llm-pi-ai` 的 providers 里,没有一份可搬的 profile;但官方 DeepSeek 的 Key
|
|
34
|
+
* 与 OpenAI 兼容地址是确定的。桌面这条走 Anthropic Messages(`api.deepseek.com/anthropic`),
|
|
35
|
+
* 手机本机 Agent 只认 OpenAI 那套,所以导出时换成手机能拨的 OpenAI 兼容地址,模型名与 Key
|
|
36
|
+
* 不变。其它插件 / 宿主渠道没有确定的地址与 Key,不在这里,导出去也用不了。
|
|
37
|
+
*/
|
|
38
|
+
const IMPORTABLE_BUILTINS = new Map([
|
|
39
|
+
['deepseek-official', {
|
|
40
|
+
name: 'DeepSeek',
|
|
41
|
+
protocol: 'openai-completions',
|
|
42
|
+
baseUrl: 'https://api.deepseek.com',
|
|
43
|
+
credentialRef: 'DEEPSEEK_API_KEY',
|
|
44
|
+
}],
|
|
45
|
+
]);
|
|
46
|
+
|
|
47
|
+
/** 这条内置渠道是否可按上面的方式导入;不是就回 null。 */
|
|
48
|
+
function importableBuiltinOf(id) {
|
|
49
|
+
return typeof id === 'string' && IMPORTABLE_BUILTINS.has(id) ? IMPORTABLE_BUILTINS.get(id) : null;
|
|
50
|
+
}
|
|
51
|
+
|
|
30
52
|
const PROTOCOLS = ['openai-completions', 'openai-responses', 'anthropic-messages', 'google-generative-ai'];
|
|
31
53
|
const GEMINI_LEVELS = ['minimal', 'low', 'medium', 'high'];
|
|
32
54
|
|
|
@@ -278,7 +300,10 @@ async function handleChannels(ctx, req, res) {
|
|
|
278
300
|
}
|
|
279
301
|
|
|
280
302
|
const customIds = Object.keys(providers);
|
|
281
|
-
const refs =
|
|
303
|
+
const refs = [...new Set([
|
|
304
|
+
...customIds.map(credentialRefOf),
|
|
305
|
+
...[...IMPORTABLE_BUILTINS.values()].map((spec) => spec.credentialRef),
|
|
306
|
+
])];
|
|
282
307
|
let keyState = {};
|
|
283
308
|
if (refs.length > 0) {
|
|
284
309
|
const described = unwrap(await ctx.apiProxy.credentials.describe({
|
|
@@ -294,12 +319,21 @@ async function handleChannels(ctx, req, res) {
|
|
|
294
319
|
if (!item || typeof item.provider !== 'string' || item.provider === '') continue;
|
|
295
320
|
// 自建路由同样会出现在 llm.providers 里,跳过——下面会以「自建」身份列一次。
|
|
296
321
|
if (Object.prototype.hasOwnProperty.call(providers, item.provider)) continue;
|
|
322
|
+
const builtin = importableBuiltinOf(item.provider);
|
|
323
|
+
const view = builtin ? keyState[builtin.credentialRef] : null;
|
|
297
324
|
channels.push({
|
|
298
325
|
id: item.provider,
|
|
299
326
|
source: 'external',
|
|
300
327
|
name: typeof item.displayName === 'string' && item.displayName.trim() ? item.displayName.trim() : item.provider,
|
|
301
328
|
active: item.active === true,
|
|
302
329
|
models: modelsOf.get(item.provider) || [],
|
|
330
|
+
// 官方内置渠道额外给手机导入页要的三格;其余插件渠道维持只读、不出现导入入口。
|
|
331
|
+
...(builtin ? {
|
|
332
|
+
importable: true,
|
|
333
|
+
protocol: builtin.protocol,
|
|
334
|
+
baseUrl: builtin.baseUrl,
|
|
335
|
+
...(view ? { keySet: view.configured === true } : {}),
|
|
336
|
+
} : {}),
|
|
303
337
|
});
|
|
304
338
|
}
|
|
305
339
|
for (const id of customIds) {
|
|
@@ -671,15 +705,76 @@ async function customChannelWithKey(ctx, id) {
|
|
|
671
705
|
return { channel, apiKey, keySet: apiKey !== '' };
|
|
672
706
|
}
|
|
673
707
|
|
|
708
|
+
/**
|
|
709
|
+
* 按 provider id 取它的模型清单(`llm.models` 的 groups)。
|
|
710
|
+
*
|
|
711
|
+
* 只给内置官方渠道的导出用:自建那批的模型在它自己的 profile 里,不走这里。
|
|
712
|
+
*/
|
|
713
|
+
async function modelsOfProvider(ctx, id) {
|
|
714
|
+
const catalog = unwrap(await ctx.apiProxy.llm.models({
|
|
715
|
+
rpcId: 'mobile',
|
|
716
|
+
method: 'llm.models',
|
|
717
|
+
payload: {},
|
|
718
|
+
}));
|
|
719
|
+
if (catalog.error) return [];
|
|
720
|
+
const groups = Array.isArray(catalog.value && catalog.value.groups) ? catalog.value.groups : [];
|
|
721
|
+
const group = groups.find((entry) => entry && entry.id === id);
|
|
722
|
+
return (Array.isArray(group && group.models) ? group.models : [])
|
|
723
|
+
.map((model) => {
|
|
724
|
+
if (!model || typeof model !== 'object') return null;
|
|
725
|
+
const modelId = typeof model.id === 'string' ? model.id.trim() : '';
|
|
726
|
+
if (!modelId) return null;
|
|
727
|
+
return { id: modelId, name: typeof model.name === 'string' && model.name.trim() ? model.name.trim() : modelId };
|
|
728
|
+
})
|
|
729
|
+
.filter(Boolean);
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
/**
|
|
733
|
+
* 内置官方渠道 → 可导出的那一条;不是这类 id 回 `null`,是这类但宿主上没注册回 `{ error }`。
|
|
734
|
+
*
|
|
735
|
+
* Key 取不到不算失败,与自建那条同一个口径:`keySet:false`,让用户自己填一次。
|
|
736
|
+
*/
|
|
737
|
+
async function builtinImportableChannel(ctx, id) {
|
|
738
|
+
const spec = importableBuiltinOf(id);
|
|
739
|
+
if (!spec) return null;
|
|
740
|
+
const listed = unwrap(await ctx.apiProxy.llm.providers({
|
|
741
|
+
rpcId: 'mobile',
|
|
742
|
+
method: 'llm.providers',
|
|
743
|
+
payload: {},
|
|
744
|
+
}));
|
|
745
|
+
if (listed.error) return { error: listed.error };
|
|
746
|
+
const registered = Array.isArray(listed.value && listed.value.providers) ? listed.value.providers : [];
|
|
747
|
+
if (!registered.some((item) => item && item.provider === id)) {
|
|
748
|
+
return { error: { code: 'channel-not-found', message: '这台电脑上没有这条渠道' }, status: 404 };
|
|
749
|
+
}
|
|
750
|
+
const models = await modelsOfProvider(ctx, id);
|
|
751
|
+
let apiKey = '';
|
|
752
|
+
try {
|
|
753
|
+
const resolved = unwrap(await ctx.apiProxy.credentials.resolve({
|
|
754
|
+
rpcId: 'mobile',
|
|
755
|
+
method: 'credentials.resolve',
|
|
756
|
+
payload: { ref: spec.credentialRef },
|
|
757
|
+
}));
|
|
758
|
+
if (!resolved.error && resolved.value && typeof resolved.value.value === 'string') apiKey = resolved.value.value;
|
|
759
|
+
} catch { /* 宿主没注册 resolve:按「没带 Key」处理 */ }
|
|
760
|
+
return {
|
|
761
|
+
channel: { id, name: spec.name, protocol: spec.protocol, baseUrl: spec.baseUrl, models },
|
|
762
|
+
apiKey,
|
|
763
|
+
keySet: apiKey !== '',
|
|
764
|
+
};
|
|
765
|
+
}
|
|
766
|
+
|
|
674
767
|
/**
|
|
675
768
|
* POST /api/mobile/v1/channels/export(token){ id }
|
|
676
769
|
* → { ok, channel, keySet, candidates }
|
|
677
770
|
*
|
|
678
|
-
*
|
|
771
|
+
* 把电脑上这条渠道整条交给手机,给「本机 Agent 新增渠道」页的一键导入用:名字、协议、
|
|
679
772
|
* 地址、模型,以及**它的 Key**。手机本来就为手动添加的渠道在本地存着同一把 Key,这里只是
|
|
680
773
|
* 把「用户再敲一遍」换成「电脑交过来」,不是新开一类暴露。
|
|
681
774
|
*
|
|
682
|
-
*
|
|
775
|
+
* 两类可导:`llm-pi-ai` 里的自建渠道,以及宿主自带的官方 DeepSeek(映射成 OpenAI 兼容
|
|
776
|
+
* 地址,见 `IMPORTABLE_BUILTINS`)。其它插件 / 宿主注册的提供方没有可搬的地址与 Key,
|
|
777
|
+
* 一律 404。
|
|
683
778
|
* Key 只在用户点名这一条时取一次,取不到(宿主没注册 resolve、凭据是环境变量提供的)就
|
|
684
779
|
* 如实回 keySet:false,由手机让用户自己填,不把失败报成整条导入失败。
|
|
685
780
|
*
|
|
@@ -692,7 +787,7 @@ async function handleChannelExport(ctx, req, res) {
|
|
|
692
787
|
if (!CHANNEL_ID_PATTERN.test(id)) {
|
|
693
788
|
return sendJson(res, 400, { ok: false, error: { code: 'bad-request', message: '需要渠道 id' } });
|
|
694
789
|
}
|
|
695
|
-
const found = await customChannelWithKey(ctx, id);
|
|
790
|
+
const found = (await builtinImportableChannel(ctx, id)) || await customChannelWithKey(ctx, id);
|
|
696
791
|
if (found.error) return sendJson(res, found.status || 400, { ok: false, error: found.error });
|
|
697
792
|
sendJson(res, 200, {
|
|
698
793
|
ok: true,
|
package/lib/mobile/feedback.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// 用途:插件反馈统一提交、读取与轮询等回复口;工具和本机面板按线程查看官方回复、继续跟进。
|
|
2
2
|
// 自检 / 探针文案不进真人反馈队列:submit 只收真实问题的现象描述。
|
|
3
|
+
// 2026-11-26:工具注册改为显式取 tools 服务,没声明注入的宿主也挂得上;真缺服务才跳过。
|
|
4
|
+
// 注册走调用方的注入作用域(`ctx.tools`),记在那一代 fiber 名下,热重载换代时随旧代卸掉。
|
|
3
5
|
'use strict';
|
|
4
6
|
|
|
5
7
|
/**
|
|
@@ -288,7 +290,19 @@ function registerFeedbackTool(ctx, deps) {
|
|
|
288
290
|
throw new Error('反馈工具缺少凭据库或实例号取值器');
|
|
289
291
|
}
|
|
290
292
|
const channels = feedbackChannels();
|
|
291
|
-
|
|
293
|
+
// 2026-11-26:显式取服务,不靠 inject。缺一个注入就整行 pending 的代价太大,
|
|
294
|
+
// 而 ctx.get('tools') 在有这个服务时(哪怕当前 fiber 没注入)照样取得到了。
|
|
295
|
+
// 但优先用 `ctx.tools`:它把注册记在当前 fiber 名下,换代时随旧代一起卸;直接拿服务对象
|
|
296
|
+
// 注册只记在服务上,热重载时旧代那份还在,会判「已经注册过」把整代装载打回去。
|
|
297
|
+
let tools = null;
|
|
298
|
+
try {
|
|
299
|
+
tools = ctx.tools ?? null;
|
|
300
|
+
} catch (error) {
|
|
301
|
+
if (!String(error?.message || error).includes('without inject')) throw error;
|
|
302
|
+
}
|
|
303
|
+
if (!tools && typeof ctx.get === 'function') tools = ctx.get('tools') || null;
|
|
304
|
+
if (!tools || typeof tools.register !== 'function') return false;
|
|
305
|
+
return tools.register(defineTool({
|
|
292
306
|
name: 'dsh_feedback',
|
|
293
307
|
description: 'Report a real problem with this mobile plugin or the AI-HUB app. '
|
|
294
308
|
+ 'Do not use `submit` for connectivity tests or automated probes: those are not real problems and must not enter the human feedback queue; use `channels` to inspect the route instead. '
|
|
@@ -394,14 +408,9 @@ function renderSummary(value) {
|
|
|
394
408
|
}
|
|
395
409
|
}
|
|
396
410
|
|
|
397
|
-
/** 装配层入口:挂 `dsh_feedback`
|
|
411
|
+
/** 装配层入口:挂 `dsh_feedback` 工具;宿主没有 tools 服务时只少这个工具。 */
|
|
398
412
|
function installFeedback(ctx, deps) {
|
|
399
|
-
|
|
400
|
-
registerFeedbackTool(ctx, deps);
|
|
401
|
-
} catch (error) {
|
|
402
|
-
const message = error && error.message ? error.message : String(error);
|
|
403
|
-
if (!message.includes('without inject')) throw error;
|
|
404
|
-
}
|
|
413
|
+
return registerFeedbackTool(ctx, deps);
|
|
405
414
|
}
|
|
406
415
|
|
|
407
416
|
module.exports = {
|
package/lib/mobile/monitor.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// 任务通知监控条目携带精确工作区归属,供本地与 APNs 偏好按层级解析。
|
|
1
2
|
'use strict';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -29,6 +30,7 @@ const { pendingFailedTurns } = require('./recent-failures.js');
|
|
|
29
30
|
const { sessionPreviewFor } = require('./session-preview.js');
|
|
30
31
|
const { archivedSessionIdsForMonitor, pendingInteractionOf, pendingCardOf } = require('./session-flags.js');
|
|
31
32
|
const { withActiveParents } = require('./session-active.js');
|
|
33
|
+
const { workspaceIdOfRows, workspaceRows } = require('./workspace-id.js');
|
|
32
34
|
|
|
33
35
|
/**
|
|
34
36
|
* 一条会话在监控视图里的那几格。
|
|
@@ -42,7 +44,7 @@ const { withActiveParents } = require('./session-active.js');
|
|
|
42
44
|
* 一字不差),只在那几条待处理的条目上带 —— 手机回前台时先问原生要它,就不必等流重新
|
|
43
45
|
* 接上才有卡(见 `session-flags.js` 的 pendingCardOf)。拿不到都不出字段。
|
|
44
46
|
*/
|
|
45
|
-
function monitorItem(summary, state, fact) {
|
|
47
|
+
function monitorItem(summary, state, fact, workspaceId = '') {
|
|
46
48
|
const running = summary.running === true;
|
|
47
49
|
// 完成/失败优先用**上一轮事实**(`session-last-turn`),不再等 `state.completed`。
|
|
48
50
|
//
|
|
@@ -59,6 +61,7 @@ function monitorItem(summary, state, fact) {
|
|
|
59
61
|
: (state ? state.completed === true : false);
|
|
60
62
|
const item = {
|
|
61
63
|
sessionId: summary.sessionId,
|
|
64
|
+
workspaceId: workspaceId || '',
|
|
62
65
|
title: listTitle(summary),
|
|
63
66
|
running,
|
|
64
67
|
completed,
|
|
@@ -171,10 +174,12 @@ async function buildMonitorState(ctx, deviceKey, extraItems = null, scopeSession
|
|
|
171
174
|
}));
|
|
172
175
|
}
|
|
173
176
|
|
|
177
|
+
const workspaceRowsSnapshot = await workspaceRows(ctx);
|
|
174
178
|
const items = live.map((summary) => monitorItem(
|
|
175
179
|
summary,
|
|
176
180
|
states.get(summary.sessionId),
|
|
177
181
|
lastTurnOf(ctx, summary.sessionId),
|
|
182
|
+
workspaceIdOfRows(workspaceRowsSnapshot, summary),
|
|
178
183
|
));
|
|
179
184
|
// 可能要提醒的那几条补一句「这一轮跑出了什么」:只在完成 / 失败 / 待回话的条目上取,
|
|
180
185
|
// 走 sessionPreviewFor 的缓存;常态(全在跑 / 全闲且已读)一条 history 都不读。
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// APNs 事件携带精确工作区归属,总控据每台手机的偏好逐设备过滤。
|
|
1
2
|
'use strict';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -42,6 +43,18 @@ const INTERACTION_TTL_MS = 30_000;
|
|
|
42
43
|
*/
|
|
43
44
|
function createPushNotifier(deps) {
|
|
44
45
|
const controlTarget = typeof deps.controlTarget === 'function' ? deps.controlTarget : () => null;
|
|
46
|
+
const resolveWorkspaceId = typeof deps.workspaceIdOf === 'function'
|
|
47
|
+
? deps.workspaceIdOf
|
|
48
|
+
: async () => '';
|
|
49
|
+
|
|
50
|
+
async function workspaceIdOf(sessionId) {
|
|
51
|
+
try {
|
|
52
|
+
const value = await resolveWorkspaceId({ sessionId });
|
|
53
|
+
return typeof value === 'string' ? value.trim() : '';
|
|
54
|
+
} catch {
|
|
55
|
+
return '';
|
|
56
|
+
}
|
|
57
|
+
}
|
|
45
58
|
|
|
46
59
|
/** 已经发出去的帧:key → { at, approvalId? }。key 是 `${sessionId}:${rpcId}`(卡)或
|
|
47
60
|
* `${sessionId}:${turn}:${status}`(轮次)。同一次收尾会被事件流与列表折叠两条路各观察到
|
|
@@ -129,7 +142,7 @@ function createPushNotifier(deps) {
|
|
|
129
142
|
* 报告一轮收尾。`fact` 是 session-last-turn 的 `lastTurnOf` 形状
|
|
130
143
|
* ({ turn, endedAt, status, ... }),只有 completed / failed 两种值得推。
|
|
131
144
|
*/
|
|
132
|
-
function notifyTurnEnded(sessionId, fact, title) {
|
|
145
|
+
async function notifyTurnEnded(sessionId, fact, title) {
|
|
133
146
|
if (!sessionId || !fact || typeof fact.turn !== 'number') return;
|
|
134
147
|
if (fact.status !== 'completed' && fact.status !== 'failed') return;
|
|
135
148
|
const fingerprint = `${sessionId}:${fact.turn}:${fact.status}`;
|
|
@@ -138,12 +151,14 @@ function createPushNotifier(deps) {
|
|
|
138
151
|
// (没有通知服务扩展),而这个列表在电脑上、读它的手机可能被设成十门语言里的任一门。
|
|
139
152
|
// 所以标题是会话名(用户自己起的),正文只给「成没成」一个符号。
|
|
140
153
|
const body = fact.status === 'failed' ? '✗' : '✓';
|
|
141
|
-
|
|
142
|
-
//
|
|
154
|
+
const workspaceId = await workspaceIdOf(sessionId);
|
|
155
|
+
// 推给这台实例登记过的全部手机:总控按每台手机保存的偏好逐设备过滤。
|
|
143
156
|
void pushFrame(fingerprint, {
|
|
144
157
|
title: title || String(sessionId).slice(0, 8),
|
|
145
158
|
body,
|
|
146
159
|
sessionId,
|
|
160
|
+
workspaceId,
|
|
161
|
+
kind: fact.status === 'failed' ? 'failed' : 'completed',
|
|
147
162
|
}, { kind: fact.status === 'failed' ? 'failed' : 'completed', sessionId });
|
|
148
163
|
}
|
|
149
164
|
|
|
@@ -182,7 +197,7 @@ function createPushNotifier(deps) {
|
|
|
182
197
|
* 前两样是审批卡上的展示信息(事实行 / 那一行高亮),通知栏里得原样带上,否则手机在后台
|
|
183
198
|
* 看到的还是没长事实行的那张卡。`title` 是会话名。
|
|
184
199
|
*/
|
|
185
|
-
function notifyInteraction(sessionId, card, hints = {}) {
|
|
200
|
+
async function notifyInteraction(sessionId, card, hints = {}) {
|
|
186
201
|
if (!sessionId || !card || typeof card !== 'object') return;
|
|
187
202
|
// 第三参早先就是「标题」一个字符串;现在扩成带提示的对象,字符串按标题认。
|
|
188
203
|
const hint = typeof hints === 'string'
|
|
@@ -259,10 +274,13 @@ function createPushNotifier(deps) {
|
|
|
259
274
|
const category = kind === 'approval'
|
|
260
275
|
? 'dsh.approval'
|
|
261
276
|
: (answerable ? 'dsh.question' : 'dsh.pending');
|
|
277
|
+
const workspaceId = await workspaceIdOf(sessionId);
|
|
262
278
|
return pushFrame(fingerprint, {
|
|
263
279
|
title: hint.title || String(sessionId).slice(0, 8),
|
|
264
280
|
body: summary,
|
|
265
281
|
sessionId,
|
|
282
|
+
workspaceId,
|
|
283
|
+
kind: 'pending',
|
|
266
284
|
category,
|
|
267
285
|
interaction,
|
|
268
286
|
}, { kind, sessionId, approvalId }, upgrade);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// 2026-11-27:「立即同步」的上报半段只认「自动上报网络地址」开关,中转 / 远程控制关着也能催报一次(与 control.js 解耦口径一致)。
|
|
1
2
|
// 手机主动重连在回执发出后调用独立隧道动作,普通配置同步保持幂等。
|
|
2
3
|
// 既有中转配置复用有界健康判据与出网诊断,保留本实例吊销回执收尾。
|
|
3
4
|
// 2026-11-21:「立即同步」只上报不等查询 —— 查询归手机,宿主没有比自己更新的上游可查。
|
|
@@ -654,8 +655,8 @@ function createRelayControlHandlers(deps) {
|
|
|
654
655
|
*/
|
|
655
656
|
async function handleControlSync(_ctx, _req, res) {
|
|
656
657
|
if (typeof syncControl !== 'function' || typeof getControl !== 'function') return unavailable(res);
|
|
657
|
-
//
|
|
658
|
-
const reporting = Boolean(state && state.
|
|
658
|
+
// 用户关了自动上报:连都不会连,催也催不动,等也等不出回执,当场给结论。中转关不关不影响这一条。
|
|
659
|
+
const reporting = Boolean(state && state.controlReportEnabled !== false);
|
|
659
660
|
if (reporting) {
|
|
660
661
|
try { syncControl(); } catch { /* 拨号失败会在下面的快照里如实反映 */ }
|
|
661
662
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// 任务提醒按精确证据解析会话的工作区归属:显式 workspaceId、唯一会话归属、唯一路径。
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
function normalizePath(value) {
|
|
5
|
+
return typeof value === 'string' ? value.trim().replace(/[\\/]+$/, '') : '';
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function workspaceIdOfRows(rows, summary) {
|
|
9
|
+
if (summary && typeof summary.workspaceId === 'string' && summary.workspaceId.trim()) return summary.workspaceId.trim();
|
|
10
|
+
const sessionId = summary && typeof summary.sessionId === 'string' ? summary.sessionId : '';
|
|
11
|
+
const cwd = normalizePath(summary && summary.cwd);
|
|
12
|
+
const items = Array.isArray(rows) ? rows : [];
|
|
13
|
+
const bySession = items.filter((row) => row && Array.isArray(row.sessionIds) && sessionId && row.sessionIds.includes(sessionId));
|
|
14
|
+
if (bySession.length === 1) return typeof bySession[0].workspaceId === 'string' ? bySession[0].workspaceId.trim() : '';
|
|
15
|
+
if (bySession.length > 1) return '';
|
|
16
|
+
if (!cwd) return '';
|
|
17
|
+
const byPath = items.filter((row) => normalizePath(row && (row.path || row.cwd)) === cwd);
|
|
18
|
+
if (byPath.length === 1) return typeof byPath[0].workspaceId === 'string' ? byPath[0].workspaceId.trim() : '';
|
|
19
|
+
return '';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async function workspaceRows(ctx, signal) {
|
|
23
|
+
const registry = ctx && ctx.get && ctx.get('workspaceRegistry');
|
|
24
|
+
if (registry && typeof registry.list === 'function') {
|
|
25
|
+
try { return registry.list().map((row) => ({ workspaceId: row.id, path: row.path, sessionIds: [...(row.sessionIds || [])] })); } catch { return []; }
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
const { workspaceListViaFollow } = require('./host-bridge/shims.js');
|
|
29
|
+
const result = await workspaceListViaFollow(ctx, signal);
|
|
30
|
+
const value = result && result.value;
|
|
31
|
+
return value && Array.isArray(value.items) ? value.items : [];
|
|
32
|
+
} catch { return []; }
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async function workspaceIdOf(ctx, summary, signal) {
|
|
36
|
+
if (summary && typeof summary.workspaceId === 'string' && summary.workspaceId.trim()) return summary.workspaceId.trim();
|
|
37
|
+
return workspaceIdOfRows(await workspaceRows(ctx, signal), summary);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
module.exports = { normalizePath, workspaceIdOfRows, workspaceRows, workspaceIdOf };
|