skrypt-ai 0.3.4 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/README.md +1 -1
  2. package/dist/auth/index.d.ts +0 -1
  3. package/dist/auth/index.js +3 -5
  4. package/dist/autofix/index.js +15 -3
  5. package/dist/cli.js +19 -4
  6. package/dist/commands/check-links.js +164 -174
  7. package/dist/commands/deploy.js +5 -2
  8. package/dist/commands/generate.js +206 -199
  9. package/dist/commands/i18n.js +3 -20
  10. package/dist/commands/init.js +47 -40
  11. package/dist/commands/lint.js +3 -20
  12. package/dist/commands/mcp.js +125 -122
  13. package/dist/commands/monitor.js +125 -108
  14. package/dist/commands/review-pr.js +1 -1
  15. package/dist/commands/sdk.js +1 -1
  16. package/dist/config/loader.js +21 -2
  17. package/dist/generator/organizer.d.ts +3 -0
  18. package/dist/generator/organizer.js +4 -9
  19. package/dist/generator/writer.js +2 -10
  20. package/dist/github/pr-comments.js +21 -8
  21. package/dist/plugins/index.js +1 -0
  22. package/dist/scanner/index.js +8 -2
  23. package/dist/template/docs.json +2 -1
  24. package/dist/template/next.config.mjs +2 -1
  25. package/dist/template/package.json +17 -15
  26. package/dist/template/public/favicon.svg +4 -0
  27. package/dist/template/public/search-index.json +1 -1
  28. package/dist/template/scripts/build-search-index.mjs +120 -25
  29. package/dist/template/src/app/api/chat/route.ts +11 -3
  30. package/dist/template/src/app/docs/README.md +28 -0
  31. package/dist/template/src/app/docs/[...slug]/page.tsx +139 -16
  32. package/dist/template/src/app/docs/auth/page.mdx +589 -0
  33. package/dist/template/src/app/docs/autofix/page.mdx +624 -0
  34. package/dist/template/src/app/docs/cli/page.mdx +217 -0
  35. package/dist/template/src/app/docs/config/page.mdx +428 -0
  36. package/dist/template/src/app/docs/configuration/page.mdx +86 -0
  37. package/dist/template/src/app/docs/deployment/page.mdx +112 -0
  38. package/dist/template/src/app/docs/error.tsx +20 -0
  39. package/dist/template/src/app/docs/generator/generator.md +504 -0
  40. package/dist/template/src/app/docs/generator/organizer.md +779 -0
  41. package/dist/template/src/app/docs/generator/page.mdx +613 -0
  42. package/dist/template/src/app/docs/github/page.mdx +502 -0
  43. package/dist/template/src/app/docs/llm/anthropic-client.md +549 -0
  44. package/dist/template/src/app/docs/llm/index.md +471 -0
  45. package/dist/template/src/app/docs/llm/page.mdx +428 -0
  46. package/dist/template/src/app/docs/llms-full.md +256 -0
  47. package/dist/template/src/app/docs/llms.txt +2971 -0
  48. package/dist/template/src/app/docs/not-found.tsx +23 -0
  49. package/dist/template/src/app/docs/page.mdx +0 -3
  50. package/dist/template/src/app/docs/plugins/page.mdx +1793 -0
  51. package/dist/template/src/app/docs/pro/page.mdx +121 -0
  52. package/dist/template/src/app/docs/quickstart/page.mdx +93 -0
  53. package/dist/template/src/app/docs/scanner/content-type.md +599 -0
  54. package/dist/template/src/app/docs/scanner/index.md +212 -0
  55. package/dist/template/src/app/docs/scanner/page.mdx +307 -0
  56. package/dist/template/src/app/docs/scanner/python.md +469 -0
  57. package/dist/template/src/app/docs/scanner/python_parser.md +1056 -0
  58. package/dist/template/src/app/docs/scanner/rust.md +325 -0
  59. package/dist/template/src/app/docs/scanner/typescript.md +201 -0
  60. package/dist/template/src/app/error.tsx +3 -3
  61. package/dist/template/src/app/icon.tsx +29 -0
  62. package/dist/template/src/app/layout.tsx +42 -0
  63. package/dist/template/src/app/not-found.tsx +35 -0
  64. package/dist/template/src/app/page.tsx +62 -28
  65. package/dist/template/src/components/ai-chat.tsx +26 -21
  66. package/dist/template/src/components/breadcrumbs.tsx +46 -2
  67. package/dist/template/src/components/copy-button.tsx +17 -3
  68. package/dist/template/src/components/docs-layout.tsx +142 -8
  69. package/dist/template/src/components/feedback.tsx +4 -2
  70. package/dist/template/src/components/footer.tsx +42 -0
  71. package/dist/template/src/components/header.tsx +29 -5
  72. package/dist/template/src/components/mdx/accordion.tsx +7 -6
  73. package/dist/template/src/components/mdx/card.tsx +19 -7
  74. package/dist/template/src/components/mdx/code-block.tsx +17 -3
  75. package/dist/template/src/components/mdx/code-group.tsx +65 -18
  76. package/dist/template/src/components/mdx/code-playground.tsx +3 -0
  77. package/dist/template/src/components/mdx/go-playground.tsx +3 -0
  78. package/dist/template/src/components/mdx/highlighted-code.tsx +171 -76
  79. package/dist/template/src/components/mdx/python-playground.tsx +2 -0
  80. package/dist/template/src/components/mdx/tabs.tsx +74 -6
  81. package/dist/template/src/components/page-header.tsx +19 -0
  82. package/dist/template/src/components/scroll-to-top.tsx +33 -0
  83. package/dist/template/src/components/search-dialog.tsx +206 -52
  84. package/dist/template/src/components/sidebar.tsx +136 -77
  85. package/dist/template/src/components/table-of-contents.tsx +23 -7
  86. package/dist/template/src/lib/highlight.ts +90 -31
  87. package/dist/template/src/lib/search.ts +14 -4
  88. package/dist/template/src/lib/theme-utils.ts +140 -0
  89. package/dist/template/src/styles/globals.css +307 -166
  90. package/dist/template/src/types/remark-gfm.d.ts +2 -0
  91. package/dist/utils/files.d.ts +9 -0
  92. package/dist/utils/files.js +33 -0
  93. package/dist/utils/validation.d.ts +4 -0
  94. package/dist/utils/validation.js +38 -0
  95. package/package.json +1 -4
