import { z } from "zod";
import { makeApiRequest } from "../api.js";
import _ from 'lodash'
/**
* Tool to get all projects for a specific workspace.
*/
export const getAllProjectsTool = {
name: "clockify-getAllProjects",
config: {
description: `
Get all projects for a specific workspace.
PREREQUISITE: clockify:whoami tool must be called first.
`,
inputSchema: {
workspaceId: z.string().describe(`The unique identifier for the workspace from which to retrieve projects. This ID is essential for fetching the projects associated with a user.`)
},
outputSchema: {
projects: z.array(z.object({
id: z.string().describe("This is the unique identifier for the project. use this id to log time against a project"),
name: z.string().describe("The name of the project"),
clientName: z.string().describe("The name of the client associated with the project")
}))
}
},
handler: async (input) => {
const { workspaceId } = input;
const result = await makeApiRequest(`/workspaces/${workspaceId}/projects`);
const structuredContent = {
projects: _.map(result, payload => _.pick(payload, ['id', 'name', 'clientName']))
}
return {
structuredContent: structuredContent || [],
content: [{
type: "text",
text: JSON.stringify({ structuredContent }, null, 2)
}]
};
}
};