@oxog/npm-llms 1.0.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Ersin Koç
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,286 @@
1
+ # @oxog/npm-llms
2
+
3
+ Extract LLM-optimized documentation (llms.txt, llms-full.txt) from any NPM package with optional AI enrichment.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@oxog/npm-llms.svg)](https://www.npmjs.com/package/@oxog/npm-llms)
6
+ [![license](https://img.shields.io/npm/l/@oxog/npm-llms.svg)](https://github.com/ersinkoc/npm-llms/blob/main/LICENSE)
7
+
8
+ ## Features
9
+
10
+ - **Zero Runtime Dependencies** - Uses only Node.js built-in modules
11
+ - **llms.txt Generation** - Token-optimized documentation for AI assistants
12
+ - **Multiple Output Formats** - llms.txt, llms-full.txt, Markdown, JSON
13
+ - **TypeScript Support** - Parses .d.ts files and TypeScript source
14
+ - **Smart Truncation** - Prioritizes important content within token limits
15
+ - **Plugin Architecture** - Extensible micro-kernel design
16
+ - **Built-in Caching** - File-based cache with TTL support
17
+ - **CLI Included** - Command-line interface for quick extraction
18
+ - **AI Enrichment** - Optional AI-powered documentation enhancement
19
+
20
+ ## AI Providers
21
+
22
+ Enhance documentation with AI-generated descriptions and examples:
23
+
24
+ | Provider | Model Examples |
25
+ |----------|----------------|
26
+ | **OpenAI** | gpt-4.1, gpt-4.1-nano, o3, o1 |
27
+ | **Claude** | claude-opus-4-5, claude-sonnet-4-5, claude-haiku-4-5 |
28
+ | **Gemini** | gemini-3-flash-preview, gemini-2.5-pro |
29
+ | **Groq** | llama-3.3-70b-versatile, llama-4-maverick |
30
+ | **Ollama** | Any local model |
31
+ | **OpenAI-Compatible** | x.ai, DeepSeek, Mistral, Together, Perplexity, OpenRouter |
32
+
33
+ ## Installation
34
+
35
+ ```bash
36
+ npm install @oxog/npm-llms
37
+ ```
38
+
39
+ ## Quick Start
40
+
41
+ ### Programmatic API
42
+
43
+ ```typescript
44
+ import { createExtractor, extract } from '@oxog/npm-llms';
45
+
46
+ // Simple one-liner
47
+ const result = await extract('zod');
48
+ console.log(result.outputs['llms']);
49
+
50
+ // With full configuration
51
+ const extractor = createExtractor({
52
+ cache: {
53
+ enabled: true,
54
+ dir: '.npm-llms-cache',
55
+ ttl: 7 * 24 * 60 * 60 * 1000, // 7 days
56
+ },
57
+ verbose: true,
58
+ });
59
+
60
+ const result = await extractor.extract('lodash@4.17.21', {
61
+ formats: ['llms', 'llms-full', 'markdown', 'json'],
62
+ llmsTokenLimit: 2000,
63
+ prioritize: ['functions', 'examples'],
64
+ });
65
+
66
+ console.log(`Package: ${result.package.name}@${result.package.version}`);
67
+ console.log(`API entries: ${result.api.length}`);
68
+ console.log(`Token count: ${result.tokenCount}`);
69
+ ```
70
+
71
+ ### CLI
72
+
73
+ ```bash
74
+ # Extract llms.txt
75
+ npm-llms extract zod --llms
76
+
77
+ # Extract all formats to a directory
78
+ npm-llms extract lodash --all -o ./docs
79
+
80
+ # Print to stdout
81
+ npm-llms extract express --llms --stdout
82
+
83
+ # Extract specific version
84
+ npm-llms extract zod@3.22.0 --json
85
+
86
+ # Clear cache
87
+ npm-llms cache-clear
88
+
89
+ # Show help
90
+ npm-llms --help
91
+ ```
92
+
93
+ ## AI Enrichment
94
+
95
+ Enhance extracted documentation with AI-generated content:
96
+
97
+ ```typescript
98
+ import { createExtractor } from '@oxog/npm-llms';
99
+ import { createClaudePlugin } from '@oxog/npm-llms/plugins';
100
+
101
+ const extractor = createExtractor();
102
+
103
+ // Use Claude for AI enrichment
104
+ extractor.use(createClaudePlugin({
105
+ model: 'claude-haiku-4-5',
106
+ // apiKey: 'sk-...' // or set ANTHROPIC_API_KEY env var
107
+ }));
108
+
109
+ const result = await extractor.extract('zod');
110
+ ```
111
+
112
+ ### Using OpenAI-Compatible Providers
113
+
114
+ ```typescript
115
+ import {
116
+ createOpenAIProvider,
117
+ createXAIProvider,
118
+ createDeepSeekProvider,
119
+ createMistralProvider,
120
+ } from '@oxog/npm-llms/plugins';
121
+
122
+ // x.ai (Grok)
123
+ const xai = createXAIProvider({ model: 'grok-3-mini-fast' });
124
+
125
+ // DeepSeek
126
+ const deepseek = createDeepSeekProvider({ model: 'deepseek-chat' });
127
+
128
+ // Mistral
129
+ const mistral = createMistralProvider({ model: 'mistral-small-latest' });
130
+
131
+ // Any OpenAI-compatible endpoint
132
+ const custom = createOpenAIProvider({
133
+ baseUrl: 'https://my-api.example.com/v1',
134
+ apiKey: 'my-key',
135
+ model: 'my-model',
136
+ });
137
+ ```
138
+
139
+ ## Output Formats
140
+
141
+ ### llms.txt
142
+
143
+ Token-limited (default 2000 tokens) summary optimized for AI assistants:
144
+ - Package description
145
+ - Installation instructions
146
+ - Quick start examples
147
+ - API summary (functions, classes, types)
148
+
149
+ ### llms-full.txt
150
+
151
+ Complete API documentation:
152
+ - All exported functions with full signatures
153
+ - All parameters and return types
154
+ - All examples from JSDoc
155
+ - Class methods and properties
156
+
157
+ ### Markdown (API.md)
158
+
159
+ Human-readable documentation:
160
+ - Table of contents
161
+ - Parameter tables
162
+ - Code examples with syntax highlighting
163
+ - Type definitions
164
+
165
+ ### JSON (api.json)
166
+
167
+ Structured JSON output for programmatic use:
168
+ - Full API metadata
169
+ - Package information
170
+ - All type definitions
171
+
172
+ ## API Reference
173
+
174
+ ### createExtractor(options?)
175
+
176
+ Creates an extractor instance with optional configuration.
177
+
178
+ ```typescript
179
+ const extractor = createExtractor({
180
+ cache: {
181
+ enabled: true, // Enable caching (default: true)
182
+ dir: '.cache', // Cache directory
183
+ ttl: 604800000, // TTL in ms (default: 7 days)
184
+ },
185
+ registry: 'https://registry.npmjs.org',
186
+ verbose: false,
187
+ });
188
+ ```
189
+
190
+ ### extractor.extract(packageSpec, options?)
191
+
192
+ Extracts documentation from a package.
193
+
194
+ ```typescript
195
+ const result = await extractor.extract('package-name@version', {
196
+ formats: ['llms', 'llms-full', 'markdown', 'json'],
197
+ llmsTokenLimit: 2000,
198
+ prioritize: ['functions', 'examples'],
199
+ ignoreCache: false,
200
+ });
201
+ ```
202
+
203
+ ### extract(packageSpec, options?)
204
+
205
+ Convenience function that creates a temporary extractor.
206
+
207
+ ```typescript
208
+ const result = await extract('zod', { formats: ['llms'] });
209
+ ```
210
+
211
+ ## Plugin System
212
+
213
+ The extractor uses a micro-kernel architecture with plugins for parsing and output generation.
214
+
215
+ ### Creating a Plugin
216
+
217
+ ```typescript
218
+ import { definePlugin } from '@oxog/npm-llms';
219
+
220
+ const myPlugin = definePlugin({
221
+ name: 'my-plugin',
222
+ version: '1.0.0',
223
+ category: 'output',
224
+
225
+ install(kernel) {
226
+ kernel.on('output:generate', async (context) => {
227
+ context.outputs.set('custom', myCustomOutput);
228
+ });
229
+ },
230
+ });
231
+
232
+ const extractor = createExtractor();
233
+ extractor.use(myPlugin);
234
+ ```
235
+
236
+ ### Available Events
237
+
238
+ - `parse:dts` - After parsing .d.ts files
239
+ - `parse:typescript` - After parsing TypeScript source
240
+ - `parse:readme` - After parsing README
241
+ - `output:generate` - When generating outputs
242
+ - `output:llms` - Before generating llms.txt
243
+ - `output:llms-full` - Before generating llms-full.txt
244
+ - `output:markdown` - Before generating markdown
245
+ - `output:json` - Before generating JSON
246
+
247
+ ## Error Handling
248
+
249
+ All errors extend `NpmLlmsError` with a `code` property:
250
+
251
+ ```typescript
252
+ import { extract, isNpmLlmsError } from '@oxog/npm-llms';
253
+
254
+ try {
255
+ await extract('nonexistent-package-12345');
256
+ } catch (error) {
257
+ if (isNpmLlmsError(error)) {
258
+ console.log(error.code); // 'PKG_NOT_FOUND'
259
+ console.log(error.message);
260
+ }
261
+ }
262
+ ```
263
+
264
+ ### Error Codes
265
+
266
+ | Code | Description |
267
+ |------|-------------|
268
+ | `PKG_NOT_FOUND` | Package doesn't exist on NPM |
269
+ | `VERSION_NOT_FOUND` | Specified version doesn't exist |
270
+ | `DOWNLOAD_FAILED` | Failed to download package tarball |
271
+ | `PARSE_ERROR` | Failed to parse source files |
272
+ | `CACHE_ERROR` | Cache read/write error |
273
+ | `CONFIG_ERROR` | Invalid configuration |
274
+ | `PLUGIN_ERROR` | Plugin error |
275
+ | `TAR_ERROR` | Tar extraction error |
276
+ | `TIMEOUT` | Operation timed out |
277
+ | `VALIDATION_ERROR` | Invalid input |
278
+
279
+ ## Requirements
280
+
281
+ - Node.js 18+
282
+ - No runtime dependencies (AI plugins are optional)
283
+
284
+ ## License
285
+
286
+ MIT