refactor: remove comfy music tool shim

This commit is contained in:
Peter Steinberger 2026-04-06 02:03:05 +01:00
parent a9f491310c
commit 177ee54f05
No known key found for this signature in database
2 changed files with 0 additions and 198 deletions

View File

@ -1,108 +0,0 @@
import { describe, expect, it, vi } from "vitest";
import { createTestPluginApi } from "../../test/helpers/plugins/plugin-api.js";
import { createComfyMusicGenerateTool } from "./music-generate-tool.js";
import { _setComfyFetchGuardForTesting } from "./workflow-runtime.js";
const { fetchWithSsrFGuardMock, saveMediaBufferMock } = vi.hoisted(() => ({
fetchWithSsrFGuardMock: vi.fn(),
saveMediaBufferMock: vi.fn(async () => ({
path: "/tmp/generated-song.mp3",
id: "music-1",
mimeType: "audio/mpeg",
bytes: 12,
})),
}));
describe("comfy music_generate tool", () => {
it("lists the comfy workflow model", async () => {
const tool = createComfyMusicGenerateTool(createTestPluginApi());
const result = await tool.execute("tool-1", { action: "list" });
expect((result.content[0] as { text: string }).text).toContain("comfy/workflow");
});
it("runs a music workflow and saves audio outputs", async () => {
_setComfyFetchGuardForTesting(fetchWithSsrFGuardMock);
fetchWithSsrFGuardMock
.mockResolvedValueOnce({
response: new Response(JSON.stringify({ prompt_id: "music-job-1" }), {
status: 200,
headers: { "content-type": "application/json" },
}),
release: vi.fn(async () => {}),
})
.mockResolvedValueOnce({
response: new Response(
JSON.stringify({
"music-job-1": {
outputs: {
"9": {
audio: [{ filename: "song.mp3", subfolder: "", type: "output" }],
},
},
},
}),
{
status: 200,
headers: { "content-type": "application/json" },
},
),
release: vi.fn(async () => {}),
})
.mockResolvedValueOnce({
response: new Response(Buffer.from("music-bytes"), {
status: 200,
headers: { "content-type": "audio/mpeg" },
}),
release: vi.fn(async () => {}),
});
const api = createTestPluginApi({
config: {
models: {
providers: {
comfy: {
music: {
workflow: {
"6": { inputs: { text: "" } },
"9": { inputs: {} },
},
promptNodeId: "6",
outputNodeId: "9",
},
},
},
},
} as never,
runtime: {
channel: {
media: {
saveMediaBuffer: saveMediaBufferMock,
},
},
} as never,
});
const tool = createComfyMusicGenerateTool(api);
const result = await tool.execute("tool-2", {
prompt: "gentle ambient synth loop",
});
expect(saveMediaBufferMock).toHaveBeenCalledWith(
Buffer.from("music-bytes"),
"audio/mpeg",
"tool-music-generation",
undefined,
"song.mp3",
);
expect((result.content[0] as { text: string }).text).toContain("MEDIA:/tmp/generated-song.mp3");
expect(result.details).toMatchObject({
provider: "comfy",
model: "workflow",
count: 1,
paths: ["/tmp/generated-song.mp3"],
media: {
mediaUrls: ["/tmp/generated-song.mp3"],
},
});
});
});

View File

@ -1,90 +0,0 @@
import { Type } from "@sinclair/typebox";
import type { AnyAgentTool, OpenClawPluginApi } from "openclaw/plugin-sdk/plugin-entry";
import { runComfyWorkflow } from "./workflow-runtime.js";
function readStringParam(params: Record<string, unknown>, key: string): string | undefined {
const value = params[key];
if (typeof value !== "string") {
return undefined;
}
const trimmed = value.trim();
return trimmed ? trimmed : undefined;
}
export function createComfyMusicGenerateTool(api: OpenClawPluginApi): AnyAgentTool {
return {
name: "music_generate",
label: "music_generate",
description: "Generate audio or music with a workflow-configured ComfyUI graph.",
parameters: Type.Object({
action: Type.Optional(Type.String({ default: "generate", enum: ["generate", "list"] })),
prompt: Type.Optional(Type.String()),
model: Type.Optional(Type.String()),
filename: Type.Optional(Type.String()),
}),
async execute(_id: string, params: Record<string, unknown>) {
const action = readStringParam(params, "action") ?? "generate";
if (action === "list") {
const text = ["Available music generation providers:", "- comfy/workflow"].join("\n");
return {
content: [{ type: "text", text }],
details: {
providers: [
{
provider: "comfy",
models: ["workflow"],
},
],
},
};
}
const prompt = readStringParam(params, "prompt");
if (!prompt) {
throw new Error("prompt required");
}
const result = await runComfyWorkflow({
cfg: api.config,
prompt,
capability: "music",
model: readStringParam(params, "model"),
outputKinds: ["audio"],
});
const filenameHint = readStringParam(params, "filename");
const saved = await Promise.all(
result.assets.map((asset) =>
api.runtime.channel.media.saveMediaBuffer(
asset.buffer,
asset.mimeType,
"tool-music-generation",
undefined,
filenameHint || asset.fileName,
),
),
);
const lines = [
`Generated ${saved.length} audio file${saved.length === 1 ? "" : "s"} with comfy/${result.model}.`,
...saved.map((entry) => `MEDIA:${entry.path}`),
];
return {
content: [{ type: "text", text: lines.join("\n") }],
details: {
provider: "comfy",
model: result.model,
count: saved.length,
media: {
mediaUrls: saved.map((entry) => entry.path),
},
paths: saved.map((entry) => entry.path),
metadata: {
promptId: result.promptId,
outputNodeIds: result.outputNodeIds,
},
},
};
},
};
}