feat(tools): implement all real endpoints from Golang_Backend and API docs with 40 real tools across 5 dynamic page archetypes
This commit is contained in:
@@ -101,24 +101,57 @@ export async function executeBackendTryIt(
|
||||
const formData = new FormData();
|
||||
const blob = new Blob([new Uint8Array(imageBuffer)]);
|
||||
|
||||
// Find file parameter name (e.g. 'image' or 'image0')
|
||||
const fileParam = endpoint.params.find((p) => p.kind === 'file') || { name: 'image' };
|
||||
// Find primary file parameter name (e.g. 'image', 'image0', 'original_image')
|
||||
const fileParam = endpoint.params.find(
|
||||
(p) => p.kind === 'file' && !p.name.toLowerCase().includes('mask') && !p.name.toLowerCase().includes('ref')
|
||||
) || { name: 'image' };
|
||||
formData.append(fileParam.name, blob, filename);
|
||||
|
||||
// Inject Secret Key (PRD §7.11: Secrets never reach browser)
|
||||
const secretParam = endpoint.params.find((p) => p.isSecret);
|
||||
if (secretParam) {
|
||||
const secretVal = process.env.API_SECRET_DEFAULT || 'abcdef';
|
||||
formData.append(secretParam.name, secretVal);
|
||||
// If mask buffer provided (Inpainting / Custom Mask / Auto Mask)
|
||||
if (options.maskBuffer && Buffer.isBuffer(options.maskBuffer)) {
|
||||
const maskParam = endpoint.params.find(
|
||||
(p) => p.name.toLowerCase().includes('mask')
|
||||
) || { name: 'mask_image' };
|
||||
const maskBlob = new Blob([new Uint8Array(options.maskBuffer)]);
|
||||
formData.append(maskParam.name, maskBlob, options.maskFilename || 'mask.png');
|
||||
}
|
||||
|
||||
// Add options
|
||||
// If secondary image buffer provided (Two-Images: Face Swap, Blend Collage, Couple Outfits)
|
||||
if (options.secondaryBuffer && Buffer.isBuffer(options.secondaryBuffer)) {
|
||||
const secParam = endpoint.params.find(
|
||||
(p) => p.kind === 'file' && p.name !== fileParam.name && !p.name.toLowerCase().includes('mask')
|
||||
) || { name: 'reference_image' };
|
||||
const secBlob = new Blob([new Uint8Array(options.secondaryBuffer)]);
|
||||
formData.append(secParam.name, secBlob, options.secondaryFilename || 'reference.jpg');
|
||||
}
|
||||
|
||||
// Inject Secret Key (PRD §7.11: Secrets never reach browser)
|
||||
const secretParam = endpoint.params.find((p) => p.isSecret || p.name === 'secretKey');
|
||||
const secretVal = process.env.API_SECRET_DEFAULT || 'abcdef';
|
||||
if (secretParam) {
|
||||
formData.append(secretParam.name, secretVal);
|
||||
} else {
|
||||
formData.append('secretKey', secretVal);
|
||||
}
|
||||
|
||||
// Add options & preset mappings (colorId, effectId, style_id, prompt, dress, etc.)
|
||||
for (const [k, v] of Object.entries(options)) {
|
||||
if (k.endsWith('Buffer') || k.endsWith('Filename')) continue;
|
||||
if (typeof v === 'string' || typeof v === 'number' || typeof v === 'boolean') {
|
||||
formData.append(k, String(v));
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure effectId / colorId / style_id synchronization if provided in options
|
||||
const selectedEffect = options.style || options.effectId || options.colorId || options.effect_id;
|
||||
if (selectedEffect) {
|
||||
for (const targetKey of ['colorId', 'effectId', 'effect_id', 'style_id', 'artId']) {
|
||||
if (endpoint.params.some((p) => p.name === targetKey) && !formData.has(targetKey)) {
|
||||
formData.append(targetKey, String(selectedEffect));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const controller = new AbortController();
|
||||
const timeoutId = setTimeout(() => controller.abort(), endpoint.limits.timeoutMs || 60000);
|
||||
|
||||
|
||||
@@ -70,6 +70,21 @@ export function extractGroups(raw: any): any[] {
|
||||
}
|
||||
return raw;
|
||||
}
|
||||
// (b) Object with sections (e.g. data.json structure)
|
||||
if (raw && Array.isArray(raw.sections)) {
|
||||
const groups: any[] = [];
|
||||
for (const section of raw.sections) {
|
||||
if (Array.isArray(section.eps)) {
|
||||
for (const ep of section.eps) {
|
||||
groups.push({
|
||||
...ep,
|
||||
title: ep.title || ep.api_key || section.title,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
return groups;
|
||||
}
|
||||
// (b) Object with list under any key (apis, groups, data, etc.)
|
||||
for (const key of ['apis', 'groups', 'data', 'catalog', 'endpoints']) {
|
||||
if (Array.isArray(raw[key])) {
|
||||
|
||||
Reference in New Issue
Block a user