mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-17 08:02:12 -06:00
fix(llm-task): forward tool cancellation (#124673)
This commit is contained in:
committed by
GitHub
parent
e0e9e272bc
commit
421e319fb7
@@ -382,6 +382,20 @@ describe("llm-task tool (json-only)", () => {
|
||||
expect(call.messages).toEqual([{ role: "user", content: expect.stringContaining("TASK:\nx") }]);
|
||||
});
|
||||
|
||||
it("forwards caller cancellation to the isolated completion", async () => {
|
||||
const controller = new AbortController();
|
||||
const cancellation = new Error("caller cancelled");
|
||||
complete.mockImplementationOnce(async (params) => {
|
||||
controller.abort(cancellation);
|
||||
params.signal?.throwIfAborted();
|
||||
return completionResult(params, '{"ok":true}');
|
||||
});
|
||||
|
||||
const tool = createLlmTaskTool(fakeApi());
|
||||
await expect(tool.execute("id", { prompt: "x" }, controller.signal)).rejects.toBe(cancellation);
|
||||
expect(firstIsolatedCompletionCall().signal).toBe(controller.signal);
|
||||
});
|
||||
|
||||
it("rejects malformed numeric run options before dispatch", async () => {
|
||||
const tool = createLlmTaskTool(fakeApi());
|
||||
|
||||
|
||||
@@ -132,7 +132,7 @@ export function createLlmTaskTool(api: OpenClawPluginApi) {
|
||||
return {
|
||||
...llmTaskToolDefinition,
|
||||
|
||||
async execute(_id: string, params: LlmTaskParams) {
|
||||
async execute(_id: string, params: LlmTaskParams, signal?: AbortSignal) {
|
||||
const prompt = typeof params.prompt === "string" ? params.prompt : "";
|
||||
if (!prompt.trim()) {
|
||||
throw new Error("prompt required");
|
||||
@@ -235,6 +235,7 @@ export function createLlmTaskTool(api: OpenClawPluginApi) {
|
||||
reasoning: thinkLevel,
|
||||
maxTokens: streamParams.maxTokens,
|
||||
temperature: streamParams.temperature,
|
||||
signal,
|
||||
purpose: "llm-task",
|
||||
execution: {
|
||||
mode: "isolated-agent-runtime",
|
||||
|
||||
Reference in New Issue
Block a user