feat: split image providers into 1h-openai-image and 1h-gemini-image, rename video to 1h-openai-video
This commit is contained in:
1 parent
3c5e5dd023
commit
8cd50b1c4d
16 files changed
+1553
-102
No files matched your search
+34
-31
@@ -1,35 +1,33 @@
|
||||
# 1-h Image Provider (`1h-image`)
|
||||
# 1-h Image Providers (`1h-openai-image` & `1h-gemini-image`)
|
||||
|
||||
OpenClaw 图像生成驱动模块,适配标准 **OpenAI Images API**(`/v1/images/generations` 及 `/v1/images/edits` 规范)。
|
||||
|
||||
专为自建聚合网关或第三方中转(如 `Bifrost`、`ccLoad`)定制打造:
|
||||
* **尺寸安全归一化**:修复官方驱动在反代环境下因 `16:9` 映射为 `2048x1152` 导致上游报 400 错误的 Bug(Issue #168665),自动将 `16:9` / `9:16` 适配为上游通用的安全比例规格(如 `1792x1024` / `1536x1024`)。
|
||||
* **格式双模自适应**:同时支持解析上游返回的 `b64_json`(Base64 内存直解码)与 `url`(自动安全下载并保存为本地 Buffer),彻底杜绝 `response malformed` 解析失败。
|
||||
* **图生图编辑支持**:当传入 `inputImages` 时,自动走 Multipart 表单发起编辑请求;纯文本生图时走轻量 JSON 请求。
|
||||
* **私有网络与反代直通**:原生支持私有/内网端点请求(`allowPrivateNetwork: true`),兼容 `127.0.0.1`、`host.incus.internal` 或自建反代网关。
|
||||
OpenClaw 图像生成驱动模块集合,根据上游协议严格分离为两个专职驱动,彻底杜绝跨协议调用引发的 400 错配。
|
||||
|
||||
---
|
||||
|
||||
## 标识符
|
||||
## 包含驱动一览
|
||||
|
||||
* **Provider ID**:`1h-image`
|
||||
* **默认模型**:`gpt-image-2`
|
||||
* **支持模型列表**:`gpt-image-2`, `gpt-image-1.5`, `gemini-3.1-flash-image`(也可在配置中自定义扩展)
|
||||
| Provider ID | 对应协议 | 默认模型 | 适用场景 / 支持模型 |
|
||||
| :--- | :--- | :--- | :--- |
|
||||
| **`1h-openai-image`** | OpenAI 标准图像协议<br>(`POST /v1/images/generations`) | `gpt-image-2` | 专为号池/公益站的 OpenAI 协议图像生成打造:<br>• `gpt-image-2`<br>• `gpt-image-2.5`<br>• `gpt-image-2.5-flare`<br>• `gpt-image-2.5-sunburst` |
|
||||
| **`1h-gemini-image`** | Google Gemini 原生内容协议<br>(`POST /v1beta/models/...:generateContent`) | `gemini-3.1-flash-image` | 专为渠道 87(CLI-Proxy)的原生 Gemini 图像生成打造:<br>• `gemini-3.1-flash-image` |
|
||||
|
||||
---
|
||||
|
||||
## 核心特性
|
||||
|
||||
1. **`1h-openai-image`(OpenAI 协议)**:
|
||||
* **尺寸安全映射**:自动将 16:9 / 9:16 安全归一化为通用尺寸(`1792x1024` / `1024x1792` / `1536x1024`),修复 Issue #168665;
|
||||
* **URL 优先与双模自适应**:默认使用 `response_format=url`,完美契合公益站防 400 校验,并自动将链接异步下载为本地图片文件;
|
||||
* **图生图编辑**:传入 `inputImages` 时自动切至 Multipart 表单走 `/v1/images/edits`。
|
||||
|
||||
2. **`1h-gemini-image`(Gemini 协议)**:
|
||||
* **原生 JSON 结构**:以标准的 `contents[].parts` 构造请求,并在返回时原生提取 `inlineData` Base64 流;
|
||||
* **无损回退链**:作为主模型的首选备用渠道,当 OpenAI 渠道拥堵超时时,以纯正 Gemini 协议秒级接管。
|
||||
|
||||
---
|
||||
|
||||
## 配置说明
|
||||
|
||||
支持通过 **Web 控制台(Control UI)** 或直接编辑 `~/.openclaw/openclaw.json`。
|
||||
|
||||
### 方式 1:Web 控制台可视化配置
|
||||
进入 **Settings → Plugins → 1-h Tools**:
|
||||
* **Image Base URL**:填写图像上游端点(例如 `https://Direct-Bifrost.oo1.dev/v1` 或内部反代地址)
|
||||
* **Image API Key**:填写 API Key 或 SecretRef(留空时自动回退读取环境变量 `OPENAI_IMAGE_API_KEY`、`BIFROST_API_KEY`、`CCLOAD_API_KEY` 或 `OPENAI_API_KEY`)
|
||||
* **Default Image Model**:例如 `gpt-image-2`
|
||||
|
||||
### 方式 2:编辑 `openclaw.json`
|
||||
|
||||
在 `~/.openclaw/openclaw.json` 中配置:
|
||||
|
||||
```json5
|
||||
@@ -39,10 +37,17 @@ OpenClaw 图像生成驱动模块,适配标准 **OpenAI Images API**(`/v1/im
|
||||
"1h-tools": {
|
||||
"enabled": true,
|
||||
"config": {
|
||||
"image": {
|
||||
"baseUrl": "https://Direct-Bifrost.oo1.dev/v1",
|
||||
"apiKey": "sk-your-bifrost-key",
|
||||
"openaiImage": {
|
||||
"baseUrl": "http://host.incus.internal:8080/v1",
|
||||
"defaultModel": "gpt-image-2",
|
||||
"apiKey": "1842894d437ee54443a99390f79811ba9ebb785175af340b492e3398dc317921",
|
||||
"responseFormat": "url",
|
||||
"allowPrivateNetwork": true
|
||||
},
|
||||
"geminiImage": {
|
||||
"baseUrl": "http://host.incus.internal:8080/v1beta",
|
||||
"defaultModel": "gemini-3.1-flash-image",
|
||||
"apiKey": "1842894d437ee54443a99390f79811ba9ebb785175af340b492e3398dc317921",
|
||||
"allowPrivateNetwork": true
|
||||
}
|
||||
}
|
||||
@@ -53,9 +58,9 @@ OpenClaw 图像生成驱动模块,适配标准 **OpenAI Images API**(`/v1/im
|
||||
"defaults": {
|
||||
"mediaModels": {
|
||||
"image": {
|
||||
"primary": "1h-image/gpt-image-2",
|
||||
"primary": "1h-openai-image/gpt-image-2",
|
||||
"fallbacks": [
|
||||
"1h-image/gemini-3.1-flash-image"
|
||||
"1h-gemini-image/gemini-3.1-flash-image"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -69,7 +74,5 @@ OpenClaw 图像生成驱动模块,适配标准 **OpenAI Images API**(`/v1/im
|
||||
## 使用方法
|
||||
|
||||
配置完成后,OpenClaw 内置的 `image_generate` 工具即可自动调度:
|
||||
* **文本生成图像**:
|
||||
> “生成一张 16:9 的秋日晨光现代书房桌面壁纸”
|
||||
* **垫图修改/编辑**:
|
||||
在对话中附带图片,提示助手基于该图进行风格调整或重绘。
|
||||
* **正常请求**:默认走 `1h-openai-image/gpt-image-2`;
|
||||
* **容灾回退**:若主模型超时(如公益站排队超时 499),系统自动使用纯正的 `1h-gemini-image/gemini-3.1-flash-image` 协议回退,绝不报 400。
|
||||
@@ -0,0 +1,302 @@
|
||||
import type { OpenClawPluginApi } from "openclaw/plugin-sdk/plugin-entry";
|
||||
import { normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
|
||||
import type {
|
||||
GeneratedImageAsset,
|
||||
ImageGenerationProvider,
|
||||
ImageGenerationRequest,
|
||||
ImageGenerationResult,
|
||||
} from "openclaw/plugin-sdk/image-generation";
|
||||
|
||||
const DEFAULT_GEMINI_IMAGE_BASE_URL = "http://host.incus.internal:8080/v1beta";
|
||||
const DEFAULT_GEMINI_IMAGE_MODEL = "gemini-3.1-flash-image";
|
||||
const DEFAULT_TIMEOUT_MS = 120_000;
|
||||
|
||||
export interface SecretRefObject {
|
||||
source: string;
|
||||
provider: string;
|
||||
id: string;
|
||||
}
|
||||
|
||||
export interface GeminiImagePluginConfig {
|
||||
baseUrl?: string;
|
||||
apiKey?: string | SecretRefObject;
|
||||
allowPrivateNetwork?: boolean;
|
||||
defaultModel?: string;
|
||||
models?: string[];
|
||||
}
|
||||
|
||||
export function resolvePluginApiKey(rawKey: string | SecretRefObject | undefined): string | undefined {
|
||||
if (typeof rawKey === "string") {
|
||||
const trimmed = rawKey.trim();
|
||||
const envMatch = trimmed.match(/^\$\{([A-Za-z0-9_]+)\}$/);
|
||||
if (envMatch) {
|
||||
return normalizeOptionalString(process.env[envMatch[1]]);
|
||||
}
|
||||
return normalizeOptionalString(trimmed);
|
||||
}
|
||||
if (rawKey && typeof rawKey === "object" && typeof rawKey.id === "string") {
|
||||
return normalizeOptionalString(process.env[rawKey.id]);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function resolveGeminiImageConfig(
|
||||
cfg: ImageGenerationRequest["cfg"] | undefined,
|
||||
apiPluginConfig?: Record<string, unknown>,
|
||||
): GeminiImagePluginConfig | undefined {
|
||||
const toolsConfig = (apiPluginConfig ?? cfg?.plugins?.entries?.["1h-tools"]?.config) as
|
||||
| {
|
||||
geminiImage?: GeminiImagePluginConfig;
|
||||
image?: GeminiImagePluginConfig;
|
||||
}
|
||||
| undefined;
|
||||
|
||||
return toolsConfig?.geminiImage ?? toolsConfig?.image;
|
||||
}
|
||||
|
||||
export function resolveConfiguredGeminiImageBaseUrl(
|
||||
pluginCfg?: GeminiImagePluginConfig,
|
||||
): string {
|
||||
return (
|
||||
normalizeOptionalString(pluginCfg?.baseUrl) ??
|
||||
normalizeOptionalString(process.env.GEMINI_IMAGE_BASE_URL) ??
|
||||
DEFAULT_GEMINI_IMAGE_BASE_URL
|
||||
);
|
||||
}
|
||||
|
||||
export function buildGeminiImageGenerationProvider({
|
||||
isProviderApiKeyConfigured,
|
||||
getPluginConfig,
|
||||
}: {
|
||||
isProviderApiKeyConfigured: OpenClawPluginApi["runtime"]["modelAuth"]["isProviderApiKeyConfigured"];
|
||||
getPluginConfig?: () => Record<string, unknown> | undefined;
|
||||
}): ImageGenerationProvider {
|
||||
return {
|
||||
id: "1h-gemini-image",
|
||||
label: "1-h Gemini Image",
|
||||
defaultModel: DEFAULT_GEMINI_IMAGE_MODEL,
|
||||
models: [DEFAULT_GEMINI_IMAGE_MODEL],
|
||||
isConfigured: (ctx) => {
|
||||
const pluginCfg = resolveGeminiImageConfig(ctx.cfg, getPluginConfig?.());
|
||||
if (
|
||||
resolvePluginApiKey(pluginCfg?.apiKey) ||
|
||||
Boolean(pluginCfg?.apiKey) ||
|
||||
normalizeOptionalString(process.env.CCLOAD_API_KEY) ||
|
||||
normalizeOptionalString(process.env.GEMINI_API_KEY) ||
|
||||
normalizeOptionalString(process.env.BIFROST_API_KEY)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return isProviderApiKeyConfigured({
|
||||
provider: "google",
|
||||
...ctx,
|
||||
profileTypes: ["api_key"],
|
||||
});
|
||||
},
|
||||
capabilities: {
|
||||
generate: {
|
||||
maxCount: 1,
|
||||
supportsSize: false,
|
||||
supportsAspectRatio: true,
|
||||
supportsResolution: false,
|
||||
},
|
||||
edit: {
|
||||
enabled: true,
|
||||
maxCount: 1,
|
||||
maxInputImages: 3,
|
||||
supportsSize: false,
|
||||
supportsAspectRatio: true,
|
||||
supportsResolution: false,
|
||||
},
|
||||
geometry: {
|
||||
aspectRatios: ["1:1", "16:9", "9:16", "4:3", "3:4", "3:2", "2:3", "21:9"],
|
||||
},
|
||||
output: {
|
||||
formats: ["jpeg", "png"],
|
||||
},
|
||||
},
|
||||
async generateImage(req: ImageGenerationRequest): Promise<ImageGenerationResult> {
|
||||
const pluginCfg = resolveGeminiImageConfig(req.cfg, getPluginConfig?.());
|
||||
const explicitApiKey =
|
||||
resolvePluginApiKey(pluginCfg?.apiKey) ??
|
||||
normalizeOptionalString(process.env.CCLOAD_API_KEY) ??
|
||||
normalizeOptionalString(process.env.GEMINI_API_KEY) ??
|
||||
normalizeOptionalString(process.env.BIFROST_API_KEY);
|
||||
|
||||
let apiKey = explicitApiKey;
|
||||
if (!apiKey) {
|
||||
const { resolveApiKeyForProvider } = await import(
|
||||
"openclaw/plugin-sdk/provider-auth-runtime"
|
||||
);
|
||||
const auth = await resolveApiKeyForProvider({
|
||||
provider: "google",
|
||||
cfg: req.cfg,
|
||||
agentDir: req.agentDir,
|
||||
store: req.authStore,
|
||||
});
|
||||
if (!auth.apiKey) {
|
||||
throw new Error("Gemini Image API key missing");
|
||||
}
|
||||
apiKey = auth.apiKey;
|
||||
}
|
||||
|
||||
const [
|
||||
{
|
||||
assertOkOrThrowHttpError,
|
||||
createProviderOperationDeadline,
|
||||
postJsonRequest,
|
||||
readProviderJsonResponse,
|
||||
resolveProviderHttpRequestConfig,
|
||||
resolveProviderOperationTimeoutMs,
|
||||
sanitizeConfiguredModelProviderRequest,
|
||||
},
|
||||
] = await Promise.all([import("openclaw/plugin-sdk/provider-http")]);
|
||||
|
||||
const fetchFn = fetch;
|
||||
const deadline = createProviderOperationDeadline({
|
||||
timeoutMs: req.timeoutMs,
|
||||
label: "Gemini Image Generation",
|
||||
});
|
||||
|
||||
const rawBaseUrl = resolveConfiguredGeminiImageBaseUrl(pluginCfg);
|
||||
const allowPrivate = pluginCfg?.allowPrivateNetwork ?? true;
|
||||
const requestConfig = sanitizeConfiguredModelProviderRequest({
|
||||
allowPrivateNetwork: allowPrivate,
|
||||
});
|
||||
|
||||
const { baseUrl, allowPrivateNetwork, headers, dispatcherPolicy } =
|
||||
resolveProviderHttpRequestConfig({
|
||||
baseUrl: rawBaseUrl,
|
||||
defaultBaseUrl: DEFAULT_GEMINI_IMAGE_BASE_URL,
|
||||
allowPrivateNetwork: allowPrivate,
|
||||
request: requestConfig,
|
||||
defaultHeaders: {
|
||||
Authorization: `Bearer ${apiKey}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
provider: "google",
|
||||
capability: "image",
|
||||
transport: "http",
|
||||
});
|
||||
|
||||
const model =
|
||||
normalizeOptionalString(req.model) ??
|
||||
normalizeOptionalString(pluginCfg?.defaultModel) ??
|
||||
DEFAULT_GEMINI_IMAGE_MODEL;
|
||||
|
||||
const submitTimeoutMs = resolveProviderOperationTimeoutMs({
|
||||
deadline,
|
||||
defaultTimeoutMs: DEFAULT_TIMEOUT_MS,
|
||||
});
|
||||
|
||||
const parts: Array<Record<string, unknown>> = [];
|
||||
const inputImages = req.inputImages ?? [];
|
||||
|
||||
for (const img of inputImages) {
|
||||
parts.push({
|
||||
inlineData: {
|
||||
mimeType: img.mimeType || "image/jpeg",
|
||||
data: img.buffer.toString("base64"),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
parts.push({
|
||||
text: req.prompt,
|
||||
});
|
||||
|
||||
const jsonBody: Record<string, unknown> = {
|
||||
contents: [
|
||||
{
|
||||
parts,
|
||||
},
|
||||
],
|
||||
generationConfig: {
|
||||
responseMimeType: "image/jpeg",
|
||||
},
|
||||
};
|
||||
|
||||
const normalizedBaseUrl = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl;
|
||||
const url = `${normalizedBaseUrl}/models/${model}:generateContent`;
|
||||
|
||||
const { response, release } = await postJsonRequest({
|
||||
url,
|
||||
headers,
|
||||
body: jsonBody,
|
||||
timeoutMs: submitTimeoutMs,
|
||||
fetchFn,
|
||||
allowPrivateNetwork,
|
||||
dispatcherPolicy,
|
||||
});
|
||||
|
||||
interface GeminiGenerateContentResponse {
|
||||
candidates?: Array<{
|
||||
content?: {
|
||||
parts?: Array<{
|
||||
text?: string;
|
||||
inlineData?: {
|
||||
mimeType?: string;
|
||||
data?: string;
|
||||
};
|
||||
}>;
|
||||
};
|
||||
finishReason?: string;
|
||||
}>;
|
||||
error?: {
|
||||
code?: number;
|
||||
message?: string;
|
||||
status?: string;
|
||||
};
|
||||
}
|
||||
|
||||
let payload: GeminiGenerateContentResponse;
|
||||
try {
|
||||
await assertOkOrThrowHttpError(response, "Gemini image generation request failed");
|
||||
payload = await readProviderJsonResponse<GeminiGenerateContentResponse>(
|
||||
response,
|
||||
"Gemini image generation failed",
|
||||
);
|
||||
} finally {
|
||||
await release();
|
||||
}
|
||||
|
||||
if (payload.error?.message) {
|
||||
throw new Error(`Gemini image generation error: ${payload.error.message}`);
|
||||
}
|
||||
|
||||
const candidateParts = payload.candidates?.[0]?.content?.parts ?? [];
|
||||
const generatedImages: GeneratedImageAsset[] = [];
|
||||
|
||||
for (let i = 0; i < candidateParts.length; i++) {
|
||||
const part = candidateParts[i];
|
||||
if (part.inlineData?.data) {
|
||||
const buffer = Buffer.from(part.inlineData.data, "base64");
|
||||
const mimeType = part.inlineData.mimeType || "image/jpeg";
|
||||
const ext = mimeType.includes("png") ? "png" : "jpg";
|
||||
generatedImages.push({
|
||||
buffer,
|
||||
mimeType,
|
||||
fileName: `image-${i + 1}.${ext}`,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (generatedImages.length === 0) {
|
||||
const textMessage = candidateParts.find((p) => p.text)?.text;
|
||||
throw new Error(
|
||||
textMessage
|
||||
? `Gemini returned text instead of an image: ${textMessage}`
|
||||
: "Gemini image generation returned no image data",
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
images: generatedImages,
|
||||
model,
|
||||
metadata: {
|
||||
finishReason: payload.candidates?.[0]?.finishReason,
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -70,9 +70,14 @@ export function resolveImageConfig(
|
||||
cfg: ImageGenerationRequest["cfg"] | undefined,
|
||||
apiPluginConfig?: Record<string, unknown>,
|
||||
): ImagePluginConfig | undefined {
|
||||
const direct = apiPluginConfig?.image as ImagePluginConfig | undefined;
|
||||
const fromCfg = cfg?.plugins?.entries?.["1h-tools"]?.config?.image as ImagePluginConfig | undefined;
|
||||
return direct ?? fromCfg;
|
||||
const toolsConfig = (apiPluginConfig ?? cfg?.plugins?.entries?.["1h-tools"]?.config) as
|
||||
| {
|
||||
openaiImage?: ImagePluginConfig;
|
||||
image?: ImagePluginConfig;
|
||||
}
|
||||
| undefined;
|
||||
|
||||
return toolsConfig?.openaiImage ?? toolsConfig?.image;
|
||||
}
|
||||
|
||||
export function resolveConfiguredImageBaseUrl(
|
||||
@@ -128,10 +133,10 @@ export function buildOpenAIImageGenerationProvider({
|
||||
getPluginConfig?: () => Record<string, unknown> | undefined;
|
||||
}): ImageGenerationProvider {
|
||||
return {
|
||||
id: "1h-image",
|
||||
label: "1-h Image",
|
||||
id: "1h-openai-image",
|
||||
label: "1-h OpenAI Image",
|
||||
defaultModel: DEFAULT_OPENAI_IMAGE_MODEL,
|
||||
models: [DEFAULT_OPENAI_IMAGE_MODEL, "gpt-image-1.5", "gemini-3.1-flash-image"],
|
||||
models: [DEFAULT_OPENAI_IMAGE_MODEL, "gpt-image-2.5", "gpt-image-2.5-flare", "gpt-image-2.5-sunburst"],
|
||||
isConfigured: (ctx) => {
|
||||
const pluginCfg = resolveImageConfig(ctx.cfg, getPluginConfig?.());
|
||||
if (
|
||||
+5
-4
@@ -7,7 +7,7 @@ describe("1h-tools", () => {
|
||||
expect(getToolPluginMetadata(entry)?.tools.map((tool) => tool.name)).toEqual(["echo"]);
|
||||
});
|
||||
|
||||
it("registers tool, video generation provider, and image generation provider", () => {
|
||||
it("registers tool, video provider, and both image providers", () => {
|
||||
const registeredTools: unknown[] = [];
|
||||
const registeredVideoProviders: unknown[] = [];
|
||||
const registeredImageProviders: unknown[] = [];
|
||||
@@ -34,9 +34,10 @@ describe("1h-tools", () => {
|
||||
expect(registeredTools[0]).toMatchObject({ name: "echo" });
|
||||
|
||||
expect(mockApi.registerVideoGenerationProvider).toHaveBeenCalledTimes(1);
|
||||
expect(registeredVideoProviders[0]).toMatchObject({ id: "1h-video" });
|
||||
expect(registeredVideoProviders[0]).toMatchObject({ id: "1h-openai-video" });
|
||||
|
||||
expect(mockApi.registerImageGenerationProvider).toHaveBeenCalledTimes(1);
|
||||
expect(registeredImageProviders[0]).toMatchObject({ id: "1h-image" });
|
||||
expect(mockApi.registerImageGenerationProvider).toHaveBeenCalledTimes(2);
|
||||
expect(registeredImageProviders[0]).toMatchObject({ id: "1h-openai-image" });
|
||||
expect(registeredImageProviders[1]).toMatchObject({ id: "1h-gemini-image" });
|
||||
});
|
||||
});
|
||||
+14
-5
@@ -2,13 +2,14 @@ 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/index.js";
|
||||
import { buildOpenAIImageGenerationProvider } from "./image/index.js";
|
||||
import { buildOpenAIVideoGenerationProvider } from "./video/openai.js";
|
||||
import { buildOpenAIImageGenerationProvider } from "./image/openai.js";
|
||||
import { buildGeminiImageGenerationProvider } from "./image/gemini.js";
|
||||
|
||||
const entry = definePluginEntry({
|
||||
id: "1h-tools",
|
||||
name: "1-h Tools",
|
||||
description: "Custom Tools and Media Providers for OpenClaw.",
|
||||
description: "Custom Tools and Media Providers (OpenAI/Gemini) for OpenClaw.",
|
||||
register(api) {
|
||||
// 1. Register tools
|
||||
api.registerTool({
|
||||
@@ -22,7 +23,7 @@ const entry = definePluginEntry({
|
||||
},
|
||||
});
|
||||
|
||||
// 2. Register video generation provider
|
||||
// 2. Register OpenAI-compatible video generation provider
|
||||
api.registerVideoGenerationProvider(
|
||||
buildOpenAIVideoGenerationProvider({
|
||||
isProviderApiKeyConfigured: api.runtime.modelAuth.isProviderApiKeyConfigured,
|
||||
@@ -30,13 +31,21 @@ const entry = definePluginEntry({
|
||||
}),
|
||||
);
|
||||
|
||||
// 3. Register image generation provider
|
||||
// 3. Register OpenAI-compatible image generation provider
|
||||
api.registerImageGenerationProvider(
|
||||
buildOpenAIImageGenerationProvider({
|
||||
isProviderApiKeyConfigured: api.runtime.modelAuth.isProviderApiKeyConfigured,
|
||||
getPluginConfig: () => api.pluginConfig,
|
||||
}),
|
||||
);
|
||||
|
||||
// 4. Register Gemini-native image generation provider
|
||||
api.registerImageGenerationProvider(
|
||||
buildGeminiImageGenerationProvider({
|
||||
isProviderApiKeyConfigured: api.runtime.modelAuth.isProviderApiKeyConfigured,
|
||||
getPluginConfig: () => api.pluginConfig,
|
||||
}),
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
+15
-17
@@ -1,27 +1,25 @@
|
||||
# 1-h Video Provider (`1h-video`)
|
||||
# 1-h OpenAI Video Provider (`1h-openai-video`)
|
||||
|
||||
OpenClaw 视频生成驱动模块,适配标准 **OpenAI Videos API**(`/v1/videos` 规范)。
|
||||
OpenClaw 视频生成驱动模块,专职适配标准 **OpenAI Videos API**(`/v1/videos` 规范)。
|
||||
|
||||
专为自建聚合网关或第三方中转(如 `gemini-web2api-go`、`ccLoad`)做了深度兼容修复:
|
||||
专为自建聚合网关或第三方中转(如 `gemini-web2api-go`、`ccLoad`)定制:
|
||||
* **任务创建**:`POST /v1/videos`。纯文本任务自动发送 JSON Body,避免第三方服务因不支持 Multipart 表单报 400 错误;带参考图/垫视频时使用标准 Multipart 表单。
|
||||
* **状态轮询**:`GET /v1/videos/{id}`。兼容提取普通对象错误信息与字符串错误消息。
|
||||
* **视频下载**:`GET /v1/videos/{id}/content`。流式下载 MP4 二进制视频流。
|
||||
* **私有网络**:原生支持私有/内网端点请求(`allowPrivateNetwork: true`),兼容 `host.incus.internal`、Tailnet 或局域网反代地址。
|
||||
* **私有网络**:原生支持私有/内网端点请求(`allowPrivateNetwork: true`),兼容 `host.incus.internal` 或局域网反代地址。
|
||||
|
||||
---
|
||||
|
||||
## 标识符
|
||||
|
||||
* **Provider ID**:`1h-openai-video`
|
||||
* **默认模型**:`gemini-video`
|
||||
* **支持模型**:`gemini-video`, `sora-2`, `sora-2-pro`
|
||||
|
||||
---
|
||||
|
||||
## 配置说明
|
||||
|
||||
支持通过 **Web 控制台(Control UI)** 或直接编辑 `~/.openclaw/openclaw.json`。
|
||||
|
||||
### 方式 1:Web 控制台可视化配置
|
||||
进入 **Settings → Plugins → 1-h Tools**:
|
||||
* **API Base URL**:填写视频上游端点(例如 `http://host.incus.internal:8083/v1` 或内部网关地址)
|
||||
* **API Key**:填写 API Key 或 SecretRef(留空时自动回退读取环境变量 `OPENAI_VIDEO_API_KEY`、`CCLOAD_API_KEY` 或 `BIFROST_API_KEY`)
|
||||
* **默认视频模型**:例如 `gemini-video` 或 `sora-2`
|
||||
|
||||
### 方式 2:编辑 `openclaw.json`
|
||||
|
||||
在 `~/.openclaw/openclaw.json` 中配置:
|
||||
|
||||
```json5
|
||||
@@ -31,10 +29,10 @@ OpenClaw 视频生成驱动模块,适配标准 **OpenAI Videos API**(`/v1/vi
|
||||
"1h-tools": {
|
||||
"enabled": true,
|
||||
"config": {
|
||||
"video": {
|
||||
"openaiVideo": {
|
||||
"baseUrl": "http://host.incus.internal:8083/v1",
|
||||
"apiKey": "sk-your-video-key",
|
||||
"defaultModel": "gemini-video",
|
||||
"apiKey": "sk-your-video-key",
|
||||
"allowPrivateNetwork": true
|
||||
}
|
||||
}
|
||||
@@ -45,7 +43,7 @@ OpenClaw 视频生成驱动模块,适配标准 **OpenAI Videos API**(`/v1/vi
|
||||
"defaults": {
|
||||
"mediaModels": {
|
||||
"video": {
|
||||
"primary": "1h-video/gemini-video"
|
||||
"primary": "1h-openai-video/gemini-video"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,9 +80,14 @@ export function resolveVideoConfig(
|
||||
cfg: VideoGenerationRequest["cfg"] | undefined,
|
||||
apiPluginConfig?: Record<string, unknown>,
|
||||
): VideoPluginConfig | undefined {
|
||||
const direct = apiPluginConfig?.video as VideoPluginConfig | undefined;
|
||||
const fromCfg = cfg?.plugins?.entries?.["1h-tools"]?.config?.video as VideoPluginConfig | undefined;
|
||||
return direct ?? fromCfg;
|
||||
const toolsConfig = (apiPluginConfig ?? cfg?.plugins?.entries?.["1h-tools"]?.config) as
|
||||
| {
|
||||
openaiVideo?: VideoPluginConfig;
|
||||
video?: VideoPluginConfig;
|
||||
}
|
||||
| undefined;
|
||||
|
||||
return toolsConfig?.openaiVideo ?? toolsConfig?.video;
|
||||
}
|
||||
|
||||
export function resolveConfiguredOpenAIBaseUrl(
|
||||
@@ -241,8 +246,8 @@ export function buildOpenAIVideoGenerationProvider({
|
||||
getPluginConfig?: () => Record<string, unknown> | undefined;
|
||||
}): VideoGenerationProvider {
|
||||
return {
|
||||
id: "1h-video",
|
||||
label: "1-h Video",
|
||||
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) => {
|
||||
Reference in new issue
Block a user