From 457360dae70a4bc565e2f727a7570316e4829eb0 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Mon, 7 Oct 2024 22:53:36 -0700 Subject: [PATCH] refac --- src/lib/components/chat/Chat.svelte | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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); }