mirror of
https://github.com/penpot/penpot-mcp.git
synced 2026-04-25 11:18:37 +00:00
Make ExecuteCodeTaskHandler use async functions by default
facilitating calls to async functions (also triggered by the LLM)
This commit is contained in:
parent
3f7153c7e4
commit
094e436d80
@ -175,7 +175,7 @@ export class ExecuteCodeTaskHandler extends TaskHandler<ExecuteCodeTaskParams> {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
// initialize context, making penpot object available with custom console
|
||||
// initialize context, making penpot, penpotUtils, storage and the custom console available
|
||||
this.context = {
|
||||
penpot: penpot,
|
||||
storage: {},
|
||||
@ -195,16 +195,11 @@ export class ExecuteCodeTaskHandler extends TaskHandler<ExecuteCodeTaskParams> {
|
||||
const context = this.context;
|
||||
const code = task.params.code;
|
||||
|
||||
let result: any = (function (ctx) {
|
||||
return Function(...Object.keys(ctx), code)(...Object.values(ctx));
|
||||
let result: any = await (async (ctx) => {
|
||||
const fn = new Function(...Object.keys(ctx), `return (async () => { ${code} })();`);
|
||||
return fn(...Object.values(ctx));
|
||||
})(context);
|
||||
|
||||
// if the result is a Promise, await it
|
||||
if (result instanceof Promise) {
|
||||
console.log("Code execution returned a Promise, awaiting result...");
|
||||
result = await result;
|
||||
}
|
||||
|
||||
console.log("Code execution result:", result);
|
||||
|
||||
// return result and captured log
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user