multiclaws 0.3.4 → 0.3.5
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/dist/index.js
CHANGED
|
@@ -89,7 +89,7 @@ function createTools(getService) {
|
|
|
89
89
|
};
|
|
90
90
|
const multiclawsDelegate = {
|
|
91
91
|
name: "multiclaws_delegate",
|
|
92
|
-
description: "Delegate a task to a remote A2A agent.",
|
|
92
|
+
description: "Delegate a task to a remote A2A agent. Returns immediately with a taskId (async). The result will be pushed as a message when the task completes. Use multiclaws_task_status to poll progress.",
|
|
93
93
|
parameters: {
|
|
94
94
|
type: "object",
|
|
95
95
|
additionalProperties: false,
|
|
@@ -51,6 +51,8 @@ export declare class MulticlawsService extends EventEmitter {
|
|
|
51
51
|
agentUrl: string;
|
|
52
52
|
task: string;
|
|
53
53
|
}): Promise<DelegateTaskResult>;
|
|
54
|
+
private runDelegatedTask;
|
|
55
|
+
private notifyTaskCompletion;
|
|
54
56
|
getTaskStatus(taskId: string): import("../task/tracker").TaskRecord | null;
|
|
55
57
|
getProfile(): Promise<AgentProfile>;
|
|
56
58
|
setProfile(patch: {
|
|
@@ -205,22 +205,63 @@ class MulticlawsService extends node_events_1.EventEmitter {
|
|
|
205
205
|
task: params.task,
|
|
206
206
|
});
|
|
207
207
|
this.taskTracker.update(track.taskId, { status: "running" });
|
|
208
|
+
// Fire-and-forget: run in background, notify user when done
|
|
209
|
+
void this.runDelegatedTask({
|
|
210
|
+
taskId: track.taskId,
|
|
211
|
+
agentRecord,
|
|
212
|
+
task: params.task,
|
|
213
|
+
});
|
|
214
|
+
return { taskId: track.taskId, status: "running" };
|
|
215
|
+
}
|
|
216
|
+
async runDelegatedTask(params) {
|
|
208
217
|
try {
|
|
209
|
-
const client = await this.createA2AClient(agentRecord);
|
|
218
|
+
const client = await this.createA2AClient(params.agentRecord);
|
|
210
219
|
const result = await client.sendMessage({
|
|
211
220
|
message: {
|
|
212
221
|
kind: "message",
|
|
213
222
|
role: "user",
|
|
214
223
|
parts: [{ kind: "text", text: params.task }],
|
|
215
|
-
messageId:
|
|
224
|
+
messageId: params.taskId,
|
|
216
225
|
},
|
|
217
226
|
});
|
|
218
|
-
|
|
227
|
+
const taskResult = this.processTaskResult(params.taskId, result);
|
|
228
|
+
await this.notifyTaskCompletion(taskResult);
|
|
219
229
|
}
|
|
220
230
|
catch (err) {
|
|
221
231
|
const errorMsg = err instanceof Error ? err.message : String(err);
|
|
222
|
-
this.taskTracker.update(
|
|
223
|
-
|
|
232
|
+
this.taskTracker.update(params.taskId, { status: "failed", error: errorMsg });
|
|
233
|
+
await this.notifyTaskCompletion({ taskId: params.taskId, status: "failed", error: errorMsg });
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
async notifyTaskCompletion(result) {
|
|
237
|
+
if (!this.options.gatewayConfig)
|
|
238
|
+
return;
|
|
239
|
+
let message;
|
|
240
|
+
if (result.status === "completed") {
|
|
241
|
+
const resultText = typeof result.output === "string" ? result.output : JSON.stringify(result.output ?? "");
|
|
242
|
+
message = [
|
|
243
|
+
`✅ **任务完成** (taskId: \`${result.taskId}\`)`,
|
|
244
|
+
"",
|
|
245
|
+
resultText,
|
|
246
|
+
].join("\n");
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
message = [
|
|
250
|
+
`❌ **任务失败** (taskId: \`${result.taskId}\`)`,
|
|
251
|
+
"",
|
|
252
|
+
result.error ?? "unknown error",
|
|
253
|
+
].join("\n");
|
|
254
|
+
}
|
|
255
|
+
try {
|
|
256
|
+
await (0, gateway_client_1.invokeGatewayTool)({
|
|
257
|
+
gateway: this.options.gatewayConfig,
|
|
258
|
+
tool: "message",
|
|
259
|
+
args: { action: "send", message },
|
|
260
|
+
timeoutMs: 5_000,
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
catch {
|
|
264
|
+
this.log("warn", `[multiclaws] failed to notify task completion: ${result.taskId}`);
|
|
224
265
|
}
|
|
225
266
|
}
|
|
226
267
|
getTaskStatus(taskId) {
|