mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-20 22:40:58 +00:00
82 lines
2.3 KiB
TypeScript
82 lines
2.3 KiB
TypeScript
import { afterEach, describe, expect, it } from "vitest";
|
|
import type { OpenClawConfig } from "../config/config.js";
|
|
import { createEmptyPluginRegistry } from "../plugins/registry.js";
|
|
import { setActivePluginRegistry } from "../plugins/runtime.js";
|
|
import { generateImage, listRuntimeImageGenerationProviders } from "./runtime.js";
|
|
|
|
describe("image-generation runtime helpers", () => {
|
|
afterEach(() => {
|
|
setActivePluginRegistry(createEmptyPluginRegistry());
|
|
});
|
|
|
|
it("generates images through the active image-generation registry", async () => {
|
|
const pluginRegistry = createEmptyPluginRegistry();
|
|
pluginRegistry.imageGenerationProviders.push({
|
|
pluginId: "image-plugin",
|
|
pluginName: "Image Plugin",
|
|
source: "test",
|
|
provider: {
|
|
id: "image-plugin",
|
|
async generateImage() {
|
|
return {
|
|
images: [
|
|
{
|
|
buffer: Buffer.from("png-bytes"),
|
|
mimeType: "image/png",
|
|
fileName: "sample.png",
|
|
},
|
|
],
|
|
model: "img-v1",
|
|
};
|
|
},
|
|
},
|
|
});
|
|
setActivePluginRegistry(pluginRegistry);
|
|
|
|
const cfg = {
|
|
agents: {
|
|
defaults: {
|
|
imageGenerationModel: {
|
|
primary: "image-plugin/img-v1",
|
|
},
|
|
},
|
|
},
|
|
} as OpenClawConfig;
|
|
|
|
const result = await generateImage({
|
|
cfg,
|
|
prompt: "draw a cat",
|
|
agentDir: "/tmp/agent",
|
|
});
|
|
|
|
expect(result.provider).toBe("image-plugin");
|
|
expect(result.model).toBe("img-v1");
|
|
expect(result.attempts).toEqual([]);
|
|
expect(result.images).toEqual([
|
|
{
|
|
buffer: Buffer.from("png-bytes"),
|
|
mimeType: "image/png",
|
|
fileName: "sample.png",
|
|
},
|
|
]);
|
|
});
|
|
|
|
it("lists runtime image-generation providers from the active registry", () => {
|
|
const pluginRegistry = createEmptyPluginRegistry();
|
|
pluginRegistry.imageGenerationProviders.push({
|
|
pluginId: "image-plugin",
|
|
pluginName: "Image Plugin",
|
|
source: "test",
|
|
provider: {
|
|
id: "image-plugin",
|
|
generateImage: async () => ({
|
|
images: [{ buffer: Buffer.from("x"), mimeType: "image/png" }],
|
|
}),
|
|
},
|
|
});
|
|
setActivePluginRegistry(pluginRegistry);
|
|
|
|
expect(listRuntimeImageGenerationProviders()).toMatchObject([{ id: "image-plugin" }]);
|
|
});
|
|
});
|