diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index cd200cb1a..c08ac35fd 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -200,9 +200,16 @@ eventConfirmationTitle = data.title; eventConfirmationMessage = data.message; } else if (type === 'execute') { + eventCallback = cb; + try { // Use Function constructor to evaluate code in a safer way - new Function(data.code)(); + const asyncFunction = new Function(`return (async () => { ${data.code} })()`); + const result = await asyncFunction(); // Await the result of the async function + + if (cb) { + cb(result); + } } catch (error) { console.error('Error executing code:', error); }