@acedatacloud/openclaw-provider 2026.5.34 → 2026.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +72 -59
- package/assets/icon.png +0 -0
- package/dist/index.d.ts +4 -10
- package/dist/index.js +34 -20
- package/dist/src/chat/generated-catalog.d.ts +9 -7
- package/dist/src/chat/generated-catalog.js +3893 -65
- package/dist/src/chat/onboard.d.ts +1 -1
- package/dist/src/chat/onboard.js +13 -2
- package/dist/src/chat/provider-catalog.d.ts +4 -2
- package/dist/src/chat/provider-catalog.js +2 -51
- package/dist/src/chat/runtime.d.ts +4 -0
- package/dist/src/chat/runtime.js +77 -0
- package/dist/src/constants.d.ts +1 -1
- package/dist/src/constants.js +1 -1
- package/dist/src/search/acedata-search-client.d.ts +2 -0
- package/dist/src/search/acedata-search-client.js +21 -13
- package/dist/src/search/acedata-search-config.js +6 -4
- package/dist/src/search/acedata-search-provider.d.ts +3 -2
- package/dist/src/search/acedata-search-provider.js +5 -2
- package/dist/src/search/acedata-search-shared.d.ts +2 -1
- package/dist/src/search/acedata-search-shared.js +37 -6
- package/dist/src/services/catalog.d.ts +46 -0
- package/dist/src/services/catalog.js +24 -0
- package/dist/src/services/client.d.ts +36 -0
- package/dist/src/services/client.js +315 -0
- package/dist/src/services/contracts/face.json +16 -0
- package/dist/src/services/contracts/fish-audio.json +15 -0
- package/dist/src/services/contracts/flux.json +13 -0
- package/dist/src/services/contracts/google-search.json +9 -0
- package/dist/src/services/contracts/gpt-image.json +13 -0
- package/dist/src/services/contracts/grok.json +12 -0
- package/dist/src/services/contracts/happyhorse.json +11 -0
- package/dist/src/services/contracts/kling.json +20 -0
- package/dist/src/services/contracts/midjourney.json +17 -0
- package/dist/src/services/contracts/minimax.json +13 -0
- package/dist/src/services/contracts/nano-banana.json +12 -0
- package/dist/src/services/contracts/qwen-image.json +11 -0
- package/dist/src/services/contracts/seedance.json +11 -0
- package/dist/src/services/contracts/seedream.json +13 -0
- package/dist/src/services/contracts/suno.json +27 -0
- package/dist/src/services/contracts/veo.json +15 -0
- package/dist/src/services/contracts/wan.json +12 -0
- package/dist/src/services/media.d.ts +25 -0
- package/dist/src/services/media.js +350 -0
- package/dist/src/services/parameters.d.ts +6 -0
- package/dist/src/services/parameters.js +165 -0
- package/dist/src/services/tools.d.ts +6 -0
- package/dist/src/services/tools.js +59 -0
- package/docs/architecture.md +58 -0
- package/docs/capabilities.md +75 -0
- package/docs/cookbook.md +77 -0
- package/docs/model-catalog.md +126 -0
- package/openclaw.plugin.json +5679 -8
- package/package.json +31 -23
- package/skills/acedata-face/SKILL.md +14 -0
- package/skills/acedata-fish-audio/SKILL.md +20 -0
- package/skills/acedata-flux/SKILL.md +18 -0
- package/skills/acedata-google-search/SKILL.md +14 -0
- package/skills/acedata-gpt-image/SKILL.md +18 -0
- package/skills/acedata-grok/SKILL.md +17 -0
- package/skills/acedata-happyhorse/SKILL.md +16 -0
- package/skills/acedata-kling/SKILL.md +25 -0
- package/skills/acedata-midjourney/SKILL.md +22 -0
- package/skills/acedata-minimax/SKILL.md +18 -0
- package/skills/acedata-nano-banana/SKILL.md +17 -0
- package/skills/acedata-qwen-image/SKILL.md +16 -0
- package/skills/acedata-seedance/SKILL.md +16 -0
- package/skills/acedata-seedream/SKILL.md +18 -0
- package/skills/acedata-suno/SKILL.md +32 -0
- package/skills/acedata-veo/SKILL.md +20 -0
- package/skills/acedata-wan/SKILL.md +17 -0
- package/index.ts +0 -110
- package/src/chat/generated-catalog.ts +0 -77
- package/src/chat/model-overrides.json +0 -93
- package/src/chat/onboard.ts +0 -33
- package/src/chat/provider-catalog.ts +0 -73
- package/src/constants.ts +0 -3
- package/src/search/acedata-search-client.ts +0 -160
- package/src/search/acedata-search-config.ts +0 -76
- package/src/search/acedata-search-provider.ts +0 -80
- package/src/search/acedata-search-shared.ts +0 -29
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
import { fetchWithSsrFGuard } from "openclaw/plugin-sdk/ssrf-runtime";
|
|
2
|
+
import { isProviderApiKeyConfigured } from "openclaw/plugin-sdk/provider-auth";
|
|
3
|
+
import { serviceById } from "./catalog.js";
|
|
4
|
+
import { ServiceClient, readLimited, record } from "./client.js";
|
|
5
|
+
import { resolveServiceKey } from "./tools.js";
|
|
6
|
+
function configured(service, cfg, agentDir) {
|
|
7
|
+
return !!record(record(record(cfg?.plugins?.entries?.acedatacloud?.config).serviceCredentials)[service]).apiKey || !!cfg?.models?.providers?.acedatacloud?.apiKey || !!(process.env.ACEDATA_API_KEY || process.env.ACEDATACLOUD_API_KEY) || isProviderApiKeyConfigured({ provider: "acedatacloud", agentDir });
|
|
8
|
+
}
|
|
9
|
+
export const IMAGE_OPERATIONS = {
|
|
10
|
+
"nano-banana": ["nano_banana_generate_image", "nano_banana_edit_image"],
|
|
11
|
+
"gpt-image": ["gpt_image_generate_image", "gpt_image_edit_image"],
|
|
12
|
+
seedream: ["seedream_generate_image", "seedream_edit_image"],
|
|
13
|
+
flux: ["flux_generate_image", "flux_edit_image"],
|
|
14
|
+
"qwen-image": ["qwen_image", "qwen_image"],
|
|
15
|
+
midjourney: ["midjourney_imagine", "midjourney_edits"],
|
|
16
|
+
};
|
|
17
|
+
export const VIDEO_OPERATIONS = {
|
|
18
|
+
seedance: "seedance_generate_video", happyhorse: "happyhorse_generate_video", grok: "grok_generate_video",
|
|
19
|
+
kling: "kling_generate_video", veo: "veo_generate_video", minimax: "minimax_generate_video",
|
|
20
|
+
wan: "wan_generate_video", flux: "flux_generate_video", midjourney: "midjourney_videos",
|
|
21
|
+
};
|
|
22
|
+
export const providerId = (service) => `acedatacloud-${service}`;
|
|
23
|
+
export function operationModels(endpoint) {
|
|
24
|
+
const models = endpoint.properties.model?.enum;
|
|
25
|
+
if (Array.isArray(models))
|
|
26
|
+
return models.filter((m) => typeof m === "string");
|
|
27
|
+
if (endpoint.path.startsWith("/midjourney/"))
|
|
28
|
+
return endpoint.path.endsWith("/videos") ? ["midjourney-video"] : ["midjourney"];
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
function catalog(api, provider, kind, models, label, capabilities) {
|
|
32
|
+
api.registerModelCatalogProvider({ provider, kinds: [kind], staticCatalog: () => models.map(model => ({ kind, provider, model, label: `${label} / ${model}`, source: "static", capabilities, authEnvVars: ["ACEDATA_API_KEY", "ACEDATACLOUD_API_KEY"] })) });
|
|
33
|
+
}
|
|
34
|
+
function exactModel(endpoint, model) {
|
|
35
|
+
if (!operationModels(endpoint).includes(model))
|
|
36
|
+
throw new Error(`Unsupported model for ${endpoint.path}: ${model}`);
|
|
37
|
+
}
|
|
38
|
+
function dataUrl(image) {
|
|
39
|
+
if (!image.buffer.length || image.buffer.length > 10 * 1024 * 1024 || !/^image\/(png|jpeg|webp)$/.test(image.mimeType))
|
|
40
|
+
throw new Error("Input images must be PNG/JPEG/WebP and at most 10 MiB.");
|
|
41
|
+
return `data:${image.mimeType};base64,${image.buffer.toString("base64")}`;
|
|
42
|
+
}
|
|
43
|
+
function assetUrl(asset) {
|
|
44
|
+
if (asset.url) {
|
|
45
|
+
if (!asset.url.startsWith("https://"))
|
|
46
|
+
throw new Error("Use HTTPS reference media URLs.");
|
|
47
|
+
return asset.url;
|
|
48
|
+
}
|
|
49
|
+
if (asset.buffer && asset.mimeType?.startsWith("image/"))
|
|
50
|
+
return dataUrl({ buffer: asset.buffer, mimeType: asset.mimeType });
|
|
51
|
+
throw new Error("This API requires an HTTPS reference URL for video/audio assets.");
|
|
52
|
+
}
|
|
53
|
+
export async function downloadAsset(url, kind, timeoutMs = 60_000) {
|
|
54
|
+
// Never send the service credential to a returned media URL. DNS pinning and
|
|
55
|
+
// redirect validation stay in the host's public SSRF guard.
|
|
56
|
+
const { response, release } = await fetchWithSsrFGuard({ url, requireHttps: true, maxRedirects: 3, timeoutMs, auditContext: `acedatacloud-${kind}-result` });
|
|
57
|
+
try {
|
|
58
|
+
if (!response.ok)
|
|
59
|
+
throw new Error(`Generated media download HTTP ${response.status}.`);
|
|
60
|
+
const buffer = await readLimited(response, kind === "image" ? 30 * 1024 * 1024 : 100 * 1024 * 1024);
|
|
61
|
+
const mimeType = response.headers.get("content-type")?.split(";")[0] ?? "";
|
|
62
|
+
if (!buffer.length || !mimeType.startsWith(`${kind}/`))
|
|
63
|
+
throw new Error(`Generated result is not a nonempty ${kind} asset.`);
|
|
64
|
+
return { buffer, mimeType };
|
|
65
|
+
}
|
|
66
|
+
finally {
|
|
67
|
+
await release();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
export function mapImageRequest(service, req) {
|
|
71
|
+
const [generate, edit] = IMAGE_OPERATIONS[service];
|
|
72
|
+
const hasImages = !!req.inputImages?.length;
|
|
73
|
+
const tool = hasImages ? edit : generate;
|
|
74
|
+
if (!tool)
|
|
75
|
+
throw new Error("This model has no native image edit operation.");
|
|
76
|
+
const endpoint = serviceById(service).endpoints[tool];
|
|
77
|
+
exactModel(endpoint, req.model);
|
|
78
|
+
if (hasImages && service === "gpt-image" && req.model.startsWith("dall-e"))
|
|
79
|
+
throw new Error("DALL-E editing is not supported by this native endpoint.");
|
|
80
|
+
if (service === "gpt-image" && req.model === "dall-e-3" && (req.count ?? 1) !== 1)
|
|
81
|
+
throw new Error("DALL-E 3 generates one image per request.");
|
|
82
|
+
if (service === "flux" && req.model.startsWith("flux-kontext") && req.size && !req.size.includes(":"))
|
|
83
|
+
throw new Error("Kontext size must be an aspect ratio.");
|
|
84
|
+
const params = { ...record(req.providerOptions?.acedatacloud), model: req.model, prompt: req.prompt };
|
|
85
|
+
if (service === "flux" && req.model.startsWith("flux-kontext"))
|
|
86
|
+
params.size = "1:1";
|
|
87
|
+
const images = req.inputImages?.map(dataUrl);
|
|
88
|
+
if (req.count !== undefined && service !== "seedream" && service !== "midjourney")
|
|
89
|
+
params[["gpt-image", "qwen-image"].includes(service) ? "n" : "count"] = req.count;
|
|
90
|
+
if (images) {
|
|
91
|
+
if (service === "flux" || service === "midjourney") {
|
|
92
|
+
if (images.length !== 1)
|
|
93
|
+
throw new Error("This edit operation accepts one image.");
|
|
94
|
+
params.image_url = images[0];
|
|
95
|
+
}
|
|
96
|
+
else
|
|
97
|
+
params[["gpt-image", "seedream"].includes(service) ? "image" : "image_urls"] = images;
|
|
98
|
+
}
|
|
99
|
+
if (req.size)
|
|
100
|
+
params.size = service === "qwen-image" ? req.size.replace("x", "*") : req.size;
|
|
101
|
+
if (req.aspectRatio)
|
|
102
|
+
params[service === "flux" ? "size" : "aspect_ratio"] = req.aspectRatio;
|
|
103
|
+
if (req.resolution)
|
|
104
|
+
params[service === "seedream" ? "size" : "resolution"] = req.resolution;
|
|
105
|
+
if (req.quality)
|
|
106
|
+
params.quality = req.quality;
|
|
107
|
+
if (req.outputFormat)
|
|
108
|
+
params.output_format = req.outputFormat;
|
|
109
|
+
if (req.background)
|
|
110
|
+
params.background = req.background;
|
|
111
|
+
if (service === "seedream" && req.count && req.count > 1) {
|
|
112
|
+
params.sequential_image_generation = "auto";
|
|
113
|
+
params.sequential_image_generation_options = { max_images: req.count };
|
|
114
|
+
delete params.count;
|
|
115
|
+
}
|
|
116
|
+
if (service === "midjourney") {
|
|
117
|
+
delete params.model;
|
|
118
|
+
delete params.count;
|
|
119
|
+
}
|
|
120
|
+
return { tool, params };
|
|
121
|
+
}
|
|
122
|
+
export function mapVideoRequest(service, req) {
|
|
123
|
+
const tool = VIDEO_OPERATIONS[service];
|
|
124
|
+
const endpoint = serviceById(service).endpoints[tool];
|
|
125
|
+
exactModel(endpoint, req.model);
|
|
126
|
+
const params = { ...req.providerOptions, model: req.model, prompt: req.prompt };
|
|
127
|
+
const images = req.inputImages?.map(assetUrl) ?? [], videos = req.inputVideos?.map(assetUrl) ?? [], audios = req.inputAudios?.map(assetUrl) ?? [];
|
|
128
|
+
if (videos.length && !["seedance", "minimax", "happyhorse", "wan", "flux"].includes(service))
|
|
129
|
+
throw new Error("Use the dedicated service edit/extend tool for this video operation.");
|
|
130
|
+
if (audios.length && !["seedance", "minimax", "wan"].includes(service))
|
|
131
|
+
throw new Error("This native video operation does not accept reference audio.");
|
|
132
|
+
const maxImages = service === "veo" ? req.model.endsWith("-ingredients") ? 3 : 2 : ["kling", "flux", "midjourney"].includes(service) ? 2 : ["seedance", "minimax", "grok"].includes(service) ? 9 : service === "wan" && req.model === "wan3.0-video" ? 10 : service === "happyhorse" && req.model.endsWith("-r2v") ? 9 : 1;
|
|
133
|
+
if (images.length > maxImages || videos.length > (service === "wan" && req.model === "wan3.0-video" ? 5 : 1))
|
|
134
|
+
throw new Error("Too many reference assets for this native operation.");
|
|
135
|
+
if (service === "veo" && req.model.endsWith("-ingredients") && !images.length)
|
|
136
|
+
throw new Error("Veo ingredients requires reference images.");
|
|
137
|
+
if (service === "midjourney" && !images.length)
|
|
138
|
+
throw new Error("Midjourney video requires an input image.");
|
|
139
|
+
if (service === "seedance" && req.model.includes("lite-i2v") && !images.length)
|
|
140
|
+
throw new Error("The selected Seedance model requires an input image.");
|
|
141
|
+
if (service === "seedance" && req.model.includes("lite-t2v") && images.length)
|
|
142
|
+
throw new Error("The selected Seedance model only supports text-to-video.");
|
|
143
|
+
if (service === "wan" && req.model !== "wan3.0-video") {
|
|
144
|
+
if (req.model.includes("-i2v") && !images.length)
|
|
145
|
+
throw new Error("The selected Wan model requires an input image.");
|
|
146
|
+
if (req.model.endsWith("-r2v") && !videos.length)
|
|
147
|
+
throw new Error("The selected Wan model requires reference video.");
|
|
148
|
+
if (req.model.endsWith("-t2v") && (images.length || videos.length))
|
|
149
|
+
throw new Error("The selected Wan model supports text-to-video only.");
|
|
150
|
+
if (req.durationSeconds !== undefined && ![5, 10, 15].includes(req.durationSeconds))
|
|
151
|
+
throw new Error("Wan 2.6 supports 5, 10 or 15 seconds.");
|
|
152
|
+
}
|
|
153
|
+
if (req.durationSeconds !== undefined)
|
|
154
|
+
params.duration = req.durationSeconds;
|
|
155
|
+
if (req.aspectRatio)
|
|
156
|
+
params[["seedance", "happyhorse", "minimax", "wan"].includes(service) ? "ratio" : "aspect_ratio"] = req.aspectRatio;
|
|
157
|
+
if (req.resolution)
|
|
158
|
+
params.resolution = ["seedance", "grok", "veo"].includes(service) ? req.resolution.toLowerCase() : req.resolution;
|
|
159
|
+
if (req.size)
|
|
160
|
+
params.size = req.size;
|
|
161
|
+
if (req.audio !== undefined)
|
|
162
|
+
params[service === "wan" ? "audio" : "generate_audio"] = req.audio;
|
|
163
|
+
if (req.watermark !== undefined)
|
|
164
|
+
params.watermark = req.watermark;
|
|
165
|
+
if (["seedance", "minimax"].includes(service)) {
|
|
166
|
+
const content = req.prompt ? [{ type: "text", text: req.prompt }] : [];
|
|
167
|
+
for (const [assets, type, role] of [[req.inputImages ?? [], "image_url", "first_frame"], [req.inputVideos ?? [], "video_url", "reference_video"], [req.inputAudios ?? [], "audio_url", "reference_audio"]])
|
|
168
|
+
for (const a of assets)
|
|
169
|
+
content.push({ type, role: a.role ?? role, [type]: { url: assetUrl(a) } });
|
|
170
|
+
params.content = content;
|
|
171
|
+
delete params.prompt;
|
|
172
|
+
}
|
|
173
|
+
else if (service === "happyhorse") {
|
|
174
|
+
if (req.model.endsWith("-video-edit")) {
|
|
175
|
+
params.action = "video_edit";
|
|
176
|
+
params.video_url = videos[0];
|
|
177
|
+
}
|
|
178
|
+
else if (req.model.endsWith("-r2v")) {
|
|
179
|
+
params.action = "reference_to_video";
|
|
180
|
+
params.image_urls = images;
|
|
181
|
+
}
|
|
182
|
+
else if (req.model.endsWith("-i2v")) {
|
|
183
|
+
params.action = "image_to_video";
|
|
184
|
+
params.image_url = images[0];
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
if (images.length || videos.length)
|
|
188
|
+
throw new Error("Select a Happy Horse model matching the input mode.");
|
|
189
|
+
params.action = "generate";
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
else if (service === "kling") {
|
|
193
|
+
params.action = images.length ? "image2video" : "text2video";
|
|
194
|
+
if (images.length) {
|
|
195
|
+
params.start_image_url = images[0];
|
|
196
|
+
if (images[1])
|
|
197
|
+
params.end_image_url = images[1];
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
else if (service === "veo") {
|
|
201
|
+
params.action = req.model.endsWith("-ingredients") ? "ingredients2video" : images.length ? "image2video" : "text2video";
|
|
202
|
+
if (images.length)
|
|
203
|
+
params.image_urls = images;
|
|
204
|
+
}
|
|
205
|
+
else if (service === "wan") {
|
|
206
|
+
params.action = images.length ? "image2video" : "text2video";
|
|
207
|
+
if (req.model === "wan3.0-video") {
|
|
208
|
+
params.media = [...(req.inputImages ?? []).map(a => ({ type: a.role ?? "reference_image", url: assetUrl(a) })), ...(req.inputVideos ?? []).map(a => ({ type: a.role ?? "reference_video", url: assetUrl(a) })), ...(req.inputAudios ?? []).map(a => ({ type: a.role ?? "reference_audio", url: assetUrl(a) }))];
|
|
209
|
+
const roles = params.media.map(a => a.type);
|
|
210
|
+
if (roles.some(r => ["first_frame", "last_frame"].includes(r)) && roles.some(r => r.startsWith("reference_")))
|
|
211
|
+
throw new Error("Wan 3 frame mode cannot mix with reference mode.");
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
if (images.length)
|
|
215
|
+
params.image_url = images[0];
|
|
216
|
+
if (videos.length)
|
|
217
|
+
params.reference_video_urls = videos;
|
|
218
|
+
if (audios.length)
|
|
219
|
+
params.audio_url = audios[0];
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
else if (service === "flux") {
|
|
223
|
+
params.mode = videos.length ? "v2v" : images.length ? "i2v" : "t2v";
|
|
224
|
+
if (images.length)
|
|
225
|
+
params.keyframes = images;
|
|
226
|
+
if (videos.length)
|
|
227
|
+
params.start_video = videos[0];
|
|
228
|
+
}
|
|
229
|
+
else if (service === "grok") {
|
|
230
|
+
if (images.length > 1)
|
|
231
|
+
params.reference_image_urls = images;
|
|
232
|
+
else if (images.length)
|
|
233
|
+
params.image_url = images[0];
|
|
234
|
+
}
|
|
235
|
+
else if (service === "midjourney") {
|
|
236
|
+
delete params.model;
|
|
237
|
+
if (images.length)
|
|
238
|
+
params.image_url = images[0];
|
|
239
|
+
if (images[1])
|
|
240
|
+
params.end_image_url = images[1];
|
|
241
|
+
}
|
|
242
|
+
return { tool, params };
|
|
243
|
+
}
|
|
244
|
+
export function registerMediaProviders(api) {
|
|
245
|
+
for (const [id, [generate, edit]] of Object.entries(IMAGE_OPERATIONS)) {
|
|
246
|
+
const service = serviceById(id), endpoint = service.endpoints[generate];
|
|
247
|
+
const models = operationModels(endpoint);
|
|
248
|
+
const provider = {
|
|
249
|
+
id: providerId(id), label: `Ace Data Cloud — ${service.label}`, models,
|
|
250
|
+
defaultModel: String(endpoint.defaults?.model ?? models[0]), defaultTimeoutMs: 600_000,
|
|
251
|
+
isConfigured: ({ cfg, agentDir }) => configured(id, cfg, agentDir),
|
|
252
|
+
capabilities: { generate: { maxCount: id === "nano-banana" ? 4 : id === "gpt-image" ? 10 : id === "qwen-image" ? 6 : 1, supportsSize: !!endpoint.properties.size, supportsAspectRatio: !!endpoint.properties.aspect_ratio || id === "flux", supportsResolution: !!endpoint.properties.resolution || id === "seedream" }, edit: { enabled: !!edit, maxInputImages: ["flux", "midjourney"].includes(id) ? 1 : id === "seedream" ? 10 : 4, ...(id === "gpt-image" ? { maxInputImagesByModel: { "dall-e-2": 0, "dall-e-3": 0 } } : {}), ...(id === "seedream" ? { maxInputImagesByModel: { "doubao-seedream-5-0-lite-260128": 14, "doubao-seedream-5-0-pro-260628": 10 } } : {}) }, ...(id === "nano-banana" ? { geometry: { aspectRatios: endpoint.properties.aspect_ratio.enum, resolutions: ["1K", "2K", "4K"] } } : {}) },
|
|
253
|
+
async generateImage(req) {
|
|
254
|
+
const mapped = mapImageRequest(id, req);
|
|
255
|
+
const result = await new ServiceClient(await resolveServiceKey(api, id, req.cfg)).complete(service, mapped.tool, mapped.params, req.timeoutMs ?? 600_000);
|
|
256
|
+
if (!result.media_urls.length)
|
|
257
|
+
throw new Error(`No image output in completed task ${result.task_id}.`);
|
|
258
|
+
let images;
|
|
259
|
+
try {
|
|
260
|
+
images = await Promise.all(result.media_urls.map(url => downloadAsset(url, "image")));
|
|
261
|
+
}
|
|
262
|
+
catch {
|
|
263
|
+
throw new Error(`Image task ${result.task_id || result.trace_id} completed but media delivery failed. Retrieve this task; do not regenerate.`);
|
|
264
|
+
}
|
|
265
|
+
return { images, model: req.model, metadata: { status: result.status, taskId: result.task_id, traceId: result.trace_id } };
|
|
266
|
+
},
|
|
267
|
+
};
|
|
268
|
+
api.registerImageGenerationProvider(provider);
|
|
269
|
+
catalog(api, provider.id, "image_generation", models, service.label, provider.capabilities);
|
|
270
|
+
}
|
|
271
|
+
for (const [id, operation] of Object.entries(VIDEO_OPERATIONS)) {
|
|
272
|
+
const service = serviceById(id), endpoint = service.endpoints[operation], models = operationModels(endpoint);
|
|
273
|
+
const limits = { maxVideos: 1, supportsResolution: !!endpoint.properties.resolution, supportsAspectRatio: !!(endpoint.properties.aspect_ratio || endpoint.properties.ratio), supportsAudio: !!(endpoint.properties.generate_audio || endpoint.properties.audio), supportsWatermark: !!endpoint.properties.watermark, ...(Array.isArray(endpoint.properties.resolution?.enum) ? { resolutions: endpoint.properties.resolution.enum.filter(r => id !== "minimax" || r !== "480P") } : {}) };
|
|
274
|
+
const provider = {
|
|
275
|
+
id: providerId(id), label: `Ace Data Cloud — ${service.label}`, models,
|
|
276
|
+
defaultModel: String(endpoint.defaults?.model ?? models.find(m => !m.endsWith("-i2v") && !m.endsWith("-r2v")) ?? models[0]), defaultTimeoutMs: 900_000,
|
|
277
|
+
isConfigured: ({ cfg, agentDir }) => configured(id, cfg, agentDir),
|
|
278
|
+
capabilities: { generate: limits, imageToVideo: { ...limits, enabled: true, maxInputImages: ["seedance", "minimax", "grok"].includes(id) ? 9 : id === "veo" ? 3 : ["kling", "flux", "midjourney"].includes(id) ? 2 : 1 }, videoToVideo: { enabled: ["seedance", "minimax", "happyhorse", "wan", "flux"].includes(id), maxInputVideos: 1 } },
|
|
279
|
+
async generateVideo(req) {
|
|
280
|
+
const mapped = mapVideoRequest(id, req);
|
|
281
|
+
const result = await new ServiceClient(await resolveServiceKey(api, id, req.cfg)).complete(service, mapped.tool, mapped.params, req.timeoutMs ?? 900_000);
|
|
282
|
+
if (!result.media_urls.length)
|
|
283
|
+
throw new Error(`No video output in completed task ${result.task_id}.`);
|
|
284
|
+
return { videos: result.media_urls.map(url => ({ url, mimeType: "video/mp4" })), model: req.model, metadata: { taskId: result.task_id, traceId: result.trace_id } };
|
|
285
|
+
},
|
|
286
|
+
};
|
|
287
|
+
api.registerVideoGenerationProvider(provider);
|
|
288
|
+
catalog(api, provider.id, "video_generation", models, service.label, provider.capabilities);
|
|
289
|
+
}
|
|
290
|
+
const suno = serviceById("suno"), endpoint = suno.endpoints.suno_generate_audios;
|
|
291
|
+
const music = {
|
|
292
|
+
id: providerId("suno"), label: "Ace Data Cloud — Suno", models: operationModels(endpoint), defaultModel: String(endpoint.defaults?.model ?? "chirp-v6"),
|
|
293
|
+
isConfigured: ({ cfg, agentDir }) => configured("suno", cfg, agentDir),
|
|
294
|
+
capabilities: { generate: { maxTracks: 2, supportsLyrics: true, supportsInstrumental: true }, edit: { enabled: false } },
|
|
295
|
+
async generateMusic(req) {
|
|
296
|
+
exactModel(endpoint, req.model);
|
|
297
|
+
const result = await new ServiceClient(await resolveServiceKey(api, "suno", req.cfg)).complete(suno, "suno_generate_audios", { model: req.model, prompt: req.prompt, ...(req.lyrics ? { custom: true, lyric: req.lyrics } : {}), ...(req.instrumental !== undefined ? { instrumental: req.instrumental } : {}) }, req.timeoutMs ?? 900_000);
|
|
298
|
+
if (!result.media_urls.length)
|
|
299
|
+
throw new Error(`No music output in completed task ${result.task_id}.`);
|
|
300
|
+
let tracks;
|
|
301
|
+
try {
|
|
302
|
+
tracks = await Promise.all(result.media_urls.filter(url => /\.(mp3|wav|ogg|flac|m4a)(\?|$)/i.test(url)).map(url => downloadAsset(url, "audio")));
|
|
303
|
+
}
|
|
304
|
+
catch {
|
|
305
|
+
throw new Error(`Music task ${result.task_id || result.trace_id} completed but media delivery failed. Retrieve this task; do not regenerate.`);
|
|
306
|
+
}
|
|
307
|
+
if (!tracks.length)
|
|
308
|
+
throw new Error("No audio tracks in completed task.");
|
|
309
|
+
return { tracks, model: req.model, metadata: { taskId: result.task_id, traceId: result.trace_id } };
|
|
310
|
+
},
|
|
311
|
+
};
|
|
312
|
+
api.registerMusicGenerationProvider(music);
|
|
313
|
+
catalog(api, music.id, "music_generation", music.models ?? [], "Suno", music.capabilities);
|
|
314
|
+
api.registerSpeechProvider({
|
|
315
|
+
id: providerId("fish-audio"), label: "Ace Data Cloud — Fish Audio", defaultModel: "s2-pro", models: ["s1", "s2-pro", "s2.1-pro"], defaultTimeoutMs: 300_000,
|
|
316
|
+
resolveConfig: ({ rawConfig }) => {
|
|
317
|
+
const source = record(rawConfig);
|
|
318
|
+
const settings = record(record(source.providers)[providerId("fish-audio")] ?? source);
|
|
319
|
+
const allowed = new Set([...Object.keys(serviceById("fish-audio").endpoints.fish_generate_audio.properties), "model", "voice", "voiceId", "modelId", "responseFormat"]);
|
|
320
|
+
return { ...Object.fromEntries(Object.entries(settings).filter(([key]) => allowed.has(key))), model: settings.model ?? "s2-pro" };
|
|
321
|
+
},
|
|
322
|
+
resolveTalkOverrides: ({ params }) => ({ ...(params.voiceId ? { voice: params.voiceId } : {}), ...(params.modelId ? { model: params.modelId } : {}) }),
|
|
323
|
+
isConfigured: ({ cfg }) => configured("fish-audio", cfg),
|
|
324
|
+
async synthesize(req) {
|
|
325
|
+
const { apiKey: _key, ...settings } = req.providerConfig;
|
|
326
|
+
const merged = { ...settings, ...req.providerOverrides };
|
|
327
|
+
const { voice, modelId, voiceId, responseFormat, ...rest } = merged;
|
|
328
|
+
const params = { ...rest, ...(modelId ? { model: modelId } : {}), ...(voice || voiceId ? { reference_id: voice || voiceId } : {}), text: req.text, format: responseFormat ?? rest.format ?? "mp3" };
|
|
329
|
+
const result = await new ServiceClient(await resolveServiceKey(api, "fish-audio", req.cfg)).complete(serviceById("fish-audio"), "fish_generate_audio", params, req.timeoutMs);
|
|
330
|
+
if (!result.media_urls[0])
|
|
331
|
+
throw new Error(`No speech audio in completed task ${result.task_id}.`);
|
|
332
|
+
let asset;
|
|
333
|
+
try {
|
|
334
|
+
asset = await downloadAsset(result.media_urls[0], "audio");
|
|
335
|
+
}
|
|
336
|
+
catch {
|
|
337
|
+
throw new Error(`Speech task ${result.task_id || result.trace_id} completed but media delivery failed. Retrieve this task; do not synthesize again.`);
|
|
338
|
+
}
|
|
339
|
+
const format = String(params.format);
|
|
340
|
+
return { audioBuffer: asset.buffer, outputFormat: format, fileExtension: `.${format}`, voiceCompatible: false };
|
|
341
|
+
},
|
|
342
|
+
async listVoices(req) {
|
|
343
|
+
const result = await new ServiceClient(await resolveServiceKey(api, "fish-audio", req.cfg)).invoke(serviceById("fish-audio"), "fish_search_voices", { page_size: 20 });
|
|
344
|
+
const data = record(result.result);
|
|
345
|
+
const voices = data.items ?? data.data;
|
|
346
|
+
return Array.isArray(voices) ? voices.map(v => { const row = record(v); return { id: String(row._id ?? row.id), name: String(row.title ?? row.name ?? row._id ?? row.id) }; }) : [];
|
|
347
|
+
},
|
|
348
|
+
});
|
|
349
|
+
catalog(api, providerId("fish-audio"), "voice", ["s1", "s2-pro", "s2.1-pro"], "Fish Audio");
|
|
350
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Endpoint } from "./catalog.js";
|
|
2
|
+
type Values = Record<string, unknown>;
|
|
3
|
+
/** Service-specific aliases from the reviewed Dify contracts; no model substitution. */
|
|
4
|
+
export declare function adaptParameters(service: string, params: Values, endpoint: Endpoint): Values;
|
|
5
|
+
export declare function finalizePayload(service: string, body: Values, endpoint: Endpoint): Values;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
function required(body, fields) {
|
|
2
|
+
if (fields.some(k => body[k] === undefined || body[k] === "" || body[k] === null))
|
|
3
|
+
throw new Error(`Required inputs: ${fields.join(", ")}`);
|
|
4
|
+
}
|
|
5
|
+
/** Service-specific aliases from the reviewed Dify contracts; no model substitution. */
|
|
6
|
+
export function adaptParameters(service, params, endpoint) {
|
|
7
|
+
const p = { ...params };
|
|
8
|
+
if (service === "gpt-image") {
|
|
9
|
+
if (p.count !== undefined) {
|
|
10
|
+
p.n = p.count;
|
|
11
|
+
delete p.count;
|
|
12
|
+
}
|
|
13
|
+
if (p.image_urls !== undefined) {
|
|
14
|
+
const images = p.image_urls;
|
|
15
|
+
p.image = typeof images === "string" && !images.startsWith("data:") ? images.trim().startsWith("[") ? JSON.parse(images) : images.split("\n").filter(Boolean) : images;
|
|
16
|
+
delete p.image_urls;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if (service === "fish-audio" && endpoint.method === "GET" && endpoint.path === "/fish/model") {
|
|
20
|
+
if (p.query !== undefined) {
|
|
21
|
+
p.title = p.query;
|
|
22
|
+
delete p.query;
|
|
23
|
+
}
|
|
24
|
+
if (p.limit !== undefined) {
|
|
25
|
+
p.page_size = p.limit;
|
|
26
|
+
delete p.limit;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (service === "seedream") {
|
|
30
|
+
if (p.image_urls !== undefined && p.image === undefined) {
|
|
31
|
+
p.image = p.image_urls;
|
|
32
|
+
delete p.image_urls;
|
|
33
|
+
}
|
|
34
|
+
if (p.max_images !== undefined) {
|
|
35
|
+
p.sequential_image_generation_options = { max_images: p.max_images };
|
|
36
|
+
delete p.max_images;
|
|
37
|
+
}
|
|
38
|
+
if (p.optimize_prompt_mode) {
|
|
39
|
+
p.optimize_prompt_options = { mode: p.optimize_prompt_mode };
|
|
40
|
+
delete p.optimize_prompt_mode;
|
|
41
|
+
}
|
|
42
|
+
if (p.web_search) {
|
|
43
|
+
p.tools = [{ type: "web_search" }];
|
|
44
|
+
delete p.web_search;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (service === "happyhorse" && endpoint.path.endsWith("/videos") && !p.model) {
|
|
48
|
+
const models = { generate: "happyhorse-1.1-t2v", image_to_video: "happyhorse-1.1-i2v", reference_to_video: "happyhorse-1.1-r2v", video_edit: "happyhorse-1.0-video-edit" };
|
|
49
|
+
p.model = models[String(p.action ?? "generate")];
|
|
50
|
+
}
|
|
51
|
+
if (service === "seedance" && endpoint.path.endsWith("/videos")) {
|
|
52
|
+
if (p.camera_fixed !== undefined) {
|
|
53
|
+
p.camerafixed = p.camera_fixed;
|
|
54
|
+
delete p.camera_fixed;
|
|
55
|
+
}
|
|
56
|
+
if (p.image_url && !p.first_frame_url) {
|
|
57
|
+
p.first_frame_url = p.image_url;
|
|
58
|
+
delete p.image_url;
|
|
59
|
+
}
|
|
60
|
+
const helpers = ["prompt", "first_frame_url", "last_frame_url", "reference_image_urls", "reference_audio_urls", "reference_video_urls"];
|
|
61
|
+
if (p.content && helpers.some(k => p[k]))
|
|
62
|
+
throw new Error("Use content or prompt/reference shortcuts, not both.");
|
|
63
|
+
if (!p.content) {
|
|
64
|
+
const content = [];
|
|
65
|
+
if (p.prompt)
|
|
66
|
+
content.push({ type: "text", text: p.prompt });
|
|
67
|
+
for (const [key, type, role, many] of [
|
|
68
|
+
["first_frame_url", "image_url", "first_frame", false], ["last_frame_url", "image_url", "last_frame", false],
|
|
69
|
+
["reference_image_urls", "image_url", "reference_image", true], ["reference_audio_urls", "audio_url", "reference_audio", true], ["reference_video_urls", "video_url", "reference_video", true],
|
|
70
|
+
]) {
|
|
71
|
+
if (!p[key])
|
|
72
|
+
continue;
|
|
73
|
+
let urls = p[key];
|
|
74
|
+
if (many && typeof urls === "string")
|
|
75
|
+
urls = urls.trim().startsWith("[") ? JSON.parse(urls) : urls.split("\n").filter(Boolean);
|
|
76
|
+
if (many && !Array.isArray(urls))
|
|
77
|
+
throw new Error(`${key} must be an array.`);
|
|
78
|
+
for (const url of many ? urls : [urls])
|
|
79
|
+
content.push({ type, role, [type]: { url } });
|
|
80
|
+
}
|
|
81
|
+
if (!content.length)
|
|
82
|
+
throw new Error("A prompt or reference content is required.");
|
|
83
|
+
p.content = content;
|
|
84
|
+
}
|
|
85
|
+
for (const k of helpers)
|
|
86
|
+
delete p[k];
|
|
87
|
+
if (p.frames !== undefined && p.duration !== undefined)
|
|
88
|
+
throw new Error("Use frames or duration, not both.");
|
|
89
|
+
}
|
|
90
|
+
return p;
|
|
91
|
+
}
|
|
92
|
+
export function finalizePayload(service, body, endpoint) {
|
|
93
|
+
if (["nano-banana", "gpt-image"].includes(service) && endpoint.operation === "edit")
|
|
94
|
+
required(body, [service === "nano-banana" ? "image_urls" : "image"]);
|
|
95
|
+
if (service === "flux" && endpoint.path.endsWith("/images")) {
|
|
96
|
+
if (endpoint.operation === "edit") {
|
|
97
|
+
required(body, ["image_url"]);
|
|
98
|
+
if (!["flux-kontext-pro", "flux-kontext-max"].includes(String(body.model)))
|
|
99
|
+
throw new Error("Editing requires a Kontext model.");
|
|
100
|
+
}
|
|
101
|
+
if (String(body.model).startsWith("flux-kontext") && !["21:9", "16:9", "4:3", "3:2", "1:1", "2:3", "3:4", "9:16", "9:21"].includes(String(body.size)))
|
|
102
|
+
throw new Error("Kontext size must be an aspect ratio.");
|
|
103
|
+
}
|
|
104
|
+
if (service === "seedance" && body.frames !== undefined)
|
|
105
|
+
delete body.duration;
|
|
106
|
+
if (service === "seedream" && endpoint.path.endsWith("/images")) {
|
|
107
|
+
if (["edit", "decompose"].includes(endpoint.operation))
|
|
108
|
+
required(body, ["image"]);
|
|
109
|
+
if (endpoint.operation !== "decompose")
|
|
110
|
+
required(body, ["prompt"]);
|
|
111
|
+
if (body.model === "doubao-seedream-5-0-pro-260628") {
|
|
112
|
+
delete body.stream;
|
|
113
|
+
if ((Array.isArray(body.image) ? body.image : body.image ? [body.image] : []).length > 10)
|
|
114
|
+
throw new Error("Seedream Pro accepts at most 10 input images.");
|
|
115
|
+
if (body.sequential_image_generation === "auto" || body.tools)
|
|
116
|
+
throw new Error("Sequential generation and search require a supporting Lite model.");
|
|
117
|
+
}
|
|
118
|
+
else if (body.background || body.layer_decomposition)
|
|
119
|
+
throw new Error("Layer decomposition and background control require Seedream 5.0 Pro.");
|
|
120
|
+
if (body.layer_decomposition && body.background)
|
|
121
|
+
throw new Error("Layer decomposition and background control cannot be combined.");
|
|
122
|
+
if (body.background === "transparent")
|
|
123
|
+
body.output_format = "png";
|
|
124
|
+
}
|
|
125
|
+
if (service === "happyhorse" && endpoint.path.endsWith("/videos")) {
|
|
126
|
+
const action = String(body.action ?? "generate");
|
|
127
|
+
const modes = { generate: ["t2v", ["prompt"]], image_to_video: ["i2v", ["image_url"]], reference_to_video: ["r2v", ["prompt", "image_urls"]], video_edit: ["video-edit", ["prompt", "video_url"]] };
|
|
128
|
+
const mode = modes[action];
|
|
129
|
+
if (!mode || !String(body.model).endsWith(mode[0]))
|
|
130
|
+
throw new Error("Select a Happy Horse model matching the action.");
|
|
131
|
+
required(body, mode[1]);
|
|
132
|
+
if (["image_to_video", "video_edit"].includes(action))
|
|
133
|
+
delete body.ratio;
|
|
134
|
+
if (action === "video_edit")
|
|
135
|
+
delete body.duration;
|
|
136
|
+
}
|
|
137
|
+
if (service === "kling" && endpoint.path === "/kling/videos") {
|
|
138
|
+
if (body.action === "text2video")
|
|
139
|
+
required(body, ["prompt"]);
|
|
140
|
+
if (body.action === "image2video" && !body.start_image_url && !body.image_list)
|
|
141
|
+
throw new Error("Image-to-video requires a first frame or image list.");
|
|
142
|
+
if (body.action === "extend")
|
|
143
|
+
required(body, ["video_id"]);
|
|
144
|
+
}
|
|
145
|
+
if (service === "minimax" && body.resolution === "480P")
|
|
146
|
+
throw new Error("MiniMax H3 supports 768P and 2K.");
|
|
147
|
+
if (service === "suno" && endpoint.path === "/suno/audios") {
|
|
148
|
+
const action = String(body.action ?? "generate");
|
|
149
|
+
if (action === "generate") {
|
|
150
|
+
if (body.custom && !body.instrumental && !body.lyric && !body.lyric_prompt)
|
|
151
|
+
throw new Error("Custom vocal music requires lyrics or a lyric prompt.");
|
|
152
|
+
if (!body.custom)
|
|
153
|
+
required(body, ["prompt"]);
|
|
154
|
+
}
|
|
155
|
+
const needs = { extend: ["audio_id", "continue_at"], upload_extend: ["audio_id", "continue_at"], cover: ["audio_id"], concat: ["audio_id"], upload_cover: ["audio_id"], artist_consistency: ["persona_id"], artist_consistency_vox: ["persona_id"], remaster: ["audio_id"], stems: ["audio_id"], all_stems: ["audio_id"], add_stem: ["audio_id"], extract_stem: ["audio_id"], mashup: ["mashup_audio_ids"], sounds: ["sound"], adjust_speed: ["audio_id", "speed_multiplier"] };
|
|
156
|
+
required(body, needs[action] ?? []);
|
|
157
|
+
for (const prefix of ["replace_section", "underpainting", "overpainting", "samples"]) {
|
|
158
|
+
if (action === prefix)
|
|
159
|
+
required(body, ["audio_id", `${prefix}_start`, `${prefix}_end`]);
|
|
160
|
+
if (body[`${prefix}_start`] !== undefined && body[`${prefix}_end`] !== undefined && Number(body[`${prefix}_end`]) <= Number(body[`${prefix}_start`]))
|
|
161
|
+
throw new Error(`${prefix}_end must exceed its start.`);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return body;
|
|
165
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { OpenClawConfig, OpenClawPluginApi } from "openclaw/plugin-sdk/plugin-entry";
|
|
2
|
+
import { type Endpoint, type Schema } from "./catalog.js";
|
|
3
|
+
export declare function resolveServiceKey(api: OpenClawPluginApi, service: string, config?: OpenClawConfig): Promise<string>;
|
|
4
|
+
export declare function toolSchema(endpoint: Endpoint): Schema;
|
|
5
|
+
export declare function operationName(name: string): string;
|
|
6
|
+
export declare function registerServiceTools(api: OpenClawPluginApi): void;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { normalizeResolvedSecretInputString } from "openclaw/plugin-sdk/secret-input";
|
|
2
|
+
import { SERVICES } from "./catalog.js";
|
|
3
|
+
import { ServiceClient, record } from "./client.js";
|
|
4
|
+
export async function resolveServiceKey(api, service, config) {
|
|
5
|
+
const entry = record(config?.plugins?.entries?.acedatacloud?.config);
|
|
6
|
+
const credential = record(record(entry.serviceCredentials)[service]).apiKey;
|
|
7
|
+
if (credential !== undefined) {
|
|
8
|
+
const key = normalizeResolvedSecretInputString({ value: credential, path: `plugins.entries.acedatacloud.config.serviceCredentials.${service}.apiKey` });
|
|
9
|
+
if (!key?.trim())
|
|
10
|
+
throw new Error(`The ${service} credential is unresolved or empty.`);
|
|
11
|
+
return key;
|
|
12
|
+
}
|
|
13
|
+
const auth = await api.runtime.modelAuth.resolveApiKeyForProvider({ provider: "acedatacloud", cfg: config });
|
|
14
|
+
if (!auth.apiKey)
|
|
15
|
+
throw new Error("Configure an Ace Data Cloud API key with access to this service.");
|
|
16
|
+
return auth.apiKey;
|
|
17
|
+
}
|
|
18
|
+
export function toolSchema(endpoint) {
|
|
19
|
+
const properties = {};
|
|
20
|
+
const required = [];
|
|
21
|
+
for (const input of endpoint.tool?.input ?? []) {
|
|
22
|
+
// Accept native structured tool input, retaining Dify convenience parameters.
|
|
23
|
+
properties[input.name] = endpoint.properties[input.name] ?? input.schema;
|
|
24
|
+
if (input.required && !(input.name in (endpoint.defaults ?? {})))
|
|
25
|
+
required.push(input.name);
|
|
26
|
+
}
|
|
27
|
+
for (const [name, schema] of Object.entries(endpoint.properties)) {
|
|
28
|
+
if (!(name in (endpoint.fixed ?? {})) && !["async", "stream", "callback_url"].includes(name))
|
|
29
|
+
properties[name] ??= schema;
|
|
30
|
+
}
|
|
31
|
+
for (const p of endpoint.parameters ?? []) {
|
|
32
|
+
const key = p.name.toLowerCase() === "idempotency-key" ? "idempotency_key" : p.name;
|
|
33
|
+
properties[key] ??= p.schema;
|
|
34
|
+
if (p.required && !required.includes(key))
|
|
35
|
+
required.push(key);
|
|
36
|
+
}
|
|
37
|
+
return { type: "object", properties, ...(required.length ? { required } : {}), additionalProperties: false };
|
|
38
|
+
}
|
|
39
|
+
export function operationName(name) { return `acedata_${name}`; }
|
|
40
|
+
export function registerServiceTools(api) {
|
|
41
|
+
const entries = SERVICES.flatMap(service => Object.entries(service.endpoints).filter(([name]) => !name.includes(":")).map(([name, endpoint]) => ({ service, name, endpoint })));
|
|
42
|
+
for (const { service, name, endpoint } of entries) {
|
|
43
|
+
api.registerTool(ctx => {
|
|
44
|
+
const nameInHost = operationName(name);
|
|
45
|
+
return {
|
|
46
|
+
name: nameInHost, label: endpoint.tool?.label ?? `${service.label}: ${name}`,
|
|
47
|
+
description: `${endpoint.tool?.description ?? name} Uses Ace Data Cloud credits for billable operations. Prompts and reference URLs are sent to api.acedata.cloud. Preserve pending task IDs; do not repeat creation requests.`,
|
|
48
|
+
parameters: toolSchema(endpoint),
|
|
49
|
+
async execute(_id, args, signal) {
|
|
50
|
+
const config = ctx.getRuntimeConfig?.() ?? ctx.runtimeConfig ?? ctx.config;
|
|
51
|
+
const serviceKey = record(record(record(config?.plugins?.entries?.acedatacloud?.config).serviceCredentials)[service.id]).apiKey;
|
|
52
|
+
const key = serviceKey !== undefined ? await resolveServiceKey(api, service.id, config) : await ctx.resolveApiKeyForProvider?.("acedatacloud") ?? await resolveServiceKey(api, service.id, config);
|
|
53
|
+
const result = await new ServiceClient(key).invoke(service, name, record(args), signal);
|
|
54
|
+
return { content: [{ type: "text", text: JSON.stringify(result) }], details: result };
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}, { name: operationName(name), optional: true });
|
|
58
|
+
}
|
|
59
|
+
}
|