dsh-team-control 0.3.1 → 0.3.2
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 +50 -21
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -264,11 +264,41 @@ function canDeliverTo(ctx, sender) {
|
|
|
264
264
|
return !!subs && typeof subs.sendMessage === 'function';
|
|
265
265
|
}
|
|
266
266
|
|
|
267
|
+
/**
|
|
268
|
+
* 这个失败是否表示「工具在当前 harness 下不可直接调用」(run_code / PTC 模式)。
|
|
269
|
+
*
|
|
270
|
+
* 不能只看 `tools.get()`:它查的是可见性,而 PTC 只改可执行性。顶层批次会被执行器以
|
|
271
|
+
* `ToolNotFoundError`(`info.code === 'UNKNOWN_TOOL'`,文案含 `only run_code is callable directly`)
|
|
272
|
+
* 拒绝,并且以 `{ isError: true }` 返回、不抛异常。判定依据放在错误本身,命中才回退服务通道。
|
|
273
|
+
*/
|
|
274
|
+
function uncallableToolFailure(error) {
|
|
275
|
+
const detail = (error && error.error) || error || {};
|
|
276
|
+
const info = detail.info || {};
|
|
277
|
+
const code = info.code || detail.code || error?.code;
|
|
278
|
+
if (code === 'UNKNOWN_TOOL') return true;
|
|
279
|
+
const message = typeof detail === 'string' ? detail : String(detail.message || error?.message || '');
|
|
280
|
+
return /unknown tool|callable directly/i.test(message);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/** 服务通道:`subagents.sendMessage`(两代宿主都保留),也用于原生工具不可直接调用时的回退。 */
|
|
284
|
+
async function sendByService(ctx, sender, targetSessionId, text, opts = {}) {
|
|
285
|
+
const subs = subagentsOf(ctx);
|
|
286
|
+
if (!subs || typeof subs.sendMessage !== 'function') throw new Error('subagents 服务不可用,无法投递消息');
|
|
287
|
+
const messageId = await subs.sendMessage(
|
|
288
|
+
sender,
|
|
289
|
+
String(targetSessionId),
|
|
290
|
+
[{ type: 'text', text: String(text) }],
|
|
291
|
+
opts.signal ? { signal: opts.signal } : {},
|
|
292
|
+
);
|
|
293
|
+
return { via: 'service', messageId: messageId != null ? String(messageId) : undefined };
|
|
294
|
+
}
|
|
295
|
+
|
|
267
296
|
/**
|
|
268
297
|
* 把一条文本消息投进某个 agent 会话(成员与 Lead 一视同仁)。
|
|
269
298
|
*
|
|
270
299
|
* - 高版本 DSH 提供原生 `send_message` 工具:走工具层调用,接收方由宿主 `resolveName` 解析
|
|
271
300
|
* (传 sessionId 时它会被原样当作会话 id),消息来源标记、空闲唤醒、后续语义变化都交给宿主;
|
|
301
|
+
* 若工具可见但不可直接调用(PTC / run_code preset),回退服务通道;
|
|
272
302
|
* - 低版本没有该工具:保持原来的 `subagents.sendMessage(sender, sessionId, content, { signal })`。
|
|
273
303
|
*
|
|
274
304
|
* `sender` 必须是精确的活跃 Agent(两代实现都这么要求),调用方负责从 `agents` 注册表或缓存的
|
|
@@ -278,35 +308,34 @@ async function sendAgentMessage(ctx, sender, targetSessionId, text, opts = {}) {
|
|
|
278
308
|
const native = nativeSendTools(ctx, sender);
|
|
279
309
|
if (native) {
|
|
280
310
|
const callId = `team-send-${randomUUID()}`;
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
311
|
+
let result;
|
|
312
|
+
try {
|
|
313
|
+
const batch = await native.tools.execute({
|
|
314
|
+
calls: [{
|
|
315
|
+
type: 'tool-call',
|
|
316
|
+
id: callId,
|
|
317
|
+
name: native.name,
|
|
318
|
+
arguments: JSON.stringify({ agent: String(targetSessionId), message: String(text) }),
|
|
319
|
+
}],
|
|
320
|
+
signal: opts.signal || AbortSignal.timeout(60000),
|
|
321
|
+
agent: sender,
|
|
322
|
+
});
|
|
323
|
+
const results = Array.isArray(batch?.results) ? batch.results : [];
|
|
324
|
+
result = (results.find((r) => r && r.callId === callId) || results[0])?.result;
|
|
325
|
+
} catch (err) {
|
|
326
|
+
if (!uncallableToolFailure(err)) throw err;
|
|
327
|
+
return sendByService(ctx, sender, targetSessionId, text, opts);
|
|
328
|
+
}
|
|
293
329
|
if (!result) throw new Error('send_message 工具没有返回执行结果');
|
|
294
330
|
if (result.isError) {
|
|
331
|
+
if (uncallableToolFailure(result)) return sendByService(ctx, sender, targetSessionId, text, opts);
|
|
295
332
|
const failure = result.error || {};
|
|
296
333
|
throw new Error(`send_message 工具投递失败:${failure.message || failure.code || '未知错误'}`);
|
|
297
334
|
}
|
|
298
335
|
const messageId = result.value && result.value.messageId;
|
|
299
336
|
return { via: 'tool', messageId: messageId != null ? String(messageId) : undefined };
|
|
300
337
|
}
|
|
301
|
-
|
|
302
|
-
if (!subs || typeof subs.sendMessage !== 'function') throw new Error('subagents 服务不可用,无法投递消息');
|
|
303
|
-
const messageId = await subs.sendMessage(
|
|
304
|
-
sender,
|
|
305
|
-
String(targetSessionId),
|
|
306
|
-
[{ type: 'text', text: String(text) }],
|
|
307
|
-
opts.signal ? { signal: opts.signal } : {},
|
|
308
|
-
);
|
|
309
|
-
return { via: 'service', messageId: messageId != null ? String(messageId) : undefined };
|
|
338
|
+
return sendByService(ctx, sender, targetSessionId, text, opts);
|
|
310
339
|
}
|
|
311
340
|
|
|
312
341
|
/** `sessions` / `workspaceChanges`:读成员自己会话里的交付文件(都是可选依赖)。 */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-team-control",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Expose the local dsh-team sidecar as model-facing tools (dsh_team_create / dsh_team_spawn / dsh_team_status / dsh_team_task / dsh_team_send / dsh_team_report_task / dsh_team_dispatch / dsh_team_control / dsh_team_approve / dsh_team_report), spawn real DSH sub-agent members with per-member permission presets, forward member approvals to the Lead, and manage the sidecar lifecycle.",
|
|
6
6
|
"icon": "./icon.svg",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
},
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"dsh-team-control-cli": "^0.3.
|
|
24
|
+
"dsh-team-control-cli": "^0.3.2"
|
|
25
25
|
},
|
|
26
26
|
"exports": {
|
|
27
27
|
".": "./index.js",
|