From 04dcb17763925e781062388ea43bbb663e7694c4 Mon Sep 17 00:00:00 2001 From: Abu Bakkar Siddique Date: Thu, 8 May 2025 20:08:57 +0530 Subject: [PATCH] Autofixing errors whenever there is an error generated --- apps/studio/src/lib/editor/engine/error/index.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/apps/studio/src/lib/editor/engine/error/index.ts b/apps/studio/src/lib/editor/engine/error/index.ts index 0a1f7100a0..6f142b836c 100644 --- a/apps/studio/src/lib/editor/engine/error/index.ts +++ b/apps/studio/src/lib/editor/engine/error/index.ts @@ -1,6 +1,6 @@ import type { ProjectsManager } from '@/lib/projects'; import { type ParsedError, compareErrors } from '@onlook/utility'; -import { makeAutoObservable } from 'mobx'; +import { autorun, makeAutoObservable } from 'mobx'; import type { EditorEngine } from '..'; export class ErrorManager { @@ -13,13 +13,23 @@ export class ErrorManager { private editorEngine: EditorEngine, private projectsManager: ProjectsManager, ) { - makeAutoObservable(this, {}); + makeAutoObservable(this); + + autorun(() => { + if (this.shouldAutoFixErrors) { + this.sendFixError(); + } + }); } get errors() { return [...this.terminalErrors]; } + get shouldAutoFixErrors() { + return this.errors.length > 0 && !this.editorEngine.chat.isWaiting; + } + async sendFixError() { if (this.errors.length > 0) { const res = await this.editorEngine.chat.sendFixErrorToAi(this.errors);