refactor: migrate to async isConfiguredAsync and remove deprecated tool-plugin import
This commit is contained in:
1 parent
8cd50b1c4d
commit
59b7316944
13 files changed
+37
-61
No files matched your search
Vendored
+2
-2
@@ -15,7 +15,7 @@ export interface GeminiImagePluginConfig {
|
||||
export declare function resolvePluginApiKey(rawKey: string | SecretRefObject | undefined): string | undefined;
|
||||
export declare function resolveGeminiImageConfig(cfg: ImageGenerationRequest["cfg"] | undefined, apiPluginConfig?: Record<string, unknown>): GeminiImagePluginConfig | undefined;
|
||||
export declare function resolveConfiguredGeminiImageBaseUrl(pluginCfg?: GeminiImagePluginConfig): string;
|
||||
export declare function buildGeminiImageGenerationProvider({ isProviderApiKeyConfigured, getPluginConfig, }: {
|
||||
isProviderApiKeyConfigured: OpenClawPluginApi["runtime"]["modelAuth"]["isProviderApiKeyConfigured"];
|
||||
export declare function buildGeminiImageGenerationProvider({ isProviderApiKeyConfiguredAsync, getPluginConfig, }: {
|
||||
isProviderApiKeyConfiguredAsync: OpenClawPluginApi["runtime"]["modelAuth"]["isProviderApiKeyConfiguredAsync"];
|
||||
getPluginConfig?: () => Record<string, unknown> | undefined;
|
||||
}): ImageGenerationProvider;
|
||||
Vendored
+3
-3
@@ -25,13 +25,13 @@ export function resolveConfiguredGeminiImageBaseUrl(pluginCfg) {
|
||||
normalizeOptionalString(process.env.GEMINI_IMAGE_BASE_URL) ??
|
||||
DEFAULT_GEMINI_IMAGE_BASE_URL);
|
||||
}
|
||||
export function buildGeminiImageGenerationProvider({ isProviderApiKeyConfigured, getPluginConfig, }) {
|
||||
export function buildGeminiImageGenerationProvider({ isProviderApiKeyConfiguredAsync, getPluginConfig, }) {
|
||||
return {
|
||||
id: "1h-gemini-image",
|
||||
label: "1-h Gemini Image",
|
||||
defaultModel: DEFAULT_GEMINI_IMAGE_MODEL,
|
||||
models: [DEFAULT_GEMINI_IMAGE_MODEL],
|
||||
isConfigured: (ctx) => {
|
||||
isConfiguredAsync: async (ctx) => {
|
||||
const pluginCfg = resolveGeminiImageConfig(ctx.cfg, getPluginConfig?.());
|
||||
if (resolvePluginApiKey(pluginCfg?.apiKey) ||
|
||||
Boolean(pluginCfg?.apiKey) ||
|
||||
@@ -40,7 +40,7 @@ export function buildGeminiImageGenerationProvider({ isProviderApiKeyConfigured,
|
||||
normalizeOptionalString(process.env.BIFROST_API_KEY)) {
|
||||
return true;
|
||||
}
|
||||
return isProviderApiKeyConfigured({
|
||||
return await isProviderApiKeyConfiguredAsync({
|
||||
provider: "google",
|
||||
...ctx,
|
||||
profileTypes: ["api_key"],
|
||||
|
||||
Vendored
+2
-2
@@ -21,7 +21,7 @@ export declare function resolveImageSize(params: {
|
||||
aspectRatio?: string;
|
||||
model?: string;
|
||||
}): string;
|
||||
export declare function buildOpenAIImageGenerationProvider({ isProviderApiKeyConfigured, getPluginConfig, }: {
|
||||
isProviderApiKeyConfigured: OpenClawPluginApi["runtime"]["modelAuth"]["isProviderApiKeyConfigured"];
|
||||
export declare function buildOpenAIImageGenerationProvider({ isProviderApiKeyConfiguredAsync, getPluginConfig, }: {
|
||||
isProviderApiKeyConfiguredAsync: OpenClawPluginApi["runtime"]["modelAuth"]["isProviderApiKeyConfiguredAsync"];
|
||||
getPluginConfig?: () => Record<string, unknown> | undefined;
|
||||
}): ImageGenerationProvider;
|
||||
Vendored
+3
-3
@@ -76,13 +76,13 @@ export function resolveImageSize(params) {
|
||||
return DEFAULT_SIZE;
|
||||
}
|
||||
}
|
||||
export function buildOpenAIImageGenerationProvider({ isProviderApiKeyConfigured, getPluginConfig, }) {
|
||||
export function buildOpenAIImageGenerationProvider({ isProviderApiKeyConfiguredAsync, getPluginConfig, }) {
|
||||
return {
|
||||
id: "1h-openai-image",
|
||||
label: "1-h OpenAI Image",
|
||||
defaultModel: DEFAULT_OPENAI_IMAGE_MODEL,
|
||||
models: [DEFAULT_OPENAI_IMAGE_MODEL, "gpt-image-2.5", "gpt-image-2.5-flare", "gpt-image-2.5-sunburst"],
|
||||
isConfigured: (ctx) => {
|
||||
isConfiguredAsync: async (ctx) => {
|
||||
const pluginCfg = resolveImageConfig(ctx.cfg, getPluginConfig?.());
|
||||
if (resolvePluginApiKey(pluginCfg?.apiKey) ||
|
||||
Boolean(pluginCfg?.apiKey) ||
|
||||
@@ -92,7 +92,7 @@ export function buildOpenAIImageGenerationProvider({ isProviderApiKeyConfigured,
|
||||
normalizeOptionalString(process.env.OPENAI_API_KEY)) {
|
||||
return true;
|
||||
}
|
||||
return isProviderApiKeyConfigured({
|
||||
return await isProviderApiKeyConfiguredAsync({
|
||||
provider: "openai",
|
||||
...ctx,
|
||||
profileTypes: ["api_key"],
|
||||
|
||||
Vendored
+3
-13
@@ -1,6 +1,5 @@
|
||||
import { jsonResult } from "openclaw/plugin-sdk/core";
|
||||
import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
|
||||
import { toolPluginMetadataSymbol } from "openclaw/plugin-sdk/tool-plugin";
|
||||
import { echoTool } from "./tools/echo.js";
|
||||
import { buildOpenAIVideoGenerationProvider } from "./video/openai.js";
|
||||
import { buildOpenAIImageGenerationProvider } from "./image/openai.js";
|
||||
@@ -23,28 +22,19 @@ const entry = definePluginEntry({
|
||||
});
|
||||
// 2. Register OpenAI-compatible video generation provider
|
||||
api.registerVideoGenerationProvider(buildOpenAIVideoGenerationProvider({
|
||||
isProviderApiKeyConfigured: api.runtime.modelAuth.isProviderApiKeyConfigured,
|
||||
isProviderApiKeyConfiguredAsync: api.runtime.modelAuth.isProviderApiKeyConfiguredAsync,
|
||||
getPluginConfig: () => api.pluginConfig,
|
||||
}));
|
||||
// 3. Register OpenAI-compatible image generation provider
|
||||
api.registerImageGenerationProvider(buildOpenAIImageGenerationProvider({
|
||||
isProviderApiKeyConfigured: api.runtime.modelAuth.isProviderApiKeyConfigured,
|
||||
isProviderApiKeyConfiguredAsync: api.runtime.modelAuth.isProviderApiKeyConfiguredAsync,
|
||||
getPluginConfig: () => api.pluginConfig,
|
||||
}));
|
||||
// 4. Register Gemini-native image generation provider
|
||||
api.registerImageGenerationProvider(buildGeminiImageGenerationProvider({
|
||||
isProviderApiKeyConfigured: api.runtime.modelAuth.isProviderApiKeyConfigured,
|
||||
isProviderApiKeyConfiguredAsync: api.runtime.modelAuth.isProviderApiKeyConfiguredAsync,
|
||||
getPluginConfig: () => api.pluginConfig,
|
||||
}));
|
||||
},
|
||||
});
|
||||
Object.defineProperty(entry, toolPluginMetadataSymbol, {
|
||||
value: {
|
||||
id: "1h-tools",
|
||||
name: "1-h Tools",
|
||||
description: "Custom Tools and Media Providers for OpenClaw.",
|
||||
tools: [echoTool],
|
||||
},
|
||||
enumerable: false,
|
||||
});
|
||||
export default entry;
|
||||
Vendored
+2
-2
@@ -53,8 +53,8 @@ export declare function fetchOpenAIVideoDownload(params: {
|
||||
deadline: ReturnType<typeof createProviderOperationDeadline>;
|
||||
fetchFn: typeof fetch;
|
||||
} & OpenAIVideoRequestPolicy): Promise<any>;
|
||||
export declare function buildOpenAIVideoGenerationProvider({ isProviderApiKeyConfigured, getPluginConfig, }: {
|
||||
isProviderApiKeyConfigured: OpenClawPluginApi["runtime"]["modelAuth"]["isProviderApiKeyConfigured"];
|
||||
export declare function buildOpenAIVideoGenerationProvider({ isProviderApiKeyConfiguredAsync, getPluginConfig, }: {
|
||||
isProviderApiKeyConfiguredAsync: OpenClawPluginApi["runtime"]["modelAuth"]["isProviderApiKeyConfiguredAsync"];
|
||||
getPluginConfig?: () => Record<string, unknown> | undefined;
|
||||
}): VideoGenerationProvider;
|
||||
export {};
|
||||
Vendored
+3
-3
@@ -134,13 +134,13 @@ export async function fetchOpenAIVideoDownload(params) {
|
||||
},
|
||||
});
|
||||
}
|
||||
export function buildOpenAIVideoGenerationProvider({ isProviderApiKeyConfigured, getPluginConfig, }) {
|
||||
export function buildOpenAIVideoGenerationProvider({ isProviderApiKeyConfiguredAsync, getPluginConfig, }) {
|
||||
return {
|
||||
id: "1h-openai-video",
|
||||
label: "1-h OpenAI Video",
|
||||
defaultModel: DEFAULT_OPENAI_VIDEO_MODEL,
|
||||
models: [DEFAULT_OPENAI_VIDEO_MODEL, "sora-2-pro", "gemini-video"],
|
||||
isConfigured: (ctx) => {
|
||||
isConfiguredAsync: async (ctx) => {
|
||||
const pluginCfg = resolveVideoConfig(ctx.cfg, getPluginConfig?.());
|
||||
if (resolvePluginApiKey(pluginCfg?.apiKey) ||
|
||||
Boolean(pluginCfg?.apiKey) ||
|
||||
@@ -149,7 +149,7 @@ export function buildOpenAIVideoGenerationProvider({ isProviderApiKeyConfigured,
|
||||
normalizeOptionalString(process.env.CCLOAD_API_KEY)) {
|
||||
return true;
|
||||
}
|
||||
return isProviderApiKeyConfigured({
|
||||
return await isProviderApiKeyConfiguredAsync({
|
||||
provider: "openai",
|
||||
...ctx,
|
||||
profileTypes: ["api_key"],
|
||||
|
||||
+4
-4
@@ -65,10 +65,10 @@ export function resolveConfiguredGeminiImageBaseUrl(
|
||||
}
|
||||
|
||||
export function buildGeminiImageGenerationProvider({
|
||||
isProviderApiKeyConfigured,
|
||||
isProviderApiKeyConfiguredAsync,
|
||||
getPluginConfig,
|
||||
}: {
|
||||
isProviderApiKeyConfigured: OpenClawPluginApi["runtime"]["modelAuth"]["isProviderApiKeyConfigured"];
|
||||
isProviderApiKeyConfiguredAsync: OpenClawPluginApi["runtime"]["modelAuth"]["isProviderApiKeyConfiguredAsync"];
|
||||
getPluginConfig?: () => Record<string, unknown> | undefined;
|
||||
}): ImageGenerationProvider {
|
||||
return {
|
||||
@@ -76,7 +76,7 @@ export function buildGeminiImageGenerationProvider({
|
||||
label: "1-h Gemini Image",
|
||||
defaultModel: DEFAULT_GEMINI_IMAGE_MODEL,
|
||||
models: [DEFAULT_GEMINI_IMAGE_MODEL],
|
||||
isConfigured: (ctx) => {
|
||||
isConfiguredAsync: async (ctx) => {
|
||||
const pluginCfg = resolveGeminiImageConfig(ctx.cfg, getPluginConfig?.());
|
||||
if (
|
||||
resolvePluginApiKey(pluginCfg?.apiKey) ||
|
||||
@@ -87,7 +87,7 @@ export function buildGeminiImageGenerationProvider({
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return isProviderApiKeyConfigured({
|
||||
return await isProviderApiKeyConfiguredAsync({
|
||||
provider: "google",
|
||||
...ctx,
|
||||
profileTypes: ["api_key"],
|
||||
|
||||
+4
-4
@@ -126,10 +126,10 @@ export function resolveImageSize(params: {
|
||||
}
|
||||
|
||||
export function buildOpenAIImageGenerationProvider({
|
||||
isProviderApiKeyConfigured,
|
||||
isProviderApiKeyConfiguredAsync,
|
||||
getPluginConfig,
|
||||
}: {
|
||||
isProviderApiKeyConfigured: OpenClawPluginApi["runtime"]["modelAuth"]["isProviderApiKeyConfigured"];
|
||||
isProviderApiKeyConfiguredAsync: OpenClawPluginApi["runtime"]["modelAuth"]["isProviderApiKeyConfiguredAsync"];
|
||||
getPluginConfig?: () => Record<string, unknown> | undefined;
|
||||
}): ImageGenerationProvider {
|
||||
return {
|
||||
@@ -137,7 +137,7 @@ export function buildOpenAIImageGenerationProvider({
|
||||
label: "1-h OpenAI Image",
|
||||
defaultModel: DEFAULT_OPENAI_IMAGE_MODEL,
|
||||
models: [DEFAULT_OPENAI_IMAGE_MODEL, "gpt-image-2.5", "gpt-image-2.5-flare", "gpt-image-2.5-sunburst"],
|
||||
isConfigured: (ctx) => {
|
||||
isConfiguredAsync: async (ctx) => {
|
||||
const pluginCfg = resolveImageConfig(ctx.cfg, getPluginConfig?.());
|
||||
if (
|
||||
resolvePluginApiKey(pluginCfg?.apiKey) ||
|
||||
@@ -149,7 +149,7 @@ export function buildOpenAIImageGenerationProvider({
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return isProviderApiKeyConfigured({
|
||||
return await isProviderApiKeyConfiguredAsync({
|
||||
provider: "openai",
|
||||
...ctx,
|
||||
profileTypes: ["api_key"],
|
||||
|
||||
+1
-6
@@ -1,12 +1,7 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import entry from "./index.js";
|
||||
import { getToolPluginMetadata } from "openclaw/plugin-sdk/tool-plugin";
|
||||
|
||||
describe("1h-tools", () => {
|
||||
it("declares tool metadata", () => {
|
||||
expect(getToolPluginMetadata(entry)?.tools.map((tool) => tool.name)).toEqual(["echo"]);
|
||||
});
|
||||
|
||||
it("registers tool, video provider, and both image providers", () => {
|
||||
const registeredTools: unknown[] = [];
|
||||
const registeredVideoProviders: unknown[] = [];
|
||||
@@ -15,7 +10,7 @@ describe("1h-tools", () => {
|
||||
const mockApi = {
|
||||
runtime: {
|
||||
modelAuth: {
|
||||
isProviderApiKeyConfigured: vi.fn().mockReturnValue(false),
|
||||
isProviderApiKeyConfiguredAsync: vi.fn().mockResolvedValue(false),
|
||||
},
|
||||
},
|
||||
pluginConfig: {},
|
||||
|
||||
+3
-14
@@ -1,6 +1,5 @@
|
||||
import { jsonResult } from "openclaw/plugin-sdk/core";
|
||||
import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
|
||||
import { toolPluginMetadataSymbol } from "openclaw/plugin-sdk/tool-plugin";
|
||||
import { echoTool } from "./tools/echo.js";
|
||||
import { buildOpenAIVideoGenerationProvider } from "./video/openai.js";
|
||||
import { buildOpenAIImageGenerationProvider } from "./image/openai.js";
|
||||
@@ -26,7 +25,7 @@ const entry = definePluginEntry({
|
||||
// 2. Register OpenAI-compatible video generation provider
|
||||
api.registerVideoGenerationProvider(
|
||||
buildOpenAIVideoGenerationProvider({
|
||||
isProviderApiKeyConfigured: api.runtime.modelAuth.isProviderApiKeyConfigured,
|
||||
isProviderApiKeyConfiguredAsync: api.runtime.modelAuth.isProviderApiKeyConfiguredAsync,
|
||||
getPluginConfig: () => api.pluginConfig,
|
||||
}),
|
||||
);
|
||||
@@ -34,7 +33,7 @@ const entry = definePluginEntry({
|
||||
// 3. Register OpenAI-compatible image generation provider
|
||||
api.registerImageGenerationProvider(
|
||||
buildOpenAIImageGenerationProvider({
|
||||
isProviderApiKeyConfigured: api.runtime.modelAuth.isProviderApiKeyConfigured,
|
||||
isProviderApiKeyConfiguredAsync: api.runtime.modelAuth.isProviderApiKeyConfiguredAsync,
|
||||
getPluginConfig: () => api.pluginConfig,
|
||||
}),
|
||||
);
|
||||
@@ -42,21 +41,11 @@ const entry = definePluginEntry({
|
||||
// 4. Register Gemini-native image generation provider
|
||||
api.registerImageGenerationProvider(
|
||||
buildGeminiImageGenerationProvider({
|
||||
isProviderApiKeyConfigured: api.runtime.modelAuth.isProviderApiKeyConfigured,
|
||||
isProviderApiKeyConfiguredAsync: api.runtime.modelAuth.isProviderApiKeyConfiguredAsync,
|
||||
getPluginConfig: () => api.pluginConfig,
|
||||
}),
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
Object.defineProperty(entry, toolPluginMetadataSymbol, {
|
||||
value: {
|
||||
id: "1h-tools",
|
||||
name: "1-h Tools",
|
||||
description: "Custom Tools and Media Providers for OpenClaw.",
|
||||
tools: [echoTool],
|
||||
},
|
||||
enumerable: false,
|
||||
});
|
||||
|
||||
export default entry;
|
||||
Vendored
+3
-1
@@ -9,7 +9,8 @@ declare module "openclaw/plugin-sdk/video-generation" {
|
||||
label?: string;
|
||||
defaultModel?: string;
|
||||
models?: string[];
|
||||
isConfigured: (ctx: { cfg?: any }) => boolean;
|
||||
isConfigured?: (ctx: { cfg?: any }) => boolean;
|
||||
isConfiguredAsync?: (ctx: { cfg?: any; agentDir?: string }) => Promise<boolean>;
|
||||
capabilities: any;
|
||||
generateVideo: (req: VideoGenerationRequest) => Promise<any>;
|
||||
}
|
||||
@@ -73,6 +74,7 @@ declare module "openclaw/plugin-sdk/image-generation" {
|
||||
models?: string[];
|
||||
capabilities: any;
|
||||
isConfigured?: (ctx: { cfg?: any }) => boolean;
|
||||
isConfiguredAsync?: (ctx: { cfg?: any; agentDir?: string }) => Promise<boolean>;
|
||||
generateImage: (req: ImageGenerationRequest) => Promise<ImageGenerationResult>;
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -239,10 +239,10 @@ export async function fetchOpenAIVideoDownload(
|
||||
}
|
||||
|
||||
export function buildOpenAIVideoGenerationProvider({
|
||||
isProviderApiKeyConfigured,
|
||||
isProviderApiKeyConfiguredAsync,
|
||||
getPluginConfig,
|
||||
}: {
|
||||
isProviderApiKeyConfigured: OpenClawPluginApi["runtime"]["modelAuth"]["isProviderApiKeyConfigured"];
|
||||
isProviderApiKeyConfiguredAsync: OpenClawPluginApi["runtime"]["modelAuth"]["isProviderApiKeyConfiguredAsync"];
|
||||
getPluginConfig?: () => Record<string, unknown> | undefined;
|
||||
}): VideoGenerationProvider {
|
||||
return {
|
||||
@@ -250,7 +250,7 @@ export function buildOpenAIVideoGenerationProvider({
|
||||
label: "1-h OpenAI Video",
|
||||
defaultModel: DEFAULT_OPENAI_VIDEO_MODEL,
|
||||
models: [DEFAULT_OPENAI_VIDEO_MODEL, "sora-2-pro", "gemini-video"],
|
||||
isConfigured: (ctx) => {
|
||||
isConfiguredAsync: async (ctx) => {
|
||||
const pluginCfg = resolveVideoConfig(ctx.cfg, getPluginConfig?.());
|
||||
if (
|
||||
resolvePluginApiKey(pluginCfg?.apiKey) ||
|
||||
@@ -261,7 +261,7 @@ export function buildOpenAIVideoGenerationProvider({
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return isProviderApiKeyConfigured({
|
||||
return await isProviderApiKeyConfiguredAsync({
|
||||
provider: "openai",
|
||||
...ctx,
|
||||
profileTypes: ["api_key"],
|
||||
|
||||
Reference in new issue
Block a user