mirror of
https://github.com/penpot/penpot-mcp.git
synced 2026-04-25 11:18:37 +00:00
Apply formatter
This commit is contained in:
parent
c3ae05c8fc
commit
f0b25c1052
@ -9,7 +9,11 @@ export class Task<TParams = any> {
|
||||
* @param taskType The type of the task to execute
|
||||
* @param params Task parameters/arguments
|
||||
*/
|
||||
constructor(public requestId: string, public taskType: string, public params: TParams) {}
|
||||
constructor(
|
||||
public requestId: string,
|
||||
public taskType: string,
|
||||
public params: TParams
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Sends a task response back to the MCP server.
|
||||
@ -70,4 +74,4 @@ export abstract class TaskHandler<TParams = any> {
|
||||
* @param task - The task to be handled
|
||||
*/
|
||||
abstract handle(task: Task<TParams>): void;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,14 +1,11 @@
|
||||
import {PrintTextTaskHandler} from "./task-handlers/PrintTextTaskHandler";
|
||||
import {ExecuteCodeTaskHandler} from "./task-handlers/ExecuteCodeTaskHandler";
|
||||
import {Task, TaskHandler} from "./TaskHandler";
|
||||
import { PrintTextTaskHandler } from "./task-handlers/PrintTextTaskHandler";
|
||||
import { ExecuteCodeTaskHandler } from "./task-handlers/ExecuteCodeTaskHandler";
|
||||
import { Task, TaskHandler } from "./TaskHandler";
|
||||
|
||||
/**
|
||||
* Registry of all available task handlers.
|
||||
*/
|
||||
const taskHandlers: TaskHandler[] = [
|
||||
new PrintTextTaskHandler(),
|
||||
new ExecuteCodeTaskHandler(),
|
||||
];
|
||||
const taskHandlers: TaskHandler[] = [new PrintTextTaskHandler(), new ExecuteCodeTaskHandler()];
|
||||
|
||||
penpot.ui.open("Penpot MCP Plugin", `?theme=${penpot.theme}`);
|
||||
|
||||
@ -45,7 +42,7 @@ function handlePluginTaskRequest(request: { id: string; task: string; params: an
|
||||
const task = new Task(request.id, request.task, request.params);
|
||||
|
||||
// Find the appropriate handler
|
||||
const handler = taskHandlers.find(h => h.isApplicableTo(task));
|
||||
const handler = taskHandlers.find((h) => h.isApplicableTo(task));
|
||||
|
||||
if (handler) {
|
||||
try {
|
||||
@ -71,7 +68,6 @@ function handlePluginTaskRequest(request: { id: string; task: string; params: an
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Update the theme in the iframe
|
||||
penpot.on("themechange", (theme) => {
|
||||
penpot.ui.sendMessage({
|
||||
|
||||
@ -1,14 +1,14 @@
|
||||
import {Task, TaskHandler} from "../TaskHandler";
|
||||
import {ExecuteCodeTaskParams} from "../../../common/src";
|
||||
import { Task, TaskHandler } from "../TaskHandler";
|
||||
import { ExecuteCodeTaskParams } from "../../../common/src";
|
||||
|
||||
/**
|
||||
* Task handler for executing JavaScript code in the plugin context.
|
||||
*
|
||||
*
|
||||
* Maintains a persistent context object that preserves state between code executions.
|
||||
*/
|
||||
export class ExecuteCodeTaskHandler extends TaskHandler<ExecuteCodeTaskParams> {
|
||||
readonly taskType = "executeCode";
|
||||
|
||||
|
||||
/**
|
||||
* Persistent context object that maintains state between code executions.
|
||||
* Contains the penpot API and any variables defined in executed code.
|
||||
@ -21,7 +21,7 @@ export class ExecuteCodeTaskHandler extends TaskHandler<ExecuteCodeTaskParams> {
|
||||
// initialize context, making penpot object available
|
||||
this.context = {
|
||||
penpot: penpot,
|
||||
storage: {}
|
||||
storage: {},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import {Task, TaskHandler} from "../TaskHandler";
|
||||
import {PrintTextTaskParams} from "../../../common/src";
|
||||
import { Task, TaskHandler } from "../TaskHandler";
|
||||
import { PrintTextTaskParams } from "../../../common/src";
|
||||
|
||||
/**
|
||||
* Task handler for printing text to Penpot.
|
||||
@ -28,4 +28,4 @@ export class PrintTextTaskHandler extends TaskHandler<PrintTextTaskParams> {
|
||||
throw new Error("Failed to create text element");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user