src / index.ts
import { type PluginContext, tool } from "@lmstudio/sdk";
import { z } from "zod";
import { TodoManager } from "./todoManager";
const todoManager = new TodoManager();
// --- Tool Definitions ---
const listTodos = tool({
name: "readTodos",
description: "View the current todo list. Displays both pending and completed items.",
parameters: {},
implementation: async () => {
return todoManager.list();
},
});
const addTodo = tool({
name: "addTodo",
description: "Add a new task. Use this to remember things for later.",
parameters: {
task: z.string().describe("The task description"),
},
implementation: async ({ task }) => {
return todoManager.add(task);
},
});
const completeTodo = tool({
name: "completeTodo",
description: "Mark a task as completed (check it off). It remains in the list history but is marked done.",
parameters: {
id: z.number().describe("The numeric ID of the task (e.g. 1, 2)"),
},
implementation: async ({ id }) => {
return todoManager.complete(id);
},
});
const removeTodo = tool({
name: "removeTodo",
description: "Permanently delete a single task by its ID.",
parameters: {
id: z.number().describe("The ID to delete"),
},
implementation: async ({ id }) => {
return todoManager.remove(id);
},
});
const clearAllTodos = tool({
name: "clearAllTodos",
description: "DANGER: Delete ALL tasks (both pending and completed). Use only if the user explicitly asks to 'wipe', 'clear', or 'reset' the entire list.",
parameters: {},
implementation: async () => {
return todoManager.clear();
},
});
// --- Main Entry Point ---
export async function main(context: PluginContext) {
context.withToolsProvider(async () => {
return [listTodos, addTodo, completeTodo, removeTodo, clearAllTodos];
});
}