feat(subagent): add session-owned task messaging and cancellation (#5985)

let's go!
This commit is contained in:
chengyongru authored and GitHub committed 2026-10-05 05:16:33 +08:00
1 parent f75470e72f
commit 6ff96f2a8f
93 files changed
+5632 -1156

No files matched your search

@@ -28,6 +28,21 @@ describe("localized agent activity contracts", () => {
expect(translated.actionTargetRich).toContain("<target></target>");
await setAppLanguage(locale);
for (const [action, keys] of [
["create", ["delegatingTask", "delegatedTask", "delegateTaskFailed"]],
["check", ["checkingSubtask", "checkedSubtask", "checkSubtaskFailed"]],
["send", ["messagingSubtask", "queuedSubtaskMessage", "messageSubtaskFailed"]],
["cancel", ["stoppingSubtask", "requestedSubtaskStop", "stopSubtaskFailed"]],
] as const) {
for (const line of [`subagent("${action}")`, `subagent({"action":"${action}","task_id":"private-id","message":"private instructions"})`]) {
const subtask = parseGenericToolTrace(line)!;
for (const [index, status] of (["running", "done", "error"] as const).entries()) {
expect(describeGenericToolRun([{ trace: subtask, status }], i18n.t)).toMatchObject({
label: translated[keys[index]], detail: "", status,
});
}
}
}
const trace = parseGenericToolTrace('read_file({"path":"src/app.tsx"})')!;
const rg = parseGenericToolTrace('rg({"args":["-n","hello world","src"]})')!;
for (const status of ["running", "done", "error"] as const) {
@@ -99,4 +114,24 @@ describe("localized agent activity contracts", () => {
expect(screen.getByText("Could not search release notes")).toBeInTheDocument();
expect(JSON.stringify(messages)).toBe(original);
});
it("renders recorded subtask actions in Chinese and English without implying execution is complete", async () => {
const messages: UIMessage[] = [{
id: "subtask-replay", role: "tool", kind: "trace", createdAt: 1,
content: 'subagent("create")',
traces: ['subagent("create")', 'subagent("check")', 'subagent("send")', 'subagent("cancel")'],
}];
const original = JSON.stringify(messages);
await setAppLanguage("zh-CN");
render(<AgentActivityCluster messages={messages} isTurnStreaming={false} hasBodyBelow expanded />);
for (const label of ["子任务已创建", "已获取子任务状态", "消息已加入子任务队列", "已处理停止请求"]) {
expect(screen.getByText(label)).toBeInTheDocument();
}
expect(screen.queryByText("已完成 Subagent")).not.toBeInTheDocument();
await act(async () => setAppLanguage("en"));
for (const label of ["Subtask created", "Subtask status retrieved", "Message queued for subtask", "Stop request processed"]) {
expect(screen.getByText(label)).toBeInTheDocument();
}
expect(JSON.stringify(messages)).toBe(original);
});
});