"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getWorkspacesOutputSchema = void 0;
const zod_1 = require("zod");
const mcpMablTool_1 = require("./mcpMablTool");
const common_1 = require("../utils/common");
exports.getWorkspacesOutputSchema = zod_1.z.object({
    workspaces: zod_1.z.array(zod_1.z.object({
        id: zod_1.z.string().describe('The workspace ID'),
        name: zod_1.z.string().describe('The workspace name'),
    })),
    currentWorkspaceId: zod_1.z.string().describe('The currently active workspace ID'),
});
const getWorkspaces = (0, mcpMablTool_1.defineTool)({
    schema: {
        name: 'get_workspaces',
        title: 'Get all available workspaces',
        description: "Get all of the workspaces that the user has access to, or get the current workspace. Example: What's my current mabl workspace?",
        inputSchema: zod_1.z.object({
            limit: zod_1.z
                .number()
                .optional()
                .describe('The maximum number of workspaces to return (default: 50)'),
        }),
        outputSchema: exports.getWorkspacesOutputSchema,
        type: 'readOnly',
    },
    handle: async (args, context) => {
        const { mablApiClient, workspaceId } = context.getCurrentContext();
        const limit = args.limit || 50;
        const workspaces = await mablApiClient.getWorkspaces(limit);
        const workspaceList = workspaces.map((workspace) => ({
            id: workspace.id,
            name: workspace.name,
        }));
        return {
            content: [
                {
                    type: 'text',
                    text: (0, common_1.jsonPrettyPrint)({
                        workspaces: workspaceList,
                        currentWorkspaceId: workspaceId,
                    }),
                },
            ],
            structuredContent: {
                workspaces: workspaceList,
                currentWorkspaceId: workspaceId,
            },
        };
    },
});
exports.default = [getWorkspaces];
