dsh-team-control 0.1.5 → 0.1.6
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/index.js +119 -27
- package/locale/zh.json +1 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -153,7 +153,9 @@ async function request(s, pathname, { method = 'GET', body, raw = false } = {})
|
|
|
153
153
|
if (!res.ok) {
|
|
154
154
|
let detail = text.slice(0, 400);
|
|
155
155
|
try { const j = JSON.parse(text); detail = `${j.error?.code || ''} ${j.error?.message || ''}`.trim() || detail; } catch { /* keep text */ }
|
|
156
|
-
|
|
156
|
+
const err = new Error(`dsh-team API ${res.status} on ${method} ${pathname}: ${detail}`);
|
|
157
|
+
err.status = res.status; // 调用方据此区分「团队不存在(404)」与服务/网络侧故障
|
|
158
|
+
throw err;
|
|
157
159
|
}
|
|
158
160
|
if (raw) return text;
|
|
159
161
|
try { return JSON.parse(text); } catch { return text; }
|
|
@@ -529,6 +531,56 @@ const llmOf = (ctx) => { try { return ctx.get('llm'); } catch { return undefined
|
|
|
529
531
|
|
|
530
532
|
let llmSyncInFlight = null;
|
|
531
533
|
|
|
534
|
+
/**
|
|
535
|
+
* 一条 route 的思考强度元数据(适配器声明):数组 = 已知(可能为空),undefined = 取不到。
|
|
536
|
+
* resolveModel 对 pi-ai 是内存目录查询;对其他适配器可能触网,所以并发受限 + 超时兜底,
|
|
537
|
+
* 取不到就不上报(sidecar 保留上一次的值),不让 effort 能力拖垮整个目录同步。
|
|
538
|
+
*/
|
|
539
|
+
async function effortsOfRoute(llm, provider, model) {
|
|
540
|
+
// llm 服务暴露的是 resolveModelInfo(带校验的精确模型元数据);resolveModel 是适配器基类方法,
|
|
541
|
+
// 部分环境/旧版本才直接挂在服务上。两个都试,优先服务公开面。
|
|
542
|
+
const resolve = typeof llm.resolveModelInfo === 'function'
|
|
543
|
+
? (p, m, signal) => llm.resolveModelInfo(p, m, signal)
|
|
544
|
+
: typeof llm.resolveModel === 'function'
|
|
545
|
+
? (p, m, signal) => llm.resolveModel(p, m, signal)
|
|
546
|
+
: null;
|
|
547
|
+
if (!resolve) return undefined;
|
|
548
|
+
const call = Promise.resolve()
|
|
549
|
+
.then(() => resolve(provider, model, AbortSignal.timeout(3000)))
|
|
550
|
+
.catch(() => undefined);
|
|
551
|
+
const info = await Promise.race([
|
|
552
|
+
call,
|
|
553
|
+
new Promise((resolve) => setTimeout(() => resolve(undefined), 3000)),
|
|
554
|
+
]);
|
|
555
|
+
const reasoning = info && info.reasoning;
|
|
556
|
+
if (!reasoning || !Array.isArray(reasoning.efforts)) return undefined;
|
|
557
|
+
// 「off」等于关思考,不是可派发的强度:既不进面板胶囊,也不进 team_models,
|
|
558
|
+
// 否则用户能「允许派发 off」而实际语义相反。
|
|
559
|
+
const efforts = reasoning.efforts
|
|
560
|
+
.filter((e) => e && e.id && String(e.id) !== 'off')
|
|
561
|
+
.map((e) => ({ id: String(e.id), name: String(e.name || e.id), ...(e.description ? { description: String(e.description) } : {}) }));
|
|
562
|
+
if (!efforts.length) return undefined;
|
|
563
|
+
const defaultEffort = reasoning.defaultEffort ? String(reasoning.defaultEffort) : null;
|
|
564
|
+
return {
|
|
565
|
+
efforts,
|
|
566
|
+
defaultEffort: defaultEffort && defaultEffort !== 'off' && efforts.some((e) => e.id === defaultEffort) ? defaultEffort : null,
|
|
567
|
+
};
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
/** 小并发 map:effort 解析最多同时 4 条,避免一次同步打爆适配器。 */
|
|
571
|
+
async function mapLimit(items, limit, fn) {
|
|
572
|
+
const out = new Array(items.length);
|
|
573
|
+
let next = 0;
|
|
574
|
+
const workers = Array.from({ length: Math.min(limit, items.length) }, async () => {
|
|
575
|
+
while (next < items.length) {
|
|
576
|
+
const i = next++;
|
|
577
|
+
out[i] = await fn(items[i], i);
|
|
578
|
+
}
|
|
579
|
+
});
|
|
580
|
+
await Promise.all(workers);
|
|
581
|
+
return out;
|
|
582
|
+
}
|
|
583
|
+
|
|
532
584
|
/** 同步一次模型目录(并发去重;由插件启动泵与 adapters-updated 事件驱动,不再由工具触发)。 */
|
|
533
585
|
async function syncLlmCatalog(s, ctx) {
|
|
534
586
|
const llm = llmOf(ctx);
|
|
@@ -548,13 +600,17 @@ async function syncLlmCatalog(s, ctx) {
|
|
|
548
600
|
let partial = false;
|
|
549
601
|
for (const p of providers) {
|
|
550
602
|
try {
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
603
|
+
const listed = await llm.listModels(p.id);
|
|
604
|
+
const withEfforts = await mapLimit(listed, 4, async (m) => {
|
|
605
|
+
if (!m || !m.id) return null;
|
|
606
|
+
const meta = await effortsOfRoute(llm, p.id, String(m.id));
|
|
607
|
+
return {
|
|
554
608
|
provider: p.id, model: String(m.id), name: m.name || String(m.id),
|
|
555
609
|
description: m.description || null, modalities: m.inputModalities || null,
|
|
556
|
-
|
|
557
|
-
|
|
610
|
+
...(meta ? { efforts: meta.efforts, ...(meta.defaultEffort ? { defaultEffort: meta.defaultEffort } : {}) } : {}),
|
|
611
|
+
};
|
|
612
|
+
});
|
|
613
|
+
for (const row of withEfforts) if (row) models.push(row);
|
|
558
614
|
} catch (e) {
|
|
559
615
|
// 单个提供商读取失败:标记 partial,让 sidecar 保留该 provider 已有的勾选
|
|
560
616
|
p.error = clip(String(e?.message || e), 300);
|
|
@@ -581,8 +637,8 @@ function leadRouteOf(caller) {
|
|
|
581
637
|
return { provider: o.provider ?? null, model: o.model ?? null, reasoningEffort: o.reasoningEffort ?? null };
|
|
582
638
|
}
|
|
583
639
|
|
|
584
|
-
/** 指定 route
|
|
585
|
-
async function assertRouteEnabled(s, ctx, provider, model) {
|
|
640
|
+
/** 指定 route 必须在用户启用的子集里,且 effort 在该 route 允许的集合里;目录尚未同步(为空)时不限制。 */
|
|
641
|
+
async function assertRouteEnabled(s, ctx, provider, model, effort = null) {
|
|
586
642
|
if (!provider && !model) return;
|
|
587
643
|
let cat;
|
|
588
644
|
try { cat = await request(s, '/api/llm/catalog'); } catch { return; }
|
|
@@ -594,9 +650,22 @@ async function assertRouteEnabled(s, ctx, provider, model) {
|
|
|
594
650
|
if (!known.length) return;
|
|
595
651
|
const enabled = all.filter((m) => m.enabled);
|
|
596
652
|
if (!enabled.length) throw new Error('所有模型路由都已停用:请先在面板「模型路由」页启用,或调用 team_models 查看。');
|
|
597
|
-
if (known.some((m) => m.enabled))
|
|
598
|
-
|
|
599
|
-
|
|
653
|
+
if (!known.some((m) => m.enabled)) {
|
|
654
|
+
const sample = enabled.slice(0, 8).map((m) => `${m.provider}/${m.model}`).join(', ');
|
|
655
|
+
throw new Error(`模型路由未启用:${[provider, model].filter(Boolean).join('/')}。可用(前 8 条):${sample}。完整列表见 team_models,或在面板「模型路由」页启用。`);
|
|
656
|
+
}
|
|
657
|
+
// effort 闸门:只有该 route 声明了 efforts 才校验;allowedEfforts=null 表示全部允许。
|
|
658
|
+
if (!effort) return;
|
|
659
|
+
const declared = known.filter((m) => Array.isArray(m.efforts) && m.efforts.length > 0);
|
|
660
|
+
if (!declared.length) return;
|
|
661
|
+
const ids = [...new Set(declared.flatMap((m) => m.efforts.map((e) => e.id)))];
|
|
662
|
+
const allowed = [...new Set(declared.flatMap((m) => (Array.isArray(m.allowedEfforts) ? m.allowedEfforts : ids)))];
|
|
663
|
+
if (!ids.includes(String(effort))) {
|
|
664
|
+
throw new Error(`模型路由 ${[provider, model].filter(Boolean).join('/')} 不支持 reasoningEffort「${effort}」:可用 ${ids.join(', ')}。`);
|
|
665
|
+
}
|
|
666
|
+
if (!allowed.includes(String(effort))) {
|
|
667
|
+
throw new Error(`模型路由 ${[provider, model].filter(Boolean).join('/')} 已禁止 reasoningEffort「${effort}」:面板「模型路由」页允许的为 ${allowed.join(', ') || '(无,省略该参数使用模型默认)'}。`);
|
|
668
|
+
}
|
|
600
669
|
}
|
|
601
670
|
|
|
602
671
|
function rememberMember(sessionId, teamId, memberId, cwd) {
|
|
@@ -609,13 +678,26 @@ function rememberMember(sessionId, teamId, memberId, cwd) {
|
|
|
609
678
|
}
|
|
610
679
|
|
|
611
680
|
async function runtimeOfTeam(s, teamId) {
|
|
612
|
-
|
|
681
|
+
// 模型偶尔会漏掉必填的 teamId。旧实现会把 undefined 拼进 URL(/api/teams/undefined),
|
|
682
|
+
// 再被下面的 catch 静默回退成 worker,于是错误被拖到 POST /api/teams/undefined/members
|
|
683
|
+
// 才爆成「team not found」,看不出真正原因是参数缺失。这里先显式挡住。
|
|
684
|
+
if (teamId == null || String(teamId).trim() === '' || String(teamId) === 'undefined' || String(teamId) === 'null') {
|
|
685
|
+
throw new Error('缺少 teamId:请把 team_create 返回的团队 id(形如 team_xxx)作为 teamId 参数传入后重试。');
|
|
686
|
+
}
|
|
687
|
+
const key = String(teamId);
|
|
688
|
+
const cached = runtimeByTeam.get(key);
|
|
613
689
|
if (cached) return cached;
|
|
614
690
|
try {
|
|
615
|
-
const team = await request(s, `/api/teams/${encodeURIComponent(
|
|
616
|
-
runtimeByTeam.set(
|
|
691
|
+
const team = await request(s, `/api/teams/${encodeURIComponent(key)}`);
|
|
692
|
+
runtimeByTeam.set(key, team.runtime || 'worker');
|
|
617
693
|
return team.runtime || 'worker';
|
|
618
|
-
} catch {
|
|
694
|
+
} catch (err) {
|
|
695
|
+
// 404 = 团队不存在(id 打错/已删除):明确报错,不能伪装成 worker 团队继续往下走。
|
|
696
|
+
if (err && err.status === 404) {
|
|
697
|
+
throw new Error(`团队不存在或 teamId 无效: ${key}(teamId 来自 team_create 返回值,请核对后重试)`);
|
|
698
|
+
}
|
|
699
|
+
return 'worker'; // sidecar 不可达等其余情况保留原兜底,后续调用会报出真实错误
|
|
700
|
+
}
|
|
619
701
|
}
|
|
620
702
|
|
|
621
703
|
const clip = (text, max) => {
|
|
@@ -1033,8 +1115,8 @@ function buildTools(s, ctx) {
|
|
|
1033
1115
|
const route = { provider: args.agentProvider || leadRoute.provider, model: args.model || leadRoute.model };
|
|
1034
1116
|
const routeChanged = route.provider !== leadRoute.provider || route.model !== leadRoute.model;
|
|
1035
1117
|
route.reasoningEffort = args.reasoningEffort || (routeChanged ? null : leadRoute.reasoningEffort);
|
|
1036
|
-
// 继承 Lead 的 route
|
|
1037
|
-
await assertRouteEnabled(s, ctx, route.provider, route.model);
|
|
1118
|
+
// 继承 Lead 的 route 也要过启用闸门:停用项不该被成员继续使用;effort 同理。
|
|
1119
|
+
await assertRouteEnabled(s, ctx, route.provider, route.model, route.reasoningEffort);
|
|
1038
1120
|
const agentOptions = {};
|
|
1039
1121
|
if (args.agentProvider) agentOptions.provider = String(args.agentProvider);
|
|
1040
1122
|
if (args.model) agentOptions.model = String(args.model);
|
|
@@ -1069,6 +1151,8 @@ function buildTools(s, ctx) {
|
|
|
1069
1151
|
role: args.role || 'teammate',
|
|
1070
1152
|
model: args.model || spawned.member.model || null,
|
|
1071
1153
|
contextMode: context,
|
|
1154
|
+
// 实际生效的思考强度(含从 Lead 继承的值):面板成员卡片据此展示,之后不可变
|
|
1155
|
+
reasoningEffort: route.reasoningEffort || null,
|
|
1072
1156
|
},
|
|
1073
1157
|
});
|
|
1074
1158
|
rememberMember(sessionId, args.teamId, registered.member.id, team?.workspace);
|
|
@@ -1099,22 +1183,28 @@ function buildTools(s, ctx) {
|
|
|
1099
1183
|
additionalProperties: false,
|
|
1100
1184
|
properties: {},
|
|
1101
1185
|
},
|
|
1102
|
-
output: jsonOutput('{ asOf, total, models: [{ provider, model, name, description, note, modalities }], hint? }'),
|
|
1186
|
+
output: jsonOutput('{ asOf, total, models: [{ provider, model, name, description, note, modalities, efforts?, defaultEffort? }], hint? }'),
|
|
1103
1187
|
isConcurrencySafe: () => true,
|
|
1104
1188
|
async execute() {
|
|
1105
1189
|
let cat = null;
|
|
1106
1190
|
try { cat = await request(s, '/api/llm/catalog'); } catch { /* catalog unavailable */ }
|
|
1107
1191
|
const all = cat ? (cat.providers || []).flatMap((p) => p.models || []) : [];
|
|
1108
|
-
const models = all.filter((m) => m.enabled).map((m) =>
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1192
|
+
const models = all.filter((m) => m.enabled).map((m) => {
|
|
1193
|
+
// 只报用户允许的 effort;allowedEfforts=null 表示全部允许。未声明 efforts 的 route 不报该字段。
|
|
1194
|
+
const effortIds = Array.isArray(m.efforts) ? m.efforts.map((e) => e.id) : [];
|
|
1195
|
+
const allowed = Array.isArray(m.allowedEfforts) ? effortIds.filter((id) => m.allowedEfforts.includes(id)) : effortIds;
|
|
1196
|
+
return {
|
|
1197
|
+
provider: m.provider,
|
|
1198
|
+
model: m.model,
|
|
1199
|
+
name: m.name,
|
|
1200
|
+
...(m.description ? { description: m.description } : {}),
|
|
1201
|
+
...(m.note ? { note: m.note } : {}),
|
|
1202
|
+
...(m.modalities ? { modalities: m.modalities } : {}),
|
|
1203
|
+
...(effortIds.length ? { efforts: allowed, ...(m.defaultEffort ? { defaultEffort: m.defaultEffort } : {}) } : {}),
|
|
1204
|
+
};
|
|
1205
|
+
});
|
|
1116
1206
|
const hint = models.length
|
|
1117
|
-
? '在 team_spawn 里用 agentProvider + model;reasoningEffort
|
|
1207
|
+
? '在 team_spawn 里用 agentProvider + model;efforts 是该 route 允许派发的 reasoningEffort 列表(省略时只在 route 不变时继承 Lead 的 effort,被禁止的 effort 会被拒绝)。'
|
|
1118
1208
|
: '没有启用的模型路由:请让用户在面板「模型路由」页勾选需要的 provider/model。';
|
|
1119
1209
|
return {
|
|
1120
1210
|
asOf: cat?.asOf || new Date().toISOString(),
|
|
@@ -1152,6 +1242,8 @@ function buildTools(s, ctx) {
|
|
|
1152
1242
|
runtime: st.runtime || runtimeByTeam.get(args.teamId) || 'worker',
|
|
1153
1243
|
members: (st.members || []).map((m) => ({
|
|
1154
1244
|
name: m.name,
|
|
1245
|
+
model: m.model || null,
|
|
1246
|
+
reasoningEffort: m.reasoningEffort || null,
|
|
1155
1247
|
status: m.status,
|
|
1156
1248
|
step: m.step,
|
|
1157
1249
|
seq: m.seq,
|
package/locale/zh.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-team-control",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Expose the local dsh-team sidecar as model-facing tools (team_create / team_spawn / team_status / team_task / team_send / team_report_task / team_dispatch / team_scope / team_control / team_report), spawn real DSH sub-agent members for runtime=agent teams, and manage the sidecar lifecycle.",
|
|
6
6
|
"icon": "./icon.svg",
|