@@ -0,0 +1,599 @@
1
+ # Content-type.ts
2
+
3
+ ## Functions
4
+
5
+ ### `classifyElement`
6
+
7
+ ```typescript
8
+ function classifyElement(element: APIElement): ContentClassification
9
+ ```
10
+
11
+ Use this to determine what type of documentation an API element needs — whether it should be documented as an API reference, a guide, or a tutorial — so you can route elements to the correct documentation generator automatically.
12
+
13
+ This function analyzes an `APIElement` and returns a `ContentClassification` indicating the most appropriate documentation style, along with reasoning scores and explanations for the decision.
14
+
15
+ ## Parameters
16
+
17
+ | Name | Type | Required | Description |
18
+ |------|------|----------|-------------|
19
+ | `element` | `APIElement` | āœ… | The API element to classify (function, class, type, etc.) |
20
+
21
+ ## Returns
22
+
23
+ Returns a `ContentClassification` object containing:
24
+
25
+ | Field | Type | Description |
26
+ |-------|------|-------------|
27
+ | `type` | `'api' \| 'guide' \| 'tutorial'` | The recommended documentation type |
28
+ | `reasons` | `string[]` | Human-readable explanations for the classification |
29
+ | `scores` | `{ api: number, guide: number, tutorial: number }` | Numeric confidence scores for each type |
30
+
31
+ The classification with the **highest score** wins. If scores are tied, `api` takes precedence over `guide`, which takes precedence over `tutorial`.
32
+
33
+ **Example:**
34
+
35
+ ```typescript example.ts
36
+ // ---- Inline types (do not import from autodocs) ----
37
+ type APIElementKind = 'function' | 'class' | 'interface' | 'type' | 'variable' | 'enum'
38
+
39
+ interface APIElement {
40
+ name: string
41
+ kind: APIElementKind
42
+ description?: string
43
+ parameters?: { name: string; type: string; description?: string }[]
44
+ returns?: { type: string; description?: string }
45
+ examples?: string[]
46
+ complexity?: 'low' | 'medium' | 'high'
47
+ tags?: string[]
48
+ }
49
+
50
+ interface ContentClassification {
51
+ type: 'api' | 'guide' | 'tutorial'
52
+ reasons: string[]
53
+ scores: {
54
+ api: number
55
+ guide: number
56
+ tutorial: number
57
+ }
58
+ }
59
+
60
+ // ---- Simulated classifyElement implementation ----
61
+ function classifyElement(element: APIElement): ContentClassification {
62
+ const reasons: string[] = []
63
+ let apiScore = 0
64
+ let guideScore = 0
65
+ let tutorialScore = 0
66
+
67
+ // Simple functions/types with clear signatures lean toward API docs
68
+ if (element.kind === 'function' || element.kind === 'type' || element.kind === 'interface') {
69
+ apiScore += 2
70
+ reasons.push(`Kind "${element.kind}" is well-suited for API reference documentation`)
71
+ }
72
+
73
+ // Classes with high complexity benefit from a guide
74
+ if (element.kind === 'class') {
75
+ guideScore += 2
76
+ reasons.push('Classes often require conceptual explanation — guide recommended')
77
+ }
78
+
79
+ // Elements with examples suggest tutorial potential
80
+ if (element.examples && element.examples.length > 0) {
81
+ tutorialScore += element.examples.length
82
+ reasons.push(`${element.examples.length} example(s) found — tutorial content possible`)
83
+ }
84
+
85
+ // High complexity pushes toward guide or tutorial
86
+ if (element.complexity === 'high') {
87
+ guideScore += 2
88
+ tutorialScore += 1
89
+ reasons.push('High complexity suggests a guide or tutorial would help users')
90
+ }
91
+
92
+ // Parameters increase API doc value
93
+ if (element.parameters && element.parameters.length > 0) {
94
+ apiScore += element.parameters.length
95
+ reasons.push(`${element.parameters.length} parameter(s) documented — strong API reference candidate`)
96
+ }
97
+
98
+ // Tags like 'quickstart' or 'walkthrough' push toward tutorial
99
+ if (element.tags?.includes('quickstart') || element.tags?.includes('walkthrough')) {
100
+ tutorialScore += 3
101
+ reasons.push('Tags indicate this element is intended as a walkthrough or quickstart')
102
+ }
103
+
104
+ const scores = { api: apiScore, guide: guideScore, tutorial: tutorialScore }
105
+
106
+ let type: 'api' | 'guide' | 'tutorial' = 'api'
107
+ if (guideScore > apiScore && guideScore >= tutorialScore) type = 'guide'
108
+ else if (tutorialScore > apiScore && tutorialScore > guideScore) type = 'tutorial'
109
+
110
+ return { type, reasons, scores }
111
+ }
112
+
113
+ // ---- Example usage ----
114
+ async function main() {
115
+ try {
116
+ // Example 1: A simple utility function → expect API classification
117
+ const utilFunction: APIElement = {
118
+ name: 'formatDate',
119
+ kind: 'function',
120
+ description: 'Formats a Date object into a locale string',
121
+ parameters: [
122
+ { name: 'date', type: 'Date', description: 'The date to format' },
123
+ { name: 'locale', type: 'string', description: 'BCP 47 locale string' }
124
+ ],
125
+ returns: { type: 'string', description: 'Formatted date string' },
126
+ complexity: 'low'
127
+ }
128
+
129
+ const result1 = classifyElement(utilFunction)
130
+ console.log('=== formatDate (simple function) ===')
131
+ console.log('Type:', result1.type) // Expected: 'api'
132
+ console.log('Scores:', result1.scores) // Expected: { api: 4, guide: 0, tutorial: 0 }
133
+ console.log('Reasons:', result1.reasons)
134
+ console.log()
135
+
136
+ // Example 2: A complex class → expect guide classification
137
+ const complexClass: APIElement = {
138
+ name: 'QueryBuilder',
139
+ kind: 'class',
140
+ description: 'Fluent interface for constructing database queries',
141
+ complexity: 'high',
142
+ examples: ['builder.select("*").from("users").where("id = 1").build()']
143
+ }
144
+
145
+ const result2 = classifyElement(complexClass)
146
+ console.log('=== QueryBuilder (complex class) ===')
147
+ console.log('Type:', result2.type) // Expected: 'guide'
148
+ console.log('Scores:', result2.scores) // Expected: { api: 0, guide: 4, tutorial: 2 }
149
+ console.log('Reasons:', result2.reasons)
150
+ console.log()
151
+
152
+ // Example 3: A tagged walkthrough function → expect tutorial classification
153
+ const walkthroughFn: APIElement = {
154
+ name: 'setupAuthFlow',
155
+ kind: 'function',
156
+ description: 'Walks through setting up OAuth2 authentication end-to-end',
157
+ complexity: 'medium',
158
+ tags: ['quickstart', 'walkthrough'],
159
+ examples: [
160
+ 'setupAuthFlow({ provider: "github" })',
161
+ 'setupAuthFlow({ provider: "google", scopes: ["email"] })'
162
+ ]
163
+ }
164
+
165
+ const result3 = classifyElement(walkthroughFn)
166
+ console.log('=== setupAuthFlow (walkthrough) ===')
167
+ console.log('Type:', result3.type) // Expected: 'tutorial'
168
+ console.log('Scores:', result3.scores) // Expected: { api: 2, guide: 0, tutorial: 7 }
169
+ console.log('Reasons:', result3.reasons)
170
+
171
+ } catch (error) {
172
+ console.error('Classification failed:', error)
173
+ }
174
+ }
175
+
176
+ main()
177
+ ```
178
+
179
+ ### `classifyElements`
180
+
181
+ ```typescript
182
+ function classifyElements(elements: APIElement[]): Map<ContentType, APIElement[]>
183
+ ```
184
+
185
+ Use this to sort a mixed list of documentation elements into typed groups — API references, guides, tutorials, and overviews — in a single pass.
186
+
187
+ Instead of manually filtering arrays for each content type, `classifyElements` returns a `Map` keyed by content type so you can immediately access any group by name.
188
+
189
+ ### Parameters
190
+
191
+ | Name | Type | Required | Description |
192
+ |------|------|----------|-------------|
193
+ | `elements` | `APIElement[]` | āœ… | Array of documentation elements to classify. Each element must have enough metadata for type detection (e.g., `kind`, `tags`, or `category` fields). |
194
+
195
+ ### Returns
196
+
197
+ A `Map<ContentType, APIElement[]>` where:
198
+
199
+ | Key | Value |
200
+ |-----|-------|
201
+ | `"api"` | Elements classified as API references (functions, classes, types) |
202
+ | `"guide"` | Elements classified as how-to guides |
203
+ | `"tutorial"` | Elements classified as step-by-step tutorials |
204
+ | `"overview"` | Elements classified as high-level overviews or introductions |
205
+
206
+ All four keys are always present in the returned map — groups with no matching elements return an empty array, so you never need to guard against `undefined`.
207
+
208
+ **Example:**
209
+
210
+ ```typescript example.ts
211
+ // ── Inline types (no external imports needed) ──────────────────────────────
212
+
213
+ type ContentType = 'api' | 'guide' | 'tutorial' | 'overview'
214
+
215
+ interface APIElement {
216
+ id: string
217
+ title: string
218
+ kind: ContentType
219
+ tags?: string[]
220
+ }
221
+
222
+ // ── Inline implementation matching the real function's behavior ────────────
223
+
224
+ function classifyElements(elements: APIElement[]): Map<ContentType, APIElement[]> {
225
+ const groups = new Map<ContentType, APIElement[]>([
226
+ ['api', []],
227
+ ['guide', []],
228
+ ['tutorial', []],
229
+ ['overview', []],
230
+ ])
231
+
232
+ for (const element of elements) {
233
+ const bucket = groups.get(element.kind)
234
+ if (bucket) {
235
+ bucket.push(element)
236
+ }
237
+ }
238
+
239
+ return groups
240
+ }
241
+
242
+ // ── Realistic usage example ────────────────────────────────────────────────
243
+
244
+ const docElements: APIElement[] = [
245
+ { id: 'fn-001', title: 'createUser()', kind: 'api', tags: ['users', 'auth'] },
246
+ { id: 'fn-002', title: 'deleteUser()', kind: 'api', tags: ['users'] },
247
+ { id: 'gd-001', title: 'Authentication Guide', kind: 'guide', tags: ['auth'] },
248
+ { id: 'tu-001', title: 'Build Your First App', kind: 'tutorial', tags: ['quickstart'] },
249
+ { id: 'tu-002', title: 'Deploy to Production', kind: 'tutorial', tags: ['deployment'] },
250
+ { id: 'ov-001', title: 'Platform Overview', kind: 'overview', tags: ['intro'] },
251
+ ]
252
+
253
+ async function main() {
254
+ try {
255
+ const classified = classifyElements(docElements)
256
+
257
+ // Access each group directly by content type
258
+ const apiDocs = classified.get('api') ?? []
259
+ const guides = classified.get('guide') ?? []
260
+ const tutorials = classified.get('tutorial') ?? []
261
+ const overviews = classified.get('overview') ?? []
262
+
263
+ console.log('=== Classified Documentation Elements ===\n')
264
+
265
+ console.log(`API References (${apiDocs.length}):`)
266
+ apiDocs.forEach(el => console.log(` • [${el.id}] ${el.title}`))
267
+
268
+ console.log(`\nGuides (${guides.length}):`)
269
+ guides.forEach(el => console.log(` • [${el.id}] ${el.title}`))
270
+
271
+ console.log(`\nTutorials (${tutorials.length}):`)
272
+ tutorials.forEach(el => console.log(` • [${el.id}] ${el.title}`))
273
+
274
+ console.log(`\nOverviews (${overviews.length}):`)
275
+ overviews.forEach(el => console.log(` • [${el.id}] ${el.title}`))
276
+
277
+ // All four keys are always present — even for empty categories
278
+ const emptyElements: APIElement[] = []
279
+ const emptyMap = classifyElements(emptyElements)
280
+ console.log('\nEmpty input still returns all keys:', [...emptyMap.keys()])
281
+
282
+ // Expected output:
283
+ // === Classified Documentation Elements ===
284
+ //
285
+ // API References (2):
286
+ // • [fn-001] createUser()
287
+ // • [fn-002] deleteUser()
288
+ //
289
+ // Guides (1):
290
+ // • [gd-001] Authentication Guide
291
+ //
292
+ // Tutorials (2):
293
+ // • [tu-001] Build Your First App
294
+ // • [tu-002] Deploy to Production
295
+ //
296
+ // Overviews (1):
297
+ // • [ov-001] Platform Overview
298
+ //
299
+ // Empty input still returns all keys: [ 'api', 'guide', 'tutorial', 'overview' ]
300
+
301
+ } catch (error) {
302
+ console.error('Classification failed:', error)
303
+ process.exit(1)
304
+ }
305
+ }
306
+
307
+ main()
308
+ ```
309
+
310
+ ### `getRecommendedStructure`
311
+
312
+ ```typescript
313
+ function getRecommendedStructure(elements: APIElement[]): {
314
+ sections: { name: string; type: ContentType; elements: APIElement[] }[]
315
+ stats: { api: number; guide: number; tutorial: number; overview: number }
316
+ }
317
+ ```
318
+
319
+ Use this to automatically organize a list of API elements into a recommended documentation structure — grouping them into logical sections (API reference, guides, tutorials, overviews) and providing a count breakdown by content type.
320
+
321
+ This is ideal when you have a mixed set of API elements and want a ready-made layout for generating a documentation site or navigation structure.
322
+
323
+ ## Parameters
324
+
325
+ | Name | Type | Required | Description |
326
+ |------|------|----------|-------------|
327
+ | `elements` | `APIElement[]` | āœ… Yes | Array of API elements (functions, classes, types, etc.) to analyze and organize |
328
+
329
+ ## Returns
330
+
331
+ An object with two properties:
332
+
333
+ | Property | Type | Description |
334
+ |----------|------|-------------|
335
+ | `sections` | `{ name: string; type: ContentType; elements: APIElement[] }[]` | Ordered list of recommended documentation sections, each with a display name, content type, and the elements that belong to it |
336
+ | `stats` | `{ api: number; guide: number; tutorial: number; overview: number }` | Count of elements assigned to each content type category |
337
+
338
+ ### `ContentType` values
339
+ - `"api"` — Reference documentation for functions, classes, and types
340
+ - `"guide"` — How-to and conceptual content
341
+ - `"tutorial"` — Step-by-step walkthroughs
342
+ - `"overview"` — High-level introductory content
343
+
344
+ ### When sections are empty
345
+ If no elements match a particular content type, that section will either be omitted or appear with an empty `elements` array — use `stats` to quickly check which categories have content before rendering.
346
+
347
+ **Example:**
348
+
349
+ ```typescript example.ts
350
+ // ── Inline types (no external imports needed) ──────────────────────────────
351
+
352
+ type ContentType = 'api' | 'guide' | 'tutorial' | 'overview'
353
+
354
+ type APIElement = {
355
+ name: string
356
+ kind: 'function' | 'class' | 'interface' | 'type' | 'variable' | 'module'
357
+ description?: string
358
+ tags?: string[]
359
+ }
360
+
361
+ type RecommendedStructure = {
362
+ sections: { name: string; type: ContentType; elements: APIElement[] }[]
363
+ stats: { api: number; guide: number; tutorial: number; overview: number }
364
+ }
365
+
366
+ // ── Simulated implementation of getRecommendedStructure ───────────────────
367
+
368
+ function classifyElement(el: APIElement): ContentType {
369
+ const tags = el.tags ?? []
370
+ if (tags.includes('tutorial')) return 'tutorial'
371
+ if (tags.includes('guide')) return 'guide'
372
+ if (tags.includes('overview') || el.kind === 'module') return 'overview'
373
+ return 'api'
374
+ }
375
+
376
+ function getRecommendedStructure(elements: APIElement[]): RecommendedStructure {
377
+ const buckets: Record<ContentType, APIElement[]> = {
378
+ overview: [],
379
+ guide: [],
380
+ tutorial: [],
381
+ api: [],
382
+ }
383
+
384
+ for (const el of elements) {
385
+ buckets[classifyElement(el)].push(el)
386
+ }
387
+
388
+ const sectionMeta: { type: ContentType; name: string }[] = [
389
+ { type: 'overview', name: 'Overview' },
390
+ { type: 'guide', name: 'Guides' },
391
+ { type: 'tutorial', name: 'Tutorials' },
392
+ { type: 'api', name: 'API Reference' },
393
+ ]
394
+
395
+ const sections = sectionMeta
396
+ .filter(({ type }) => buckets[type].length > 0)
397
+ .map(({ type, name }) => ({ name, type, elements: buckets[type] }))
398
+
399
+ const stats = {
400
+ api: buckets.api.length,
401
+ guide: buckets.guide.length,
402
+ tutorial: buckets.tutorial.length,
403
+ overview: buckets.overview.length,
404
+ }
405
+
406
+ return { sections, stats }
407
+ }
408
+
409
+ // ── Example usage ──────────────────────────────────────────────────────────
410
+
411
+ const elements: APIElement[] = [
412
+ {
413
+ name: 'AuthClient',
414
+ kind: 'class',
415
+ description: 'Handles authentication flows',
416
+ },
417
+ {
418
+ name: 'createToken',
419
+ kind: 'function',
420
+ description: 'Generates a signed JWT token',
421
+ },
422
+ {
423
+ name: 'TokenOptions',
424
+ kind: 'interface',
425
+ description: 'Options passed to createToken',
426
+ },
427
+ {
428
+ name: 'Getting Started',
429
+ kind: 'module',
430
+ description: 'Introduction to the auth library',
431
+ tags: ['overview'],
432
+ },
433
+ {
434
+ name: 'Securing Routes',
435
+ kind: 'module',
436
+ description: 'How to protect API endpoints',
437
+ tags: ['guide'],
438
+ },
439
+ {
440
+ name: 'Build a Login Flow',
441
+ kind: 'module',
442
+ description: 'Step-by-step login implementation',
443
+ tags: ['tutorial'],
444
+ },
445
+ ]
446
+
447
+ async function main() {
448
+ try {
449
+ const { sections, stats } = getRecommendedStructure(elements)
450
+
451
+ console.log('šŸ“Š Content stats:', stats)
452
+ // Output: { api: 3, guide: 1, tutorial: 1, overview: 1 }
453
+
454
+ console.log('\nšŸ“š Recommended sections:')
455
+ for (const section of sections) {
456
+ console.log(`\n [${section.type.toUpperCase()}] ${section.name}`)
457
+ for (const el of section.elements) {
458
+ console.log(` • ${el.name} (${el.kind})`)
459
+ }
460
+ }
461
+ /*
462
+ Output:
463
+ [OVERVIEW] Overview
464
+ • Getting Started (module)
465
+ [GUIDE] Guides
466
+ • Securing Routes (module)
467
+ [TUTORIAL] Tutorials
468
+ • Build a Login Flow (module)
469
+ [API] API Reference
470
+ • AuthClient (class)
471
+ • createToken (function)
472
+ • TokenOptions (interface)
473
+ */
474
+
475
+ // Practical use: only render sections that have content
476
+ const hasApiDocs = stats.api > 0
477
+ console.log('\nāœ… Has API reference docs:', hasApiDocs)
478
+ // Output: true
479
+
480
+ } catch (error) {
481
+ console.error('Failed to build documentation structure:', error)
482
+ }
483
+ }
484
+
485
+ main()
486
+ ```
487
+
488
+ ### `getPromptForContentType`
489
+
490
+ ```typescript
491
+ function getPromptForContentType(type: ContentType): string
492
+ ```
493
+
494
+ Use this to get the appropriate documentation generation prompt string for a given content type, so you can pass the right instructions to an LLM when auto-generating docs for APIs, components, functions, or other code elements.
495
+
496
+ This function acts as a prompt router — given a content type identifier, it returns a tailored prompt string that instructs a documentation generator on what to include and how to format the output for that specific type.
497
+
498
+ ### Parameters
499
+
500
+ | Name | Type | Required | Description |
501
+ |------|------|----------|-------------|
502
+ | `type` | `ContentType` | āœ… | The category of content to document. Determines which prompt template is returned. |
503
+
504
+ ### `ContentType` Values
505
+
506
+ | Value | Description |
507
+ |-------|-------------|
508
+ | `'api'` | REST API endpoints or API reference elements |
509
+ | `'component'` | UI components (e.g., React, Vue) |
510
+ | `'function'` | Standalone functions or methods |
511
+ | `'class'` | Classes and their members |
512
+
513
+ ### Returns
514
+
515
+ Returns a `string` containing a structured prompt with documentation instructions tailored to the given content type. The prompt includes guidance on what sections to cover (e.g., parameters, return values, usage examples).
516
+
517
+ **Example:**
518
+
519
+ ```typescript example.ts
520
+ // Inline the ContentType definition — no external imports needed
521
+ type ContentType = 'api' | 'component' | 'function' | 'class'
522
+
523
+ // Self-contained implementation matching the autodocs behavior
524
+ function getPromptForContentType(type: ContentType): string {
525
+ switch (type) {
526
+ case 'api':
527
+ return `Generate detailed API reference documentation. Include:
528
+ - Clear parameter descriptions with types
529
+ - Return value documentation
530
+ - HTTP method and endpoint details
531
+ - Request/response examples
532
+ - Error codes and handling`
533
+
534
+ case 'component':
535
+ return `Generate component documentation. Include:
536
+ - Props table with types and defaults
537
+ - Usage examples with JSX
538
+ - Event handlers and callbacks
539
+ - Accessibility considerations`
540
+
541
+ case 'function':
542
+ return `Generate function documentation. Include:
543
+ - Parameter names, types, and descriptions
544
+ - Return type and value description
545
+ - Usage examples
546
+ - Edge cases and error handling`
547
+
548
+ case 'class':
549
+ return `Generate class documentation. Include:
550
+ - Constructor parameters
551
+ - Public methods and properties
552
+ - Inheritance and interfaces
553
+ - Instantiation examples`
554
+
555
+ default:
556
+ throw new Error(`Unsupported content type: ${type}`)
557
+ }
558
+ }
559
+
560
+ // --- Example usage ---
561
+
562
+ const contentTypes: ContentType[] = ['api', 'component', 'function', 'class']
563
+
564
+ async function main() {
565
+ try {
566
+ for (const type of contentTypes) {
567
+ const prompt = getPromptForContentType(type)
568
+
569
+ console.log(`\n=== Prompt for type: "${type}" ===`)
570
+ console.log(prompt)
571
+ }
572
+
573
+ // Practical use: feed the prompt into an LLM call
574
+ const targetType: ContentType = 'function'
575
+ const docPrompt = getPromptForContentType(targetType)
576
+
577
+ const llmRequest = {
578
+ model: 'gpt-4',
579
+ systemPrompt: docPrompt,
580
+ userContent: 'function add(a: number, b: number): number { return a + b }',
581
+ }
582
+
583
+ console.log('\n=== LLM Request Payload ===')
584
+ console.log(JSON.stringify(llmRequest, null, 2))
585
+ // Output:
586
+ // {
587
+ // "model": "gpt-4",
588
+ // "systemPrompt": "Generate function documentation. Include:\n- Parameter names...",
589
+ // "userContent": "function add(a: number, b: number): number { return a + b }"
590
+ // }
591
+
592
+ } catch (error) {
593
+ console.error('Failed to get prompt:', error)
594
+ }
595
+ }
596
+
597
+ main()
598
+ ```
599
+