import { z } from "zod";
import { makeApiRequest } from "../api.js";
const logTimeEntrySchema = {
date: z.string().describe("Date for the time entry"),
description: z.string().describe("Description of the work performed"),
projectId: z.string().describe("ID of the project to log time against"),
workspaceId: z.string().describe("ID of the workspace"),
}
export const logTimeEntryTool = {
name: "clockify-logTimeEntry",
config: {
description: `
Log a time entry in Clockify for a given date and project.
PREREQUISITE: clockify:whoami tool must be called first to get the workspace id.
REQUIRES: clockify:getAllProjects tool must be called first to get the project id.
`,
inputSchema: logTimeEntrySchema
},
handler: async (input) => {
const { date, description, projectId, workspaceId} = input;
const parsedDate = new Date(date);
const startDateTime = new Date(parsedDate.setUTCHours(3, 30, 0, 0)).toISOString();
const endDateTime = new Date(parsedDate.setUTCHours(11, 30, 0, 0)).toISOString();
const timeEntry = {
description,
projectId,
start: startDateTime,
end: endDateTime,
type: "REGULAR",
};
const result = await makeApiRequest(`/workspaces/${workspaceId}/time-entries`, "POST", timeEntry);
return {
content: [{
type: "text",
text: JSON.stringify(result, null, 2)
}]
};
}
};