fix: update tool installation checks and refactor stdout JSON parsing in AI modules

This commit is contained in:
ashim-hq
2026-04-19 12:13:26 +08:00
parent dc7ba119f8
commit 12c4d4de6f
14 changed files with 43 additions and 39 deletions
+1 -1
View File
@@ -100,7 +100,7 @@ export function isFeatureInstalled(bundleId: string): boolean {
export function isToolInstalled(toolId: string): boolean {
const bundleId = TOOL_BUNDLE_MAP[toolId];
if (!bundleId) return false;
if (!bundleId) return true;
return isFeatureInstalled(bundleId);
}
+11 -12
View File
@@ -32,6 +32,17 @@ const settingsSchema = z.object({
*/
export function registerRestorePhoto(app: FastifyInstance) {
app.post("/api/v1/tools/restore-photo", async (request: FastifyRequest, reply: FastifyReply) => {
if (!isToolInstalled("restore-photo")) {
const bundle = getBundleForTool("restore-photo");
return reply.status(501).send({
error: "Feature not installed",
code: "FEATURE_NOT_INSTALLED",
feature: "photo-restoration",
featureName: bundle?.name ?? "Photo Restoration",
estimatedSize: bundle?.estimatedSize ?? "unknown",
});
}
let fileBuffer: Buffer | null = null;
let filename = "image";
let settingsRaw: string | null = null;
@@ -69,18 +80,6 @@ export function registerRestorePhoto(app: FastifyInstance) {
return reply.status(400).send({ error: `Invalid image: ${validation.reason}` });
}
// Guard: check if the photo restoration feature bundle is installed
if (!isToolInstalled("restore-photo")) {
const bundle = getBundleForTool("restore-photo");
return reply.status(501).send({
error: "Feature not installed",
code: "FEATURE_NOT_INSTALLED",
feature: "photo-restoration",
featureName: bundle?.name ?? "Photo Restoration",
estimatedSize: bundle?.estimatedSize ?? "unknown",
});
}
try {
const settings = settingsSchema.parse(settingsRaw ? JSON.parse(settingsRaw) : {});