mirror of
https://github.com/jackwener/OpenCLI.git
synced 2026-09-14 18:25:42 +08:00
d2974a9ff6
* refactor(adapters): convert adapter layer from TypeScript to JavaScript Core framework stays TypeScript; adapter layer moves to JS-first. Adapters are essentially "executable config + browser scripts" that barely use TS features — this simplifies the build/distribution pipeline by removing the dist/clis/ intermediate compilation step. Changes: - Convert all 753 adapter files in clis/ from .ts to .js - Update tsconfig to exclude clis/ from compilation - Simplify build-manifest to scan clis/*.js directly (no dist/clis/) - Update discovery, main, fetch-adapters to load JS adapters from clis/ - Update generate-verified to output .js artifacts - Update package.json files field: dist/clis/ → clis/ - Fix all test files for the .ts → .js transition * fix(main): use findPackageRoot for BUILTIN_CLIS path The previous relative path (../../clis from __dirname) only worked for dist/src/main.js but broke dev mode (tsx src/main.ts) where __dirname is <repo>/src — resolving to /clis instead of <repo>/clis. Use findPackageRoot() which works for both dev and prod paths.
47 lines
2.1 KiB
JavaScript
47 lines
2.1 KiB
JavaScript
/**
|
|
* Yollomi virtual try-on — POST /api/ai/virtual-try-on
|
|
*/
|
|
import * as path from 'node:path';
|
|
import { cli, Strategy } from '@jackwener/opencli/registry';
|
|
import { CliError } from '@jackwener/opencli/errors';
|
|
import { log } from '@jackwener/opencli/logger';
|
|
import { YOLLOMI_DOMAIN, yollomiPost, downloadOutput, fmtBytes } from './utils.js';
|
|
cli({
|
|
site: 'yollomi',
|
|
name: 'try-on',
|
|
description: 'Virtual try-on — see how clothes look on a person (3 credits)',
|
|
domain: YOLLOMI_DOMAIN,
|
|
strategy: Strategy.COOKIE,
|
|
args: [
|
|
{ name: 'person', required: true, help: 'Person photo URL (upload via "opencli yollomi upload" first)' },
|
|
{ name: 'cloth', required: true, help: 'Clothing image URL' },
|
|
{ name: 'cloth-type', default: 'upper', choices: ['upper', 'lower', 'overall'], help: 'Clothing type' },
|
|
{ name: 'output', default: './yollomi-output', help: 'Output directory' },
|
|
{ name: 'no-download', type: 'boolean', default: false, help: 'Only show URL' },
|
|
],
|
|
columns: ['status', 'file', 'size', 'url'],
|
|
func: async (page, kwargs) => {
|
|
log.status('Processing virtual try-on...');
|
|
const data = await yollomiPost(page, '/api/ai/virtual-try-on', {
|
|
person_image: kwargs.person,
|
|
cloth_image: kwargs.cloth,
|
|
cloth_type: kwargs['cloth-type'],
|
|
output_format: 'png',
|
|
output_quality: 100,
|
|
});
|
|
const url = data.image || (data.images?.[0]);
|
|
if (!url)
|
|
throw new CliError('EMPTY_RESPONSE', 'No result', 'Check both images have clear subjects');
|
|
if (kwargs['no-download'])
|
|
return [{ status: 'generated', file: '-', size: '-', url }];
|
|
try {
|
|
const filename = `yollomi_tryon_${Date.now()}.png`;
|
|
const { path: fp, size } = await downloadOutput(url, kwargs.output, filename);
|
|
return [{ status: 'saved', file: path.relative('.', fp), size: fmtBytes(size), url }];
|
|
}
|
|
catch {
|
|
return [{ status: 'download-failed', file: '-', size: '-', url }];
|
|
}
|
|
},
|
|
});
|