mirror of
https://github.com/penpot/penpot-mcp.git
synced 2026-05-24 09:23:53 +00:00
Make TaskHandler.handle async
This commit is contained in:
parent
fca9298d20
commit
4350f18ab3
@ -73,5 +73,5 @@ export abstract class TaskHandler<TParams = any> {
|
||||
*
|
||||
* @param task - The task to be handled
|
||||
*/
|
||||
abstract handle(task: Task<TParams>): void;
|
||||
abstract handle(task: Task<TParams>): Promise<void>;
|
||||
}
|
||||
|
||||
@ -28,7 +28,9 @@ penpot.ui.onMessage<string | { id: string; task: string; params: any }>((message
|
||||
|
||||
// New request-based message handling
|
||||
if (typeof message === "object" && message.task && message.id) {
|
||||
handlePluginTaskRequest(message);
|
||||
handlePluginTaskRequest(message).catch((error) => {
|
||||
console.error("Error in handlePluginTaskRequest:", error);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@ -37,7 +39,7 @@ penpot.ui.onMessage<string | { id: string; task: string; params: any }>((message
|
||||
*
|
||||
* @param request - The task request containing ID, task type and parameters
|
||||
*/
|
||||
function handlePluginTaskRequest(request: { id: string; task: string; params: any }): void {
|
||||
async function handlePluginTaskRequest(request: { id: string; task: string; params: any }): Promise<void> {
|
||||
console.log("Executing plugin task:", request.task, request.params);
|
||||
const task = new Task(request.id, request.task, request.params);
|
||||
|
||||
@ -48,7 +50,7 @@ function handlePluginTaskRequest(request: { id: string; task: string; params: an
|
||||
try {
|
||||
// Cast the params to the expected type and handle the task
|
||||
console.log("Processing task with handler:", handler);
|
||||
handler.handle(task);
|
||||
await handler.handle(task);
|
||||
|
||||
// check whether a response was sent and send a generic success if not
|
||||
if (!task.isResponseSent) {
|
||||
|
||||
@ -182,7 +182,7 @@ export class ExecuteCodeTaskHandler extends TaskHandler<ExecuteCodeTaskParams> {
|
||||
};
|
||||
}
|
||||
|
||||
handle(task: Task<ExecuteCodeTaskParams>): void {
|
||||
async handle(task: Task<ExecuteCodeTaskParams>): Promise<void> {
|
||||
if (!task.params.code) {
|
||||
task.sendError("executeCode task requires 'code' parameter");
|
||||
return;
|
||||
|
||||
@ -7,7 +7,7 @@ import { PrintTextTaskParams } from "../../../common/src";
|
||||
export class PrintTextTaskHandler extends TaskHandler<PrintTextTaskParams> {
|
||||
readonly taskType = "printText";
|
||||
|
||||
handle(task: Task<PrintTextTaskParams>): void {
|
||||
async handle(task: Task<PrintTextTaskParams>): Promise<void> {
|
||||
if (!task.params.text) {
|
||||
throw new Error("printText task requires 'text' parameter");
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user