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:
2026-11-11 11:34:43 +05:30
parent 1e675d56fa
commit 6c268adbf6
87 changed files with 28466 additions and 2383 deletions
+41 -8
View File
@@ -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);