import { type } from "arktype"; import type { ToolContext } from "./server.ts"; import { execute, tool } from "./shared.ts"; interface GiteaComment { id: number; body?: string | null; user?: { login?: string } } export const GetIssueComments = type({ issue_number: type.number.describe("The issue number to get comments for"), }); export function GetIssueCommentsTool(ctx: ToolContext) { return tool({ name: "get_issue_comments", description: "Get all comments for a Gitea issue or PR. Example: `get_issue_comments({ issue_number: 1234 })`.", parameters: GetIssueComments, execute: execute(async ({ issue_number }) => { ctx.toolState.issueNumber = issue_number; const r = await ctx.gitea.request( "GET /repos/{owner}/{repo}/issues/{index}/comments", { owner: ctx.repo.owner, repo: ctx.repo.name, index: issue_number, limit: 50 } ); const comments = r.data as GiteaComment[]; return { issue_number, comments: comments.map((c) => ({ id: c.id, body: c.body, user: c.user?.login })), count: comments.length, }; }), }); }