mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-06 05:51:15 +08:00
fix: validate subagents recent minutes
This commit is contained in:
@@ -9,4 +9,15 @@ describe("subagents tool", () => {
|
||||
"List active and recent subagents for the requester session. If sessions_yield exists, use it for completion; do not poll wait loops.",
|
||||
);
|
||||
});
|
||||
|
||||
it.each([0, 1.5])("rejects invalid recentMinutes value %s", async (recentMinutes) => {
|
||||
const tool = createSubagentsTool();
|
||||
|
||||
await expect(
|
||||
tool.execute("call-1", {
|
||||
action: "list",
|
||||
recentMinutes,
|
||||
}),
|
||||
).rejects.toThrow("recentMinutes must be a positive integer");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -9,14 +9,14 @@ import {
|
||||
} from "../subagent-control.js";
|
||||
import { buildSubagentList } from "../subagent-list.js";
|
||||
import type { AnyAgentTool } from "./common.js";
|
||||
import { jsonResult, readNumberParam, readStringParam } from "./common.js";
|
||||
import { jsonResult, readPositiveIntegerParam, readStringParam } from "./common.js";
|
||||
|
||||
const SUBAGENT_ACTIONS = ["list"] as const;
|
||||
type SubagentAction = (typeof SUBAGENT_ACTIONS)[number];
|
||||
|
||||
const SubagentsToolSchema = Type.Object({
|
||||
action: optionalStringEnum(SUBAGENT_ACTIONS),
|
||||
recentMinutes: Type.Optional(Type.Number({ minimum: 1 })),
|
||||
recentMinutes: Type.Optional(Type.Integer({ minimum: 1 })),
|
||||
});
|
||||
|
||||
export function createSubagentsTool(opts?: { agentSessionKey?: string }): AnyAgentTool {
|
||||
@@ -30,15 +30,16 @@ export function createSubagentsTool(opts?: { agentSessionKey?: string }): AnyAge
|
||||
const params = args as Record<string, unknown>;
|
||||
const action = (readStringParam(params, "action") ?? "list") as SubagentAction;
|
||||
const cfg = getRuntimeConfig();
|
||||
const recentMinutesRaw = readPositiveIntegerParam(params, "recentMinutes");
|
||||
const recentMinutes =
|
||||
recentMinutesRaw === undefined
|
||||
? DEFAULT_RECENT_MINUTES
|
||||
: Math.min(MAX_RECENT_MINUTES, recentMinutesRaw);
|
||||
const controller = resolveSubagentController({
|
||||
cfg,
|
||||
agentSessionKey: opts?.agentSessionKey,
|
||||
});
|
||||
const runs = listControlledSubagentRuns(controller.controllerSessionKey);
|
||||
const recentMinutesRaw = readNumberParam(params, "recentMinutes");
|
||||
const recentMinutes = recentMinutesRaw
|
||||
? Math.max(1, Math.min(MAX_RECENT_MINUTES, Math.floor(recentMinutesRaw)))
|
||||
: DEFAULT_RECENT_MINUTES;
|
||||
|
||||
if (action === "list") {
|
||||
const list = buildSubagentList({
|
||||
|
||||
Reference in New Issue
Block a user