mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 23:01:37 +00:00
fix: route manual subagent spawn replies via OriginatingTo fallback
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
import { resetSubagentRegistryForTests } from "../../agents/subagent-registry.js";
|
|
||||||
import type { SpawnSubagentResult } from "../../agents/subagent-spawn.js";
|
import type { SpawnSubagentResult } from "../../agents/subagent-spawn.js";
|
||||||
import type { OpenClawConfig } from "../../config/config.js";
|
import type { OpenClawConfig } from "../../config/config.js";
|
||||||
|
import { resetSubagentRegistryForTests } from "../../agents/subagent-registry.js";
|
||||||
|
|
||||||
const hoisted = vi.hoisted(() => {
|
const hoisted = vi.hoisted(() => {
|
||||||
const spawnSubagentDirectMock = vi.fn();
|
const spawnSubagentDirectMock = vi.fn();
|
||||||
@@ -170,6 +170,21 @@ describe("/subagents spawn command", () => {
|
|||||||
expect(spawnCtx.agentTo).toBe("channel:12345");
|
expect(spawnCtx.agentTo).toBe("channel:12345");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("falls back to OriginatingTo for agentTo when command.to is missing", async () => {
|
||||||
|
spawnSubagentDirectMock.mockResolvedValue(acceptedResult());
|
||||||
|
const params = buildCommandTestParams("/subagents spawn beta do the thing", baseCfg, {
|
||||||
|
OriginatingTo: "channel:manual",
|
||||||
|
To: "channel:fallback-from-to",
|
||||||
|
});
|
||||||
|
params.command.to = undefined;
|
||||||
|
|
||||||
|
const result = await handleSubagentsCommand(params, true);
|
||||||
|
expect(result).not.toBeNull();
|
||||||
|
expect(result?.reply?.text).toContain("Spawned subagent beta");
|
||||||
|
|
||||||
|
const [, spawnCtx] = spawnSubagentDirectMock.mock.calls[0];
|
||||||
|
expect(spawnCtx).toMatchObject({ agentTo: "channel:manual" });
|
||||||
|
});
|
||||||
it("returns forbidden for unauthorized cross-agent spawn", async () => {
|
it("returns forbidden for unauthorized cross-agent spawn", async () => {
|
||||||
spawnSubagentDirectMock.mockResolvedValue(
|
spawnSubagentDirectMock.mockResolvedValue(
|
||||||
forbiddenResult("agentId is not allowed for sessions_spawn (allowed: alpha)"),
|
forbiddenResult("agentId is not allowed for sessions_spawn (allowed: alpha)"),
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import crypto from "node:crypto";
|
import crypto from "node:crypto";
|
||||||
|
import type { SubagentRunRecord } from "../../agents/subagent-registry.js";
|
||||||
|
import type { CommandHandler } from "./commands-types.js";
|
||||||
import { AGENT_LANE_SUBAGENT } from "../../agents/lanes.js";
|
import { AGENT_LANE_SUBAGENT } from "../../agents/lanes.js";
|
||||||
import { abortEmbeddedPiRun } from "../../agents/pi-embedded.js";
|
import { abortEmbeddedPiRun } from "../../agents/pi-embedded.js";
|
||||||
import type { SubagentRunRecord } from "../../agents/subagent-registry.js";
|
|
||||||
import {
|
import {
|
||||||
clearSubagentRunSteerRestart,
|
clearSubagentRunSteerRestart,
|
||||||
listSubagentRunsForRequester,
|
listSubagentRunsForRequester,
|
||||||
@@ -35,7 +36,6 @@ import {
|
|||||||
} from "../../shared/subagents-format.js";
|
} from "../../shared/subagents-format.js";
|
||||||
import { INTERNAL_MESSAGE_CHANNEL } from "../../utils/message-channel.js";
|
import { INTERNAL_MESSAGE_CHANNEL } from "../../utils/message-channel.js";
|
||||||
import { stopSubagentsForRequester } from "./abort.js";
|
import { stopSubagentsForRequester } from "./abort.js";
|
||||||
import type { CommandHandler } from "./commands-types.js";
|
|
||||||
import { clearSessionQueues } from "./queue.js";
|
import { clearSessionQueues } from "./queue.js";
|
||||||
import { formatRunLabel, formatRunStatus, sortSubagentRuns } from "./subagents-utils.js";
|
import { formatRunLabel, formatRunStatus, sortSubagentRuns } from "./subagents-utils.js";
|
||||||
|
|
||||||
@@ -682,13 +682,19 @@ export const handleSubagentsCommand: CommandHandler = async (params, allowTextCo
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const commandTo = typeof params.command.to === "string" ? params.command.to.trim() : "";
|
||||||
|
const originatingTo =
|
||||||
|
typeof params.ctx.OriginatingTo === "string" ? params.ctx.OriginatingTo.trim() : "";
|
||||||
|
const fallbackTo = typeof params.ctx.To === "string" ? params.ctx.To.trim() : "";
|
||||||
|
const normalizedTo = commandTo || originatingTo || fallbackTo || undefined;
|
||||||
|
|
||||||
const result = await spawnSubagentDirect(
|
const result = await spawnSubagentDirect(
|
||||||
{ task, agentId, model, thinking, cleanup: "keep", expectsCompletionMessage: true },
|
{ task, agentId, model, thinking, cleanup: "keep", expectsCompletionMessage: true },
|
||||||
{
|
{
|
||||||
agentSessionKey: requesterKey,
|
agentSessionKey: requesterKey,
|
||||||
agentChannel: params.ctx.OriginatingChannel ?? params.command.channel,
|
agentChannel: params.ctx.OriginatingChannel ?? params.command.channel,
|
||||||
agentAccountId: params.ctx.AccountId,
|
agentAccountId: params.ctx.AccountId,
|
||||||
agentTo: params.ctx.OriginatingTo ?? params.command.to,
|
agentTo: normalizedTo,
|
||||||
agentThreadId: params.ctx.MessageThreadId,
|
agentThreadId: params.ctx.MessageThreadId,
|
||||||
agentGroupId: params.sessionEntry?.groupId ?? null,
|
agentGroupId: params.sessionEntry?.groupId ?? null,
|
||||||
agentGroupChannel: params.sessionEntry?.groupChannel ?? null,
|
agentGroupChannel: params.sessionEntry?.groupChannel ?? null,
|
||||||
|
|||||||
Reference in New Issue
Block a user