import { createLogger } from "../utils/logger.js";
const log = createLogger("resource:execution-summary");
export function registerExecutionSummaryResource(server, registry, client, config) {
    server.registerResource("execution-summary", "executions:///recent", {
        title: "Recent Executions",
        description: "Recent pipeline execution summaries (last 10).",
        mimeType: "application/json",
    }, async (uri) => {
        try {
            log.info("Fetching recent executions");
            const result = await registry.dispatch(client, "execution", "list", {
                org_id: config.HARNESS_ORG,
                project_id: config.HARNESS_PROJECT ?? "",
                size: 10,
                page: 0,
            }, { tool: "execution_summary_resource" });
            return {
                contents: [{
                        uri: uri.href,
                        mimeType: "application/json",
                        text: JSON.stringify(result, null, 2),
                    }],
            };
        }
        catch (err) {
            log.warn("Failed to fetch recent executions", { error: String(err) });
            return {
                contents: [{
                        uri: uri.href,
                        mimeType: "application/json",
                        text: JSON.stringify({ error: String(err), items: [] }, null, 2),
                    }],
            };
        }
    });
}
//# sourceMappingURL=execution-summary.js.map