import { SchemaBasedCommand, CommandSchema } from "../SchemaBasedCommand"; import { TaskContext, TaskResponse } from "../types"; const schema: CommandSchema = { type: "object", title: "math", description: "execute some javascript code to calculate a value", properties: { code: { type: "string", description: "javascript expression to evaluate" } }, required: ["code"], returns: "the calculated value" }; export interface MathCommandInput { code: string; } export class MathCommand extends SchemaBasedCommand { public constructor(title?: string, description?: string) { super(schema, title, description); } public execute(context: TaskContext, input: MathCommandInput): Promise { try { return Promise.resolve(eval(input.code)); } catch (err: unknown) { // Give feedback to the model that it wrote bad code const message = (err as any).toString(); return Promise.resolve({ type: 'TaskResponse', status: 'error', message }); } } }