Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | 3x 3x 3x 3x 3x 3x 3x 7x 5x 5x 5x 5x 12x 7x 5x 5x 4x 1x 3x 3x 2x 2x 2x 2x 2x 2x 1x 1x 1x 3x 3x 3x 3x 3x 10x 7x 3x 3x 3x 1x 2x 2x 2x 2x 2x 2x 2x 8x 4x 2x 2x 2x 1x 1x 1x 2x 2x 2x 2x 2x 2x 1x 1x 1x 3x 18x 3x 6x 3x 7x 5x 25x 2x | /* eslint-disable @typescript-eslint/no-unsafe-assignment */ import { zodToJsonSchema } from "zod-to-json-schema"; import { ListWikiPagesSchema, GetWikiPageSchema } from "./schema-readonly"; import { CreateWikiPageSchema, UpdateWikiPageSchema, DeleteWikiPageSchema } from "./schema"; import { enhancedFetch } from "../../utils/fetch"; import { cleanGidsFromObject } from "../../utils/idConversion"; import { resolveNamespaceForAPI } from "../../utils/namespace"; import { ToolRegistry, EnhancedToolDefinition } from "../../types"; /** * Wiki tools registry - unified registry containing all wiki operation tools with their handlers */ export const wikiToolRegistry: ToolRegistry = new Map<string, EnhancedToolDefinition>([ // Read-only tools [ "list_wiki_pages", { name: "list_wiki_pages", description: "BROWSE: Explore all wiki pages in project or group documentation. Use when: Discovering available guides and documentation, Understanding project knowledge base structure, Finding existing pages before creating new ones. Wiki provides collaborative documentation separate from code repository. Returns page titles, slugs, content formats, and creation dates.", inputSchema: zodToJsonSchema(ListWikiPagesSchema), handler: async (args: unknown): Promise<unknown> => { const options = ListWikiPagesSchema.parse(args); const { namespace } = options; // Resolve namespace type and get proper API path const { entityType, encodedPath } = await resolveNamespaceForAPI(namespace); const queryParams = new URLSearchParams(); Object.entries(options).forEach(([key, value]) => { if (value !== undefined && value !== null && key !== "namespace") { queryParams.set(key, String(value)); } }); const apiUrl = `${process.env.GITLAB_API_URL}/api/v4/${entityType}/${encodedPath}/wikis?${queryParams}`; const response = await enhancedFetch(apiUrl, { headers: { Authorization: `Bearer ${process.env.GITLAB_TOKEN}`, }, }); if (!response.ok) { throw new Error(`GitLab API error: ${response.status} ${response.statusText}`); } const wikiPages = await response.json(); return cleanGidsFromObject(wikiPages); }, }, ], [ "get_wiki_page", { name: "get_wiki_page", description: "READ: Get complete wiki page content and metadata by slug. Use when: Reading technical documentation and guides, Accessing project knowledge base content, Getting full markdown with formatting. Returns complete page content, metadata, edit history, and author information. Perfect for content analysis and documentation review.", inputSchema: zodToJsonSchema(GetWikiPageSchema), handler: async (args: unknown): Promise<unknown> => { const options = GetWikiPageSchema.parse(args); const { namespace, slug } = options; // Resolve namespace type and get proper API path const { entityType, encodedPath } = await resolveNamespaceForAPI(namespace); const apiUrl = `${process.env.GITLAB_API_URL}/api/v4/${entityType}/${encodedPath}/wikis/${encodeURIComponent(slug)}`; const response = await enhancedFetch(apiUrl, { headers: { Authorization: `Bearer ${process.env.GITLAB_TOKEN}`, }, }); if (!response.ok) { throw new Error(`GitLab API error: ${response.status} ${response.statusText}`); } const wikiPage = await response.json(); return cleanGidsFromObject(wikiPage); }, }, ], // Write tools [ "create_wiki_page", { name: "create_wiki_page", description: "CREATE: Add new documentation page to project or group wiki. Use when: Adding technical documentation, user guides, or FAQs, Creating project knowledge base content, Establishing team documentation standards. Check list_wiki_pages FIRST to avoid duplicate topics. Supports GitLab Flavored Markdown with extensions. Creates version-controlled documentation.", inputSchema: zodToJsonSchema(CreateWikiPageSchema), handler: async (args: unknown): Promise<unknown> => { const options = CreateWikiPageSchema.parse(args); const { namespace } = options; // Resolve namespace type and get proper API path const { entityType, encodedPath } = await resolveNamespaceForAPI(namespace); const body: Record<string, unknown> = {}; Object.entries(options).forEach(([key, value]) => { if (value !== undefined && value !== null && key !== "namespace") { body[key] = value; } }); const apiUrl = `${process.env.GITLAB_API_URL}/api/v4/${entityType}/${encodedPath}/wikis`; const response = await enhancedFetch(apiUrl, { method: "POST", headers: { Authorization: `Bearer ${process.env.GITLAB_TOKEN}`, "Content-Type": "application/json", }, body: JSON.stringify(body), }); if (!response.ok) { throw new Error(`GitLab API error: ${response.status} ${response.statusText}`); } const wikiPage = await response.json(); return cleanGidsFromObject(wikiPage); }, }, ], [ "update_wiki_page", { name: "update_wiki_page", description: "UPDATE: Modify existing wiki page content or properties. Use when: Updating documentation with new information, Fixing errors or improving clarity, Reorganizing content structure. Maintains complete version history with change tracking. Supports collaborative editing with author attribution and diff viewing.", inputSchema: zodToJsonSchema(UpdateWikiPageSchema), handler: async (args: unknown): Promise<unknown> => { const options = UpdateWikiPageSchema.parse(args); const { namespace, slug } = options; // Resolve namespace type and get proper API path const { entityType, encodedPath } = await resolveNamespaceForAPI(namespace); const body: Record<string, unknown> = {}; Object.entries(options).forEach(([key, value]) => { if (value !== undefined && value !== null && key !== "namespace" && key !== "slug") { body[key] = value; } }); const apiUrl = `${process.env.GITLAB_API_URL}/api/v4/${entityType}/${encodedPath}/wikis/${encodeURIComponent(slug)}`; const response = await enhancedFetch(apiUrl, { method: "PUT", headers: { Authorization: `Bearer ${process.env.GITLAB_TOKEN}`, "Content-Type": "application/json", }, body: JSON.stringify(body), }); if (!response.ok) { throw new Error(`GitLab API error: ${response.status} ${response.statusText}`); } const wikiPage = await response.json(); return cleanGidsFromObject(wikiPage); }, }, ], [ "delete_wiki_page", { name: "delete_wiki_page", description: "DELETE: Permanently remove wiki page from documentation. Use when: Cleaning up outdated or obsolete content, Removing duplicate or incorrect pages, Reorganizing wiki structure. WARNING: Deletes page and ALL version history permanently - cannot be undone. Consider archiving important content first.", inputSchema: zodToJsonSchema(DeleteWikiPageSchema), handler: async (args: unknown): Promise<unknown> => { const options = DeleteWikiPageSchema.parse(args); const { namespace, slug } = options; // Resolve namespace type and get proper API path const { entityType, encodedPath } = await resolveNamespaceForAPI(namespace); const apiUrl = `${process.env.GITLAB_API_URL}/api/v4/${entityType}/${encodedPath}/wikis/${encodeURIComponent(slug)}`; const response = await enhancedFetch(apiUrl, { method: "DELETE", headers: { Authorization: `Bearer ${process.env.GITLAB_TOKEN}`, }, }); if (!response.ok) { throw new Error(`GitLab API error: ${response.status} ${response.statusText}`); } // Wiki deletion may return empty response const result = response.status === 204 ? { deleted: true } : await response.json(); return cleanGidsFromObject(result); }, }, ], ]); /** * Get read-only tool names from the registry */ export function getWikiReadOnlyToolNames(): string[] { return ["list_wiki_pages", "get_wiki_page"]; } /** * Get all tool definitions from the registry (for backward compatibility) */ export function getWikiToolDefinitions(): EnhancedToolDefinition[] { return Array.from(wikiToolRegistry.values()); } /** * Get filtered tools based on read-only mode */ export function getFilteredWikiTools(readOnlyMode: boolean = false): EnhancedToolDefinition[] { if (readOnlyMode) { const readOnlyNames = getWikiReadOnlyToolNames(); return Array.from(wikiToolRegistry.values()).filter(tool => readOnlyNames.includes(tool.name)); } return getWikiToolDefinitions(); } |